2 ; Ullrich von Bassewitz, 21.06.2002
4 ; Common functions of the tgi graphics kernel.
10 .include "tgi-kernel.inc"
11 .include "tgi-error.inc"
14 ;----------------------------------------------------------------------------
19 _tgi_drv: .res 2 ; Pointer to driver
20 ; From here on, variables get cleared when a new driver is loaded
22 _tgi_error: .res 1 ; Last error code
23 _tgi_gmode: .res 1 ; Flag: Graphics mode active
24 _tgi_curx: .res 2 ; Current drawing cursor X
25 _tgi_cury: .res 2 ; Current drawing cursor Y
26 _tgi_color: .res 1 ; Current drawing color
27 _tgi_font: .res 1 ; Which font to use
28 _tgi_textdir: .res 1 ; Current text direction
29 _tgi_vectorfont: .res 2 ; Pointer to vector font
30 ; The following are character scale/size variables in 8.8 fixed point
31 ; format. They are required to be in this order and adjacent.
32 _tgi_textscalew: .res 2 ; Vector font width scale
33 .res 2 ; Bitmap font width scale
34 _tgi_charwidth: .res 2 ; Full width of one bitmap char
35 _tgi_textscaleh: .res 2 ; Vector font height scale
36 .res 2 ; Bitmap font height scale
37 _tgi_charheight: .res 2 ; Full height of one bitmap char
39 ; End of section that gets cleared when a new driver is loaded
42 ; Maximum X and Y coordinate (that is, xres-1 and yres-1)
46 ; The following variables are copied from the driver header for faster access.
47 ; fontwidth and fontheight are expected to be in order and adjacent.
49 _tgi_xres: .res 2 ; X resolution of the current mode
50 _tgi_yres: .res 2 ; Y resolution of the current mode
51 _tgi_colorcount: .res 1 ; Number of available colors
52 _tgi_pagecount: .res 1 ; Number of available screen pages
53 _tgi_fontwidth: .res 1 ; System font width in pixels
54 _tgi_fontheight: .res 1 ; System font height in pixels
55 _tgi_aspectratio: .res 2 ; Aspect ratio in 8.8 fixed point
56 _tgi_flags: .res 1 ; TGI driver flags
61 ; Jump table for the driver functions.
64 tgi_install: jmp $0000
65 tgi_uninstall: jmp $0000
68 tgi_geterror: jmp $0000
69 tgi_control: jmp $0000
71 tgi_setviewpage: jmp $0000
72 tgi_setdrawpage: jmp $0000
73 tgi_setcolor: jmp $0000
74 tgi_setpalette: jmp $0000
75 tgi_getpalette: jmp $0000
76 tgi_getdefpalette: jmp $0000
77 tgi_setpixel: jmp $0000
78 tgi_getpixel: jmp $0000
81 tgi_textstyle: jmp $0000
82 tgi_outtext: jmp $0000
84 ; Driver header signature
86 tgi_sig: .byte $74, $67, $69, TGI_API_VERSION ; "tgi", version
90 ;----------------------------------------------------------------------------
91 ; void __fastcall__ tgi_install (void* driver);
92 ; /* Install an already loaded driver. */
101 ; Check the driver signature
103 ldy #.sizeof(tgi_sig)-1
110 ; Set the library reference
119 ; Copy the jump vectors
121 ldy #TGI_HDR::JUMPTAB
123 @L1: inx ; Skip JMP opcode
124 jsr copy ; Copy one byte
125 jsr copy ; Copy one byte
126 cpy #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB))
129 ; Call the driver install routine. It may update header variables, so we copy
130 ; them after this call.
134 ; Copy variables from the driver header for faster access.
136 jsr tgi_set_ptr ; Set ptr1 to tgi_drv
137 ldy #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1)
138 ldx #.sizeof(TGI_HDR::VARS)-1
140 sta tgi_driver_vars,x
145 ; Initialize some other variables
149 @L4: sta cstart,x ; Clear error/mode/curx/cury/...
155 ; Copy one byte to the jump vectors
163 ;----------------------------------------------------------------------------
164 ; Set an invalid argument error
171 ;----------------------------------------------------------------------------
172 ; Set an invalid driver error
175 lda #TGI_ERR_INV_DRIVER
179 ;----------------------------------------------------------------------------
180 ; Load the pointer to the tgi driver into ptr1.
189 ;----------------------------------------------------------------------------
190 ; void tgi_uninstall (void);
191 ; /* Uninstall the currently loaded driver but do not unload it. Will call
192 ; ** tgi_done if necessary.
196 jsr _tgi_done ; Switch off graphics
198 jsr tgi_uninstall ; Allow the driver to clean up
200 ; Clear driver pointer and error code