-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.go
68 lines (63 loc) · 1.49 KB
/
common.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
package main
import (
"io"
"os"
)
// DummyDevice only exists for protyping purposes, and will always return `0`
// when read from, as well as not do anything when written to
var DummyDevice = Device{
ReadByte: func(d *Device, port byte) byte {
return 0
},
WriteByte: func(d *Device, port byte) {
},
}
// The SystemDevice controls the execution of the Uxn system
// Reference: https://wiki.xxiivv.com/site/varvara.html#system
var SystemDevice = Device{
ReadByte: func(d *Device, port byte) byte {
switch port {
case 0x2:
return d.u.WorkingStack.Pointer
case 0x3:
return d.u.ReturnStack.Pointer
default:
return d.Data[port]
}
},
WriteByte: func(d *Device, port byte) {
switch port {
case 0x2:
d.u.WorkingStack.Pointer = d.Data[port]
case 0x3:
d.u.ReturnStack.Pointer = d.Data[port]
case 0xe: // Prints the contents of the stacks
panic("system_inspect")
//system_inspect(d.u)
case 0xf: // Halts the program
d.u.Halted = true
default:
//panic("system_deo_special")
//system_deo_special(d, port)
}
},
}
// The ConsoleDevice controls input and output from the host
// Reference: https://wiki.xxiivv.com/site/varvara.html#console
var ConsoleDevice = Device{
ReadByte: func(d *Device, port byte) byte {
panic("Tried to read from unimplemented device")
},
WriteByte: func(d *Device, port byte) {
var out io.Writer
switch port {
case 0x8:
out = os.Stdout
case 0x9:
out = os.Stderr
}
if out != nil {
out.Write([]byte{d.Data[port]})
}
},
}