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