Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit 73aa226

Browse files
author
moatom
committed
Fix a bug in the making bitmap pic and find ! in $0x21C9.
1 parent e26ec17 commit 73aa226

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

cpu.sml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ struct
473473
val (insn, nextPc, baseCycle) = fetchAndDecode (#PC regs)
474474
val (newRegs, additionalCycle) = exec (regs # {PC = nextPc}, insn)
475475
in
476-
(prtRegs (regs, cycle); (newRegs, cycle + baseCycle + additionalCycle))
476+
(* (prtRegs (regs, cycle); *)
477+
(newRegs, cycle + baseCycle + additionalCycle)
478+
(* ) *)
477479
end
478480
end

main.sml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,26 @@ val StatusRegister = {N=false, V=false, B5=true, B4=false, D=false, I=true, Z=f
22
type cpuData = {regs : CPU.registers, cycle : int}
33
val CYCLES_PER_FRAME = 263 * 341 div 3 - 1
44

5-
fun printScreen pic = ()
5+
fun printScreen fb =
6+
let
7+
val a = Array.length fb
8+
fun loop 0 = print "---The end of a frame---\n"
9+
| loop n =
10+
(if 0wx80 < Array.sub (fb, a-n) then print "." else print " ";
11+
if (a-n) mod 256 = 255 then (print "|\n"; loop (n-1)) else loop (n-1))
12+
in
13+
loop a
14+
end
15+
616
fun frame cData =
717
let
818
val (newCpuRegs, newCpuCycle) = CPU.cpu (#regs cData, #cycle cData)
919
in
1020
if newCpuCycle > CYCLES_PER_FRAME
1121
then (printScreen (PPU.ppu ());
22+
print (Word8.toString (PPU.read 0wx21C8) ^ "\n");
23+
print (Word8.toString (PPU.read 0wx21C9) ^ "\n");
24+
print (Word8.toString (PPU.read 0wx21D0) ^ "\n");
1225
frame (cData # {regs = newCpuRegs, cycle = 0}))
1326
else frame (cData # {regs = newCpuRegs, cycle = newCpuCycle})
1427
end

ppu.sml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,21 @@ struct
4949
then c * Common.pow (10, d)
5050
else 0
5151
in
52-
getBoolDigi (a, 0wx1, n, 8)
53-
+ getBoolDigi (a, 0wx2, n, 7)
54-
+ getBoolDigi (a, 0wx4, n, 6)
55-
+ getBoolDigi (a, 0wx8, n, 5)
52+
getBoolDigi (a, 0wx1, n, 0)
53+
+ getBoolDigi (a, 0wx2, n, 1)
54+
+ getBoolDigi (a, 0wx4, n, 2)
55+
+ getBoolDigi (a, 0wx8, n, 3)
5656
+ getBoolDigi (a, 0wx10, n, 4)
57-
+ getBoolDigi (a, 0wx20, n, 3)
58-
+ getBoolDigi (a, 0wx40, n, 2)
59-
+ getBoolDigi (a, 0wx80, n, 1)
57+
+ getBoolDigi (a, 0wx20, n, 5)
58+
+ getBoolDigi (a, 0wx40, n, 6)
59+
+ getBoolDigi (a, 0wx80, n, 7)
6060
end
6161
in
62+
(* タイルの1ラインずつを合成して格納 *)
6263
(Array.update (array, n, dodo (low, 1) + dodo (high, 2));
64+
(* print ("a" ^ Word8.toString low ^ "\n");
65+
print ("b" ^ Word8.toString high ^ "\n");
66+
print (Int.toString (dodo (low, 1) + dodo (high, 2)) ^"\n"); *)
6367
synthTile i (j+1) array (n+1))
6468
end
6569

@@ -93,7 +97,7 @@ struct
9397
val pnt = traceAt 0 0 (Array.array (16*15, 0w0:word8))(* Palettes Number resolution Table for blocks *)
9498

9599
fun toGlay c =
96-
(Word.>> (c, 0w4) + (Word.>> (c, 0w2) mod 0wx100) + (c mod 0wx100)) div 0w3
100+
(Word.>> (c, 0w32) + (Word.>> (c, 0w16) mod 0wx100) + (c mod 0wx100)) div 0w3
97101
fun getColor (pn, 0) = toGlay (Vector.sub (colors, Word8.toInt (read (0wx3F00))))
98102
| getColor (pn, cn) = toGlay (Vector.sub (colors, Word8.toInt (read (0wx3F01 + w8ToW16 ((0w4*pn - 0w1 + Word8.fromInt cn))))))
99103
fun render 7680 t b = frameBuf
@@ -121,6 +125,7 @@ struct
121125
Array.update (frameBuf, pos + 5, getColor (pN, c5));
122126
Array.update (frameBuf, pos + 6, getColor (pN, c6));
123127
Array.update (frameBuf, pos + 7, getColor (pN, c7));
128+
(* print (Word.toString (getColor (pN, c0)) ^ "\n"); *)
124129
render (l+1) (if l mod 8 = 7 then t+1 else t) (case b of
125130
119 => 0
126131
| _ => if t mod 2 = 1 then b+1 else b)

0 commit comments

Comments
 (0)