-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapper.sml
61 lines (60 loc) · 2.03 KB
/
mapper.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
structure Mapper =
struct
fun init name =
let
val file = BinIO.openIn ("./rom/" ^ name)
val cartridge : word8 vector = BinIO.inputAll file
val _ = BinIO.closeIn file
val promUnits = Vector.sub (cartridge, 4)
val cromStart = 16 + 16384 * Word8.toInt promUnits
fun processCrom 8192 = ()
| processCrom n =
(
Array.update (PPU.chrRom, n, Vector.sub (cartridge, n + cromStart));
processCrom (n+1)
)
fun mapper0 _ =
let
fun nrom128 n =
let
fun processProm 16384 = ()
| processProm n =
let
val subed = Vector.sub (cartridge, n+16)
val target = n + Word.toInt (0wx8000-0wx4020)
in
(
Array.update (CPU.prgRom, target, subed);
Array.update (CPU.prgRom, target + 16384, subed);
processProm (n+1)
)
end
in
(processProm n; processCrom n)
end
fun nrom256 n =
let
fun processProm 32768 = ()
| processProm n =
let
val subed = Vector.sub (cartridge, n+16)
val target = n + Word.toInt (0wx8000-0wx4020)
in
(
Array.update (CPU.prgRom, target, subed);
processProm (n+1)
)
end
in
(processProm n; processCrom n)
end
in
case promUnits of
0w1 => nrom128 0
| 0w2 => nrom256 0
| _ => ()
end
in
mapper0 ()
end
end