]> gitweb.factorcode.org Git - factor.git/blob - extra/cpu/8080/test/test.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / extra / cpu / 8080 / test / test.factor
1 USING: kernel cpu.8080 cpu.8080.emulator math math io\r
2 tools.time combinators sequences io.files ;\r
3 IN: cpu.8080.test\r
4 \r
5 : step ( cpu -- )\r
6   #! Run a single 8080 instruction\r
7   [ read-instruction ] keep ! n cpu\r
8   over get-cycles over inc-cycles\r
9   [ swap instructions case ] keep\r
10   [ cpu-pc HEX: FFFF bitand ] keep \r
11   [ set-cpu-pc ] keep \r
12   process-interrupts ;\r
13 \r
14 \r
15 : test-step ( cpu -- cpu )\r
16   [ step ] keep dup cpu. ;\r
17 \r
18 : test-cpu ( -- cpu )\r
19   <cpu> "invaders.rom" over load-rom dup cpu. ;\r
20 \r
21 : test-n ( n -- )\r
22   test-cpu swap [ test-step ] times drop ;\r
23 \r
24 : run-n ( cpu n -- cpu )\r
25   [ dup step ] times ;\r
26 \r
27 : each-8bit ( n quot -- )\r
28   8 -rot [ >r bit? r> call ] 2curry each ; inline\r
29 \r
30 : >ppm ( cpu filename -- cpu )\r
31   #! Dump the current screen image to a ppm image file with the given name.\r
32   <file-writer> [\r
33     "P3" print\r
34     "256 224" print\r
35     "1" print\r
36     224 [\r
37       32 [\r
38         over 32 * over +  HEX: 2400 + ! cpu h w addr\r
39         >r pick r> swap cpu-ram nth [\r
40           0 = [\r
41             " 0 0 0" write\r
42           ] [\r
43             " 1 1 1" write\r
44           ] if\r
45         ] each-8bit drop\r
46       ] each drop nl\r
47     ] each\r
48   ] with-stream ;\r
49 \r
50 : time-test ( -- )\r
51   test-cpu [ 1000000 run-n drop ] time ;\r