Blob Blame History Raw
From ede64f68a9e2a9bf38d70e0887748409ba157384 Mon Sep 17 00:00:00 2001
From: jede <jede@oric.org>
Date: Wed, 17 Jul 2019 21:48:53 +0200
Subject: [PATCH 023/170] Fix bug with bgcolor and textcolor

---
 libsrc/telestrat/bgcolor.s   | 15 +--------
 libsrc/telestrat/clrscr.s    | 14 ++++----
 libsrc/telestrat/cputc.s     | 31 +++++++++--------
 libsrc/telestrat/gotox.s     |  5 ---
 libsrc/telestrat/gotoxy.s    | 64 +++++++++++++++++++-----------------
 libsrc/telestrat/gotoy.s     |  9 ++---
 libsrc/telestrat/textcolor.s | 16 ---------
 7 files changed, 62 insertions(+), 92 deletions(-)

diff --git a/libsrc/telestrat/bgcolor.s b/libsrc/telestrat/bgcolor.s
index 14ecf4bd..2f602922 100644
--- a/libsrc/telestrat/bgcolor.s
+++ b/libsrc/telestrat/bgcolor.s
@@ -3,23 +3,10 @@
 
         .export         _bgcolor
         .import         BGCOLOR
-        .import         BGCOLOR_CHANGE
+
         .include        "telestrat.inc"
 
 .proc _bgcolor
-    cmp     BGCOLOR       ; Do we set the same color? If we don't detect it, we loose one char on the screen for each bgcolor call with the same color
-    bne     out           ; Yes
-    
-    ldy     #$00
-    sty     BGCOLOR_CHANGE
-
-    rts
-out:
-    ldx     BGCOLOR       ; Get last color in order to return it
     sta     BGCOLOR
-
-    lda     #$01          ; Notify the change color  
-    sta     BGCOLOR_CHANGE  
-    txa                   ; Return previous color
     rts
 .endproc
diff --git a/libsrc/telestrat/clrscr.s b/libsrc/telestrat/clrscr.s
index 22a88012..f44000d1 100644
--- a/libsrc/telestrat/clrscr.s
+++ b/libsrc/telestrat/clrscr.s
@@ -3,9 +3,8 @@
 ;
 
     .export    _clrscr
-
-
-    .import    CHARCOLOR_CHANGE, CHARCOLOR, BGCOLOR, BGCOLOR_CHANGE
+    .import    OLD_CHARCOLOR, OLD_BGCOLOR, CHARCOLOR, BGCOLOR
+    
     .include   "telestrat.inc"
 
 .proc _clrscr
@@ -34,13 +33,14 @@
     stx     SCRY
     dex
     stx     SCRX
-
-    stx     CHARCOLOR_CHANGE
-    stx     BGCOLOR_CHANGE
+    
+    ; X is equal to 0
+    stx     BGCOLOR
+    stx     OLD_BGCOLOR
 
     lda     #$07
     sta     CHARCOLOR
-    sta     BGCOLOR
+    sta     OLD_CHARCOLOR
 
     rts
 .endproc
diff --git a/libsrc/telestrat/cputc.s b/libsrc/telestrat/cputc.s
index d313d778..4b8e4fef 100644
--- a/libsrc/telestrat/cputc.s
+++ b/libsrc/telestrat/cputc.s
@@ -4,34 +4,39 @@
 ; void cputc (char c);
 ;
 
-        .export         _cputc, CHARCOLOR, CHARCOLOR_CHANGE, BGCOLOR, BGCOLOR_CHANGE
+        .export         _cputc, CHARCOLOR, OLD_CHARCOLOR, BGCOLOR, OLD_BGCOLOR
 
         .include        "telestrat.inc"
 
 .proc _cputc
-    ldx     CHARCOLOR_CHANGE
+    ldx     CHARCOLOR
+    cpx     OLD_CHARCOLOR
     beq     do_not_change_color_foreground
+    
+    stx     OLD_CHARCOLOR         ; Store CHARCOLOR into OLD_CHARCOLOR
+
     dec     SCRX
     dec     SCRX
+
     pha
-    lda     CHARCOLOR
+    txa                           ; Swap X to A because, X contains CHARCOLOR
     BRK_TELEMON  XFWR             ; Change color on the screen (foreground)
-    lda     #$00
-    sta     CHARCOLOR_CHANGE
     inc     SCRX
     pla
 
 do_not_change_color_foreground:
-    ldx     BGCOLOR_CHANGE
+    ldx     BGCOLOR
+    cpx     OLD_BGCOLOR
     beq     do_not_change_color
+
+    stx     OLD_BGCOLOR
+
     dec     SCRX                 ; Dec SCRX in order to place attribute before the right position
+
     pha
-    lda     BGCOLOR
+    txa                          ; Swap X to A because, X contains CHARCOLOR
     ORA     #%00010000           ; Add 16 because background color is an attribute between 16 and 23. 17 is red background for example
     BRK_TELEMON  XFWR            ; Change color on the screen (background)
-    lda     #$00
-    sta     BGCOLOR_CHANGE
-
     pla
 
 do_not_change_color:
