From d14385bab43650505381b93ca34132205c5de127 Mon Sep 17 00:00:00 2001 From: Luigi Thirty Date: Tue, 30 May 2017 21:38:19 -0400 Subject: [PATCH] initial commit --- GRAF.SRC/BUILD.S | 14 + GRAF.SRC/DEG2RAD.TABLE.S | 360 ++++++++++++ GRAF.SRC/DP.TABLE.S | 56 ++ GRAF.SRC/FIXED.MACROS.S | 79 +++ GRAF.SRC/FIXED.MATH.S | 162 ++++++ GRAF.SRC/GLYPH.S | 347 ++++++++++++ GRAF.SRC/GRAF.MACROS.S | 116 ++++ GRAF.SRC/GRAF.S | 538 ++++++++++++++++++ GRAF.SRC/LINES.S | 1129 ++++++++++++++++++++++++++++++++++++++ GRAF.SRC/VIDEO.EQUATES.S | 62 +++ GRAF.SRC/VRAM.TABLE.S | 200 +++++++ 11 files changed, 3063 insertions(+) create mode 100644 GRAF.SRC/BUILD.S create mode 100644 GRAF.SRC/DEG2RAD.TABLE.S create mode 100644 GRAF.SRC/DP.TABLE.S create mode 100644 GRAF.SRC/FIXED.MACROS.S create mode 100644 GRAF.SRC/FIXED.MATH.S create mode 100644 GRAF.SRC/GLYPH.S create mode 100644 GRAF.SRC/GRAF.MACROS.S create mode 100644 GRAF.SRC/GRAF.S create mode 100644 GRAF.SRC/LINES.S create mode 100644 GRAF.SRC/VIDEO.EQUATES.S create mode 100644 GRAF.SRC/VRAM.TABLE.S diff --git a/GRAF.SRC/BUILD.S b/GRAF.SRC/BUILD.S new file mode 100644 index 0000000..d364a63 --- /dev/null +++ b/GRAF.SRC/BUILD.S @@ -0,0 +1,14 @@ +************************************************** +* GRAF LINKER SCRIPT * +************************************************** + + ASM GRAF.S ;Assemble if needed + ASM LINES.S ;Assemble if needed + ASM FIXED.MATH.S ;Assemble if needed + + LNK GRAF.L + LNK LINES.L + LNK FIXED.MATH.L + + TYP S16 + SAV GRAF diff --git a/GRAF.SRC/DEG2RAD.TABLE.S b/GRAF.SRC/DEG2RAD.TABLE.S new file mode 100644 index 0000000..33dd014 --- /dev/null +++ b/GRAF.SRC/DEG2RAD.TABLE.S @@ -0,0 +1,360 @@ + dw $0,$0 ; 0 degrees + dw $477,$0 ; 1 degrees + dw $8ef,$0 ; 2 degrees + dw $d67,$0 ; 3 degrees + dw $11df,$0 ; 4 degrees + dw $1657,$0 ; 5 degrees + dw $1ace,$0 ; 6 degrees + dw $1f46,$0 ; 7 degrees + dw $23be,$0 ; 8 degrees + dw $2836,$0 ; 9 degrees + dw $2cae,$0 ; 10 degrees + dw $3125,$0 ; 11 degrees + dw $359d,$0 ; 12 degrees + dw $3a15,$0 ; 13 degrees + dw $3e8d,$0 ; 14 degrees + dw $4305,$0 ; 15 degrees + dw $477c,$0 ; 16 degrees + dw $4bf4,$0 ; 17 degrees + dw $506c,$0 ; 18 degrees + dw $54e4,$0 ; 19 degrees + dw $595c,$0 ; 20 degrees + dw $5dd3,$0 ; 21 degrees + dw $624b,$0 ; 22 degrees + dw $66c3,$0 ; 23 degrees + dw $6b3b,$0 ; 24 degrees + dw $6fb3,$0 ; 25 degrees + dw $742a,$0 ; 26 degrees + dw $78a2,$0 ; 27 degrees + dw $7d1a,$0 ; 28 degrees + dw $8192,$0 ; 29 degrees + dw $860a,$0 ; 30 degrees + dw $8a81,$0 ; 31 degrees + dw $8ef9,$0 ; 32 degrees + dw $9371,$0 ; 33 degrees + dw $97e9,$0 ; 34 degrees + dw $9c61,$0 ; 35 degrees + dw $a0d8,$0 ; 36 degrees + dw $a550,$0 ; 37 degrees + dw $a9c8,$0 ; 38 degrees + dw $ae40,$0 ; 39 degrees + dw $b2b8,$0 ; 40 degrees + dw $b72f,$0 ; 41 degrees + dw $bba7,$0 ; 42 degrees + dw $c01f,$0 ; 43 degrees + dw $c497,$0 ; 44 degrees + dw $c90f,$0 ; 45 degrees + dw $cd86,$0 ; 46 degrees + dw $d1fe,$0 ; 47 degrees + dw $d676,$0 ; 48 degrees + dw $daee,$0 ; 49 degrees + dw $df66,$0 ; 50 degrees + dw $e3dd,$0 ; 51 degrees + dw $e855,$0 ; 52 degrees + dw $eccd,$0 ; 53 degrees + dw $f145,$0 ; 54 degrees + dw $f5bd,$0 ; 55 degrees + dw $fa34,$0 ; 56 degrees + dw $feac,$0 ; 57 degrees + dw $324,$1 ; 58 degrees + dw $79c,$1 ; 59 degrees + dw $c14,$1 ; 60 degrees + dw $108b,$1 ; 61 degrees + dw $1503,$1 ; 62 degrees + dw $197b,$1 ; 63 degrees + dw $1df3,$1 ; 64 degrees + dw $226b,$1 ; 65 degrees + dw $26e2,$1 ; 66 degrees + dw $2b5a,$1 ; 67 degrees + dw $2fd2,$1 ; 68 degrees + dw $344a,$1 ; 69 degrees + dw $38c2,$1 ; 70 degrees + dw $3d39,$1 ; 71 degrees + dw $41b1,$1 ; 72 degrees + dw $4629,$1 ; 73 degrees + dw $4aa1,$1 ; 74 degrees + dw $4f19,$1 ; 75 degrees + dw $5390,$1 ; 76 degrees + dw $5808,$1 ; 77 degrees + dw $5c80,$1 ; 78 degrees + dw $60f8,$1 ; 79 degrees + dw $6570,$1 ; 80 degrees + dw $69e7,$1 ; 81 degrees + dw $6e5f,$1 ; 82 degrees + dw $72d7,$1 ; 83 degrees + dw $774f,$1 ; 84 degrees + dw $7bc7,$1 ; 85 degrees + dw $803e,$1 ; 86 degrees + dw $84b6,$1 ; 87 degrees + dw $892e,$1 ; 88 degrees + dw $8da6,$1 ; 89 degrees + dw $921e,$1 ; 90 degrees + dw $9695,$1 ; 91 degrees + dw $9b0d,$1 ; 92 degrees + dw $9f85,$1 ; 93 degrees + dw $a3fd,$1 ; 94 degrees + dw $a875,$1 ; 95 degrees + dw $acec,$1 ; 96 degrees + dw $b164,$1 ; 97 degrees + dw $b5dc,$1 ; 98 degrees + dw $ba54,$1 ; 99 degrees + dw $becc,$1 ; 100 degrees + dw $c343,$1 ; 101 degrees + dw $c7bb,$1 ; 102 degrees + dw $cc33,$1 ; 103 degrees + dw $d0ab,$1 ; 104 degrees + dw $d523,$1 ; 105 degrees + dw $d99a,$1 ; 106 degrees + dw $de12,$1 ; 107 degrees + dw $e28a,$1 ; 108 degrees + dw $e702,$1 ; 109 degrees + dw $eb7a,$1 ; 110 degrees + dw $eff1,$1 ; 111 degrees + dw $f469,$1 ; 112 degrees + dw $f8e1,$1 ; 113 degrees + dw $fd59,$1 ; 114 degrees + dw $1d1,$2 ; 115 degrees + dw $648,$2 ; 116 degrees + dw $ac0,$2 ; 117 degrees + dw $f38,$2 ; 118 degrees + dw $13b0,$2 ; 119 degrees + dw $1828,$2 ; 120 degrees + dw $1c9f,$2 ; 121 degrees + dw $2117,$2 ; 122 degrees + dw $258f,$2 ; 123 degrees + dw $2a07,$2 ; 124 degrees + dw $2e7f,$2 ; 125 degrees + dw $32f6,$2 ; 126 degrees + dw $376e,$2 ; 127 degrees + dw $3be6,$2 ; 128 degrees + dw $405e,$2 ; 129 degrees + dw $44d6,$2 ; 130 degrees + dw $494d,$2 ; 131 degrees + dw $4dc5,$2 ; 132 degrees + dw $523d,$2 ; 133 degrees + dw $56b5,$2 ; 134 degrees + dw $5b2d,$2 ; 135 degrees + dw $5fa5,$2 ; 136 degrees + dw $641c,$2 ; 137 degrees + dw $6894,$2 ; 138 degrees + dw $6d0c,$2 ; 139 degrees + dw $7184,$2 ; 140 degrees + dw $75fc,$2 ; 141 degrees + dw $7a73,$2 ; 142 degrees + dw $7eeb,$2 ; 143 degrees + dw $8363,$2 ; 144 degrees + dw $87db,$2 ; 145 degrees + dw $8c53,$2 ; 146 degrees + dw $90ca,$2 ; 147 degrees + dw $9542,$2 ; 148 degrees + dw $99ba,$2 ; 149 degrees + dw $9e32,$2 ; 150 degrees + dw $a2aa,$2 ; 151 degrees + dw $a721,$2 ; 152 degrees + dw $ab99,$2 ; 153 degrees + dw $b011,$2 ; 154 degrees + dw $b489,$2 ; 155 degrees + dw $b901,$2 ; 156 degrees + dw $bd78,$2 ; 157 degrees + dw $c1f0,$2 ; 158 degrees + dw $c668,$2 ; 159 degrees + dw $cae0,$2 ; 160 degrees + dw $cf58,$2 ; 161 degrees + dw $d3cf,$2 ; 162 degrees + dw $d847,$2 ; 163 degrees + dw $dcbf,$2 ; 164 degrees + dw $e137,$2 ; 165 degrees + dw $e5af,$2 ; 166 degrees + dw $ea26,$2 ; 167 degrees + dw $ee9e,$2 ; 168 degrees + dw $f316,$2 ; 169 degrees + dw $f78e,$2 ; 170 degrees + dw $fc06,$2 ; 171 degrees + dw $7d,$3 ; 172 degrees + dw $4f5,$3 ; 173 degrees + dw $96d,$3 ; 174 degrees + dw $de5,$3 ; 175 degrees + dw $125d,$3 ; 176 degrees + dw $16d4,$3 ; 177 degrees + dw $1b4c,$3 ; 178 degrees + dw $1fc4,$3 ; 179 degrees + dw $243c,$3 ; 180 degrees + dw $28b4,$3 ; 181 degrees + dw $2d2b,$3 ; 182 degrees + dw $31a3,$3 ; 183 degrees + dw $361b,$3 ; 184 degrees + dw $3a93,$3 ; 185 degrees + dw $3f0b,$3 ; 186 degrees + dw $4382,$3 ; 187 degrees + dw $47fa,$3 ; 188 degrees + dw $4c72,$3 ; 189 degrees + dw $50ea,$3 ; 190 degrees + dw $5562,$3 ; 191 degrees + dw $59d9,$3 ; 192 degrees + dw $5e51,$3 ; 193 degrees + dw $62c9,$3 ; 194 degrees + dw $6741,$3 ; 195 degrees + dw $6bb9,$3 ; 196 degrees + dw $7030,$3 ; 197 degrees + dw $74a8,$3 ; 198 degrees + dw $7920,$3 ; 199 degrees + dw $7d98,$3 ; 200 degrees + dw $8210,$3 ; 201 degrees + dw $8687,$3 ; 202 degrees + dw $8aff,$3 ; 203 degrees + dw $8f77,$3 ; 204 degrees + dw $93ef,$3 ; 205 degrees + dw $9867,$3 ; 206 degrees + dw $9cde,$3 ; 207 degrees + dw $a156,$3 ; 208 degrees + dw $a5ce,$3 ; 209 degrees + dw $aa46,$3 ; 210 degrees + dw $aebe,$3 ; 211 degrees + dw $b335,$3 ; 212 degrees + dw $b7ad,$3 ; 213 degrees + dw $bc25,$3 ; 214 degrees + dw $c09d,$3 ; 215 degrees + dw $c515,$3 ; 216 degrees + dw $c98c,$3 ; 217 degrees + dw $ce04,$3 ; 218 degrees + dw $d27c,$3 ; 219 degrees + dw $d6f4,$3 ; 220 degrees + dw $db6c,$3 ; 221 degrees + dw $dfe3,$3 ; 222 degrees + dw $e45b,$3 ; 223 degrees + dw $e8d3,$3 ; 224 degrees + dw $ed4b,$3 ; 225 degrees + dw $f1c3,$3 ; 226 degrees + dw $f63a,$3 ; 227 degrees + dw $fab2,$3 ; 228 degrees + dw $ff2a,$3 ; 229 degrees + dw $3a2,$4 ; 230 degrees + dw $81a,$4 ; 231 degrees + dw $c91,$4 ; 232 degrees + dw $1109,$4 ; 233 degrees + dw $1581,$4 ; 234 degrees + dw $19f9,$4 ; 235 degrees + dw $1e71,$4 ; 236 degrees + dw $22e8,$4 ; 237 degrees + dw $2760,$4 ; 238 degrees + dw $2bd8,$4 ; 239 degrees + dw $3050,$4 ; 240 degrees + dw $34c8,$4 ; 241 degrees + dw $393f,$4 ; 242 degrees + dw $3db7,$4 ; 243 degrees + dw $422f,$4 ; 244 degrees + dw $46a7,$4 ; 245 degrees + dw $4b1f,$4 ; 246 degrees + dw $4f96,$4 ; 247 degrees + dw $540e,$4 ; 248 degrees + dw $5886,$4 ; 249 degrees + dw $5cfe,$4 ; 250 degrees + dw $6176,$4 ; 251 degrees + dw $65ed,$4 ; 252 degrees + dw $6a65,$4 ; 253 degrees + dw $6edd,$4 ; 254 degrees + dw $7355,$4 ; 255 degrees + dw $77cd,$4 ; 256 degrees + dw $7c44,$4 ; 257 degrees + dw $80bc,$4 ; 258 degrees + dw $8534,$4 ; 259 degrees + dw $89ac,$4 ; 260 degrees + dw $8e24,$4 ; 261 degrees + dw $929b,$4 ; 262 degrees + dw $9713,$4 ; 263 degrees + dw $9b8b,$4 ; 264 degrees + dw $a003,$4 ; 265 degrees + dw $a47b,$4 ; 266 degrees + dw $a8f3,$4 ; 267 degrees + dw $ad6a,$4 ; 268 degrees + dw $b1e2,$4 ; 269 degrees + dw $b65a,$4 ; 270 degrees + dw $bad2,$4 ; 271 degrees + dw $bf4a,$4 ; 272 degrees + dw $c3c1,$4 ; 273 degrees + dw $c839,$4 ; 274 degrees + dw $ccb1,$4 ; 275 degrees + dw $d129,$4 ; 276 degrees + dw $d5a1,$4 ; 277 degrees + dw $da18,$4 ; 278 degrees + dw $de90,$4 ; 279 degrees + dw $e308,$4 ; 280 degrees + dw $e780,$4 ; 281 degrees + dw $ebf8,$4 ; 282 degrees + dw $f06f,$4 ; 283 degrees + dw $f4e7,$4 ; 284 degrees + dw $f95f,$4 ; 285 degrees + dw $fdd7,$4 ; 286 degrees + dw $24f,$5 ; 287 degrees + dw $6c6,$5 ; 288 degrees + dw $b3e,$5 ; 289 degrees + dw $fb6,$5 ; 290 degrees + dw $142e,$5 ; 291 degrees + dw $18a6,$5 ; 292 degrees + dw $1d1d,$5 ; 293 degrees + dw $2195,$5 ; 294 degrees + dw $260d,$5 ; 295 degrees + dw $2a85,$5 ; 296 degrees + dw $2efd,$5 ; 297 degrees + dw $3374,$5 ; 298 degrees + dw $37ec,$5 ; 299 degrees + dw $3c64,$5 ; 300 degrees + dw $40dc,$5 ; 301 degrees + dw $4554,$5 ; 302 degrees + dw $49cb,$5 ; 303 degrees + dw $4e43,$5 ; 304 degrees + dw $52bb,$5 ; 305 degrees + dw $5733,$5 ; 306 degrees + dw $5bab,$5 ; 307 degrees + dw $6022,$5 ; 308 degrees + dw $649a,$5 ; 309 degrees + dw $6912,$5 ; 310 degrees + dw $6d8a,$5 ; 311 degrees + dw $7202,$5 ; 312 degrees + dw $7679,$5 ; 313 degrees + dw $7af1,$5 ; 314 degrees + dw $7f69,$5 ; 315 degrees + dw $83e1,$5 ; 316 degrees + dw $8859,$5 ; 317 degrees + dw $8cd0,$5 ; 318 degrees + dw $9148,$5 ; 319 degrees + dw $95c0,$5 ; 320 degrees + dw $9a38,$5 ; 321 degrees + dw $9eb0,$5 ; 322 degrees + dw $a327,$5 ; 323 degrees + dw $a79f,$5 ; 324 degrees + dw $ac17,$5 ; 325 degrees + dw $b08f,$5 ; 326 degrees + dw $b507,$5 ; 327 degrees + dw $b97e,$5 ; 328 degrees + dw $bdf6,$5 ; 329 degrees + dw $c26e,$5 ; 330 degrees + dw $c6e6,$5 ; 331 degrees + dw $cb5e,$5 ; 332 degrees + dw $cfd5,$5 ; 333 degrees + dw $d44d,$5 ; 334 degrees + dw $d8c5,$5 ; 335 degrees + dw $dd3d,$5 ; 336 degrees + dw $e1b5,$5 ; 337 degrees + dw $e62c,$5 ; 338 degrees + dw $eaa4,$5 ; 339 degrees + dw $ef1c,$5 ; 340 degrees + dw $f394,$5 ; 341 degrees + dw $f80c,$5 ; 342 degrees + dw $fc83,$5 ; 343 degrees + dw $fb,$6 ; 344 degrees + dw $573,$6 ; 345 degrees + dw $9eb,$6 ; 346 degrees + dw $e63,$6 ; 347 degrees + dw $12da,$6 ; 348 degrees + dw $1752,$6 ; 349 degrees + dw $1bca,$6 ; 350 degrees + dw $2042,$6 ; 351 degrees + dw $24ba,$6 ; 352 degrees + dw $2931,$6 ; 353 degrees + dw $2da9,$6 ; 354 degrees + dw $3221,$6 ; 355 degrees + dw $3699,$6 ; 356 degrees + dw $3b11,$6 ; 357 degrees + dw $3f88,$6 ; 358 degrees + dw $4400,$6 ; 359 degrees \ No newline at end of file diff --git a/GRAF.SRC/DP.TABLE.S b/GRAF.SRC/DP.TABLE.S new file mode 100644 index 0000000..ae94310 --- /dev/null +++ b/GRAF.SRC/DP.TABLE.S @@ -0,0 +1,56 @@ +* Direct Page addresses. +PixelPtr = $00 + +rectData ; A rectangle data structure. +rX1 = $04 ;DP +rX2 = $06 ;DP +rY1 = $08 ;DP +rY2 = $0A ;DP + +* Private data for graphics routines +rXSize = $0C +rYSize = $0E + +penColor = $10 ; Color we're using to draw. + +* General line drawing from (x1,y1) to (x2,y2) +lnX1 = $12 +lnY1 = $14 + +lnX2 = $16 +lnY2 = $18 + +lnXSize = $1A ;for horizontal drawing +lnYSize = $1C ;for vertical drawing + +* Glyph drawing +ptr_Glyph = $30 ;Pointer to current glyph. +glyph_sl_drawn = $34 ;How many drawn scanlines of the current glyph? + +dest_X = $36 ;Destination of drawing +dest_Y = $38 +dest_Offset = $3A +glyph_ASCII = $3C ;ASCII code of next glyph to draw. + +* Pixel plotting +p_PixelLocation = $40 ;2 bytes: $E1BBAA + +plotX = $80 +plotY = $82 + +* Fixed-Point Math +fx_Scratch = $90 ; 4 bytes - scratch area +fx_Operand1 = $94 ; 4 bytes - Operand 1 +fx_Operand2 = $98 ; 4 bytes - Operand 2 +fx_Result = $9C ; 4 bytes - Result +fx_RotatedX = $A0 +fx_RotatedY = $A4 + +Radians = $B0 + +* Shape data +ptr_RotatedVertices = $F4 ; Pointer to rotated vertices for Rotate functions. +ptr_Long_Shape = $F8 ; A long pointer to shape data. +ptr_Shape = $FC ; Pointer to shape data. + +RETURN_ADDRESS = $FE ; store the return address here diff --git a/GRAF.SRC/FIXED.MACROS.S b/GRAF.SRC/FIXED.MACROS.S new file mode 100644 index 0000000..0153eab --- /dev/null +++ b/GRAF.SRC/FIXED.MACROS.S @@ -0,0 +1,79 @@ + EXT FX_INIT + EXT FX_SET + EXT FX_ADD + EXT FX_SUB + +************************************************** +* Required definitions +fixed_10000 adrl $27100000 +************************************************** + +M_FX_VERTEX MAC + dw $0000,]1,$0000,]2 + <<< + +* Multiply a FIXED by 10000 to produce a FIXED with the fraction now +* in the decimal word. +M_FX_TO_DECIMAL MAC + LDA ]1 + STA fx_Scratch + LDA #0 + STA fx_Scratch+2 + ~FixMul fx_Scratch;fixed_10000 + PullLong ]2 + <<< + +************************************************** +M_FX_INIT MAC + LDA ]1 ; param 1 is a WORD pointer + PHA + JSR FX_INIT + PLA + <<< + +M_FX_SET MAC + LDA ]1 ; destination + PHA + LDA ]2 ; integer + PHA + LDA ]3 ; decimal + PHA + JSR FX_SET + PLA + PLA + PLA + <<< + +M_FX_ADD MAC + LDA ]1 ; WORD ptr to operand 1 + PHA + LDA ]2 ; WORD ptr to operand 2 + PHA + LDA ]3 ; WORD ptr to result + PHA + JSR FX_ADD + PLA + PLA + PLA + <<< + +M_FX_SUB MAC + LDA ]1 ; WORD ptr to operand 1 + PHA + LDA ]2 ; WORD ptr to operand 2 + PHA + LDA ]3 ; WORD ptr to result + PHA + JSR FX_SUB + PLA + PLA + PLA + <<< + + +M_FX_PULL_HEXSTR MAC + PLA ]1 + STA ]1 + PLA ]1+2 + STA ]1+2 + <<< diff --git a/GRAF.SRC/FIXED.MATH.S b/GRAF.SRC/FIXED.MATH.S new file mode 100644 index 0000000..262ee5c --- /dev/null +++ b/GRAF.SRC/FIXED.MATH.S @@ -0,0 +1,162 @@ +************************************************** +* Fixed-Point Math Routines * +* A fixed-point variable consists of two parts. * +* * +* The high word is the binary INTEGER component. * +* The low word is the binary FRACTION component.* +************************************************** + REL + + LST OFF + DSK FIXED.MATH.L + + USE 4/MACROS + USE 4/UTIL.MACS + + USE DP.TABLE + +* Macros are defined in FIXED.MACROS + + M65816 1 + + NOP + NOP + +************************************************** +* FX_INIT +* Initializes a fixed-point value to 0. +* Input: $3,S = ptr to the variable to initialize. + +FX_INIT ENT + + LDY #0 + LDA $3,S + STA fx_Scratch + + LDA #0 + STA (fx_Scratch),Y + + LDY #2 + STA (fx_Scratch),Y + + RTS + +************************************************** +* FX_SET +* Sets a fixed point number. +* Input: $3,S = 16-bit binary integer +* ...... $5,S = 16-bit binary fraction +* ...... $7,S = pointer to destination + +FX_SET ENT + LDY #0 + + LDA $3,S + STA ($7,S),Y ; copy the integer + + LDA $7,S + INC + INC + STA $7,S + + LDA $5,S + STA ($7,S),Y + + RTS + +************************************************** +* FX_ADD +* Adds two fixed point operands together, storing the result elsewhere. +* Input: $B,S = LONG result space +* ...... $7,S = LONG operand 2 +* ...... $3,S = LONG operand 1 + +FX_ADD ENT + + LDA $1,S + STA RETURN_ADDRESS + + LDA #0 + STA $B,S + +* Add the fractional component: fx_Operand1 + fx_Operand2 + LDA $3,S + + CLC + ADC $7,S + + STA $B,S + +* Is the Carry flag set? + BCC :addIntegers + +* Yes, the result overflowed. + LDA #1 + STA $D,S ; C = 1 + +:addIntegers + LDA $5,S ; R = A + CLC + ADC $9,S ; R = A+B + CLC + ADC $D,S ; R = A+B+C + STA $D,S ; store R + + PLA + PLA + PLA + PLA ;discard two longs, leaving Result on the stack + + LDA RETURN_ADDRESS + STA $1,S + + RTS + +************************************************** +* FX_SUB +* Subtracts two fixed point operands, storing the result elsewhere. +* Input: $B,S = LONG result space +* ...... $7,S = LONG operand 2 +* ...... $3,S = LONG operand 1 + +FX_SUB ENT + + LDA $1,S + STA RETURN_ADDRESS + + LDA #0 + STA $D,S + +* Subtract the fractional component: fx_Operand1 - fx_Operand2 +* If we overflow, subtract 1 from the integer result. + LDA $3,S + + SEC + SBC $7,S + + STA $B,S + +* Is the Negative flag set? + BPL :subIntegers + +* Yes, the result is negative. + LDA #-1 + STA $D,S ; C = 1 + +:subIntegers + LDA $5,S ; R = A + SEC + SBC $9,S ; R = A-B + SEC + SBC $D,S ; R = A-B-C + STA $D,S ; store R + + PLA + PLA + PLA + PLA ;discard two longs, leaving Result on the stack + + LDA RETURN_ADDRESS + STA $1,S + + RTS diff --git a/GRAF.SRC/GLYPH.S b/GRAF.SRC/GLYPH.S new file mode 100644 index 0000000..fc60e78 --- /dev/null +++ b/GRAF.SRC/GLYPH.S @@ -0,0 +1,347 @@ +ASCIIGlyphs ; Starts at 0x20 + dw glyph_SPC ;20 + dw glyph_SPC ;21 + dw glyph_SPC ;22 + dw glyph_SPC ;23 + dw glyph_SPC ;24 + dw glyph_SPC ;25 + dw glyph_SPC ;26 + dw glyph_SPC ;27 + dw glyph_SPC ;28 + dw glyph_SPC ;29 + dw glyph_Asterisk ;2A + dw glyph_SPC ;2B + dw glyph_SPC ;2C + dw glyph_SPC ;2D + dw glyph_Period ;2E + dw glyph_SPC ;2F + dw glyph_0 ;30 + dw glyph_1 ;31 + dw glyph_2 ;32 + dw glyph_3 ;33 + dw glyph_4 ;34 + dw glyph_5 ;35 + dw glyph_6 ;36 + dw glyph_7 ;37 + dw glyph_8 ;38 + dw glyph_9 ;39 + dw glyph_SPC ;3A + dw glyph_SPC ;3B + dw glyph_SPC ;3C + dw glyph_SPC ;3D + dw glyph_SPC ;3E + dw glyph_Question ;3F + dw glyph_SPC ;40 +AlphaGlyphs ; Starts at 0x41. + dw glyph_A + dw glyph_B + dw glyph_C + dw glyph_D + dw glyph_E + dw glyph_F + dw glyph_G + dw glyph_H + dw glyph_I + dw glyph_J + dw glyph_K + dw glyph_L + dw glyph_M + dw glyph_N + dw glyph_O + dw glyph_P + dw glyph_Q + dw glyph_R + dw glyph_S + dw glyph_T + dw glyph_U + dw glyph_V + dw glyph_W + dw glyph_X + dw glyph_Y + dw glyph_Z + + +glyph_A hex 000FF000 + hex 00F00F00 + hex 0F0000F0 + hex 0FFFFFF0 + hex 0F0000F0 + hex 0F0000F0 + +glyph_B hex 0FFFFF00 + hex 0F0000F0 + hex 0FFFFF00 + hex 0F0000F0 + hex 0F0000F0 + hex 0FFFFF00 + +glyph_C hex 00FFFFF0 + hex 0F000000 + hex 0F000000 + hex 0F000000 + hex 0F000000 + hex 00FFFFF0 + +glyph_D hex 0FFFFF00 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0FFFFF00 + +glyph_E hex 0FFFFFF0 + hex 0F000000 + hex 0FFFF000 + hex 0F000000 + hex 0F000000 + hex 0FFFFFF0 + +glyph_F hex 0FFFFFF0 + hex 0F000000 + hex 0FFFF000 + hex 0F000000 + hex 0F000000 + hex 0F000000 + +glyph_G hex 00FFFFF0 + hex 0F000000 + hex 0F000000 + hex 0F00FFF0 + hex 0F0000F0 + hex 00FFFF00 + +glyph_H hex 0F0000F0 + hex 0F0000F0 + hex 0FFFFFF0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + +glyph_I hex 0FFFFF00 + hex 000F0000 + hex 000F0000 + hex 000F0000 + hex 000F0000 + hex 0FFFFF00 + +glyph_J hex 000000F0 + hex 000000F0 + hex 000000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 00FFFF00 + +glyph_K hex 0F000F00 + hex 0F00F000 + hex 0FFF0000 + hex 0F00F000 + hex 0F000F00 + hex 0F000F00 + +glyph_L hex 0F000000 + hex 0F000000 + hex 0F000000 + hex 0F000000 + hex 0F000000 + hex 0FFFFFF0 + +glyph_M hex 0F0000F0 + hex 0FF00FF0 + hex 0F0FF0F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + +glyph_N hex 0F0000F0 + hex 0FF000F0 + hex 0F0F00F0 + hex 0F00F0F0 + hex 0F000FF0 + hex 0F0000F0 + +glyph_O hex 00FFFF00 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 00FFFF00 + +glyph_P hex 0FFFFF00 + hex 0F0000F0 + hex 0FFFFF00 + hex 0F000000 + hex 0F000000 + hex 0F000000 + +glyph_Q hex 00FFFF00 + hex 0F0000F0 + hex 0F0000F0 + hex 0F00F0F0 + hex 0F000FF0 + hex 00FFFFF0 + +glyph_R hex 0FFFFF00 + hex 0F0000F0 + hex 0FFFFF00 + hex 0F000F00 + hex 0F0000F0 + hex 0F0000F0 + +glyph_S hex 00FFFFF0 + hex 0F000000 + hex 00FFFF00 + hex 000000F0 + hex 000000F0 + hex 0FFFFF00 + +glyph_T hex 0FFFFF00 + hex 000F0000 + hex 000F0000 + hex 000F0000 + hex 000F0000 + hex 000F0000 + +glyph_U hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 00FFFF00 + +glyph_V hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 00F00F00 + hex 000FF000 + +glyph_W hex 0F0000F0 + hex 0F0000F0 + hex 0F0000F0 + hex 0F0FF0F0 + hex 0FF00FF0 + hex 0F0000F0 + +glyph_X hex 0F0000F0 + hex 00F00F00 + hex 000FF000 + hex 000FF000 + hex 00F00F00 + hex 0F0000F0 + +glyph_Y hex F00000F0 + hex 0F000F00 + hex 00F0F000 + hex 000F0000 + hex 000F0000 + hex 000F0000 + +glyph_Z hex 0FFFFFF0 + hex 00000F00 + hex 0000F000 + hex 000F0000 + hex 00F00000 + hex 0FFFFFF0 + +glyph_SPC hex 00000000 + hex 00000000 + hex 00000000 + hex 00000000 + hex 00000000 + hex 00000000 + +************************************************** + +glyph_Asterisk + hex 00000000 + hex 00F0F0F0 + hex 000FFF00 + hex 00FFFFF0 + hex 000FFF00 + hex 00F0F0F0 + +glyph_Period + hex 00000000 + hex 00000000 + hex 00000000 + hex 00000000 + hex 0000FF00 + hex 0000FF00 + +glyph_0 hex 00FFFF00 + hex 0F000FF0 + hex 0F00F0F0 + hex 0F0F00F0 + hex 0FF000F0 + hex 00FFFF00 + +glyph_1 hex 000F0000 + hex 00FF0000 + hex 000F0000 + hex 000F0000 + hex 000F0000 + hex 00FFF000 + +glyph_2 hex 00FFFF00 + hex 0F0000F0 + hex 00000F00 + hex 000FF000 + hex 00F00000 + hex 0FFFFFF0 + +glyph_3 hex 00FFFF00 + hex 000000F0 + hex 000FFF00 + hex 000000F0 + hex 000000F0 + hex 00FFFF00 + +glyph_4 hex 0000FF00 + hex 000F0F00 + hex 00F00F00 + hex 0FFFFFF0 + hex 00000F00 + hex 00000F00 + +glyph_5 hex 0FFFFFF0 + hex 0F000000 + hex 0FFFFF00 + hex 000000F0 + hex 0F0000F0 + hex 00FFFF00 + +glyph_6 hex 000FFF00 + hex 00F00000 + hex 0F000000 + hex 0FFFFF00 + hex 0F0000F0 + hex 00FFFF00 + +glyph_7 hex 0FFFFFF0 + hex 000000F0 + hex 00000F00 + hex 0000F000 + hex 000F0000 + hex 000F0000 + +glyph_8 hex 00FFFF00 + hex 0F0000F0 + hex 00FFFF00 + hex 0F0000F0 + hex 0F0000F0 + hex 00FFFF00 + +glyph_9 hex 00FFFF00 + hex 0F0000F0 + hex 00FFFF00 + hex 0000F000 + hex 000F0000 + hex 00F00000 + +glyph_Question + hex 00FFF000 + hex 0F000F00 + hex 00000F00 + hex 000FF000 + hex 00000000 + hex 000FF000 diff --git a/GRAF.SRC/GRAF.MACROS.S b/GRAF.SRC/GRAF.MACROS.S new file mode 100644 index 0000000..178609a --- /dev/null +++ b/GRAF.SRC/GRAF.MACROS.S @@ -0,0 +1,116 @@ +************************************************** +* Macros for use with GRAF. * +************************************************** + +************************************************** +* Externals * +************************************************** + +SetDBR MAC + SEP #$30 + LDA ]1 + PHA ;data bank = $E1 + PLB + REP #$30 + <<< + +M_ADD MAC + CLC + ADC ]1 + <<< + +M_DrawRectangle MAC + LDA ]1 + STA rX1 + LDA ]2 + STA rY1 + LDA ]3 + STA rX2 + LDA ]4 + STA rY2 + JSR DrawRectangle + <<< + +M_DrawGlyph MAC + LDA ]1 + AND #$00FF + PHA + LDA ]2 + STA dest_X + LDA ]3 + STA dest_Y + JSR DrawGlyph + PLA ;pull our value off the stack + <<< + +M_DrawString MAC + LDA ]1 + PHA + LDA ]2 + STA dest_X + LDA ]3 + STA dest_Y + JSR DrawString + PLA ;pull our value off the stack + <<< + +M_Bresenham MAC + LDA ]1 + STA lnX1 + LDA ]2 + STA lnY1 + LDA ]3 + STA lnX2 + LDA ]4 + STA lnY2 + JSR Bresenham + <<< + +M_DrawShape MAC + LDA ]1 ; pointer to shape + PHA + LDA ]2 ; origin X + PHA + LDA ]3 ; origin Y + PHA + JSR DrawShape + <<< + +M_DrawShape2 MAC + LDA ]1 ; pointer to shape + PHA + LDA ]2 ; origin X + PHA + LDA ]3 ; origin Y + PHA + JSR DrawShape2 + <<< + +M_RotateShape MAC + LDA ]1 ; pointer to shape + PHA + LDA ]2 ; pointer to fixed radians + PHA + JSR RotateShape + PLA + PLA + RTS + <<< + +M_MoveLongFromPtr MAC + LDY #0 + LDA ]1,Y + STA ]2 + LDY #2 + LDA ]1,Y + STA ]2+2 + <<< + +M_MoveLongToPtr MAC + LDY #0 + LDA ]1 + STA ]2,Y + LDY #2 + LDA ]1+2 + STA ]2,Y + <<< diff --git a/GRAF.SRC/GRAF.S b/GRAF.SRC/GRAF.S new file mode 100644 index 0000000..13d44ff --- /dev/null +++ b/GRAF.SRC/GRAF.S @@ -0,0 +1,538 @@ + REL + DSK GRAF.L + + JMP INIT + + LST OFF + USE 4/DOS.16.MACS + USE 4/EVENT.MACS + USE 4/INT.MACS + USE 4/LOCATOR.MACS + USE 4/MACROS + USE 4/MEM.MACS + USE 4/SANE.MACS + USE 4/UTIL.MACS + + USE GRAF.MACROS + USE FIXED.MACROS + USE DP.TABLE + + PUT VIDEO.EQUATES + +************************************************** + EXT DrawRectangle + EXT PaletteTable + EXT Bresenham + EXT DrawShape + EXT DrawShape2 + EXT RotateVertex + EXT ClearScreen +************************************************** + +* Data... +mmID ds 2 + +old_DP ds 2 ;store the DP so we can restore it on exit +old_SP ds 2 ;store the SP so we can restore it on exit + +DP_ptr ds 2 ;pointer to direct-page bank +DP_hndl ds 4 + +ScratchPtr ds 4 ;a scratch memory pointer + +fixed_test_1 ds 4 +fixed_test_2 ds 4 +fixed_test_3 ds 4 +fixed_HALF adrl $00008000 ; 0.5000 + +INT_scratch_1 ds 2 +INT_scratch_2 ds 2 +INT_scratch_3 ds 3 + +INT_65535 = $FFFF + +degrees_to_rotate ds 2 + +************************************************** +* Tool Startup structures +StartStopRef ds 4 ; reference to StartStopRec + +StartStopRec + dw 0 ; must be 0 + dw $0 ; QD 320px + ds 2 ; resFileID + ds 4 ; dPageHandle + dw 4 ; Number of tools to start + +ToolsList + dw 3,$0100 ; Misc Tools + dw 6,$0100 ; Event Manager + dw 10,$0100 ; SANE + dw 11,$0100 ; Integer Math + +evtMouseDown = 1 +evtKeyDown = 3 + +************************************************** +* Event Manager record +EventRecord +evtWhat ds 2 +evtMsg ds 4 +evtWhen ds 4 +evtWhere ds 4 +evtMods ds 2 ; Modifiers + +************************************************** +* Strings * +str_Title ASC "THE VALUE OF 100 * COS(45) IS: ",00 +str_lol ASC "PLUS A BUNCH OF FRACTIONAL JUNK",00 + + ; Room for 16 characters +str_IntMath db 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 + +* Decimal and fractional strings for printing a FIXED value. +str_fx1 db 00,00,00,00,00,00,00,00,00 +str_fx2 db 00,00,00,00,00,00,00,00,00 +************************************************** +INIT MX %00 ;16-bit mode + + PHK + PLB ;data bank = program bank + + TDC + STA old_DP ;store the DP as of the start of program + TSC + STA old_SP ;store the SP as of the start of program + +TOOLS _TLStartUp + ~MMStartUp ; Memory Manager +* _IMStartUp ; Integer Tools + + PLA + STA mmID ;get our Memory Manager ID + +* Start up the remaining tools. + PushLong #0 + PushWord mmID + PEA #0 + PushLong #StartStopRec + _StartupTools + PullLong StartStopRef + +* Allocate some direct page memory + PushLong #0 + PushLong #$300 ;3 pages + PushWord mmID + PushWord #$C001 ;Locked, fixed, fixed bank + PushLong #0 + _NewHandle + +* Dereference the handle. + PLX ; X = low 16 bits of handle + PLA ; A = high 16 bits of handle + PHD ;save caller's direct page register + PHA ; push high word + PHX ;push low word + TSC ;get stack pointer in A + TCD ;and put it in D + LDA [1] ;get low word of master pointer + TAX ;and put it in X + LDY #$0002 ;offset to high word of master pointer + LDA [1],Y ;get high word + PLY ;remove low word of handle + PLY ;and high word + PLD ;restore caller's direct page register + +* A,X is now nnHHMMLL. Since this is a direct page pointer, +* all we care about is MMLL. + STX DP_ptr + TXA + TCD ;and now we have our own direct page + + CLC + ADC #$200 + PHA ;push address of direct-page bank + _SANEStartUp ;start SANE + + LDA #GS_PixelData + STA $00 ;$00 = ptr to current pixel + +START LDA #0 + JSR SetSCBs + LDA #0 + JSR ClearToColor + JSR EnableSHR + + LDA #$FFFF + STA penColor + + LDA #0 + M_FX_INIT #fixed_test_1 + M_FX_INIT #fixed_test_2 + M_FX_INIT #fixed_test_3 + + LDA #45 + STA degrees_to_rotate + +************************************************** +EventLoop +* Let's play with the Integer tools! + PushWord degrees_to_rotate + PushLong #shape_Square + JSR RotateShape2 + PullLong + PullWord ;clean stack + + JSR ClearScreen + M_DrawShape2 #shape_Square;#100;#100 + +* Are there any events waiting for us? + PushWord #0 ;result + PushWord #$000A ;event mask + PushLong #EventRecord + _EventAvail ; nulls out EventRecord if there's no event + +:eventAvailable +* Look for keydown and mouse button 0 down + PushWord #0 + PushWord #$000A + PushLong #EventRecord + _GetNextEvent + +:isThisOurEvent + PLA ; A = 0 if not our event + CMP #0 + BEQ :done + +:checkEventDetails + LDA evtWhat + CMP #evtMouseDown ; is this a mouse button 0 event? + BEQ EXIT + + CMP #evtKeyDown ; is this a key event? + BNE :done + +* This is a key event. +* TODO: uh, something + +* Finally... +:done + INC degrees_to_rotate + +* Uncomment this line to loop + JMP EventLoop + +Waiting + JSR WaitKey + JMP EXIT + +************************************************** +* Stuff to do when we exit. +EXIT + PEA #0 + PushLong #StartStopRef + _ShutdownTools ; orderly shutdown of our opened tools + _DisposeAll ; release all owned memory handles + _MMShutDown + _TLShutDown + + JSL $E100A8 ; and exit the application + DW $2029 + ADRL #QuitParms + +QuitParms ADRL $00000000 + DW $0000 + + +************************************************** +CalculatePixelOffset +* Input coordinates in dp addrs dest_X and dest_Y +* Outputs to dest_Offset + LDY dest_Y + LDA dest_X + LSR + +:loop + CPY #0 ;each Y = 160 bytes added to A + BEQ :done + CLC + ADC #BYTES_PER_LINE + DEY + BRA :loop + +:done + STA dest_Offset ;store the destination + RTS + +************************************************** +RotateShape2 +* B,S = WORD number of degrees to rotate +* 7,S = LONG pointer to shape data structure +* 5,S = return address +* 3,S = WORD number of vertices in shape +* 1,S = vertex we're on + + LDA #0 + PHA + PHA + +* How many vertices are there in this shape? + LDA #0 + LDY #0 + SHORT + LDA ($7,S),Y + LONG + STA $3,S + + LDA $7,S + STA ptr_Long_Shape + LDA $9,S + STA ptr_Long_Shape+2 + + INC ptr_Long_Shape + +* ptr_Long_Shape is the source. +* Calculate ptr_RotatedVertices with the following formula: +* ptr_RotatedVertices = ptr_Long_Shape + (8 * vertex_count) + LDA $3,S + ASL + ASL + ASL ; multiply vertex count by 8 + CLC + ADC ptr_Long_Shape + STA ptr_RotatedVertices ; and construct the pointer with it + LDA ptr_Long_Shape+2 + STA ptr_RotatedVertices+2 + +:nextVertex +* Vertex 1 + PushWord $B,S + PushLong ptr_Long_Shape + JSR RotateVertex + +* Store the X vertex + M_MoveLongToPtr fx_RotatedX;(ptr_RotatedVertices) + + LDA ptr_Long_Shape + CLC + ADC #4 + STA ptr_Long_Shape + + LDA ptr_RotatedVertices + CLC + ADC #4 + STA ptr_RotatedVertices + +* And store the Y vertex + M_MoveLongToPtr fx_RotatedY;(ptr_RotatedVertices) + + LDA ptr_Long_Shape + CLC + ADC #4 + STA ptr_Long_Shape + + LDA ptr_RotatedVertices + CLC + ADC #4 + STA ptr_RotatedVertices + + LDA $1,S + INC + STA $1,S + + CMP $3,S + BNE :nextVertex + BRA :done + +:done + PLA + PLA + + RTS + +************************************************** +ResetIntMathString + LDA #0 + LDY #15 + +:loop STA str_IntMath,Y + CPY #0 + BEQ :done + DEY + BRA :loop + +:done + RTS + +************************************************** +DrawString ;keep doing DrawGlyph until we hit a $00 + + PHA ;local variable +this_glyph = $1,S ; +ptr_String = $5,S ;input, the string pointer + +:getNextCharLoop + LDY #0 + LDA ($5,S),Y ;grab the character we need + + AND #$007F ;strip the high bit + CMP #0 ;NUL? + BEQ :done + +* Okay, now draw this character code. + STA this_glyph + M_DrawGlyph this_glyph;dest_X;dest_Y + + LDA $5,S + INC + STA $5,S ;next character + + LDA dest_X + CLC + ADC #8 + STA dest_X ;advance a character cell + + BRA :getNextCharLoop + +:done + PLA ;destroy local variable + RTS + +************************************************** +DrawGlyph ;Just draw the glyph_A for now + ;at (X,Y) +:init + LDA #0 + STA glyph_sl_drawn + + JSR CalculatePixelOffset ;stores this in dest_Offset + JMP :makePtr + +:makePtr + LDA $3,S ; Get the glyph from the stack + SEC + SBC #$20 ; subtract $20 to get the offset into the table + ASL ; multiply the char by 2 to get the offset + TAY + + LDA ASCIIGlyphs,Y + STA ptr_Glyph + SHORT + PHB + PLA + LONG + AND #$00FF + STA ptr_Glyph+2 ;constructed a 24-bit pointer. +:draw +* A glyph is 8x6. + PHB + SetDBR #$E1 + + LDY #0 + LDX dest_Offset + +:drawScanline + LDA [ptr_Glyph],Y + STA $2000,X + + INX + INX + INY + INY + LDA [ptr_Glyph],Y + STA $2000,X + + DEX ;Back to byte 0 + DEX + INY + INY +* Next scanline. + TXA + CLC + ADC #BYTES_PER_LINE ;move to next scanline + TAX + + INC glyph_sl_drawn + LDA glyph_sl_drawn + CMP #6 + BEQ :doneDrawing + BRA :drawScanline + +:doneDrawing + PLB + RTS + +************************************************** +* Load the palette +LoadPalette + LDX #0 + +:loop + LDA PaletteTable,X + STAL GS_Palettes,X ;set palette 0 color 0 + INX + INX + CMP #32 + BNE :loop + + RTS + +* Enable Super Hi-Res graphics +EnableSHR + SHORT + LDAL $00C029 + ORA #$C0 ; Enable SHR and linear VRAM + STAL $00C029 ; New Video Register + LONG + RTS + +* Clear screen to one solid color in A. +ClearToColor + LDX #$7D00 ; Pixel data is $E12000-$E19D00 +:clearLoop + DEX + DEX + STAL $E12000,X ; pixel location + BNE :clearLoop ; loop until X == 0 + RTS + +* Sets all Scanline Control Bits to A. +SetSCBs + LDX #$0100 +:scbLoop + DEX + DEX + STAL $E19D00,X + BNE :scbLoop + RTS + +* Wait for a keypress. +WaitKey + SEP #$30 ; 8-bit mode +:wait LDAL $00C000 ; Apple II keyboard register + BPL :wait + STAL $00C010 + REP #$30 ; 16-bit mode + RTS + +************************************************** +shape_Square + db 4 ; how many vertices in the shape? + +* Each M_FX_VERTEX specifies one vertex. +shape_Square_vertices + M_FX_VERTEX #-20;#-20 + M_FX_VERTEX #20;#-20 + M_FX_VERTEX #20;#20 + M_FX_VERTEX #-20;#20 + +* And then leave room at the end for the transformed vertices. +shape_Square_transformed + ds 8 + ds 8 + ds 8 + ds 8 + +************************************************** +glyph_data ; Marks the start of the glyphs. + PUT GLYPH diff --git a/GRAF.SRC/LINES.S b/GRAF.SRC/LINES.S new file mode 100644 index 0000000..24237ec --- /dev/null +++ b/GRAF.SRC/LINES.S @@ -0,0 +1,1129 @@ + REL + LST OFF + DSK LINES.L + + USE 4/DOS.16.MACS ;merlin16 macros + USE 4/INT.MACS + USE 4/LOCATOR.MACS + USE 4/MACROS + USE 4/MEM.MACS + USE 4/UTIL.MACS + + USE GRAF.MACROS ; My macros + USE FIXED.MACROS + USE DP.TABLE ; Direct Page variables + + PUT VIDEO.EQUATES + M65816 1 + +M_PlotPixel MAC + LDA ]1 + STA plotX + LDA ]2 + STA plotY + JSR PlotPixel + <<< + +************************************************** +* Data... +mmID ds 2 + +old_DP ds 2 ;store the DP so we can restore it on exit +old_SP ds 2 ;store the SP so we can restore it on exit + +DP_ptr ds 2 ;pointer to direct-page bank +DP_hndl ds 4 +ScratchPtr ds 4 ;a scratch memory pointer + +************************************************* +DrawRectangle ENT +* Draw from (X1,Y1) to (X2,Y1) + LDA rX1 + STA lnX1 + LDA rX2 + STA lnX2 + LDA rY1 + STA lnY1 + JSR DrawHorizontalLine + +* Draw from (X1,Y2) to (X2,Y2) + LDA rY2 + STA lnY1 + JSR DrawHorizontalLine + +* Draw from (X1,Y1) to (X1,Y2) + LDA rX1 + STA lnX1 + LDA rX2 + STA lnX2 + LDA rY1 + STA lnY1 + LDA rY2 + STA lnY2 + JSR DrawVerticalLine + +* Draw from (X2,Y1) to (X2,Y2) + LDA rX2 + STA lnX1 + LDA rX2 + STA lnX2 + LDA rY1 + STA lnY1 + LDA rY2 + STA lnY2 + JSR DrawVerticalLine + + RTS + +************************************************** +BresenhamNegSlope ENT + +Bresenham ENT ;Bresenham's line thingy. +* Only works for positive slopes... + +b_dX = $1,S +b_dY = $3,S +b_D = $5,S + +b_x = $7,S +b_y = $9,S + +b_yIncrement = $B,S + + PHA + PHA + PHA + PHA + PHA ;5 16-bit variables + PHA + +* Swap the points if X2 is bigger than X1. + LDA lnX2 + CMP lnX1 + BGE :getSlopeSign + +:swap + LDA lnX1 + LDX lnX2 + STA lnX2 + STX lnX1 + + LDA lnY1 + LDX lnY2 + STA lnY2 + STX lnY1 + +:getSlopeSign + LDA #1 + STA $B,S ;b_yIncrement + + LDA lnY2 + CMP lnY1 + BGE :plotEndpoints ;slope is positive + +* Slope is negative. + LDA #-1 + STA $B,S ;b_yIncrement + +:plotEndpoints + M_PlotPixel lnX1;lnY1 + M_PlotPixel lnX2;lnY2 + +* dX = abs(x1-x0) + LDA lnX2 + SEC + SBC lnX1 + + BIT #$8000 ; is the result negative? + BEQ :posDX +:negDX + EOR #$FFFF ; flip sign + CLC + ADC #1 +:posDX + STA $1,S ;b_dX + +* dY = abs(y1-y0) + LDA lnY2 + SEC + SBC lnY1 + + BIT #$8000 ; is the result negative? + BEQ :posDY +:negDY + EOR #$FFFF ; flip sign + CLC + ADC #1 +:posDY + STA $3,S ;b_dY + +* if(dx > dy) + LDA $1,S ;b_dX + CMP $3,S ;b_dY + BLT BresStepY + +:bresStepX +* D = 2*dY - dX + LDA $3,S ;b_dY + ASL ;multiply by 2 + SEC + SBC $1,S ;b_dX + STA $5,S ;b_D + +* y = y0 + LDA lnY1 + STA $9,S ;b_y + +* for x from x0 to x1 + LDA lnX1 + STA $7,S ;b_x +:xLoop + LDA $7,S ;b_x + CMP lnX2 + BEQ :done + +* plot(x,y) + M_PlotPixel $7,S;$9,S ;b_x;b_y +* if D > 0 + LDA $5,S ;b_D + BIT #$8000 ; check sign bit + BNE :endIf + +* y = y + y_increment + LDA $9,S ;b_y + CLC + ADC $B,S ;b_yIncrement + STA $9,S ;b_y + +* D = D - 2*dx + LDA $5,S ;b_D + SEC + SBC $1,S ;b_dX + SEC + SBC $1,S ;b_dX + STA $5,S ;b_D + +:endIf + LDA $3,S ;b_dY + ASL ;multiply by 2 + CLC + ADC $5,S ;b_D + STA $5,S ;b_D + +:xLoopNext + LDA $7,S + INC + STA $7,S ;b_x + BRA :xLoop + +:done + PLA + PLA + PLA + PLA + PLA + PLA + RTS + +************************************************** +BresStepY +* Bresenham where we step using Y instead of X. +* Swap the points if Y2 is bigger than Y1. + LDA lnY2 + CMP lnY1 + BGE :go + +:swap + LDA lnX1 + LDX lnX2 + STA lnX2 + STX lnX1 + + LDA lnY1 + LDX lnY2 + STA lnY2 + STX lnY1 + +:go +* D = 2*dX - dY + LDA $1,S ;b_dX + ASL ;multiply by 2 + SEC + SBC $3,S ;b_dY + STA $5,S ;b_D + +* x = x0 + LDA lnX1 + STA $7,S ;b_x + +* for y from y0 to y1 + LDA lnY1 + STA $9,S ;b_y +:yLoop + LDA $9,S ;b_y + CMP lnY2 + BEQ :done + +* plot(x,y) + M_PlotPixel $7,S;$9,S ;b_x;b_y + +* if D > 0 + LDA $5,S ;b_D + BIT #$8000 ; check sign bit + BNE :endIf + +* x = x + x_increment + LDA $7,S ;b_x + CLC + ADC $B,S ;b_xIncrement + STA $7,S ;b_x + +* D = D - 2*dy + LDA $5,S ;b_D + SEC + SBC $3,S ;b_dy + SEC + SBC $3,S ;b_dy + STA $5,S ;b_D + +:endIf + LDA $1,S ;b_dx + ASL ;multiply by 2 + CLC + ADC $5,S ;b_D + STA $5,S ;b_D + +:yLoopNext + LDA $9,S + INC + STA $9,S ;b_y + BRA :yLoop + +:done + PLA + PLA + PLA + PLA + PLA + PLA + RTS + +************************************************** +PlotPixel +* Clip to the 320x200 screen. + LDA plotX + CMP #320 + BGE :abort + + LDA plotY + CMP #200 + BGE :abort + + BRA :doPlot + +:abort + RTS + +:doPlot + LDA plotY + ASL ;multiply by 2 + TAY + + LDA plotX + LSR ; divide by 2 to get pixel address + + CLC + ADC VRAMRows,Y ; now find the right row + TAY + + PHB ; we need to preserve all 16 bits of Y + PHY + +:plot ; and plot the pixel + SetDBR #$E1 ; clobbers high byte of Y + + PLY ; and retrieves Y + + LDA plotX + AND #$1 + BEQ :plotOdd + BRA :plotEven + +:plotOdd + LDA penColor + AND #$00FF + ORA $0000,Y + STA $0000,Y + + PLB ;restore the old DBR + RTS + +:plotEven + LDA penColor + AND #$FF00 + ORA $0000,Y + STA $0000,Y + + PLB ;restore the old DBR + RTS + +************************************************** +DrawHorizontalLine +* Draw a horizontal line from (lnX1,lnY1) to (lnX2,lnY1) + PHB + SetDBR #$E1 + + SUB lnX2;lnX1;lnXSize ;calculate line length + +* LDA lnX2 ;A = x2 +* ADC lnX1 ;A = x1+x2 +* LSR ;A = (x1+x2)/2 + + LDA #0 + ADC lnX2 + LSR ;A = x2 / 2 since we draw right to left + +* Now calculate pixel offset using y1. 160 per y1 + LDY lnY1 +:yCalcLoop + CPY #0 + BEQ :prepDrawing + CLC + ADC #160 ;each #160 added moves down one scanline + DEY + BRA :yCalcLoop + +:prepDrawing + TAY ;Y = pixel offset + + LDA lnXSize + LSR + TAX ;X = pixels to draw + + LDA penColor + +:drawLoop ;draw rXSize pixels. + CPX #0 + BEQ :horizontalDone + DEX + DEY + STA $2000,Y + BRA :drawLoop + +:horizontalDone + PLB ;restore the old DBR + RTS + +************************************************** +DrawVerticalLine +* Draw a vertical line from (lnX1,lnY1) to (lnX1,lnY2) + PHB + SetDBR #$E1 + + SUB lnY2;lnY1;lnYSize ;calculate line length + +:calcStartY + LDA #0 ;A = 0 + ADC lnX1 ;A = x1 + LSR ;A = x1/2 + + LDX lnY1 +:calcLoop + CPX #0 + BEQ :prepDrawing + CLC + ADC #160 ;Add 160 per scanline we start on + DEX + BRA :calcLoop + +:prepDrawing + LDX lnYSize ;X = pixels to draw + TAY ;Y = pixel address offset + LDA penColor ;A = pen color +* TODO: Check if we draw $00FF or $FF00 (even or odd pixel) + BIT #$01 ;Is this an odd pixel? + BEQ :drawOdd + BNE :drawEven + +:drawEven + AND #$00FF + BRA :drawLoop + +:drawOdd + AND #$FF00 + BRA :drawLoop + +:drawLoop + CPX #0 + BEQ :verticalDone + PHA + ORA $2000,Y + STA $2000,Y + PLA + DEX ;subtract one pixel + + PHA + TYA + CLC + ADC #160 ;go to next scanline + TAY + PLA + + BRA :drawLoop + +:verticalDone + PLB + RTS + +************************************************** +RoundFixedVertex MAC + PHY ; preserve Y + PHA ; make room for the result + INY + INY + LDA (ptr_Shape),Y + PHA ; push the low word of the FIXED + DEY + DEY + LDA (ptr_Shape),Y + PHA ; and the high word + _FixRound ; round it + PLA ; and pull the result + PLY ; and grab Y + <<< + +************************************************** +DrawShape2 ENT ; draw a shape. pointer is at $FC + PHA ; $1,S = current vertex + PHA ; $3,S = number of vertices + ; $5,S = return address + ; $7,S = origin X + ; $9,S = origin Y + ; $B,S = pointer to shape data + + LDA $B,S + STA ptr_Shape ; save pointer to $FC + + LDA #0 + STA $1,S ; initialize current vertex to 0 + + SHORT + LDA (ptr_Shape) ; A = vertex count in shape + LONG + + DEC + STA $3,S ; set shape vertex count + + INC ptr_Shape ; ptr_Shape now points to the start of the + ; vertex data + + LDA $3,S ; but we need to advance it to the transformed + INC ; vertices + ASL + ASL + ASL ; so multiply vertex count by sizeof(vertex) + CLC + ADC ptr_Shape ; add it to the pointer address + STA ptr_Shape ; magic. + +:getNextVertex +* Grab the first two vertices and load them into lnX1 and lnY1 + + LDA $1,S ; get current vertex + ASL + ASL ; multiply by 8 to get offset + ASL + TAY ; and now the offset is in Y + +* X coordinate + RoundFixedVertex ; round off the X value + CLC + ADC $7,S ; add the origin + STA lnX1 ; grab and store vertex 0 X coord + +* Y coordinate + INY + INY ; advance offset to v0 Y coord + INY + INY + + RoundFixedVertex ; round off the Y value + CLC + ADC $7,S ; add the origin + STA lnY1 ; grab and store vertex 0 X coord + +* Next vertex + LDA $1,S + INC + STA $1,S ; currentVertex += 1 + +* Grab the next two vertices - this produces one line. + INY + INY ; advance offset to v1 X coord + INY + INY + + RoundFixedVertex + ADC $7,S + STA lnX2 ; save it + + INY + INY ; advance offset to v1 Y coord + INY + INY + + RoundFixedVertex + CLC + ADC $9,S + STA lnY2 ; save it + + JSR Bresenham ; draw our line now + +* Is this the last vertex? + LDA $1,S + CMP $3,S + BEQ :isLastVertex + BRL :getNextVertex + +:isLastVertex +* The last vertex, so draw it and wrap back to v0. + + LDA $1,S ; get current vertex + ASL + ASL + ASL ; multiply by 8 to get offset + TAY ; and now the offset is in Y + + RoundFixedVertex + CLC + ADC $7,S + STA lnX1 ; grab and store vertex 0 X coord + + INY + INY ; advance offset to v0 Y coord + INY + INY + + RoundFixedVertex + CLC + ADC $9,S + STA lnY1 ; store v0 Y coord + + LDA $1,S + INC + STA $1,S ; currentVertex += 1 + +* Go back to vertex 0 to finish the shape. + LDA #0 + TAY + + RoundFixedVertex + CLC + ADC $7,S + STA lnX2 ; save it + + INY + INY ; advance offset to v1 Y coord + INY + INY + + RoundFixedVertex + CLC + ADC $9,S + STA lnY2 ; save it + + JSR Bresenham ; draw our line now + +:done + PLA + PLA + RTS + + +************************************************** +DrawShape ENT ; draw a shape. pointer is at $FC + PHA ; $1,S = current vertex + PHA ; $3,S = number of vertices + ; $5,S = return address + ; $7,S = origin X + ; $9,S = origin Y + ; $B,S = pointer to shape data + + LDA $B,S + STA ptr_Shape ; save pointer to $FC + + LDA #0 + STA $1,S ; initialize current vertex to 0 + + SHORT + LDA (ptr_Shape) ; A = vertex count in shape + LONG + + DEC + STA $3,S ; set shape vertex count + + INC ptr_Shape ; ptr_Shape now points to the start of the + ; vertex data + + LDA $3,S ; but we need to advance it to the transformed + INC ; vertices + ASL + ASL + ASL ; so multiply vertex count by sizeof(vertex) + CLC + ADC ptr_Shape ; add it to the pointer address + INC ; add 2 bytes + INC ; and now it points to the high word of vertices + STA ptr_Shape ; magic. + +:getNextVertex +* Grab the first two vertices and load them into lnX1 and lnY1 + + LDA $1,S ; get current vertex + ASL + ASL ; multiply by 8 to get offset + ASL + TAY ; and now the offset is in Y + + LDA (ptr_Shape),Y + CLC + ADC $7,S ; add the origin + STA lnX1 ; grab and store vertex 0 X coord + + INY + INY ; advance offset to v0 Y coord + INY + INY + + LDA (ptr_Shape),Y + CLC + ADC $7,S ; add the origin + STA lnY1 ; grab and store vertex 0 X coord + + LDA $1,S + INC + STA $1,S ; currentVertex += 1 + +* Grab the next two vertices - this produces one line. + INY + INY ; advance offset to v1 X coord + INY + INY + + LDA (ptr_Shape),Y + CLC + ADC $7,S + STA lnX2 ; save it + + INY + INY ; advance offset to v1 Y coord + INY + INY + + LDA (ptr_Shape),Y + CLC + ADC $9,S + STA lnY2 ; save it + + JSR Bresenham ; draw our line now + +* Is this the last vertex? + LDA $1,S + CMP $3,S + BEQ :isLastVertex + BRL :getNextVertex + +:isLastVertex +* The last vertex, so draw it and wrap back to v0. + + LDA $1,S ; get current vertex + ASL + ASL + ASL ; multiply by 8 to get offset + TAY ; and now the offset is in Y + + LDA (ptr_Shape),Y + CLC + ADC $7,S + STA lnX1 ; grab and store vertex 0 X coord + + INY + INY ; advance offset to v0 Y coord + INY + INY + + LDA (ptr_Shape),Y + CLC + ADC $9,S + STA lnY1 ; store v0 Y coord + + LDA $1,S + INC + STA $1,S ; currentVertex += 1 + +* Go back to vertex 0 to finish the shape. + LDA #0 + TAY + + LDA (ptr_Shape),Y + CLC + ADC $7,S + STA lnX2 ; save it + + INY + INY ; advance offset to v1 Y coord + INY + INY + + LDA (ptr_Shape),Y + CLC + ADC $9,S + STA lnY2 ; save it + + JSR Bresenham ; draw our line now + +:done + PLA + PLA + RTS + +************************************************** +RotateVertex ENT +* Rotate a FIXED vertex around (0,0) by theta degrees. +* +* 7,S = WORD number of degrees to rotate +* 3,S = LONG pointer to vertex + +* Retrieve FIXED radians from the table. + LDA 7,S + ASL + ASL ;multiply by 4 to get table offset + TAY + LDA DegreesToRadians,Y + STA Radians ; get low word + INY + INY + LDA DegreesToRadians,Y + STA Radians+2 ; get high word + +* Calculate rotation of X component. + LDA 3,S + STA ptr_Shape + + M_MoveLongFromPtr (ptr_Shape);fx_Operand2 + + ~FracCos Radians + PullLong fx_Operand1 ; contains FRAC value cos(45) + ~Frac2Fix fx_Operand1 + PullLong fx_Operand1 ; contains FIXED value cos(45) + + ~FixMul fx_Operand1;fx_Operand2 ; v.X * cos(45) + PullLong fx_Result ; fx_Result = v.X * cos(45) + + LDA ptr_Shape + CLC + ADC #4 ; advance to Y component of vertex + STA ptr_Shape + M_MoveLongFromPtr (ptr_Shape);fx_Operand2 + + ~FracSin Radians + PullLong fx_Operand1 + ~Frac2Fix fx_Operand1 + PullLong fx_Operand1 ; fx_Operand1 = FIXED sin(45deg) + + ~FixMul fx_Operand1;fx_Operand2 ; SP = fx_Operand1*fx_Operand2 + PullLong fx_Operand2 + + MoveLong fx_Result;fx_Operand1 +* fx_Operand1 = v.X * cos(45deg) | fx_Operand2 = v.Y * cos(45deg) + +* Subtract fx_Operand1 and fx_Operand2 + PushLong #0 + PushLong fx_Operand2 + PushLong fx_Operand1 + JSR FX_SUB + + PullLong fx_RotatedX + +* Calculate rotation of Y component. + +* ptr_Shape is still pointing to Y + M_MoveLongFromPtr (ptr_Shape);fx_Operand2 + + ~FracCos Radians + PullLong fx_Operand1 ; contains FRAC value cos(45) + ~Frac2Fix fx_Operand1 + PullLong fx_Operand1 ; contains FIXED value cos(45) + + ~FixMul fx_Operand1;fx_Operand2 ; v.Y * cos(45) + PullLong fx_Result ; fx_Result = v.Y * cos(45) + + LDA ptr_Shape + SEC + SBC #4 ; return to X component of vertex + STA ptr_Shape + M_MoveLongFromPtr (ptr_Shape);fx_Operand2 + + ~FracSin Radians + PullLong fx_Operand1 + ~Frac2Fix fx_Operand1 + PullLong fx_Operand1 + + ~FixMul fx_Operand1;fx_Operand2 + PullLong fx_Operand2 + + MoveLong fx_Result;fx_Operand1 + +* Add fx_Operand1 and fx_Operand2 + PushLong #0 + PushLong fx_Operand2 + PushLong fx_Operand1 + JSR FX_ADD + + PullLong fx_RotatedY + +* Clean up the stack before we return. + LDA $1,S + STA $7,S + PullLong + PullWord + + RTS + +************************************************** +ClearScreen ENT + LDA #0 + LDX #$7D00 +:clearLoop + DEX + DEX + STAL $E12000,X + BNE :clearLoop + RTS + +************************************************** +PaletteTable ENT +pltBlack dw $0000 ;Black +pltDGray dw $0777 ;Dark Gray +pltBrown dw $0841 ;Brown +pltPurple dw $072C ;Purple +pltBlue dw $000F ;Blue +pltDGreen dw $0080 ;Dark Green +pltOrange dw $0F70 ;Orange +pltRed dw $0D00 ;Red +pltBeige dw $0FA9 ;Beige +pltYellow dw $0FF0 ;Yellow +pltGreen dw $00E0 ;Green +pltLBlue dw $04DF ;Light Blue +pltLilac dw $0DAF ;Lilac +pltPeri dw $078F ;Periwinkle +pltLGray dw $0CCC ;Light Gray +pltWhite dw $0FFF ;White +EndPaletteTable + +DegreesToRadians +* Each entry is a 4-byte FIXED value. + PUT DEG2RAD.TABLE + +************************************************** +VRAMRows + dw $A0*0+$2000 + dw $A0*1+$2000 + dw $A0*2+$2000 + dw $A0*3+$2000 + dw $A0*4+$2000 + dw $A0*5+$2000 + dw $A0*6+$2000 + dw $A0*7+$2000 + dw $A0*8+$2000 + dw $A0*9+$2000 + dw $A0*10+$2000 + dw $A0*11+$2000 + dw $A0*12+$2000 + dw $A0*13+$2000 + dw $A0*14+$2000 + dw $A0*15+$2000 + dw $A0*16+$2000 + dw $A0*17+$2000 + dw $A0*18+$2000 + dw $A0*19+$2000 + dw $A0*20+$2000 + dw $A0*21+$2000 + dw $A0*22+$2000 + dw $A0*23+$2000 + dw $A0*24+$2000 + dw $A0*25+$2000 + dw $A0*26+$2000 + dw $A0*27+$2000 + dw $A0*28+$2000 + dw $A0*29+$2000 + dw $A0*30+$2000 + dw $A0*31+$2000 + dw $A0*32+$2000 + dw $A0*33+$2000 + dw $A0*34+$2000 + dw $A0*35+$2000 + dw $A0*36+$2000 + dw $A0*37+$2000 + dw $A0*38+$2000 + dw $A0*39+$2000 + dw $A0*40+$2000 + dw $A0*41+$2000 + dw $A0*42+$2000 + dw $A0*43+$2000 + dw $A0*44+$2000 + dw $A0*45+$2000 + dw $A0*46+$2000 + dw $A0*47+$2000 + dw $A0*48+$2000 + dw $A0*49+$2000 + dw $A0*50+$2000 + dw $A0*51+$2000 + dw $A0*52+$2000 + dw $A0*53+$2000 + dw $A0*54+$2000 + dw $A0*55+$2000 + dw $A0*56+$2000 + dw $A0*57+$2000 + dw $A0*58+$2000 + dw $A0*59+$2000 + dw $A0*60+$2000 + dw $A0*61+$2000 + dw $A0*62+$2000 + dw $A0*63+$2000 + dw $A0*64+$2000 + dw $A0*65+$2000 + dw $A0*66+$2000 + dw $A0*67+$2000 + dw $A0*68+$2000 + dw $A0*69+$2000 + dw $A0*70+$2000 + dw $A0*71+$2000 + dw $A0*72+$2000 + dw $A0*73+$2000 + dw $A0*74+$2000 + dw $A0*75+$2000 + dw $A0*76+$2000 + dw $A0*77+$2000 + dw $A0*78+$2000 + dw $A0*79+$2000 + dw $A0*80+$2000 + dw $A0*81+$2000 + dw $A0*82+$2000 + dw $A0*83+$2000 + dw $A0*84+$2000 + dw $A0*85+$2000 + dw $A0*86+$2000 + dw $A0*87+$2000 + dw $A0*88+$2000 + dw $A0*89+$2000 + dw $A0*90+$2000 + dw $A0*91+$2000 + dw $A0*92+$2000 + dw $A0*93+$2000 + dw $A0*94+$2000 + dw $A0*95+$2000 + dw $A0*96+$2000 + dw $A0*97+$2000 + dw $A0*98+$2000 + dw $A0*99+$2000 + dw $A0*100+$2000 + dw $A0*101+$2000 + dw $A0*102+$2000 + dw $A0*103+$2000 + dw $A0*104+$2000 + dw $A0*105+$2000 + dw $A0*106+$2000 + dw $A0*107+$2000 + dw $A0*108+$2000 + dw $A0*109+$2000 + dw $A0*110+$2000 + dw $A0*111+$2000 + dw $A0*112+$2000 + dw $A0*113+$2000 + dw $A0*114+$2000 + dw $A0*115+$2000 + dw $A0*116+$2000 + dw $A0*117+$2000 + dw $A0*118+$2000 + dw $A0*119+$2000 + dw $A0*120+$2000 + dw $A0*121+$2000 + dw $A0*122+$2000 + dw $A0*123+$2000 + dw $A0*124+$2000 + dw $A0*125+$2000 + dw $A0*126+$2000 + dw $A0*127+$2000 + dw $A0*128+$2000 + dw $A0*129+$2000 + dw $A0*130+$2000 + dw $A0*131+$2000 + dw $A0*132+$2000 + dw $A0*133+$2000 + dw $A0*134+$2000 + dw $A0*135+$2000 + dw $A0*136+$2000 + dw $A0*137+$2000 + dw $A0*138+$2000 + dw $A0*139+$2000 + dw $A0*140+$2000 + dw $A0*141+$2000 + dw $A0*142+$2000 + dw $A0*143+$2000 + dw $A0*144+$2000 + dw $A0*145+$2000 + dw $A0*146+$2000 + dw $A0*147+$2000 + dw $A0*148+$2000 + dw $A0*149+$2000 + dw $A0*150+$2000 + dw $A0*151+$2000 + dw $A0*152+$2000 + dw $A0*153+$2000 + dw $A0*154+$2000 + dw $A0*155+$2000 + dw $A0*156+$2000 + dw $A0*157+$2000 + dw $A0*158+$2000 + dw $A0*159+$2000 + dw $A0*160+$2000 + dw $A0*161+$2000 + dw $A0*162+$2000 + dw $A0*163+$2000 + dw $A0*164+$2000 + dw $A0*165+$2000 + dw $A0*166+$2000 + dw $A0*167+$2000 + dw $A0*168+$2000 + dw $A0*169+$2000 + dw $A0*170+$2000 + dw $A0*171+$2000 + dw $A0*172+$2000 + dw $A0*173+$2000 + dw $A0*174+$2000 + dw $A0*175+$2000 + dw $A0*176+$2000 + dw $A0*177+$2000 + dw $A0*178+$2000 + dw $A0*179+$2000 + dw $A0*180+$2000 + dw $A0*181+$2000 + dw $A0*182+$2000 + dw $A0*183+$2000 + dw $A0*184+$2000 + dw $A0*185+$2000 + dw $A0*186+$2000 + dw $A0*187+$2000 + dw $A0*188+$2000 + dw $A0*189+$2000 + dw $A0*190+$2000 + dw $A0*191+$2000 + dw $A0*192+$2000 + dw $A0*193+$2000 + dw $A0*194+$2000 + dw $A0*195+$2000 + dw $A0*196+$2000 + dw $A0*197+$2000 + dw $A0*198+$2000 + dw $A0*199+$2000 diff --git a/GRAF.SRC/VIDEO.EQUATES.S b/GRAF.SRC/VIDEO.EQUATES.S new file mode 100644 index 0000000..8b207f2 --- /dev/null +++ b/GRAF.SRC/VIDEO.EQUATES.S @@ -0,0 +1,62 @@ +************************************************** +* Video equates. + +************************************************** +* Video Constants +PIXEL_WIDTH = 320 +PIXEL_HEIGHT = 200 +BITS_PER_PIXEL = 4 +PIXELS_PER_BYTE = 2 +BYTES_PER_LINE = PIXEL_WIDTH/PIXELS_PER_BYTE + +************************************************** +* Video memory registers +GS_VBLInt = $00C019 ; VBlank interrupt? 0 = on, 1 = off +GS_TextColor = $00C022 ; TTTTBBBB T=text, B=bg color +GS_VGCInt = $00C023 ; $80 = any interrupt has fired + ; $40 = 1Hz interrupt + ; $20 = scanline interrupt + ; $04 = 1Hz interrupt on/off + ; $02 = scanline interrupt on/off +GS_SHRRegister = $00C029 ; MLCXXXXB + ; M = 0 for Apple II video, 1 for SHR + ; L = linearize SHR VRAM? + ; C = 1 for color, 0 for b/w + ; XXXX = Reserved + ; B = Bank latch? 1 = aux, 0 = ignored +GS_VGCIntClear = $00C032 ; $40 = clear 1Hz int, $20 = clr scanline int +GS_BorderColor = $00C034 ; XXXXCCCC X = DO NOT MODIFY, C = color + +* Video memory locations +GS_PixelData = $E12000 ; $E12000 - $E19CFF +GS_SCBs = $E19D00 ; $E19D00 - $E19DC7 +GS_Palettes = $E19E00 ; 32 bytes per palette + ; 16 palettes + ; $E19E00 - $E19FFF + +************************************************** +ROW_0 = 0 +ROW_1 = 8 +ROW_2 = 16 +ROW_3 = 24 +ROW_4 = 32 +ROW_5 = 40 +ROW_6 = 48 +ROW_7 = 56 +ROW_8 = 64 +ROW_9 = 72 +ROW_10 = 80 +ROW_11 = 88 +ROW_12 = 96 +ROW_13 = 104 +ROW_14 = 112 +ROW_15 = 120 +ROW_16 = 128 +ROW_17 = 136 +ROW_18 = 144 +ROW_19 = 152 +ROW_20 = 160 +ROW_21 = 168 +ROW_22 = 176 +ROW_23 = 184 +ROW_24 = 192 diff --git a/GRAF.SRC/VRAM.TABLE.S b/GRAF.SRC/VRAM.TABLE.S new file mode 100644 index 0000000..d50ed30 --- /dev/null +++ b/GRAF.SRC/VRAM.TABLE.S @@ -0,0 +1,200 @@ + dw $A0*0+$2000 + dw $A0*1+$2000 + dw $A0*2+$2000 + dw $A0*3+$2000 + dw $A0*4+$2000 + dw $A0*5+$2000 + dw $A0*6+$2000 + dw $A0*7+$2000 + dw $A0*8+$2000 + dw $A0*9+$2000 + dw $A0*10+$2000 + dw $A0*11+$2000 + dw $A0*12+$2000 + dw $A0*13+$2000 + dw $A0*14+$2000 + dw $A0*15+$2000 + dw $A0*16+$2000 + dw $A0*17+$2000 + dw $A0*18+$2000 + dw $A0*19+$2000 + dw $A0*20+$2000 + dw $A0*21+$2000 + dw $A0*22+$2000 + dw $A0*23+$2000 + dw $A0*24+$2000 + dw $A0*25+$2000 + dw $A0*26+$2000 + dw $A0*27+$2000 + dw $A0*28+$2000 + dw $A0*29+$2000 + dw $A0*30+$2000 + dw $A0*31+$2000 + dw $A0*32+$2000 + dw $A0*33+$2000 + dw $A0*34+$2000 + dw $A0*35+$2000 + dw $A0*36+$2000 + dw $A0*37+$2000 + dw $A0*38+$2000 + dw $A0*39+$2000 + dw $A0*40+$2000 + dw $A0*41+$2000 + dw $A0*42+$2000 + dw $A0*43+$2000 + dw $A0*44+$2000 + dw $A0*45+$2000 + dw $A0*46+$2000 + dw $A0*47+$2000 + dw $A0*48+$2000 + dw $A0*49+$2000 + dw $A0*50+$2000 + dw $A0*51+$2000 + dw $A0*52+$2000 + dw $A0*53+$2000 + dw $A0*54+$2000 + dw $A0*55+$2000 + dw $A0*56+$2000 + dw $A0*57+$2000 + dw $A0*58+$2000 + dw $A0*59+$2000 + dw $A0*60+$2000 + dw $A0*61+$2000 + dw $A0*62+$2000 + dw $A0*63+$2000 + dw $A0*64+$2000 + dw $A0*65+$2000 + dw $A0*66+$2000 + dw $A0*67+$2000 + dw $A0*68+$2000 + dw $A0*69+$2000 + dw $A0*70+$2000 + dw $A0*71+$2000 + dw $A0*72+$2000 + dw $A0*73+$2000 + dw $A0*74+$2000 + dw $A0*75+$2000 + dw $A0*76+$2000 + dw $A0*77+$2000 + dw $A0*78+$2000 + dw $A0*79+$2000 + dw $A0*80+$2000 + dw $A0*81+$2000 + dw $A0*82+$2000 + dw $A0*83+$2000 + dw $A0*84+$2000 + dw $A0*85+$2000 + dw $A0*86+$2000 + dw $A0*87+$2000 + dw $A0*88+$2000 + dw $A0*89+$2000 + dw $A0*90+$2000 + dw $A0*91+$2000 + dw $A0*92+$2000 + dw $A0*93+$2000 + dw $A0*94+$2000 + dw $A0*95+$2000 + dw $A0*96+$2000 + dw $A0*97+$2000 + dw $A0*98+$2000 + dw $A0*99+$2000 + dw $A0*100+$2000 + dw $A0*101+$2000 + dw $A0*102+$2000 + dw $A0*103+$2000 + dw $A0*104+$2000 + dw $A0*105+$2000 + dw $A0*106+$2000 + dw $A0*107+$2000 + dw $A0*108+$2000 + dw $A0*109+$2000 + dw $A0*110+$2000 + dw $A0*111+$2000 + dw $A0*112+$2000 + dw $A0*113+$2000 + dw $A0*114+$2000 + dw $A0*115+$2000 + dw $A0*116+$2000 + dw $A0*117+$2000 + dw $A0*118+$2000 + dw $A0*119+$2000 + dw $A0*120+$2000 + dw $A0*121+$2000 + dw $A0*122+$2000 + dw $A0*123+$2000 + dw $A0*124+$2000 + dw $A0*125+$2000 + dw $A0*126+$2000 + dw $A0*127+$2000 + dw $A0*128+$2000 + dw $A0*129+$2000 + dw $A0*130+$2000 + dw $A0*131+$2000 + dw $A0*132+$2000 + dw $A0*133+$2000 + dw $A0*134+$2000 + dw $A0*135+$2000 + dw $A0*136+$2000 + dw $A0*137+$2000 + dw $A0*138+$2000 + dw $A0*139+$2000 + dw $A0*140+$2000 + dw $A0*141+$2000 + dw $A0*142+$2000 + dw $A0*143+$2000 + dw $A0*144+$2000 + dw $A0*145+$2000 + dw $A0*146+$2000 + dw $A0*147+$2000 + dw $A0*148+$2000 + dw $A0*149+$2000 + dw $A0*150+$2000 + dw $A0*151+$2000 + dw $A0*152+$2000 + dw $A0*153+$2000 + dw $A0*154+$2000 + dw $A0*155+$2000 + dw $A0*156+$2000 + dw $A0*157+$2000 + dw $A0*158+$2000 + dw $A0*159+$2000 + dw $A0*160+$2000 + dw $A0*161+$2000 + dw $A0*162+$2000 + dw $A0*163+$2000 + dw $A0*164+$2000 + dw $A0*165+$2000 + dw $A0*166+$2000 + dw $A0*167+$2000 + dw $A0*168+$2000 + dw $A0*169+$2000 + dw $A0*170+$2000 + dw $A0*171+$2000 + dw $A0*172+$2000 + dw $A0*173+$2000 + dw $A0*174+$2000 + dw $A0*175+$2000 + dw $A0*176+$2000 + dw $A0*177+$2000 + dw $A0*178+$2000 + dw $A0*179+$2000 + dw $A0*180+$2000 + dw $A0*181+$2000 + dw $A0*182+$2000 + dw $A0*183+$2000 + dw $A0*184+$2000 + dw $A0*185+$2000 + dw $A0*186+$2000 + dw $A0*187+$2000 + dw $A0*188+$2000 + dw $A0*189+$2000 + dw $A0*190+$2000 + dw $A0*191+$2000 + dw $A0*192+$2000 + dw $A0*193+$2000 + dw $A0*194+$2000 + dw $A0*195+$2000 + dw $A0*196+$2000 + dw $A0*197+$2000 + dw $A0*198+$2000 + dw $A0*199+$2000