removed unused code and more documentation cleanup

This commit is contained in:
Colby Swandale 2016-09-18 23:14:03 +10:00
parent d305150b05
commit f4bd164e06
7 changed files with 12 additions and 96 deletions

View file

@ -6,7 +6,6 @@ require "waterfoul/interrupt"
require "waterfoul/mmu" require "waterfoul/mmu"
require "Waterfoul/timer" require "Waterfoul/timer"
require "waterfoul/cpu" require "waterfoul/cpu"
require "waterfoul/sound"
require "waterfoul/errors" require "waterfoul/errors"
require "waterfoul/sdl" require "waterfoul/sdl"
require "waterfoul/screen" require "waterfoul/screen"

View file

@ -1,6 +0,0 @@
module LibC
extend FFI::Library
ffi_lib FFI::Library::LIBC
attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer
end

View file

@ -1,10 +1,12 @@
require 'waterfoul/boot_rom' require 'waterfoul/boot_rom'
module Waterfoul module Waterfoul
# The MMU (Memory Management Unit) in a chip in the device that acts a switch. # The MMU (Memory Management Unit) in a chip in the device that is the
# It allows programs to interact with subsytems like the GPU and IO depending # interface to hardware for reading and writing to memory.
# on the location in memory when reading from or writing to seeing the CPU #
# does not implement any IO instructions. # 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 class MMU
MEMORY_SIZE = 65536 # bytes MEMORY_SIZE = 65536 # bytes
# unmap boot rom register address # unmap boot rom register address

View file

@ -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

View file

@ -1,6 +1,5 @@
module Waterfoul module Waterfoul
class Screen class Screen
WINDOW_WIDTH = 480 WINDOW_WIDTH = 480
WINDOW_HEIGHT = 432 WINDOW_HEIGHT = 432

View file

@ -1,20 +1,17 @@
module Waterfoul module Waterfoul
# Set the state of the emulator as defined to the same state as it typically # set the state of the CPU and memory to the same state when the boot
# is after it has finished running the bootloader and ready to execute the # program has finished executing. This lets us run the game without
# game program. # needing to execute the boot rom every time the emulator is started.
# This lets us run the game without needing to execute the boot rom
# every time the emulator is started.
class SkipBoot class SkipBoot
def self.set_state(cpu) def self.set_state(cpu)
# CPU registers # set cpu register state
cpu.set_register :pc, 0x100 cpu.set_register :pc, 0x100
cpu.set_register :af, 0x1B0 cpu.set_register :af, 0x1B0
cpu.set_register :bc, 0x13 cpu.set_register :bc, 0x13
cpu.set_register :de, 0xD8 cpu.set_register :de, 0xD8
cpu.set_register :hl, 0x14D cpu.set_register :hl, 0x14D
cpu.set_register :sp, 0xFFFE cpu.set_register :sp, 0xFFFE
# IO registers # set IO reigster state
$mmu.write_byte 0xFF10, 0x80 $mmu.write_byte 0xFF10, 0x80
$mmu.write_byte 0xFF11, 0xBF $mmu.write_byte 0xFF11, 0xBF
$mmu.write_byte 0xFF12, 0xF3 $mmu.write_byte 0xFF12, 0xF3
@ -37,6 +34,7 @@ module Waterfoul
$mmu.write_byte 0xFF49, 0xFF $mmu.write_byte 0xFF49, 0xFF
# unmap the boot rom # unmap the boot rom
$mmu.write_byte 0xFF50, 0x1 $mmu.write_byte 0xFF50, 0x1
cpu cpu
end end
end end

View file

@ -1,11 +0,0 @@
module Waterfoul
class Sound
def initialize
@clock = 0
end
def step(cpu_time)
@clock += cpu_time
end
end
end