Jump to content
IGNORED

First cc65 attempt, a utility...


Recommended Posts

Many thanks to @Wrathchild and @Irgendwer who helped me resolve a few issues getting cc65 going.

 

I decided to re-write a program I wrote back in 1986 in BASIC which produces DATA statement files from a binary file

which can then be entered into your BASIC program and for Assembler where you may want picture/sprite data it

produces .BYTE statements which again can be entered into Assembler/MAC65.

 

The code wasn't written to produce a small footprint, nor for high speed, just for me to get used to the environment.

The program allow user input, verifys for correct input data/filenames.

 

Not tried it on "real hardware" yet, but works fine in Altirra.

 

I've attahed the .XEX file and 'C' code

 

It was compiled using the following command:-

 

cl65 -t atari -Wl "-D__RESERVED_MEMORY__=1" --static-locals -o autodata.xex autodata.c

autodata.xex AUTODATA.c

  • Like 1
Link to comment
Share on other sites

You will be fine adding the option '-O' (capital o) to your cl65 command to enable the optimizer.

 

As an exercise for you, compile the C to assembler without optimizing, copy the '.s' generated aside, then repeat with '-O' and compare the two, e.g.

cl65 -t atari -S -Wl "-D__RESERVED_MEMORY__=1" --static-locals autodata.c
ren autodata.s autodata1.s
cl65 -t atari -S -O -Wl "-D__RESERVED_MEMORY__=1" --static-locals autodata.c
ren autodata.s autodata2.s

[Edit] Thinking about it, you can just use the -o (output) in the command line:

 

cl65 -t atari -S -Wl "-D__RESERVED_MEMORY__=1" --static-locals -o autodata1.s autodata.c
cl65 -t atari -S -O -Wl "-D__RESERVED_MEMORY__=1" --static-locals -o autodata2.s autodata.c

 

image.thumb.png.81b4687664c2b65222198ae38e499635.png

Edited by Wrathchild
Link to comment
Share on other sites

Very interesting, nice to know the output can be .asm files, had a look through and yes, you can see a lot of inefficient code

which the -O reduces.

On the .xex file, its about 1K smaller with the optimizer.

 

Edited by TGB1718
Link to comment
Share on other sites

the best thing you can do for cc65 is to minimize local variable usage, and do --static-locals, I mean it, treat cc65 like C flavored ACTION!

 

...because the stack gymnastics are one of the biggest expanders of code.

 

Also, more function parameters cause lots of stack juggling.

 

And if you literally leverage Atari specific OS features, (And get rid of the very generalized usage of standard c I/O functions), that chomps off a lot, too. I made my own little routines e.g. for screen input and output that call CIO.

 

some examples here:

https://github.com/FujiNetWIFI/atariwifi/tree/master/fnc-tools/fconfig

 

-Thom

Link to comment
Share on other sites

One question related to the .s output, looking through the code generated, I notice a strange Op Code

jne, I found 3 occurances, I know what it's doing, but it's not a 6502 Op Code.

Do you know why it's not bne, maybe the compiler treats it as bne ?

 

 

L0223:    lda     L01DB
    ora     L01DB+1
    jne     L0226
    lda     L01E0

 

L02CF:    lda     L0293
    ora     L0293+1
    jne     L02D2
    lda     L0298

 

L006D:    lda     _flag
    ora     _flag+1
    jne     L00B2
    jsr     _clrscr

Link to comment
Share on other sites

1 hour ago, TGB1718 said:

Do you know why it's not bne, maybe the compiler treats it as bne ?

It's a macro, where the assembler examines the distance of the branch. In case it is in the branch range, a bne is used - otherwise a construct with the "opposite" branch and jump:
 

.macro  jne     Target
        .if     .match(Target, 0)
                beq     *+5
                jmp     Target
        .elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
                bne     Target
        .else
                beq     *+5
                jmp     Target
        .endif
.endmacro

 

Edited by Irgendwer
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...