Blob Blame Raw
From 7f9e73a1ce42ca5489f7b533d942a4d8b3193148 Mon Sep 17 00:00:00 2001
From: jede <jede@oric.org>
Date: Sat, 6 Jul 2019 10:16:57 +0200
Subject: [PATCH 17/29] Add textcolor and bgcolor.s

---
 asminc/telestrat.inc         |  1 +
 doc/telestrat.sgml           | 10 ++++++++--
 libsrc/telestrat/bgcolor.s   | 28 +++++++++++++++++++++++++++
 libsrc/telestrat/clrscr.s    | 15 ++++++++++++---
 libsrc/telestrat/cputc.s     | 37 +++++++++++++++++++++++++++++++++---
 libsrc/telestrat/gotoxy.s    | 21 +++++++++++++++-----
 libsrc/telestrat/gotoy.s     |  3 ++-
 libsrc/telestrat/textcolor.s | 28 +++++++++++++++++++++++++++
 8 files changed, 129 insertions(+), 14 deletions(-)
 create mode 100644 libsrc/telestrat/bgcolor.s
 create mode 100644 libsrc/telestrat/textcolor.s

diff --git a/asminc/telestrat.inc b/asminc/telestrat.inc
index 3526c6f9..2036574a 100644
--- a/asminc/telestrat.inc
+++ b/asminc/telestrat.inc
@@ -286,6 +286,7 @@ XZAP             = $46          ; Send Zap sound to PSG
 XSHOOT           = $47
 XMKDIR           = $4B          ; Create a folder. Only available in TELEMON 3.x (bank 7 of Orix)
 XRM              = $4D          ; Remove a folder or a file. Only available in TELEMON 3.x (bank 7 of Orix)
+XFWR             = $4E          ; Put a char on the first screen. Only available in TELEMON 3.x (bank 7 of Orix)
 XGOKBD           = $52
 
 ; Buffer management
diff --git a/doc/telestrat.sgml b/doc/telestrat.sgml
index e52b183d..0cb40c50 100644
--- a/doc/telestrat.sgml
+++ b/doc/telestrat.sgml
@@ -212,7 +212,8 @@ RS232 port with Telemon calls (see XSOUT primitive for example)
 Telemon 3.0 handles fopen, fread, fclose primitives. It means that this
 function will crash the Telestrat because Telemon 2.4 does not have these
 primitives. By the way, Telemon 3.0 uses an extension "ch376 card" which
-handles sdcard and FAT 32 usb key. In the next version of Telemon, FT DOS, Sedoric, Stratsed will be handled in these 3 primitives (fopen, fread, fclose).
+handles sdcard and FAT 32 usb key. In the next version of Telemon, FT DOS, 
+Sedoric, Stratsed will be handled in these 3 primitives (fopen, fread, fclose).
 
 <itemize>
 <item>fclose
@@ -220,7 +221,12 @@ handles sdcard and FAT 32 usb key. In the next version of Telemon, FT DOS, Sedor
 <item>fread
 </itemize>
 
-
+<sect1>conio<p>
+Functions textcolor and bgcolor are available only with Telemon 3.0 (Orix). 
+Telemon 2.4 primitives can't handle any change of colors in text mode except with XINK or 
+XPAPER primitives which put on the first and second columns ink and paper attributes. 
+The only way to change color on the same line for text is to handle it in pure assembly 
+without systems calls.
 
 <sect>Other hints<p>
 
diff --git a/libsrc/telestrat/bgcolor.s b/libsrc/telestrat/bgcolor.s
new file mode 100644
index 00000000..4af0ef76
--- /dev/null
+++ b/libsrc/telestrat/bgcolor.s
@@ -0,0 +1,28 @@
+; 2019-07-02, Jede (jede@oric.org)
+;
+
+        .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 textcolor call with the same color
+    bne     out           ; Yes
+    lda     #$00
+    sta     BGCOLOR_CHANGE
+    
+    lda     BGCOLOR       ; Return last color
+
+    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 1f90a7ca..a24647f8 100644
--- a/libsrc/telestrat/clrscr.s
+++ b/libsrc/telestrat/clrscr.s
@@ -4,15 +4,15 @@
 
     .export    _clrscr
 
-    .importzp  sp
 
+    .import    CHARCOLOR_CHANGE, CHARCOLOR, BGCOLOR, BGCOLOR_CHANGE
     .include   "telestrat.inc"
 
 .proc _clrscr
     ; Switch to text mode
     BRK_TELEMON(XTEXT)
 
-    lda     #<SCREEN
+    lda     #<SCREEN                                ; Get position screen
     ldy     #>SCREEN
     sta     RES
     sty     RES+1
