| 1 |
;ACME 0.95 |
| 2 |
|
| 3 |
!ifdef lib_cbm_c128_vdc_a !eof |
| 4 |
lib_cbm_c128_vdc_a = 1 |
| 5 |
|
| 6 |
; there are three different versions of the C128's Video Display Controller: |
| 7 |
; v0: VDC 8563 R7A in C128 and C128-D |
| 8 |
; v1: VDC 8563 R8/R9 in C128 and C128-D |
| 9 |
; v2: VDC 8568 in C128-DCR |
| 10 |
; 8563 and 8568 have different pinouts, so do not try to use one of them on a |
| 11 |
; board intended for the other! |
| 12 |
|
| 13 |
|
| 14 |
; hardware differences: |
| 15 |
|
| 16 |
; the 8563 uses external circuitry to convert RGBIHV to monochrome/luminance. |
| 17 |
; the 8568 does a part of this internally and therefore needs fewer external |
| 18 |
; components. |
| 19 |
|
| 20 |
; the 8568 has an additional register (r37) to change sync polarities. |
| 21 |
|
| 22 |
|
| 23 |
; software differences: |
| 24 |
|
| 25 |
; the horizontal scroll bits of r25 differ between v0 and v1/v2: in v0, set these |
| 26 |
; bits to zero. in v1/v2, set these bits to the same value as bits4-7 of r22. |
| 27 |
; the additional register r37 can be ignored (as the C128 kernal does). |
| 28 |
|
| 29 |
|
| 30 |
; access macros: |
| 31 |
|
| 32 |
!macro vdc_lda { |
| 33 |
- bit vdc_state |
| 34 |
bpl - |
| 35 |
lda vdc_data |
| 36 |
} |
| 37 |
|
| 38 |
!macro vdc_sta { |
| 39 |
- bit vdc_state |
| 40 |
bpl - |
| 41 |
sta vdc_data |
| 42 |
} |
| 43 |
|
| 44 |
!macro vdc_ldx { |
| 45 |
- bit vdc_state |
| 46 |
bpl - |
| 47 |
ldx vdc_data |
| 48 |
} |
| 49 |
|
| 50 |
!macro vdc_stx { |
| 51 |
- bit vdc_state |
| 52 |
bpl - |
| 53 |
stx vdc_data |
| 54 |
} |
| 55 |
|
| 56 |
!macro vdc_ldy { |
| 57 |
- bit vdc_state |
| 58 |
bpl - |
| 59 |
ldy vdc_data |
| 60 |
} |
| 61 |
|
| 62 |
!macro vdc_sty { |
| 63 |
- bit vdc_state |
| 64 |
bpl - |
| 65 |
sty vdc_data |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
; color codes: |
| 70 |
|
| 71 |
; These are the colors officially available on the C128 - the same names as if |
| 72 |
; using a C64's VIC, but different codes of course. |
| 73 |
|
| 74 |
; color name RGBI VIC equivalent |
| 75 |
vdccolor_BLACK = %.... ; 0 |
| 76 |
vdccolor_WHITE = %#### ; 15 |
| 77 |
vdccolor_RED = %#... ; 8 |
| 78 |
vdccolor_CYAN = %.### ; 7 |
| 79 |
vdccolor_PURPLE = %#.## ; 11 |
| 80 |
vdccolor_GREEN = %.#.. ; 4 |
| 81 |
vdccolor_BLUE = %..#. ; 2 |
| 82 |
vdccolor_YELLOW = %##.# ; 13 |
| 83 |
vdccolor_ORANGE = %#.#. ; 10 (on VDC, this is in fact a dark shade of purple) |
| 84 |
vdccolor_BROWN = %##.. ; 12 |
| 85 |
vdccolor_LRED = %#..# ; 9 |
| 86 |
vdccolor_GRAY1 = %.##. ; 6 (on VDC, this is in fact a dark shade of cyan) |
| 87 |
vdccolor_GRAY2 = %...# ; 1 (this is almost, but not quite, entirely black) |
| 88 |
vdccolor_LGREEN = %.#.# ; 5 |
| 89 |
vdccolor_LBLUE = %..## ; 3 |
| 90 |
vdccolor_GRAY3 = %###. ; 14 |
| 91 |
|
| 92 |
; The following alternative names are much easier to remember when you're used |
| 93 |
; to writing programs for the VDC: There are eight main colors, and each one is |
| 94 |
; available in a light and a dark shade - even black and white! |
| 95 |
|
| 96 |
; primary colors RGBI code |
| 97 |
vdccolor_DRED = %#... |
| 98 |
vdccolor_DGREEN = %.#.. |
| 99 |
vdccolor_DBLUE = %..#. |
| 100 |
vdccolor_LRED = %#..# |
| 101 |
vdccolor_LGREEN = %.#.# |
| 102 |
vdccolor_LBLUE = %..## |
| 103 |
|
| 104 |
; secondary colors RGBI code |
| 105 |
vdccolor_LCYAN = %.### |
| 106 |
vdccolor_LMAGENTA = %#.## |
| 107 |
vdccolor_LYELLOW = %##.# |
| 108 |
vdccolor_DCYAN = %.##. |
| 109 |
vdccolor_DMAGENTA = %#.#. |
| 110 |
vdccolor_DYELLOW = %##.. |
| 111 |
|
| 112 |
; black & white RGBI code |
| 113 |
vdccolor_DBLACK = %.... |
| 114 |
vdccolor_LBLACK = %...# |
| 115 |
vdccolor_LWHITE = %#### |
| 116 |
vdccolor_DWHITE = %###. |
| 117 |
|
| 118 |
; if you don't like the concept of shaded black/white, then use these: |
| 119 |
|
| 120 |
; gray level RGBI code |
| 121 |
vdccolor_BLACK = %.... ; "dark black" => "black" |
| 122 |
vdccolor_DGRAY = %...# ; "light black" => "dark grey" |
| 123 |
vdccolor_LGRAY = %###. ; "dark white" => "light grey" |
| 124 |
vdccolor_WHITE = %#### ; "light white" => "white" |
| 125 |
|
| 126 |
|
| 127 |
; attribute flags (2rufRGBI) |
| 128 |
vdcattr_2ND = %#....... ; second character set |
| 129 |
vdcattr_REVS = %.#...... ; reverse mode |
| 130 |
vdcattr_UL = %..#..... ; underline |
| 131 |
vdcattr_FLASH = %...#.... ; flash |
| 132 |
vdcattr_R = %....#... ; red |
| 133 |
vdcattr_G = %.....#.. ; green |
| 134 |
vdcattr_B = %......#. ; blue |
| 135 |
vdcattr_I = %.......# ; intensity |
| 136 |
|
| 137 |
|
| 138 |
!address { |
| 139 |
; direct registers |
| 140 |
vdc_state = $d600 ; READING this location yields status flags, see below |
| 141 |
vdc_reg = $d600 ; WRITING this location selects an indirect register |
| 142 |
vdc_data = $d601 ; data of selected indirect register |
| 143 |
} |
| 144 |
; status flags in vdc_state: |
| 145 |
vdcstate_READY = %#....... ; RAM access is finished |
| 146 |
vdcstate_LIGHTPEN = %.#...... ; light pen has been activated |
| 147 |
vdcstate_IN_BORDER = %..#..... ; electron beam is in upper or lower border |
| 148 |
vdcstate_VERSIONMASK = %...##### ; vdc version (0, 1 or 2) |
| 149 |
|
| 150 |
|
| 151 |
; indirect registers (default value, see $e179 in C128 kernal) |
| 152 |
vdcr_htotal = 0 ; 126 (127 for PAL, depends on kernal version) characters per line, minus one |
| 153 |
vdcr_columns = 1 ; 80 characters per line, actually displayed |
| 154 |
vdcr_hdisp = 1 |
| 155 |
vdcr_hsync_pos = 2 ; 102 character position to send horizontal sync in |
| 156 |
vdcr_syncwidth = 3 ; $49 4b vertical, 4b horizontal |
| 157 |
vdcr_vtotal = 4 ; 32 (39 or 38 for PAL, depends on kernal version) character lines per screen, minus one |
| 158 |
vdcr_vadjust = 5 ; 0 additional scan lines per screen (to fix timings) |
| 159 |
vdcr_lines = 6 ; 25 character lines per screen, actually displayed |
| 160 |
vdcr_vdisp = 6 |
| 161 |
vdcr_vsync_pos = 7 ; 29 (32 for PAL) character line to send vertical sync in |
| 162 |
vdcr_interlace = 8 ; 0 interlace mode (0=2=std, 1=jitter, 3=interlace) |
| 163 |
vdcr_charheight_total = 9 ; 7 5b total, minus one |
| 164 |
vdcr_crsr_start = 10 ; $20 2b mode, 5b scanline (top line of cursor) |
| 165 |
vdcr_CRSRSTART_MODE_MASK = %.##..... |
| 166 |
; vdcr_CRSRSTART_MODE_FIXED = %........ ; fixed cursor |
| 167 |
vdcr_CRSRSTART_MODE_OFF = %..#..... ; invisible |
| 168 |
vdcr_CRSRSTART_MODE_FAST = %.#...... ; flashing with 1/16 of refresh freq |
| 169 |
vdcr_CRSRSTART_MODE_SLOW = %.##..... ; flashing with 1/32 of refresh freq |
| 170 |
vdcr_crsr_end = 11 ; 7 5b scanline (bottom line of cursor, plus 1, so should be 8 instead of 7!) |
| 171 |
vdcr_display_hi = 12 ; 0 RAM address of display buffer, |
| 172 |
vdcr_display_lo = 13 ; 0 see "hardscroll" notes below |
| 173 |
vdcr_crsr_hi = 14 ; 0 RAM address of cursor |
| 174 |
vdcr_crsr_lo = 15 ; 0 |
| 175 |
vdcr_lp_y = 16 ; -- y position of light pen (lines, plus 1) |
| 176 |
vdcr_lp_x = 17 ; -- x position of light pen (characters, plus 8) |
| 177 |
vdcr_ram_hi = 18 ; -- RAM address of register 31 (reading/writing r31 |
| 178 |
vdcr_ram_lo = 19 ; -- automatically increments this address) |
| 179 |
vdcr_attr_hi = 20 ; $08 RAM address of attribute buffer, |
| 180 |
vdcr_attr_lo = 21 ; $00 see "hardscroll" notes below |
| 181 |
vdcr_charwidth = 22 ; $78 4b total minus one, 4b displayed |
| 182 |
vdcr_charheight_disp = 23 ; 8 5b displayed, minus one (so 7 would suffice) |
| 183 |
vdcr_control_v = 24 ; $20 vertical scroll and much other stuff |
| 184 |
vdcr_CONTROLV_BLOCKMODE_MASK = %#....... |
| 185 |
; vdcr_CONTROLV_BLOCKMODE_WRITE = %........ ; writing to register 30 starts block write |
| 186 |
vdcr_CONTROLV_BLOCKMODE_COPY = %#....... ; writing to register 30 starts block copy |
| 187 |
vdcr_CONTROLV_REVERSESCREEN = %.#...... |
| 188 |
vdcr_CONTROLV_FLASHFREQ_MASK = %..#..... |
| 189 |
; vdcr_CONTROLV_FLASHFREQ_FAST = %........ |
| 190 |
vdcr_CONTROLV_FLASHFREQ_SLOW = %..#..... |
| 191 |
vdcr_CONTROLV_UPSCROLL_MASK = %...##### |
| 192 |
vdcr_control_h = 25 ; $47 ($40 for vdc version 0) horizontal scroll and much other stuff |
| 193 |
vdcr_CONTROLH_MODE_MASK = %#....... |
| 194 |
; vdcr_CONTROLH_MODE_TEXT = %........ |
| 195 |
vdcr_CONTROLH_MODE_BITMAP = %#....... |
| 196 |
vdcr_CONTROLH_ATTRIBUTES_MASK = %.#...... |
| 197 |
; vdcr_CONTROLH_ATTRIBUTES_OFF = %........ |
| 198 |
vdcr_CONTROLH_ATTRIBUTES_ON = %.#...... |
| 199 |
vdcr_CONTROLH_SEMIGRAPHICS = %..#..... |
| 200 |
vdcr_CONTROLH_PIXELWIDTH_MASK = %...#.... |
| 201 |
; vdcr_CONTROLH_PIXELWIDTH_NARROW = %........ |
| 202 |
vdcr_CONTROLH_PIXELWIDTH_WIDE = %...#.... |
| 203 |
vdcr_CONTROLH_RIGHTSCROLL_MASK = %....#### |
| 204 |
vdcr_color = 26 ; $f0 4b foreground, 4b background |
| 205 |
vdcr_COLOR_FOREGROUND_MASK = %####.... ; only used if attributes are off (see bit 6 of reg 25) |
| 206 |
vdcr_COLOR_BACKGROUND_MASK = %....#### |
| 207 |
vdcr_row_inc = 27 ; 0 address increment per row |
| 208 |
vdcr_charset = 28 ; $20 3b charset pointer, 1b RAM type, 4b unused |
| 209 |
vdcr_CHARSET_ADRESS_MASK = %###..... |
| 210 |
vdcr_CHARSET_RAMTYPE_MASK = %...#.... |
| 211 |
; vdcr_CHARSET_RAMTYPE_16K = %........ |
| 212 |
vdcr_CHARSET_RAMTYPE_64K = %...#.... |
| 213 |
vdcr_underline = 29 ; 7 5b scanline |
| 214 |
vdcr_cycles = 30 ; -- number of write- or copy-cycles. 0 means 256. |
| 215 |
vdcr_access = 31 ; -- contents of RAM selected by registers 18/19 |
| 216 |
vdcr_source_hi = 32 ; -- start address for block copy (block copying |
| 217 |
vdcr_source_lo = 33 ; -- automatically increments this address) |
| 218 |
vdcr_enable_start = 34 ; 125 column to enable display in (6 is left of text) |
| 219 |
vdcr_enable_end = 35 ; 100 column to disable display in (86 is right of text) |
| 220 |
vdcr_dram_refresh = 36 ; 5 RAM refresh cycles per line (lower 4 bits) |
| 221 |
vdcr_sync_polarity = 37 ; -- only in VDC 8568 |
| 222 |
vdcr_HSYNC_POLARITY = %#....... |
| 223 |
vdcr_VSYNC_POLARITY = %.#...... |
| 224 |
|
| 225 |
!address { |
| 226 |
; the c128 ROMs contain look-up tables to convert vic color values to vdc color |
| 227 |
; values and vice-versa: |
| 228 |
; rom4_* needs "low rom area" enabled ($4000..$7fff) |
| 229 |
; rom8_* needs "middle rom area" enabled ($8000..$bfff) |
| 230 |
; romc_* needs "high rom area" enabled ($c000..$ffff) |
| 231 |
rom4_vic_to_vdc_color_table = $6a4c ; 00 0f 08 07 0b 04 02 0d 0a 0c 09 06 01 05 03 0e |
| 232 |
rom8_vdc_to_vic_color_table = $81f3 ; 00 0c 06 0e 05 0d 0b 03 02 0a 08 04 09 07 0f 01 |
| 233 |
romc_vic_to_vdc_color_table = $ce5c ; 00 0f 08 07 0b 04 02 0d 0a 0c 09 06 01 05 03 0e |
| 234 |
} |
| 235 |
|
| 236 |
; "hardscroll" notes: |
| 237 |
; the vdc seems to read the values from registers 12/13/20/21 (screen ram and |
| 238 |
; attribute ram) at the _end_ of the display window, so if you change these |
| 239 |
; registers in the lower border, the next frame will still use the old values. |
| 240 |
; this is important if you want to combine hardscroll and softscroll. |