|
4 | 4 |
|
5 | 5 | # MIT License
|
6 | 6 | #
|
7 |
| -# Copyright (c) 2019 corax89, 2023 Timendus |
| 7 | +# Copyright (c) 2019 corax89, 2023,2024 Timendus |
8 | 8 | #
|
9 | 9 | # Permission is hereby granted, free of charge, to any person obtaining a copy
|
10 | 10 | # of this software and associated documentation files (the "Software"), to deal
|
|
27 | 27 | :alias x0 v8
|
28 | 28 | :alias x1 v9
|
29 | 29 | :alias x2 vA
|
30 |
| -:alias y vB |
| 30 | +:alias y vB |
31 | 31 |
|
32 | 32 | :macro drawop A B {
|
33 | 33 | i := A
|
34 | 34 | sprite x0 y 4
|
| 35 | + |
35 | 36 | i := B
|
36 | 37 | sprite x1 y 4
|
37 | 38 | }
|
38 | 39 |
|
39 |
| -: test2X |
40 |
| - i := image-ok |
41 |
| - sprite x2 y 4 |
| 40 | +: test-2X-0E |
| 41 | + v0 := 1 |
42 | 42 | return
|
| 43 | + # These opcodes will run if the interpreter doesn't have return (00EE) implemented: |
| 44 | + v0 := 2 |
| 45 | + jump test-2X-0E-hard-return |
43 | 46 |
|
44 | 47 | : main
|
45 | 48 | clear
|
| 49 | + |
| 50 | + # Display current version |
46 | 51 | x0 := 50
|
47 | 52 | y := 26
|
48 | 53 | i := version-0-0
|
|
51 | 56 | i := version-1-0
|
52 | 57 | sprite x0 y 4
|
53 | 58 |
|
| 59 | + # Show output in the first column |
54 | 60 | x0 := 2
|
55 | 61 | x1 := 6
|
56 | 62 | x2 := 11
|
57 | 63 | y := 1
|
| 64 | + |
| 65 | +################# |
| 66 | +# Test 3xNN |
| 67 | + |
58 | 68 | v5 := 42
|
59 | 69 | v6 := 43
|
60 |
| - |
61 |
| - #test 3x |
62 | 70 | drawop im3 imX
|
63 | 71 | i := image-ok
|
64 | 72 | if v6 != 43 then i := image-no
|
65 | 73 | sprite x2 y 4
|
66 | 74 |
|
67 |
| - #test 4x |
| 75 | +################# |
| 76 | +# Test 4xNN |
| 77 | + |
68 | 78 | y := 6
|
69 | 79 | drawop im4 imX
|
70 | 80 | i := image-no
|
71 | 81 | if v5 == 42 then i := image-ok
|
72 | 82 | sprite x2 y 4
|
73 | 83 |
|
74 |
| - #test 5x |
| 84 | +################# |
| 85 | +# Test 5xy0 |
| 86 | + |
75 | 87 | y := 11
|
76 | 88 | drawop im5 imX
|
77 | 89 | i := image-no
|
78 | 90 | if v5 != v6 then i := image-ok
|
79 | 91 | sprite x2 y 4
|
80 | 92 |
|
81 |
| - #test 7x |
| 93 | +################# |
| 94 | +# Test 7xNN |
| 95 | + |
82 | 96 | y := 16
|
83 | 97 | drawop im7 imX
|
84 | 98 | i := image-no
|
85 | 99 | v6 += 255
|
86 | 100 | if v6 == 42 then i := image-ok
|
87 | 101 | sprite x2 y 4
|
88 | 102 |
|
89 |
| - #test 9x |
| 103 | +################# |
| 104 | +# Test 9xy0 |
| 105 | + |
90 | 106 | y += 5
|
91 | 107 | drawop im9 imX
|
92 | 108 | i := image-no
|
93 | 109 | if v5 == v6 then i := image-ok
|
94 | 110 | sprite x2 y 4
|
95 | 111 |
|
96 |
| - #test 1x |
| 112 | +################# |
| 113 | +# Test 1NNN (displayed as 1X) |
| 114 | + |
97 | 115 | y += 5
|
98 | 116 | drawop im1 imX
|
99 | 117 | i := image-ok
|
100 |
| - jump test1x |
| 118 | + jump test-1X-pass |
101 | 119 | i := image-no
|
102 |
| -: test1x |
| 120 | +: test-1X-pass |
103 | 121 | sprite x2 y 4
|
104 | 122 |
|
105 |
| - #test "AX" |
106 |
| - # Note by Timendus: I think this really tests 2NNN, not ANNN, so I changed the |
107 |
| - # displayed label on this to not confuse users. |
108 |
| - # See PR: https://github.com/corax89/chip8-test-rom/pull/9 |
| 123 | + # Show output in the second column |
109 | 124 | x0 := 18
|
110 | 125 | x1 := 22
|
111 | 126 | x2 := 27
|
112 | 127 | y := 1
|
| 128 | + |
| 129 | +################# |
| 130 | +# Test calling subroutines (2NNN, displayed as 2X) |
| 131 | + |
113 | 132 | drawop im2 imX
|
114 |
| - test2X |
| 133 | + v0 := 0 |
| 134 | + test-2X-0E # Attempt to run a subroutine |
| 135 | +: test-2X-0E-hard-return |
| 136 | + i := image-ok |
| 137 | + if v0 == 0 then i := image-no # Subroutine was never called |
| 138 | + sprite x2 y 4 |
| 139 | + |
| 140 | +################# |
| 141 | +# Test returning from subroutines (00EE, displayed as 0E) |
115 | 142 |
|
116 |
| - #test 0E |
117 | 143 | y += 5
|
118 | 144 | drawop im0 imE
|
119 | 145 | i := image-ok
|
120 |
| - sprite x2 y 4 |
| 146 | + if v0 == 2 then i := image-no # Return didn't work |
| 147 | + if v0 != 0 then sprite x2 y 4 # If subroutine wasn't called, return wasn't tested |
| 148 | + |
| 149 | +################# |
| 150 | +# Test 8xy0 |
121 | 151 |
|
122 |
| - #test 8xy0 |
123 | 152 | y += 5
|
124 | 153 | drawop im8 im0
|
125 | 154 | i := image-no
|
|
129 | 158 | if v7 == 42 then i := image-ok
|
130 | 159 | sprite x2 y 4
|
131 | 160 |
|
132 |
| - #test 8xy1 |
| 161 | +################# |
| 162 | +# Test 8xy1 |
| 163 | + |
133 | 164 | y += 5
|
134 | 165 | drawop im8 im1
|
135 | 166 | i := image-no
|
|
139 | 170 | if v7 == 43 then i := image-ok
|
140 | 171 | sprite x2 y 4
|
141 | 172 |
|
142 |
| - #test 8xy2 |
| 173 | +################# |
| 174 | +# Test 8xy2 |
| 175 | + |
143 | 176 | y += 5
|
144 | 177 | drawop im8 im2
|
145 | 178 | i := image-no
|
|
149 | 182 | if v7 == 24 then i := image-ok
|
150 | 183 | sprite x2 y 4
|
151 | 184 |
|
152 |
| - #test 8xy3 |
| 185 | +################# |
| 186 | +# Test 8xy3 |
| 187 | + |
153 | 188 | y += 5
|
154 | 189 | drawop im8 im3
|
155 | 190 | i := image-no
|
|
159 | 194 | if v7 == 103 then i := image-ok
|
160 | 195 | sprite x2 y 4
|
161 | 196 |
|
162 |
| - #test 8xy4 |
| 197 | + # Show output in the third column |
163 | 198 | x0 := 34
|
164 | 199 | x1 := 38
|
165 | 200 | x2 := 43
|
166 | 201 | y := 1
|
| 202 | + |
| 203 | +################# |
| 204 | +# Test 8xy4 |
| 205 | + |
167 | 206 | drawop im8 im4
|
168 | 207 | i := image-no
|
169 | 208 | v6 := 140
|
|
172 | 211 | if v7 == 24 then i := image-ok
|
173 | 212 | sprite x2 y 4
|
174 | 213 |
|
175 |
| - #test 8xy5 |
| 214 | +################# |
| 215 | +# Test 8xy5 |
| 216 | + |
176 | 217 | y += 5
|
177 | 218 | drawop im8 im5
|
178 | 219 | i := image-no
|
|
182 | 223 | if v7 == 236 then i := image-ok
|
183 | 224 | sprite x2 y 4
|
184 | 225 |
|
185 |
| - #test 8xy7 |
| 226 | +################# |
| 227 | +# Test 8xy7 |
| 228 | + |
186 | 229 | y += 5
|
187 | 230 | drawop im8 im7
|
188 | 231 | i := image-no
|
|
192 | 235 | if v7 == 236 then i := image-ok
|
193 | 236 | sprite x2 y 4
|
194 | 237 |
|
195 |
| - #test "8xyE" |
196 |
| - # Note by Timendus: This should be 8XY6, changed the label here too. |
197 |
| - # See PR: https://github.com/corax89/chip8-test-rom/pull/7 |
| 238 | +################# |
| 239 | +# Test 8xy6 |
| 240 | + |
198 | 241 | y += 5
|
199 | 242 | drawop im8 im6
|
200 | 243 | i := image-no
|
|
203 | 246 | if v6 == 7 then i := image-ok
|
204 | 247 | sprite x2 y 4
|
205 | 248 |
|
206 |
| - #test "8xy6" |
207 |
| - # Note by Timendus: This should be 8XYE, changed the label here too. |
208 |
| - # See PR: https://github.com/corax89/chip8-test-rom/pull/7 |
| 249 | +################# |
| 250 | +# Test 8xyE |
| 251 | + |
209 | 252 | y += 5
|
210 | 253 | drawop im8 imE
|
211 | 254 | i := image-no
|
|
214 | 257 | if v6 == 192 then i := image-ok
|
215 | 258 | sprite x2 y 4
|
216 | 259 |
|
217 |
| - #test Fx65 |
| 260 | +################# |
| 261 | +# Test Fx65 |
| 262 | + |
218 | 263 | y += 5
|
219 | 264 | drawop imF im6
|
220 | 265 | i := scratchpad
|
|
224 | 269 | if v1 != 0x55 then i := image-no
|
225 | 270 | sprite x2 y 4
|
226 | 271 |
|
227 |
| - #test Fx55 |
| 272 | +################# |
| 273 | +# Test Fx55 |
| 274 | + |
228 | 275 | x0 := 50
|
229 | 276 | x1 := 54
|
230 | 277 | x2 := 59
|
|
244 | 291 | if v1 != 0 then i := image-no
|
245 | 292 | sprite x2 y 4
|
246 | 293 |
|
247 |
| - #test Fx33 |
| 294 | +################# |
| 295 | +# Test Fx33 |
| 296 | + |
248 | 297 | y += 5
|
249 | 298 | drawop imF im3
|
| 299 | + |
| 300 | + # N >= 100 |
250 | 301 | i := scratchpad
|
251 | 302 | v6 := 137
|
252 | 303 | bcd v6
|
253 | 304 | load v2
|
| 305 | + i := image-no |
| 306 | + if v0 != 1 then jump fx33-fail |
| 307 | + if v1 != 3 then jump fx33-fail |
| 308 | + if v2 != 7 then jump fx33-fail |
| 309 | + |
| 310 | + # N < 100 |
| 311 | + i := scratchpad |
| 312 | + v6 := 65 |
| 313 | + bcd v6 |
| 314 | + load v2 |
| 315 | + i := image-no |
| 316 | + if v0 != 0 then jump fx33-fail |
| 317 | + if v1 != 6 then jump fx33-fail |
| 318 | + if v2 != 5 then jump fx33-fail |
| 319 | + |
| 320 | + # N < 10 |
| 321 | + i := scratchpad |
| 322 | + v6 := 4 |
| 323 | + bcd v6 |
| 324 | + load v2 |
| 325 | + i := image-no |
| 326 | + if v0 != 0 then jump fx33-fail |
| 327 | + if v1 != 0 then jump fx33-fail |
| 328 | + if v2 != 4 then jump fx33-fail |
| 329 | + |
254 | 330 | i := image-ok
|
255 |
| - if v0 != 1 then i := image-no |
256 |
| - if v1 != 3 then i := image-no |
257 |
| - if v2 != 7 then i := image-no |
| 331 | +: fx33-fail |
258 | 332 | sprite x2 y 4
|
259 | 333 |
|
260 |
| - #test Fx1E |
| 334 | +################# |
| 335 | +# Test Fx1E |
| 336 | + |
261 | 337 | y += 5
|
262 | 338 | drawop imF imE
|
263 | 339 | i := image-no
|
264 | 340 | v6 := 4
|
265 | 341 | i += v6
|
266 | 342 | sprite x2 y 4
|
267 | 343 |
|
268 |
| - # Test to see if registers are 8 bit, as much as we can |
| 344 | +################# |
| 345 | +# Test to see if registers are 8 bit, as thoroughly as possible. |
| 346 | + |
269 | 347 | y += 5
|
270 | 348 | drawop imV imX
|
271 | 349 | i := image-ok
|
| 350 | + |
272 | 351 | # Addition opcodes should not allow us to overflow
|
273 | 352 | v6 := 255
|
274 | 353 | v6 += 10
|
|
281 | 360 | if v6 != 9 then i := image-no
|
282 | 361 | v6 >>= v6
|
283 | 362 | if v6 != 4 then i := image-no
|
| 363 | + |
284 | 364 | # Shift opcodes should not retain bits
|
285 | 365 | v6 := 255
|
286 | 366 | v6 <<= v6
|
|
289 | 369 | v6 >>= v6
|
290 | 370 | v6 <<= v6
|
291 | 371 | if v6 != 126 then i := image-no
|
| 372 | + |
292 | 373 | # Subtraction should wrap back to positive
|
293 | 374 | v6 := 5
|
294 | 375 | v6 -= 10
|
|
299 | 380 | v6 := 5
|
300 | 381 | v0 =- v6
|
301 | 382 | if v0 != 251 then i := image-no
|
| 383 | + |
302 | 384 | sprite x2 y 4
|
303 | 385 |
|
| 386 | +################# |
| 387 | +# Test is done! |
| 388 | + |
304 | 389 | loop again
|
305 | 390 |
|
306 | 391 | : scratchpad
|
|
416 | 501 | : version-0-0
|
417 | 502 | 0x0a 0xae 0xa2 0x42
|
418 | 503 | : version-1-0
|
419 |
| - 0x10 0x30 0x10 0xb8 |
| 504 | + 0x38 0x08 0x30 0xb8 |
420 | 505 |
|
0 commit comments