073ecbe
From f3f15cfd25dc5379ca48021884f4b96471dd895e Mon Sep 17 00:00:00 2001
073ecbe
From: Greg King <gregdk@users.sf.net>
073ecbe
Date: Sat, 12 Oct 2019 04:01:03 -0400
a4f04fe
Subject: [PATCH 060/170] Fixed problems with the Atari Lynx's TGI driver.
073ecbe
073ecbe
* The sprite-types for black and transparent backgrounds were swapped.
073ecbe
* A filler-byte for text output isn't printed.  (A hardware bug might not need that work-around in most cases.)
073ecbe
---
073ecbe
 libsrc/lynx/tgi/lynx-160-102-16.s | 52 +++++++++++++++++--------------
073ecbe
 1 file changed, 28 insertions(+), 24 deletions(-)
073ecbe
073ecbe
diff --git a/libsrc/lynx/tgi/lynx-160-102-16.s b/libsrc/lynx/tgi/lynx-160-102-16.s
073ecbe
index 04bdaae0..0728e687 100644
073ecbe
--- a/libsrc/lynx/tgi/lynx-160-102-16.s
073ecbe
+++ b/libsrc/lynx/tgi/lynx-160-102-16.s
073ecbe
@@ -1,10 +1,10 @@
073ecbe
 ;
073ecbe
 ; Graphics driver for the 160x102x16 mode on the Lynx.
073ecbe
 ;
073ecbe
-; All the drawing functions are simply done by sprites as the sprite
073ecbe
+; All the drawing functions simply are done by sprites, as the sprite
073ecbe
 ; engine is the only way to do fast graphics on a Lynx.
073ecbe
 ;
073ecbe
-; This code is written by Karri Kaksonen, 2004 for the cc65 compiler.
073ecbe
+; This code was written by Karri Kaksonen, 2004 for the cc65 compiler.
073ecbe
 ;
073ecbe
 
073ecbe
         .include        "zeropage.inc"
073ecbe
@@ -104,8 +104,10 @@ BGINDEX:        .res    1       ; Pen to use for text background
073ecbe
 DRAWPAGE:       .res    1
073ecbe
 SWAPREQUEST:    .res    1
073ecbe
 
073ecbe
+; 8 rows with (one offset-byte plus 20 character bytes plus one fill-byte) plus one 0-offset-byte.
073ecbe
+; (As an experiment, the fill-byte isn't being generated.
073ecbe
+;  It might not be needed to work around a Suzy bug.)
073ecbe
 text_bitmap:    .res    8*(1+20+1)+1
073ecbe
-; 8 rows with (one offset-byte plus 20 character bytes plus one fill-byte) plus one 0-offset-byte
073ecbe
 
073ecbe
 ; Constants and tables
073ecbe
 
073ecbe
@@ -830,7 +832,7 @@ TEXTSTYLE:
073ecbe
 
073ecbe
 ; ------------------------------------------------------------------------
073ecbe
 ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
073ecbe
-; current text style. The text to output is given as a zero terminated
073ecbe
+; current text style. The text to output is given as a zero-terminated
073ecbe
 ; string with address in ptr3.
073ecbe
 ;
073ecbe
 ; Must set an error code: NO
073ecbe
@@ -842,12 +844,11 @@ OUTTEXT:
073ecbe
         lda     TEXTMAGY
073ecbe
         sta     text_sy+1
073ecbe
 
073ecbe
-        stz     text_sprite     ; Set normal sprite
073ecbe
         lda     BGINDEX
073ecbe
-        bne     @L1
073ecbe
-        lda     #4
073ecbe
-        sta     text_sprite     ; Set opaque sprite
073ecbe
+        beq     @L1             ; Choose opaque black sprite?
073ecbe
+        lda     #$04            ; No, choose normal sprite
073ecbe
 @L1:
073ecbe
+        sta     text_sprite
073ecbe
         lda     DRAWINDEX       ; Set color
073ecbe
         asl
