2 ; Ullrich von Bassewitz, 21.06.2002
4 ; Common functions of the tgi graphics kernel.
7 .include "tgi-kernel.inc"
8 .include "tgi-error.inc"
11 .interruptor tgi_irq ; Export as IRQ handler
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 two store an 8.8 fixed point value in the first two bytes,
31 ; and a rounded integer value in the third byte. The latter is passed to the
32 ; driver to scale the bitmap font. The variables are expected to be in
33 ; this order and adjacent.
34 _tgi_textscalew: .res 3 ; Text scale for the width
35 _tgi_textscaleh: .res 3 ; Text scale for the height
37 ; The following two must also be in exactly this order
38 _tgi_charwidth: .res 1 ; Char width of system font
39 _tgi_charheight: .res 1 ; Char height of system font
41 ; End of section that gets cleared when a new driver is loaded
44 ; Maximum X and Y coordinate (that is, xres-1 and yres-1)
48 ; The following variables are copied from the driver header for faster access
49 ; fontwidth and fontheight are expected to be in order and adjacent.
51 _tgi_xres: .res 2 ; X resolution of the current mode
52 _tgi_yres: .res 2 ; Y resolution of the current mode
53 _tgi_colorcount: .res 1 ; Number of available colors
54 _tgi_pagecount: .res 1 ; Number of available screen pages
55 _tgi_fontwidth: .res 1 ; System font width in pixels
56 _tgi_fontheight: .res 1 ; System font height in pixels
57 _tgi_aspectratio: .res 2 ; Aspect ratio in 8.8 fixed point
62 ; Jump table for the driver functions.
65 tgi_install: jmp $0000
66 tgi_uninstall: jmp $0000
69 tgi_geterror: jmp $0000
70 tgi_control: jmp $0000
72 tgi_setviewpage: jmp $0000
73 tgi_setdrawpage: jmp $0000
74 tgi_setcolor: jmp $0000
75 tgi_setpalette: jmp $0000
76 tgi_getpalette: jmp $0000
77 tgi_getdefpalette: jmp $0000
78 tgi_setpixel: jmp $0000
79 tgi_getpixel: jmp $0000
82 tgi_textstyle: jmp $0000
83 tgi_outtext: jmp $0000
84 tgi_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
86 ; Driver header signature
88 tgi_sig: .byte $74, $67, $69, TGI_API_VERSION ; "tgi", version
92 ;----------------------------------------------------------------------------
93 ; void __fastcall__ tgi_install (void* driver);
94 ; /* Install an already loaded driver. */
103 ; Check the driver signature
105 ldy #.sizeof(tgi_sig)-1
112 ; Copy the jump vectors
114 ldy #TGI_HDR::JUMPTAB
116 @L1: inx ; Skip JMP opcode
117 jsr copy ; Copy one byte
118 jsr copy ; Copy one byte
119 cpy #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB))
122 ; Call the driver install routine. It may update header variables, so we copy
123 ; them after this call.
127 ; Copy variables from the driver header for faster access.
129 jsr tgi_set_ptr ; Set ptr1 to tgi_drv
130 ldy #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1)
131 ldx #.sizeof(TGI_HDR::VARS)-1
133 sta tgi_driver_vars,x
138 ; Install the IRQ vector if the driver needs it.
140 lda tgi_irq+2 ; Check high byte of IRQ vector
141 beq @L4 ; Jump if vector invalid
142 lda #$4C ; Jump opcode
143 sta tgi_irq ; Activate IRQ routine
145 ; Initialize some other variables
149 @L5: 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 __fastcall__ 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 lda #$60 ; RTS opcode
201 sta tgi_irq ; Disable IRQ entry point
203 ; Clear driver pointer and error code