Page 2 of 3

Re: How to use redefined characters in CC65

Posted: Tue Aug 22, 2017 3:24 pm
by beamrider
I didn't forget RAM1 but had nothing to put in it..

You will need to split your code between MAIN and RAM1 (as the UDCs sit in between).

Move some of your functions into another file and specify the segment at the top, eg

Code: Select all

#pragma codeseg ("RAM1CODE")
then add it to the cfg file in the SEGMENTS secion..

Code: Select all

RAM1CODE:     load = RAM1,     type = ro;
of course you will need to compile and link it which would be better done with a MAKE file, but that's another topic...

Re: How to use redefined characters in CC65

Posted: Tue Aug 22, 2017 4:00 pm
by plbyrd
Oliver Schmidt's universal makefile for cc65 is just about perfection.

https://github.com/cc65/wiki/wiki/Bigger-Projects

Re: How to use redefined characters in CC65

Posted: Tue Aug 22, 2017 4:03 pm
by Linzino
Thanks a lot!
I am trying to understand more now how the CFG works.

I did not know that one should use pragmas to specify the segment.
I thought it was done automatically by the linker.

So, I need to figure out which part of the code should go to which segment.
I guess I can do this by looking at the size of the object files.

Re: How to use redefined characters in CC65

Posted: Tue Aug 22, 2017 4:06 pm
by plbyrd
Linzino wrote:Thanks a lot!
I am trying to understand more now how the CFG works.

I did not know that one should use pragmas to specify the segment.
I thought it was done automatically by the linker.

So, I need to figure out which part of the code should go to which segment.
I guess I can do this by looking at the size of the object files.
Well, the linker is pretty good at that. The reason to put code in a specific spot is for applications that do banking. Putting concise, shared pieces of code in an appropriately sized chunk of RAM is a big help and one of the great features of the linker in cc65.

Re: How to use redefined characters in CC65

Posted: Tue Aug 22, 2017 5:28 pm
by Linzino
The goal of my personal project is to write a little fun game for nearly all 8 bit computers (+ TI/994a which technically is 16 bit)

Whatever makefile solution I decide to use,
should work with CC65 (6502), SDCC (Z80), ZSDCC (Z80), SCCZ80 (Z80) and CMOC (6809), GCC for TI (TMS9900), C99C (TMS9900).

For the moment I am only compiling with CC65 (6502), ZSDCC (Z80), SCCZ80 (Z80).

Re: How to use redefined characters in CC65

Posted: Tue Aug 22, 2017 6:01 pm
by plbyrd
Linzino wrote:The goal of my personal project is to write a little fun game for nearly all 8 bit computers (+ TI/994a which technically is 16 bit)

Whatever makefile solution I decide to use,
should work with CC65 (6502), SDCC (Z80), ZSDCC (Z80), SCCZ80 (Z80) and CMOC (6809), GCC for TI (TMS9900), C99C (TMS9900).

For the moment I am only compiling with CC65 (6502), ZSDCC (Z80), SCCZ80 (Z80).
I don't think you'll find an out-of-the-box Makefile, but you can definitely make one. (see what I did there?)

Re: How to use redefined characters in CC65

Posted: Wed Aug 23, 2017 12:20 am
by beamrider
Linzino wrote: The reason to put code in a specific spot is for applications that do banking. Putting concise, shared pieces of code in an appropriately sized chunk of RAM is a big help and one of the great features of the linker in cc65.
Not only banking, but anywhere a non-contiguous memory layout is required or where specific segments must reside at specific memory locations (i.e. vic-20).

Linzino wrote:So, I need to figure out which part of the code should go to which segment.
I guess I can do this by looking at the size of the object files.
The linker will tell you if you overflow and by how much. You can look at the segment list in the .map file to see segments which can be rearranged to fill any gaps

Code: Select all

