Jump to content
IGNORED

CC65 - online course - lesson #1


Recommended Posts

20 hours ago, TGB1718 said:

Would love to try CC65, but can't seem to get anything to work, don't get the environment shown in the video's, there doesn't

seem to be a way to create a project to get started and it appears without that there is no way to confugure a build environment.

here to help....

 

create the following file main.c in any editor (could be notepad, notepad++, sublime text editor, other)

Quote

include <atari.h>

 

void main(void)

{

     while (1)

    {

    };

}

this program does an endless loop and basically do nothing. it is just for the sake of this example.

 

the next thing would be to create a build file. which is basically a command line that runs the CC65 compiler and linker to create the Atari executable (*.xex).

 

creare the following build.bat file (on windows):

Quote

cl65 --debug-info -Wl --dbgfile,mytest.lab -m mytest.map -Ln mytest.lbl -t atari -Oi main.c -o mytest.xex -C atari.cfg

there are a lot of parameters in the build command , what is important is the -o followed by the filename.xex  - that would be your executable file.

 

another important parameter is the -C followed by the config file name atari.cfg

 

here is a default config file named atari.cfg you can use:

Quote

FEATURES {
    STARTADDRESS: default = $2000;
}
SYMBOLS {
    __EXEHDR__:          type = import;
    __SYSTEM_CHECK__:    type = import;  # force inclusion of "system check" load chunk
    __AUTOSTART__:       type = import;  # force inclusion of autostart "trailer"
    __STACKSIZE__:       type = weak, value = $0800; # 2k stack
    __STARTADDRESS__:    type = export, value = %S;
    __RESERVED_MEMORY__: type = weak, value = $0000;

}
MEMORY {
    ZP:         file = "", define = yes, start = $0082, size = $007E;

# file header, just $FFFF
    HEADER:     file = %O,               start = $0000, size = $0002;

# "system check" load chunk
    SYSCHKHDR:  file = %O,               start = $0000, size = $0004;
    SYSCHKCHNK: file = %O,               start = $2E00, size = $0300;
    SYSCHKTRL:  file = %O,               start = $0000, size = $0006;

# "main program" load chunk
    MAINHDR:    file = %O,               start = $0000, size = $0004;
    MAIN:       file = %O, define = yes, start = %S,    size = $BC20 - __STACKSIZE__ - __RESERVED_MEMORY__ - %S;
    TRAILER:    file = %O,               start = $0000, size = $0006;
}
SEGMENTS {
    ZEROPAGE:  load = ZP,         type = zp;
    EXTZP:     load = ZP,         type = zp,                optional = yes;
    EXEHDR:    load = HEADER,     type = ro;
    SYSCHKHDR: load = SYSCHKHDR,  type = ro,                optional = yes;
    SYSCHK:    load = SYSCHKCHNK, type = rw,  define = yes, optional = yes;
    SYSCHKTRL: load = SYSCHKTRL,  type = ro,                optional = yes;
    MAINHDR:   load = MAINHDR,    type = ro;
    STARTUP:   load = MAIN,       type = ro,  define = yes;
    LOWBSS:    load = MAIN,       type = rw,                optional = yes;  # not zero initialized
    LOWCODE:   load = MAIN,       type = ro,  define = yes, optional = yes;
    ONCE:      load = MAIN,       type = ro,                optional = yes;
    CODE:      load = MAIN,       type = ro,  define = yes;
    RODATA:    load = MAIN,       type = ro;
    DATA:      load = MAIN,       type = rw;
    INIT:      load = MAIN,       type = rw,                optional = yes;
    BSS:       load = MAIN,       type = bss, define = yes;
    AUTOSTRT:  load = TRAILER,    type = ro;
}
FEATURES {
    CONDES: type    = constructor,
            label   = __CONSTRUCTOR_TABLE__,
            count   = __CONSTRUCTOR_COUNT__,
            segment = ONCE;
    CONDES: type    = destructor,
            label   = __DESTRUCTOR_TABLE__,
            count   = __DESTRUCTOR_COUNT__,
            segment = RODATA;
    CONDES: type    = interruptor,
            label   = __INTERRUPTOR_TABLE__,
            count   = __INTERRUPTOR_COUNT__,
            segment = RODATA,
            import  = __CALLIRQ__;
}
 

you can just copy and paste . this is the default publishd with CC65 library. 

notice i've set my program to start at 2000 memory address location:

Quote

FEATURES {
    STARTADDRESS: default = $2000;
}

 you can set it anywhere in the RAM address space.

 

you're ready.

build the program by running the build.bat in command line window

 

if all worked fine and no errors, you should see the executable mytest.xex created in your folder.

now all you have to do is run it with any emultaor of A8, for example open the file with Altirra emultar.

you will see this:

