How do I redefine characters with 8k or more RAM?

Basic and Machine Language

Moderator: Moderators

rhurst
Omega Star Commander
Posts: 1371
Joined: Thu Jan 31, 2008 2:12 pm
Website: https://robert.hurst-ri.us
Location: Providence, RI
Occupation: Tech & Innovation

Re: How do I redefine characters with 8k or more RAM?

Post by rhurst »

Very nice -- glad to see you saw this through to creation. 8)
Any technology distinguishable from magic is insufficiently advanced.
https://robert.hurst-ri.us/rob/retrocomputing
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: How do I redefine characters with 8k or more RAM?

Post by chysn »

A very impressive image, nicely done!
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: How do I redefine characters with 8k or more RAM?

Post by Mike »

Screens built this way become somewhat more involved when the viewer cannot anymore tell easily that the picture was 'tiled' from characters.

Here is a particularly nice example from a type-in game (Dangerous Planet):

Image

These are a number of different characters that 'carve' out the boundary between free space and solid rock. The game is included in my Games Collection and it consists of two parts: the first part shows the title screen, redefines the characters and gives instructions; the second part contains the main part of the game. It is written in 100% BASIC, so it is quite easy to see how the in-game screen is built from PRINT statements.

The green "A9"-crystals at the bottom of the cave and also some of the enemies use multicolour, BTW - and it was this very game which made me aware of this display method. :)

I would like to add that not only the letters A..Z can be redefined, you can build an entire new character set from up to 256 characters. There is also no restriction that the symbols shall somehow relate to the original glyphs - their shape is only relevant while you are working in text mode. Some games - when they use redefined letters - even only feature those letters in the character set that are actually used in the display, and these letters do not even need to reside at their 'original' position.

At some point you advance to the notion that the text screen might not be relevant at all anymore (except for providing colour RAM attribute data), and then you tile it with unique characters to create a bitmap instead.
Duke
Vic 20 Newbie
Posts: 13
Joined: Mon Jan 01, 2024 9:21 am
Location: Netherlands
Occupation: Teacher

Re: How do I redefine characters with 8k or more RAM?

Post by Duke »

It took a few more weeks of practice and learning, and I think I understand how to explain what I've been up to. I might get some of the wording incorrect and maybe not quite explain a concept clearly or accurately. If I missed something, there is a lot of information in this thread that was used to help me solve the puzzle. Please take some time and read over it.

The picture of the park was written on the stock machine. It redefines 26 characters and prints the picture line by line. This is fine, but I found that I couldn't get it to show more than one character color per row of characters with PRINT commands. I learned that you can POKE your characters and their color to a specific location, so this fixed that issue. Unfortunately, typing out POKE commands takes up a lot of RAM, especially when filling the entire screen. It can be done, but only if the picture isn't too complex. I wanted to see if I could make a more complex image by poking every single location and color, which could only be done with 8k or more of RAM.

This is where the most learning had to be done. First, the shift registers for character and color location change, so you need to map out the new locations and colors. Then, you need to be able to redefine the characters into multi-color mode. On the stock system, I was able to do this with

Code: Select all

POKE36869,255
. On the 8k+, this number needs to be changed to

Code: Select all

36869,205
.

Then I needed to understand the that my characters were being placed somewhere on the RAM. This RAM location is

Code: Select all

POKE5120
. I need to tell the machine to write the characters to this memory address. Here is a formula to help with the READA statement needed to load the redefined characters into memory

Code: Select all

FORX=0TO(D*8)-1:READA:POKE5120+X,A:NEXTX
. D = number of DATA statements in your program. Because the starting memory address for basic on the machine with 8k+ is 4609, this means that my program can only use memory from address' 4609 -5120. To get around this problem, you need to type in the statement

Code: Select all

POKE44,22:POKE5632,0:NEW
before you load your program. This starts basic at memory address 5632, which is past the DATA statements. You can now use the rest of the RAM given to basic for your program.

In summary, here is the part of the program that I write when I want to redefine 64 characters starting with @.

Code: Select all

POKE36869,205
FORX=0TO511:POKE5120+X,PEEK(32768+X):NEXT X
FORX=0TO511:READA:POKE5120+X,A:NEXTX
The picture of the tower was drawn by poking every single character and color location on the screen. It's a much different accomplishment than printing out pictures. This allows for much more detailed art using the redefined characters. I'm very happy with how the PRINT command pictures came out, too.

