Page 6 of 6

Re: Calypsi C compiler toolchain for 6502 and 65816

Posted: Mon Oct 24, 2022 3:25 pm
by Proxy
i would still recommend going to the github and have the dev himself take a look at it. as i've never dabbled with interrupts with C (except for arduino stuff).

Re: Calypsi C compiler toolchain for 6502 and 65816

Posted: Mon Oct 24, 2022 6:06 pm
by BigDumbDinosaur
arrow201 wrote:
Following up to my previous post, I have a home brewed 65C02 from the late 1980s...Next is interrupts. I don't know, but it seems setting up the IRQ will not work the way I want it to using the attribute commands or modifying the interrupt.h(which appears to have been made for the C64?)

What Proxy said about contacting the Calypsi developer.

I do not recommend using C to write an interrupt service routine (ISR) for the 65C02. The resulting machine code will be larger and slower compared to the assembly language equivalent. Some parts of an ISR may be time-critical, e.g., processing UART interrupts, which won’t mesh well with the capabilities of a typical C compiler targeting the eight-bit 6502 family.

Re: Calypsi C compiler toolchain for 6502 and 65816

Posted: Mon Oct 24, 2022 6:16 pm
by arrow201
Thank you guys for your responses. :) Yes, after posting, I sent an email to the developer, pointing him to my post. Hopefully, he'll respond back here so everyone benefits. If not, and emails me directly, I'll repost any answers from the developer. BigDumbDinosaur( :) ), thank you, yes, I agree with you, but I would just like to see it work. :)

Thanks!

Re: Calypsi C compiler toolchain for 6502 and 65816

Posted: Wed Oct 26, 2022 5:34 am
by hth313
The load to 0x1000 looks right, that is the best way of doing it, using a custom named section and placing it at the address in the linker rules file.

You can define an interrupt function using the interrupt attribute:

Code: Select all

__attribute__((interrupt))
void MyIRQ() {
  // some code
}
The compiler will take care of saving registers and generating the RTI instruction at the end.

Inline assembler is not currently supported. I have no immediate plans to implement it. Currently you need to separate C and assembly in different source files. If there is any specific reason/use-case you have for it, let me know. You can call functions written in assembler and the compiler should be able to handle at least some stuff you might want it for, using interrupt functions as shown above and by intrinsic functions (see the user guide and the provided header file intrinsics6502.h).

Re: Calypsi C compiler toolchain for 6502 and 65816

Posted: Wed Oct 26, 2022 5:38 am
by hth313
Regarding interrupts in C. If you do it, avoid making function calls as that will generate a lot of save overhead. Well, you can make calls to small functions provided that they are inlined. Refer to the user guide about inlining and how to control it (to some degree).

Re: Calypsi C compiler toolchain for 6502 and 65816

Posted: Wed Oct 26, 2022 3:00 pm
by arrow201
Thank you much for your help :) I didn't realize that one can just put __attribute__((interrupt)), I thought an address was required.
As for inline asm, I can only think the use would be to save on overhead JSR/RTS calls, especially if it's just a few instructions.

Regarding calling asm from C(manual Sections 18.2/18.3), I'm not sure I totally get it since I have thick skull. :) Example: Say I want to pass the address to an asm function, would I do:
.c

Code: Select all

extern void MBII_Display(uint16_t *pData);

int main ()
{
	const char Data[6] = "Hello";	

	MBII_Display((uint16_t *)&Data);
...
}
.s

Code: Select all

; MBII_API.s
;
	.section code
	.extern _Zp ; pseudo zero page registers	

	.public MBII_Display
MBII_Display:
      pha
      ; store the Data addr at $00C8/$00C9
		lda zp:_Zp
		sta 0xC8
		lda zp:_Zp+1
		sta 0xC9
		jsr	0xE042    ;display the null terminated chars who's address is at $00C8/$00C9
      pla
		rts
Thanks!

* UPDATE * - the above is correct. If passing down a byte it will use the accumulator, after that or if passing a 16 bit var, it'll use the _Zp pseudo registers, as per the 6502 guide. This info can be found at 18.3 Calling convention (P.94) (for v.3.6.10)
I haven't written anything huge, only test programs, but find this compiler works very well. Simple VIA(6522) port toggling, and counter IRQs. Sounds via a PSG(AY-3-8910), serial and memory tests all work without a hitch. :)
Thanks guys for your help! :)

Re: Calypsi C compiler toolchain for 6502 and 65816

Posted: Thu Feb 16, 2023 8:06 pm
by JeeK
BillG wrote:
I thought I felt my ears burning...
[..]
https://www.lucidtechnologies.info/6803_instr.pdf
Meanwhile reachable only at https://web.archive.org/web/20211126214 ... _instr.pdf