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