]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi-kernel.s
remove superfluous ".code" line
[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         .include        "tgi-kernel.inc"
8         .include        "tgi-error.inc"
9
10         .importzp       ptr1
11         .interruptor    tgi_irq         ; Export as IRQ handler
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 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
36
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
40
41 ; End of section that gets cleared when a new driver is loaded
42 csize   = * - cstart
43
44 ; Maximum X and Y coordinate (that is, xres-1 and yres-1)
45 _tgi_xmax:          .res    2
46 _tgi_ymax:          .res    2
47
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.
50 tgi_driver_vars:
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
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 ; Copy the jump vectors
113
114         ldy     #TGI_HDR::JUMPTAB
115         ldx     #0
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))
120         bne     @L1
121
122 ; Call the driver install routine. It may update header variables, so we copy
123 ; them after this call.
124
125         jsr     tgi_install
126
127 ; Copy variables from the driver header for faster access.
128
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
132 @L3:    lda     (ptr1),y
133         sta     tgi_driver_vars,x
134         dey
135         dex
136         bpl     @L3
137
138 ; Install the IRQ vector if the driver needs it.
139
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
144
145 ; Initialize some other variables
146
147         lda     #$00
148 @L4:    ldx     #csize-1
149 @L5:    sta     cstart,x                ; Clear error/mode/curx/cury/...
150         dex
151         bpl     @L5
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 __fastcall__ 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         lda     #$60                    ; RTS opcode
201         sta     tgi_irq                 ; Disable IRQ entry point
202
203 ; Clear driver pointer and error code
204
205         lda     #$00
206         sta     _tgi_drv
207         sta     _tgi_drv+1
208         sta     _tgi_error
209
210         rts
211
212
213