2 ; Generic Atari graphics driver
14 ; ******************************************************************************
16 ; ----------------------------------------------------------------------
18 ; Header. Includes jump table and constants.
20 ; ----------------------------------------------------------------------
34 module_header .ident (.sprintf ("_atr%s%d%s_tgi", LABEL_X, ::grmode, LABEL_P2))
38 .byte $74, $67, $69 ; "tgi"
39 .byte TGI_API_VERSION ; TGI API version number
40 libref: .addr $0000 ; Library reference
41 .word x_res ; X resolution
42 .word y_res ; Y resolution
43 .byte colors ; Number of drawing colors
44 .byte pages ; Number of screens available
45 .byte 8 ; System font X size
46 .byte 8 ; System font Y size
47 .word aspect ; Aspect ratio
48 .byte 0 ; TGI driver flags
72 ; ******************************************************************************
74 ; ----------------------------------------------------------------------
78 ; ----------------------------------------------------------------------
86 ; ******************************************************************************
88 ; ----------------------------------------------------------------------
92 ; ----------------------------------------------------------------------
100 .if ::grmode = 9 || ::grmode = 11
101 palette = default_palette
104 .res colors ; The current palette
108 .res 1 ; Current pixel mask
110 .res 1 ; IOCB channel number for graphics
114 .res 1 ; High byte of screen address for screen page 0
116 .res 1 ; High byte of display list address for screen page 0
117 ; Page 1's addresses are 8K higher
122 .byte 1 ; Horizontal text scaling factor
124 .byte 1 ; Vertical text scaling factor
126 .word 8 ; Horizontal text scaling factor * 8
128 .word 8 ; Vertical text scaling factor * 8
130 .byte 0 ; Text direction,
138 ; ******************************************************************************
142 ; ----------------------------------------------------------------------
144 ; Put a pixel at (sptr),y using x as the bit mask offset
146 ; ----------------------------------------------------------------------
155 ; ******************************************************************************
159 .byte "S:",$9B ; Device code for screen
160 screen_device_length := * - screen_device
166 ; ----------------------------------------------------------------------
168 ; INIT: Switch to graphics mode
170 ; ----------------------------------------------------------------------
174 ; Initialize drawing color
188 ; setup pointer to CIO
206 ; Not enough resources available (free IOCB or memory)
207 ; enter with C cleared!
208 nores: lda #TGI_ERR_NO_RES
211 found: ; Check if enough RAM is available
221 bcc nores ; not enough memory
223 ; Switch into graphics mode
234 lda #<screen_device_length
236 lda #>screen_device_length
241 ; Reserve 8K of high memory
245 ; Close and reopen graphics
260 lda #<screen_device_length
262 lda #>screen_device_length
265 ; Save screen pointers
274 ; Reset the error code and return
280 ; ******************************************************************************
284 ; ----------------------------------------------------------------------
286 ; DONE: Switch back to text mode
288 ; ----------------------------------------------------------------------
293 ; Free 8K of high memory
304 ; Close the S: device
309 ; Reopen it in Graphics 0
320 lda #<screen_device_length
322 lda #>screen_device_length
326 ; Now close it again; we don't need it anymore :)
332 ; ******************************************************************************
336 ; ----------------------------------------------------------------------
338 ; GETERROR: Return the error code in A and clear it
340 ; ----------------------------------------------------------------------
349 ; ******************************************************************************
353 ; ----------------------------------------------------------------------
355 ; CLEAR: Clear the screen
357 ; ----------------------------------------------------------------------
360 ; Load the screen address in sptr
371 ; Clear full pages if any
382 ; Clear the rest, if any
392 ; ******************************************************************************
396 ; ----------------------------------------------------------------------
398 ; GETPALETTE: Return the current palette in A/X
400 ; ----------------------------------------------------------------------
408 ; ******************************************************************************
412 ; ----------------------------------------------------------------------
414 ; GETDEFPALETTE: Return the default palette in A/X
416 ; ----------------------------------------------------------------------
419 lda #<default_palette
420 ldx #>default_palette
424 ; ******************************************************************************
428 ; ----------------------------------------------------------------------
430 ; SETCOLOR: Set the drawing color (in A)
432 ; ----------------------------------------------------------------------
438 ; Map colors like this: 0 -> 0, 1 -> 15, 2 -> 1, 3 -> 2 etc.
452 ; ******************************************************************************
456 ; ----------------------------------------------------------------------
458 ; CALC: Calculate the screen address
460 ; x1 (ptr1) x coordinate
461 ; y1 (ptr2) y coordinate
463 ; sptr + y screen address
466 ; ----------------------------------------------------------------------
471 ; calculate line offset
476 .if ::x_res / ::ppb = 40
478 .elseif ::x_res / ::ppb = 20
480 .elseif ::x_res / ::ppb = 10
504 ; calculate bit mask offset
509 ; calculate row offset
541 ; ******************************************************************************
545 ; ----------------------------------------------------------------------
547 ; Draw one pixel at x1, y1
549 ; ----------------------------------------------------------------------
557 ; ******************************************************************************
561 ; ----------------------------------------------------------------------
563 ; GETPIXEL: Read the color value of a pixel and return it in A/X
565 ; ----------------------------------------------------------------------
601 ; Map colors like this: 0 -> 0, 15 -> 1, 2 -> 3, 3 -> 4 etc.
612 ; Map out of range colors like this:
626 .endif ; ::grmode = 10
635 ; ******************************************************************************
639 ; ----------------------------------------------------------------------
641 ; LINE: Draw a line from x1,y1 to x2,y2
643 ; ----------------------------------------------------------------------
647 ; position ptr1, ptr2
697 ; if dx is positive, no problem
700 ; if dx is negative, swap x1,y1 with x2,y2
701 lda x1 ; x1 <-> x2, low byte
705 lda x1 + 1 ; x1 <-> x2, high byte
709 lda y1 ; y1 <-> y2, low byte
713 lda y1 + 1 ; y1 <-> y2, high byte
742 lda #<(65536 - x_res / ppb)
744 lda #>(65536 - x_res / ppb)
746 bne skip_iy_1 ; always
779 ; dx is the major axis
826 ; loop while dx-- >= 0
840 ; dy is the major axis
886 ; loop while dy-- >= 0
898 .endif ; USE_CIO_LINE
901 ; ******************************************************************************
905 ; ----------------------------------------------------------------------
907 ; Clip and draw bar, this function will disappear when text clipping
908 ; will be done int the TGI kernel
910 ; ----------------------------------------------------------------------
921 .if >(::x_res - 1) > 0
940 .if >(::x_res - 1) > 0
951 ; ******************************************************************************
955 ; ----------------------------------------------------------------------
957 ; BAR: Draw a filled rectangle with the corners at x1,y1,x2,y2
959 ; ----------------------------------------------------------------------
975 ; Calculate upper left corner
986 ; Calculate upper right corner
990 .if >(::x_res - 1) > 0
1006 ; Calculate memory difference between x1 and x2
1044 cont: ; Go to next row
1050 skipm: ; Loop while --dy > 0
1058 ; ******************************************************************************
1062 ; ----------------------------------------------------------------------
1064 ; TEXTSTYLE: Set text style. Scale factors in X and Y and direction in A
1066 ; ----------------------------------------------------------------------
1071 ; Save text direction in bit 8 so that we can use BIT instruction later
1075 ; Save 8 * scaling factors
1101 ; ******************************************************************************
1105 ; ----------------------------------------------------------------------
1107 ; OUTTEXT: Draw text at x1, y1. String is in ptr3
1109 ; ----------------------------------------------------------------------
1117 ataint: .byte 64,0,32,96
1121 .if >(::x_res - 1) > 0
1134 ; Don't draw zero sized characters
1140 not0: ; Save string address, ptr3 is needed by BAR
1155 .if >(::x_res - 1) > 0
1164 ; Calculate y2 and adjust y1
1176 ; Calculate for vertical text
1202 skiph: ; Save coords
1217 .if >(::x_res - 1) > 0
1224 ; Draw one character
1225 ; Convert to ANTIC code
1236 ; Save and clear inverse video bit
1239 ; Calculate font data address
1264 .if >(::x_res - 1) > 0
1273 ; Put one row of the glyph
1282 ; Put one column of the row
1350 ; Restore old values
1363 .if >(::x_res - 1) > 0
1409 .if >(::x_res - 1) > 0
1432 jne loop ; Check for null character
1438 ; ******************************************************************************
1442 ; ----------------------------------------------------------------------
1444 ; SETVIEWPAGE, page in A
1446 ; ----------------------------------------------------------------------
1455 beq done ; We're already in the desired page
1460 ; Wait until next VBLANK
1461 wait: cpx RTCLOK + 2
1468 ; ******************************************************************************
1472 ; ----------------------------------------------------------------------
1474 ; SETDRAWPAGE, page in A
1476 ; ----------------------------------------------------------------------
1488 ; ******************************************************************************
1490 ; ----------------------------------------------------------------------
1492 ; Unimplemented functions that require an error code
1494 ; ----------------------------------------------------------------------
1497 lda #TGI_ERR_INV_FUNC
1501 ; ******************************************************************************
1503 ; ----------------------------------------------------------------------
1505 ; Unimplemented functions that don't require an error code
1507 ; ----------------------------------------------------------------------