5d1eeff978be2f1124976e2cce2e3ed94b74f6f8
[ScratchNES.git] / src / CPU / common.tosh
1 define ; [comment]
2
3 define mapper read (addr)
4 if addr < 8192 then
5 set M to item (addr mod 2048 + 1) of RAM
6 else
7 if addr > 32767 then
8 set M to (join "0x" (item ((addr - 32768) mod 16384 + 1) of PRG-ROM))
9 end
10 end
11
12 define mapper write (addr) (value)
13 if addr < 8192 then
14 replace item addr mod 2048 + 1 of RAM with value
15 else
16 if addr > 8191 and addr < 8200 then
17 ask join join (value) " to PPU " (addr) and wait
18 else
19 if addr > 32768 then
20 say "Writing to ROM isn't very nice, you know..."
21 end
22 end
23 end
24
25 define PLP
26 set flagN to < (item (join (letter 1 of M) "8")+1 of AND) = 8>
27 set flagV to < (item (join (letter 1 of M) "4")+1 of AND) = 4>
28 set flagB to < (item (join (letter 1 of M) "1")+1 of AND) = 1>
29 set flagD to < (item (join (letter 2 of M) "8")+1 of AND) = 8>
30 set flagI to < (item (join (letter 2 of M) "4")+1 of AND) = 4>
31 set flagZ to < (item (join (letter 2 of M) "2")+1 of AND) = 2>
32 set flagC to < (item (join (letter 2 of M) "1")+1 of AND) = 1>
33
34 define interrupt
35
36 define compute SR
37 set SR to (128*flagN) + (64*flagV) + (32) + (16*flagB) + (8*flagD) + (4*flagI) + (2*flagZ) + (1*flagC)
38
39 when flag clicked
40 set A to 0
41 set X to 0
42 set Y to 0
43 set S to "0xFD"
44 set PC to 49152
45 show variable A
46 show variable X
47 show variable Y
48 show variable PC
49 show variable M
50 show variable flagC
51 show variable flagV
52 show variable flagN
53 show variable flagZ
54 show variable flagI
55 show variable flagB
56 show variable flagD
57 show variable S
58 set line to 0
59 show variable line
60 delete all of RAM
61 repeat 2048
62 add "0" to RAM
63 end
64
65 when p key pressed
66 mapper read (PC)
67 interpret instruction (M)
68 change line by 1
69
70 define interpret instruction (opcode)
This page took 0.059072 seconds and 3 git commands to generate.