@@ -41,9 +46,9 @@ do_not_change_color:
 .bss
 CHARCOLOR:
     .res 1
-CHARCOLOR_CHANGE:
+OLD_CHARCOLOR:
     .res 1    
 BGCOLOR:
-    .res 1
-BGCOLOR_CHANGE:
     .res 1    
+OLD_BGCOLOR:
+    .res 1
diff --git a/libsrc/telestrat/gotox.s b/libsrc/telestrat/gotox.s
index f16c05b7..cd8828d6 100644
--- a/libsrc/telestrat/gotox.s
+++ b/libsrc/telestrat/gotox.s
@@ -3,13 +3,8 @@
 ;
     .export    _gotox
 
-    .import    popa
-
-    .importzp  sp
-
     .include   "telestrat.inc"
 
-
 .proc _gotox
    sta    SCRX
    rts
diff --git a/libsrc/telestrat/gotoxy.s b/libsrc/telestrat/gotoxy.s
index 7a53a77a..04a680e6 100644
--- a/libsrc/telestrat/gotoxy.s
+++ b/libsrc/telestrat/gotoxy.s
@@ -7,7 +7,7 @@
 
         .export         gotoxy, _gotoxy, update_adscr
 
-        .import         popa, CHARCOLOR_CHANGE, BGCOLOR_CHANGE
+        .import         popa, OLD_CHARCOLOR, OLD_BGCOLOR
 
         .include        "telestrat.inc"
 
@@ -17,41 +17,43 @@ gotoxy: jsr     popa            ; Get Y
 
 ; This function moves only the display cursor; it does not move the prompt position.
 ; In telemon, there is a position for the prompt, and another for the cursor.
-        sta     SCRY
-        jsr     popa
-        sta     SCRX
-        
-        jsr     update_adscr          ; Update adress video ram position when SCRY et SCRX are modified
-        ;       Force to put again attribute when it moves on the screen
-
-        rts
-.endproc
-
-
-.proc update_adscr
 
-        lda     #$01
-        sta     CHARCOLOR_CHANGE
-        sta     BGCOLOR_CHANGE
+    sta     SCRY
+    jsr     update_adscr          ; Update adress video ram position when SCRY is modified 
 
-        lda     #<SCREEN
-        sta     ADSCRL
+    jsr     popa
+    sta     SCRX
 
-        lda     #>SCREEN
-        sta     ADSCRH
+    rts
+.endproc
 
-        ldy     SCRY
-        beq     out
+.proc update_adscr
+; Force to set again color if cursor moves       
+; $FF is used because we know that it's impossible to have this value with a color
+; It prevents a bug : If bgcolor or textcolor is set to black for example with no char displays,
+; next cputsxy will not set the attribute if y coordinate changes
+    lda     #$FF                  
+    sta     OLD_CHARCOLOR         
+    sta     OLD_BGCOLOR           
+
+    lda     #<SCREEN
+    sta     ADSCRL
+
+    lda     #>SCREEN
+    sta     ADSCRH
+
+    ldy     SCRY
+    beq     out
 loop:
-        lda     ADSCRL          
-        clc
-        adc     #$28
-        bcc     skip
-        inc     ADSCRH
+    lda     ADSCRL          
+    clc
+    adc     #$28
+    bcc     skip
+    inc     ADSCRH
 skip:
-        sta     ADSCRL        
-        dey
-        bne     loop
+    sta     ADSCRL        
+    dey
+    bne     loop
 out:        
-        rts
+    rts
 .endproc
diff --git a/libsrc/telestrat/gotoy.s b/libsrc/telestrat/gotoy.s
index 13be8e42..182e3f74 100644
--- a/libsrc/telestrat/gotoy.s
+++ b/libsrc/telestrat/gotoy.s
@@ -8,10 +8,7 @@
     .include   "telestrat.inc"
 
 .proc _gotoy
-   sta     SCRY
-   jsr     update_adscr
-
-   ; We change the current line, it means that we need to put color attributes again.
-   ; That is not the case with _gotox because, it's on the same line attribute are already set
-   rts
+    sta     SCRY
+    jsr     update_adscr
+    rts
 .endproc
diff --git a/libsrc/telestrat/textcolor.s b/libsrc/telestrat/textcolor.s
index ee6ba729..77bf6c71 100644
--- a/libsrc/telestrat/textcolor.s
+++ b/libsrc/telestrat/textcolor.s
@@ -3,25 +3,9 @@
 
         .export         _textcolor
         .import         CHARCOLOR
-        .import         CHARCOLOR_CHANGE
         .include        "telestrat.inc"
 
 .proc _textcolor
-    cmp     CHARCOLOR       ; Do we set the same color? If we don't detect it, we loose one char on the screen for each textcolor call with the same color
-    bne     out             ; yes
-
-    ldy     #$00
-    sty     CHARCOLOR_CHANGE
-    
-    ; Return last color
-
-    rts
-out:
-    ldx     CHARCOLOR       ; Get last color in order to return it
     sta     CHARCOLOR
-
-    lda     #$01
-    sta     CHARCOLOR_CHANGE
-    txa                     ; Return previous color
     rts
 .endproc
-- 
2.26.0