]> gitweb.factorcode.org Git - factor.git/blob - extra/cpu/8080/test/test.factor
use radix literals
[factor.git] / extra / cpu / 8080 / test / test.factor
1 USING: \r
2     accessors\r
3     combinators\r
4     cpu.8080\r
5     cpu.8080.emulator\r
6     io\r
7     io.files\r
8     io.encodings.ascii\r
9     kernel \r
10     math\r
11     math.bits\r
12     sequences\r
13     tools.time\r
14 ;\r
15 IN: cpu.8080.test\r
16 \r
17 : step ( cpu -- )\r
18   #! Run a single 8080 instruction\r
19   [ read-instruction ] keep ! n cpu\r
20   over get-cycles over inc-cycles\r
21   [ swap instructions nth call( cpu -- ) ] keep\r
22   [ pc>> 0xFFFF bitand ] keep \r
23   [ pc<< ] keep \r
24   process-interrupts ;\r
25 \r
26 : test-step ( cpu -- cpu )\r
27   [ step ] keep dup cpu. ;\r
28 \r
29 : invaders ( -- seq )\r
30   {\r
31     { 0x0000 "invaders/invaders.h" }\r
32     { 0x0800 "invaders/invaders.g" }\r
33     { 0x1000 "invaders/invaders.f" }\r
34     { 0x1800 "invaders/invaders.e" }\r
35   } ;\r
36 \r
37 : test-cpu ( -- cpu )\r
38   <cpu> invaders over load-rom* dup cpu. ;\r
39 \r
40 : test-n ( n -- )\r
41   test-cpu swap [ test-step ] times drop ;\r
42 \r
43 : run-n ( cpu n -- cpu )\r
44   [ dup step ] times ;\r
45 \r
46 : each-8bit ( n quot -- )\r
47   [ 8 <bits> ] dip each ; inline\r
48 \r
49 : >ppm ( cpu filename -- cpu )\r
50   #! Dump the current screen image to a ppm image file with the given name.\r
51   ascii [\r
52     "P3" print\r
53     "256 224" print\r
54     "1" print\r
55     224 [\r
56       32 [\r
57         over 32 * over +  0x2400 + ! cpu h w addr\r
58         [ pick ] dip swap ram>> nth [\r
59           [\r
60             " 0 0 0" write\r
61           ] [\r
62             " 1 1 1" write\r
63           ] if\r
64         ] each-8bit drop\r
65       ] each drop nl\r
66     ] each\r
67   ] with-file-writer ;\r
68 \r
69 : time-test ( -- )\r
70   test-cpu [ 1000000 run-n drop ] time ;\r