upgrade core, fix frameskipping bug

This commit is contained in:
dborth 2008-09-22 23:00:10 +00:00
parent e1c493fed1
commit c711145d1d
83 changed files with 29032 additions and 36431 deletions

View File

@ -18,17 +18,17 @@ include $(DEVKITPPC)/gamecube_rules
TARGET := vbagx_gc TARGET := vbagx_gc
TARGETDIR := executables TARGETDIR := executables
BUILD := build_gc BUILD := build_gc
SOURCES := source/vba source/vba/gb source/ngc SOURCES := source/vba source/vba/agb source/vba/dmg source/ngc
INCLUDES := source/vba source/vba/gb source/ngc INCLUDES := source/vba source/ngc
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) -maltivec \ CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) \
-DNGC -DWORDS_BIGENDIAN -DC_CORE \ -DNGC -DWORDS_BIGENDIAN -DC_CORE -DFINAL_VERSION \
-DCHANFFS -DSDL -DHAVE_ZUTIL_H -DSDL -DNO_PNG -DHAVE_ZUTIL_H
CXXFLAGS = -save-temps -Xassembler -aln=$@.lst $(CFLAGS) CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------

View File

@ -18,17 +18,17 @@ include $(DEVKITPPC)/wii_rules
TARGET := vbagx_wii TARGET := vbagx_wii
TARGETDIR := executables TARGETDIR := executables
BUILD := build_wii BUILD := build_wii
SOURCES := source/vba source/vba/gb source/ngc SOURCES := source/vba source/vba/agb source/vba/dmg source/ngc
INCLUDES := source/vba source/vba/gb source/ngc INCLUDES := source/vba source/ngc
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) -maltivec \ CFLAGS = -g -O3 -Wall $(MACHDEP) $(INCLUDE) \
-DNGC -DWORDS_BIGENDIAN -DC_CORE \ -DNGC -DWORDS_BIGENDIAN -DC_CORE -DFINAL_VERSION \
-DCHANFFS -DSDL -DHAVE_ZUTIL_H -DSDL -DNO_PNG -DHAVE_ZUTIL_H
CXXFLAGS = -save-temps -Xassembler -aln=$@.lst $(CFLAGS) CXXFLAGS = $(CFLAGS)
LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------

View File

@ -1,7 +1,7 @@
¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤ ¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤
- Visual Boy Advance GX - - Visual Boy Advance GX -
Version 1.0.1 Version 1.0.2
(Under GPL License) (Under GPL License)
¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤ ¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤°`°¤ø,¸,ø¤°`°¤ø,¸¸,ø¤
@ -22,6 +22,16 @@ With it you can play GBA/Game Boy Color/Game Boy games on your Wii/GameCube.
|0O×øo· UPDATE HISTORY ·oø×O0| |0O×øo· UPDATE HISTORY ·oø×O0|
`¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨' `¨•¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨¨ ¨¨¨¨¨¨¨¨¨¨¨¨¨'
[What's New 1.0.2]
* New core! The core is a modified version of VBA-M and VBA 1.80 beta 3
* Better emulation speeds. Should now be nearly full speed all the time
* Turbo speed feature. Mapped to right C-stick (classic controller &
Gamecube controller), and A+B for wiimote
* Controller mapping preferences bug fixed. Your preferences will reset
automatically to correct any problems in your preferences file
* Fix a frameskipping bug
* Some tweaks behind the scenes
[What's New 1.0.1] [What's New 1.0.1]
* GBA games now run at full speed * GBA games now run at full speed
* Menu improvements, with spiffy new background - thanks brakken! * Menu improvements, with spiffy new background - thanks brakken!

View File

@ -13,23 +13,21 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "GBA.h" #include "agb/GBA.h"
#include "agbprint.h" #include "agb/agbprint.h"
#include "Flash.h" #include "Flash.h"
#include "Port.h" #include "Port.h"
#include "RTC.h" #include "RTC.h"
#include "Sound.h" #include "Sound.h"
#include "Text.h"
#include "unzip.h" #include "unzip.h"
#include "Util.h" #include "Util.h"
#include "gb/GB.h" #include "dmg/GB.h"
#include "gb/gbGlobals.h" #include "dmg/gbGlobals.h"
#include "vba.h" #include "vba.h"
#include "fileop.h" #include "fileop.h"
#include "audio.h" #include "audio.h"
#include "vmmem.h" #include "vmmem.h"
#include "pal60.h"
#include "input.h" #include "input.h"
#include "video.h" #include "video.h"
#include "menudraw.h" #include "menudraw.h"
@ -44,9 +42,6 @@ static tb_t start, now;
u32 loadtimeradjust; u32 loadtimeradjust;
int throttle = 100;
u32 throttleLastTime = 0;
static u32 autoFrameSkipLastTime = 0; static u32 autoFrameSkipLastTime = 0;
static int frameskipadjust = 0; static int frameskipadjust = 0;
@ -122,7 +117,7 @@ bool systemPauseOnFrame()
{ {
return false; return false;
} }
/*
void GC_Sleep(u32 dwMiliseconds) void GC_Sleep(u32 dwMiliseconds)
{ {
int nVBlanks = (dwMiliseconds / 16); int nVBlanks = (dwMiliseconds / 16);
@ -131,7 +126,7 @@ void GC_Sleep(u32 dwMiliseconds)
VIDEO_WaitVSync(); VIDEO_WaitVSync();
} }
} }
*/
void system10Frames(int rate) void system10Frames(int rate)
{ {
if ( cartridgeType == 1 ) if ( cartridgeType == 1 )
@ -181,8 +176,8 @@ void system10Frames(int rate)
****************************************************************************/ ****************************************************************************/
void systemGbPrint(u8 *data,int pages,int feed,int palette, int contrast) {} void systemGbPrint(u8 *data,int pages,int feed,int palette, int contrast) {}
void debuggerOutput(char *, u32) {} void debuggerOutput(const char *s, u32 addr) {}
void (*dbgOutput)(char *, u32) = debuggerOutput; void (*dbgOutput)(const char *s, u32 addr) = debuggerOutput;
void systemMessage(int num, const char *msg, ...) {} void systemMessage(int num, const char *msg, ...) {}
/**************************************************************************** /****************************************************************************
@ -397,7 +392,7 @@ int loadVBAROM(char filename[])
} }
// Set defaults // Set defaults
flashSetSize(0x10000); flashSetSize(0x20000); // 128K saves
rtcEnable(true); rtcEnable(true);
agbPrintEnable(false); agbPrintEnable(false);
soundOffFlag = false; soundOffFlag = false;
@ -425,6 +420,9 @@ int loadVBAROM(char filename[])
emulating = 1; emulating = 1;
// reset frameskip variables
autoFrameSkipLastTime = frameskipadjust = systemFrameSkip = 0;
// Start system clock // Start system clock
mftb(&start); mftb(&start);

View File

@ -17,7 +17,7 @@
#include <fat.h> #include <fat.h>
#include <sys/dir.h> #include <sys/dir.h>
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Util.h" #include "Util.h"
#include "Port.h" #include "Port.h"
@ -104,20 +104,16 @@ static void VMClose( void )
int VMCPULoadROM( char *filename ) int VMCPULoadROM( char *filename )
{ {
int res=0; int res=0;
char temp[512]; //char temp[512];
VMClose(); VMClose();
VMAllocGBA(); VMAllocGBA();
GBAROMSize = 0; GBAROMSize = 0;
sprintf(temp,"Filename %s\n", filename);
//WaitPrompt(temp);
romfile = gen_fopen(filename, "rb"); romfile = gen_fopen(filename, "rb");
if ( romfile == NULL ) if ( romfile == NULL )
{ {
WaitPrompt((char*) "Error opening file!"); WaitPrompt((char*) "Error opening file!");
//while(1);
VMClose(); VMClose();
return 0; return 0;
} }
@ -126,7 +122,7 @@ int VMCPULoadROM( char *filename )
GBAROMSize = ftell(romfile); GBAROMSize = ftell(romfile);
fseek(romfile, 0, SEEK_SET); fseek(romfile, 0, SEEK_SET);
sprintf(temp,"ROM Size %dMb (%dMBit)", GBAROMSize/1024/1024,(GBAROMSize*8)/1024/1024); //sprintf(temp,"ROM Size %dMb (%dMBit)", GBAROMSize/1024/1024,(GBAROMSize*8)/1024/1024);
//WaitPrompt(temp); //WaitPrompt(temp);
rom = (u8 *)MEM2Storage; rom = (u8 *)MEM2Storage;
@ -137,7 +133,8 @@ int VMCPULoadROM( char *filename )
if ( (u32)res != GBAROMSize ) if ( (u32)res != GBAROMSize )
{ {
WaitPrompt((char*) "Error reading file!"); WaitPrompt((char*) "Error reading file!");
while(1); VMClose();
return 0;
} }
strcpy( romfilename, filename ); strcpy( romfilename, filename );
@ -208,7 +205,7 @@ u8 VMRead8( u32 address )
#include <string.h> #include <string.h>
#include <malloc.h> #include <malloc.h>
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Util.h" #include "Util.h"
#include "Port.h" #include "Port.h"
@ -389,13 +386,12 @@ int VMCPULoadROM( char *filename )
loadtimeradjust = useVM = GBAROMSize = 0; loadtimeradjust = useVM = GBAROMSize = 0;
printf("Filename %s\n", filename); //printf("Filename %s\n", filename);
romfile = gen_fopen(filename, "rb"); romfile = gen_fopen(filename, "rb");
if ( romfile == NULL ) if ( romfile == NULL )
{ {
WaitPrompt((char*) "Error opening file!"); WaitPrompt((char*) "Error opening file!");
while(1);
VMClose(); VMClose();
return 0; return 0;
} }
@ -408,7 +404,8 @@ int VMCPULoadROM( char *filename )
{ {
sprintf(msg, "Error reading file! %i \n",res); sprintf(msg, "Error reading file! %i \n",res);
WaitPrompt(msg); WaitPrompt(msg);
while(1); VMClose();
return 0;
} }
fseek(romfile, 0, SEEK_END); fseek(romfile, 0, SEEK_END);
@ -446,7 +443,8 @@ static void VMNewPage( int pageid )
{ {
sprintf(msg, "Seek error! - Offset %08x %d\n", pageid << VMSHIFTBITS, res); sprintf(msg, "Seek error! - Offset %08x %d\n", pageid << VMSHIFTBITS, res);
WaitPrompt(msg); WaitPrompt(msg);
while(1); VMClose();
return;
} }
VMAllocate( pageid ); VMAllocate( pageid );
@ -456,7 +454,8 @@ static void VMNewPage( int pageid )
{ {
sprintf(msg, "Error reading! %d bytes only\n", res); sprintf(msg, "Error reading! %d bytes only\n", res);
WaitPrompt(msg); WaitPrompt(msg);
while(1); VMClose();
return;
} }
mftb(&end); mftb(&end);
@ -516,7 +515,8 @@ u32 VMRead32( u32 address )
default: default:
sprintf(msg, "VM32 : Unknown page type! (%d) [%d]", vmpage[pageid].pagetype, pageid); sprintf(msg, "VM32 : Unknown page type! (%d) [%d]", vmpage[pageid].pagetype, pageid);
WaitPrompt(msg); WaitPrompt(msg);
while(1); VMClose();
return 0;
} }
/* Can never get here ... but stops gcc bitchin' */ /* Can never get here ... but stops gcc bitchin' */
@ -555,7 +555,8 @@ u16 VMRead16( u32 address )
default: default:
WaitPrompt((char*) "VM16 : Unknown page type!"); WaitPrompt((char*) "VM16 : Unknown page type!");
while(1); VMClose();
return 0;
} }
/* Can never get here ... but stops gcc bitchin' */ /* Can never get here ... but stops gcc bitchin' */
@ -594,7 +595,8 @@ u8 VMRead8( u32 address )
default: default:
WaitPrompt((char*) "VM8 : Unknown page type!"); WaitPrompt((char*) "VM8 : Unknown page type!");
while(1); VMClose();
return 0;
} }
/* Can never get here ... but stops gcc bitchin' */ /* Can never get here ... but stops gcc bitchin' */

View File

@ -24,9 +24,9 @@
CheatSearchBlock cheatSearchBlocks[4]; CheatSearchBlock cheatSearchBlocks[4];
CheatSearchData cheatSearchData = { CheatSearchData cheatSearchData = {
0, 0,
cheatSearchBlocks cheatSearchBlocks
}; };
static bool cheatSearchEQ(u32 a, u32 b) static bool cheatSearchEQ(u32 a, u32 b)
{ {
@ -89,32 +89,31 @@ static bool cheatSearchSignedGE(s32 a, s32 b)
} }
static bool (*cheatSearchFunc[])(u32,u32) = { static bool (*cheatSearchFunc[])(u32,u32) = {
cheatSearchEQ, cheatSearchEQ,
cheatSearchNE, cheatSearchNE,
cheatSearchLT, cheatSearchLT,
cheatSearchLE, cheatSearchLE,
cheatSearchGT, cheatSearchGT,
cheatSearchGE cheatSearchGE
}; };
static bool (*cheatSearchSignedFunc[])(s32,s32) = { static bool (*cheatSearchSignedFunc[])(s32,s32) = {
cheatSearchSignedEQ, cheatSearchSignedEQ,
cheatSearchSignedNE, cheatSearchSignedNE,
cheatSearchSignedLT, cheatSearchSignedLT,
cheatSearchSignedLE, cheatSearchSignedLE,
cheatSearchSignedGT, cheatSearchSignedGT,
cheatSearchSignedGE cheatSearchSignedGE
}; };
void cheatSearchCleanup(CheatSearchData *cs) void cheatSearchCleanup(CheatSearchData *cs)
{ {
int count = cs->count; int count = cs->count;
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) {
{ free(cs->blocks[i].saved);
free(cs->blocks[i].saved); free(cs->blocks[i].bits);
free(cs->blocks[i].bits); }
}
cs->count = 0; cs->count = 0;
} }
@ -122,34 +121,32 @@ void cheatSearchStart(const CheatSearchData *cs)
{ {
int count = cs->count; int count = cs->count;
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++) {
{ CheatSearchBlock *block = &cs->blocks[i];
CheatSearchBlock *block = &cs->blocks[i];
memset(block->bits, 0xff, block->size >> 3); memset(block->bits, 0xff, block->size >> 3);
memcpy(block->saved, block->data, block->size); memcpy(block->saved, block->data, block->size);
} }
} }
s32 cheatSearchSignedRead(u8 *data, int off, int size) s32 cheatSearchSignedRead(u8 *data, int off, int size)
{ {
u32 res = data[off++]; u32 res = data[off++];
switch(size) switch(size) {
{ case BITS_8:
case BITS_8: res <<= 24;
res <<= 24; return ((s32)res) >> 24;
return ((s32)res) >> 24; case BITS_16:
case BITS_16: res |= ((u32)data[off++])<<8;
res |= ((u32)data[off++])<<8; res <<= 16;
res <<= 16; return ((s32)res) >> 16;
return ((s32)res) >> 16; case BITS_32:
case BITS_32: res |= ((u32)data[off++])<<8;
res |= ((u32)data[off++])<<8; res |= ((u32)data[off++])<<16;
res |= ((u32)data[off++])<<16; res |= ((u32)data[off++])<<24;
res |= ((u32)data[off++])<<24; return (s32)res;
return (s32)res; }
}
return (s32)res; return (s32)res;
} }
@ -158,12 +155,11 @@ u32 cheatSearchRead(u8 *data, int off, int size)
u32 res = data[off++]; u32 res = data[off++];
if(size == BITS_16) if(size == BITS_16)
res |= ((u32)data[off++])<<8; res |= ((u32)data[off++])<<8;
else if(size == BITS_32) else if(size == BITS_32) {
{ res |= ((u32)data[off++])<<8;
res |= ((u32)data[off++])<<8; res |= ((u32)data[off++])<<16;
res |= ((u32)data[off++])<<16; res |= ((u32)data[off++])<<24;
res |= ((u32)data[off++])<<24; }
}
return res; return res;
} }
@ -178,78 +174,65 @@ void cheatSearch(const CheatSearchData *cs, int compare, int size,
else if(size == BITS_32) else if(size == BITS_32)
inc = 4; inc = 4;
if(isSigned) if(isSigned) {
{ bool (*func)(s32,s32) = cheatSearchSignedFunc[compare];
bool (*func)(s32,s32) = cheatSearchSignedFunc[compare];
for(int i = 0; i < cs->count; i++) for(int i = 0; i < cs->count; i++) {
{ CheatSearchBlock *block = &cs->blocks[i];
CheatSearchBlock *block = &cs->blocks[i]; int size2 = block->size;
int size2 = block->size; u8 *bits = block->bits;
u8 *bits = block->bits; u8 *data = block->data;
u8 *data = block->data; u8 *saved = block->saved;
u8 *saved = block->saved;
for(int j = 0; j < size2; j += inc) for(int j = 0; j < size2; j += inc) {
{ if(IS_BIT_SET(bits, j)) {
if(IS_BIT_SET(bits, j)) s32 a = cheatSearchSignedRead(data, j, size);
{ s32 b = cheatSearchSignedRead(saved,j, size);
s32 a = cheatSearchSignedRead(data, j, size);
s32 b = cheatSearchSignedRead(saved,j, size);
if(!func(a, b)) if(!func(a, b)) {
{ CLEAR_BIT(bits, j);
CLEAR_BIT(bits, j); if(size == BITS_16)
if(size == BITS_16) CLEAR_BIT(bits, j+1);
CLEAR_BIT(bits, j+1); if(size == BITS_32) {
if(size == BITS_32) CLEAR_BIT(bits, j+2);
{ CLEAR_BIT(bits, j+3);
CLEAR_BIT(bits, j+2); }
CLEAR_BIT(bits, j+3); }
} }
} }
}
}
}
} }
else } else {
{ bool (*func)(u32,u32) = cheatSearchFunc[compare];
bool (*func)(u32,u32) = cheatSearchFunc[compare];
for(int i = 0; i < cs->count; i++) for(int i = 0; i < cs->count; i++) {
{ CheatSearchBlock *block = &cs->blocks[i];
CheatSearchBlock *block = &cs->blocks[i]; int size2 = block->size;
int size2 = block->size; u8 *bits = block->bits;
u8 *bits = block->bits; u8 *data = block->data;
u8 *data = block->data; u8 *saved = block->saved;
u8 *saved = block->saved;
for(int j = 0; j < size2; j += inc) for(int j = 0; j < size2; j += inc) {
{ if(IS_BIT_SET(bits, j)) {
if(IS_BIT_SET(bits, j)) u32 a = cheatSearchRead(data, j, size);
{ u32 b = cheatSearchRead(saved,j, size);
u32 a = cheatSearchRead(data, j, size);
u32 b = cheatSearchRead(saved,j, size);
if(!func(a, b)) if(!func(a, b)) {
{ CLEAR_BIT(bits, j);
CLEAR_BIT(bits, j); if(size == BITS_16)
if(size == BITS_16) CLEAR_BIT(bits, j+1);
CLEAR_BIT(bits, j+1); if(size == BITS_32) {
if(size == BITS_32) CLEAR_BIT(bits, j+2);
{ CLEAR_BIT(bits, j+3);
CLEAR_BIT(bits, j+2); }
CLEAR_BIT(bits, j+3); }
} }
} }
}
}
}
} }
}
} }
void cheatSearchValue(const CheatSearchData *cs, int compare, int size, void cheatSearchValue(const CheatSearchData *cs, int compare, int size,
bool isSigned, u32 value) bool isSigned, u32 value)
{ {
if(compare < 0 || compare > SEARCH_GE) if(compare < 0 || compare > SEARCH_GE)
return; return;
@ -259,71 +242,58 @@ void cheatSearchValue(const CheatSearchData *cs, int compare, int size,
else if(size == BITS_32) else if(size == BITS_32)
inc = 4; inc = 4;
if(isSigned) if(isSigned) {
{ bool (*func)(s32,s32) = cheatSearchSignedFunc[compare];
bool (*func)(s32,s32) = cheatSearchSignedFunc[compare];
for(int i = 0; i < cs->count; i++) for(int i = 0; i < cs->count; i++) {
{ CheatSearchBlock *block = &cs->blocks[i];
CheatSearchBlock *block = &cs->blocks[i]; int size2 = block->size;
int size2 = block->size; u8 *bits = block->bits;
u8 *bits = block->bits; u8 *data = block->data;
u8 *data = block->data;
for(int j = 0; j < size2; j += inc) for(int j = 0; j < size2; j += inc) {
{ if(IS_BIT_SET(bits, j)) {
if(IS_BIT_SET(bits, j)) s32 a = cheatSearchSignedRead(data, j, size);
{ s32 b = (s32)value;
s32 a = cheatSearchSignedRead(data, j, size);
s32 b = (s32)value;
if(!func(a, b)) if(!func(a, b)) {
{ CLEAR_BIT(bits, j);
CLEAR_BIT(bits, j); if(size == BITS_16)
if(size == BITS_16) CLEAR_BIT(bits, j+1);
CLEAR_BIT(bits, j+1); if(size == BITS_32) {
if(size == BITS_32) CLEAR_BIT(bits, j+2);
{ CLEAR_BIT(bits, j+3);
CLEAR_BIT(bits, j+2); }
CLEAR_BIT(bits, j+3); }
} }
} }
}
}
}
} }
else } else {
{ bool (*func)(u32,u32) = cheatSearchFunc[compare];
bool (*func)(u32,u32) = cheatSearchFunc[compare];
for(int i = 0; i < cs->count; i++) for(int i = 0; i < cs->count; i++) {
{ CheatSearchBlock *block = &cs->blocks[i];
CheatSearchBlock *block = &cs->blocks[i]; int size2 = block->size;
int size2 = block->size; u8 *bits = block->bits;
u8 *bits = block->bits; u8 *data = block->data;
u8 *data = block->data;
for(int j = 0; j < size2; j += inc) for(int j = 0; j < size2; j += inc) {
{ if(IS_BIT_SET(bits, j)) {
if(IS_BIT_SET(bits, j)) u32 a = cheatSearchRead(data, j, size);
{
u32 a = cheatSearchRead(data, j, size);
if(!func(a, value)) if(!func(a, value)) {
{ CLEAR_BIT(bits, j);
CLEAR_BIT(bits, j); if(size == BITS_16)
if(size == BITS_16) CLEAR_BIT(bits, j+1);
CLEAR_BIT(bits, j+1); if(size == BITS_32) {
if(size == BITS_32) CLEAR_BIT(bits, j+2);
{ CLEAR_BIT(bits, j+3);
CLEAR_BIT(bits, j+2); }
CLEAR_BIT(bits, j+3); }
} }
} }
}
}
}
} }
}
} }
int cheatSearchGetCount(const CheatSearchData *cs, int size) int cheatSearchGetCount(const CheatSearchData *cs, int size)
@ -335,28 +305,25 @@ int cheatSearchGetCount(const CheatSearchData *cs, int size)
else if(size == BITS_32) else if(size == BITS_32)
inc = 4; inc = 4;
for(int i = 0; i < cs->count; i++) for(int i = 0; i < cs->count; i++) {
{ CheatSearchBlock *block = &cs->blocks[i];
CheatSearchBlock *block = &cs->blocks[i];
int size2 = block->size; int size2 = block->size;
u8 *bits = block->bits; u8 *bits = block->bits;
for(int j = 0; j < size2; j += inc) for(int j = 0; j < size2; j += inc) {
{ if(IS_BIT_SET(bits, j))
if(IS_BIT_SET(bits, j)) res++;
res++;
}
} }
}
return res; return res;
} }
void cheatSearchUpdateValues(const CheatSearchData *cs) void cheatSearchUpdateValues(const CheatSearchData *cs)
{ {
for(int i = 0; i < cs->count; i++) for(int i = 0; i < cs->count; i++) {
{ CheatSearchBlock *block = &cs->blocks[i];
CheatSearchBlock *block = &cs->blocks[i];
memcpy(block->saved, block->data, block->size); memcpy(block->saved, block->data, block->size);
} }
} }

View File

