Skip to the content
2 layers20.5 × 53 mmR6522decode, the printed circuit board in 3D

A RAM expansion to make your VIC-20 memory map more sensible

Size
20.5 × 53 mm
Copper layers
2
Thickness
1.6 mm
Parts
4
Nets
42
Pads
87
Tracks, vias
106, 0
Routed
Yes
KiCad
KiCad 5 (file 20171130)
Created
11 Sep 2021
Updated
22 Sep 2021

Overview

R6522decode is an open-source printed circuit board by hansliss, from the hansliss/SensibleRAM repository on GitHub. It is a 2-layer board of 20.5 × 53 mm with 4 parts on 42 nets, routed with 106 tracks and 0 vias.

It is built around the SN74LVC1G02DBVR. Its parts include 3 ICs and 1 connector.

Main components

1

README

README.md

SensibleRAM

NOTE: This doesn't currently work in a real VIC-20, since the address decoding for the VIA chips is incomplete, so they collide with this memory! I'm testing another patch to take care of that problem.

A RAM expansion to make your VIC-20 more sensible

This is actually how the VIC-20 should have been designed in the first place, hence the name SensibleRAM. It would have saved us all some headaches back in the day.

You may already know that there are many different cool modern memory expansion cartridges for the VIC-20 nowadays, providing up to 35-37kB of expansion memory. Some of that memory can benefit from this hack if you are using BASIC, whilst some of it is not relevant here. The aim here is to provide BASIC with as much memory as possible, regardless of what memory expansions you have.

Before you spend a lot of time on this, please be aware that this is anachronistic nerdery of the highest degree. What this does would have been really cool in 1981. Forty years later, in 2021, not so much.

Note that this hardware is as yet untested. The software has been tested in a patched VICE, however. Once I receive the boards and can test it properly, I'll update this and add some photos.

Background

The VIC-20 has a somewhat confusing memory map. It comes with 5kB of system RAM as standard, with 1k at the bottom of the memory map, and 4k at $1000. To BASIC, those upper 4k are available as working memory, minus 0.5k that is used by the system for screen memory.

Normally, the screen memory is located at $1E00, so BASIC memory is $1000-$1DFF which is 3584 bytes. One byte is always consumed by BASIC, so the computer reports 3583 bytes free.

If you add a 3k RAM expansion, it will be located at $0400-0FFF, and the available space increases to 6655 bytes.

If you add larger expansions, they will start att BLK1 at $2000 and expand upwards until they reach $7FFF. However, when this happens, the screen memory becomes a problem, since at $1E00, it will split the system RAM in two non-contiguous parts. That won't do, so the screen memory is moved to $1000 if you add memory to BLK1, and all the memory between $1200 and $7FFF becomes usable to BASIC.

However, with one of those larger expansions in place, any 3k memory at $0400 becomes unusable to BASIC, since it ends up outside the contiguous area.

All this has two negative effects on the system:

  1. The screen memory placement at either $1E00 or $1000 precludes any chance of getting contiguous memory between $0400 and $7FFF
  2. the screen memory eats up 512 bytes that could have been used as BASIC memory.

The hardware

The reason that the screen memory is located in one of those places as opposed to $0400 or $7E00 is the way the VIC chip is wired into the system. The screen memory has to be shared between the CPU and the VIC, and the VIC can only address 16k of memory.

The way this has been handled is that the VIC chip shares two different blocks with the CPU, BLK0 and BLK4. The VIC chip has 14 address bits. VA0-VA12 are connected via a tri-state buffer (controlled by a clock pin, but let's leave bus sharing out of this) to the CPU's CA0-CA12, but the most significant bit VA13 is connected to the active-low block selector /BLK4. This means that what the CPU sees as $0000-$1FFF, the VIC sees as $2000-$3FFF, and what the CPU sees as $8000-$9FFF is $0000-1FFF to the VIC.

There's also a mechanism explicitly blocking the VIC chip from sharing some areas with the CPU. Those include the three RAM blocks RAM[1-3] at $0400, the main expansion and ROM blocks BLK[1,2,3,5,6,7] (which have to be blocked since the VIC chip can't address them), and the two auxiliary I/O areas I/O2 and I/O3, located within BLK4. On top of that, the expansions we talked about earlier are all cartridge expansions, so they are sitting on the CPU bus rather than the VIC bus, which means they are unavailable to the VIC anyway.

Conclusion

So, we're left with choosing an area within the interval $1000-$1FFF for the screen memory, since the first kB in BLK0 is used by the OS (although you can map the screen memory to the zero page, for a fun exercise), and BLK4, which is used only for the character ROM, the colour RAM and the I/O registers, doesn't have any available RAM.

Tough.

The fix

However, the I/O registers at I/O0 ($9000-$93FF) take up far less than the entire interval, with the highest register at $912F. This leaves $9200-$93FF entirely free, and this area is addressable to both the CPU and the VIC.

So, this project adds 512 bytes of RAM to $9200, and with the included programs you can move the screen memory to this area on your VIC, freeing up 512 bytes of BASIC RAM. If you have both 3k and 8k+ expansions, you can also add those 3k to your available BASIC RAM, for a whopping total win of 3500 bytes.

The included assembly program will try to move the screen memory and start/end memory pointers as correctly as possible regardless of what memory expansions are present, and will then reinitialize BASIC.

