2 ; Generic Atari graphics driver
7 ; ******************************************************************************
9 ; ----------------------------------------------------------------------
11 ; Header. Includes jump table and constants.
13 ; ----------------------------------------------------------------------
19 .byte $74, $67, $69 ; "tgi"
20 .byte TGI_API_VERSION ; TGI API version number
21 .word x_res ; X resolution
22 .word y_res ; Y resolution
23 .byte colors ; Number of drawing colors
24 .byte pages ; Number of screens available
25 .byte 8 ; System font X size
26 .byte 8 ; System font Y size
27 .word aspect ; Aspect ratio
50 .addr 0 ; IRQ entry is unused
52 ; ******************************************************************************
54 ; ----------------------------------------------------------------------
58 ; ----------------------------------------------------------------------
66 ; ******************************************************************************
68 ; ----------------------------------------------------------------------
72 ; ----------------------------------------------------------------------
80 .if ::grmode = 9 || ::grmode = 11
81 palette = default_palette
84 .res colors ; The current palette
88 .res 1 ; Current pixel mask
90 .res 1 ; IOCB channel number for graphics
94 .res 1 ; High byte of screen address for screen page 0
96 .res 1 ; High byte of display list address for screen page 0
97 ; Page 1's addresses are 8K higher
102 .byte 1 ; Horizontal text scaling factor
104 .byte 1 ; Vertical text scaling factor
106 .word 8 ; Horizontal text scaling factor * 8
108 .word 8 ; Vertical text scaling factor * 8
110 .byte 0 ; Text direction,
114 ; ******************************************************************************
118 ; ----------------------------------------------------------------------
120 ; Put a pixel at (sptr),y using x as the bit mask offset
122 ; ----------------------------------------------------------------------
131 ; ******************************************************************************
135 .byte "S:",$9B ; Device code for screen
136 screen_device_length := * - screen_device
142 ; ----------------------------------------------------------------------
144 ; INIT: Switch to graphics mode
146 ; ----------------------------------------------------------------------
150 ; Initialize drawing color
171 ; Not enough resources available (free IOCB or memory)
172 ; enter with C cleared!
173 nores: lda #TGI_ERR_NO_RES
176 found: ; Check if enough RAM is available
186 bcc nores ; not enough memory
188 ; Switch into graphics mode
199 lda #<screen_device_length
201 lda #>screen_device_length
206 ; Reserve 8K of high memory
210 ; Close and reopen graphics
225 lda #<screen_device_length
227 lda #>screen_device_length
230 ; Save screen pointers
239 ; Reset the error code and return
245 ; ******************************************************************************
249 ; ----------------------------------------------------------------------
251 ; DONE: Switch back to text mode
253 ; ----------------------------------------------------------------------
258 ; Free 8K of high memory
269 ; Close the S: device
274 ; Reopen it in Graphics 0
285 lda #<screen_device_length
287 lda #>screen_device_length
291 ; Now close it again; we don't need it anymore :)
297 ; ******************************************************************************
301 ; ----------------------------------------------------------------------
303 ; GETERROR: Return the error code in A and clear it
305 ; ----------------------------------------------------------------------
314 ; ******************************************************************************
318 ; ----------------------------------------------------------------------
320 ; CLEAR: Clear the screen
322 ; ----------------------------------------------------------------------
325 ; Load the screen address in sptr
336 ; Clear full pages if any
347 ; Clear the rest, if any
357 ; ******************************************************************************
361 ; ----------------------------------------------------------------------
363 ; GETPALETTE: Return the current palette in A/X
365 ; ----------------------------------------------------------------------
373 ; ******************************************************************************
377 ; ----------------------------------------------------------------------
379 ; GETDEFPALETTE: Return the default palette in A/X
381 ; ----------------------------------------------------------------------
384 lda #<default_palette
385 ldx #>default_palette
389 ; ******************************************************************************
393 ; ----------------------------------------------------------------------
395 ; SETCOLOR: Set the drawing color (in A)
397 ; ----------------------------------------------------------------------
403 ; Map colors like this: 0 -> 0, 1 -> 15, 2 -> 1, 3 -> 2 etc.
417 ; ******************************************************************************
421 ; ----------------------------------------------------------------------
423 ; CALC: Calculate the screen address
425 ; x1 (ptr1) x coordinate
426 ; y1 (ptr2) y coordinate
428 ; sptr + y screen address
431 ; ----------------------------------------------------------------------
436 ; calculate line offset
441 .if ::x_res / ::ppb = 40
443 .elseif ::x_res / ::ppb = 20
445 .elseif ::x_res / ::ppb = 10
469 ; calculate bit mask offset
474 ; calculate row offset
506 ; ******************************************************************************
510 ; ----------------------------------------------------------------------
512 ; Draw one pixel at x1, y1
514 ; ----------------------------------------------------------------------
522 ; ******************************************************************************
526 ; ----------------------------------------------------------------------
528 ; GETPIXEL: Read the color value of a pixel and return it in A/X
530 ; ----------------------------------------------------------------------
566 ; Map colors like this: 0 -> 0, 15 -> 1, 2 -> 3, 3 -> 4 etc.
577 ; Map out of range colors like this:
591 .endif ; ::grmode = 10
600 ; ******************************************************************************
604 ; ----------------------------------------------------------------------
606 ; LINE: Draw a line from x1,y1 to x2,y2
608 ; ----------------------------------------------------------------------
612 ; position ptr1, ptr2
662 ; if dx is positive, no problem
665 ; if dx is negative, swap x1,y1 with x2,y2
666 lda x1 ; x1 <-> x2, low byte
670 lda x1 + 1 ; x1 <-> x2, high byte
674 lda y1 ; y1 <-> y2, low byte
678 lda y1 + 1 ; y1 <-> y2, high byte
707 lda #<(65536 - x_res / ppb)
709 lda #>(65536 - x_res / ppb)
711 bne skip_iy_1 ; always
744 ; dx is the major axis
791 ; loop while dx-- >= 0
805 ; dy is the major axis
851 ; loop while dy-- >= 0
863 .endif ; USE_CIO_LINE
866 ; ******************************************************************************
870 ; ----------------------------------------------------------------------
872 ; Clip and draw bar, this function will disappear when text clipping
873 ; will be done int the TGI kernel
875 ; ----------------------------------------------------------------------
886 .if >(::x_res - 1) > 0
905 .if >(::x_res - 1) > 0
916 ; ******************************************************************************
920 ; ----------------------------------------------------------------------
922 ; BAR: Draw a filled rectangle with the corners at x1,y1,x2,y2
924 ; ----------------------------------------------------------------------
940 ; Calculate upper left corner
951 ; Calculate upper right corner
955 .if >(::x_res - 1) > 0
971 ; Calculate memory difference between x1 and x2
1009 cont: ; Go to next row
1015 skipm: ; Loop while --dy > 0
1023 ; ******************************************************************************
1027 ; ----------------------------------------------------------------------
1029 ; TEXTSTYLE: Set text style. Scale factors in X and Y and direction in A
1031 ; ----------------------------------------------------------------------
1036 ; Save text direction in bit 8 so that we can use BIT instruction later
1040 ; Save 8 * scaling factors
1066 ; ******************************************************************************
1070 ; ----------------------------------------------------------------------
1072 ; OUTTEXT: Draw text at x1, y1. String is in ptr3
1074 ; ----------------------------------------------------------------------
1082 ataint: .byte 64,0,32,96
1086 .if >(::x_res - 1) > 0
1099 ; Don't draw zero sized characters
1105 not0: ; Save string address, ptr3 is needed by BAR
1120 .if >(::x_res - 1) > 0
1129 ; Calculate y2 and adjust y1
1141 ; Calculate for vertical text
1167 skiph: ; Save coords
1182 .if >(::x_res - 1) > 0
1189 ; Draw one character
1190 ; Convert to ANTIC code
1201 ; Save and clear inverse video bit
1204 ; Calculate font data address
1229 .if >(::x_res - 1) > 0
1238 ; Put one row of the glyph
1247 ; Put one column of the row
1315 ; Restore old values
1328 .if >(::x_res - 1) > 0
1374 .if >(::x_res - 1) > 0
1397 jne loop ; Check for null character
1403 ; ******************************************************************************
1407 ; ----------------------------------------------------------------------
1409 ; SETVIEWPAGE, page in A
1411 ; ----------------------------------------------------------------------
1420 beq done ; We're already in the desired page
1425 ; Wait until next VBLANK
1426 wait: cpx RTCLOK + 2
1433 ; ******************************************************************************
1437 ; ----------------------------------------------------------------------
1439 ; SETDRAWPAGE, page in A
1441 ; ----------------------------------------------------------------------
1453 ; ******************************************************************************
1455 ; ----------------------------------------------------------------------
1457 ; Unimplemented functions that require an error code
1459 ; ----------------------------------------------------------------------
1462 lda #TGI_ERR_INV_FUNC
1466 ; ******************************************************************************
1468 ; ----------------------------------------------------------------------
1470 ; Unimplemented functions that don't require an error code
1472 ; ----------------------------------------------------------------------