Rolled my own memmove() routine for auxmem. Still some issues!

This commit is contained in:
Bobbi Webber-Manners 2020-08-05 23:45:23 -04:00
parent 6c6c187cba
commit a9157dd072

View File

@ -125,13 +125,54 @@ void set_gapbuf(uint16_t i, char c) {
* Must be in LC
*/
#pragma code-name (push, "LC")
void move_in_gapbuf(uint16_t dest, uint16_t src, size_t n) {
void move_in_gapbuf(uint16_t dst, uint16_t src, size_t n) {
#ifdef AUXMEM
__asm__("sta $c005"); // Write aux mem
__asm__("sta $c003"); // Read aux mem
// TODO DO STUFF
__asm__("sta $c002"); // Read main mem
__asm__("sta $c004"); // Write main mem
if (dst > src) {
// Start with highest addr
// dest[n-1] = src[n-1] etc.
*(uint16_t*)(0xfa) = n; // Stuff sz in ZP
*(uint16_t*)(0xfc) = (uint16_t)0x0800 + src + n - 1; // Stuff src in ZP
*(uint16_t*)(0xfe) = (uint16_t)0x0800 + dst + n - 1; // Stuff dst in ZP
__asm__("sta $c005"); // Write aux mem
__asm__("sta $c003"); // Read aux mem
dl1:
__asm__("lda ($fc)"); // *src
__asm__("sta ($fe)"); // -> *dst
__asm__("dec $fc"); // LSB of src
__asm__("bne %g", ds1);
__asm__("dec $fd"); // MSB of src
ds1:
__asm__("dec $fe"); // LSB of dst
__asm__("bne %g", ds2);
__asm__("dec $ff"); // MSB of dst
ds2:
__asm__("dec $fa"); // n
__asm__("bne %g", dl1); // Loop
__asm__("sta $c002"); // Read main mem
__asm__("sta $c004"); // Write main mem
} else {
// Start with lowest addr
*(uint16_t*)(0xfa) = n; // Stuff sz in ZP
*(uint16_t*)(0xfc) = (uint16_t)0x0800 + src; // Stuff src in ZP
*(uint16_t*)(0xfe) = (uint16_t)0x0800 + dst; // Stuff dst in ZP
__asm__("sta $c005"); // Write aux mem
__asm__("sta $c003"); // Read aux mem
al1:
__asm__("lda ($fc)"); // *src
__asm__("sta ($fe)"); // -> *dst
__asm__("inc $fc"); // LSB of src
__asm__("bne %g", as1);
__asm__("inc $fd"); // MSB of src
as1:
__asm__("inc $fe"); // LSB of dst
__asm__("bne %g", as2);
__asm__("inc $ff"); // MSB of dst
as2:
__asm__("dec $fa"); // n
__asm__("bne %g", al1); // Loop
__asm__("sta $c002"); // Read main mem
__asm__("sta $c004"); // Write main mem
}
#else
memmove(gapbuf + dest, gapbuf + src, n);
#endif