Get Started with 6502 Assembly Programming on Atari Lynx
atarigamer.com
atarigamer.com
So all that remains is to pick a platform! And there's no shortage of them. Glad to see Lynx is yet another participant in the vibrant 6502 homebrew community.
I’m curious specifically why you think this is. The 6502 with its poor register set and special purpose addressing mode seems to make it a relatively terrible/challenging C target.
If you want that, you should learn the PDP-11 instruction set, which is actually why the C language is the way it is. In particular, C is rather uniquely unsuited for segmented memory models, which many 6502 systems have, whereas other languages with lower-level features or accommodations can easily function under such a memory model, because they were designed with it in mind instead of solely for the PDP-11.
On that note, C isn't actually a low-level language and I'm aware the 6502 is an example of an instruction set it maps very poorly to, compared to how a machine code programmer would approach it, so I'm curious why you made this relationship, since it's rather tenuous.
C was often used to program 16-bit x86 systems, and it handled that well enough.
A more relevant limitation of the 6502, however, is its stack. The 6502 stack is limited to a single page of 256 bytes, and there is no stack-relative addressing mode. This makes a C-style stack difficult to implement -- most C implementations for the 6502 implement a secondary data stack in main memory.
For example, if the compiler can prove that a function never gets more than one active stack frame (no recursion) then the local variables don't need to be on a stack. They can be in the data section. If the compiler can prove this for two functions together, such that they will never both have active stack frames, then the variables can reside in the same memory. Going beyond this, partial sharing is possible. If function X calls function Y, the variables of function Y can reside in the locations of many of the variables of function X. It is only the variables of function X that must survive the call to Y that would need distinct memory locations.
Inlining can help too. That gets rid of the need to push a return address and so on.
The first is that the optimization can be limited to within one file. Calls going between source files can sometimes limit the optimization opportunity because it may become impossible to prove that there is no mutual recursion. Functions that may be involved in recursion can not be optimized in this way. One might add a #pragma to override the compiler's determination of safety.
The second possible answer is to have the link phase do the real compiling. The supposed compile phase just preprocesses and verifies syntax.
Function pointers certainly liven things up. Suppose the function pointer of type *X is used to call a function of type X, which then exclusively calls functions of type Y. If we know that none of those type Y functions end up calling any type X functions, then that first-mentioned function of type X will not get more than one stack frame. It is thus safe to optimize with that assumption.
Of course, you can pick the system/context you want to learn in: many 8-bit computers used 6502 chips. For example, this book is well-regarded for those with Apple II nostalgia: https://archive.org/details/AssemblyLinesCompleteWagner
I'm sure there are tons of NES-targeted tutorials too.
Also, are their free or paid-for asset libraries?
Thanks in advance!
To put it on a cart, you'll use RetroUSB PowerPak or Everdrive N8.
Don't know about assets.
Jumping into "no-framebuffer/racing-the-beam" 6502 programming on the Atari 2600 for the uninitiated is just ... cruel.
The C compiler is fascinating. There is a uint24_t which maps to an unsigned int. This is because the EZ80 CPU is capable of ganging three 8-bit registers together to handle 24-bit data. Pointers are also 24-bit. The "short" and "long" types are of normal size, 16-bit and 32-bit. There is no alignment or padding. Serious stuff needs to be in assembly. The C compiler doesn't optimize very well.
So that is 3 programming languages on a $100 device that happens to be useful for all sorts of normal school classes. The calculator is fine for the SAT, ACT, AP Statistics, AP Calculus, and now even the AP sciences.
NEG is described as:
EOR #255 (XOR/Flip bits)
SEC (Clear carry)
ADD #1 (add 1)
Of course, it's: EOR #255 (XOR/Flip bits)
CLC (Clear carry)
ADC #1 (add 1 with carry 0)
or: EOR #255 (XOR/Flip bits)
SEC (Set carry)
ADC #0 (add 0 with carry 1) EOR #255 ; Invert
INC A ; Add 1
It looks like the Lynx has a 65SC02 which is a 65C02 without the bit manipulation instructions, so it should have the INC A instruction. INC z_E
BNE IncDE_Done
INC z_D
IncDE_Done:
Should be: LDA z_E
BNE DecDE
DEC z_D
DecDe:
DEC z_ESee also the TurboGrafx-16 console, which had a similar arrangement: an 8-bit 6502-descendent and a 16-bit graphics chip. It got a lot of flak for being “fake 16-bit”. I think the Lynx was better able to get away with it because it was on such a different level than other handhelds of the time (besides maybe the expensive portable version of the TG-16!), whereas the TG-16 had to go up against the 68000-based Sega Genesis.
The thing is, you can't really use any single factor to determine CPU bitness. Not memory bus width, ALU width, register width, physical address width, etc.
Another good resource is forum.6502.org as there are plenty of 6502 experts there that have built their own 6502 machines for a hobby