From 496ef13a946c49674813a23e3120a2af07866c95 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Sun, 21 Jan 2024 17:01:08 -0600 Subject: [PATCH] Updated api.h which was causing kernel events to be screwy. --- README | 3 + examples/sprites/helicopter.c | 170 ++++++++++++++--------------- examples/tilemap/u5map.c | 53 +++++---- f256lib/api.h | 200 +++++++++++++++++++--------------- f256lib/bitmap.c | 24 +--- f256lib/f256.h | 10 +- f256lib/text.c | 3 +- 7 files changed, 240 insertions(+), 223 deletions(-) diff --git a/README b/README index 10550d5..3bb6df1 100644 --- a/README +++ b/README @@ -68,6 +68,9 @@ proper size for your intended use and have 256 or fewer colors. The result of the conversion will be a "clut" file with the color lookup table in it as well as an "indexed" file of the pixels in your image mapped to the color table. +The image converter can also take a bitmap and slice it into 8x8, 16x16, 24x24, +or 32x32 chunks for use as sprite data. + EXAMPLES ======== diff --git a/examples/sprites/helicopter.c b/examples/sprites/helicopter.c index a33458b..ebe73ab 100644 --- a/examples/sprites/helicopter.c +++ b/examples/sprites/helicopter.c @@ -129,95 +129,93 @@ void getInput(void) { static byte twoJoy = 0; static byte keyJoy = 0; - kernelCall(NextEvent); + do { + kernelCall(NextEvent); - // Read real joysticks. - if (kernelEvent(JOYSTICK)) { - oneJoy = kernelEventData.joystick.joy0; - twoJoy = kernelEventData.joystick.joy1; - anyJoy = oneJoy | twoJoy | keyJoy; - } - - // Use keyboard as virtual joystick. - // ***TODO*** This doesn't work worth a crap. - if (kernelEvent(key.PRESSED)) { - switch (kernelEventData.key.ascii) { - case 'w': - case 'W': - keyJoy |= JOY_UP; - break; - case 'a': - case 'A': - keyJoy |= JOY_LEFT; - break; - case 's': - case 'S': - keyJoy |= JOY_DOWN; - break; - case 'd': - case 'D': - keyJoy |= JOY_RIGHT; - break; - case 'j': - case 'J': - keyJoy |= JOY_BUTTON_1; - break; - case 'k': - case 'K': - keyJoy |= JOY_BUTTON_2; - break; - case 'l': - case 'L': - keyJoy |= JOY_BUTTON_3; - break; + if (kernelEventData.type != 0) { + textPrintInt(kernelEventData.type); + textPrint(" "); + textPrintInt(kernelEvent(key.PRESSED)); + textPrint(" "); + textPrintInt(kernelEvent(key.RELEASED)); + textPrint("\n"); } - anyJoy = oneJoy | twoJoy | keyJoy; - } - if (kernelEvent(key.RELEASED)) { - switch (kernelEventData.key.ascii) { - case 'w': - case 'W': - keyJoy &= JOY_UP; - break; - case 'a': - case 'A': - keyJoy &= JOY_LEFT; - break; - case 's': - case 'S': - keyJoy &= JOY_DOWN; - break; - case 'd': - case 'D': - keyJoy &= JOY_RIGHT; - break; - case 'j': - case 'J': - keyJoy &= JOY_BUTTON_1; - break; - case 'k': - case 'K': - keyJoy &= JOY_BUTTON_2; - break; - case 'l': - case 'L': - keyJoy &= JOY_BUTTON_3; - break; - anyJoy = oneJoy | twoJoy | keyJoy; - } - } - /* - textGotoXY(0, 0); - textPrintInt(oneJoy); - textPrint(" "); - textPrintInt(twoJoy); - textPrint(" "); - textPrintInt(keyJoy); - textPrint(" "); - textPrintInt(anyJoy); - textPrint(" "); - */ + // Read real joysticks. + if (kernelEventData.type == kernelEvent(GAME)) { + oneJoy = kernelEventData.game.game0; + twoJoy = kernelEventData.game.game1; + } + + // Use keyboard as virtual joystick. + if (kernelEventData.type == kernelEvent(key.PRESSED)) { + switch (kernelEventData.key.ascii) { + case 'w': + case 'W': + keyJoy |= JOY_UP; + break; + case 'a': + case 'A': + keyJoy |= JOY_LEFT; + break; + case 's': + case 'S': + keyJoy |= JOY_DOWN; + break; + case 'd': + case 'D': + keyJoy |= JOY_RIGHT; + break; + case 'j': + case 'J': + keyJoy |= JOY_BUTTON_1; + break; + case 'k': + case 'K': + keyJoy |= JOY_BUTTON_2; + break; + case 'l': + case 'L': + keyJoy |= JOY_BUTTON_3; + break; + } + } + if (kernelEventData.type == kernelEvent(key.RELEASED)) { + switch (kernelEventData.key.ascii) { + case 'w': + case 'W': + keyJoy &= ~JOY_UP; + break; + case 'a': + case 'A': + keyJoy &= ~JOY_LEFT; + break; + case 's': + case 'S': + keyJoy &= ~JOY_DOWN; + break; + case 'd': + case 'D': + keyJoy &= ~JOY_RIGHT; + break; + case 'j': + case 'J': + keyJoy &= ~JOY_BUTTON_1; + break; + case 'k': + case 'K': + keyJoy &= ~JOY_BUTTON_2; + break; + case 'l': + case 'L': + keyJoy &= ~JOY_BUTTON_3; + break; + } + } + } while (kernelGetPending() > 0); + + // Merge inputs. Yes, this allows dumb things like LEFT and RIGHT at the same time. + anyJoy = oneJoy | twoJoy | keyJoy; } diff --git a/examples/tilemap/u5map.c b/examples/tilemap/u5map.c index fba5bb8..1dea208 100644 --- a/examples/tilemap/u5map.c +++ b/examples/tilemap/u5map.c @@ -60,35 +60,34 @@ int main(void) { tileSetScroll(0, 0, xs, 0, ys); - while(true) { + while (true) { + kernelEventData.type = 0; kernelCall(NextEvent); - if (kernelGetPending() > 0) { - if (kernelEvent(key.PRESSED)) { - switch (kernelEventData.key.ascii) { - case 'w': - case 'W': - ys--; - break; - case 'a': - case 'A': - xs--; - break; - case 's': - case 'S': - ys++; - break; - case 'd': - case 'D': - xs++; - break; - } - tileSetScroll(0, 0, xs, 0, ys); - textGotoXY(0, 0); - textPrintInt(xs); - textPrint(", "); - textPrintInt(ys); - textPrint(" "); + if (kernelEventData.type == kernelEvent(key.RELEASED)) { + switch (kernelEventData.key.ascii) { + case 'w': + case 'W': + ys--; + break; + case 'a': + case 'A': + xs--; + break; + case 's': + case 'S': + ys++; + break; + case 'd': + case 'D': + xs++; + break; } + tileSetScroll(0, 0, xs, 0, ys); + textGotoXY(0, 0); + textPrintInt(xs); + textPrint(", "); + textPrintInt(ys); + textPrint(" "); } } diff --git a/f256lib/api.h b/f256lib/api.h index 1d8e772..b82611d 100644 --- a/f256lib/api.h +++ b/f256lib/api.h @@ -1,33 +1,28 @@ /* - * This file is part of the TinyCore MicroKernel for the Foenix F256, - * Copyright 2022,2023 Jessie Oberreuter . As with - * the Linux Kernel Exception to the GPL3, programs built to run on the - * MicroKernel are expected to include this file. Doing so does not affect - * their license status. + * This file is part of the TinyCore 6502 MicroKernel, Copyright 2022 Jessie + * Oberreuter . As with the Linux Kernel Exception to + * the GPL3, programs built to run on the MicroKernel are expected to + * include this file. Doing so does not effect their license status. * - * SPDX-License-Identifier: GPL-3.0-only + * Kernel Calls Populate the kernel.arg.* variables appropriately, and then + * JSR to one of the velctors below: */ -/* - * Kernel calls populate the kernel.arg.* variables appropriately, and then - * JSR to one of the velctors below: - */ - -#ifndef kernel_h -#define kernel_h +#ifndef kernel_api_h +#define kernel_api_h #include struct call { // Mount at $ff00 - long NextEvent; // Copy the next event into user-space. - long ReadData; // Copy primary bulk event data into user-space - long ReadExt; // Copy secondary bolk event data into user-space - long Yield; // Give unused time to the kernel. - long Putch; // deprecated - long Basic; // deprecated - long dummy1; // reserved - long dummy2; // reserved + long NextEvent; // Copy the next event into user-space. + long ReadData; // Copy primary bulk event data into user-space + long ReadExt; // Copy secondary bolk event data into user-space + long Yield; // Give unused time to the kernel. + long Putch; // deprecated + long RunBlock; // + long RunNamed; // + long reserved; struct { long List; // Returns a bit-set of available block-accessible devices. @@ -57,43 +52,55 @@ struct call { // Mount at $ff00 long Close; // Close an open file. long Rename; // Rename a closed file. long Delete; // Delete a closed file. + long Seek; // Set the next read/write position within an open file. } File; struct { long Open; // Open a directory for reading. long Read; // Read a directory entry; may also return VOLUME and FREE events. long Close; // Close a directory once finished reading. + long MkDir; // Create a new directory. + long RmDir; // Deletes an existing directory. } Directory; long gate; - struct { - long GetSize; // Returns rows/cols in kernel args. - long DrawRow; // Draw text/color buffers left-to-right - long DrawColumn; // Draw text/color buffers top-to-bottom - } Display; - struct { long GetIP; // Get the local IP address. long SetIP; // Set the local IP address. long GetDNS; // Get the configured DNS IP address. long SetDNS; // Set the configured DNS IP address. - long GetTime; // - long SetTime; // - long GetSysInfo; // - long SetBPS; // Set the serial BPS (should match the SLIP router's speed). - } Config; + long SendICMP; // Send an ICMP packet (typically a ping). + long Match; // Determine if the current event matches a specific socket. + + struct { + long Init; // Initialize a 32 byte UDP socket structure. + long Send; // Send data via the supplied UDP socket structure. + long Recv; // Copy the UDP payload from the event to the user's address space. + } UDP; + + struct { + long Open; // Initialize a 256 byte TCP structure for a specified destination. + long Accept; // Initialize a 256 byte TCP structure from a received SYN packet. + long Reject; // Reply to a received TCP packet with a REJECT message. + long Send; // Accept some new data and send an ACK along with any unACK'd data. + long Recv; // Copy any new TCP bytes into the user's buf and update the socket state. + } TCP; + }; struct { - long InitUDP; // - long SendUDP; // - long RecvUDP; // - long InitTCP; // - long SendTCP; // - long RecvTCP; // - long SendICMP; // - long RecvICMP; // - } Net; + long Reset; // Re-init the display. + long GetSize; // Returns rows/cols in kernel args. + long DrawRow; // Draw text/color buffers left-to-right + long DrawColumn; // Draw text/color buffers top-to-bottom + } Display; + + struct { + long GetTime; // Get the date+time in BCD: YY,YY,MM,DD,HH,MM,SS,cS + long SetTime; // + long GetSysInfo; // + long SetBPS; // + } Config; }; // Kernel Call Arguments; mount at $f0 @@ -105,11 +112,11 @@ struct events_t { struct common_t { char dummy[8-sizeof(struct events_t)]; - void * ext; - uint8_t extlen; - void * buf; - uint8_t buflen; - void * internal; + const void * ext; + uint8_t extlen; + const void * buf; + uint8_t buflen; + void * internal; }; struct fs_mkfs_t { @@ -169,6 +176,12 @@ struct fs_delete_t { // fname_len = args.buflen }; +struct fs_seek_t { + uint8_t streak; + uint8_t cookie; + uint32_t position; +}; + struct file_t { union { struct fs_open_t open; @@ -177,6 +190,7 @@ struct file_t { struct fs_close_t close; struct fs_rename_t rename; struct fs_delete_t delete; + struct fs_seek_t seek; }; }; @@ -201,6 +215,8 @@ struct dir_t { struct dir_open_t open; struct dir_read_t read; struct dir_close_t close; + struct dir_open_t mkdir; + struct dir_open_t rmdir; }; }; @@ -236,58 +252,68 @@ struct call_args { struct events { uint16_t reserved; uint16_t deprecated; - uint16_t JOYSTICK; // joystick events + uint16_t GAME; // joystick events uint16_t DEVICE; // deprecated struct { - uint8_t PRESSED; - uint8_t RELEASED; + uint16_t PRESSED; + uint16_t RELEASED; } key; struct { - uint8_t DELTA; - uint8_t CLICKS; + uint16_t DELTA; + uint16_t CLICKS; } mouse; struct { - uint8_t NAME; - uint8_t SIZE; - uint8_t DATA; - uint8_t WROTE; - uint8_t FORMATTED; - uint8_t ERROR; + uint16_t NAME; + uint16_t SIZE; + uint16_t DATA; + uint16_t WROTE; + uint16_t FORMATTED; + uint16_t ERROR; } block; struct { - uint8_t SIZE; - uint8_t CREATED; - uint8_t CHECKED; - uint8_t DATA; - uint8_t WROTE; - uint8_t ERROR; + uint16_t SIZE; + uint16_t CREATED; + uint16_t CHECKED; + uint16_t DATA; + uint16_t WROTE; + uint16_t ERROR; } fs; struct { - uint8_t NOT_FOUND; - uint8_t OPENED; - uint8_t DATA; - uint8_t WROTE; - uint8_t EOF; - uint8_t CLOSED; - uint8_t RENAMED; - uint8_t DELETED; - uint8_t ERROR; + uint16_t NOT_FOUND; + uint16_t OPENED; + uint16_t DATA; + uint16_t WROTE; + uint16_t EOF; + uint16_t CLOSED; + uint16_t RENAMED; + uint16_t DELETED; + uint16_t ERROR; + uint16_t SEEK; } file; struct { - uint8_t OPENED; - uint8_t VOLUME; - uint8_t FILE; - uint8_t FREE; - uint8_t EOF; - uint8_t CLOSED; - uint8_t ERROR; + uint16_t OPENED; + uint16_t VOLUME; + uint16_t FILE; + uint16_t FREE; + uint16_t EOF; + uint16_t CLOSED; + uint16_t ERROR; } directory; + + struct { + uint16_t TCP; + uint16_t UDP; + } net; + + struct { + uint16_t TICK; + } clock; }; @@ -318,9 +344,9 @@ struct event_mouse_t { }; }; -struct event_joystick_t { - uint8_t joy0; - uint8_t joy1; +struct event_game_t { + uint8_t game0; + uint8_t game1; }; struct event_fs_data_t { @@ -375,11 +401,11 @@ struct event_t { uint8_t buf; // kernel's buf page ID uint8_t ext; // kernel's ext page ID 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; + struct event_key_t key; + struct event_mouse_t mouse; + struct event_game_t game; + struct event_file_t file; + struct event_dir_t directory; }; }; #endif diff --git a/f256lib/bitmap.c b/f256lib/bitmap.c index 040dd10..63235b7 100644 --- a/f256lib/bitmap.c +++ b/f256lib/bitmap.c @@ -36,9 +36,8 @@ static byte _BITMAP_CLUT[3]; static byte _color; static byte _active; // Current drawing page. -#define bitmapPutPixelIOSet(x, y) FAR_POKE((_BITMAP_BASE[_active] + mathUnsignedAddition(mathUnsignedMultiply(y, _MAX_X), (int32_t)x)), _color) -//static void bitmapPutPixelIOSet(uint16_t x, uint16_t y); +#define bitmapPutPixelIOSet(x, y) FAR_POKE((_BITMAP_BASE[_active] + mathUnsignedAddition(mathUnsignedMultiply(y, _MAX_X), (int32_t)x)), _color) void bitmapClear(void) { @@ -144,21 +143,6 @@ void bitmapPutPixel(uint16_t x, uint16_t y) { } -/* -// 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; - - pixelRAM = _BITMAP_BASE[_active] + mathUnsignedAddition(mathUnsignedMultiply(y, _MAX_X), (int32_t)x); - block = pixelRAM / EIGHTK; - pixelRAM &= 0x1FFF; // Find offset into this block. - POKE(SWAP_SLOT, block); - POKE(SWAP_ADDR + pixelRAM, _color); -} -*/ - - void bitmapReset(void) { uint32_t realSize; uint32_t pageBlocks; @@ -250,13 +234,13 @@ void bitmapSetColor(byte c) { void bitmapSetVisible(byte p, bool v) { switch (p) { case 0: - POKE(VKY_BM0_CTRL, v ? 1 | _BITMAP_CLUT[p] : 0); // Enable bitmap 0, GLUT 0. + POKE(VKY_BM0_CTRL, v ? 1 | _BITMAP_CLUT[p] : 0); // Enable bitmap 0. break; case 1: - POKE(VKY_BM1_CTRL, v ? 1 | _BITMAP_CLUT[p] : 0); // Enable bitmap 0, GLUT 0. + POKE(VKY_BM1_CTRL, v ? 1 | _BITMAP_CLUT[p] : 0); // Enable bitmap 1. break; case 2: - POKE(VKY_BM2_CTRL, v ? 1 | _BITMAP_CLUT[p] : 0); // Enable bitmap 0, GLUT 0. + POKE(VKY_BM2_CTRL, v ? 1 | _BITMAP_CLUT[p] : 0); // Enable bitmap 2. break; } } diff --git a/f256lib/f256.h b/f256lib/f256.h index 4784441..2cfe034 100644 --- a/f256lib/f256.h +++ b/f256lib/f256.h @@ -58,10 +58,9 @@ typedef unsigned char bool; // Our stuff. #define SWAP_SLOT MMU_MEM_BANK_5 -#define SWAP_ADDR ((uint16_t)(SWAP_SLOT - MMU_MEM_BANK_0) * (uint16_t)0x2000) // This is an attempt to allow us to free up slot 5 and use slot 6 for paging -// RAM in and out. Currently, it does not work. +// RAM in and out. ***TODO*** Currently, it does not work. #if SWAP_SLOT == MMU_MEM_BANK_6 #define SWAP_IO_SETUP() \ @@ -78,6 +77,11 @@ typedef unsigned char bool; asm("cli"); \ }) +#elif SWAP_SLOT == MMU_MEM_BANK_7 + +#define SWAP_IO_SETUP() asm("sei"); +#define SWAP_IO_SHUTDOWN() asm("cli"); + #else #define SWAP_IO_SETUP() @@ -85,6 +89,8 @@ typedef unsigned char bool; #endif +#define SWAP_ADDR ((uint16_t)(SWAP_SLOT - MMU_MEM_BANK_0) * (uint16_t)0x2000) + // Things not in the Merlin defs. #define TEXT_MATRIX 0xc000 // I/O Page 2 diff --git a/f256lib/text.c b/f256lib/text.c index 3ca4904..a6bf775 100644 --- a/f256lib/text.c +++ b/f256lib/text.c @@ -192,7 +192,6 @@ void textPrintUInt(uint32_t value){ } -// Reset display to text, "standard" colors. void textReset(void) { byte x; byte y; @@ -239,6 +238,8 @@ void textSetCursor(byte c) { void textSetDouble(bool x, bool y) { + //***TODO*** Adding this function seems to have screwed up scrolling. + POKE(VKY_MSTR_CTRL_1, (PEEK(VKY_MSTR_CTRL_1) & 0xf9) | (x << 1) | (y << 2)); _MAX_COL = x ? 40 : 80;