@@ -20,7 +20,7 @@
     ldy     #<(SCREEN+SCREEN_XSIZE*SCREEN_YSIZE)
     ldx     #>(SCREEN+SCREEN_XSIZE*SCREEN_YSIZE)
     lda     #' '
-    BRK_TELEMON XFILLM
+    BRK_TELEMON XFILLM                              ; Calls XFILLM : it fills A value from RES address and size of X and Y value
 
 
     ; reset prompt position
@@ -34,5 +34,14 @@
     sta     SCRY
     lda     #$00
     sta     SCRX
+
+    lda     #$00
+    sta     CHARCOLOR_CHANGE
+    sta     BGCOLOR_CHANGE
+
+    lda     #$07
+    sta     CHARCOLOR
+    sta     BGCOLOR
+
     rts
 .endproc
diff --git a/libsrc/telestrat/cputc.s b/libsrc/telestrat/cputc.s
index b4f2966a..f38db8a1 100644
--- a/libsrc/telestrat/cputc.s
+++ b/libsrc/telestrat/cputc.s
@@ -4,12 +4,43 @@
 ; void cputc (char c);
 ;
 
-        .export         _cputc
+        .export         _cputc, CHARCOLOR, CHARCOLOR_CHANGE, BGCOLOR, BGCOLOR_CHANGE
 
         .include        "telestrat.inc"
 
 .proc _cputc
-    BRK_TELEMON  XWR0       ; macro send char to screen (channel 0 in telemon terms)
+    ldx     CHARCOLOR_CHANGE
+    beq     do_not_change_color_foreground
+
+    pha
+    lda     CHARCOLOR
+    BRK_TELEMON  $4E             ; Change color on the screen (foreground)
+    lda     #$00
+    sta     CHARCOLOR_CHANGE
+    pla
+
+do_not_change_color_foreground:
+    ldx     BGCOLOR_CHANGE
+    beq     do_not_change_color
+
+    pha
+    lda     BGCOLOR
+    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:
+    BRK_TELEMON  XFWR            ; Macro send char to screen (channel 0)
     rts
 .endproc
-
+CHARCOLOR:
+    .res 1
+CHARCOLOR_CHANGE:
+    .res 1    
+BGCOLOR:
+    .res 1
+BGCOLOR_CHANGE:
+    .res 1    
diff --git a/libsrc/telestrat/gotoxy.s b/libsrc/telestrat/gotoxy.s
index 03d0a215..0a3db00b 100644
--- a/libsrc/telestrat/gotoxy.s
+++ b/libsrc/telestrat/gotoxy.s
@@ -5,10 +5,10 @@
 ; void gotoxy (unsigned char x, unsigned char y);
 ;
 
-        .export         gotoxy, _gotoxy
+        .export         gotoxy, _gotoxy, _update_adscr
+
+        .import         popa,CHARCOLOR_CHANGE,BGCOLOR_CHANGE
 
-        .import         popa
-        .importzp       sp
 
         .include        "telestrat.inc"
 
@@ -22,6 +22,16 @@ gotoxy: jsr     popa            ; Get Y
         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
+        lda     #$01
+        sta     CHARCOLOR_CHANGE
+        sta     BGCOLOR_CHANGE
+        rts
+.endproc
+
+
+.proc _update_adscr
         lda     #<SCREEN
         sta     ADSCRL
 
@@ -29,6 +39,7 @@ gotoxy: jsr     popa            ; Get Y
         sta     ADSCRL+1
 
         ldy     SCRY
+        beq     out
 loop:
         lda     ADSCRL          
         clc
@@ -39,6 +50,6 @@ skip:
         sta     ADSCRL        
         dey
         bne     loop
-
+out:        
         rts
-.endproc
+.endproc
\ No newline at end of file
diff --git a/libsrc/telestrat/gotoy.s b/libsrc/telestrat/gotoy.s
index 05ed71de..c6010cc2 100644
--- a/libsrc/telestrat/gotoy.s
+++ b/libsrc/telestrat/gotoy.s
@@ -3,11 +3,12 @@
 ;
     .export    _gotoy
 
-    .importzp  sp
+    .import    _update_adscr
 
     .include   "telestrat.inc"
 
 .proc _gotoy
    sta     SCRY
+   jsr     _update_adscr
    rts
 .endproc
diff --git a/libsrc/telestrat/textcolor.s b/libsrc/telestrat/textcolor.s
new file mode 100644
index 00000000..6c635268
--- /dev/null
+++ b/libsrc/telestrat/textcolor.s
@@ -0,0 +1,28 @@
+; 2019-07-02, Jede (jede@oric.org)
+;
+
+        .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
+    lda     #$00
+    sta     CHARCOLOR_CHANGE
+    
+    lda     CHARCOLOR       ; 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.21.0