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
175 found: ; Check if enough RAM is available
188 nomem: lda #TGI_ERR_NO_MEM
191 ; Switch into graphics mode
202 lda #<screen_device_length
204 lda #>screen_device_length
209 ; Reserve 8K of high memory
213 ; Close and reopen graphics
228 lda #<screen_device_length
230 lda #>screen_device_length
233 ; Save screen pointers
242 ; Reset the error code and return
248 ; ******************************************************************************
252 ; ----------------------------------------------------------------------
254 ; DONE: Switch back to text mode
256 ; ----------------------------------------------------------------------
261 ; Free 8K of high memory
272 ; Close the S: device
277 ; Reopen it in Graphics 0
288 lda #<screen_device_length
290 lda #>screen_device_length
294 ; Now close it again; we don't need it anymore :)
300 ; ******************************************************************************
304 ; ----------------------------------------------------------------------
306 ; GETERROR: Return the error code in A and clear it
308 ; ----------------------------------------------------------------------
317 ; ******************************************************************************
321 ; ----------------------------------------------------------------------
323 ; CLEAR: Clear the screen
325 ; ----------------------------------------------------------------------
328 ; Load the screen address in sptr
339 ; Clear full pages if any
350 ; Clear the rest, if any
360 ; ******************************************************************************
364 ; ----------------------------------------------------------------------
366 ; GETPALETTE: Return the current palette in A/X
368 ; ----------------------------------------------------------------------
376 ; ******************************************************************************
380 ; ----------------------------------------------------------------------
382 ; GETDEFPALETTE: Return the default palette in A/X
384 ; ----------------------------------------------------------------------
387 lda #<default_palette
388 ldx #>default_palette
392 ; ******************************************************************************
396 ; ----------------------------------------------------------------------
398 ; SETCOLOR: Set the drawing color (in A)
400 ; ----------------------------------------------------------------------
406 ; Map colors like this: 0 -> 0, 1 -> 15, 2 -> 1, 3 -> 2 etc.
420 ; ******************************************************************************
424 ; ----------------------------------------------------------------------
426 ; CALC: Calculate the screen address
428 ; x1 (ptr1) x coordinate
429 ; y1 (ptr2) y coordinate
431 ; sptr + y screen address
434 ; ----------------------------------------------------------------------
439 ; calculate line offset
444 .if ::x_res / ::ppb = 40
446 .elseif ::x_res / ::ppb = 20
448 .elseif ::x_res / ::ppb = 10
472 ; calculate bit mask offset
477 ; calculate row offset
509 ; ******************************************************************************
513 ; ----------------------------------------------------------------------
515 ; Draw one pixel at x1, y1
517 ; ----------------------------------------------------------------------
525 ; ******************************************************************************
529 ; ----------------------------------------------------------------------
531 ; GETPIXEL: Read the color value of a pixel and return it in A/X
533 ; ----------------------------------------------------------------------
569 ; Map colors like this: 0 -> 0, 15 -> 1, 2 -> 3, 3 -> 4 etc.
580 ; Map out of range colors like this:
594 .endif ; ::grmode = 10
603 ; ******************************************************************************
607 ; ----------------------------------------------------------------------
609 ; LINE: Draw a line from x1,y1 to x2,y2
611 ; ----------------------------------------------------------------------
615 ; position ptr1, ptr2
665 ; if dx is positive, no problem
668 ; if dx is negative, swap x1,y1 with x2,y2
669 lda x1 ; x1 <-> x2, low byte
673 lda x1 + 1 ; x1 <-> x2, high byte
677 lda y1 ; y1 <-> y2, low byte
681 lda y1 + 1 ; y1 <-> y2, high byte
710 lda #<(65536 - x_res / ppb)
712 lda #>(65536 - x_res / ppb)
714 bne skip_iy_1 ; always
747 ; dx is the major axis
794 ; loop while dx-- >= 0
808 ; dy is the major axis
854 ; loop while dy-- >= 0
866 .endif ; USE_CIO_LINE
869 ; ******************************************************************************
873 ; ----------------------------------------------------------------------
875 ; Clip and draw bar, this function will disappear when text clipping
876 ; will be done int the TGI kernel
878 ; ----------------------------------------------------------------------
889 .if >(::x_res - 1) > 0
908 .if >(::x_res - 1) > 0
919 ; ******************************************************************************
923 ; ----------------------------------------------------------------------
925 ; BAR: Draw a filled rectangle with the corners at x1,y1,x2,y2
927 ; ----------------------------------------------------------------------
943 ; Calculate upper left corner
954 ; Calculate upper right corner
958 .if >(::x_res - 1) > 0
974 ; Calculate memory difference between x1 and x2
1012 cont: ; Go to next row
1018 skipm: ; Loop while --dy > 0
1026 ; ******************************************************************************
1030 ; ----------------------------------------------------------------------
1032 ; TEXTSTYLE: Set text style. Scale factors in X and Y and direction in A
1034 ; ----------------------------------------------------------------------
1039 ; Save text direction in bit 8 so that we can use BIT instruction later
1043 ; Save 8 * scaling factors
1069 ; ******************************************************************************
1073 ; ----------------------------------------------------------------------
1075 ; OUTTEXT: Draw text at x1, y1. String is in ptr3
1077 ; ----------------------------------------------------------------------
1085 ataint: .byte 64,0,32,96
1089 .if >(::x_res - 1) > 0
1102 ; Don't draw zero sized characters
1108 not0: ; Save string address, ptr3 is needed by BAR
1123 .if >(::x_res - 1) > 0
1132 ; Calculate y2 and adjust y1
1144 ; Calculate for vertical text
1170 skiph: ; Save coords
1185 .if >(::x_res - 1) > 0
1192 ; Draw one character
1193 ; Convert to ANTIC code
1204 ; Save and clear inverse video bit
1207 ; Calculate font data address
1232 .if >(::x_res - 1) > 0
1241 ; Put one row of the glyph
1250 ; Put one column of the row
1318 ; Restore old values
1331 .if >(::x_res - 1) > 0
1377 .if >(::x_res - 1) > 0
1400 jne loop ; Check for null character
1406 ; ******************************************************************************
1410 ; ----------------------------------------------------------------------
1412 ; SETVIEWPAGE, page in A
1414 ; ----------------------------------------------------------------------
1423 beq done ; We're already in the desired page
1428 ; Wait until next VBLANK
1429 wait: cpx RTCLOK + 2
1436 ; ******************************************************************************
1440 ; ----------------------------------------------------------------------
1442 ; SETDRAWPAGE, page in A
1444 ; ----------------------------------------------------------------------
1456 ; ******************************************************************************
1458 ; ----------------------------------------------------------------------
1460 ; Unimplemented functions that require an error code
1462 ; ----------------------------------------------------------------------
1465 lda #TGI_ERR_INV_FUNC
1469 ; ******************************************************************************
1471 ; ----------------------------------------------------------------------
1473 ; Unimplemented functions that don't require an error code
1475 ; ----------------------------------------------------------------------