File tree Expand file tree Collapse file tree 7 files changed +64
-5
lines changed Expand file tree Collapse file tree 7 files changed +64
-5
lines changed Original file line number Diff line number Diff line change @@ -280,14 +280,12 @@ void cpu_reset(bool hard)
280
280
IME = 0 ;
281
281
IMA = 0 ;
282
282
283
- PC = 0x0100 ;
283
+ PC = hw . bios ? 0x0000 : 0x0100 ;
284
284
SP = 0xFFFE ;
285
- AF = 0x01B0 ;
285
+ AF = hw . cgb ? 0x11B0 : 0x01B0 ;
286
286
BC = 0x0013 ;
287
287
DE = 0x00D8 ;
288
288
HL = 0x014D ;
289
-
290
- if (hw .cgb ) A = 0x11 ;
291
289
}
292
290
293
291
/* cnt - time to emulate, expressed in real clock cycles */
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ typedef struct
28
28
un32 cgb ;
29
29
n32 hdma ;
30
30
n32 serial ;
31
+ un8 * bios ;
31
32
} hw_t ;
32
33
33
34
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ int rom_loadbank(int bank)
170
170
171
171
int rom_load (const char * file )
172
172
{
173
- MESSAGE_INFO ("Loading file: '%s'\n" , file );
173
+ MESSAGE_INFO ("Loading file: '%s'\n" , file );
174
174
175
175
fpRomFile = fopen (file , "rb" );
176
176
if (fpRomFile == NULL )
@@ -565,6 +565,9 @@ int state_load(const char *file)
565
565
fclose (fp );
566
566
free (buf );
567
567
568
+ // Disable BIOS. This is a hack to support old saves
569
+ R_BIOS = 0x1 ;
570
+
568
571
pal_dirty ();
569
572
sound_dirty ();
570
573
mem_updatemap ();
@@ -577,3 +580,29 @@ int state_load(const char *file)
577
580
578
581
return -1 ;
579
582
}
583
+
584
+
585
+ int bios_load (const char * file )
586
+ {
587
+ MESSAGE_INFO ("Loading BIOS file: '%s'\n" , file );
588
+
589
+ FILE * fpBiosFile = fopen (file , "rb" );
590
+ if (fpBiosFile == NULL )
591
+ {
592
+ MESSAGE_ERROR ("BIOS fopen failed" );
593
+ return -1 ;
594
+ }
595
+
596
+ hw .bios = malloc (0x900 );
597
+ if (!hw .bios )
598
+ emu_die ("Out of memory" );
599
+
600
+ if (fread (hw .bios , 1 , 0x900 , fpBiosFile ) >= 0x100 )
601
+ {
602
+ MESSAGE_INFO ("BIOS loaded\n" );
603
+ }
604
+
605
+ fclose (fpBiosFile );
606
+
607
+ return 0 ;
608
+ }
Original file line number Diff line number Diff line change 4
4
int rom_loadbank (int );
5
5
int rom_load (const char * file );
6
6
void rom_unload (void );
7
+ int bios_load (const char * file );
8
+ void bios_unload (void );
7
9
8
10
int sram_load (const char * file );
9
11
int sram_save (const char * file );
Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ void IRAM_ATTR mem_updatemap()
44
44
mbc .rmap [0x2 ] = rom .bank [0 ];
45
45
mbc .rmap [0x3 ] = rom .bank [0 ];
46
46
47
+ // Force bios to go through mem_read (speed doesn't really matter here)
48
+ if (hw .bios && (R_BIOS & 1 ) == 0 )
49
+ {
50
+ mbc .rmap [0x0 ] = NULL ;
51
+ }
52
+
47
53
if (mbc .rombank < mbc .romsize )
48
54
{
49
55
mbc .rmap [0x4 ] = rom .bank [mbc .rombank ] - 0x4000 ;
@@ -198,6 +204,10 @@ static inline void ioreg_write(byte r, byte b)
198
204
case RI_KEY1 :
199
205
REG (r ) = (REG (r ) & 0x80 ) | (b & 0x01 );
200
206
break ;
207
+ case RI_BIOS :
208
+ REG (r ) = b ;
209
+ mem_updatemap ();
210
+ break ;
201
211
case RI_HDMA1 :
202
212
case RI_HDMA2 :
203
213
case RI_HDMA3 :
@@ -250,6 +260,7 @@ static inline byte ioreg_read(byte r)
250
260
case RI_OCPD :
251
261
case RI_SVBK :
252
262
case RI_KEY1 :
263
+ case RI_BIOS :
253
264
case RI_HDMA1 :
254
265
case RI_HDMA2 :
255
266
case RI_HDMA3 :
@@ -514,6 +525,14 @@ byte IRAM_ATTR mem_read(addr_t a)
514
525
switch (ha )
515
526
{
516
527
case 0x0 :
528
+ if (a < 0x900 && (R_BIOS & 1 ) == 0 )
529
+ {
530
+ if (a < 0x100 )
531
+ return hw .bios [a ];
532
+ if (hw .cgb && a >= 0x200 )
533
+ return hw .bios [a ];
534
+ }
535
+ // fall through
517
536
case 0x2 :
518
537
return rom .bank [0 ][a & 0x3fff ];
519
538
Original file line number Diff line number Diff line change 45
45
46
46
#define RI_VBK 0x4F
47
47
48
+ #define RI_BIOS 0x50
49
+
48
50
#define RI_HDMA1 0x51
49
51
#define RI_HDMA2 0x52
50
52
#define RI_HDMA3 0x53
128
130
#define R_WY REG(RI_WY)
129
131
#define R_WX REG(RI_WX)
130
132
133
+ #define R_BIOS REG(RI_BIOS)
134
+
131
135
#define R_VBK REG(RI_VBK)
132
136
133
137
#define R_HDMA1 REG(RI_HDMA1)
Original file line number Diff line number Diff line change @@ -254,6 +254,12 @@ void app_main(void)
254
254
// Load ROM
255
255
rom_load (app -> romPath );
256
256
257
+ // Load BIOS
258
+ if (hw .cgb )
259
+ bios_load (RG_BASE_PATH "/bios/gbc_bios.bin" );
260
+ else
261
+ bios_load (RG_BASE_PATH "/bios/gb_bios.bin" );
262
+
257
263
// Set palette for non-gbc games (must be after rom_load)
258
264
pal_set_dmg (rg_settings_get_app_int32 (SETTING_PALETTE , 0 ));
259
265
You can’t perform that action at this time.
0 commit comments