loop cpu forever, make cpu tick other components

This commit is contained in:
Matthew Berry 2020-10-03 00:00:00 -07:00
parent fc9f3d3035
commit 7228a50427
3 changed files with 27 additions and 6 deletions

View file

@ -59,6 +59,7 @@ class CPU
else
arm_execute instr
end
@gba.tick 1
end
def check_cond(cond : Word) : Bool

View file

@ -13,6 +13,8 @@ class GBA
getter display : Display { Display.new }
getter ppu : PPU { PPU.new self }
@cycles = 0
def initialize(rom_path : String)
@cartridge = Cartridge.new rom_path
@ -34,13 +36,17 @@ class GBA
end
def run : Nil
# puts @cartridge.title
loop do
280896.times do
cpu.tick
end
ppu.tick 280896
cpu.tick
end
end
def tick(cycles : Int) : Nil
ppu.tick cycles
@cycles += cycles
if @cycles >= PPU::REFRESH
handle_events
@cycles -= PPU::REFRESH
end
end
end

View file

@ -3,6 +3,14 @@ class PPU
VRAM = 0x06000000..0x06017FFF
OAM = 0x07000000..0x070003FF
# Display timings in cycles
HDRAW = 960
HBLANK = 272
SCANLINE = HDRAW + HBLANK
VDRAW = 160 * SCANLINE
VBLANK = 68 * SCANLINE
REFRESH = VDRAW + VBLANK
# LCD Control
class DISPCNT < BitField(UInt16)
bool obj_window_display
@ -25,11 +33,17 @@ class PPU
@dispcnt : DISPCNT = DISPCNT.new 0
@cycles = 0
def initialize(@gba : GBA)
end
def tick(cycles : Int) : Nil
@gba.display.draw @vram
@cycles += cycles
if @cycles >= REFRESH
@gba.display.draw @vram
@cycles -= REFRESH
end
end
def [](index : Int) : Byte