Jump to content
  • 0

Colour Text and other tips for text displays


Nadia
 Share

Question

Hi It's been a few months since I have posted since I have been without a pc. I followed a few guides a couple months back but I am struggling to wrap my head around the Vera chip and displaying colors and graphics. I decided I wanted to make my own little text adventure game now that I have a new computer, but I don't know how to change the colour of the texts in the game and the background that the text would be displayed on. So if anyone could explain it to me or guide me towards the right answer I would appreciate it. I was also wondering if their was a good tutorial for the VERA chip that is for more novice programmers. I am very new to programming so this can be very hard for me to wrap my head around. Thanks to anyone who took the time to read and or answer.  ❤️ Nadia ❤️

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0
56 minutes ago, Snickers11001001 said:

Are you programming in BASIC or will you be using something different?

I am using basic. It will be a basic CYOA game that I want to use some basic color text and use special petscii characters to make basic graphics.

Link to comment
Share on other sites

  • 0

You can use PETSCII codes to set both background and foreground color.

Something like this:

Quote

10 PRINT CHR$($81):REM SET FOREGROUND COLOR TO ORANGE
20 PRINT CHR$($01):REM SWAP FOREGROUND- AND BACKGROUND COLOR
30 PRINT CHR$($1F):REM SET FOREGROUND COLOR TO BLUE
40 PRINT "THIS TEXT IS BLUE ON ORANGE BACKGROUND"

You can find a table of the PETSCII codes here: https://cx16.dk/cx16-petscii/

If you are writing directly to VERA memory, you need to remember that in default text modes, each character on screen uses 2 bytes of VRAM.

The first byte contains the screencode of the character and the second byte contains the bacground- and foreground color.

So you write to VRAM like this:

Quote

10 VPOKE 0,0,0         :REM DISPLAY AN @ SIGN AT COORDINATE 0,0
20 VPOKE 0,1,$51       :REM MAKE IT WHITE ON GREEN
30 VPOKE 0,(10*2)+(256*1),0:REM PRINT AN @ AT COORDINATE 10,1
40 VPOKE 0,(10*2)+(256*1)+1,$51:REM WHITE ON GREEN AGAIN

You can find a table of screencodes and VERA standard colors here: https://cx16.dk/veratext/verachars/

When you use VPOKE to write to VRAM, you have to calculate the addresses your self, but it is fairly easy.

Your X coordinate should always be doubled as each character on screen takes up 2 bytes. This is why I have (10*2) on line 30 and 40 above to make the @ sign appear at X=10.

Each line takes up 256 bytes of VRAM even though only 80 (or 40) characters are visible so in order to calculated your Y coordinate you simply multiply it by 256.

The final calculation is:

Quote

(Xcoordinate*2)+(Ycoordinate*256) = Character on screen
(Xcoordinate*2)+(Ycoordinate*256)+1 = Color of character on screen

The color information is most easily given in hexadecimal as that means that the first digit (upper nibble) is the background color and the second digit (lower nibble) is the foreground color. For more information on VPOKE, have a look at the manual: https://github.com/commanderx16/x16-docs/blob/master/Commander X16 Programmer's Reference Guide.md#vpoke

 

  • Like 1
Link to comment
Share on other sites

  • 0

Here’s one quick tip: By default, the background color is not a single value like it was on C64. Each character has its own foreground and background color attributes.

This defaults to white on blue.

in BASIC, you may use the command COLOR to set what foreground/BG colors are used when typing or using PRINT commands.

Its easiest to understand the values if you use hexadecimal to specify the color.

For example:

COLOR $14 will be the reverse colors from default- blue on white. COLOR $41 will return to the default white on blue.

So in hex (values specified with a $) the first digit is the BG color and the second digit is the FG color. Since this is hex, each digit ranges from 0-9 then A-F for values 10-15.

So to set BG color 12 and FG color 10, you would use COLOR $CA

If you use variables to hold the colors, you may set those using hex also.

BG=$C0 : FG=$0A : COLOR BG+FG

If you use decimal it’s much uglier:

BG=12*16 : FG=10 : COLOR BG+FG

or

BG=12 : FG=10 : COLOR BG*16+FG

How to set the whole screen BG color:

The simple way is to change to your desired color scheme and then clear the screen.

Another way to do this without clearing the screen is to take advantage of the fact that black isn’t actually black - it’s transparent. The color palette defaults to using black as the BG color. So, if you set the BG print color to black (e.g. COLOR $01) (white on black) and then clear the screen you’ll have black BG with white text.

However, you can change this black to any color and the whole screen will change immediately without having to clear it.

VPOKE 1,$FA00,$05 : VPOKE 1,$FA01,$0C

Now the background will be some shade of purple.These two commands just changed the color palette entry zero, which is the true screen BG color.

$FA00 holds the green/blue level and $FA01 holds the red level.

Link to comment
Share on other sites

  • 0

The COLOR command in BASIC is actually even simpler. You just use the foreground color for the first argument and the background color for the second -- no need to combine them into a single hex byte. This lets you use the first 16 colors (0-15) of the palette for either argument:

image.png.3225219909331e996c8fdc4737d6a8bd.png

This is perfectly good for just doing a text-based adventure, but if you want to get into having something more than just a running console, you'll want to get into VPOKE-ing character and color codes.

  • Like 1
Link to comment
Share on other sites

  • 0
Posted (edited)

@SlithyMatt @ZeroByte @JimmyDansbo Thanks so much for the great information. For this project I will only be using the color command because the main ideaof the game was to show myself I could make my own game and also to help me learn basic conditionals. The second game I do I want to have graphics so these charts and other information will help with that.  Thank you all for your time and great answers I honestly expected no one to answer so it means a lot to me. ❤️

Edited by Nadia
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use