How to get character codes shown in the manual?

Basic and Machine Language

Moderator: Moderators

Post Reply
The Geek on Skates
Vic 20 Drifter
Posts: 33
Joined: Fri Jul 12, 2019 6:11 am
Website: http://www.geekonskates.com
Occupation: Code Monkey

How to get character codes shown in the manual?

Post by The Geek on Skates »

Good morning & happy Friday! :)

I've been working on a Pong clone using cc65, and I've run into something kind of strange: the character codes listed in the manual are inconsistent with the ones I'm POKE'ing to the screen. For example:

Code: Select all

#include <conio.h>
#include <peekpoke.h>
int main() {
    // Using this to make the screen black & white with a blue-green border
    bgcolor(0);
    bordercolor(3);
    textcolor(1);
    clrscr();
    
    // This prints a sort of checkerboard character.
    // But in the manual, 127 is a triangle (kinda like a filled-in backslash)
    // and the checkered character is listed with code 191.  So I tried it in hex,
    // and 0x127 is an apostrophe.
    POKE(7680, 127);
    
    return 0;
}
So I dug deeper into the manual and found out there's a BASIC command called CHR$ that converts a number to a character. But there's a difference between what's in the manual and what this CHR$ thing returns. It's interesting because the Vic-20 has more non-printable characters than a modern computer has, so it looks like the idea is to be able to print those to i.e. clear the screen. That's awesome, and I'd like to learn how to do that, buuuuut... how can I get the "real" values? Is it just a matter of simple subtraction (191 - 127 = 64, so subtract 64 from what's in the manual) or what? :lol:

And here are some details that might be useful, in case it makes a difference: I'm using the VICE emulator and the latest version of cc65 on Ubuntu 18.04, and I didn't have a Vic-20 growing up, so I don't know much in the way of BASIC. I'd eventually like to work my way up to Assembly, but right now I just now like 4 commands (lda, sta, jsr and rts lol). But for now, cc65 works. I've used it for little intro tunes (and wrote a little sound library for it I'll be putting on my BitBucket later) so I know it works on the Vic-20.

Thanks in advance. :)
User avatar
Mike
Herr VC
Posts: 4901
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: How to get character codes shown in the manual?

Post by Mike »

You need to differentiate between screen codes (what is POKEd into screen RAM) and CHR$ codes (a.k.a. as PETSCII - what is printed out via PRINT or JSR $FFD2) - both tables are given in the User's Manual (pp. 141..142 and pp. 145..147, respectively).

Also, if you write directly (i.e. POKE) into screen RAM, make sure that you also write the corresponding colour RAM address. Per default, the KERNAL initialises the colour RAM to 1 (=white) on a screen clearing action, regardless of current foreground or background colour. So, unless you happen to use a non-white background, chances are that a POKE to screen RAM gives you a white on white, i.e. invisible character.
The Geek on Skates
Vic 20 Drifter
Posts: 33
Joined: Fri Jul 12, 2019 6:11 am
Website: http://www.geekonskates.com
Occupation: Code Monkey

Re: How to get character codes shown in the manual?

Post by The Geek on Skates »

lol yup, I learned that one the hard way too. That's why I went with a black screen! :lol: "It's Pong, so I can get away with that!" But I was able to find the addresses to fix that problem. Kinda hilarious their default is white-on-white. I know coding 24/7 can be tiring, but that seems like a pretty noticeable mistake. Or maybe there was some hardware limitation involved, lol idk.

But yeah, I found the thing you were talking about the disparate characters sets. After pouring over the wrong appendix for 2 hours and experimenting with countless numbers, I eventually said, okay, time to move on to reading the keyboard (another task I'm fighting with lol). But then I stumbled on that page and it was like, "what the...?!?! No way! What's this?" lol. And for anyone else reading this in the future, there's an additional wrinkle: in addition to there being SCREEN vs. CHR character sets, there are TWO VERSIONS of the "screen" character set. But at least now I can research how to figure out which one you're on and change between them.

Anyway, I really do have a ton to learn since I didn't grow up with this machine, especially since we're talking directly to hardware here. I've been thinking about starting with the C64, but I really like the VIC's simpler sound API, bigger characters and all that; and the fact that it can still play Donkey Kong, Pac-Man, Space Invaders, Frogger, Q-Bert and all the other arcade titles I used to love makes it extremely awesome IMO. But unlike the C64, there doesn't seem to be much documentation around anymore (and cc65 in general is in desperate need of some good tutorials, on all systems. I plan to write a few as I gain experience). So this is the first of many questions, and I already have 3 or 4 more, but I think I'm gonna dive into the manual a bit before I come back. Thanks for being so cool with helping out a newbie. :lol:
Post Reply