mirror of
https://github.com/colby-swandale/waterfoul
synced 2024-12-27 21:58:55 +01:00
Use read_memory_byte for all reads of addresses over 0xFE00
This commit is contained in:
parent
89aaa3e2cb
commit
c3e8074f96
6 changed files with 22 additions and 22 deletions
|
@ -125,7 +125,7 @@ module Waterfoul
|
||||||
# master disable interrupts
|
# master disable interrupts
|
||||||
@ime = false
|
@ime = false
|
||||||
push_onto_stack @pc
|
push_onto_stack @pc
|
||||||
if_reg = $mmu.read_byte 0xFF0F
|
if_reg = $mmu.read_memory_byte 0xFF0F
|
||||||
case interrupt
|
case interrupt
|
||||||
when Interrupt::INTERRUPT_VBLANK
|
when Interrupt::INTERRUPT_VBLANK
|
||||||
@pc = 0x40
|
@pc = 0x40
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Waterfoul
|
||||||
# Halt CPU & LCD display until button pressed.
|
# Halt CPU & LCD display until button pressed.
|
||||||
# @flags - - - -
|
# @flags - - - -
|
||||||
def halt
|
def halt
|
||||||
@pre_halt_interrupt = $mmu.read_byte(0xFF0F)
|
@pre_halt_interrupt = $mmu.read_memory_byte(0xFF0F)
|
||||||
@halt = true
|
@halt = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,13 @@ module Waterfoul
|
||||||
|
|
||||||
#
|
#
|
||||||
def self.request_interrupt(interrupt)
|
def self.request_interrupt(interrupt)
|
||||||
if_reg = $mmu.read_byte IF_REG_MEM_LOC
|
if_reg = $mmu.read_memory_byte IF_REG_MEM_LOC
|
||||||
$mmu.write_byte IF_REG_MEM_LOC, (if_reg | interrupt)
|
$mmu.write_byte IF_REG_MEM_LOC, (if_reg | interrupt)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.pending_interrupt
|
def self.pending_interrupt
|
||||||
ie_reg = $mmu.read_byte IE_REG_MEM_LOC
|
ie_reg = $mmu.read_memory_byte IE_REG_MEM_LOC
|
||||||
if_reg = $mmu.read_byte IF_REG_MEM_LOC
|
if_reg = $mmu.read_memory_byte IF_REG_MEM_LOC
|
||||||
pending_interrupts = if_reg & ie_reg
|
pending_interrupts = if_reg & ie_reg
|
||||||
|
|
||||||
if pending_interrupts & INTERRUPT_VBLANK == INTERRUPT_VBLANK
|
if pending_interrupts & INTERRUPT_VBLANK == INTERRUPT_VBLANK
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Waterfoul
|
||||||
private
|
private
|
||||||
|
|
||||||
def lcdc
|
def lcdc
|
||||||
$mmu.read_byte LCDC_MEM_LOC
|
$mmu.read_memory_byte LCDC_MEM_LOC
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -128,7 +128,7 @@ module Waterfoul
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_stat_mode
|
def update_stat_mode
|
||||||
stat = $mmu.read_byte 0xFF41
|
stat = $mmu.read_memory_byte 0xFF41
|
||||||
new_stat = (stat & 0xFC) | (@mode & 0x3)
|
new_stat = (stat & 0xFC) | (@mode & 0x3)
|
||||||
$mmu.write_byte 0xFF41, new_stat
|
$mmu.write_byte 0xFF41, new_stat
|
||||||
end
|
end
|
||||||
|
@ -140,8 +140,8 @@ module Waterfoul
|
||||||
# if the LCDC window enable bit flag is not set
|
# if the LCDC window enable bit flag is not set
|
||||||
return if @window_line > 143 || !IO::LCDControl.window_enabled?
|
return if @window_line > 143 || !IO::LCDControl.window_enabled?
|
||||||
|
|
||||||
window_pos_x = $mmu.read_byte(0xFF4B) - 7
|
window_pos_x = $mmu.read_memory_byte(0xFF4B) - 7
|
||||||
window_pos_y = $mmu.read_byte(0xFF4A)
|
window_pos_y = $mmu.read_memory_byte(0xFF4A)
|
||||||
|
|
||||||
# don't render if the window is outside the bounds of the screen
|
# don't render if the window is outside the bounds of the screen
|
||||||
return if window_pos_x > 159 || window_pos_y > 143 || window_pos_y > line
|
return if window_pos_x > 159 || window_pos_y > 143 || window_pos_y > line
|
||||||
|
@ -206,14 +206,14 @@ module Waterfoul
|
||||||
39.downto(0) do |sprite|
|
39.downto(0) do |sprite|
|
||||||
sprite_offset = sprite * 4
|
sprite_offset = sprite * 4
|
||||||
|
|
||||||
sprite_y = $mmu.read_byte(0xFE00 + sprite_offset) - 16
|
sprite_y = $mmu.read_memory_byte(0xFE00 + sprite_offset) - 16
|
||||||
next if sprite_y > line || (sprite_y + sprite_size) <= line
|
next if sprite_y > line || (sprite_y + sprite_size) <= line
|
||||||
|
|
||||||
sprite_x = $mmu.read_byte(0xFE00 + sprite_offset + 1) - 8
|
sprite_x = $mmu.read_memory_byte(0xFE00 + sprite_offset + 1) - 8
|
||||||
next if sprite_x < -7 || sprite_x >= Screen::SCREEN_WIDTH
|
next if sprite_x < -7 || sprite_x >= Screen::SCREEN_WIDTH
|
||||||
|
|
||||||
sprite_tile_offset = ($mmu.read_byte(0xFE00 + sprite_offset + 2) & (sprite_size == 16 ? 0xFE : 0xFF)) * 16
|
sprite_tile_offset = ($mmu.read_memory_byte(0xFE00 + sprite_offset + 2) & (sprite_size == 16 ? 0xFE : 0xFF)) * 16
|
||||||
sprite_flags = $mmu.read_byte(0xFE00 + sprite_offset + 3)
|
sprite_flags = $mmu.read_memory_byte(0xFE00 + sprite_offset + 3)
|
||||||
x_flip = sprite_flags & 0x20 == 0x20 ? true : false
|
x_flip = sprite_flags & 0x20 == 0x20 ? true : false
|
||||||
y_flip = sprite_flags & 0x40 == 0x40 ? true : false
|
y_flip = sprite_flags & 0x40 == 0x40 ? true : false
|
||||||
#above_bg = sprite_flags & 0x80 == 0x80 ? true : false
|
#above_bg = sprite_flags & 0x80 == 0x80 ? true : false
|
||||||
|
@ -269,9 +269,9 @@ module Waterfoul
|
||||||
tiles_select = IO::LCDControl.bg_tile_select
|
tiles_select = IO::LCDControl.bg_tile_select
|
||||||
map_select = IO::LCDControl.bg_map_select
|
map_select = IO::LCDControl.bg_map_select
|
||||||
# x pixel offset
|
# x pixel offset
|
||||||
scx = $mmu.read_byte 0xFF43
|
scx = $mmu.read_memory_byte 0xFF43
|
||||||
# y pixel offset
|
# y pixel offset
|
||||||
scy = $mmu.read_byte 0xFF42
|
scy = $mmu.read_memory_byte 0xFF42
|
||||||
# line with y offset
|
# line with y offset
|
||||||
line_adjusted = (line + scy) & 0xFF
|
line_adjusted = (line + scy) & 0xFF
|
||||||
# get position of tile row to read
|
# get position of tile row to read
|
||||||
|
@ -332,8 +332,8 @@ module Waterfoul
|
||||||
|
|
||||||
def compare_lylc
|
def compare_lylc
|
||||||
if IO::LCDControl.screen_enabled?
|
if IO::LCDControl.screen_enabled?
|
||||||
lyc = $mmu.read_byte 0xFF45
|
lyc = $mmu.read_memory_byte 0xFF45
|
||||||
stat = $mmu.read_byte 0xFF41
|
stat = $mmu.read_memory_byte 0xFF41
|
||||||
|
|
||||||
if lyc == current_line
|
if lyc == current_line
|
||||||
stat = stat | 0x4
|
stat = stat | 0x4
|
||||||
|
@ -345,7 +345,7 @@ module Waterfoul
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_line
|
def current_line
|
||||||
$mmu.read_byte LCDC_Y_COORDINATE_MEM_LOC
|
$mmu.read_memory_byte LCDC_Y_COORDINATE_MEM_LOC
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_current_line
|
def reset_current_line
|
||||||
|
|
|
@ -27,9 +27,9 @@ module Waterfoul
|
||||||
end
|
end
|
||||||
|
|
||||||
def inc_tima_register
|
def inc_tima_register
|
||||||
tima = $mmu.read_byte 0xFF05
|
tima = $mmu.read_memory_byte 0xFF05
|
||||||
if tima == 0xFF
|
if tima == 0xFF
|
||||||
tima = $mmu.read_byte 0xFF06
|
tima = $mmu.read_memory_byte 0xFF06
|
||||||
Interrupt.request_interrupt(Interrupt::INTERRUPT_TIMER)
|
Interrupt.request_interrupt(Interrupt::INTERRUPT_TIMER)
|
||||||
else
|
else
|
||||||
tima += 1
|
tima += 1
|
||||||
|
@ -39,7 +39,7 @@ module Waterfoul
|
||||||
end
|
end
|
||||||
|
|
||||||
def inc_div_register
|
def inc_div_register
|
||||||
div = $mmu.read_byte 0xFF04
|
div = $mmu.read_memory_byte 0xFF04
|
||||||
div = (div + 1) & 0xFF
|
div = (div + 1) & 0xFF
|
||||||
$mmu.write_byte 0xFF04, div, hardware_operation: true
|
$mmu.write_byte 0xFF04, div, hardware_operation: true
|
||||||
@div_cycles -= DIV_INC_TIME
|
@div_cycles -= DIV_INC_TIME
|
||||||
|
@ -52,7 +52,7 @@ module Waterfoul
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@register = $mmu.read_byte 0xFF07
|
@register = $mmu.read_memory_byte 0xFF07
|
||||||
end
|
end
|
||||||
|
|
||||||
def running?
|
def running?
|
||||||
|
|
Loading…
Reference in a new issue