Skip to content

Commit

Permalink
Correct color detection and various graphics out of bounds errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zeta0134 committed Jan 16, 2017
1 parent bf90cf1 commit be1342b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions gameboy/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ local function draw_sprites_into_scanline(scanline, bg_index)
end

graphics.draw_scanline = function(scanline)
if scanline < 0 or scanline > 143 then
print("Bad scanline: ", scanline)
return
end
local bg_y = scanline + io.ram[ports.SCY]
local bg_x = io.ram[ports.SCX]
-- wrap the map in the Y direction
Expand Down
4 changes: 2 additions & 2 deletions gameboy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ gameboy.run_until_vblank = function()
end

gameboy.run_until_hblank = function()
local old_scanline = gameboy.graphics.scanline()
local old_scanline = gameboy.io.ram[gameboy.io.ports.LY]
local instructions = 0
while old_scanline == gameboy.graphics.scanline() and instructions < 100000 do
while old_scanline == gameboy.io.ram[gameboy.io.ports.LY] and instructions < 100000 do
gameboy.step()
instructions = instructions + 1
end
Expand Down
3 changes: 2 additions & 1 deletion gameboy/rom_header.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ rom_header.parse_cartridge_header = function(data)
header.title = extract_string(data, 0x134, 0x143)
header.manufacturer = extract_string(data, 0x13F, 0x142)

local cgb = bit32.band(data[0x143], 0x8) ~= 0
local cgb = (bit32.band(data[0x143], 0x80) ~= 0)
if cgb then
header.color = true
header.title = extract_string(data, 0x134, 0x13E)
else
header.color = false
end
Expand Down

0 comments on commit be1342b

Please sign in to comment.