1 USING: kernel cpu.8080 cpu.8080.emulator math math io
\r
2 tools.time combinators sequences io.files io.encodings.ascii ;
\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
15 : test-step ( cpu -- cpu )
\r
16 [ step ] keep dup cpu. ;
\r
18 : test-cpu ( -- cpu )
\r
19 <cpu> "invaders.rom" over load-rom dup cpu. ;
\r
22 test-cpu swap [ test-step ] times drop ;
\r
24 : run-n ( cpu n -- cpu )
\r
25 [ dup step ] times ;
\r
27 : each-8bit ( n quot -- )
\r
28 8 -rot [ >r bit? r> call ] 2curry each ; inline
\r
30 : >ppm ( cpu filename -- cpu )
\r
31 #! Dump the current screen image to a ppm image file with the given name.
\r
38 over 32 * over + HEX: 2400 + ! cpu h w addr
\r
39 >r pick r> swap cpu-ram nth [
\r
48 ] with-file-writer ;
\r
51 test-cpu [ 1000000 run-n drop ] time ;
\r