How to use redefined characters in CC65

You need an actual VIC.

Moderator: Moderators

User avatar
beamrider
Vic 20 Nerd
Posts: 872
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: How to use redefined characters in CC65

Postby beamrider » Tue Aug 22, 2017 3:24 pm

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...

User avatar
plbyrd
Vic 20 Hobbyist
Posts: 118
Joined: Tue Jun 01, 2010 9:32 pm
Website: http://thesharp.ninja
Location: Clarksville, TN
Occupation: Software Engineer

Re: How to use redefined characters in CC65

Postby plbyrd » Tue Aug 22, 2017 4:00 pm

Oliver Schmidt's universal makefile for cc65 is just about perfection.

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

Linzino
Vic 20 Amateur
Posts: 53
Joined: Fri Nov 06, 2015 4:13 pm
Website: http://retrocomputingarchive.blogspot.fr/
Location: France

Re: How to use redefined characters in CC65

Postby Linzino » Tue Aug 22, 2017 4:03 pm

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.

User avatar
plbyrd
Vic 20 Hobbyist
Posts: 118
Joined: Tue Jun 01, 2010 9:32 pm
Website: http://thesharp.ninja
Location: Clarksville, TN
Occupation: Software Engineer

Re: How to use redefined characters in CC65

Postby plbyrd » Tue Aug 22, 2017 4:06 pm

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.

Linzino
Vic 20 Amateur
Posts: 53
Joined: Fri Nov 06, 2015 4:13 pm
Website: http://retrocomputingarchive.blogspot.fr/
Location: France

Re: How to use redefined characters in CC65

Postby Linzino » Tue Aug 22, 2017 5:28 pm

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).

User avatar
plbyrd
Vic 20 Hobbyist
Posts: 118
Joined: Tue Jun 01, 2010 9:32 pm
Website: http://thesharp.ninja
Location: Clarksville, TN
Occupation: Software Engineer

Re: How to use redefined characters in CC65

Postby plbyrd » Tue Aug 22, 2017 6:01 pm

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?)

User avatar
beamrider
Vic 20 Nerd
Posts: 872
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: How to use redefined characters in CC65

Postby beamrider » Wed Aug 23, 2017 12:20 am

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

Linzino
Vic 20 Amateur
Posts: 53
Joined: Fri Nov 06, 2015 4:13 pm
Website: http://retrocomputingarchive.blogspot.fr/
Location: France

Re: How to use redefined characters in CC65

Postby Linzino » Thu Dec 21, 2017 8:17 am

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.

Linzino
Vic 20 Amateur
Posts: 53
Joined: Fri Nov 06, 2015 4:13 pm
Website: http://retrocomputingarchive.blogspot.fr/
Location: France

Re: How to use redefined characters in CC65

Postby Linzino » Thu Dec 21, 2017 5:07 pm

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!
Attachments
Vic20UDG5.jpg

User avatar
pixel
Vic 20 Nerd
Posts: 913
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/pixel/
Location: various
Occupation: Pan–galactic shaman

Re: How to use redefined characters in CC65

Postby pixel » Sat Dec 23, 2017 6:36 am

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);
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose


Return to “Emulation and Cross Development”

Who is online

Users browsing this forum: No registered users and 1 guest