Segment list:
-------------
Name                   Start     End    Size  Align
----------------------------------------------------
ZEROPAGE              000002  00001B  00001A  00001
LOADADDR              0011FF  001200  000002  00001
EXEHDR                001201  00120C  00000C  00001
STARTUP               00120D  001246  00003A  00001
ONCE                  001247  001252  00000C  00001
CODE                  001253  0013FB  0001A9  00001
RODATA                0013FC  00140F  000014  00001
DATA                  001410  001438  000029  00001
INIT                  001439  001452  00001A  00001
BSS                   001453  001453  000001  00001
UDCCHAR               001C00  001C17  000018  00001

Re: How to use redefined characters in CC65

Posted: Thu Dec 21, 2017 8:17 am
by Linzino
I have (almost) been able to add UDG to the Vic 20 versions by using a slightly modified version of @beamrider's CFG for the Vic20 + 8k and Vic20 + 16k versions of my game.

What is broken when using this configutation is that the stack is placed somewhere in memory where it conflicts with graphics memory. Some characters are corrupted as if code or the stack itself were lying on the graphics memory area.

I have never had any such problem with the default cfg's because the stack position in those cases is somehow implied.
This is no longer the case and I need to place the stack (a very small you) where it causes no harm.

My cfg is:

SYMBOLS {
__LOADADDR__: type = import;
__EXEHDR__: type = import;
__STACKSIZE__: type = weak, value = $0104; # 256 byte stack
}
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;
CHARMEM: file = %O, start = $1C00, size = $0400, type = rw, define = yes, fill = yes;
RAM1: file = %O, start = $2000, size = $4000, 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 = MAIN, type = bss;
BSS: load = MAIN, type = bss, define = yes;
UDCCHAR: load = CHARMEM, type = ro, define = yes, optional = no;
}
FEATURES {...
...

where value = $0104; is a value that, by chance, seems to place the stack at a location where no immediate disaster is visible on the screen but it is clearly not a solution (just a hack).

If I use
MAIN: file = %O, define = yes, start = $120D, fill = yes, size = $1C00 - $120D - __STACKSIZE__;

then the game compiles but does not even start.

Re: How to use redefined characters in CC65

Posted: Thu Dec 21, 2017 5:07 pm
by Linzino
Hi everyone,

I could figure out what was wrong in the cfg... I had a hole where the stack is supposed to be. This has been fixed with the DUMMY memory area:
"
...
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, size = __STACKSIZE__, fill = yes;
CHARMEM: file = %O, start = $1C00, size = $0400, type = rw, define = yes, fill = yes;
RAM1: file = %O, start = $2000, size = $4000, type = rw;
}
...
"

Now my little game looks even better!

Re: How to use redefined characters in CC65

Posted: Sat Dec 23, 2017 6:36 am
by pixel
How about something like this for convenience?:

Code: Select all

MEMORY {
	ZP: file = "", define = yes, start = $0002, size = $001A;
	LOADADDR: file = %O, start = $11FF, size = $0002;
	HEADER: file = %O, start = $1201, size = $000C;
	SCREEN: start = $1000, size = $0200;
	EXTRAHEAP: file = %O, start = $1200, size = $0100, type = rw, define = yes, fill = yes;
	CHARMEM: file = %O, start = $1300, size = $0400, type = rw, define = yes, fill = yes;
	MAIN: file = %O, define = yes, start = $1700, fill = yes, size = $4900 - __STACKSIZE__;
}
You could even add the EXTRAHEAP for malloc() like this:

Code: Select all

	_heapadd ((void *) 0x1200, 0x100);

Re: How to use redefined characters in CC65

Posted: Wed Jan 30, 2019 2:19 am
by Mozartkügel
@beamrider Thanks for sharing the template! I got a small beginning of a game up and running with it over the last couple of weeks (yay!) I'm not such a technical person but I'm slowly learning more about C64/Vic-20/C16/Plus4 programming, and I love it! :D

Re: How to use redefined characters in CC65

Posted: Sun Apr 21, 2019 5:10 pm
by Mozartkügel
Hi guys, I wanted to have 256 user defined characters instead of 128 using beamriders template / 16k cfg, so I tried to make CHARMEM $0800 instead of $0400 in the cfg file, but then I realized VIC can only see the chars if they're in the internal memory. It seems the cfg is set up exactly for 128 characters since everything above that spills over above $2000.

