-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinput.go
43 lines (38 loc) · 1.21 KB
/
input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"log"
"github.com/nsf/termbox-go"
)
func processInput(cpu *CPU) (err error) {
for {
switch ev := termbox.PollEvent(); ev.Type {
case termbox.EventKey:
if cpu.DebugMode {
log.Println(fmt.Sprintf("Key pressed: %d", ev.Ch))
}
cpu.keyBuffer = append(cpu.keyBuffer, ev.Ch)
switch {
case ev.Ch == 'q' || ev.Key == termbox.KeyEsc || ev.Key == termbox.KeyCtrlC || ev.Key == termbox.KeyCtrlD:
instr := cpu.ReadMemory(cpu.PC)
op := instr >> 12
// stop the CPU from executing
cpu.Stop()
if cpu.DebugMode {
log.Println("========= DEBUG OUTPUT ====================")
log.Println(fmt.Sprintf("R0: 0x%04X", cpu.Reg[0]))
log.Println(fmt.Sprintf("R1: 0x%04X", cpu.Reg[1]))
log.Println(fmt.Sprintf("R2: 0x%04X", cpu.Reg[2]))
log.Println(fmt.Sprintf("R3: 0x%04X", cpu.Reg[3]))
log.Println(fmt.Sprintf("R4: 0x%04X", cpu.Reg[4]))
log.Println(fmt.Sprintf("R5: 0x%04X", cpu.Reg[5]))
log.Println(fmt.Sprintf("R6: 0x%04X", cpu.Reg[6]))
log.Println(fmt.Sprintf("R7: 0x%04X", cpu.Reg[7]))
log.Println(fmt.Sprintf("PC: 0x%04X", cpu.PC))
log.Println(fmt.Sprintf("Inst: 0x%04X Op: %d", instr, op))
}
return
}
}
}
}