How do I get CC65 to include NO startup code?

You need an actual VIC.

Moderator: Moderators

User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: How do I get CC65 to include NO startup code?

Post by Mike »

groepaz wrote:try with -Osir :) the generated code is large in some cases, but its not *that* bad really :)
Now that's really funny. With a slightly trimmed version of 'main.c' ...

Code: Select all

typedef unsigned char byte;

#define SCREEN_ADDR   (0x1E00)
#define COL_ADDR      (0x9600)

void main()
{
    *((byte *)(SCREEN_ADDR+1)) = 0x01;
    *((byte *)(COL_ADDR+1)) = 0x02;
    
    *((byte *)(SCREEN_ADDR+2)) = 0x02;
    *((byte *)(COL_ADDR+2)) = 0x03;

    loop: goto loop;
}
... and using 'cc65 -t none -Osir' it's actually possible to coerce cc65 into producing the desired output:

Code: Select all

;
; File generated by cc65 v 2.13.2
;
	.fopt		compiler,"cc65 v 2.13.2"
	.setcpu		"6502"
	.smart		on
	.autoimport	on
	.case		on
	.debuginfo	off
	.importzp	sp, sreg, regsave, regbank, tmp1, ptr1, ptr2
	.macpack	longbranch
	.forceimport	__STARTUP__
	.export		_main

; ---------------------------------------------------------------
; void __near__ main (void)
; ---------------------------------------------------------------

.segment	"CODE"

.proc	_main: near

.segment	"CODE"

	lda     #$01
	sta     $1E01
	lda     #$02
	sta     $9601
	sta     $1E02
	lda     #$03
	sta     $9602
L0017:	jmp     L0017

.endproc
Not bad. :lol:

Maybe I'm just used to a C programming style that doesn't want to miss out on the standard library functions. On non-65xx platforms, that is. Of course C always offers you to create an own library, when the supplied implementation doesn't suit you.
groepaz
Vic 20 Scientist
Posts: 1185
Joined: Wed Aug 25, 2010 5:30 pm

Re: How do I get CC65 to include NO startup code?

Post by groepaz »

oh, actually even with cc65 it is a very good idea to use the standard library as often as possible (usually the generated code will be smaller and faster than doing the same stuff inline) - however, its also a good idea to think twice about what you are using. as said malloc is often not a good idea and static buffers work better (as in: smaller footprint). also avoiding things like printf (because printf is actually file i/o, it pulls in tons of stuff - better use conio). those things are common things to do on other embedded platforms as well :)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
JavaJack59
Vic 20 Newbie
Posts: 11
Joined: Thu Jun 05, 2014 1:55 pm

Re: How do I get CC65 to include NO startup code?

Post by JavaJack59 »

I could do with some tips on converting the jiffy clock to integers 0-9. I'm assuming there's something in ROM that can do this for me ("print ti$") but I don't know how to make use of it.
User avatar
Mike
Herr VC
Posts: 4831
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: How do I get CC65 to include NO startup code?

Post by Mike »

JavaJack59 wrote:I could do with some tips on converting the jiffy clock to integers 0-9. I'm assuming there's something in ROM that can do this for me ("print ti$") but I don't know how to make use of it.
I suppose you overlooked that reply:
Mike wrote:
JavaJack59 wrote:A digital clock program. Read the jiffy clock and display it [...]
In that case, the thread 'Display of TI$ in border (unex. or +3K)' might be worth a look. :wink:
And yes, there's a routine in ROM to do the same. However, that routine relies on float and string operations and requires one to set up a lot of zeropage locations, and memory areas in a certain way to operate correctly.

Anyway, it should not be too difficult to infer from the disassembly how my own implementation of the conversion works. The jiffy clock is a 24-bit number, and it is incremented by one every 1/60 second (and reset to 0 as it reaches 24:00:00). There's a table with tens of hours, then hours, tens of minutes, minutes, tens of seconds and seconds in jiffies, which are (in that order) subtracted off a copy of the jiffy clock until the respective digit underflows to obtain a string equivalent to TI$ - which however is directly written to a part of the extended screen unreachable by the editor.

OTOH, there's always 'time.h' in the standard library, where time(), localtime() and asctime() also should be able to do the job. :P
JavaJack59
Vic 20 Newbie
Posts: 11
Joined: Thu Jun 05, 2014 1:55 pm

Re: How do I get CC65 to include NO startup code?

Post by JavaJack59 »

Mike wrote:subtracted off a copy of the jiffy clock until the respective digit underflows
Yeah, I did read it, but it wasn't immediately obvious to me how to translate it into vanilla C, since it relied on lower level things like the CPU overflow flag.
JavaJack59
Vic 20 Newbie
Posts: 11
Joined: Thu Jun 05, 2014 1:55 pm

Re: How do I get CC65 to include NO startup code?

Post by JavaJack59 »

A "while greater than, subtract" loop seems to work.

It took me a while to figure out that I couldn't just copy the clock bytes to a long variable as-is. I had to reverse them because of little-endianness.
User avatar
beamrider
Vic 20 Scientist
Posts: 1448
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: How do I get CC65 to include NO startup code?

Post by beamrider »

Nice. Good to see an example in 'c' for the vic.

Sent from my Nexus 5 using Tapatalk
Post Reply