073ecbe
         asl
073ecbe
@@ -875,15 +876,18 @@ OUTTEXT:
073ecbe
         ldy     #20
073ecbe
 @L3:
073ecbe
         sty     STRLEN
073ecbe
+        tya
073ecbe
         bne     @L4
073ecbe
-        rts                     ; Zero length string
073ecbe
+        rts                     ; Zero-length string
073ecbe
 @L4:
073ecbe
         iny                     ; Prepare text_bitmap
073ecbe
-        iny
073ecbe
+
073ecbe
+; The next instruction is commented because the code won't include a fill-byte.
073ecbe
+;        iny
073ecbe
         sty     STROFF
073ecbe
 
073ecbe
         ldy     #8-1            ; 8 pixel lines per character
073ecbe
-        ldx     #0
073ecbe
+        ldx     #$00
073ecbe
         clc
073ecbe
 @L5:
073ecbe
         lda     STROFF
073ecbe
@@ -891,45 +895,45 @@ OUTTEXT:
073ecbe
         txa
073ecbe
         adc     STROFF
073ecbe
         tax
073ecbe
-        lda     #$ff
073ecbe
-        sta     text_bitmap-1,x
073ecbe
+
073ecbe
+; This was the fill-byte.
073ecbe
+;        lda     #$FF
073ecbe
+;        sta     text_bitmap-1,x
073ecbe
         dey
073ecbe
         bpl     @L5
073ecbe
         stz     text_bitmap,x
073ecbe
 
073ecbe
         stz     tmp2
073ecbe
-        iny
073ecbe
+        iny                     ;(ldy #$00)
073ecbe
 @L6:
073ecbe
         lda     (STRPTR),y
073ecbe
         sty     tmp1
073ecbe
 
073ecbe
-        sec                     ; (ch-' ') * 8
073ecbe
-        sbc     #32
073ecbe
-        stz     FONTOFF
073ecbe
+        sub     #' '            ; (ch - ' ') * 8
073ecbe
         stz     FONTOFF+1
073ecbe
         asl
073ecbe
         asl
073ecbe
         rol     FONTOFF+1
073ecbe
         asl
073ecbe
         rol     FONTOFF+1
073ecbe
-        clc                     ; Choose font
073ecbe
-        adc     #
073ecbe
+        ;clc                    ; (cleared by rol)
073ecbe
+        adc     #
073ecbe
         sta     FONTOFF
073ecbe
         lda     FONTOFF+1
073ecbe
         adc     #>font
073ecbe
         sta     FONTOFF+1
073ecbe
 
073ecbe
-; and now copy the 8 bytes of that char
073ecbe
+; And now, copy the 8 bytes of that glyph.
073ecbe
 
073ecbe
         ldx     tmp2
073ecbe
         inx
073ecbe
         stx     tmp2
073ecbe
 
073ecbe
-; draw char from top to bottom, reading char-data from offset 8-1 to offset 0
073ecbe
+; Draw char. from top to bottom, reading char-data from offset 8-1 to offset 0.
073ecbe
         ldy     #8-1
073ecbe
 @L7:
073ecbe
-        lda     (FONTOFF),y         ; *chptr
073ecbe
-        sta     text_bitmap,x    ;textbuf[y*(1+len+1)+1+x]
073ecbe
+        lda     (FONTOFF),y     ; *chptr
073ecbe
+        sta     text_bitmap,x   ; textbuf[y*(1+len+1)+1+x]
073ecbe
 
073ecbe
         txa
073ecbe
         adc     STROFF
073ecbe
@@ -938,7 +942,7 @@ OUTTEXT:
073ecbe
         dey
073ecbe
         bpl     @L7
073ecbe
 
073ecbe
-        ; goto next char
073ecbe
+        ; Goto next char.
073ecbe
         ldy     tmp1
073ecbe
         iny
073ecbe
         dec     STRLEN
073ecbe
-- 
a4f04fe
2.26.0
073ecbe