image.thumb.png.61d285400a7b93f4ee62116f4fbbe343.png

 

now , your ready to write anything you'd like in the main.c file and use this framework to compile and run your programs.

 

good luck!

Link to comment
Share on other sites

30 minutes ago, Yaron Nir said:

you can just copy and paste . this is the default publishd with CC65 library. 

 

33 minutes ago, Yaron Nir said:

-C atari.cfg

You shouldn't need to do this as the linker should find the config file within the CC65 installation's "cfg" folder.

You can override the default by specifying any of the below, e.g. "-C atari-xex.cfg" depending on your requirements.

 

image.png.262d4940881c3b5416a03d3db143094d.png

 

Or, of course, to specify your own rolled config file, e.g. when making a cartridge.

 

But for a newbie I would recommend they don't need to get involved with config's right away and so adding "-C atari.cfg" is not necessary

  • Like 1
Link to comment
Share on other sites

52 minutes ago, Yaron Nir said:

cl65 --debug-info -Wl --dbgfile,mytest.lab -m mytest.map -Ln mytest.lbl -t atari -Oi main.c -o mytest.xex -C atari.cfg

 

Really? For a beginner, just checking if the cc65 setup is OK and if he is able to produce an executable, this command line is an easier start:

cl65 -t atari -o text.xex main.c

 

  • Like 2
Link to comment
Share on other sites

many thanks for all the replies, it worked fine from the command line, was wondering what you have to do in Sublime to

make it use cl65, I've tried lots of soultions that I "Googled", but none work, it insist on using gcc which obviosly fails.

Link to comment
Share on other sites

1 minute ago, TGB1718 said:

many thanks for all the replies, it worked fine from the command line, was wondering what you have to do in Sublime to

make it use cl65, I've tried lots of soultions that I "Googled", but none work, it insist on using gcc which obviosly fails.

ok, 

from sublime, chooes to add new build system:

image.thumb.png.4b89966bd4b80f9099c80cf29b232bda.png

 

in the template file that is opened, change the command to:

Quote

{
    "cmd": ["build.bat"]
}

save the file, call it cc65.sublime-build. it is mostly located at:

Quote

..\AppData\Roaming\Sublime Text 3\Packages\User

then you will be a new build system in the menu:

image.thumb.png.e1eccad85bd105bff33ae6ae0d2514c9.png

 

now just make sure you open your folder of your problem in sublime, the folder should contain the files i've explained above (main.c, build.bat, atari.cfg)

 

type CTRL+B to build your program (just build from the menu)

 

hope that helped

  • Like 1
Link to comment
Share on other sites

24 minutes ago, Wrathchild said:

@Yaron Nir

Maybe get a moderator to change the title of the thread for you as you've chosen to include new parts within the thread rather than start new ones for each part?

i thought that if i would be starting each thread for each lesson, i would be trolling... and people would get annoyed, this keeps all the lessons under one thread.

i would though change the thread title maybe to specify "lessons" plural rather than state lesson #1.....

 

Link to comment
Share on other sites

1 hour ago, Yaron Nir said:

which ones? there should be no quirks if working properly...?

It's ok, I've just checked on a Linux installation and I get the same behaviour, never noticed this before.

 

int x;

char msg[10];

scanf("%d",&x);

gets(msg);

 

 

this code doesn't get msg as the keyboard buffer keeps <CR> in the buffer after scanf

so jumps over gets as it receives the <CR>

 

fflush(stdin) doesn't seem to clear it

just never noticed this before

Link to comment
Share on other sites

Hi!

2 hours ago, TGB1718 said:

It's ok, I've just checked on a Linux installation and I get the same behaviour, never noticed this before.

 

int x;

char msg[10];

scanf("%d",&x);

gets(msg);

This should be:

    int x;
    char msg[10];
    scanf("%d\n",&x);
    gets(msg);

Have Fun!

 

Link to comment
Share on other sites

On 4/7/2020 at 3:09 PM, Yaron Nir said:

i thought that if i would be starting each thread for each lesson, i would be trolling... and people would get annoyed, this keeps all the lessons under one thread.

i would though change the thread title maybe to specify "lessons" plural rather than state lesson #1.....

 

And ask for editing rights on the first post, if you don't already have that, so you can link all lessons from the first post, too.

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...
  • 2 weeks later...

ok, last lesson #8 - RMT music files and SFX support

 

You can find code sample from all the lessons in the following GIT link:

https://github.com/AsafSaar/Atari-8bit-Programming

 

I know this is not in english native language, but you can view the videos and see the explanations. 

 

 

I hope this will help someone. I trully encourage to develope in high language such as C for the atari 8-bit.

everything is possible, you just need to understand the language and 8-bit limitations. 

 

Cheers,

Yaron

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...