gbdb: remove some conditionals from mem_read()
By reading directly from a "RAM" array, and copying in the cart data over the old bootrom. Also, some other fixups because I'm too lazy to properly split patches for a personal project.
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
load ../harvest_moon.gb
|
||||||
bootrom ../bootrom.gb
|
bootrom ../bootrom.gb
|
||||||
echo Running test...
|
echo Running test...
|
||||||
set quiet 1
|
set quiet 1
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include "common/tri.h"
|
#include "common/tri.h"
|
||||||
|
|
||||||
#define INPUT_MAX_LEN 512
|
#define INPUT_MAX_LEN 512
|
||||||
#define MAX_BREAKPTS 2 /* Should be plenty for anyone */
|
#define MAX_BREAKPTS 16 /* Should be plenty for anyone */
|
||||||
#define MAX_RAM_LEN (1 << 20) /* Up to 8Mb Cartridge */
|
#define MAX_RAM_LEN (1 << 20) /* Up to 8Mb Cartridge */
|
||||||
#define UNMAP_BOOTROM_ADDR 0xff50
|
#define UNMAP_BOOTROM_ADDR 0xff50
|
||||||
|
|
||||||
@@ -46,6 +46,7 @@ static struct lr35902_state cpu;
|
|||||||
static struct gb_video video;
|
static struct gb_video video;
|
||||||
|
|
||||||
static unsigned char bootrom[0x100] = {0};
|
static unsigned char bootrom[0x100] = {0};
|
||||||
|
static unsigned char cart_low[0x100] = {0};
|
||||||
|
|
||||||
static int bootrom_mapped = 1;
|
static int bootrom_mapped = 1;
|
||||||
|
|
||||||
@@ -97,12 +98,6 @@ static uint8_t mem_read(struct lr35902_state *cpu, uint16_t addr)
|
|||||||
{
|
{
|
||||||
|
|
||||||
switch (addr) {
|
switch (addr) {
|
||||||
case 0 ... 0x100-1:
|
|
||||||
if (bootrom_mapped) {
|
|
||||||
return bootrom[addr];
|
|
||||||
} else {
|
|
||||||
return ram[addr];
|
|
||||||
}
|
|
||||||
case 0xFF40 ... 0xFF4B:
|
case 0xFF40 ... 0xFF4B:
|
||||||
return gb_video_mem_read(&video, addr);
|
return gb_video_mem_read(&video, addr);
|
||||||
default:
|
default:
|
||||||
@@ -117,6 +112,7 @@ static void mem_write(struct lr35902_state *cpu, uint16_t addr, uint8_t val)
|
|||||||
case UNMAP_BOOTROM_ADDR:
|
case UNMAP_BOOTROM_ADDR:
|
||||||
if (val == 1) {
|
if (val == 1) {
|
||||||
bootrom_mapped = 0;
|
bootrom_mapped = 0;
|
||||||
|
memcpy(ram, cart_low, sizeof(cart_low));
|
||||||
gb_log("bootrom unmapped\n");
|
gb_log("bootrom unmapped\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -375,7 +371,7 @@ static void assert(char *arg_list)
|
|||||||
return;
|
return;
|
||||||
fail:
|
fail:
|
||||||
printf("ASSERT: %s %s %s\n", val0_str, operator_str, val1_str);
|
printf("ASSERT: %s %s %s\n", val0_str, operator_str, val1_str);
|
||||||
printf("%s=%ld, %s=%ld\n", val0_str, val0, val1_str, val1);
|
printf("%s=%lld, %s=%lld\n", val0_str, val0, val1_str, val1);
|
||||||
regs(NULL);
|
regs(NULL);
|
||||||
stats(NULL);
|
stats(NULL);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -449,6 +445,8 @@ static void load(char *arg_list)
|
|||||||
|
|
||||||
strip_newline(token);
|
strip_newline(token);
|
||||||
load_file_to_buffer(token, ram, sizeof(ram));
|
load_file_to_buffer(token, ram, sizeof(ram));
|
||||||
|
load_file_to_buffer(token, cart_low, sizeof(cart_low));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void load_bootrom(char *arg_list)
|
static void load_bootrom(char *arg_list)
|
||||||
@@ -461,6 +459,7 @@ static void load_bootrom(char *arg_list)
|
|||||||
|
|
||||||
strip_newline(token);
|
strip_newline(token);
|
||||||
load_file_to_buffer(token, bootrom, sizeof(bootrom));
|
load_file_to_buffer(token, bootrom, sizeof(bootrom));
|
||||||
|
load_file_to_buffer(token, ram, sizeof(bootrom));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -326,12 +326,10 @@ void lr35902_cycle(struct lr35902_state *cpu)
|
|||||||
|
|
||||||
if (cpu->stall_cycles > 0) {
|
if (cpu->stall_cycles > 0) {
|
||||||
cpu->stall_cycles--;
|
cpu->stall_cycles--;
|
||||||
if (cpu->stall_cycles == 0) {
|
|
||||||
cpu->metrics.retired_instrs++;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpu->metrics.retired_instrs++;
|
||||||
inst = cpu->mem_read(cpu, cpu->pc++);
|
inst = cpu->mem_read(cpu, cpu->pc++);
|
||||||
cpu->stall_cycles = op_extra_cycles[inst];
|
cpu->stall_cycles = op_extra_cycles[inst];
|
||||||
|
|
||||||
|
|||||||
@@ -14,16 +14,15 @@ void gb_video_init(struct gb_video *video)
|
|||||||
|
|
||||||
void gb_video_cycle(struct gb_video *video)
|
void gb_video_cycle(struct gb_video *video)
|
||||||
{
|
{
|
||||||
|
if (video->line_counter < CYCLES_PER_LINE - 1) {
|
||||||
video->line_counter++;
|
video->line_counter++;
|
||||||
|
} else {
|
||||||
if (video->line_counter >= CYCLES_PER_LINE) {
|
|
||||||
video->line_counter = 0;
|
video->line_counter = 0;
|
||||||
video->curline += 1;
|
video->curline += 1;
|
||||||
if (video->curline > LCD_Y_MAX) {
|
if (video->curline > LCD_Y_MAX) {
|
||||||
video->curline = 0;
|
video->curline = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t gb_video_mem_read(struct gb_video *video, uint16_t addr)
|
uint8_t gb_video_mem_read(struct gb_video *video, uint16_t addr)
|
||||||
|
|||||||
Reference in New Issue
Block a user