mirror of
https://github.com/mattrberry/crab.git
synced 2024-12-28 09:58:49 +01:00
very basic ppu, passing tonc first.gba
This commit is contained in:
parent
b25d941d0f
commit
fc9f3d3035
5 changed files with 53 additions and 1 deletions
|
@ -14,5 +14,7 @@ dependencies:
|
|||
bitfield:
|
||||
github: mattrberry/bitfield
|
||||
version: 0.1.0
|
||||
sdl:
|
||||
git: git@github.com:ysbaddaden/sdl.cr.git
|
||||
|
||||
license: MIT
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
require "bitfield"
|
||||
require "sdl"
|
||||
|
||||
require "./crab/gba"
|
||||
|
||||
|
|
23
src/crab/display.cr
Normal file
23
src/crab/display.cr
Normal file
|
@ -0,0 +1,23 @@
|
|||
class Display
|
||||
WIDTH = 240
|
||||
HEIGHT = 160
|
||||
SCALE = 4
|
||||
|
||||
PIXELFORMAT_RGB24 = (1 << 28) | (7 << 24) | (1 << 20) | (0 << 16) | (24 << 8) | (3 << 0)
|
||||
PIXELFORMAT_BGR555 = (1 << 28) | (5 << 24) | (5 << 20) | (3 << 16) | (15 << 8) | (2 << 0)
|
||||
TEXTUREACCESS_STREAMING = 1
|
||||
|
||||
def initialize
|
||||
@window = SDL::Window.new("crab", WIDTH * SCALE, HEIGHT * SCALE)
|
||||
@renderer = SDL::Renderer.new @window
|
||||
@renderer.logical_size = {WIDTH, HEIGHT}
|
||||
@texture = LibSDL.create_texture @renderer, PIXELFORMAT_BGR555, TEXTUREACCESS_STREAMING, WIDTH, HEIGHT
|
||||
end
|
||||
|
||||
def draw(framebuffer : Bytes) : Nil
|
||||
LibSDL.update_texture @texture, nil, framebuffer, WIDTH * 2
|
||||
@renderer.clear
|
||||
@renderer.copy @texture
|
||||
@renderer.present
|
||||
end
|
||||
end
|
|
@ -3,22 +3,44 @@ require "./util"
|
|||
require "./cartridge"
|
||||
require "./bus"
|
||||
require "./cpu"
|
||||
require "./display"
|
||||
require "./ppu"
|
||||
|
||||
class GBA
|
||||
getter cartridge : Cartridge
|
||||
getter bus : Bus { Bus.new self }
|
||||
getter cpu : CPU { CPU.new self }
|
||||
getter display : Display { Display.new }
|
||||
getter ppu : PPU { PPU.new self }
|
||||
|
||||
def initialize(rom_path : String)
|
||||
@cartridge = Cartridge.new rom_path
|
||||
|
||||
SDL.init(SDL::Init::VIDEO | SDL::Init::AUDIO | SDL::Init::JOYSTICK)
|
||||
LibSDL.joystick_open 0
|
||||
at_exit { SDL.quit }
|
||||
end
|
||||
|
||||
def handle_events : Nil
|
||||
while event = SDL::Event.poll
|
||||
case event
|
||||
when SDL::Event::Quit then exit 0
|
||||
when SDL::Event::Keyboard,
|
||||
SDL::Event::JoyHat,
|
||||
SDL::Event::JoyButton
|
||||
else nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def run : Nil
|
||||
# puts @cartridge.title
|
||||
loop do
|
||||
cpu.tick
|
||||
280896.times do
|
||||
cpu.tick
|
||||
end
|
||||
ppu.tick 280896
|
||||
handle_events
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -28,6 +28,10 @@ class PPU
|
|||
def initialize(@gba : GBA)
|
||||
end
|
||||
|
||||
def tick(cycles : Int) : Nil
|
||||
@gba.display.draw @vram
|
||||
end
|
||||
|
||||
def [](index : Int) : Byte
|
||||
case index
|
||||
when 0x04000000 then (@dispcnt.value >> 8).to_u8
|
||||
|
|
Loading…
Reference in a new issue