Renamed text functions to match the rest of the library. Starting math routines.

This commit is contained in:
Scott Duensing 2024-01-07 18:24:45 -06:00
parent af68da6cb5
commit a36ef5c495
10 changed files with 116 additions and 53 deletions

View file

@ -172,9 +172,6 @@ int main(void) {
f256Init();
resetText();
bitmapReset();
while(1) {
if (p) {
p = 0;

View file

@ -38,8 +38,6 @@ void bitmap(void) {
byte l;
byte c = 0;
bitmapReset();
bitmapGetResolution(&mx, &my);
for (l=0; l<TEXTCOLORS_COUNT; l++)
@ -83,16 +81,15 @@ void bitmap(void) {
void text(void) {
resetText();
print("F256 LIVES!\n");
setTextColor(LIGHT_GREEN, BLACK);
print("Green!\n\n");
setTextColor(ORANGE, BLACK);
print("byte is "); printInt(sizeof(byte));
print("\nint is "); printInt(sizeof(int));
print("\nint16_t is "); printInt(sizeof(int16_t));
print("\nint32_t is "); printInt(sizeof(int32_t));
print("\n");
textPrint("F256 LIVES!\n");
textSetColor(LIGHT_GREEN, BLACK);
textPrint("Green!\n\n");
textSetColor(ORANGE, BLACK);
textPrint("byte is "); textPrintInt(sizeof(byte));
textPrint("\nint is "); textPrintInt(sizeof(int));
textPrint("\nint16_t is "); textPrintInt(sizeof(int16_t));
textPrint("\nint32_t is "); textPrintInt(sizeof(int32_t));
textPrint("\n");
}

View file

@ -36,9 +36,6 @@ static byte _color;
static byte _page;
char error;
void bitmapClear(void) {
#ifdef BOOM
dmaFill(_BITMAP_BASE[_page], _PAGE_SIZE, _color);
@ -180,9 +177,11 @@ void bitmapReset(void) {
_BITMAP_BASE[1] = _BITMAP_BASE[0] + realSize; // Page 2 = 0x24000
_BITMAP_BASE[2] = _BITMAP_BASE[1] + realSize; // Page 3 = 0x38000
print("\nbase0 = "); printInt(_BITMAP_BASE[0]);
print("\nbase1 = "); printInt(_BITMAP_BASE[1]);
print("\nbase2 = "); printInt(_BITMAP_BASE[2]);
/*
textPrint("\nbase0 = "); textPrintInt(_BITMAP_BASE[0]);
textPrint("\nbase1 = "); textPrintInt(_BITMAP_BASE[1]);
textPrint("\nbase2 = "); textPrintInt(_BITMAP_BASE[2]);
*/
// Set palette to a gradient so there's at least *something*.
for (x=0; x<256; x++) bitmapDefineColor(x, x, x, x);

View file

@ -24,9 +24,6 @@
#include "dma.h"
char error;
static void dmaWait(void);

View file

@ -26,6 +26,10 @@
#include "text.c"
#include "bitmap.c"
#include "dma.c"
#include "math.h"
char error;
void f256Init(void) {
@ -56,6 +60,9 @@ void f256Init(void) {
// MMU_MEM_BANK_7 belongs to the MicroKernel.
randomSeed(0); //***TODO*** Use clock or something.
textReset();
bitmapReset();
}

View file

@ -57,6 +57,13 @@ typedef unsigned char byte;
#define RAST_ROW_H 0xd01b
typedef struct colorS {
byte r;
byte g;
byte b;
} colorT;
// Single-byte
#define PEEK(addy) ((byte)*(volatile byte *)(addy))
#define POKE(addy, value) (*(volatile byte *)(addy) = (value))
@ -97,6 +104,7 @@ void waitVerticalBlank(void);
#include "text.h"
#include "bitmap.h"
#include "dma.h"
#include "math.h"
#ifdef __cplusplus

24
f256lib/math.c Normal file
View file

@ -0,0 +1,24 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "math.h"

42
f256lib/math.h Normal file
View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Scott Duensing, scott@kangaroopunch.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MATH_H
#define MATH_H
#ifdef __cplusplus
extern "C"
{
#endif
#include "f256.h"
#ifdef __cplusplus
}
#endif
#endif // MATH_H

View file

@ -24,9 +24,6 @@
#include "text.h"
char error;
colorT textColors[16] = {
{ 0x00, 0x00, 0x00 }, // 0 Black
{ 0xdd, 0x00, 0x33 }, // 1 Deep Red
@ -57,7 +54,7 @@ static byte _ccolor = 240;
// Clear screen to current text attributes.
void cls(void) {
void textClear(void) {
int i;
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
volatile byte *vram = (byte *)TEXT_MATRIX;
@ -71,12 +68,12 @@ void cls(void) {
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
gotoxy(0, 0);
textGotoXY(0, 0);
}
// Define text color.
void defineTextColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb) {
void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
byte *write;
@ -99,7 +96,7 @@ void defineTextColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byt
// Move cursor.
void gotoxy(byte x, byte y) {
void textGotoXY(byte x, byte y) {
byte mmu;
mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
@ -118,7 +115,7 @@ void gotoxy(byte x, byte y) {
// Print a string to the screen.
void print(char *message) {
void textPrint(char *message) {
int x = 0;
int i = 0;
int j = 0;
@ -169,28 +166,28 @@ void print(char *message) {
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
gotoxy(_col, _row);
textGotoXY(_col, _row);
}
void printInt(int32_t value){
void textPrintInt(int32_t value){
char c[2];
if (value < 0) {
print("-");
textPrint("-");
value = -value;
}
if (value > 9) printInt(value / 10);
if (value > 9) textPrintInt(value / 10);
c[0] = '0' + (value % 10);
c[1] = 0;
print(c);
textPrint(c);
}
// Reset display to text, "standard" colors.
void resetText(void) {
void textReset(void) {
byte mmu = PEEK(MMU_IO_CTRL); // Get current MMU state.
byte x;
byte y;
@ -209,7 +206,7 @@ void resetText(void) {
// Set up default text colors.
for (x=0; x<TEXTCOLORS_COUNT; x++)
defineTextColor(x,
textDefineColor(x,
textColors[x].r,
textColors[x].g,
textColors[x].b,
@ -219,11 +216,11 @@ void resetText(void) {
POKE(MMU_IO_CTRL, mmu); // Restore MMU state.
cls();
textClear();
}
void setTextColor(byte f, byte b) {
void textSetColor(byte f, byte b) {
_fcolor = f;
_bcolor = b;
_ccolor = (f << 4) + b;

View file

@ -55,22 +55,17 @@ typedef enum textColorsE {
TEXTCOLORS_COUNT
} textColorsT;
typedef struct colorS {
byte r;
byte g;
byte b;
} colorT;
extern colorT textColors[16];
void cls(void);
void defineTextColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb);
void gotoxy(byte x, byte y);
void print(char *message);
void printInt(int32_t value);
void resetText(void);
void setTextColor(byte f, byte b);
void textClear(void);
void textDefineColor(byte slot, byte fr, byte fg, byte fb, byte br, byte bg, byte bb);
void textGotoXY(byte x, byte y);
void textPrint(char *message);
void textPrintInt(int32_t value);
void textReset(void);
void textSetColor(byte f, byte b);
#ifdef __cplusplus