Here's a short BASIC program that does the same, but assumes you have expansions in RAM[1-3] and BLK[1-3]:

text
10pO36866,pE(36866)or128:pO36869,(pE(36869)and15)or(4*16)
20pO648,146:pO44,4:pO43,1:pO56,128:pO55,0:pO642,4
30pO641,0:pO644,128:pO643,0:pO1024,0:sys58232

The effects

Here are some examples of what happens when you use this with different expansions:

ExpansionOrig. free ramOrig max array sizeNew free RAMNew max array sizeRAM increase
None3583111940951289512
RAM[1-3]6655214371672313512
BLK1117753848122874021512
RAM[1-3],
BLK1
1177538481535950433584
BLK[1-2]199676581204796751512
RAM[1-3],
BLK[1-2]
1996765812355177743584
BLK[1-3]281599310286719480512
RAM[1-3],
BLK[1-3]
28159931031743105053584

The "max array size" fields come from an experiment I did, using the BASIC program testmem.bas that DIM'd string arrays of increasing size and filled them with strings, until no more memory was left. This program would have taken a week to run at the largest memory sizes, had I not run it in warp mode in VICE (see VICE_patching_notes.md).

The future

Feel free to build on this! One possible addition would be to add an I/O location at, say $91FF, that causes the character ROM to be detached from the CPU bus and replaced with RAM, for an additional 4k of available RAM at $8000 - $8FFF, which is within the contiguous section. This would increase free space to 35839 bytes. Since this design uses a 32k chip which is 99.4% wasted, this would be a noble use of some of the space.

Please let me know what you come up with, and let me know if you actually try this thing out.

Some technical notes without any explanatory text

text
bit 7 of $9002 controls A9 of screen memory and A9 of color memory
bit 4-7 of $9005 controls A10-A13 of VIC screen memory. A13 is /BLK4 to the CPU

$9200 = 1001 0010 0000 0000 = (VIC) b01001 000000000
$93FF = 1001 0011 1111 1111 = (VIC) b01001 111111111

!(A9 & A12 & !(A10 | A11 | A13))

A9:
$9002.7 = 1

A10-13:
$9005.4-7 = 0100

§1

Parts

4
QtyValueFootprintReferences
1Conn_01x01Pin_Headers:Pin_Header_Straight_1x01_Pitch2.54mmJ1
1R6522Housings_DIP:DIP-40_W15.24mmU2
1R6522_socketHousings_DIP:DIP-40_W15.24mmU1
1SN74LVC1G02DBVRTO_SOT_Packages_SMD:SOT-23-6_HandsolderingU3

More from hansliss/SensibleRAM

1
  • 2 layers42 × 55 mmSensibleRAM, the printed circuit board in 3D

    SensibleRAM

    hansliss/SensibleRAM

    A RAM expansion to make your VIC-20 memory map more sensible

    5 parts

Similar boards

  • 4 layers140 × 120 mmPianoMatrice, the printed circuit board in 3D

    PianoMatrice

    manvalan/MuonScope

    Piano di rivelazione MuonScope con 16 fotodiodi VBPW34S in matrice 4×4 a passo 10 mm, per il bus MIKILAB REV5.1.

    490 parts
  • 2 layers30 × 90 mmBrakes, the printed circuit board in 3D

    Brakes

    olin-electric-motorsports/olin-electric-motorsports

    OEM Monorepo

    92 parts14
  • 4 layers26.7 × 31.8 mmMag encoder, the printed circuit board in 3D

    Mag encoder

    frc971/electrical

    This repo contains the electrical files for the 971 FRC team. The files include PCBs and the electrical system diagrams. The PCBs are created using KiCad.

    23 parts3Apache-2.0
  • 2 layers18.5 × 26 mm24g2usb rp2350zero, the printed circuit board in 3D

    24g2usb rp2350zero

    joypad-ai/joypad-os

    Universal controller firmware for building adapters, dongles, and custom controllers.

    4 parts1.7kApache-2.0
  • 2 layers116 × 33 mm966595-1 and 963356-1, the printed circuit board in 3D

    966595-1 and 963356-1

    rusefi/rusefi

    rusefi - GPL internal combustion engine control unit

    4 parts1.2k
  • 2 layers19 × 18 mmDaughter board, the printed circuit board in 3D

    Daughter board

    hackclub/OnBoard

    💡 Join 1,000 teenagers and make your first PCB with a $100 grant!

    4 parts915
  • 2 layers24.8 × 24.8 mmNrf24 breakout, the printed circuit board in 3D

    Nrf24 breakout

    tardate/LittleArduinoProjects

    a collection of "Little Electronic & Arduino Projects", most involving electronics or an Arduino in one way or another!

    4 parts803MIT
  • 2 layers26 × 20 mmCap chain, the printed circuit board in 3D

    Cap chain

    drandyhaas/KiCadRoutingTools

    A set of Python/Rust tools to aid routing in KiCad

    4 parts744MIT

Questions

How big is the R6522decode PCB?

It measures 20.5 × 53 mm and has 2 copper layers, 1.6 mm thick.

What parts does the R6522decode use?

4 parts, built around the SN74LVC1G02DBVR. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the R6522decode KiCad files?

From the hansliss/SensibleRAM repository on GitHub, at the commit this page was made from: the board is PCBs/R6522decode/R6522decode.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the R6522decode design in my own project?

Its repository states no licence, so its author keeps all rights: ask hansliss before reusing the design.