]> git.sur5r.net Git - cc65/blob - libsrc/apple2/apple2-280-192-8.s
Removed generic macpack
[cc65] / libsrc / apple2 / apple2-280-192-8.s
1 ;
2 ; Graphics driver for the 280x192x8 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 HBASL   :=      $26
20 HMASK   :=      $30
21 PAGE    :=      $E6
22 SCALE   :=      $E7
23 ROT     :=      $F9
24
25 ; Graphics entry points, by cbmnut (applenut??) cbmnut@hushmail.com
26
27 TEXT    :=      $F399   ; Return to text screen
28 HGR2    :=      $F3D8   ; Initialize and clear hi-res page 2.
29 HGR     :=      $F3E2   ; Initialize and clear hi-res page 1.
30 HCLR    :=      $F3F2   ; Clear the current hi-res screen to black.
31 BKGND   :=      $F3F6   ; Clear the current hi-res screen to the
32                         ; last plotted color (from ($1C).
33 HPOSN   :=      $F411   ; Positions the hi-res cursor without
34                         ; plotting a point.
35                         ; Enter with (A) = Y-coordinate, and
36                         ; (Y,X) = X-coordinate.
37 HPLOT   :=      $F457   ; Calls HPOSN and tries to plot a dot at
38                         ; the cursor's position.  If you are
39                         ; trying to plot a non-white color at
40                         ; a complementary color position, no
41                         ; dot will be plotted.
42 LRUD    :=      $F4D1   ; ???
43 HLIN    :=      $F53A   ; Draws a line from the last plotted
44                         ; point or line destination to:
45                         ; (X,A) = X-coordinate, and
46                         ; (Y) = Y-coordinate.
47 HFIND   :=      $F5CB   ; Converts the hi-res coursor's position
48                         ; back to X- and Y-coordinates; stores
49                         ; X-coordinate at $E0,E1 and Y-coordinate
50                         ; at $E2.
51 DRAW    :=      $F601   ; Draws a shape.  Enter with (Y,X) = the
52                         ; address of the shape table, and (A) =
53                         ; the rotation factor.  Uses the current
54                         ; color.
55 XDRAW   :=      $F65D   ; Draws a shape by inverting the existing
56                         ; color of the dots the shape draws over.
57                         ; Same entry parameters as DRAW.
58 SETHCOL :=      $F6EC   ; Set the hi-res color to (X), where (X)
59                         ; must be between 0 and 7.
60
61 ; ------------------------------------------------------------------------
62
63 ; Variables mapped to the zero page segment variables. Some of these are
64 ; used for passing parameters to the driver.
65
66 X1      :=      ptr1
67 Y1      :=      ptr2
68 X2      :=      ptr3
69 Y2      :=      ptr4
70
71 ; ------------------------------------------------------------------------
72
73         .segment        "JUMPTABLE"
74
75 ; Header. Includes jump table and constants.
76
77 ; First part of the header is a structure that has a magic and defines the
78 ; capabilities of the driver
79
80         .byte   $74, $67, $69   ; "tgi"
81         .byte   TGI_API_VERSION ; TGI API version number
82 xres:   .word   280             ; X resolution
83 yres:   .word   192             ; Y resolution
84         .byte   8               ; Number of drawing colors
85         .byte   2               ; Number of screens available
86         .byte   8               ; System font X size
87         .byte   8               ; System font Y size
88         .word   $100            ; Aspect ratio
89
90 ; Next comes the jump table. With the exception of IRQ, all entries must be
91 ; valid and may point to an RTS for test versions (function not implemented).
92
93         .addr   INSTALL
94         .addr   UNINSTALL
95         .addr   INIT
96         .addr   DONE
97         .addr   GETERROR
98         .addr   CONTROL
99         .addr   CLEAR
100         .addr   SETVIEWPAGE
101         .addr   SETDRAWPAGE
102         .addr   SETCOLOR
103         .addr   SETPALETTE
104         .addr   GETPALETTE
105         .addr   GETDEFPALETTE
106         .addr   SETPIXEL
107         .addr   GETPIXEL
108         .addr   LINE
109         .addr   BAR
110         .addr   TEXTSTYLE
111         .addr   OUTTEXT
112         .addr   0               ; IRQ entry is unused
113
114 ; ------------------------------------------------------------------------
115
116         .bss
117
118 ; Absolute variables used in the code
119
120 ERROR:  .res    1               ; Error code
121
122         .ifdef  __APPLE2ENH__
123 Set80:  .res    1               ; Set 80 column store
124         .endif
125
126 ; ------------------------------------------------------------------------
127
128         .rodata
129
130 ; Constants and tables
131
132 DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
133
134 SHAPE:
135         ; Beagle Bros Shape Mechanic font F.ASCII.SMALL
136         .byte   $64,$01,$D0,$00,$D5,$00,$DA,$00,$E0,$00,$EF,$00,$FE,$00,$0C,$01
137         .byte   $19,$01,$1D,$01,$25,$01,$2D,$01,$3D,$01,$46,$01,$4B,$01,$52,$01
138         .byte   $56,$01,$60,$01,$70,$01,$77,$01,$83,$01,$8E,$01,$9A,$01,$A7,$01
139         .byte   $B6,$01,$BF,$01,$CE,$01,$DD,$01,$E2,$01,$E7,$01,$F9,$01,$03,$02
140         .byte   $15,$02,$1F,$02,$32,$02,$42,$02,$52,$02,$5E,$02,$6C,$02,$79,$02
141         .byte   $85,$02,$91,$02,$A1,$02,$A9,$02,$B2,$02,$BF,$02,$C5,$02,$D5,$02
142         .byte   $E5,$02,$F4,$02,$00,$03,$10,$03,$1F,$03,$2D,$03,$35,$03,$44,$03
143         .byte   $53,$03,$63,$03,$71,$03,$7B,$03,$85,$03,$91,$03,$97,$03,$A3,$03
144         .byte   $B6,$03,$BF,$03,$C3,$03,$CF,$03,$DC,$03,$E4,$03,$F3,$03,$00,$04
145         .byte   $0A,$04,$19,$04,$25,$04,$2A,$04,$32,$04,$3C,$04,$43,$04,$50,$04
146         .byte   $5A,$04,$66,$04,$72,$04,$7E,$04,$87,$04,$94,$04,$9C,$04,$A8,$04
147         .byte   $B4,$04,$C1,$04,$CC,$04,$DB,$04,$E6,$04,$EE,$04,$F3,$04,$FB,$04
148         .byte   $04,$05,$1A,$05,$1F,$05,$24,$05,$29,$05,$22,$01,$00,$00,$00,$00
149         .byte   $09,$89,$92,$92,$00,$36,$36,$16,$0E,$00,$0D,$FE,$6E,$96,$52,$00
150         .byte   $69,$FE,$17,$2D,$2D,$1E,$1F,$17,$2D,$2D,$1E,$1F,$6E,$4E,$00,$09
151         .byte   $8D,$3F,$BF,$0D,$15,$3F,$0E,$0D,$1E,$3F,$77,$71,$09,$00,$6D,$11
152         .byte   $DF,$77,$09,$1E,$17,$4D,$3A,$DF,$4E,$29,$0E,$00,$A9,$1F,$6E,$1E
153         .byte   $17,$0D,$0D,$1E,$DF,$0E,$6D,$0E,$00,$36,$96,$52,$00,$09,$1E,$17
154         .byte   $36,$15,$0E,$0E,$00,$15,$0E,$36,$1E,$17,$4E,$01,$00,$09,$8D,$1F
155         .byte   $1F,$0E,$2D,$1E,$17,$2D,$15,$1F,$1F,$4E,$4E,$01,$00,$89,$6E,$3A
156         .byte   $3F,$77,$31,$56,$09,$00,$92,$8A,$F6,$0D,$00,$52,$89,$3F,$B7,$52
157         .byte   $49,$00,$92,$92,$0E,$00,$49,$11,$17,$1E,$17,$1E,$56,$49,$01,$00
158         .byte   $29,$AD,$DF,$33,$4D,$35,$1F,$1F,$2E,$4D,$FE,$1B,$0E,$2D,$4E,$00
159         .byte   $31,$77,$36,$BE,$2D,$0E,$00,$29,$AD,$DF,$73,$49,$1E,$BF,$1E,$2E
160         .byte   $2D,$75,$00,$2D,$2D,$BE,$3E,$4E,$FE,$1B,$0E,$2D,$4E,$00,$49,$3E
161         .byte   $17,$0D,$FE,$33,$2D,$2D,$1E,$76,$01,$00,$2D,$2D,$DE,$1B,$2E,$2D
162         .byte   $15,$36,$DF,$73,$2D,$4E,$00,$09,$2D,$DE,$BB,$4D,$3A,$3F,$6E,$09
163         .byte   $FE,$1B,$0E,$2D,$4E,$00,$2D,$2D,$BE,$1E,$17,$36,$4E,$09,$00,$29
164         .byte   $AD,$DF,$33,$4D,$F1,$3F,$17,$4D,$31,$DF,$73,$2D,$4E,$00,$29,$AD
165         .byte   $DF,$33,$4D,$31,$3F,$77,$09,$1E,$DF,$2A,$75,$09,$00,$12,$16,$96
166         .byte   $01,$00,$52,$B2,$F6,$0D,$00,$49,$3E,$17,$2D,$2D,$35,$3F,$3F,$3F
167         .byte   $0E,$2D,$2D,$F5,$1B,$77,$4E,$09,$00,$12,$2D,$2D,$DE,$9B,$2D,$2D
168         .byte   $96,$01,$00,$49,$15,$FF,$13,$2D,$2D,$AD,$3F,$3F,$3F,$2E,$2D,$2D
169         .byte   $1E,$37,$4E,$09,$00,$29,$AD,$DF,$73,$09,$1E,$B6,$4E,$01,$00,$09
170         .byte   $2D,$3E,$37,$2D,$3E,$FF,$2A,$2D,$2D,$F5,$3F,$3F,$0E,$2D,$1E,$4D
171         .byte   $01,$00,$09,$15,$1F,$17,$4D,$31,$DF,$33,$2D,$2D,$FE,$1B,$6E,$09
172         .byte   $0E,$00,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$4D,$31,$DF,$33,$2D,$75
173         .byte   $01,$00,$29,$AD,$DF,$33,$36,$4D,$11,$DF,$73,$2D,$4E,$00,$2D,$AD
174         .byte   $DF,$6E,$31,$DF,$6E,$31,$DF,$17,$2D,$75,$01,$00,$2D,$2D,$DE,$1B
175         .byte   $6E,$11,$3F,$37,$36,$2D,$2D,$0E,$00,$2D,$2D,$DE,$1B,$6E,$11,$3F
176         .byte   $37,$36,$4E,$49,$00,$29,$AD,$DF,$33,$36,$4D,$35,$DF,$73,$2D,$75
177         .byte   $00,$4D,$31,$DF,$33,$4D,$31,$3F,$3F,$6E,$09,$FE,$1B,$6E,$09,$0E
178         .byte   $00,$2D,$1E,$36,$36,$17,$2D,$0E,$00,$49,$31,$36,$36,$DF,$73,$2D
179         .byte   $4E,$00,$4D,$F1,$DF,$6E,$1E,$37,$0D,$15,$DF,$6E,$09,$0E,$00,$36
180         .byte   $36,$36,$2D,$75,$00,$4D,$31,$FF,$37,$0D,$0D,$FE,$1F,$6E,$09,$FE
181         .byte   $1B,$6E,$09,$0E,$00,$4D,$31,$DF,$33,$6D,$31,$1F,$1F,$6E,$29,$FE
182         .byte   $1B,$6E,$09,$0E,$00,$29,$AD,$DF,$33,$4D,$31,$DF,$33,$4D,$31,$DF
183         .byte   $73,$2D,$4E,$00,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$36,$4E,$49,$00
184         .byte   $29,$AD,$DF,$33,$4D,$31,$DF,$33,$0D,$0D,$1E,$DF,$0E,$6D,$0E,$00
185         .byte   $2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$0D,$15,$DF,$6E,$09,$0E,$00,$29
186         .byte   $AD,$DF,$33,$4D,$3A,$77,$09,$FE,$1B,$0E,$2D,$4E,$00,$2D,$2D,$DE
187         .byte   $36,$36,$76,$09,$00,$4D,$31,$DF,$33,$4D,$31,$DF,$33,$4D,$31,$DF
188         .byte   $73,$2D,$4E,$00,$4D,$31,$DF,$33,$4D,$31,$DF,$33,$4D,$F1,$1F,$0E
189         .byte   $4E,$01,$00,$4D,$31,$DF,$33,$4D,$31,$1F,$1F,$6E,$0D,$3E,$1F,$37
190         .byte   $4D,$71,$00,$4D,$31,$DF,$73,$0D,$1E,$17,$0D,$15,$DF,$33,$4D,$71
191         .byte   $00,$4D,$31,$DF,$73,$0D,$1E,$36,$76,$09,$00,$2D,$2D,$BE,$1E,$17
192         .byte   $1E,$2E,$2D,$75,$00,$2D,$2D,$DE,$3B,$2E,$3E,$2E,$3E,$2E,$2D,$75
193         .byte   $00,$72,$15,$0E,$15,$56,$00,$2D,$2D,$3E,$2E,$3E,$2E,$3E,$DF,$2A
194         .byte   $2D,$75,$00,$49,$15,$3F,$17,$2D,$2D,$15,$3F,$3F,$3F,$4E,$2D,$3E
195         .byte   $37,$2D,$3E,$6F,$49,$00,$92,$92,$49,$11,$3F,$3F,$4D,$09,$00,$76
196         .byte   $96,$52,$00,$52,$2D,$35,$DF,$33,$4D,$31,$FF,$73,$6D,$0E,$00,$36
197         .byte   $2D,$AD,$DF,$33,$4D,$31,$DF,$33,$2D,$75,$01,$00,$52,$2D,$DE,$33
198         .byte   $76,$2D,$0E,$00,$49,$31,$DF,$2A,$2D,$FE,$1B,$6E,$09,$FE,$1B,$0E
199         .byte   $2D,$75,$00,$52,$2D,$15,$DF,$33,$2D,$2D,$DE,$1B,$0E,$2D,$75,$00
200         .byte   $09,$F5,$33,$8D,$3F,$77,$36,$4E,$01,$00,$52,$2D,$35,$DF,$33,$4D
201         .byte   $31,$3F,$77,$09,$1E,$3F,$4D,$01,$00,$36,$2D,$AD,$DF,$33,$4D,$31
202         .byte   $DF,$33,$4D,$71,$00,$16,$36,$36,$0E,$00,$09,$9E,$35,$36,$F6,$6F
203         .byte   $01,$00,$36,$4D,$1E,$1F,$2E,$15,$1F,$6E,$71,$00,$35,$36,$36,$17
204         .byte   $2D,$0E,$00,$12,$2D,$AD,$1F,$1F,$6E,$0D,$FE,$1F,$6E,$0D,$0E,$00
205         .byte   $12,$2D,$15,$DF,$6E,$31,$DF,$6E,$71,$00,$52,$2D,$15,$DF,$33,$4D
206         .byte   $31,$DF,$73,$2D,$4E,$00,$12,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$6E
207         .byte   $49,$00,$52,$2D,$35,$DF,$33,$4D,$31,$3F,$77,$09,$2E,$00,$12,$0D
208         .byte   $AD,$DF,$37,$36,$4E,$49,$00,$52,$2D,$F5,$DB,$0E,$2D,$15,$DF,$13
209         .byte   $2D,$75,$01,$00,$31,$17,$2D,$F5,$33,$76,$75,$00,$12,$4D,$31,$DF
210         .byte   $33,$4D,$31,$FF,$73,$6D,$0E,$00,$12,$4D,$31,$DF,$33,$4D,$F1,$1F
211         .byte   $0E,$4E,$01,$00,$12,$4D,$31,$DF,$33,$0D,$0D,$FE,$1F,$0E,$0D,$4E
212         .byte   $00,$12,$4D,$F1,$1F,$0E,$15,$1F,$17,$4D,$71,$00,$12,$4D,$31,$DF
213         .byte   $33,$4D,$31,$3F,$77,$09,$1E,$3F,$4D,$01,$00,$12,$2D,$2D,$1E,$17
214         .byte   $1E,$17,$2D,$2D,$0E,$00,$09,$F5,$33,$1E,$0E,$76,$75,$00,$36,$36
215         .byte   $36,$2E,$00,$AD,$AE,$17,$FE,$2A,$4E,$01,$00,$69,$11,$1F,$1F,$4E
216         .byte   $B1,$92,$09,$00,$2D,$2D,$35,$3F,$3F,$37,$2D,$2D,$35,$3F,$3F,$37
217         .byte   $2D,$2D,$35,$3F,$3F,$37,$2D,$2D,$75,$00,$40,$C0,$40,$18,$00,$40
218         .byte   $C0,$40,$43,$00,$40,$C0,$40,$08,$00,$19,$00,$00
219
220 ; ------------------------------------------------------------------------
221
222         .code
223
224 ; INIT: Changes an already installed device from text mode to graphics mode.
225 ; Note that INIT/DONE may be called multiple times while the driver
226 ; is loaded, while INSTALL is only called once, so any code that is needed
227 ; to initializes variables and so on must go here. Setting palette and
228 ; clearing the screen is not needed because this is called by the graphics
229 ; kernel later.
230 ; The graphics kernel will never call INIT when a graphics mode is already
231 ; active, so there is no need to protect against that.
232 ; Must set an error code: YES
233 INIT:
234         .ifdef  __APPLE2ENH__
235         ; Save and clear 80 column store
236         lda     RD80COL
237         sta     Set80
238         sta     CLR80COL
239         .endif
240
241         ; Switch into graphics mode
242         bit     HIRES
243         bit     MIXCLR
244         bit     TXTCLR
245
246         ; Beagle Bros Shape Mechanic fonts don't
247         ; scale well so use fixed scaling factor
248         lda     #1
249         sta     SCALE
250
251         ; Done, reset the error code
252         lda     #TGI_ERR_OK
253         sta     ERROR
254
255         ; Fall through
256
257 ; INSTALL routine. Is called after the driver is loaded into memory. May
258 ; initialize anything that has to be done just once. Is probably empty
259 ; most of the time.
260 ; Must set an error code: NO
261 INSTALL:
262         ; Fall through
263
264 ; UNINSTALL routine. Is called before the driver is removed from memory. May
265 ; clean up anything done by INSTALL but is probably empty most of the time.
266 ; Must set an error code: NO
267 UNINSTALL:
268         rts
269
270 ; DONE: Will be called to switch the graphics device back into text mode.
271 ; The graphics kernel will never call DONE when no graphics mode is active,
272 ; so there is no need to protect against that.
273 ; Must set an error code: NO
274 DONE:
275         ; Switch into text mode
276         bit     TXTSET
277         bit     LOWSCR
278
279         .ifdef  __APPLE2ENH__
280         ; Restore 80 column store
281         lda     Set80
282         bpl     :+
283         sta     SET80COL
284 :       bit     LORES           ; Limit SET80COL-HISCR to text
285         .endif
286         rts
287
288 ; GETERROR: Return the error code in A and clear it.
289 GETERROR:
290         lda     ERROR
291         ldx     #TGI_ERR_OK
292         stx     ERROR
293         rts
294
295 ; CLEAR: Clears the screen.
296 ; Must set an error code: NO
297 CLEAR:
298         bit     $C082           ; Switch in ROM
299         jsr     HCLR
300         bit     $C080           ; Switch in LC bank 2 for R/O
301         rts
302
303 ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
304 ; The page number is already checked to be valid by the graphics kernel.
305 ; Must set an error code: NO (will only be called if page ok)
306 SETVIEWPAGE:
307         tax
308         .assert LOWSCR + 1 = HISCR, error
309         lda     LOWSCR,x        ; No BIT absolute,X available
310         rts
311
312 ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
313 ; The page number is already checked to be valid by the graphics kernel.
314 ; Must set an error code: NO (will only be called if page ok)
315 SETDRAWPAGE:
316         tax
317         beq     :+
318         lda     #>$4000         ; Page 2
319         .byte   $2C             ; BIT absolute
320 :       lda     #>$2000         ; Page 1
321         sta     PAGE
322         rts
323
324 ; SETCOLOR: Set the drawing color (in A). The new color is already checked
325 ; to be in a valid range (0..maxcolor-1).
326 ; Must set an error code: NO (will only be called if color ok)
327 SETCOLOR:
328         bit     $C082           ; Switch in ROM
329         tax
330         jsr     SETHCOL
331         bit     $C080           ; Switch in LC bank 2 for R/O
332         rts
333
334 ; CONTROL: Platform/driver specific entry point.
335 ; Must set an error code: YES
336 CONTROL:
337         ; Fall through
338
339 ; SETPALETTE: Set the palette (not available with all drivers/hardware).
340 ; A pointer to the palette is passed in ptr1. Must set an error if palettes
341 ; are not supported
342 ; Must set an error code: YES
343 SETPALETTE:
344         lda     #TGI_ERR_INV_FUNC
345         sta     ERROR
346         rts
347
348 ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
349 ; set the palette should return the default palette here, so there's no
350 ; way for this function to fail.
351 ; Must set an error code: NO
352 GETPALETTE:
353         ; Fall through
354
355 ; GETDEFPALETTE: Return the default palette for the driver in A/X. All
356 ; drivers should return something reasonable here, even drivers that don't
357 ; support palettes, otherwise the caller has no way to determine the colors
358 ; of the (not changeable) palette.
359 ; Must set an error code: NO (all drivers must have a default palette)
360 GETDEFPALETTE:
361         lda     #<DEFPALETTE
362         ldx     #>DEFPALETTE
363         rts
364
365 ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
366 ; color. The coordinates passed to this function are never outside the
367 ; visible screen area, so there is no need for clipping inside this function.
368 ; Must set an error code: NO
369 SETPIXEL:
370         bit     $C082           ; Switch in ROM
371         ldx     X1
372         ldy     X1+1
373         lda     Y1
374         jsr     HPLOT
375         bit     $C080           ; Switch in LC bank 2 for R/O
376         rts
377
378 ; GETPIXEL: Read the color value of a pixel and return it in A/X. The
379 ; coordinates passed to this function are never outside the visible screen
380 ; area, so there is no need for clipping inside this function.
381 GETPIXEL:
382         bit     $C082           ; Switch in ROM
383         ldx     X1
384         ldy     X1+1
385         lda     Y1
386         jsr     HPOSN
387         lda     (HBASL),y
388         and     HMASK
389         asl
390         beq     :+              ; 0 (black)
391         lda     #$03            ; 3 (white)
392 :       bcc     :+
393         adc     #$03            ; += 4 (black -> black2, white -> white2)
394 :       ldx     #$00
395         bit     $C080           ; Switch in LC bank 2 for R/O
396         rts
397
398 ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
399 ; X2/Y2 = ptr3/ptr4 using the current drawing color.
400 ; Must set an error code: NO
401 LINE:
402         bit     $C082           ; Switch in ROM
403         ldx     X1
404         ldy     X1+1
405         lda     Y1
406         jsr     HPOSN
407         lda     X2
408         ldx     X2+1
409         ldy     Y2
410         jsr     HLIN
411         bit     $C080           ; Switch in LC bank 2 for R/O
412         rts
413
414 ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
415 ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
416 ; Contrary to most other functions, the graphics kernel will sort and clip
417 ; the coordinates before calling the driver, so on entry the following
418 ; conditions are valid:
419 ;       X1 <= X2
420 ;       Y1 <= Y2
421 ;       (X1 >= 0) && (X1 < XRES)
422 ;       (X2 >= 0) && (X2 < XRES)
423 ;       (Y1 >= 0) && (Y1 < YRES)
424 ;       (Y2 >= 0) && (Y2 < YRES)
425 ; Must set an error code: NO
426 BAR:
427         inc     Y2
428 :       lda     Y2
429         pha
430         lda     Y1
431         sta     Y2
432         jsr     LINE
433         pla
434         sta     Y2
435         inc     Y1
436         cmp     Y1
437         bne     :-
438         rts
439
440 ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
441 ; direction is passend in X/Y, the text direction is passed in A.
442 ; Must set an error code: NO
443 TEXTSTYLE:
444         cmp     #TGI_TEXT_VERTICAL
445         bne     :+
446         lda     #48
447 :       sta     ROT
448         rts
449
450 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
451 ; current text style. The text to output is given as a zero terminated
452 ; string with address in ptr3.
453 ; Must set an error code: NO
454 OUTTEXT:
455         bit     $C082           ; Switch in ROM
456         lda     X1
457         ldy     X1+1
458         ldx     ROT
459         php                     ; Save Z flag
460         beq     :+              ; Not horizontal
461         sec
462         sbc     #7              ; Adjust X
463         bcs     :+
464         dey
465 :       tax
466         lda     Y1
467         plp                     ; Restore Z flag
468         bne     :+              ; Not vertical
469         sec
470         sbc     #7              ; Adjust Y
471 :       jsr     HPOSN
472         clc
473         lda     SHAPE+2*99      ; "connection char"
474         adc     #<SHAPE
475         sta     ptr4
476         lda     SHAPE+2*99+1    ; "connection char"
477         adc     #>SHAPE
478         sta     ptr4+1
479         ldy     #$00
480 :       lda     (ptr3),y
481         beq     :+
482         sty     tmp1            ; Save string index
483         sec
484         sbc     #$1F            ; No control chars
485         asl                     ; Offset * 2
486         tay
487         clc
488         lda     SHAPE,y
489         adc     #<SHAPE
490         tax
491         lda     SHAPE+1,y
492         adc     #>SHAPE
493         tay
494         lda     ROT
495         jsr     DRAW            ; Draw char from string
496         ldx     ptr4
497         ldy     ptr4+1
498         lda     ROT
499         jsr     DRAW            ; Draw "connection char"
500         ldy     tmp1            ; Restore string index
501         iny
502         bne     :-              ; Branch always
503 :       bit     $C080           ; Switch in LC bank 2 for R/O
504         rts