In this thread, there is information about how to draw pictures on the Vic-20 by using PRINT or POKE commands in both 0-3k and 8k+ machines. I hope this helps anybody out there learning to draw on this wonder computer.

Now that I have this and a few other things figured out, I have enough to start making my graphic text adventure type game. I just got the build working tonight. With that done, there isn't much to do with the machine for a while since what I need now is a story and some art.
Duke
Vic 20 Newbie
Posts: 13
Joined: Mon Jan 01, 2024 9:21 am
Location: Netherlands
Occupation: Teacher

Re: How do I redefine characters with 8k or more RAM?

Post by Duke »

I would like to add that not only the letters A..Z can be redefined, you can build an entire new character set from up to 256 characters. There is also no restriction that the symbols shall somehow relate to the original glyphs - their shape is only relevant while you are working in text mode. Some games - when they use redefined letters - even only feature those letters in the character set that are actually used in the display, and these letters do not even need to reside at their 'original' position.
Certainly true. I'm currently working with 64 redefined characters. I used these to make the basic layout for the game and some test art. You can see the full set in the pub picture.
image6.jpeg
image5.jpeg
image4.jpeg
ricky_derocher
Vic 20 Newbie
Posts: 12
Joined: Mon Feb 05, 2024 11:56 pm
Location: New Hampshire

Re: How do I redefine characters with 8k or more RAM?

Post by ricky_derocher »

Duke wrote: Wed Jan 24, 2024 10:53 am Thanks for all the help. I have successfully drawn a full screen image using 8k+ RAM configuration. Here is the image.

success.jpg

I'll post more later. Just happy that it works.
Nice picture! Reminds me of Nebulas / Tower Toppler. :-)
Duke
Vic 20 Newbie
Posts: 13
Joined: Mon Jan 01, 2024 9:21 am
Location: Netherlands
Occupation: Teacher

Re: How do I redefine characters with 8k or more RAM?

Post by Duke »

Good evening all.

My next bit of trouble is redefining all 256 characters. I have 256 data statements each with 8 values separated by commas. I've checked each one. I think my understanding of what I'm doing is no longer valid. I am trying to figure out how to not have an "out of data" error or a "syntax" error when trying to redefine everything. This is what my understanding tells me is needed:

Code: Select all

2 POKE36869,205:POKE646,10:POKE36879,168:POKE36878,225
3 FOR X=0 TO 2047: POKE5120+X,PEEK(32768+X): NEXT X
4 FOR X=0 TO 2047: READ A: POKE5128+X,A: NEXT X
I've changed the maximum values of x in lines 2 and 3 for the number of data statements (256x8-1). Unfortunately, this isn't enough to redefine everything. Experimenting with various values and trying to split the information up, I was able to redefine 75 characters before getting an "out of data" statement. Unfortunately I didn't make a proper save of that variation, so I'd have to go back to experimenting before I could reproduce it. I've tried setting the starting address of basic to different locations including:

Code: Select all

POKE44,22:POKE7168,0:NEW
I thought I had this understood, but once again I'm hat in hand and asking for help. I'm quite keen on making something with redefined characters and in basic.
User avatar
tokra
Vic 20 Scientist
Posts: 1123
Joined: Tue Apr 27, 2010 5:32 pm
Location: Scheessel, Germany

Re: How do I redefine characters with 8k or more RAM?

Post by tokra »

You seem to be going in the right direction, but it seems you still do not understand a few basic concepts:

Code: Select all

POKE44,22:POKE7168,0:NEW
If you want to redefine 256 characters starting from 5120, you will need to protect 2048 bytes from BASIC access from 5120 onwards (= up to memory location 7167). As such you need to use POKE 44,28 (not 22) since 28*256 = 7168. The two memory locations at 43 and 44 tell the BASIC-interpreter where the BASIC-program starts (in low- and high-byte order). And the value in memory location 43 is 1 from power-on. You got the right idea with POKE 7168,0 but if you set the BASIC start to 22*256 = 5632 your program that follows will overwrite itself eventually (see lines 3 and 4).
Duke wrote: Sat Mar 09, 2024 11:19 am

