mirror of
https://github.com/colby-swandale/waterfoul
synced 2024-12-25 21:58:55 +01:00
implement mbc3 functionality
This commit is contained in:
parent
b0d024108a
commit
b95a41520c
1 changed files with 42 additions and 5 deletions
|
@ -1,14 +1,51 @@
|
|||
module Waterfoul
|
||||
module MBC
|
||||
class MBC3
|
||||
def self.[](i)
|
||||
fail
|
||||
def initialize(program)
|
||||
@game_program = program
|
||||
@ram_bank = 0
|
||||
@rom_bank = 0
|
||||
@ram_enable = false
|
||||
end
|
||||
|
||||
def self.[]=(i,v)
|
||||
fail
|
||||
def [](i)
|
||||
case i
|
||||
when 0x0...0x4000 # ROM Bank 0
|
||||
@game_program[i]
|
||||
when 0x4000...0x8000 # ROM Bank n
|
||||
addr = i - 0x4000
|
||||
offset = @rom_bank * 0x4000
|
||||
@game_program[offset + addr]
|
||||
when 0xA000...0xC000
|
||||
if @ram_enabled
|
||||
addr = i - 0xA000
|
||||
if @ram_bank == 0
|
||||
@ram[addr]
|
||||
else
|
||||
offset = @ram_bank * 0x8000
|
||||
@ram[offset + addr]
|
||||
end
|
||||
else
|
||||
0xFF
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def []=(i,v)
|
||||
case i
|
||||
when 0x0...0x2000
|
||||
@ram_enable = (v & 0xA == 0xA ? true : false)
|
||||
when 0x2000...0x4000
|
||||
@rom_bank = (v & 0x7F)
|
||||
@rom_bank += 1 if @rom_bank == 0
|
||||
when 0x4000...0x6000
|
||||
if v <= 0x3
|
||||
@ram_bank = (v & 0x3)
|
||||
#elsif (0x8..0xC) === v
|
||||
end
|
||||
when 0x6000...0x8000
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue