Various fixes.

This commit is contained in:
Scott Duensing 2024-02-01 19:45:09 -06:00
parent 400b35cd25
commit 9415a2ebc2
10 changed files with 59 additions and 17 deletions

View file

@ -68,15 +68,19 @@ void dirtest(void) {
int main(void) { int main(void) {
struct time_t clock;
f256Init(); f256Init();
//dirtest(); //dirtest();
while(true) { while(true) {
kernelNextEvent(); kernelNextEvent();
kernelArgs->common.buf = &clock;
kernelArgs->common.buflen = sizeof(struct time_t);
kernelCall(Clock.GetTime); kernelCall(Clock.GetTime);
textGotoXY(0, 0); textGotoXY(0, 0);
printf("%d.%d ", kernelArgs->time.seconds, kernelArgs->time.centis); printf("%d.%d ", clock.seconds, clock.centis);
} }
return 0; return 0;

View file

@ -287,7 +287,6 @@ struct call_args {
struct display_t display; struct display_t display;
struct net_t net; struct net_t net;
struct timer_t timer; struct timer_t timer;
struct time_t time;
}; };
}; };

View file

@ -61,10 +61,7 @@ void f256Init(void) {
tileReset(); tileReset();
spriteReset(); spriteReset();
fileReset(); fileReset();
randomReset();
//***TODO*** The clock stuff doesn't actually work.
kernelCall(Clock.GetTime);
randomSeed(kernelArgs->time.centis);
} }
@ -85,6 +82,22 @@ byte FAR_PEEK(uint32_t address) {
} }
uint16_t FAR_PEEKW(uint32_t address) {
byte block;
uint16_t result;
SWAP_IO_SETUP();
block = address / EIGHTK;
address &= 0x1FFF; // Find offset into this block.
POKE(SWAP_SLOT, block);
result = PEEKW(SWAP_ADDR + address);
SWAP_IO_SHUTDOWN();
return result;
}
void FAR_POKE(uint32_t address, byte value) { void FAR_POKE(uint32_t address, byte value) {
byte block; byte block;
@ -98,3 +111,18 @@ void FAR_POKE(uint32_t address, byte value) {
SWAP_IO_SHUTDOWN(); SWAP_IO_SHUTDOWN();
} }
void FAR_POKEW(uint32_t address, uint16_t value) {
byte block;
SWAP_IO_SETUP();
block = address / EIGHTK;
address &= 0x1FFF; // Find offset into this block.
POKE(SWAP_SLOT, block);
POKEW(SWAP_ADDR + address, value);
SWAP_IO_SHUTDOWN();
}

View file

@ -147,6 +147,7 @@ typedef struct colorS {
#define LOW_BYTE(v) ((byte)(x)) #define LOW_BYTE(v) ((byte)(x))
#define HIGH_BYTE(v) ((byte)(((uint16_t)(x)) >> 8)) #define HIGH_BYTE(v) ((byte)(((uint16_t)(x)) >> 8))
#define SWAP_NIBBLES(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4) #define SWAP_NIBBLES(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4)
#define SWAP_UINT16(x) (((x) >> 8) | ((x) << 8))
#define CHECK_BIT(x, pos) (x & (1UL << pos)) #define CHECK_BIT(x, pos) (x & (1UL << pos))
#define TOGGLE_BIT(x, pos) (x ^= (1U << pos)) #define TOGGLE_BIT(x, pos) (x ^= (1U << pos))
#define CLEAR_BIT(x, pos) (x &= (~(1U << pos))) #define CLEAR_BIT(x, pos) (x &= (~(1U << pos)))
@ -158,7 +159,9 @@ extern byte SOF;
void f256Init(void); void f256Init(void);
byte FAR_PEEK(uint32_t address); byte FAR_PEEK(uint32_t address);
uint16_t FAR_PEEKW(uint32_t address);
void FAR_POKE(uint32_t address, byte value); void FAR_POKE(uint32_t address, byte value);
void FAR_POKEW(uint32_t address, uint16_t value);
#include "kernel.h" #include "kernel.h"

View file

@ -105,10 +105,10 @@ int8_t fileMakeDir(char *dir) {
} }
int16_t *fileOpen(char *fname, char *mode) { uint8_t *fileOpen(char *fname, char *mode) {
int16_t ret = 0; uint8_t ret = 0;
uint8_t m = 0; // Default to READ. uint8_t m = 0; // Default to READ.
int16_t *fd; uint8_t *fd;
byte drive; byte drive;
char *c; char *c;
@ -132,7 +132,7 @@ int16_t *fileOpen(char *fname, char *mode) {
kernelNextEvent(); kernelNextEvent();
switch (kernelEventData.type) { switch (kernelEventData.type) {
case kernelEvent(file.OPENED): case kernelEvent(file.OPENED):
fd = (int16_t *)malloc(sizeof(int16_t)); fd = (uint8_t *)malloc(sizeof(uint8_t));
*fd = ret; *fd = ret;
return fd; return fd;
case kernelEvent(file.NOT_FOUND): case kernelEvent(file.NOT_FOUND):

View file

@ -44,7 +44,7 @@ typedef struct fileDirEntS {
void fileClose(uint8_t *fd); void fileClose(uint8_t *fd);
int8_t fileCloseDir(char *dir); int8_t fileCloseDir(char *dir);
int8_t fileMakeDir(char *dir); int8_t fileMakeDir(char *dir);
int16_t *fileOpen(char *fname, char *mode); uint8_t *fileOpen(char *fname, char *mode);
char *fileOpenDir(char *name); char *fileOpenDir(char *name);
int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd); int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd);
fileDirEntT *fileReadDir(char *dir); fileDirEntT *fileReadDir(char *dir);
@ -56,10 +56,6 @@ int8_t fileUnlink(char *name);
int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd); int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd);
// mkdir
// rmdir
#define _DE_ISREG(t) (t == 0) #define _DE_ISREG(t) (t == 0)
#define _DE_ISDIR(t) (t == 1) #define _DE_ISDIR(t) (t == 1)
#define _DE_ISLBL(t) (t == 2) #define _DE_ISLBL(t) (t == 2)
@ -73,6 +69,7 @@ int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd);
#define DIR char #define DIR char
#define dirent fileDirEntS #define dirent fileDirEntS
#define FILE uint8_t #define FILE uint8_t
#define fclose fileClose
#define fopen fileOpen #define fopen fileOpen
#define fread fileRead #define fread fileRead
#define fseek fileSeek #define fseek fileSeek

View file

@ -58,7 +58,6 @@ typedef struct call_args kernelArgsT;
extern kernelEventT kernelEventData; extern kernelEventT kernelEventData;
extern kernelArgsT *kernelArgs; extern kernelArgsT *kernelArgs;
extern char kernelError;
byte kernelGetPending(void); byte kernelGetPending(void);

View file

@ -35,7 +35,7 @@ extern "C"
void __putchar(char c); void __putchar(char c);
int getchar(void); int getchar(void); // This is an int so llvm-mos finds it.
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -34,6 +34,17 @@ uint16_t randomRead(void) {
} }
void randomReset(void) {
struct time_t clock;
// Seed the random number generator from the clock.
kernelArgs->common.buf = &clock;
kernelArgs->common.buflen = sizeof(struct time_t);
kernelCall(Clock.GetTime);
randomSeed(mathUnsignedMultiply(clock.seconds, clock.centis));
}
void randomSeed(uint16_t seed) { void randomSeed(uint16_t seed) {
POKEW(VKY_SEEDL, seed); POKEW(VKY_SEEDL, seed);
POKE(VKY_RND_CTRL, 3); // Enable, load seed. POKE(VKY_RND_CTRL, 3); // Enable, load seed.

View file

@ -35,6 +35,7 @@ extern "C"
uint16_t randomRead(void); uint16_t randomRead(void);
void randomReset(void);
void randomSeed(uint16_t seed); void randomSeed(uint16_t seed);