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