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/source/spec.c | 306 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 183 insertions(+), 123 deletions(-) (limited to 'arm9/source/spec.c') 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<