mirror of
https://github.com/mattrberry/crab.git
synced 2025-01-30 20:34:45 +01:00
ppu writes to dispcnt
This commit is contained in:
parent
843fb155df
commit
b830b97687
3 changed files with 60 additions and 4 deletions
|
@ -1,6 +1,14 @@
|
||||||
class Bus
|
class Bus
|
||||||
WRAM_BOARD = 0x02000000..0x0203FFFF
|
WRAM_BOARD = 0x02000000..0x0203FFFF
|
||||||
WRAM_CHIP = 0x03000000..0x03007FFF
|
WRAM_CHIP = 0x03000000..0x03007FFF
|
||||||
|
PPU_IO = 0x04000000..0x0400005F
|
||||||
|
SOUND_IO = 0x04000060..0x040000AF
|
||||||
|
DMA_IO = 0x040000B0..0x040000FF
|
||||||
|
TIMER_IO = 0x04000100..0x0400011F
|
||||||
|
SERIAL_IO_1 = 0x04000120..0x0400012F
|
||||||
|
KEYPAD_IO = 0x04000130..0x04000133
|
||||||
|
SERIAL_IO_2 = 0x04000134..0x040001FF
|
||||||
|
INTERRUPT_IO = 0x04000200..0x0400FFFF
|
||||||
CARTRIDGE = 0x08000000..0x0FFFFFFF
|
CARTRIDGE = 0x08000000..0x0FFFFFFF
|
||||||
UNUSED = 0x10000000..0xFFFFFFFF
|
UNUSED = 0x10000000..0xFFFFFFFF
|
||||||
|
|
||||||
|
@ -15,6 +23,7 @@ class Bus
|
||||||
case index
|
case index
|
||||||
when WRAM_BOARD then @wram_board[index - WRAM_BOARD.begin]
|
when WRAM_BOARD then @wram_board[index - WRAM_BOARD.begin]
|
||||||
when WRAM_CHIP then @wram_chip[index - WRAM_CHIP.begin]
|
when WRAM_CHIP then @wram_chip[index - WRAM_CHIP.begin]
|
||||||
|
when PPU_IO then @gba.ppu[index]
|
||||||
when CARTRIDGE then @gba.cartridge[index - CARTRIDGE.begin]
|
when CARTRIDGE then @gba.cartridge[index - CARTRIDGE.begin]
|
||||||
when UNUSED then 0xFF
|
when UNUSED then 0xFF
|
||||||
else 0xFF
|
else 0xFF
|
||||||
|
@ -38,6 +47,7 @@ class Bus
|
||||||
case index
|
case index
|
||||||
when WRAM_BOARD then @wram_board[index - WRAM_BOARD.begin] = value
|
when WRAM_BOARD then @wram_board[index - WRAM_BOARD.begin] = value
|
||||||
when WRAM_CHIP then @wram_chip[index - WRAM_CHIP.begin] = value
|
when WRAM_CHIP then @wram_chip[index - WRAM_CHIP.begin] = value
|
||||||
|
when PPU_IO then @gba.ppu[index] = value
|
||||||
when CARTRIDGE then @gba.cartridge[index - CARTRIDGE.begin] = value # todo is this meant to be writable?
|
when CARTRIDGE then @gba.cartridge[index - CARTRIDGE.begin] = value # todo is this meant to be writable?
|
||||||
when UNUSED then nil
|
when UNUSED then nil
|
||||||
else raise "Unimplemented write ~ addr:#{hex_str index.to_u32}, val:#{value}"
|
else raise "Unimplemented write ~ addr:#{hex_str index.to_u32}, val:#{value}"
|
||||||
|
|
|
@ -3,11 +3,13 @@ require "./util"
|
||||||
require "./cartridge"
|
require "./cartridge"
|
||||||
require "./bus"
|
require "./bus"
|
||||||
require "./cpu"
|
require "./cpu"
|
||||||
|
require "./ppu"
|
||||||
|
|
||||||
class GBA
|
class GBA
|
||||||
getter cartridge : Cartridge
|
getter cartridge : Cartridge
|
||||||
getter bus : Bus { Bus.new self }
|
getter bus : Bus { Bus.new self }
|
||||||
getter cpu : CPU { CPU.new self }
|
getter cpu : CPU { CPU.new self }
|
||||||
|
getter ppu : PPU { PPU.new self }
|
||||||
|
|
||||||
def initialize(rom_path : String)
|
def initialize(rom_path : String)
|
||||||
@cartridge = Cartridge.new rom_path
|
@cartridge = Cartridge.new rom_path
|
||||||
|
|
44
src/crab/ppu.cr
Normal file
44
src/crab/ppu.cr
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
class PPU
|
||||||
|
# LCD Control
|
||||||
|
class DISPCNT < BitField(UInt16)
|
||||||
|
bool obj_window_display
|
||||||
|
bool window_1_display
|
||||||
|
bool window_0_display
|
||||||
|
bool screen_display_obj
|
||||||
|
bool screen_display_bg3
|
||||||
|
bool screen_display_bg2
|
||||||
|
bool screen_display_bg1
|
||||||
|
bool screen_display_bg0
|
||||||
|
bool forced_blank # (1=Allow access to VRAM,Palette,OAM)
|
||||||
|
bool obj_character_vram_mapping # (0=Two dimensional, 1=One dimensional)
|
||||||
|
bool hblank_interval_free # (1=Allow access to OAM during H-Blank)
|
||||||
|
bool display_frame_select # (0-1=Frame 0-1) (for BG Modes 4,5 only)
|
||||||
|
bool reserved_for_bios # todo update bitfield macro to support overwriting/locking values
|
||||||
|
num bg_mode, 3 # (0-5=Video Mode 0-5, 6-7=Prohibited)
|
||||||
|
end
|
||||||
|
|
||||||
|
@dispcnt : DISPCNT = DISPCNT.new 0
|
||||||
|
|
||||||
|
def initialize(@gba : GBA)
|
||||||
|
end
|
||||||
|
|
||||||
|
def [](index : Int) : Byte
|
||||||
|
case index
|
||||||
|
when 0x04000000 then (@dispcnt.value >> 8).to_u8
|
||||||
|
when 0x04000001 then @dispcnt.value.to_u8!
|
||||||
|
when 0x04000002 then 0_u8
|
||||||
|
when 0x04000003 then 0_u8
|
||||||
|
else raise "Unimplemented PPU read ~ addr:#{hex_str index.to_u32}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def []=(index : Int, value : Byte) : Nil
|
||||||
|
case index
|
||||||
|
when 0x04000000 then @dispcnt.value = (@dispcnt.value & 0x00FF) | value.to_u16 << 8
|
||||||
|
when 0x04000001 then @dispcnt.value = (@dispcnt.value & 0xFF00) | value
|
||||||
|
when 0x04000002
|
||||||
|
when 0x04000003
|
||||||
|
else raise "Unimplemented PPU write ~ addr:#{hex_str index.to_u32}, val:#{value}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue