How to use redefined characters in CC65

You need an actual VIC.

Moderator: Moderators

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

How to use redefined characters in CC65

Postby Linzino » Mon Aug 21, 2017 2:55 pm

Hi everyone,

I need help for my cross-system game CROSS CHASE, which is written in ANSI C and compiled with CC65.
It supports most 8-bit computers including the Vic 20 (not all of them yey)
For the Vic 20 I have not been able to implement redefined characters.
One main problem is to understand how to configure CC65's linker.

I think I need to tell the linker somehow to relocate my code above the screen memory but I do not know how to do it.
Has anyone use it and redefined characters?

Regards
Fabrizio

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

Re: How to use redefined characters in CC65

Postby beamrider » Mon Aug 21, 2017 3:40 pm

Try something like the following:

Code: Select all

MEMORY {
    ZP: start =  $0002, size = $001A, type = rw, define = yes;
    SCREEN: start =  $1000, size = $0200;
    STARTRAM: start = $11FF, size = $0201, define = yes, file = %O, fill = yes;
    RAM: start = $1200, size = $0A00, define = yes, file = %O, fill = yes;
    CHAR: start = $1C00, size = $0400, type = rw,  define = yes, fill = yes;
    RAM1: start = $2000, size = $4000, type = rw, file = %O;
}
SEGMENTS {
    STARTUP:  load = STARTRAM, type = ro;
    LOWCODE:  load = STARTRAM, type = ro,               optional = yes;
    UDCCHAR:  load = CHAR, type = rw, define = yes, optional = no;
    INIT:     load = RAM, type = ro, define = yes, optional = yes;
    CODE:     load = RAM1, type = ro, define = yes;
    RODATA:   load = RAM, type = ro;
    DATA:     load = RAM, type = rw;
    ZPSAVE:   load = RAM,             type = bss, define   = yes;
    BSS:      load = RAM, type = bss, define = yes;
    HEAP:     load = RAM, type = bss, optional = yes; # must sit just below stack
    ZEROPAGE: load = ZP,  type = zp;
}
FEATURES {
    CONDES: segment = INIT,
       type = constructor,
       label = __CONSTRUCTOR_TABLE__,
       count = __CONSTRUCTOR_COUNT__;
    CONDES: segment = RODATA,
       type = destructor,
       label = __DESTRUCTOR_TABLE__,
       count = __DESTRUCTOR_COUNT__;
    CONDES: segment = RODATA,
       type = interruptor,
       label = __INTERRUPTOR_TABLE__,
       count = __INTERRUPTOR_COUNT__;
}
SYMBOLS {
    __STACKSIZE__ = $400;   # 1K stack
}



Then compile the UDCs @ $1C00 by including them in the appropriate segment:

e.g.

Code: Select all

   .segment "UDCCHAR"
      .export _Charset

_Charset:

char0: .byte  $1C,$22,$4A,$56,$4C,$20,$1E,$00
char1: .byte  $18,$24,$42,$7E,$42,$42,$42,$00
etc...


and reference as..

Code: Select all


typedef unsigned char BYTE;

extern BYTE Charset[];



finally in your 'c' code something like this to point the VIC-1 chip at the correct location...

Code: Select all

   
   
   BYTE  tmp;
   tmp = ~0x0F & PEEK(&(VIC.addr));
   POKE(&(VIC.addr), tmp | 0x0F);
   

Linzino
Vic 20 Drifter
Posts: 37
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 » Mon Aug 21, 2017 4:24 pm

THANKS!!

This will help me get the Vic 20 version of CROSS CHASE to get redefined characters!

Linzino
Vic 20 Drifter
Posts: 37
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:58 am

Does your config create the BASIC loader?

If not, what should I do to have both redefined characters and the BASIC loader?

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

Re: How to use redefined characters in CC65

Postby beamrider » Tue Aug 22, 2017 6:39 am

CC65 has its own basic loader that should call your main()?

Linzino
Vic 20 Drifter
Posts: 37
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 9:08 am

The standard CFG files that come with CC^% would create a 1 or 2 line BASIC program that simply runs the program.

