Skip to content
unbibium edited this page Feb 15, 2013 · 2 revisions

As a general rule, I've ported the routines as closely as possible to maintain the same behavior as the 6502 version, so that doing the same thing on the Commodore 64 and the DCPU-16 will cause the same sequence of JSR instructions to occur. Everything that happens between the JSR instructions is up in the air.

I generally am more careful about preserving registers in the kernal than in the BASIC interpreter. The registers most likely to be destroyed during a kernal call are A, X, and Y, and possible C and Z if the 6502 version of the subroutine returned anything important in the carry bit or the zero-result flag.

Conversely, for subroutines that accept 16-bit pointers across two registers, this project requires only one register be used.

In most cases, dealing with pointers is easy: copying a pointer from one location to another eas two LD opcodes followed by two ST opcodes, and in DCPU is replaced with a single SET opcode. It gets slightly tricker when dealing with pointer math, as was the case in the code that inserts and deletes lines, where the original 6502 code copied different halves of the pointer at different points, and juggled the carry bits to make it as fast as possible. I could only port it by running some tests on a C64 emulator and stepping through the code in the ML monitor, examining the pointers and working out what the intent of the code was.

...

Clone this wiki locally