1; 2; Graphics driver for the 280x192x8 mode on the Apple II 3; 4; Stefan Haubenthal <polluks@sdf.lonestar.org> 5; Oliver Schmidt <ol.sc@web.de> 6; 7 8 .include "zeropage.inc" 9 10 .include "tgi-kernel.inc" 11 .include "tgi-error.inc" 12 .include "apple2.inc" 13 14 .macpack module 15 16; ------------------------------------------------------------------------ 17 18; Zero page stuff 19 20HBASL := $26 21HMASK := $30 22PAGE := $E6 23SCALE := $E7 24ROT := $F9 25 26; Graphics entry points, by cbmnut (applenut??) cbmnut@hushmail.com 27 28TEXT := $F399 ; Return to text screen 29HGR2 := $F3D8 ; Initialize and clear hi-res page 2. 30HGR := $F3E2 ; Initialize and clear hi-res page 1. 31HCLR := $F3F2 ; Clear the current hi-res screen to black. 32BKGND := $F3F6 ; Clear the current hi-res screen to the 33 ; last plotted color (from ($1C). 34HPOSN := $F411 ; Positions the hi-res cursor without 35 ; plotting a point. 36 ; Enter with (A) = Y-coordinate, and 37 ; (Y,X) = X-coordinate. 38HPLOT := $F457 ; Calls HPOSN and tries to plot a dot at 39 ; the cursor's position. If you are 40 ; trying to plot a non-white color at 41 ; a complementary color position, no 42 ; dot will be plotted. 43HLIN := $F53A ; Draws a line from the last plotted 44 ; point or line destination to: 45 ; (X,A) = X-coordinate, and 46 ; (Y) = Y-coordinate. 47HFIND := $F5CB ; Converts the hi-res coursor's position 48 ; back to X- and Y-coordinates; stores 49 ; X-coordinate at $E0,E1 and Y-coordinate 50 ; at $E2. 51DRAW := $F601 ; Draws a shape. Enter with (Y,X) = the 52 ; address of the shape table, and (A) = 53 ; the rotation factor. Uses the current 54 ; color. 55XDRAW := $F65D ; Draws a shape by inverting the existing 56 ; color of the dots the shape draws over. 57 ; Same entry parameters as DRAW. 58SETHCOL := $F6EC ; Set the hi-res color to (X), where (X) 59 ; must be between 0 and 7. 60 61; ------------------------------------------------------------------------ 62 63; Variables mapped to the zero page segment variables. Some of these are 64; used for passing parameters to the driver. 65 66X1 := ptr1 67Y1 := ptr2 68X2 := ptr3 69Y2 := ptr4 70 71; ------------------------------------------------------------------------ 72 73 .ifdef __APPLE2ENH__ 74 module_header _a2e_hi_tgi 75 .else 76 module_header _a2_hi_tgi 77 .endif 78 79; Header. Includes jump table and constants. 80 81; First part of the header is a structure that has a magic and defines the 82; capabilities of the driver 83 84 .byte $74, $67, $69 ; "tgi" 85 .byte TGI_API_VERSION ; TGI API version number 86 .addr $0000 ; Library reference 87 .word 280 ; X resolution 88 .word 192 ; Y resolution 89 .byte 8 ; Number of drawing colors 90pages: .byte 2 ; Number of screens available 91 .byte 7 ; System font X size 92 .byte 8 ; System font Y size 93 .word $00EA ; Aspect ratio (based on 4/3 display) 94 .byte 0 ; TGI driver flags 95 96; Next comes the jump table. With the exception of IRQ, all entries must be 97; valid and may point to an RTS for test versions (function not implemented). 98 99 .addr INSTALL 100 .addr UNINSTALL 101 .addr INIT 102 .addr DONE 103 .addr GETERROR 104 .addr CONTROL 105 .addr CLEAR 106 .addr SETVIEWPAGE 107 .addr SETDRAWPAGE 108 .addr SETCOLOR 109 .addr SETPALETTE 110 .addr GETPALETTE 111 .addr GETDEFPALETTE 112 .addr SETPIXEL 113 .addr GETPIXEL 114 .addr LINE 115 .addr BAR 116 .addr TEXTSTYLE 117 .addr OUTTEXT 118 119; ------------------------------------------------------------------------ 120 121 .bss 122 123; Absolute variables used in the code 124 125ERROR: .res 1 ; Error code 126 127; ------------------------------------------------------------------------ 128 129 .rodata 130 131; Constants and tables 132 133DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07 134 135FONT: 136 ; Beagle Bros Shape Mechanic font F.ASCII.SMALL 137 ; modified to exactly reproduce the text glyphs 138 .incbin "a2.hi.fnt" 139 140; ------------------------------------------------------------------------ 141 142 .code 143 144; INSTALL routine. Is called after the driver is loaded into memory. May 145; initialize anything that has to be done just once. Is probably empty 146; most of the time. 147; Must set an error code: NO 148INSTALL: 149 .ifdef __APPLE2ENH__ 150 ; No page switching if 80 column store is enabled 151 bit RD80COL 152 bpl :+ 153 lda #$01 154 sta pages 155: .endif 156 157 ; Fall through 158 159; UNINSTALL routine. Is called before the driver is removed from memory. May 160; clean up anything done by INSTALL but is probably empty most of the time. 161; Must set an error code: NO 162UNINSTALL: 163 rts 164 165; INIT: Changes an already installed device from text mode to graphics mode. 166; Note that INIT/DONE may be called multiple times while the driver 167; is loaded, while INSTALL is only called once, so any code that is needed 168; to initializes variables and so on must go here. Setting palette and 169; clearing the screen is not needed because this is called by the graphics 170; kernel later. 171; The graphics kernel will never call INIT when a graphics mode is already 172; active, so there is no need to protect against that. 173; Must set an error code: YES 174INIT: 175 ; Switch into graphics mode 176 bit MIXCLR 177 bit HIRES 178 .ifdef __APPLE2ENH__ 179 sta IOUDISON 180 bit DHIRESOFF 181 .endif 182 bit TXTCLR 183 184 ; Beagle Bros Shape Mechanic fonts don't 185 ; scale well so use fixed scaling factor 186 lda #$01 187 sta SCALE 188 189 ; Done, reset the error code 190 lda #TGI_ERR_OK 191 sta ERROR 192 rts 193 194; DONE: Will be called to switch the graphics device back into text mode. 195; The graphics kernel will never call DONE when no graphics mode is active, 196; so there is no need to protect against that. 197; Must set an error code: NO 198DONE: 199 ; Switch into text mode 200 bit TXTSET 201 bit LOWSCR 202 203 .ifdef __APPLE2ENH__ 204 ; Limit SET80COL-HISCR to text 205 bit LORES 206 .endif 207 208 ; Reset the text window top 209 lda #$00 210 sta WNDTOP 211 rts 212 213; GETERROR: Return the error code in A and clear it. 214GETERROR: 215 lda ERROR 216 ldx #TGI_ERR_OK 217 stx ERROR 218 rts 219 220; CONTROL: Platform/driver specific entry point. 221; Must set an error code: YES 222CONTROL: 223 ; Check data msb and code to be 0 224 ora ptr1+1 225 bne err 226 227 ; Check data lsb to be [0..1] 228 lda ptr1 229 cmp #1+1 230 bcs err 231 232 ; Set text window top 233 tax 234 beq :+ 235 lda #20 236: sta WNDTOP 237 238 ; Switch 4 lines of text 239 .assert MIXCLR + 1 = MIXSET, error 240 lda MIXCLR,x ; No BIT absolute,X available 241 242 ; Done, reset the error code 243 lda #TGI_ERR_OK 244 beq :+ ; Branch always 245 246 ; Done, set the error code 247err: lda #TGI_ERR_INV_ARG 248: sta ERROR 249 rts 250 251; CLEAR: Clears the screen. 252; Must set an error code: NO 253CLEAR: 254 bit $C082 ; Switch in ROM 255 jsr HCLR 256 bit $C080 ; Switch in LC bank 2 for R/O 257 rts 258 259; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n). 260; The page number is already checked to be valid by the graphics kernel. 261; Must set an error code: NO (will only be called if page ok) 262SETVIEWPAGE: 263 tax 264 .assert LOWSCR + 1 = HISCR, error 265 lda LOWSCR,x ; No BIT absolute,X available 266 rts 267 268; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n). 269; The page number is already checked to be valid by the graphics kernel. 270; Must set an error code: NO (will only be called if page ok) 271SETDRAWPAGE: 272 tax 273 beq :+ 274 lda #>$4000 ; Page 2 275 .byte $2C ; BIT absolute 276: lda #>$2000 ; Page 1 277 sta PAGE 278 rts 279 280; SETCOLOR: Set the drawing color (in A). The new color is already checked 281; to be in a valid range (0..maxcolor-1). 282; Must set an error code: NO (will only be called if color ok) 283SETCOLOR: 284 bit $C082 ; Switch in ROM 285 tax 286 jsr SETHCOL 287 bit $C080 ; Switch in LC bank 2 for R/O 288 rts 289 290; SETPALETTE: Set the palette (not available with all drivers/hardware). 291; A pointer to the palette is passed in ptr1. Must set an error if palettes 292; are not supported 293; Must set an error code: YES 294SETPALETTE: 295 lda #TGI_ERR_INV_FUNC 296 sta ERROR 297 rts 298 299; GETPALETTE: Return the current palette in A/X. Even drivers that cannot 300; set the palette should return the default palette here, so there's no 301; way for this function to fail. 302; Must set an error code: NO 303GETPALETTE: 304 ; Fall through 305 306; GETDEFPALETTE: Return the default palette for the driver in A/X. All 307; drivers should return something reasonable here, even drivers that don't 308; support palettes, otherwise the caller has no way to determine the colors 309; of the (not changeable) palette. 310; Must set an error code: NO (all drivers must have a default palette) 311GETDEFPALETTE: 312 lda #<DEFPALETTE 313 ldx #>DEFPALETTE 314 rts 315 316; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing 317; color. The coordinates passed to this function are never outside the 318; visible screen area, so there is no need for clipping inside this function. 319; Must set an error code: NO 320SETPIXEL: 321 bit $C082 ; Switch in ROM 322 ldx X1 323 ldy X1+1 324 lda Y1 325 jsr HPLOT 326 bit $C080 ; Switch in LC bank 2 for R/O 327 rts 328 329; GETPIXEL: Read the color value of a pixel and return it in A/X. The 330; coordinates passed to this function are never outside the visible screen 331; area, so there is no need for clipping inside this function. 332GETPIXEL: 333 bit $C082 ; Switch in ROM 334 ldx X1 335 ldy X1+1 336 lda Y1 337 jsr HPOSN 338 lda (HBASL),y 339 and HMASK 340 asl 341 beq :+ ; 0 (black) 342 lda #$03 ; 3 (white) 343: bcc :+ 344 adc #$03 ; += 4 (black -> black2, white -> white2) 345: ldx #$00 346 bit $C080 ; Switch in LC bank 2 for R/O 347 rts 348 349; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and 350; X2/Y2 = ptr3/ptr4 using the current drawing color. 351; Must set an error code: NO 352LINE: 353 bit $C082 ; Switch in ROM 354 ldx X1 355 ldy X1+1 356 lda Y1 357 jsr HPOSN 358 lda X2 359 ldx X2+1 360 ldy Y2 361 jsr HLIN 362 bit $C080 ; Switch in LC bank 2 for R/O 363 rts 364 365; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where 366; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color. 367; Contrary to most other functions, the graphics kernel will sort and clip 368; the coordinates before calling the driver, so on entry the following 369; conditions are valid: 370; X1 <= X2 371; Y1 <= Y2 372; (X1 >= 0) && (X1 < XRES) 373; (X2 >= 0) && (X2 < XRES) 374; (Y1 >= 0) && (Y1 < YRES) 375; (Y2 >= 0) && (Y2 < YRES) 376; Must set an error code: NO 377BAR: 378 inc Y2 379: lda Y2 380 pha 381 lda Y1 382 sta Y2 383 jsr LINE 384 pla 385 sta Y2 386 inc Y1 387 cmp Y1 388 bne :- 389 rts 390 391; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y 392; direction is passend in X/Y, the text direction is passed in A. 393; Must set an error code: NO 394TEXTSTYLE: 395 cmp #TGI_TEXT_VERTICAL 396 bne :+ 397 lda #48 398: sta ROT 399 rts 400 401; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the 402; current text style. The text to output is given as a zero terminated 403; string with address in ptr3. 404; Must set an error code: NO 405OUTTEXT: 406 bit $C082 ; Switch in ROM 407 lda X1 408 ldy X1+1 409 ldx ROT 410 php ; Save Z flag 411 beq :+ ; Not horizontal 412 sec 413 sbc #$07 ; Adjust X 414 bcs :+ 415 dey 416: tax 417 lda Y1 418 plp ; Restore Z flag 419 bne :+ ; Not vertical 420 sec 421 sbc #$07 ; Adjust Y 422: jsr HPOSN 423 clc 424 lda FONT+2*99 ; "connection char" 425 adc #<FONT 426 sta ptr4 427 lda FONT+2*99+1 ; "connection char" 428 adc #>FONT 429 sta ptr4+1 430 ldy #$00 431: lda (ptr3),y 432 beq :+ 433 sty tmp1 ; Save string index 434 sec 435 sbc #$1F ; No control chars 436 asl ; Offset * 2 437 tay 438 clc 439 lda FONT,y 440 adc #<FONT 441 tax 442 lda FONT+1,y 443 adc #>FONT 444 tay 445 lda ROT 446 jsr DRAW ; Draw char from string 447 ldx ptr4 448 ldy ptr4+1 449 lda ROT 450 jsr DRAW ; Draw "connection char" 451 ldy tmp1 ; Restore string index 452 iny 453 bne :- ; Branch always 454: bit $C080 ; Switch in LC bank 2 for R/O 455 rts 456