diff --git a/lib/waterfoul.rb b/lib/waterfoul.rb index 275c252..296068f 100644 --- a/lib/waterfoul.rb +++ b/lib/waterfoul.rb @@ -6,7 +6,6 @@ require "waterfoul/interrupt" require "waterfoul/mmu" require "Waterfoul/timer" require "waterfoul/cpu" -require "waterfoul/sound" require "waterfoul/errors" require "waterfoul/sdl" require "waterfoul/screen" diff --git a/lib/waterfoul/libc.rb b/lib/waterfoul/libc.rb deleted file mode 100644 index 6e584d3..0000000 --- a/lib/waterfoul/libc.rb +++ /dev/null @@ -1,6 +0,0 @@ -module LibC - extend FFI::Library - ffi_lib FFI::Library::LIBC - - attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer -end diff --git a/lib/waterfoul/mmu.rb b/lib/waterfoul/mmu.rb index 7c360a8..081344c 100644 --- a/lib/waterfoul/mmu.rb +++ b/lib/waterfoul/mmu.rb @@ -1,10 +1,12 @@ require 'waterfoul/boot_rom' module Waterfoul - # The MMU (Memory Management Unit) in a chip in the device that acts a switch. - # It allows programs to interact with subsytems like the GPU and IO depending - # on the location in memory when reading from or writing to seeing the CPU - # does not implement any IO instructions. + # The MMU (Memory Management Unit) in a chip in the device that is the + # interface to hardware for reading and writing to memory. + # + # The MMU also provides the program a way to interact with hardware + # like the PPU and IO using memory registers. This is due to the CPU + # not having any IO instructions. class MMU MEMORY_SIZE = 65536 # bytes # unmap boot rom register address diff --git a/lib/waterfoul/render/background.rb b/lib/waterfoul/render/background.rb deleted file mode 100644 index cf0b6a8..0000000 --- a/lib/waterfoul/render/background.rb +++ /dev/null @@ -1,65 +0,0 @@ -module Waterfoul - module Render - class Background - class << self - def render - line = current_line - line_width = line * SCREEN_WIDTH - - if IO::LCDControl.bg_display - # tile and map select - tiles_select = IO::LCDControl.bg_tile_select - map_select = IO::LCDControl.bg_map_select - # x pixel offset - scx = $mmu.read_byte 0xFF43 - # y pixel offset - scy = $mmu.read_byte 0xFF42 - # adjusted line with y offset - line_adjusted = line + scy - # get position of tile row to read - y_offset = (line_adjusted / 8) * 32 - # relative line number in tile - tile_line = line_adjusted % 8 - # relative line number offset - tile_line_offset = tile_line * 2 - - 0.upto(31) do |x| - tile = 0 - if tiles_select == 0x8800 - tile = signed_value $mmu.read_byte(map_select + y_offset + x) - tile += 128 - else - tile = $mmu.read_byte map_select + y_offset + x - end - - line_pixel_offset = x * 8 - tile_select_offset = tile * 16 - tile_address = tiles_select + tile_select_offset + tile_line_offset - - byte_1 = $mmu.read_byte tile_address - byte_2 = $mmu.read_byte (tile_address + 1) - - 0.upto(7) do |pixelx| - buffer_addr = (line_pixel_offset + pixelx - scx) - - next if (buffer_addr >= SCREEN_WIDTH) - - pixel = (byte_1 & (0x1 << (7 - pixelx)) > 0) ? 1 : 0 - pixel |= (byte_2 & (0x1 << (7 - pixelx)) > 0) ? 2 : 0 - position = line_width + buffer_addr - palette = $mmu.read_byte 0xFF47 - color = (palette >> (pixel * 2)) & 0x3 - - @framebuffer[position] = color - end - end - else - 0.upto(SCREEN_WIDTH) do |i| - @framebuffer[line_width + i] = 0 - end - end - end - end - end - end -end diff --git a/lib/waterfoul/screen.rb b/lib/waterfoul/screen.rb index 74f7b9d..0dbd934 100644 --- a/lib/waterfoul/screen.rb +++ b/lib/waterfoul/screen.rb @@ -1,6 +1,5 @@ module Waterfoul class Screen - WINDOW_WIDTH = 480 WINDOW_HEIGHT = 432 diff --git a/lib/waterfoul/skip_boot.rb b/lib/waterfoul/skip_boot.rb index 9714ae9..54ccd7e 100644 --- a/lib/waterfoul/skip_boot.rb +++ b/lib/waterfoul/skip_boot.rb @@ -1,20 +1,17 @@ module Waterfoul - # Set the state of the emulator as defined to the same state as it typically - # is after it has finished running the bootloader and ready to execute the - # game program. - - # This lets us run the game without needing to execute the boot rom - # every time the emulator is started. + # set the state of the CPU and memory to the same state when the boot + # program has finished executing. This lets us run the game without + # needing to execute the boot rom every time the emulator is started. class SkipBoot def self.set_state(cpu) - # CPU registers + # set cpu register state cpu.set_register :pc, 0x100 cpu.set_register :af, 0x1B0 cpu.set_register :bc, 0x13 cpu.set_register :de, 0xD8 cpu.set_register :hl, 0x14D cpu.set_register :sp, 0xFFFE - # IO registers + # set IO reigster state $mmu.write_byte 0xFF10, 0x80 $mmu.write_byte 0xFF11, 0xBF $mmu.write_byte 0xFF12, 0xF3 @@ -37,6 +34,7 @@ module Waterfoul $mmu.write_byte 0xFF49, 0xFF # unmap the boot rom $mmu.write_byte 0xFF50, 0x1 + cpu end end diff --git a/lib/waterfoul/sound.rb b/lib/waterfoul/sound.rb deleted file mode 100644 index 665b4be..0000000 --- a/lib/waterfoul/sound.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Waterfoul - class Sound - def initialize - @clock = 0 - end - - def step(cpu_time) - @clock += cpu_time - end - end -end