Very basic kernel support working.

This commit is contained in:
Scott Duensing 2024-01-11 19:25:58 -06:00
parent 6c21d5cac9
commit edfd5e5aee
9 changed files with 217 additions and 84 deletions

View file

@ -231,8 +231,6 @@ 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;

View file

@ -209,8 +209,6 @@ int main(void) {
bitmapSetColor(255);
draw_cube(p, t);
t += 2;
kernelUpdate();
}
return 0;

View file

@ -65,8 +65,6 @@ void bitmap(void) {
y2 = randomRead() % my;
bitmapLine(x, y, x2, y2);
kernelUpdate();
}
}
@ -85,14 +83,15 @@ void text(void) {
textPrint("\nint32_t is "); textPrintInt(sizeof(int32_t));
textPrint("\n");
textPrint("\n");
textPrint("\nEvent Size: "); textPrintInt(sizeof(kernelEvent(key.PRESSED)));
textPrint("\n\n");
textGetXY(&x, &y);
while(1) {
kernelUpdate();
//kernelCall(NextEvent);
textGotoXY(x, y);
textPrint("Pending: ");
textPrintInt(kernelGetPendingEvents());
textPrintInt(kernelGetPending());
textPrint(" ");
}
}

View file

@ -236,7 +236,7 @@ struct call_args {
struct events {
uint16_t reserved;
uint16_t deprecated;
uint16_t GAME; // joystick events
uint16_t JOYSTICK; // joystick events
uint16_t DEVICE; // deprecated
struct {
@ -318,6 +318,11 @@ struct event_mouse_t {
};
};
struct event_joystick_t {
uint8_t joy0;
uint8_t joy1;
};
struct event_fs_data_t {
uint8_t requested; // Requested number of bytes to read
uint8_t delivered; // Number of bytes actually read
@ -372,6 +377,7 @@ struct event_t {
union {
struct event_key_t key;
struct event_mouse_t mouse;
struct event_joystick_t joystick;
struct event_file_t file;
struct event_dir_t directory;
};

View file

@ -37,6 +37,9 @@ static byte _color;
static byte _active; // Current drawing page.
static void bitmapPutPixelIOSet(uint16_t x, uint16_t y);
void bitmapClear(void) {
#ifdef BOOM
dmaFill(_BITMAP_BASE[_active], _PAGE_SIZE, _color);
@ -45,8 +48,18 @@ void bitmapClear(void) {
byte block = _BITMAP_BASE[_active] / EIGHTK;
byte x;
uint16_t c;
byte mmu;
byte ram;
volatile byte *mem = (byte *)SWAP_ADDR;
// Hoping the compiler optimizes this out when not needed. :-)
if (SWAP_SLOT == MMU_MEM_BANK_6) {
mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
ram = PEEK(MMU_MEM_BANK_6); // Get current slot 6 contents.
asm("sei");
POKE(MMU_IO_CTRL, 4); // Turn off I/O window.
}
// Clear full 8k blocks.
for (x=0; x<9; x++) {
POKE(SWAP_SLOT, block++);
@ -55,6 +68,12 @@ void bitmapClear(void) {
// Clear last partial block.
POKE(SWAP_SLOT, block);
for (c=0; c<5120; c++) mem[c] = _color;
if (SWAP_SLOT == MMU_MEM_BANK_6) {
POKE(MMU_MEM_BANK_6, ram); // Restore slot 6.
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
asm("cli");
}
#endif
}
@ -73,6 +92,16 @@ void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
int16_t incX;
int16_t incY;
int16_t balance;
byte mmu;
byte ram;
// Hoping the compiler optimizes this out when not needed. :-)
if (SWAP_SLOT == MMU_MEM_BANK_6) {
mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
ram = PEEK(MMU_MEM_BANK_6); // Get current slot 6 contents.
asm("sei");
POKE(MMU_IO_CTRL, 4); // Turn off I/O window.
}
if (x2 >= x1) {
dx = x2 - x1;
@ -98,7 +127,7 @@ void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
balance = dy - dx;
dx <<= 1;
while (x != x2) {
bitmapPutPixel(x, y);
bitmapPutPixelIOSet(x, y);
if (balance >= 0) {
y += incY;
balance -= dx;
@ -106,13 +135,13 @@ void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
balance += dy;
x += incX;
}
bitmapPutPixel(x, y);
bitmapPutPixelIOSet(x, y);
} else {
dx <<= 1;
balance = dx - dy;
dy <<= 1;
while (y != y2) {
bitmapPutPixel(x, y);
bitmapPutPixelIOSet(x, y);
if (balance >= 0) {
x += incX;
balance -= dy;
@ -120,12 +149,41 @@ void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
balance += dx;
y += incY;
}
bitmapPutPixel(x, y);
bitmapPutPixelIOSet(x, y);
}
if (SWAP_SLOT == MMU_MEM_BANK_6) {
POKE(MMU_MEM_BANK_6, ram); // Restore slot 6.
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
asm("cli");
}
}
void bitmapPutPixel(uint16_t x, uint16_t y) {
byte mmu;
byte ram;
// Hoping the compiler optimizes this out when not needed. :-)
if (SWAP_SLOT == MMU_MEM_BANK_6) {
mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
ram = PEEK(MMU_MEM_BANK_6); // Get current slot 6 contents.
asm("sei");
POKE(MMU_IO_CTRL, 4); // Turn off I/O window.
}
bitmapPutPixelIOSet(x, y);
if (SWAP_SLOT == MMU_MEM_BANK_6) {
POKE(MMU_MEM_BANK_6, ram); // Restore slot 6.
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
asm("cli");
}
}
// This does the actual pixel setting but depends on the I/O being umapped.
static void bitmapPutPixelIOSet(uint16_t x, uint16_t y) {
uint32_t pixelRAM;
byte block;

View file

@ -50,9 +50,9 @@ void f256Init(void) {
POKE(MMU_MEM_BANK_2, 2);
POKE(MMU_MEM_BANK_3, 3);
POKE(MMU_MEM_BANK_4, 4);
POKE(MMU_MEM_BANK_5, 5); // Don't use this - it's for the library.
// MMU_MEM_BANK_6 is always mapped to I/O.
// MMU_MEM_BANK_7 belongs to the MicroKernel.
POKE(MMU_MEM_BANK_5, 5);
//POKE(MMU_MEM_BANK_6, 6); // Don't use this - it's for the micro kernel.
//POKE(MMU_MEM_BANK_7, 7); // Don't use this - it's for the micro kernel.
kernelReset();
graphicsReset();

View file

@ -57,7 +57,7 @@ typedef unsigned char bool;
// Our stuff.
#define SWAP_SLOT MMU_MEM_BANK_5 //***TODO*** Move this to 6 to save 8k.
#define SWAP_SLOT MMU_MEM_BANK_5
#define SWAP_ADDR 0xa000

View file

@ -24,42 +24,111 @@
#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;
kernelEventT kernelEventData; // Allocate some RAM to hold event data.
kernelArgsT *kernelArgs; // Create an alias for the kernel args.
char kernelError;
/*
RTC_BUFFER .dstruct kernel.time_t
kGetTimeStamp
lda #<RTC_BUFFER
sta kernel.args.buf
lda #>RTC_BUFFER
sta kernel.args.buf+1
lda #size(kernel.time_t)
sta kernel.args.buflen
jsr kernel.Clock.GetTime
rts
*/
byte kernelGetPendingEvents(void) {
return -args->events.pending;
byte kernelGetPending(void) {
return -kernelArgs->events.pending;
}
void kernelReset(void) {
// Plop this into the zero page where the kernel can find it.
kernelArgs = (kernelArgsT *)0x00f0;
// Tell the kernel where our event buffer lives.
args->events.event = &event;
kernelUpdate();
kernelArgs->events.event = &kernelEventData;
}
void kernelUpdate(void) {
CALL(NextEvent);
}
/*
case EVENT(JOYSTICK):
// Joystick
break;
case EVENT(key.PRESSED):
// Keyboard
break;
case EVENT(key.RELEASED):
// Keyboard
break;
case EVENT(mouse.CLICKS):
// Mouse
break;
case EVENT(mouse.DELTA):
// Mouse
break;
case EVENT(block.NAME):
// Block
break;
case EVENT(block.SIZE):
// Block
break;
case EVENT(block.DATA):
// Block
break;
case EVENT(block.WROTE):
// Block
break;
case EVENT(block.FORMATTED):
// Block
break;
case EVENT(block.ERROR):
// Block
break;
case EVENT(file.NOT_FOUND):
// File
break;
case EVENT(file.OPENED):
// File
break;
case EVENT(file.DATA):
// File
break;
case EVENT(file.WROTE):
// File
break;
case EVENT(file.EOF):
// File
break;
case EVENT(file.CLOSED):
// File
break;
case EVENT(file.RENAMED):
// File
break;
case EVENT(file.DELETED):
// File
break;
case EVENT(file.ERROR):
// File
break;
case EVENT(directory.OPENED):
// Directory
break;
case EVENT(directory.VOLUME):
// Directory
break;
case EVENT(directory.FILE):
// Directory
break;
case EVENT(directory.FREE):
// Directory
break;
case EVENT(directory.EOF):
// Directory
break;
case EVENT(directory.CLOSED):
// Directory
break;
case EVENT(directory.ERROR):
// Directory
break;
// ***TODO*** Network
*/

View file

@ -34,23 +34,28 @@ extern "C"
#include "f256.h"
#define VECTOR(member) (size_t)(&((struct call *)0xff00)->member)
#define EVENT(member) (size_t)(&((struct events *)0)->member)
#define CALL(fn) \
#define kernelEvent(member) (size_t)(&((struct events *)0)->member)
#define kernelVector(member) (size_t)(&((struct call *)0xff00)->member)
#define kernelCall(fn) \
asm("jsr %[addy] \n" \
"stz %[err] \n" \
"ror %[err]" \
: [err] "+m"(error) \
: [addy] "i"(VECTOR(fn)) \
: [err] "+m"(kernelError) \
: [addy] "i"(kernelVector(fn)) \
: "a", "x", "y", "c", "v");
extern char error;
typedef struct event_t kernelEventT;
typedef struct call_args kernelArgsT;
byte kernelGetPendingEvents(void);
extern char kernelError;
extern kernelArgsT *kernelArgs;
extern kernelEventT kernelEventData;
byte kernelGetPending(void);
void kernelReset(void);
void kernelUpdate(void);
#ifdef __cplusplus