]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi-kernel.s
Code goes into the CODE segment, not RODATA.
[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 .code
71 ;----------------------------------------------------------------------------
72 ; void __fastcall__ tgi_install (void* driver);
73 ; /* Install an already loaded driver. */
74
75
76 _tgi_install:
77         sta     _tgi_drv
78         sta     ptr1
79         stx     _tgi_drv+1
80         stx     ptr1+1
81
82 ; Check the driver signature
83
84         ldy     #.sizeof(tgi_sig)-1
85 @L0:    lda     (ptr1),y
86         cmp     tgi_sig,y
87         bne     tgi_inv_drv
88         dey
89         bpl     @L0
90
91 ; Copy the jump vectors
92
93         ldy     #TGI_HDR::JUMPTAB
94         ldx     #0
95 @L1:    inx                             ; Skip JMP opcode
96         jsr     copy                    ; Copy one byte
97         jsr     copy                    ; Copy one byte
98         cpy     #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB))
99         bne     @L1
100
101 ; Call the driver install routine. It may update header variables, so we copy
102 ; them after this call.
103
104         jsr     tgi_install
105
106 ; Copy variables from the driver header for faster access.
107
108         jsr     tgi_set_ptr             ; Set ptr1 to tgi_drv
109         ldy     #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1)
110         ldx     #.sizeof(TGI_HDR::VARS)-1
111 @L3:    lda     (ptr1),y
112         sta     tgi_driver_vars,x
113         dey
114         dex
115         bpl     @L3
116
117 ; Install the IRQ vector if the driver needs it.
118
119         lda     tgi_irq+2               ; Check high byte of IRQ vector
120         beq     @L4                     ; Jump if vector invalid
121         lda     #$4C                    ; Jump opcode
122         sta     tgi_irq                 ; Activate IRQ routine
123
124 ; Initialize some other variables
125
126         lda     #$00
127 @L4:    ldx     #8-1
128 @L5:    sta     _tgi_error,x            ; Clear error/mode/curx/cury/textdir
129         dex
130         bpl     @L5
131
132         rts
133
134 ; Copy one byte from the jump vectors
135
136 copy:   lda     (ptr1),y
137         sta     tgi_install,x
138         iny
139         inx
140         rts
141
142 ;----------------------------------------------------------------------------
143 ; Set an invalid argument error
144
145 tgi_inv_arg:
146         lda     #TGI_ERR_INV_ARG
147         sta     _tgi_error
148         rts
149
150 ;----------------------------------------------------------------------------
151 ; Set an invalid driver error
152
153 tgi_inv_drv:
154         lda     #TGI_ERR_INV_DRIVER
155         sta     _tgi_error
156         rts
157
158 ;----------------------------------------------------------------------------
159 ; Load the pointer to the tgi driver into ptr1.
160
161 tgi_set_ptr:
162         lda     _tgi_drv
163         sta     ptr1
164         lda     _tgi_drv+1
165         sta     ptr1+1
166         rts
167
168 ;----------------------------------------------------------------------------
169 ; void __fastcall__ tgi_uninstall (void);
170 ; /* Uninstall the currently loaded driver but do not unload it. Will call
171 ;  * tgi_done if necessary.
172 ;  */
173
174 _tgi_uninstall:
175         jsr     _tgi_done               ; Switch off graphics
176
177         jsr     tgi_uninstall           ; Allow the driver to clean up
178
179         lda     #$60                    ; RTS opcode
180         sta     tgi_irq                 ; Disable IRQ entry point
181
182 ; Clear driver pointer and error code
183
184         lda     #$00
185         sta     _tgi_drv
186         sta     _tgi_drv+1
187         sta     _tgi_error
188
189         rts
190
191
192