Class: Badline::VIC::Sequencer

Inherits:
Object
  • Object
show all
Defined in:
lib/badline/vic/sequencer.rb

Overview

VIC-II Sequencer

Turns fetched graphics data into output pixels.

Constant Summary collapse

DISPLAY_X_BOUNDS =
[
  [135, 438].freeze,
  [128, 447].freeze
].freeze
GFX_X_START =

The graphics window always spans the full 40 columns, ignoring CSEL.

GFX_X_END =
DISPLAY_X_BOUNDS[1][1] + 1
WINDOW_COMPARES =
left compare, right compare

for the border flip-flop per CSEL state.

[
  [DISPLAY_X_BOUNDS[0][0], DISPLAY_X_BOUNDS[0][1] + 1].freeze,
  [GFX_X_START, GFX_X_END].freeze
].freeze
BORDER_Y_BOUNDS =
[
  [55, 247].freeze,
  [51, 251].freeze
].freeze
BORDER_FULL =

Border coverage per 8-pixel group, tracked so apply_border can skip window groups and bulk-fill full border groups.

0
BORDER_NONE =
1
BORDER_MIXED =
2
NULL_MODE =
GraphicsMode::Null.new
MODES =
[
  GraphicsMode::Text.new,                   # 000 standard text
  GraphicsMode::MulticolorText.new,         # 001 multicolour text
  GraphicsMode::Bitmap.new,                 # 010 standard bitmap
  GraphicsMode::MulticolorBitmap.new,       # 011 multicolour bitmap
  GraphicsMode::ExtendedBackgroundText.new, # 100 ECM text
  NULL_MODE,                                # 101 invalid
  NULL_MODE,                                # 110 invalid
  NULL_MODE                                 # 111 invalid
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, registers, bank) ⇒ Sequencer

Returns a new instance of Sequencer.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/badline/vic/sequencer.rb', line 54

def initialize(width, registers, bank)
  @width = width
  @registers = registers
  @bank = bank
  @colors = Array.new(width, 0)
  @fg = Array.new(width, false)
  @border = Array.new(width, true)
  @border_groups = Array.new(width / 8, BORDER_FULL)
  @cur_colors = Array.new(8, 0)
  @cur_fg = GraphicsMode::NO_FG
  @prev_colors = Array.new(8, 0)
  @prev_fg = GraphicsMode::NO_FG
  @vertical_border = true
  @main_border = true
  new_line(0)
end

Instance Attribute Details

#bankObject (readonly)

Returns the value of attribute bank.



49
50
51
# File 'lib/badline/vic/sequencer.rb', line 49

def bank
  @bank
end

#borderObject (readonly)

Returns the value of attribute border.



49
50
51
# File 'lib/badline/vic/sequencer.rb', line 49

def border
  @border
end

#colorsObject (readonly)

Returns the value of attribute colors.



49
50
51
# File 'lib/badline/vic/sequencer.rb', line 49

def colors
  @colors
end

#cur_colorsObject (readonly)

Returns the value of attribute cur_colors.



49
50
51
# File 'lib/badline/vic/sequencer.rb', line 49

def cur_colors
  @cur_colors
end

#cur_fgObject

The fg masks are shared frozen patterns assigned by reference, never mutated in place.



52
53
54
# File 'lib/badline/vic/sequencer.rb', line 52

def cur_fg
  @cur_fg
end

#fgObject (readonly)

Returns the value of attribute fg.



49
50
51
# File 'lib/badline/vic/sequencer.rb', line 49

def fg
  @fg
end

#registersObject (readonly)

Returns the value of attribute registers.



49
50
51
# File 'lib/badline/vic/sequencer.rb', line 49

def registers
  @registers
end

Instance Method Details

#apply_borderObject

Repaint the border over the composited line, hiding the sprites.



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/badline/vic/sequencer.rb', line 83

def apply_border
  color = @registers.border
  group = 0
  while group < @border_groups.length
    case @border_groups[group]
    when BORDER_FULL then @colors.fill(color, group * 8, 8)
    when BORDER_MIXED then paint_mixed_border(color, group * 8)
    end
    group += 1
  end
end

#emit(screencode, color, col, cell, row) ⇒ Object



95
96
97
98
99
# File 'lib/badline/vic/sequencer.rb', line 95

def emit(screencode, color, col, cell, row)
  MODES[@registers.mode].decode(screencode, color, cell, row, self)
  output(col)
  roll
end

#emit_idle(col) ⇒ Object



101
102
103
104
105
106
# File 'lib/badline/vic/sequencer.rb', line 101

def emit_idle(col)
  @cur_colors.fill(@registers.background)
  @cur_fg = GraphicsMode::NO_FG
  output(col)
  roll
end

#new_line(line) ⇒ Object

Reset the line buffers at the start of a rasterline and re-evaluate the vertical border flip-flop.



73
74
75
76
77
78
79
80
# File 'lib/badline/vic/sequencer.rb', line 73

def new_line(line)
  update_vertical_border(line)
  @colors.fill(@registers.border)
  @fg.fill(false)
  @border_groups.fill(BORDER_FULL)
  @prev_colors.fill(@registers.background)
  @prev_fg = GraphicsMode::NO_FG
end