fix input not working correctly

This commit is contained in:
Colby 2016-08-08 21:15:20 +10:00
parent ce5f524312
commit e729181763
2 changed files with 25 additions and 25 deletions

View file

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

View file

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