Code: Select all

2 POKE36869,205:POKE646,10:POKE36879,168:POKE36878,225
3 FOR X=0 TO 2047: POKE5120+X,PEEK(32768+X): NEXT X
4 FOR X=0 TO 2047: READ A: POKE5128+X,A: NEXT X
In Line 4 it should read POKE 5120+X,A not 5128. If you keep it that way you will overwrite your own program again, as you will POKE to 7175 in the end, which is where your BASIC-program is residing in memory.

Also if you use redefine the full 256 chars, you should dispose of line 3 completely, as it only takes up time and all the values get overwriten in line 4 anyway. For debugging however this might make sense.

Furthermore you need to make sure you have a full 2048 elements in your DATA-statements, if you have less you will get the "out of data"-error.
Usually such BASIC-programs which want to keep part of the ROM-charset, only copy those parts and redefine just the ones that are needed, but then you will need a few FOR-NEXT-loops where you copy and write just the values you want to the correct memory locations.
Duke
Vic 20 Newbie
Posts: 13
Joined: Mon Jan 01, 2024 9:21 am
Location: Netherlands
Occupation: Teacher

Re: How do I redefine characters with 8k or more RAM?

Post by Duke »

VIC202.jpg
This is my cockpit view. The tricky part was making sure I had the character color available to make the buttons different colors. I think it turned out well.
If you want to redefine 256 characters starting from 5120, you will need to protect 2048 bytes from BASIC access from 5120 onwards (= up to memory location 7167). As such you need to use POKE 44,28 (not 22) since 28*256 = 7168
Right on the money. I didn't understand that there was math involved in creating that number. I thought 44,22 was a catch-all for redefining the starting address of basic. Now I know that I will need to calculate it further if I'm using different numbers of redefined characters.
In Line 4 it should read POKE 5120+X,A not 5128. If you keep it that way you will overwrite your own program again, as you will POKE to 7175 in the end, which is where your BASIC-program is residing in memory.
Totally right. I thought I had corrected that in the program I posted. My apologies for being sloppy.

All in all, a total success. I can now use all 256 redefined characters. Thank you for the help again. I'll try not to be too much trouble, but I know I'll have more questions in the future. This is straightforward yet tricky business this Vic-20.
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: How do I redefine characters with 8k or more RAM?

Post by Mike »

Duke wrote:I didn't understand that there was math involved in creating that number.
When you did not ask about that detail, it was foreseeable to me that you would run into this issue: next logical step after redefining part of a character set would be redefining the entire character set.

I did not want to lock away an entire 2 KB RAM for the first application you had in mind - with just a +8K RAM expansion, having 1.5 KB less for no good reason might not have been what you wanted.

Pretty much everything in computers involves math. You are changing the memory configuration here beyond what BASIC and KERNAL normally arrange for you on power up, and that requires knowledge about pointers, where they are located and how their value is derived from how you want the memory setup to be.


Edit: you also should consider using a binary font file instead of DATA lines to redefine the character set. DATAs just take up valuable space and are only justified for relatively small applications. No-one's going to type in a list of 2048 numbers from a listing printout nowadays.

Your character editor should be able to emit a font file anyway. Please take a look at this recent thread how to load the font file into memory. The other preparations to protect memory still apply and are also featured in said thread.
Duke
Vic 20 Newbie
Posts: 13
Joined: Mon Jan 01, 2024 9:21 am
Location: Netherlands
Occupation: Teacher

Re: How do I redefine characters with 8k or more RAM?

Post by Duke »

When you did not ask about that detail, it was foreseeable to me that you would run into this issue: next logical step after redefining part of a character set would be redefining the entire character set.
Quite right. I already had that thought when I was redefining 64 characters, but I wasn't ready to make anything quite so big at the time. I also figured I had enough knowledge to just experiment my way through it, which was true up to a point. Once I hit that mental block, I had to reach out again. It's incredible how accurate and quick the responses are. This is an incredible place. I'm truly building off the backs of giants.

Once again, I'll be practicing and making a bunch of things with my new found knowledge. I'm sure I'll get to another mental block soon enough, but one thing at a time. Each time I learn something new, there are so many ways to implement it and I want to really understand and practice it all the way before I add something new to the mix.

Thanks for all the help.
Post Reply