@@ -0,0 +1,561 @@ |
|
|
1 |
{+-----------------------------------------------------------------------------+ |
|
|
2 |
| Description: Memory functions |
|
|
3 |
| last changes: 15.12.2000 |
|
|
4 |
| |
|
|
5 |
| http://www.tu-ilmenau.de/~hackbart |
|
|
6 |
+----------------------------------------------------------------------------+} |
|
|
7 |
|
|
|
8 |
unit machine; |
|
|
9 |
|
|
|
10 |
{$MODE Delphi} |
|
|
11 |
|
|
|
12 |
interface uses windows; |
|
|
13 |
|
|
|
14 |
const |
|
|
15 |
MaxCompanies=74; |
|
|
16 |
|
|
|
17 |
Companies:Array[0..maxCompanies] of record Code:Word;Name:String end= |
|
|
18 |
( |
|
|
19 |
( code:$3301;Name:'Nintendo' ),( code:$7901;Name:'Accolade' ),( code:$A400;Name:'Konami' ), |
|
|
20 |
( code:$6701;Name:'Ocean' ),( code:$5601;Name:'LJN' ),( code:$9900;Name:'ARC?' ), |
|
|
21 |
( code:$0101;Name:'Nintendo' ),( code:$0801;Name:'Capcom' ),( code:$0100;Name:'Nintendo' ), |
|
|
22 |
( code:$BB01;Name:'SunSoft' ),( code:$A401;Name:'Konami' ),( code:$AF01;Name:'Namcot?' ), |
|
|
23 |
( code:$4901;Name:'Irem' ),( code:$9C01;Name:'Imagineer' ),( code:$A600;Name:'Kawada?' ), |
|
|
24 |
( code:$B101;Name:'Nexoft' ),( code:$5101;Name:'Acclaim' ),( code:$6001;Name:'Titus' ), |
|
|
25 |
( code:$B601;Name:'HAL' ),( code:$3300;Name:'Nintendo' ),( code:$0B00;Name:'Coconuts?' ), |
|
|
26 |
( code:$5401;Name:'Gametek' ),( code:$7F01;Name:'Kemco?' ),( code:$C001;Name:'Taito' ), |
|
|
27 |
( code:$EB01;Name:'Atlus' ),( code:$E800;Name:'Asmik?' ),( code:$DA00;Name:'Tomy?' ), |
|
|
28 |
( code:$B100;Name:'ASCII?' ),( code:$EB00;Name:'Atlus' ),( code:$C000;Name:'Taito' ), |
|
|
29 |
( code:$9C00;Name:'Imagineer' ),( code:$C201;Name:'Kemco?' ),( code:$D101;Name:'Sofel?' ), |
|
|
30 |
( code:$6101;Name:'Virgin' ),( code:$BB00;Name:'SunSoft' ),( code:$CE01;Name:'FCI?' ), |
|
|
31 |
( code:$B400;Name:'Enix?' ),( code:$BD01;Name:'Imagesoft' ),( code:$0A01;Name:'Jaleco?' ), |
|
|
32 |
( code:$DF00;Name:'Altron?' ),( code:$A700;Name:'Takara?' ),( code:$EE00;Name:'IGS?' ), |
|
|
33 |
( code:$8300;Name:'Lozc?' ),( code:$5001;Name:'Absolute?' ),( code:$DD00;Name:'NCS?' ), |
|
|
34 |
( code:$E500;Name:'Epoch?' ),( code:$CB00;Name:'VAP?' ),( code:$8C00;Name:'Vic Tokai' ), |
|
|
35 |
( code:$C200;Name:'Kemco?' ),( code:$BF00;Name:'Sammy?' ), |
|
|
36 |
( code:$1800;Name:'Hudson Soft' ),( code:$CA01;Name:'Palcom/Ultra' ), |
|
|
37 |
( code:$CA00;Name:'Palcom/Ultra' ),( code:$C500;Name:'Data East?' ), |
|
|
38 |
( code:$A900;Name:'Technos Japan?' ),( code:$D900;Name:'Banpresto?' ), |
|
|
39 |
( code:$7201;Name:'Broderbund?' ),( code:$7A01;Name:'Triffix Entertainment?' ), |
|
|
40 |
( code:$E100;Name:'Towachiki?' ),( code:$9300;Name:'Tsuburava?' ), |
|
|
41 |
( code:$C600;Name:'Tonkin House?' ),( code:$CE00;Name:'Pony Canyon' ), |
|
|
42 |
( code:$7001;Name:'Infogrames?' ),( code:$8B01;Name:'Bullet-Proof Software?' ), |
|
|
43 |
( code:$5501;Name:'Park Place?' ),( code:$EA00;Name:'King Records?' ), |
|
|
44 |
( code:$5D01;Name:'Tradewest?' ),( code:$6F01;Name:'ElectroBrain?' ), |
|
|
45 |
( code:$AA01;Name:'Broderbund?' ),( code:$C301;Name:'SquareSoft' ), |
|
|
46 |
( code:$5201;Name:'Activision?' ),( code:$5A01;Name:'Bitmap Brothers/Mindscape' ), |
|
|
47 |
( code:$5301;Name:'American Sammy' ),( code:$4701;Name:'Spectrum Holobyte' ), |
|
|
48 |
( code:$1801;Name:'Hudson Soft')); |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
{+ Wichtig !! die beiden Speicherfunktionen müssen |
|
|
52 |
unbedingt CDECL deklariert sein !!! +} |
|
|
53 |
|
|
|
54 |
function speekb(address:Word):Byte;cdecl; |
|
|
55 |
procedure spokeb(address:WORD;data:byte);cdecl; |
|
|
56 |
|
|
|
57 |
function wordpeek(Addr:Word):Word; |
|
|
58 |
procedure wordpoke(addr:Word;val:Word); |
|
|
59 |
procedure push_pc; |
|
|
60 |
|
|
|
61 |
procedure set_bank(number:DWORD); |
|
|
62 |
procedure set_bank_mbc1_hi(data:DWORD); |
|
|
63 |
procedure set_bank_mbc1_lo(data:DWORD); |
|
|
64 |
procedure set_bank_mbc5_lo(data:DWORD); |
|
|
65 |
procedure set_bank_mbc5_hi(data:DWORD); |
|
|
66 |
procedure set_ff0f(number:Byte); |
|
|
67 |
function getcompany:String; |
|
|
68 |
implementation uses vars,sound; |
|
|
69 |
|
|
|
70 |
function getCompany:String; |
|
|
71 |
var j:word; |
|
|
72 |
i:integer; |
|
|
73 |
begin |
|
|
74 |
if cart=nil then exit; |
|
|
75 |
J:=byte(pchar(cart)[$014B]) shl 8+byte(pchar(cart)[$014A]); |
|
|
76 |
for I:=low(companies) to high(companies) do |
|
|
77 |
if Companies[I].Code=J then |
|
|
78 |
begin |
|
|
79 |
result:=Companies[I].Name;exit; |
|
|
80 |
end; |
|
|
81 |
result:=''; |
|
|
82 |
end; |
|
|
83 |
procedure set_bank(number:DWORD); |
|
|
84 |
begin |
|
|
85 |
if number=0 then number:=1; |
|
|
86 |
number:=number mod srom; |
|
|
87 |
if number=0 then number:=1; |
|
|
88 |
addr_bank:=number*$4000-$4000; |
|
|
89 |
end; |
|
|
90 |
|
|
|
91 |
procedure set_bank_mbc1_hi(data:DWord); |
|
|
92 |
begin |
|
|
93 |
data:=(data and 3) shl 5; |
|
|
94 |
rom_priv:=(rom_priv and 31) or Data; |
|
|
95 |
set_bank(rom_priv); |
|
|
96 |
end; |
|
|
97 |
|
|
|
98 |
procedure set_bank_mbc1_lo(data:Dword); |
|
|
99 |
begin |
|
|
100 |
rom_priv:=(rom_priv and 96) or data; |
|
|
101 |
set_bank(rom_priv); |
|
|
102 |
end; |
|
|
103 |
|
|
|
104 |
procedure set_bank_mbc5_lo(data:DWORD); |
|
|
105 |
begin |
|
|
106 |
rom_priv:=(rom_priv and 256) or data; |
|
|
107 |
set_bank(rom_priv); |
|
|
108 |
end; |
|
|
109 |
|
|
|
110 |
procedure set_bank_mbc5_hi(data:Dword); |
|
|
111 |
begin |
|
|
112 |
if(data and 1>0) then rom_priv:=rom_priv or 256 |
|
|
113 |
else |
|
|
114 |
rom_priv:=rom_priv and 255; |
|
|
115 |
set_bank(rom_priv); |
|
|
116 |
end; |
|
|
117 |
|
|
|
118 |
procedure set_ff0f(number:Byte); |
|
|
119 |
(* |
|
|
120 |
|
|
|
121 |
FF0F - IFLAGS [RW] Interrupt Flags |
|
|
122 |
|
|
|
123 |
----------------------------------------------+----------+---------- |
|
|
124 |
FFFF -- ISWITCH [RW] Interrupt Enable/Disable | set to 1 | set to 0 |
|
|
125 |
Bit4 Transition High->Low on pins P10-P13 | ENABLED | DISABLED |
|
|
126 |
Bit3 End of serial I/O transfer | ENABLED | DISABLED |
|
|
127 |
Bit2 Timer overflow | ENABLED | DISABLED |
|
|
128 |
Bit1 LCD controller interrupt [see LCDSTAT] | ENABLED | DISABLED |
|
|
129 |
Bit0 LCD vertical blanking impulse | ENABLED | DISABLED |
|
|
130 |
----------------------------------------------+----------+---------- |
|
|
131 |
|
|
|
132 |
*) |
|
|
133 |
begin |
|
|
134 |
if m_iram[$ffff] and number>0 then |
|
|
135 |
m_iram[$ff0f]:=m_iram[$ff0f] or number; |
|
|
136 |
end; |
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
function wordpeek(Addr:Word):Word; |
|
|
141 |
begin |
|
|
142 |
result:=((speekb((addr)+1) shl 8) or speekb(addr)); |
|
|
143 |
end; |
|
|
144 |
|
|
|
145 |
procedure wordpoke(addr:Word;val:Word); |
|
|
146 |
begin |
|
|
147 |
spokeb(addr, LO(val));spokeb(addr + 1, HI(val)); |
|
|
148 |
end; |
|
|
149 |
|
|
|
150 |
function speekb(address:Word):Byte; |
|
|
151 |
var cr,res:byte; |
|
|
152 |
begin |
|
|
153 |
if cart=NIL then begin result:=0;exit;end; |
|
|
154 |
if address<$8000 then |
|
|
155 |
begin |
|
|
156 |
if (memc=ROM) or (address<$4000) then |
|
|
157 |
res:=byte(pchar(cart)[address]) |
|
|
158 |
else |
|
|
159 |
res:=byte(pchar(cart)[address+addr_bank]); |
|
|
160 |
|
|
|
161 |
asm mov al,res;end;result:=res;exit; |
|
|
162 |
// Problem mit cdecl, keine Registerübergabe !! |
|
|
163 |
end; |
|
|
164 |
|
|
|
165 |
if (address>=$e000) and (address<$fe00) then dec(address,$2000); |
|
|
166 |
|
|
|
167 |
if gb_mode=CGB then |
|
|
168 |
begin |
|
|
169 |
if (m_iram[$ff4f] and 1>0) and (address>=$8000) and (address<$a000) then |
|
|
170 |
begin |
|
|
171 |
res:=m_iram2[address]; |
|
|
172 |
asm mov al,res;end; result:=res;exit; |
|
|
173 |
end; |
|
|
174 |
if (address>=$d000) and (address<=$dfff) then |
|
|
175 |
begin |
|
|
176 |
cr:=(m_iram[$ff70]) and 7; |
|
|
177 |
if cr=0 then cr:=1; |
|
|
178 |
res:=m_cgbram[4096*cr+address-$d000]; |
|
|
179 |
asm mov al,res; end; result:=res;exit; |
|
|
180 |
end; |
|
|
181 |
|
|
|
182 |
case address of |
|
|
183 |
$ff26: begin // sound |
|
|
184 |
m_iram[$ff26]:=(m_iram[$ff26] and $f0) or (byte(snd[4].Enable) shl 3) or |
|
|
185 |
(byte(snd[3].Enable) shl 2) or (byte(snd[2].Enable) shl 1) or byte(snd[1].Enable); |
|
|
186 |
res:=m_iram[$ff26]; |
|
|
187 |
asm mov al,res end; result:=res; |
|
|
188 |
end; |
|
|
189 |
$ff69: begin |
|
|
190 |
res:=palramb[(m_iram[$ff68]) and 63]; |
|
|
191 |
asm mov al,res; end; result:=res;exit; |
|
|
192 |
end; |
|
|
193 |
$ff6b: begin |
|
|
194 |
res:=palramo[(m_iram[$ff68]) and 63]; |
|
|
195 |
asm mov al,res; end; result:=res;exit; |
|
|
196 |
end; |
|
|
197 |
end; // case |
|
|
198 |
end; // end CGB |
|
|
199 |
|
|
|
200 |
|
|
|
201 |
if (sram>0) and ((address>=$a000) and (address<$c000)) then |
|
|
202 |
begin |
|
|
203 |
res:=m_ram[address-$a000+n_ram*$8912]; |
|
|
204 |
asm mov al,res; end; result:=res;exit; |
|
|
205 |
end; |
|
|
206 |
|
|
|
207 |
res:=m_iram[address]; |
|
|
208 |
asm mov al,res; end; result:=res; |
|
|
209 |
end; |
|
|
210 |
|
|
|
211 |
procedure spokeb(address:WORD;data:byte);cdecl; // neu |
|
|
212 |
var cr:byte; |
|
|
213 |
ji,pi:longint; |
|
|
214 |
sAddr,Offset:Word; |
|
|
215 |
templ,tempr:Byte; |
|
|
216 |
|
|
|
217 |
begin |
|
|
218 |
if cart=NIL then exit; |
|
|
219 |
if (address<$8000) then |
|
|
220 |
begin |
|
|
221 |
case memc of |
|
|
222 |
MBC3: begin |
|
|
223 |
if((address>=$2000) and (address<=$3fff)) then |
|
|
224 |
begin |
|
|
225 |
if(data=0) then data:=1; |
|
|
226 |
set_bank(data); |
|
|
227 |
exit; |
|
|
228 |
end else |
|
|
229 |
if ((address>=$4000) and (address<$6000)) then |
|
|
230 |
begin |
|
|
231 |
n_ram:=data and 3; |
|
|
232 |
exit; |
|
|
233 |
end; |
|
|
234 |
end; |
|
|
235 |
MBC1: begin |
|
|
236 |
if((address>=$6000) and (address<$8000)) then |
|
|
237 |
begin |
|
|
238 |
mbc1_type:=data and 1; |
|
|
239 |
exit; |
|
|
240 |
end |
|
|
241 |
else |
|
|
242 |
if((address>=$2000) and (address<$4000)) then |
|
|
243 |
begin |
|
|
244 |
data:=data and 31; |
|
|
245 |
set_bank_mbc1_lo(data); |
|
|
246 |
exit; |
|
|
247 |
end else |
|
|
248 |
if((address>=$4000) and (address<$6000)) then |
|
|
249 |
begin |
|
|
250 |
if mbc1_type>0 then |
|
|
251 |
begin |
|
|
252 |
n_ram:=data and 3; |
|
|
253 |
exit; |
|
|
254 |
end; |
|
|
255 |
end |
|
|
256 |
else |
|
|
257 |
begin |
|
|
258 |
set_bank_mbc1_hi(data); |
|
|
259 |
exit; |
|
|
260 |
end; |
|
|
261 |
end; |
|
|
262 |
MBC5: begin |
|
|
263 |
if((address>=$2000) and (address<=$2fff)) then |
|
|
264 |
begin |
|
|
265 |
set_bank_mbc5_lo(data); |
|
|
266 |
exit; |
|
|
267 |
end; |
|
|
268 |
if((address>=$3000) and (address<=$3fff)) then |
|
|
269 |
begin |
|
|
270 |
set_bank_mbc5_hi(data); |
|
|
271 |
exit; |
|
|
272 |
end; |
|
|
273 |
if((address>=$4000) and (address<=$5fff)) then |
|
|
274 |
begin |
|
|
275 |
n_ram:=data and 15; |
|
|
276 |
exit; |
|
|
277 |
end; |
|
|
278 |
end; |
|
|
279 |
MBC2: begin |
|
|
280 |
if((address>=$2000) and (address<$4000) and (address and 256>0)) then |
|
|
281 |
begin |
|
|
282 |
data:=data and 15; |
|
|
283 |
set_bank(data); |
|
|
284 |
exit; |
|
|
285 |
end; |
|
|
286 |
end; |
|
|
287 |
end; |
|
|
288 |
end; |
|
|
289 |
|
|
|
290 |
|
|
|
291 |
if gb_mode=CGB then |
|
|
292 |
begin |
|
|
293 |
if ((address>=$d000) and (address<=$dfff)) then |
|
|
294 |
begin |
|
|
295 |
cr:=(m_iram[$ff70]) and 7; |
|
|
296 |
if(cr=0) then cr:=1; |
|
|
297 |
m_cgbram[4096*cr+address-$d000]:=data; |
|
|
298 |
exit; |
|
|
299 |
end; |
|
|
300 |
|
|
|
301 |
if (address=$ff55) then |
|
|
302 |
begin |
|
|
303 |
if(data and 128=0) then |
|
|
304 |
begin |
|
|
305 |
if hdma>0 then hdma:=0 else |
|
|
306 |
begin |
|
|
307 |
adr_s:=((m_iram[$ff51]) shl 8) or (m_iram[$ff52] and 240); |
|
|
308 |
adr_p:=((((m_iram[$ff53]) and 31) shl 8) or (m_iram[$ff54] and 240)) or $8000; |
|
|
309 |
for ji:=0 to ((data and 127)*16+16)-1 do |
|
|
310 |
begin |
|
|
311 |
spokeb(adr_p,speekb(adr_s)); |
|
|
312 |
inc(adr_p);inc(adr_s); |
|
|
313 |
end; |
|
|
314 |
inc(cnumber,data*32+928 div gb_speed); |
|
|
315 |
data:=$ff; |
|
|
316 |
end |
|
|
317 |
end |
|
|
318 |
else |
|
|
319 |
begin |
|
|
320 |
data:=data and 127; |
|
|
321 |
if(m_iram[$ff40] and 128>0) then |
|
|
322 |
begin |
|
|
323 |
hdma:=1; |
|
|
324 |
hdma_count:=data+1; |
|
|
325 |
adr_s:=((m_iram[$ff51]) shl 8) or (m_iram[$ff52] and 240); |
|
|
326 |
adr_p:=((((m_iram[$ff53]) and 31) shl 8) or (m_iram[$ff54] and 240)) or $8000; |
|
|
327 |
end; |
|
|
328 |
end; |
|
|
329 |
end; |
|
|
330 |
|
|
|
331 |
|
|
|
332 |
if((address>=$8000) and (address<$a000) and ((m_iram[$ff4f] and 1>0))) then |
|
|
333 |
begin |
|
|
334 |
m_iram2[address]:=data; |
|
|
335 |
exit; |
|
|
336 |
end; |
|
|
337 |
|
|
|
338 |
case address of |
|
|
339 |
$ff69: begin |
|
|
340 |
palramb[(m_iram[$ff68]) and 63]:=data; |
|
|
341 |
if(m_iram[$ff68] and 1)>0 then |
|
|
342 |
begin |
|
|
343 |
tempL:=((m_iram[$ff68]) and 56) shr 3; |
|
|
344 |
tempR:=((m_iram[$ff68]) and 6) shr 1; |
|
|
345 |
pal_b[templ][tempr][0]:=(data and 124) shl 1; |
|
|
346 |
pal_b[templ][tempr][1]:=pal_b[templ][tempr][1] and 63; |
|
|
347 |
pal_b[templ][tempr][1]:=pal_b[templ][tempr][1] or (data shl 6); |
|
|
348 |
end |
|
|
349 |
else |
|
|
350 |
begin |
|
|
351 |
templ:=((m_iram[$ff68]) and 56) shr 3; |
|
|
352 |
tempr:=((m_iram[$ff68]) and 6) shr 1; |
|
|
353 |
|
|
|
354 |
pal_b[templ][tempr][2]:=(data and 31) shl 3; |
|
|
355 |
pal_b[templ][tempr][1]:=pal_b[templ][tempr][1] and 192; |
|
|
356 |
pal_b[templ][tempr][1]:=pal_b[templ][tempr][1] or ((data and 224) shr 2); |
|
|
357 |
end; |
|
|
358 |
|
|
|
359 |
pal_dx_b[((m_iram[$ff68]) and 56) shr 3][((m_iram[$ff68]) and 6) shr 1]:= |
|
|
360 |
(((pal_b[((m_iram[$ff68]) and 56) shr 3][((m_iram[$ff68]) and 6) shr 1][2]) shr (8-dx_r)) shl dx_sr) or (((pal_b[((m_iram[$ff68]) and 56) shr 3][((m_iram[$ff68]) and 6) shr 1][1]) shr (8-dx_g)) shl dx_sg) or (((pal_b[((m_iram[$ff68]) and 56) shr 3][((m_iram[$ff68]) and 6) shr 1][0]) shr (8-dx_b)) shl dx_sb); |
|
|
361 |
if(m_iram[$ff68] and 128)>0 then |
|
|
362 |
begin |
|
|
363 |
m_iram[$ff68]:=m_iram[$ff68] and $3f; |
|
|
364 |
inc(m_iram[$ff68]); |
|
|
365 |
m_iram[$ff68]:=m_iram[$ff68] or 128; |
|
|
366 |
end; |
|
|
367 |
end; |
|
|
368 |
$ff6b: begin |
|
|
369 |
palramo[(m_iram[$ff6a]) and 63]:=data; |
|
|
370 |
if(m_iram[$ff6a] and 1)>0 then |
|
|
371 |
begin |
|
|
372 |
templ:=((m_iram[$ff6a]) and 56) shr 3; |
|
|
373 |
tempr:=((m_iram[$ff6a]) and 6) shr 1; |
|
|
374 |
|
|
|
375 |
pal_o[templ][tempr][0]:=(data and 124) shl 1; |
|
|
376 |
pal_o[templ][tempr][1]:=pal_o[templ][tempr][1] and 63; |
|
|
377 |
pal_o[templ][tempr][1]:=pal_o[templ][tempr][1] or (data shl 6); |
|
|
378 |
end |
|
|
379 |
else |
|
|
380 |
begin |
|
|
381 |
templ:=((m_iram[$ff6a]) and 56) shr 3; |
|
|
382 |
tempr:=((m_iram[$ff6a]) and 6) shr 1; |
|
|
383 |
|
|
|
384 |
pal_o[templ][tempr][2]:=(data and 31) shl 3; |
|
|
385 |
pal_o[templ][tempr][1]:=pal_o[templ][tempr][1] and 192; |
|
|
386 |
pal_o[templ][tempr][1]:=pal_o[templ][tempr][1] or ((data and 224) shr 2); |
|
|
387 |
end; |
|
|
388 |
pal_dx_o[((m_iram[$ff6a]) and 56) shr 3][((m_iram[$ff6a]) and 6) shr 1]:=(((pal_o[((m_iram[$ff6a]) and 56) shr 3][((m_iram[$ff6a]) and 6) shr 1][2]) shr (8-dx_r)) shl dx_sr) or (((pal_o[((m_iram[$ff6a]) and 56) shr 3][((m_iram[$ff6a]) and 6) shr 1][1]) shr (8-dx_g)) shl dx_sg) or (((pal_o[((m_iram[$ff6a]) and 56) shr 3][((m_iram[$ff6a]) and 6) shr 1][0]) shr (8-dx_b)) shl dx_sb); |
|
|
389 |
if(m_iram[$ff6a] and 128)>0 then |
|
|
390 |
begin |
|
|
391 |
m_iram[$ff6a]:=m_iram[$ff6a] and $3f; |
|
|
392 |
inc(m_iram[$ff6a]); |
|
|
393 |
m_iram[$ff6a]:=m_iram[$ff6a] or 128; |
|
|
394 |
end; |
|
|
395 |
end; |
|
|
396 |
end; |
|
|
397 |
end; |
|
|
398 |
|
|
|
399 |
if ((address>=$e000) and (address<$fe00)) then dec(address,$2000); |
|
|
400 |
|
|
|
401 |
if (address>=$ff00) then |
|
|
402 |
begin |
|
|
403 |
case address of |
|
|
404 |
$ff00: begin |
|
|
405 |
if (data=3) then data:=$ff else |
|
|
406 |
if((data and $30)=$30) then data:=$ff |
|
|
407 |
else |
|
|
408 |
begin |
|
|
409 |
if((data and $30)=$20) then |
|
|
410 |
data:=$20 or (k_down shl 3) or (k_up shl 2) or (k_left shl 1) or k_right |
|
|
411 |
else |
|
|
412 |
if((data and $30)=$10) then |
|
|
413 |
data:=$10 or (k_start shl 3) or (k_select shl 2) or(k_b shl 1) or k_a; |
|
|
414 |
end; |
|
|
415 |
data:=data or $c0; |
|
|
416 |
end; |
|
|
417 |
$ff02: begin |
|
|
418 |
if((data and 128>0) and (data and 1>0)) then sio_count:=8; |
|
|
419 |
data:=data or 126; |
|
|
420 |
end; |
|
|
421 |
$ff04: begin |
|
|
422 |
data:=0; |
|
|
423 |
n_ff04:=0; |
|
|
424 |
end; |
|
|
425 |
$ff07: begin |
|
|
426 |
if(data and 4)>0 then |
|
|
427 |
begin |
|
|
428 |
c_count:=0; |
|
|
429 |
t_count:=m_iram[$ff06]; |
|
|
430 |
end; |
|
|
431 |
end; |
|
|
432 |
$ff40: begin |
|
|
433 |
if(data and 128=0) then vbioff_count:=1 else |
|
|
434 |
if(m_iram[$ff40] and 128)=0 then |
|
|
435 |
begin |
|
|
436 |
old_mode:=5; |
|
|
437 |
cycles:=1; |
|
|
438 |
cur_c:=2; |
|
|
439 |
nr_t:=0; |
|
|
440 |
end; |
|
|
441 |
end; |
|
|
442 |
$ff0f: begin |
|
|
443 |
if(data and 16)>0 then set_ff0f(16); |
|
|
444 |
if(data and 8)>0 then set_ff0f(8); |
|
|
445 |
if(data and 4)>0 then set_ff0f(4); |
|
|
446 |
if(data and 2)>0 then set_ff0f(2); |
|
|
447 |
if(data and 1)>0 then set_ff0f(1); |
|
|
448 |
end; |
|
|
449 |
$ff10..$ff3F: begin |
|
|
450 |
sndRegChange:=true; |
|
|
451 |
if address=$ff26 then |
|
|
452 |
begin |
|
|
453 |
m_iram[$ff26]:=data; |
|
|
454 |
if data and $80=0 then |
|
|
455 |
begin |
|
|
456 |
snd[1].Enable:=false; |
|
|
457 |
snd[2].Enable:=false; |
|
|
458 |
snd[3].Enable:=false; |
|
|
459 |
snd[4].Enable:=false; |
|
|
460 |
end; |
|
|
461 |
exit; |
|
|
462 |
end; |
|
|
463 |
m_iram[address]:=data; |
|
|
464 |
exit; |
|
|
465 |
end; |
|
|
466 |
|
|
|
467 |
$ff47: begin |
|
|
468 |
if(gb_mode<>CGB) then |
|
|
469 |
begin |
|
|
470 |
gb_mode:=CGB; |
|
|
471 |
spokeb($ff68,128); |
|
|
472 |
spokeb($ff69,(colors[data and 3]) and $ff); |
|
|
473 |
spokeb($ff69,(colors[data and 3]) shr 8); |
|
|
474 |
spokeb($ff69,(colors[(data and $c) shr 2]) and $ff); |
|
|
475 |
spokeb($ff69,(colors[(data and $c) shr 2]) shr 8); |
|
|
476 |
spokeb($ff69,(colors[(data and $30) shr 4]) and $ff); |
|
|
477 |
spokeb($ff69,(colors[(data and $30) shr 4]) shr 8); |
|
|
478 |
spokeb($ff69,(colors[(data and $c0) shr 6]) and $ff); |
|
|
479 |
spokeb($ff69,(colors[(data and $c0) shr 6]) shr 8); |
|
|
480 |
gb_mode:=DMG; |
|
|
481 |
end; |
|
|
482 |
end; |
|
|
483 |
$ff48: begin |
|
|
484 |
if(gb_mode<>CGB) then |
|
|
485 |
begin |
|
|
486 |
gb_mode:=CGB; |
|
|
487 |
spokeb($ff6a,128); |
|
|
488 |
spokeb($ff6b,(colors[data and 3]) and $ff); |
|
|
489 |
spokeb($ff6b,(colors[data and 3]) shr 8); |
|
|
490 |
spokeb($ff6b,(colors[(data and $c) shr 2]) and $ff); |
|
|
491 |
spokeb($ff6b,(colors[(data and $c) shr 2]) shr 8); |
|
|
492 |
spokeb($ff6b,(colors[(data and $30) shr 4]) and $ff); |
|
|
493 |
spokeb($ff6b,(colors[(data and $30) shr 4]) shr 8); |
|
|
494 |
spokeb($ff6b,(colors[(data and $c0) shr 6]) and $ff); |
|
|
495 |
spokeb($ff6b,(colors[(data and $c0) shr 6]) shr 8); |
|
|
496 |
gb_mode:=DMG; |
|
|
497 |
end; |
|
|
498 |
end; |
|
|
499 |
$ff49: begin |
|
|
500 |
if gb_mode<>CGB then |
|
|
501 |
begin |
|
|
502 |
gb_mode:=CGB; |
|
|
503 |
spokeb($ff6a,128+8); |
|
|
504 |
spokeb($ff6b,(colors[data and 3]) and $ff); |
|
|
505 |
spokeb($ff6b,(colors[data and 3]) shr 8); |
|
|
506 |
spokeb($ff6b,(colors[(data and $c) shr 2]) and $ff); |
|
|
507 |
spokeb($ff6b,(colors[(data and $c) shr 2]) shr 8); |
|
|
508 |
spokeb($ff6b,(colors[(data and $30) shr 4]) and $ff); |
|
|
509 |
spokeb($ff6b,(colors[(data and $30) shr 4]) shr 8); |
|
|
510 |
spokeb($ff6b,(colors[(data and $c0) shr 6]) and $ff); |
|
|
511 |
spokeb($ff6b,(colors[(data and $c0) shr 6]) shr 8); |
|
|
512 |
gb_mode:=DMG; |
|
|
513 |
end; |
|
|
514 |
end; |
|
|
515 |
$ff41: begin |
|
|
516 |
if((mode=0) or (mode=1)) then |
|
|
517 |
begin |
|
|
518 |
m_iram[$ff0f]:=m_iram[$ff0f] or 2; |
|
|
519 |
set_ff0f(2); |
|
|
520 |
end; |
|
|
521 |
end; |
|
|
522 |
$ff46: begin |
|
|
523 |
sAddr:=data shl 8; |
|
|
524 |
Offset:=$fe00; |
|
|
525 |
for pi:=0 to $9f do |
|
|
526 |
begin |
|
|
527 |
m_iram[Offset]:=speekb(sAddr); |
|
|
528 |
inc(Offset);inc(sAddr); |
|
|
529 |
end; |
|
|
530 |
end; |
|
|
531 |
|
|
|
532 |
end; |
|
|
533 |
end; |
|
|
534 |
|
|
|
535 |
if(sram>0) and (address>=$a000) and (address<$c000) then |
|
|
536 |
m_ram[address-$a000+n_ram*$8912]:=data |
|
|
537 |
else |
|
|
538 |
m_iram[address]:=data; |
|
|
539 |
end; |
|
|
540 |
|
|
|
541 |
|
|
|
542 |
procedure push_pc;assembler; |
|
|
543 |
asm |
|
|
544 |
mov ax,pc.w |
|
|
545 |
dec sp_.w |
|
|
546 |
xchg ah,al |
|
|
547 |
push eax |
|
|
548 |
push dword ptr sp_.w |
|
|
549 |
call spokeb |
|
|
550 |
lea esp,[esp+8] |
|
|
551 |
mov ax,pc.w |
|
|
552 |
push eax |
|
|
553 |
dec sp_.w |
|
|
554 |
push dword ptr sp_.w |
|
|
555 |
call spokeb |
|
|
556 |
lea esp,[esp+8] |
|
|
557 |
end; |
|
|
558 |
(* dec(sp_.W,2);wordpoke(sp_.W,pc.w);*) |
|
|
559 |
|
|
|
560 |
|
|
|
561 |
end. |