Unexpanded VIC 20 Memory

Basic and Machine Language

Moderator: Moderators

Post Reply
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Unexpanded VIC 20 Memory

Post by Legacy »

So now comes chapter 3 Machine Language Programming :

We all know the Unexpanded Vic 20 has 5120 Bytes of memory
and 3583 Bytes of this is free. I'm having a problem with figuring out how much space is allocated for RAM, how much for ROM, how many chips are inside the machine, etc, and the actual conversion from Hex memory locations to Decimal.
According to the manual the vic has 256 pages of memory with 256 locations on each page or 65535 total locations, what I don't understand is , how the 65535 locations are contained within 5120 bytes of memory. What kind of conversion is going on here? Also it says 6502 uses 2 bytes to form an address ok so 2 bytes is 16 bits, say my address is 7168, would that be formed into hexadecimal $1C00, how many bytes are there total in 7168 address?
I just don't get how we can POKE a location like 36878 when 5120 is available. There's some basic concept I'm missing here, I've read an re-read the book with no comprehension unfortunately. We know a system has 2 types of memory, ROM/RAM, the ROM cannot be changed but the RAM can. Would someone mind giving me an overview or Vic-20 guide to Memory for Dummies Manual ? I'm having a hard time discerning the differences between the two, how the processor handles them, what is stored on each, the size of the actual chips,and the conversion of hex/decimal address location, among others.
If Active ram is address 4096 - 7679 that is only 3583 bytes ..... so 1 byte = 1 address location? That's still only 3583, not 65535... Having a hard time seeing the big picture here, can someone please shed some insight on my dilemma I'd really like to understand what it is their explaining. Thank You - Legacy
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

Im looking at the chart here for VIC 20 MEMORY LOCATIONS, i just dont get how 5120 = 65535
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Re: Unexpanded VIC 20 Memory

Post by tlr »

Legacy wrote:...what I don't understand is , how the 65535 locations are contained within 5120 bytes of memory.
It's the other way around: the 5120 bytes of memory are contained within the 65536 locations.
The VIC20 has 5120 bytes of RAM, but there are other locations mapped to ROM, I/O chips, color memory...
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

Just out of the chips on the unexpanded Ive already counted 12k, so how come theres not 12000 bytes free but only 3853? Or are we only counting the 1k from 0-1023, 3.5k 4096-7679, and .5k of screen ram, that would give us 5120, still theres a whole lot of other stuff i dont get, are all those other chips ROM? vic chip, character rom, color RAM and I/O blocks... Im starting to see a little bit now how we can call from ROM to RAM todo something like POKE a color code onto a specific screen location.
6502dude
megacart
Posts: 1581
Joined: Wed Dec 01, 2004 9:53 am

Post by 6502dude »

Legacy wrote:Im looking at the chart here for VIC 20 MEMORY LOCATIONS, i just dont get how 5120 = 65535
It may be helpful o look a a Vic-20 memory map:
http://www.zimmers.net/cbmpics/cbm/vic/memorymap.txt

The first 1024 bytes 0000-03FF (of the 5120 RAM bytes) are used by Vic-20 for various configuration settings, tape buffer, temp working space for 6502, etc.
Depending on what ML program you create and how much it uses other parts of Vic-20 (ie. RS-232 routines, cassette drive, etc), you can actually use most of the RAM above the first 256bytes (referred to as zero page).

The next 3583 bytes 1000-1DFF (of 5120 RAM bytes) is designated as Basic RAM, but this space can easily be used ML programs.

The final 512 byes 1E00-1FFF (of 5120 RAM bytes) is assigned to video display memory. If you blank display, turn off monitor, or don't mind seeing "junk" on your screen, you can use these bytes as well for your ML program.
Image Mega-Cart: the ultimate cartridge for your Commodore Vic-20
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

Legacy wrote:Just out of the chips on the unexpanded Ive already counted 12k, so how come theres not 12000 bytes free but only 3853? Or are we only counting the 1k from 0-1023, 3.5k 4096-7679, and .5k of screen ram, that would give us 5120, still theres a whole lot of other stuff i dont get, are all those other chips ROM? vic chip, character rom, color RAM and I/O blocks... Im starting to see a little bit now how we can call from ROM to RAM todo something like POKE a color code onto a specific screen location.
The ROMs can hardly be considered free but there is 20Kbyte of ROM in the VIC20.
The color RAM is indeed an additional 512 bytes of RAM. It is only 1024 * 4-bit wide though, so it cannot be used freely.
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

5120 x 8 = 40960

65535-40960 = 24575 this must account for the 3 RAM/ROM expansions
(8k = 24575) we are not using so each POKE essentialy equals one bit?

Now I see, but why'd they throw that color RAM in the middle of the ROM
they should have just added it after screen RAM at address 8192. So
what we are doing is when writing a BASIC program from RAM, we are calling bits of DATA from specific ROM chips such as the VIC ROM chip for sound that has sound producing data stored on it, 6502 pulls it out and makes it run/work . So these locations ALREADY exist in the machine, we can't change them, but we can access them to utilize in our own compilations.

The part I'm not understanding now is how can we use 2 BYTES for each
address when we've just established one address = 1 bit, or maybe I have that wrong...
shem
Vic 20 Enthusiast
Posts: 197
Joined: Sun Sep 17, 2006 6:52 am

