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
28 .byte 0 ; TGI driver flags
51 .addr 0 ; IRQ entry is unused
53 ; ******************************************************************************
55 ; ----------------------------------------------------------------------
59 ; ----------------------------------------------------------------------
67 ; ******************************************************************************
69 ; ----------------------------------------------------------------------
73 ; ----------------------------------------------------------------------
81 .if ::grmode = 9 || ::grmode = 11
82 palette = default_palette
85 .res colors ; The current palette
89 .res 1 ; Current pixel mask
91 .res 1 ; IOCB channel number for graphics
95 .res 1 ; High byte of screen address for screen page 0
97 .res 1 ; High byte of display list address for screen page 0
98 ; Page 1's addresses are 8K higher
103 .byte 1 ; Horizontal text scaling factor
105 .byte 1 ; Vertical text scaling factor
107 .word 8 ; Horizontal text scaling factor * 8
109 .word 8 ; Vertical text scaling factor * 8
111 .byte 0 ; Text direction,
115 ; ******************************************************************************
119 ; ----------------------------------------------------------------------
121 ; Put a pixel at (sptr),y using x as the bit mask offset
123 ; ----------------------------------------------------------------------
132 ; ******************************************************************************
136 .byte "S:",$9B ; Device code for screen
137 screen_device_length := * - screen_device
143 ; ----------------------------------------------------------------------
145 ; INIT: Switch to graphics mode
147 ; ----------------------------------------------------------------------
151 ; Initialize drawing color
172 ; Not enough resources available (free IOCB or memory)
173 ; enter with C cleared!
174 nores: lda #TGI_ERR_NO_RES
177 found: ; Check if enough RAM is available
187 bcc nores ; not enough memory
189 ; Switch into graphics mode
200 lda #<screen_device_length
202 lda #>screen_device_length
207 ; Reserve 8K of high memory
211 ; Close and reopen graphics
226 lda #<screen_device_length
228 lda #>screen_device_length
231 ; Save screen pointers
240 ; Reset the error code and return
246 ; ******************************************************************************
250 ; ----------------------------------------------------------------------
252 ; DONE: Switch back to text mode
254 ; ----------------------------------------------------------------------
259 ; Free 8K of high memory
270 ; Close the S: device
275 ; Reopen it in Graphics 0
286 lda #<screen_device_length
288 lda #>screen_device_length
292 ; Now close it again; we don't need it anymore :)
298 ; ******************************************************************************
302 ; ----------------------------------------------------------------------
304 ; GETERROR: Return the error code in A and clear it
306 ; ----------------------------------------------------------------------
315 ; ******************************************************************************
319 ; ----------------------------------------------------------------------
321 ; CLEAR: Clear the screen
323 ; ----------------------------------------------------------------------
326 ; Load the screen address in sptr
337 ; Clear full pages if any
348 ; Clear the rest, if any
358 ; ******************************************************************************
362 ; ----------------------------------------------------------------------
364 ; GETPALETTE: Return the current palette in A/X
366 ; ----------------------------------------------------------------------
374 ; ******************************************************************************
378 ; ----------------------------------------------------------------------
380 ; GETDEFPALETTE: Return the default palette in A/X
382 ; ----------------------------------------------------------------------
385 lda #<default_palette
386 ldx #>default_palette
390 ; ******************************************************************************
394 ; ----------------------------------------------------------------------
396 ; SETCOLOR: Set the drawing color (in A)
398 ; ----------------------------------------------------------------------
404 ; Map colors like this: 0 -> 0, 1 -> 15, 2 -> 1, 3 -> 2 etc.
418 ; ******************************************************************************
422 ; ----------------------------------------------------------------------
424 ; CALC: Calculate the screen address
426 ; x1 (ptr1) x coordinate
427 ; y1 (ptr2) y coordinate
429 ; sptr + y screen address
432 ; ----------------------------------------------------------------------
437 ; calculate line offset
442 .if ::x_res / ::ppb = 40
444 .elseif ::x_res / ::ppb = 20
446 .elseif ::x_res / ::ppb = 10
470 ; calculate bit mask offset
475 ; calculate row offset
507 ; ******************************************************************************
511 ; ----------------------------------------------------------------------
513 ; Draw one pixel at x1, y1
515 ; ----------------------------------------------------------------------
523 ; ******************************************************************************
527 ; ----------------------------------------------------------------------
529 ; GETPIXEL: Read the color value of a pixel and return it in A/X
531 ; ----------------------------------------------------------------------
567 ; Map colors like this: 0 -> 0, 15 -> 1, 2 -> 3, 3 -> 4 etc.
578 ; Map out of range colors like this:
592 .endif ; ::grmode = 10
601 ; ******************************************************************************
605 ; ----------------------------------------------------------------------
607 ; LINE: Draw a line from x1,y1 to x2,y2
609 ; ----------------------------------------------------------------------
613 ; position ptr1, ptr2
663 ; if dx is positive, no problem
666 ; if dx is negative, swap x1,y1 with x2,y2
667 lda x1 ; x1 <-> x2, low byte
671 lda x1 + 1 ; x1 <-> x2, high byte
675 lda y1 ; y1 <-> y2, low byte
679 lda y1 + 1 ; y1 <-> y2, high byte
708 lda #<(65536 - x_res / ppb)
710 lda #>(65536 - x_res / ppb)
712 bne skip_iy_1 ; always
745 ; dx is the major axis
792 ; loop while dx-- >= 0
806 ; dy is the major axis
852 ; loop while dy-- >= 0
864 .endif ; USE_CIO_LINE
867 ; ******************************************************************************
871 ; ----------------------------------------------------------------------
873 ; Clip and draw bar, this function will disappear when text clipping
874 ; will be done int the TGI kernel
876 ; ----------------------------------------------------------------------
887 .if >(::x_res - 1) > 0
906 .if >(::x_res - 1) > 0
917 ; ******************************************************************************
921 ; ----------------------------------------------------------------------
923 ; BAR: Draw a filled rectangle with the corners at x1,y1,x2,y2
925 ; ----------------------------------------------------------------------
941 ; Calculate upper left corner
952 ; Calculate upper right corner
956 .if >(::x_res - 1) > 0
972 ; Calculate memory difference between x1 and x2
1010 cont: ; Go to next row
1016 skipm: ; Loop while --dy > 0
1024 ; ******************************************************************************
1028 ; ----------------------------------------------------------------------
1030 ; TEXTSTYLE: Set text style. Scale factors in X and Y and direction in A
1032 ; ----------------------------------------------------------------------
1037 ; Save text direction in bit 8 so that we can use BIT instruction later
1041 ; Save 8 * scaling factors
1067 ; ******************************************************************************
1071 ; ----------------------------------------------------------------------
1073 ; OUTTEXT: Draw text at x1, y1. String is in ptr3
1075 ; ----------------------------------------------------------------------
1083 ataint: .byte 64,0,32,96
1087 .if >(::x_res - 1) > 0
1100 ; Don't draw zero sized characters
1106 not0: ; Save string address, ptr3 is needed by BAR
1121 .if >(::x_res - 1) > 0
1130 ; Calculate y2 and adjust y1
1142 ; Calculate for vertical text
1168 skiph: ; Save coords
1183 .if >(::x_res - 1) > 0
1190 ; Draw one character
1191 ; Convert to ANTIC code
1202 ; Save and clear inverse video bit
1205 ; Calculate font data address
1230 .if >(::x_res - 1) > 0
1239 ; Put one row of the glyph
1248 ; Put one column of the row
1316 ; Restore old values
1329 .if >(::x_res - 1) > 0
1375 .if >(::x_res - 1) > 0
1398 jne loop ; Check for null character
1404 ; ******************************************************************************
1408 ; ----------------------------------------------------------------------
1410 ; SETVIEWPAGE, page in A
1412 ; ----------------------------------------------------------------------
1421 beq done ; We're already in the desired page
1426 ; Wait until next VBLANK
1427 wait: cpx RTCLOK + 2
1434 ; ******************************************************************************
1438 ; ----------------------------------------------------------------------
1440 ; SETDRAWPAGE, page in A
1442 ; ----------------------------------------------------------------------
1454 ; ******************************************************************************
1456 ; ----------------------------------------------------------------------
1458 ; Unimplemented functions that require an error code
1460 ; ----------------------------------------------------------------------
1463 lda #TGI_ERR_INV_FUNC
1467 ; ******************************************************************************
1469 ; ----------------------------------------------------------------------
1471 ; Unimplemented functions that don't require an error code
1473 ; ----------------------------------------------------------------------