Chris Cureau wrote: > Very interesting! I'll look a little closer in a bit... > > One of the nice things about the c128 is the built in MMU...which allows remapping of page 0 and page 1 (zero page and stack, respectively) at any given moment. The same thing is possible with the 65816/65265 CPUs, which are the next target. If you also use the o65 format, you can do software relocation. There are still limitations of course, but the barriers are lower given those things... Being able to remap the stack is a big win. Is 256 bytes a realistic C stack size, I wonder? I did some work a while back looking at ways of doing C on the 6502 and the Z80. They both suck, because both processors predate stack-frame-based languages, and so don't have any useful addressing modes (like stack-relative addressing). On the Z80 you have to copy sp into one of your precious 16-bit index registers, and then indirect each byte individually; at 4 bytes of code a byte, that's 8 bytes to read a single 16-bit value off the stack! On the 6502 it's even worse because of that fixed-position stack. Most compilers maintain their own C stack, with appalling performance results, of course. But if you *can* use the 6502 stack as the C stack, you can do something like this... stackaddr: // in zero page dw 0x0100 load_16_bit_value_at_sp_plus_a_into_xy: tsx stx stackaddr+1 tay ldx (stackaddr), y iny ldy (stackaddr), y That's nine bytes, unfortunately, but with luck you may be able to offset that by much more efficient parameter passing (as you can use pha/phx/phy to push values onto the stack). Plus, of course, if you were doing it for real you could arrange that the stack offset starts in Y rather than A, which would save you a byte. TBH, I thing the 6502 is such a poor match for C that it'd be better to compile to p-code (like a more advanced SWEET16); the improved code density should outweigh the performance issues for most tasks. I did actually do most of one a while back, with a Z80 interpreter, and had the ACK compiling to it, at least to a degree... I can dig it out if anyone cares. Alternatively you could write your programs in Fortran. The 6502 should run Fortran quite well. -- ┌─── dg@cowlark.com ───── http://www.cowlark.com ───── │ "Parents let children ride bicycles on the street. But parents do not │ allow children to hear vulgar words. Therefore we can deduce that │ cursing is more dangerous than being hit by a car." --- Scott Adams
Attachment:
signature.asc
Description: OpenPGP digital signature