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

@ -110,8 +110,7 @@ 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);
} }
@ -122,8 +121,7 @@ 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);
@ -135,8 +133,7 @@ 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;
@ -158,8 +155,7 @@ 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;
@ -178,32 +174,26 @@ 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 a = cheatSearchSignedRead(data, j, size);
s32 b = cheatSearchSignedRead(saved,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+2);
CLEAR_BIT(bits, j+3); CLEAR_BIT(bits, j+3);
} }
@ -211,33 +201,26 @@ void cheatSearch(const CheatSearchData *cs, int compare, int size,
} }
} }
} }
} } 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 a = cheatSearchRead(data, j, size);
u32 b = cheatSearchRead(saved,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+2);
CLEAR_BIT(bits, j+3); CLEAR_BIT(bits, j+3);
} }
@ -259,31 +242,25 @@ 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 a = cheatSearchSignedRead(data, j, size);
s32 b = (s32)value; 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+2);
CLEAR_BIT(bits, j+3); CLEAR_BIT(bits, j+3);
} }
@ -291,31 +268,24 @@ void cheatSearchValue(const CheatSearchData *cs, int compare, int size,
} }
} }
} }
} } 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+2);
CLEAR_BIT(bits, j+3); CLEAR_BIT(bits, j+3);
} }
@ -335,14 +305,12 @@ 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++;
} }
@ -352,8 +320,7 @@ int cheatSearchGetCount(const CheatSearchData *cs, int size)
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,8 +22,7 @@
#include "System.h" #include "System.h"
struct CheatSearchBlock struct CheatSearchBlock {
{
int size; int size;
u32 offset; u32 offset;
u8 *bits; u8 *bits;
@ -31,8 +30,7 @@ struct CheatSearchBlock
u8 *saved; u8 *saved;
}; };
struct CheatSearchData struct CheatSearchData {
{
int count; int count;
CheatSearchBlock *blocks; CheatSearchBlock *blocks;
}; };

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,12 +20,12 @@
#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;
@ -33,7 +33,7 @@ struct CheatsData
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"
@ -42,6 +43,11 @@ variable_desc eepromSaveData[] = {
{ NULL, 0 } { NULL, 0 }
}; };
void eepromInit()
{
memset(eepromData, 255, sizeof(eepromData));
}
void eepromReset() void eepromReset()
{ {
eepromMode = EEPROM_IDLE; eepromMode = EEPROM_IDLE;
@ -62,23 +68,28 @@ 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 {
else
{
// prior to 0.7.1, only 4K EEPROM was supported // prior to 0.7.1, only 4K EEPROM was supported
eepromSize = 512; 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:
@ -86,8 +97,7 @@ int eepromRead(u32 /* address */)
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;
@ -118,8 +128,7 @@ 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;
@ -130,48 +139,36 @@ void eepromWrite(u32 /* address */, u8 value)
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(cpuDmaCount == 0x11 || cpuDmaCount == 0x51) {
{ if(eepromBits == 0x11) {
if(eepromBits == 0x11)
{
eepromInUse = true; eepromInUse = true;
eepromSize = 0x2000; eepromSize = 0x2000;
eepromAddress = ((eepromBuffer[0] & 0x3F) << 8) | eepromAddress = ((eepromBuffer[0] & 0x3F) << 8) |
((eepromBuffer[1] & 0xFF)); ((eepromBuffer[1] & 0xFF));
if(!(eepromBuffer[0] & 0x40)) if(!(eepromBuffer[0] & 0x40)) {
{
eepromBuffer[0] = bit; eepromBuffer[0] = bit;
eepromBits = 1; eepromBits = 1;
eepromByte = 0; eepromByte = 0;
eepromMode = EEPROM_WRITEDATA; eepromMode = EEPROM_WRITEDATA;
} } else {
else
{
eepromMode = EEPROM_READDATA; eepromMode = EEPROM_READDATA;
eepromByte = 0; eepromByte = 0;
eepromBits = 0; eepromBits = 0;
} }
} }
} } else {
else if(eepromBits == 9) {
{
if(eepromBits == 9)
{
eepromInUse = true; eepromInUse = true;
eepromAddress = (eepromBuffer[0] & 0x3F); eepromAddress = (eepromBuffer[0] & 0x3F);
if(!(eepromBuffer[0] & 0x40)) if(!(eepromBuffer[0] & 0x40)) {
{
eepromBuffer[0] = bit; eepromBuffer[0] = bit;
eepromBits = 1; eepromBits = 1;
eepromByte = 0; eepromByte = 0;
eepromMode = EEPROM_WRITEDATA; eepromMode = EEPROM_WRITEDATA;
} } else {
else
{
eepromMode = EEPROM_READDATA; eepromMode = EEPROM_READDATA;
eepromByte = 0; eepromByte = 0;
eepromBits = 0; eepromBits = 0;
@ -188,22 +185,17 @@ void eepromWrite(u32 /* address */, u8 value)
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(eepromBits == 0x40) if(eepromBits == 0x40) {
{
eepromInUse = true; eepromInUse = true;
// write data; // write data;
for(int i = 0; i < 8; i++) for(int i = 0; i < 8; i++) {
{
eepromData[(eepromAddress << 3) + i] = eepromBuffer[i]; eepromData[(eepromAddress << 3) + i] = eepromBuffer[i];
} }
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
} } else if(eepromBits == 0x41) {
else if(eepromBits == 0x41)
{
eepromMode = EEPROM_IDLE; eepromMode = EEPROM_IDLE;
eepromByte = 0; eepromByte = 0;
eepromBits = 0; eepromBits = 0;

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"
@ -67,6 +67,11 @@ static variable_desc flashSaveData3[] = {
{ NULL, 0 } { NULL, 0 }
}; };
void flashInit()
{
memset(flashSaveMemory, 0xff, sizeof(flashSaveMemory));
}
void flashReset() void flashReset()
{ {
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
@ -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 {
else
{
utilReadData(gzFile, flashSaveData3); 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);
flashSize = size; if(size == 0x10000) {
if(size == 0x10000)
{
flashDeviceID = 0x1b; flashDeviceID = 0x1b;
flashManufacturerID = 0x32; flashManufacturerID = 0x32;
} } else {
else
{
flashDeviceID = 0x13; //0x09; flashDeviceID = 0x13; //0x09;
flashManufacturerID = 0x62; //0xc2; 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;
} }
u8 flashRead(u32 address) u8 flashRead(u32 address)
@ -117,13 +132,11 @@ 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: case 0:
// manufacturer ID // manufacturer ID
return flashManufacturerID; return flashManufacturerID;
@ -143,13 +156,10 @@ u8 flashRead(u32 address)
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 {
else
{
saveType = 1; saveType = 1;
cpuSaveGameFunc = sramWrite; cpuSaveGameFunc = sramWrite;
} }
@ -157,13 +167,19 @@ void flashSaveDecide(u32 address, u8 byte)
(*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;
@ -175,97 +191,69 @@ void flashWrite(u32 address, u8 byte)
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
break; break;
case FLASH_CMD_2: case FLASH_CMD_2:
if(address == 0x5555) if(address == 0x5555) {
{ if(byte == 0x90) {
if(byte == 0x90)
{
flashState = FLASH_AUTOSELECT; flashState = FLASH_AUTOSELECT;
flashReadState = FLASH_AUTOSELECT; flashReadState = FLASH_AUTOSELECT;
} } else if(byte == 0x80) {
else if(byte == 0x80)
{
flashState = FLASH_CMD_3; flashState = FLASH_CMD_3;
} } else if(byte == 0xF0) {
else if(byte == 0xF0)
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} } else if(byte == 0xA0) {
else if(byte == 0xA0)
{
flashState = FLASH_PROGRAM; flashState = FLASH_PROGRAM;
} } else if(byte == 0xB0 && flashSize == 0x20000) {
else if(byte == 0xB0 && flashSize == 0x20000)
{
flashState = FLASH_SETBANK; flashState = FLASH_SETBANK;
} } else {
else
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} }
} } else {
else
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} }
break; break;
case FLASH_CMD_3: case FLASH_CMD_3:
if(address == 0x5555 && byte == 0xAA) if(address == 0x5555 && byte == 0xAA) {
{
flashState = FLASH_CMD_4; flashState = FLASH_CMD_4;
} } else {
else
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} }
break; break;
case FLASH_CMD_4: case FLASH_CMD_4:
if(address == 0x2AAA && byte == 0x55) if(address == 0x2AAA && byte == 0x55) {
{
flashState = FLASH_CMD_5; flashState = FLASH_CMD_5;
} } else {
else
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} }
break; break;
case FLASH_CMD_5: case FLASH_CMD_5:
if(byte == 0x30) if(byte == 0x30) {
{
// SECTOR ERASE // SECTOR ERASE
memset(&flashSaveMemory[(flashBank << 16) + (address & 0xF000)], memset(&flashSaveMemory[(flashBank << 16) + (address & 0xF000)],
0, 0,
0x1000); 0x1000);
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashReadState = FLASH_ERASE_COMPLETE; flashReadState = FLASH_ERASE_COMPLETE;
} } else if(byte == 0x10) {
else if(byte == 0x10)
{
// CHIP ERASE // CHIP ERASE
memset(flashSaveMemory, 0, flashSize); memset(flashSaveMemory, 0, flashSize);
systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED; systemSaveUpdateCounter = SYSTEM_SAVE_UPDATED;
flashReadState = FLASH_ERASE_COMPLETE; flashReadState = FLASH_ERASE_COMPLETE;
} } else {
else
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} }
break; break;
case FLASH_AUTOSELECT: case FLASH_AUTOSELECT:
if(byte == 0xF0) if(byte == 0xF0) {
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} } else if(address == 0x5555 && byte == 0xAA)
else if(address == 0x5555 && byte == 0xAA)
flashState = FLASH_CMD_1; flashState = FLASH_CMD_1;
else else {
{
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
} }
@ -277,8 +265,7 @@ void flashWrite(u32 address, u8 byte)
flashReadState = FLASH_READ_ARRAY; flashReadState = FLASH_READ_ARRAY;
break; break;
case FLASH_SETBANK: case FLASH_SETBANK:
if(address == 0) if(address == 0) {
{
flashBank = (byte & 1); flashBank = (byte & 1);
} }
flashState = FLASH_READ_ARRAY; flashState = FLASH_READ_ARRAY;

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;

View File

@ -16,40 +16,34 @@
// 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 mode0RenderLine() void mode0RenderLine()
{ {
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;
} }
return; 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) {
{
gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2); gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2);
} }
if(layerEnable & 0x0800) if(layerEnable & 0x0800) {
{
gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3); gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3);
} }
@ -57,67 +51,56 @@ void mode0RenderLine()
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)) if((u8)(line1[x]>>24) < (u8)(color >> 24)) {
{
color = line1[x]; color = line1[x];
top = 0x02; top = 0x02;
} }
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)) if((u8)(line3[x]>>24) < (u8)(color >> 24)) {
{
color = line3[x]; color = line3[x];
top = 0x08; top = 0x08;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if((top & 0x10) && (color & 0x00010000)) if((top & 0x10) && (color & 0x00010000)) {
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24)) if((u8)(line0[x]>>24) < (u8)(back >> 24)) {
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
if((u8)(line1[x]>>24) < (u8)(back >> 24)) if((u8)(line1[x]>>24) < (u8)(back >> 24)) {
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
if((u8)(line2[x]>>24) < (u8)(back >> 24)) if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
if((u8)(line3[x]>>24) < (u8)(back >> 24)) if((u8)(line3[x]>>24) < (u8)(back >> 24)) {
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
@ -126,10 +109,8 @@ void mode0RenderLine()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -150,32 +131,26 @@ void mode0RenderLineNoWindow()
{ {
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;
} }
return; 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) {
{
gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2); gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2);
} }
if(layerEnable & 0x0800) if(layerEnable & 0x0800) {
{
gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3); gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3);
} }
@ -185,93 +160,74 @@ void mode0RenderLineNoWindow()
int effect = (BLDMOD >> 6) & 3; int effect = (BLDMOD >> 6) & 3;
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(line1[x] < (color & 0xFF000000)) if(line1[x] < (color & 0xFF000000)) {
{
color = line1[x]; color = line1[x];
top = 0x02; top = 0x02;
} }
if(line2[x] < (color & 0xFF000000)) if(line2[x] < (color & 0xFF000000)) {
{
color = line2[x]; color = line2[x];
top = 0x04; top = 0x04;
} }
if(line3[x] < (color & 0xFF000000)) if(line3[x] < (color & 0xFF000000)) {
{
color = line3[x]; color = line3[x];
top = 0x08; top = 0x08;
} }
if(lineOBJ[x] < (color & 0xFF000000)) if(lineOBJ[x] < (color & 0xFF000000)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(!(color & 0x00010000)) if(!(color & 0x00010000)) {
{ switch(effect) {
switch(effect)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line0[x] < back) if(line0[x] < back) {
{ if(top != 0x01) {
if(top != 0x01)
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
} }
if(line1[x] < (back & 0xFF000000)) if(line1[x] < (back & 0xFF000000)) {
{ if(top != 0x02) {
if(top != 0x02)
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
} }
if(line2[x] < (back & 0xFF000000)) if(line2[x] < (back & 0xFF000000)) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if(line3[x] < (back & 0xFF000000)) if(line3[x] < (back & 0xFF000000)) {
{ if(top != 0x08) {
if(top != 0x08)
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
} }
if(lineOBJ[x] < (back & 0xFF000000)) if(lineOBJ[x] < (back & 0xFF000000)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -294,33 +250,27 @@ void mode0RenderLineNoWindow()
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break; break;
} }
} } else {
else
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line0[x] < back) if(line0[x] < back) {
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
if(line1[x] < (back & 0xFF000000)) if(line1[x] < (back & 0xFF000000)) {
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
if(line2[x] < (back & 0xFF000000)) if(line2[x] < (back & 0xFF000000)) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
if(line3[x] < (back & 0xFF000000)) if(line3[x] < (back & 0xFF000000)) {
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
@ -329,10 +279,8 @@ void mode0RenderLineNoWindow()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -353,10 +301,8 @@ void mode0RenderLineAll()
{ {
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;
} }
return; return;
@ -365,8 +311,7 @@ void mode0RenderLineAll()
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));
@ -375,8 +320,7 @@ void mode0RenderLineAll()
else else
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x4000) if(layerEnable & 0x4000) {
{
u8 v0 = WIN1V >> 8; u8 v0 = WIN1V >> 8;
u8 v1 = WIN1V & 255; u8 v1 = WIN1V & 255;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
@ -386,23 +330,19 @@ void mode0RenderLineAll()
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); 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)) {
{
gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2); gfxDrawTextScreen(BG2CNT, BG2HOFS, BG2VOFS, line2);
} }
if((layerEnable & 0x0800)) if((layerEnable & 0x0800)) {
{
gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3); gfxDrawTextScreen(BG3CNT, BG3HOFS, BG3VOFS, line3);
} }
@ -415,116 +355,132 @@ void mode0RenderLineAll()
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(inWindow1) {
{
if(gfxInWin1[x]) if(gfxInWin1[x])
mask = inWin1Mask; mask = inWin1Mask;
} }
if(inWindow0) if(inWindow0) {
{ if(gfxInWin0[x]) {
if(gfxInWin0[x])
{
mask = inWin0Mask; mask = inWin0Mask;
} }
} }
if((mask & 1) && (line0[x] < color)) if((mask & 1) && (line0[x] < color)) {
{
color = line0[x]; color = line0[x];
top = 0x01; top = 0x01;
} }
if((mask & 2) && ((u8)(line1[x]>>24) < (u8)(color >> 24))) if((mask & 2) && ((u8)(line1[x]>>24) < (u8)(color >> 24))) {
{
color = line1[x]; color = line1[x];
top = 0x02; top = 0x02;
} }
if((mask & 4) && ((u8)(line2[x]>>24) < (u8)(color >> 24))) if((mask & 4) && ((u8)(line2[x]>>24) < (u8)(color >> 24))) {
{
color = line2[x]; color = line2[x];
top = 0x04; top = 0x04;
} }
if((mask & 8) && ((u8)(line3[x]>>24) < (u8)(color >> 24))) if((mask & 8) && ((u8)(line3[x]>>24) < (u8)(color >> 24))) {
{
color = line3[x]; color = line3[x];
top = 0x08; top = 0x08;
} }
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))) if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >> 24))) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; 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((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 in the window // special FX on in the window
if(mask & 32) switch((BLDMOD >> 6) & 3) {
{
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x01) {
if(top != 0x01)
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
} }
if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x02) {
if(top != 0x02)
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
} }
if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x08) {
if(top != 0x08)
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
} }
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -547,105 +503,6 @@ void mode0RenderLineAll()
break; 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((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 & 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((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; lineMix[x] = color;
} }

View File

@ -16,36 +16,31 @@
// 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; gfxLastVCOUNT = VCOUNT;
return; 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;
@ -58,55 +53,46 @@ void mode1RenderLine()
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)) if((u8)(line1[x]>>24) < (u8)(color >> 24)) {
{
color = line1[x]; color = line1[x];
top = 0x02; top = 0x02;
} }
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)(lineOBJ[x]>>24) < (u8)(color >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if((top & 0x10) && (color & 0x00010000)) if((top & 0x10) && (color & 0x00010000)) {
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24)) if((u8)(line0[x]>>24) < (u8)(back >> 24)) {
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
if((u8)(line1[x]>>24) < (u8)(back >> 24)) if((u8)(line1[x]>>24) < (u8)(back >> 24)) {
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
if((u8)(line2[x]>>24) < (u8)(back >> 24)) if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -115,10 +101,8 @@ void mode1RenderLine()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -141,29 +125,24 @@ 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; gfxLastVCOUNT = VCOUNT;
return; 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;
@ -176,78 +155,62 @@ void mode1RenderLineNoWindow()
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)) if((u8)(line1[x]>>24) < (u8)(color >> 24)) {
{
color = line1[x]; color = line1[x];
top = 0x02; top = 0x02;
} }
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)(lineOBJ[x]>>24) < (u8)(color >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(!(color & 0x00010000)) if(!(color & 0x00010000)) {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24)) if((u8)(line0[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x01) {
if(top != 0x01)
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
} }
if((u8)(line1[x]>>24) < (u8)(back >> 24)) if((u8)(line1[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x02) {
if(top != 0x02)
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
} }
if((u8)(line2[x]>>24) < (u8)(back >> 24)) if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -269,27 +232,22 @@ void mode1RenderLineNoWindow()
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break; break;
} }
} } else {
else
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((u8)(line0[x]>>24) < (u8)(back >> 24)) if((u8)(line0[x]>>24) < (u8)(back >> 24)) {
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
if((u8)(line1[x]>>24) < (u8)(back >> 24)) if((u8)(line1[x]>>24) < (u8)(back >> 24)) {
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
if((u8)(line2[x]>>24) < (u8)(back >> 24)) if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -298,10 +256,8 @@ void mode1RenderLineNoWindow()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -324,10 +280,8 @@ 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; gfxLastVCOUNT = VCOUNT;
@ -337,8 +291,7 @@ void mode1RenderLineAll()
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));
@ -347,8 +300,7 @@ void mode1RenderLineAll()
else else
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x4000) if(layerEnable & 0x4000) {
{
u8 v0 = WIN1V >> 8; u8 v0 = WIN1V >> 8;
u8 v1 = WIN1V & 255; u8 v1 = WIN1V & 255;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
@ -358,18 +310,15 @@ void mode1RenderLineAll()
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); 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;
@ -387,101 +336,116 @@ 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(inWindow1) {
{
if(gfxInWin1[x]) if(gfxInWin1[x])
mask = inWin1Mask; mask = inWin1Mask;
} }
if(inWindow0) if(inWindow0) {
{ if(gfxInWin0[x]) {
if(gfxInWin0[x])
{
mask = inWin0Mask; mask = inWin0Mask;
} }
} }
if(line0[x] < color && (mask & 1)) if(line0[x] < color && (mask & 1)) {
{
color = line0[x]; color = line0[x];
top = 0x01; top = 0x01;
} }
if((u8)(line1[x]>>24) < (u8)(color >> 24) && (mask & 2)) if((u8)(line1[x]>>24) < (u8)(color >> 24) && (mask & 2)) {
{
color = line1[x]; color = line1[x];
top = 0x02; top = 0x02;
} }
if((u8)(line2[x]>>24) < (u8)(color >> 24) && (mask & 4)) if((u8)(line2[x]>>24) < (u8)(color >> 24) && (mask & 4)) {
{
color = line2[x]; color = line2[x];
top = 0x04; top = 0x04;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; 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 // special FX on the window
if(mask & 32) switch((BLDMOD >> 6) & 3) {
{
if(!(color & 0x00010000))
{
switch((BLDMOD >> 6) & 3)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24))
{ if((mask & 1) && (u8)(line0[x]>>24) < (u8)(back >> 24)) {
if(top != 0x01) if(top != 0x01) {
{
back = line0[x]; back = line0[x];
top2 = 0x01; top2 = 0x01;
} }
} }
if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) if((mask & 2) && (u8)(line1[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x02) {
if(top != 0x02)
{
back = line1[x]; back = line1[x];
top2 = 0x02; top2 = 0x02;
} }
} }
if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) if((mask & 4) && (u8)(line2[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -504,93 +468,6 @@ void mode1RenderLineAll()
break; 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; lineMix[x] = color;
} }

View File

@ -16,26 +16,23 @@
// 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; gfxLastVCOUNT = VCOUNT;
return; return;
} }
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
@ -45,8 +42,7 @@ void mode2RenderLine()
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;
@ -60,44 +56,37 @@ void mode2RenderLine()
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)) if((u8)(line3[x]>>24) < (u8)(color >> 24)) {
{
color = line3[x]; color = line3[x];
top = 0x08; top = 0x08;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if((top & 0x10) && (color & 0x00010000)) if((top & 0x10) && (color & 0x00010000)) {
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24)) if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
if((u8)(line3[x]>>24) < (u8)(back >> 24)) if((u8)(line3[x]>>24) < (u8)(back >> 24)) {
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
@ -106,10 +95,8 @@ void mode2RenderLine()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -133,18 +120,15 @@ 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; gfxLastVCOUNT = VCOUNT;
return; return;
} }
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
changed = 3; changed = 3;
@ -154,8 +138,7 @@ void mode2RenderLineNoWindow()
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;
@ -169,65 +152,52 @@ void mode2RenderLineNoWindow()
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)) if((u8)(line3[x]>>24) < (u8)(color >> 24)) {
{
color = line3[x]; color = line3[x];
top = 0x08; top = 0x08;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(!(color & 0x00010000)) if(!(color & 0x00010000)) {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24)) if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((u8)(line3[x]>>24) < (u8)(back >> 24)) if((u8)(line3[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x08) {
if(top != 0x08)
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
} }
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -249,21 +219,17 @@ void mode2RenderLineNoWindow()
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break; break;
} }
} } else {
else
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((u8)(line2[x]>>24) < (u8)(back >> 24)) if((u8)(line2[x]>>24) < (u8)(back >> 24)) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
if((u8)(line3[x]>>24) < (u8)(back >> 24)) if((u8)(line3[x]>>24) < (u8)(back >> 24)) {
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
@ -272,10 +238,8 @@ void mode2RenderLineNoWindow()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -299,10 +263,8 @@ 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; gfxLastVCOUNT = VCOUNT;
@ -312,8 +274,7 @@ void mode2RenderLineAll()
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));
@ -322,8 +283,7 @@ void mode2RenderLineAll()
else else
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x4000) if(layerEnable & 0x4000) {
{
u8 v0 = WIN1V >> 8; u8 v0 = WIN1V >> 8;
u8 v1 = WIN1V & 255; u8 v1 = WIN1V & 255;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
@ -333,8 +293,7 @@ void mode2RenderLineAll()
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); 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;
@ -344,8 +303,7 @@ void mode2RenderLineAll()
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;
@ -364,86 +322,99 @@ 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(inWindow1) {
{
if(gfxInWin1[x]) if(gfxInWin1[x])
mask = inWin1Mask; mask = inWin1Mask;
} }
if(inWindow0) if(inWindow0) {
{ if(gfxInWin0[x]) {
if(gfxInWin0[x])
{
mask = inWin0Mask; mask = inWin0Mask;
} }
} }
if(line2[x] < color && (mask & 4)) if(line2[x] < color && (mask & 4)) {
{
color = line2[x]; color = line2[x];
top = 0x04; top = 0x04;
} }
if((u8)(line3[x]>>24) < (u8)(color >> 24) && (mask & 8)) if((u8)(line3[x]>>24) < (u8)(color >> 24) && (mask & 8)) {
{
color = line3[x]; color = line3[x];
top = 0x08; top = 0x08;
} }
if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24) && (mask & 16)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(mask & 32) if(color & 0x00010000) {
{ // semi-transparent OBJ
if(!(color & 0x00010000)) u32 back = backdrop;
{ u8 top2 = 0x20;
switch((BLDMOD >> 6) & 3)
{ 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: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) if((mask & 4) && line2[x] < back) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) if((mask & 8) && (u8)(line3[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x08) {
if(top != 0x08)
{
back = line3[x]; back = line3[x];
top2 = 0x08; top2 = 0x08;
} }
} }
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -466,81 +437,6 @@ void mode2RenderLineAll()
break; 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; lineMix[x] = color;
} }

