randrew / uxn32

Uxn emulator for Windows and Wine
169 stars 7 forks source link

Support for two new System/expansion commands #21

Open neauoire opened 6 months ago

neauoire commented 6 months ago

Added two new commands, one that's basically just memset, and another that copies a length of memory starting at the end of the data, it helps with people who want to shift memory over itself. The command 0x1 is unchanged.

https://lists.sr.ht/~rabbits/uxn/%3C6a8207b3-9261-4a1a-9850-6ed56a6540c5%40100r.co%3E

ram = u->ram;
        addr = PEEK2(d + 2);
        if(ram[addr] == 0x0) {
            Uint8 value = ram[addr + 7];
            Uint16 i, length = PEEK2(ram + addr + 1);
            Uint16 dst_page = PEEK2(ram + addr + 3), dst_addr = PEEK2(ram + addr + 5);
            int dst = (dst_page % RAM_PAGES) * 0x10000;
            for(i = 0; i < length; i++)
                ram[dst + (Uint16)(dst_addr + i)] = value;
        } else if(ram[addr] == 0x1) {
            Uint16 i, length = PEEK2(ram + addr + 1);
            Uint16 a_page = PEEK2(ram + addr + 3), a_addr = PEEK2(ram + addr + 5);
            Uint16 b_page = PEEK2(ram + addr + 7), b_addr = PEEK2(ram + addr + 9);
            int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000;
            for(i = 0; i < length; i++)
                ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)];
        } else if(ram[addr] == 0x2) {
            Uint16 i, length = PEEK2(ram + addr + 1);
            Uint16 a_page = PEEK2(ram + addr + 3), a_addr = PEEK2(ram + addr + 5);
            Uint16 b_page = PEEK2(ram + addr + 7), b_addr = PEEK2(ram + addr + 9);
            int src = (a_page % RAM_PAGES) * 0x10000, dst = (b_page % RAM_PAGES) * 0x10000;
            for(i = length - 1; i != 0xffff; i--)
                ram[dst + (Uint16)(b_addr + i)] = ram[src + (Uint16)(a_addr + i)];
        }
randrew commented 6 months ago

OK. I think I can implement this sometime in the next few weeks.