diff --git a/examples/cube-pre/build.sh b/examples/cube-pre/build.sh index 03be1e9..0b5ef2d 100755 --- a/examples/cube-pre/build.sh +++ b/examples/cube-pre/build.sh @@ -24,13 +24,13 @@ PROJECT=cube-pre +START=0x200 + F256=$(pwd)/../.. LLVM=${F256}/llvm-mos SETTINGS=${LLVM}/mos-platform/f256k/lib/settings.ld PATH=${LLVM}/bin:${PATH} -START=0x200 - echo "__f256_start = ${START};" > ${SETTINGS} CLANG="mos-f256k-clang -I${F256}/include -I${F256}/f256lib -O3" diff --git a/examples/cube-pre/cube-pre.c b/examples/cube-pre/cube-pre.c index cb296c4..8fdd338 100644 --- a/examples/cube-pre/cube-pre.c +++ b/examples/cube-pre/cube-pre.c @@ -195,6 +195,7 @@ int main(void) { cubeProjX[i] = TO_LONG(fix_mul(cubeProjX[i], scale)) + widthOffset; cubeProjY[i] = TO_LONG(fix_mul(cubeProjY[i], scale)) + heightOffset; } + l = 0; for (i=0; i<24; i += 2) { line[l][t].x1 = cubeProjX[edges[i]]; @@ -203,6 +204,8 @@ int main(void) { line[l][t].y2 = cubeProjY[edges[i + 1]]; l++; } + + kernelUpdate(); } textClear(); @@ -228,6 +231,8 @@ int main(void) { for (i=0; i<12; i++) bitmapLine(line[i][p].x1, line[i][p].y1, line[i][p].x2, line[i][p].y2); l++; p++; + + kernelUpdate(); } return 0; diff --git a/examples/cube/build.sh b/examples/cube/build.sh index 3583c40..640e977 100755 --- a/examples/cube/build.sh +++ b/examples/cube/build.sh @@ -23,29 +23,31 @@ # +PROJECT=cube +START=0x200 + + F256=$(pwd)/../.. LLVM=${F256}/llvm-mos SETTINGS=${LLVM}/mos-platform/f256k/lib/settings.ld PATH=${LLVM}/bin:${PATH} -START=0x2000 - echo "__f256_start = ${START};" > ${SETTINGS} CLANG="mos-f256k-clang -I${F256}/include -I${F256}/f256lib -O3" ${CLANG} -c ${F256}/f256lib/f256.c -${CLANG} -c cube.c -${CLANG} -o cube cube.o f256.o +${CLANG} -c ${PROJECT}.c +${CLANG} -o ${PROJECT} ${PROJECT}.o f256.o -mv -f cube cube.bin +mv -f ${PROJECT} ${PROJECT}.bin ${F256}/header/header \ pgz 24 \ - cube.pgz \ + ${PROJECT}.pgz \ ${START} \ - cube.bin ${START} + ${PROJECT}.bin ${START} -#llvm-nm cube.elf > cube.lst -llvm-objdump -d --print-imm-hex cube.elf > cube.lst -hexdump -C cube.pgz > cube.hex +#llvm-nm ${PROJECT}.elf > ${PROJECT}.lst +llvm-objdump -d --print-imm-hex ${PROJECT}.elf > ${PROJECT}.lst +hexdump -C ${PROJECT}.pgz > ${PROJECT}.hex diff --git a/examples/cube/cube.c b/examples/cube/cube.c index 48b6924..e53556a 100644 --- a/examples/cube/cube.c +++ b/examples/cube/cube.c @@ -209,6 +209,8 @@ int main(void) { bitmapSetColor(255); draw_cube(p, t); t += 2; + + kernelUpdate(); } return 0; diff --git a/examples/pgztest/build.sh b/examples/pgztest/build.sh index 019e550..440b54a 100755 --- a/examples/pgztest/build.sh +++ b/examples/pgztest/build.sh @@ -23,29 +23,30 @@ # +PROJECT=pgztest +START=0x200 + F256=$(pwd)/../.. LLVM=${F256}/llvm-mos SETTINGS=${LLVM}/mos-platform/f256k/lib/settings.ld PATH=${LLVM}/bin:${PATH} -START=0x2000 - echo "__f256_start = ${START};" > ${SETTINGS} -CLANG="mos-f256k-clang -I${F256}/include -I${F256}/f256lib -Os" +CLANG="mos-f256k-clang -I${F256}/include -I${F256}/f256lib -O3" ${CLANG} -c ${F256}/f256lib/f256.c -${CLANG} -c pgztest.c -${CLANG} -o pgztest pgztest.o f256.o +${CLANG} -c ${PROJECT}.c +${CLANG} -o ${PROJECT} ${PROJECT}.o f256.o -mv -f pgztest pgztest.bin +mv -f ${PROJECT} ${PROJECT}.bin ${F256}/header/header \ pgz 24 \ - pgztest.pgz \ + ${PROJECT}.pgz \ ${START} \ - pgztest.bin ${START} + ${PROJECT}.bin ${START} -#llvm-nm pgztest.elf > pgztest.lst -llvm-objdump -d --print-imm-hex pgztest.elf > pgztest.lst -hexdump -C pgztest.pgz > pgztest.hex +#llvm-nm ${PROJECT}.elf > ${PROJECT}.lst +llvm-objdump -d --print-imm-hex ${PROJECT}.elf > ${PROJECT}.lst +hexdump -C ${PROJECT}.pgz > ${PROJECT}.hex diff --git a/examples/pgztest/pgztest.c b/examples/pgztest/pgztest.c index c290b86..ca6c2cc 100644 --- a/examples/pgztest/pgztest.c +++ b/examples/pgztest/pgztest.c @@ -65,11 +65,16 @@ void bitmap(void) { y2 = randomRead() % my; bitmapLine(x, y, x2, y2); + + kernelUpdate(); } } void text(void) { + byte x; + byte y; + textPrint("F256 LIVES!\n"); textSetColor(LIGHT_GREEN, BLACK); textPrint("Green!\n\n"); @@ -79,12 +84,23 @@ void text(void) { textPrint("\nint16_t is "); textPrintInt(sizeof(int16_t)); textPrint("\nint32_t is "); textPrintInt(sizeof(int32_t)); textPrint("\n"); + + textPrint("\n"); + textGetXY(&x, &y); + + while(1) { + kernelUpdate(); + textGotoXY(x, y); + textPrint("Pending: "); + textPrintInt(kernelGetPendingEvents()); + textPrint(" "); + } } int main(void) { f256Init(); text(); - bitmap(); + //bitmap(); return 0; } diff --git a/f256lib/dma.c b/f256lib/dma.c index a741ea4..9c22197 100644 --- a/f256lib/dma.c +++ b/f256lib/dma.c @@ -53,6 +53,9 @@ void dma2dFill(uint32_t start, uint16_t width, uint16_t height, uint16_t stride, static void dmaWait(void) { + + //***FIX*** This whole block seems unneeded if DMA halts the CPU while it transfers. + // First, wait for DMA to be complete. while (PEEK(DMA_STATUS) & DMA_STAT_BUSY) // Spin our wheels. diff --git a/f256lib/f256.c b/f256lib/f256.c index 11bebec..4ac0b23 100644 --- a/f256lib/f256.c +++ b/f256lib/f256.c @@ -54,11 +54,12 @@ void f256Init(void) { // MMU_MEM_BANK_6 is always mapped to I/O. // MMU_MEM_BANK_7 belongs to the MicroKernel. - randomSeed(0); //***TODO*** Use clock or something. - + kernelReset(); graphicsReset(); textReset(); bitmapReset(); tileReset(); spriteReset(); + + randomSeed(0); //***TODO*** Use clock or something. } diff --git a/f256lib/kernel.c b/f256lib/kernel.c index 28fcc82..512e8ce 100644 --- a/f256lib/kernel.c +++ b/f256lib/kernel.c @@ -24,6 +24,11 @@ #include "kernel.h" +// Allocate some RAM to hold event data. +static struct event_t event; +// Create an alias for the kernel args. +static struct call_args *args = (struct call_args *)0x00f0; + char error; @@ -40,3 +45,21 @@ kGetTimeStamp jsr kernel.Clock.GetTime rts */ + + +byte kernelGetPendingEvents(void) { + return -args->events.pending; +} + + +void kernelReset(void) { + // Tell the kernel where our event buffer lives. + args->events.event = &event; + + kernelUpdate(); +} + + +void kernelUpdate(void) { + CALL(NextEvent); +} diff --git a/f256lib/kernel.h b/f256lib/kernel.h index 1c789c4..5965cf8 100644 --- a/f256lib/kernel.h +++ b/f256lib/kernel.h @@ -34,8 +34,8 @@ extern "C" #include "f256.h" -#define VECTOR(member) (size_t)(&((struct call *)0xff00)->member) -#define EVENT(member) (size_t)(&((struct events *)0)->member) +#define VECTOR(member) (size_t)(&((struct call *)0xff00)->member) +#define EVENT(member) (size_t)(&((struct events *)0)->member) #define CALL(fn) \ asm("jsr %[addy] \n" \ "stz %[err] \n" \ @@ -45,8 +45,12 @@ extern "C" : "a", "x", "y", "c", "v"); -extern struct event_t event; // The event struct is allocated in crt0. Or is it? -extern char error; +extern char error; + + +byte kernelGetPendingEvents(void); +void kernelReset(void); +void kernelUpdate(void); #ifdef __cplusplus diff --git a/f256lib/text.c b/f256lib/text.c index 7aba65c..1553a09 100644 --- a/f256lib/text.c +++ b/f256lib/text.c @@ -92,6 +92,12 @@ void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byt } +void textGetXY(byte *x, byte *y) { + *x = _col; + *y = _row; +} + + // Move cursor. void textGotoXY(byte x, byte y) { _col = x; diff --git a/f256lib/text.h b/f256lib/text.h index f9a0a4a..96f2627 100644 --- a/f256lib/text.h +++ b/f256lib/text.h @@ -61,6 +61,7 @@ extern colorT textColors[16]; void textClear(void); void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb); +void textGetXY(byte *x, byte *y); void textGotoXY(byte x, byte y); void textPrint(char *message); void textPrintInt(int32_t value);