From f39151d7f9bf82e7295c60b89d9da02c781528eb Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 15 Apr 2007 23:55:24 +0000 Subject: Development checkin -- not yet working --- arm9/include/spec.h | 2 +- arm9/source/config.c | 2 +- arm9/source/main.c | 48 +++----- arm9/source/spec.c | 306 +++++++++++++++++++++++++++++-------------------- arm9/source/tapes.c | 2 +- arm9/source/textmode.c | 26 ++++- 6 files changed, 225 insertions(+), 161 deletions(-) diff --git a/arm9/include/spec.h b/arm9/include/spec.h index f9f6786..8ec05a9 100644 --- a/arm9/include/spec.h +++ b/arm9/include/spec.h @@ -30,7 +30,7 @@ /* Initialise the SPEC */ -void SPECInit(uint16 *vram, Z80 *z80); +void SPECInit(uint16 *palette, uint16 *vram, Z80 *z80); /* Handle keypresses */ diff --git a/arm9/source/config.c b/arm9/source/config.c index 648834b..a6f4555 100644 --- a/arm9/source/config.c +++ b/arm9/source/config.c @@ -43,7 +43,7 @@ const char *conf_entry[DS48_NUM_CONFIG_ITEMS]= int DS48_Config[DS48_NUM_CONFIG_ITEMS]= { TRUE, - FALSE, + TRUE, FALSE }; diff --git a/arm9/source/main.c b/arm9/source/main.c index b32174a..235098b 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -211,21 +211,19 @@ static void Splash(void) */ static void MapJoypad(void) { -#if 0 SoftKeyEvent ev; SoftKey pad = NUM_SOFT_KEYS; int done = FALSE; - char text[256]; SK_DisplayKeyboard(); + SK_SetDisplayBrightness(TRUE); - ZX SpectrumSuspendDisplay(); - - ZX SpectrumDisplayString("press the joypad button you want\n" - "to define and then the ZX Spectrum key\n" - "you want to use.\n\n" - "press on the config banner to\n" - "finish."); + TM_Cls(); + TM_Put(0,0,"Press the joypad button you want\n" + "to define and then the key\n" + "you want to use.\n\n" + "press on the config banner to\n" + "finish."); while(!done) { @@ -244,17 +242,15 @@ static void MapJoypad(void) { pad = ev.key; - /* Now, just how dumb was making % the inverse on/off... - */ - sprintf(text,"defining\n %%%s%%",SK_KeyName(pad)); - ZX SpectrumDisplayString(text); + TM_Cls(); + TM_printf(0,0,"Defining:\n %s",SK_KeyName(pad)); } if (ev.key<=SK_SPACE && pad!=NUM_SOFT_KEYS) { - sprintf(text,"mapped\n %%%s%%\nto\n %%%s%%", + TM_Cls(); + TM_printf(0,0,"Mapped:\n %s\nto:\n %s", SK_KeyName(pad),SK_KeyName(ev.key)); - ZX SpectrumDisplayString(text); SK_DefinePad(pad,ev.key); @@ -266,8 +262,8 @@ static void MapJoypad(void) swiWaitForVBlank(); } - ZX SpectrumResumeDisplay(); -#endif + TM_Cls(); + SK_SetDisplayBrightness(FALSE); } @@ -279,22 +275,14 @@ int main(int argc, char *argv[]) powerON(POWER_ALL_2D); - /* Set up main screen for ZX Spectrum. + /* Set up main screen for the Spectrum. */ - videoSetMode(MODE_3_2D | DISPLAY_BG0_ACTIVE | DISPLAY_BG3_ACTIVE); + videoSetMode(MODE_3_2D | DISPLAY_BG3_ACTIVE); vramSetBankA(VRAM_A_MAIN_BG_0x06000000); vramSetBankB(VRAM_B_MAIN_BG_0x06020000); - BG0_CR = BG_COLOR_256 | BG_32x32 | BG_MAP_BASE(0) | - BG_TILE_BASE(1) | BG_PRIORITY(0); - BG0_X0 = 0; - BG0_Y0 = 0; - - BG_PALETTE[0] = RGB15(31,31,31); - BG_PALETTE[1] = RGB15(0,0,0); - - BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE(2) | BG_PRIORITY(1); + BG3_CR = BG_BMP8_256x256 | BG_BMP_BASE(0); BG3_XDX = 0x100; BG3_XDY = 0; BG3_YDX = 0; @@ -358,7 +346,7 @@ int main(int argc, char *argv[]) GUI_Alert(TRUE,"Failed to initialise\nthe Z80 CPU emulation!"); } - SPECInit((uint16*)BG_BMP_RAM(2), z80); + SPECInit(BG_PALETTE, (uint16*)BG_BMP_RAM(0), z80); Splash(); @@ -374,7 +362,7 @@ int main(int argc, char *argv[]) { SoftKeyEvent ev; - /* Z80Exec(z80); */ + Z80Exec(z80); while(SK_GetEvent(&ev)) { diff --git a/arm9/source/spec.c b/arm9/source/spec.c index 70b1931..47524cb 100644 --- a/arm9/source/spec.c +++ b/arm9/source/spec.c @@ -27,6 +27,7 @@ #include "spec.h" #include "spec48_bin.h" +#include "gui.h" #ifndef TRUE #define TRUE 1 @@ -42,6 +43,7 @@ /* ---------------------------------------- STATICS */ +static uint16 *pal; static uint16 *vram; static const int ROMLEN=0x4000; @@ -60,13 +62,11 @@ static const int ROM_LOAD=0x562; #define SCRDATA 0x4000 #define ATTR 0x5800 -#define ATTR_AT(x,y) Z80_MEMORY[ATTR+(x)+((y)/8)*32] - Z80Byte Z80_MEMORY[0x10000]; /* Number of cycles per frame */ -static Z80Val FRAME_CYCLES=69888; +#define FRAME_CYCLES 69888 /* GFX vars @@ -79,35 +79,52 @@ static int flashctr=0; #define NVAL 25 /* Normal RGB intensity */ #define BVAL 31 /* Bright RGB intensity */ -static Z80Byte *line[SCR_H]; /* Accelerators to screen data */ +/* Accelerators to screen data - start of screen mem that matches an attribute. +*/ +static Z80Byte *scr_accel[TXT_W * TXT_H]; +static uint16 *vram_accel[TXT_W * TXT_H]; static struct { - uint16 col; int r,g,b; } coltable[16]= { - {0, 0x00,0x00,0x00}, /* BLACK */ - {0, 0x00,0x00,NVAL}, /* BLUE */ - {0, NVAL,0x00,0x00}, /* RED */ - {0, NVAL,0x00,NVAL}, /* MAGENTA */ - {0, 0x00,NVAL,0x00}, /* GREEN */ - {0, 0x00,NVAL,NVAL}, /* CYAN */ - {0, NVAL,NVAL,0x00}, /* YELLOW */ - {0, NVAL,NVAL,NVAL}, /* WHITE */ - - {0, 0x00,0x00,0x00}, /* BLACK */ - {0, 0x00,0x00,BVAL}, /* BLUE */ - {0, BVAL,0x00,0x00}, /* RED */ - {0, BVAL,0x00,BVAL}, /* MAGENTA */ - {0, 0x00,BVAL,0x00}, /* GREEN */ - {0, 0x00,BVAL,BVAL}, /* CYAN */ - {0, BVAL,BVAL,0x00}, /* YELLOW */ - {0, BVAL,BVAL,BVAL}, /* WHITE */ - + {0x00,0x00,0x00}, /* BLACK */ + {0x00,0x00,NVAL}, /* BLUE */ + {NVAL,0x00,0x00}, /* RED */ + {NVAL,0x00,NVAL}, /* MAGENTA */ + {0x00,NVAL,0x00}, /* GREEN */ + {0x00,NVAL,NVAL}, /* CYAN */ + {NVAL,NVAL,0x00}, /* YELLOW */ + {NVAL,NVAL,NVAL}, /* WHITE */ + + {0x00,0x00,0x00}, /* BLACK */ + {0x00,0x00,BVAL}, /* BLUE */ + {BVAL,0x00,0x00}, /* RED */ + {BVAL,0x00,BVAL}, /* MAGENTA */ + {0x00,BVAL,0x00}, /* GREEN */ + {0x00,BVAL,BVAL}, /* CYAN */ + {BVAL,BVAL,0x00}, /* YELLOW */ + {BVAL,BVAL,BVAL}, /* WHITE */ }; +/* Screen content checkers +*/ +typedef struct +{ + int ink; + int paper; +} ColourCell; + +static ColourCell last_attr[TXT_W * TXT_H]; +static Z80Byte last_screen[SCR_W * SCR_H / 8]; + +/* Lookups for bitmask to screen data +*/ +static uint16 bitmap_to_screen[256][4]; + + /* The keyboard */ static Z80Byte matrix[8]; @@ -128,108 +145,118 @@ static struct {7,0x10}, {7,0x08}, {7,0x04}, {7,0x02}, {7,0x01} /* B - SPACE */ }; -static int debug_matrix = FALSE; - /* ---------------------------------------- PRIVATE FUNCTIONS */ -static void FillBox(int x, int y, int w, int h, int colour) +static void DrawScreen(void) { int f; - uint16 *base; + int r; + int ink; + int paper; + Z80Byte *scr; + Z80Byte *old_scr; + int scr_data; + int inv_scr_data; + int att; + uint16 *vr; - colour|=0x8000; + old_scr = last_screen; - base=vram+x+y*256; + swiWaitForVBlank(); - while(h--) + for(f=0;f>3; + } + else + { + ink = (att&0x07); + paper = (att&0x38)>>3; } - base+=256; - } -} - + if (att&0x40) + { + ink += 8; + paper += 8; + } + /* Get screen address for this attribute and VRAM base + */ + scr = scr_accel[f]; + vr = vram_accel[f]; -static void DrawScreen(void) -{ - int f,r; - int ink,paper,t; - int y; - Z80Byte *scr; - Z80Byte b; - Z80Byte att; - uint16 *vr; + /* If attribute has changed, redraw 8x8 block + */ + if (last_attr[f].ink != ink || last_attr[f].paper != paper) + { + for(r=0;r<8;r++) + { + scr_data = *scr; + inv_scr_data = scr_data^0xff; - vr=vram; + *vr = (bitmap_to_screen[scr_data][0] & ink) | + (bitmap_to_screen[inv_scr_data][0] & paper); - /* swiWaitForVBlank(); */ + *(vr+1) = (bitmap_to_screen[scr_data][1] & ink) | + (bitmap_to_screen[inv_scr_data][1] & paper); - for(y=0;y>3; + vr += 128; - if (att&0x40) - { - ink+=8; - paper+=8; - } + *old_scr++ = scr_data; - if ((att&0x80)&&(flash)) - { - t=ink; - ink=paper; - paper=t; + scr += 32; } - b=*scr++; - + last_attr[f].ink = ink; + last_attr[f].paper = paper; + } + else + { + /* Attribute not changed, so see if screen data has changed + */ for(r=0;r<8;r++) { - if (b&(1<<(7-r))) - { - *vr++=coltable[ink].col; - } - else + scr_data = *scr; + + if (scr_data != *old_scr) { - *vr++=coltable[paper].col; - } - } - } - } + inv_scr_data = scr_data^0xff; - if (debug_matrix) - { - int m; - int b; + *vr = (bitmap_to_screen[scr_data][0] & ink) | + (bitmap_to_screen[inv_scr_data][0] & paper); - for(m=0;m<8;m++) - { - for(b=0;b<8;b++) - { - uint16 col; + *(vr+1) = (bitmap_to_screen[scr_data][1] & ink) | + (bitmap_to_screen[inv_scr_data][1] & paper); - if (matrix[m]&(1<