@ -22,20 +22,18 @@
#include "System.h" #include "System.h"
struct CheatSearchBlock struct CheatSearchBlock {
{ int size;
int size; u32 offset;
u32 offset; u8 *bits;
u8 *bits; u8 *data;
u8 *data; u8 *saved;
u8 *saved; };
};
struct CheatSearchData struct CheatSearchData {
{ int count;
int count; CheatSearchBlock *blocks;
CheatSearchBlock *blocks; };
};
enum { enum {
SEARCH_EQ, SEARCH_EQ,
@ -65,9 +63,9 @@ extern CheatSearchData cheatSearchData;
extern void cheatSearchCleanup(CheatSearchData *cs); extern void cheatSearchCleanup(CheatSearchData *cs);
extern void cheatSearchStart(const CheatSearchData *cs); extern void cheatSearchStart(const CheatSearchData *cs);
extern void cheatSearch(const CheatSearchData *cs, int compare, int size, extern void cheatSearch(const CheatSearchData *cs, int compare, int size,
bool isSigned); bool isSigned);
extern void cheatSearchValue(const CheatSearchData *cs, int compare, int size, extern void cheatSearchValue(const CheatSearchData *cs, int compare, int size,
bool isSigned, u32 value); bool isSigned, u32 value);
extern int cheatSearchGetCount(const CheatSearchData *cs, int size); extern int cheatSearchGetCount(const CheatSearchData *cs, int size);
extern void cheatSearchUpdateValues(const CheatSearchData *cs); extern void cheatSearchUpdateValues(const CheatSearchData *cs);
extern s32 cheatSearchSignedRead(u8 *data, int off, int size); extern s32 cheatSearchSignedRead(u8 *data, int off, int size);

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
// -*- C++ -*- // -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2004-2006 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -20,20 +20,20 @@
#ifndef GBA_CHEATS_H #ifndef GBA_CHEATS_H
#define GBA_CHEATS_H #define GBA_CHEATS_H
struct CheatsData struct CheatsData {
{ int code;
int code; int size;
int size; int status;
int status; bool enabled;
bool enabled; u32 rawaddress;
u32 address; u32 address;
u32 value; u32 value;
u32 oldValue; u32 oldValue;
char codestring[20]; char codestring[20];
char desc[32]; char desc[32];
}; };
extern void cheatsAdd(const char *,const char *,u32,u32,int,int); extern void cheatsAdd(const char *,const char *,u32, u32,u32,int,int);
extern void cheatsAddCheatCode(const char *code, const char *desc); extern void cheatsAddCheatCode(const char *code, const char *desc);
extern void cheatsAddGSACode(const char *code, const char *desc, bool v3); extern void cheatsAddGSACode(const char *code, const char *desc, bool v3);
extern void cheatsAddCBACode(const char *code, const char *desc); extern void cheatsAddCBACode(const char *code, const char *desc);
@ -43,12 +43,12 @@ extern void cheatsDeleteAll(bool restore);
extern void cheatsEnable(int number); extern void cheatsEnable(int number);
extern void cheatsDisable(int number); extern void cheatsDisable(int number);
extern void cheatsSaveGame(gzFile file); extern void cheatsSaveGame(gzFile file);
extern void cheatsReadGame(gzFile file); extern void cheatsReadGame(gzFile file, int version);
extern void cheatsSaveCheatList(const char *file); extern void cheatsSaveCheatList(const char *file);
extern bool cheatsLoadCheatList(const char *file); extern bool cheatsLoadCheatList(const char *file);
extern void cheatsWriteMemory(u32 *, u32, u32); extern void cheatsWriteMemory(u32, u32);
extern void cheatsWriteHalfWord(u16 *, u16, u16); extern void cheatsWriteHalfWord(u32, u16);
extern void cheatsWriteByte(u8 *, u8); extern void cheatsWriteByte(u32, u8);
extern int cheatsCheckKeys(u32,u32); extern int cheatsCheckKeys(u32,u32);
extern int cheatsNumber; extern int cheatsNumber;
extern CheatsData cheatsList[100]; extern CheatsData cheatsList[100];

View File

@ -1,6 +1,6 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -16,7 +16,8 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include <string.h>
#include "agb/GBA.h"
#include "EEprom.h" #include "EEprom.h"
#include "Util.h" #include "Util.h"
@ -32,15 +33,20 @@ bool eepromInUse = false;
int eepromSize = 512; int eepromSize = 512;
variable_desc eepromSaveData[] = { variable_desc eepromSaveData[] = {
{ &eepromMode, sizeof(int) }, { &eepromMode, sizeof(int) },
{ &eepromByte, sizeof(int) }, { &eepromByte, sizeof(int) },
{ &eepromBits , sizeof(int) }, { &eepromBits , sizeof(int) },
{ &eepromAddress , sizeof(int) }, { &eepromAddress , sizeof(int) },
{ &eepromInUse, sizeof(bool) }, { &eepromInUse, sizeof(bool) },
{ &eepromData[0], 512 }, { &eepromData[0], 512 },
{ &eepromBuffer[0], 16 }, { &eepromBuffer[0], 16 },
{ NULL, 0 } { NULL, 0 }
}; };
void eepromInit()
{
memset(eepromData, 255, sizeof(eepromData));
}
void eepromReset() void eepromReset()
{ {
@ -62,39 +68,43 @@ void eepromSaveGame(gzFile gzFile)
void eepromReadGame(gzFile gzFile, int version) void eepromReadGame(gzFile gzFile, int version)
{ {
utilReadData(gzFile, eepromSaveData); utilReadData(gzFile, eepromSaveData);
if(version >= SAVE_GAME_VERSION_3) if(version >= SAVE_GAME_VERSION_3) {
{ eepromSize = utilReadInt(gzFile);
eepromSize = utilReadInt(gzFile); utilGzRead(gzFile, eepromData, 0x2000);
utilGzRead(gzFile, eepromData, 0x2000); } else {
} // prior to 0.7.1, only 4K EEPROM was supported
else eepromSize = 512;
{ }
// prior to 0.7.1, only 4K EEPROM was supported
eepromSize = 512;
}
} }
void eepromReadGameSkip(gzFile gzFile, int version)
{
// skip the eeprom data in a save game
utilReadDataSkip(gzFile, eepromSaveData);
if(version >= SAVE_GAME_VERSION_3) {
utilGzSeek(gzFile, sizeof(int), SEEK_CUR);
utilGzSeek(gzFile, 0x2000, SEEK_CUR);
}
}
int eepromRead(u32 /* address */) int eepromRead(u32 /* address */)
{ {
switch(eepromMode) switch(eepromMode) {
{ case EEPROM_IDLE:
case EEPROM_IDLE: case EEPROM_READADDRESS:
case EEPROM_READADDRESS: case EEPROM_WRITEDATA:
case EEPROM_WRITEDATA: return 1;
return 1; case EEPROM_READDATA:
case EEPROM_READDATA:
{ {
eepromBits++; eepromBits++;
if(eepromBits == 4) if(eepromBits == 4) {
{ eepromMode = EEPROM_READDATA2;
eepromMode = EEPROM_READDATA2; eepromBits = 0;
eepromBits = 0; eepromByte = 0;
eepromByte = 0; }
}
return 0; return 0;
} }
case EEPROM_READDATA2: case EEPROM_READDATA2:
{ {
int data = 0; int data = 0;
int address = eepromAddress << 3; int address = eepromAddress << 3;
@ -107,9 +117,9 @@ int eepromRead(u32 /* address */)
eepromMode = EEPROM_IDLE; eepromMode = EEPROM_IDLE;
return data; return data;
} }
default: default:
return 0; return 0;
} }
return 1; return 1;
} }
@ -118,97 +128,79 @@ void eepromWrite(u32 /* address */, u8 value)
if(cpuDmaCount == 0) if(cpuDmaCount == 0)
return; return;
int bit = value & 1; int bit = value & 1;
switch(eepromMode) switch(eepromMode) {
{ case EEPROM_IDLE:
case EEPROM_IDLE: eepromByte = 0;
eepromByte = 0; eepromBits = 1;
eepromBits = 1; eepromBuffer[eepromByte] = bit;
eepromBuffer[eepromByte] = bit; eepromMode = EEPROM_READADDRESS;
eepromMode = EEPROM_READADDRESS; break;
break; case EEPROM_READADDRESS:
case EEPROM_READADDRESS: eepromBuffer[eepromByte] <<= 1;
eepromBuffer[eepromByte] <<= 1; eepromBuffer[eepromByte] |= bit;
eepromBuffer[eepromByte] |= bit; eepromBits++;
eepromBits++; if((eepromBits & 7) == 0) {
if((eepromBits & 7) == 0) eepromByte++;
{ }
eepromByte++; if(cpuDmaCount == 0x11 || cpuDmaCount == 0x51) {
} if(eepromBits == 0x11) {
if(cpuDmaCount == 0x11 || cpuDmaCount == 0x51) eepromInUse = true;
{ eepromSize = 0x2000;
if(eepromBits == 0x11) eepromAddress = ((eepromBuffer[0] & 0x3F) << 8) |
{ ((eepromBuffer[1] & 0xFF));
eepromInUse = true; if(!(eepromBuffer[0] & 0x40)) {
eepromSize = 0x2000; eepromBuffer[0] = bit;
eepromAddress = ((eepromBuffer[0] & 0x3F) << 8) | eepromBits = 1;
((eepromBuffer[1] & 0xFF)); eepromByte = 0;
if(!(eepromBuffer[0] & 0x40)) eepromMode = EEPROM_WRITEDATA;
{ } else {
eepromBuffer[0] = bit; eepromMode = EEPROM_READDATA;
eepromBits = 1;
eepromByte = 0;
eepromMode = EEPROM_WRITEDATA;
}
else
{
eepromMode = EEPROM_READDATA;
eepromByte = 0;
eepromBits = 0;
}
}
}
else
{
if(eepromBits == 9)
{
eepromInUse = true;
eepromAddress = (eepromBuffer[0] & 0x3F);
if(!(eepromBuffer[0] & 0x40))
{
eepromBuffer[0] = bit;
eepromBits = 1;
eepromByte = 0;
eepromMode = EEPROM_WRITEDATA;
}
else
{
eepromMode = EEPROM_READDATA;
eepromByte = 0;
eepromBits = 0;
}
}
}
break;
case EEPROM_READDATA:
case EEPROM_READDATA2:
// should we reset here?
eepromMode = EEPROM_IDLE;
break;
case EEPROM_WRITEDATA:
eepromBuffer[eepromByte] <<= 1;
eepromBuffer[eepromByte] |= bit;
eepromBits++;
if((eepromBits & 7) == 0)
{
eepromByte++;
}
if(eepromBits == 0x40)
{
eepromInUse = true;
// write data;
for(int i = 0; i < 8; i++)
{
eepromData[(eepromAddress << 3) + i] = eepromBuffer[i];
}
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
}
else if(eepromBits == 0x41)
{
eepromMode = EEPROM_IDLE;
eepromByte = 0; eepromByte = 0;
eepromBits = 0; eepromBits = 0;
} }
break; }
} else {
if(eepromBits == 9) {
eepromInUse = true;
eepromAddress = (eepromBuffer[0] & 0x3F);
if(!(eepromBuffer[0] & 0x40)) {
eepromBuffer[0] = bit;
eepromBits = 1;
eepromByte = 0;
eepromMode = EEPROM_WRITEDATA;
} else {
eepromMode = EEPROM_READDATA;
eepromByte = 0;
eepromBits = 0;
}
}
} }
break;
case EEPROM_READDATA:
case EEPROM_READDATA2:
// should we reset here?
eepromMode = EEPROM_IDLE;
break;
case EEPROM_WRITEDATA:
eepromBuffer[eepromByte] <<= 1;
eepromBuffer[eepromByte] |= bit;
eepromBits++;
if((eepromBits & 7) == 0) {
eepromByte++;
}
if(eepromBits == 0x40) {
eepromInUse = true;
// write data;
for(int i = 0; i < 8; i++) {
eepromData[(eepromAddress << 3) + i] = eepromBuffer[i];
}
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} else if(eepromBits == 0x41) {
eepromMode = EEPROM_IDLE;
eepromByte = 0;
eepromBits = 0;
}
break;
}
} }

View File

@ -1,7 +1,7 @@
// -*- C++ -*- // -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -20,10 +20,12 @@
#ifndef VBA_EEPROM_H #ifndef VBA_EEPROM_H
#define VBA_EEPROM_H #define VBA_EEPROM_H
extern void eepromSaveGame(gzFile gzFile); extern void eepromSaveGame(gzFile _gzFile);
extern void eepromReadGame(gzFile gzFile, int version); extern void eepromReadGame(gzFile _gzFile, int version);
extern void eepromReadGameSkip(gzFile _gzFile, int version);
extern int eepromRead(u32 address); extern int eepromRead(u32 address);
extern void eepromWrite(u32 address, u8 value); extern void eepromWrite(u32 address, u8 value);
extern void eepromInit();
extern void eepromReset(); extern void eepromReset();
extern u8 eepromData[0x2000]; extern u8 eepromData[0x2000];
extern bool eepromInUse; extern bool eepromInUse;

View File

@ -1,6 +1,6 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2004-2006 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -18,7 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Flash.h" #include "Flash.h"
#include "Sram.h" #include "Sram.h"
@ -44,28 +44,33 @@ int flashManufacturerID = 0x32;
int flashBank = 0; int flashBank = 0;
static variable_desc flashSaveData[] = { static variable_desc flashSaveData[] = {
{ &flashState, sizeof(int) }, { &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) }, { &flashReadState, sizeof(int) },
{ &flashSaveMemory[0], 0x10000 }, { &flashSaveMemory[0], 0x10000 },
{ NULL, 0 } { NULL, 0 }
}; };
static variable_desc flashSaveData2[] = { static variable_desc flashSaveData2[] = {
{ &flashState, sizeof(int) }, { &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) }, { &flashReadState, sizeof(int) },
{ &flashSize, sizeof(int) }, { &flashSize, sizeof(int) },
{ &flashSaveMemory[0], 0x20000 }, { &flashSaveMemory[0], 0x20000 },
{ NULL, 0 } { NULL, 0 }
}; };
static variable_desc flashSaveData3[] = { static variable_desc flashSaveData3[] = {
{ &flashState, sizeof(int) }, { &flashState, sizeof(int) },
{ &flashReadState, sizeof(int) }, { &flashReadState, sizeof(int) },
{ &flashSize, sizeof(int) }, { &flashSize, sizeof(int) },
{ &flashBank, sizeof(int) }, { &flashBank, sizeof(int) },
{ &flashSaveMemory[0], 0x20000 }, { &flashSaveMemory[0], 0x20000 },
{ NULL, 0 } { NULL, 0 }
}; };
void flashInit()
{
memset(flashSaveMemory, 0xff, sizeof(flashSaveMemory));
}
void flashReset() void flashReset()
{ {
@ -83,32 +88,42 @@ void flashReadGame(gzFile gzFile, int version)
{ {
if(version < SAVE_GAME_VERSION_5) if(version < SAVE_GAME_VERSION_5)
utilReadData(gzFile, flashSaveData); utilReadData(gzFile, flashSaveData);
else if(version < SAVE_GAME_VERSION_7) else if(version < SAVE_GAME_VERSION_7) {
{ utilReadData(gzFile, flashSaveData2);
utilReadData(gzFile, flashSaveData2); flashBank = 0;
flashBank = 0; flashSetSize(flashSize);
flashSetSize(flashSize); } else {
} utilReadData(gzFile, flashSaveData3);
else }
{ }
utilReadData(gzFile, flashSaveData3);
} void flashReadGameSkip(gzFile gzFile, int version)
{
// skip the flash data in a save game
if(version < SAVE_GAME_VERSION_5)
utilReadDataSkip(gzFile, flashSaveData);
else if(version < SAVE_GAME_VERSION_7) {
utilReadDataSkip(gzFile, flashSaveData2);
} else {
utilReadDataSkip(gzFile, flashSaveData3);
}
} }
void flashSetSize(int size) void flashSetSize(int size)
{ {
// log("Setting flash size to %d\n", size); // log("Setting flash size to %d\n", size);
if(size == 0x10000) {
flashDeviceID = 0x1b;
flashManufacturerID = 0x32;
} else {
flashDeviceID = 0x13; //0x09;
flashManufacturerID = 0x62; //0xc2;
}
// Added to make 64k saves compatible with 128k ones
// (allow wrongfuly set 64k saves to work for Pokemon games)
if ((size == 0x20000) && (flashSize == 0x10000))
memcpy((u8 *)(flashSaveMemory+0x10000), (u8 *)(flashSaveMemory), 0x10000);
flashSize = size; flashSize = size;
if(size == 0x10000)
{
flashDeviceID = 0x1b;
flashManufacturerID = 0x32;
}
else
{
flashDeviceID = 0x13; //0x09;
flashManufacturerID = 0x62; //0xc2;
}
} }
u8 flashRead(u32 address) u8 flashRead(u32 address)
@ -117,172 +132,144 @@ u8 flashRead(u32 address)
// log("Current read state is %d\n", flashReadState); // log("Current read state is %d\n", flashReadState);
address &= 0xFFFF; address &= 0xFFFF;
switch(flashReadState) switch(flashReadState) {
{ case FLASH_READ_ARRAY:
case FLASH_READ_ARRAY: return flashSaveMemory[(flashBank << 16) + address];
return flashSaveMemory[(flashBank << 16) + address]; case FLASH_AUTOSELECT:
case FLASH_AUTOSELECT: switch(address & 0xFF) {
switch(address & 0xFF) case 0:
{ // manufacturer ID
case 0: return flashManufacturerID;
// manufacturer ID case 1:
return flashManufacturerID; // device ID
case 1: return flashDeviceID;
// device ID }
return flashDeviceID; break;
} case FLASH_ERASE_COMPLETE:
break; flashState = FLASH_READ_ARRAY;
case FLASH_ERASE_COMPLETE: flashReadState = FLASH_READ_ARRAY;
flashState = FLASH_READ_ARRAY; return 0xFF;
flashReadState = FLASH_READ_ARRAY; };
return 0xFF;
};
return 0; return 0;
} }
void flashSaveDecide(u32 address, u8 byte) void flashSaveDecide(u32 address, u8 byte)
{ {
// log("Deciding save type %08x\n", address); // log("Deciding save type %08x\n", address);
if(address == 0x0e005555) if(address == 0x0e005555) {
{ saveType = 2;
saveType = 2; cpuSaveGameFunc = flashWrite;
cpuSaveGameFunc = flashWrite; } else {
} saveType = 1;
else cpuSaveGameFunc = sramWrite;
{ }
saveType = 1;
cpuSaveGameFunc = sramWrite;
}
(*cpuSaveGameFunc)(address, byte); (*cpuSaveGameFunc)(address, byte);
} }
void flashDelayedWrite(u32 address, u8 byte)
{
saveType = 2;
cpuSaveGameFunc = flashWrite;
flashWrite(address, byte);
}
void flashWrite(u32 address, u8 byte) void flashWrite(u32 address, u8 byte)
{ {
// log("Writing %02x at %08x\n", byte, address); // log("Writing %02x at %08x\n", byte, address);
// log("Current state is %d\n", flashState); // log("Current state is %d\n", flashState);
address &= 0xFFFF; address &= 0xFFFF;
switch(flashState) switch(flashState) {
{ case FLASH_READ_ARRAY:
case FLASH_READ_ARRAY: if(address == 0x5555 && byte == 0xAA)
if(address == 0x5555 && byte == 0xAA) flashState = FLASH_CMD_1;
flashState = FLASH_CMD_1; break;
break; case FLASH_CMD_1:
case FLASH_CMD_1: if(address == 0x2AAA && byte == 0x55)
if(address == 0x2AAA && byte == 0x55) flashState = FLASH_CMD_2;
flashState = FLASH_CMD_2; else
else flashState = FLASH_READ_ARRAY;
break;
case FLASH_CMD_2:
if(address == 0x5555) {
if(byte == 0x90) {
flashState = FLASH_AUTOSELECT;
flashReadState = FLASH_AUTOSELECT;
} else if(byte == 0x80) {
flashState = FLASH_CMD_3;
} else if(byte == 0xF0) {
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
break; flashReadState = FLASH_READ_ARRAY;
case FLASH_CMD_2: } else if(byte == 0xA0) {
if(address == 0x5555) flashState = FLASH_PROGRAM;
{ } else if(byte == 0xB0 && flashSize == 0x20000) {
if(byte == 0x90) flashState = FLASH_SETBANK;
{ } else {
flashState = FLASH_AUTOSELECT; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_AUTOSELECT; flashReadState = FLASH_READ_ARRAY;
} }
else if(byte == 0x80) } else {
{
flashState = FLASH_CMD_3;
}
else if(byte == 0xF0)
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
else if(byte == 0xA0)
{
flashState = FLASH_PROGRAM;
}
else if(byte == 0xB0 && flashSize == 0x20000)
{
flashState = FLASH_SETBANK;
}
else
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
}
else
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_CMD_3:
if(address == 0x5555 && byte == 0xAA)
{
flashState = FLASH_CMD_4;
}
else
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_CMD_4:
if(address == 0x2AAA && byte == 0x55)
{
flashState = FLASH_CMD_5;
}
else
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_CMD_5:
if(byte == 0x30)
{
// SECTOR ERASE
memset(&flashSaveMemory[(flashBank << 16) + (address & 0xF000)],
0,
0x1000);
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashReadState = FLASH_ERASE_COMPLETE;
}
else if(byte == 0x10)
{
// CHIP ERASE
memset(flashSaveMemory, 0, flashSize);
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashReadState = FLASH_ERASE_COMPLETE;
}
else
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_AUTOSELECT:
if(byte == 0xF0)
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
else if(address == 0x5555 && byte == 0xAA)
flashState = FLASH_CMD_1;
else
{
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_PROGRAM:
flashSaveMemory[(flashBank<<16)+address] = byte;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
break;
case FLASH_SETBANK:
if(address == 0)
{
flashBank = (byte & 1);
}
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
break;
} }
break;
case FLASH_CMD_3:
if(address == 0x5555 && byte == 0xAA) {
flashState = FLASH_CMD_4;
} else {
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_CMD_4:
if(address == 0x2AAA && byte == 0x55) {
flashState = FLASH_CMD_5;
} else {
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_CMD_5:
if(byte == 0x30) {
// SECTOR ERASE
memset(&flashSaveMemory[(flashBank << 16) + (address & 0xF000)],
0,
0x1000);
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashReadState = FLASH_ERASE_COMPLETE;
} else if(byte == 0x10) {
// CHIP ERASE
memset(flashSaveMemory, 0, flashSize);
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashReadState = FLASH_ERASE_COMPLETE;
} else {
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_AUTOSELECT:
if(byte == 0xF0) {
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
} else if(address == 0x5555 && byte == 0xAA)
flashState = FLASH_CMD_1;
else {
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
}
break;
case FLASH_PROGRAM:
flashSaveMemory[(flashBank<<16)+address] = byte;
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
break;
case FLASH_SETBANK:
if(address == 0) {
flashBank = (byte & 1);
}
flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY;
break;
}
} }

View File

@ -20,14 +20,17 @@
#ifndef VBA_FLASH_H #ifndef VBA_FLASH_H
#define VBA_FLASH_H #define VBA_FLASH_H
extern void flashSaveGame(gzFile gzFile); extern void flashSaveGame(gzFile _gzFile);
extern void flashReadGame(gzFile gzFile, int version); extern void flashReadGame(gzFile _gzFile, int version);
extern void flashReadGameSkip(gzFile _gzFile, int version);
extern u8 flashRead(u32 address); extern u8 flashRead(u32 address);
extern void flashWrite(u32 address, u8 byte); extern void flashWrite(u32 address, u8 byte);
extern void flashDelayedWrite(u32 address, u8 byte);
extern u8 flashSaveMemory[0x20000]; extern u8 flashSaveMemory[0x20000];
extern void flashSaveDecide(u32 address, u8 byte); extern void flashSaveDecide(u32 address, u8 byte);
extern void flashReset(); extern void flashReset();
extern void flashSetSize(int size); extern void flashSetSize(int size);
extern void flashInit();
extern int flashSize; extern int flashSize;
#endif // VBA_FLASH_H #endif // VBA_FLASH_H

File diff suppressed because it is too large Load Diff

View File

@ -1,556 +0,0 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef VBA_GBAinline_H
#define VBA_GBAinline_H
#include "System.h"
#include "Port.h"
#include "RTC.h"
#include "vmmem.h"
extern bool cpuSramEnabled;
extern bool cpuFlashEnabled;
extern bool cpuEEPROMEnabled;
extern bool cpuEEPROMSensorEnabled;
#define VM_USED 1
#define CPUReadByteQuickDef(addr) \
map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]
#define CPUReadHalfWordQuickDef(addr) \
READ16LE(((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
#define CPUReadMemoryQuickDef(addr) \
READ32LE(((u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
u8 inline CPUReadByteQuick( u32 addr )
{
switch(addr >> 24 )
{
case 8:
case 9:
case 10:
case 12:
return VMRead8( addr & 0x1FFFFFF );
default:
return CPUReadByteQuickDef(addr);
}
return 0;
}
u16 inline CPUReadHalfWordQuick( u32 addr )
{
switch(addr >> 24)
{
case 8:
case 9:
case 10:
case 12:
return VMRead16( addr & 0x1FFFFFF );
default:
return CPUReadHalfWordQuickDef(addr);
}
return 0;
}
u32 inline CPUReadMemoryQuick( u32 addr )
{
switch(addr >> 24)
{
case 8:
case 9:
case 10:
case 12:
return VMRead32( addr & 0x1FFFFFF );
default:
return CPUReadMemoryQuickDef(addr);
}
return 0;
}
inline u32 CPUReadMemory(u32 address)
{
#ifdef DEV_VERSION
if(address & 3)
{
if(systemVerbose & VERBOSE_UNALIGNED_MEMORY)
{
log("Unaligned word read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
}
#endif
u32 value;
switch(address >> 24)
{
case 0:
if(reg[15].I >> 24)
{
if(address < 0x4000)
{
#ifdef DEV_VERSION
if(systemVerbose & VERBOSE_ILLEGAL_READ)
{
log("Illegal word read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
value = READ32LE(((u32 *)&biosProtected));
}
else goto unreadable;
}
else
value = READ32LE(((u32 *)&bios[address & 0x3FFC]));
break;
case 2:
value = READ32LE(((u32 *)&workRAM[address & 0x3FFFC]));
break;
case 3:
value = READ32LE(((u32 *)&internalRAM[address & 0x7ffC]));
break;
case 4:
if((address < 0x4000400) && ioReadable[address & 0x3fc])
{
if(ioReadable[(address & 0x3fc) + 2])
value = READ32LE(((u32 *)&ioMem[address & 0x3fC]));
else
value = READ16LE(((u16 *)&ioMem[address & 0x3fc]));
}
else goto unreadable;
break;
case 5:
value = READ32LE(((u32 *)&paletteRAM[address & 0x3fC]));
break;
case 6:
value = READ32LE(((u32 *)&vram[address & 0x1fffc]));
break;
case 7:
value = READ32LE(((u32 *)&oam[address & 0x3FC]));
break;
case 8:
case 9:
case 10:
case 11:
case 12:
/** Need NGC VM here **/
//value = READ32LE(((u32 *)&rom[address&0x1FFFFFC]));
value = VMRead32( address & 0x1FFFFFC );
break;
case 13:
if(cpuEEPROMEnabled)
// no need to swap this
return eepromRead(address);
goto unreadable;
case 14:
if(cpuFlashEnabled | cpuSramEnabled)
// no need to swap this
return flashRead(address);
// default
default:
unreadable:
#ifdef DEV_VERSION
if(systemVerbose & VERBOSE_ILLEGAL_READ)
{
log("Illegal word read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
// if(ioMem[0x205] & 0x40) {
if(armState)
{
#if VM_USED
value = CPUReadMemoryQuick(reg[15].I);
#else
value = CPUReadMemoryQuickDef(reg[15].I);
#endif
//value = VMRead32(reg[15].I);
}
else
{
#if VM_USED
value = CPUReadHalfWordQuick(reg[15].I) |
CPUReadHalfWordQuick(reg[15].I) << 16;
#else
value = CPUReadHalfWordQuickDef(reg[15].I) |
CPUReadHalfWordQuickDef(reg[15].I) << 16;
#endif
//value = VMRead16(reg[15].I) | VMRead16(reg[15].I) << 16;
}
// } else {
// value = *((u32 *)&bios[address & 0x3ffc]);
// }
// return 0xFFFFFFFF;
}
if(address & 3)
{
#ifdef C_CORE
int shift = (address & 3) << 3;
value = (value >> shift) | (value << (32 - shift));
#else
#ifdef __GNUC__
asm("and $3, %%ecx;"
"shl $3 ,%%ecx;"
"ror %%cl, %0"
: "=r" (value)
: "r" (value), "c" (address));
#else
__asm {
mov ecx, address;
and ecx, 3;
shl ecx, 3;
ror [dword ptr value], cl;
}
#endif
#endif
}
return value;
}
extern u32 myROM[];
inline u32 CPUReadHalfWord(u32 address)
{
#ifdef DEV_VERSION
if(address & 1)
{
if(systemVerbose & VERBOSE_UNALIGNED_MEMORY)
{
log("Unaligned halfword read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
}
#endif
u32 value;
switch(address >> 24)
{
case 0:
if (reg[15].I >> 24)
{
if(address < 0x4000)
{
#ifdef DEV_VERSION
if(systemVerbose & VERBOSE_ILLEGAL_READ)
{
log("Illegal halfword read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
value = READ16LE(((u16 *)&biosProtected[address&2]));
}
else goto unreadable;
}
else
value = READ16LE(((u16 *)&bios[address & 0x3FFE]));
break;
case 2:
value = READ16LE(((u16 *)&workRAM[address & 0x3FFFE]));
break;
case 3:
value = READ16LE(((u16 *)&internalRAM[address & 0x7ffe]));
break;
case 4:
if((address < 0x4000400) && ioReadable[address & 0x3fe])
value = READ16LE(((u16 *)&ioMem[address & 0x3fe]));
else goto unreadable;
break;
case 5:
value = READ16LE(((u16 *)&paletteRAM[address & 0x3fe]));
break;
case 6:
value = READ16LE(((u16 *)&vram[address & 0x1fffe]));
break;
case 7:
value = READ16LE(((u16 *)&oam[address & 0x3fe]));
break;
case 8:
case 9:
case 10:
case 11:
case 12:
if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
value = rtcRead(address);
else
/** Need NGC VM Here **/
//value = READ16LE(((u16 *)&rom[address & 0x1FFFFFE]));
value = VMRead16( address & 0x1FFFFFE );
break;
case 13:
if(cpuEEPROMEnabled)
// no need to swap this
return eepromRead(address);
goto unreadable;
case 14:
if(cpuFlashEnabled | cpuSramEnabled)
// no need to swap this
return flashRead(address);
// default
default:
unreadable:
#ifdef DEV_VERSION
if(systemVerbose & VERBOSE_ILLEGAL_READ)
{
log("Illegal halfword read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
extern bool cpuDmaHack;
extern u32 cpuDmaLast;
extern int cpuDmaCount;
if(cpuDmaHack && cpuDmaCount)
{
value = (u16)cpuDmaLast;
}
else
{
if(armState)
{
#if VM_USED
value = CPUReadHalfWordQuick(reg[15].I + (address & 2));
#else
value = CPUReadHalfWordQuickDef(reg[15].I + (address & 2));
#endif
//value = VMRead16(reg[15].I + (address & 2));
}
else
{
#if VM_USED
value = CPUReadHalfWordQuick(reg[15].I);
#else
value = CPUReadHalfWordQuickDef(reg[15].I);
#endif
//value = VMRead16(reg[15].I);
}
}
// return value;
// if(address & 1)
// value = (value >> 8) | ((value & 0xFF) << 24);
// return 0xFFFF;
break;
}
if(address & 1)
{
value = (value >> 8) | (value << 24);
}
return value;
}
inline u16 CPUReadHalfWordSigned(u32 address)
{
u16 value = CPUReadHalfWord(address);
if((address & 1))
value = (s8)value;
return value;
}
inline u8 CPUReadByte(u32 address)
{
switch(address >> 24)
{
case 0:
if (reg[15].I >> 24)
{
if(address < 0x4000)
{
#ifdef DEV_VERSION
if(systemVerbose & VERBOSE_ILLEGAL_READ)
{
log("Illegal byte read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
return biosProtected[address & 3];
}
else goto unreadable;
}
return bios[address & 0x3FFF];
case 2:
return workRAM[address & 0x3FFFF];
case 3:
return internalRAM[address & 0x7fff];
case 4:
if((address < 0x4000400) && ioReadable[address & 0x3ff])
return ioMem[address & 0x3ff];
else goto unreadable;
case 5:
return paletteRAM[address & 0x3ff];
case 6:
return vram[address & 0x1ffff];
case 7:
return oam[address & 0x3ff];
case 8:
case 9:
case 10:
case 11:
case 12:
/** Need NGC VM Here **/
//return rom[address & 0x1FFFFFF];
return VMRead8( address & 0x1FFFFFF );
case 13:
if(cpuEEPROMEnabled)
return eepromRead(address);
goto unreadable;
case 14:
if(cpuSramEnabled | cpuFlashEnabled)
return flashRead(address);
if(cpuEEPROMSensorEnabled)
{
switch(address & 0x00008f00)
{
case 0x8200:
return systemGetSensorX() & 255;
case 0x8300:
return (systemGetSensorX() >> 8)|0x80;
case 0x8400:
return systemGetSensorY() & 255;
case 0x8500:
return systemGetSensorY() >> 8;
}
}
// default
default:
unreadable:
#ifdef DEV_VERSION
if(systemVerbose & VERBOSE_ILLEGAL_READ)
{
log("Illegal byte read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
if(armState)
{
#if VM_USED
return CPUReadByteQuick(reg[15].I+(address & 3));
#else
return CPUReadByteQuickDef(reg[15].I+(address & 3));
#endif
//return VMRead8(reg[15].I+(address & 3));
}
else
{
#if VM_USED
return CPUReadByteQuick(reg[15].I+(address & 1));
#else
return CPUReadByteQuickDef(reg[15].I+(address & 1));
#endif
//return VMRead8(reg[15].I+(address & 1));
}
// return 0xFF;
break;
}
}
inline void CPUWriteMemory(u32 address, u32 value)
{
#ifdef DEV_VERSION
if(address & 3)
{
if(systemVerbose & VERBOSE_UNALIGNED_MEMORY)
{
log("Unaliagned word write: %08x to %08x from %08x\n",
value,
address,
armMode ? armNextPC - 4 : armNextPC - 2);
}
}
#endif
switch(address >> 24)
{
case 0x02:
#ifdef SDL
if(*((u32 *)&freezeWorkRAM[address & 0x3FFFC]))
cheatsWriteMemory((u32 *)&workRAM[address & 0x3FFFC],
value,
*((u32 *)&freezeWorkRAM[address & 0x3FFFC]));
else
#endif
WRITE32LE(((u32 *)&workRAM[address & 0x3FFFC]), value);
break;
case 0x03:
#ifdef SDL
if(*((u32 *)&freezeInternalRAM[address & 0x7ffc]))
cheatsWriteMemory((u32 *)&internalRAM[address & 0x7FFC],
value,
*((u32 *)&freezeInternalRAM[address & 0x7ffc]));
else
#endif
WRITE32LE(((u32 *)&internalRAM[address & 0x7ffC]), value);
break;
case 0x04:
CPUUpdateRegister((address & 0x3FC), value & 0xFFFF);
CPUUpdateRegister((address & 0x3FC) + 2, (value >> 16));
break;
case 0x05:
WRITE32LE(((u32 *)&paletteRAM[address & 0x3FC]), value);
break;
case 0x06:
if(address & 0x10000)
WRITE32LE(((u32 *)&vram[address & 0x17ffc]), value);
else
WRITE32LE(((u32 *)&vram[address & 0x1fffc]), value);
break;
case 0x07:
WRITE32LE(((u32 *)&oam[address & 0x3fc]), value);
break;
case 0x0D:
if(cpuEEPROMEnabled)
{
eepromWrite(address, value);
break;
}
goto unwritable;
case 0x0E:
if(!eepromInUse | cpuSramEnabled | cpuFlashEnabled)
{
(*cpuSaveGameFunc)(address, (u8)value);
break;
}
// default
default:
unwritable:
#ifdef DEV_VERSION
if(systemVerbose & VERBOSE_ILLEGAL_WRITE)
{
log("Illegal word write: %08x to %08x from %08x\n",
value,
address,
armMode ? armNextPC - 4 : armNextPC - 2);
}
#endif
break;
}
}
#endif //VBA_GBAinline_H

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -16,7 +16,12 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include "agb/GBA.h"
#ifdef BKPT_SUPPORT
int oldreg[17];
char oldbuffer[10];
#endif
reg_pair reg[45]; reg_pair reg[45];
memoryMap map[256]; memoryMap map[256];
@ -43,8 +48,9 @@ int layerSettings = 0xff00;
int layerEnable = 0xff00; int layerEnable = 0xff00;
bool speedHack = false; bool speedHack = false;
int cpuSaveType = 0; int cpuSaveType = 0;
bool cpuEnhancedDetection = true;
bool cheatsEnabled = true; bool cheatsEnabled = true;
bool mirroringEnable = false;
bool skipSaveGameBattery = false;
u8 *bios = NULL; u8 *bios = NULL;
u8 *rom = NULL; u8 *rom = NULL;

View File

@ -1,7 +1,7 @@
// -*- C++ -*- // -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -20,6 +20,8 @@
#ifndef VBA_GLOBALS_H #ifndef VBA_GLOBALS_H
#define VBA_GLOBALS_H #define VBA_GLOBALS_H
#include "agb/GBA.h"
#define VERBOSE_SWI 1 #define VERBOSE_SWI 1
#define VERBOSE_UNALIGNED_MEMORY 2 #define VERBOSE_UNALIGNED_MEMORY 2
#define VERBOSE_ILLEGAL_WRITE 4 #define VERBOSE_ILLEGAL_WRITE 4
@ -30,6 +32,7 @@
#define VERBOSE_DMA3 128 #define VERBOSE_DMA3 128
#define VERBOSE_UNDEFINED 256 #define VERBOSE_UNDEFINED 256
#define VERBOSE_AGBPRINT 512 #define VERBOSE_AGBPRINT 512
#define VERBOSE_SOUNDOUTPUT 1024
extern reg_pair reg[45]; extern reg_pair reg[45];
extern bool ioReadable[0x400]; extern bool ioReadable[0x400];
@ -55,8 +58,9 @@ extern int layerSettings;
extern int layerEnable; extern int layerEnable;
extern bool speedHack; extern bool speedHack;
extern int cpuSaveType; extern int cpuSaveType;
extern bool cpuEnhancedDetection;
extern bool cheatsEnabled; extern bool cheatsEnabled;
extern bool mirroringEnable;
extern bool skipSaveGameBattery;
extern u8 *bios; extern u8 *bios;
extern u8 *rom; extern u8 *rom;

File diff suppressed because it is too large Load Diff

View File

@ -16,123 +16,107 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Gfx.h" #include "agb/GBAGfx.h"
void mode1RenderLine() void mode1RenderLine()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x0100) if(layerEnable & 0x0100) {
{ gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); }
}
if(layerEnable & 0x0200) if(layerEnable & 0x0200) {
{ gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); }
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3; gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2PC, BG2PD,
BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y, changed, line2);
gfxBG2X, gfxBG2Y, changed, line2); }
}
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20;
if(line0[x] < color) if(line0[x] < color) {
{ color = line0[x];
color = line0[x]; top = 0x01;
top = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(color >> 24))
{
color = line1[x];
top = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(color >> 24))
{
color = line2[x];
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000))
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24))
{
back = line0[x];
top2 = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(back >> 24))
{
back = line1[x];
top2 = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(line1[x]>>24) < (u8)(color >> 24)) {
color = line1[x];
top = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(color >> 24)) {
color = line2[x];
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000)) {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24)) {
back = line0[x];
top2 = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(back >> 24)) {
back = line1[x];
top2 = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
@ -141,181 +125,153 @@ void mode1RenderLineNoWindow()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x0100) if(layerEnable & 0x0100) {
{ gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); }
}
if(layerEnable & 0x0200) if(layerEnable & 0x0200) {
{ gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); }
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3; gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2PC, BG2PD,
BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y, changed, line2);
gfxBG2X, gfxBG2Y, changed, line2); }
}
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20;
if(line0[x] < color) if(line0[x] < color) {
{ color = line0[x];
color = line0[x]; top = 0x01;
top = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(color >> 24))
{
color = line1[x];
top = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(color >> 24))
{
color = line2[x];
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24))
{
if(top != 0x01)
{
back = line0[x];
top2 = 0x01;
}
}
if((u8)(line1[x]>>24) < (u8)(back >> 24))
{
if(top != 0x02)
{
back = line1[x];
top2 = 0x02;
}
}
if((u8)(line2[x]>>24) < (u8)(back >> 24))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24))
{
back = line0[x];
top2 = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(back >> 24))
{
back = line1[x];
top2 = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(line1[x]>>24) < (u8)(color >> 24)) {
color = line1[x];
top = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(color >> 24)) {
color = line2[x];
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000)) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24)) {
if(top != 0x01) {
back = line0[x];
top2 = 0x01;
}
}
if((u8)(line1[x]>>24) < (u8)(back >> 24)) {
if(top != 0x02) {
back = line1[x];
top2 = 0x02;
}
}
if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
} else {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24)) {
back = line0[x];
top2 = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(back >> 24)) {
back = line1[x];
top2 = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
@ -324,59 +280,52 @@ void mode1RenderLineAll()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
bool inWindow0 = false; bool inWindow0 = false;
bool inWindow1 = false; bool inWindow1 = false;
if(layerEnable & 0x2000) if(layerEnable & 0x2000) {
{ u8 v0 = WIN0V >> 8;
u8 v0 = WIN0V >> 8; u8 v1 = WIN0V & 255;
u8 v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); if(v1 >= v0)
if(v1 >= v0) inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1); else
else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); }
} if(layerEnable & 0x4000) {
if(layerEnable & 0x4000) u8 v0 = WIN1V >> 8;
{ u8 v1 = WIN1V & 255;
u8 v0 = WIN1V >> 8; inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
u8 v1 = WIN1V & 255; if(v1 >= v0)
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
if(v1 >= v0) else
inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1); inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
else }
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
}
if(layerEnable & 0x0100) if(layerEnable & 0x0100) {
{ gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0); }
}
if(layerEnable & 0x0200) if(layerEnable & 0x0200) {
{ gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1); }
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3; gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2PC, BG2PD,
BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y, changed, line2);
gfxBG2X, gfxBG2Y, changed, line2); }
}
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
gfxDrawOBJWin(lineOBJWin); gfxDrawOBJWin(lineOBJWin);
@ -387,213 +336,141 @@ void mode1RenderLineAll()
u8 inWin1Mask = WININ >> 8; u8 inWin1Mask = WININ >> 8;
u8 outMask = WINOUT & 0xFF; u8 outMask = WINOUT & 0xFF;
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20; u8 mask = outMask;
u8 mask = outMask;
if(!(lineOBJWin[x] & 0x80000000)) if(!(lineOBJWin[x] & 0x80000000)) {
{ mask = WINOUT >> 8;
mask = WINOUT >> 8;
}
if(inWindow1)
{
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0)
{
if(gfxInWin0[x])
{
mask = inWin0Mask;
}
}
if(line0[x] < color && (mask & 1))
{
color = line0[x];
top = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(color >> 24) && (mask & 2))
{
color = line1[x];
top = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(color >> 24) && (mask & 4))
{
color = line2[x];
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16))
{
color = lineOBJ[x];
top = 0x10;
}
// special FX on the window
if(mask & 32)
{
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
{
if(top != 0x01)
{
back = line0[x];
top2 = 0x01;
}
}
if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24))
{
if(top != 0x02)
{
back = line1[x];
top2 = 0x02;
}
}
if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
{
back = line0[x];
top2 = 0x01;
}
if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24))
{
back = line1[x];
top2 = 0x02;
}
if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
}
else if(color & 0x00010000)
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
{
back = line0[x];
top2 = 0x01;
}
if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24))
{
back = line1[x];
top2 = 0x02;
}
if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if(inWindow1) {
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0) {
if(gfxInWin0[x]) {
mask = inWin0Mask;
}
}
if(line0[x] < color && (mask & 1)) {
color = line0[x];
top = 0x01;
}
if((u8)(line1[x]>>24) < (u8)(color >> 24) && (mask & 2)) {
color = line1[x];
top = 0x02;
}
if((u8)(line2[x]>>24) < (u8)(color >> 24) && (mask & 4)) {
color = line2[x];
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16)) {
color = lineOBJ[x];
top = 0x10;
}
if(color & 0x00010000) {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) {
back = line0[x];
top2 = 0x01;
}
if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) {
back = line1[x];
top2 = 0x02;
}
if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
} else if(mask & 32) {
// special FX on the window
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) {
if(top != 0x01) {
back = line0[x];
top2 = 0x01;
}
}
if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) {
if(top != 0x02) {
back = line1[x];
top2 = 0x02;
}
}
if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }

