Some code cleanup.

This commit is contained in:
Scott Duensing 2024-01-16 19:00:01 -06:00
parent edf1c56956
commit 0b79976955
7 changed files with 67 additions and 66 deletions

1
README
View file

@ -27,6 +27,7 @@ At a minimum, you should run the following:
./build-llvm-mos.sh all
./build-merlin.sh
./update-defines.sh
./build-tools.sh
SCRIPTS

View file

@ -38,16 +38,18 @@ void bitmap(void) {
byte l;
byte c = 0;
textPrint("\n");
// textPrint("\n");
for (l=0; l<TEXTCOLORS_COUNT; l++) {
graphicsDefineColor(0, l, textColors[l].r, textColors[l].g, textColors[l].b);
/*
textSetColor(l, 0);
textPrint("Color "); textPrintInt(l);
textPrint(" = R:"); textPrintInt(textColors[l].r);
textPrint(" G:"); textPrintInt(textColors[l].g);
textPrint(" B:"); textPrintInt(textColors[l].b);
textPrint("\n");
*/
}
bitmapSetColor(0);
@ -99,7 +101,7 @@ void text(void) {
int main(void) {
f256Init();
text();
//bitmap();
//text();
bitmap();
return 0;
}

View file

@ -48,17 +48,9 @@ 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.
}
SWAP_IO_SETUP();
// Clear full 8k blocks.
for (x=0; x<9; x++) {
@ -69,11 +61,7 @@ void bitmapClear(void) {
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");
}
SWAP_IO_SHUTDOWN();
#endif
}
@ -92,16 +80,8 @@ 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.
}
SWAP_IO_SETUP();
if (x2 >= x1) {
dx = x2 - x1;
@ -152,33 +132,14 @@ void bitmapLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) {
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");
}
SWAP_IO_SHUTDOWN();
}
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.
}
SWAP_IO_SETUP();
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");
}
SWAP_IO_SHUTDOWN();
}

View file

@ -39,11 +39,9 @@ void f256Init(void) {
POKE(MMU_IO_CTRL, MMU_IO_PAGE_0);
POKE(VKY_MSTR_CTRL_0, 63); // Enable text and all graphics.
//POKE(VKY_MSTR_CTRL_1, 0);
//POKE(VKY_MSTR_CTRL_1, 20); // Enable FON_OVLY and DBL_Y.
POKE(VKY_MSTR_CTRL_1, 4); // Enable DBL_Y.
POKE(MMU_MEM_CTRL, 0xb3); // MLUT editing enabled, editing 3, 3 is active.
// Set all memory slots to be CPU memory.
POKE(MMU_MEM_BANK_0, 0);
POKE(MMU_MEM_BANK_1, 1);
@ -61,34 +59,25 @@ void f256Init(void) {
tileReset();
spriteReset();
// Make font taller for us blind people.
textSetDouble(false, true);
randomSeed(0); //***TODO*** Use clock or something.
}
byte FAR_PEEK(uint32_t address) {
byte block;
byte mmu;
byte ram;
byte result;
// 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.
}
SWAP_IO_SETUP();
block = address / EIGHTK;
address &= 0x1FFF; // Find offset into this block.
POKE(SWAP_SLOT, block);
result = PEEK(SWAP_ADDR + address);
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");
}
SWAP_IO_SHUTDOWN();
return result;
}

View file

@ -58,7 +58,32 @@ typedef unsigned char bool;
// Our stuff.
#define SWAP_SLOT MMU_MEM_BANK_5
#define SWAP_ADDR 0xa000
#define SWAP_ADDR ((SWAP_SLOT - MMU_MEM_BANK_0) * 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.
#if SWAP_SLOT == MMU_MEM_BANK_6
#define SWAP_IO_SETUP() \
byte sios_mmu = PEEK(MMU_IO_CTRL); \
byte sios_ram = PEEK(MMU_MEM_BANK_6); \
({ \
asm("sei"); \
POKE(MMU_IO_CTRL, 4); \
})
#define SWAP_IO_SHUTDOWN() ({ \
POKE(MMU_MEM_BANK_6, sios_ram); \
POKE(MMU_IO_CTRL, sios_mmu); \
asm("cli"); \
})
#else
#define SWAP_IO_SETUP()
#define SWAP_IO_SHUTDOWN()
#endif
// Things not in the Merlin defs.
@ -76,6 +101,14 @@ typedef unsigned char bool;
#define VKY_TS6_SQUARE (VKY_TS6_ADDR_H+1)
#define VKY_TS7_SQUARE (VKY_TS7_ADDR_H+1)
#define JOY_UP 1
#define JOY_DOWN 2
#define JOY_LEFT 4
#define JOY_RIGHT 8
#define JOY_BUTTON_1 16
#define JOY_BUTTON_2 32
#define JOY_BUTTON_3 64
typedef struct colorS {
byte r;
@ -100,6 +133,15 @@ typedef struct colorS {
#define PEEKD(addy) ((uint32_t)*(volatile uint32_t *)(addy))
#define POKED(addy,value) (*(volatile uint32_t *)(addy) = (value))
// Bit fun.
#define LOW_BYTE(v) ((byte)(x))
#define HIGH_BYTE(v) ((byte)(((uint16_t)(x)) >> 8))
#define SWAP_NIBBLES(x) ((x & 0x0F) << 4 | (x & 0xF0) >> 4)
#define CHECK_BIT(x, pos) (x & (1UL << pos))
#define TOGGLE_BIT(x, pos) (x ^= (1U << pos))
#define CLEAR_BIT(x, pos) (x &= (~(1U << pos)))
#define SET_BIT(x, pos) (x |= (1U << pos))
void f256Init(void);
byte FAR_PEEK(uint32_t address);

View file

@ -225,3 +225,8 @@ void textSetCursor(byte c) {
POKE(VKY_CRSR_CHAR, c); // Set cursor shape. (199 = Checkerboard)
}
}
void textSetDouble(bool x, bool y) {
POKE(VKY_MSTR_CTRL_1, (PEEK(VKY_MSTR_CTRL_1) & 0xf9) | (x << 1) | (y << 2));
}

View file

@ -68,6 +68,7 @@ void textPrintInt(int32_t value);
void textReset(void);
void textSetColor(byte f, byte b);
void textSetCursor(byte c);
void textSetDouble(bool x, bool y);
#ifdef __cplusplus