I don't understand how to make MAIN memory smaller in the cfg to fit 2K of chars i.e. 256 chars "in a row" in internal memory. Is it possible to move over some of these: STARTUP, LOWCODE, ONCE, RODATA, INIT or BSS from MAIN to RAM1 and then check the map file how much memory I can remove/save from MAIN? Or are those stuff that also always need to be in internal memory? I moved CODE and DATA segments to RAM1 earlier and that seems to be working fine.

Code: Select all

# Memory configuration for the VIC-20 with 16K RAM Cartridge
# Contributed by Stefan Haubenthal
SYMBOLS {
    __LOADADDR__:  type = import;
    __EXEHDR__:    type = import;
    __STACKSIZE__: type = weak, value = $0100; # 256 byte stack
}
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;
    CHARMEM:  file = %O, start = $1C00, size = $0400, type = rw,  define = yes, fill = yes;
    RAM1: 	  file = %O, start = $2000, size = $4000, type = rw, define = yes;}

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 = RAM1,     type = rw;
    INIT:     load = MAIN,     type = bss;
    BSS:      load = MAIN,     type = bss, define   = yes;
    UDCCHAR:  load = CHARMEM,  type = ro, define = yes, optional = no;
}
Any help or pointing me in the right direction appreciated!

Re: How to use redefined characters in CC65

Posted: Tue Apr 23, 2019 12:13 pm
by beamrider
From memory, I think you just need to change $1C00 to $1800 and size of CHARMEM to $0800

Code: Select all

    
    MAIN:     file = %O, define = yes, start = $120D, fill = yes, size = $1800 - $120D;
    CHARMEM:  file = %O, start = $1800, size = $0800, type = rw,  define = yes, fill = yes;
    RAM1:      file = %O, start = $2000, size = $4000, type = rw, define = yes;

Re: How to use redefined characters in CC65

Posted: Wed Apr 24, 2019 4:18 am
by Mozartkügel
beamrider wrote:From memory, I think you just need to change $1C00 to $1800 and size of CHARMEM to $0800

Code: Select all

    
    MAIN:     file = %O, define = yes, start = $120D, fill = yes, size = $1800 - $120D;
    CHARMEM:  file = %O, start = $1800, size = $0800, type = rw,  define = yes, fill = yes;
    RAM1:      file = %O, start = $2000, size = $4000, type = rw, define = yes;
I thought I tried that already! :oops: However big thanks for helping out again! It does compile and start the game now, but the screen is empty (I can hear the sfx when I run around in the game), I was thinking that maybe the characters got "displaced". I tried and tried to find the issue last night but couldn't pinpoint it. If I make the charmem size $0600 and main size to $1600 - $120D instead I can see some of my characters on the screen (but the wrong ones).

I stared thinking maybe this code snippet from the sample is the issue, if it initializes the char memory for 128 chars and not for 256 chars. Unfortunately I can't understand the code at all. :oops: I googled so apparently tilde inverts the bits but I still have no idea what this code does. I tried looking for clues in the cc65 folder and in vic20.h what VIC.addr would be doing but to no avail. Sorry for not being such a knowledgeable programmer, but getting the "base"/code-template down the first time around for a new system is always the hardest.

Code: Select all

    //    Initialise character memory for 128 chars at $1C00 as per config file
    tmp = ~0x0F & PEEK(&(VIC.addr));
    POKE(&(VIC.addr), tmp | 0x0F);
Super thankful for any further help!

Re: How to use redefined characters in CC65

Posted: Wed Apr 24, 2019 5:22 am
by beamrider
I think with chars at $1800, that 0x0F needs to be 0x0E

Code: Select all

    //    Initialise character memory for 256 chars at $1800 as per config file
    tmp = ~0x0E & PEEK(&(VIC.addr));
    POKE(&(VIC.addr), tmp | 0x0E);