]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi-kernel.s
Start of TGI changes. Untested, may not work.
[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 _tgi_error:         .res    1           ; Last error code
21 _tgi_gmode:         .res    1           ; Flag: Graphics mode active
22 _tgi_curx:          .res    2           ; Current drawing cursor X
23 _tgi_cury:          .res    2           ; Current drawing cursor Y
24 _tgi_color:         .res    1           ; Current drawing color
25 _tgi_textdir:       .res    1           ; Current text direction
26 ; The following two store an 8.8 fixed point value in the first two bytes,
27 ; and a rounded integer value in the third byte. The latter is passed to the
28 ; driver to scale the bitmap font. The variables are expected to be in 
29 ; this order and adjacent.
30 _tgi_textmagw:      .res    3           ; Text magnification for the width
31 _tgi_textmagh:      .res    3           ; Text magnification for the height
32                           
33 ; The following two must also be in exactly this order
34 _tgi_charheight:    .res    1           ; Char height of system font
35 _tgi_charwidth:     .res    1           ; Char width of system font
36
37 ; The following variables are copied from the driver header for faster access
38 ; fontwidth and fontheight are expected to be in order and adjacent.
39 tgi_driver_vars:
40 _tgi_xres:          .res    2           ; X resolution of the current mode
41 _tgi_yres:          .res    2           ; Y resolution of the current mode
42 _tgi_colorcount:    .res    1           ; Number of available colors
43 _tgi_pagecount:     .res    1           ; Number of available screen pages
44 _tgi_fontwidth:     .res    1           ; System font width in pixels
45 _tgi_fontheight:    .res    1           ; System font height in pixels
46 _tgi_aspectratio:   .res    2           ; Aspect ratio in 8.8 fixed point
47
48
49 .data
50
51 ; Jump table for the driver functions.
52
53 tgi_install:        jmp     $0000
54 tgi_uninstall:      jmp     $0000
55 tgi_init:           jmp     $0000
56 tgi_done:           jmp     $0000
57 tgi_geterror:       jmp     $0000
58 tgi_control:        jmp     $0000
59 tgi_clear:          jmp     $0000
60 tgi_setviewpage:    jmp     $0000
61 tgi_setdrawpage:    jmp     $0000
62 tgi_setcolor:       jmp     $0000
63 tgi_setpalette:     jmp     $0000
64 tgi_getpalette:     jmp     $0000
65 tgi_getdefpalette:  jmp     $0000
66 tgi_setpixel:       jmp     $0000
67 tgi_getpixel:       jmp     $0000
68 tgi_line:           jmp     $0000
69 tgi_bar:            jmp     $0000
70 tgi_textstyle:      jmp     $0000
71 tgi_outtext:        jmp     $0000
72 tgi_irq:            .byte   $60, $00, $00       ; RTS plus two dummy bytes
73
74 ; Driver header signature
75 .rodata
76 tgi_sig:        .byte   $74, $67, $69, TGI_API_VERSION  ; "tgi", version
77
78
79 .code
80 ;----------------------------------------------------------------------------
81 ; void __fastcall__ tgi_install (void* driver);
82 ; /* Install an already loaded driver. */
83
84
85 _tgi_install:
86         sta     _tgi_drv
87         sta     ptr1
88         stx     _tgi_drv+1
89         stx     ptr1+1
90
91 ; Check the driver signature
92
93         ldy     #.sizeof(tgi_sig)-1
94 @L0:    lda     (ptr1),y
95         cmp     tgi_sig,y
96         bne     tgi_inv_drv
97         dey
98         bpl     @L0
99
100 ; Copy the jump vectors
101
102         ldy     #TGI_HDR::JUMPTAB
103         ldx     #0
104 @L1:    inx                             ; Skip JMP opcode
105         jsr     copy                    ; Copy one byte
106         jsr     copy                    ; Copy one byte
107         cpy     #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB))
108         bne     @L1
109
110 ; Call the driver install routine. It may update header variables, so we copy
111 ; them after this call.
112
113         jsr     tgi_install
114
115 ; Copy variables from the driver header for faster access.
116
117         jsr     tgi_set_ptr             ; Set ptr1 to tgi_drv
118         ldy     #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1)
119         ldx     #.sizeof(TGI_HDR::VARS)-1
120 @L3:    lda     (ptr1),y
121         sta     tgi_driver_vars,x
122         dey
123         dex
124         bpl     @L3
125
126 ; Install the IRQ vector if the driver needs it.
127
128         lda     tgi_irq+2               ; Check high byte of IRQ vector
129         beq     @L4                     ; Jump if vector invalid
130         lda     #$4C                    ; Jump opcode
131         sta     tgi_irq                 ; Activate IRQ routine
132
133 ; Initialize some other variables
134
135         lda     #$00
136 @L4:    ldx     #8-1
137 @L5:    sta     _tgi_error,x            ; Clear error/mode/curx/cury/textdir
138         dex
139         bpl     @L5
140
141         rts
142
143 ; Copy one byte from the jump vectors
144
145 copy:   lda     (ptr1),y
146         sta     tgi_install,x
147         iny
148         inx
149         rts
150
151 ;----------------------------------------------------------------------------
152 ; Set an invalid argument error
153
154 tgi_inv_arg:
155         lda     #TGI_ERR_INV_ARG
156         sta     _tgi_error
157         rts
158
159 ;----------------------------------------------------------------------------
160 ; Set an invalid driver error
161
162 tgi_inv_drv:
163         lda     #TGI_ERR_INV_DRIVER
164         sta     _tgi_error
165         rts
166
167 ;----------------------------------------------------------------------------
168 ; Load the pointer to the tgi driver into ptr1.
169
170 tgi_set_ptr:
171         lda     _tgi_drv
172         sta     ptr1
173         lda     _tgi_drv+1
174         sta     ptr1+1
175         rts
176
177 ;----------------------------------------------------------------------------
178 ; void __fastcall__ tgi_uninstall (void);
179 ; /* Uninstall the currently loaded driver but do not unload it. Will call
180 ;  * tgi_done if necessary.
181 ;  */
182
183 _tgi_uninstall:
184         jsr     _tgi_done               ; Switch off graphics
185
186         jsr     tgi_uninstall           ; Allow the driver to clean up
187
188         lda     #$60                    ; RTS opcode
189         sta     tgi_irq                 ; Disable IRQ entry point
190
191 ; Clear driver pointer and error code
192
193         lda     #$00
194         sta     _tgi_drv
195         sta     _tgi_drv+1
196         sta     _tgi_error
197
198         rts
199
200
201