Class: Badline::VIC::Bank

Inherits:
Object
  • Object
show all
Includes:
Addressable
Defined in:
lib/badline/vic/bank.rb

Overview

The 16K window the VIC sees into RAM, selected by CIA2 $DD00. Character ROM shadows $1000-$1FFF in banks 0 and 2.

Constant Summary collapse

BANK_STARTS =

The CIA2 port A bank bits are inverted: %11 selects bank 0.

[0xc000, 0x8000, 0x4000, 0x0000].freeze

Instance Attribute Summary collapse

Attributes included from Addressable

#end, #length

Instance Method Summary collapse

Methods included from Addressable

#[], #[]=, #addressable_at, #in_range?, #peek16, #poke16, #range

Methods included from IntegerHelper

#bcd, #bcd_to_i, #format16, #format8, #high_byte, #low_byte, #signed_int8, #uint16

Constructor Details

#initialize(address_bus = nil) ⇒ Bank

Returns a new instance of Bank.



15
16
17
18
# File 'lib/badline/vic/bank.rb', line 15

def initialize(address_bus = nil)
  addressable_at(0x0000, length: 2**14)
  @address_bus = address_bus || AddressBus.new
end

Instance Attribute Details

#address_busObject (readonly)

Returns the value of attribute address_bus.



13
14
15
# File 'lib/badline/vic/bank.rb', line 13

def address_bus
  @address_bus
end

Instance Method Details

#peek(offset) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/badline/vic/bank.rb', line 20

def peek(offset)
  return ultimax_peek(offset) if @address_bus.ultimax

  bits = bank_switch_register
  if bits.allbits?(0b01) && (offset & 0xf000) == 0x1000
    @address_bus.character_rom.peek(0xc000 + offset)
  else
    @address_bus.ram.peek(BANK_STARTS[bits] + offset)
  end
end

#peek_color(offset) ⇒ Object



31
32
33
# File 'lib/badline/vic/bank.rb', line 31

def peek_color(offset)
  address_bus.color_ram.peek(0xd800 + offset) & 0x0f
end

#poke(_addr, _value) ⇒ Object



35
36
37
# File 'lib/badline/vic/bank.rb', line 35

def poke(_addr, _value)
  raise ReadOnlyMemoryError
end

#startObject



39
40
41
# File 'lib/badline/vic/bank.rb', line 39

def start
  BANK_STARTS[bank_switch_register]
end