]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi-kernel.s
Removed IRQ support from TGI drivers.
[cc65] / libsrc / tgi / tgi-kernel.s
1 ;
2 ; Ullrich von Bassewitz, 21.06.2002
3 ;
4 ; Common functions of the tgi graphics kernel.
5 ;
6
7         .import         tgi_libref
8         .importzp       ptr1
9
10         .include        "tgi-kernel.inc"
11         .include        "tgi-error.inc"
12
13
14 ;----------------------------------------------------------------------------
15 ; Variables
16
17 .bss
18
19 _tgi_drv:           .res    2           ; Pointer to driver
20 ; From here on, variables get cleared when a new driver is loaded
21 cstart:
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
38
39 ; End of section that gets cleared when a new driver is loaded
40 csize   = * - cstart
41
42 ; Maximum X and Y coordinate (that is, xres-1 and yres-1)
43 _tgi_xmax:          .res    2
44 _tgi_ymax:          .res    2
45
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.
48 tgi_driver_vars:
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
57
58
59 .data
60
61 ; Jump table for the driver functions.
62
63 jumpvectors:
64 tgi_install:        jmp     $0000
65 tgi_uninstall:      jmp     $0000
66 tgi_init:           jmp     $0000
67 tgi_done:           jmp     $0000
68 tgi_geterror:       jmp     $0000
69 tgi_control:        jmp     $0000
70 tgi_clear:          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
79 tgi_line:           jmp     $0000
80 tgi_bar:            jmp     $0000
81 tgi_textstyle:      jmp     $0000
82 tgi_outtext:        jmp     $0000
83
84 ; Driver header signature
85 .rodata
86 tgi_sig:        .byte   $74, $67, $69, TGI_API_VERSION  ; "tgi", version
87
88
89 .code
90 ;----------------------------------------------------------------------------
91 ; void __fastcall__ tgi_install (void* driver);
92 ; /* Install an already loaded driver. */
93
94
95 _tgi_install:
96         sta     _tgi_drv
97         sta     ptr1
98         stx     _tgi_drv+1
99         stx     ptr1+1
100
101 ; Check the driver signature
102
103         ldy     #.sizeof(tgi_sig)-1
104 @L0:    lda     (ptr1),y
105         cmp     tgi_sig,y
106         bne     tgi_inv_drv
107         dey
108         bpl     @L0
109
110 ; Set the library reference
111
112         ldy     #TGI_HDR::LIBREF
113         lda     #<tgi_libref
114         sta     (ptr1),y
115         iny
116         lda     #>tgi_libref
117         sta     (ptr1),y
118
119 ; Copy the jump vectors
120
121         ldy     #TGI_HDR::JUMPTAB
122         ldx     #0
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))
127         bne     @L1
128
129 ; Call the driver install routine. It may update header variables, so we copy
130 ; them after this call.
131
132         jsr     tgi_install
133
134 ; Copy variables from the driver header for faster access.
135
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
139 @L3:    lda     (ptr1),y
140         sta     tgi_driver_vars,x
141         dey
142         dex
143         bpl     @L3
144
145 ; Initialize some other variables
146
147         lda     #$00
148         ldx     #csize-1
149 @L4:    sta     cstart,x                ; Clear error/mode/curx/cury/...
150         dex
151         bpl     @L4
152
153         rts
154
155 ; Copy one byte to the jump vectors
156
157 copy:   lda     (ptr1),y
158         sta     jumpvectors,x
159         iny
160         inx
161         rts
162
163 ;----------------------------------------------------------------------------
164 ; Set an invalid argument error
165
166 tgi_inv_arg:
167         lda     #TGI_ERR_INV_ARG
168         sta     _tgi_error
169         rts
170
171 ;----------------------------------------------------------------------------
172 ; Set an invalid driver error
173
174 tgi_inv_drv:
175         lda     #TGI_ERR_INV_DRIVER
176         sta     _tgi_error
177         rts
178
179 ;----------------------------------------------------------------------------
180 ; Load the pointer to the tgi driver into ptr1.
181
182 tgi_set_ptr:
183         lda     _tgi_drv
184         sta     ptr1
185         lda     _tgi_drv+1
186         sta     ptr1+1
187         rts
188
189 ;----------------------------------------------------------------------------
190 ; void tgi_uninstall (void);
191 ; /* Uninstall the currently loaded driver but do not unload it. Will call
192 ; ** tgi_done if necessary.
193 ; */
194
195 _tgi_uninstall:
196         jsr     _tgi_done               ; Switch off graphics
197
198         jsr     tgi_uninstall           ; Allow the driver to clean up
199
200 ; Clear driver pointer and error code
201
202 tgi_clear_ptr:
203         lda     #$00
204         sta     _tgi_drv
205         sta     _tgi_drv+1
206         sta     _tgi_error
207
208         rts