Skip to content

Commit 3890eda

Browse files
committed
fixed DMG bootrom colour
1 parent 51cb316 commit 3890eda

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

internal/gameboy/gameboy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,9 @@ func NewGameBoy(rom []byte, opts ...Opt) *GameBoy {
376376
}
377377
// try to load cheats using filename of rom
378378
g.Bus.Map(g.model)
379+
g.Colourise()
379380
if !g.dontBoot {
380381
g.CPU.Boot(g.model)
381-
g.Colourise()
382382
g.Bus.Boot()
383383

384384
// schedule the frame sequencer event for the next 8192 ticks

internal/io/bus.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func (b *Bus) Map(m types.Model) {
9595

9696
// setup CGB only registers
9797
if b.isGBC && b.c.IsCGBCartridge() {
98-
b.vRAMBankMask = 1
9998
b.ReserveAddress(types.KEY0, func(v byte) byte {
10099
// KEY0 is only writable when boot ROM is running TODO verify
101100
if !b.bootROMDone {
@@ -196,6 +195,7 @@ func (b *Bus) Map(m types.Model) {
196195

197196
// setup cgb model registers
198197
if b.model == types.CGBABC || b.model == types.CGB0 {
198+
b.vRAMBankMask = 1
199199
b.ReserveAddress(types.VBK, func(v byte) byte {
200200
if b.IsGBCCart() || b.IsBooting() { // CGB boot ROM makes use of both banks
201201
copy(b.vRAM[b.data[types.VBK]&0x1][:], b.data[0x8000:0xA000])
@@ -289,6 +289,10 @@ func (b *Bus) Boot() {
289289

290290
if b.model == types.CGBABC || b.model == types.CGB0 {
291291
b.Set(types.VBK, 0xFE)
292+
293+
if !b.IsGBCCart() {
294+
b.vRAMBankMask = 0
295+
}
292296
}
293297

294298
b.bootROMDone = true
@@ -327,6 +331,9 @@ func (b *Bus) Write(addr uint16, value byte) {
327331
}
328332
b.bootROMDone = true
329333
value = 0xff
334+
if b.isGBC && !b.IsGBCCart() {
335+
b.vRAMBankMask = 0
336+
}
330337

331338
for _, f := range b.bootHandlers {
332339
f()
@@ -374,9 +381,6 @@ func (b *Bus) Write(addr uint16, value byte) {
374381
default:
375382
if handler := b.writeHandlers[addr&0xFF]; handler != nil {
376383
// check to see if a component has reserved this address
377-
if addr == 0xff15 {
378-
panic("how")
379-
}
380384
value = handler(value)
381385
} else if addr <= 0xff7f {
382386
return

internal/ppu/ppu.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,11 @@ func New(b *io.Bus, s *scheduler.Scheduler) *PPU {
306306
})
307307

308308
b.RegisterBootHandler(func() {
309-
p.BGColourisationPalette = p.ColourPalette[0]
310-
p.OBJ0ColourisationPalette = p.ColourSpritePalette[0]
311-
p.OBJ1ColourisationPalette = p.ColourSpritePalette[1]
309+
if b.IsGBC() && !b.IsGBCCart() {
310+
p.BGColourisationPalette = p.ColourPalette[0]
311+
p.OBJ0ColourisationPalette = p.ColourSpritePalette[0]
312+
p.OBJ1ColourisationPalette = p.ColourSpritePalette[1]
313+
}
312314
p.TileMaps = [2][32][32]TileEntry{}
313315
})
314316

0 commit comments

Comments
 (0)