View File

@ -16,114 +16,101 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Gfx.h" #include "agb/GBAGfx.h"
void mode2RenderLine() void mode2RenderLine()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3;
gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y, BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
changed, line2); changed, line2);
} }
if(layerEnable & 0x0800) if(layerEnable & 0x0800) {
{ int changed = gfxBG3Changed;
int changed = gfxBG3Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3;
gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H, gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y, BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
changed, line3); changed, line3);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20;
if((u8)(line2[x]>>24) < (u8)(color >> 24)) if((u8)(line2[x]>>24) < (u8)(color >> 24)) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(color >> 24))
{
color = line3[x];
top = 0x08;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000))
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(back >> 24))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(line3[x]>>24) < (u8)(color >> 24)) {
color = line3[x];
top = 0x08;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000)) {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
back = line2[x];
top2 = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(back >> 24)) {
back = line3[x];
top2 = 0x08;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxBG3Changed = 0; gfxBG3Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
@ -133,163 +120,140 @@ void mode2RenderLineNoWindow()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3;
gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y, BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
changed, line2); changed, line2);
} }
if(layerEnable & 0x0800) if(layerEnable & 0x0800) {
{ int changed = gfxBG3Changed;
int changed = gfxBG3Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3;
gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H, gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y, BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
changed, line3); changed, line3);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20;
if((u8)(line2[x]>>24) < (u8)(color >> 24)) if((u8)(line2[x]>>24) < (u8)(color >> 24)) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(color >> 24))
{
color = line3[x];
top = 0x08;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24))
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((u8)(line3[x]>>24) < (u8)(back >> 24))
{
if(top != 0x08)
{
back = line3[x];
top2 = 0x08;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24))
{
back = line2[x];
top2 = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(back >> 24))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(line3[x]>>24) < (u8)(color >> 24)) {
color = line3[x];
top = 0x08;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000)) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((u8)(line3[x]>>24) < (u8)(back >> 24)) {
if(top != 0x08) {
back = line3[x];
top2 = 0x08;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
} else {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
back = line2[x];
top2 = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(back >> 24)) {
back = line3[x];
top2 = 0x08;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxBG3Changed = 0; gfxBG3Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
@ -299,61 +263,55 @@ void mode2RenderLineAll()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
bool inWindow0 = false; bool inWindow0 = false;
bool inWindow1 = false; bool inWindow1 = false;
if(layerEnable & 0x2000) if(layerEnable & 0x2000) {
{ u8 v0 = WIN0V >> 8;
u8 v0 = WIN0V >> 8; u8 v1 = WIN0V & 255;
u8 v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); if(v1 >= v0)
if(v1 >= v0) inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1); else
else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); }
} if(layerEnable & 0x4000) {
if(layerEnable & 0x4000) u8 v0 = WIN1V >> 8;
{ u8 v1 = WIN1V & 255;
u8 v0 = WIN1V >> 8; inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
u8 v1 = WIN1V & 255; if(v1 >= v0)
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
if(v1 >= v0) else
inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1); inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
else }
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3;
gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, gfxDrawRotScreen(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y, BG2PA, BG2PB, BG2PC, BG2PD, gfxBG2X, gfxBG2Y,
changed, line2); changed, line2);
} }
if(layerEnable & 0x0800) if(layerEnable & 0x0800) {
{ int changed = gfxBG3Changed;
int changed = gfxBG3Changed; if(gfxLastVCOUNT > VCOUNT)
if(gfxLastVCOUNT > VCOUNT) changed = 3;
changed = 3;
gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H, gfxDrawRotScreen(BG3CNT, BG3X_L, BG3X_H, BG3Y_L, BG3Y_H,
BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y, BG3PA, BG3PB, BG3PC, BG3PD, gfxBG3X, gfxBG3Y,
changed, line3); changed, line3);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
gfxDrawOBJWin(lineOBJWin); gfxDrawOBJWin(lineOBJWin);
@ -364,186 +322,124 @@ void mode2RenderLineAll()
u8 inWin1Mask = WININ >> 8; u8 inWin1Mask = WININ >> 8;
u8 outMask = WINOUT & 0xFF; u8 outMask = WINOUT & 0xFF;
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20; u8 mask = outMask;
u8 mask = outMask;
if(!(lineOBJWin[x] & 0x80000000)) if(!(lineOBJWin[x] & 0x80000000)) {
{ mask = WINOUT >> 8;
mask = WINOUT >> 8;
}
if(inWindow1)
{
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0)
{
if(gfxInWin0[x])
{
mask = inWin0Mask;
}
}
if(line2[x] < color && (mask & 4))
{
color = line2[x];
top = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(color >> 24) && (mask & 8))
{
color = line3[x];
top = 0x08;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16))
{
color = lineOBJ[x];
top = 0x10;
}
if(mask & 32)
{
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
{
if(top != 0x08)
{
back = line3[x];
top2 = 0x08;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
}
else if(color & 0x00010000)
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24))
{
back = line3[x];
top2 = 0x08;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if(inWindow1) {
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0) {
if(gfxInWin0[x]) {
mask = inWin0Mask;
}
}
if(line2[x] < color && (mask & 4)) {
color = line2[x];
top = 0x04;
}
if((u8)(line3[x]>>24) < (u8)(color >> 24) && (mask & 8)) {
color = line3[x];
top = 0x08;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16)) {
color = lineOBJ[x];
top = 0x10;
}
if(color & 0x00010000) {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) {
back = line3[x];
top2 = 0x08;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
} else if(mask & 32) {
// special FX on the window
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) {
if(top != 0x08) {
back = line3[x];
top2 = 0x08;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxBG3Changed = 0; gfxBG3Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;

View File

@ -16,93 +16,83 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Gfx.h" #include "agb/GBAGfx.h"
void mode3RenderLine() void mode3RenderLine()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H, gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H,
BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2Y_L, BG2Y_H, BG2PA, BG2PB,
BG2PC, BG2PD, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 background = (READ16LE(&palette[0]) | 0x30000000); u32 background = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = background;
u32 color = background; u8 top = 0x20;
u8 top = 0x20;
if(line2[x] < color) if(line2[x] < color) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
{
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000))
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000)) {
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
@ -111,134 +101,116 @@ void mode3RenderLineNoWindow()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H, gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H,
BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2Y_L, BG2Y_H, BG2PA, BG2PB,
BG2PC, BG2PD, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 background = (READ16LE(&palette[0]) | 0x30000000); u32 background = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = background;
u32 color = background; u8 top = 0x20;
u8 top = 0x20;
if(line2[x] < color) if(line2[x] < color) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
{
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000)) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
} else {
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
@ -247,53 +219,48 @@ void mode3RenderLineAll()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x80) if(DISPCNT & 0x80) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
bool inWindow0 = false; bool inWindow0 = false;
bool inWindow1 = false; bool inWindow1 = false;
if(layerEnable & 0x2000) if(layerEnable & 0x2000) {
{ u8 v0 = WIN0V >> 8;
u8 v0 = WIN0V >> 8; u8 v1 = WIN0V & 255;
u8 v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); if(v1 >= v0)
if(v1 >= v0) inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1); else
else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); }
} if(layerEnable & 0x4000) {
if(layerEnable & 0x4000) u8 v0 = WIN1V >> 8;
{ u8 v1 = WIN1V & 255;
u8 v0 = WIN1V >> 8; inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
u8 v1 = WIN1V & 255; if(v1 >= v0)
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
if(v1 >= v0) else
inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1); inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
else }
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
}
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H, gfxDrawRotScreen16Bit(BG2CNT, BG2X_L, BG2X_H,
BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2Y_L, BG2Y_H, BG2PA, BG2PB,
BG2PC, BG2PD, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
gfxDrawOBJWin(lineOBJWin); gfxDrawOBJWin(lineOBJWin);
@ -304,160 +271,107 @@ void mode3RenderLineAll()
u32 background = (READ16LE(&palette[0]) | 0x30000000); u32 background = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = background;
u32 color = background; u8 top = 0x20;
u8 top = 0x20; u8 mask = outMask;
u8 mask = outMask;
if(!(lineOBJWin[x] & 0x80000000)) if(!(lineOBJWin[x] & 0x80000000)) {
{ mask = WINOUT >> 8;
mask = WINOUT >> 8;
}
if(inWindow1)
{
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0)
{
if(gfxInWin0[x])
{
mask = inWin0Mask;
}
}
if((mask & 4) && (line2[x] < color))
{
color = line2[x];
top = 0x04;
}
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24)))
{
color = lineOBJ[x];
top = 0x10;
}
if(mask & 32)
{
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
}
else if(color & 0x00010000)
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if(inWindow1) {
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0) {
if(gfxInWin0[x]) {
mask = inWin0Mask;
}
}
if((mask & 4) && (line2[x] < color)) {
color = line2[x];
top = 0x04;
}
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) {
color = lineOBJ[x];
top = 0x10;
}
if(color & 0x00010000) {
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
} else if(mask & 32) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }

View File

@ -16,92 +16,82 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include "agb/GBA.h"
#include "Gfx.h" #include "agb/GBAGfx.h"
#include "Globals.h" #include "Globals.h"
void mode4RenderLine() void mode4RenderLine()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x0080) if(DISPCNT & 0x0080) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x400) if(layerEnable & 0x400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
BG2PA, BG2PB, BG2PC, BG2PD, BG2PA, BG2PB, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20;
if(line2[x] < color) if(line2[x] < color) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000))
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000)) {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if(line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
@ -110,133 +100,115 @@ void mode4RenderLineNoWindow()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x0080) if(DISPCNT & 0x0080) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
if(layerEnable & 0x400) if(layerEnable & 0x400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
BG2PA, BG2PB, BG2PC, BG2PD, BG2PA, BG2PB, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 backdrop = (READ16LE(&palette[0]) | 0x30000000); u32 backdrop = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20;
if(line2[x] < color) if(line2[x] < color) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))
{
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = backdrop;
u8 top2 = 0x20;
if(line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000)) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
if(line2[x] < back) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
} else {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if(line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
@ -245,52 +217,47 @@ void mode4RenderLineAll()
{ {
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(DISPCNT & 0x0080) if(DISPCNT & 0x0080) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
bool inWindow0 = false; bool inWindow0 = false;
bool inWindow1 = false; bool inWindow1 = false;
if(layerEnable & 0x2000) if(layerEnable & 0x2000) {
{ u8 v0 = WIN0V >> 8;
u8 v0 = WIN0V >> 8; u8 v1 = WIN0V & 255;
u8 v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); if(v1 >= v0)
if(v1 >= v0) inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1); else
else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); }
} if(layerEnable & 0x4000) {
if(layerEnable & 0x4000) u8 v0 = WIN1V >> 8;
{ u8 v1 = WIN1V & 255;
u8 v0 = WIN1V >> 8; inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
u8 v1 = WIN1V & 255; if(v1 >= v0)
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
if(v1 >= v0) else
inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1); inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
else }
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
}
if(layerEnable & 0x400) if(layerEnable & 0x400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H, gfxDrawRotScreen256(BG2CNT, BG2X_L, BG2X_H, BG2Y_L, BG2Y_H,
BG2PA, BG2PB, BG2PC, BG2PD, BG2PA, BG2PB, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
gfxDrawOBJWin(lineOBJWin); gfxDrawOBJWin(lineOBJWin);
@ -301,160 +268,107 @@ void mode4RenderLineAll()
u8 inWin1Mask = WININ >> 8; u8 inWin1Mask = WININ >> 8;
u8 outMask = WINOUT & 0xFF; u8 outMask = WINOUT & 0xFF;
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = backdrop;
u32 color = backdrop; u8 top = 0x20;
u8 top = 0x20; u8 mask = outMask;
u8 mask = outMask;
if(!(lineOBJWin[x] & 0x80000000)) if(!(lineOBJWin[x] & 0x80000000)) {
{ mask = WINOUT >> 8;
mask = WINOUT >> 8;
}
if(inWindow1)
{
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0)
{
if(gfxInWin0[x])
{
mask = inWin0Mask;
}
}
if((mask & 4) && (line2[x] < color))
{
color = line2[x];
top = 0x04;
}
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24)))
{
color = lineOBJ[x];
top = 0x10;
}
if(mask & 32)
{
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
}
else if(color & 0x00010000)
{
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if(inWindow1) {
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0) {
if(gfxInWin0[x]) {
mask = inWin0Mask;
}
}
if((mask & 4) && (line2[x] < color)) {
color = line2[x];
top = 0x04;
}
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) {
color = lineOBJ[x];
top = 0x10;
}
if(color & 0x00010000) {
// semi-transparent OBJ
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
} else if(mask & 32) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }

View File

@ -16,260 +16,229 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Gfx.h" #include "agb/GBAGfx.h"
void mode5RenderLine() void mode5RenderLine()
{ {
if(DISPCNT & 0x0080) if(DISPCNT & 0x0080) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H, gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H,
BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2Y_L, BG2Y_H, BG2PA, BG2PB,
BG2PC, BG2PD, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 background = (READ16LE(&palette[0]) | 0x30000000); u32 background = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = background;
u32 color = background; u8 top = 0x20;
u8 top = 0x20;
if(line2[x] < color) if(line2[x] < color) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
{
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000))
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
color = lineOBJ[x];
top = 0x10;
}
if((top & 0x10) && (color & 0x00010000)) {
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
void mode5RenderLineNoWindow() void mode5RenderLineNoWindow()
{ {
if(DISPCNT & 0x0080) if(DISPCNT & 0x0080) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H, gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H,
BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2Y_L, BG2Y_H, BG2PA, BG2PB,
BG2PC, BG2PD, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
u32 background = ( READ16LE(&palette[0]) | 0x30000000); u32 background = ( READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = background;
u32 color = background; u8 top = 0x20;
u8 top = 0x20;
if(line2[x] < color) if(line2[x] < color) {
{ color = line2[x];
color = line2[x]; top = 0x04;
top = 0x04;
}
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24))
{
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
color = lineOBJ[x];
top = 0x10;
}
if(!(color & 0x00010000)) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
} else {
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if(line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }
void mode5RenderLineAll() void mode5RenderLineAll()
{ {
if(DISPCNT & 0x0080) if(DISPCNT & 0x0080) {
{ for(int x = 0; x < 240; x++) {
for(int x = 0; x < 240; x++) lineMix[x] = 0x7fff;
{
lineMix[x] = 0x7fff;
}
gfxLastVCOUNT = VCOUNT;
return;
} }
gfxLastVCOUNT = VCOUNT;
return;
}
u16 *palette = (u16 *)paletteRAM; u16 *palette = (u16 *)paletteRAM;
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{ int changed = gfxBG2Changed;
int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H, gfxDrawRotScreen16Bit160(BG2CNT, BG2X_L, BG2X_H,
BG2Y_L, BG2Y_H, BG2PA, BG2PB, BG2Y_L, BG2Y_H, BG2PA, BG2PB,
BG2PC, BG2PD, BG2PC, BG2PD,
gfxBG2X, gfxBG2Y, changed, gfxBG2X, gfxBG2Y, changed,
line2); line2);
} }
gfxDrawSprites(lineOBJ); gfxDrawSprites(lineOBJ);
gfxDrawOBJWin(lineOBJWin); gfxDrawOBJWin(lineOBJWin);
@ -277,26 +246,24 @@ void mode5RenderLineAll()
bool inWindow0 = false; bool inWindow0 = false;
bool inWindow1 = false; bool inWindow1 = false;
if(layerEnable & 0x2000) if(layerEnable & 0x2000) {
{ u8 v0 = WIN0V >> 8;
u8 v0 = WIN0V >> 8; u8 v1 = WIN0V & 255;
u8 v1 = WIN0V & 255; inWindow0 = ((v0 == v1) && (v0 >= 0xe8));
inWindow0 = ((v0 == v1) && (v0 >= 0xe8)); if(v1 >= v0)
if(v1 >= v0) inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 && VCOUNT < v1); else
else inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); }
} if(layerEnable & 0x4000) {
if(layerEnable & 0x4000) u8 v0 = WIN1V >> 8;
{ u8 v1 = WIN1V & 255;
u8 v0 = WIN1V >> 8; inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
u8 v1 = WIN1V & 255; if(v1 >= v0)
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1);
if(v1 >= v0) else
inWindow1 |= (VCOUNT >= v0 && VCOUNT < v1); inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
else }
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
}
u8 inWin0Mask = WININ & 0xFF; u8 inWin0Mask = WININ & 0xFF;
u8 inWin1Mask = WININ >> 8; u8 inWin1Mask = WININ >> 8;
@ -304,160 +271,107 @@ void mode5RenderLineAll()
u32 background = (READ16LE(&palette[0]) | 0x30000000); u32 background = (READ16LE(&palette[0]) | 0x30000000);
for(int x = 0; x < 240; x++) for(int x = 0; x < 240; x++) {
{ u32 color = background;
u32 color = background; u8 top = 0x20;
u8 top = 0x20; u8 mask = outMask;
u8 mask = outMask;
if(!(lineOBJWin[x] & 0x80000000)) if(!(lineOBJWin[x] & 0x80000000)) {
{ mask = WINOUT >> 8;
mask = WINOUT >> 8;
}
if(inWindow1)
{
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0)
{
if(gfxInWin0[x])
{
mask = inWin0Mask;
}
}
if((mask & 4) && (line2[x] < color))
{
color = line2[x];
top = 0x04;
}
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24)))
{
color = lineOBJ[x];
top = 0x10;
}
if(mask & 32)
{
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0:
break;
case 1:
{
if(top & BLDMOD)
{
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
if(top != 0x04)
{
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24))
{
if(top != 0x10)
{
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
else
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
}
else if(color & 0x00010000)
{
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back)
{
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else
{
switch((BLDMOD >> 6) & 3)
{
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
}
lineMix[x] = color;
} }
if(inWindow1) {
if(gfxInWin1[x])
mask = inWin1Mask;
}
if(inWindow0) {
if(gfxInWin0[x]) {
mask = inWin0Mask;
}
}
if((mask & 4) && (line2[x] < color)) {
color = line2[x];
top = 0x04;
}
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) {
color = lineOBJ[x];
top = 0x10;
}
if(color & 0x00010000) {
// semi-transparent OBJ
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
back = line2[x];
top2 = 0x04;
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
else {
switch((BLDMOD >> 6) & 3) {
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
} else if(mask & 32) {
switch((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
if(top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) {
if(top != 0x04) {
back = line2[x];
top2 = 0x04;
}
}
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
if(top != 0x10) {
back = lineOBJ[x];
top2 = 0x10;
}
}
if(top2 & (BLDMOD>>8))
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
case 2:
if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
break;
case 3:
if(BLDMOD & top)
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break;
}
}
lineMix[x] = color;
}
gfxBG2Changed = 0; gfxBG2Changed = 0;
gfxLastVCOUNT = VCOUNT; gfxLastVCOUNT = VCOUNT;
} }

View File

@ -60,3 +60,5 @@
#define MSG_INVALID_CBA_CODE 39 #define MSG_INVALID_CBA_CODE 39
#define MSG_CBA_CODE_WARNING 40 #define MSG_CBA_CODE_WARNING 40
#define MSG_OUT_OF_MEMORY 41 #define MSG_OUT_OF_MEMORY 41
#define MSG_WRONG_GAMESHARK_CODE 42
#define MSG_UNSUPPORTED_GAMESHARK_CODE 43

View File

@ -33,8 +33,6 @@ static inline u32 swap32(u32 v)
} }
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
#define __ppc__
#if defined(__GNUC__) && defined(__ppc__) #if defined(__GNUC__) && defined(__ppc__)
#define READ16LE(base) \ #define READ16LE(base) \

View File

