Class: Rubyboy::Bus
- Inherits:
-
Object
- Object
- Rubyboy::Bus
- Defined in:
- lib/rubyboy/bus.rb
Instance Method Summary collapse
-
#initialize(ppu, rom, ram, mbc, timer, interrupt, joypad, apu) ⇒ Bus
constructor
A new instance of Bus.
- #read_byte(addr) ⇒ Object
- #read_word(addr) ⇒ Object
- #write_byte(addr, value) ⇒ Object
- #write_word(addr, value) ⇒ Object
Constructor Details
#initialize(ppu, rom, ram, mbc, timer, interrupt, joypad, apu) ⇒ Bus
Returns a new instance of Bus.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rubyboy/bus.rb', line 5 def initialize(ppu, rom, ram, mbc, timer, interrupt, joypad, apu) @ppu = ppu @rom = rom @ram = ram @mbc = mbc @joypad = joypad @apu = apu @interrupt = interrupt @timer = timer end |
Instance Method Details
#read_byte(addr) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubyboy/bus.rb', line 16 def read_byte(addr) case addr >> 12 when 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xa, 0xb return @mbc.read_byte(addr) when 0x8, 0x9 return @ppu.read_byte(addr) when 0xc return @ram.wram1[addr - 0xc000] when 0xd return @ram.wram2[addr - 0xd000] when 0xf case addr >> 8 when 0xfe return @ppu.read_byte(addr) if addr <= 0xfe9f when 0xff last_byte = addr & 0xFF case last_byte when 0x00 return @joypad.read_byte(addr) when 0x04, 0x05, 0x06, 0x07 return @timer.read_byte(addr) when 0x0f return @interrupt.read_byte(addr) when 0x46 return @ppu.read_byte(addr) when 0xff return @interrupt.read_byte(addr) end return @apu.read_byte(addr) if last_byte <= 0x26 && last_byte >= 0x10 return @apu.read_byte(addr) if last_byte <= 0x3f && last_byte >= 0x30 return @ppu.read_byte(addr) if last_byte <= 0x4b && last_byte >= 0x40 return @ram.hram[addr - 0xff80] if last_byte <= 0xfe && last_byte >= 0x80 end end 0xff end |
#read_word(addr) ⇒ Object
103 104 105 |
# File 'lib/rubyboy/bus.rb', line 103 def read_word(addr) read_byte(addr) + (read_byte(addr + 1) << 8) end |
#write_byte(addr, value) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rubyboy/bus.rb', line 59 def write_byte(addr, value) case addr >> 12 when 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0xa, 0xb return @mbc.write_byte(addr, value) when 0x8, 0x9 return @ppu.write_byte(addr, value) when 0xc return @ram.wram1[addr - 0xc000] = value when 0xd return @ram.wram2[addr - 0xd000] = value when 0xf case addr >> 8 when 0xfe return @ppu.write_byte(addr, value) if addr <= 0xfe9f when 0xff last_byte = addr & 0xFF case last_byte when 0x00 return @joypad.write_byte(addr, value) when 0x04, 0x05, 0x06, 0x07 return @timer.write_byte(addr, value) when 0x0f return @interrupt.write_byte(addr, value) when 0x46 0xa0.times { |i| write_byte(0xfe00 + i, read_byte((value << 8) + i)) } return when 0xff return @interrupt.write_byte(addr, value) end return @apu.write_byte(addr, value) if last_byte <= 0x26 && last_byte >= 0x10 return @apu.write_byte(addr, value) if last_byte <= 0x3f && last_byte >= 0x30 return @ppu.write_byte(addr, value) if last_byte <= 0x4b && last_byte >= 0x40 return @ram.hram[addr - 0xff80] = value if last_byte <= 0xfe && last_byte >= 0x80 end end nil end |
#write_word(addr, value) ⇒ Object
107 108 109 110 |
# File 'lib/rubyboy/bus.rb', line 107 def write_word(addr, value) write_byte(addr, value & 0xff) write_byte(addr + 1, value >> 8) end |