rename methods and paths of audio classes to increase gb/gba similarity

maybe this will help merge them someday
This commit is contained in:
Matthew Berry 2022-07-14 19:48:05 -07:00
parent dfdd319ca9
commit 5f6a3310a1
19 changed files with 49 additions and 49 deletions

View file

@ -1,5 +1,5 @@
require "./audio/abstract_channels" # so that channels don't need to all import require "./apu/abstract_channels" # so that channels don't need to all import
require "./audio/*" require "./apu/*"
module GB module GB
class APU class APU

View file

@ -136,13 +136,13 @@ module GBA
@dma_channels.timer_overflow timer @dma_channels.timer_overflow timer
end end
def read_io(io_addr : Int) : UInt8 def [](io_addr : Int) : UInt8
case io_addr case io_addr
when @channel1 then @channel1.read_io io_addr when @channel1 then @channel1[io_addr]
when @channel2 then @channel2.read_io io_addr when @channel2 then @channel2[io_addr]
when @channel3 then @channel3.read_io io_addr when @channel3 then @channel3[io_addr]
when @channel4 then @channel4.read_io io_addr when @channel4 then @channel4[io_addr]
when @dma_channels then @dma_channels.read_io io_addr when @dma_channels then @dma_channels[io_addr]
when 0x80 then @soundcnt_l.value.to_u8! when 0x80 then @soundcnt_l.value.to_u8!
when 0x81 then (@soundcnt_l.value >> 8).to_u8! when 0x81 then (@soundcnt_l.value >> 8).to_u8!
when 0x82 then @soundcnt_h.value.to_u8! when 0x82 then @soundcnt_h.value.to_u8!
@ -162,21 +162,21 @@ module GBA
end end
# write to apu memory # write to apu memory
def write_io(io_addr : Int, value : UInt8) : Nil def []=(io_addr : Int, value : UInt8) : Nil
return unless @sound_enabled || 0x82 <= io_addr <= 0x89 || Channel3::WAVE_RAM_RANGE.includes?(io_addr) return unless @sound_enabled || 0x82 <= io_addr <= 0x89 || Channel3::WAVE_RAM_RANGE.includes?(io_addr)
case io_addr case io_addr
when @channel1 then @channel1.write_io io_addr, value when @channel1 then @channel1[io_addr] = value
when @channel2 then @channel2.write_io io_addr, value when @channel2 then @channel2[io_addr] = value
when @channel3 then @channel3.write_io io_addr, value when @channel3 then @channel3[io_addr] = value
when @channel4 then @channel4.write_io io_addr, value when @channel4 then @channel4[io_addr] = value
when @dma_channels then @dma_channels.write_io io_addr, value when @dma_channels then @dma_channels[io_addr] = value
when 0x80 then @soundcnt_l.value = (@soundcnt_l.value & 0xFF00) | 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 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 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 0x83 then @soundcnt_h.value = (@soundcnt_h.value & 0x00FF) | value.to_u16 << 8
when 0x84 when 0x84
if value & 0x80 == 0 && @sound_enabled if value & 0x80 == 0 && @sound_enabled
(0x60..0x81).each { |addr| self.write_io addr, 0x00 } (0x60..0x81).each { |addr| self[addr] = 0x00 }
@sound_enabled = false @sound_enabled = false
elsif value & 0x80 > 0 && !@sound_enabled elsif value & 0x80 > 0 && !@sound_enabled
@sound_enabled = true @sound_enabled = true

View file

@ -42,8 +42,8 @@ module GBA
abstract def get_amplitude : Int16 abstract def get_amplitude : Int16
abstract def read_io(index : Int) : UInt8 abstract def [](index : Int) : UInt8
abstract def write_io(index : Int, value : UInt8) : Nil abstract def []=(index : Int, value : UInt8) : Nil
end end
abstract class VolumeEnvelopeChannel < SoundChannel abstract class VolumeEnvelopeChannel < SoundChannel

View file

@ -77,7 +77,7 @@ module GBA
calculated calculated
end end
def read_io(index : Int) : UInt8 def [](index : Int) : UInt8
case index case index
when 0x60 then 0x80_u8 | @sweep_period << 4 | (@negate ? 0x08 : 0) | @shift when 0x60 then 0x80_u8 | @sweep_period << 4 | (@negate ? 0x08 : 0) | @shift
when 0x62 then 0x3F_u8 | @duty << 6 when 0x62 then 0x3F_u8 | @duty << 6
@ -88,7 +88,7 @@ module GBA
end end
end end
def write_io(index : Int, value : UInt8) : Nil def []=(index : Int, value : UInt8) : Nil
case index case index
when 0x60 when 0x60
@sweep_period = (value & 0x70) >> 4 @sweep_period = (value & 0x70) >> 4

View file

@ -43,7 +43,7 @@ module GBA
end end
end end
def read_io(index : Int) : UInt8 def [](index : Int) : UInt8
case index case index
when 0x68 then 0x3F_u8 | @duty << 6 when 0x68 then 0x3F_u8 | @duty << 6
when 0x69 then read_NRx2 when 0x69 then read_NRx2
@ -53,7 +53,7 @@ module GBA
end end
end end
def write_io(index : Int, value : UInt8) : Nil def []=(index : Int, value : UInt8) : Nil
case index case index
when 0x68 when 0x68
@duty = (value & 0xC0) >> 6 @duty = (value & 0xC0) >> 6

View file

@ -49,7 +49,7 @@ module GBA
end end
end end
def read_io(index : Int) : UInt8 def [](index : Int) : UInt8
case index case index
when 0x70 then 0x7F_u8 | (@dac_enabled ? 0x80 : 0) when 0x70 then 0x7F_u8 | (@dac_enabled ? 0x80 : 0)
when 0x72 then 0xFF_u8 when 0x72 then 0xFF_u8
@ -66,7 +66,7 @@ module GBA
end end
end end
def write_io(index : Int, value : UInt8) : Nil def []=(index : Int, value : UInt8) : Nil
case index case index
when 0x70 when 0x70
@dac_enabled = value & 0x80 > 0 @dac_enabled = value & 0x80 > 0

View file

@ -43,7 +43,7 @@ module GBA
end end
end end
def read_io(index : Int) : UInt8 def [](index : Int) : UInt8
case index case index
when 0x78 then 0xFF_u8 when 0x78 then 0xFF_u8
when 0x79 then read_NRx2 when 0x79 then read_NRx2
@ -53,7 +53,7 @@ module GBA
end end
end end
def write_io(index : Int, value : UInt8) : Nil def []=(index : Int, value : UInt8) : Nil
case index case index
when 0x78 when 0x78
@length_load = value & 0x3F @length_load = value & 0x3F

View file

@ -19,11 +19,11 @@ module GBA
] ]
end end
def read_io(index : Int) : UInt8 def [](index : Int) : UInt8
0_u8 0_u8
end end
def write_io(index : Int, value : Byte) : Nil def []=(index : Int, value : Byte) : Nil
channel = bit?(index, 2).to_unsafe channel = bit?(index, 2).to_unsafe
if @sizes[channel] < 32 if @sizes[channel] < 32
@fifos[channel][(@positions[channel] + @sizes[channel]) % 32] = value.to_i8! @fifos[channel][(@positions[channel] + @sizes[channel]) % 32] = value.to_i8!

View file

@ -41,7 +41,7 @@ module GBA
->{ @gba.interrupts.reg_if.dma2 = true }, ->{ @gba.interrupts.reg_if.dma3 = true }] ->{ @gba.interrupts.reg_if.dma2 = true }, ->{ @gba.interrupts.reg_if.dma3 = true }]
end end
def read_io(io_addr : Int) : UInt8 def [](io_addr : Int) : UInt8
return 0_u8 if io_addr >= 0xE0 # todo: OOB read return 0_u8 if io_addr >= 0xE0 # todo: OOB read
channel = (io_addr - 0xB0) // 12 channel = (io_addr - 0xB0) // 12
reg = (io_addr - 0xB0) % 12 reg = (io_addr - 0xB0) % 12
@ -58,7 +58,7 @@ module GBA
end end
end end
def write_io(io_addr : Int, value : UInt8) : Nil def []=(io_addr : Int, value : UInt8) : Nil
return if io_addr >= 0xE0 # todo: OOB write return if io_addr >= 0xE0 # todo: OOB write
channel = (io_addr - 0xB0) // 12 channel = (io_addr - 0xB0) // 12
reg = (io_addr - 0xB0) % 12 reg = (io_addr - 0xB0) % 12

