Reading Colour RAM

Basic and Machine Language

Moderator: Moderators

Post Reply
SparkyNZ
Vic 20 Enthusiast
Posts: 192
Joined: Tue Jan 18, 2011 2:23 am

Reading Colour RAM

Post by SparkyNZ »

I've noticed that if I try to do a PEEK(38400), I don't always get the actual colour value back - and I see the same thing in VICE (unexpanded Vic).

When the kernel scrolls the screen up (as it would during a LIST for example), I assume that the the kernel must read the colour RAM in order to move the colour codes up the screen.

What is needed in order to read the colour RAM correctly - and what causes the changing values that I see at 38400?
User avatar
Wilson
Vic 20 Devotee
Posts: 252
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Re: Reading Colour RAM

Post by Wilson »

The color RAM is only 4-bit. What you read on the upper 4 bits will just be garbage on the bus.
You need to AND your read value with $0f to get the actual contents of the memory between $9400-$9800.
SparkyNZ
Vic 20 Enthusiast
Posts: 192
Joined: Tue Jan 18, 2011 2:23 am

Re: Reading Colour RAM

Post by SparkyNZ »

Wilson wrote: Mon May 05, 2025 4:39 pm The color RAM is only 4-bit. What you read on the upper 4 bits will just be garbage on the bus.
You need to AND your read value with $0f to get the actual contents of the memory between $9400-$9800.
Oh, is it that simple? Hehe. Of course - that makes perfect sense now. Thanks for that :-)
User avatar
Orangeman96
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 16, 2024 3:42 pm
Location: U.S.A.

Re: Reading Colour RAM

Post by Orangeman96 »

Wilson wrote: Mon May 05, 2025 4:39 pm The color RAM is only 4-bit. What you read on the upper 4 bits will just be garbage on the bus.
You need to AND your read value with $0f to get the actual contents of the memory between $9400-$9800.
So is the high nybble is always garbage on the bus between $9400-$9800 / 37888-38912? -OGM
User avatar
AndyH
Vic 20 Afficionado
Posts: 442
Joined: Thu Jun 17, 2004 5:51 am
Website: https://www.hewco.uk
Location: UK
Occupation: Developer

Re: Reading Colour RAM

Post by AndyH »

Yes, those bits are just not available.

It can be used for storing data within these limitations for the range that's spare. On Emu's Massive Hunt I use it to store 4 flags per screen to determine what objects you've collected on that screen.
--
AndyH
HEWCO | Vic 20 blog
SparkyNZ
Vic 20 Enthusiast
Posts: 192
Joined: Tue Jan 18, 2011 2:23 am

Re: Reading Colour RAM

Post by SparkyNZ »

AndyH wrote: Wed May 07, 2025 4:54 pm Yes, those bits are just not available.

It can be used for storing data within these limitations for the range that's spare. On Emu's Massive Hunt I use it to store 4 flags per screen to determine what objects you've collected on that screen.
So whereabouts do your 4 bits actually get written to? The colour RAM chips are only 4bits wide I believe - so where do the other 4bits go if you're writing to $9600 for example?
User avatar
AndyH
Vic 20 Afficionado
Posts: 442
Joined: Thu Jun 17, 2004 5:51 am
Website: https://www.hewco.uk
Location: UK
Occupation: Developer

Re: Reading Colour RAM

Post by AndyH »

Depending where your screen is set, either $9400 or $9600 will be free to use (the lower 4 bits).
--
AndyH
HEWCO | Vic 20 blog
SparkyNZ
Vic 20 Enthusiast
Posts: 192
Joined: Tue Jan 18, 2011 2:23 am

Re: Reading Colour RAM

Post by SparkyNZ »

AndyH wrote: Wed May 07, 2025 5:40 pm Depending where your screen is set, either $9400 or $9600 will be free to use (the lower 4 bits).
Oh sorry, I thought you were meaning that the upper 4 bits could be used to store additional 4 bits of data.
User avatar
Orangeman96
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 16, 2024 3:42 pm
Location: U.S.A.

Re: Reading Colour RAM

Post by Orangeman96 »