@ -1,6 +1,6 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -17,7 +17,7 @@
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "System.h" #include "System.h"
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Port.h" #include "Port.h"
#include "Util.h" #include "Util.h"
@ -29,22 +29,20 @@
enum RTCSTATE { IDLE, COMMAND, DATA, READDATA }; enum RTCSTATE { IDLE, COMMAND, DATA, READDATA };
typedef struct typedef struct {
{ u8 byte0;
u8 byte0; u8 byte1;
u8 byte1; u8 byte2;
u8 byte2; u8 command;
u8 command; int dataLen;
int dataLen; int bits;
int bits; RTCSTATE state;
RTCSTATE state; u8 data[12];
u8 data[12]; // reserved variables for future
// reserved variables for future u8 reserved[12];
u8 reserved[12]; bool reserved2;
bool reserved2; u32 reserved3;
u32 reserved3; } RTCCLOCKDATA;
}
RTCCLOCKDATA;
static RTCCLOCKDATA rtcClockData; static RTCCLOCKDATA rtcClockData;
static bool rtcEnabled = false; static bool rtcEnabled = false;
@ -61,18 +59,19 @@ bool rtcIsEnabled()
u16 rtcRead(u32 address) u16 rtcRead(u32 address)
{ {
if(rtcEnabled) if(rtcEnabled) {
{ switch(address){
if(address == 0x80000c8) case 0x80000c8:
return rtcClockData.byte2; return rtcClockData.byte2;
else if(address == 0x80000c6) break;
return rtcClockData.byte1; case 0x80000c6:
else if(address == 0x80000c4) return rtcClockData.byte1;
{ break;
return rtcClockData.byte0; case 0x80000c4:
} return rtcClockData.byte0;
break;
} }
}
//return READ16LE((&rom[address & 0x1FFFFFE])); //return READ16LE((&rom[address & 0x1FFFFFE]));
return VMRead16( address & 0x1FFFFFE ); return VMRead16( address & 0x1FFFFFE );
} }
@ -90,134 +89,117 @@ bool rtcWrite(u32 address, u16 value)
if(!rtcEnabled) if(!rtcEnabled)
return false; return false;
if(address == 0x80000c8) if(address == 0x80000c8) {
{ rtcClockData.byte2 = (u8)value; // enable ?
rtcClockData.byte2 = (u8)value; // enable ? } else if(address == 0x80000c6) {
} rtcClockData.byte1 = (u8)value; // read/write
else if(address == 0x80000c6) } else if(address == 0x80000c4) {
{ if(rtcClockData.byte2 & 1) {
rtcClockData.byte1 = (u8)value; // read/write if(rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5) {
} rtcClockData.state = COMMAND;
else if(address == 0x80000c4) rtcClockData.bits = 0;
{ rtcClockData.command = 0;
if(rtcClockData.byte2 & 1) } else if(!(rtcClockData.byte0 & 1) && (value & 1)) { // bit transfer
{ rtcClockData.byte0 = (u8)value;
if(rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5) switch(rtcClockData.state) {
{ case COMMAND:
rtcClockData.state = COMMAND; rtcClockData.command |= ((value & 2) >> 1) << (7-rtcClockData.bits);
rtcClockData.bits++;
if(rtcClockData.bits == 8) {
rtcClockData.bits = 0;
switch(rtcClockData.command) {
case 0x60:
// not sure what this command does but it doesn't take parameters
// maybe it is a reset or stop
rtcClockData.state = IDLE;
rtcClockData.bits = 0; rtcClockData.bits = 0;
rtcClockData.command = 0; break;
case 0x62:
// this sets the control state but not sure what those values are
rtcClockData.state = READDATA;
rtcClockData.dataLen = 1;
break;
case 0x63:
rtcClockData.dataLen = 1;
rtcClockData.data[0] = 0x40;
rtcClockData.state = DATA;
break;
case 0x64:
break;
case 0x65:
{
struct tm *newtime;
time_t long_time;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_time ); /* Convert to local time. */
rtcClockData.dataLen = 7;
rtcClockData.data[0] = toBCD(newtime->tm_year);
rtcClockData.data[1] = toBCD(newtime->tm_mon+1);
rtcClockData.data[2] = toBCD(newtime->tm_mday);
rtcClockData.data[3] = toBCD(newtime->tm_wday);
rtcClockData.data[4] = toBCD(newtime->tm_hour);
rtcClockData.data[5] = toBCD(newtime->tm_min);
rtcClockData.data[6] = toBCD(newtime->tm_sec);
rtcClockData.state = DATA;
}
break;
case 0x67:
{
struct tm *newtime;
time_t long_time;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_time ); /* Convert to local time. */
rtcClockData.dataLen = 3;
rtcClockData.data[0] = toBCD(newtime->tm_hour);
rtcClockData.data[1] = toBCD(newtime->tm_min);
rtcClockData.data[2] = toBCD(newtime->tm_sec);
rtcClockData.state = DATA;
}
break;
default:
systemMessage(0, N_("Unknown RTC command %02x"), rtcClockData.command);
rtcClockData.state = IDLE;
break;
} }
else if(!(rtcClockData.byte0 & 1) && (value & 1)) }
{ // bit transfer break;
rtcClockData.byte0 = (u8)value; case DATA:
switch(rtcClockData.state) if(rtcClockData.byte1 & 2) {
{ } else {
case COMMAND: rtcClockData.byte0 = (rtcClockData.byte0 & ~2) |
rtcClockData.command |= ((value & 2) >> 1) << (7-rtcClockData.bits); ((rtcClockData.data[rtcClockData.bits >> 3] >>
rtcClockData.bits++; (rtcClockData.bits & 7)) & 1)*2;
if(rtcClockData.bits == 8) rtcClockData.bits++;
{ if(rtcClockData.bits == 8*rtcClockData.dataLen) {
rtcClockData.bits = 0; rtcClockData.bits = 0;
switch(rtcClockData.command) rtcClockData.state = IDLE;
{
case 0x60:
// not sure what this command does but it doesn't take parameters
// maybe it is a reset or stop
rtcClockData.state = IDLE;
rtcClockData.bits = 0;
break;
case 0x62:
// this sets the control state but not sure what those values are
rtcClockData.state = READDATA;
rtcClockData.dataLen = 1;
break;
case 0x63:
rtcClockData.dataLen = 1;
rtcClockData.data[0] = 0x40;
rtcClockData.state = DATA;
break;
case 0x65:
{
struct tm *newtime;
time_t long_time;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_time ); /* Convert to local time. */
rtcClockData.dataLen = 7;
rtcClockData.data[0] = toBCD(newtime->tm_year);
rtcClockData.data[1] = toBCD(newtime->tm_mon+1);
rtcClockData.data[2] = toBCD(newtime->tm_mday);
rtcClockData.data[3] = 0;
rtcClockData.data[4] = toBCD(newtime->tm_hour);
rtcClockData.data[5] = toBCD(newtime->tm_min);
rtcClockData.data[6] = toBCD(newtime->tm_sec);
rtcClockData.state = DATA;
}
break;
case 0x67:
{
struct tm *newtime;
time_t long_time;
time( &long_time ); /* Get time as long integer. */
newtime = localtime( &long_time ); /* Convert to local time. */
rtcClockData.dataLen = 3;
rtcClockData.data[0] = toBCD(newtime->tm_hour);
rtcClockData.data[1] = toBCD(newtime->tm_min);
rtcClockData.data[2] = toBCD(newtime->tm_sec);
rtcClockData.state = DATA;
}
break;
default:
systemMessage(0, N_("Unknown RTC command %02x"), rtcClockData.command);
rtcClockData.state = IDLE;
break;
}
}
break;
case DATA:
if(rtcClockData.byte1 & 2)
{}
else
{
rtcClockData.byte0 = (rtcClockData.byte0 & ~2) |
((rtcClockData.data[rtcClockData.bits >> 3] >>
(rtcClockData.bits & 7)) & 1)*2;
rtcClockData.bits++;
if(rtcClockData.bits == 8*rtcClockData.dataLen)
{
rtcClockData.bits = 0;
rtcClockData.state = IDLE;
}
}
break;
case READDATA:
if(!(rtcClockData.byte1 & 2))
{}
else
{
rtcClockData.data[rtcClockData.bits >> 3] =
(rtcClockData.data[rtcClockData.bits >> 3] >> 1) |
((value << 6) & 128);
rtcClockData.bits++;
if(rtcClockData.bits == 8*rtcClockData.dataLen)
{
rtcClockData.bits = 0;
rtcClockData.state = IDLE;
}
}
break;
default:
break;
}
} }
else }
rtcClockData.byte0 = (u8)value; break;
case READDATA:
if(!(rtcClockData.byte1 & 2)) {
} else {
rtcClockData.data[rtcClockData.bits >> 3] =
(rtcClockData.data[rtcClockData.bits >> 3] >> 1) |
((value << 6) & 128);
rtcClockData.bits++;
if(rtcClockData.bits == 8*rtcClockData.dataLen) {
rtcClockData.bits = 0;
rtcClockData.state = IDLE;
}
}
break;
default:
break;
} }
} else
rtcClockData.byte0 = (u8)value;
} }
}
return true; return true;
} }

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2004 Forgotten and the VBA development team
// Copyright (C) 2004-2006 VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -20,6 +21,8 @@
#ifndef VBA_SOUND_H #ifndef VBA_SOUND_H
#define VBA_SOUND_H #define VBA_SOUND_H
#include "System.h"
#define NR10 0x60 #define NR10 0x60
#define NR11 0x62 #define NR11 0x62
#define NR12 0x63 #define NR12 0x63
@ -47,23 +50,22 @@
#define FIFOB_L 0xa4 #define FIFOB_L 0xa4
#define FIFOB_H 0xa6 #define FIFOB_H 0xa6
extern void soundTick(); void soundTick();
extern void soundShutdown(); void soundShutdown();
extern bool soundInit(); bool soundInit();
extern void soundPause(); void soundPause();
extern void soundResume(); void soundResume();
extern void soundEnable(int); void soundEnable(int);
extern void soundDisable(int); void soundDisable(int);
extern int soundGetEnable(); int soundGetEnable();
extern void soundReset(); void soundReset();
extern void soundSaveGame(gzFile); void soundSaveGame(gzFile);
extern void soundReadGame(gzFile, int); void soundReadGame(gzFile, int);
extern void soundEvent(u32, u8); void soundEvent(u32, u8);
extern void soundEvent(u32, u16); void soundEvent(u32, u16);
extern void soundTimerOverflow(int); void soundTimerOverflow(int);
extern void soundSetQuality(int); void soundSetQuality(int);
//extern int SOUND_TICKS;
extern int SOUND_CLOCK_TICKS; extern int SOUND_CLOCK_TICKS;
extern int soundTicks; extern int soundTicks;
extern int soundPaused; extern int soundPaused;

View File

@ -16,7 +16,8 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h"
#include "Flash.h" #include "Flash.h"
#include "Sram.h" #include "Sram.h"
@ -24,6 +25,12 @@ u8 sramRead(u32 address)
{ {
return flashSaveMemory[address & 0xFFFF]; return flashSaveMemory[address & 0xFFFF];
} }
void sramDelayedWrite(u32 address, u8 byte)
{
saveType = 1;
cpuSaveGameFunc = sramWrite;
sramWrite(address, byte);
}
void sramWrite(u32 address, u8 byte) void sramWrite(u32 address, u8 byte)
{ {

View File

@ -22,5 +22,6 @@
extern u8 sramRead(u32 address); extern u8 sramRead(u32 address);
extern void sramWrite(u32 address, u8 byte); extern void sramWrite(u32 address, u8 byte);
extern void sramDelayedWrite(u32 address, u8 byte);
#endif // VBA_SRAM_H #endif // VBA_SRAM_H

View File

@ -20,63 +20,60 @@
#ifndef VBA_SYSTEM_H #ifndef VBA_SYSTEM_H
#define VBA_SYSTEM_H #define VBA_SYSTEM_H
#include <stdint.h>
#include "unzip.h" #include "unzip.h"
#ifndef NULL #ifndef NULL
#define NULL 0 #define NULL 0
#endif #endif
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef unsigned char u8; typedef unsigned char u8;
typedef unsigned short u16; typedef unsigned short u16;
typedef unsigned int u32; typedef unsigned int u32;
#ifdef _MSC_VER struct EmulatedSystem {
typedef unsigned __int64 u64; // main emulation function
#else void (*emuMain)(int);
typedef unsigned long long u64; // reset emulator
#endif void (*emuReset)();
// clean up memory
typedef signed char s8; void (*emuCleanUp)();
typedef signed short s16; // load battery file
typedef signed int s32; bool (*emuReadBattery)(const char *);
// write battery file
#ifdef _MSC_VER bool (*emuWriteBattery)(const char *);
typedef signed __int64 s64; // load state
#else bool (*emuReadState)(const char *);
typedef signed long long s64; // save state
#endif bool (*emuWriteState)(const char *);
// load memory state (rewind)
struct EmulatedSystem bool (*emuReadMemState)(char *, int);
{ // write memory state (rewind)
// main emulation function bool (*emuWriteMemState)(char *, int);
void (*emuMain)(int); // write PNG file
// reset emulator bool (*emuWritePNG)(const char *);
void (*emuReset)(); // write BMP file
// clean up memory bool (*emuWriteBMP)(const char *);
void (*emuCleanUp)(); // emulator update CPSR (ARM only)
// load battery file void (*emuUpdateCPSR)();
bool (*emuReadBattery)(const char *); // emulator has debugger
// write battery file bool emuHasDebugger;
bool (*emuWriteBattery)(const char *); // clock ticks to emulate
// load state int emuCount;
bool (*emuReadState)(const char *); };
// save state
bool (*emuWriteState)(const char *);
// load memory state (rewind)
bool (*emuReadMemState)(char *, int);
// write memory state (rewind)
bool (*emuWriteMemState)(char *, int);
// write PNG file
bool (*emuWritePNG)(const char *);
// write BMP file
bool (*emuWriteBMP)(const char *);
// emulator update CPSR (ARM only)
void (*emuUpdateCPSR)();
// emulator has debugger
bool emuHasDebugger;
// clock ticks to emulate
int emuCount;
};
extern void log(const char *,...); extern void log(const char *,...);
@ -107,7 +104,16 @@ extern void system10Frames(int);
extern void systemFrame(); extern void systemFrame();
extern void systemGbBorderOn(); extern void systemGbBorderOn();
extern bool systemSoundOn; extern void Sm60FPS_Init();
extern bool Sm60FPS_CanSkipFrame();
extern void Sm60FPS_Sleep();
extern void DbgMsg(const char *msg, ...);
extern void winlog(const char *,...);
extern void (*dbgOutput)(const char *s, u32 addr);
extern void (*dbgSignal)(int sig,int number);
extern bool systemSoundOn; // old sound system
extern u16 systemColorMap16[0x10000]; extern u16 systemColorMap16[0x10000];
//extern u32 systemColorMap32[0x10000]; //extern u32 systemColorMap32[0x10000];
extern u32 *systemColorMap32; extern u32 *systemColorMap32;
@ -120,6 +126,8 @@ extern int systemDebug;
extern int systemVerbose; extern int systemVerbose;
extern int systemFrameSkip; extern int systemFrameSkip;
extern int systemSaveUpdateCounter; extern int systemSaveUpdateCounter;
extern int systemSpeed;
extern int systemThrottle;
#define SYSTEM_SAVE_UPDATED 30 #define SYSTEM_SAVE_UPDATED 30
#define SYSTEM_SAVE_NOT_UPDATED 0 #define SYSTEM_SAVE_NOT_UPDATED 0

View File

@ -1,180 +0,0 @@
/* FCE Ultra - NES/Famicom Emulator
*
* Copyright notice for this file:
* Copyright (C) 2002 Ben Parnell
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Code originally from fceu/drawing.h file, adapted by Forgotten
*/
#include "System.h"
extern int RGB_LOW_BITS_MASK;
static const u8 fontdata2[2048] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7e,0x81,0xa5,0x81,0xbd,0x99,0x81,0x7e,0x7e,0xff,0xdb,0xff,0xc3,0xe7,0xff,0x7e,0x36,0x7f,0x7f,0x7f,0x3e,0x1c,0x08,0x00,0x08,0x1c,0x3e,0x7f,0x3e,0x1c,0x08,0x00,0x1c,0x3e,0x1c,0x7f,0x7f,0x3e,0x1c,0x3e,0x08,0x08,0x1c,0x3e,0x7f,0x3e,0x1c,0x3e,0x00,0x00,0x18,0x3c,0x3c,0x18,0x00,0x00,0xff,0xff,0xe7,0xc3,0xc3,0xe7,0xff,0xff,0x00,0x3c,0x66,0x42,0x42,0x66,0x3c,0x00,0xff,0xc3,0x99,0xbd,0xbd,0x99,0xc3,0xff,0xf0,0xe0,0xf0,0xbe,0x33,0x33,0x33,0x1e,0x3c,0x66,0x66,0x66,0x3c,0x18,0x7e,0x18,0xfc,0xcc,0xfc,0x0c,0x0c,0x0e,0x0f,0x07,0xfe,0xc6,0xfe,0xc6,0xc6,0xe6,0x67,0x03,0x99,0x5a,0x3c,0xe7,0xe7,0x3c,0x5a,0x99,0x01,0x07,0x1f,0x7f,0x1f,0x07,0x01,0x00,0x40,0x70,0x7c,0x7f,0x7c,0x70,0x40,0x00,0x18,0x3c,0x7e,0x18,0x18,0x7e,0x3c,0x18,0x66,0x66,0x66,0x66,0x66,0x00,0x66,0x00,0xfe,0xdb,0xdb,0xde,0xd8,0xd8,0xd8,0x00,0x7c,0xc6,0x1c,0x36,0x36,0x1c,0x33,0x1e,0x00,0x00,0x00,0x00,0x7e,0x7e,0x7e,0x00,0x18,0x3c,0x7e,0x18,0x7e,0x3c,0x18,0xff,0x18,0x3c,0x7e,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x7e,0x3c,0x18,0x00,0x00,0x18,0x30,0x7f,0x30,0x18,0x00,0x00,0x00,0x0c,0x06,0x7f,0x06,0x0c,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x7f,0x00,0x00,0x00,0x24,0x66,0xff,0x66,0x24,0x00,0x00,0x00,0x18,0x3c,0x7e,0xff,0xff,0x00,0x00,0x00,0xff,0xff,0x7e,0x3c,0x18,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x1e,0x1e,0x0c,0x0c,0x00,0x0c,0x00,0x36,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x36,0x36,0x7f,0x36,0x7f,0x36,0x36,0x00,0x0c,0x3e,0x03,0x1e,0x30,0x1f,0x0c,0x00,0x00,0x63,0x33,0x18,0x0c,0x66,0x63,0x00,0x1c,0x36,0x1c,0x6e,0x3b,0x33,0x6e,0x00,0x06,0x06,0x03,0x00,0x00,0x00,0x00,0x00,0x18,0x0c,0x06,0x06,0x06,0x0c,0x18,0x00,0x06,0x0c,0x18,0x18,0x18,0x0c,0x06,0x00,0x00,0x66,0x3c,0xff,0x3c,0x66,0x00,0x00,0x00,0x0c,0x0c,0x3f,0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x0c,0x06,0x00,0x00,0x00,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x0c,0x00,0x60,0x30,0x18,0x0c,0x06,0x03,0x01,0x00,0x3e,0x63,0x73,0x7b,0x6f,0x67,0x3e,0x00,0x0c,0x0e,0x0c,0x0c,0x0c,0x0c,0x3f,0x00,0x1e,0x33,0x30,0x1c,0x06,0x33,0x3f,0x00,0x1e,0x33,0x30,0x1c,0x30,0x33,0x1e,0x00,0x38,0x3c,0x36,0x33,0x7f,0x30,0x78,0x00,0x3f,0x03,0x1f,0x30,0x30,0x33,0x1e,0x00,0x1c,0x06,0x03,0x1f,0x33,0x33,0x1e,0x00,0x3f,0x33,0x30,0x18,0x0c,0x0c,0x0c,0x00,0x1e,0x33,0x33,0x1e,0x33,0x33,0x1e,0x00,0x1e,0x33,0x33,0x3e,0x30,0x18,0x0e,0x00,0x00,0x0c,0x0c,0x00,0x00,0x0c,0x0c,0x00,0x00,0x0c,0x0c,0x00,0x00,0x0c,0x0c,0x06,0x18,0x0c,0x06,0x03,0x06,0x0c,0x18,0x00,0x00,0x00,0x3f,0x00,0x00,0x3f,0x00,0x00,0x06,0x0c,0x18,0x30,0x18,0x0c,0x06,0x00,0x1e,0x33,0x30,0x18,0x0c,0x00,0x0c,0x00,
0x3e,0x63,0x7b,0x7b,0x7b,0x03,0x1e,0x00,0x0c,0x1e,0x33,0x33,0x3f,0x33,0x33,0x00,0x3f,0x66,0x66,0x3e,0x66,0x66,0x3f,0x00,0x3c,0x66,0x03,0x03,0x03,0x66,0x3c,0x00,0x1f,0x36,0x66,0x66,0x66,0x36,0x1f,0x00,0x7f,0x46,0x16,0x1e,0x16,0x46,0x7f,0x00,0x7f,0x46,0x16,0x1e,0x16,0x06,0x0f,0x00,0x3c,0x66,0x03,0x03,0x73,0x66,0x7c,0x00,0x33,0x33,0x33,0x3f,0x33,0x33,0x33,0x00,0x1e,0x0c,0x0c,0x0c,0x0c,0x0c,0x1e,0x00,0x78,0x30,0x30,0x30,0x33,0x33,0x1e,0x00,0x67,0x66,0x36,0x1e,0x36,0x66,0x67,0x00,0x0f,0x06,0x06,0x06,0x46,0x66,0x7f,0x00,0x63,0x77,0x7f,0x7f,0x6b,0x63,0x63,0x00,0x63,0x67,0x6f,0x7b,0x73,0x63,0x63,0x00,0x1c,0x36,0x63,0x63,0x63,0x36,0x1c,0x00,0x3f,0x66,0x66,0x3e,0x06,0x06,0x0f,0x00,0x1e,0x33,0x33,0x33,0x3b,0x1e,0x38,0x00,0x3f,0x66,0x66,0x3e,0x36,0x66,0x67,0x00,0x1e,0x33,0x07,0x0e,0x38,0x33,0x1e,0x00,0x3f,0x2d,0x0c,0x0c,0x0c,0x0c,0x1e,0x00,0x33,0x33,0x33,0x33,0x33,0x33,0x3f,0x00,0x33,0x33,0x33,0x33,0x33,0x1e,0x0c,0x00,0x63,0x63,0x63,0x6b,0x7f,0x77,0x63,0x00,0x63,0x63,0x36,0x1c,0x1c,0x36,0x63,0x00,0x33,0x33,0x33,0x1e,0x0c,0x0c,0x1e,0x00,0x7f,0x63,0x31,0x18,0x4c,0x66,0x7f,0x00,0x1e,0x06,0x06,0x06,0x06,0x06,0x1e,0x00,0x03,0x06,0x0c,0x18,0x30,0x60,0x40,0x00,0x1e,0x18,0x18,0x18,0x18,0x18,0x1e,0x00,0x08,0x1c,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,
0x0c,0x0c,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1e,0x30,0x3e,0x33,0x6e,0x00,0x07,0x06,0x06,0x3e,0x66,0x66,0x3b,0x00,0x00,0x00,0x1e,0x33,0x03,0x33,0x1e,0x00,0x38,0x30,0x30,0x3e,0x33,0x33,0x6e,0x00,0x00,0x00,0x1e,0x33,0x3f,0x03,0x1e,0x00,0x1c,0x36,0x06,0x0f,0x06,0x06,0x0f,0x00,0x00,0x00,0x6e,0x33,0x33,0x3e,0x30,0x1f,0x07,0x06,0x36,0x6e,0x66,0x66,0x67,0x00,0x0c,0x00,0x0e,0x0c,0x0c,0x0c,0x1e,0x00,0x30,0x00,0x30,0x30,0x30,0x33,0x33,0x1e,0x07,0x06,0x66,0x36,0x1e,0x36,0x67,0x00,0x0e,0x0c,0x0c,0x0c,0x0c,0x0c,0x1e,0x00,0x00,0x00,0x33,0x7f,0x7f,0x6b,0x63,0x00,0x00,0x00,0x1f,0x33,0x33,0x33,0x33,0x00,0x00,0x00,0x1e,0x33,0x33,0x33,0x1e,0x00,0x00,0x00,0x3b,0x66,0x66,0x3e,0x06,0x0f,0x00,0x00,0x6e,0x33,0x33,0x3e,0x30,0x78,0x00,0x00,0x3b,0x6e,0x66,0x06,0x0f,0x00,0x00,0x00,0x3e,0x03,0x1e,0x30,0x1f,0x00,0x08,0x0c,0x3e,0x0c,0x0c,0x2c,0x18,0x00,0x00,0x00,0x33,0x33,0x33,0x33,0x6e,0x00,0x00,0x00,0x33,0x33,0x33,0x1e,0x0c,0x00,0x00,0x00,0x63,0x6b,0x7f,0x7f,0x36,0x00,0x00,0x00,0x63,0x36,0x1c,0x36,0x63,0x00,0x00,0x00,0x33,0x33,0x33,0x3e,0x30,0x1f,0x00,0x00,0x3f,0x19,0x0c,0x26,0x3f,0x00,0x38,0x0c,0x0c,0x07,0x0c,0x0c,0x38,0x00,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x00,0x07,0x0c,0x0c,0x38,0x0c,0x0c,0x07,0x00,0x6e,0x3b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x1c,0x36,0x63,0x63,0x7f,0x00,
0x1e,0x33,0x03,0x33,0x1e,0x18,0x30,0x1e,0x00,0x33,0x00,0x33,0x33,0x33,0x7e,0x00,0x38,0x00,0x1e,0x33,0x3f,0x03,0x1e,0x00,0x7e,0xc3,0x3c,0x60,0x7c,0x66,0xfc,0x00,0x33,0x00,0x1e,0x30,0x3e,0x33,0x7e,0x00,0x07,0x00,0x1e,0x30,0x3e,0x33,0x7e,0x00,0x0c,0x0c,0x1e,0x30,0x3e,0x33,0x7e,0x00,0x00,0x00,0x1e,0x03,0x03,0x1e,0x30,0x1c,0x7e,0xc3,0x3c,0x66,0x7e,0x06,0x3c,0x00,0x33,0x00,0x1e,0x33,0x3f,0x03,0x1e,0x00,0x07,0x00,0x1e,0x33,0x3f,0x03,0x1e,0x00,0x33,0x00,0x0e,0x0c,0x0c,0x0c,0x1e,0x00,0x3e,0x63,0x1c,0x18,0x18,0x18,0x3c,0x00,0x07,0x00,0x0e,0x0c,0x0c,0x0c,0x1e,0x00,0x63,0x1c,0x36,0x63,0x7f,0x63,0x63,0x00,0x0c,0x0c,0x00,0x1e,0x33,0x3f,0x33,0x00,0x38,0x00,0x3f,0x06,0x1e,0x06,0x3f,0x00,0x00,0x00,0xfe,0x30,0xfe,0x33,0xfe,0x00,0x7c,0x36,0x33,0x7f,0x33,0x33,0x73,0x00,0x1e,0x33,0x00,0x1e,0x33,0x33,0x1e,0x00,0x00,0x33,0x00,0x1e,0x33,0x33,0x1e,0x00,0x00,0x07,0x00,0x1e,0x33,0x33,0x1e,0x00,0x1e,0x33,0x00,0x33,0x33,0x33,0x7e,0x00,0x00,0x07,0x00,0x33,0x33,0x33,0x7e,0x00,0x00,0x33,0x00,0x33,0x33,0x3e,0x30,0x1f,0xc3,0x18,0x3c,0x66,0x66,0x3c,0x18,0x00,0x33,0x00,0x33,0x33,0x33,0x33,0x1e,0x00,0x18,0x18,0x7e,0x03,0x03,0x7e,0x18,0x18,0x1c,0x36,0x26,0x0f,0x06,0x67,0x3f,0x00,0x33,0x33,0x1e,0x3f,0x0c,0x3f,0x0c,0x0c,0x1f,0x33,0x33,0x5f,0x63,0xf3,0x63,0xe3,0x70,0xd8,0x18,0x3c,0x18,0x18,0x1b,0x0e,
0x38,0x00,0x1e,0x30,0x3e,0x33,0x7e,0x00,0x1c,0x00,0x0e,0x0c,0x0c,0x0c,0x1e,0x00,0x00,0x38,0x00,0x1e,0x33,0x33,0x1e,0x00,0x00,0x38,0x00,0x33,0x33,0x33,0x7e,0x00,0x00,0x1f,0x00,0x1f,0x33,0x33,0x33,0x00,0x3f,0x00,0x33,0x37,0x3f,0x3b,0x33,0x00,0x3c,0x36,0x36,0x7c,0x00,0x7e,0x00,0x00,0x1c,0x36,0x36,0x1c,0x00,0x3e,0x00,0x00,0x0c,0x00,0x0c,0x06,0x03,0x33,0x1e,0x00,0x00,0x00,0x00,0x3f,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x3f,0x30,0x30,0x00,0x00,0xc3,0x63,0x33,0x7b,0xcc,0x66,0x33,0xf0,0xc3,0x63,0x33,0xdb,0xec,0xf6,0xf3,0xc0,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00,0xcc,0x66,0x33,0x66,0xcc,0x00,0x00,0x00,0x33,0x66,0xcc,0x66,0x33,0x00,0x00,0x44,0x11,0x44,0x11,0x44,0x11,0x44,0x11,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xaa,0x55,0xdb,0xee,0xdb,0x77,0xdb,0xee,0xdb,0x77,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1f,0x18,0x18,0x18,0x18,0x18,0x1f,0x18,0x1f,0x18,0x18,0x18,0x6c,0x6c,0x6c,0x6c,0x6f,0x6c,0x6c,0x6c,0x00,0x00,0x00,0x00,0x7f,0x6c,0x6c,0x6c,0x00,0x00,0x1f,0x18,0x1f,0x18,0x18,0x18,0x6c,0x6c,0x6f,0x60,0x6f,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x00,0x00,0x7f,0x60,0x6f,0x6c,0x6c,0x6c,0x6c,0x6c,0x6f,0x60,0x7f,0x00,0x00,0x00,0x6c,0x6c,0x6c,0x6c,0x7f,0x00,0x00,0x00,0x18,0x18,0x1f,0x18,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x18,0x18,0x18,
0x18,0x18,0x18,0x18,0xf8,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0xf8,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x18,0x18,0x18,0x18,0xff,0x18,0x18,0x18,0x18,0x18,0xf8,0x18,0xf8,0x18,0x18,0x18,0x6c,0x6c,0x6c,0x6c,0xec,0x6c,0x6c,0x6c,0x6c,0x6c,0xec,0x0c,0xfc,0x00,0x00,0x00,0x00,0x00,0xfc,0x0c,0xec,0x6c,0x6c,0x6c,0x6c,0x6c,0xef,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0xff,0x00,0xef,0x6c,0x6c,0x6c,0x6c,0x6c,0xec,0x0c,0xec,0x6c,0x6c,0x6c,0x00,0x00,0xff,0x00,0xff,0x00,0x00,0x00,0x6c,0x6c,0xef,0x00,0xef,0x6c,0x6c,0x6c,0x18,0x18,0xff,0x00,0xff,0x00,0x00,0x00,0x6c,0x6c,0x6c,0x6c,0xff,0x00,0x00,0x00,0x00,0x00,0xff,0x00,0xff,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0xff,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0xfc,0x00,0x00,0x00,0x18,0x18,0xf8,0x18,0xf8,0x00,0x00,0x00,0x00,0x00,0xf8,0x18,0xf8,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0xfc,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0x6c,0xff,0x6c,0x6c,0x6c,0x18,0x18,0xff,0x18,0xff,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x18,0x18,0x18,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
0x00,0x00,0x6e,0x3b,0x13,0x3b,0x6e,0x00,0x00,0x1e,0x33,0x1f,0x33,0x1f,0x03,0x03,0x00,0x3f,0x33,0x03,0x03,0x03,0x03,0x00,0x00,0x7f,0x36,0x36,0x36,0x36,0x36,0x00,0x3f,0x33,0x06,0x0c,0x06,0x33,0x3f,0x00,0x00,0x00,0x7e,0x1b,0x1b,0x1b,0x0e,0x00,0x00,0x66,0x66,0x66,0x66,0x3e,0x06,0x03,0x00,0x6e,0x3b,0x18,0x18,0x18,0x18,0x00,0x3f,0x0c,0x1e,0x33,0x33,0x1e,0x0c,0x3f,0x1c,0x36,0x63,0x7f,0x63,0x36,0x1c,0x00,0x1c,0x36,0x63,0x63,0x36,0x36,0x77,0x00,0x38,0x0c,0x18,0x3e,0x33,0x33,0x1e,0x00,0x00,0x00,0x7e,0xdb,0xdb,0x7e,0x00,0x00,0x60,0x30,0x7e,0xdb,0xdb,0x7e,0x06,0x03,0x1c,0x06,0x03,0x1f,0x03,0x06,0x1c,0x00,0x1e,0x33,0x33,0x33,0x33,0x33,0x33,0x00,0x00,0x3f,0x00,0x3f,0x00,0x3f,0x00,0x00,0x0c,0x0c,0x3f,0x0c,0x0c,0x00,0x3f,0x00,0x06,0x0c,0x18,0x0c,0x06,0x00,0x3f,0x00,0x18,0x0c,0x06,0x0c,0x18,0x00,0x3f,0x00,0x70,0xd8,0xd8,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x1b,0x1b,0x0e,0x0c,0x0c,0x00,0x3f,0x00,0x0c,0x0c,0x00,0x00,0x6e,0x3b,0x00,0x6e,0x3b,0x00,0x00,0x1c,0x36,0x36,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0xf0,0x30,0x30,0x30,0x37,0x36,0x3c,0x38,0x1e,0x36,0x36,0x36,0x36,0x00,0x00,0x00,0x0e,0x18,0x0c,0x06,0x1e,0x00,0x00,0x00,0x00,0x00,0x3c,0x3c,0x3c,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
static void drawTextInternal(u8 *screen, int pitch, int x, int y,
const char *string, bool trans)
{
screen += y*pitch;
int inc = 2;
switch(systemColorDepth)
{
case 24:
inc = 3;
break;
case 32:
inc = 4;
break;
}
screen += x*inc;
switch(systemColorDepth)
{
case 16:
{
while(*string)
{
char c = *string++;
u8 *scr = screen;
u16 mask = ~RGB_LOW_BITS_MASK;
int h, w;
u16 *s = (u16 *)scr;
for (h = 0; h < 8; h++)
{
for (w = 0; w < 8; w++, s++)
{
int on = (fontdata2[(c<<3)+h]>>w)&1;
if(trans)
{
if(on)
*s = ((0xf) << systemRedShift) +
((*s & mask) >>1);
}
else
{
if(on)
*s = (0x1f) << systemRedShift;
}
}
scr += pitch;
s = (u16 *)scr;
}
screen += inc*8;
}
}
break;
case 24:
{
while(*string)
{
char c = *string++;
u8 *scr = screen;
int h, w;
u8 *s = (u8 *)scr;
for (h = 0; h < 8; h++)
{
for (w = 0; w < 8; w++, s+=3)
{
int on = (fontdata2[(c<<3)+h]>>w)&1;
if(trans)
{
if(on)
{
u32 color = (0x1f) << systemRedShift;
*s = ((color & 255)>>1)+(*s>>1);
*(s+1) = (((color >> 8) & 255)>>1)+(*(s+1)>>1);
*(s+2) = (((color >> 16) & 255)>>1)+(*(s+2)>>1);
}
}
else
{
if(on)
{
u32 color = (0x1f) << systemRedShift;
*s = (color & 255);
*(s+1) = (color >> 8) & 255;
*(s+2) = (color >> 16) & 255;
}
}
}
scr += pitch;
s = (u8 *)scr;
}
screen += inc*8;
}
}
break;
case 32:
{
while(*string)
{
char c = *string++;
u8 *scr = screen;
int h, w;
u32 mask = 0xfefefe;
u32 *s = (u32 *)scr;
for (h = 0; h < 8; h++)
{
for (w = 0; w < 8; w++, s++)
{
int on = (fontdata2[(c<<3)+h]>>w)&1;
if(trans)
{
if(on)
*s = ((0xf) << systemRedShift) + ((*s & mask)>>1);
}
else
{
if(on)
*s = (0x1f) << systemRedShift;
}
}
scr += pitch;
s = (u32 *)scr;
}
screen += inc*8;
}
}
break;
}
}
void drawText(u8 *screen, int pitch, int x, int y, const char *string)
{
drawTextInternal(screen, pitch, x, y, string, false);
}
void drawTextTransp(u8 *screen, int pitch, int x, int y, const char *string)
{
drawTextInternal(screen, pitch, x, y, string, true);
}

View File

@ -1,21 +0,0 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
extern void drawText(u8 *, int, int, int, const char *);
extern void drawTextTransp(u8 *, int, int, int, const char *);

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,9 @@
#ifndef VBA_UTIL_H #ifndef VBA_UTIL_H
#define VBA_UTIL_H #define VBA_UTIL_H
#include "System.h"
enum IMAGE_TYPE { enum IMAGE_TYPE {
IMAGE_UNKNOWN = -1, IMAGE_UNKNOWN = -1,
IMAGE_GBA = 0, IMAGE_GBA = 0,
@ -27,40 +30,38 @@ enum IMAGE_TYPE {
// save game // save game
typedef struct typedef struct {
{ void *address;
void *address; int size;
int size; } variable_desc;
}
variable_desc;
extern bool utilWritePNGFile(const char *, int, int, u8 *); extern bool utilWritePNGFile(const char *, int, int, u8 *);
extern bool utilWriteBMPFile(const char *, int, int, u8 *); extern bool utilWriteBMPFile(const char *, int, int, u8 *);
extern void utilApplyIPS(const char *ips, u8 **rom, int *size); extern void utilApplyIPS(const char *ips, u8 **rom, int *size);
extern void utilWriteBMP(char *, int, int, u8 *);
extern bool utilIsGBAImage(const char *); extern bool utilIsGBAImage(const char *);
extern bool utilIsGBImage(const char *); extern bool utilIsGBImage(const char *);
extern bool utilIsZipFile(const char *);
extern bool utilIsGzipFile(const char *); extern bool utilIsGzipFile(const char *);
extern bool utilIsRarFile(const char *); extern void utilStripDoubleExtension(const char *, char *);
extern void utilGetBaseName(const char *, char *);
extern IMAGE_TYPE utilFindType(const char *); extern IMAGE_TYPE utilFindType(const char *);
extern u8 *utilLoad(const char *, extern u8 *utilLoad(const char *,
bool (*)(const char*), bool (*)(const char*),
u8 *, u8 *,
int &); int &);
extern void utilPutDword(u8 *, u32); extern void utilPutDword(u8 *, u32);
extern void utilPutWord(u8 *, u16); extern void utilPutWord(u8 *, u16);
extern void utilWriteData(gzFile, variable_desc *); extern void utilWriteData(gzFile, variable_desc *);
extern void utilReadData(gzFile, variable_desc *); extern void utilReadData(gzFile, variable_desc *);
extern void utilReadDataSkip(gzFile, variable_desc *);
extern int utilReadInt(gzFile); extern int utilReadInt(gzFile);
extern void utilWriteInt(gzFile, int); extern void utilWriteInt(gzFile, int);
extern gzFile utilGzOpen(const char *file, const char *mode); extern gzFile utilGzOpen(const char *file, const char *mode);
extern gzFile utilMemGzOpen(char *memory, int available, char *mode); extern gzFile utilMemGzOpen(char *memory, int available, const char *mode);
extern int utilGzWrite(gzFile file, const voidp buffer, unsigned int len); extern int utilGzWrite(gzFile file, const voidp buffer, unsigned int len);
extern int utilGzRead(gzFile file, voidp buffer, unsigned int len); extern int utilGzRead(gzFile file, voidp buffer, unsigned int len);
extern int utilGzClose(gzFile file); extern int utilGzClose(gzFile file);
extern z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence);
extern long utilGzMemTell(gzFile file); extern long utilGzMemTell(gzFile file);
extern void utilGBAFindSave(const u8 *, const int); extern void utilGBAFindSave(const u8 *, const int);
extern void utilUpdateSystemColorMaps();
#endif #endif

File diff suppressed because it is too large Load Diff

2967
source/vba/agb/GBA-arm.cpp Normal file

File diff suppressed because it is too large Load Diff

2343
source/vba/agb/GBA-thumb.cpp Normal file

File diff suppressed because it is too large Load Diff

3994
source/vba/agb/GBA.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
// -*- C++ -*- // -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@
#ifndef VBA_GBA_H #ifndef VBA_GBA_H
#define VBA_GBA_H #define VBA_GBA_H
#include "System.h" #include "../System.h"
#define SAVE_GAME_VERSION_1 1 #define SAVE_GAME_VERSION_1 1
#define SAVE_GAME_VERSION_2 2 #define SAVE_GAME_VERSION_2 2
@ -30,48 +30,44 @@
#define SAVE_GAME_VERSION_6 6 #define SAVE_GAME_VERSION_6 6
#define SAVE_GAME_VERSION_7 7 #define SAVE_GAME_VERSION_7 7
#define SAVE_GAME_VERSION_8 8 #define SAVE_GAME_VERSION_8 8
#define SAVE_GAME_VERSION SAVE_GAME_VERSION_8 #define SAVE_GAME_VERSION_9 9
#define SAVE_GAME_VERSION_10 10
#define SAVE_GAME_VERSION SAVE_GAME_VERSION_10
typedef struct typedef struct {
{ u8 *address;
u8 *address; u32 mask;
u32 mask; } memoryMap;
}
memoryMap;
typedef union { typedef union {
struct struct {
{
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
u8 B3; u8 B3;
u8 B2; u8 B2;
u8 B1; u8 B1;
u8 B0; u8 B0;
#else #else
u8 B0; u8 B0;
u8 B1; u8 B1;
u8 B2; u8 B2;
u8 B3; u8 B3;
#endif #endif
} } B;
B; struct {
struct
{
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
u16 W1; u16 W1;
u16 W0; u16 W0;
#else #else
u16 W0; u16 W0;
u16 W1; u16 W1;
#endif #endif
} } W;
W;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
volatile u32 I; volatile u32 I;
#else #else
u32 I; u32 I;
#endif #endif
} reg_pair; } reg_pair;
#ifndef NO_GBA_MAP #ifndef NO_GBA_MAP
extern memoryMap map[256]; extern memoryMap map[256];
@ -89,8 +85,17 @@ extern bool armState;
extern int armMode; extern int armMode;
extern void (*cpuSaveGameFunc)(u32,u8); extern void (*cpuSaveGameFunc)(u32,u8);
extern bool freezeWorkRAM[0x40000]; #ifdef BKPT_SUPPORT
extern bool freezeInternalRAM[0x8000]; extern u8 freezeWorkRAM[0x40000];
extern u8 freezeInternalRAM[0x8000];
extern u8 freezeVRAM[0x18000];
extern u8 freezeOAM[0x400];
extern u8 freezePRAM[0x400];
extern bool debugger_last;
extern int oldreg[17];
extern char oldbuffer[10];
#endif
extern bool CPUReadGSASnapshot(const char *); extern bool CPUReadGSASnapshot(const char *);
extern bool CPUWriteGSASnapshot(const char *, const char *, const char *, const char *); extern bool CPUWriteGSASnapshot(const char *, const char *, const char *, const char *);
extern bool CPUWriteBatteryFile(const char *); extern bool CPUWriteBatteryFile(const char *);
@ -101,14 +106,15 @@ extern bool CPUWritePNGFile(const char *);
extern bool CPUWriteBMPFile(const char *); extern bool CPUWriteBMPFile(const char *);
extern void CPUCleanUp(); extern void CPUCleanUp();
extern void CPUUpdateRender(); extern void CPUUpdateRender();
extern void CPUUpdateRenderBuffers(bool);
extern bool CPUReadMemState(char *, int); extern bool CPUReadMemState(char *, int);
extern bool CPUReadState(const char *); extern bool CPUReadState(const char *);
extern bool CPUWriteMemState(char *, int); extern bool CPUWriteMemState(char *, int);
extern bool CPUWriteState(const char *); extern bool CPUWriteState(const char *);
extern int CPULoadRom(const char *); extern int CPULoadRom(const char *);
extern void doMirroring(bool);
extern void CPUUpdateRegister(u32, u16); extern void CPUUpdateRegister(u32, u16);
extern void CPUWriteHalfWord(u32, u16); extern void applyTimer ();
extern void CPUWriteByte(u32, u8);
extern void CPUInit(const char *,bool); extern void CPUInit(const char *,bool);
extern void CPUReset(); extern void CPUReset();
extern void CPULoop(int); extern void CPULoop(int);
@ -116,7 +122,8 @@ extern void CPUCheckDMA(int,int);
extern bool CPUIsGBAImage(const char *); extern bool CPUIsGBAImage(const char *);
extern bool CPUIsZipFile(const char *); extern bool CPUIsZipFile(const char *);
#ifdef PROFILING #ifdef PROFILING
extern void cpuProfil(char *buffer, int, u32, int); #include "prof/prof.h"
extern void cpuProfil(profile_segment *seg);
extern void cpuEnableProfiling(int hz); extern void cpuEnableProfiling(int hz);
#endif #endif
@ -145,9 +152,9 @@ extern struct EmulatedSystem GBASystem;
#define R14_FIQ 43 #define R14_FIQ 43
#define SPSR_FIQ 44 #define SPSR_FIQ 44
#include "Cheats.h" #include "../Cheats.h"
#include "Globals.h" #include "../Globals.h"
#include "EEprom.h" #include "../EEprom.h"
#include "Flash.h" #include "../Flash.h"
#endif //VBA_GBA_H #endif //VBA_GBA_H

View File

@ -16,12 +16,11 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "System.h" #include "../System.h"
int coeff[32] = { int coeff[32] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16};
u32 line0[240]; u32 line0[240];
u32 line1[240]; u32 line1[240];
@ -32,6 +31,7 @@ u32 lineOBJWin[240];
u32 lineMix[240]; u32 lineMix[240];
bool gfxInWin0[240]; bool gfxInWin0[240];
bool gfxInWin1[240]; bool gfxInWin1[240];
int lineOBJpixleft[128];
int gfxBG2Changed = 0; int gfxBG2Changed = 0;
int gfxBG3Changed = 0; int gfxBG3Changed = 0;

1601
source/vba/agb/GBAGfx.h Normal file

File diff suppressed because it is too large Load Diff

302
source/vba/agb/GBAcpu.h Normal file
View File

@ -0,0 +1,302 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef VBA_GBAcpu_H
#define VBA_GBAcpu_H
extern int armExecute();
extern int thumbExecute();
#ifdef __GNUC__
# define INSN_REGPARM __attribute__((regparm(1)))
# define LIKELY(x) __builtin_expect(!!(x),1)
# define UNLIKELY(x) __builtin_expect(!!(x),0)
#else
# define INSN_REGPARM /*nothing*/
# define LIKELY(x) (x)
# define UNLIKELY(x) (x)
#endif
#define UPDATE_REG(address, value)\
{\
WRITE16LE(((u16 *)&ioMem[address]),value);\
}\
#define ARM_PREFETCH \
{\
cpuPrefetch[0] = CPUReadMemoryQuick(armNextPC);\
cpuPrefetch[1] = CPUReadMemoryQuick(armNextPC+4);\
}
#define THUMB_PREFETCH \
{\
cpuPrefetch[0] = CPUReadHalfWordQuick(armNextPC);\
cpuPrefetch[1] = CPUReadHalfWordQuick(armNextPC+2);\
}
#define ARM_PREFETCH_NEXT \
cpuPrefetch[1] = CPUReadMemoryQuick(armNextPC+4);
#define THUMB_PREFETCH_NEXT\
cpuPrefetch[1] = CPUReadHalfWordQuick(armNextPC+2);
extern int SWITicks;
extern u32 mastercode;
extern bool busPrefetch;
extern bool busPrefetchEnable;
extern u32 busPrefetchCount;
extern int cpuNextEvent;
extern bool holdState;
extern u32 cpuPrefetch[2];
extern int cpuTotalTicks;
extern u8 memoryWait[16];
extern u8 memoryWait32[16];
extern u8 memoryWaitSeq[16];
extern u8 memoryWaitSeq32[16];
extern u8 cpuBitsSet[256];
extern u8 cpuLowestBitSet[256];
extern void CPUSwitchMode(int mode, bool saveState, bool breakLoop);
extern void CPUSwitchMode(int mode, bool saveState);
extern void CPUUpdateCPSR();
extern void CPUUpdateFlags(bool breakLoop);
extern void CPUUpdateFlags();
extern void CPUUndefinedException();
extern void CPUSoftwareInterrupt();
extern void CPUSoftwareInterrupt(int comment);
// Waitstates when accessing data
inline int dataTicksAccess16(u32 address) // DATA 8/16bits NON SEQ
{
int addr = (address>>24)&15;
int value = memoryWait[addr];
if ((addr>=0x08) || (addr < 0x02))
{
busPrefetchCount=0;
busPrefetch=false;
}
else if (busPrefetch)
{
int waitState = value;
if (!waitState)
waitState = 1;
busPrefetchCount = ((busPrefetchCount+1)<<waitState) - 1;
}
return value;
}
inline int dataTicksAccess32(u32 address) // DATA 32bits NON SEQ
{
int addr = (address>>24)&15;
int value = memoryWait32[addr];
if ((addr>=0x08) || (addr < 0x02))
{
busPrefetchCount=0;
busPrefetch=false;
}
else if (busPrefetch)
{
int waitState = value;
if (!waitState)
waitState = 1;
busPrefetchCount = ((busPrefetchCount+1)<<waitState) - 1;
}
return value;
}
inline int dataTicksAccessSeq16(u32 address)// DATA 8/16bits SEQ
{
int addr = (address>>24)&15;
int value = memoryWaitSeq[addr];
if ((addr>=0x08) || (addr < 0x02))
{
busPrefetchCount=0;
busPrefetch=false;
}
else if (busPrefetch)
{
int waitState = value;
if (!waitState)
waitState = 1;
busPrefetchCount = ((busPrefetchCount+1)<<waitState) - 1;
}
return value;
}
inline int dataTicksAccessSeq32(u32 address)// DATA 32bits SEQ
{
int addr = (address>>24)&15;
int value = memoryWaitSeq32[addr];
if ((addr>=0x08) || (addr < 0x02))
{
busPrefetchCount=0;
busPrefetch=false;
}
else if (busPrefetch)
{
int waitState = value;
if (!waitState)
waitState = 1;
busPrefetchCount = ((busPrefetchCount+1)<<waitState) - 1;
}
return value;
}
// Waitstates when executing opcode
inline int codeTicksAccess16(u32 address) // THUMB NON SEQ
{
int addr = (address>>24)&15;
if ((addr>=0x08) && (addr<=0x0D))
{
if (busPrefetchCount&0x1)
{
if (busPrefetchCount&0x2)
{
busPrefetchCount = ((busPrefetchCount&0xFF)>>2) | (busPrefetchCount&0xFFFFFF00);
return 0;
}
busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00);
return memoryWaitSeq[addr]-1;
}
else
{
busPrefetchCount=0;
return memoryWait[addr];
}
}
else
{
busPrefetchCount = 0;
return memoryWait[addr];
}
}
inline int codeTicksAccess32(u32 address) // ARM NON SEQ
{
int addr = (address>>24)&15;
if ((addr>=0x08) && (addr<=0x0D))
{
if (busPrefetchCount&0x1)
{
if (busPrefetchCount&0x2)
{
busPrefetchCount = ((busPrefetchCount&0xFF)>>2) | (busPrefetchCount&0xFFFFFF00);
return 0;
}
busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00);
return memoryWaitSeq[addr] - 1;
}
else
{
busPrefetchCount = 0;
return memoryWait32[addr];
}
}
else
{
busPrefetchCount = 0;
return memoryWait32[addr];
}
}
inline int codeTicksAccessSeq16(u32 address) // THUMB SEQ
{
int addr = (address>>24)&15;
if ((addr>=0x08) && (addr<=0x0D))
{
if (busPrefetchCount&0x1)
{
busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00);
return 0;
}
else
if (busPrefetchCount>0xFF)
{
busPrefetchCount=0;
return memoryWait[addr];
}
else
return memoryWaitSeq[addr];
}
else
{
busPrefetchCount = 0;
return memoryWaitSeq[addr];
}
}
inline int codeTicksAccessSeq32(u32 address) // ARM SEQ
{
int addr = (address>>24)&15;
if ((addr>=0x08) && (addr<=0x0D))
{
if (busPrefetchCount&0x1)
{
if (busPrefetchCount&0x2)
{
busPrefetchCount = ((busPrefetchCount&0xFF)>>2) | (busPrefetchCount&0xFFFFFF00);
return 0;
}
busPrefetchCount = ((busPrefetchCount&0xFF)>>1) | (busPrefetchCount&0xFFFFFF00);
return memoryWaitSeq[addr];
}
else
if (busPrefetchCount>0xFF)
{
busPrefetchCount=0;
return memoryWait32[addr];
}
else
return memoryWaitSeq32[addr];
}
else
{
return memoryWaitSeq32[addr];
}
}
// Emulates the Cheat System (m) code
inline void cpuMasterCodeCheck()
{
if((mastercode) && (mastercode == armNextPC))
{
u32 joy = 0;
if(systemReadJoypads())
joy = systemReadJoypad(-1);
u32 ext = (joy >> 10);
cpuTotalTicks += cheatsCheckKeys(P1^0x3FF, ext);
}
}
#endif //VBA_GBAcpu_H

