]> git.sur5r.net Git - cc65/blob - libsrc/apple2/apple2-40-48-16.s
Removed tgi_load() and all corresponding infrastructure. The idea behind tgi_load...
[cc65] / libsrc / apple2 / apple2-40-48-16.s
1 ;
2 ; Graphics driver for the 40x48x16 mode on the Apple II
3 ;
4 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
5 ; Oliver Schmidt <ol.sc@web.de>
6 ;
7
8         .include        "zeropage.inc"
9
10         .include        "tgi-kernel.inc"
11         .include        "tgi-error.inc"
12         .include        "apple2.inc"
13
14 ; ------------------------------------------------------------------------
15
16 ; Zero page stuff
17
18 H2      :=      $2C
19 COLOR   :=      $30
20
21 ; ROM entry points
22
23 TEXT    :=      $F399
24 PLOT    :=      $F800
25 HLINE   :=      $F819
26 CLRSC2  :=      $F838
27 SETCOL  :=      $F864
28 SCRN    :=      $F871
29 SETGR   :=      $FB40
30 HOME    :=      $FC58
31
32 ; Used for passing parameters to the driver
33
34 X1      :=      ptr1
35 Y1      :=      ptr2
36 X2      :=      ptr3
37 Y2      :=      ptr4
38
39 ; ------------------------------------------------------------------------
40
41         .segment        "JUMPTABLE"
42
43 ; Header. Includes jump table and constants.
44
45 ; First part of the header is a structure that has a magic and defines the
46 ; capabilities of the driver
47
48         .byte   $74, $67, $69   ; "tgi"
49         .byte   TGI_API_VERSION ; TGI API version number
50         .word   40              ; X resolution
51         .word   48              ; Y resolution
52         .byte   16              ; Number of drawing colors
53         .byte   1               ; Number of screens available
54         .byte   8               ; System font X size
55         .byte   8               ; System font Y size
56         .word   $0198           ; Aspect ratio (based on 4/3 display)
57
58 ; Next comes the jump table. With the exception of IRQ, all entries must be
59 ; valid and may point to an RTS for test versions (function not implemented).
60
61         .addr   INSTALL
62         .addr   UNINSTALL
63         .addr   INIT
64         .addr   DONE
65         .addr   GETERROR
66         .addr   CONTROL
67         .addr   CLEAR
68         .addr   SETVIEWPAGE
69         .addr   SETDRAWPAGE
70         .addr   SETCOLOR
71         .addr   SETPALETTE
72         .addr   GETPALETTE
73         .addr   GETDEFPALETTE
74         .addr   SETPIXEL
75         .addr   GETPIXEL
76         .addr   LINE
77         .addr   BAR
78         .addr   TEXTSTYLE
79         .addr   OUTTEXT
80         .addr   0               ; IRQ entry is unused
81
82 ; ------------------------------------------------------------------------
83
84         .bss
85
86 ERROR:  .res    1               ; Error code
87 MIX:    .res    1               ; 4 lines of text
88
89 ; ------------------------------------------------------------------------
90
91         .rodata
92
93 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
94             .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
95
96 TGI2COL:    .byte $00, $0C, $03, $0F, $01, $09, $06, $02
97             .byte $04, $05, $07, $08, $0A, $0B, $0D, $0E
98
99 COL2TGI:    .byte $00, $04, $07, $02, $08, $09, $06, $0A
100             .byte $0B, $05, $0C, $0D, $01, $0E, $0F, $03
101
102 MAXY:   .byte 47, 39
103
104 ; ------------------------------------------------------------------------
105
106         .code
107
108 ; INIT: Changes an already installed device from text mode to graphics mode.
109 ; Note that INIT/DONE may be called multiple times while the driver
110 ; is loaded, while INSTALL is only called once, so any code that is needed
111 ; to initializes variables and so on must go here. Setting palette and
112 ; clearing the screen is not needed because this is called by the graphics
113 ; kernel later.
114 ; The graphics kernel will never call INIT when a graphics mode is already
115 ; active, so there is no need to protect against that.
116 ; Must set an error code: YES
117 INIT:
118         ; Switch into graphics mode
119         bit     $C082           ; Switch in ROM
120         jsr     SETGR
121         bit     MIXCLR
122         bit     $C080           ; Switch in LC bank 2 for R/O
123
124         ; Done, reset the error code
125         lda     #TGI_ERR_OK
126         sta     ERROR
127         sta     MIX
128
129         ; Fall through
130
131 ; INSTALL routine. Is called after the driver is loaded into memory. May
132 ; initialize anything that has to be done just once. Is probably empty
133 ; most of the time.
134 ; Must set an error code: NO
135 INSTALL:
136         ; Fall through
137
138 ; UNINSTALL routine. Is called before the driver is removed from memory. May
139 ; clean up anything done by INSTALL but is probably empty most of the time.
140 ; Must set an error code: NO
141 UNINSTALL:
142         ; Fall through
143
144 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
145 ; The page number is already checked to be valid by the graphics kernel.
146 ; Must set an error code: NO (will only be called if page ok)
147 SETVIEWPAGE:
148         ; Fall through
149
150 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
151 ; The page number is already checked to be valid by the graphics kernel.
152 ; Must set an error code: NO (will only be called if page ok)
153 SETDRAWPAGE:
154         ; Fall through
155
156 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
157 ; direction is passend in X/Y, the text direction is passed in A.
158 ; Must set an error code: NO
159 TEXTSTYLE:
160         ; Fall through
161
162 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
163 ; current text style. The text to output is given as a zero terminated
164 ; string with address in ptr3.
165 ; Must set an error code: NO
166 OUTTEXT:
167         rts
168
169 ; DONE: Will be called to switch the graphics device back into text mode.
170 ; The graphics kernel will never call DONE when no graphics mode is active,
171 ; so there is no need to protect against that.
172 ; Must set an error code: NO
173 DONE:
174         bit     $C082           ; Switch in ROM
175         jsr     TEXT
176         jsr     HOME
177         bit     $C080           ; Switch in LC bank 2 for R/O
178         rts
179
180 ; GETERROR: Return the error code in A and clear it.
181 GETERROR:
182         lda     ERROR
183         ldx     #TGI_ERR_OK
184         stx     ERROR
185         rts
186
187 ; CLEAR: Clears the screen.
188 ; Must set an error code: NO
189 CLEAR:
190         bit     $C082           ; Switch in ROM
191         lda     COLOR           ; Save current drawing color
192         pha
193         ldx     MIX
194         ldy     MAXY,x          ; Max Y depends on 4 lines of text
195         jsr     CLRSC2
196         pla
197         sta     COLOR           ; Restore current drawing color
198         bit     $C080           ; Switch in LC bank 2 for R/O
199         rts
200
201 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
202 ; to be in a valid range (0..maxcolor-1).
203 ; Must set an error code: NO (will only be called if color ok)
204 SETCOLOR:
205         bit     $C082           ; Switch in ROM
206         tax
207         lda     TGI2COL,x
208         jsr     SETCOL
209         bit     $C080           ; Switch in LC bank 2 for R/O
210         rts
211
212 ; CONTROL: Platform/driver specific entry point.
213 ; Must set an error code: YES
214 CONTROL:
215         ; Check data msb and code to be 0
216         ora     ptr1+1
217         bne     err
218
219         ; Check data lsb to be [0..1]
220         lda     ptr1
221         cmp     #1+1
222         bcs     err
223         bit     $C082           ; Switch in ROM
224
225         ; Switch 4 lines of text
226         tax
227         .assert MIXCLR + 1 = MIXSET, error
228         lda     MIXCLR,x        ; No BIT absolute,X available
229
230         ; Save current switch setting
231         txa
232         sta     MIX
233         bne     text
234
235         ; Clear 8 lines of graphics
236         lda     COLOR           ; Save current drawing color
237         pha
238         lda     #39             ; Rightmost column
239         sta     H2
240         ldx     #40             ; First line
241 :       txa
242         ldy     #$00            ; Leftmost column
243         sty     COLOR           ; Black
244         jsr     HLINE           ; Preserves X
245         inx
246         cpx     #47+1           ; Last line
247         bcc     :-
248         pla
249         sta     COLOR           ; Restore current drawing color
250         bcs     :+              ; Branch always
251
252         ; Clear 4 lines of text
253 text:   jsr     HOME
254 :       bit     $C080           ; Switch in LC bank 2 for R/O
255
256         ; Done, reset the error code
257         lda     #TGI_ERR_OK
258         beq     :+              ; Branch always
259         
260         ; Done, set the error code
261 err:    lda     #TGI_ERR_INV_ARG
262 :       sta     ERROR
263         rts
264
265 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
266 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
267 ; are not supported
268 ; Must set an error code: YES
269 SETPALETTE:
270         lda     #TGI_ERR_INV_FUNC
271         sta     ERROR
272         rts
273
274 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
275 ; set the palette should return the default palette here, so there's no
276 ; way for this function to fail.
277 ; Must set an error code: NO
278 GETPALETTE:
279         ; Fall through
280
281 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
282 ; drivers should return something reasonable here, even drivers that don't
283 ; support palettes, otherwise the caller has no way to determine the colors
284 ; of the (not changeable) palette.
285 ; Must set an error code: NO (all drivers must have a default palette)
286 GETDEFPALETTE:
287         lda     #<DEFPALETTE
288         ldx     #>DEFPALETTE
289         rts
290
291 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
292 ; color. The coordinates passed to this function are never outside the
293 ; visible screen area, so there is no need for clipping inside this function.
294 ; Must set an error code: NO
295 SETPIXEL:
296         bit     $C082           ; Switch in ROM
297         ldy     X1
298         lda     Y1
299         jsr     PLOT
300         bit     $C080           ; Switch in LC bank 2 for R/O
301         rts
302
303 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
304 ; coordinates passed to this function are never outside the visible screen
305 ; area, so there is no need for clipping inside this function.
306 GETPIXEL:
307         bit     $C082           ; Switch in ROM
308         ldy     X1
309         lda     Y1
310         jsr     SCRN
311         tax
312         lda     COL2TGI,x
313         ldx     #$00
314         bit     $C080           ; Switch in LC bank 2 for R/O
315         rts
316
317 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
318 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
319 ; Contrary to most other functions, the graphics kernel will sort and clip
320 ; the coordinates before calling the driver, so on entry the following
321 ; conditions are valid:
322 ;       X1 <= X2
323 ;       Y1 <= Y2
324 ;       (X1 >= 0) && (X1 < XRES)
325 ;       (X2 >= 0) && (X2 < XRES)
326 ;       (Y1 >= 0) && (Y1 < YRES)
327 ;       (Y2 >= 0) && (Y2 < YRES)
328 ; Must set an error code: NO
329 BAR:
330         bit     $C082           ; Switch in ROM
331         lda     X2
332         sta     H2
333         inc     Y2
334         ldx     Y1
335 :       txa
336         ldy     X1
337         jsr     HLINE           ; Preserves X
338         inx
339         cpx     Y2
340         bcc     :-
341         bit     $C080           ; Switch in LC bank 2 for R/O
342         rts
343
344 ; ------------------------------------------------------------------------
345
346 .include        "../tgi/tgidrv_line.inc"