add rom boot read
This commit is contained in:
+4
-1
@@ -2,4 +2,7 @@ build
|
|||||||
uf2
|
uf2
|
||||||
.pio
|
.pio
|
||||||
.vscode
|
.vscode
|
||||||
*_bin.h
|
*_bin.h
|
||||||
|
*.bin
|
||||||
|
*.gb
|
||||||
|
*.gbc
|
||||||
|
|||||||
+25
-4
@@ -63,8 +63,29 @@ static void gb_error(struct gb_s* gb, const enum gb_error_e gb_err, const uint16
|
|||||||
error(String("Error ") + gb_err + " occurred: " + gb_err_str[gb_err] + " at 0x" + String(addr, 16));
|
error(String("Error ") + gb_err + " occurred: " + gb_err_str[gb_err] + " at 0x" + String(addr, 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_init_error_e initGbContext() {
|
#ifdef USE_BOOT_ROM
|
||||||
memcpy(rom_bank0, rom, sizeof(rom_bank0));
|
#include "boot_cgb_bin.h"
|
||||||
return gb_init(&gb, &gb_rom_read, &gb_cart_ram_read,
|
#include "boot_gb_bin.h"
|
||||||
&gb_cart_ram_write, &gb_error, NULL);
|
static uint8_t gb_bootrom_read(struct gb_s* gb, const uint_fast16_t addr) {
|
||||||
|
if (gb->cgb.cgbMode) {
|
||||||
|
return CGB_BOOT_ROM[addr];
|
||||||
|
} else {
|
||||||
|
return GB_BOOT_ROM[addr];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void initGbContext() {
|
||||||
|
memcpy(rom_bank0, rom, sizeof(rom_bank0));
|
||||||
|
|
||||||
|
auto ret = gb_init(&gb, &gb_rom_read, &gb_cart_ram_read, &gb_cart_ram_write, &gb_error, NULL);
|
||||||
|
if (ret != GB_INIT_NO_ERROR) {
|
||||||
|
error(String("Error initializing emulator: ") + ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USE_BOOT_ROM
|
||||||
|
// gb_bootrom_read has to be set after gb_init(), as it sets it to NULL
|
||||||
|
gb_set_bootrom(&gb, &gb_bootrom_read);
|
||||||
|
gb_reset(&gb);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ extern const uint8_t* rom;
|
|||||||
#define RAM_SIZE 32768
|
#define RAM_SIZE 32768
|
||||||
extern uint8_t ram[RAM_SIZE];
|
extern uint8_t ram[RAM_SIZE];
|
||||||
|
|
||||||
gb_init_error_e initGbContext();
|
void initGbContext();
|
||||||
|
|||||||
+1
-5
@@ -64,11 +64,7 @@ void startEmulator() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Serial.println("Init GB context ...");
|
Serial.println("Init GB context ...");
|
||||||
auto ret = initGbContext();
|
initGbContext();
|
||||||
if (ret != GB_INIT_NO_ERROR) {
|
|
||||||
Serial.printf("Error: %d\n", ret);
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Automatically assign a colour palette to the game */
|
/* Automatically assign a colour palette to the game */
|
||||||
char rom_title[16];
|
char rom_title[16];
|
||||||
|
|||||||
Reference in New Issue
Block a user