738
source/vba/agb/GBAinline.h Normal file
View File

@ -0,0 +1,738 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2005 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef VBA_GBAinline_H
#define VBA_GBAinline_H
#include "../System.h"
#include "../Port.h"
#include "../RTC.h"
#include "../Sound.h"
#include "agbprint.h"
extern const u32 objTilesAddress[3];
extern bool stopState;
extern bool holdState;
extern int holdType;
extern int cpuNextEvent;
extern bool cpuSramEnabled;
extern bool cpuFlashEnabled;
extern bool cpuEEPROMEnabled;
extern bool cpuEEPROMSensorEnabled;
extern bool cpuDmaHack;
extern u32 cpuDmaLast;
extern bool timer0On;
extern int timer0Ticks;
extern int timer0ClockReload;
extern bool timer1On;
extern int timer1Ticks;
extern int timer1ClockReload;
extern bool timer2On;
extern int timer2Ticks;
extern int timer2ClockReload;
extern bool timer3On;
extern int timer3Ticks;
extern int timer3ClockReload;
extern int cpuTotalTicks;
#define CPUReadByteQuick(addr) \
map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]
#define CPUReadHalfWordQuick(addr) \
READ16LE(((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
#define CPUReadMemoryQuick(addr) \
READ32LE(((u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
static inline u32 CPUReadMemory(u32 address)
{
#ifdef GBA_LOGGING
if(address & 3) {
if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
log("Unaligned word read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
}
#endif
u32 value;
switch(address >> 24) {
case 0:
if(reg[15].I >> 24) {
if(address < 0x4000) {
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal word read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
value = READ32LE(((u32 *)&biosProtected));
}
else goto unreadable;
} else
value = READ32LE(((u32 *)&bios[address & 0x3FFC]));
break;
case 2:
value = READ32LE(((u32 *)&workRAM[address & 0x3FFFC]));
break;
case 3:
value = READ32LE(((u32 *)&internalRAM[address & 0x7ffC]));
break;
case 4:
if((address < 0x4000400) && ioReadable[address & 0x3fc]) {
if(ioReadable[(address & 0x3fc) + 2])
value = READ32LE(((u32 *)&ioMem[address & 0x3fC]));
else
value = READ16LE(((u16 *)&ioMem[address & 0x3fc]));
} else goto unreadable;
break;
case 5:
value = READ32LE(((u32 *)&paletteRAM[address & 0x3fC]));
break;
case 6:
address = (address & 0x1fffc);
if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
{
value = 0;
break;
}
if ((address & 0x18000) == 0x18000)
address &= 0x17fff;
value = READ32LE(((u32 *)&vram[address]));
break;
case 7:
value = READ32LE(((u32 *)&oam[address & 0x3FC]));
break;
case 8:
case 9:
case 10:
case 11:
case 12:
value = READ32LE(((u32 *)&rom[address&0x1FFFFFC]));
break;
case 13:
if(cpuEEPROMEnabled)
// no need to swap this
return eepromRead(address);
goto unreadable;
case 14:
if(cpuFlashEnabled | cpuSramEnabled)
// no need to swap this
return flashRead(address);
// default
default:
unreadable:
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal word read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
if(cpuDmaHack) {
value = cpuDmaLast;
} else {
if(armState) {
value = CPUReadMemoryQuick(reg[15].I);
} else {
value = CPUReadHalfWordQuick(reg[15].I) |
CPUReadHalfWordQuick(reg[15].I) << 16;
}
}
}
if(address & 3) {
#ifdef C_CORE
int shift = (address & 3) << 3;
value = (value >> shift) | (value << (32 - shift));
#else
#ifdef __GNUC__
asm("and $3, %%ecx;"
"shl $3 ,%%ecx;"
"ror %%cl, %0"
: "=r" (value)
: "r" (value), "c" (address));
#else
__asm {
mov ecx, address;
and ecx, 3;
shl ecx, 3;
ror [dword ptr value], cl;
}
#endif
#endif
}
return value;
}
extern u32 myROM[];
static inline u32 CPUReadHalfWord(u32 address)
{
#ifdef GBA_LOGGING
if(address & 1) {
if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
log("Unaligned halfword read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
}
#endif
u32 value;
switch(address >> 24) {
case 0:
if (reg[15].I >> 24) {
if(address < 0x4000) {
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal halfword read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
value = READ16LE(((u16 *)&biosProtected[address&2]));
} else goto unreadable;
} else
value = READ16LE(((u16 *)&bios[address & 0x3FFE]));
break;
case 2:
value = READ16LE(((u16 *)&workRAM[address & 0x3FFFE]));
break;
case 3:
value = READ16LE(((u16 *)&internalRAM[address & 0x7ffe]));
break;
case 4:
if((address < 0x4000400) && ioReadable[address & 0x3fe])
{
value = READ16LE(((u16 *)&ioMem[address & 0x3fe]));
if (((address & 0x3fe)>0xFF) && ((address & 0x3fe)<0x10E))
{
if (((address & 0x3fe) == 0x100) && timer0On)
value = 0xFFFF - ((timer0Ticks-cpuTotalTicks) >> timer0ClockReload);
else
if (((address & 0x3fe) == 0x104) && timer1On && !(TM1CNT & 4))
value = 0xFFFF - ((timer1Ticks-cpuTotalTicks) >> timer1ClockReload);
else
if (((address & 0x3fe) == 0x108) && timer2On && !(TM2CNT & 4))
value = 0xFFFF - ((timer2Ticks-cpuTotalTicks) >> timer2ClockReload);
else
if (((address & 0x3fe) == 0x10C) && timer3On && !(TM3CNT & 4))
value = 0xFFFF - ((timer3Ticks-cpuTotalTicks) >> timer3ClockReload);
}
}
else goto unreadable;
break;
case 5:
value = READ16LE(((u16 *)&paletteRAM[address & 0x3fe]));
break;
case 6:
address = (address & 0x1fffe);
if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
{
value = 0;
break;
}
if ((address & 0x18000) == 0x18000)
address &= 0x17fff;
value = READ16LE(((u16 *)&vram[address]));
break;
case 7:
value = READ16LE(((u16 *)&oam[address & 0x3fe]));
break;
case 8:
case 9:
case 10:
case 11:
case 12:
if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
value = rtcRead(address);
else
value = READ16LE(((u16 *)&rom[address & 0x1FFFFFE]));
break;
case 13:
if(cpuEEPROMEnabled)
// no need to swap this
return eepromRead(address);
goto unreadable;
case 14:
if(cpuFlashEnabled | cpuSramEnabled)
// no need to swap this
return flashRead(address);
// default
default:
unreadable:
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal halfword read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
if(cpuDmaHack) {
value = cpuDmaLast & 0xFFFF;
} else {
if(armState) {
value = CPUReadHalfWordQuick(reg[15].I + (address & 2));
} else {
value = CPUReadHalfWordQuick(reg[15].I);
}
}
break;
}
if(address & 1) {
value = (value >> 8) | (value << 24);
}
return value;
}
static inline u16 CPUReadHalfWordSigned(u32 address)
{
u16 value = CPUReadHalfWord(address);
if((address & 1))
value = (s8)value;
return value;
}
static inline u8 CPUReadByte(u32 address)
{
switch(address >> 24) {
case 0:
if (reg[15].I >> 24) {
if(address < 0x4000) {
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal byte read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
return biosProtected[address & 3];
} else goto unreadable;
}
return bios[address & 0x3FFF];
case 2:
return workRAM[address & 0x3FFFF];
case 3:
return internalRAM[address & 0x7fff];
case 4:
if((address < 0x4000400) && ioReadable[address & 0x3ff])
return ioMem[address & 0x3ff];
else goto unreadable;
case 5:
return paletteRAM[address & 0x3ff];
case 6:
address = (address & 0x1ffff);
if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
return 0;
if ((address & 0x18000) == 0x18000)
address &= 0x17fff;
return vram[address];
case 7:
return oam[address & 0x3ff];
case 8:
case 9:
case 10:
case 11:
case 12:
return rom[address & 0x1FFFFFF];
case 13:
if(cpuEEPROMEnabled)
return eepromRead(address);
goto unreadable;
case 14:
if(cpuSramEnabled | cpuFlashEnabled)
return flashRead(address);
if(cpuEEPROMSensorEnabled) {
switch(address & 0x00008f00) {
case 0x8200:
return systemGetSensorX() & 255;
case 0x8300:
return (systemGetSensorX() >> 8)|0x80;
case 0x8400:
return systemGetSensorY() & 255;
case 0x8500:
return systemGetSensorY() >> 8;
}
}
// default
default:
unreadable:
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_READ) {
log("Illegal byte read: %08x at %08x\n", address, armMode ?
armNextPC - 4 : armNextPC - 2);
}
#endif
if(cpuDmaHack) {
return cpuDmaLast & 0xFF;
} else {
if(armState) {
return CPUReadByteQuick(reg[15].I+(address & 3));
} else {
return CPUReadByteQuick(reg[15].I+(address & 1));
}
}
break;
}
}
static inline void CPUWriteMemory(u32 address, u32 value)
{
#ifdef GBA_LOGGING
if(address & 3) {
if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
log("Unaligned word write: %08x to %08x from %08x\n",
value,
address,
armMode ? armNextPC - 4 : armNextPC - 2);
}
}
#endif
switch(address >> 24) {
case 0x02:
#ifdef BKPT_SUPPORT
if(*((u32 *)&freezeWorkRAM[address & 0x3FFFC]))
cheatsWriteMemory(address & 0x203FFFC,
value);
else
#endif
WRITE32LE(((u32 *)&workRAM[address & 0x3FFFC]), value);
break;
case 0x03:
#ifdef BKPT_SUPPORT
if(*((u32 *)&freezeInternalRAM[address & 0x7ffc]))
cheatsWriteMemory(address & 0x3007FFC,
value);
else
#endif
WRITE32LE(((u32 *)&internalRAM[address & 0x7ffC]), value);
break;
case 0x04:
if(address < 0x4000400) {
CPUUpdateRegister((address & 0x3FC), value & 0xFFFF);
CPUUpdateRegister((address & 0x3FC) + 2, (value >> 16));
} else goto unwritable;
break;
case 0x05:
#ifdef BKPT_SUPPORT
if(*((u32 *)&freezePRAM[address & 0x3fc]))
cheatsWriteMemory(address & 0x70003FC,
value);
else
#endif
WRITE32LE(((u32 *)&paletteRAM[address & 0x3FC]), value);
break;
case 0x06:
address = (address & 0x1fffc);
if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
return;
if ((address & 0x18000) == 0x18000)
address &= 0x17fff;
#ifdef BKPT_SUPPORT
if(*((u32 *)&freezeVRAM[address]))
cheatsWriteMemory(address + 0x06000000, value);
else
#endif
WRITE32LE(((u32 *)&vram[address]), value);
break;
case 0x07:
#ifdef BKPT_SUPPORT
if(*((u32 *)&freezeOAM[address & 0x3fc]))
cheatsWriteMemory(address & 0x70003FC,
value);
else
#endif
WRITE32LE(((u32 *)&oam[address & 0x3fc]), value);
break;
case 0x0D:
if(cpuEEPROMEnabled) {
eepromWrite(address, value);
break;
}
goto unwritable;
case 0x0E:
if(!eepromInUse | cpuSramEnabled | cpuFlashEnabled) {
(*cpuSaveGameFunc)(address, (u8)value);
break;
}
// default
default:
unwritable:
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
log("Illegal word write: %08x to %08x from %08x\n",
value,
address,
armMode ? armNextPC - 4 : armNextPC - 2);
}
#endif
break;
}
}
static inline void CPUWriteHalfWord(u32 address, u16 value)
{
#ifdef GBA_LOGGING
if(address & 1) {
if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
log("Unaligned halfword write: %04x to %08x from %08x\n",
value,
address,
armMode ? armNextPC - 4 : armNextPC - 2);
}
}
#endif
switch(address >> 24) {
case 2:
#ifdef BKPT_SUPPORT
if(*((u16 *)&freezeWorkRAM[address & 0x3FFFE]))
cheatsWriteHalfWord(address & 0x203FFFE,
value);
else
#endif
WRITE16LE(((u16 *)&workRAM[address & 0x3FFFE]),value);
break;
case 3:
#ifdef BKPT_SUPPORT
if(*((u16 *)&freezeInternalRAM[address & 0x7ffe]))
cheatsWriteHalfWord(address & 0x3007ffe,
value);
else
#endif
WRITE16LE(((u16 *)&internalRAM[address & 0x7ffe]), value);
break;
case 4:
if(address < 0x4000400)
CPUUpdateRegister(address & 0x3fe, value);
else goto unwritable;
break;
case 5:
#ifdef BKPT_SUPPORT
if(*((u16 *)&freezePRAM[address & 0x03fe]))
cheatsWriteHalfWord(address & 0x70003fe,
value);
else
#endif
WRITE16LE(((u16 *)&paletteRAM[address & 0x3fe]), value);
break;
case 6:
address = (address & 0x1fffe);
if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
return;
if ((address & 0x18000) == 0x18000)
address &= 0x17fff;
#ifdef BKPT_SUPPORT
if(*((u16 *)&freezeVRAM[address]))
cheatsWriteHalfWord(address + 0x06000000,
value);
else
#endif
WRITE16LE(((u16 *)&vram[address]), value);
break;
case 7:
#ifdef BKPT_SUPPORT
if(*((u16 *)&freezeOAM[address & 0x03fe]))
cheatsWriteHalfWord(address & 0x70003fe,
value);
else
#endif
WRITE16LE(((u16 *)&oam[address & 0x3fe]), value);
break;
case 8:
case 9:
if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8) {
if(!rtcWrite(address, value))
goto unwritable;
} else if(!agbPrintWrite(address, value)) goto unwritable;
break;
case 13:
if(cpuEEPROMEnabled) {
eepromWrite(address, (u8)value);
break;
}
goto unwritable;
case 14:
if(!eepromInUse | cpuSramEnabled | cpuFlashEnabled) {
(*cpuSaveGameFunc)(address, (u8)value);
break;
}
goto unwritable;
default:
unwritable:
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
log("Illegal halfword write: %04x to %08x from %08x\n",
value,
address,
armMode ? armNextPC - 4 : armNextPC - 2);
}
#endif
break;
}
}
static inline void CPUWriteByte(u32 address, u8 b)
{
switch(address >> 24) {
case 2:
#ifdef BKPT_SUPPORT
if(freezeWorkRAM[address & 0x3FFFF])
cheatsWriteByte(address & 0x203FFFF, b);
else
#endif
workRAM[address & 0x3FFFF] = b;
break;
case 3:
#ifdef BKPT_SUPPORT
if(freezeInternalRAM[address & 0x7fff])
cheatsWriteByte(address & 0x3007fff, b);
else
#endif
internalRAM[address & 0x7fff] = b;
break;
case 4:
if(address < 0x4000400) {
switch(address & 0x3FF) {
case 0x301:
if(b == 0x80)
stopState = true;
holdState = 1;
holdType = -1;
cpuNextEvent = cpuTotalTicks;
break;
case 0x60:
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x68:
case 0x69:
case 0x6c:
case 0x6d:
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
case 0x78:
case 0x79:
case 0x7c:
case 0x7d:
case 0x80:
case 0x81:
case 0x84:
case 0x85:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9a:
case 0x9b:
case 0x9c:
case 0x9d:
case 0x9e:
case 0x9f:
soundEvent(address&0xFF, b);
break;
default:
if(address & 1)
CPUUpdateRegister(address & 0x3fe,
((READ16LE(((u16 *)&ioMem[address & 0x3fe])))
& 0x00FF) |
b<<8);
else
CPUUpdateRegister(address & 0x3fe,
((READ16LE(((u16 *)&ioMem[address & 0x3fe])) & 0xFF00) | b));
}
break;
} else goto unwritable;
break;
case 5:
// no need to switch
*((u16 *)&paletteRAM[address & 0x3FE]) = (b << 8) | b;
break;
case 6:
address = (address & 0x1fffe);
if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
return;
if ((address & 0x18000) == 0x18000)
address &= 0x17fff;
// no need to switch
// byte writes to OBJ VRAM are ignored
if ((address) < objTilesAddress[((DISPCNT&7)+1)>>2])
{
#ifdef BKPT_SUPPORT
if(freezeVRAM[address])
cheatsWriteByte(address + 0x06000000, b);
else
#endif
*((u16 *)&vram[address]) = (b << 8) | b;
}
break;
case 7:
// no need to switch
// byte writes to OAM are ignored
// *((u16 *)&oam[address & 0x3FE]) = (b << 8) | b;
break;
case 13:
if(cpuEEPROMEnabled) {
eepromWrite(address, b);
break;
}
goto unwritable;
case 14:
if (!(saveType == 5) && (!eepromInUse | cpuSramEnabled | cpuFlashEnabled)) {
//if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) {
(*cpuSaveGameFunc)(address, b);
break;
}
// default
default:
unwritable:
#ifdef GBA_LOGGING
if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
log("Illegal byte write: %02x to %08x from %08x\n",
b,
address,
armMode ? armNextPC - 4 : armNextPC -2 );
}
#endif
break;
}
}
#endif //VBA_GBAinline_H

View File

@ -22,6 +22,7 @@
#include "GBA.h" #include "GBA.h"
#include "Globals.h" #include "Globals.h"
#include "Port.h" #include "Port.h"
#include "System.h"
#define debuggerWriteHalfWord(addr, value) \ #define debuggerWriteHalfWord(addr, value) \
WRITE16LE((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], (value)) WRITE16LE((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], (value))
@ -34,26 +35,21 @@ static bool agbPrintProtect = false;
bool agbPrintWrite(u32 address, u16 value) bool agbPrintWrite(u32 address, u16 value)
{ {
if(agbPrintEnabled) if(agbPrintEnabled) {
{ if(address == 0x9fe2ffe) { // protect
if(address == 0x9fe2ffe) agbPrintProtect = (value != 0);
{ // protect debuggerWriteHalfWord(address, value);
agbPrintProtect = (value != 0); return true;
debuggerWriteHalfWord(address, value); } else {
return true; if(agbPrintProtect &&
} ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
else || (address >= 0x8fd0000 && address <= 0x8fdffff)
{ || (address >= 0x9fd0000 && address <= 0x9fdffff))) {
if(agbPrintProtect && debuggerWriteHalfWord(address, value);
((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure return true;
|| (address >= 0x8fd0000 && address <= 0x8fdffff) }
|| (address >= 0x9fd0000 && address <= 0x9fdffff)))
{
debuggerWriteHalfWord(address, value);
return true;
}
}
} }
}
return false; return false;
} }
@ -72,35 +68,31 @@ bool agbPrintIsEnabled()
return agbPrintEnabled; return agbPrintEnabled;
} }
extern void (*dbgOutput)(char *, u32);
void agbPrintFlush() void agbPrintFlush()
{ {
u16 get = debuggerReadHalfWord(0x9fe20fc); u16 get = debuggerReadHalfWord(0x9fe20fc);
u16 put = debuggerReadHalfWord(0x9fe20fe); u16 put = debuggerReadHalfWord(0x9fe20fe);
u32 address = (debuggerReadHalfWord(0x9fe20fa) << 16); u32 address = (debuggerReadHalfWord(0x9fe20fa) << 16);
if(address != 0xfd0000 && address != 0x1fd0000) if(address != 0xfd0000 && address != 0x1fd0000) {
{ dbgOutput("Did you forget to call AGBPrintInit?\n", 0);
dbgOutput("Did you forget to call AGBPrintInit?\n", 0); // get rid of the text otherwise we will continue to be called
// get rid of the text otherwise we will continue to be called debuggerWriteHalfWord(0x9fe20fc, put);
debuggerWriteHalfWord(0x9fe20fc, put); return;
return; }
}
u8 *data = &rom[address]; u8 *data = &rom[address];
while(get != put) while(get != put) {
{ char c = data[get++];
char c = data[get++]; char s[2];
char s[2]; s[0] = c;
s[0] = c; s[1] = 0;
s[1] = 0;
if(systemVerbose & VERBOSE_AGBPRINT) if(systemVerbose & VERBOSE_AGBPRINT)
dbgOutput(s, 0); dbgOutput(s, 0);
if(c == '\n') if(c == '\n')
break; break;
} }
debuggerWriteHalfWord(0x9fe20fc, get); debuggerWriteHalfWord(0x9fe20fc, get);
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,432 +0,0 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** Code adapted from Exult source code by Forgotten
** Scale.cc - Trying to scale with bilinear interpolation.
**
** Written: 6/14/00 - JSF
**/
#include "System.h"
static u8 row_cur[3*322];
static u8 row_next[3*322];
static u8 *rgb_row_cur = row_cur;
static u8 *rgb_row_next = row_next;
#define RGB(r,g,b) ((r)>>3) << systemRedShift |\
((g) >> 3) << systemGreenShift |\
((b) >> 3) << systemBlueShift\
static void fill_rgb_row_16(u16 *from, int src_width, u8 *row, int width)
{
u8 *copy_start = row + src_width*3;
u8 *all_stop = row + width*3;
while (row < copy_start)
{
u16 color = *from++;
*row++ = ((color >> systemRedShift) & 0x1f) << 3;
*row++ = ((color >> systemGreenShift) & 0x1f) << 3;
*row++ = ((color >> systemBlueShift) & 0x1f) << 3;
}
// any remaining elements to be written to 'row' are a replica of the
// preceding pixel
u8 *p = row-3;
while (row < all_stop)
{
// we're guaranteed three elements per pixel; could unroll the loop
// further, especially with a Duff's Device, but the gains would be
// probably limited (judging by profiler output)
*row++ = *p++;
*row++ = *p++;
*row++ = *p++;
}
}
static void fill_rgb_row_32(u32 *from, int src_width, u8 *row, int width)
{
u8 *copy_start = row + src_width*3;
u8 *all_stop = row + width*3;
while (row < copy_start)
{
u32 color = *from++;
*row++ = ((color >> systemRedShift) & 0x1f) << 3;
*row++ = ((color >> systemGreenShift) & 0x1f) << 3;
*row++ = ((color >> systemBlueShift) & 0x1f) << 3;
}
// any remaining elements to be written to 'row' are a replica of the
// preceding pixel
u8 *p = row-3;
while (row < all_stop)
{
// we're guaranteed three elements per pixel; could unroll the loop
// further, especially with a Duff's Device, but the gains would be
// probably limited (judging by profiler output)
*row++ = *p++;
*row++ = *p++;
*row++ = *p++;
}
}
void Bilinear(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u8 *dstPtr, u32 dstPitch, int width, int height)
{
u16 *to = (u16 *)dstPtr;
u16 *to_odd = (u16 *)(dstPtr + dstPitch);
int from_width = width;
u16 *from = (u16 *)srcPtr;
fill_rgb_row_16(from, from_width, rgb_row_cur, width+1);
for(int y = 0; y < height; y++)
{
u16 *from_orig = from;
u16 *to_orig = to;
if (y+1 < height)
fill_rgb_row_16(from+width+2, from_width, rgb_row_next,
width+1);
else
fill_rgb_row_16(from, from_width, rgb_row_next, width+1);
// every pixel in the src region, is extended to 4 pixels in the
// destination, arranged in a square 'quad'; if the current src
// pixel is 'a', then in what follows 'b' is the src pixel to the
// right, 'c' is the src pixel below, and 'd' is the src pixel to
// the right and down
u8 *cur_row = rgb_row_cur;
u8 *next_row = rgb_row_next;
u8 *ar = cur_row++;
u8 *ag = cur_row++;
u8 *ab = cur_row++;
u8 *cr = next_row++;
u8 *cg = next_row++;
u8 *cb = next_row++;
for(int x=0; x < width; x++)
{
u8 *br = cur_row++;
u8 *bg = cur_row++;
u8 *bb = cur_row++;
u8 *dr = next_row++;
u8 *dg = next_row++;
u8 *db = next_row++;
// upper left pixel in quad: just copy it in
*to++ = RGB(*ar, *ag, *ab);
// upper right
*to++ = RGB((*ar+*br)>>1, (*ag+*bg)>>1, (*ab+*bb)>>1);
// lower left
*to_odd++ = RGB((*ar+*cr)>>1, (*ag+*cg)>>1, (*ab+*cb)>>1);
// lower right
*to_odd++ = RGB((*ar+*br+*cr+*dr)>>2,
(*ag+*bg+*cg+*dg)>>2,
(*ab+*bb+*cb+*db)>>2);
// 'b' becomes 'a', 'd' becomes 'c'
ar = br;
ag = bg;
ab = bb;
cr = dr;
cg = dg;
cb = db;
}
// the "next" rgb row becomes the current; the old current rgb row is
// recycled and serves as the new "next" row
u8 *temp;
temp = rgb_row_cur;
rgb_row_cur = rgb_row_next;
rgb_row_next = temp;
// update the pointers for start of next pair of lines
from = (u16 *)((u8 *)from_orig + srcPitch);
to = (u16 *)((u8 *)to_orig + (dstPitch << 1));
to_odd = (u16 *)((u8 *)to + dstPitch);
}
}
void BilinearPlus(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u8 *dstPtr, u32 dstPitch, int width, int height)
{
u16 *to = (u16 *)dstPtr;
u16 *to_odd = (u16 *)(dstPtr + dstPitch);
int from_width = width;
u16 *from = (u16 *)srcPtr;
fill_rgb_row_16(from, from_width, rgb_row_cur, width+1);
for(int y = 0; y < height; y++)
{
u16 *from_orig = from;
u16 *to_orig = to;
if (y+1 < height)
fill_rgb_row_16(from+width+2, from_width, rgb_row_next,
width+1);
else
fill_rgb_row_16(from, from_width, rgb_row_next, width+1);
// every pixel in the src region, is extended to 4 pixels in the
// destination, arranged in a square 'quad'; if the current src
// pixel is 'a', then in what follows 'b' is the src pixel to the
// right, 'c' is the src pixel below, and 'd' is the src pixel to
// the right and down
u8 *cur_row = rgb_row_cur;
u8 *next_row = rgb_row_next;
u8 *ar = cur_row++;
u8 *ag = cur_row++;
u8 *ab = cur_row++;
u8 *cr = next_row++;
u8 *cg = next_row++;
u8 *cb = next_row++;
for(int x=0; x < width; x++)
{
u8 *br = cur_row++;
u8 *bg = cur_row++;
u8 *bb = cur_row++;
u8 *dr = next_row++;
u8 *dg = next_row++;
u8 *db = next_row++;
// upper left pixel in quad: just copy it in
//*to++ = manip.rgb(*ar, *ag, *ab);
#ifdef USE_ORIGINAL_BILINEAR_PLUS
*to++ = RGB(
(((*ar)<<2) +((*ar)) + (*cr+*br+*br) )>> 3,
(((*ag)<<2) +((*ag)) + (*cg+*bg+*bg) )>> 3,
(((*ab)<<2) +((*ab)) + (*cb+*bb+*bb) )>> 3);
#else
*to++ = RGB(
(((*ar)<<3) +((*ar)<<1) + (*cr+*br+*br+*cr) )>> 4,
(((*ag)<<3) +((*ag)<<1) + (*cg+*bg+*bg+*cg) )>> 4,
(((*ab)<<3) +((*ab)<<1) + (*cb+*bb+*bb+*cb) )>> 4);
#endif
// upper right
*to++ = RGB((*ar+*br)>>1, (*ag+*bg)>>1, (*ab+*bb)>>1);
// lower left
*to_odd++ = RGB((*ar+*cr)>>1, (*ag+*cg)>>1, (*ab+*cb)>>1);
// lower right
*to_odd++ = RGB((*ar+*br+*cr+*dr)>>2,
(*ag+*bg+*cg+*dg)>>2,
(*ab+*bb+*cb+*db)>>2);
// 'b' becomes 'a', 'd' becomes 'c'
ar = br;
ag = bg;
ab = bb;
cr = dr;
cg = dg;
cb = db;
}
// the "next" rgb row becomes the current; the old current rgb row is
// recycled and serves as the new "next" row
u8 *temp;
temp = rgb_row_cur;
rgb_row_cur = rgb_row_next;
rgb_row_next = temp;
// update the pointers for start of next pair of lines
from = (u16 *)((u8 *)from_orig + srcPitch);
to = (u16 *)((u8 *)to_orig + (dstPitch << 1));
to_odd = (u16 *)((u8 *)to + dstPitch);
}
}
void Bilinear32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u8 *dstPtr, u32 dstPitch, int width, int height)
{
u32 *to = (u32 *)dstPtr;
u32 *to_odd = (u32 *)(dstPtr + dstPitch);
int from_width = width;
if(width+1 < from_width)
from_width = width+1;
u32 *from = (u32 *)srcPtr;
fill_rgb_row_32(from, from_width, rgb_row_cur, width+1);
for(int y = 0; y < height; y++)
{
u32 *from_orig = from;
u32 *to_orig = to;
if (y+1 < height)
fill_rgb_row_32(from+width+1, from_width, rgb_row_next,
width+1);
else
fill_rgb_row_32(from, from_width, rgb_row_next, width+1);
// every pixel in the src region, is extended to 4 pixels in the
// destination, arranged in a square 'quad'; if the current src
// pixel is 'a', then in what follows 'b' is the src pixel to the
// right, 'c' is the src pixel below, and 'd' is the src pixel to
// the right and down
u8 *cur_row = rgb_row_cur;
u8 *next_row = rgb_row_next;
u8 *ar = cur_row++;
u8 *ag = cur_row++;
u8 *ab = cur_row++;
u8 *cr = next_row++;
u8 *cg = next_row++;
u8 *cb = next_row++;
for(int x=0; x < width; x++)
{
u8 *br = cur_row++;
u8 *bg = cur_row++;
u8 *bb = cur_row++;
u8 *dr = next_row++;
u8 *dg = next_row++;
u8 *db = next_row++;
// upper left pixel in quad: just copy it in
*to++ = RGB(*ar, *ag, *ab);
// upper right
*to++ = RGB((*ar+*br)>>1, (*ag+*bg)>>1, (*ab+*bb)>>1);
// lower left
*to_odd++ = RGB((*ar+*cr)>>1, (*ag+*cg)>>1, (*ab+*cb)>>1);
// lower right
*to_odd++ = RGB((*ar+*br+*cr+*dr)>>2,
(*ag+*bg+*cg+*dg)>>2,
(*ab+*bb+*cb+*db)>>2);
// 'b' becomes 'a', 'd' becomes 'c'
ar = br;
ag = bg;
ab = bb;
cr = dr;
cg = dg;
cb = db;
}
// the "next" rgb row becomes the current; the old current rgb row is
// recycled and serves as the new "next" row
u8 *temp;
temp = rgb_row_cur;
rgb_row_cur = rgb_row_next;
rgb_row_next = temp;
// update the pointers for start of next pair of lines
from = (u32 *)((u8 *)from_orig + srcPitch);
to = (u32 *)((u8 *)to_orig + (dstPitch << 1));
to_odd = (u32 *)((u8 *)to + dstPitch);
}
}
void BilinearPlus32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u8 *dstPtr, u32 dstPitch, int width, int height)
{
u32 *to = (u32 *)dstPtr;
u32 *to_odd = (u32 *)(dstPtr + dstPitch);
int from_width = width;
if(width+1 < from_width)
from_width = width+1;
u32 *from = (u32 *)srcPtr;
fill_rgb_row_32(from, from_width, rgb_row_cur, width+1);
for(int y = 0; y < height; y++)
{
u32 *from_orig = from;
u32 *to_orig = to;
if (y+1 < height)
fill_rgb_row_32(from+width+1, from_width, rgb_row_next,
width+1);
else
fill_rgb_row_32(from, from_width, rgb_row_next, width+1);
// every pixel in the src region, is extended to 4 pixels in the
// destination, arranged in a square 'quad'; if the current src
// pixel is 'a', then in what follows 'b' is the src pixel to the
// right, 'c' is the src pixel below, and 'd' is the src pixel to
// the right and down
u8 *cur_row = rgb_row_cur;
u8 *next_row = rgb_row_next;
u8 *ar = cur_row++;
u8 *ag = cur_row++;
u8 *ab = cur_row++;
u8 *cr = next_row++;
u8 *cg = next_row++;
u8 *cb = next_row++;
for(int x=0; x < width; x++)
{
u8 *br = cur_row++;
u8 *bg = cur_row++;
u8 *bb = cur_row++;
u8 *dr = next_row++;
u8 *dg = next_row++;
u8 *db = next_row++;
// upper left pixel in quad: just copy it in
//*to++ = manip.rgb(*ar, *ag, *ab);
#ifdef USE_ORIGINAL_BILINEAR_PLUS
*to++ = RGB(
(((*ar)<<2) +((*ar)) + (*cr+*br+*br) )>> 3,
(((*ag)<<2) +((*ag)) + (*cg+*bg+*bg) )>> 3,
(((*ab)<<2) +((*ab)) + (*cb+*bb+*bb) )>> 3);
#else
*to++ = RGB(
(((*ar)<<3) +((*ar)<<1) + (*cr+*br+*br+*cr) )>> 4,
(((*ag)<<3) +((*ag)<<1) + (*cg+*bg+*bg+*cg) )>> 4,
(((*ab)<<3) +((*ab)<<1) + (*cb+*bb+*bb+*cb) )>> 4);
#endif
// upper right
*to++ = RGB((*ar+*br)>>1, (*ag+*bg)>>1, (*ab+*bb)>>1);
// lower left
*to_odd++ = RGB((*ar+*cr)>>1, (*ag+*cg)>>1, (*ab+*cb)>>1);
// lower right
*to_odd++ = RGB((*ar+*br+*cr+*dr)>>2,
(*ag+*bg+*cg+*dg)>>2,
(*ab+*bb+*cb+*db)>>2);
// 'b' becomes 'a', 'd' becomes 'c'
ar = br;
ag = bg;
ab = bb;
cr = dr;
cg = dg;
cb = db;
}
// the "next" rgb row becomes the current; the old current rgb row is
// recycled and serves as the new "next" row
u8 *temp;
temp = rgb_row_cur;
rgb_row_cur = rgb_row_next;
rgb_row_next = temp;
// update the pointers for start of next pair of lines
from = (u32 *)((u8 *)from_orig + srcPitch);
to = (u32 *)((u8 *)to_orig + (dstPitch << 1));
to_odd = (u32 *)((u8 *)to + dstPitch);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
// -*- C++ -*- // -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten // Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team // Copyright (C) 2004-2006 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify // This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -23,6 +23,7 @@
extern void BIOS_ArcTan(); extern void BIOS_ArcTan();
extern void BIOS_ArcTan2(); extern void BIOS_ArcTan2();
extern void BIOS_BitUnPack(); extern void BIOS_BitUnPack();
extern void BIOS_GetBiosChecksum();
extern void BIOS_BgAffineSet(); extern void BIOS_BgAffineSet();
extern void BIOS_CpuSet(); extern void BIOS_CpuSet();
extern void BIOS_CpuFastSet(); extern void BIOS_CpuFastSet();

View File

@ -2548,9 +2548,11 @@ bool gbReadSaveState(const char *name)
bool gbWritePNGFile(const char *fileName) bool gbWritePNGFile(const char *fileName)
{ {
if(gbBorderOn) // if(gbBorderOn)
return utilWritePNGFile(fileName, 256, 224, pix); // return utilWritePNGFile(fileName, 256, 224, pix);
return utilWritePNGFile(fileName, 160, 144, pix); // return utilWritePNGFile(fileName, 160, 144, pix);
return false;
} }
bool gbWriteBMPFile(const char *fileName) bool gbWriteBMPFile(const char *fileName)

View File

@ -18,7 +18,7 @@
#include <string.h> #include <string.h>
#include "../GBA.h" #include "../agb/GBA.h"
#include "gbGlobals.h" #include "gbGlobals.h"
#include "gbSGB.h" #include "gbSGB.h"

View File

@ -16,7 +16,7 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../GBA.h" #include "../agb/GBA.h"
u8 *gbMemoryMap[16]; u8 *gbMemoryMap[16];

View File

@ -16,7 +16,7 @@
// along with this program; if not, write to the Free Software Foundation, // along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../GBA.h" #include "../agb/GBA.h"
#include "../Port.h" #include "../Port.h"
#include "gbGlobals.h" #include "gbGlobals.h"
#include "gbMemory.h" #include "gbMemory.h"

View File

@ -18,7 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "../GBA.h" #include "../agb/GBA.h"
u8 gbPrinterStatus = 0; u8 gbPrinterStatus = 0;
int gbPrinterState = 0; int gbPrinterState = 0;

File diff suppressed because it is too large Load Diff

View File

@ -19,11 +19,6 @@
#ifndef VBA_ELF_H #ifndef VBA_ELF_H
#define VBA_ELF_H #define VBA_ELF_H
#include <fat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/dir.h>
enum LocationType { enum LocationType {
LOCATION_register, LOCATION_register,
@ -36,92 +31,85 @@ enum LocationType {
#define DW_ATE_unsigned 0x07 #define DW_ATE_unsigned 0x07
#define DW_ATE_unsigned_char 0x08 #define DW_ATE_unsigned_char 0x08
struct ELFHeader struct ELFHeader {
{ u32 magic;
u32 magic; u8 clazz;
u8 clazz; u8 data;
u8 data; u8 version;
u8 version; u8 pad[9];
u8 pad[9]; u16 e_type;
u16 e_type; u16 e_machine;
u16 e_machine; u32 e_version;
u32 e_version; u32 e_entry;
u32 e_entry; u32 e_phoff;
u32 e_phoff; u32 e_shoff;
u32 e_shoff; u32 e_flags;
u32 e_flags; u16 e_ehsize;
u16 e_ehsize; u16 e_phentsize;
u16 e_phentsize; u16 e_phnum;
u16 e_phnum; u16 e_shentsize;
u16 e_shentsize; u16 e_shnum;
u16 e_shnum; u16 e_shstrndx;
u16 e_shstrndx; };
};
struct ELFProgramHeader struct ELFProgramHeader {
{ u32 type;
u32 type; u32 offset;
u32 offset; u32 vaddr;
u32 vaddr; u32 paddr;
u32 paddr; u32 filesz;
u32 filesz; u32 memsz;
u32 memsz; u32 flags;
u32 flags; u32 align;
u32 align; };
};
struct ELFSectionHeader struct ELFSectionHeader {
{ u32 name;
u32 name; u32 type;
u32 type; u32 flags;
u32 flags; u32 addr;
u32 addr; u32 offset;
u32 offset; u32 size;
u32 size; u32 link;
u32 link; u32 info;
u32 info; u32 addralign;
u32 addralign; u32 entsize;
u32 entsize; };
};
struct ELFSymbol struct ELFSymbol {
{ u32 name;
u32 name; u32 value;
u32 size;
u8 info;
u8 other;
u16 shndx;
};
struct ELFBlock {
int length;
u8 *data;
};
struct ELFAttr {
u32 name;
u32 form;
union {
u32 value; u32 value;
u32 size; char *string;
u8 info;
u8 other;
u16 shndx;
};
struct ELFBlock
{
int length;
u8 *data; u8 *data;
bool flag;
ELFBlock *block;
}; };
};
struct ELFAttr struct ELFAbbrev {
{ u32 number;
u32 name; u32 tag;
u32 form; bool hasChildren;
union { int numAttrs;
u32 value; ELFAttr *attrs;
char *string; ELFAbbrev *next;
u8 *data; };
bool flag;
ELFBlock *block;
};
};
struct ELFAbbrev
{
u32 number;
u32 tag;
bool hasChildren;
int numAttrs;
ELFAttr *attrs;
ELFAbbrev *next;
};
enum TypeEnum { enum TypeEnum {
TYPE_base, TYPE_base,
@ -138,174 +126,158 @@ enum TypeEnum {
struct Type; struct Type;
struct Object; struct Object;
struct FunctionType struct FunctionType {
{ Type *returnType;
Type *returnType; Object *args;
Object *args; };
};
struct Member struct Member {
{ char *name;
char *name; Type *type;
Type *type; int bitSize;
int bitSize; int bitOffset;
int bitOffset; int byteSize;
int byteSize; ELFBlock *location;
ELFBlock *location; };
};
struct Struct struct Struct {
{ int memberCount;
int memberCount; Member *members;
Member *members; };
};
struct Array struct Array {
{ Type *type;
Type *type; int maxBounds;
int maxBounds; int *bounds;
int *bounds; };
};
struct EnumMember struct EnumMember {
{ char *name;
char *name; u32 value;
u32 value; };
};
struct Enum struct Enum {
{ int count;
int count; EnumMember *members;
EnumMember *members; };
};
struct Type struct Type {
{ u32 offset;
u32 offset; TypeEnum type;
TypeEnum type; const char *name;
char *name; int encoding;
int encoding; int size;
int size; int bitSize;
int bitSize; union {
union { Type *pointer;
Type *pointer; FunctionType *function;
FunctionType *function; Array *array;
Array *array; Struct *structure;
Struct *structure; Enum *enumeration;
Enum *enumeration;
};
Type *next;
}; };
Type *next;
};
struct Object struct Object {
{ char *name;
char *name; int file;
int file; int line;
int line; bool external;
bool external; Type *type;
Type *type; ELFBlock *location;
ELFBlock *location; u32 startScope;
u32 startScope; u32 endScope;
u32 endScope; Object *next;
Object *next; };
};
struct Function struct Function {
{ char *name;
char *name; u32 lowPC;
u32 lowPC; u32 highPC;
u32 highPC; int file;
int file; int line;
int line; bool external;
bool external; Type *returnType;
Type *returnType; Object *parameters;
Object *parameters; Object *variables;
Object *variables; ELFBlock *frameBase;
ELFBlock *frameBase; Function *next;
Function *next; };
};
struct LineInfoItem struct LineInfoItem {
{ u32 address;
u32 address; char *file;
char *file; int line;
int line; };
};
struct LineInfo struct LineInfo {
{ int fileCount;
int fileCount; char **files;
char **files; int number;
int number; LineInfoItem *lines;
LineInfoItem *lines; };
};
struct ARange struct ARange {
{ u32 lowPC;
u32 lowPC; u32 highPC;
u32 highPC; };
};
struct ARanges struct ARanges {
{ u32 offset;
u32 offset; int count;
int count; ARange *ranges;
ARange *ranges; };
};
struct CompileUnit struct CompileUnit {
{ u32 length;
u32 length; u8 *top;
u8 *top; u32 offset;
u32 offset; ELFAbbrev **abbrevs;
ELFAbbrev **abbrevs; ARanges *ranges;
ARanges *ranges; char *name;
char *name; char *compdir;
char *compdir; u32 lowPC;
u32 lowPC; u32 highPC;
u32 highPC; bool hasLineInfo;
bool hasLineInfo; u32 lineInfo;
u32 lineInfo; LineInfo *lineInfoTable;
LineInfo *lineInfoTable; Function *functions;
Function *functions; Function *lastFunction;
Function *lastFunction; Object *variables;
Object *variables; Type *types;
Type *types; CompileUnit *next;
CompileUnit *next; };
};
struct DebugInfo struct DebugInfo {
{ u8 *debugfile;
u8 *debugfile; u8 *abbrevdata;
u8 *abbrevdata; u8 *debugdata;
u8 *debugdata; u8 *infodata;
u8 *infodata; int numRanges;
int numRanges; ARanges *ranges;
ARanges *ranges; };
};
struct Symbol struct Symbol {
{ const char *name;
char *name; int type;
int type; int binding;
int binding; u32 address;
u32 address; u32 value;
u32 value; u32 size;
u32 size; };
};
extern u32 elfReadLEB128(u8 *, int *); extern u32 elfReadLEB128(u8 *, int *);
extern s32 elfReadSignedLEB128(u8 *, int *); extern s32 elfReadSignedLEB128(u8 *, int *);
extern bool elfRead(const char *, int &, FILE* f); extern bool elfRead(const char *, int &, FILE *f);
extern bool elfGetSymbolAddress(char *,u32 *, u32 *, int *); extern bool elfGetSymbolAddress(const char *,u32 *, u32 *, int *);
extern char *elfGetAddressSymbol(u32); extern const char *elfGetAddressSymbol(u32);
extern char *elfGetSymbol(int, u32 *, u32 *, int *); extern const char *elfGetSymbol(int, u32 *, u32 *, int *);
extern void elfCleanUp(); extern void elfCleanUp();
extern bool elfGetCurrentFunction(u32, Function **, CompileUnit **c); extern bool elfGetCurrentFunction(u32, Function **, CompileUnit **c);
extern bool elfGetObject(char *, Function *, CompileUnit *, Object **); extern bool elfGetObject(const char *, Function *, CompileUnit *, Object **);
extern bool elfFindLineInUnit(u32 *, CompileUnit *, int); extern bool elfFindLineInUnit(u32 *, CompileUnit *, int);
extern bool elfFindLineInModule(u32 *, char *, int); extern bool elfFindLineInModule(u32 *, const char *, int);
u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *); u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *);
u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *, u32); u32 elfDecodeLocation(Function *, ELFBlock *, LocationType *, u32);
int elfFindLine(CompileUnit *unit, Function *func, u32 addr, char **); int elfFindLine(CompileUnit *unit, Function *func, u32 addr, const char **);
#endif #endif

View File

@ -1,69 +0,0 @@
// -*- C++ -*-
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
struct Node
{
Type *type;
u32 location;
u32 objLocation;
LocationType locType;
int value;
int index;
char *name;
Node *expression;
Member *member;
void (*print)(Node *);
bool (*resolve)(Node *, Function *f, CompileUnit *u);
};
extern void exprNodeCleanUp();
extern Node *exprNodeIdentifier();
extern void exprNodeIdentifierPrint(Node *);
extern bool exprNodeIdentifierResolve(Node *, Function *, CompileUnit *);
extern Node *exprNodeNumber();
extern void exprNodeNumberPrint(Node *);
extern bool exprNodeNumberResolve(Node *, Function *, CompileUnit *);
extern Node *exprNodeStar(Node *);
extern void exprNodeStarPrint(Node *);
extern bool exprNodeStarResolve(Node *, Function *, CompileUnit *);
extern Node *exprNodeDot(Node *, Node *);
extern void exprNodeDotPrint(Node *);
extern bool exprNodeDotResolve(Node *, Function *, CompileUnit *);
extern Node *exprNodeArrow(Node *, Node *);
extern void exprNodeArrowPrint(Node *);
extern bool exprNodeArrowResolve(Node *, Function *, CompileUnit *);
extern Node *exprNodeAddr(Node *);
extern void exprNodeAddrPrint(Node *);
extern bool exprNodeAddrResolve(Node *, Function *, CompileUnit *);
extern Node *exprNodeSizeof(Node *);
extern void exprNodeSizeofPrint(Node *);
extern bool exprNodeSizeofResolve(Node *, Function *, CompileUnit *);
extern Node *exprNodeArray(Node *, Node *);
extern void exprNodeArrayPrint(Node *);
extern bool exprNodeArrayResolve(Node *, Function *, CompileUnit *);
#define YYSTYPE struct Node *

File diff suppressed because it is too large Load Diff

View File

@ -1,142 +0,0 @@
/* Declarations for getopt.
Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 2000
Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@gnu.org.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
#ifdef __cplusplus
extern "C"
{
#endif
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
extern char *optarg;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
and for communication between successive calls to `getopt'.
On entry to `getopt', zero means this is the first call; initialize.
When `getopt' returns -1, this is the index of the first of the
non-option elements that the caller should itself scan.
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern int optind;
/* Callers store zero here to inhibit the error message `getopt' prints
for unrecognized options. */
extern int opterr;
/* Set to an option character which was unrecognized. */
extern int optopt;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
of `struct option' terminated by an element containing a name which is
zero.
The field `has_arg' is:
no_argument (or 0) if the option does not take an argument,
required_argument (or 1) if the option requires an argument,
optional_argument (or 2) if the option takes an optional argument.
If the field `flag' is not NULL, it points to a variable that is set
to the value given in the field `val' when the option is found, but
left unchanged if the option is not found.
To have a long-named option do something other than set an `int' to
a compiled-in constant, such as set a value from `optarg', set the
option's `flag' field to zero and its `val' field to a nonzero
value (the equivalent single-letter option character, if there is
one). For long options that have a zero `flag' field, `getopt'
returns the contents of the `val' field. */
struct option
{
#if defined (__STDC__) && __STDC__
const char *name;
#else
char *name;
#endif
/* has_arg can't be an enum because some compilers complain about
type mismatches in all the code that assumes it is an int. */
int has_arg;
int *flag;
int val;
};
/* Names for the values of the `has_arg' field of `struct option'. */
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if defined (__STDC__) && __STDC__
/* HAVE_DECL_* is a three-state macro: undefined, 0 or 1. If it is
undefined, we haven't run the autoconf check so provide the
declaration without arguments. If it is 0, we checked and failed
to find the declaration so provide a fully prototyped one. If it
is 1, we found it so don't provide any declaration at all. */
#if defined (__GNU_LIBRARY__) || (defined (HAVE_DECL_GETOPT) && !HAVE_DECL_GETOPT)
/* Many other libraries have conflicting prototypes for getopt, with
differences in the consts, in stdlib.h. To avoid compilation
errors, only prototype getopt for the GNU C library. */
extern int getopt (int argc, char *const *argv, const char *shortopts);
#else /* not __GNU_LIBRARY__ */
# if !defined (HAVE_DECL_GETOPT)
extern int getopt ();
# endif
#endif /* __GNU_LIBRARY__ */
extern int getopt_long (int argc, char *const *argv, const char *shortopts,
const struct option *longopts, int *longind);
extern int getopt_long_only (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind);
/* Internal only. Users should not call this directly. */
extern int _getopt_internal (int argc, char *const *argv,
const char *shortopts,
const struct option *longopts, int *longind,
int long_only);
#else /* not __STDC__ */
extern int getopt ();
extern int getopt_long ();
extern int getopt_long_only ();
extern int _getopt_internal ();
#endif /* __STDC__ */
#ifdef __cplusplus
}
#endif
#endif /* getopt.h */

View File

@ -1,191 +0,0 @@
/* getopt_long and getopt_long_only entry points for GNU getopt.
Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98
Free Software Foundation, Inc.
NOTE: This source is derived from an old version taken from the GNU C
Library (glibc).
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "getopt.h"
#if !defined __STDC__ || !__STDC__
/* This is a separate conditional since some stdc systems
reject `defined (const)'. */
#ifndef const
#define const
#endif
#endif
#include <stdio.h>
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#define GETOPT_INTERFACE_VERSION 2
#if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2
#include <gnu-versions.h>
#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION
#define ELIDE_CODE
#endif
#endif
#ifndef ELIDE_CODE
/* This needs to come after some library #include
to get __GNU_LIBRARY__ defined. */
#ifdef __GNU_LIBRARY__
#include <stdlib.h>
#endif
#ifndef NULL
#define NULL 0
#endif
int
getopt_long (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
}
/* Like getopt_long, but '-' as well as '--' can indicate a long option.
If an option that starts with '-' (not '--') doesn't match a long option,
but does match a short option, it is parsed as a short option
instead. */
int
getopt_long_only (argc, argv, options, long_options, opt_index)
int argc;
char *const *argv;
const char *options;
const struct option *long_options;
int *opt_index;
{
return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
}
#endif /* Not ELIDE_CODE. */
#ifdef TEST
#include <stdio.h>
int
main (argc, argv)
int argc;
char **argv;
{
int c;
int digit_optind = 0;
while (1)
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
static struct option long_options[] =
{
{"add", 1, 0, 0
},
{"append", 0, 0, 0},
{"delete", 1, 0, 0},
{"verbose", 0, 0, 0},
{"create", 0, 0, 0},
{"file", 1, 0, 0},
{0, 0, 0, 0}
};
c = getopt_long (argc, argv, "abc:d:0123456789",
long_options, &option_index);
if (c == -1)
break;
switch (c)
{
case 0:
printf ("option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
if (digit_optind != 0 && digit_optind != this_option_optind)
printf ("digits occur in two different argv-elements.\n");
digit_optind = this_option_optind;
printf ("option %c\n", c);
break;
case 'a':
printf ("option a\n");
break;
case 'b':
printf ("option b\n");
break;
case 'c':
printf ("option c with value `%s'\n", optarg);
break;
case 'd':
printf ("option d with value `%s'\n", optarg);
break;
case '?':
break;
default:
printf ("?? getopt returned character code 0%o ??\n", c);
}
}
if (optind < argc)
{
printf ("non-option ARGV-elements: ");
while (optind < argc)
printf ("%s ", argv[optind++]);
printf ("\n");
}
exit (0);
}
#endif /* TEST */

View File

@ -68,107 +68,106 @@ static void SmartIB_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
int count = width >> 2; int count = width >> 2;
for(int i = 0; i < height; i++) for(int i = 0; i < height; i++) {
{
#ifdef __GNUC__ #ifdef __GNUC__
asm volatile ( asm volatile (
"push %4\n" "push %4\n"
"movq 0(%5), %%mm7\n" // colorMask "movq 0(%5), %%mm7\n" // colorMask
"0:\n" "0:\n"
"movq 0(%0), %%mm0\n" // src0 "movq 0(%0), %%mm0\n" // src0
"movq 0(%1), %%mm1\n" // src1 "movq 0(%1), %%mm1\n" // src1
"movq 0(%2), %%mm2\n" // src2 "movq 0(%2), %%mm2\n" // src2
"movq 0(%3), %%mm3\n" // src3 "movq 0(%3), %%mm3\n" // src3
"movq %%mm0, 0(%3)\n" // src3 = src0 "movq %%mm0, 0(%3)\n" // src3 = src0
"movq %%mm0, %%mm4\n" "movq %%mm0, %%mm4\n"
"movq %%mm1, %%mm5\n" "movq %%mm1, %%mm5\n"
"pcmpeqw %%mm2, %%mm5\n" // src1 == src2 (A) "pcmpeqw %%mm2, %%mm5\n" // src1 == src2 (A)
"pcmpeqw %%mm3, %%mm4\n" // src3 == src0 (B) "pcmpeqw %%mm3, %%mm4\n" // src3 == src0 (B)
"por %%mm5, %%mm4\n" // A | B "por %%mm5, %%mm4\n" // A | B
"movq %%mm2, %%mm5\n" "movq %%mm2, %%mm5\n"
"pcmpeqw %%mm0, %%mm5\n" // src0 == src2 (C) "pcmpeqw %%mm0, %%mm5\n" // src0 == src2 (C)
"pcmpeqw %%mm1, %%mm3\n" // src1 == src3 (D) "pcmpeqw %%mm1, %%mm3\n" // src1 == src3 (D)
"por %%mm3, %%mm5\n" // C|D "por %%mm3, %%mm5\n" // C|D
"pandn %%mm5, %%mm4\n" // (!(A|B))&(C|D) "pandn %%mm5, %%mm4\n" // (!(A|B))&(C|D)
"movq %%mm0, %%mm2\n" "movq %%mm0, %%mm2\n"
"pand %%mm7, %%mm2\n" // color & colorMask "pand %%mm7, %%mm2\n" // color & colorMask
"pand %%mm7, %%mm1\n" // src1 & colorMask "pand %%mm7, %%mm1\n" // src1 & colorMask
"psrlw $1, %%mm2\n" // (color & colorMask) >> 1 (E) "psrlw $1, %%mm2\n" // (color & colorMask) >> 1 (E)
"psrlw $1, %%mm1\n" // (src & colorMask) >> 1 (F) "psrlw $1, %%mm1\n" // (src & colorMask) >> 1 (F)
"paddw %%mm2, %%mm1\n" // E+F "paddw %%mm2, %%mm1\n" // E+F
"pand %%mm4, %%mm1\n" // (E+F) & res "pand %%mm4, %%mm1\n" // (E+F) & res
"pandn %%mm0, %%mm4\n" // color& !res "pandn %%mm0, %%mm4\n" // color& !res
"por %%mm1, %%mm4\n" "por %%mm1, %%mm4\n"
"movq %%mm4, 0(%0)\n" // src0 = res "movq %%mm4, 0(%0)\n" // src0 = res
"addl $8, %0\n" "addl $8, %0\n"
"addl $8, %1\n" "addl $8, %1\n"
"addl $8, %2\n" "addl $8, %2\n"
"addl $8, %3\n" "addl $8, %3\n"
"decl %4\n" "decl %4\n"
"jnz 0b\n" "jnz 0b\n"
"pop %4\n" "pop %4\n"
"emms\n" "emms\n"
: "+r" (src0), "+r" (src1), "+r" (src2), "+r" (src3) : "+r" (src0), "+r" (src1), "+r" (src2), "+r" (src3)
: "r" (count), "r" (qRGB_COLOR_MASK) : "r" (count), "r" (qRGB_COLOR_MASK)
); );
#else #else
__asm { __asm {
movq mm7, qword ptr [qRGB_COLOR_MASK]; movq mm7, qword ptr [qRGB_COLOR_MASK];
mov eax, src0; mov eax, src0;
mov ebx, src1; mov ebx, src1;
mov ecx, src2; mov ecx, src2;
mov edx, src3; mov edx, src3;
mov edi, count; mov edi, count;
label0: label0:
movq mm0, qword ptr [eax]; // src0 movq mm0, qword ptr [eax]; // src0
movq mm1, qword ptr [ebx]; // src1 movq mm1, qword ptr [ebx]; // src1
movq mm2, qword ptr [ecx]; // src2 movq mm2, qword ptr [ecx]; // src2
movq mm3, qword ptr [edx]; // src3 movq mm3, qword ptr [edx]; // src3
movq qword ptr [edx], mm0; // src3 = src0 movq qword ptr [edx], mm0; // src3 = src0
movq mm4, mm0; movq mm4, mm0;
movq mm5, mm1; movq mm5, mm1;
pcmpeqw mm5, mm2; // src1 == src2 (A) pcmpeqw mm5, mm2; // src1 == src2 (A)
pcmpeqw mm4, mm3; // src3 == src0 (B) pcmpeqw mm4, mm3; // src3 == src0 (B)
por mm4, mm5; // A | B por mm4, mm5; // A | B
movq mm5, mm2; movq mm5, mm2;
pcmpeqw mm5, mm0; // src0 == src2 (C) pcmpeqw mm5, mm0; // src0 == src2 (C)
pcmpeqw mm3, mm1; // src1 == src3 (D) pcmpeqw mm3, mm1; // src1 == src3 (D)
por mm5, mm3; // C|D por mm5, mm3; // C|D
pandn mm4, mm5; // (!(A|B))&(C|D) pandn mm4, mm5; // (!(A|B))&(C|D)
movq mm2, mm0; movq mm2, mm0;
pand mm2, mm7; // color & colorMask pand mm2, mm7; // color & colorMask
pand mm1, mm7; // src1 & colorMask pand mm1, mm7; // src1 & colorMask
psrlw mm2, 1; // (color & colorMask) >> 1 (E) psrlw mm2, 1; // (color & colorMask) >> 1 (E)
psrlw mm1, 1; // (src & colorMask) >> 1 (F) psrlw mm1, 1; // (src & colorMask) >> 1 (F)
paddw mm1, mm2; // E+F paddw mm1, mm2; // E+F
pand mm1, mm4; // (E+F) & res pand mm1, mm4; // (E+F) & res
pandn mm4, mm0; // color & !res pandn mm4, mm0; // color & !res
por mm4, mm1; por mm4, mm1;
movq qword ptr [eax], mm4; // src0 = res movq qword ptr [eax], mm4; // src0 = res
add eax, 8; add eax, 8;
add ebx, 8; add ebx, 8;
add ecx, 8; add ecx, 8;
add edx, 8; add edx, 8;
dec edi; dec edi;
jnz label0; jnz label0;
mov src0, eax; mov src0, eax;
mov src1, ebx; mov src1, ebx;
mov src2, ecx; mov src2, ecx;
mov src3, edx; mov src3, edx;
emms; emms;
}
#endif
src0+=2;
src1+=2;
src2+=2;
src3+=2;
} }
#endif
src0+=2;
src1+=2;
src2+=2;
src3+=2;
}
/* Swap buffers around */ /* Swap buffers around */
u8 *temp = frm1; u8 *temp = frm1;
@ -180,16 +179,14 @@ static void SmartIB_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
void SmartIB(u8 *srcPtr, u32 srcPitch, int width, int height) void SmartIB(u8 *srcPtr, u32 srcPitch, int width, int height)
{ {
if(frm1 == NULL) if(frm1 == NULL) {
{ Init();
Init(); }
}
#ifdef MMX #ifdef MMX
if(cpu_mmx) if(cpu_mmx) {
{ SmartIB_MMX(srcPtr, srcPitch, width, height);
SmartIB_MMX(srcPtr, srcPitch, width, height); return;
return; }
}
#endif #endif
u16 colorMask = ~RGB_LOW_BITS_MASK; u16 colorMask = ~RGB_LOW_BITS_MASK;
@ -203,18 +200,17 @@ void SmartIB(u8 *srcPtr, u32 srcPitch, int width, int height)
int pos = 0; int pos = 0;
for (int j = 0; j < height; j++) for (int j = 0; j < height; j++)
for (int i = 0; i < sPitch; i++) for (int i = 0; i < sPitch; i++) {
{ u16 color = src0[pos];
u16 color = src0[pos]; src0[pos] =
src0[pos] = (src1[pos] != src2[pos]) &&
(src1[pos] != src2[pos]) && (src3[pos] != color) &&
(src3[pos] != color) && ((color == src2[pos]) || (src1[pos] == src3[pos]))
((color == src2[pos]) || (src1[pos] == src3[pos])) ? (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)) :
? (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)) : color;
color; src3[pos] = color; /* oldest buffer now holds newest frame */
src3[pos] = color; /* oldest buffer now holds newest frame */ pos++;
pos++; }
}
/* Swap buffers around */ /* Swap buffers around */
u8 *temp = frm1; u8 *temp = frm1;
@ -233,108 +229,107 @@ static void SmartIB32_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
int count = width >> 1; int count = width >> 1;
for(int i = 0; i < height; i++) for(int i = 0; i < height; i++) {
{
#ifdef __GNUC__ #ifdef __GNUC__
asm volatile ( asm volatile (
"push %4\n" "push %4\n"
"movq 0(%5), %%mm7\n" // colorMask "movq 0(%5), %%mm7\n" // colorMask
"0:\n" "0:\n"
"movq 0(%0), %%mm0\n" // src0 "movq 0(%0), %%mm0\n" // src0
"movq 0(%1), %%mm1\n" // src1 "movq 0(%1), %%mm1\n" // src1
"movq 0(%2), %%mm2\n" // src2 "movq 0(%2), %%mm2\n" // src2
"movq 0(%3), %%mm3\n" // src3 "movq 0(%3), %%mm3\n" // src3
"movq %%mm0, 0(%3)\n" // src3 = src0 "movq %%mm0, 0(%3)\n" // src3 = src0
"movq %%mm0, %%mm4\n" "movq %%mm0, %%mm4\n"
"movq %%mm1, %%mm5\n" "movq %%mm1, %%mm5\n"
"pcmpeqd %%mm2, %%mm5\n" // src1 == src2 (A) "pcmpeqd %%mm2, %%mm5\n" // src1 == src2 (A)
"pcmpeqd %%mm3, %%mm4\n" // src3 == src0 (B) "pcmpeqd %%mm3, %%mm4\n" // src3 == src0 (B)
"por %%mm5, %%mm4\n" // A | B "por %%mm5, %%mm4\n" // A | B
"movq %%mm2, %%mm5\n" "movq %%mm2, %%mm5\n"
"pcmpeqd %%mm0, %%mm5\n" // src0 == src2 (C) "pcmpeqd %%mm0, %%mm5\n" // src0 == src2 (C)
"pcmpeqd %%mm1, %%mm3\n" // src1 == src3 (D) "pcmpeqd %%mm1, %%mm3\n" // src1 == src3 (D)
"por %%mm3, %%mm5\n" // C|D "por %%mm3, %%mm5\n" // C|D
"pandn %%mm5, %%mm4\n" // (!(A|B))&(C|D) "pandn %%mm5, %%mm4\n" // (!(A|B))&(C|D)
"movq %%mm0, %%mm2\n" "movq %%mm0, %%mm2\n"
"pand %%mm7, %%mm2\n" // color & colorMask "pand %%mm7, %%mm2\n" // color & colorMask
"pand %%mm7, %%mm1\n" // src1 & colorMask "pand %%mm7, %%mm1\n" // src1 & colorMask
"psrld $1, %%mm2\n" // (color & colorMask) >> 1 (E) "psrld $1, %%mm2\n" // (color & colorMask) >> 1 (E)
"psrld $1, %%mm1\n" // (src & colorMask) >> 1 (F) "psrld $1, %%mm1\n" // (src & colorMask) >> 1 (F)
"paddd %%mm2, %%mm1\n" // E+F "paddd %%mm2, %%mm1\n" // E+F
"pand %%mm4, %%mm1\n" // (E+F) & res "pand %%mm4, %%mm1\n" // (E+F) & res
"pandn %%mm0, %%mm4\n" // color& !res "pandn %%mm0, %%mm4\n" // color& !res
"por %%mm1, %%mm4\n" "por %%mm1, %%mm4\n"
"movq %%mm4, 0(%0)\n" // src0 = res "movq %%mm4, 0(%0)\n" // src0 = res
"addl $8, %0\n" "addl $8, %0\n"
"addl $8, %1\n" "addl $8, %1\n"
"addl $8, %2\n" "addl $8, %2\n"
"addl $8, %3\n" "addl $8, %3\n"
"decl %4\n" "decl %4\n"
"jnz 0b\n" "jnz 0b\n"
"pop %4\n" "pop %4\n"
"emms\n" "emms\n"
: "+r" (src0), "+r" (src1), "+r" (src2), "+r" (src3) : "+r" (src0), "+r" (src1), "+r" (src2), "+r" (src3)
: "r" (count), "r" (qRGB_COLOR_MASK) : "r" (count), "r" (qRGB_COLOR_MASK)
); );
#else #else
__asm { __asm {
movq mm7, qword ptr [qRGB_COLOR_MASK]; movq mm7, qword ptr [qRGB_COLOR_MASK];
mov eax, src0; mov eax, src0;
mov ebx, src1; mov ebx, src1;
mov ecx, src2; mov ecx, src2;
mov edx, src3; mov edx, src3;
mov edi, count; mov edi, count;
label0: label0:
movq mm0, qword ptr [eax]; // src0 movq mm0, qword ptr [eax]; // src0
movq mm1, qword ptr [ebx]; // src1 movq mm1, qword ptr [ebx]; // src1
movq mm2, qword ptr [ecx]; // src2 movq mm2, qword ptr [ecx]; // src2
movq mm3, qword ptr [edx]; // src3 movq mm3, qword ptr [edx]; // src3
movq qword ptr [edx], mm0; // src3 = src0 movq qword ptr [edx], mm0; // src3 = src0
movq mm4, mm0; movq mm4, mm0;
movq mm5, mm1; movq mm5, mm1;
pcmpeqd mm5, mm2; // src1 == src2 (A) pcmpeqd mm5, mm2; // src1 == src2 (A)
pcmpeqd mm4, mm3; // src3 == src0 (B) pcmpeqd mm4, mm3; // src3 == src0 (B)
por mm4, mm5; // A | B por mm4, mm5; // A | B
movq mm5, mm2; movq mm5, mm2;
pcmpeqd mm5, mm0; // src0 == src2 (C) pcmpeqd mm5, mm0; // src0 == src2 (C)
pcmpeqd mm3, mm1; // src1 == src3 (D) pcmpeqd mm3, mm1; // src1 == src3 (D)
por mm5, mm3; // C|D por mm5, mm3; // C|D
pandn mm4, mm5; // (!(A|B))&(C|D) pandn mm4, mm5; // (!(A|B))&(C|D)
movq mm2, mm0; movq mm2, mm0;
pand mm2, mm7; // color & colorMask pand mm2, mm7; // color & colorMask
pand mm1, mm7; // src1 & colorMask pand mm1, mm7; // src1 & colorMask
psrld mm2, 1; // (color & colorMask) >> 1 (E) psrld mm2, 1; // (color & colorMask) >> 1 (E)
psrld mm1, 1; // (src & colorMask) >> 1 (F) psrld mm1, 1; // (src & colorMask) >> 1 (F)
paddd mm1, mm2; // E+F paddd mm1, mm2; // E+F
pand mm1, mm4; // (E+F) & res pand mm1, mm4; // (E+F) & res
pandn mm4, mm0; // color & !res pandn mm4, mm0; // color & !res
por mm4, mm1; por mm4, mm1;
movq qword ptr [eax], mm4; // src0 = res movq qword ptr [eax], mm4; // src0 = res
add eax, 8; add eax, 8;
add ebx, 8; add ebx, 8;
add ecx, 8; add ecx, 8;
add edx, 8; add edx, 8;
dec edi; dec edi;
jnz label0; jnz label0;
mov src0, eax; mov src0, eax;
mov src1, ebx; mov src1, ebx;
mov src2, ecx; mov src2, ecx;
mov src3, edx; mov src3, edx;
emms; emms;
} }
#endif #endif
src0++; src0++;
src1++; src1++;
src2++; src2++;
src3++; src3++;
} }
/* Swap buffers around */ /* Swap buffers around */
u8 *temp = frm1; u8 *temp = frm1;
frm1 = frm3; frm1 = frm3;
@ -345,16 +340,14 @@ static void SmartIB32_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
void SmartIB32(u8 *srcPtr, u32 srcPitch, int width, int height) void SmartIB32(u8 *srcPtr, u32 srcPitch, int width, int height)
{ {
if(frm1 == NULL) if(frm1 == NULL) {
{ Init();
Init(); }
}
#ifdef MMX #ifdef MMX
if(cpu_mmx) if(cpu_mmx) {
{ SmartIB32_MMX(srcPtr, srcPitch, width, height);
SmartIB32_MMX(srcPtr, srcPitch, width, height); return;
return; }
}
#endif #endif
u32 *src0 = (u32 *)srcPtr; u32 *src0 = (u32 *)srcPtr;
@ -368,18 +361,17 @@ void SmartIB32(u8 *srcPtr, u32 srcPitch, int width, int height)
int pos = 0; int pos = 0;
for (int j = 0; j < height; j++) for (int j = 0; j < height; j++)
for (int i = 0; i < sPitch; i++) for (int i = 0; i < sPitch; i++) {
{ u32 color = src0[pos];
u32 color = src0[pos]; src0[pos] =
src0[pos] = (src1[pos] != src2[pos]) &&
(src1[pos] != src2[pos]) && (src3[pos] != color) &&
(src3[pos] != color) && ((color == src2[pos]) || (src1[pos] == src3[pos]))
((color == src2[pos]) || (src1[pos] == src3[pos])) ? (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)) :
? (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)) : color;
color; src3[pos] = color; /* oldest buffer now holds newest frame */
src3[pos] = color; /* oldest buffer now holds newest frame */ pos++;
pos++; }
}
/* Swap buffers around */ /* Swap buffers around */
u8 *temp = frm1; u8 *temp = frm1;
@ -396,81 +388,78 @@ static void MotionBlurIB_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
int count = width >> 2; int count = width >> 2;
for(int i = 0; i < height; i++) for(int i = 0; i < height; i++) {
{
#ifdef __GNUC__ #ifdef __GNUC__
asm volatile ( asm volatile (
"push %2\n" "push %2\n"
"movq 0(%3), %%mm7\n" // colorMask "movq 0(%3), %%mm7\n" // colorMask
"0:\n" "0:\n"
"movq 0(%0), %%mm0\n" // src0 "movq 0(%0), %%mm0\n" // src0
"movq 0(%1), %%mm1\n" // src1 "movq 0(%1), %%mm1\n" // src1
"movq %%mm0, 0(%1)\n" // src1 = src0 "movq %%mm0, 0(%1)\n" // src1 = src0
"pand %%mm7, %%mm0\n" // color & colorMask "pand %%mm7, %%mm0\n" // color & colorMask
"pand %%mm7, %%mm1\n" // src1 & colorMask "pand %%mm7, %%mm1\n" // src1 & colorMask
"psrlw $1, %%mm0\n" // (color & colorMask) >> 1 (E) "psrlw $1, %%mm0\n" // (color & colorMask) >> 1 (E)
"psrlw $1, %%mm1\n" // (src & colorMask) >> 1 (F) "psrlw $1, %%mm1\n" // (src & colorMask) >> 1 (F)
"paddw %%mm1, %%mm0\n" // E+F "paddw %%mm1, %%mm0\n" // E+F
"movq %%mm0, 0(%0)\n" // src0 = res "movq %%mm0, 0(%0)\n" // src0 = res
"addl $8, %0\n" "addl $8, %0\n"
"addl $8, %1\n" "addl $8, %1\n"
"decl %2\n" "decl %2\n"
"jnz 0b\n" "jnz 0b\n"
"pop %2\n" "pop %2\n"
"emms\n" "emms\n"
: "+r" (src0), "+r" (src1) : "+r" (src0), "+r" (src1)
: "r" (count), "r" (qRGB_COLOR_MASK) : "r" (count), "r" (qRGB_COLOR_MASK)
); );
#else #else
__asm { __asm {
movq mm7, qword ptr [qRGB_COLOR_MASK]; movq mm7, qword ptr [qRGB_COLOR_MASK];
mov eax, src0; mov eax, src0;
mov ebx, src1; mov ebx, src1;
mov edi, count; mov edi, count;
label0: label0:
movq mm0, qword ptr [eax]; // src0 movq mm0, qword ptr [eax]; // src0
movq mm1, qword ptr [ebx]; // src1 movq mm1, qword ptr [ebx]; // src1
movq qword ptr [ebx], mm0; // src1 = src0 movq qword ptr [ebx], mm0; // src1 = src0
pand mm0, mm7; // color & colorMask pand mm0, mm7; // color & colorMask
pand mm1, mm7; // src1 & colorMask pand mm1, mm7; // src1 & colorMask
psrlw mm0, 1; // (color & colorMask) >> 1 (E) psrlw mm0, 1; // (color & colorMask) >> 1 (E)
psrlw mm1, 1; // (src & colorMask) >> 1 (F) psrlw mm1, 1; // (src & colorMask) >> 1 (F)
paddw mm0, mm1; // E+F paddw mm0, mm1; // E+F
movq qword ptr [eax], mm0; // src0 = res movq qword ptr [eax], mm0; // src0 = res
add eax, 8; add eax, 8;
add ebx, 8; add ebx, 8;
dec edi; dec edi;
jnz label0; jnz label0;
mov src0, eax; mov src0, eax;
mov src1, ebx; mov src1, ebx;
emms; emms;
}
#endif
src0+=2;
src1+=2;
} }
#endif
src0+=2;
src1+=2;
}
} }
#endif #endif
void MotionBlurIB(u8 *srcPtr, u32 srcPitch, int width, int height) void MotionBlurIB(u8 *srcPtr, u32 srcPitch, int width, int height)
{ {
if(frm1 == NULL) if(frm1 == NULL) {
{ Init();
Init(); }
}
#ifdef MMX #ifdef MMX
if(cpu_mmx) if(cpu_mmx) {
{ MotionBlurIB_MMX(srcPtr, srcPitch, width, height);
MotionBlurIB_MMX(srcPtr, srcPitch, width, height); return;
return; }
}
#endif #endif
u16 colorMask = ~RGB_LOW_BITS_MASK; u16 colorMask = ~RGB_LOW_BITS_MASK;
@ -482,14 +471,13 @@ void MotionBlurIB(u8 *srcPtr, u32 srcPitch, int width, int height)
int pos = 0; int pos = 0;
for (int j = 0; j < height; j++) for (int j = 0; j < height; j++)
for (int i = 0; i < sPitch; i++) for (int i = 0; i < sPitch; i++) {
{ u16 color = src0[pos];
u16 color = src0[pos]; src0[pos] =
src0[pos] = (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1));
(((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1)); src1[pos] = color;
src1[pos] = color; pos++;
pos++; }
}
} }
#ifdef MMX #ifdef MMX
@ -500,81 +488,78 @@ static void MotionBlurIB32_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
int count = width >> 1; int count = width >> 1;
for(int i = 0; i < height; i++) for(int i = 0; i < height; i++) {
{
#ifdef __GNUC__ #ifdef __GNUC__
asm volatile ( asm volatile (
"push %2\n" "push %2\n"
"movq 0(%3), %%mm7\n" // colorMask "movq 0(%3), %%mm7\n" // colorMask
"0:\n" "0:\n"
"movq 0(%0), %%mm0\n" // src0 "movq 0(%0), %%mm0\n" // src0
"movq 0(%1), %%mm1\n" // src1 "movq 0(%1), %%mm1\n" // src1
"movq %%mm0, 0(%1)\n" // src1 = src0 "movq %%mm0, 0(%1)\n" // src1 = src0
"pand %%mm7, %%mm0\n" // color & colorMask "pand %%mm7, %%mm0\n" // color & colorMask
"pand %%mm7, %%mm1\n" // src1 & colorMask "pand %%mm7, %%mm1\n" // src1 & colorMask
"psrld $1, %%mm0\n" // (color & colorMask) >> 1 (E) "psrld $1, %%mm0\n" // (color & colorMask) >> 1 (E)
"psrld $1, %%mm1\n" // (src & colorMask) >> 1 (F) "psrld $1, %%mm1\n" // (src & colorMask) >> 1 (F)
"paddd %%mm1, %%mm0\n" // E+F "paddd %%mm1, %%mm0\n" // E+F
"movq %%mm0, 0(%0)\n" // src0 = res "movq %%mm0, 0(%0)\n" // src0 = res
"addl $8, %0\n" "addl $8, %0\n"
"addl $8, %1\n" "addl $8, %1\n"
"decl %2\n" "decl %2\n"
"jnz 0b\n" "jnz 0b\n"
"pop %2\n" "pop %2\n"
"emms\n" "emms\n"
: "+r" (src0), "+r" (src1) : "+r" (src0), "+r" (src1)
: "r" (count), "r" (qRGB_COLOR_MASK) : "r" (count), "r" (qRGB_COLOR_MASK)
); );
#else #else
__asm { __asm {
movq mm7, qword ptr [qRGB_COLOR_MASK]; movq mm7, qword ptr [qRGB_COLOR_MASK];
mov eax, src0; mov eax, src0;
mov ebx, src1; mov ebx, src1;
mov edi, count; mov edi, count;
label0: label0:
movq mm0, qword ptr [eax]; // src0 movq mm0, qword ptr [eax]; // src0
movq mm1, qword ptr [ebx]; // src1 movq mm1, qword ptr [ebx]; // src1
movq qword ptr [ebx], mm0; // src1 = src0 movq qword ptr [ebx], mm0; // src1 = src0
pand mm0, mm7; // color & colorMask pand mm0, mm7; // color & colorMask
pand mm1, mm7; // src1 & colorMask pand mm1, mm7; // src1 & colorMask
psrld mm0, 1; // (color & colorMask) >> 1 (E) psrld mm0, 1; // (color & colorMask) >> 1 (E)
psrld mm1, 1; // (src & colorMask) >> 1 (F) psrld mm1, 1; // (src & colorMask) >> 1 (F)
paddd mm0, mm1; // E+F paddd mm0, mm1; // E+F
movq qword ptr [eax], mm0; // src0 = res movq qword ptr [eax], mm0; // src0 = res
add eax, 8; add eax, 8;
add ebx, 8; add ebx, 8;
dec edi; dec edi;
jnz label0; jnz label0;
mov src0, eax; mov src0, eax;
mov src1, ebx; mov src1, ebx;
emms; emms;
}
#endif
src0++;
src1++;
} }
#endif
src0++;
src1++;
}
} }
#endif #endif
void MotionBlurIB32(u8 *srcPtr, u32 srcPitch, int width, int height) void MotionBlurIB32(u8 *srcPtr, u32 srcPitch, int width, int height)
{ {
if(frm1 == NULL) if(frm1 == NULL) {
{ Init();
Init(); }
}
#ifdef MMX #ifdef MMX
if(cpu_mmx) if(cpu_mmx) {
{ MotionBlurIB32_MMX(srcPtr, srcPitch, width, height);
MotionBlurIB32_MMX(srcPtr, srcPitch, width, height); return;
return; }
}
#endif #endif
u32 *src0 = (u32 *)srcPtr; u32 *src0 = (u32 *)srcPtr;
@ -586,58 +571,11 @@ void MotionBlurIB32(u8 *srcPtr, u32 srcPitch, int width, int height)
int pos = 0; int pos = 0;
for (int j = 0; j < height; j++) for (int j = 0; j < height; j++)
for (int i = 0; i < sPitch; i++) for (int i = 0; i < sPitch; i++) {
{ u32 color = src0[pos];
u32 color = src0[pos]; src0[pos] = (((color & colorMask) >> 1) +
src0[pos] = (((color & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1));
((src1[pos] & colorMask) >> 1)); src1[pos] = color;
src1[pos] = color; pos++;
pos++;
}
}
static int count = 0;
void InterlaceIB(u8 *srcPtr, u32 srcPitch, int width, int height)
{
if(frm1 == NULL)
{
Init();
} }
u16 colorMask = ~RGB_LOW_BITS_MASK;
u16 *src0 = (u16 *)srcPtr;
u16 *src1 = (u16 *)frm1;
int sPitch = srcPitch >> 1;
int pos = 0;
for (int j = 0; j < height; j++)
{
bool render = count ? (j & 1) != 0 : (j & 1) == 0;
if(render)
{
for (int i = 0; i < sPitch; i++)
{
u16 color = src0[pos];
src0[pos] =
(((color & colorMask) >> 1) + ((((src1[pos] & colorMask) >> 1) & colorMask) >> 1));
src1[pos] = color;
pos++;
}
}
else
{
for (int i = 0; i < sPitch; i++)
{
u16 color = src0[pos];
src0[pos] =
(((((color & colorMask) >> 1) & colorMask) >> 1) + ((src1[pos] & colorMask) >> 1));
src1[pos] = color;
pos++;
}
}
}
count = count ^ 1;
} }

View File

@ -31,6 +31,14 @@
#ifndef __INTERP_H #ifndef __INTERP_H
#define __INTERP_H #define __INTERP_H
#define __STDC_CONSTANT_MACROS
#include <stdint.h>
typedef uint16_t interp_uint16;
typedef uint32_t interp_uint32;
/***************************************************************************/ /***************************************************************************/
/* Basic types */ /* Basic types */
@ -46,79 +54,79 @@ static unsigned interp_bits_per_pixel;
static inline u16 interp_16_521(u16 p1, u16 p2, u16 p3) static inline u16 interp_16_521(u16 p1, u16 p2, u16 p3)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*2 + INTERP_16_MASK_1(p3)*1) / 8) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*2 + INTERP_16_MASK_1(p3)*1) / 8)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*2 + INTERP_16_MASK_2(p3)*1) / 8); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*2 + INTERP_16_MASK_2(p3)*1) / 8);
} }
static inline u16 interp_16_332(u16 p1, u16 p2, u16 p3) static inline u16 interp_16_332(u16 p1, u16 p2, u16 p3)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)*2) / 8) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)*2) / 8)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)*2) / 8); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)*2) / 8);
} }
static inline u16 interp_16_611(u16 p1, u16 p2, u16 p3) static inline u16 interp_16_611(u16 p1, u16 p2, u16 p3)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*6 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 8) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*6 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 8)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*6 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 8); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*6 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 8);
} }
static inline u16 interp_16_71(u16 p1, u16 p2) static inline u16 interp_16_71(u16 p1, u16 p2)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*7 + INTERP_16_MASK_1(p2)) / 8) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*7 + INTERP_16_MASK_1(p2)) / 8)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*7 + INTERP_16_MASK_2(p2)) / 8); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*7 + INTERP_16_MASK_2(p2)) / 8);
} }
static inline u16 interp_16_211(u16 p1, u16 p2, u16 p3) static inline u16 interp_16_211(u16 p1, u16 p2, u16 p3)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*2 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 4) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*2 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 4)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*2 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 4); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*2 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 4);
} }
static inline u16 interp_16_772(u16 p1, u16 p2, u16 p3) static inline u16 interp_16_772(u16 p1, u16 p2, u16 p3)
{ {
return INTERP_16_MASK_1(((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2))*7 + INTERP_16_MASK_1(p3)*2) / 16) return INTERP_16_MASK_1(((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2))*7 + INTERP_16_MASK_1(p3)*2) / 16)
| INTERP_16_MASK_2(((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2))*7 + INTERP_16_MASK_2(p3)*2) / 16); | INTERP_16_MASK_2(((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2))*7 + INTERP_16_MASK_2(p3)*2) / 16);
} }
static inline u16 interp_16_11(u16 p1, u16 p2) static inline u16 interp_16_11(u16 p1, u16 p2)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2)) / 2) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1) + INTERP_16_MASK_1(p2)) / 2)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2)) / 2); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1) + INTERP_16_MASK_2(p2)) / 2);
} }
static inline u16 interp_16_31(u16 p1, u16 p2) static inline u16 interp_16_31(u16 p1, u16 p2)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)) / 4) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*3 + INTERP_16_MASK_1(p2)) / 4)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)) / 4); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*3 + INTERP_16_MASK_2(p2)) / 4);
} }
static inline u16 interp_16_1411(u16 p1, u16 p2, u16 p3) static inline u16 interp_16_1411(u16 p1, u16 p2, u16 p3)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*14 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 16) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*14 + INTERP_16_MASK_1(p2) + INTERP_16_MASK_1(p3)) / 16)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*14 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 16); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*14 + INTERP_16_MASK_2(p2) + INTERP_16_MASK_2(p3)) / 16);
} }
static inline u16 interp_16_431(u16 p1, u16 p2, u16 p3) static inline u16 interp_16_431(u16 p1, u16 p2, u16 p3)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*4 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)) / 8) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*4 + INTERP_16_MASK_1(p2)*3 + INTERP_16_MASK_1(p3)) / 8)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*4 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)) / 8); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*4 + INTERP_16_MASK_2(p2)*3 + INTERP_16_MASK_2(p3)) / 8);
} }
static inline u16 interp_16_53(u16 p1, u16 p2) static inline u16 interp_16_53(u16 p1, u16 p2)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*3) / 8) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*5 + INTERP_16_MASK_1(p2)*3) / 8)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*3) / 8); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*5 + INTERP_16_MASK_2(p2)*3) / 8);
} }
static inline u16 interp_16_151(u16 p1, u16 p2) static inline u16 interp_16_151(u16 p1, u16 p2)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*15 + INTERP_16_MASK_1(p2)) / 16) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*15 + INTERP_16_MASK_1(p2)) / 16)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*15 + INTERP_16_MASK_2(p2)) / 16); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*15 + INTERP_16_MASK_2(p2)) / 16);
} }
static inline u16 interp_16_97(u16 p1, u16 p2) static inline u16 interp_16_97(u16 p1, u16 p2)
{ {
return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*9 + INTERP_16_MASK_1(p2)*7) / 16) return INTERP_16_MASK_1((INTERP_16_MASK_1(p1)*9 + INTERP_16_MASK_1(p2)*7) / 16)
| INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*9 + INTERP_16_MASK_2(p2)*7) / 16); | INTERP_16_MASK_2((INTERP_16_MASK_2(p1)*9 + INTERP_16_MASK_2(p2)*7) / 16);
} }
#define INTERP_32_MASK_1(v) (v & 0xFF00FF) #define INTERP_32_MASK_1(v) (v & 0xFF00FF)
@ -127,79 +135,79 @@ static inline u16 interp_16_97(u16 p1, u16 p2)
static inline u32 interp_32_521(u32 p1, u32 p2, u32 p3) static inline u32 interp_32_521(u32 p1, u32 p2, u32 p3)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*2 + INTERP_32_MASK_1(p3)*1) / 8) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*2 + INTERP_32_MASK_1(p3)*1) / 8)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*2 + INTERP_32_MASK_2(p3)*1) / 8); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*2 + INTERP_32_MASK_2(p3)*1) / 8);
} }
static inline u32 interp_32_332(u32 p1, u32 p2, u32 p3) static inline u32 interp_32_332(u32 p1, u32 p2, u32 p3)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)*2) / 8) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)*2) / 8)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)*2) / 8); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)*2) / 8);
} }
static inline u32 interp_32_211(u32 p1, u32 p2, u32 p3) static inline u32 interp_32_211(u32 p1, u32 p2, u32 p3)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*2 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 4) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*2 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 4)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*2 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 4); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*2 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 4);
} }
static inline u32 interp_32_611(u32 p1, u32 p2, u32 p3) static inline u32 interp_32_611(u32 p1, u32 p2, u32 p3)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*6 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 8) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*6 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 8)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*6 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 8); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*6 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 8);
} }
static inline u32 interp_32_71(u32 p1, u32 p2) static inline u32 interp_32_71(u32 p1, u32 p2)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*7 + INTERP_32_MASK_1(p2)) / 8) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*7 + INTERP_32_MASK_1(p2)) / 8)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*7 + INTERP_32_MASK_2(p2)) / 8); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*7 + INTERP_32_MASK_2(p2)) / 8);
} }
static inline u32 interp_32_772(u32 p1, u32 p2, u32 p3) static inline u32 interp_32_772(u32 p1, u32 p2, u32 p3)
{ {
return INTERP_32_MASK_1(((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2))*7 + INTERP_32_MASK_1(p3)*2) / 16) return INTERP_32_MASK_1(((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2))*7 + INTERP_32_MASK_1(p3)*2) / 16)
| INTERP_32_MASK_2(((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2))*7 + INTERP_32_MASK_2(p3)*2) / 16); | INTERP_32_MASK_2(((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2))*7 + INTERP_32_MASK_2(p3)*2) / 16);
} }
static inline u32 interp_32_11(u32 p1, u32 p2) static inline u32 interp_32_11(u32 p1, u32 p2)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2)) / 2) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1) + INTERP_32_MASK_1(p2)) / 2)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2)) / 2); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1) + INTERP_32_MASK_2(p2)) / 2);
} }
static inline u32 interp_32_31(u32 p1, u32 p2) static inline u32 interp_32_31(u32 p1, u32 p2)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)) / 4) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*3 + INTERP_32_MASK_1(p2)) / 4)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)) / 4); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*3 + INTERP_32_MASK_2(p2)) / 4);
} }
static inline u32 interp_32_1411(u32 p1, u32 p2, u32 p3) static inline u32 interp_32_1411(u32 p1, u32 p2, u32 p3)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*14 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 16) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*14 + INTERP_32_MASK_1(p2) + INTERP_32_MASK_1(p3)) / 16)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*14 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 16); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*14 + INTERP_32_MASK_2(p2) + INTERP_32_MASK_2(p3)) / 16);
} }
static inline u32 interp_32_431(u32 p1, u32 p2, u32 p3) static inline u32 interp_32_431(u32 p1, u32 p2, u32 p3)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*4 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)) / 8) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*4 + INTERP_32_MASK_1(p2)*3 + INTERP_32_MASK_1(p3)) / 8)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*4 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)) / 8); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*4 + INTERP_32_MASK_2(p2)*3 + INTERP_32_MASK_2(p3)) / 8);
} }
static inline u32 interp_32_53(u32 p1, u32 p2) static inline u32 interp_32_53(u32 p1, u32 p2)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*3) / 8) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*5 + INTERP_32_MASK_1(p2)*3) / 8)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*3) / 8); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*5 + INTERP_32_MASK_2(p2)*3) / 8);
} }
static inline u32 interp_32_151(u32 p1, u32 p2) static inline u32 interp_32_151(u32 p1, u32 p2)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*15 + INTERP_32_MASK_1(p2)) / 16) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*15 + INTERP_32_MASK_1(p2)) / 16)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*15 + INTERP_32_MASK_2(p2)) / 16); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*15 + INTERP_32_MASK_2(p2)) / 16);
} }
static inline u32 interp_32_97(u32 p1, u32 p2) static inline u32 interp_32_97(u32 p1, u32 p2)
{ {
return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*9 + INTERP_32_MASK_1(p2)*7) / 16) return INTERP_32_MASK_1((INTERP_32_MASK_1(p1)*9 + INTERP_32_MASK_1(p2)*7) / 16)
| INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*9 + INTERP_32_MASK_2(p2)*7) / 16); | INTERP_32_MASK_2((INTERP_32_MASK_2(p1)*9 + INTERP_32_MASK_2(p2)*7) / 16);
} }
/***************************************************************************/ /***************************************************************************/
@ -217,18 +225,15 @@ static int interp_16_diff(u16 p1, u16 p2)
if (p1 == p2) if (p1 == p2)
return 0; return 0;
if (interp_bits_per_pixel == 16) if (interp_bits_per_pixel == 16) {
{ b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3;
b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3; g = (int)((p1 & 0x7E0) - (p2 & 0x7E0)) >> 3;
g = (int)((p1 & 0x7E0) - (p2 & 0x7E0)) >> 3; r = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8;
r = (int)((p1 & 0xF800) - (p2 & 0xF800)) >> 8; } else {
} b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3;
else g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2;
{ r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7;
b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3; }
g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2;
r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7;
}
y = r + g + b; y = r + g + b;
u = r - b; u = r - b;
@ -278,21 +283,20 @@ static void interp_set(unsigned bits_per_pixel)
{ {
interp_bits_per_pixel = bits_per_pixel; interp_bits_per_pixel = bits_per_pixel;
switch (bits_per_pixel) switch (bits_per_pixel) {
{ case 15 :
case 15 : interp_mask[0] = 0x7C1F;
interp_mask[0] = 0x7C1F; interp_mask[1] = 0x03E0;
interp_mask[1] = 0x03E0; break;
break; case 16 :
case 16 : interp_mask[0] = 0xF81F;
interp_mask[0] = 0xF81F; interp_mask[1] = 0x07E0;
interp_mask[1] = 0x07E0; break;
break; case 32 :
case 32 : interp_mask[0] = 0xFF00FF;
interp_mask[0] = 0xFF00FF; interp_mask[1] = 0x00FF00;
interp_mask[1] = 0x00FF00; break;
break; }
}
} }
#endif #endif

