Class: Badline::AddressBus

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

Overview

Overlays:

0x8000-0x9FFF - Cartridge ROM (low) - 8kb 0xA000-0xBFFF - BASIC ROM / Cartridge ROM (high) - 8kb 0xD000-0xDFFF - Character ROM / I/O - 4kb 0xE000-0xFFFF - KERNAL ROM / Cartridge ROM (high) - 8kb

Defined Under Namespace

Modules: OpenSpace

Constant Summary collapse

PORT_PULLUPS =
0b0001_0111
PORT_FLOATING =
0b1100_1000

Instance Attribute Summary collapse

Attributes included from Addressable

#end, #length, #start

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

#initializeAddressBus

Returns a new instance of AddressBus.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/badline/address_bus.rb', line 47

def initialize
  @ram = Memory.new([0xff, 0x07], length: 2**16, start: 0)
  @cartridge = nil

  @basic_rom     = ROM.load("basic.rom",     0xa000)
  @character_rom = ROM.load("character.rom", 0xd000)
  @kernal_rom    = ROM.load("kernal.rom",    0xe000)

  @keyboard = Keyboard.new
  @joystick2 = Joystick.new
  @vic  = VIC.new(self)
  @cia1 = CIA.new(
    start: 0xdc00,
    peripheral: ControlPorts.new(keyboard: @keyboard, joystick2: @joystick2)
  )
  @cia2 = CIA.new(start: 0xdd00)
  @sid  = SID.new

  @color_ram = ColorMemory.new(start: 0xd800, length: 2**10)

  @port_ddr = 0x2f
  @port_out = 0x37
  @port_floating = 0x00
  @io_port = Status.new(%i[basic kernal io tape_out tape_switch tape_motor], value: port_value)

  @read_pages = Array.new(256)
  @write_pages = Array.new(256)
  update_overlays!
end

Instance Attribute Details

#basic_romObject (readonly)

Returns the value of attribute basic_rom.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def basic_rom
  @basic_rom
end

#cartridgeObject (readonly)

Returns the value of attribute cartridge.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def cartridge
  @cartridge
end

#character_romObject (readonly)

Returns the value of attribute character_rom.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def character_rom
  @character_rom
end

#cia1Object (readonly)

Returns the value of attribute cia1.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def cia1
  @cia1
end

#cia2Object (readonly)

Returns the value of attribute cia2.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def cia2
  @cia2
end

#color_ramObject (readonly)

Returns the value of attribute color_ram.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def color_ram
  @color_ram
end

#io_portObject (readonly)

Returns the value of attribute io_port.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def io_port
  @io_port
end

#joystick2Object (readonly)

Returns the value of attribute joystick2.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def joystick2
  @joystick2
end

#kernal_romObject (readonly)

Returns the value of attribute kernal_rom.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def kernal_rom
  @kernal_rom
end

#keyboardObject (readonly)

Returns the value of attribute keyboard.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def keyboard
  @keyboard
end

#ramObject (readonly)

Returns the value of attribute ram.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def ram
  @ram
end

#sidObject (readonly)

Returns the value of attribute sid.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def sid
  @sid
end

#ultimaxObject (readonly)

Returns the value of attribute ultimax.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def ultimax
  @ultimax
end

#vicObject (readonly)

Returns the value of attribute vic.



43
44
45
# File 'lib/badline/address_bus.rb', line 43

def vic
  @vic
end

Instance Method Details

#attach_cartridge(cartridge) ⇒ Object



77
78
79
80
81
# File 'lib/badline/address_bus.rb', line 77

def attach_cartridge(cartridge)
  @cartridge = cartridge
  cartridge.on_change { update_overlays! }
  update_overlays!
end

#disable_overlays!Object



83
84
85
# File 'lib/badline/address_bus.rb', line 83

def disable_overlays!
  poke(1, 0)
end

#inspectObject



103
104
105
106
107
# File 'lib/badline/address_bus.rb', line 103

def inspect
  "#<#{self.class.name} port=#{format('0x%02x', @io_port.value)} " \
    "cartridge=#{@cartridge ? @cartridge.class.name : 'none'} " \
    "ultimax=#{@ultimax}>"
end

#peek(addr) ⇒ Object



87
88
89
90
91
92
# File 'lib/badline/address_bus.rb', line 87

def peek(addr)
  return @port_ddr if addr.zero?
  return @io_port.value if addr == 0x01

  @read_pages[addr >> 8].peek(addr)
end

#poke(addr, value) ⇒ Object



94
95
96
97
98
99
100
101
# File 'lib/badline/address_bus.rb', line 94

def poke(addr, value)
  if addr < 0x02
    addr.zero? ? @port_ddr = value : @port_out = value
    update_port!
  else
    @write_pages[addr >> 8].poke(addr, value)
  end
end