Blob Blame Raw
From a0a6537bdaa29743ceea170ee4884ab018da7369 Mon Sep 17 00:00:00 2001
From: jede <jede@oric.org>
Date: Sun, 7 Jul 2019 22:02:48 +0200
Subject: [PATCH 21/29] Fix typo and optimize

---
 libsrc/telestrat/bgcolor.s   |  9 +++------
 libsrc/telestrat/cputc.s     |  7 +++++--
 libsrc/telestrat/gotoxy.s    |  8 ++++----
 libsrc/telestrat/gotoy.s     |  4 ++--
 libsrc/telestrat/textcolor.s | 15 +++++++--------
 5 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/libsrc/telestrat/bgcolor.s b/libsrc/telestrat/bgcolor.s
index 4af0ef76..14ecf4bd 100644
--- a/libsrc/telestrat/bgcolor.s
+++ b/libsrc/telestrat/bgcolor.s
@@ -7,12 +7,11 @@
         .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 textcolor call with the same color
+    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
-    lda     #$00
-    sta     BGCOLOR_CHANGE
     
-    lda     BGCOLOR       ; Return last color
+    ldy     #$00
+    sty     BGCOLOR_CHANGE
 
     rts
 out:
@@ -24,5 +23,3 @@ out:
     txa                   ; Return previous color
     rts
 .endproc
-
-
diff --git a/libsrc/telestrat/cputc.s b/libsrc/telestrat/cputc.s
index f38db8a1..96763caf 100644
--- a/libsrc/telestrat/cputc.s
+++ b/libsrc/telestrat/cputc.s
@@ -11,18 +11,20 @@
 .proc _cputc
     ldx     CHARCOLOR_CHANGE
     beq     do_not_change_color_foreground
-
+    dec     SCRX
+    dec     SCRX
     pha
     lda     CHARCOLOR
     BRK_TELEMON  $4E             ; Change color on the screen (foreground)
     lda     #$00
     sta     CHARCOLOR_CHANGE
+    inc     SCRX
     pla
 
 do_not_change_color_foreground:
     ldx     BGCOLOR_CHANGE
     beq     do_not_change_color
-
+    dec     SCRX                 ; Dec SCRX in order to place attribute before the right position
     pha
     lda     BGCOLOR
     ORA     #%00010000           ; Add 16 because background color is an attribute between 16 and 23. 17 is red background for example
@@ -36,6 +38,7 @@ do_not_change_color:
     BRK_TELEMON  XFWR            ; Macro send char to screen (channel 0)
     rts
 .endproc
+.bss
 CHARCOLOR:
     .res 1
 CHARCOLOR_CHANGE:
diff --git a/libsrc/telestrat/gotoxy.s b/libsrc/telestrat/gotoxy.s
index 73e7d272..8dcb69e8 100644
--- a/libsrc/telestrat/gotoxy.s
+++ b/libsrc/telestrat/gotoxy.s
@@ -5,7 +5,7 @@
 ; void gotoxy (unsigned char x, unsigned char y);
 ;
 
-        .export         gotoxy, _gotoxy, _update_adscr
+        .export         gotoxy, _gotoxy, update_adscr
 
         .import         popa, CHARCOLOR_CHANGE, BGCOLOR_CHANGE
 
@@ -21,7 +21,7 @@ gotoxy: jsr     popa            ; Get Y
         jsr     popa
         sta     SCRX
         
-        jsr     _update_adscr          ; Update adress video ram position when SCRY et SCRX are modified
+        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
         lda     #$01
         sta     CHARCOLOR_CHANGE
@@ -30,7 +30,7 @@ gotoxy: jsr     popa            ; Get Y
 .endproc
 
 
-.proc _update_adscr
+.proc update_adscr
         lda     #<SCREEN
         sta     ADSCRL
 
@@ -51,4 +51,4 @@ skip:
         bne     loop
 out:        
         rts
-.endproc
\ No newline at end of file
+.endproc
diff --git a/libsrc/telestrat/gotoy.s b/libsrc/telestrat/gotoy.s
index ee437f00..ae6a0bcf 100644
--- a/libsrc/telestrat/gotoy.s
+++ b/libsrc/telestrat/gotoy.s
@@ -4,13 +4,13 @@
     .export    _gotoy
     .import    CHARCOLOR_CHANGE, BGCOLOR_CHANGE
 
-    .import    _update_adscr
+    .import    update_adscr
 
     .include   "telestrat.inc"
 
 .proc _gotoy
    sta     SCRY
-   jsr     _update_adscr
+   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
diff --git a/libsrc/telestrat/textcolor.s b/libsrc/telestrat/textcolor.s
index 6c635268..b5584902 100644
--- a/libsrc/telestrat/textcolor.s
+++ b/libsrc/telestrat/textcolor.s
@@ -7,22 +7,21 @@
         .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
+    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
-    lda     #$00
-    sta     CHARCOLOR_CHANGE
     
-    lda     CHARCOLOR       ; return last color
+    ldy     #$00
+    sty     CHARCOLOR_CHANGE
+    
+    lda     CHARCOLOR       ; Return last color
 
     rts
 out:
-    ldx     CHARCOLOR       ; get last color in order to return it
+    ldx     CHARCOLOR       ; Get last color in order to return it
     sta     CHARCOLOR
 
     lda     #$01
     sta     CHARCOLOR_CHANGE
-    txa                     ; return previous color
+    txa                     ; Return previous color
     rts
 .endproc
-
-
-- 
2.21.0