View File

@ -21,82 +21,78 @@
extern int RGB_LOW_BITS_MASK; extern int RGB_LOW_BITS_MASK;
void Pixelate(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr, void Pixelate(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
u8 *dstPtr, u32 dstPitch, int width, int height) u8 *dstPtr, u32 dstPitch, int width, int height)
{ {
u8 *nextLine, *finish; u8 *nextLine, *finish;
u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16)); u32 colorMask = ~(RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 16));
nextLine = dstPtr + dstPitch; nextLine = dstPtr + dstPitch;
do do {
{ u32 *bP = (u32 *) srcPtr;
u32 *bP = (u32 *) srcPtr; u32 *xP = (u32 *) deltaPtr;
u32 *xP = (u32 *) deltaPtr; u32 *dP = (u32 *) dstPtr;
u32 *dP = (u32 *) dstPtr; u32 *nL = (u32 *) nextLine;
u32 *nL = (u32 *) nextLine; u32 currentPixel;
u32 currentPixel; u32 nextPixel;
u32 nextPixel; u32 currentDelta;
u32 currentDelta; u32 nextDelta;
u32 nextDelta;
finish = (u8 *) bP + ((width+2) << 1); finish = (u8 *) bP + ((width+2) << 1);
nextPixel = *bP++;
nextDelta = *xP++;
do {
currentPixel = nextPixel;
currentDelta = nextDelta;
nextPixel = *bP++; nextPixel = *bP++;
nextDelta = *xP++; nextDelta = *xP++;
do if ((nextPixel != nextDelta) || (currentPixel != currentDelta)) {
{ u32 colorA, colorB, product;
currentPixel = nextPixel;
currentDelta = nextDelta;
nextPixel = *bP++;
nextDelta = *xP++;
if ((nextPixel != nextDelta) || (currentPixel != currentDelta)) *(xP - 2) = currentPixel;
{
u32 colorA, colorB, product;
*(xP - 2) = currentPixel;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
colorA = currentPixel >> 16; colorA = currentPixel >> 16;
colorB = currentPixel & 0xffff; colorB = currentPixel & 0xffff;
#else #else
colorA = currentPixel & 0xffff; colorA = currentPixel & 0xffff;
colorB = currentPixel >> 16; colorB = currentPixel >> 16;
#endif #endif
product = (((colorA & colorMask) >> 1) & colorMask) >> 1; product = (((colorA & colorMask) >> 1) & colorMask) >> 1;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*(nL) = (product << 16) | (product); *(nL) = (product << 16) | (product);
*(dP) = (colorA << 16) | product; *(dP) = (colorA << 16) | product;
#else #else
*(nL) = product | (product << 16); *(nL) = product | (product << 16);
*(dP) = colorA | (product << 16); *(dP) = colorA | (product << 16);
#endif #endif
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
colorA = nextPixel >> 16; colorA = nextPixel >> 16;
#else #else
colorA = nextPixel & 0xffff; colorA = nextPixel & 0xffff;
#endif #endif
product = (((colorB & colorMask) >> 1) & colorMask) >> 1; product = (((colorB & colorMask) >> 1) & colorMask) >> 1;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
*(nL + 1) = (product << 16) | (product); *(nL + 1) = (product << 16) | (product);
*(dP + 1) = (colorB << 16) | (product); *(dP + 1) = (colorB << 16) | (product);
#else #else
*(nL + 1) = (product) | (product << 16); *(nL + 1) = (product) | (product << 16);
*(dP + 1) = (colorB) | (product << 16); *(dP + 1) = (colorB) | (product << 16);
#endif #endif
} }
dP += 2; dP += 2;
nL += 2; nL += 2;
} } while ((u8 *) bP < finish);
while ((u8 *) bP < finish);
deltaPtr += srcPitch; deltaPtr += srcPitch;
srcPtr += srcPitch; srcPtr += srcPitch;
dstPtr += dstPitch << 1; dstPtr += dstPitch << 1;
nextLine += dstPitch << 1; nextLine += dstPitch << 1;
} }
while (--height); while (--height);
} }
@ -108,50 +104,47 @@ void Pixelate32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
nextLine = dstPtr + dstPitch; nextLine = dstPtr + dstPitch;
do do {
{ u32 *bP = (u32 *) srcPtr;
u32 *bP = (u32 *) srcPtr; // u32 *xP = (u32 *) deltaPtr;
// u32 *xP = (u32 *) deltaPtr; u32 *dP = (u32 *) dstPtr;
u32 *dP = (u32 *) dstPtr; u32 *nL = (u32 *) nextLine;
u32 *nL = (u32 *) nextLine; u32 currentPixel;
u32 currentPixel; u32 nextPixel;
u32 nextPixel;
finish = (u8 *) bP + ((width+1) << 2); finish = (u8 *) bP + ((width+1) << 2);
nextPixel = *bP++;
do {
currentPixel = nextPixel;
nextPixel = *bP++; nextPixel = *bP++;
do u32 colorA, colorB, product;
{
currentPixel = nextPixel;
nextPixel = *bP++;
u32 colorA, colorB, product; colorA = currentPixel;
colorB = nextPixel;
colorA = currentPixel; product = (((colorA & colorMask) >> 1) & colorMask) >> 1;
colorB = nextPixel; *(nL) = product;
*(nL+1) = product;
*(dP) = colorA;
*(dP+1) = product;
product = (((colorA & colorMask) >> 1) & colorMask) >> 1; nextPixel = *bP++;
*(nL) = product; colorA = nextPixel;
*(nL+1) = product; product = (((colorB & colorMask) >> 1) & colorMask) >> 1;
*(dP) = colorA; *(nL + 2) = product;
*(dP+1) = product; *(nL + 3) = product;
*(dP + 2) = colorB;
*(dP + 3) = product;
nextPixel = *bP++; dP += 4;
colorA = nextPixel; nL += 4;
product = (((colorB & colorMask) >> 1) & colorMask) >> 1; } while ((u8 *) bP < finish);
*(nL + 2) = product;
*(nL + 3) = product;
*(dP + 2) = colorB;
*(dP + 3) = product;
dP += 4; srcPtr += srcPitch;
nL += 4; dstPtr += dstPitch << 1;
} nextLine += dstPitch << 1;
while ((u8 *) bP < finish); }
srcPtr += srcPitch;
dstPtr += dstPitch << 1;
nextLine += dstPitch << 1;
}
while (--height); while (--height);
} }

