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 ; The following two store an 8.8 fixed point value in the first two bytes,
30 ; and a rounded integer value in the third byte. The latter is passed to the
31 ; driver to scale the bitmap font. The variables are expected to be in
32 ; this order and adjacent.
33 _tgi_textscalew: .res 3 ; Text scale for the width
34 _tgi_textscaleh: .res 3 ; Text scale for the height
36 ; The following two must also be in exactly this order
37 _tgi_charwidth: .res 1 ; Char width of system font
38 _tgi_charheight: .res 1 ; Char height of system font
40 ; End of section that gets cleared when a new driver is loaded
43 ; Maximum X and Y coordinate (that is, xres-1 and yres-1)
47 ; The following variables are copied from the driver header for faster access
48 ; fontwidth and fontheight are expected to be in order and adjacent.
50 _tgi_xres: .res 2 ; X resolution of the current mode
51 _tgi_yres: .res 2 ; Y resolution of the current mode
52 _tgi_colorcount: .res 1 ; Number of available colors
53 _tgi_pagecount: .res 1 ; Number of available screen pages
54 _tgi_fontwidth: .res 1 ; System font width in pixels
55 _tgi_fontheight: .res 1 ; System font height in pixels
56 _tgi_aspectratio: .res 2 ; Aspect ratio in 8.8 fixed point
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
83 tgi_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes
85 ; Driver header signature
87 tgi_sig: .byte $74, $67, $69, TGI_API_VERSION ; "tgi", version
91 ;----------------------------------------------------------------------------
92 ; void __fastcall__ tgi_install (void* driver);
93 ; /* Install an already loaded driver. */
102 ; Check the driver signature
104 ldy #.sizeof(tgi_sig)-1
111 ; Copy the jump vectors
113 ldy #TGI_HDR::JUMPTAB
115 @L1: inx ; Skip JMP opcode
116 jsr copy ; Copy one byte
117 jsr copy ; Copy one byte
118 cpy #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB))
121 ; Call the driver install routine. It may update header variables, so we copy
122 ; them after this call.
126 ; Copy variables from the driver header for faster access.
128 jsr tgi_set_ptr ; Set ptr1 to tgi_drv
129 ldy #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1)
130 ldx #.sizeof(TGI_HDR::VARS)-1
132 sta tgi_driver_vars,x
137 ; Install the IRQ vector if the driver needs it.
139 lda tgi_irq+2 ; Check high byte of IRQ vector
140 beq @L4 ; Jump if vector invalid
141 lda #$4C ; Jump opcode
142 sta tgi_irq ; Activate IRQ routine
144 ; Initialize some other variables
148 @L5: sta cstart,x ; Clear error/mode/curx/cury/...
154 ; Copy one byte to the jump vectors
162 ;----------------------------------------------------------------------------
163 ; Set an invalid argument error
170 ;----------------------------------------------------------------------------
171 ; Set an invalid driver error
174 lda #TGI_ERR_INV_DRIVER
178 ;----------------------------------------------------------------------------
179 ; Load the pointer to the tgi driver into ptr1.
188 ;----------------------------------------------------------------------------
189 ; void __fastcall__ tgi_uninstall (void);
190 ; /* Uninstall the currently loaded driver but do not unload it. Will call
191 ; * tgi_done if necessary.
195 jsr _tgi_done ; Switch off graphics
197 jsr tgi_uninstall ; Allow the driver to clean up
199 lda #$60 ; RTS opcode
200 sta tgi_irq ; Disable IRQ entry point
202 ; Clear driver pointer and error code