diff --git a/samples/memmap/allmem.c b/samples/memmap/allmem.c new file mode 100644 index 0000000..725730a --- /dev/null +++ b/samples/memmap/allmem.c @@ -0,0 +1,48 @@ +#include +#include +#include + +// make space until 0x1000 by for the stack + +#pragma region( stack, 0x0a00, 0x1000, , , {stack} ) + +// everything beyond will be code, data, bss and heap to the end + +#pragma region( main, 0x1000, 0xfff0, , , {code, data, bss, heap} ) + +int main(void) +{ + // Install the IRQ trampoline + + mmap_trampoline(); + + // Hide the basic ROM, must be first instruction + + mmap_set(MMAP_RAM); + + // Allocate all memory + + unsigned total = 0; + while (char * data = malloc(1024)) + { + total += 1024; + + // Swap in kernal for print + + mmap_set(MMAP_NO_BASIC); + printf("ALLOCATED %5u AT %04x\n", total, (unsigned)data); + mmap_set(MMAP_RAM); + + // Fill it with trash + + for(unsigned i=0; i<1024; i++) + data[i] = 0xaa; + } + + // Return basic ROM to normal state + + mmap_set(MMAP_ROM); + + return 0; +} + diff --git a/samples/memmap/largemem.c b/samples/memmap/largemem.c new file mode 100644 index 0000000..dbc6ecf --- /dev/null +++ b/samples/memmap/largemem.c @@ -0,0 +1,35 @@ +#include +#include +#include + +// make space until 0xd000 by extending the default region + +#pragma region( main, 0x0a00, 0xd000, , , {code, data, bss, heap, stack} ) + +int main(void) +{ + // Hide the basic ROM, must be first instruction + + mmap_set(MMAP_NO_BASIC) + + // Allocate all memory + + unsigned total = 0; + while (char * data = malloc(1024)) + { + total += 1024; + + printf("ALLOCATED %5u AT %04x\n", total, (unsigned)data); + + // Fill it with trash + + for(unsigned i=0; i<1024; i++) + data[i] = 0xaa; + } + + // Return basic ROM to normal state + + mmap_set(MMAP_ROM) + + return 0; +} diff --git a/samples/memmap/make.bat b/samples/memmap/make.bat new file mode 100644 index 0000000..a763ce6 --- /dev/null +++ b/samples/memmap/make.bat @@ -0,0 +1,2 @@ +..\..\bin\oscar64 largemem.c +..\..\bin\oscar64 allmem.c diff --git a/samples/scrolling/colorram.c b/samples/scrolling/colorram.c new file mode 100644 index 0000000..efa964e --- /dev/null +++ b/samples/scrolling/colorram.c @@ -0,0 +1,136 @@ +#include +#include +#include +#include + +#define screen ((byte *)0x0400) +#define color ((byte *)0xd800) +#define sline(x, y) (screen + 40 * (y) + (x)) +#define cline(x, y) (color + 40 * (y) + (x)) + +char rbuff[25], cbuff[25]; + +#define SPLIT1 8 +#define SPLIT2 16 + +void scrollLeft0(void) +{ + for(char x=0; x<39; x++) + { +#assign y 0 +#repeat + sline(0, y)[x] = sline(1, y)[x]; + cline(0, y)[x] = cline(1, y)[x]; +#assign y y + 1 +#until y == SPLIT1 + } +#assign y 0 +#repeat + sline(0, y)[39] = rbuff[y]; + cline(0, y)[39] = cbuff[y]; +#assign y y + 1 +#until y == SPLIT1 +} + +void scrollLeft1(void) +{ + for(char x=0; x<39; x++) + { +#assign y SPLIT1 +#repeat + sline(0, y)[x] = sline(1, y)[x]; + cline(0, y)[x] = cline(1, y)[x]; +#assign y y + 1 +#until y == SPLIT2 + } +#assign y SPLIT1 +#repeat + sline(0, y)[39] = rbuff[y]; + cline(0, y)[39] = cbuff[y]; +#assign y y + 1 +#until y == SPLIT2 + for(char x=0; x<39; x++) + { +#assign y SPLIT2 +#repeat + sline(0, y)[x] = sline(1, y)[x]; + cline(0, y)[x] = cline(1, y)[x]; +#assign y y + 1 +#until y == 25 + } +#assign y SPLIT2 +#repeat + sline(0, y)[39] = rbuff[y]; + cline(0, y)[39] = cbuff[y]; +#assign y y + 1 +#until y == 25 +} + + +inline void waitTop(void) +{ + while ((vic.ctrl1 & VIC_CTRL1_RST8)) + ; +} + +inline void waitBottom(void) +{ + while (!(vic.ctrl1 & VIC_CTRL1_RST8)) + ; +} + +inline void waitSync(void) +{ + while (vic.raster != 50 + 8 * SPLIT1) + ; +} + +void prepcol(void) +{ + for(char i=0; i<25; i++) + { + unsigned r = rand(); + cbuff[i] = r & 15; + rbuff[i] = (r & 16) ? 102 : 160; + } +} + +int main(void) +{ + memset(screen, 0x20, 1000); + memset(color, 7, 1000); + + vic.color_back = VCOL_BLACK; + vic.color_border = VCOL_BLACK; + + char x = 0; + + for(;;) + { + x = (x + 1) & 7; + + if (x == 0) + { + waitSync(); + scrollLeft0(); + } + + waitBottom(); + + vic.ctrl2 = (7 - x) & 7; + + if (x == 0) + { + scrollLeft1(); + } + else + { + if (x == 4) + prepcol(); + waitTop(); + } + } + + return 0; + +} diff --git a/samples/scrolling/make.bat b/samples/scrolling/make.bat index 5d18a5d..764d578 100644 --- a/samples/scrolling/make.bat +++ b/samples/scrolling/make.bat @@ -1,3 +1,4 @@ ..\..\bin\oscar64 bigfont.c -n ..\..\bin\oscar64 tunnel.c -n ..\..\bin\oscar64 grid2d.c -n +..\..\bin\oscar64 colorram.c -n