]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi-kernel.s
use first free IOCB for "GRAPHICS 0" call instead of using a hard-coded one
[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         .interruptor    tgi_irq         ; Export as IRQ handler
10
11         .include        "tgi-kernel.inc"
12         .include        "tgi-error.inc"
13
14
15 ;----------------------------------------------------------------------------
16 ; Variables
17
18 .bss
19
20 _tgi_drv:           .res    2           ; Pointer to driver
21 ; From here on, variables get cleared when a new driver is loaded
22 cstart:
23 _tgi_error:         .res    1           ; Last error code
24 _tgi_gmode:         .res    1           ; Flag: Graphics mode active
25 _tgi_curx:          .res    2           ; Current drawing cursor X
26 _tgi_cury:          .res    2           ; Current drawing cursor Y
27 _tgi_color:         .res    1           ; Current drawing color
28 _tgi_font:          .res    1           ; Which font to use
29 _tgi_textdir:       .res    1           ; Current text direction
30 _tgi_vectorfont:    .res    2           ; Pointer to vector font
31 ; The following are character scale/size variables in 8.8 fixed point
32 ; format. They are required to be in this order and adjacent.
33 _tgi_textscalew:    .res    2           ; Vector font width scale
34                     .res    2           ; Bitmap font width scale
35 _tgi_charwidth:     .res    2           ; Full width of one bitmap char
36 _tgi_textscaleh:    .res    2           ; Vector font height scale
37                     .res    2           ; Bitmap font height scale
38 _tgi_charheight:    .res    2           ; Full height of one bitmap char
39
40 ; End of section that gets cleared when a new driver is loaded
41 csize   = * - cstart
42
43 ; Maximum X and Y coordinate (that is, xres-1 and yres-1)
44 _tgi_xmax:          .res    2
45 _tgi_ymax:          .res    2
46
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.
49 tgi_driver_vars:
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
57 _tgi_flags:         .res    1           ; TGI driver flags
58
59
60 .data
61
62 ; Jump table for the driver functions.
63
64 jumpvectors:
65 tgi_install:        jmp     $0000
66 tgi_uninstall:      jmp     $0000
67 tgi_init:           jmp     $0000
68 tgi_done:           jmp     $0000
69 tgi_geterror:       jmp     $0000
70 tgi_control:        jmp     $0000
71 tgi_clear:          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
80 tgi_line:           jmp     $0000
81 tgi_bar:            jmp     $0000
82 tgi_textstyle:      jmp     $0000
83 tgi_outtext:        jmp     $0000
84 tgi_irq:            .byte   $60, $00, $00       ; RTS plus two dummy bytes
85
86 ; Driver header signature
87 .rodata
88 tgi_sig:        .byte   $74, $67, $69, TGI_API_VERSION  ; "tgi", version
89
90
91 .code
92 ;----------------------------------------------------------------------------
93 ; void __fastcall__ tgi_install (void* driver);
94 ; /* Install an already loaded driver. */
95
96
97 _tgi_install:
98         sta     _tgi_drv
99         sta     ptr1
100         stx     _tgi_drv+1
101         stx     ptr1+1
102
103 ; Check the driver signature
104
105         ldy     #.sizeof(tgi_sig)-1
106 @L0:    lda     (ptr1),y
107         cmp     tgi_sig,y
108         bne     tgi_inv_drv
109         dey
110         bpl     @L0
111
112 ; Set the library reference
113
114         ldy     #TGI_HDR::LIBREF
115         lda     #<tgi_libref
116         sta     (ptr1),y
117         iny
118         lda     #>tgi_libref
119         sta     (ptr1),y
120
121 ; Copy the jump vectors
122
123         ldy     #TGI_HDR::JUMPTAB
124         ldx     #0
125 @L1:    inx                             ; Skip JMP opcode
126         jsr     copy                    ; Copy one byte
127         jsr     copy                    ; Copy one byte
128         cpy     #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB))
129         bne     @L1
130
131 ; Call the driver install routine. It may update header variables, so we copy
132 ; them after this call.
133
134         jsr     tgi_install
135
136 ; Copy variables from the driver header for faster access.
137
138         jsr     tgi_set_ptr             ; Set ptr1 to tgi_drv
139         ldy     #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1)
140         ldx     #.sizeof(TGI_HDR::VARS)-1
141 @L3:    lda     (ptr1),y
142         sta     tgi_driver_vars,x
143         dey
144         dex
145         bpl     @L3
146
147 ; Install the IRQ vector if the driver needs it.
148
149         lda     tgi_irq+2               ; Check high byte of IRQ vector
150         beq     @L4                     ; Jump if vector invalid
151         lda     #$4C                    ; Jump opcode
152         sta     tgi_irq                 ; Activate IRQ routine
153
154 ; Initialize some other variables
155
156         lda     #$00
157 @L4:    ldx     #csize-1
158 @L5:    sta     cstart,x                ; Clear error/mode/curx/cury/...
159         dex
160         bpl     @L5
161
162         rts
163
164 ; Copy one byte to the jump vectors
165
166 copy:   lda     (ptr1),y
167         sta     jumpvectors,x
168         iny
169         inx
170         rts
171
172 ;----------------------------------------------------------------------------
173 ; Set an invalid argument error
174
175 tgi_inv_arg:
176         lda     #TGI_ERR_INV_ARG
177         sta     _tgi_error
178         rts
179
180 ;----------------------------------------------------------------------------
181 ; Set an invalid driver error
182
183 tgi_inv_drv:
184         lda     #TGI_ERR_INV_DRIVER
185         sta     _tgi_error
186         rts
187
188 ;----------------------------------------------------------------------------
189 ; Load the pointer to the tgi driver into ptr1.
190
191 tgi_set_ptr:
192         lda     _tgi_drv
193         sta     ptr1
194         lda     _tgi_drv+1
195         sta     ptr1+1
196         rts
197
198 ;----------------------------------------------------------------------------
199 ; void tgi_uninstall (void);
200 ; /* Uninstall the currently loaded driver but do not unload it. Will call
201 ;  * tgi_done if necessary.
202 ;  */
203
204 _tgi_uninstall:
205         jsr     _tgi_done               ; Switch off graphics
206
207         jsr     tgi_uninstall           ; Allow the driver to clean up
208
209         lda     #$60                    ; RTS opcode
210         sta     tgi_irq                 ; Disable IRQ entry point
211
212 ; Clear driver pointer and error code
213
214 tgi_clear_ptr:
215         lda     #$00
216         sta     _tgi_drv
217         sta     _tgi_drv+1
218         sta     _tgi_error
219
220         rts