Vic 20 +8k with less than 64 UDG

Basic and Machine Language

Moderator: Moderators

Post Reply
Linzino
Vic 20 Dabbler
Posts: 83
Joined: Fri Nov 06, 2015 4:13 pm
Website: http://retrocomputingarchive.blogspot.fr/
Location: France

Vic 20 +8k with less than 64 UDG

Post by Linzino »

Hi everyone,

I am trying to fit my game (https://github.com/Fabrizio-Caruso/CROSS-CHASE) into a Vic 20 +8k.
I only need a few UDG (between 10 and 15) and I want to use the minimum graphics memory.

I am using CC65 (and other devkits for other CPUs since my game is massively multitarget with more than 100 systems supported by the very same game code).

I initialize the graphics by setting $9005 to 0xFF. Maybe I am doing something wrong here... Any idea?

I am trying to have the UDG definitions at $1C00 and only take $200 (512) bytes. Is it a good idea?

The code is split in two areas (one starting at $120D and one starting at $1E00) as described below.

My linker cfg looks like

Code: Select all

...
MEMORY {
    ZP:       file = "", define = yes, start = $0002, size = $001A;
    SCREEN:   start =  $1000, size = $0200;
    LOADADDR: file = %O,               start = $11FF, size = $0002;
    HEADER:   file = %O,               start = $1201, size = $000C;
    MAIN:     file = %O, define = yes, start = $120D, fill = yes, size = $1C00 - $120D - __STACKSIZE__;
    DUMMY:    file = %O,               start = $1C00 - __STACKSIZE__ - 1, fill = yes, size = __STACKSIZE__;
    CHARMEM:  file = %O, start = $1C00, size = $0200, type = rw,  define = yes, fill = yes;
    RAM1: 	  file = %O, start = $1E00, size = $2200, type = rw;
}
SEGMENTS {
    ZEROPAGE: load = ZP,       type = zp;
    LOADADDR: load = LOADADDR, type = ro;
    EXEHDR:   load = HEADER,   type = ro;
    STARTUP:  load = MAIN,     type = ro;
    LOWCODE:  load = MAIN,     type = ro,  optional = yes;
    ONCE:     load = MAIN,     type = ro,  optional = yes;
    CODE:     load = RAM1,     type = ro;
    RODATA:   load = MAIN,     type = ro;
    DATA:     load = MAIN,     type = rw;
    INIT:     load = RAM1,     type = bss;
    BSS:      load = MAIN,     type = bss, define   = yes;
    UDCCHAR:  load = CHARMEM,  type = ro, define = yes, optional = no;
    CODE2:    load = MAIN,     type = ro;
}
...
but I when I run my game the screen is filled with garbadge, the game runs nevetherless but I only see the character colors change as if the screen memory were mapped somewhere else.

Who could give me a hand on this?

Fabrizio
User avatar
Mike
Herr VC
Posts: 4901
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Vic 20 +8k with less than 64 UDG

Post by Mike »

Writing $FF into $9005 sets the base address of the character generator to $1C00 and puts the text screen at $1C00 or $1E00, depending on bit 7 (value: 128) of $9002.
Linzino wrote:

Code: Select all

SCREEN:   start =  $1000, size = $0200;
[...]

I initialize the graphics by setting $9005 to 0xFF. Maybe I am doing something wrong here... Any idea?
This.

You want to write another value to $9005 so VIC still has the screen RAM at $1000, but reads the character definitions from $1C00. Please look up the VIC-I data sheet.
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic 20 +8k with less than 64 UDG

Post by Kakemoms »

Hi Linzino! A good resource for programmers is Compute Mapping the VIC which also has some examples. I find it a good book to find concrete answers to some of the programming issues one encounters. Check it out!
Linzino
Vic 20 Dabbler
Posts: 83
Joined: Fri Nov 06, 2015 4:13 pm
Website: http://retrocomputingarchive.blogspot.fr/
Location: France

Re: Vic 20 +8k with less than 64 UDG

Post by Linzino »

Thanks!

@Mike, thanks a lot!

What I really need is just to use very few UDG at the cheapest possible cost for memory (without doing super-complicated stuff).
I only need about 10 or 15 UDG for my game.

I wouldn't mind having the screen elsewhere.
User avatar
Mike
Herr VC
Posts: 4901
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Vic 20 +8k with less than 64 UDG

Post by Mike »

Linzino wrote:I wouldn't mind having the screen elsewhere.
There's no good reason to put the screen to somewhere else than $1000 with that RAM config (and with want you want to do).

Likewise, you'd want to keep the UDGs at $1C00, so you can use just a few characters beginning from $1C00, continue with code/data just behind those few characters, yet still are able to access the non-inverted character set in ROM by outputting reverse characters.
... (without doing super-complicated stuff) ...
Figuring out the correct value to put into $9005 to have the screen at $1000 and the character set at $1C00 is not exactly rocket science. Sorry.
Kakemoms
Vic 20 Nerd
Posts: 740
Joined: Sun Feb 15, 2015 8:45 am

Re: Vic 20 +8k with less than 64 UDG

Post by Kakemoms »

Linzino wrote:What I really need is just to use very few UDG at the cheapest possible cost for memory (without doing super-complicated stuff).
I only need about 10 or 15 UDG for my game.
Well, if you want to try some more complicated stuff, you could move the CHAR map to $0000 and use the available bytes in the tape buffer (around 828-1023). That will give you about 24 characters until you want to load something from tape again.

The complicated part about this is that you will have to switch to the normal CHAR rom again if you want to display normal text/numbers. E.g. you will need to wait for a certain scanline by doing:

Code: Select all

   ldx #30  ;Rasterline no*2
sync
   cpx $9004
   bne sync
Then switch to the CHAR map you need, then wait for another raster line location, then switch back again.

More complicated, but the most memory efficient if you want to preserve BASIC operation. If you need BASIC to work at the same time, you will need to set up an interrupt (look in the book I sent a link to).
Linzino
Vic 20 Dabbler
Posts: 83
Joined: Fri Nov 06, 2015 4:13 pm
Website: http://retrocomputingarchive.blogspot.fr/
Location: France

Re: Vic 20 +8k with less than 64 UDG

Post by Linzino »

Thanks everyone!

In my case Mike's suggested solution is the best because I am coding in C.

Probably setting $9005 to 192+15 should do it and place the characters at $1C00 and the screen memory at $1000. The character memory should just take up $0800 bytes.

Using the tape buffer would be cool but a bit too hard to do in C in a universal 8-bit project covering any 8-bit hardware with the same (meta)-code.

So far I have managed to fit my full game in the +8k configuration without graphics and I am pretty happy about the result.
The +16k has graphics and a few extra details. In both cases the game is fully enjoyable.
User avatar
Mike
Herr VC
Posts: 4901
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Vic 20 +8k with less than 64 UDG

Post by Mike »

Linzino wrote:The character memory should just take up $0800 bytes.
There's no need to waste 2048 bytes for your 10..15 UDGs!
Mike wrote:Likewise, you'd want to keep the UDGs at $1C00, so you can use just a few characters beginning from $1C00, continue with code/data just behind those few characters, yet still are able to access the non-inverted character set in ROM by outputting reverse characters.
That's a standard technique especially used with the unexpanded VIC-20 and also saving a lot of memory there.

The quoted paragraph rephrased: when you set the character generator to $1C00, the VIC chip "jumps" to $8000 after $1FFF and accesses the non-inverted upper-case charset when you use the screen codes 128..255. With the unexpanded VIC-20, the standard position of the screen at $1E00 overlaps with the screen codes 64..127, thus only the codes 0..63 are available for UDGs.

As I wrote, no-one forces you to use a full character set with 256 characters, and lay most of it waste. Put your UDGs at $1C00, use 80..120 bytes at this position, continue your program code right after the UDGs (at $1C50 or $1C78 or whatever) - and you can *still* use the non-inverted upper-case ROM characters for score display or whatever else, by using the screen codes 128..255.

And it's no 'super-complicated stuff' either.
funkheld
Vic 20 Devotee
Posts: 241
Joined: Tue Sep 10, 2019 4:23 am

Re: Vic 20 +8k with less than 64 UDG

Post by funkheld »

Hi good afternoon.
what should a vic20.cfg look like when I do this:
-----------------------------------------------------
30 poke 36869,192+13 : poke 36867,151
-----------------------------------------------------

and would like to start the program at memory:
start with sys8192.

thnaks
greeting
Post Reply