Bug fixes. fwrite and fread now return expected values.

This commit is contained in:
Scott Duensing 2024-02-05 19:47:48 -06:00
parent bc01375056
commit 94a84e3920
3 changed files with 29 additions and 22 deletions

View file

@ -182,11 +182,11 @@ int16_t fileRead(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd) {
while (gathered < bytes) {
returned = kernelRead(*fd, data + gathered, bytes - gathered);
if (returned <= 0) break;
if (returned <= 0) return -1;
gathered += returned;
}
return gathered;
return nmemb;
}
@ -382,7 +382,7 @@ int16_t fileWrite(void *buf, uint16_t nbytes, uint16_t nmemb, uint8_t *fd) {
bytes -= written;
}
return total;
return nmemb;
}

View file

@ -74,21 +74,30 @@ void textClear(void) {
}
// Define text color.
void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb) {
void textDefineBackgroundColor(byte slot, byte r, byte g, byte b) {
byte *write;
write = (byte *)VKY_TXT_BGLUT + mathUnsignedMultiply(slot, 4);
*write++ = b;
*write++ = g;
*write++ = r;
*write++ = 0xff;
}
void textDefineForegroundColor(byte slot, byte r, byte g, byte b) {
byte *write;
write = (byte *)VKY_TXT_FGLUT + mathUnsignedMultiply(slot, 4);
*write++ = fb;
*write++ = fg;
*write++ = fr;
*write++ = b;
*write++ = g;
*write++ = r;
*write++ = 0xff;
}
write = (byte *)VKY_TXT_BGLUT + mathUnsignedMultiply(slot, 4);
*write++ = bb;
*write++ = bg;
*write++ = br;
*write++ = 0xff;
void textEnableBackgroundColors(bool b) {
POKE(VKY_MSTR_CTRL_1, (PEEK(VKY_MSTR_CTRL_1) & 0xef) | (b << 4));
}
@ -210,14 +219,10 @@ void textReset(void) {
textSetCursor(0);
// Set up default text colors.
for (x=0; x<TEXTCOLORS_COUNT; x++)
textDefineColor(x,
textColors[x].r,
textColors[x].g,
textColors[x].b,
textColors[x].r,
textColors[x].g,
textColors[x].b);
for (x=0; x<TEXTCOLORS_COUNT; x++) {
textDefineForegroundColor(x, textColors[x].r, textColors[x].g, textColors[x].b);
textDefineBackgroundColor(x, textColors[x].r, textColors[x].g, textColors[x].b);
}
textClear();
}

View file

@ -62,7 +62,9 @@ extern colorT textColors[16];
void __putchar(char c); // Allows printf().
void textClear(void);
void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb);
void textDefineBackgroundColor(byte slot, byte r, byte g, byte b);
void textDefineForegroundColor(byte slot, byte r, byte g, byte b);
void textEnableBackgroundColors(bool b);
void textGetXY(byte *x, byte *y);
void textGotoXY(byte x, byte y);
void textPrint(char *message);