View File

@ -1,112 +0,0 @@
// VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
// Copyright (C) 1999-2003 Forgotten
// Copyright (C) 2004 Forgotten and the VBA development team
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or(at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "System.h"
void Simple2x(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u8 *dstPtr, u32 dstPitch, int width, int height)
{
u8 *nextLine, *finish;
nextLine = dstPtr + dstPitch;
do
{
u32 *bP = (u32 *) srcPtr;
u32 *dP = (u32 *) dstPtr;
u32 *nL = (u32 *) nextLine;
u32 currentPixel;
finish = (u8 *) bP + ((width+2) << 1);
currentPixel = *bP++;
do
{
#ifdef WORDS_BIGENDIAN
u32 color = currentPixel >> 16;
#else
u32 color = currentPixel & 0xffff;
#endif
color = color | (color << 16);
*(dP) = color;
*(nL) = color;
#ifdef WORDS_BIGENDIAN
color = currentPixel & 0xffff;
#else
color = currentPixel >> 16;
#endif
color = color| (color << 16);
*(dP + 1) = color;
*(nL + 1) = color;
currentPixel = *bP++;
dP += 2;
nL += 2;
}
while ((u8 *) bP < finish);
srcPtr += srcPitch;
dstPtr += dstPitch << 1;
nextLine += dstPitch << 1;
}
while (--height);
}
void Simple2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u8 *dstPtr, u32 dstPitch, int width, int height)
{
u8 *nextLine, *finish;
nextLine = dstPtr + dstPitch;
do
{
u32 *bP = (u32 *) srcPtr;
u32 *dP = (u32 *) dstPtr;
u32 *nL = (u32 *) nextLine;
u32 currentPixel;
finish = (u8 *) bP + ((width+1) << 2);
currentPixel = *bP++;
do
{
u32 color = currentPixel;
*(dP) = color;
*(dP+1) = color;
*(nL) = color;
*(nL + 1) = color;
currentPixel = *bP++;
dP += 2;
nL += 2;
}
while ((u8 *) bP < finish);
srcPtr += srcPitch;
dstPtr += dstPitch << 1;
nextLine += dstPitch << 1;
}
while (--height);
}

File diff suppressed because it is too large Load Diff