diff --git a/gb.c b/gb.c index 2e7c69c..7770552 100644 --- a/gb.c +++ b/gb.c @@ -6,12 +6,10 @@ #include int savereq, loadreq; -int cpuhalt; -int backup; int savefd = -1; int saveframes; const char *romname; -u8 mbc, feat, mode; +u8 mbc, mode; void writeback(void) @@ -68,6 +66,7 @@ loadsave(const char *file) static void loadrom(const char* file) { + int feat; FILE* f; long sz; static u8 mbctab[31] = { 0, 1, 1, 1, -1, 2, 2, -1, 0, 0, -1, 6, 6, 6, -1, 3, @@ -114,8 +113,8 @@ loadrom(const char* file) break; default: panic("unsupported mbc %d", mbc); } - if ((rom[0x143] & 0x80) != 0 && (mode & FORCEDMG) == 0) - mode = CGB | COL; + if (rom[0x143] & 0x80 != 0) + panic("unsupported color"); if((feat & FEATBAT) != 0) loadsave(file); } @@ -147,11 +146,7 @@ flush() static void colinit(void) { - union - { - u8 c[4]; - u32 l; - } c; + union {u8 c[4]; u32 l;}c; c.c[3] = 0; for (int i = 0; i < 4; i++) { diff --git a/gb.h b/gb.h index d9735e0..973b9be 100644 --- a/gb.h +++ b/gb.h @@ -174,15 +174,14 @@ extern u32 pal[64]; extern u8 dma; extern u32 divclock; extern u64 clock; -extern u8 ppuy, ppustate, ppuw; +extern u8 ppuy, ppustate; extern u8 keys; extern int prish; extern u8 mode; -extern u8 mbc, feat; +extern u8 mbc; extern Event* elist; extern Event evhblank, evjoypad; extern u32 moncols[4]; -extern u32 white; extern u8* pic; extern int (*mapper)(int, int); extern Event *events[NEVENT]; diff --git a/mem.c b/mem.c index a483482..c7038fa 100644 --- a/mem.c +++ b/mem.c @@ -71,7 +71,6 @@ regwrite(u16 a, u8 v) ppusync(); if ((~v & reg[a] & LCDEN) != 0) { ppuy = 0; - ppuw = 0; ppustate = 0; delevent(&evhblank); } @@ -236,13 +235,9 @@ mbc1(int a, int v) } void -meminit(void) +meminit() { - union - { - u8 c[4]; - u32 l; - } c; + union {u8 c[4]; u32 l;}c; c.c[0] = c.c[1] = c.c[2] = 0; c.c[3] = 1; @@ -250,14 +245,12 @@ meminit(void) c.l >>= 1; c.c[0] = c.c[1] = c.c[2] = 0xff; c.c[3] = 0; - white = c.l; romb = rom + 0x4000; wramb = wram + 0x1000; vramb = vram; mapper = mappers[mbc]; mapper(INIT, 0); - reg[LCDC] = 0x91; reg[IF] = 0xE0; reg[SVBK] = 0xff; diff --git a/ppu.c b/ppu.c index 6790111..43dc764 100644 --- a/ppu.c +++ b/ppu.c @@ -34,7 +34,7 @@ enum }; jmp_buf mainjmp,renderjmp; -u8 ppustate, ppuy, ppuw; +u8 ppustate, ppuy; u64 hblclock, rendclock; static int cyc, ppux, ppux0; sprite spr[10], *sprm; @@ -110,8 +110,8 @@ ppurender(void) } while (m > 8); if (win == -1) { win = 1; - ta = 0x1800 | reg[LCDC] << 4 & 0x400 | ppuw - reg[WY] << 2 & 0x3E0; - y = ppuw - reg[WY] << 1 & 14; + ta = 0x1800 | reg[LCDC] << 4 & 0x400 | ppuy - reg[WY] << 2 & 0x3E0; + y = ppuy - reg[WY] << 1 & 14; cyc += 12; m = 175 - reg[WX]; goto restart; @@ -193,11 +193,11 @@ sprites(void) for (; x < x1; ++x) { attr = picp[x] >> prish; chr = q->chr; - if ((chr & ((q->t & SPRXFL) != 0 ? 0x0101 : 0x8080)) != 0 && + if((chr & ((q->t & SPRXFL) != 0 ? 0x0101 : 0x8080)) != 0 && (attr & TILSPR) == 0 && ((mode & COL) != 0 && (reg[LCDC] & BGPRI) == 0 || (attr & TILCOL0) != 0 || - (attr & TILPRI) == 0 && (q->t & SPRPRI) == 0)) { + (attr & TILPRI) == 0 && (q->t & SPRPRI) == 0)){ if ((q->t & SPRXFL) == 0) picp[x] = pal[q->pal | chr >> 15 | chr >> 6 & 2] | TILSPR << prish; else @@ -245,8 +245,6 @@ hblanktick(void* _) switch (ppustate) { case 0: hblclock = clock + evhblank.time; - if (reg[WX] <= 166 && reg[WY] <= 143) - ppuw++; if (++ppuy == 144) { ppustate = 1; if (reg[STAT] & IRQM1) @@ -265,11 +263,8 @@ hblanktick(void* _) break; case 1: hblclock = clock + evhblank.time; - if (reg[WX] <= 166 && reg[WY] <= 143) - ppuw++; if (++ppuy == 154) { ppuy = 0; - ppuw = 0; ppustate = 2; if (reg[STAT] & IRQM2) reg[IF] |= IRQLCDS;