AndyH wrote: Wed May 07, 2025 5:40 pm Depending where your screen is set, either $9400 or $9600 will be free to use (the lower 4 bits).
So its only two low nybbles then, AndyH: the low nybble of $9400 (four bits) and the low nybble of $9600 (four bits)? -OGM
SparkyNZ
Vic 20 Enthusiast
Posts: 192
Joined: Tue Jan 18, 2011 2:23 am

Re: Reading Colour RAM

Post by SparkyNZ »

Orangeman96 wrote: Wed May 07, 2025 6:46 pm So its only two low nybbles then, AndyH: the low nybble of $9400 (four bits) and the low nybble of $9600 (four bits)? -OGM
I'm pretty sure the read of $9600 on an unexpanded Vic reads the same physical chip and location as $9400 does with 8K RAM expansion. In other words the address mapping changes when the 8K RAM is present, but the Vic chip is always accessing the same colour RAM chip locations in both cases.

If we had a screen that was smaller than the full colour RAM that is available, then we could use the unused colour RAM 4-bit locations that are at the end of the screen space. Maybe that's the bit I didn't get.
User avatar
Orangeman96
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 16, 2024 3:42 pm
Location: U.S.A.

Re: Reading Colour RAM

Post by Orangeman96 »

SparkyNZ wrote: Wed May 07, 2025 7:15 pm
I'm pretty sure the read of $9600 on an unexpanded Vic reads the same physical chip and location as $9400 does with 8K RAM expansion. In other words the address mapping changes when the 8K RAM is present, but the Vic chip is always accessing the same colour RAM chip locations in both cases.

If we had a screen that was smaller than the full colour RAM that is available, then we could use the unused colour RAM 4-bit locations that are at the end of the screen space. Maybe that's the bit I didn't get.
Gotcha, Sparky, I was just trying to ascertain how many half-byte locations were acutally in-play/meaningfully-usable. -OGM
SparkyNZ
Vic 20 Enthusiast
Posts: 192
Joined: Tue Jan 18, 2011 2:23 am

Re: Reading Colour RAM

Post by SparkyNZ »

Orangeman96 wrote: Wed May 07, 2025 8:37 pm Gotcha, Sparky, I was just trying to ascertain how many half-byte locations were acutally in-play/meaningfully-usable. -OGM
If its 4-bit x 1K.. For a default screen size of 22x23, that would be 506 nybbles.. so I guess 1024 - 506 nybbles free?

Hehe. This is all quite fun and hacky - I would never have thought about using the colour RAM for additional memory :-)
User avatar
AndyH
Vic 20 Afficionado
Posts: 442
Joined: Thu Jun 17, 2004 5:51 am
Website: https://www.hewco.uk
Location: UK
Occupation: Developer

Re: Reading Colour RAM

Post by AndyH »

Colour memory, with only lower 4 bits wired up are between $9400 and $97ff.

Mapping the Vic describes the memory range as bits 7-4 = not there, bit 3 = multicolour, bits 0-2 = foreground colour.

Bit 7 of $9002 affects the location of screen memory (along with $9005) but more importantly it also defines if colour memory starts at $9400 or $9600.

So for Emu I use the unused colour space for my screen item flags. Only lower nybble is usable.

In another game, Bluevolution, I use the spare colour ram for my meteor bits, like a double buffer. Again only the lower 4 bits used.
Last edited by AndyH on Thu May 08, 2025 1:38 am, edited 1 time in total.
--
AndyH
HEWCO | Vic 20 blog
User avatar
Mike
Herr VC
Posts: 5134
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Reading Colour RAM

Post by Mike »

So much for the rumours, here are the facts: https://sleepingelephant.com/ipw-web/bu ... 1&start=22
User avatar
Orangeman96
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 16, 2024 3:42 pm
Location: U.S.A.

Re: Reading Colour RAM

Post by Orangeman96 »

Mike wrote: Thu May 08, 2025 1:17 am So much for the rumours, here are the facts: https://sleepingelephant.com/ipw-web/bu ... 1&start=22
Vielen Dank, Herr VC! :mrgreen: -OGM

(mod: unnecessary full quote of linked-to posting removed)
Post Reply