Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions firmware/opcodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bool syncArmed = false;
uint statSyncStage = 0; //0 = false, 1 = register read to A, 2 = masked to 0x03, 3 = cp to 0x01
uint lySyncStage = 0; //0 = false, 1 = register read, 2 = cp
uint syncReferenceCycle;
bool blockVRAMWrites; //0 = allow writes, 1 = block writes
int syncOffset; //Helper to calculate offset to scanline for synching

void setOffsetToLine(uint8_t line) {
Expand Down Expand Up @@ -63,6 +64,9 @@ void toMemory(uint16_t address, uint8_t data) {

if ((address & 0xe000) == 0x8000) { //Writing to VRAM
VRAM_HASH(address, data); //Calculate hash for game detection if we are writing to VRAM
// Block writes to GBC VRAM attribute map.
if (blockVRAMWrites)
return;
} else if (address >= 0xff00) { //Handle some IO registers
switch (address) {
case 0xff04: //Reset DIV register
Expand Down Expand Up @@ -112,6 +116,11 @@ void toMemory(uint16_t address, uint8_t data) {
paletteOBP1[2] = ((~data >> 4) & 0x03);
paletteOBP1[3] = ((~data >> 6) & 0x03);
break;
case 0xff4f: //VBK, GBC VRAM bank
// If VRAM bank 1 is selected, temporarily block all writes to VRAM to avoid glitches.
// We only care about bit 0.
blockVRAMWrites = data & 1;
break;
case 0xff4d: //KEY1, GBC double speed mode switch
if (data & 0x01)
stop("Game Boy Color\ngames are not\nsupported.");
Expand Down
2 changes: 2 additions & 0 deletions firmware/opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
extern void (*opcodes[])();
void toMemory(uint16_t address, uint8_t data);

extern bool blockVRAMWrites;

#endif
3 changes: 3 additions & 0 deletions firmware/ppu.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ppu.h"

#include "cpubus.h"
#include "opcodes.h"
#include "jpeg/jpeg.h"
#include "debug.h"

Expand Down Expand Up @@ -93,6 +94,8 @@ void ppuInit() {
interp_set_config(interp1, 0, &cfgMasked1);
interp_set_config(interp1, 1, &cfgUnmasked1);

blockVRAMWrites = 0;

readyBufferIsNew = false;
renderState = start;
y = 0;
Expand Down
Loading