[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: cc65 / ca65: how to interface C and assembly?
- Subject: Re: cc65 / ca65: how to interface C and assembly?
- From: Andy McFadden <fadden@fadden.com>
- Date: 06 Dec 2005 16:33:58 GMT
- Newsgroups: comp.sys.apple2, comp.sys.cbm, comp.sys.atari.8bit
- Organization: faddenInternet, Inc.
- References: <4395b60d$0$9636$9b4e6d93@newsread2.arcor-online.net>
- Sender: Andy McFadden <fadden@adsl-209-204-141-120.sonic.net>
- User-agent: tin/1.4.7-20030322 ("Suggestions") (UNIX) (Linux/2.6.11-1.1369_FC4 (i686))
- Xref: g2news1.google.com comp.sys.apple2:7137 comp.sys.cbm:12742 comp.sys.atari.8bit:3611
In comp.sys.apple2 Linards Ticmanis <ticmanis@gmx.de> wrote:
> 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.
If you're worried about where your code lives, relocate your code
somewhere else during program initialization, and jump to it. This
is essentially the approach used for assembly code embedded in Applesoft
programs. Write some inline assembly that calls the function at the
fixed address.
The way you carefully avoid interfering with zero page is to save and
restore the zero-page values on entry and exit. You won't be using
interrupts since your code is timing-critical, so there's no race
condition.
--
Send mail to fadden@fadden.com (Andy McFadden) - http://www.fadden.com/
CD-Recordable FAQ - http://www.cdrfaq.org/
CiderPress Apple II archive utility for Windows - http://www.faddensoft.com/
Fight Internet Spam - http://spam.abuse.net/spam/ & http://spamcop.net/