From e7291817638db55d8e1e779ca69e5ee174d7f45f Mon Sep 17 00:00:00 2001 From: Colby Date: Mon, 8 Aug 2016 21:15:20 +1000 Subject: [PATCH] fix input not working correctly --- lib/waterfoul/input.rb | 47 +++++++++++++++++++++--------------------- lib/waterfoul/mmu.rb | 3 +-- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/waterfoul/input.rb b/lib/waterfoul/input.rb index 248f5d3..0ecd506 100644 --- a/lib/waterfoul/input.rb +++ b/lib/waterfoul/input.rb @@ -11,54 +11,55 @@ module Waterfoul B_INPUT_KEYCODE = 5 START_INPUT_KEYCODE = 40 SELECT_INPUT_KEYCODE = 229 - POLL_RATE = 65536 + POLL_RATE = 5000 def initialize @modeclock = 0 - @current_key = 0 - $mmu.write_byte 0xFF00, 0x3F, hardware_operation: true + @current_keys = 0 + $mmu.write_byte 0xFF00, 0xFF, hardware_operation: true end def step(cycles = 1) - @modeclock =+ cycles + @modeclock += cycles event = SDL2::Event.poll + if @modeclock >= POLL_RATE @modeclock -= POLL_RATE - return unless @current_key > 0 - joypad_byte = $mmu.read_byte 0xFF00 - key_byte = 0x3F + input = $mmu.read_byte 0xFF00 - if joypad_byte & 0x10 == 0x00 + if input & 0x10 == 0x00 case @current_key when UP_INPUT_KEYCODE - key_byte ^= 0x4 + input ^= 0x4 when DOWN_INPUT_KEYCODE - key_byte ^= 0x8 + input ^= 0x8 when RIGHT_INPUT_KEYCODE - key_byte ^= 0x1 + input ^= 0x1 when LEFT_INPUT_KEYCODE - key_byte ^= 0x2 + input ^= 0x2 end - p "bar!" - elsif joypad_byte & 0x20 == 0x00 + @current_key = 0 + $mmu.write_byte 0xFF0F, input + Interrupt.request_interrupt(Interrupt::INTERRUPT_JOYPAD) + elsif input & 0x20 == 0x0 case @current_key when A_INPUT_KEYCODE - key_byte ^= 0x1 + input ^= 0x1 when B_INPUT_KEYCODE - key_byte ^= 0x2 + input ^= 0x2 when START_INPUT_KEYCODE - key_byte ^= 0x8 + input ^= 0x8 when SELECT_INPUT_KEYCODE - key_byte ^= 0x4 + input ^= 0x4 end - p "foo!" + @current_key = 0 + $mmu.write_byte 0xFF0F, input + Interrupt.request_interrupt(Interrupt::INTERRUPT_JOYPAD) end - - $mmu.write_byte 0xFF00, (joypad_byte & key_byte), hardware_operation: true - Interrupt.request_interrupt Interrupt::INTERRUPT_JOYPAD - elsif event.kind_of? SDL2::Event::KeyDown + elsif event.kind_of?(SDL2::Event::KeyDown) @current_key = event.scancode + p @current_key end end end diff --git a/lib/waterfoul/mmu.rb b/lib/waterfoul/mmu.rb index 765b044..7cb20e8 100644 --- a/lib/waterfoul/mmu.rb +++ b/lib/waterfoul/mmu.rb @@ -67,8 +67,7 @@ module Waterfoul when UNMAP_BOOT_ROM_MEM_LOC # unmap the boot rom when 0xFF50 is wrtiten to in memory @map_boot_rom = false if v == 0x1 && @map_boot_rom when 0xFF00 - current = self[0xFF00] - @memory[0xFF00] = (current & 0xF) | (v & 0x30) + @memory[i] = v | 0xF when 0xFF46 # DMA transfer dma_transfer v @memory[i] = v