Commander X16 Petscii control codes question...

codewar65

Member
Sep 25, 2019
34
19
8
I'm implementing a new 'Reverse' control code (I will call Invert) in a project I'm working. It will swap the upper and lower nybbles of the current text color.

This way, to set a new background, print a foreground color, 'invert' it to the background, set new foreground color. This code is still stateless and easy to work with (for me). Invert also works like a Reverse toggle if you aren't messing with changing colors.
 
  • Like
Reactions: BruceMcF

BruceMcF

Active Member
May 19, 2019
150
49
28
As a general function, this is even better than the "copy foreground to background" color, since on it's own it gives reversing colors in one code and it gives all other settings of background and foreground in the same number of codes as "copy foreground to background". Plus it is just as atomic as an operation, unlike "the next color code is a background color code" or "if there are two color codes in a row, the first one was background" approaches.
 
  • Like
Reactions: codewar65

codewar65

Member
Sep 25, 2019
34
19
8
I think I might try to test this in a patch kernal here to see how it works in general. 19 bytes of code in editor.1.s should do the trick.

Code:
        cmp #$02    ; check ctrl-b for invert.
        bne @skip
        lda color    ; get current text color.
        asl a        ; swap msn/lsn.
        adc #$80
        rol a
        asl a
        adc #$80
        rol a
        sta color    ; stash back.
        rts
@skip:
 
Last edited:

mobluse

Member
Sep 20, 2019
40
18
8
Yes I think it would be good if you send a pull request. Now when RAM addresses changes (e.g. color changed from 646 in r34 and earlier to 713 in r35) it is more important to change background color using a new PETSCII control code.
 

codewar65

Member
Sep 25, 2019
34
19
8
Yes I think it would be good if you send a pull request. Now when RAM addresses changes (e.g. color changed from 646 in r34 and earlier to 713 in r35) it is more important to change background color using a new PETSCII control code.
I'll see if I can figure out how to do this.
 

mobluse

Member
Sep 20, 2019
40
18
8
The easiest way to do a pull request is to start editing a file in the repository you want to change with the GitHub editor. Then you can add more changes to your branch, e.g. change other files. One can check the pull request locally according to https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally.

Would this change slow down PRINTing in general?

I wonder why they use a RAM address and POKE to control colors. Would it not be more efficient to use video RAM and VPOKE? Maybe they now need to check color for each character before it is printed, and that would slow down printing.
 

codewar65

Member
Sep 25, 2019
34
19
8
The easiest way to do a pull request is to start editing a file in the repository you want to change with the GitHub editor. Then you can add more changes to your branch, e.g. change other files. One can check the pull request locally according to https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/checking-out-pull-requests-locally.
I'd like to hold on that until I can test this locally with my own build of the ROM. Being on Windows, it's tedious building much of this.

Would this change slow down PRINTing in general?
No. It's on the tail end of the printing routine when all known control characters have been compared and executed. This is where the character is compared with the 16 color controls to find a match.
 

codewar65

Member
Sep 25, 2019
34
19
8
Yes I think it would be good if you send a pull request. Now when RAM addresses changes (e.g. color changed from 646 in r34 and earlier to 713 in r35) it is more important to change background color using a new PETSCII control code.
I just built the ROM on my linux box and tested it out here. Works fine.

Using control-b ($02) for the invert.

Untitled-1.png
 
  • Like
Reactions: mobluse
May 22, 2019
504
266
63
I wonder why they use a RAM address and POKE to control colors. Would it not be more efficient to use video RAM and VPOKE? Maybe they now need to check color for each character before it is printed, and that would slow down printing.
Because VERA doesn't "print". It simply displays memory locations as characters. The character output code is actually part of BASIC and the KERNAL, which load memory locations with character and color data. So printing a character involves loading one memory location with the the character and the next with the color data. 646 is the memory location that holds the next color to be placed in VERA when a character is printed.
 

mobluse

Member
Sep 20, 2019
40
18
8
I could download and update the ROM using
Bash:
cd x16-rom
git fetch origin pull/89/head:patch-1
git checkout patch-1
make
cp rom.bin ../x16-emulator
@codewar65's example worked for me in x16emu in Raspbian Buster Linux on Raspberry Pi 4 B.

In aritm-x16.bas for coming r35 I could change this line:
1116 OPEN 1,0:POKE 713,0:PRINT CHR$($8E);CHR$($9E):SCREEN 0
to:
1116 OPEN 1,0:PRINT CHR$($8E);CHR$($90);CHR$($02);CHR$($9E):SCREEN 0
and thus be independent of changing RAM addresses, and also be able to change background in my filter program. The filter program, petscii2utf8, has not yet been updated to change background, i.e. handle Ctrl+B/$02.

There is already Reverse On/Reverse Off ($12/$92), so the importance of Ctrl+B is to change the background and also to be able to emit a character to a filter or serial port to tell that the background has changed.
 
Last edited:
  • Like
Reactions: codewar65

codewar65

Member
Sep 25, 2019
34
19
8
The main thrust of adding an ability to change background via PETSCII is the art scene. Exchanging files in a PETSCII format to allow to access background colors. I do all my coding in assembler or C or Pascal. But a common interchange to express art is important to me. Plus I'm a big ANSI art fan and the ability to access all the good stuff via control codes is important.
 

codewar65

Member
Sep 25, 2019
34
19
8
There is already Reverse On/Reverse Off ($12/$92), so the importance of Ctrl+B is to change the background and also to be able to emit a character to a filter or serial port to tell that the background has changed.
Reverse On/Off toggles the upper half/lower half of the character ROM. Not really needed on the x16 as there is now a true background color. We only need 128 characters in ROM (unless you need that odd 256 color mode).
 

mobluse

Member
Sep 20, 2019
40
18
8
I thought Reverse On/Off worked for PETSCII-UC, PETSCII-LC, and ISO mode, but it doesn't work for ISO mode. Try RUNning this program before and after Ctrl+O:
Code:
10 PRINT "ABCD";CHR$($12);"EFGH";CHR$($92);"IJKL"
20 PRINT "ABCD";CHR$($02);"EFGH";CHR$($02);"IJKL"
CHR$($02) for reversing only works if you have merged PR 89 for x16-rom.
 

BruceMcF

Active Member
May 19, 2019
150
49
28
There is already Reverse On/Reverse Off ($12/$92), so the importance of Ctrl+B is to change the background and also to be able to emit a character to a filter or serial port to tell that the background has changed.
It's quite useful in rich text on a character display to allow users to pick which color combinations represents which text attribute. Even for italic, bold and underline, that is eight combinations.
 
  • Like
Reactions: mobluse