View file

@ -25,7 +25,7 @@ module GBA
def initialize(@gba : GBA) def initialize(@gba : GBA)
end end
def read_io(io_addr : Int) : Byte def [](io_addr : Int) : Byte
case io_addr case io_addr
when 0x200 then 0xFF_u8 & @reg_ie.value when 0x200 then 0xFF_u8 & @reg_ie.value
when 0x201 then 0xFF_u8 & @reg_ie.value >> 8 when 0x201 then 0xFF_u8 & @reg_ie.value >> 8
@ -37,7 +37,7 @@ module GBA
end end
end end
def write_io(io_addr : Int, value : Byte) : Nil def []=(io_addr : Int, value : Byte) : Nil
case io_addr case io_addr
when 0x200 then @reg_ie.value = (@reg_ie.value & 0xFF00) | value when 0x200 then @reg_ie.value = (@reg_ie.value & 0xFF00) | value
when 0x201 then @reg_ie.value = (@reg_ie.value & 0x00FF) | value.to_u16 << 8 when 0x201 then @reg_ie.value = (@reg_ie.value & 0x00FF) | value.to_u16 << 8

View file

@ -36,7 +36,7 @@ module GBA
def initialize(@gba : GBA) def initialize(@gba : GBA)
end end
def read_io(io_addr : Int) : Byte def [](io_addr : Int) : Byte
case io_addr case io_addr
when 0x130 then 0xFF_u8 & @keyinput.value when 0x130 then 0xFF_u8 & @keyinput.value
when 0x131 then 0xFF_u8 & @keyinput.value >> 8 when 0x131 then 0xFF_u8 & @keyinput.value >> 8
@ -46,7 +46,7 @@ module GBA
end end
end end
def write_io(io_addr : Int, value : Byte) : Nil def []=(io_addr : Int, value : Byte) : Nil
case io_addr case io_addr
when 0x130 then nil when 0x130 then nil
when 0x131 then nil when 0x131 then nil

View file

