-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.go
101 lines (83 loc) · 2.77 KB
/
video.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"github.com/tncardoso/gocurses"
)
const (
windowLines = 12
windowColumns = 32
)
type Display struct {
main *gocurses.Window
debug *gocurses.Window
memory *gocurses.Window
registers *gocurses.Window
cpu *Cpu
}
func (display *Display) update_main() {
display.main.Box(0, 0)
display.main.Mvaddstr(0, 2, "DCPU-16")
for i := int(0); i < windowLines*windowColumns; i++ {
ch := int(display.cpu.Mem[0x8000+i-1]&0xff)
if ch == 0 {
ch = 96
}
display.main.Mvaddch((i/windowColumns)+1, (i%windowColumns)+1, rune(ch))
}
display.main.Refresh()
}
func (display *Display) log(str string) {
display.debug.Addstr(str)
display.debug.Refresh()
}
func (display *Display) update_debug() {
//display.debug.Box(0, 0)
//display.debug.Mvaddstr(0, 2, "Debug")
display.debug.Refresh()
}
func (display *Display) update_memory() {
display.memory.Box(0, 0)
display.memory.Mvaddstr(0, 2, "Memory")
display.memory.Refresh()
}
func (display *Display) update_registers() {
display.registers.Box(0, 0)
display.registers.Mvaddstr(0, 2, "Info/Registers")
display.registers.Mvaddstr(1, 1, fmt.Sprintf("A: %X B: %X C: %X",
display.cpu.A, display.cpu.B, display.cpu.C))
display.registers.Mvaddstr(2, 1, fmt.Sprintf("X: %X Y: %X Z: %X",
display.cpu.X, display.cpu.Y, display.cpu.Z))
display.registers.Mvaddstr(3, 1, fmt.Sprintf("I: %X J: %X, O: %X",
display.cpu.I, display.cpu.J, display.cpu.O))
display.registers.Mvaddstr(4, 1, fmt.Sprintf("PC: %X SP: %X",
display.cpu.PC, display.cpu.PC))
display.registers.Mvaddstr(5, 1, fmt.Sprintf("Cycles: %.f", display.cpu.cycles))
display.registers.Refresh()
}
func NewDisplay(cpu *Cpu) *Display {
display := &Display {cpu: cpu}
gocurses.Initscr()
defer gocurses.End()
gocurses.Cbreak()
gocurses.Noecho()
gocurses.Stdscr.Keypad(false)
gocurses.Refresh()
// Main Window
display.main = gocurses.NewWindow(windowLines+2, windowColumns+2, 1, 1)
// Info Window
display.registers = gocurses.NewWindow(windowLines/2+1, windowColumns+2,
1, windowColumns+3)
// Memory Window
display.memory = gocurses.NewWindow(windowLines/2+1, windowColumns+2,
windowLines/2+2, windowColumns+3)
//// Debug Window
display.debug = gocurses.NewWindow(windowLines+2, 80, windowLines+3, 1)
display.debug.Scrollok(true)
// Refresh All Windows
display.update_main()
display.update_memory()
display.update_registers()
display.update_debug()
//gocurses.Getch()
return display
}