Standard CFG:
...
MEMORY {
...
HEADER: file = %O, start = $1201, size = $000C;
...
SEGMENTS {
...
EXEHDR: load = HEADER, type = ro;
...
So that loading the game program would auto-start it, i.e., I do not need to type something like sys <address>.

Is your CFG not doing that? How do I run my program?
In your CFG I do not see HEADER nor EXEHDR.
So I do not understand how it should run.

Linzino
Vic 20 Drifter
Posts: 37
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 11:15 am

Your CFG seems invalid or maybe something else is required.

If I use your CFG file as is: I get errors with the __STACK__
Attribute expected, got '__STACKSIZE__

If I fix it, then I get errors about ZPSAVE being inexistent.

If I remove ZPSAVE
Segment `UDCCHAR' overflows memory area `CHAR' by 1024 bytes
independenly of the size of the file that contains
"
.segment "UDCCHAR"
.export _Charset

_Charset:
...(exactly 1024 bytes)
"
(I have included the .s file with the UDCCHAR segment)

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

Re: How to use redefined characters in CC65

Postby beamrider » Tue Aug 22, 2017 11:32 am

try the following sample

https://drive.google.com/uc?export=down ... WdtbVdrQTg

(assuming windows)
Edit compile.bat and set your path to VICE
Run compile.bat

should display this

Image

Linzino
Vic 20 Drifter
Posts: 37
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 12:25 pm

Your file includes the entire CC65 kit.

Are you using a modified or outdated version of CC65? What did you need to modify?

It fails at the linker command. I am trying to fix it.
"
The system cannot find the path specified.
"

Even if I manage to run your code, will I be able to have my cross-system game to compile?
My game should compile for all computer targets in CC65 and possible Z88DK. I am aiming at a "universal" 8-bit game.

I fear I will need to understand what to change in CC65 to get all my targets to work.
Last edited by Linzino on Tue Aug 22, 2017 12:39 pm, edited 1 time in total.

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

Re: How to use redefined characters in CC65

Postby beamrider » Tue Aug 22, 2017 12:30 pm

I'm not sure how old it is, but it's a standard CC65 distribution.

Not sure what you mean by 'modify'? The CFG file can be arranged as you like it.

You asked for an example of using UDCs in CC65 and the example does just that. You will need to work out how to get from the sample to meet your own needs I'm afraid.

Linzino
Vic 20 Drifter
Posts: 37
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 12:46 pm

Thanks a lot! I manage to fix the path!

It does work indeed. It is kind of magic for me, though.
It produces a .prg file that I can load with Vice.

I wonder if and what I need to change in your cfg for my project.
With the current CC65 your CFG produces various errors. I don't know what is wrong.

I may try to use your CC65 set up to compile the Vic 20 target if I cannot figure out what to do with the current CC65.

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

Re: How to use redefined characters in CC65

Postby beamrider » Tue Aug 22, 2017 1:09 pm

yes, I just swapped in the latest CC65 and I can get it to compile by updating the CFG file, but the characters don't show...

I'll have a further play when I get some more time...

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

Re: How to use redefined characters in CC65

Postby beamrider » Tue Aug 22, 2017 2:26 pm

I've updated the sample to use the latest version of CC65 and the supplied config file format.

https://drive.google.com/uc?export=down ... EpZbnU1Qkk

Linzino
Vic 20 Drifter
Posts: 37
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 2:35 pm

Thanks!

I will have to figure out how to use it with my code...
Do I need to compile the object files one at a time and link them at the end?

I am getting tons of errors if I run my usual (very long) command line

C:\Retro\DEV\cc65-snapshot-win32\bin>cl65.exe -O -t vic20 -DVIC20_SOUNDS --config "C:\Users\Brizio\Documents\GitHub\PortableChase"\cfg\vic20-16k_GFX.cfg "C:\Users\Brizio\Documents\GitHub\PortableChase"\vic20\vic20_UDG.s < c files > -o "C:\Users\Brizio\Documents\GitHub\PortableChase"\deliverables\cvic20-16k_sounds.prg
ld65: Warning: C:\Users\Brizio\Documents\GitHub\PortableChase\cfg\vic20-16k_GFX.cfg(13): Segment `CODE' overflows memory area `MAIN' by 14312 bytes
ld65: Warning: C:\Users\Brizio\Documents\GitHub\PortableChase\cfg\vic20-16k_GFX.cfg(14): Segment `UDCCHAR' overflows memory area `CHARMEM' by 1024 bytes
ld65: Error: Cannot generate most of the files due to memory area overflows

Remark:
The executable without the 1k user-defined characters is 17721 bytes in size. So it should be possible to have 1024 bytes for the redefined characters.

Linzino
Vic 20 Drifter
Posts: 37
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 2:51 pm

Maybe you have forgotten RAM1 in the cfg.
I am trying to guess...

Your small program will fit in the memory section before the caracter memory but
my game won't fit in that tiny RAM.


Return to “Emulation and Cross Development”

Who is online

Users browsing this forum: No registered users and 1 guest