@ -22,15 +22,15 @@ module GBA
def [](index : Int) : Byte def [](index : Int) : Byte
io_addr = 0xFFFFFF_u32 & index io_addr = 0xFFFFFF_u32 & index
if io_addr <= 0x05F if io_addr <= 0x05F
@gba.ppu.read_io io_addr @gba.ppu[io_addr]
elsif io_addr <= 0xAF elsif io_addr <= 0xAF
@gba.apu.read_io io_addr @gba.apu[io_addr]
elsif io_addr <= 0xFF elsif io_addr <= 0xFF
@gba.dma.read_io io_addr @gba.dma[io_addr]
elsif 0x100 <= io_addr <= 0x10F elsif 0x100 <= io_addr <= 0x10F
@gba.timer.read_io io_addr @gba.timer[io_addr]
elsif 0x130 <= io_addr <= 0x133 elsif 0x130 <= io_addr <= 0x133
@gba.keypad.read_io io_addr @gba.keypad[io_addr]
elsif 0x120 <= io_addr <= 0x12F || 0x134 <= io_addr <= 0x1FF elsif 0x120 <= io_addr <= 0x12F || 0x134 <= io_addr <= 0x1FF
# todo: serial # todo: serial
if io_addr == 0x135 if io_addr == 0x135
@ -39,7 +39,7 @@ module GBA
0_u8 0_u8
end end
elsif 0x200 <= io_addr <= 0x203 || 0x208 <= io_addr <= 0x209 elsif 0x200 <= io_addr <= 0x203 || 0x208 <= io_addr <= 0x209
@gba.interrupts.read_io io_addr @gba.interrupts[io_addr]
elsif 0x204 <= io_addr <= 0x205 elsif 0x204 <= io_addr <= 0x205
(@waitcnt.value >> (8 * (io_addr & 1))).to_u8! (@waitcnt.value >> (8 * (io_addr & 1))).to_u8!
else else
@ -50,19 +50,19 @@ module GBA
def []=(index : Int, value : Byte) : Nil def []=(index : Int, value : Byte) : Nil
io_addr = 0xFFFFFF_u32 & index io_addr = 0xFFFFFF_u32 & index
if io_addr <= 0x05F if io_addr <= 0x05F
@gba.ppu.write_io io_addr, value @gba.ppu[io_addr] = value
elsif io_addr <= 0xAF elsif io_addr <= 0xAF
@gba.apu.write_io io_addr, value @gba.apu[io_addr] = value
elsif io_addr <= 0xFF elsif io_addr <= 0xFF
@gba.dma.write_io io_addr, value @gba.dma[io_addr] = value
elsif 0x100 <= io_addr <= 0x10F elsif 0x100 <= io_addr <= 0x10F
@gba.timer.write_io io_addr, value @gba.timer[io_addr] = value
elsif 0x130 <= io_addr <= 0x133 elsif 0x130 <= io_addr <= 0x133
@gba.keypad.read_io io_addr @gba.keypad[io_addr]
elsif 0x120 <= io_addr <= 0x12F || 0x134 <= io_addr <= 0x1FF elsif 0x120 <= io_addr <= 0x12F || 0x134 <= io_addr <= 0x1FF
# todo: serial # todo: serial
elsif 0x200 <= io_addr <= 0x203 || 0x208 <= io_addr <= 0x209 elsif 0x200 <= io_addr <= 0x203 || 0x208 <= io_addr <= 0x209
@gba.interrupts.write_io io_addr, value @gba.interrupts[io_addr] = value
elsif 0x204 <= io_addr <= 0x205 elsif 0x204 <= io_addr <= 0x205
shift = 8 * (io_addr & 1) shift = 8 * (io_addr & 1)
mask = 0xFF00_u16 >> shift mask = 0xFF00_u16 >> shift

View file

@ -385,7 +385,7 @@ module GBA
end end
end end
def read_io(io_addr : Int) : Byte def [](io_addr : Int) : Byte
case io_addr case io_addr
when 0x000..0x001 then @dispcnt.read_byte(io_addr & 1) when 0x000..0x001 then @dispcnt.read_byte(io_addr & 1)
when 0x002..0x003 then 0_u8 # todo green swap when 0x002..0x003 then 0_u8 # todo green swap
@ -422,7 +422,7 @@ module GBA
end end
end end
def write_io(io_addr : Int, value : Byte) : Nil def []=(io_addr : Int, value : Byte) : Nil
case io_addr case io_addr
when 0x000..0x001 then @dispcnt.write_byte(io_addr & 1, value) when 0x000..0x001 then @dispcnt.write_byte(io_addr & 1, value)
when 0x002..0x003 # undocumented - green swap when 0x002..0x003 # undocumented - green swap

View file

@ -51,7 +51,7 @@ module GBA
@cycle_enabled[num] = @gba.scheduler.cycles @cycle_enabled[num] = @gba.scheduler.cycles
end end
def read_io(io_addr : Int) : UInt8 def [](io_addr : Int) : UInt8
num = (io_addr & 0xF) // 4 num = (io_addr & 0xF) // 4
value = if bit?(io_addr, 1) value = if bit?(io_addr, 1)
@tmcnt[num].value @tmcnt[num].value
@ -62,7 +62,7 @@ module GBA
value.to_u8! value.to_u8!
end end
def write_io(io_addr : Int, value : UInt8) : Nil def []=(io_addr : Int, value : UInt8) : Nil
num = (io_addr & 0xF) // 4 num = (io_addr & 0xF) // 4
high = bit?(io_addr, 0) high = bit?(io_addr, 0)
mask = 0xFF00_u16 mask = 0xFF00_u16