summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2018-06-27 22:56:28 -0400
committerPaul Duncan <pabs@pablotron.org>2018-06-27 22:56:28 -0400
commit9b1ece39d6dac829fe9014b5de776b2d68fec0c3 (patch)
treed642cb2838eab1f2440aa40d428334400a4b0a74
parent3869f125ad429f3148092decd4209d9307647b3f (diff)
downloadgb-c-9b1ece39d6dac829fe9014b5de776b2d68fec0c3.tar.bz2
gb-c-9b1ece39d6dac829fe9014b5de776b2d68fec0c3.zip
misc oam/vram function fixes
-rw-r--r--gb.h2
-rw-r--r--ops.yaml70
2 files changed, 31 insertions, 41 deletions
diff --git a/gb.h b/gb.h
index 358c1f2..2be0806 100644
--- a/gb.h
+++ b/gb.h
@@ -56,7 +56,7 @@ struct gb_t_ {
uint8_t eram[0x10000]; // external ram (banked, up to 64k)
uint8_t vram[0x2000]; // vram (8k)
uint8_t oam[0xA0]; // oam (160 bytes)
- uint8_t zram[0x7F]; // zram (128 bytes)
+ uint8_t zram[0x80]; // zram (128 bytes)
// rom (at least 32k)
const uint8_t *rom;
diff --git a/ops.yaml b/ops.yaml
index 3088ea2..d11350e 100644
--- a/ops.yaml
+++ b/ops.yaml
@@ -8833,9 +8833,10 @@ templates:
const gb_t * const ctx,
const uint16_t addr
) {
- if (gpu_is_active(ctx) && gpu_get_mode(ctx) == GPU_MODE_VRAM) {
+ switch (gpu_get_mode(ctx)) {
+ case GPU_MODE_VRAM:
return 0xFF;
- } else {
+ default:
// return vram (8k)
return ctx->mmu.vram[addr & 0x1FFF];
}
@@ -8846,18 +8847,14 @@ templates:
const gb_t * const ctx,
const uint16_t addr
) {
- if (gpu_is_active(ctx)) {
- switch (gpu_get_mode(ctx)) {
- case GPU_MODE_HBLANK:
- case GPU_MODE_VBLANK:
- // oam memory (160 bytes):
- return ctx->mmu.oam[addr & 0xFF];
- default:
- return 0;
- }
- } else {
+ // NOTE: gpu_get_mode() returns VBLANK if gpu is inactive
+ switch (gpu_get_mode(ctx)) {
+ case GPU_MODE_HBLANK:
+ case GPU_MODE_VBLANK:
// oam memory (160 bytes):
- return ctx->mmu.oam[addr & 0xFF];
+ return ctx->mmu.oam[addr - 0xFE00];
+ default:
+ return 0;
}
}
@@ -8971,21 +8968,15 @@ templates:
const uint16_t addr,
const uint8_t val
) {
- if (gpu_is_active(ctx)) {
- switch (gpu_get_mode(ctx)) {
- case GPU_MODE_HBLANK:
- case GPU_MODE_VBLANK:
- case GPU_MODE_OAM:
- // vram (8k)
- ctx->mmu.vram[addr & 0x1FFF] = val;
- break;
- default:
- // do nothing
- break;
- }
- } else {
- // vram (8k)
+ // NOTE: gpu_get_mode() returns VBLANK if lcd is inactive
+ switch (gpu_get_mode(ctx)) {
+ case GPU_MODE_VRAM:
+ // do nothing
+ break;
+ default:
+ // write to vram (8k)
ctx->mmu.vram[addr & 0x1FFF] = val;
+ break;
}
}
@@ -8995,21 +8986,20 @@ templates:
const uint16_t addr,
const uint8_t val
) {
- if (gpu_is_active(ctx)) {
- switch (gpu_get_mode(ctx) & 0x3) {
- case GPU_MODE_HBLANK:
- case GPU_MODE_VBLANK:
- // oam memory (160 bytes):
- ctx->mmu.oam[addr & 0xFF] = val;
+ // NOTE: gpu_get_mode() returns VBLANK if lcd is inactive
+ switch (gpu_get_mode(ctx) & 0x3) {
+ case GPU_MODE_HBLANK:
+ case GPU_MODE_VBLANK:
+ // oam memory (160 bytes):
+ ctx->mmu.oam[addr - 0xFE00] = val;
- // invalidate oam cache
- ctx->gpu.oam_dirty = true;
+ // invalidate oam cache
+ ctx->gpu.oam_dirty = true;
- break;
- default:
- // do nothing
- break;
- }
+ break;
+ default:
+ // do nothing
+ break;
}
}