Post by shem »

Yes you cant use the roms but you can use the rem which they are copied to
as the vic starts up the roms eg basic is copied into ram so if you are coding in ML you can use that ram as you dont need basic you can do the same for the charecter rom also if you are writing a game you dont need the vic's fonts well the ones you need you can always copy into ram thus freeing up more space for ML
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

Legacy wrote:The part I'm not understanding now is how can we use 2 BYTES for each
address when we've just established one address = 1 bit, or maybe I have that wrong...
You've got it mixed up.
The size of the data in a location is 8-bits. The address to find such a location is 16-bits.
POKE addr, data
data = PEEK( addr )
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

Very useful ways of freeing up memory, that seems to be the common theme here ,writing ML programs in the 3583 bytes and maybe use some of zero page and character ROM space which I have already dealt with a little...

What was misleading was when the book said we have 256 pages with 256 locations on each page giving us 65535 locations, if your working with an unexpanaded vic you really only have 160 pages with 256 locations on each page giving you 40960 total locations or bits.

also, for example we will use zero page: 0 - 1023 , $0000 - $03FF , 1024 bytes now the book says there are 256 locations on this page, how is that 256 locations evenly distributed among 1024 bytes or are we talking about - 1024 x 8 = 8192 bits / 256 = 32 bits , so each location contains 32 bits?

tlr - dont understand that 16/8 bit address/data scheme
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

Legacy wrote:What was misleading was when the book said we have 256 pages with 256 locations on each page giving us 65535 locations, if your working with an unexpanaded vic you really only have 160 pages with 256 locations on each page giving you 40960 total locations or bits.
This is incorrect. A page is 256 bytes. The unexpanded VIC has ~20 pages of RAM using this terminology.
Legacy wrote:also, for example we will use zero page: 0 - 1023 , $0000 - $03FF , 1024 bytes now the book says there are 256 locations on this page, how is that 256 locations evenly distributed among 1024 bytes or are we talking about - 1024 x 8 = 8192 bits / 256 = 32 bits , so each location contains 32 bits?
Zero page is $0000-$00ff. 256 bytes, i.e 256 * 8 bits.
Legacy wrote:tlr - dont understand that 16/8 bit address/data scheme
The smallest unit you can address is a byte, not a bit. A byte is a data unit consisting of 8-bits.
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

gotcha- thanks m8 :D - but I highly doubt I'm a master now as my Title suggests :D
Legacy
Vic 20 Enthusiast
Posts: 154
Joined: Wed Dec 31, 2008 4:01 pm

Post by Legacy »

6402Dude:The first 1024 bytes 0000-03FF (of the 5120 RAM bytes) are used by Vic-20 for various configuration settings, tape buffer, temp working space for 6502, etc.

As 6502 said, that is throwin me off too cause tlr is saying first page is 0000-00FF and 6502Dude is saying 0000-03FF.

So I guess what really matters is , every 256 bytes is a page and the vic has 65535 bytes or 64K , maybe its really a Commodore 64 in disguise!
zutman
Vic 20 Newbie
Posts: 15
Joined: Mon Sep 22, 2008 5:37 am

Post by zutman »

Legacy wrote:So I guess what really matters is , every 256 bytes is a page and the vic has 65535 bytes or 64K , maybe its really a Commodore 64 in disguise!
You better compare them the other way round: a C64 is a souped up VIC-20. :)
Richard James
Vic 20 Devotee
Posts: 269
Joined: Mon Feb 04, 2008 6:06 am

Post by Richard James »

The 6502 has an 8bit data bus and registers and a 16bit address bus and registers. Thus it can read and write 8bits at a time, and access up to 16bits of memory. 16bits of memory gives 2^16 or 65535 locations each is 8bit or 1 Byte due to the 8bit data bus. So the processor can read/write 65535Bytes of memory or 64KBytes.

This 64KByte Address space is divided up into RAM, ROM, I/O and expansion areas. The division is done through what is called mapping. Each chip RAM, ROM, I/O chip is mapped to a different address space.

Basically when the 6502 requests data or writes data it sends out a 16bit address and the Logic circuits in the VIC20 decide what chip is addressed and then the chip takes the lower address bits and determines what memory to return.

For instance a RAM chip might be selected by 3bits of address memory and then the remaining 16-3 = 13bits is mapped onto the memory giving 13bits of address or 2^13 = 8192 data words or 8KBytes.

There are of course gaps in the memory address space for expansion. So the memory is not contiguous, so there is a gap between the end of low memory and the start of BASIC memory, of a size of 3Kbytes. Low memory is from $0000 to $03FF which includes Zero Page which is $0000 to $00FF. Each page is only 256Bytes or $00 - $FF in range. So in Low memory there are 4 pages. $0000 - $00FF, $0100 - $01FF, $0200 - $02FF and $0300 to $03FF.

So there is memory between $0000 - $03FF then there is a gap for the 3Kbyte expansion RAM and then BASIC memory goes between $1000 - $1DFF and then there is 512Bytes for the screen. $1E00 to $1FFF. Then there are gaps for more expansion RAM/ROM etc.

Zero Page is important because 6502 opcodes (commands) are smaller and faster when accessing it. There is memory just beyond it as I have stated above.
Change is inevitable except from a vending machine.
Post Reply