mirror of
https://github.com/mattrberry/crab.git
synced 2025-01-18 10:26:22 +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:
|
bitfield:
|
||||||
github: mattrberry/bitfield
|
github: mattrberry/bitfield
|
||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
sdl:
|
||||||
|
git: git@github.com:ysbaddaden/sdl.cr.git
|
||||||
|
|
||||||
license: MIT
|
license: MIT
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
require "bitfield"
|
require "bitfield"
|
||||||
|
require "sdl"
|
||||||
|
|
||||||
require "./crab/gba"
|
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 "./cartridge"
|
||||||
require "./bus"
|
require "./bus"
|
||||||
require "./cpu"
|
require "./cpu"
|
||||||
|
require "./display"
|
||||||
require "./ppu"
|
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 display : Display { Display.new }
|
||||||
getter ppu : PPU { PPU.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
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
def run : Nil
|
def run : Nil
|
||||||
# puts @cartridge.title
|
# puts @cartridge.title
|
||||||
loop do
|
loop do
|
||||||
|
280896.times do
|
||||||
cpu.tick
|
cpu.tick
|
||||||
end
|
end
|
||||||
|
ppu.tick 280896
|
||||||
|
handle_events
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,10 @@ class PPU
|
||||||
def initialize(@gba : GBA)
|
def initialize(@gba : GBA)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tick(cycles : Int) : Nil
|
||||||
|
@gba.display.draw @vram
|
||||||
|
end
|
||||||
|
|
||||||
def [](index : Int) : Byte
|
def [](index : Int) : Byte
|
||||||
case index
|
case index
|
||||||
when 0x04000000 then (@dispcnt.value >> 8).to_u8
|
when 0x04000000 then (@dispcnt.value >> 8).to_u8
|
||||||
|
|
Loading…
Reference in a new issue