View File

@ -16,26 +16,23 @@
// 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; gfxLastVCOUNT = VCOUNT;
return; return;
} }
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
@ -52,31 +49,26 @@ void mode3RenderLine()
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)) if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if((top & 0x10) && (color & 0x00010000)) if((top & 0x10) && (color & 0x00010000)) {
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -85,10 +77,8 @@ void mode3RenderLine()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -111,18 +101,15 @@ 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; gfxLastVCOUNT = VCOUNT;
return; return;
} }
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
@ -139,49 +126,39 @@ void mode3RenderLineNoWindow()
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)) if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(!(color & 0x00010000)) if(!(color & 0x00010000)) {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -204,15 +181,12 @@ void mode3RenderLineNoWindow()
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break; break;
} }
} } else {
else
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -221,10 +195,8 @@ void mode3RenderLineNoWindow()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -247,10 +219,8 @@ 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; gfxLastVCOUNT = VCOUNT;
@ -260,8 +230,7 @@ void mode3RenderLineAll()
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));
@ -270,8 +239,7 @@ void mode3RenderLineAll()
else else
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x4000) if(layerEnable & 0x4000) {
{
u8 v0 = WIN1V >> 8; u8 v0 = WIN1V >> 8;
u8 v1 = WIN1V & 255; u8 v1 = WIN1V & 255;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
@ -281,8 +249,7 @@ void mode3RenderLineAll()
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x0400) if(layerEnable & 0x0400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
@ -304,71 +271,81 @@ 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(inWindow1) {
{
if(gfxInWin1[x]) if(gfxInWin1[x])
mask = inWin1Mask; mask = inWin1Mask;
} }
if(inWindow0) if(inWindow0) {
{ if(gfxInWin0[x]) {
if(gfxInWin0[x])
{
mask = inWin0Mask; mask = inWin0Mask;
} }
} }
if((mask & 4) && (line2[x] < color)) if((mask & 4) && (line2[x] < color)) {
{
color = line2[x]; color = line2[x];
top = 0x04; top = 0x04;
} }
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(mask & 32) if(color & 0x00010000) {
{ // semi-transparent OBJ
if(!(color & 0x00010000)) u32 back = background;
{ u8 top2 = 0x20;
switch((BLDMOD >> 6) & 3)
{ 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: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) if((mask & 4) && line2[x] < back) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -392,69 +369,6 @@ void mode3RenderLineAll()
break; 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; lineMix[x] = color;
} }

View File

@ -16,26 +16,23 @@
// 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; gfxLastVCOUNT = VCOUNT;
return; return;
} }
if(layerEnable & 0x400) if(layerEnable & 0x400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
@ -51,31 +48,26 @@ void mode4RenderLine()
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)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if((top & 0x10) && (color & 0x00010000)) if((top & 0x10) && (color & 0x00010000)) {
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -84,10 +76,8 @@ void mode4RenderLine()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -110,18 +100,15 @@ 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; gfxLastVCOUNT = VCOUNT;
return; return;
} }
if(layerEnable & 0x400) if(layerEnable & 0x400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
@ -137,49 +124,39 @@ void mode4RenderLineNoWindow()
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)) if((u8)(lineOBJ[x]>>24) < (u8)(color >> 24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(!(color & 0x00010000)) if(!(color & 0x00010000)) {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -202,15 +179,12 @@ void mode4RenderLineNoWindow()
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break; break;
} }
} } else {
else
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -219,10 +193,8 @@ void mode4RenderLineNoWindow()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -245,10 +217,8 @@ 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; gfxLastVCOUNT = VCOUNT;
@ -258,8 +228,7 @@ void mode4RenderLineAll()
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));
@ -268,8 +237,7 @@ void mode4RenderLineAll()
else else
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x4000) if(layerEnable & 0x4000) {
{
u8 v0 = WIN1V >> 8; u8 v0 = WIN1V >> 8;
u8 v1 = WIN1V & 255; u8 v1 = WIN1V & 255;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
@ -279,8 +247,7 @@ void mode4RenderLineAll()
inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow1 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x400) if(layerEnable & 0x400) {
{
int changed = gfxBG2Changed; int changed = gfxBG2Changed;
if(gfxLastVCOUNT > VCOUNT) if(gfxLastVCOUNT > VCOUNT)
@ -301,71 +268,81 @@ 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(inWindow1) {
{
if(gfxInWin1[x]) if(gfxInWin1[x])
mask = inWin1Mask; mask = inWin1Mask;
} }
if(inWindow0) if(inWindow0) {
{ if(gfxInWin0[x]) {
if(gfxInWin0[x])
{
mask = inWin0Mask; mask = inWin0Mask;
} }
} }
if((mask & 4) && (line2[x] < color)) if((mask & 4) && (line2[x] < color)) {
{
color = line2[x]; color = line2[x];
top = 0x04; top = 0x04;
} }
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(mask & 32) if(color & 0x00010000) {
{ // semi-transparent OBJ
if(!(color & 0x00010000)) u32 back = backdrop;
{ u8 top2 = 0x20;
switch((BLDMOD >> 6) & 3)
{ 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: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = backdrop; u32 back = backdrop;
u8 top2 = 0x20; u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) if((mask & 4) && line2[x] < back) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -389,69 +366,6 @@ void mode4RenderLineAll()
break; 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; lineMix[x] = color;
} }

View File

@ -16,16 +16,14 @@
// 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; gfxLastVCOUNT = VCOUNT;
@ -34,8 +32,7 @@ void mode5RenderLine()
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)
@ -52,31 +49,26 @@ void mode5RenderLine()
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)) if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if((top & 0x10) && (color & 0x00010000)) if((top & 0x10) && (color & 0x00010000)) {
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -85,10 +77,8 @@ void mode5RenderLine()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -109,10 +99,8 @@ void mode5RenderLine()
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; gfxLastVCOUNT = VCOUNT;
@ -121,8 +109,7 @@ void mode5RenderLineNoWindow()
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)
@ -139,49 +126,39 @@ void mode5RenderLineNoWindow()
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)) if((u8)(lineOBJ[x]>>24) < (u8)(color >>24)) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(!(color & 0x00010000)) if(!(color & 0x00010000)) {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 0: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -204,15 +181,12 @@ void mode5RenderLineNoWindow()
color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxDecreaseBrightness(color, coeff[COLY & 0x1F]);
break; break;
} }
} } else {
else
{
// semi-transparent OBJ // semi-transparent OBJ
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if(line2[x] < back) if(line2[x] < back) {
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
@ -221,10 +195,8 @@ void mode5RenderLineNoWindow()
color = gfxAlphaBlend(color, back, color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F], coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]); coeff[(COLEV >> 8) & 0x1F]);
else else {
{ switch((BLDMOD >> 6) & 3) {
switch((BLDMOD >> 6) & 3)
{
case 2: case 2:
if(BLDMOD & top) if(BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]); color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -245,10 +217,8 @@ void mode5RenderLineNoWindow()
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; gfxLastVCOUNT = VCOUNT;
@ -257,8 +227,7 @@ void mode5RenderLineAll()
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)
@ -277,8 +246,7 @@ 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));
@ -287,8 +255,7 @@ void mode5RenderLineAll()
else else
inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1); inWindow0 |= (VCOUNT >= v0 || VCOUNT < v1);
} }
if(layerEnable & 0x4000) if(layerEnable & 0x4000) {
{
u8 v0 = WIN1V >> 8; u8 v0 = WIN1V >> 8;
u8 v1 = WIN1V & 255; u8 v1 = WIN1V & 255;
inWindow1 = ((v0 == v1) && (v0 >= 0xe8)); inWindow1 = ((v0 == v1) && (v0 >= 0xe8));
@ -304,71 +271,81 @@ 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(inWindow1) {
{
if(gfxInWin1[x]) if(gfxInWin1[x])
mask = inWin1Mask; mask = inWin1Mask;
} }
if(inWindow0) if(inWindow0) {
{ if(gfxInWin0[x]) {
if(gfxInWin0[x])
{
mask = inWin0Mask; mask = inWin0Mask;
} }
} }
if((mask & 4) && (line2[x] < color)) if((mask & 4) && (line2[x] < color)) {
{
color = line2[x]; color = line2[x];
top = 0x04; top = 0x04;
} }
if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) if((mask & 16) && ((u8)(lineOBJ[x]>>24) < (u8)(color >>24))) {
{
color = lineOBJ[x]; color = lineOBJ[x];
top = 0x10; top = 0x10;
} }
if(mask & 32) if(color & 0x00010000) {
{ // semi-transparent OBJ
if(!(color & 0x00010000)) u32 back = background;
{ u8 top2 = 0x20;
switch((BLDMOD >> 6) & 3)
{ 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: case 0:
break; break;
case 1: case 1:
{ {
if(top & BLDMOD) if(top & BLDMOD) {
{
u32 back = background; u32 back = background;
u8 top2 = 0x20; u8 top2 = 0x20;
if((mask & 4) && line2[x] < back) if((mask & 4) && line2[x] < back) {
{ if(top != 0x04) {
if(top != 0x04)
{
back = line2[x]; back = line2[x];
top2 = 0x04; top2 = 0x04;
} }
} }
if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) if((mask & 16) && (u8)(lineOBJ[x]>>24) < (u8)(back >> 24)) {
{ if(top != 0x10) {
if(top != 0x10)
{
back = lineOBJ[x]; back = lineOBJ[x];
top2 = 0x10; top2 = 0x10;
} }
@ -392,69 +369,6 @@ void mode5RenderLineAll()
break; 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; lineMix[x] = color;
} }

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,8 +29,7 @@
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;
@ -43,8 +42,7 @@ typedef struct
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;
case 0x80000c6:
return rtcClockData.byte1; return rtcClockData.byte1;
else if(address == 0x80000c4) break;
{ case 0x80000c4:
return rtcClockData.byte0; return rtcClockData.byte0;
break;
} }
} }
//return READ16LE((&rom[address & 0x1FFFFFE])); //return READ16LE((&rom[address & 0x1FFFFFE]));
return VMRead16( address & 0x1FFFFFE ); return VMRead16( address & 0x1FFFFFE );
} }
@ -90,37 +89,25 @@ 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) {
else if(address == 0x80000c6)
{
rtcClockData.byte1 = (u8)value; // read/write rtcClockData.byte1 = (u8)value; // read/write
} } else if(address == 0x80000c4) {
else if(address == 0x80000c4) if(rtcClockData.byte2 & 1) {
{ if(rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5) {
if(rtcClockData.byte2 & 1)
{
if(rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5)
{
rtcClockData.state = COMMAND; rtcClockData.state = COMMAND;
rtcClockData.bits = 0; rtcClockData.bits = 0;
rtcClockData.command = 0; rtcClockData.command = 0;
} } else if(!(rtcClockData.byte0 & 1) && (value & 1)) { // bit transfer
else if(!(rtcClockData.byte0 & 1) && (value & 1))
{ // bit transfer
rtcClockData.byte0 = (u8)value; rtcClockData.byte0 = (u8)value;
switch(rtcClockData.state) switch(rtcClockData.state) {
{
case COMMAND: case COMMAND:
rtcClockData.command |= ((value & 2) >> 1) << (7-rtcClockData.bits); rtcClockData.command |= ((value & 2) >> 1) << (7-rtcClockData.bits);
rtcClockData.bits++; rtcClockData.bits++;
if(rtcClockData.bits == 8) if(rtcClockData.bits == 8) {
{
rtcClockData.bits = 0; rtcClockData.bits = 0;
switch(rtcClockData.command) switch(rtcClockData.command) {
{
case 0x60: case 0x60:
// not sure what this command does but it doesn't take parameters // not sure what this command does but it doesn't take parameters
// maybe it is a reset or stop // maybe it is a reset or stop
@ -137,6 +124,8 @@ bool rtcWrite(u32 address, u16 value)
rtcClockData.data[0] = 0x40; rtcClockData.data[0] = 0x40;
rtcClockData.state = DATA; rtcClockData.state = DATA;
break; break;
case 0x64:
break;
case 0x65: case 0x65:
{ {
struct tm *newtime; struct tm *newtime;
@ -149,7 +138,7 @@ bool rtcWrite(u32 address, u16 value)
rtcClockData.data[0] = toBCD(newtime->tm_year); rtcClockData.data[0] = toBCD(newtime->tm_year);
rtcClockData.data[1] = toBCD(newtime->tm_mon+1); rtcClockData.data[1] = toBCD(newtime->tm_mon+1);
rtcClockData.data[2] = toBCD(newtime->tm_mday); rtcClockData.data[2] = toBCD(newtime->tm_mday);
rtcClockData.data[3] = 0; rtcClockData.data[3] = toBCD(newtime->tm_wday);
rtcClockData.data[4] = toBCD(newtime->tm_hour); rtcClockData.data[4] = toBCD(newtime->tm_hour);
rtcClockData.data[5] = toBCD(newtime->tm_min); rtcClockData.data[5] = toBCD(newtime->tm_min);
rtcClockData.data[6] = toBCD(newtime->tm_sec); rtcClockData.data[6] = toBCD(newtime->tm_sec);
@ -179,32 +168,26 @@ bool rtcWrite(u32 address, u16 value)
} }
break; break;
case DATA: case DATA:
if(rtcClockData.byte1 & 2) if(rtcClockData.byte1 & 2) {
{} } else {
else
{
rtcClockData.byte0 = (rtcClockData.byte0 & ~2) | rtcClockData.byte0 = (rtcClockData.byte0 & ~2) |
((rtcClockData.data[rtcClockData.bits >> 3] >> ((rtcClockData.data[rtcClockData.bits >> 3] >>
(rtcClockData.bits & 7)) & 1)*2; (rtcClockData.bits & 7)) & 1)*2;
rtcClockData.bits++; rtcClockData.bits++;
if(rtcClockData.bits == 8*rtcClockData.dataLen) if(rtcClockData.bits == 8*rtcClockData.dataLen) {
{
rtcClockData.bits = 0; rtcClockData.bits = 0;
rtcClockData.state = IDLE; rtcClockData.state = IDLE;
} }
} }
break; break;
case READDATA: case READDATA:
if(!(rtcClockData.byte1 & 2)) if(!(rtcClockData.byte1 & 2)) {
{} } else {
else
{
rtcClockData.data[rtcClockData.bits >> 3] = rtcClockData.data[rtcClockData.bits >> 3] =
(rtcClockData.data[rtcClockData.bits >> 3] >> 1) | (rtcClockData.data[rtcClockData.bits >> 3] >> 1) |
((value << 6) & 128); ((value << 6) & 128);
rtcClockData.bits++; rtcClockData.bits++;
if(rtcClockData.bits == 8*rtcClockData.dataLen) if(rtcClockData.bits == 8*rtcClockData.dataLen) {
{
rtcClockData.bits = 0; rtcClockData.bits = 0;
rtcClockData.state = IDLE; rtcClockData.state = IDLE;
} }
@ -213,8 +196,7 @@ bool rtcWrite(u32 address, u16 value)
default: default:
break; break;
} }
} } else
else
rtcClockData.byte0 = (u8)value; rtcClockData.byte0 = (u8)value;
} }
} }

View File

@ -1,6 +1,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
@ -18,9 +19,10 @@
#include <string.h> #include <string.h>
#include "GBA.h"
#include "Globals.h"
#include "Sound.h" #include "Sound.h"
#include "agb/GBA.h"
#include "Globals.h"
#include "Util.h" #include "Util.h"
#define USE_TICKS_AS 380 #define USE_TICKS_AS 380
@ -288,8 +290,7 @@ void soundEvent(u32 address, u8 data)
{ {
int freq = 0; int freq = 0;
switch(address) switch(address) {
{
case NR10: case NR10:
data &= 0x7f; data &= 0x7f;
sound1SweepATL = sound1SweepATLReload = 344 * ((data >> 4) & 7); sound1SweepATL = sound1SweepATLReload = 344 * ((data >> 4) & 7);
@ -314,11 +315,9 @@ void soundEvent(u32 address, u8 data)
freq = (((int)(ioMem[NR14] & 7)) << 8) | data; freq = (((int)(ioMem[NR14] & 7)) << 8) | data;
sound1ATL = 172 * (64 - (ioMem[NR11] & 0x3f)); sound1ATL = 172 * (64 - (ioMem[NR11] & 0x3f));
freq = 2048 - freq; freq = 2048 - freq;
if(freq) if(freq) {
{
sound1Skip = SOUND_MAGIC / freq; sound1Skip = SOUND_MAGIC / freq;
} } else
else
sound1Skip = 0; sound1Skip = 0;
ioMem[address] = data; ioMem[address] = data;
break; break;
@ -328,14 +327,11 @@ void soundEvent(u32 address, u8 data)
freq = 2048 - freq; freq = 2048 - freq;
sound1ATL = 172 * (64 - (ioMem[NR11] & 0x3f)); sound1ATL = 172 * (64 - (ioMem[NR11] & 0x3f));
sound1Continue = data & 0x40; sound1Continue = data & 0x40;
if(freq) if(freq) {
{
sound1Skip = SOUND_MAGIC / freq; sound1Skip = SOUND_MAGIC / freq;
} } else
else
sound1Skip = 0; sound1Skip = 0;
if(data & 0x80) if(data & 0x80) {
{
ioMem[NR52] |= 1; ioMem[NR52] |= 1;
sound1EnvelopeVolume = ioMem[NR12] >> 4; sound1EnvelopeVolume = ioMem[NR12] >> 4;
sound1EnvelopeUpDown = ioMem[NR12] & 0x08; sound1EnvelopeUpDown = ioMem[NR12] & 0x08;
@ -367,11 +363,9 @@ void soundEvent(u32 address, u8 data)
freq = (((int)(ioMem[NR24] & 7)) << 8) | data; freq = (((int)(ioMem[NR24] & 7)) << 8) | data;
sound2ATL = 172 * (64 - (ioMem[NR21] & 0x3f)); sound2ATL = 172 * (64 - (ioMem[NR21] & 0x3f));
freq = 2048 - freq; freq = 2048 - freq;
if(freq) if(freq) {
{
sound2Skip = SOUND_MAGIC / freq; sound2Skip = SOUND_MAGIC / freq;
} } else
else
sound2Skip = 0; sound2Skip = 0;
ioMem[address] = data; ioMem[address] = data;
break; break;
@ -381,14 +375,11 @@ void soundEvent(u32 address, u8 data)
freq = 2048 - freq; freq = 2048 - freq;
sound2ATL = 172 * (64 - (ioMem[NR21] & 0x3f)); sound2ATL = 172 * (64 - (ioMem[NR21] & 0x3f));
sound2Continue = data & 0x40; sound2Continue = data & 0x40;
if(freq) if(freq) {
{
sound2Skip = SOUND_MAGIC / freq; sound2Skip = SOUND_MAGIC / freq;
} } else
else
sound2Skip = 0; sound2Skip = 0;
if(data & 0x80) if(data & 0x80) {
{
ioMem[NR52] |= 2; ioMem[NR52] |= 2;
sound2EnvelopeVolume = ioMem[NR22] >> 4; sound2EnvelopeVolume = ioMem[NR22] >> 4;
sound2EnvelopeUpDown = ioMem[NR22] & 0x08; sound2EnvelopeUpDown = ioMem[NR22] & 0x08;
@ -398,12 +389,11 @@ void soundEvent(u32 address, u8 data)
sound2Index = 0; sound2Index = 0;
sound2On = 1; sound2On = 1;
} }
break;
ioMem[address] = data; ioMem[address] = data;
break;
case NR30: case NR30:
data &= 0xe0; data &= 0xe0;
if(!(data & 0x80)) if(!(data & 0x80)) {
{
ioMem[NR52] &= 0xfb; ioMem[NR52] &= 0xfb;
sound3On = 0; sound3On = 0;
} }
@ -426,28 +416,22 @@ void soundEvent(u32 address, u8 data)
break; break;
case NR33: case NR33:
freq = 2048 - (((int)(ioMem[NR34]&7) << 8) | data); freq = 2048 - (((int)(ioMem[NR34]&7) << 8) | data);
if(freq) if(freq) {
{
sound3Skip = SOUND_MAGIC_2 / freq; sound3Skip = SOUND_MAGIC_2 / freq;
} } else
else
sound3Skip = 0; sound3Skip = 0;
ioMem[address] = data; ioMem[address] = data;
break; break;
case NR34: case NR34:
data &= 0xc7; data &= 0xc7;
freq = 2048 - (((data &7) << 8) | (int)ioMem[NR33]); freq = 2048 - (((data &7) << 8) | (int)ioMem[NR33]);
if(freq) if(freq) {
{
sound3Skip = SOUND_MAGIC_2 / freq; sound3Skip = SOUND_MAGIC_2 / freq;
} } else {
else
{
sound3Skip = 0; sound3Skip = 0;
} }
sound3Continue = data & 0x40; sound3Continue = data & 0x40;
if((data & 0x80) && (ioMem[NR30] & 0x80)) if((data & 0x80) && (ioMem[NR30] & 0x80)) {
{
ioMem[NR52] |= 4; ioMem[NR52] |= 4;
sound3ATL = 172 * (256 - ioMem[NR31]); sound3ATL = 172 * (256 - ioMem[NR31]);
sound3Index = 0; sound3Index = 0;
@ -483,8 +467,7 @@ void soundEvent(u32 address, u8 data)
case NR44: case NR44:
data &= 0xc0; data &= 0xc0;
sound4Continue = data & 0x40; sound4Continue = data & 0x40;
if(data & 0x80) if(data & 0x80) {
{
ioMem[NR52] |= 8; ioMem[NR52] |= 8;
sound4EnvelopeVolume = ioMem[NR42] >> 4; sound4EnvelopeVolume = ioMem[NR42] >> 4;
sound4EnvelopeUpDown = ioMem[NR42] & 0x08; sound4EnvelopeUpDown = ioMem[NR42] & 0x08;
@ -526,8 +509,7 @@ void soundEvent(u32 address, u8 data)
data &= 0x80; data &= 0x80;
data |= ioMem[NR52] & 15; data |= ioMem[NR52] & 15;
soundMasterOn = data & 0x80; soundMasterOn = data & 0x80;
if(!(data & 0x80)) if(!(data & 0x80)) {
{
sound1On = 0; sound1On = 0;
sound2On = 0; sound2On = 0;
sound3On = 0; sound3On = 0;
@ -558,14 +540,11 @@ void soundEvent(u32 address, u8 data)
void soundEvent(u32 address, u16 data) void soundEvent(u32 address, u16 data)
{ {
switch(address) switch(address) {
{
case SGCNT0_H: case SGCNT0_H:
data &= 0xFF0F; data &= 0xFF0F;
soundControl = data & 0x770F; soundControl = data & 0x770F;
; if(data & 0x0800) {
if(data & 0x0800)
{
soundDSFifoAWriteIndex = 0; soundDSFifoAWriteIndex = 0;
soundDSFifoAIndex = 0; soundDSFifoAIndex = 0;
soundDSFifoACount = 0; soundDSFifoACount = 0;
@ -574,8 +553,7 @@ void soundEvent(u32 address, u16 data)
} }
soundDSAEnabled = (data & 0x0300) ? true : false; soundDSAEnabled = (data & 0x0300) ? true : false;
soundDSATimer = (data & 0x0400) ? 1 : 0; soundDSATimer = (data & 0x0400) ? 1 : 0;
if(data & 0x8000) if(data & 0x8000) {
{
soundDSFifoBWriteIndex = 0; soundDSFifoBWriteIndex = 0;
soundDSFifoBIndex = 0; soundDSFifoBIndex = 0;
soundDSFifoBCount = 0; soundDSFifoBCount = 0;
@ -584,7 +562,7 @@ void soundEvent(u32 address, u16 data)
} }
soundDSBEnabled = (data & 0x3000) ? true : false; soundDSBEnabled = (data & 0x3000) ? true : false;
soundDSBTimer = (data & 0x4000) ? 1 : 0; soundDSBTimer = (data & 0x4000) ? 1 : 0;
*((u16 *)&ioMem[address]) = data; *((u16 *)&ioMem[address]) = soundControl;
break; break;
case FIFOA_L: case FIFOA_L:
case FIFOA_H: case FIFOA_H:
@ -627,8 +605,7 @@ void soundChannel1()
int freq = 0; int freq = 0;
int value = 0; int value = 0;
if(sound1On && (sound1ATL || !sound1Continue)) if(sound1On && (sound1ATL || !sound1Continue)) {
{
sound1Index += soundQuality*sound1Skip; sound1Index += soundQuality*sound1Skip;
sound1Index &= 0x1fffffff; sound1Index &= 0x1fffffff;
@ -638,32 +615,24 @@ void soundChannel1()
soundBuffer[0][soundIndex] = value; soundBuffer[0][soundIndex] = value;
if(sound1On) if(sound1On) {
{ if(sound1ATL) {
if(sound1ATL)
{
sound1ATL-=soundQuality; sound1ATL-=soundQuality;
if(sound1ATL <=0 && sound1Continue) if(sound1ATL <=0 && sound1Continue) {
{
ioMem[NR52] &= 0xfe; ioMem[NR52] &= 0xfe;
sound1On = 0; sound1On = 0;
} }
} }
if(sound1EnvelopeATL) if(sound1EnvelopeATL) {
{
sound1EnvelopeATL-=soundQuality; sound1EnvelopeATL-=soundQuality;
if(sound1EnvelopeATL<=0) if(sound1EnvelopeATL<=0) {
{ if(sound1EnvelopeUpDown) {
if(sound1EnvelopeUpDown)
{
if(sound1EnvelopeVolume < 15) if(sound1EnvelopeVolume < 15)
sound1EnvelopeVolume++; sound1EnvelopeVolume++;
} } else {
else
{
if(sound1EnvelopeVolume) if(sound1EnvelopeVolume)
sound1EnvelopeVolume--; sound1EnvelopeVolume--;
} }
@ -672,12 +641,10 @@ void soundChannel1()
} }
} }
if(sound1SweepATL) if(sound1SweepATL) {
{
sound1SweepATL-=soundQuality; sound1SweepATL-=soundQuality;
if(sound1SweepATL<=0) if(sound1SweepATL<=0) {
{
freq = (((int)(ioMem[NR14]&7) << 8) | ioMem[NR13]); freq = (((int)(ioMem[NR14]&7) << 8) | ioMem[NR13]);
int updown = 1; int updown = 1;
@ -686,27 +653,20 @@ void soundChannel1()
updown = -1; updown = -1;
int newfreq = 0; int newfreq = 0;
if(sound1SweepSteps) if(sound1SweepSteps) {
{
newfreq = freq + updown * freq / (1 << sound1SweepSteps); newfreq = freq + updown * freq / (1 << sound1SweepSteps);
if(newfreq == freq) if(newfreq == freq)
newfreq = 0; newfreq = 0;
} } else
else
newfreq = freq; newfreq = freq;
if(newfreq < 0) if(newfreq < 0) {
{
sound1SweepATL += sound1SweepATLReload; sound1SweepATL += sound1SweepATLReload;
} } else if(newfreq > 2047) {
else if(newfreq > 2047)
{
sound1SweepATL = 0; sound1SweepATL = 0;
sound1On = 0; sound1On = 0;
ioMem[NR52] &= 0xfe; ioMem[NR52] &= 0xfe;
} } else {
else
{
sound1SweepATL += sound1SweepATLReload; sound1SweepATL += sound1SweepATLReload;
sound1Skip = SOUND_MAGIC/(2048 - newfreq); sound1Skip = SOUND_MAGIC/(2048 - newfreq);
@ -725,8 +685,7 @@ void soundChannel2()
int value = 0; int value = 0;
if(sound2On && (sound2ATL || !sound2Continue)) if(sound2On && (sound2ATL || !sound2Continue)) {
{
sound2Index += soundQuality*sound2Skip; sound2Index += soundQuality*sound2Skip;
sound2Index &= 0x1fffffff; sound2Index &= 0x1fffffff;
@ -735,32 +694,24 @@ void soundChannel2()
soundBuffer[1][soundIndex] = value; soundBuffer[1][soundIndex] = value;
if(sound2On) if(sound2On) {
{ if(sound2ATL) {
if(sound2ATL)
{
sound2ATL-=soundQuality; sound2ATL-=soundQuality;
if(sound2ATL <= 0 && sound2Continue) if(sound2ATL <= 0 && sound2Continue) {
{
ioMem[NR52] &= 0xfd; ioMem[NR52] &= 0xfd;
sound2On = 0; sound2On = 0;
} }
} }
if(sound2EnvelopeATL) if(sound2EnvelopeATL) {
{
sound2EnvelopeATL-=soundQuality; sound2EnvelopeATL-=soundQuality;
if(sound2EnvelopeATL <= 0) if(sound2EnvelopeATL <= 0) {
{ if(sound2EnvelopeUpDown) {
if(sound2EnvelopeUpDown)
{
if(sound2EnvelopeVolume < 15) if(sound2EnvelopeVolume < 15)
sound2EnvelopeVolume++; sound2EnvelopeVolume++;
} } else {
else
{
if(sound2EnvelopeVolume) if(sound2EnvelopeVolume)
sound2EnvelopeVolume--; sound2EnvelopeVolume--;
} }
@ -774,41 +725,29 @@ void soundChannel3()
{ {
int value = sound3Last; int value = sound3Last;
if(sound3On && (sound3ATL || !sound3Continue)) if(sound3On && (sound3ATL || !sound3Continue)) {
{
sound3Index += soundQuality*sound3Skip; sound3Index += soundQuality*sound3Skip;
if(sound3DataSize) if(sound3DataSize) {
{
sound3Index &= 0x3fffffff; sound3Index &= 0x3fffffff;
value = sound3WaveRam[sound3Index>>25]; value = sound3WaveRam[sound3Index>>25];
} } else {
else
{
sound3Index &= 0x1fffffff; sound3Index &= 0x1fffffff;
value = sound3WaveRam[sound3Bank*0x10 + (sound3Index>>25)]; value = sound3WaveRam[sound3Bank*0x10 + (sound3Index>>25)];
} }
if( (sound3Index & 0x01000000)) if( (sound3Index & 0x01000000)) {
{
value &= 0x0f; value &= 0x0f;
} } else {
else
{
value >>= 4; value >>= 4;
} }
value -= 8; value -= 8;
//value *= 2; value *= 2;
value <<= 1;
if(sound3ForcedOutput) if(sound3ForcedOutput) {
{
value = ((value >> 1) + value) >> 1; value = ((value >> 1) + value) >> 1;
} } else {
else switch(sound3OutputLevel) {
{
switch(sound3OutputLevel)
{
case 0: case 0:
value = 0; value = 0;
break; break;
@ -827,14 +766,11 @@ void soundChannel3()
soundBuffer[2][soundIndex] = value; soundBuffer[2][soundIndex] = value;
if(sound3On) if(sound3On) {
{ if(sound3ATL) {
if(sound3ATL)
{
sound3ATL-=soundQuality; sound3ATL-=soundQuality;
if(sound3ATL <= 0 && sound3Continue) if(sound3ATL <= 0 && sound3Continue) {
{
ioMem[NR52] &= 0xfb; ioMem[NR52] &= 0xfb;
sound3On = 0; sound3On = 0;
} }
@ -848,27 +784,20 @@ void soundChannel4()
int value = 0; int value = 0;
if(sound4Clock <= 0x0c) if(sound4Clock <= 0x0c) {
{ if(sound4On && (sound4ATL || !sound4Continue)) {
if(sound4On && (sound4ATL || !sound4Continue))
{
sound4Index += soundQuality*sound4Skip; sound4Index += soundQuality*sound4Skip;
sound4ShiftIndex += soundQuality*sound4ShiftSkip; sound4ShiftIndex += soundQuality*sound4ShiftSkip;
if(sound4NSteps) if(sound4NSteps) {
{ while(sound4ShiftIndex > 0x1fffff) {
while(sound4ShiftIndex > 0x1fffff)
{
sound4ShiftRight = (((sound4ShiftRight << 6) ^ sound4ShiftRight = (((sound4ShiftRight << 6) ^
(sound4ShiftRight << 5)) & 0x40) | (sound4ShiftRight << 5)) & 0x40) |
(sound4ShiftRight >> 1); (sound4ShiftRight >> 1);
sound4ShiftIndex -= 0x200000; sound4ShiftIndex -= 0x200000;
} }
} } else {
else while(sound4ShiftIndex > 0x1fffff) {
{
while(sound4ShiftIndex > 0x1fffff)
{
sound4ShiftRight = (((sound4ShiftRight << 14) ^ sound4ShiftRight = (((sound4ShiftRight << 14) ^
(sound4ShiftRight << 13)) & 0x4000) | (sound4ShiftRight << 13)) & 0x4000) |
(sound4ShiftRight >> 1); (sound4ShiftRight >> 1);
@ -881,41 +810,31 @@ void soundChannel4()
sound4ShiftIndex &= 0x1fffff; sound4ShiftIndex &= 0x1fffff;
value = ((sound4ShiftRight & 1)*2-1) * vol; value = ((sound4ShiftRight & 1)*2-1) * vol;
} } else {
else
{
value = 0; value = 0;
} }
} }
soundBuffer[3][soundIndex] = value; soundBuffer[3][soundIndex] = value;
if(sound4On) if(sound4On) {
{ if(sound4ATL) {
if(sound4ATL)
{
sound4ATL-=soundQuality; sound4ATL-=soundQuality;
if(sound4ATL <= 0 && sound4Continue) if(sound4ATL <= 0 && sound4Continue) {
{
ioMem[NR52] &= 0xfd; ioMem[NR52] &= 0xfd;
sound4On = 0; sound4On = 0;
} }
} }
if(sound4EnvelopeATL) if(sound4EnvelopeATL) {
{
sound4EnvelopeATL-=soundQuality; sound4EnvelopeATL-=soundQuality;
if(sound4EnvelopeATL <= 0) if(sound4EnvelopeATL <= 0) {
{ if(sound4EnvelopeUpDown) {
if(sound4EnvelopeUpDown)
{
if(sound4EnvelopeVolume < 15) if(sound4EnvelopeVolume < 15)
sound4EnvelopeVolume++; sound4EnvelopeVolume++;
} } else {
else
{
if(sound4EnvelopeVolume) if(sound4EnvelopeVolume)
sound4EnvelopeVolume--; sound4EnvelopeVolume--;
} }
@ -932,13 +851,10 @@ void soundDirectSoundA()
void soundDirectSoundATimer() void soundDirectSoundATimer()
{ {
if(soundDSAEnabled) if(soundDSAEnabled) {
{ if(soundDSFifoACount <= 16) {
if(soundDSFifoACount <= 16)
{
CPUCheckDMA(3, 2); CPUCheckDMA(3, 2);
if(soundDSFifoACount <= 16) if(soundDSFifoACount <= 16) {
{
soundEvent(FIFOA_L, (u16)0); soundEvent(FIFOA_L, (u16)0);
soundEvent(FIFOA_H, (u16)0); soundEvent(FIFOA_H, (u16)0);
soundEvent(FIFOA_L, (u16)0); soundEvent(FIFOA_L, (u16)0);
@ -951,10 +867,9 @@ void soundDirectSoundATimer()
} }
soundDSAValue = (soundDSFifoA[soundDSFifoAIndex]); soundDSAValue = (soundDSFifoA[soundDSFifoAIndex]);
soundDSFifoAIndex = (++soundDSFifoAIndex) & 31; soundDSFifoAIndex = (soundDSFifoAIndex + 1) & 31;
soundDSFifoACount--; soundDSFifoACount--;
} } else
else
soundDSAValue = 0; soundDSAValue = 0;
} }
@ -965,13 +880,10 @@ void soundDirectSoundB()
void soundDirectSoundBTimer() void soundDirectSoundBTimer()
{ {
if(soundDSBEnabled) if(soundDSBEnabled) {
{ if(soundDSFifoBCount <= 16) {
if(soundDSFifoBCount <= 16)
{
CPUCheckDMA(3, 4); CPUCheckDMA(3, 4);
if(soundDSFifoBCount <= 16) if(soundDSFifoBCount <= 16) {
{
soundEvent(FIFOB_L, (u16)0); soundEvent(FIFOB_L, (u16)0);
soundEvent(FIFOB_H, (u16)0); soundEvent(FIFOB_H, (u16)0);
soundEvent(FIFOB_L, (u16)0); soundEvent(FIFOB_L, (u16)0);
@ -984,23 +896,19 @@ void soundDirectSoundBTimer()
} }
soundDSBValue = (soundDSFifoB[soundDSFifoBIndex]); soundDSBValue = (soundDSFifoB[soundDSFifoBIndex]);
soundDSFifoBIndex = (++soundDSFifoBIndex) & 31; soundDSFifoBIndex = (soundDSFifoBIndex + 1) & 31;
soundDSFifoBCount--; soundDSFifoBCount--;
} } else {
else
{
soundDSBValue = 0; soundDSBValue = 0;
} }
} }
void soundTimerOverflow(int timer) void soundTimerOverflow(int timer)
{ {
if(soundDSAEnabled && (soundDSATimer == timer)) if(soundDSAEnabled && (soundDSATimer == timer)) {
{
soundDirectSoundATimer(); soundDirectSoundATimer();
} }
if(soundDSBEnabled && (soundDSBTimer == timer)) if(soundDSBEnabled && (soundDSBTimer == timer)) {
{
soundDirectSoundBTimer(); soundDirectSoundBTimer();
} }
} }
@ -1017,33 +925,27 @@ void soundMix()
int dsaRatio = ioMem[0x82] & 4; int dsaRatio = ioMem[0x82] & 4;
int dsbRatio = ioMem[0x82] & 8; int dsbRatio = ioMem[0x82] & 8;
if(soundBalance & 16) if(soundBalance & 16) {
{
cgbRes = ((s8)soundBuffer[0][soundIndex]); cgbRes = ((s8)soundBuffer[0][soundIndex]);
} }
if(soundBalance & 32) if(soundBalance & 32) {
{
cgbRes += ((s8)soundBuffer[1][soundIndex]); cgbRes += ((s8)soundBuffer[1][soundIndex]);
} }
if(soundBalance & 64) if(soundBalance & 64) {
{
cgbRes += ((s8)soundBuffer[2][soundIndex]); cgbRes += ((s8)soundBuffer[2][soundIndex]);
} }
if(soundBalance & 128) if(soundBalance & 128) {
{
cgbRes += ((s8)soundBuffer[3][soundIndex]); cgbRes += ((s8)soundBuffer[3][soundIndex]);
} }
if((soundControl & 0x0200) && (soundEnableFlag & 0x100)) if((soundControl & 0x0200) && (soundEnableFlag & 0x100)){
{
if(!dsaRatio) if(!dsaRatio)
res = ((s8)soundBuffer[4][soundIndex])>>1; res = ((s8)soundBuffer[4][soundIndex])>>1;
else else
res = ((s8)soundBuffer[4][soundIndex]); res = ((s8)soundBuffer[4][soundIndex]);
} }
if((soundControl & 0x2000) && (soundEnableFlag & 0x200)) if((soundControl & 0x2000) && (soundEnableFlag & 0x200)){
{
if(!dsbRatio) if(!dsbRatio)
res += ((s8)soundBuffer[5][soundIndex])>>1; res += ((s8)soundBuffer[5][soundIndex])>>1;
else else
@ -1053,8 +955,7 @@ void soundMix()
res = (res * 170); res = (res * 170);
cgbRes = (cgbRes * 52 * soundLevel1); cgbRes = (cgbRes * 52 * soundLevel1);
switch(ratio) switch(ratio) {
{
case 0: case 0:
case 3: // prohibited, but 25% case 3: // prohibited, but 25%
cgbRes >>= 2; cgbRes >>= 2;
@ -1068,16 +969,14 @@ void soundMix()
res += cgbRes; res += cgbRes;
if(soundEcho) if(soundEcho) {
{
res *= 2; res *= 2;
res += soundFilter[soundEchoIndex]; res += soundFilter[soundEchoIndex];
res /= 2; res /= 2;
soundFilter[soundEchoIndex++] = res; soundFilter[soundEchoIndex++] = res;
} }
if(soundLowPass) if(soundLowPass) {
{
soundLeft[4] = soundLeft[3]; soundLeft[4] = soundLeft[3];
soundLeft[3] = soundLeft[2]; soundLeft[3] = soundLeft[2];
soundLeft[2] = soundLeft[1]; soundLeft[2] = soundLeft[1];
@ -1087,8 +986,7 @@ void soundMix()
soundLeft[0])/14; soundLeft[0])/14;
} }
switch(soundVolume) switch(soundVolume) {
{
case 0: case 0:
case 1: case 1:
case 2: case 2:
@ -1116,33 +1014,27 @@ void soundMix()
res = 0; res = 0;
cgbRes = 0; cgbRes = 0;
if(soundBalance & 1) if(soundBalance & 1) {
{
cgbRes = ((s8)soundBuffer[0][soundIndex]); cgbRes = ((s8)soundBuffer[0][soundIndex]);
} }
if(soundBalance & 2) if(soundBalance & 2) {
{
cgbRes += ((s8)soundBuffer[1][soundIndex]); cgbRes += ((s8)soundBuffer[1][soundIndex]);
} }
if(soundBalance & 4) if(soundBalance & 4) {
{
cgbRes += ((s8)soundBuffer[2][soundIndex]); cgbRes += ((s8)soundBuffer[2][soundIndex]);
} }
if(soundBalance & 8) if(soundBalance & 8) {
{
cgbRes += ((s8)soundBuffer[3][soundIndex]); cgbRes += ((s8)soundBuffer[3][soundIndex]);
} }
if((soundControl & 0x0100) && (soundEnableFlag & 0x100)) if((soundControl & 0x0100) && (soundEnableFlag & 0x100)){
{
if(!dsaRatio) if(!dsaRatio)
res = ((s8)soundBuffer[4][soundIndex])>>1; res = ((s8)soundBuffer[4][soundIndex])>>1;
else else
res = ((s8)soundBuffer[4][soundIndex]); res = ((s8)soundBuffer[4][soundIndex]);
} }
if((soundControl & 0x1000) && (soundEnableFlag & 0x200)) if((soundControl & 0x1000) && (soundEnableFlag & 0x200)){
{
if(!dsbRatio) if(!dsbRatio)
res += ((s8)soundBuffer[5][soundIndex])>>1; res += ((s8)soundBuffer[5][soundIndex])>>1;
else else
@ -1152,8 +1044,7 @@ void soundMix()
res = (res * 170); res = (res * 170);
cgbRes = (cgbRes * 52 * soundLevel1); cgbRes = (cgbRes * 52 * soundLevel1);
switch(ratio) switch(ratio) {
{
case 0: case 0:
case 3: // prohibited, but 25% case 3: // prohibited, but 25%
cgbRes >>= 2; cgbRes >>= 2;
@ -1167,8 +1058,7 @@ void soundMix()
res += cgbRes; res += cgbRes;
if(soundEcho) if(soundEcho) {
{
res *= 2; res *= 2;
res += soundFilter[soundEchoIndex]; res += soundFilter[soundEchoIndex];
res /= 2; res /= 2;
@ -1178,8 +1068,7 @@ void soundMix()
soundEchoIndex = 0; soundEchoIndex = 0;
} }
if(soundLowPass) if(soundLowPass) {
{
soundRight[4] = soundRight[3]; soundRight[4] = soundRight[3];
soundRight[3] = soundRight[2]; soundRight[3] = soundRight[2];
soundRight[2] = soundRight[1]; soundRight[2] = soundRight[1];
@ -1189,8 +1078,7 @@ void soundMix()
soundRight[0])/14; soundRight[0])/14;
} }
switch(soundVolume) switch(soundVolume) {
{
case 0: case 0:
case 1: case 1:
case 2: case 2:
@ -1218,10 +1106,8 @@ void soundMix()
void soundTick() void soundTick()
{ {
if(systemSoundOn) if(systemSoundOn) {
{ if(soundMasterOn && !stopState) {
if(soundMasterOn && !stopState)
{
soundChannel1(); soundChannel1();
soundChannel2(); soundChannel2();
soundChannel3(); soundChannel3();
@ -1229,21 +1115,16 @@ void soundTick()
soundDirectSoundA(); soundDirectSoundA();
soundDirectSoundB(); soundDirectSoundB();
soundMix(); soundMix();
} } else {
else
{
soundFinalWave[soundBufferIndex++] = 0; soundFinalWave[soundBufferIndex++] = 0;
soundFinalWave[soundBufferIndex++] = 0; soundFinalWave[soundBufferIndex++] = 0;
} }
soundIndex++; soundIndex++;
if(2*soundBufferIndex >= soundBufferLen) if(2*soundBufferIndex >= soundBufferLen) {
{ if(systemSoundOn) {
if(systemSoundOn) if(soundPaused) {
{
if(soundPaused)
{
soundResume(); soundResume();
} }
@ -1369,15 +1250,13 @@ void soundReset()
int addr = 0x90; int addr = 0x90;
while(addr < 0xA0) while(addr < 0xA0) {
{
ioMem[addr++] = 0x00; ioMem[addr++] = 0x00;
ioMem[addr++] = 0xff; ioMem[addr++] = 0xff;
} }
addr = 0; addr = 0;
while(addr < 0x20) while(addr < 0x20) {
{
sound3WaveRam[addr++] = 0x00; sound3WaveRam[addr++] = 0x00;
sound3WaveRam[addr++] = 0xff; sound3WaveRam[addr++] = 0xff;
} }
@ -1390,8 +1269,7 @@ void soundReset()
bool soundInit() bool soundInit()
{ {
if(systemSoundInit()) if(systemSoundInit()) {
{
memset(soundBuffer[0], 0, 735*2); memset(soundBuffer[0], 0, 735*2);
memset(soundBuffer[1], 0, 735*2); memset(soundBuffer[1], 0, 735*2);
memset(soundBuffer[2], 0, 735*2); memset(soundBuffer[2], 0, 735*2);
@ -1407,8 +1285,7 @@ bool soundInit()
void soundSetQuality(int quality) void soundSetQuality(int quality)
{ {
if(soundQuality != quality && systemCanChangeSoundQuality()) if(soundQuality != quality && systemCanChangeSoundQuality()) {
{
if(!soundOffFlag) if(!soundOffFlag)
soundShutdown(); soundShutdown();
soundQuality = quality; soundQuality = quality;
@ -1418,9 +1295,7 @@ void soundSetQuality(int quality)
SOUND_CLOCK_TICKS = USE_TICKS_AS * soundQuality; SOUND_CLOCK_TICKS = USE_TICKS_AS * soundQuality;
soundIndex = 0; soundIndex = 0;
soundBufferIndex = 0; soundBufferIndex = 0;
} } else if(soundQuality != quality) {
else if(soundQuality != quality)
{
soundNextPosition = 0; soundNextPosition = 0;
SOUND_CLOCK_TICKS = USE_TICKS_AS * soundQuality; SOUND_CLOCK_TICKS = USE_TICKS_AS * soundQuality;
soundIndex = 0; soundIndex = 0;
@ -1439,12 +1314,9 @@ void soundSaveGame(gzFile gzFile)
void soundReadGame(gzFile gzFile, int version) void soundReadGame(gzFile gzFile, int version)
{ {
utilReadData(gzFile, soundSaveStruct); utilReadData(gzFile, soundSaveStruct);
if(version >= SAVE_GAME_VERSION_3) if(version >= SAVE_GAME_VERSION_3) {
{
utilReadData(gzFile, soundSaveStructV2); utilReadData(gzFile, soundSaveStructV2);
} } else {
else
{
sound3Bank = (ioMem[NR30] >> 6) & 1; sound3Bank = (ioMem[NR30] >> 6) & 1;
sound3DataSize = (ioMem[NR30] >> 5) & 1; sound3DataSize = (ioMem[NR30] >> 5) & 1;
sound3ForcedOutput = (ioMem[NR32] >> 7) & 1; sound3ForcedOutput = (ioMem[NR32] >> 7) & 1;

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,34 +20,31 @@
#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;
#else
typedef unsigned long long u64;
#endif
typedef signed char s8;
typedef signed short s16;
typedef signed int s32;
#ifdef _MSC_VER
typedef signed __int64 s64;
#else
typedef signed long long s64;
#endif
struct EmulatedSystem
{
// main emulation function // main emulation function
void (*emuMain)(int); void (*emuMain)(int);
// reset emulator // reset emulator
@ -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 *);

View File

@ -1,7 +1,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-2006 Forgotten and the VBA development team
// Copyright (C) 2007-2008 VBA-M development team and Shay Green
// 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
// the Free Software Foundation; either version 2, or(at your option) // the Free Software Foundation; either version 2, or(at your option)
@ -22,27 +22,22 @@
#include <string.h> #include <string.h>
#include <zlib.h> #include <zlib.h>
extern "C" #ifndef NO_PNG
{ extern "C" {
#include <png.h> #include <png.h>
} }
#if 0
#include "unrarlib.h"
#endif #endif
#include "System.h" #include "System.h"
#include "NLS.h" #include "NLS.h"
#include "Util.h" #include "Util.h"
#include "Flash.h" #include "Flash.h"
#include "GBA.h" #include "agb/GBA.h"
#include "Globals.h" #include "Globals.h"
#include "RTC.h" #include "RTC.h"
#include "Port.h" #include "Port.h"
extern "C" {
extern "C"
{
#include "memgzio.h" #include "memgzio.h"
} }
@ -50,19 +45,28 @@ extern "C"
#define _stricmp strcasecmp #define _stricmp strcasecmp
#endif // ! _MSC_VER #endif // ! _MSC_VER
extern int systemColorDepth;
extern int systemRedShift;
extern int systemGreenShift;
extern int systemBlueShift;
extern u16 systemColorMap16[0x10000];
//extern u32 systemColorMap32[0x10000];
extern u32 *systemColorMap32;
static int (*utilGzWriteFunc)(gzFile, const voidp, unsigned int) = NULL; static int (*utilGzWriteFunc)(gzFile, const voidp, unsigned int) = NULL;
static int (*utilGzReadFunc)(gzFile, voidp, unsigned int) = NULL; static int (*utilGzReadFunc)(gzFile, voidp, unsigned int) = NULL;
static int (*utilGzCloseFunc)(gzFile) = NULL; static int (*utilGzCloseFunc)(gzFile) = NULL;
static z_off_t (*utilGzSeekFunc)(gzFile, z_off_t, int) = NULL;
bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix) bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
{ {
#if 0 #ifndef NO_PNG
u8 writeBuffer[512 * 3]; u8 writeBuffer[512 * 3];
FILE* fp = gen_fopen(fileName,"wb"); FILE *fp = fopen(fileName,"wb");
if(!fp) if(!fp) {
{
systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName); systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName);
return false; return false;
} }
@ -71,23 +75,20 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
NULL, NULL,
NULL, NULL,
NULL); NULL);
if(!png_ptr) if(!png_ptr) {
{
gen_fclose(fp); gen_fclose(fp);
return false; return false;
} }
png_infop info_ptr = png_create_info_struct(png_ptr); png_infop info_ptr = png_create_info_struct(png_ptr);
if(!info_ptr) if(!info_ptr) {
{
png_destroy_write_struct(&png_ptr,NULL); png_destroy_write_struct(&png_ptr,NULL);
gen_fclose(fp); gen_fclose(fp);
return false; return false;
} }
if(setjmp(png_ptr->jmpbuf)) if(setjmp(png_ptr->jmpbuf)) {
{
png_destroy_write_struct(&png_ptr,NULL); png_destroy_write_struct(&png_ptr,NULL);
gen_fclose(fp); gen_fclose(fp);
return false; return false;
@ -112,15 +113,12 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
int sizeX = w; int sizeX = w;
int sizeY = h; int sizeY = h;
switch(systemColorDepth) switch(systemColorDepth) {
{
case 16: case 16:
{ {
u16 *p = (u16 *)(pix+(w+2)*2); // skip first black line u16 *p = (u16 *)(pix+(w+2)*2); // skip first black line
for(int y = 0; y < sizeY; y++) for(int y = 0; y < sizeY; y++) {
{ for(int x = 0; x < sizeX; x++) {
for(int x = 0; x < sizeX; x++)
{
u16 v = *p++; u16 v = *p++;
*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R *b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
@ -138,18 +136,13 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
case 24: case 24:
{ {
u8 *pixU8 = (u8 *)pix; u8 *pixU8 = (u8 *)pix;
for(int y = 0; y < sizeY; y++) for(int y = 0; y < sizeY; y++) {
{ for(int x = 0; x < sizeX; x++) {
for(int x = 0; x < sizeX; x++) if(systemRedShift < systemBlueShift) {
{
if(systemRedShift < systemBlueShift)
{
*b++ = *pixU8++; // R *b++ = *pixU8++; // R
*b++ = *pixU8++; // G *b++ = *pixU8++; // G
*b++ = *pixU8++; // B *b++ = *pixU8++; // B
} } else {
else
{
int blue = *pixU8++; int blue = *pixU8++;
int green = *pixU8++; int green = *pixU8++;
int red = *pixU8++; int red = *pixU8++;
@ -168,10 +161,8 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
case 32: case 32:
{ {
u32 *pixU32 = (u32 *)(pix+4*(w+1)); u32 *pixU32 = (u32 *)(pix+4*(w+1));
for(int y = 0; y < sizeY; y++) for(int y = 0; y < sizeY; y++) {
{ for(int x = 0; x < sizeX; x++) {
for(int x = 0; x < sizeX; x++)
{
u32 v = *pixU32++; u32 v = *pixU32++;
*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R *b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
@ -194,8 +185,10 @@ bool utilWritePNGFile(const char *fileName, int w, int h, u8 *pix)
gen_fclose(fp); gen_fclose(fp);
#endif
return true; return true;
#else
return false;
#endif
} }
void utilPutDword(u8 *p, u32 value) void utilPutDword(u8 *p, u32 value)
@ -212,97 +205,18 @@ void utilPutWord(u8 *p, u16 value)
*p = (value >> 8) & 255; *p = (value >> 8) & 255;
} }
void utilWriteBMP(char *buf, int w, int h, u8 *pix)
{
u8 *b = (u8 *)buf;
int sizeX = w;
int sizeY = h;
switch(systemColorDepth)
{
case 16:
{
u16 *p = (u16 *)(pix+(w+2)*(h)*2); // skip first black line
for(int y = 0; y < sizeY; y++)
{
for(int x = 0; x < sizeX; x++)
{
u16 v = *p++;
*b++ = ((v >> systemBlueShift) & 0x01f) << 3; // B
*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
}
p++; // skip black pixel for filters
p++; // skip black pixel for filters
p -= 2*(w+2);
}
}
break;
case 24:
{
u8 *pixU8 = (u8 *)pix+3*w*(h-1);
for(int y = 0; y < sizeY; y++)
{
for(int x = 0; x < sizeX; x++)
{
if(systemRedShift > systemBlueShift)
{
*b++ = *pixU8++; // B
*b++ = *pixU8++; // G
*b++ = *pixU8++; // R
}
else
{
int red = *pixU8++;
int green = *pixU8++;
int blue = *pixU8++;
*b++ = blue;
*b++ = green;
*b++ = red;
}
}
pixU8 -= 2*3*w;
}
}
break;
case 32:
{
u32 *pixU32 = (u32 *)(pix+4*(w+1)*(h));
for(int y = 0; y < sizeY; y++)
{
for(int x = 0; x < sizeX; x++)
{
u32 v = *pixU32++;
*b++ = ((v >> systemBlueShift) & 0x001f) << 3; // B
*b++ = ((v >> systemGreenShift) & 0x001f) << 3; // G
*b++ = ((v >> systemRedShift) & 0x001f) << 3; // R
}
pixU32++;
pixU32 -= 2*(w+1);
}
}
break;
}
}
bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix) bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
{ {
u8 writeBuffer[512 * 3]; u8 writeBuffer[512 * 3];
FILE *fp = gen_fopen(fileName,"wb"); FILE *fp = gen_fopen(fileName,"wb");
if(!fp) if(!fp) {
{
systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName); systemMessage(MSG_ERROR_CREATING_FILE, N_("Error creating file %s"), fileName);
return false; return false;
} }
struct struct {
{
u8 ident[2]; u8 ident[2];
u8 filesize[4]; u8 filesize[4];
u8 reserved[4]; u8 reserved[4];
@ -319,8 +233,7 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
u8 colors[4]; u8 colors[4];
u8 importantcolors[4]; u8 importantcolors[4];
// u8 pad[2]; // u8 pad[2];
} } bmpheader;
bmpheader;
memset(&bmpheader, 0, sizeof(bmpheader)); memset(&bmpheader, 0, sizeof(bmpheader));
bmpheader.ident[0] = 'B'; bmpheader.ident[0] = 'B';
@ -343,15 +256,12 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
int sizeX = w; int sizeX = w;
int sizeY = h; int sizeY = h;
switch(systemColorDepth) switch(systemColorDepth) {
{
case 16: case 16:
{ {
u16 *p = (u16 *)(pix+(w+2)*(h)*2); // skip first black line u16 *p = (u16 *)(pix+(w+2)*(h)*2); // skip first black line
for(int y = 0; y < sizeY; y++) for(int y = 0; y < sizeY; y++) {
{ for(int x = 0; x < sizeX; x++) {
for(int x = 0; x < sizeX; x++)
{
u16 v = *p++; u16 v = *p++;
*b++ = ((v >> systemBlueShift) & 0x01f) << 3; // B *b++ = ((v >> systemBlueShift) & 0x01f) << 3; // B
@ -370,18 +280,13 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
case 24: case 24:
{ {
u8 *pixU8 = (u8 *)pix+3*w*(h-1); u8 *pixU8 = (u8 *)pix+3*w*(h-1);
for(int y = 0; y < sizeY; y++) for(int y = 0; y < sizeY; y++) {
{ for(int x = 0; x < sizeX; x++) {
for(int x = 0; x < sizeX; x++) if(systemRedShift > systemBlueShift) {
{
if(systemRedShift > systemBlueShift)
{
*b++ = *pixU8++; // B *b++ = *pixU8++; // B
*b++ = *pixU8++; // G *b++ = *pixU8++; // G
*b++ = *pixU8++; // R *b++ = *pixU8++; // R
} } else {
else
{
int red = *pixU8++; int red = *pixU8++;
int green = *pixU8++; int green = *pixU8++;
int blue = *pixU8++; int blue = *pixU8++;
@ -401,10 +306,8 @@ bool utilWriteBMPFile(const char *fileName, int w, int h, u8 *pix)
case 32: case 32:
{ {
u32 *pixU32 = (u32 *)(pix+4*(w+1)*(h)); u32 *pixU32 = (u32 *)(pix+4*(w+1)*(h));
for(int y = 0; y < sizeY; y++) for(int y = 0; y < sizeY; y++) {
{ for(int x = 0; x < sizeX; x++) {
for(int x = 0; x < sizeX; x++)
{
u32 v = *pixU32++; u32 v = *pixU32++;
*b++ = ((v >> systemBlueShift) & 0x001f) << 3; // B *b++ = ((v >> systemBlueShift) & 0x001f) << 3; // B
@ -469,13 +372,11 @@ void utilApplyIPS(const char *ips, u8 **r, int *s)
gen_fgetc(f) == 'A' && gen_fgetc(f) == 'A' &&
gen_fgetc(f) == 'T' && gen_fgetc(f) == 'T' &&
gen_fgetc(f) == 'C' && gen_fgetc(f) == 'C' &&
gen_fgetc(f) == 'H') gen_fgetc(f) == 'H') {
{
int b; int b;
int offset; int offset;
int len; int len;
for(;;) for(;;) {
{
// read offset // read offset
offset = utilReadInt3(f); offset = utilReadInt3(f);
// if offset == EOF, end of patch // if offset == EOF, end of patch
@ -483,8 +384,7 @@ void utilApplyIPS(const char *ips, u8 **r, int *s)
break; break;
// read length // read length
len = utilReadInt2(f); len = utilReadInt2(f);
if(!len) if(!len) {
{
// len == 0, RLE block // len == 0, RLE block
len = utilReadInt2(f); len = utilReadInt2(f);
// byte to fill // byte to fill
@ -492,29 +392,22 @@ void utilApplyIPS(const char *ips, u8 **r, int *s)
if(c == -1) if(c == -1)
break; break;
b = (u8)c; b = (u8)c;
} } else
else
b= -1; b= -1;
// check if we need to reallocate our ROM // check if we need to reallocate our ROM
if((offset + len) >= size) if((offset + len) >= size) {
{
size *= 2; size *= 2;
rom = (u8 *)realloc(rom, size); rom = (u8 *)realloc(rom, size);
*r = rom; *r = rom;
*s = size; *s = size;
} }
if(b == -1) if(b == -1) {
{
// normal block, just read the data // normal block, just read the data
//if(gen_fread(&rom[offset], 1, len, f) != (size_t)len)
if(gen_fread(&rom[offset], 1, len, f) != (int)len) if(gen_fread(&rom[offset], 1, len, f) != (int)len)
break; break;
} } else {
else
{
// fill the region with the given byte // fill the region with the given byte
while(len--) while(len--) {
{
rom[offset++] = b; rom[offset++] = b;
} }
} }
@ -524,27 +417,26 @@ void utilApplyIPS(const char *ips, u8 **r, int *s)
gen_fclose(f); gen_fclose(f);
} }
//TODO: Modify ZSNES code for this
void utilApplyUPS(const char *ips, u8 **r, int *s)
{
}
extern bool cpuIsMultiBoot; extern bool cpuIsMultiBoot;
bool utilIsGBAImage(const char * file) bool utilIsGBAImage(const char * file)
{ {
cpuIsMultiBoot = false; cpuIsMultiBoot = false;
if(strlen(file) > 4) if(strlen(file) > 4) {
{ const char * p = strrchr(file,'.');
char * p = strrchr(file,'.');
if(p != NULL) if(p != NULL) {
{ if((_stricmp(p, ".agb") == 0) ||
if(_stricmp(p, ".gba") == 0) (_stricmp(p, ".gba") == 0) ||
(_stricmp(p, ".bin") == 0) ||
(_stricmp(p, ".elf") == 0))
return true; return true;
if(_stricmp(p, ".agb") == 0) if(_stricmp(p, ".mb") == 0) {
return true;
if(_stricmp(p, ".bin") == 0)
return true;
if(_stricmp(p, ".elf") == 0)
return true;
if(_stricmp(p, ".mb") == 0)
{
cpuIsMultiBoot = true; cpuIsMultiBoot = true;
return true; return true;
} }
@ -556,19 +448,15 @@ bool utilIsGBAImage(const char * file)
bool utilIsGBImage(const char * file) bool utilIsGBImage(const char * file)
{ {
if(strlen(file) > 4) if(strlen(file) > 4) {
{ const char * p = strrchr(file,'.');
char * p = strrchr(file,'.');
if(p != NULL) if(p != NULL) {
{ if((_stricmp(p, ".dmg") == 0) ||
if(_stricmp(p, ".gb") == 0) (_stricmp(p, ".gb") == 0) ||
return true; (_stricmp(p, ".gbc") == 0) ||
if(_stricmp(p, ".gbc") == 0) (_stricmp(p, ".cgb") == 0) ||
return true; (_stricmp(p, ".sgb") == 0))
if(_stricmp(p, ".cgb") == 0)
return true;
if(_stricmp(p, ".sgb") == 0)
return true; return true;
} }
} }
@ -591,33 +479,12 @@ bool utilIsZipFile(const char *file)
return false; return false;
} }
#if 0
bool utilIsRarFile(const char *file)
{
if(strlen(file) > 4)
{
char * p = strrchr(file,'.');
if(p != NULL)
{
if(_stricmp(p, ".rar") == 0)
return true;
}
}
return false;
}
#endif
bool utilIsGzipFile(const char *file) bool utilIsGzipFile(const char *file)
{ {
if(strlen(file) > 3) if(strlen(file) > 3) {
{ const char * p = strrchr(file,'.');
char * p = strrchr(file,'.');
if(p != NULL) if(p != NULL) {
{
if(_stricmp(p, ".gz") == 0) if(_stricmp(p, ".gz") == 0)
return true; return true;
if(_stricmp(p, ".z") == 0) if(_stricmp(p, ".z") == 0)
@ -628,12 +495,13 @@ bool utilIsGzipFile(const char *file)
return false; return false;
} }
void utilGetBaseName(const char *file, char *buffer) // strip .gz or .z off end
void utilStripDoubleExtension(const char *file, char *buffer)
{ {
if(buffer != file) // allows conversion in place
strcpy(buffer, file); strcpy(buffer, file);
if(utilIsGzipFile(file)) if(utilIsGzipFile(file)) {
{
char *p = strrchr(buffer, '.'); char *p = strrchr(buffer, '.');
if(p) if(p)
@ -641,6 +509,12 @@ void utilGetBaseName(const char *file, char *buffer)
} }
} }
static bool utilIsImage(const char *file)
{
return utilIsGBAImage(file) || utilIsGBImage(file);
}
IMAGE_TYPE utilFindType(const char *file) IMAGE_TYPE utilFindType(const char *file)
{ {
char buffer[2048]; char buffer[2048];
@ -658,10 +532,12 @@ IMAGE_TYPE utilFindType(const char *file)
int r = unzGoToFirstFile(unz); int r = unzGoToFirstFile(unz);
if(r != UNZ_OK) if(r != UNZ_OK)
{ {
unzClose(unz); unzClose(unz);
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file); systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
return IMAGE_UNKNOWN; return IMAGE_UNKNOWN;
} }
IMAGE_TYPE found = IMAGE_UNKNOWN; IMAGE_TYPE found = IMAGE_UNKNOWN;
@ -669,6 +545,7 @@ IMAGE_TYPE utilFindType(const char *file)
unz_file_info info; unz_file_info info;
while(true) while(true)
{ {
r = unzGetCurrentFileInfo(unz, r = unzGetCurrentFileInfo(unz,
&info, &info,
@ -680,9 +557,13 @@ IMAGE_TYPE utilFindType(const char *file)
0); 0);
if(r != UNZ_OK) if(r != UNZ_OK)
{ {
unzClose(unz); unzClose(unz);
systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file); systemMessage(MSG_BAD_ZIP_FILE, N_("Bad ZIP file %s"), file);
return IMAGE_UNKNOWN; return IMAGE_UNKNOWN;
} }
@ -712,42 +593,11 @@ IMAGE_TYPE utilFindType(const char *file)
return found; return found;
} }
return found; return found;
#if 0
}
else if(utilIsRarFile(file))
{
IMAGE_TYPE found = IMAGE_UNKNOWN;
ArchiveList_struct *rarList = NULL;
if(urarlib_list((void *)file, (ArchiveList_struct *)&rarList))
{
ArchiveList_struct *p = rarList;
while(p)
{
if(utilIsGBAImage(p->item.Name))
{
found = IMAGE_GBA;
break;
}
if(utilIsGBImage(p->item.Name))
{
found = IMAGE_GB;
break;
}
p = p->next;
}
urarlib_freelist(rarList);
}
return found;
#endif
} }
else else
{ {
if(utilIsGzipFile(file)) if(utilIsGzipFile(file))
utilGetBaseName(file, buffer); utilStripDoubleExtension(file, buffer);
else else
strcpy(buffer, file); strcpy(buffer, file);
@ -768,10 +618,12 @@ static int utilGetSize(int size)
} }
static u8 *utilLoadFromZip(const char *file, static u8 *utilLoadFromZip(const char *file,
bool (*accept)(const char *), bool (*accept)(const char *),
u8 *data, u8 *data,
int &size) int &size)
{ {
char buffer[2048]; char buffer[2048];
unzFile unz = unzOpen(file); unzFile unz = unzOpen(file);
@ -891,12 +743,16 @@ static u8 *utilLoadGzipFile(const char *file,
if(f == NULL) if(f == NULL)
{ {
systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file); systemMessage(MSG_ERROR_OPENING_IMAGE, N_("Error opening image %s"), file);
return NULL; return NULL;
} }
gen_fseek(f, -4, SEEK_END); gen_fseek(f, -4, SEEK_END);
int fileSize = gen_fgetc(f) | (gen_fgetc(f) << 8) | (gen_fgetc(f) << 16) | (gen_fgetc(f) << 24); int fileSize = gen_fgetc(f) | (gen_fgetc(f) << 8) | (gen_fgetc(f) << 16) | (gen_fgetc(f) << 24);
gen_fclose(f); gen_fclose(f);
if(size == 0) if(size == 0)
size = fileSize; size = fileSize;
@ -941,61 +797,6 @@ static u8 *utilLoadGzipFile(const char *file,
return image; return image;
} }
#if 0
static u8 *utilLoadRarFile(const char *file,
bool (*accept)(const char *),
u8 *data,
int &size)
{
char buffer[2048];
ArchiveList_struct *rarList = NULL;
if(urarlib_list((void *)file, (ArchiveList_struct *)&rarList))
{
ArchiveList_struct *p = rarList;
bool found = false;
while(p)
{
if(accept(p->item.Name))
{
strcpy(buffer, p->item.Name);
found = true;
break;
}
p = p->next;
}
if(found)
{
void *memory = NULL;
unsigned long lsize = 0;
size = p->item.UnpSize;
int r = urarlib_get((void *)&memory, &lsize, buffer, (void *)file, "");
if(!r)
{
systemMessage(MSG_ERROR_READING_IMAGE,
N_("Error reading image %s"), buffer);
urarlib_freelist(rarList);
return NULL;
}
u8 *image = (u8 *)memory;
if(data != NULL)
{
memcpy(image, data, size);
}
urarlib_freelist(rarList);
return image;
}
systemMessage(MSG_NO_IMAGE_ON_ZIP,
N_("No image found on RAR file %s"), file);
urarlib_freelist(rarList);
return NULL;
}
// nothing found
return NULL;
}
#endif
u8 *utilLoad(const char *file, u8 *utilLoad(const char *file,
bool (*accept)(const char *), bool (*accept)(const char *),
u8 *data, u8 *data,
@ -1009,12 +810,6 @@ u8 *utilLoad(const char *file,
{ {
return utilLoadGzipFile(file, accept, data, size); return utilLoadGzipFile(file, accept, data, size);
} }
#if 0
if(utilIsRarFile(file))
{
return utilLoadRarFile(file, accept, data, size);
}
#endif
u8 *image = data; u8 *image = data;
@ -1035,9 +830,13 @@ u8 *utilLoad(const char *file,
if(image == NULL) if(image == NULL)
{ {
image = (u8 *)malloc(utilGetSize(size)); image = (u8 *)malloc(utilGetSize(size));
if(image == NULL) if(image == NULL)
{ {
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"), systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"data"); "data");
gen_fclose(f); gen_fclose(f);
@ -1051,6 +850,11 @@ u8 *utilLoad(const char *file,
if(r != (int)read) if(r != (int)read)
{ {
systemMessage(MSG_ERROR_READING_IMAGE, systemMessage(MSG_ERROR_READING_IMAGE,
N_("Error reading image %s"), file); N_("Error reading image %s"), file);
if(data == NULL) if(data == NULL)
@ -1077,17 +881,23 @@ int utilReadInt(gzFile gzFile)
void utilReadData(gzFile gzFile, variable_desc* data) void utilReadData(gzFile gzFile, variable_desc* data)
{ {
while(data->address) while(data->address) {
{
utilGzRead(gzFile, data->address, data->size); utilGzRead(gzFile, data->address, data->size);
data++; data++;
} }
} }
void utilReadDataSkip(gzFile gzFile, variable_desc* data)
{
while(data->address) {
utilGzSeek(gzFile, data->size, SEEK_CUR);
data++;
}
}
void utilWriteData(gzFile gzFile, variable_desc *data) void utilWriteData(gzFile gzFile, variable_desc *data)
{ {
while(data->address) while(data->address) {
{
utilGzWrite(gzFile, data->address, data->size); utilGzWrite(gzFile, data->address, data->size);
data++; data++;
} }
@ -1098,11 +908,12 @@ gzFile utilGzOpen(const char *file, const char *mode)
utilGzWriteFunc = (int (*)(void *,void * const, unsigned int))gzwrite; utilGzWriteFunc = (int (*)(void *,void * const, unsigned int))gzwrite;
utilGzReadFunc = gzread; utilGzReadFunc = gzread;
utilGzCloseFunc = gzclose; utilGzCloseFunc = gzclose;
utilGzSeekFunc = gzseek;
return gzopen(file, mode); return gzopen(file, mode);
} }
gzFile utilMemGzOpen(char *memory, int available, char *mode) gzFile utilMemGzOpen(char *memory, int available, const char *mode)
{ {
utilGzWriteFunc = memgzwrite; utilGzWriteFunc = memgzwrite;
utilGzReadFunc = memgzread; utilGzReadFunc = memgzread;
@ -1126,6 +937,11 @@ int utilGzClose(gzFile file)
return utilGzCloseFunc(file); return utilGzCloseFunc(file);
} }
z_off_t utilGzSeek(gzFile file, z_off_t offset, int whence)
{
return utilGzSeekFunc(file, offset, whence);
}
long utilGzMemTell(gzFile file) long utilGzMemTell(gzFile file)
{ {
return memtell(file); return memtell(file);
@ -1139,58 +955,67 @@ void utilGBAFindSave(const u8 *data, const int size)
int flashSize = 0x10000; int flashSize = 0x10000;
bool rtcFound = false; bool rtcFound = false;
while(p < end) while(p < end) {
{
u32 d = READ32LE(p); u32 d = READ32LE(p);
if(d == 0x52504545) if(d == 0x52504545) {
{ if(memcmp(p, "EEPROM_", 7) == 0) {
if(memcmp(p, "EEPROM_", 7) == 0) if(saveType == 0)
{ saveType = 3;
}
} else if (d == 0x4D415253) {
if(memcmp(p, "SRAM_", 5) == 0) {
if(saveType == 0) if(saveType == 0)
saveType = 1; saveType = 1;
} }
} } else if (d == 0x53414C46) {
else if (d == 0x4D415253) if(memcmp(p, "FLASH1M_", 8) == 0) {
{ if(saveType == 0) {
if(memcmp(p, "SRAM_", 5) == 0)
{
if(saveType == 0)
saveType = 2; saveType = 2;
}
}
else if (d == 0x53414C46)
{
if(memcmp(p, "FLASH1M_", 8) == 0)
{
if(saveType == 0)
{
saveType = 3;
flashSize = 0x20000; flashSize = 0x20000;
} }
} } else if(memcmp(p, "FLASH", 5) == 0) {
else if(memcmp(p, "FLASH", 5) == 0) if(saveType == 0) {
{ saveType = 2;
if(saveType == 0)
{
saveType = 3;
flashSize = 0x10000; flashSize = 0x10000;
} }
} }
} } else if (d == 0x52494953) {
else if (d == 0x52494953)
{
if(memcmp(p, "SIIRTC_V", 8) == 0) if(memcmp(p, "SIIRTC_V", 8) == 0)
rtcFound = true; rtcFound = true;
} }
p++; p++;
} }
// if no matches found, then set it to NONE // if no matches found, then set it to NONE
if(saveType == 0) if(saveType == 0) {
{
saveType = 5; saveType = 5;
} }
rtcEnable(rtcFound); rtcEnable(rtcFound);
cpuSaveType = saveType; cpuSaveType = saveType;
flashSetSize(flashSize); flashSetSize(flashSize);
} }
void utilUpdateSystemColorMaps()
{
switch(systemColorDepth) {
case 16:
{
for(int i = 0; i < 0x10000; i++) {
systemColorMap16[i] = ((i & 0x1f) << systemRedShift) |
(((i & 0x3e0) >> 5) << systemGreenShift) |
(((i & 0x7c00) >> 10) << systemBlueShift);
}
}
break;
case 24:
case 32:
{
for(int i = 0; i < 0x10000; i++) {
systemColorMap32[i] = ((i & 0x1f) << systemRedShift) |
(((i & 0x3e0) >> 5) << systemGreenShift) |
(((i & 0x7c00) >> 10) << systemBlueShift);
}
}
break;
}
}

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,23 +30,18 @@ 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*),
@ -54,13 +52,16 @@ 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

View File

@ -41,8 +41,7 @@
extern "C" bool cpu_mmx; extern "C" bool cpu_mmx;
#endif #endif
static void internal_scale2x_16_def(u16 *dst, const u16* src0, const u16* src1, const u16* src2, unsigned count) static void internal_scale2x_16_def(u16 *dst, const u16* src0, const u16* src1, const u16* src2, unsigned count) {
{
/* first pixel */ /* first pixel */
dst[0] = src1[0]; dst[0] = src1[0];
if (src1[1] == src0[0] && src2[0] != src0[0]) if (src1[1] == src0[0] && src2[0] != src0[0])
@ -56,15 +55,11 @@ static void internal_scale2x_16_def(u16 *dst, const u16* src0, const u16* src1,
/* central pixels */ /* central pixels */
count -= 2; count -= 2;
while (count) while (count) {
{ if (src0[0] != src2[0] && src1[-1] != src1[1]) {
if (src0[0] != src2[0] && src1[-1] != src1[1])
{
dst[0] = src1[-1] == src0[0] ? src0[0] : src1[0]; dst[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
dst[1] = src1[1] == src0[0] ? src0[0] : src1[0]; dst[1] = src1[1] == src0[0] ? src0[0] : src1[0];
} } else {
else
{
dst[0] = src1[0]; dst[0] = src1[0];
dst[1] = src1[0]; dst[1] = src1[0];
} }
@ -103,15 +98,11 @@ static void internal_scale2x_32_def(u32* dst,
/* central pixels */ /* central pixels */
count -= 2; count -= 2;
while (count) while (count) {
{ if (src0[0] != src2[0] && src1[-1] != src1[1]) {
if (src0[0] != src2[0] && src1[-1] != src1[1])
{
dst[0] = src1[-1] == src0[0] ? src0[0] : src1[0]; dst[0] = src1[-1] == src0[0] ? src0[0] : src1[0];
dst[1] = src1[1] == src0[0] ? src0[0] : src1[0]; dst[1] = src1[1] == src0[0] ? src0[0] : src1[0];
} } else {
else
{
dst[0] = src1[0]; dst[0] = src1[0];
dst[1] = src1[0]; dst[1] = src1[0];
} }
@ -132,8 +123,7 @@ static void internal_scale2x_32_def(u32* dst,
} }
#ifdef MMX #ifdef MMX
static void internal_scale2x_16_mmx_single(u16* dst, const u16* src0, const u16* src1, const u16* src2, unsigned count) static void internal_scale2x_16_mmx_single(u16* dst, const u16* src0, const u16* src1, const u16* src2, unsigned count) {
{
/* always do the first and last run */ /* always do the first and last run */
count -= 2*4; count -= 2*4;
@ -515,8 +505,7 @@ static void internal_scale2x_16_mmx_single(u16* dst, const u16* src0, const u16*
#endif #endif
} }
static void internal_scale2x_32_mmx_single(u32* dst, const u32* src0, const u32* src1, const u32* src2, unsigned count) static void internal_scale2x_32_mmx_single(u32* dst, const u32* src0, const u32* src1, const u32* src2, unsigned count) {
{
/* always do the first and last run */ /* always do the first and last run */
count -= 2*2; count -= 2*2;
@ -897,15 +886,13 @@ static void internal_scale2x_32_mmx_single(u32* dst, const u32* src0, const u32*
#endif #endif
} }
static void internal_scale2x_16_mmx(u16* dst0, u16* dst1, const u16* src0, const u16* src1, const u16* src2, unsigned count) static void internal_scale2x_16_mmx(u16* dst0, u16* dst1, const u16* src0, const u16* src1, const u16* src2, unsigned count) {
{
// assert( count >= 2*4 ); // assert( count >= 2*4 );
internal_scale2x_16_mmx_single(dst0, src0, src1, src2, count); internal_scale2x_16_mmx_single(dst0, src0, src1, src2, count);
internal_scale2x_16_mmx_single(dst1, src2, src1, src0, count); internal_scale2x_16_mmx_single(dst1, src2, src1, src0, count);
} }
static void internal_scale2x_32_mmx(u32* dst0, u32* dst1, const u32* src0, const u32* src1, const u32* src2, unsigned count) static void internal_scale2x_32_mmx(u32* dst0, u32* dst1, const u32* src0, const u32* src1, const u32* src2, unsigned count) {
{
// assert( count >= 2*2 ); // assert( count >= 2*2 );
internal_scale2x_32_mmx_single(dst0, src0, src1, src2, count); internal_scale2x_32_mmx_single(dst0, src0, src1, src2, count);
internal_scale2x_32_mmx_single(dst1, src2, src1, src0, count); internal_scale2x_32_mmx_single(dst1, src2, src1, src0, count);
@ -922,15 +909,13 @@ void AdMame2x(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u16 *src1 = src0 + (srcPitch >> 1); u16 *src1 = src0 + (srcPitch >> 1);
u16 *src2 = src1 + (srcPitch >> 1); u16 *src2 = src1 + (srcPitch >> 1);
#ifdef MMX #ifdef MMX
if(cpu_mmx) if(cpu_mmx) {
{
internal_scale2x_16_mmx(dst0, dst1, src0, src0, src1, width); internal_scale2x_16_mmx(dst0, dst1, src0, src0, src1, width);
int count = height; int count = height;
count -= 2; count -= 2;
while(count) while(count) {
{
dst0 += dstPitch; dst0 += dstPitch;
dst1 += dstPitch; dst1 += dstPitch;
internal_scale2x_16_mmx(dst0, dst1, src0, src1, src2, width); internal_scale2x_16_mmx(dst0, dst1, src0, src1, src2, width);
@ -942,9 +927,7 @@ void AdMame2x(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
dst0 += dstPitch; dst0 += dstPitch;
dst1 += dstPitch; dst1 += dstPitch;
internal_scale2x_16_mmx(dst0, dst1, src0, src1, src1, width); internal_scale2x_16_mmx(dst0, dst1, src0, src1, src1, width);
} } else {
else
{
#endif #endif
internal_scale2x_16_def(dst0, src0, src0, src1, width); internal_scale2x_16_def(dst0, src0, src0, src1, width);
internal_scale2x_16_def(dst1, src1, src0, src0, width); internal_scale2x_16_def(dst1, src1, src0, src0, width);
@ -952,8 +935,7 @@ void AdMame2x(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
int count = height; int count = height;
count -= 2; count -= 2;
while(count) while(count) {
{
dst0 += dstPitch; dst0 += dstPitch;
dst1 += dstPitch; dst1 += dstPitch;
internal_scale2x_16_def(dst0, src0, src1, src2, width); internal_scale2x_16_def(dst0, src0, src1, src2, width);
@ -982,15 +964,13 @@ void AdMame2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
u32 *src1 = src0 + (srcPitch >> 2); u32 *src1 = src0 + (srcPitch >> 2);
u32 *src2 = src1 + (srcPitch >> 2); u32 *src2 = src1 + (srcPitch >> 2);
#ifdef MMX #ifdef MMX
if(cpu_mmx) if(cpu_mmx) {
{
internal_scale2x_32_mmx(dst0, dst1, src0, src0, src1, width); internal_scale2x_32_mmx(dst0, dst1, src0, src0, src1, width);
int count = height; int count = height;
count -= 2; count -= 2;
while(count) while(count) {
{
dst0 += dstPitch >> 1; dst0 += dstPitch >> 1;
dst1 += dstPitch >> 1; dst1 += dstPitch >> 1;
internal_scale2x_32_mmx(dst0, dst1, src0, src1, src2, width); internal_scale2x_32_mmx(dst0, dst1, src0, src1, src2, width);
@ -1002,9 +982,7 @@ void AdMame2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
dst0 += dstPitch >> 1; dst0 += dstPitch >> 1;
dst1 += dstPitch >> 1; dst1 += dstPitch >> 1;
internal_scale2x_32_mmx(dst0, dst1, src0, src1, src1, width); internal_scale2x_32_mmx(dst0, dst1, src0, src1, src1, width);
} } else {
else
{
#endif #endif
internal_scale2x_32_def(dst0, src0, src0, src1, width); internal_scale2x_32_def(dst0, src0, src0, src1, width);
internal_scale2x_32_def(dst1, src1, src0, src0, width); internal_scale2x_32_def(dst1, src1, src0, src0, width);
@ -1012,8 +990,7 @@ void AdMame2x32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
int count = height; int count = height;
count -= 2; count -= 2;
while(count) while(count) {
{
dst0 += dstPitch >> 1; dst0 += dstPitch >> 1;
dst1 += dstPitch >> 1; dst1 += dstPitch >> 1;
internal_scale2x_32_def(dst0, src0, src1, src2, width); internal_scale2x_32_def(dst0, src0, src1, src2, width);

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,18 +30,17 @@
#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;
@ -53,10 +52,8 @@ typedef union {
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;
@ -64,8 +61,7 @@ typedef union {
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
@ -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,13 +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 "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];
u32 line2[240]; u32 line2[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,21 +35,16 @@ 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)
{ // protect
agbPrintProtect = (value != 0); agbPrintProtect = (value != 0);
debuggerWriteHalfWord(address, value); debuggerWriteHalfWord(address, value);
return true; return true;
} } else {
else
{
if(agbPrintProtect && if(agbPrintProtect &&
((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
|| (address >= 0x8fd0000 && address <= 0x8fdffff) || (address >= 0x8fd0000 && address <= 0x8fdffff)
|| (address >= 0x9fd0000 && address <= 0x9fdffff))) || (address >= 0x9fd0000 && address <= 0x9fdffff))) {
{
debuggerWriteHalfWord(address, value); debuggerWriteHalfWord(address, value);
return true; return true;
} }
@ -72,16 +68,13 @@ 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);
@ -90,8 +83,7 @@ void agbPrintFlush()
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;

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
@ -23,15 +23,14 @@
#include "System.h" #include "System.h"
#include "Port.h" #include "Port.h"
#include "GBA.h" #include "agb/GBA.h"
#include "armdis.h" #include "armdis.h"
#include "elf.h" #include "elf.h"
struct Opcodes struct Opcodes {
{
u32 mask; u32 mask;
u32 cval; u32 cval;
char *mnemonic; const char *mnemonic;
}; };
#define debuggerReadMemory(addr) \ #define debuggerReadMemory(addr) \
@ -45,31 +44,26 @@ struct Opcodes
const char hdig[] = "0123456789abcdef"; const char hdig[] = "0123456789abcdef";
const char *decVals[16] = const char *decVals[16] = {
{
"0","1","2","3","4","5","6","7","8", "0","1","2","3","4","5","6","7","8",
"9","10","11","12","13","14","15" "9","10","11","12","13","14","15"
}; };
const char *regs[16] = const char *regs[16] = {
{
"r0","r1","r2","r3","r4","r5","r6","r7", "r0","r1","r2","r3","r4","r5","r6","r7",
"r8","r9","r10","r11","r12","sp","lr","pc" "r8","r9","r10","r11","r12","sp","lr","pc"
}; };
const char *conditions[16] = const char *conditions[16] = {
{
"eq","ne","cs","cc","mi","pl","vs","vc", "eq","ne","cs","cc","mi","pl","vs","vc",
"hi","ls","ge","lt","gt","le","","nv" "hi","ls","ge","lt","gt","le","","nv"
}; };
const char *shifts[5] = const char *shifts[5] = {
{
"lsl","lsr","asr","ror","rrx" "lsl","lsr","asr","ror","rrx"
}; };
const char *armMultLoadStore[12] = const char *armMultLoadStore[12] = {
{
// non-stack // non-stack
"da","ia","db","ib", "da","ia","db","ib",
// stack store // stack store
@ -78,8 +72,7 @@ const char *armMultLoadStore[12] =
"fa","fd","ea","ed" "fa","fd","ea","ed"
}; };
const Opcodes thumbOpcodes[] = const Opcodes thumbOpcodes[] = {
{
// Format 1 // Format 1
{0xf800, 0x0000, "lsl %r0, %r3, %o"}, {0xf800, 0x0000, "lsl %r0, %r3, %o"},
{0xf800, 0x0800, "lsr %r0, %r3, %o"}, {0xf800, 0x0800, "lsr %r0, %r3, %o"},
@ -124,8 +117,8 @@ const Opcodes thumbOpcodes[] =
{0xfa00, 0x5800, "ldr%b %r0, [%r3, %r6]"}, {0xfa00, 0x5800, "ldr%b %r0, [%r3, %r6]"},
// Format 8 // Format 8
{0xfe00, 0x5200, "strh %r0, [%r3, %r6]"}, {0xfe00, 0x5200, "strh %r0, [%r3, %r6]"},
{0xfe00, 0x5600, "ldrh %r0, [%r3, %r6]"}, {0xfe00, 0x5600, "ldsb %r0, [%r3, %r6]"},
{0xfe00, 0x5a00, "ldsb %r0, [%r3, %r6]"}, {0xfe00, 0x5a00, "ldrh %r0, [%r3, %r6]"},
{0xfe00, 0x5e00, "ldsh %r0, [%r3, %r6]"}, {0xfe00, 0x5e00, "ldsh %r0, [%r3, %r6]"},
// Format 9 // Format 9
{0xe800, 0x6000, "str%B %r0, [%r3, %p]"}, {0xe800, 0x6000, "str%B %r0, [%r3, %p]"},
@ -165,8 +158,7 @@ const Opcodes thumbOpcodes[] =
{0x0000, 0x0000, "[ ??? ]"} {0x0000, 0x0000, "[ ??? ]"}
}; };
const Opcodes armOpcodes[] = const Opcodes armOpcodes[] = {
{
// Undefined // Undefined
{0x0e000010, 0x06000010, "[ undefined ]"}, {0x0e000010, 0x06000010, "[ undefined ]"},
// Branch instructions // Branch instructions
@ -217,61 +209,50 @@ const Opcodes armOpcodes[] =
{0x00000000, 0x00000000, "[ ??? ]"} {0x00000000, 0x00000000, "[ ??? ]"}
}; };
char* addStr(char *dest, const char *src) char* addStr(char *dest, const char *src){
{ while (*src){
while (*src)
{
*dest++ = *src++; *dest++ = *src++;
} }
return dest; return dest;
} }
char* addHex(char *dest, int siz, u32 val) char* addHex(char *dest, int siz, u32 val){
{ if (siz==0){
if (siz==0)
{
siz = 28; siz = 28;
while ( (((val>>siz)&15)==0) && (siz>=4) ) while ( (((val>>siz)&15)==0) && (siz>=4) )
siz -= 4; siz -= 4;
siz += 4; siz += 4;
} }
while (siz>0) while (siz>0){
{
siz -= 4; siz -= 4;
*dest++ = hdig[(val>>siz)&15]; *dest++ = hdig[(val>>siz)&15];
} }
return dest; return dest;
} }
int disArm(u32 offset, char *dest, int flags) int disArm(u32 offset, char *dest, int flags){
{
u32 opcode = debuggerReadMemory(offset); u32 opcode = debuggerReadMemory(offset);
const Opcodes *sp = armOpcodes; const Opcodes *sp = armOpcodes;
while( sp->cval != (opcode & sp->mask) ) while( sp->cval != (opcode & sp->mask) )
sp++; sp++;
if (flags&DIS_VIEW_ADDRESS) if (flags&DIS_VIEW_ADDRESS){
{
dest = addHex(dest, 32, offset); dest = addHex(dest, 32, offset);
*dest++ = ' '; *dest++ = ' ';
} }
if (flags&DIS_VIEW_CODE) if (flags&DIS_VIEW_CODE){
{
dest = addHex(dest, 32, opcode); dest = addHex(dest, 32, opcode);
*dest++ = ' '; *dest++ = ' ';
} }
char *src = sp->mnemonic; const char *src = sp->mnemonic;
while (*src) while (*src){
{
if (*src!='%') if (*src!='%')
*dest++ = *src++; *dest++ = *src++;
else else{
{
src++; src++;
switch (*src) switch (*src){
{
case 'c': case 'c':
dest = addStr(dest, conditions[opcode>>28]); dest = addStr(dest, conditions[opcode>>28]);
break; break;
@ -289,36 +270,28 @@ int disArm(u32 offset, char *dest, int flags)
} }
break; break;
case 'i': case 'i':
if (opcode&(1<<25)) if (opcode&(1<<25)){
{
dest = addStr(dest, "#0x"); dest = addStr(dest, "#0x");
int imm = opcode&0xff; int imm = opcode&0xff;
int rot = (opcode&0xf00)>>7; int rot = (opcode&0xf00)>>7;
int val = (imm<<(32-rot))|(imm>>rot); int val = (imm<<(32-rot))|(imm>>rot);
dest = addHex(dest, 0, val); dest = addHex(dest, 0, val);
} } else{
else
{
dest = addStr(dest, regs[opcode&0x0f]); dest = addStr(dest, regs[opcode&0x0f]);
int shi = (opcode>>5)&3; int shi = (opcode>>5)&3;
int sdw = (opcode>>7)&0x1f; int sdw = (opcode>>7)&0x1f;
if ((sdw==0)&&(shi==3)) if ((sdw==0)&&(shi==3))
shi = 4; shi = 4;
if ( (sdw) || (opcode&0x10) || (shi)) if ( (sdw) || (opcode&0x10) || (shi)) {
{
dest = addStr(dest, ", "); dest = addStr(dest, ", ");
dest = addStr(dest, shifts[shi]); dest = addStr(dest, shifts[shi]);
if (opcode&0x10) if (opcode&0x10){
{
*dest++ = ' '; *dest++ = ' ';
dest = addStr(dest, regs[(opcode>>8)&15]); dest = addStr(dest, regs[(opcode>>8)&15]);
} } else {
else
{
if (sdw==0 && ( (shi==1) || (shi==2) )) if (sdw==0 && ( (shi==1) || (shi==2) ))
sdw = 32; sdw = 32;
if(shi != 4) if(shi != 4) {
{
dest = addStr(dest, " #0x"); dest = addStr(dest, " #0x");
dest = addHex(dest, 8, sdw); dest = addHex(dest, 8, sdw);
} }
@ -331,8 +304,7 @@ int disArm(u32 offset, char *dest, int flags)
dest = addStr(dest, "spsr"); dest = addStr(dest, "spsr");
else else
dest = addStr(dest, "cpsr"); dest = addStr(dest, "cpsr");
if(opcode & 0x00F00000) if(opcode & 0x00F00000) {
{
*dest++ = '_'; *dest++ = '_';
if(opcode & 0x00080000) if(opcode & 0x00080000)
*dest++ = 'f'; *dest++ = 'f';
@ -363,8 +335,7 @@ int disArm(u32 offset, char *dest, int flags)
*dest++ = 'b'; *dest++ = 'b';
break; break;
case 'a': case 'a':
if ((opcode&0x076f0000)==0x004f0000) if ((opcode&0x076f0000)==0x004f0000){
{
*dest++ = '['; *dest++ = '[';
*dest++ = '$'; *dest++ = '$';
int adr = offset+8; int adr = offset+8;
@ -380,8 +351,7 @@ int disArm(u32 offset, char *dest, int flags)
dest = addHex(dest ,32, debuggerReadMemory(adr)); dest = addHex(dest ,32, debuggerReadMemory(adr));
*dest++=')'; *dest++=')';
} }
if ((opcode&0x072f0000)==0x050f0000) if ((opcode&0x072f0000)==0x050f0000){
{
*dest++ = '['; *dest++ = '[';
*dest++ = '$'; *dest++ = '$';
int adr = offset+8; int adr = offset+8;
@ -395,34 +365,26 @@ int disArm(u32 offset, char *dest, int flags)
*dest++ = '$'; *dest++ = '$';
dest = addHex(dest ,32, debuggerReadMemory(adr)); dest = addHex(dest ,32, debuggerReadMemory(adr));
*dest++=')'; *dest++=')';
} } else {
else
{
int reg = (opcode>>16)&15; int reg = (opcode>>16)&15;
*dest++ = '['; *dest++ = '[';
dest = addStr(dest, regs[reg]); dest = addStr(dest, regs[reg]);
if (!(opcode&(1<<24))) if (!(opcode&(1<<24)))
*dest++ = ']'; *dest++ = ']';
if ( ((opcode&(1<<25))&&(opcode&(1<<26))) || (!(opcode&(1<<22))&&!(opcode&(1<<26))) ) if ( ((opcode&(1<<25))&&(opcode&(1<<26))) || (!(opcode&(1<<22))&&!(opcode&(1<<26))) ){
{
dest = addStr(dest, ", "); dest = addStr(dest, ", ");
if (!(opcode&(1<<23))) if (!(opcode&(1<<23)))
*dest++ = '-'; *dest++ = '-';
dest = addStr(dest, regs[opcode&0x0f]); dest = addStr(dest, regs[opcode&0x0f]);
int shi = (opcode>>5)&3; int shi = (opcode>>5)&3;
if (opcode&(1<<26)) if (opcode&(1<<26)){
{ if ( ((opcode>>7)&0x1f) || (opcode&0x10) || (shi==1) || (shi==2)){
if ( ((opcode>>7)&0x1f) || (opcode&0x10) || (shi==1) || (shi==2))
{
dest = addStr(dest, ", "); dest = addStr(dest, ", ");
dest = addStr(dest, shifts[shi]); dest = addStr(dest, shifts[shi]);
if (opcode&0x10) if (opcode&0x10){
{
*dest++ = ' '; *dest++ = ' ';
dest = addStr(dest, regs[(opcode>>8)&15]); dest = addStr(dest, regs[(opcode>>8)&15]);
} } else {
else
{
int sdw = (opcode>>7)&0x1f; int sdw = (opcode>>7)&0x1f;
if (sdw==0 && ( (shi==1) || (shi==2) )) if (sdw==0 && ( (shi==1) || (shi==2) ))
sdw = 32; sdw = 32;
@ -431,16 +393,13 @@ int disArm(u32 offset, char *dest, int flags)
} }
} }
} }
} } else {
else
{
int off; int off;
if (opcode&(1<<26)) if (opcode&(1<<26))
off = opcode&0xfff; off = opcode&0xfff;
else else
off = (opcode&15)|((opcode>>4)&0xf0); off = (opcode&15)|((opcode>>4)&0xf0);
if (off) if (off){
{
dest = addStr(dest, ", "); dest = addStr(dest, ", ");
if (!(opcode&(1<<23))) if (!(opcode&(1<<23)))
*dest++ = '-'; *dest++ = '-';
@ -448,8 +407,7 @@ int disArm(u32 offset, char *dest, int flags)
dest = addHex(dest, 0, off); dest = addHex(dest, 0, off);
} }
} }
if (opcode&(1<<24)) if (opcode&(1<<24)){
{
*dest++ = ']'; *dest++ = ']';
if (opcode&(1<<21)) if (opcode&(1<<21))
*dest++ = '!'; *dest++ = '!';
@ -469,14 +427,12 @@ int disArm(u32 offset, char *dest, int flags)
*dest++ = 'b'; *dest++ = 'b';
break; break;
case 'm': case 'm':
if (((opcode>>16)&15)==13) if (((opcode>>16)&15)==13) {
{
if(opcode & 0x00100000) if(opcode & 0x00100000)
dest = addStr(dest, armMultLoadStore[8+((opcode>>23)&3)]); dest = addStr(dest, armMultLoadStore[8+((opcode>>23)&3)]);
else else
dest = addStr(dest, armMultLoadStore[4+((opcode>>23)&3)]); dest = addStr(dest, armMultLoadStore[4+((opcode>>23)&3)]);
} } else
else
dest = addStr(dest, armMultLoadStore[(opcode>>23)&3]); dest = addStr(dest, armMultLoadStore[(opcode>>23)&3]);
break; break;
case 'l': case 'l':
@ -487,10 +443,8 @@ int disArm(u32 offset, char *dest, int flags)
int rlst = opcode&0xffff; int rlst = opcode&0xffff;
int msk = 0; int msk = 0;
int not_first = 0; int not_first = 0;
while (msk<16) while (msk<16){
{ if (rlst&(1<<msk)){
if (rlst&(1<<msk))
{
int fr = msk; int fr = msk;
while (rlst&(1<<msk)) while (rlst&(1<<msk))
msk++; msk++;
@ -499,8 +453,7 @@ int disArm(u32 offset, char *dest, int flags)
//dest = addStr(dest, ", "); //dest = addStr(dest, ", ");
*dest++ = ','; *dest++ = ',';
dest = addStr(dest, regs[fr]); dest = addStr(dest, regs[fr]);
if (fr!=to) if (fr!=to){
{
if (fr==to-1) if (fr==to-1)
//dest = addStr(", "); //dest = addStr(", ");
*dest++ = ','; *dest++ = ',';
@ -509,8 +462,7 @@ int disArm(u32 offset, char *dest, int flags)
dest = addStr(dest, regs[to]); dest = addStr(dest, regs[to]);
} }
not_first = 1; not_first = 1;
} } else
else
msk++; msk++;
} }
*dest++ = '}'; *dest++ = '}';
@ -543,8 +495,7 @@ int disArm(u32 offset, char *dest, int flags)
case 'V': case 'V':
{ {
int val = (opcode>>5)&7; int val = (opcode>>5)&7;
if (val) if (val){
{
dest = addStr(dest, ", "); dest = addStr(dest, ", ");
dest = addStr(dest, decVals[val]); dest = addStr(dest, decVals[val]);
} }
@ -555,8 +506,7 @@ int disArm(u32 offset, char *dest, int flags)
*dest++ = 'l'; *dest++ = 'l';
break; break;
case 'A': case 'A':
if ((opcode&0x012f0000)==0x010f0000) if ((opcode&0x012f0000)==0x010f0000){
{
int adr = offset+8; int adr = offset+8;
int add = (opcode&0xff)<<2; int add = (opcode&0xff)<<2;
if (opcode&(1<<23)) if (opcode&(1<<23))
@ -565,24 +515,20 @@ int disArm(u32 offset, char *dest, int flags)
adr -= add; adr -= add;
*dest++ = '$'; *dest++ = '$';
addHex(dest, 32, adr); addHex(dest, 32, adr);
} } else {
else
{
*dest++ = '['; *dest++ = '[';
dest = addStr(dest, regs[(opcode>>16)&15]); dest = addStr(dest, regs[(opcode>>16)&15]);
if (!(opcode&(1<<24))) if (!(opcode&(1<<24)))
*dest++ = ']'; *dest++ = ']';
int off = (opcode&0xff)<<2; int off = (opcode&0xff)<<2;
if (off) if (off){
{
dest = addStr(dest, ", "); dest = addStr(dest, ", ");
if (!(opcode&(1<<23))) if (!(opcode&(1<<23)))
*dest++ = '-'; *dest++ = '-';
dest = addStr(dest, "#0x"); dest = addStr(dest, "#0x");
dest = addHex(dest, 0, off); dest = addHex(dest, 0, off);
} }
if (opcode&(1<<24)) if (opcode&(1<<24)){
{
*dest++ = ']'; *dest++ = ']';
if (opcode&(1<<21)) if (opcode&(1<<21))
*dest++ = '!'; *dest++ = '!';
@ -598,8 +544,7 @@ int disArm(u32 offset, char *dest, int flags)
return 4; return 4;
} }
int disThumb(u32 offset, char *dest, int flags) int disThumb(u32 offset, char *dest, int flags){
{
u32 opcode = debuggerReadHalfWord(offset); u32 opcode = debuggerReadHalfWord(offset);
const Opcodes *sp = thumbOpcodes; const Opcodes *sp = thumbOpcodes;
@ -607,27 +552,22 @@ int disThumb(u32 offset, char *dest, int flags)
while( sp->cval != (opcode & sp->mask) ) while( sp->cval != (opcode & sp->mask) )
sp++; sp++;
if (flags&DIS_VIEW_ADDRESS) if (flags&DIS_VIEW_ADDRESS){
{
dest = addHex(dest, 32, offset); dest = addHex(dest, 32, offset);
*dest++ = ' '; *dest++ = ' ';
} }
if (flags&DIS_VIEW_CODE) if (flags&DIS_VIEW_CODE){
{
dest = addHex(dest, 16, opcode); dest = addHex(dest, 16, opcode);
*dest++ = ' '; *dest++ = ' ';
} }
char *src = sp->mnemonic; const char *src = sp->mnemonic;
while (*src) while (*src){
{
if (*src!='%') if (*src!='%')
*dest++ = *src++; *dest++ = *src++;
else else {
{
src++; src++;
switch (*src) switch (*src){
{
case 'r': case 'r':
src++; src++;
dest = addStr(dest, regs[(opcode>>(*src-'0'))&7]); dest = addStr(dest, regs[(opcode>>(*src-'0'))&7]);
@ -680,9 +620,8 @@ int disThumb(u32 offset, char *dest, int flags)
((opcode & 0xff)<<2)); ((opcode & 0xff)<<2));
*dest++ = '$'; *dest++ = '$';
dest = addHex(dest, 32, value); dest = addHex(dest, 32, value);
char *s = elfGetAddressSymbol(value); const char *s = elfGetAddressSymbol(value);
if(*s) if(*s) {
{
*dest++ = ' '; *dest++ = ' ';
dest = addStr(dest, s); dest = addStr(dest, s);
} }
@ -693,9 +632,8 @@ int disThumb(u32 offset, char *dest, int flags)
u32 value = (offset&0xfffffffc)+4+((opcode & 0xff)<<2); u32 value = (offset&0xfffffffc)+4+((opcode & 0xff)<<2);
*dest++ = '$'; *dest++ = '$';
dest = addHex(dest, 32, value); dest = addHex(dest, 32, value);
char *s = elfGetAddressSymbol(value); const char *s = elfGetAddressSymbol(value);
if(*s) if(*s) {
{
*dest++ = ' '; *dest++ = ' ';
dest = addStr(dest, s); dest = addStr(dest, s);
} }
@ -736,10 +674,8 @@ int disThumb(u32 offset, char *dest, int flags)
int rlst = opcode&0xff; int rlst = opcode&0xff;
int msk = 0; int msk = 0;
int not_first = 0; int not_first = 0;
while (msk<8) while (msk<8){
{ if (rlst&(1<<msk)){
if (rlst&(1<<msk))
{
int fr = msk; int fr = msk;
while (rlst&(1<<msk)) while (rlst&(1<<msk))
msk++; msk++;
@ -747,8 +683,7 @@ int disThumb(u32 offset, char *dest, int flags)
if (not_first) if (not_first)
*dest++ = ','; *dest++ = ',';
dest = addStr(dest, regs[fr]); dest = addStr(dest, regs[fr]);
if (fr!=to) if (fr!=to){
{
if (fr==to-1) if (fr==to-1)
*dest++ = ','; *dest++ = ',';
else else
@ -756,8 +691,7 @@ int disThumb(u32 offset, char *dest, int flags)
dest = addStr(dest, regs[to]); dest = addStr(dest, regs[to]);
} }
not_first = 1; not_first = 1;
} } else
else
msk++; msk++;
} }
} }
@ -789,9 +723,8 @@ int disThumb(u32 offset, char *dest, int flags)
add = (add<<12)|((nopcode&0x7ff)<<1); add = (add<<12)|((nopcode&0x7ff)<<1);
*dest++ = '$'; *dest++ = '$';
dest = addHex(dest,32, offset+4+add); dest = addHex(dest,32, offset+4+add);
char *s = elfGetAddressSymbol(offset+4+add); const char *s = elfGetAddressSymbol(offset+4+add);
if(*s) if(*s) {
{
*dest++ = ' '; *dest++ = ' ';
*dest++ = '('; *dest++ = '(';
dest = addStr(dest, s); dest = addStr(dest, s);

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,8 +31,7 @@ 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;
@ -58,8 +52,7 @@ struct ELFHeader
u16 e_shstrndx; u16 e_shstrndx;
}; };
struct ELFProgramHeader struct ELFProgramHeader {
{
u32 type; u32 type;
u32 offset; u32 offset;
u32 vaddr; u32 vaddr;
@ -70,8 +63,7 @@ struct ELFProgramHeader
u32 align; u32 align;
}; };
struct ELFSectionHeader struct ELFSectionHeader {
{
u32 name; u32 name;
u32 type; u32 type;
u32 flags; u32 flags;
@ -84,8 +76,7 @@ struct ELFSectionHeader
u32 entsize; u32 entsize;
}; };
struct ELFSymbol struct ELFSymbol {
{
u32 name; u32 name;
u32 value; u32 value;
u32 size; u32 size;
@ -94,14 +85,12 @@ struct ELFSymbol
u16 shndx; u16 shndx;
}; };
struct ELFBlock struct ELFBlock {
{
int length; int length;
u8 *data; u8 *data;
}; };
struct ELFAttr struct ELFAttr {
{
u32 name; u32 name;
u32 form; u32 form;
union { union {
@ -113,8 +102,7 @@ struct ELFAttr
}; };
}; };
struct ELFAbbrev struct ELFAbbrev {
{
u32 number; u32 number;
u32 tag; u32 tag;
bool hasChildren; bool hasChildren;
@ -138,14 +126,12 @@ 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;
@ -154,36 +140,31 @@ struct Member
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;
char *name; const char *name;
int encoding; int encoding;
int size; int size;
int bitSize; int bitSize;
@ -197,8 +178,7 @@ struct Type
Type *next; Type *next;
}; };
struct Object struct Object {
{
char *name; char *name;
int file; int file;
int line; int line;
@ -210,8 +190,7 @@ struct Object
Object *next; Object *next;
}; };
struct Function struct Function {
{
char *name; char *name;
u32 lowPC; u32 lowPC;
u32 highPC; u32 highPC;
@ -225,36 +204,31 @@ struct Function
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;
@ -274,8 +248,7 @@ struct CompileUnit
CompileUnit *next; CompileUnit *next;
}; };
struct DebugInfo struct DebugInfo {
{
u8 *debugfile; u8 *debugfile;
u8 *abbrevdata; u8 *abbrevdata;
u8 *debugdata; u8 *debugdata;
@ -284,9 +257,8 @@ struct DebugInfo
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;
@ -297,15 +269,15 @@ struct Symbol
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,8 +68,7 @@ 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"
@ -180,13 +179,11 @@ 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;
} }
@ -203,8 +200,7 @@ 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]) &&
@ -233,8 +229,7 @@ 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"
@ -345,13 +340,11 @@ 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;
} }
@ -368,8 +361,7 @@ 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]) &&
@ -396,8 +388,7 @@ 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"
@ -460,14 +451,12 @@ static void MotionBlurIB_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
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;
} }
@ -482,8 +471,7 @@ 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));
@ -500,8 +488,7 @@ 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"
@ -564,14 +551,12 @@ static void MotionBlurIB32_MMX(u8 *srcPtr, u32 srcPitch, int width, int height)
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;
} }
@ -586,8 +571,7 @@ 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));
@ -595,49 +579,3 @@ void MotionBlurIB32(u8 *srcPtr, u32 srcPitch, int width, int height)
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 */
@ -217,14 +225,11 @@ 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 {
else
{
b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3; b = (int)((p1 & 0x1F) - (p2 & 0x1F)) << 3;
g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2; g = (int)((p1 & 0x3E0) - (p2 & 0x3E0)) >> 2;
r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7; r = (int)((p1 & 0x7C00) - (p2 & 0x7C00)) >> 7;
@ -278,8 +283,7 @@ 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;

View File

@ -28,8 +28,7 @@ void Pixelate(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;
@ -43,15 +42,13 @@ void Pixelate(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
nextPixel = *bP++; nextPixel = *bP++;
nextDelta = *xP++; nextDelta = *xP++;
do do {
{
currentPixel = nextPixel; currentPixel = nextPixel;
currentDelta = nextDelta; currentDelta = nextDelta;
nextPixel = *bP++; nextPixel = *bP++;
nextDelta = *xP++; nextDelta = *xP++;
if ((nextPixel != nextDelta) || (currentPixel != currentDelta)) if ((nextPixel != nextDelta) || (currentPixel != currentDelta)) {
{
u32 colorA, colorB, product; u32 colorA, colorB, product;
*(xP - 2) = currentPixel; *(xP - 2) = currentPixel;
@ -89,8 +86,7 @@ void Pixelate(u8 *srcPtr, u32 srcPitch, u8 *deltaPtr,
dP += 2; dP += 2;
nL += 2; nL += 2;
} } while ((u8 *) bP < finish);
while ((u8 *) bP < finish);
deltaPtr += srcPitch; deltaPtr += srcPitch;
srcPtr += srcPitch; srcPtr += srcPitch;
@ -108,8 +104,7 @@ 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;
@ -120,8 +115,7 @@ void Pixelate32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
finish = (u8 *) bP + ((width+1) << 2); finish = (u8 *) bP + ((width+1) << 2);
nextPixel = *bP++; nextPixel = *bP++;
do do {
{
currentPixel = nextPixel; currentPixel = nextPixel;
nextPixel = *bP++; nextPixel = *bP++;
@ -146,8 +140,7 @@ void Pixelate32(u8 *srcPtr, u32 srcPitch, u8 * /* deltaPtr */,
dP += 4; dP += 4;
nL += 4; nL += 4;
} } while ((u8 *) bP < finish);
while ((u8 *) bP < finish);
srcPtr += srcPitch; srcPtr += srcPitch;
dstPtr += dstPitch << 1; dstPtr += dstPitch << 1;

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