GinDiamond wrote:
Hey, I'm sorry I wasn't as clear as I could be.
$8A5A is a subroutine in the SYM-1 ROM that waits and grabs an incoming byte from the serial port and puts it in the Accumulator.
I also am not quite sure what you mean about making an asm file with my function in it, however, this seems like what I should do for sure. How would I link that with a command?
Okay, getting clearer picture here. Didn't realize you were using a prebuilt ROM; in that case the above method could work fine, though I would ditch the global variable:
Code:
int getch(void)
{
char c;
__asm__ ("JSR $8A5A");
__asm__ ("STA %b", c);
return c;
}
Still not what I'd consider the most ideal, but you're using a C compiler, there's going to be a lot of boiler plate code that the compiler adds.
With something like the SYM-1 (which I just gave myself a crash course on), you can't grantee that every ROM function is written to interface with the CC65 compiler. getch() is such a simple function you might be able to just link it in with some fancy stuff with the linker, but I don't know how to do that off the top of my head.
As to the question of how to link assembly with C:
You can create an assembly file (usually the extension is .asm or .s) and then assemble it using the CA65 assembler which comes with the CC65 compiler.
You would join multiple files together with a linker step, most people wrap this up with a Makefile or some other such system for building multiple files.
A simple Makefile might look like so:
Code:
OBJS=asm1.o asm2.o cfile1.o cfile2.o
# Assemble .s files into .o files
.s.o:
ca65 --cpu 65c02 -I include -o $@ $<
# Compile .c files into .o files
.c.o:
cc65 --cpu 65c02 -I include -o $@ $<
# Generate your program from the above created .o files.
myprogram.bin: $(OBJS)
ld65 $(OBJS) -o myprogram.bin
CC65 doesn't come with Make on it's own, you'll have to get and install Make for whatever platform you're running on. And each flavor of Make has it's own little quarks. (I would recommend GNU Make simply because it has probably the most extensive documentation on the net)
If you look at the CC65 docs I believe they talk about how you can roll a Makefile that works with their tools.
If you want you can try dissecting the ROM I've been slowly coding up which has a Makefile, but it is purely in assembly, no C.
(It does use the CA65 assembler though)
https://github.com/Kelmar/LemonGood Luck!