[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cc65 / ca65: how to interface C and assembly?



Hello,

please excuse the cross-posting, but I thought that maybe somebody from these three groups might be able to help me along a bit.

I'm not new to the C language or to 6502 assembly language, but I'm new to cc65. I want to write a program in C using cc65, but I need to integrate a small piece of cycle-counted assembly code to do low-level disk writes with the correct timing; the Apple hardware is very picky in this regard, so it's impossible to use compiled code.

I'd like best to use inline assembly ("asm") statements inside a C frame function, but the code is not allowed to cross a page boundary, since this would destroy the timing of branch instructions; and it seems that ".align" is not allowed in asm statements. Is there any way to tell the compiler that you want a piece of inline assembly to be page-aligned?

If I can't use inline assembly, I'd need to know how to interface assembly and C code. Especially, how do I access function parameters of different data types from assembly language, how do I return values, and how can I use temporary storage in the zero page without interfering with whatever the compiled code does on the zero page. The cc65 documentation is largely silent on these matters, and while I've looked at a few pieces of assembly code produced by the compiler, I found it rather convoluted and not that easy to understand.

I understand that there's a software-implemented stack, using "sp" for a stack pointer / base pointer, local variables and parameters are both stored on this stack, and addressed with "(sp),y" type instructions, and that for a number of stack manipulation operations, there are a couple of standardized "jsr"s to library code; but exactly how the different data types are stored remains unclear to me, also how to use zero page in a compatible way.

If anybody could help with hints or with just some sample code that I could look at, I'd be grateful for replies in these groups. Given that the resulting discussion will probably be of some interest to the people in these three groups, I've not set a "Followup-To:"; if you're absolutely against cross posting, feel free to reply in just one group.

If there are any web forums or mailing lists where this question is more likely to get useful answers, I'd be also grateful for a link.

Many thanks in advance!

--
Linards Ticmanis