Previous two [here and here] tutorials hopefully bring you into the 8-bit 6502 NES programming. Before starting this tutorial, I am going to say a bit more about the 6502 NES hardware. The NES (Nintendo Entertainment System) has a 8-bit 6502 CPU (which can address 16-bit memory address from $0000 to $FFFF). It also comes with a 2K RAM (Yes, only 2K, so be wise to use memory), and a PPU (Picture Processing Unit). Most basic games are size of 40K and there also are 60K, 80K, 128K and 256K games. The 6502 CPU is 8 bit and kinda slow, so the gaming performance is limited even the size can be extended by external storage (slot)
With C compiler for 6502, we can easily write C programs to generate the *.nes programs. We can embed inline 6502 assembly languages easily (6502 assembly programming is handy and helpful because most of the cases, we need to operate directly with the hardware). We can use asm() to include a one line assembly.
1 2 3 4 | void main() { asm("nop"); } |
void main() { asm("nop"); }
We can also write the assembly file in *.s extension
1 2 3 4 5 6 7 8 | .export _testasm .segment "CODE" .proc _testasm: near inc $F0 rts .endproc |
.export _testasm .segment "CODE" .proc _testasm: near inc $F0 rts .endproc
and include it in C program:
1 2 3 4 5 6 7 8 | void testasm(); void main() { while(1){ testasm(); // call the assembled function } } |
void testasm(); void main() { while(1){ testasm(); // call the assembled function } }
At command line, we just need to include the *.s for compilation.
cl65 -t nes -o test.nes test.c test.s
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Tutorial 2 - C Programming in 6502
Next Post: Tutorial 4 - C Programming in 6502 - Useful Macros
Can you please show to do I pass parameter to the 6502 function from C?
It is the same in C language e.g. int sample(int x) { return x * 2; } int x = sample(2);
I meant how do I receive that value in the 6502 code?
Can you give me a snippet of how to do that in 6502?
In this chapter, I follow this codes, but when i executive the “cl65 -t nes -o asm.nes asm.c asm.s” A strange thing happened,my .s file lose. The console tell me can’t find that .s file. I have no idea about this.
I find the problem. The problem is the file name. I “mv asm.s test.s”.so It’s right.Maybe asm.s is a important file in the linux.