-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.odin
134 lines (119 loc) · 1.5 KB
/
mem.odin
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package main
import "core:container/queue"
import "core:fmt"
import "core:os"
ram: [4096]u8
reg: [0x10]u8
display: [64][32]u8
stack: queue.Queue(u16)
@(init)
initMem :: proc() {
queue.init(&stack)
font := [?]u8 {
0xF0,
0x90,
0x90,
0x90,
0xF0, // 0
0x20,
0x60,
0x20,
0x20,
0x70, // 1
0xF0,
0x10,
0xF0,
0x80,
0xF0, // 2
0xF0,
0x10,
0xF0,
0x10,
0xF0, // 3
0x90,
0x90,
0xF0,
0x10,
0x10, // 4
0xF0,
0x80,
0xF0,
0x10,
0xF0, // 5
0xF0,
0x80,
0xF0,
0x90,
0xF0, // 6
0xF0,
0x10,
0x20,
0x40,
0x40, // 7
0xF0,
0x90,
0xF0,
0x90,
0xF0, // 8
0xF0,
0x90,
0xF0,
0x10,
0xF0, // 9
0xF0,
0x90,
0xF0,
0x90,
0x90, // A
0xE0,
0x90,
0xE0,
0x90,
0xE0, // B
0xF0,
0x80,
0x80,
0x80,
0xF0, // C
0xE0,
0x90,
0x90,
0x90,
0xE0, // D
0xF0,
0x80,
0xF0,
0x80,
0xF0, // E
0xF0,
0x80,
0xF0,
0x80,
0x80, // F
}
// add font data to memory
for i in 0 ..< len(font) {
ram[0x050 + i] = font[i]
}
// fmt.println(j)
// fmt.printf("%x",ram)
// load rom
rom: []byte
ok: bool
if len(os.args) > 1 do rom, ok = os.read_entire_file(os.args[1])
else do rom, ok = os.read_entire_file("roms/ibm.ch8")
assert(ok, "Error loading rom")
for i in 0 ..< len(rom) {
ram[0x200 + i] = rom[i]
}
// fmt.printf("%x",ram)
// display[0][0] = 0x01
// fmt.printf("%x\n\n\n", display)
// clearDisplay()
// fmt.printf("%x", display)
}
cycles: u64
I: u16
PC: u16 = 0x200
DTimer, STimer: u8
block := 0