allow writes to dma apu channels

This commit is contained in:
Matthew Berry 2020-12-13 12:38:16 -08:00
parent 4b6563773c
commit 1aab2cc5a8
2 changed files with 38 additions and 16 deletions

View file

@ -82,6 +82,7 @@ class APU
@channel2 = Channel2.new @gba
@channel3 = Channel3.new @gba
@channel4 = Channel4.new @gba
@dma_channels = DMAChannels.new @gba
tick_frame_sequencer
get_sample
@ -160,14 +161,15 @@ class APU
def read_io(io_addr : Int) : UInt8
case io_addr
when @channel1 then @channel1.read_io io_addr
when @channel2 then @channel2.read_io io_addr
when @channel3 then @channel3.read_io io_addr
when @channel4 then @channel4.read_io io_addr
when 0x80 then @soundcnt_l.value.to_u8!
when 0x81 then (@soundcnt_l.value >> 8).to_u8!
when 0x82 then @soundcnt_h.value.to_u8!
when 0x83 then (@soundcnt_h.value >> 8).to_u8!
when @channel1 then @channel1.read_io io_addr
when @channel2 then @channel2.read_io io_addr
when @channel3 then @channel3.read_io io_addr
when @channel4 then @channel4.read_io io_addr
when @dma_channels then @dma_channels.read_io io_addr
when 0x80 then @soundcnt_l.value.to_u8!
when 0x81 then (@soundcnt_l.value >> 8).to_u8!
when 0x82 then @soundcnt_h.value.to_u8!
when 0x83 then (@soundcnt_h.value >> 8).to_u8!
when 0x84
0x70_u8 |
(@sound_enabled ? 0x80 : 0) |
@ -186,14 +188,15 @@ class APU
def write_io(io_addr : Int, value : UInt8) : Nil
return unless @sound_enabled || io_addr == 0x84 || Channel3::WAVE_RAM_RANGE.includes?(io_addr)
case io_addr
when @channel1 then @channel1.write_io io_addr, value
when @channel2 then @channel2.write_io io_addr, value
when @channel3 then @channel3.write_io io_addr, value
when @channel4 then @channel4.write_io io_addr, value
when 0x80 then @soundcnt_l.value = (@soundcnt_l.value & 0xFF00) | value
when 0x81 then @soundcnt_l.value = (@soundcnt_l.value & 0x00FF) | value.to_u16 << 8
when 0x82 then @soundcnt_h.value = (@soundcnt_h.value & 0xFF00) | value
when 0x83 then @soundcnt_h.value = (@soundcnt_h.value & 0x00FF) | value.to_u16 << 8
when @channel1 then @channel1.write_io io_addr, value
when @channel2 then @channel2.write_io io_addr, value
when @channel3 then @channel3.write_io io_addr, value
when @channel4 then @channel4.write_io io_addr, value
when @dma_channels then @dma_channels.write_io io_addr, value
when 0x80 then @soundcnt_l.value = (@soundcnt_l.value & 0xFF00) | value
when 0x81 then @soundcnt_l.value = (@soundcnt_l.value & 0x00FF) | value.to_u16 << 8
when 0x82 then @soundcnt_h.value = (@soundcnt_h.value & 0xFF00) | value
when 0x83 then @soundcnt_h.value = (@soundcnt_h.value & 0x00FF) | value.to_u16 << 8
when 0x84
if value & 0x80 == 0 && @sound_enabled
(0xFF10..0xFF25).each { |addr| self.write_io addr, 0x00 }

View file

@ -0,0 +1,19 @@
class DMAChannels
RANGE = 0xA0..0xA7
def ===(value) : Bool
value.is_a?(Int) && RANGE.includes?(value)
end
def initialize(@gba : GBA)
end
def read_io(index : Int) : UInt8
abort "Reading DMA sound: #{hex_str index.to_u8}"
0_u8
end
def write_io(index : Int, value : UInt8) : Nil
abort "Writing DMA sound: #{hex_str index.to_u8} -> #{hex_str value}"
end
end