-
Notifications
You must be signed in to change notification settings - Fork 8
/
MuROM.asm
198 lines (161 loc) · 3.8 KB
/
MuROM.asm
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
; MuhonMourn Cart
RDSLT : equ 000ch
CHGMOD : equ 005fh
LDIRVM : equ 005ch
DISSCR : equ 0041h
RSLREG : equ 0138h
PATCHLEN: equ 01f0h
PATCHBEGIN: equ 0e000h
FORCLR: equ 0f3e9h
BAKCLR: equ 0f3e9h
BDRCLR: equ 0f3ebh
BOTTOM: equ 0fc48h
EXPTBL: equ 0fcc1h
; variables
presentSlot: equ PATCHBEGIN + PATCHLEN ; last address of patch
org 04000h
db 'AB' ; header ID
dw Initialize ; ditto
dw 0 ; CALL expansion
dw 0 ; device expansion
dw 0 ; No Basic program
ds 6,0 ; reserved
Initialize:
in a,(0a8h)
ld (presentSlot),a ; save present slot configuration
; at the moment, page 0 -> BIOS
; page 1 -> ROM
; page 2 -> RAM
; page 3 -> RAM
; Screen3:color 15,1,1
ld a,15 ; color 15,1,1
ld (FORCLR),a
ld a,1
ld (BAKCLR),a
ld (BDRCLR),a
ld a,3
call CHGMOD
; prepare for transfer
ld bc,1536 ; Length
ld de,0 ; VRAM address
ld a,(BOTTOM+1)
cp 80h ; machines with 32k or more always have 80h here
jr z, SPLASH_SCREEN
jr c, SPLASH_SCREEN
DO_NORAM_SCREEN
ld hl,NORAM
call LDIRVM
FREEZE: jr FREEZE
SPLASH_SCREEN:
ld a,(presentSlot)
ld hl,QUEEN3
bit 2,a ; test for cart inserted on odd/even slot
DO_QUEEN: ; even
jr z, DO_SPLASH
DO_INFOSOC: ; odd
ld hl,INFOSOC
DO_SPLASH:
call LDIRVM
ld b,3
SPL_DLY:
call delay1s
djnz SPL_DLY
; copy the upper part of the game c000..d3ff, e000..e1f0
; copy the Ninja Tap code
ld hl,06a00h
ld de,0e000h
ld bc,PATCHLEN ;
ldir
ld hl,06c00h
ld de,0c000h
ld bc,01400h
ldir
; read from game slot and write on RAM
; suggested by user abekermsx from github
get_page1_slot:
call RSLREG ; Read the primary slots register
rrca
rrca
and 3
ld c,a
ld b,0
ld hl,EXPTBL ; HL = Address of the secondary slot flags table
add hl,bc
ld a,(hl)
and $80 ; Keep the bit 7 (secondary slot flag)
or c
ld c,a
inc hl
inc hl
inc hl
inc hl ; HL = Address of the secondary slot register in the secondary slot register table
ld a,(hl)
and $0c
or c
ld ( presentSlot ),a
; prepare to tranfer data
ld hl,8000h
ld de,8000h
ld bc,4000h
slotldir:
push bc
push de
ld a,(presentSlot)
call RDSLT
pop de
pop bc
ld (de),a
inc de
inc hl
dec bc
ld a,b
or c
jr nz, slotldir
; load switching slot routine in page 3
ld hl,SWSLOT
ld de,0e1f0h
ld bc,ENDSWSLOT-SWSLOT
ldir
jp 0e1f0h
SWSLOT:
in a,(0a8h) ; bits 2,3 are the slot where this rom is running
; bits 0,1 are the slot where BIOS is running
ld e,a ; save slot configuration
and 11110011b ; 0f3h mask bits for page 1
ld d,a ; then save it
ld a,e ; get back the paging register
rlca ; shift bits from page 0 to page 2 position
rlca
and 0ch ; isolate bits from page 0
or d ; add them to the slot register
out (0a8h),a ; select correct pages
; disable the screen
call DISSCR
; now jump to the game
ld hl, 0915fh
ex (sp),hl
;ei
ret
; ei
; jp 0915fh
ENDSWSLOT:
delay1s:
ld hl,1000 ;
dl0: ;
ld c,154 ; 8 | = 8 + (5+5+13) * (C-1) + (5+5+8) * C
dl1: ; | = 8 + (5+5+13) * C - (13-8)
nop ; 5 | = (8-5) + (5+5+13) * C
dec c ; 5 | = 3 + 23 * C
jr nz,dl1 ; 13/8 | for C = 154, dl1= 3 + 23 * 154 = 3.545 cycles
dec hl ; 7 | = ( 3545 + 7 + 5 + 5 + 5 + 13 ) * HL - (13-8)
ld a,h ; 5 | = 3580 * HL - 5
nop ; 5 | for HL = 1000, dl0 = 3580 * 1000 - 5 = 3.579.995 cycles
or l ; 5 | or 1 second on a standard MSX machine
jr nz,dl0 ; 13/8 |
ret ; |
include splashNoram.inc
include splashInfoSoc.inc
include splashQueen3.inc
FREE_AREA:
org 069ffh ; org 0bfffh
nop