Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (56 sloc) 1.83 KB
package main
import (
"github.com/nsf/termbox-go"
)
func main() {
program := []Word{
/*
0x7c01, 0x0030, 0x7de1, 0x1000, 0x0020, 0x7803, 0x1000, 0xc00d,
0x7dc1, 0x001a, 0xa861, 0x7c01, 0x2000, 0x2161, 0x2000, 0x8463,
0x806d, 0x7dc1, 0x000d, 0x9031, 0x7c10, 0x0018, 0x7dc1, 0x001a,
0x9037, 0x61c1, 0x7dc1, 0x001a, 0x0000, 0x0000, 0x0000, 0x0000,
*/
/*
0x8061, 0x8071, 0x7c11, 0xf100, 0x5801, 0x001f, 0x800c, 0x7dc1,
0x003c, 0x7c0e, 0x00ff, 0x7dc1, 0x0014, 0x040a, 0x0171, 0x8000,
0x8462, 0x8472, 0x7dc1, 0x0004, 0x0011, 0x7c19, 0x00ff, 0xa017,
0x7c0e, 0x01ff, 0x7c12, 0x0080, 0x8462, 0x7dc1, 0x0004, 0x0170,
0x0048, 0x0065, 0x006c, 0x006c, 0x006f, 0x0020, 0x02e1, 0x0077,
0x006f, 0x0072, 0x006c, 0x0064, 0x0170, 0x002c, 0x0020, 0x0068,
0x006f, 0x0077, 0x0020, 0x0061, 0x0072, 0x0065, 0x0020, 0x0079,
0x006f, 0x0075, 0x003f, 0x0000, 0x7dc1, 0x0000,
*/
0x7C01, 0xBEEF, 0x01E1, 0x1000, 0x780D, 0x1000, 0x7DC1, 0x0020, 0x8061, 0x816C, 0x0013, 0x7DC1, 0x0020,
0x5961, 0x8000, 0x0013, 0x8462, 0x7DC1, 0x0009, 0x0048, 0x0065, 0x006C, 0x006C, 0x006F, 0x0020, 0x0077,
0x006F, 0x0072, 0x006C, 0x0064, 0x0021, 0x0000, 0x85C3,
}
cpu := new(Dcpu)
cpu.PC = 0
cpu.SP = 0xffff
video := new(Video)
video.Init()
event_queue := make(chan termbox.Event)
go func() {
for {
ev := termbox.PollEvent()
event_queue <- ev
}
}()
for index, value := range program {
Memory[index] = value
}
runloop:
for ; int(cpu.PC) < len(program); {
cpu.Step()
select {
case ev := <-event_queue:
if ev.Type == termbox.EventKey && ev.Key == termbox.KeyEsc {
break runloop
}
default:
cpu.Step()
video.DrawScreen()
}
}
video.Close()
}