more and more formating issues, I keep doing it in parts for my own reasons

This commit is contained in:
Zach Bacon 2016-07-09 10:13:54 -04:00
parent 48086ba62f
commit 1f37311a4a
No known key found for this signature in database
GPG Key ID: 7D110798AFE84B3A
50 changed files with 30207 additions and 30645 deletions

View File

@ -1,11 +1,10 @@
#include <memory.h>
#include "../Util.h"
#include "../common/Types.h"
#include "gbGlobals.h"
#include "gbSGB.h"
u8 gbInvertTab[256] = {
uint8_t gbInvertTab[256] = {
0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
@ -40,16 +39,16 @@ u8 gbInvertTab[256] = {
0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
};
u16 gbLineMix[160];
u16 gbWindowColor[160];
uint16_t gbLineMix[160];
uint16_t gbWindowColor[160];
extern int inUseRegister_WY;
extern int layerSettings;
void gbRenderLine()
{
memset(gbLineMix, 0, sizeof(gbLineMix));
u8* bank0;
u8* bank1;
uint8_t* bank0;
uint8_t* bank1;
if (gbCgbMode) {
bank0 = &gbVram[0x0000];
bank1 = &gbVram[0x2000];
@ -91,11 +90,11 @@ void gbRenderLine()
int tile_map_address = tile_map_line_y + tx;
u8 attrs = 0;
uint8_t attrs = 0;
if (bank1 != NULL)
attrs = bank1[tile_map_address];
u8 tile = bank0[tile_map_address];
uint8_t tile = bank0[tile_map_address];
tile_map_address++;
@ -108,8 +107,8 @@ void gbRenderLine()
if ((register_LCDC & 0x01 || gbCgbMode) && (layerSettings & 0x0100)) {
while (x < 160) {
u8 tile_a = 0;
u8 tile_b = 0;
uint8_t tile_a = 0;
uint8_t tile_b = 0;
if (attrs & 0x40) {
tile_pattern_address = tile_pattern + tile * 16 + (7 - by) * 2;
@ -129,7 +128,7 @@ void gbRenderLine()
}
while (bx > 0) {
u8 c = (tile_a & bx) ? 1 : 0;
uint8_t c = (tile_a & bx) ? 1 : 0;
c += ((tile_b & bx) ? 2 : 0);
gbLineBuffer[x] = c; // mark the gbLineBuffer color
@ -204,7 +203,7 @@ void gbRenderLine()
// (this fixes white flashes on Last Bible II)
// Also added the gbColorOption (fixes Dracula Densetsu II color problems)
for (int i = 0; i < 160; i++) {
u16 color = gbColorOption ? gbColorFilter[0x7FFF] : 0x7FFF;
uint16_t color = gbColorOption ? gbColorFilter[0x7FFF] : 0x7FFF;
if (!gbCgbMode)
color = gbColorOption ? gbColorFilter[gbPalette[gbBgpLine[i + (gbSpeed ? 5 : 11) + gbSpritesTicks[i] * (gbSpeed ? 2 : 4)] & 3] & 0x7FFF] : gbPalette[gbBgpLine[i + (gbSpeed ? 5 : 11) + gbSpritesTicks[i] * (gbSpeed ? 2 : 4)] & 3] & 0x7FFF;
gbLineMix[i] = color;
@ -279,7 +278,7 @@ void gbRenderLine()
x = wx;
tile = bank0[tile_map_address];
u8 attrs = 0;
uint8_t attrs = 0;
if (bank1)
attrs = bank1[tile_map_address];
tile_map_address++;
@ -298,8 +297,8 @@ void gbRenderLine()
gbLineMix[i] = gbWindowColor[i];
while (x < 160) {
u8 tile_a = 0;
u8 tile_b = 0;
uint8_t tile_a = 0;
uint8_t tile_b = 0;
if (attrs & 0x40) {
tile_pattern_address = tile_pattern + tile * 16 + (7 - by) * 2;
@ -319,7 +318,7 @@ void gbRenderLine()
}
while (bx > 0) {
u8 c = (tile_a & bx) != 0 ? 1 : 0;
uint8_t c = (tile_a & bx) != 0 ? 1 : 0;
c += ((tile_b & bx) != 0 ? 2 : 0);
if (x >= 0) {
@ -386,7 +385,7 @@ void gbRenderLine()
gbWindowLine = 0;
}
} else {
u16 color = gbColorOption ? gbColorFilter[0x7FFF] : 0x7FFF;
uint16_t color = gbColorOption ? gbColorFilter[0x7FFF] : 0x7FFF;
if (!gbCgbMode)
color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] : gbPalette[0] & 0x7FFF;
for (int i = 0; i < 160; i++) {
@ -399,8 +398,8 @@ void gbRenderLine()
void gbDrawSpriteTile(int tile, int x, int y, int t, int flags,
int size, int spriteNumber)
{
u8* bank0;
u8* bank1;
uint8_t* bank0;
uint8_t* bank1;
if (gbCgbMode) {
bank0 = &gbVram[0x0000];
bank1 = &gbVram[0x2000];
@ -415,7 +414,7 @@ void gbDrawSpriteTile(int tile, int x, int y, int t, int flags,
gbObp0[i] = (gbObp0Line[x + 11 + gbSpritesTicks[x] * (gbSpeed ? 2 : 4)] >> (i << 1)) & 3;
gbObp1[i] = (gbObp1Line[x + 11 + gbSpritesTicks[x] * (gbSpeed ? 2 : 4)] >> (i << 1)) & 3;
}
u8* pal = gbObp0;
uint8_t* pal = gbObp0;
int flipx = (flags & 0x20);
int flipy = (flags & 0x40);
@ -442,8 +441,8 @@ void gbDrawSpriteTile(int tile, int x, int y, int t, int flags,
}
for (int xx = 0; xx < 8; xx++) {
u8 mask = 1 << (7 - xx);
u8 c = 0;
uint8_t mask = 1 << (7 - xx);
uint8_t c = 0;
if ((a & mask))
c++;
if ((b & mask))
@ -459,7 +458,7 @@ void gbDrawSpriteTile(int tile, int x, int y, int t, int flags,
if (xxx < 0 || xxx > 159)
continue;
u16 color = gbLineBuffer[xxx];
uint16_t color = gbLineBuffer[xxx];
// Fixes OAM-BG priority
if (prio && (register_LCDC & 1)) {

View File

@ -95,10 +95,10 @@ w, word, u32 --> word
sw, sword, s32, int --> signed word
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "BreakpointStructures.h"
#include "remote.h"
@ -143,9 +143,6 @@ struct intToString compareFlagMapping[] = {
//
//char* compareFlagMapping[] = {"Never","==",">",">=","<","<=","!=","<=>"};
//Constructors
//case '*': flag = 0xf; break;
//case 't': flag = 0x8; break; // thumb
@ -154,7 +151,8 @@ struct intToString compareFlagMapping[] = {
//case 'r': flag = 0x2; break; // mem read
//case 'w': flag = 0x1; break; // mem write
//case 'i': flag = 0x3; break;
struct ConditionalBreak* addConditionalBreak(u32 address, u8 flag){
struct ConditionalBreak* addConditionalBreak(u32 address, u8 flag)
{
u8 condIndex = address >> 24;
struct ConditionalBreak* cond = NULL;
BreakSet((&map[condIndex])->breakPoints, address & (&map[condIndex])->mask, ((flag & 0xf) | (flag >> 4)));
@ -225,8 +223,8 @@ addCB_nextHandle:
}
}
void addCondition(struct ConditionalBreak* base, struct ConditionalBreakNode* toAdd){
void addCondition(struct ConditionalBreak* base, struct ConditionalBreakNode* toAdd)
{
if (base->firstCond) {
struct ConditionalBreakNode *curr, *prev;
curr = base->firstCond;
@ -242,7 +240,8 @@ void addCondition(struct ConditionalBreak* base, struct ConditionalBreakNode* to
}
//destructors
void freeConditionalBreak(struct ConditionalBreak* toFree){
void freeConditionalBreak(struct ConditionalBreak* toFree)
{
struct ConditionalBreakNode* freeMe;
while (toFree->firstCond) {
freeMe = toFree->firstCond;
@ -252,7 +251,8 @@ void freeConditionalBreak(struct ConditionalBreak* toFree){
free(toFree);
}
void freeConditionalNode(struct ConditionalBreakNode* toDel){
void freeConditionalNode(struct ConditionalBreakNode* toDel)
{
if (toDel->next)
freeConditionalNode(toDel->next);
if (toDel->address)
@ -262,7 +262,8 @@ void freeConditionalNode(struct ConditionalBreakNode* toDel){
free(toDel);
}
void freeAllConditionals(){
void freeAllConditionals()
{
for (int i = 0; i < 16; i++) {
while (conditionals[i]) {
struct ConditionalBreak* tmp = conditionals[i];
@ -272,7 +273,8 @@ void freeAllConditionals(){
}
}
int removeConditionalBreak(struct ConditionalBreak* toDelete){
int removeConditionalBreak(struct ConditionalBreak* toDelete)
{
if (toDelete) {
u8 condIndex = toDelete->break_address >> 24;
struct ConditionalBreak* base = conditionals[condIndex];
@ -391,7 +393,8 @@ int removeAllConditions(u32 address, u8 flags){
return true;
}*/
void recountFlagsForAddress(u32 address){
void recountFlagsForAddress(u32 address)
{
struct ConditionalBreak* base = conditionals[address >> 24];
u8 flags = 0;
while (base) {
@ -412,9 +415,9 @@ void recountFlagsForAddress(u32 address){
BreakSet((&map[address >> 24])->breakPoints, address & (&map[address >> 24])->mask, ((flags >> 4) | (flags & 0x8)));
}
//Removers
int removeConditionalBreakNo(u32 addrNo, u8 number){
int removeConditionalBreakNo(u32 addrNo, u8 number)
{
if (conditionals[addrNo >> 24]) {
struct ConditionalBreak* base = conditionals[addrNo >> 24];
struct ConditionalBreak* curr = conditionals[addrNo >> 24];
@ -454,7 +457,8 @@ if(conditionals[addrNo>>24]){
return -2;
}
int removeFlagFromConditionalBreakNo(u32 addrNo, u8 number, u8 flag){
int removeFlagFromConditionalBreakNo(u32 addrNo, u8 number, u8 flag)
{
if (conditionals[addrNo >> 24]) {
struct ConditionalBreak* base = conditionals[addrNo >> 24];
struct ConditionalBreak* curr = conditionals[addrNo >> 24];
@ -502,7 +506,8 @@ int removeFlagFromConditionalBreakNo(u32 addrNo, u8 number, u8 flag){
return -2;
}
int removeConditionalWithAddress(u32 address){
int removeConditionalWithAddress(u32 address)
{
u8 addrNo = address >> 24;
if (conditionals[addrNo] != NULL) {
struct ConditionalBreak* base = conditionals[addrNo];
@ -527,7 +532,8 @@ int removeConditionalWithAddress(u32 address){
return -2;
}
int removeConditionalWithFlag(u8 flag, bool orMode){
int removeConditionalWithFlag(u8 flag, bool orMode)
{
for (u8 addrNo = 0; addrNo < 16; addrNo++) {
if (conditionals[addrNo] != NULL) {
struct ConditionalBreak* base = conditionals[addrNo];
@ -542,8 +548,7 @@ int removeConditionalWithFlag(u8 flag, bool orMode){
conditionals[addrNo] = curr->next;
base = curr->next;
curr = base;
}
else{
} else {
base->next = curr->next;
freeConditionalBreak(curr);
curr = base->next;
@ -564,15 +569,15 @@ int removeConditionalWithFlag(u8 flag, bool orMode){
return -2;
}
int removeConditionalWithAddressAndFlag(u32 address, u8 flag, bool orMode){
int removeConditionalWithAddressAndFlag(u32 address, u8 flag, bool orMode)
{
u8 addrNo = address >> 24;
if (conditionals[addrNo] != NULL) {
struct ConditionalBreak* base = conditionals[addrNo];
struct ConditionalBreak* curr = conditionals[addrNo];
u8 count = 0;
while (curr && address >= curr->break_address) {
if((curr->break_address == address) &&
(((curr->type_flags & flag) == curr->type_flags) || (orMode && (curr->type_flags & flag)))){
if ((curr->break_address == address) && (((curr->type_flags & flag) == curr->type_flags) || (orMode && (curr->type_flags & flag)))) {
curr->type_flags &= ~flag;
BreakClear((&map[address >> 24])->breakPoints, curr->break_address & (&map[address >> 24])->mask, ((flag & 0xf) | (flag >> 4)));
if (curr->type_flags == 0) {
@ -580,8 +585,7 @@ int removeConditionalWithAddressAndFlag(u32 address, u8 flag, bool orMode){
conditionals[addrNo] = curr->next;
freeConditionalBreak(curr);
curr = conditionals[addrNo];
}
else{
} else {
base->next = curr->next;
freeConditionalBreak(curr);
curr = base->next;
@ -601,8 +605,6 @@ int removeConditionalWithAddressAndFlag(u32 address, u8 flag, bool orMode){
return -2;
}
//true creating code for a given expression.
//It assumes an if was found, and that all up to the if was removed.
//receives an array of chars following the pattern:
@ -610,7 +612,8 @@ int removeConditionalWithAddressAndFlag(u32 address, u8 flag, bool orMode){
//<expType is optional, and always assumes int-compare as default.
u8 parseExpressionType(char* type);
u8 parseConditionOperand(char* type);
void parseAndCreateConditionalBreaks(u32 address, u8 flags, char** exp, int n){
void parseAndCreateConditionalBreaks(u32 address, u8 flags, char** exp, int n)
{
struct ConditionalBreak* workBreak = addConditionalBreak(address, flags);
flags &= 0xf;
if (!flags)
@ -624,22 +627,26 @@ void parseAndCreateConditionalBreaks(u32 address, u8 flags, char** exp, int n){
if (exp[i][0] == '\'') {
now->exp_type_flags |= parseExpressionType(&exp[i][1]);
i++;
if(i >= n) goto fail;
if (i >= n)
goto fail;
} else {
now->exp_type_flags |= 6; //assume signed word
}
now->address = strdup(exp[i]);
i++;
if(i >= n) goto fail;
if (i >= n)
goto fail;
char* operandName = exp[i];
now->cond_flags = parseConditionOperand(exp[i]);
i++;
if(i >= n) goto fail;
if (i >= n)
goto fail;
if (exp[i][0] == '\'') {
now->exp_type_flags |= (parseExpressionType(&exp[i][1]) << 4);
i++;
if(i >= n) goto fail;
if (i >= n)
goto fail;
} else {
now->exp_type_flags |= 0x60; //assume signed word
}
@ -678,7 +685,8 @@ void parseAndCreateConditionalBreaks(u32 address, u8 flags, char** exp, int n){
}
//aux
u8 parseExpressionType(char* given_type){
u8 parseExpressionType(char* given_type)
{
u8 flags = 0;
//for such a small string, pays off to convert first
char* type = strdup(given_type);
@ -723,27 +731,32 @@ u8 parseExpressionType(char* given_type){
return flags;
}
u8 parseConditionOperand(char* type){
u8 parseConditionOperand(char* type)
{
u8 flag = 0;
if (toupper(type[0]) == 'S') {
flag = 8;
type++;
}
switch (type[0]) {
case '!': if(type[1] == '=' || type[1] == '\0')
case '!':
if (type[1] == '=' || type[1] == '\0')
return flag | 0x6;
break;
case '=': if(type[1] == '=' || type[1] == '\0')
case '=':
if (type[1] == '=' || type[1] == '\0')
return flag | 0x1;
break;
case '<': if(type[1] == '>')
case '<':
if (type[1] == '>')
return flag | 0x6;
if (type[1] == '=')
return flag | 0x5;
if (type[1] == '\0')
return flag | 0x4;
break;
case '>': if(type[1] == '<')
case '>':
if (type[1] == '<')
return flag | 0x6;
if (type[1] == '=')
return flag | 0x3;
@ -753,28 +766,33 @@ u8 parseConditionOperand(char* type){
default:;
}
switch (tolower(type[0])) {
case 'l': if(tolower(type[1]) == 'e')
case 'l':
if (tolower(type[1]) == 'e')
return flag | 0x5;
if (tolower(type[1]) == 't')
return flag | 0x4;
break;
case 'g': if(tolower(type[1]) == 'e')
case 'g':
if (tolower(type[1]) == 'e')
return flag | 0x3;
if (tolower(type[1]) == 't')
return flag | 0x2;
case 'e': if(tolower(type[1]) == 'q')
case 'e':
if (tolower(type[1]) == 'q')
return flag | 0x1;
if (type[1] == '\0')
return flag | 0x1;
case 'n': if(tolower(type[1]) == 'e')
case 'n':
if (tolower(type[1]) == 'e')
return flag | 0x6;
default:;
}
return flag;
}
u32 calculateFinalValue(char* expToEval, u8 type_of_flags){
u32 calculateFinalValue(char* expToEval, u8 type_of_flags)
{
u32 val;
if (!dexp_eval(expToEval, &val)) {
printf("Invalid expression.\n");
@ -782,27 +800,34 @@ u32 calculateFinalValue(char* expToEval, u8 type_of_flags){
}
if (type_of_flags & 0x4) {
switch (type_of_flags & 0x3) {
case 0: return (s8)(val&0xff);
case 1: return (s16)(val&0xffff);
default: return (int)val;
case 0:
return (s8)(val & 0xff);
case 1:
return (s16)(val & 0xffff);
default:
return (int)val;
}
} else {
switch (type_of_flags & 0x3) {
case 0: return (u8)(val&0xff);
case 1: return (u16)(val&0xffff);
default: return val;
case 0:
return (u8)(val & 0xff);
case 1:
return (u16)(val & 0xffff);
default:
return val;
}
}
}
//check for execution
bool isCorrectBreak(struct ConditionalBreak* toTest, u8 accessType){
bool isCorrectBreak(struct ConditionalBreak* toTest, u8 accessType)
{
return (toTest->type_flags & accessType);
}
bool doBreak(struct ConditionalBreak* toTest){
bool doBreak(struct ConditionalBreak* toTest)
{
struct ConditionalBreakNode* toExamine = toTest->firstCond;
bool globalVeredict = true;
@ -817,12 +842,12 @@ bool doBreak(struct ConditionalBreak* toTest){
}
toExamine = toExamine->next;
globalVeredict = veredict && globalVeredict;
}
return globalVeredict;
}
bool doesBreak(u32 address, u8 allowedFlags){
bool doesBreak(u32 address, u8 allowedFlags)
{
u8 addrNo = address >> 24;
if (conditionals[addrNo]) {
struct ConditionalBreak* base = conditionals[addrNo];

View File

@ -4,14 +4,10 @@
#include "../common/Types.h"
#define readWord(addr) \
((map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]) + \
((map[(addr + 1) >> 24].address[(addr + 1) & map[(addr + 1) >> 24].mask]) << 8) + \
((map[(addr + 2) >> 24].address[(addr + 2) & map[(addr + 2) >> 24].mask]) << 16) + \
((map[(addr + 3) >> 24].address[(addr + 3) & map[(addr + 3) >> 24].mask]) << 24))
((map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]) + ((map[(addr + 1) >> 24].address[(addr + 1) & map[(addr + 1) >> 24].mask]) << 8) + ((map[(addr + 2) >> 24].address[(addr + 2) & map[(addr + 2) >> 24].mask]) << 16) + ((map[(addr + 3) >> 24].address[(addr + 3) & map[(addr + 3) >> 24].mask]) << 24))
#define readHalfWord(addr) \
((&map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]) + \
((&map[(addr + 1) >> 24].address[(addr + 1) & map[(addr + 1) >> 24].mask]) << 8))
((&map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]) + ((&map[(addr + 1) >> 24].address[(addr + 1) & map[(addr + 1) >> 24].mask]) << 8))
#define readByte(addr) map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]

View File

@ -1,5 +1,5 @@
#include <stdlib.h>
#include <memory.h>
#include <stdlib.h>
#include "CheatSearch.h"
@ -308,4 +308,3 @@ void cheatSearchUpdateValues(const CheatSearchData *cs)
memcpy(block->saved, block->data, block->size);
}
}

View File

@ -16,9 +16,16 @@ struct CheatSearchData {
CheatSearchBlock* blocks;
};
enum { SEARCH_EQ, SEARCH_NE, SEARCH_LT, SEARCH_LE, SEARCH_GT, SEARCH_GE };
enum { SEARCH_EQ,
SEARCH_NE,
SEARCH_LT,
SEARCH_LE,
SEARCH_GT,
SEARCH_GE };
enum { BITS_8, BITS_16, BITS_32 };
enum { BITS_8,
BITS_16,
BITS_32 };
#define SET_BIT(bits, off) (bits)[(off) >> 3] |= (1 << ((off)&7))

View File

@ -1,14 +1,14 @@
#include <memory.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <memory.h>
#include <stdio.h>
#include <string.h>
#include "GBA.h"
#include "GBAinline.h"
#include "Cheats.h"
#include "Globals.h"
#include "../NLS.h"
#include "../Util.h"
#include "Cheats.h"
#include "GBA.h"
#include "GBAinline.h"
#include "Globals.h"
/**
* Gameshark code types: (based on AR v1.0)
@ -297,7 +297,6 @@ u8 v3_deadtable2[256] = {
#define debuggerWriteByte(addr, value) \
map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask] = (value)
#define CHEAT_IS_HEX(a) (((a) >= 'A' && (a) <= 'F') || ((a) >= '0' && (a) <= '9'))
#define CHEAT_PATCH_ROM_16BIT(a, v) \
@ -742,8 +741,7 @@ int cheatsCheckKeys(u32 keys, u32 extended)
CPUWriteMemory(cheatsList[i].address, cheatsList[i].value);
}
break;
case CBA_IF_KEYS_PRESSED:
{
case CBA_IF_KEYS_PRESSED: {
u16 value = cheatsList[i].value;
u32 addr = cheatsList[i].address;
if ((addr & 0xF0) == 0x20) {
@ -759,15 +757,13 @@ int cheatsCheckKeys(u32 keys, u32 extended)
i++;
}
}
}
break;
} break;
case CBA_IF_TRUE:
if (CPUReadHalfWord(cheatsList[i].address) != cheatsList[i].value) {
i++;
}
break;
case CBA_SLIDE_CODE:
{
case CBA_SLIDE_CODE: {
u32 address = cheatsList[i].address;
u16 value = cheatsList[i].value;
i++;
@ -781,8 +777,7 @@ int cheatsCheckKeys(u32 keys, u32 extended)
value += vinc;
}
}
}
break;
} break;
case CBA_IF_FALSE:
if (CPUReadHalfWord(cheatsList[i].address) == cheatsList[i].value) {
i++;
@ -790,8 +785,7 @@ int cheatsCheckKeys(u32 keys, u32 extended)
break;
case CBA_AND:
CPUWriteHalfWord(cheatsList[i].address,
CPUReadHalfWord(cheatsList[i].address) &
cheatsList[i].value);
CPUReadHalfWord(cheatsList[i].address) & cheatsList[i].value);
break;
case GSA_8_BIT_IF_TRUE:
if (CPUReadByte(cheatsList[i].address) != cheatsList[i].value) {
@ -813,8 +807,7 @@ int cheatsCheckKeys(u32 keys, u32 extended)
i++;
}
break;
case GSA_8_BIT_FILL:
{
case GSA_8_BIT_FILL: {
u32 addr = cheatsList[i].address;
u8 v = cheatsList[i].value & 0xff;
u32 end = addr + (cheatsList[i].value >> 8);
@ -822,10 +815,8 @@ int cheatsCheckKeys(u32 keys, u32 extended)
CPUWriteByte(addr, v);
addr++;
} while (addr <= end);
}
break;
case GSA_16_BIT_FILL:
{
} break;
case GSA_16_BIT_FILL: {
u32 addr = cheatsList[i].address;
u16 v = cheatsList[i].value & 0xffff;
u32 end = addr + ((cheatsList[i].value >> 16) << 1);
@ -833,8 +824,7 @@ int cheatsCheckKeys(u32 keys, u32 extended)
CPUWriteHalfWord(addr, v);
addr += 2;
} while (addr <= end);
}
break;
} break;
case GSA_8_BIT_IF_TRUE2:
if (CPUReadByte(cheatsList[i].address) != cheatsList[i].value) {
i += 2;
@ -868,18 +858,15 @@ int cheatsCheckKeys(u32 keys, u32 extended)
case CBA_ADD:
if ((cheatsList[i].address & 1) == 0) {
CPUWriteHalfWord(cheatsList[i].address,
CPUReadHalfWord(cheatsList[i].address) +
cheatsList[i].value);
CPUReadHalfWord(cheatsList[i].address) + cheatsList[i].value);
} else {
CPUWriteMemory(cheatsList[i].address & 0x0FFFFFFE,
CPUReadMemory(cheatsList[i].address & 0x0FFFFFFE) +
cheatsList[i].value);
CPUReadMemory(cheatsList[i].address & 0x0FFFFFFE) + cheatsList[i].value);
}
break;
case CBA_OR:
CPUWriteHalfWord(cheatsList[i].address,
CPUReadHalfWord(cheatsList[i].address) |
cheatsList[i].value);
CPUReadHalfWord(cheatsList[i].address) | cheatsList[i].value);
break;
case CBA_GT:
if (!(CPUReadHalfWord(cheatsList[i].address) > cheatsList[i].value)) {
@ -891,8 +878,7 @@ int cheatsCheckKeys(u32 keys, u32 extended)
i++;
}
break;
case CBA_SUPER:
{
case CBA_SUPER: {
int count = 2 * ((cheatsList[i].value - 1) & 0xFFFF) + 1;
u32 address = cheatsList[i].address;
for (int x = 0; x <= count; x++) {
@ -907,28 +893,21 @@ int cheatsCheckKeys(u32 keys, u32 extended)
CPUWriteByte(address, b);
address++;
}
}
break;
} break;
case GSA_8_BIT_POINTER:
if (((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000)) ||
((CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000)))
{
if (((CPUReadMemory(cheatsList[i].address) >= 0x02000000) && (CPUReadMemory(cheatsList[i].address) < 0x02040000)) || ((CPUReadMemory(cheatsList[i].address) >= 0x03000000) && (CPUReadMemory(cheatsList[i].address) < 0x03008000))) {
CPUWriteByte(CPUReadMemory(cheatsList[i].address) + ((cheatsList[i].value & 0xFFFFFF00) >> 8),
cheatsList[i].value & 0xFF);
}
break;
case GSA_16_BIT_POINTER:
if (((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000)) ||
((CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000)))
{
if (((CPUReadMemory(cheatsList[i].address) >= 0x02000000) && (CPUReadMemory(cheatsList[i].address) < 0x02040000)) || ((CPUReadMemory(cheatsList[i].address) >= 0x03000000) && (CPUReadMemory(cheatsList[i].address) < 0x03008000))) {
CPUWriteHalfWord(CPUReadMemory(cheatsList[i].address) + ((cheatsList[i].value & 0xFFFF0000) >> 15),
cheatsList[i].value & 0xFFFF);
}
break;
case GSA_32_BIT_POINTER:
if (((CPUReadMemory(cheatsList[i].address)>=0x02000000) && (CPUReadMemory(cheatsList[i].address)<0x02040000)) ||
((CPUReadMemory(cheatsList[i].address)>=0x03000000) && (CPUReadMemory(cheatsList[i].address)<0x03008000)))
{
if (((CPUReadMemory(cheatsList[i].address) >= 0x02000000) && (CPUReadMemory(cheatsList[i].address) < 0x02040000)) || ((CPUReadMemory(cheatsList[i].address) >= 0x03000000) && (CPUReadMemory(cheatsList[i].address) < 0x03008000))) {
CPUWriteMemory(CPUReadMemory(cheatsList[i].address),
cheatsList[i].value);
}
@ -1102,13 +1081,11 @@ int cheatsCheckKeys(u32 keys, u32 extended)
}
break;
case GSA_16_BIT_WRITE_IOREGS:
if ((cheatsList[i].address <= 0x3FF) && (cheatsList[i].address != 0x6) &&
(cheatsList[i].address != 0x130))
if ((cheatsList[i].address <= 0x3FF) && (cheatsList[i].address != 0x6) && (cheatsList[i].address != 0x130))
ioMem[cheatsList[i].address & 0x3FE] = cheatsList[i].value & 0xFFFF;
break;
case GSA_32_BIT_WRITE_IOREGS:
if (cheatsList[i].address<=0x3FF)
{
if (cheatsList[i].address <= 0x3FF) {
if (((cheatsList[i].address & 0x3FC) != 0x6) && ((cheatsList[i].address & 0x3FC) != 0x130))
ioMem[cheatsList[i].address & 0x3FC] = (cheatsList[i].value & 0xFFFF);
if ((((cheatsList[i].address & 0x3FC) + 2) != 0x6) && ((cheatsList[i].address & 0x3FC) + 2) != 0x130)
@ -1225,8 +1202,7 @@ int cheatsCheckKeys(u32 keys, u32 extended)
onoff = false;
}
break;
case GSA_GROUP_WRITE:
{
case GSA_GROUP_WRITE: {
int count = ((cheatsList[i].address) & 0xFFFE) + 1;
u32 value = cheatsList[i].value;
if (count == 0)
@ -1237,12 +1213,10 @@ int cheatsCheckKeys(u32 keys, u32 extended)
if (x < count)
i++;
CPUWriteMemory(cheatsList[i].rawaddress, value);
}
else
} else
CPUWriteMemory(cheatsList[i].value, value);
}
}
break;
} break;
case GSA_32_BIT_ADD2:
CPUWriteMemory(cheatsList[i].value,
(CPUReadMemory(cheatsList[i].value) + cheatsList[i + 1].rawaddress) & 0xFFFFFFFF);
@ -1399,8 +1373,7 @@ void cheatsDelete(int number, bool restore)
}
}
if ((x + 1) < cheatsNumber) {
memcpy(&cheatsList[x], &cheatsList[x+1], sizeof(CheatsData)*
(cheatsNumber-x-1));
memcpy(&cheatsList[x], &cheatsList[x + 1], sizeof(CheatsData) * (cheatsNumber - x - 1));
}
cheatsNumber--;
}
@ -1532,7 +1505,8 @@ u16 cheatsGSAGetDeadface(bool v3)
return 0;
}
void cheatsGSAChangeEncryption(u16 value, bool v3) {
void cheatsGSAChangeEncryption(u16 value, bool v3)
{
int i;
u8 *deadtable1, *deadtable2;
@ -1541,8 +1515,7 @@ void cheatsGSAChangeEncryption(u16 value, bool v3) {
deadtable2 = (u8*)(&v3_deadtable2);
for (i = 0; i < 4; i++)
seeds_v3[i] = seed_gen(((value & 0xFF00) >> 8), (value & 0xFF) + i, deadtable1, deadtable2);
}
else {
} else {
deadtable1 = (u8*)(&v1_deadtable1);
deadtable2 = (u8*)(&v1_deadtable2);
for (i = 0; i < 4; i++) {
@ -1551,7 +1524,8 @@ void cheatsGSAChangeEncryption(u16 value, bool v3) {
}
}
u32 seed_gen(u8 upper, u8 seed, u8 *deadtable1, u8 *deadtable2) {
u32 seed_gen(u8 upper, u8 seed, u8* deadtable1, u8* deadtable2)
{
int i;
u32 newseed = 0;
@ -1568,10 +1542,8 @@ void cheatsDecryptGSACode(u32& address, u32& value, bool v3)
int bitsleft = 32;
while (bitsleft > 0) {
value -= ((((address << 4) + seeds[2]) ^ (address + rollingseed)) ^
((address >> 5) + seeds[3]));
address -= ((((value << 4) + seeds[0]) ^ (value + rollingseed)) ^
((value >> 5) + seeds[1]));
value -= ((((address << 4) + seeds[2]) ^ (address + rollingseed)) ^ ((address >> 5) + seeds[3]));
address -= ((((value << 4) + seeds[0]) ^ (value + rollingseed)) ^ ((value >> 5) + seeds[1]));
rollingseed -= 0x9E3779B9;
bitsleft--;
}
@ -1633,13 +1605,11 @@ void cheatsAddGSACode(const char *code, const char *desc, bool v3)
u32 addr = (address & 0x00F00000) << 4 | (address & 0x0003FFFF);
u16 mcode = (address >> 24 & 0xFF);
if ((mcode & 0xFE) == 0xC4)
{
if ((mcode & 0xFE) == 0xC4) {
cheatsAdd(code, desc, address, (address & 0x1FFFFFF) | (0x08000000),
value, 257, MASTER_CODE);
mastercode = (address & 0x1FFFFFF) | (0x08000000);
}
else
} else
switch (type) {
case 0x00:
if (address == 0) {
@ -2218,14 +2188,16 @@ u32 cheatsCBACalcIndex(u32 x, u32 y)
if (y < x) {
y = y << 4;
x0 = x0 << 4;
} else break;
} else
break;
}
while (y < 0x80000000) {
if (y < x) {
y = y << 1;
x0 = x0 << 1;
} else break;
} else
break;
}
loop:
@ -2330,8 +2302,7 @@ u16 cheatsCBAGenValue(u32 x, u32 y, u32 z)
u32 temp = z ^ x;
if ((int)temp >= 0) {
temp = z << 0x11;
}
else {
} else {
temp = z << 0x01;
temp ^= x0;
temp = temp << 0x10;
@ -2343,7 +2314,8 @@ u16 cheatsCBAGenValue(u32 x, u32 y, u32 z)
return z & 0xffff;
}
void cheatsCBAGenTable() {
void cheatsCBAGenTable()
{
for (int i = 0; i < 0x100; i++) {
cheatsCBATable[i] = cheatsCBAGenValue(i, 0x1021, 0);
}
@ -2361,13 +2333,21 @@ u16 cheatsCBACalcCRC(u8 *rom, int count)
if (count != -1) {
while (count != -1) {
crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
^ *rom++]) << 0x10) >> 0x10;
^ *rom++])
<< 0x10)
>> 0x10;
crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
^ *rom++]) << 0x10) >> 0x10;
^ *rom++])
<< 0x10)
>> 0x10;
crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
^ *rom++]) << 0x10) >> 0x10;
^ *rom++])
<< 0x10)
>> 0x10;
crc = (((crc << 0x08) ^ cheatsCBATable[(((u32)crc << 0x10) >> 0x18)
^ *rom++]) << 0x10) >> 0x10;
^ *rom++])
<< 0x10)
>> 0x10;
count--;
}
}
@ -2386,10 +2366,8 @@ void cheatsCBADecrypt(u8 *decrypt)
chatsCBAScramble(array, count, cheatsCBASeedBuffer[count]);
}
cheatsCBAArrayToValue(array, decrypt);
*((u32 *)decrypt) = cheatsCBAGetValue(decrypt) ^
cheatsCBASeed[0];
*((u16 *)(decrypt+4)) = (cheatsCBAGetData(decrypt) ^
cheatsCBASeed[1]) & 0xffff;
*((u32*)decrypt) = cheatsCBAGetValue(decrypt) ^ cheatsCBASeed[0];
*((u16*)(decrypt + 4)) = (cheatsCBAGetData(decrypt) ^ cheatsCBASeed[1]) & 0xffff;
cheatsCBAReverseArray(decrypt, array);
@ -2409,7 +2387,8 @@ void cheatsCBADecrypt(u8 *decrypt)
*((u32*)decrypt) = cheatsCBAGetValue(decrypt)
^ cheatsCBASeed[2];
*((u16*)(decrypt + 4)) = (cheatsCBAGetData(decrypt)
^ cheatsCBASeed[3]) & 0xffff;
^ cheatsCBASeed[3])
& 0xffff;
}
int cheatsCBAGetCount()
@ -2487,8 +2466,7 @@ void cheatsAddCBACode(const char *code, const char *desc)
0
};
if(cheatsCBAGetCount() == 0 &&
(address >> 28) == 9) {
if (cheatsCBAGetCount() == 0 && (address >> 28) == 9) {
u32 seed[8];
cheatsCBAParseSeedCode(address, value, seed);
cheatsCBAChangeEncryption(seed);
@ -2510,8 +2488,7 @@ void cheatsAddCBACode(const char *code, const char *desc)
}
switch (type) {
case 0x00:
{
case 0x00: {
if (!cheatsCBATableGenerated)
cheatsCBAGenTable();
u32 crc = cheatsCBACalcCRC(rom, 0x10000);
@ -2521,8 +2498,7 @@ void cheatsAddCBACode(const char *code, const char *desc)
}
cheatsAdd(code, desc, address, address & 0x0FFFFFFF, value, 512,
UNKNOWN_CODE);
}
break;
} break;
case 0x01:
cheatsAdd(code, desc, address, (address & 0x1FFFFFF) | 0x08000000, value, 512, MASTER_CODE);
mastercode = (address & 0x1FFFFFF) | 0x08000000;
@ -2607,12 +2583,10 @@ void cheatsReadGame(gzFile file, int version)
if (version > 8)
utilGzRead(file, cheatsList, sizeof(cheatsList));
bool firstCodeBreaker = true;
for (int i = 0; i < cheatsNumber; i++) {
if (version <9)
{
if (version < 9) {
cheatsList[i].code = utilReadInt(file);
cheatsList[i].size = utilReadInt(file);
cheatsList[i].status = utilReadInt(file);
@ -2668,7 +2642,6 @@ void cheatsReadGame(gzFile file, int version)
}
}
// skip the cheat list data
void cheatsReadGameSkip(gzFile file, int version)
{
@ -2686,7 +2659,6 @@ void cheatsReadGameSkip( gzFile file, int version )
}
}
void cheatsSaveCheatList(const char* file)
{
if (cheatsNumber == 0)
@ -2733,7 +2705,6 @@ bool cheatsLoadCheatList(const char *file)
return false;
}
if ((type != 0) && (type != 1)) {
systemMessage(MSG_UNSUPPORTED_CHEAT_LIST_TYPE,
N_("Unsupported cheat list type %d"), type);
@ -2745,15 +2716,12 @@ bool cheatsLoadCheatList(const char *file)
fclose(f);
return false;
}
if (type == 1)
{
if (type == 1) {
if (fread(cheatsList, 1, sizeof(cheatsList), f) > sizeof(cheatsList)) {
fclose(f);
return false;
}
}
else if (type == 0)
{
} else if (type == 0) {
for (int i = 0; i < count; i++) {
fread(&cheatsList[i].code, 1, sizeof(int), f);
fread(&cheatsList[i].size, 1, sizeof(int), f);

View File

@ -1,8 +1,8 @@
#include <memory.h>
#include <string.h>
#include "GBA.h"
#include "EEprom.h"
#include "../Util.h"
#include "GBA.h"
#include <memory.h>
#include <string.h>
extern int cpuDmaCount;
@ -110,8 +110,7 @@ int eepromRead(u32 /* address */)
case EEPROM_READADDRESS:
case EEPROM_WRITEDATA:
return 1;
case EEPROM_READDATA:
{
case EEPROM_READDATA: {
eepromBits++;
if (eepromBits == 4) {
eepromMode = EEPROM_READDATA2;
@ -120,8 +119,7 @@ int eepromRead(u32 /* address */)
}
return 0;
}
case EEPROM_READDATA2:
{
case EEPROM_READDATA2: {
int data = 0;
int address = eepromAddress << 3;
int mask = 1 << (7 - (eepromBits & 7));
@ -162,8 +160,7 @@ void eepromWrite(u32 /* address */, u8 value)
if (eepromBits == 0x11) {
eepromInUse = true;
eepromSize = 0x2000;
eepromAddress = ((eepromBuffer[0] & 0x3F) << 8) |
((eepromBuffer[1] & 0xFF));
eepromAddress = ((eepromBuffer[0] & 0x3F) << 8) | ((eepromBuffer[1] & 0xFF));
if (!(eepromBuffer[0] & 0x40)) {
eepromBuffer[0] = bit;
eepromBits = 1;

View File

@ -1,11 +1,11 @@
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include "Flash.h"
#include "../Util.h"
#include "GBA.h"
#include "Globals.h"
#include "Flash.h"
#include "Sram.h"
#include "../Util.h"
#include <memory.h>
#include <stdio.h>
#include <string.h>
#define FLASH_READ_ARRAY 0
#define FLASH_CMD_1 1
@ -114,7 +114,6 @@ void flashReadGameSkip(gzFile gzFile, int version)
}
#endif
void flashSetSize(int size)
{
// log("Setting flash size to %d\n", size);

View File

@ -1,25 +1,25 @@
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../NLS.h"
#include "../System.h"
#include "../Util.h"
#include "../common/ConfigManager.h"
#include "Cheats.h"
#include "EEprom.h"
#include "Flash.h"
#include "GBA.h"
#include "GBAcpu.h"
#include "GBAinline.h"
#include "Globals.h"
#include "EEprom.h"
#include "Flash.h"
#include "Sound.h"
#include "Sram.h"
#include "bios.h"
#include "Cheats.h"
#include "../NLS.h"
#include "elf.h"
#include "../Util.h"
#include "../System.h"
#include "../common/ConfigManager.h"
#include "agbprint.h"
#include "bios.h"
#include "elf.h"
#include "remote.h"
#ifdef PROFILING
@ -59,7 +59,6 @@ static INSN_REGPARM void armBreakpoint(u32 opcode)
}
#endif
// Subroutine to count instructions (for debugging/optimizing)
//#define INSN_COUNTER // comment out if you don't want it
#ifdef INSN_COUNTER
@ -101,10 +100,12 @@ static void count(u32 opcode, int cond_res)
// Common macros //////////////////////////////////////////////////////////
#ifdef BKPT_SUPPORT
#define CONSOLE_OUTPUT(a,b) do { \
#define CONSOLE_OUTPUT(a, b) \
do { \
if ((opcode == 0xe0000000) && (reg[0].I == 0xC0DED00D)) { \
dbgOutput((a), (b)); \
} while (0)
} \
while (0)
#else
#define CONSOLE_OUTPUT(a, b) /* nothing */
#endif
@ -151,8 +152,7 @@ static void count(u32 opcode, int cond_res)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[base].I), \
"r" (value) \
); \
"r"(value)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -169,8 +169,7 @@ static void count(u32 opcode, int cond_res)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[base].I), \
"r" (value) \
); \
"r"(value)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -187,8 +186,7 @@ static void count(u32 opcode, int cond_res)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[base].I), \
"r" (value) \
); \
"r"(value)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -207,8 +205,7 @@ static void count(u32 opcode, int cond_res)
"=r"(Flags) \
: "r"(reg[base].I), \
"r"(value), \
"r" (C_FLAG << 29) \
); \
"r"(C_FLAG << 29)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -227,8 +224,7 @@ static void count(u32 opcode, int cond_res)
"=r"(Flags) \
: "r"(reg[base].I), \
"r"(value), \
"r" (C_FLAG << 29) \
); \
"r"(C_FLAG << 29)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -247,8 +243,7 @@ static void count(u32 opcode, int cond_res)
"=r"(Flags) \
: "r"(reg[base].I), \
"r"(value), \
"r" (C_FLAG << 29) \
); \
"r"(C_FLAG << 29)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -265,8 +260,7 @@ static void count(u32 opcode, int cond_res)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[base].I), \
"r" (value) \
); \
"r"(value)); \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \
@ -282,8 +276,7 @@ static void count(u32 opcode, int cond_res)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[base].I), \
"r" (value) \
); \
"r"(value)); \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \
@ -303,7 +296,8 @@ static void count(u32 opcode, int cond_res)
#define EMIT2(op, src, dest) #op " " src ", " dest "; "
#define KONST(val) "$" #val
#define ASMVAR(cvar) ASMVAR2(__USER_LABEL_PREFIX__, cvar)
#define ASMVAR2(prefix,cvar) STRING (prefix) cvar
#define ASMVAR2(prefix, cvar) STRING(prefix) \
cvar
#define STRING(x) #x
#define VAR(var) ASMVAR(#var)
#define VARL(var) ASMVAR(#var)
@ -685,8 +679,7 @@ static void count(u32 opcode, int cond_res)
: "0"(offset), "c"(shift));
#define RRX_OFFSET \
asm(EMIT2(btl,KONST(0),VAR(C_FLAG)) \
"rcr $1, %0" \
asm(EMIT2(btl, KONST(0), VAR(C_FLAG)) "rcr $1, %0" \
: "=r"(offset) \
: "0"(offset));
@ -698,7 +691,6 @@ static void count(u32 opcode, int cond_res)
__asm ror value, cl \
}
#define ROR_OFFSET \
__asm { \
__asm mov ecx, shift \
@ -725,19 +717,13 @@ static void count(u32 opcode, int cond_res)
#define C_SETCOND_ADD \
N_FLAG = ((s32)res < 0) ? true : false; \
Z_FLAG = (res == 0) ? true : false; \
V_FLAG = ((NEG(lhs) & NEG(rhs) & POS(res)) | \
(POS(lhs) & POS(rhs) & NEG(res))) ? true : false;\
C_FLAG = ((NEG(lhs) & NEG(rhs)) | \
(NEG(lhs) & POS(res)) | \
(NEG(rhs) & POS(res))) ? true : false;
V_FLAG = ((NEG(lhs) & NEG(rhs) & POS(res)) | (POS(lhs) & POS(rhs) & NEG(res))) ? true : false; \
C_FLAG = ((NEG(lhs) & NEG(rhs)) | (NEG(lhs) & POS(res)) | (NEG(rhs) & POS(res))) ? true : false;
#define C_SETCOND_SUB \
N_FLAG = ((s32)res < 0) ? true : false; \
Z_FLAG = (res == 0) ? true : false; \
V_FLAG = ((NEG(lhs) & POS(rhs) & POS(res)) | \
(POS(lhs) & NEG(rhs) & NEG(res))) ? true : false;\
C_FLAG = ((NEG(lhs) & POS(rhs)) | \
(NEG(lhs) & POS(res)) | \
(POS(rhs) & POS(res))) ? true : false;
V_FLAG = ((NEG(lhs) & POS(rhs) & POS(res)) | (POS(lhs) & NEG(rhs) & NEG(res))) ? true : false; \
C_FLAG = ((NEG(lhs) & POS(rhs)) | (NEG(lhs) & POS(res)) | (POS(rhs) & POS(res))) ? true : false;
#ifndef ALU_INIT_C
#define ALU_INIT_C \
@ -870,13 +856,11 @@ static void count(u32 opcode, int cond_res)
if (LIKELY(shift)) { \
u32 v = reg[opcode & 0x0F].I; \
C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
value = ((v << (32 - shift)) | \
(v >> shift)); \
value = ((v << (32 - shift)) | (v >> shift)); \
} else { \
u32 v = reg[opcode & 0x0F].I; \
C_OUT = (v & 1) ? true : false; \
value = ((v >> 1) | \
(C_FLAG << 31)); \
value = ((v >> 1) | (C_FLAG << 31)); \
}
#endif
// OP Rd,Rb,Rm ROR Rs
@ -890,8 +874,7 @@ static void count(u32 opcode, int cond_res)
if (LIKELY(shift & 0x1F)) { \
u32 v = rm; \
C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
value = ((v << (32 - shift)) | \
(v >> shift)); \
value = ((v << (32 - shift)) | (v >> shift)); \
} else { \
value = rm; \
if (shift) \
@ -905,8 +888,7 @@ static void count(u32 opcode, int cond_res)
if (UNLIKELY(shift)) { \
u32 v = opcode & 0xFF; \
C_OUT = (v >> (shift - 1)) & 1 ? true : false; \
value = ((v << (32 - shift)) | \
(v >> shift)); \
value = ((v << (32 - shift)) | (v >> shift)); \
} else { \
value = opcode & 0xFF; \
}
@ -945,7 +927,10 @@ static void count(u32 opcode, int cond_res)
#define VALUE_IMM_NC VALUE_IMM_C
#endif
#define C_CHECK_PC(SETCOND) if (LIKELY(dest != 15)) { SETCOND }
#define C_CHECK_PC(SETCOND) \
if (LIKELY(dest != 15)) { \
SETCOND \
}
#ifndef OP_AND
#define OP_AND \
u32 res = reg[(opcode >> 16) & 15].I & value; \
@ -1566,8 +1551,7 @@ static INSN_REGPARM void arm121(u32 opcode)
#define LDR(CALC_OFFSET, CALC_ADDRESS, LOAD_DATA, WRITEBACK, SIZE) \
LDRSTR_INIT(CALC_OFFSET, CALC_ADDRESS); \
LOAD_DATA; \
if (dest != base) \
{ \
if (dest != base) { \
WRITEBACK; \
} \
clockTicks = 0; \
@ -2145,15 +2129,13 @@ static INSN_REGPARM void arm7F6(u32 opcode) { LDR_PREINC_WB(OFFSET_ROR, OP_LDRB,
clockTicks += 1 + codeTicksAccessSeq32(armNextPC); \
}
// STMDA Rn, {Rlist}
static INSN_REGPARM void arm800(u32 opcode)
{
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
STM_ALL;
@ -2166,8 +2148,7 @@ static INSN_REGPARM void arm810(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
LDM_ALL;
@ -2180,8 +2161,7 @@ static INSN_REGPARM void arm820(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
STMW_ALL;
@ -2194,8 +2174,7 @@ static INSN_REGPARM void arm830(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
LDM_ALL;
@ -2210,8 +2189,7 @@ static INSN_REGPARM void arm840(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
STM_ALL_2;
@ -2224,8 +2202,7 @@ static INSN_REGPARM void arm850(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
LDM_ALL_2;
@ -2239,8 +2216,7 @@ static INSN_REGPARM void arm860(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
STMW_ALL_2;
@ -2253,8 +2229,7 @@ static INSN_REGPARM void arm870(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (temp + 4) & 0xFFFFFFFC;
int count = 0;
LDM_ALL_2;
@ -2296,8 +2271,7 @@ static INSN_REGPARM void arm8A0(u32 opcode)
int base = (opcode & 0x000F0000) >> 16;
u32 address = reg[base].I & 0xFFFFFFFC;
int count = 0;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@ -2308,8 +2282,7 @@ static INSN_REGPARM void arm8B0(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = reg[base].I & 0xFFFFFFFC;
int count = 0;
LDM_ALL;
@ -2351,8 +2324,7 @@ static INSN_REGPARM void arm8E0(u32 opcode)
int base = (opcode & 0x000F0000) >> 16;
u32 address = reg[base].I & 0xFFFFFFFC;
int count = 0;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL_2;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@ -2363,8 +2335,7 @@ static INSN_REGPARM void arm8F0(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = reg[base].I & 0xFFFFFFFC;
int count = 0;
LDM_ALL_2;
@ -2380,8 +2351,7 @@ static INSN_REGPARM void arm900(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
STM_ALL;
@ -2394,8 +2364,7 @@ static INSN_REGPARM void arm910(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
LDM_ALL;
@ -2408,8 +2377,7 @@ static INSN_REGPARM void arm920(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
STMW_ALL;
@ -2422,8 +2390,7 @@ static INSN_REGPARM void arm930(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
LDM_ALL;
@ -2438,8 +2405,7 @@ static INSN_REGPARM void arm940(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
STM_ALL_2;
@ -2452,8 +2418,7 @@ static INSN_REGPARM void arm950(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
LDM_ALL_2;
@ -2467,8 +2432,7 @@ static INSN_REGPARM void arm960(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
STMW_ALL_2;
@ -2481,8 +2445,7 @@ static INSN_REGPARM void arm970(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I -
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I - 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = temp & 0xFFFFFFFC;
int count = 0;
LDM_ALL_2;
@ -2524,8 +2487,7 @@ static INSN_REGPARM void arm9A0(u32 opcode)
int base = (opcode & 0x000F0000) >> 16;
u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
int count = 0;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@ -2536,8 +2498,7 @@ static INSN_REGPARM void arm9B0(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
int count = 0;
LDM_ALL;
@ -2579,8 +2540,7 @@ static INSN_REGPARM void arm9E0(u32 opcode)
int base = (opcode & 0x000F0000) >> 16;
u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
int count = 0;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 0xFF] + cpuBitsSet[(opcode >> 8) & 255]);
STMW_ALL_2;
clockTicks += 1 + codeTicksAccess32(armNextPC);
}
@ -2591,8 +2551,7 @@ static INSN_REGPARM void arm9F0(u32 opcode)
if (busPrefetchCount == 0)
busPrefetch = busPrefetchEnable;
int base = (opcode & 0x000F0000) >> 16;
u32 temp = reg[base].I +
4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 temp = reg[base].I + 4 * (cpuBitsSet[opcode & 255] + cpuBitsSet[(opcode >> 8) & 255]);
u32 address = (reg[base].I + 4) & 0xFFFFFFFC;
int count = 0;
LDM_ALL_2;
@ -2635,7 +2594,6 @@ static INSN_REGPARM void armB00(u32 opcode)
busPrefetchCount = 0;
}
#ifdef GP_SUPPORT
// MRC
static INSN_REGPARM void armE01(u32 opcode)
@ -2645,7 +2603,6 @@ static INSN_REGPARM void armE01(u32 opcode)
#define armE01 armUnknownInsn
#endif
// SWI <comment>
static INSN_REGPARM void armF00(u32 opcode)
{
@ -2662,7 +2619,8 @@ typedef INSN_REGPARM void (*insnfunc_t)(u32 opcode);
insn, insn, insn, insn, insn, insn, insn, insn, \
insn, insn, insn, insn, insn, insn, insn, insn
#define REP256(insn) \
REP16(insn),REP16(insn),REP16(insn),REP16(insn),\
REP16(insn) \
, REP16(insn), REP16(insn), REP16(insn), \
REP16(insn), REP16(insn), REP16(insn), REP16(insn), \
REP16(insn), REP16(insn), REP16(insn), REP16(insn), \
REP16(insn), REP16(insn), REP16(insn), REP16(insn)

View File

@ -1,28 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _MSC_VER
#include <strings.h>
#endif
#include "../NLS.h"
#include "../System.h"
#include "../Util.h"
#include "../common/ConfigManager.h"
#include "Cheats.h"
#include "EEprom.h"
#include "Flash.h"
#include "GBA.h"
#include "GBAcpu.h"
#include "GBAinline.h"
#include "Globals.h"
#include "EEprom.h"
#include "Flash.h"
#include "Sound.h"
#include "Sram.h"
#include "bios.h"
#include "Cheats.h"
#include "../NLS.h"
#include "elf.h"
#include "../Util.h"
#include "../System.h"
#include "../common/ConfigManager.h"
#include "agbprint.h"
#include "bios.h"
#include "elf.h"
#include "remote.h"
#ifdef PROFILING
@ -59,12 +59,14 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
// Common macros //////////////////////////////////////////////////////////
#ifdef BKPT_SUPPORT
# define THUMB_CONSOLE_OUTPUT(a,b) do { \
#define THUMB_CONSOLE_OUTPUT(a, b) \
do { \
if ((opcode == 0x4000) && (reg[0].I == 0xC0DED00D)) { \
dbgOutput((a), (b)); \
} \
} while (0)
# define UPDATE_OLDREG do { \
#define UPDATE_OLDREG \
do { \
if (debugger_last) { \
snprintf(oldbuffer, sizeof(oldbuffer), "%08X", \
armState ? reg[15].I - 4 : reg[15].I - 2); \
@ -95,8 +97,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[source].I), \
"r" (reg[N].I) \
); \
"r"(reg[N].I)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -113,8 +114,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[source].I), \
"r" (N) \
); \
"r"(N)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -132,8 +132,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[(d)].I), \
"r" (opcode & 255) \
); \
"r"(opcode & 255)); \
reg[(d)].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -150,8 +149,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[dest].I), \
"r" (value) \
); \
"r"(value)); \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \
@ -170,12 +168,12 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "r" (reg[dest].I), \
"r" (value), \
"r" (C_FLAG << 29) \
); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \
V_FLAG = (Flags >> 26) & 1; \
);
reg[dest].I = Result;
Z_FLAG = (Flags >> 29) & 1;
N_FLAG = (Flags >> 31) & 1;
C_FLAG = (Flags >> 25) & 1;
V_FLAG = (Flags >> 26) & 1;
}
#define SUB_RD_RS_RN(N) \
{ \
@ -187,8 +185,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[source].I), \
"r" (reg[N].I) \
); \
"r"(reg[N].I)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -205,8 +202,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[source].I), \
"r" (N) \
); \
"r"(N)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -224,8 +220,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[(d)].I), \
"r" (opcode & 255) \
); \
"r"(opcode & 255)); \
reg[(d)].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -242,8 +237,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[(d)].I), \
"r" (opcode & 255) \
); \
"r"(opcode & 255)); \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \
@ -262,12 +256,12 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "r" (reg[dest].I), \
"r" (value), \
"r" (C_FLAG << 29) \
); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \
V_FLAG = (Flags >> 26) & 1; \
);
reg[dest].I = Result;
Z_FLAG = (Flags >> 29) & 1;
N_FLAG = (Flags >> 31) & 1;
C_FLAG = (Flags >> 25) & 1;
V_FLAG = (Flags >> 26) & 1;
}
#define NEG_RD_RS \
{ \
@ -279,8 +273,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[source].I), \
"r" (0) \
); \
"r"(0)); \
reg[dest].I = Result; \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
@ -297,8 +290,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "=r"(Result), \
"=r"(Flags) \
: "r"(reg[dest].I), \
"r" (value) \
); \
"r"(value)); \
Z_FLAG = (Flags >> 29) & 1; \
N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \
@ -309,7 +301,8 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
#define EMIT2(op, src, dest) #op " " src ", " dest "; "
#define KONST(val) "$" #val
#define ASMVAR(cvar) ASMVAR2(__USER_LABEL_PREFIX__, cvar)
#define ASMVAR2(prefix,cvar) STRING (prefix) cvar
#define ASMVAR2(prefix, cvar) STRING(prefix) \
cvar
#define STRING(x) #x
#define VAR(var) ASMVAR(#var)
#define REGREF1(index) ASMVAR("reg(" index ")")
@ -319,24 +312,21 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
#define edx "%%edx"
#define ADD_RN_O8(d) \
asm("andl $0xFF, %%eax;" \
"addl %%eax, %0;"\
EMIT1(setsb, VAR(N_FLAG)) \
"addl %%eax, %0;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setcb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
: "=m"(reg[(d)].I));
#define CMN_RD_RS \
asm ("add %0, %1;"\
EMIT1(setsb, VAR(N_FLAG)) \
asm("add %0, %1;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setcb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
: \
: "r" (value), "r" (reg[dest].I):"1");
: "r"(value), "r"(reg[dest].I) \
: "1");
#define ADC_RD_RS \
asm (EMIT2(bt,KONST(0),VAR(C_FLAG)) \
"adc %1, %%ebx;"\
EMIT1(setsb, VAR(N_FLAG)) \
asm(EMIT2(bt, KONST(0), VAR(C_FLAG)) "adc %1, %%ebx;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setcb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
@ -344,383 +334,216 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
: "r"(value), "b"(reg[dest].I));
#define SUB_RN_O8(d) \
asm("andl $0xFF, %%eax;" \
"subl %%eax, %0;"\
EMIT1(setsb, VAR(N_FLAG)) \
"subl %%eax, %0;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
: "=m"(reg[(d)].I));
#define MOV_RN_O8(d) \
asm ("andl $0xFF, %%eax;"\
EMIT2(movb,KONST(0),VAR(N_FLAG)) \
"movl %%eax, %0;"\
EMIT1(setzb, VAR(Z_FLAG)) \
asm("andl $0xFF, %%eax;" EMIT2(movb, KONST(0), VAR(N_FLAG)) "movl %%eax, %0;" EMIT1(setzb, VAR(Z_FLAG)) \
: "=m"(reg[(d)].I));
#define CMP_RN_O8(d) \
asm("andl $0xFF, %%eax;" \
"cmpl %%eax, %0;"\
EMIT1(setsb, VAR(N_FLAG)) \
"cmpl %%eax, %0;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
: \
: "m"(reg[(d)].I));
#define SBC_RD_RS \
asm volatile (EMIT2(bt,KONST(0),VAR(C_FLAG)) \
"cmc;"\
"sbb %1, %%ebx;"\
EMIT1(setsb, VAR(N_FLAG)) \
asm volatile(EMIT2(bt, KONST(0), VAR(C_FLAG)) "cmc;" \
"sbb %1, %%ebx;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
: "=b"(reg[dest].I) \
: "r" (value), "b" (reg[dest].I) : "cc", "memory");
: "r"(value), "b"(reg[dest].I) \
: "cc", "memory");
#define LSL_RD_RS \
asm ("shl %%cl, %%eax;"\
EMIT1(setcb, VAR(C_FLAG)) \
asm("shl %%cl, %%eax;" EMIT1(setcb, VAR(C_FLAG)) \
: "=a"(value) \
: "a"(reg[dest].I), "c"(value));
#define LSR_RD_RS \
asm ("shr %%cl, %%eax;"\
EMIT1(setcb, VAR(C_FLAG)) \
asm("shr %%cl, %%eax;" EMIT1(setcb, VAR(C_FLAG)) \
: "=a"(value) \
: "a"(reg[dest].I), "c"(value));
#define ASR_RD_RS \
asm ("sar %%cl, %%eax;"\
EMIT1(setcb, VAR(C_FLAG)) \
asm("sar %%cl, %%eax;" EMIT1(setcb, VAR(C_FLAG)) \
: "=a"(value) \
: "a"(reg[dest].I), "c"(value));
#define ROR_RD_RS \
asm ("ror %%cl, %%eax;"\
EMIT1(setcb, VAR(C_FLAG)) \
asm("ror %%cl, %%eax;" EMIT1(setcb, VAR(C_FLAG)) \
: "=a"(value) \
: "a"(reg[dest].I), "c"(value));
#define NEG_RD_RS \
asm ("neg %%ebx;"\
EMIT1(setsb, VAR(N_FLAG)) \
asm("neg %%ebx;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
: "=b"(reg[dest].I) \
: "b"(reg[source].I));
#define CMP_RD_RS \
asm ("sub %0, %1;"\
EMIT1(setsb, VAR(N_FLAG)) \
asm("sub %0, %1;" EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG)) \
: \
: "r" (value), "r" (reg[dest].I):"1");
: "r"(value), "r"(reg[dest].I) \
: "1");
#define IMM5_INSN(OP, N) \
asm("movl %%eax,%%ecx;" \
"shrl $1,%%eax;" \
"andl $7,%%ecx;" \
"andl $0x1C,%%eax;" \
EMIT2(movl, REGREF1(eax), edx) \
"andl $0x1C,%%eax;" EMIT2(movl, REGREF1(eax), edx) \
OP \
EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT2(movl, edx, REGREF2(ecx, 4)) \
: : "i" (N))
: \
: "i"(N))
#define IMM5_INSN_0(OP) \
asm("movl %%eax,%%ecx;" \
"shrl $1,%%eax;" \
"andl $7,%%ecx;" \
"andl $0x1C,%%eax;" \
EMIT2(movl, REGREF1(eax), edx) \
"andl $0x1C,%%eax;" EMIT2(movl, REGREF1(eax), edx) \
OP \
EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT2(movl, edx, REGREF2(ecx, 4)) \
: : )
: \
:)
#define IMM5_LSL \
"shll %0,%%edx;"\
EMIT1(setcb, VAR(C_FLAG))
"shll %0,%%edx;" EMIT1(setcb, VAR(C_FLAG))
#define IMM5_LSL_0 \
"testl %%edx,%%edx;"
#define IMM5_LSR \
"shrl %0,%%edx;"\
EMIT1(setcb, VAR(C_FLAG))
"shrl %0,%%edx;" EMIT1(setcb, VAR(C_FLAG))
#define IMM5_LSR_0 \
"testl %%edx,%%edx;"\
EMIT1(setsb, VAR(C_FLAG)) \
"xorl %%edx,%%edx;"
"testl %%edx,%%edx;" EMIT1(setsb, VAR(C_FLAG)) "xorl %%edx,%%edx;"
#define IMM5_ASR \
"sarl %0,%%edx;"\
EMIT1(setcb, VAR(C_FLAG))
"sarl %0,%%edx;" EMIT1(setcb, VAR(C_FLAG))
#define IMM5_ASR_0 \
"sarl $31,%%edx;"\
EMIT1(setsb, VAR(C_FLAG))
"sarl $31,%%edx;" EMIT1(setsb, VAR(C_FLAG))
#define THREEARG_INSN(OP, N) \
asm("movl %%eax,%%edx;" \
"shrl $1,%%edx;" \
"andl $0x1C,%%edx;" \
"andl $7,%%eax;" \
EMIT2(movl, REGREF1(edx), ecx) \
"andl $7,%%eax;" EMIT2(movl, REGREF1(edx), ecx) \
OP(N) \
EMIT1(setsb, VAR(N_FLAG)) \
EMIT1(setzb, VAR(Z_FLAG)) \
EMIT2(movl, ecx, REGREF2(eax, 4)) \
: : )
: \
:)
#define ADD_RD_RS_RN(N) \
EMIT2(add, VAR(reg) "+" #N "*4", ecx) \
EMIT1(setcb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG))
#define ADD_RD_RS_O3(N) \
"add $"#N",%%ecx;" \
EMIT1(setcb, VAR(C_FLAG)) \
"add $" #N ",%%ecx;" EMIT1(setcb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG))
#define ADD_RD_RS_O3_0(N) \
EMIT2(movb, KONST(0), VAR(C_FLAG)) \
"add $0,%%ecx;" \
EMIT2(movb,KONST(0),VAR(V_FLAG))
"add $0,%%ecx;" EMIT2(movb, KONST(0), VAR(V_FLAG))
#define SUB_RD_RS_RN(N) \
EMIT2(sub, VAR(reg) "+" #N "*4", ecx) \
EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG))
#define SUB_RD_RS_O3(N) \
"sub $"#N",%%ecx;" \
EMIT1(setncb, VAR(C_FLAG)) \
"sub $" #N ",%%ecx;" EMIT1(setncb, VAR(C_FLAG)) \
EMIT1(setob, VAR(V_FLAG))
#define SUB_RD_RS_O3_0(N) \
EMIT2(movb, KONST(1), VAR(C_FLAG)) \
"sub $0,%%ecx;" \
EMIT2(movb,KONST(0),VAR(V_FLAG))
"sub $0,%%ecx;" EMIT2(movb, KONST(0), VAR(V_FLAG))
#endif
#else // !__GNUC__
#define ADD_RD_RS_RN(N) \
{ \
__asm mov eax, source\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm add ebx, dword ptr [OFFSET reg+4*N]\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov eax, source __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm add ebx, dword ptr[OFFSET reg + 4 * N] __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define ADD_RD_RS_O3(N) \
{ \
__asm mov eax, source\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm add ebx, N\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov eax, source __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm add ebx, N __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define ADD_RD_RS_O3_0 \
{ \
__asm mov eax, source\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm add ebx, 0\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm mov byte ptr C_FLAG, 0\
__asm mov byte ptr V_FLAG, 0\
__asm mov eax, source __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm add ebx, 0 __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm mov byte ptr C_FLAG, 0 __asm mov byte ptr V_FLAG, 0 \
}
#define ADD_RN_O8(d) \
{ \
__asm mov ebx, opcode\
__asm and ebx, 255\
__asm add dword ptr [OFFSET reg+4*(d)], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov ebx, opcode __asm and ebx, 255 __asm add dword ptr[OFFSET reg + 4 * (d)], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define CMN_RD_RS \
{ \
__asm mov eax, dest\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm add ebx, value\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov eax, dest __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm add ebx, value __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define ADC_RD_RS \
{ \
__asm mov ebx, dest\
__asm mov ebx, dword ptr [OFFSET reg+4*ebx]\
__asm bt word ptr C_FLAG, 0\
__asm adc ebx, value\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov ebx, dest __asm mov ebx, dword ptr[OFFSET reg + 4 * ebx] __asm bt word ptr C_FLAG, 0 __asm adc ebx, value __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define SUB_RD_RS_RN(N) \
{ \
__asm mov eax, source\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm sub ebx, dword ptr [OFFSET reg+4*N]\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setnc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov eax, source __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm sub ebx, dword ptr[OFFSET reg + 4 * N] __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setnc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define SUB_RD_RS_O3(N) \
{ \
__asm mov eax, source\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm sub ebx, N\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setnc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov eax, source __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm sub ebx, N __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setnc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define SUB_RD_RS_O3_0 \
{ \
__asm mov eax, source\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm sub ebx, 0\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm mov byte ptr C_FLAG, 1\
__asm mov byte ptr V_FLAG, 0\
__asm mov eax, source __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm sub ebx, 0 __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm mov byte ptr C_FLAG, 1 __asm mov byte ptr V_FLAG, 0 \
}
#define SUB_RN_O8(d) \
{ \
__asm mov ebx, opcode\
__asm and ebx, 255\
__asm sub dword ptr [OFFSET reg + 4*(d)], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setnc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov ebx, opcode __asm and ebx, 255 __asm sub dword ptr[OFFSET reg + 4 * (d)], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setnc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define MOV_RN_O8(d) \
{ \
__asm mov eax, opcode\
__asm and eax, 255\
__asm mov dword ptr [OFFSET reg+4*(d)], eax\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm mov eax, opcode __asm and eax, 255 __asm mov dword ptr[OFFSET reg + 4 * (d)], eax __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG \
}
#define CMP_RN_O8(d) \
{ \
__asm mov eax, dword ptr [OFFSET reg+4*(d)]\
__asm mov ebx, opcode\
__asm and ebx, 255\
__asm sub eax, ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setnc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov eax, dword ptr[OFFSET reg + 4 * (d)] __asm mov ebx, opcode __asm and ebx, 255 __asm sub eax, ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setnc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define SBC_RD_RS \
{ \
__asm mov ebx, dest\
__asm mov ebx, dword ptr [OFFSET reg + 4*ebx]\
__asm mov eax, value\
__asm bt word ptr C_FLAG, 0\
__asm cmc\
__asm sbb ebx, eax\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg + 4*eax], ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setnc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov ebx, dest __asm mov ebx, dword ptr[OFFSET reg + 4 * ebx] __asm mov eax, value __asm bt word ptr C_FLAG, 0 __asm cmc __asm sbb ebx, eax __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setnc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define LSL_RD_RM_I5 \
{ \
__asm mov eax, source\
__asm mov eax, dword ptr [OFFSET reg + 4 * eax]\
__asm mov cl, byte ptr shift\
__asm shl eax, cl\
__asm mov value, eax\
__asm setc byte ptr C_FLAG\
__asm mov eax, source __asm mov eax, dword ptr[OFFSET reg + 4 * eax] __asm mov cl, byte ptr shift __asm shl eax, cl __asm mov value, eax __asm setc byte ptr C_FLAG \
}
#define LSL_RD_RS \
{ \
__asm mov eax, dest\
__asm mov eax, dword ptr [OFFSET reg + 4 * eax]\
__asm mov cl, byte ptr value\
__asm shl eax, cl\
__asm mov value, eax\
__asm setc byte ptr C_FLAG\
__asm mov eax, dest __asm mov eax, dword ptr[OFFSET reg + 4 * eax] __asm mov cl, byte ptr value __asm shl eax, cl __asm mov value, eax __asm setc byte ptr C_FLAG \
}
#define LSR_RD_RM_I5 \
{ \
__asm mov eax, source\
__asm mov eax, dword ptr [OFFSET reg + 4 * eax]\
__asm mov cl, byte ptr shift\
__asm shr eax, cl\
__asm mov value, eax\
__asm setc byte ptr C_FLAG\
__asm mov eax, source __asm mov eax, dword ptr[OFFSET reg + 4 * eax] __asm mov cl, byte ptr shift __asm shr eax, cl __asm mov value, eax __asm setc byte ptr C_FLAG \
}
#define LSR_RD_RS \
{ \
__asm mov eax, dest\
__asm mov eax, dword ptr [OFFSET reg + 4 * eax]\
__asm mov cl, byte ptr value\
__asm shr eax, cl\
__asm mov value, eax\
__asm setc byte ptr C_FLAG\
__asm mov eax, dest __asm mov eax, dword ptr[OFFSET reg + 4 * eax] __asm mov cl, byte ptr value __asm shr eax, cl __asm mov value, eax __asm setc byte ptr C_FLAG \
}
#define ASR_RD_RM_I5 \
{ \
__asm mov eax, source\
__asm mov eax, dword ptr [OFFSET reg + 4*eax]\
__asm mov cl, byte ptr shift\
__asm sar eax, cl\
__asm mov value, eax\
__asm setc byte ptr C_FLAG\
__asm mov eax, source __asm mov eax, dword ptr[OFFSET reg + 4 * eax] __asm mov cl, byte ptr shift __asm sar eax, cl __asm mov value, eax __asm setc byte ptr C_FLAG \
}
#define ASR_RD_RS \
{ \
__asm mov eax, dest\
__asm mov eax, dword ptr [OFFSET reg + 4*eax]\
__asm mov cl, byte ptr value\
__asm sar eax, cl\
__asm mov value, eax\
__asm setc byte ptr C_FLAG\
__asm mov eax, dest __asm mov eax, dword ptr[OFFSET reg + 4 * eax] __asm mov cl, byte ptr value __asm sar eax, cl __asm mov value, eax __asm setc byte ptr C_FLAG \
}
#define ROR_RD_RS \
{ \
__asm mov eax, dest\
__asm mov eax, dword ptr [OFFSET reg + 4*eax]\
__asm mov cl, byte ptr value\
__asm ror eax, cl\
__asm mov value, eax\
__asm setc byte ptr C_FLAG\
__asm mov eax, dest __asm mov eax, dword ptr[OFFSET reg + 4 * eax] __asm mov cl, byte ptr value __asm ror eax, cl __asm mov value, eax __asm setc byte ptr C_FLAG \
}
#define NEG_RD_RS \
{ \
__asm mov ebx, source\
__asm mov ebx, dword ptr [OFFSET reg+4*ebx]\
__asm neg ebx\
__asm mov eax, dest\
__asm mov dword ptr [OFFSET reg+4*eax],ebx\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setnc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov ebx, source __asm mov ebx, dword ptr[OFFSET reg + 4 * ebx] __asm neg ebx __asm mov eax, dest __asm mov dword ptr[OFFSET reg + 4 * eax], ebx __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setnc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#define CMP_RD_RS \
{ \
__asm mov eax, dest\
__asm mov ebx, dword ptr [OFFSET reg+4*eax]\
__asm sub ebx, value\
__asm sets byte ptr N_FLAG\
__asm setz byte ptr Z_FLAG\
__asm setnc byte ptr C_FLAG\
__asm seto byte ptr V_FLAG\
__asm mov eax, dest __asm mov ebx, dword ptr[OFFSET reg + 4 * eax] __asm sub ebx, value __asm sets byte ptr N_FLAG __asm setz byte ptr Z_FLAG __asm setnc byte ptr C_FLAG __asm seto byte ptr V_FLAG \
}
#endif
#endif
@ -728,25 +551,19 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
// C core
#ifndef ADDCARRY
#define ADDCARRY(a, b, c) \
C_FLAG = ((NEG(a) & NEG(b)) |\
(NEG(a) & POS(c)) |\
(NEG(b) & POS(c))) ? true : false;
C_FLAG = ((NEG(a) & NEG(b)) | (NEG(a) & POS(c)) | (NEG(b) & POS(c))) ? true : false;
#endif
#ifndef ADDOVERFLOW
#define ADDOVERFLOW(a, b, c) \
V_FLAG = ((NEG(a) & NEG(b) & POS(c)) |\
(POS(a) & POS(b) & NEG(c))) ? true : false;
V_FLAG = ((NEG(a) & NEG(b) & POS(c)) | (POS(a) & POS(b) & NEG(c))) ? true : false;
#endif
#ifndef SUBCARRY
#define SUBCARRY(a, b, c) \
C_FLAG = ((NEG(a) & POS(b)) |\
(NEG(a) & POS(c)) |\
(POS(b) & POS(c))) ? true : false;
C_FLAG = ((NEG(a) & POS(b)) | (NEG(a) & POS(c)) | (POS(b) & POS(c))) ? true : false;
#endif
#ifndef SUBOVERFLOW
#define SUBOVERFLOW(a, b, c) \
V_FLAG = ((NEG(a) & POS(b) & POS(c)) |\
(POS(a) & NEG(b) & NEG(c))) ? true : false;
V_FLAG = ((NEG(a) & POS(b) & POS(c)) | (POS(a) & NEG(b) & NEG(c))) ? true : false;
#endif
#ifndef ADD_RD_RS_RN
#define ADD_RD_RS_RN(N) \
@ -936,8 +753,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
#define ROR_RD_RS \
{ \
C_FLAG = (reg[dest].I >> (value - 1)) & 1 ? true : false; \
value = ((reg[dest].I << (32 - value)) |\
(reg[dest].I >> value));\
value = ((reg[dest].I << (32 - value)) | (reg[dest].I >> value)); \
}
#endif
#ifndef NEG_RD_RS
@ -1467,7 +1283,6 @@ static INSN_REGPARM void thumb46_3(u32 opcode)
}
}
// BX Rs
static INSN_REGPARM void thumb47(u32 opcode)
{
@ -2337,7 +2152,6 @@ int thumbExecute()
(*thumbInsnTable[opcode >> 6])(opcode);
#ifdef BKPT_SUPPORT
if (enableRegBreak) {
if (lowRegBreakCounter[0])

View File

@ -1,32 +1,32 @@
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <memory.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef _MSC_VER
#include <strings.h>
#endif
#include "../NLS.h"
#include "../System.h"
#include "../Util.h"
#include "../common/ConfigManager.h"
#include "../common/Port.h"
#include "Cheats.h"
#include "EEprom.h"
#include "Flash.h"
#include "GBA.h"
#include "GBAGfx.h"
#include "GBALink.h"
#include "GBAcpu.h"
#include "GBAinline.h"
#include "Globals.h"
#include "GBAGfx.h"
#include "EEprom.h"
#include "Flash.h"
#include "Sound.h"
#include "Sram.h"
#include "bios.h"
#include "Cheats.h"
#include "../NLS.h"
#include "elf.h"
#include "../Util.h"
#include "../common/Port.h"
#include "../common/ConfigManager.h"
#include "../System.h"
#include "agbprint.h"
#include "bios.h"
#include "elf.h"
#include "ereader.h"
#include "GBALink.h"
#ifdef PROFILING
#include "prof/prof.h"
@ -143,18 +143,13 @@ const u8 gamepakWaitState[4] = { 4, 3, 2, 8 };
const u8 gamepakWaitState0[2] = { 2, 1 };
const u8 gamepakWaitState1[2] = { 4, 1 };
const u8 gamepakWaitState2[2] = { 8, 1 };
const bool isInRom [16]=
{ false, false, false, false, false, false, false, false,
const bool isInRom[16] = { false, false, false, false, false, false, false, false,
true, true, true, true, true, true, false, false };
u8 memoryWait[16] =
{ 0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 0 };
u8 memoryWait32[16] =
{ 0, 0, 5, 0, 0, 1, 1, 0, 7, 7, 9, 9, 13, 13, 4, 0 };
u8 memoryWaitSeq[16] =
{ 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 4, 4, 8, 8, 4, 0 };
u8 memoryWaitSeq32[16] =
{ 0, 0, 5, 0, 0, 1, 1, 0, 5, 5, 9, 9, 17, 17, 4, 0 };
u8 memoryWait[16] = { 0, 0, 2, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 0 };
u8 memoryWait32[16] = { 0, 0, 5, 0, 0, 1, 1, 0, 7, 7, 9, 9, 13, 13, 4, 0 };
u8 memoryWaitSeq[16] = { 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 4, 4, 8, 8, 4, 0 };
u8 memoryWaitSeq32[16] = { 0, 0, 5, 0, 0, 1, 1, 0, 5, 5, 9, 9, 17, 17, 4, 0 };
// The videoMemoryWait constants are used to add some waitstates
// if the opcode access video memory data outside of vblank/hblank
@ -163,7 +158,6 @@ u8 memoryWaitSeq32[16] =
//const u8 videoMemoryWait[16] =
// {0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
u8 biosProtected[4];
#ifdef WORDS_BIGENDIAN
@ -482,7 +476,6 @@ void cpuEnableProfiling(int hz)
}
#endif
inline int CPUUpdateTicks()
{
int cpuLoopTicks = lcdTicks;
@ -566,7 +559,7 @@ extern u32 line3[240];
for (int i = 0; i < 240; i++) { \
*array++ = 0x80000000; \
} \
}\
}
void CPUUpdateRenderBuffers(bool force)
{
@ -683,7 +676,6 @@ bool CPUWriteState(const char *file)
return res;
}
bool CPUWriteMemState(char* memory, int available, long& reserved)
{
gzFile gzFile = utilMemGzOpen(memory, available, "w");
@ -705,7 +697,6 @@ bool CPUWriteMemState(char *memory, int available, long& reserved)
}
#endif
#ifdef __LIBRETRO__
bool CPUReadState(const u8* data, unsigned size)
{
@ -731,8 +722,7 @@ bool CPUReadState(const u8* data, unsigned size)
IRQTicks = utilReadIntMem(data);
if (IRQTicks > 0)
intState = true;
else
{
else {
intState = false;
IRQTicks = 0;
}
@ -854,18 +844,14 @@ static bool CPUReadState(gzFile gzFile)
else
stopState = utilReadInt(gzFile) ? true : false;
if(version < SAVE_GAME_VERSION_4)
{
if (version < SAVE_GAME_VERSION_4) {
IRQTicks = 0;
intState = false;
}
else
{
} else {
IRQTicks = utilReadInt(gzFile);
if (IRQTicks > 0)
intState = true;
else
{
else {
intState = false;
IRQTicks = 0;
}
@ -1020,7 +1006,8 @@ bool CPUWriteBatteryFile(const char *fileName)
if (gbaSaveType == 0) {
if (eepromInUse)
gbaSaveType = 3;
else switch(saveType) {
else
switch (saveType) {
case 1:
gbaSaveType = 1;
break;
@ -1134,7 +1121,8 @@ bool CPUReadGSASPSnapshot(const char *fileName)
const size_t namepos = 0x0c, namesz = 12;
const size_t footerpos = 0x42c, footersz = 4;
char footer[footersz+1], romname[namesz+1], savename[namesz+1];;
char footer[footersz + 1], romname[namesz + 1], savename[namesz + 1];
;
FILE* file = fopen(fileName, "rb");
if (!file) {
@ -1183,7 +1171,6 @@ bool CPUReadGSASPSnapshot(const char *fileName)
return true;
}
bool CPUWriteGSASnapshot(const char* fileName,
const char* title,
const char* desc,
@ -1506,8 +1493,7 @@ void SetMapMasks()
systemMessage(MSG_OUT_OF_MEMORY, N_("Failed to allocate memory for %s"),
"TRACE");
}
}
else {
} else {
map[i].trace = NULL;
map[i].breakPoints = NULL; //\\
@ -1563,8 +1549,7 @@ int CPULoadRom(const char *szFile)
}
} else
#endif //NO_DEBUGGER
if(szFile!=NULL)
{
if (szFile != NULL) {
if (!utilLoad(szFile,
utilIsGBAImage,
whereToLoad,
@ -1758,12 +1743,10 @@ void doMirroring (bool b)
romSizeRounded++;
u32 mirroredRomSize = (((romSizeRounded) >> 20) & 0x3F) << 20;
u32 mirroredRomAddress = mirroredRomSize;
if ((mirroredRomSize <=0x800000) && (b))
{
if ((mirroredRomSize <= 0x800000) && (b)) {
if (mirroredRomSize == 0)
mirroredRomSize = 0x100000;
while (mirroredRomAddress<0x01000000)
{
while (mirroredRomAddress < 0x01000000) {
memcpy((u16*)(rom + mirroredRomAddress), (u16*)(rom), mirroredRomSize);
mirroredRomAddress += mirroredRomSize;
}
@ -1794,8 +1777,7 @@ void CPUUpdateRender()
{
switch (DISPCNT & 7) {
case 0:
if((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
cpuDisableSfx)
if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx)
renderLine = mode0RenderLine;
else if (fxOn && !windowOn && !(layerEnable & 0x8000))
renderLine = mode0RenderLineNoWindow;
@ -1803,8 +1785,7 @@ void CPUUpdateRender()
renderLine = mode0RenderLineAll;
break;
case 1:
if((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
cpuDisableSfx)
if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx)
renderLine = mode1RenderLine;
else if (fxOn && !windowOn && !(layerEnable & 0x8000))
renderLine = mode1RenderLineNoWindow;
@ -1812,8 +1793,7 @@ void CPUUpdateRender()
renderLine = mode1RenderLineAll;
break;
case 2:
if((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
cpuDisableSfx)
if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx)
renderLine = mode2RenderLine;
else if (fxOn && !windowOn && !(layerEnable & 0x8000))
renderLine = mode2RenderLineNoWindow;
@ -1821,8 +1801,7 @@ void CPUUpdateRender()
renderLine = mode2RenderLineAll;
break;
case 3:
if((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
cpuDisableSfx)
if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx)
renderLine = mode3RenderLine;
else if (fxOn && !windowOn && !(layerEnable & 0x8000))
renderLine = mode3RenderLineNoWindow;
@ -1830,8 +1809,7 @@ void CPUUpdateRender()
renderLine = mode3RenderLineAll;
break;
case 4:
if((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
cpuDisableSfx)
if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx)
renderLine = mode4RenderLine;
else if (fxOn && !windowOn && !(layerEnable & 0x8000))
renderLine = mode4RenderLineNoWindow;
@ -1839,8 +1817,7 @@ void CPUUpdateRender()
renderLine = mode4RenderLineAll;
break;
case 5:
if((!fxOn && !windowOn && !(layerEnable & 0x8000)) ||
cpuDisableSfx)
if ((!fxOn && !windowOn && !(layerEnable & 0x8000)) || cpuDisableSfx)
renderLine = mode5RenderLine;
else if (fxOn && !windowOn && !(layerEnable & 0x8000))
renderLine = mode5RenderLineNoWindow;
@ -2057,7 +2034,8 @@ void CPUSoftwareInterrupt()
void CPUSoftwareInterrupt(int comment)
{
static bool disableMessage = false;
if(armState) comment >>= 16;
if (armState)
comment >>= 16;
#ifdef BKPT_SUPPORT
if (comment == 0xff) {
dbgOutput(NULL, reg[0].I);
@ -2105,13 +2083,10 @@ void CPUSoftwareInterrupt(int comment)
VCOUNT);
}
#endif
if ((comment & 0xF8) != 0xE0)
{
if ((comment & 0xF8) != 0xE0) {
CPUSoftwareInterrupt();
return;
}
else
{
} else {
if (CheckEReaderRegion())
BIOS_EReader_ScanCard(comment);
else
@ -2190,46 +2165,31 @@ void CPUSoftwareInterrupt(int comment)
case 0x0A:
BIOS_ArcTan2();
break;
case 0x0B:
{
case 0x0B: {
int len = (reg[2].I & 0x1FFFFF) >> 1;
if (!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + len) & 0xe000000) == 0))
{
if ((reg[2].I >> 24) & 1)
{
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + len) & 0xe000000) == 0)) {
if ((reg[2].I >> 24) & 1) {
if ((reg[2].I >> 26) & 1)
SWITicks = (7 + memoryWait32[(reg[1].I >> 24) & 0xF]) * (len >> 1);
else
SWITicks = (8 + memoryWait[(reg[1].I >> 24) & 0xF]) * (len);
}
else
{
} else {
if ((reg[2].I >> 26) & 1)
SWITicks = (10 + memoryWait32[(reg[0].I>>24) & 0xF] +
memoryWait32[(reg[1].I>>24) & 0xF]) * (len>>1);
SWITicks = (10 + memoryWait32[(reg[0].I >> 24) & 0xF] + memoryWait32[(reg[1].I >> 24) & 0xF]) * (len >> 1);
else
SWITicks = (11 + memoryWait[(reg[0].I>>24) & 0xF] +
memoryWait[(reg[1].I>>24) & 0xF]) * len;
SWITicks = (11 + memoryWait[(reg[0].I >> 24) & 0xF] + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
}
}
BIOS_CpuSet();
break;
case 0x0C:
{
case 0x0C: {
int len = (reg[2].I & 0x1FFFFF) >> 5;
if (!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + len) & 0xe000000) == 0))
{
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + len) & 0xe000000) == 0)) {
if ((reg[2].I >> 24) & 1)
SWITicks = (6 + memoryWait32[(reg[1].I>>24) & 0xF] +
7 * (memoryWaitSeq32[(reg[1].I>>24) & 0xF] + 1)) * len;
SWITicks = (6 + memoryWait32[(reg[1].I >> 24) & 0xF] + 7 * (memoryWaitSeq32[(reg[1].I >> 24) & 0xF] + 1)) * len;
else
SWITicks = (9 + memoryWait32[(reg[0].I>>24) & 0xF] +
memoryWait32[(reg[1].I>>24) & 0xF] +
7 * (memoryWaitSeq32[(reg[0].I>>24) & 0xF] +
memoryWaitSeq32[(reg[1].I>>24) & 0xF] + 2)) * len;
SWITicks = (9 + memoryWait32[(reg[0].I >> 24) & 0xF] + memoryWait32[(reg[1].I >> 24) & 0xF] + 7 * (memoryWaitSeq32[(reg[0].I >> 24) & 0xF] + memoryWaitSeq32[(reg[1].I >> 24) & 0xF] + 2)) * len;
}
}
BIOS_CpuFastSet();
@ -2243,89 +2203,66 @@ void CPUSoftwareInterrupt(int comment)
case 0x0F:
BIOS_ObjAffineSet();
break;
case 0x10:
{
case 0x10: {
int len = CPUReadHalfWord(reg[2].I);
if (!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + len) & 0xe000000) == 0))
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + len) & 0xe000000) == 0))
SWITicks = (32 + memoryWait[(reg[0].I >> 24) & 0xF]) * len;
}
BIOS_BitUnPack();
break;
case 0x11:
{
case 0x11: {
u32 len = CPUReadMemory(reg[0].I) >> 8;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (9 + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
BIOS_LZ77UnCompWram();
break;
case 0x12:
{
case 0x12: {
u32 len = CPUReadMemory(reg[0].I) >> 8;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (19 + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
BIOS_LZ77UnCompVram();
break;
case 0x13:
{
case 0x13: {
u32 len = CPUReadMemory(reg[0].I) >> 8;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (29 + (memoryWait[(reg[0].I >> 24) & 0xF] << 1)) * len;
}
BIOS_HuffUnComp();
break;
case 0x14:
{
case 0x14: {
u32 len = CPUReadMemory(reg[0].I) >> 8;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (11 + memoryWait[(reg[0].I>>24) & 0xF] +
memoryWait[(reg[1].I>>24) & 0xF]) * len;
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (11 + memoryWait[(reg[0].I >> 24) & 0xF] + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
BIOS_RLUnCompWram();
break;
case 0x15:
{
case 0x15: {
u32 len = CPUReadMemory(reg[0].I) >> 9;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (34 + (memoryWait[(reg[0].I>>24) & 0xF] << 1) +
memoryWait[(reg[1].I>>24) & 0xF]) * len;
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (34 + (memoryWait[(reg[0].I >> 24) & 0xF] << 1) + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
BIOS_RLUnCompVram();
break;
case 0x16:
{
case 0x16: {
u32 len = CPUReadMemory(reg[0].I) >> 8;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (13 + memoryWait[(reg[0].I>>24) & 0xF] +
memoryWait[(reg[1].I>>24) & 0xF]) * len;
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (13 + memoryWait[(reg[0].I >> 24) & 0xF] + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
BIOS_Diff8bitUnFilterWram();
break;
case 0x17:
{
case 0x17: {
u32 len = CPUReadMemory(reg[0].I) >> 9;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (39 + (memoryWait[(reg[0].I>>24) & 0xF]<<1) +
memoryWait[(reg[1].I>>24) & 0xF]) * len;
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (39 + (memoryWait[(reg[0].I >> 24) & 0xF] << 1) + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
BIOS_Diff8bitUnFilterVram();
break;
case 0x18:
{
case 0x18: {
u32 len = CPUReadMemory(reg[0].I) >> 9;
if(!(((reg[0].I & 0xe000000) == 0) ||
((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (13 + memoryWait[(reg[0].I>>24) & 0xF] +
memoryWait[(reg[1].I>>24) & 0xF]) * len;
if (!(((reg[0].I & 0xe000000) == 0) || ((reg[0].I + (len & 0x1fffff)) & 0xe000000) == 0))
SWITicks = (13 + memoryWait[(reg[0].I >> 24) & 0xF] + memoryWait[(reg[1].I >> 24) & 0xF]) * len;
}
BIOS_Diff16bitUnFilter();
break;
@ -2418,13 +2355,11 @@ void CPUCompareVCOUNT()
DISPSTAT &= 0xFFFB;
UPDATE_REG(0x4, DISPSTAT);
}
if (layerEnableDelay>0)
{
if (layerEnableDelay > 0) {
layerEnableDelay--;
if (layerEnableDelay == 1)
layerEnable = layerSettings & DISPCNT;
}
}
void doDMA(u32& s, u32& d, u32 si, u32 di, u32 c, int transfer32)
@ -2492,15 +2427,11 @@ void doDMA(u32 &s, u32 &d, u32 si, u32 di, u32 c, int transfer32)
if (transfer32) {
sw = 1 + memoryWaitSeq32[sm & 15];
dw = 1 + memoryWaitSeq32[dm & 15];
totalTicks = (sw+dw)*(sc-1) + 6 + memoryWait32[sm & 15] +
memoryWaitSeq32[dm & 15];
}
else
{
totalTicks = (sw + dw) * (sc - 1) + 6 + memoryWait32[sm & 15] + memoryWaitSeq32[dm & 15];
} else {
sw = 1 + memoryWaitSeq[sm & 15];
dw = 1 + memoryWaitSeq[dm & 15];
totalTicks = (sw+dw)*(sc-1) + 6 + memoryWait[sm & 15] +
memoryWaitSeq[dm & 15];
totalTicks = (sw + dw) * (sc - 1) + 6 + memoryWait[sm & 15] + memoryWaitSeq[dm & 15];
}
cpuDmaTicksToUpdate += totalTicks;
@ -2761,10 +2692,8 @@ void CPUCheckDMA(int reason, int dmamask)
void CPUUpdateRegister(u32 address, u16 value)
{
switch(address)
{
case 0x00:
{ // we need to place the following code in { } because we declare & initialize variables in a case statement
switch (address) {
case 0x00: { // we need to place the following code in { } because we declare & initialize variables in a case statement
if ((value & 7) > 5) {
// display modes above 0-5 are prohibited
DISPCNT = (value & 7);
@ -3025,8 +2954,7 @@ void CPUUpdateRegister(u32 address, u16 value)
DM0CNT_L = value & 0x3FFF;
UPDATE_REG(0xB8, 0);
break;
case 0xBA:
{
case 0xBA: {
bool start = ((DM0CNT_H ^ value) & 0x8000) ? true : false;
value &= 0xF7E0;
@ -3038,8 +2966,7 @@ void CPUUpdateRegister(u32 address, u16 value)
dma0Dest = DM0DAD_L | (DM0DAD_H << 16);
CPUCheckDMA(0, 1);
}
}
break;
} break;
case 0xBC:
DM1SAD_L = value;
UPDATE_REG(0xBC, DM1SAD_L);
@ -3060,8 +2987,7 @@ void CPUUpdateRegister(u32 address, u16 value)
DM1CNT_L = value & 0x3FFF;
UPDATE_REG(0xC4, 0);
break;
case 0xC6:
{
case 0xC6: {
bool start = ((DM1CNT_H ^ value) & 0x8000) ? true : false;
value &= 0xF7E0;
@ -3073,8 +2999,7 @@ void CPUUpdateRegister(u32 address, u16 value)
dma1Dest = DM1DAD_L | (DM1DAD_H << 16);
CPUCheckDMA(0, 2);
}
}
break;
} break;
case 0xC8:
DM2SAD_L = value;
UPDATE_REG(0xC8, DM2SAD_L);
@ -3095,8 +3020,7 @@ void CPUUpdateRegister(u32 address, u16 value)
DM2CNT_L = value & 0x3FFF;
UPDATE_REG(0xD0, 0);
break;
case 0xD2:
{
case 0xD2: {
bool start = ((DM2CNT_H ^ value) & 0x8000) ? true : false;
value &= 0xF7E0;
@ -3110,8 +3034,7 @@ void CPUUpdateRegister(u32 address, u16 value)
CPUCheckDMA(0, 4);
}
}
break;
} break;
case 0xD4:
DM3SAD_L = value;
UPDATE_REG(0xD4, DM3SAD_L);
@ -3132,8 +3055,7 @@ void CPUUpdateRegister(u32 address, u16 value)
DM3CNT_L = value;
UPDATE_REG(0xDC, 0);
break;
case 0xDE:
{
case 0xDE: {
bool start = ((DM3CNT_H ^ value) & 0x8000) ? true : false;
value &= 0xFFE0;
@ -3146,8 +3068,7 @@ void CPUUpdateRegister(u32 address, u16 value)
dma3Dest = DM3DAD_L | (DM3DAD_H << 16);
CPUCheckDMA(0, 8);
}
}
break;
} break;
case 0x100:
timer0Reload = value;
interp_rate();
@ -3183,7 +3104,6 @@ void CPUUpdateRegister(u32 address, u16 value)
cpuNextEvent = cpuTotalTicks;
break;
#ifndef NO_LINK
case COMM_SIOCNT:
StartLink(value);
@ -3208,18 +3128,20 @@ void CPUUpdateRegister(u32 address, u16 value)
StartGPLink(value);
break;
case COMM_JOYCNT:
{
case COMM_JOYCNT: {
u16 cur = READ16LE(&ioMem[COMM_JOYCNT]);
if (value & JOYCNT_RESET) cur &= ~JOYCNT_RESET;
if (value & JOYCNT_RECV_COMPLETE) cur &= ~JOYCNT_RECV_COMPLETE;
if (value & JOYCNT_SEND_COMPLETE) cur &= ~JOYCNT_SEND_COMPLETE;
if (value & JOYCNT_INT_ENABLE) cur |= JOYCNT_INT_ENABLE;
if (value & JOYCNT_RESET)
cur &= ~JOYCNT_RESET;
if (value & JOYCNT_RECV_COMPLETE)
cur &= ~JOYCNT_RECV_COMPLETE;
if (value & JOYCNT_SEND_COMPLETE)
cur &= ~JOYCNT_SEND_COMPLETE;
if (value & JOYCNT_INT_ENABLE)
cur |= JOYCNT_INT_ENABLE;
UPDATE_REG(COMM_JOYCNT, cur);
}
break;
} break;
case COMM_JOY_RECV_L:
UPDATE_REG(COMM_JOY_RECV_L, value);
@ -3252,22 +3174,18 @@ void CPUUpdateRegister(u32 address, u16 value)
IF ^= (value & IF);
UPDATE_REG(0x202, IF);
break;
case 0x204:
{
case 0x204: {
memoryWait[0x0e] = memoryWaitSeq[0x0e] = gamepakRamWaitState[value & 3];
if (!speedHack) {
memoryWait[0x08] = memoryWait[0x09] = gamepakWaitState[(value >> 2) & 3];
memoryWaitSeq[0x08] = memoryWaitSeq[0x09] =
gamepakWaitState0[(value >> 4) & 1];
memoryWaitSeq[0x08] = memoryWaitSeq[0x09] = gamepakWaitState0[(value >> 4) & 1];
memoryWait[0x0a] = memoryWait[0x0b] = gamepakWaitState[(value >> 5) & 3];
memoryWaitSeq[0x0a] = memoryWaitSeq[0x0b] =
gamepakWaitState1[(value >> 7) & 1];
memoryWaitSeq[0x0a] = memoryWaitSeq[0x0b] = gamepakWaitState1[(value >> 7) & 1];
memoryWait[0x0c] = memoryWait[0x0d] = gamepakWaitState[(value >> 8) & 3];
memoryWaitSeq[0x0c] = memoryWaitSeq[0x0d] =
gamepakWaitState2[(value >> 10) & 1];
memoryWaitSeq[0x0c] = memoryWaitSeq[0x0d] = gamepakWaitState2[(value >> 10) & 1];
} else {
memoryWait[0x08] = memoryWait[0x09] = 3;
memoryWaitSeq[0x08] = memoryWaitSeq[0x09] = 1;
@ -3295,8 +3213,7 @@ void CPUUpdateRegister(u32 address, u16 value)
}
UPDATE_REG(0x204, value & 0x7FFF);
}
break;
} break;
case 0x208:
IME = value & 1;
UPDATE_REG(0x208, IME);
@ -3316,8 +3233,7 @@ void CPUUpdateRegister(u32 address, u16 value)
void applyTimer()
{
if (timerOnOffDelay & 1)
{
if (timerOnOffDelay & 1) {
timer0ClockReload = TIMER_TICKS[timer0Value & 3];
if (!timer0On && (timer0Value & 0x80)) {
// reload the counter
@ -3331,8 +3247,7 @@ void applyTimer ()
UPDATE_REG(0x102, TM0CNT);
// CPUUpdateTicks();
}
if (timerOnOffDelay & 2)
{
if (timerOnOffDelay & 2) {
timer1ClockReload = TIMER_TICKS[timer1Value & 3];
if (!timer1On && (timer1Value & 0x80)) {
// reload the counter
@ -3345,8 +3260,7 @@ void applyTimer ()
interp_rate();
UPDATE_REG(0x106, TM1CNT);
}
if (timerOnOffDelay & 4)
{
if (timerOnOffDelay & 4) {
timer2ClockReload = TIMER_TICKS[timer2Value & 3];
if (!timer2On && (timer2Value & 0x80)) {
// reload the counter
@ -3358,8 +3272,7 @@ void applyTimer ()
TM2CNT = timer2Value & 0xC7;
UPDATE_REG(0x10A, TM2CNT);
}
if (timerOnOffDelay & 8)
{
if (timerOnOffDelay & 8) {
timer3ClockReload = TIMER_TICKS[timer3Value & 3];
if (!timer3On && (timer3Value & 0x80)) {
// reload the counter
@ -3544,8 +3457,7 @@ void CPUReset()
break;
}
}
switch (CheckEReaderRegion())
{
switch (CheckEReaderRegion()) {
case 1: //US
EReaderWriteMemory(0x8009134, 0x46C0DFE0);
break;
@ -3823,7 +3735,6 @@ void CPULoop(int ticks)
if (cpuNextEvent > ticks)
cpuNextEvent = ticks;
for (;;) {
if (!holdState && !SWITicks) {
if (armState) {
@ -3851,8 +3762,7 @@ void CPULoop(int ticks)
if (cpuTotalTicks >= cpuNextEvent) {
int remainingTicks = cpuTotalTicks - cpuNextEvent;
if (SWITicks)
{
if (SWITicks) {
SWITicks -= clockTicks;
if (SWITicks < 0)
SWITicks = 0;
@ -3863,8 +3773,7 @@ void CPULoop(int ticks)
updateLoop:
if (IRQTicks)
{
if (IRQTicks) {
IRQTicks -= clockTicks;
if (IRQTicks < 0)
IRQTicks = 0;
@ -3872,7 +3781,6 @@ void CPULoop(int ticks)
lcdTicks -= clockTicks;
if (lcdTicks <= 0) {
if (DISPSTAT & 1) { // V-BLANK
// if in V-Blank mode, keep computing...
@ -3990,12 +3898,10 @@ void CPULoop(int ticks)
CPUCompareVCOUNT();
} else {
if(frameCount >= framesToSkip)
{
if (frameCount >= framesToSkip) {
(*renderLine)();
switch (systemColorDepth) {
case 16:
{
case 16: {
#ifdef __LIBRETRO__
u16* dest = (u16*)pix + 240 * VCOUNT;
#else
@ -4026,10 +3932,8 @@ void CPULoop(int ticks)
#ifndef __LIBRETRO__
*dest++ = 0;
#endif
}
break;
case 24:
{
} break;
case 24: {
u8* dest = (u8*)pix + 240 * VCOUNT * 3;
for (int x = 0; x < 240;) {
*((u32*)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
@ -4068,10 +3972,8 @@ void CPULoop(int ticks)
*((u32*)dest) = systemColorMap32[lineMix[x++] & 0xFFFF];
dest += 3;
}
}
break;
case 32:
{
} break;
case 32: {
#ifdef __LIBRETRO__
u32* dest = (u32*)pix + 240 * VCOUNT;
#else
@ -4098,8 +4000,7 @@ void CPULoop(int ticks)
*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
*dest++ = systemColorMap32[lineMix[x++] & 0xFFFF];
}
}
break;
} break;
}
}
// entering H-Blank
@ -4230,8 +4131,6 @@ void CPULoop(int ticks)
timerOverflow = 0;
#ifdef PROFILING
profilingTicks -= clockTicks;
if (profilingTicks <= 0) {
@ -4283,28 +4182,21 @@ void CPULoop(int ticks)
if (stopState)
res &= 0x3080;
if (res) {
if (intState)
{
if (!IRQTicks)
{
if (intState) {
if (!IRQTicks) {
CPUInterrupt();
intState = false;
holdState = false;
stopState = false;
holdType = 0;
}
}
else
{
if (!holdState)
{
} else {
if (!holdState) {
intState = true;
IRQTicks = 7;
if (cpuNextEvent > IRQTicks)
cpuNextEvent = IRQTicks;
}
else
{
} else {
CPUInterrupt();
holdState = false;
stopState = false;
@ -4338,7 +4230,6 @@ void CPULoop(int ticks)
if (ticks <= 0 || cpuBreakLoop)
break;
}
}
#ifndef NO_LINK
@ -4348,8 +4239,7 @@ void CPULoop(int ticks)
}
#ifdef TILED_RENDERING
union u8h
{
union u8h {
struct
{
/* 0*/ unsigned lo : 4;
@ -4358,8 +4248,7 @@ union u8h
u8 val;
};
union TileEntry
{
union TileEntry {
struct
{
/* 0*/ unsigned tileNum : 10;
@ -4370,8 +4259,7 @@ union TileEntry
u16 val;
};
struct TileLine
{
struct TileLine {
u32 pixels[8];
};
@ -4388,13 +4276,13 @@ inline const TileLine gfxReadTile(const u16 *screenSource, const int yyy, const
tile.val = READ16LE(screenSource);
int tileY = yyy & 7;
if (tile.vFlip) tileY = 7 - tileY;
if (tile.vFlip)
tileY = 7 - tileY;
TileLine tileLine;
const u8* tileBase = &charBase[tile.tileNum * 64 + tileY * 8];
if (!tile.hFlip)
{
if (!tile.hFlip) {
gfxDrawPixel(&tileLine.pixels[0], tileBase[0], palette, prio);
gfxDrawPixel(&tileLine.pixels[1], tileBase[1], palette, prio);
gfxDrawPixel(&tileLine.pixels[2], tileBase[2], palette, prio);
@ -4403,9 +4291,7 @@ inline const TileLine gfxReadTile(const u16 *screenSource, const int yyy, const
gfxDrawPixel(&tileLine.pixels[5], tileBase[5], palette, prio);
gfxDrawPixel(&tileLine.pixels[6], tileBase[6], palette, prio);
gfxDrawPixel(&tileLine.pixels[7], tileBase[7], palette, prio);
}
else
{
} else {
gfxDrawPixel(&tileLine.pixels[0], tileBase[7], palette, prio);
gfxDrawPixel(&tileLine.pixels[1], tileBase[6], palette, prio);
gfxDrawPixel(&tileLine.pixels[2], tileBase[5], palette, prio);
@ -4425,14 +4311,14 @@ inline const TileLine gfxReadTilePal(const u16 *screenSource, const int yyy, con
tile.val = READ16LE(screenSource);
int tileY = yyy & 7;
if (tile.vFlip) tileY = 7 - tileY;
if (tile.vFlip)
tileY = 7 - tileY;
palette += tile.palette * 16;
TileLine tileLine;
const u8h* tileBase = (u8h*)&charBase[tile.tileNum * 32 + tileY * 4];
if (!tile.hFlip)
{
if (!tile.hFlip) {
gfxDrawPixel(&tileLine.pixels[0], tileBase[0].lo, palette, prio);
gfxDrawPixel(&tileLine.pixels[1], tileBase[0].hi, palette, prio);
gfxDrawPixel(&tileLine.pixels[2], tileBase[1].lo, palette, prio);
@ -4441,9 +4327,7 @@ inline const TileLine gfxReadTilePal(const u16 *screenSource, const int yyy, con
gfxDrawPixel(&tileLine.pixels[5], tileBase[2].hi, palette, prio);
gfxDrawPixel(&tileLine.pixels[6], tileBase[3].lo, palette, prio);
gfxDrawPixel(&tileLine.pixels[7], tileBase[3].hi, palette, prio);
}
else
{
} else {
gfxDrawPixel(&tileLine.pixels[0], tileBase[3].hi, palette, prio);
gfxDrawPixel(&tileLine.pixels[1], tileBase[3].lo, palette, prio);
gfxDrawPixel(&tileLine.pixels[2], tileBase[2].hi, palette, prio);
@ -4477,8 +4361,7 @@ static void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs,
u32 prio = ((control & 3) << 25) + 0x1000000;
int sizeX = 256;
int sizeY = 256;
switch ((control >> 14) & 3)
{
switch ((control >> 14) & 3) {
case 0:
break;
case 1:
@ -4503,17 +4386,14 @@ static void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs,
int mosaicX = (MOSAIC & 0x000F) + 1;
int mosaicY = ((MOSAIC & 0x00F0) >> 4) + 1;
if (mosaicOn)
{
if ((VCOUNT % mosaicY) != 0)
{
if (mosaicOn) {
if ((VCOUNT % mosaicY) != 0) {
mosaicY = VCOUNT - (VCOUNT % mosaicY);
yyy = (vofs + mosaicY) & maskY;
}
}
if (yyy > 255 && sizeY > 256)
{
if (yyy > 255 && sizeY > 256) {
yyy &= 255;
screenBase += 0x400;
if (sizeX > 256)
@ -4527,60 +4407,47 @@ static void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs,
const int firstTileX = xxx & 7;
// First tile, if clipped
if (firstTileX)
{
if (firstTileX) {
gfxDrawTileClipped(readTile(screenSource, yyy, charBase, palette, prio), &line[x], firstTileX, 8 - firstTileX);
screenSource++;
x += 8 - firstTileX;
xxx += 8 - firstTileX;
if (xxx == 256 && sizeX > 256)
{
if (xxx == 256 && sizeX > 256) {
screenSource = screenBase + 0x400 + yshift;
}
else if (xxx >= sizeX)
{
} else if (xxx >= sizeX) {
xxx = 0;
screenSource = screenBase + yshift;
}
}
// Middle tiles, full
while (x < 240 - firstTileX)
{
while (x < 240 - firstTileX) {
gfxDrawTile(readTile(screenSource, yyy, charBase, palette, prio), &line[x]);
screenSource++;
xxx += 8;
x += 8;
if (xxx == 256 && sizeX > 256)
{
if (xxx == 256 && sizeX > 256) {
screenSource = screenBase + 0x400 + yshift;
}
else if (xxx >= sizeX)
{
} else if (xxx >= sizeX) {
xxx = 0;
screenSource = screenBase + yshift;
}
}
// Last tile, if clipped
if (firstTileX)
{
if (firstTileX) {
gfxDrawTileClipped(readTile(screenSource, yyy, charBase, palette, prio), &line[x], 0, firstTileX);
}
if (mosaicOn)
{
if (mosaicX > 1)
{
if (mosaicOn) {
if (mosaicX > 1) {
int m = 1;
for (int i = 0; i < 239; i++)
{
for (int i = 0; i < 239; i++) {
line[i + 1] = line[i];
m++;
if (m == mosaicX)
{
if (m == mosaicX) {
m = 1;
i++;
}
@ -4598,7 +4465,6 @@ void gfxDrawTextScreen(u16 control, u16 hofs, u16 vofs, u32 *line)
}
#endif
struct EmulatedSystem GBASystem = {
// emuMain
CPULoop,

View File

@ -2,7 +2,8 @@
int coeff[32] = {
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 line1[240];

View File

@ -741,15 +741,10 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
t -= (t % mosaicY);
}
int realX = ((sizeX) << 7) -
(fieldX >> 1) * dx -
(fieldY >> 1) * dmx + t * dmx;
int realY = ((sizeY) << 7) -
(fieldX >> 1) * dy -
(fieldY >> 1) * dmy + t * dmy;
int realX = ((sizeX) << 7) - (fieldX >> 1) * dx - (fieldY >> 1) * dmx + t * dmx;
int realY = ((sizeY) << 7) - (fieldX >> 1) * dy - (fieldY >> 1) * dmy + t * dmy;
u32 prio = (((a2 >> 10) & 3) << 25) |
((a0 & 0x0c00) << 6);
u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00) << 6);
if (a0 & 0x2000) {
int c = (a2 & 0x3FF);
@ -768,81 +763,52 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
int xxx = realX >> 8;
int yyy = realY >> 8;
if (xxx < 0 ||
xxx >= sizeX ||
yyy < 0 ||
yyy >= sizeY ||
sx >= 240)
if (xxx < 0 || xxx >= sizeX || yyy < 0 || yyy >= sizeY || sx >= 240)
;
else {
u32 color = vram
[0x10000 +
((((c +
(yyy >>
3) *
inc)
<< 5) +
((yyy & 7)
<< 3) +
((xxx >> 3)
<< 6) +
(xxx & 7)) &
0x7FFF)];
if ((color == 0) &&
(((prio >> 25) &
3) <
((lineOBJ
[sx] >>
25) &
3))) {
lineOBJ[sx] =
(lineOBJ
[sx] &
0xF9FFFFFF) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
[0x10000 + ((((c + (yyy >> 3) * inc)
<< 5)
+ ((yyy & 7)
<< 3)
+ ((xxx >> 3)
<< 6)
+ (xxx & 7))
& 0x7FFF)];
if ((color == 0) && (((prio >> 25) & 3) < ((lineOBJ
[sx]
>> 25)
& 3))) {
lineOBJ[sx] = (lineOBJ
[sx]
& 0xF9FFFFFF)
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
} else if (
(color) &&
(prio <
(lineOBJ[sx] &
0xFF000000))) {
lineOBJ[sx] =
READ16LE(
(color) && (prio < (lineOBJ[sx] & 0xFF000000))) {
lineOBJ[sx] = READ16LE(
&spritePalette
[color]) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
[color])
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
}
if (a0 & 0x1000) {
m++;
if (m ==
mosaicX)
if (m == mosaicX)
m = 0;
}
#ifdef SPRITE_DEBUG
if (t == 0 ||
t == maskY ||
x == 0 ||
x == maskX)
lineOBJ[sx] =
0x001F;
if (t == 0 || t == maskY || x == 0 || x == maskX)
lineOBJ[sx] = 0x001F;
#endif
}
sx = (sx + 1) & 511;
@ -865,74 +831,47 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
continue;
int xxx = realX >> 8;
int yyy = realY >> 8;
if (xxx < 0 ||
xxx >= sizeX ||
yyy < 0 ||
yyy >= sizeY ||
sx >= 240)
if (xxx < 0 || xxx >= sizeX || yyy < 0 || yyy >= sizeY || sx >= 240)
;
else {
u32 color = vram
[0x10000 +
((((c +
(yyy >>
3) *
inc)
<< 5) +
((yyy & 7)
<< 2) +
((xxx >> 3)
<< 5) +
((xxx & 7) >>
1)) &
0x7FFF)];
[0x10000 + ((((c + (yyy >> 3) * inc)
<< 5)
+ ((yyy & 7)
<< 2)
+ ((xxx >> 3)
<< 5)
+ ((xxx & 7) >> 1))
& 0x7FFF)];
if (xxx & 1)
color >>= 4;
else
color &=
0x0F;
color &= 0x0F;
if ((color == 0) &&
(((prio >> 25) &
3) <
((lineOBJ
[sx] >>
25) &
3))) {
lineOBJ[sx] =
(lineOBJ
[sx] &
0xF9FFFFFF) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
if ((color == 0) && (((prio >> 25) & 3) < ((lineOBJ
[sx]
>> 25)
& 3))) {
lineOBJ[sx] = (lineOBJ
[sx]
& 0xF9FFFFFF)
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
} else if (
(color) &&
(prio <
(lineOBJ[sx] &
0xFF000000))) {
lineOBJ[sx] =
READ16LE(
(color) && (prio < (lineOBJ[sx] & 0xFF000000))) {
lineOBJ[sx] = READ16LE(
&spritePalette
[palette +
color]) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
[palette + color])
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
}
}
if ((a0 & 0x1000) && m) {
@ -942,10 +881,8 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
}
#ifdef SPRITE_DEBUG
if (t == 0 || t == maskY ||
x == 0 || x == maskX)
lineOBJ[sx] =
0x001F;
if (t == 0 || t == maskY || x == 0 || x == maskX)
lineOBJ[sx] = 0x001F;
#endif
sx = (sx + 1) & 511;
realX += dx;
@ -986,17 +923,11 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
t -= (t % mosaicY);
}
int address =
0x10000 +
((((c + (t >> 3) * inc) << 5) +
((t & 7) << 3) + ((xxx >> 3) << 6) +
(xxx & 7)) &
0x7FFF);
int address = 0x10000 + ((((c + (t >> 3) * inc) << 5) + ((t & 7) << 3) + ((xxx >> 3) << 6) + (xxx & 7)) & 0x7FFF);
if (a1 & 0x1000)
xxx = 7;
u32 prio = (((a2 >> 10) & 3) << 25) |
((a0 & 0x0c00) << 6);
u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00) << 6);
for (int xx = 0; xx < sizeX; xx++) {
if (xx >= startpix)
@ -1005,39 +936,23 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
continue;
if (sx < 240) {
u8 color = vram[address];
if ((color == 0) &&
(((prio >> 25) & 3) <
((lineOBJ[sx] >> 25) &
3))) {
lineOBJ[sx] =
(lineOBJ[sx] &
0xF9FFFFFF) |
prio;
if ((a0 & 0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
} else if ((color) &&
(prio <
(lineOBJ[sx] &
0xFF000000))) {
lineOBJ[sx] =
READ16LE(
if ((color == 0) && (((prio >> 25) & 3) < ((lineOBJ[sx] >> 25) & 3))) {
lineOBJ[sx] = (lineOBJ[sx] & 0xF9FFFFFF) | prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
} else if ((color) && (prio < (lineOBJ[sx] & 0xFF000000))) {
lineOBJ[sx] = READ16LE(
&spritePalette
[color]) |
prio;
if ((a0 & 0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
[color])
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
}
if (a0 & 0x1000) {
@ -1047,10 +962,8 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
}
#ifdef SPRITE_DEBUG
if (t == 0 || t == maskY ||
xx == 0 || xx == maskX)
lineOBJ[sx] =
0x001F;
if (t == 0 || t == maskY || xx == 0 || xx == maskX)
lineOBJ[sx] = 0x001F;
#endif
}
@ -1094,14 +1007,8 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
t -= (t % mosaicY);
}
int address =
0x10000 +
((((c + (t >> 3) * inc) << 5) +
((t & 7) << 2) + ((xxx >> 3) << 5) +
((xxx & 7) >> 1)) &
0x7FFF);
u32 prio = (((a2 >> 10) & 3) << 25) |
((a0 & 0x0c00) << 6);
int address = 0x10000 + ((((c + (t >> 3) * inc) << 5) + ((t & 7) << 2) + ((xxx >> 3) << 5) + ((xxx & 7) >> 1)) & 0x7FFF);
u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 & 0x0c00) << 6);
int palette = (a2 >> 8) & 0xF0;
if (a1 & 0x1000) {
xxx = 7;
@ -1112,57 +1019,36 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
if (lineOBJpix < 0)
continue;
if (sx < 240) {
u8 color =
vram[address];
u8 color = vram[address];
if (xx & 1) {
color =
(color >>
4);
color = (color >> 4);
} else
color &=
0x0F;
color &= 0x0F;
if ((color == 0) &&
(((prio >> 25) &
3) <
((lineOBJ
[sx] >>
25) &
3))) {
lineOBJ[sx] =
(lineOBJ
[sx] &
0xF9FFFFFF) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
if ((color == 0) && (((prio >> 25) & 3) < ((lineOBJ
[sx]
>> 25)
& 3))) {
lineOBJ[sx] = (lineOBJ
[sx]
& 0xF9FFFFFF)
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
} else if (
(color) &&
(prio <
(lineOBJ[sx] &
0xFF000000))) {
lineOBJ[sx] =
READ16LE(
(color) && (prio < (lineOBJ[sx] & 0xFF000000))) {
lineOBJ[sx] = READ16LE(
&spritePalette
[palette +
color]) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
[palette + color])
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
}
}
if (a0 & 0x1000) {
@ -1171,10 +1057,8 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
m = 0;
}
#ifdef SPRITE_DEBUG
if (t == 0 || t == maskY ||
xx == 0 || xx == maskX)
lineOBJ[sx] =
0x001F;
if (t == 0 || t == maskY || xx == 0 || xx == maskX)
lineOBJ[sx] = 0x001F;
#endif
sx = (sx + 1) & 511;
xxx--;
@ -1194,57 +1078,36 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
if (lineOBJpix < 0)
continue;
if (sx < 240) {
u8 color =
vram[address];
u8 color = vram[address];
if (xx & 1) {
color =
(color >>
4);
color = (color >> 4);
} else
color &=
0x0F;
color &= 0x0F;
if ((color == 0) &&
(((prio >> 25) &
3) <
((lineOBJ
[sx] >>
25) &
3))) {
lineOBJ[sx] =
(lineOBJ
[sx] &
0xF9FFFFFF) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
if ((color == 0) && (((prio >> 25) & 3) < ((lineOBJ
[sx]
>> 25)
& 3))) {
lineOBJ[sx] = (lineOBJ
[sx]
& 0xF9FFFFFF)
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
} else if (
(color) &&
(prio <
(lineOBJ[sx] &
0xFF000000))) {
lineOBJ[sx] =
READ16LE(
(color) && (prio < (lineOBJ[sx] & 0xFF000000))) {
lineOBJ[sx] = READ16LE(
&spritePalette
[palette +
color]) |
prio;
if ((a0 &
0x1000) &&
m)
lineOBJ[sx] =
(lineOBJ
[sx -
1] &
0xF9FFFFFF) |
prio;
[palette + color])
| prio;
if ((a0 & 0x1000) && m)
lineOBJ[sx] = (lineOBJ
[sx - 1]
& 0xF9FFFFFF)
| prio;
}
}
if (a0 & 0x1000) {
@ -1253,10 +1116,8 @@ static inline void gfxDrawSprites(u32 *lineOBJ)
m = 0;
}
#ifdef SPRITE_DEBUG
if (t == 0 || t == maskY ||
xx == 0 || xx == maskX)
lineOBJ[sx] =
0x001F;
if (t == 0 || t == maskY || xx == 0 || xx == maskX)
lineOBJ[sx] = 0x001F;
#endif
sx = (sx + 1) & 511;
xxx++;
@ -1357,10 +1218,8 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin)
if (dmy & 0x8000)
dmy |= 0xFFFF8000;
int realX = ((sizeX) << 7) - (fieldX >> 1) * dx -
(fieldY >> 1) * dmx + t * dmx;
int realY = ((sizeY) << 7) - (fieldX >> 1) * dy -
(fieldY >> 1) * dmy + t * dmy;
int realX = ((sizeX) << 7) - (fieldX >> 1) * dx - (fieldY >> 1) * dmx + t * dmx;
int realY = ((sizeY) << 7) - (fieldX >> 1) * dy - (fieldY >> 1) * dmy + t * dmy;
// u32 prio = (((a2 >> 10) & 3) << 25) | ((a0 &
// 0x0c00)<<6);
@ -1382,19 +1241,13 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin)
int xxx = realX >> 8;
int yyy = realY >> 8;
if (xxx < 0 || xxx >= sizeX ||
yyy < 0 || yyy >= sizeY ||
sx >= 240) {
if (xxx < 0 || xxx >= sizeX || yyy < 0 || yyy >= sizeY || sx >= 240) {
} else {
u32 color = vram
[0x10000 +
((((c +
(yyy >> 3) * inc)
<< 5) +
((yyy & 7) << 3) +
((xxx >> 3) << 6) +
(xxx & 7)) &
0x7fff)];
[0x10000 + ((((c + (yyy >> 3) * inc)
<< 5)
+ ((yyy & 7) << 3) + ((xxx >> 3) << 6) + (xxx & 7))
& 0x7fff)];
if (color) {
lineOBJWin[sx] = 1;
}
@ -1427,19 +1280,13 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin)
// lineOBJ[sx] =
// 0x001F | prio;
// } else {
if (xxx < 0 || xxx >= sizeX ||
yyy < 0 || yyy >= sizeY ||
sx >= 240) {
if (xxx < 0 || xxx >= sizeX || yyy < 0 || yyy >= sizeY || sx >= 240) {
} else {
u32 color = vram
[0x10000 +
((((c +
(yyy >> 3) * inc)
<< 5) +
((yyy & 7) << 2) +
((xxx >> 3) << 5) +
((xxx & 7) >> 1)) &
0x7fff)];
[0x10000 + ((((c + (yyy >> 3) * inc)
<< 5)
+ ((yyy & 7) << 2) + ((xxx >> 3) << 5) + ((xxx & 7) >> 1))
& 0x7fff)];
if (xxx & 1)
color >>= 4;
else
@ -1485,12 +1332,7 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin)
int xxx = 0;
if (a1 & 0x1000)
xxx = sizeX - 1;
int address =
0x10000 +
((((c + (t >> 3) * inc) << 5) +
((t & 7) << 3) + ((xxx >> 3) << 6) +
(xxx & 7)) &
0x7fff);
int address = 0x10000 + ((((c + (t >> 3) * inc) << 5) + ((t & 7) << 3) + ((xxx >> 3) << 6) + (xxx & 7)) & 0x7fff);
if (a1 & 0x1000)
xxx = 7;
// u32 prio = (((a2 >> 10) & 3) << 25) |
@ -1542,12 +1384,7 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin)
int xxx = 0;
if (a1 & 0x1000)
xxx = sizeX - 1;
int address =
0x10000 +
((((c + (t >> 3) * inc) << 5) +
((t & 7) << 2) + ((xxx >> 3) << 5) +
((xxx & 7) >> 1)) &
0x7fff);
int address = 0x10000 + ((((c + (t >> 3) * inc) << 5) + ((t & 7) << 2) + ((xxx >> 3) << 5) + ((xxx & 7) >> 1)) & 0x7fff);
// u32 prio = (((a2 >> 10) & 3) << 25) |
// ((a0 & 0x0c00)<<6);
// int palette = (a2 >> 8) & 0xF0;
@ -1560,20 +1397,16 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin)
if (lineOBJpix < 0)
continue;
if (sx < 240) {
u8 color =
vram[address];
u8 color = vram[address];
if (xx & 1) {
color =
(color >>
4);
color = (color >> 4);
} else
color &=
0x0F;
color &= 0x0F;
if (color) {
lineOBJWin
[sx] =
1;
[sx]
= 1;
}
}
sx = (sx + 1) & 511;
@ -1594,20 +1427,16 @@ static inline void gfxDrawOBJWin(u32 *lineOBJWin)
if (lineOBJpix < 0)
continue;
if (sx < 240) {
u8 color =
vram[address];
u8 color = vram[address];
if (xx & 1) {
color =
(color >>
4);
color = (color >> 4);
} else
color &=
0x0F;
color &= 0x0F;
if (color) {
lineOBJWin
[sx] =
1;
[sx]
= 1;
}
}
sx = (sx + 1) & 511;

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,10 @@ enum LinkMode {
/**
* State of the connection attempt
*/
enum ConnectionState { LINK_OK, LINK_ERROR, LINK_NEEDS_UPDATE, LINK_ABORT };
enum ConnectionState { LINK_OK,
LINK_ERROR,
LINK_NEEDS_UPDATE,
LINK_ABORT };
/**
* Initialize GBA linking

View File

@ -46,8 +46,7 @@ char GBASockClient::ReceiveCmd(char* data_in, bool block)
return data_in[0];
std::size_t num_received = 0;
if (block || clock_sync == 0)
{
if (block || clock_sync == 0) {
sf::SocketSelector Selector;
Selector.add(client);
Selector.wait(sf::seconds(6));
@ -68,8 +67,7 @@ void GBASockClient::ReceiveClock(bool block)
if (clock_client.receive(sync_ticks, 4, num_received) == sf::Socket::Disconnected)
Disconnect();
if (num_received == 4)
{
if (num_received == 4) {
clock_sync_ticks = 0;
for (int i = 0; i < 4; i++)
clock_sync_ticks |= (u8)(sync_ticks[i]) << ((3 - i) * 8);

View File

@ -3,8 +3,7 @@
#include "../common/Types.h"
#include <SFML/Network.hpp>
class GBASockClient
{
class GBASockClient {
public:
GBASockClient(sf::IpAddress _server_addr);
~GBASockClient();

View File

@ -144,12 +144,10 @@ inline int codeTicksAccess16(u32 address) // THUMB NON SEQ
if ((addr >= 0x08) && (addr <= 0x0D)) {
if (busPrefetchCount & 0x1) {
if (busPrefetchCount & 0x2) {
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 2) |
(busPrefetchCount & 0xFFFFFF00);
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 2) | (busPrefetchCount & 0xFFFFFF00);
return 0;
}
busPrefetchCount =
((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
return memoryWaitSeq[addr] - 1;
} else {
busPrefetchCount = 0;
@ -168,12 +166,10 @@ inline int codeTicksAccess32(u32 address) // ARM NON SEQ
if ((addr >= 0x08) && (addr <= 0x0D)) {
if (busPrefetchCount & 0x1) {
if (busPrefetchCount & 0x2) {
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 2) |
(busPrefetchCount & 0xFFFFFF00);
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 2) | (busPrefetchCount & 0xFFFFFF00);
return 0;
}
busPrefetchCount =
((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
return memoryWaitSeq[addr] - 1;
} else {
busPrefetchCount = 0;
@ -191,8 +187,7 @@ inline int codeTicksAccessSeq16(u32 address) // THUMB SEQ
if ((addr >= 0x08) && (addr <= 0x0D)) {
if (busPrefetchCount & 0x1) {
busPrefetchCount =
((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
return 0;
} else if (busPrefetchCount > 0xFF) {
busPrefetchCount = 0;
@ -212,12 +207,10 @@ inline int codeTicksAccessSeq32(u32 address) // ARM SEQ
if ((addr >= 0x08) && (addr <= 0x0D)) {
if (busPrefetchCount & 0x1) {
if (busPrefetchCount & 0x2) {
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 2) |
(busPrefetchCount & 0xFFFFFF00);
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 2) | (busPrefetchCount & 0xFFFFFF00);
return 0;
}
busPrefetchCount =
((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
busPrefetchCount = ((busPrefetchCount & 0xFF) >> 1) | (busPrefetchCount & 0xFFFFFF00);
return memoryWaitSeq[addr];
} else if (busPrefetchCount > 0xFF) {
busPrefetchCount = 0;

View File

@ -154,8 +154,7 @@ static inline u32 CPUReadMemory(u32 address)
if (armState) {
return CPUReadMemoryQuick(reg[15].I);
} else {
return CPUReadHalfWordQuick(reg[15].I) |
CPUReadHalfWordQuick(reg[15].I) << 16;
return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
}
}
break;
@ -242,17 +241,13 @@ static inline u32 CPUReadHalfWord(u32 address)
value = READ16LE(((u16*)&ioMem[address & 0x3fe]));
if (((address & 0x3fe) > 0xFF) && ((address & 0x3fe) < 0x10E)) {
if (((address & 0x3fe) == 0x100) && timer0On)
value = 0xFFFF - ((timer0Ticks - cpuTotalTicks) >>
timer0ClockReload);
value = 0xFFFF - ((timer0Ticks - cpuTotalTicks) >> timer0ClockReload);
else if (((address & 0x3fe) == 0x104) && timer1On && !(TM1CNT & 4))
value = 0xFFFF - ((timer1Ticks - cpuTotalTicks) >>
timer1ClockReload);
value = 0xFFFF - ((timer1Ticks - cpuTotalTicks) >> timer1ClockReload);
else if (((address & 0x3fe) == 0x108) && timer2On && !(TM2CNT & 4))
value = 0xFFFF - ((timer2Ticks - cpuTotalTicks) >>
timer2ClockReload);
value = 0xFFFF - ((timer2Ticks - cpuTotalTicks) >> timer2ClockReload);
else if (((address & 0x3fe) == 0x10C) && timer3On && !(TM3CNT & 4))
value = 0xFFFF - ((timer3Ticks - cpuTotalTicks) >>
timer3ClockReload);
value = 0xFFFF - ((timer3Ticks - cpuTotalTicks) >> timer3ClockReload);
}
} else if ((address < 0x4000400) && ioReadable[address & 0x3fc]) {
value = 0;
@ -750,12 +745,10 @@ static inline void CPUWriteByte(u32 address, u8 b)
u32 lowerBits = address & 0x3fe;
if (address & 1) {
CPUUpdateRegister(lowerBits,
(READ16LE(&ioMem[lowerBits]) & 0x00FF) |
(b << 8));
(READ16LE(&ioMem[lowerBits]) & 0x00FF) | (b << 8));
} else {
CPUUpdateRegister(lowerBits,
(READ16LE(&ioMem[lowerBits]) & 0xFF00) |
b);
(READ16LE(&ioMem[lowerBits]) & 0xFF00) | b);
}
}
break;

View File

@ -1,6 +1,6 @@
#include "GBA.h"
#include "Globals.h"
#include "GBAGfx.h"
#include "Globals.h"
void mode0RenderLine()
{
@ -185,8 +185,7 @@ void mode0RenderLineNoWindow()
switch (effect) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -229,10 +228,8 @@ void mode0RenderLineNoWindow()
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -443,8 +440,7 @@ void mode0RenderLineAll()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -488,8 +484,7 @@ void mode0RenderLineAll()
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);

View File

@ -1,6 +1,6 @@
#include "GBA.h"
#include "Globals.h"
#include "GBAGfx.h"
#include "Globals.h"
void mode1RenderLine()
{
@ -124,7 +124,6 @@ void mode1RenderLineNoWindow()
gfxDrawTextScreen(BG0CNT, BG0HOFS, BG0VOFS, line0);
}
if (layerEnable & 0x0200) {
gfxDrawTextScreen(BG1CNT, BG1HOFS, BG1VOFS, line1);
}
@ -175,8 +174,7 @@ void mode1RenderLineNoWindow()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -213,8 +211,7 @@ void mode1RenderLineNoWindow()
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -414,8 +411,7 @@ void mode1RenderLineAll()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -453,8 +449,7 @@ void mode1RenderLineAll()
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);

View File

@ -1,6 +1,6 @@
#include "GBA.h"
#include "Globals.h"
#include "GBAGfx.h"
#include "Globals.h"
void mode2RenderLine()
{
@ -47,7 +47,6 @@ void mode2RenderLine()
u32 color = backdrop;
u8 top = 0x20;
if ((u8)(line2[x] >> 24) < (u8)(color >> 24)) {
color = line2[x];
top = 0x04;
@ -148,7 +147,6 @@ void mode2RenderLineNoWindow()
u32 color = backdrop;
u8 top = 0x20;
if ((u8)(line2[x] >> 24) < (u8)(color >> 24)) {
color = line2[x];
top = 0x04;
@ -168,8 +166,7 @@ void mode2RenderLineNoWindow()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -200,8 +197,7 @@ void mode2RenderLineNoWindow()
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -390,8 +386,7 @@ void mode2RenderLineAll()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -422,8 +417,7 @@ void mode2RenderLineAll()
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);

View File

@ -1,6 +1,6 @@
#include "GBA.h"
#include "Globals.h"
#include "GBAGfx.h"
#include "Globals.h"
void mode3RenderLine()
{
@ -136,8 +136,7 @@ void mode3RenderLineNoWindow()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
@ -160,10 +159,8 @@ void mode3RenderLineNoWindow()
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -328,8 +325,7 @@ void mode3RenderLineAll()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
@ -352,10 +348,8 @@ void mode3RenderLineAll()
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);

View File

@ -134,8 +134,7 @@ void mode4RenderLineNoWindow()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -158,10 +157,8 @@ void mode4RenderLineNoWindow()
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -325,8 +322,7 @@ void mode4RenderLineAll()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = backdrop;
u8 top2 = 0x20;
@ -349,10 +345,8 @@ void mode4RenderLineAll()
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);

View File

@ -1,6 +1,6 @@
#include "GBA.h"
#include "Globals.h"
#include "GBAGfx.h"
#include "Globals.h"
void mode5RenderLine()
{
@ -136,8 +136,7 @@ void mode5RenderLineNoWindow()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
@ -160,10 +159,8 @@ void mode5RenderLineNoWindow()
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);
@ -328,8 +325,7 @@ void mode5RenderLineAll()
switch ((BLDMOD >> 6) & 3) {
case 0:
break;
case 1:
{
case 1: {
if (top & BLDMOD) {
u32 back = background;
u8 top2 = 0x20;
@ -352,10 +348,8 @@ void mode5RenderLineAll()
color = gfxAlphaBlend(color, back,
coeff[COLEV & 0x1F],
coeff[(COLEV >> 8) & 0x1F]);
}
}
break;
} break;
case 2:
if (BLDMOD & top)
color = gfxIncreaseBrightness(color, coeff[COLY & 0x1F]);

View File

@ -1,16 +1,15 @@
#include "../NLS.h"
#include "../System.h"
#include "../Util.h"
#include "../common/Port.h"
#include "GBA.h"
#include "Globals.h"
#include "../common/Port.h"
#include "../Util.h"
#include "../NLS.h"
#include <time.h>
#include <memory.h>
#include <string.h>
#include <time.h>
enum RTCSTATE
{
enum RTCSTATE {
IDLE = 0,
COMMAND,
DATA,
@ -59,8 +58,7 @@ u16 rtcRead(u32 address)
{
int res = 0;
switch (address)
{
switch (address) {
case 0x80000c8:
return rtcClockData.enable;
break;
@ -70,31 +68,26 @@ u16 rtcRead(u32 address)
break;
case 0x80000c4:
if (!(rtcClockData.enable & 1))
{
if (!(rtcClockData.enable & 1)) {
return 0;
}
// Boktai Solar Sensor
if (rtcClockData.select == 0x07)
{
if (rtcClockData.reserved[11] >= systemGetSensorDarkness())
{
if (rtcClockData.select == 0x07) {
if (rtcClockData.reserved[11] >= systemGetSensorDarkness()) {
res |= 8;
}
}
// WarioWare Twisted Tilt Sensor
if (rtcClockData.select == 0x0b)
{
if (rtcClockData.select == 0x0b) {
u16 v = systemGetSensorZ();
v = 0x6C0 + v;
res |= ((v >> rtcClockData.reserved[11]) & 1) << 2;
}
// Real Time Clock
if (rtcClockEnabled && (rtcClockData.select & 0x04))
{
if (rtcClockEnabled && (rtcClockData.select & 0x04)) {
res |= rtcClockData.byte0;
}
@ -124,8 +117,7 @@ void rtcUpdateTime(int ticks)
{
countTicks += ticks;
if (countTicks > TICKS_PER_SECOND)
{
if (countTicks > TICKS_PER_SECOND) {
countTicks -= TICKS_PER_SECOND;
gba_time.tm_sec++;
mktime(&gba_time);
@ -134,43 +126,33 @@ void rtcUpdateTime(int ticks)
bool rtcWrite(u32 address, u16 value)
{
if (address == 0x80000c8)
{
if (address == 0x80000c8) {
rtcClockData.enable = (u8)value; // bit 0 = enable reading from 0x80000c4 c6 and c8
}
else if (address == 0x80000c6)
{
} else if (address == 0x80000c6) {
rtcClockData.select = (u8)value; // 0=read/1=write (for each of 4 low bits)
// rumble is off when not writing to that pin
if (rtcRumbleEnabled && !(value & 8)) systemCartridgeRumble(false);
}
else if (address == 0x80000c4) // 4 bits of I/O Port Data (upper bits not used)
if (rtcRumbleEnabled && !(value & 8))
systemCartridgeRumble(false);
} else if (address == 0x80000c4) // 4 bits of I/O Port Data (upper bits not used)
{
// WarioWare Twisted rumble
if (rtcRumbleEnabled && (rtcClockData.select & 0x08))
{
if (rtcRumbleEnabled && (rtcClockData.select & 0x08)) {
systemCartridgeRumble(value & 8);
}
// Boktai solar sensor
if (rtcClockData.select == 0x07)
{
if (value & 2)
{
if (rtcClockData.select == 0x07) {
if (value & 2) {
// reset counter to 0
rtcClockData.reserved[11] = 0;
}
if ((value & 1) && !(rtcClockData.reserved[10] & 1))
{
if ((value & 1) && !(rtcClockData.reserved[10] & 1)) {
// increase counter, ready to do another read
if (rtcClockData.reserved[11] < 255)
{
if (rtcClockData.reserved[11] < 255) {
rtcClockData.reserved[11]++;
}
else
{
} else {
rtcClockData.reserved[11] = 0;
}
}
@ -179,16 +161,13 @@ bool rtcWrite(u32 address, u16 value)
}
// WarioWare Twisted rotation sensor
if (rtcClockData.select == 0x0b)
{
if (value & 2)
{
if (rtcClockData.select == 0x0b) {
if (value & 2) {
// clock goes high in preperation for reading a bit
rtcClockData.reserved[11]--;
}
if (value & 1)
{
if (value & 1) {
// start ADC conversion
rtcClockData.reserved[11] = 15;
}
@ -197,30 +176,24 @@ bool rtcWrite(u32 address, u16 value)
}
// Real Time Clock
if (rtcClockData.select & 4)
{
if (rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5)
{
if (rtcClockData.select & 4) {
if (rtcClockData.state == IDLE && rtcClockData.byte0 == 1 && value == 5) {
rtcClockData.state = COMMAND;
rtcClockData.bits = 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;
switch (rtcClockData.state)
{
switch (rtcClockData.state) {
case COMMAND:
rtcClockData.command |= ((value & 2) >> 1) << (7 - rtcClockData.bits);
rtcClockData.bits++;
if (rtcClockData.bits == 8)
{
if (rtcClockData.bits == 8) {
rtcClockData.bits = 0;
switch (rtcClockData.command)
{
switch (rtcClockData.command) {
case 0x60:
// not sure what this command does but it doesn't take parameters
// maybe it is a reset or stop
@ -243,8 +216,7 @@ bool rtcWrite(u32 address, u16 value)
case 0x64:
break;
case 0x65:
{
case 0x65: {
if (rtcEnabled)
SetGBATime();
@ -257,11 +229,9 @@ bool rtcWrite(u32 address, u16 value)
rtcClockData.data[5] = toBCD(gba_time.tm_min);
rtcClockData.data[6] = toBCD(gba_time.tm_sec);
rtcClockData.state = DATA;
}
break;
} break;
case 0x67:
{
case 0x67: {
if (rtcEnabled)
SetGBATime();
@ -270,8 +240,7 @@ bool rtcWrite(u32 address, u16 value)
rtcClockData.data[1] = toBCD(gba_time.tm_min);
rtcClockData.data[2] = toBCD(gba_time.tm_sec);
rtcClockData.state = DATA;
}
break;
} break;
default:
log(N_("Unknown RTC command %02x"), rtcClockData.command);
@ -283,18 +252,12 @@ bool rtcWrite(u32 address, u16 value)
break;
case DATA:
if (rtcClockData.select & 2)
{
}
else if (rtcClockData.select & 4)
{
rtcClockData.byte0 = (rtcClockData.byte0 & ~2) |
((rtcClockData.data[rtcClockData.bits >> 3] >>
(rtcClockData.bits & 7)) & 1) * 2;
if (rtcClockData.select & 2) {
} else if (rtcClockData.select & 4) {
rtcClockData.byte0 = (rtcClockData.byte0 & ~2) | ((rtcClockData.data[rtcClockData.bits >> 3] >> (rtcClockData.bits & 7)) & 1) * 2;
rtcClockData.bits++;
if (rtcClockData.bits == 8 * rtcClockData.dataLen)
{
if (rtcClockData.bits == 8 * rtcClockData.dataLen) {
rtcClockData.bits = 0;
rtcClockData.state = IDLE;
}
@ -303,18 +266,12 @@ bool rtcWrite(u32 address, u16 value)
break;
case READDATA:
if (!(rtcClockData.select & 2))
{
}
else
{
rtcClockData.data[rtcClockData.bits >> 3] =
(rtcClockData.data[rtcClockData.bits >> 3] >> 1) |
((value << 6) & 128);
if (!(rtcClockData.select & 2)) {
} else {
rtcClockData.data[rtcClockData.bits >> 3] = (rtcClockData.data[rtcClockData.bits >> 3] >> 1) | ((value << 6) & 128);
rtcClockData.bits++;
if (rtcClockData.bits == 8 * rtcClockData.dataLen)
{
if (rtcClockData.bits == 8 * rtcClockData.dataLen) {
rtcClockData.bits = 0;
rtcClockData.state = IDLE;
}
@ -325,8 +282,7 @@ bool rtcWrite(u32 address, u16 value)
default:
break;
}
}
else
} else
rtcClockData.byte0 = (u8)value;
}
}

View File

@ -2,10 +2,10 @@
#include "Sound.h"
#include "GBA.h"
#include "Globals.h"
#include "../Util.h"
#include "../common/Port.h"
#include "GBA.h"
#include "Globals.h"
#include "../apu/Gb_Apu.h"
#include "../apu/Multi_Buffer.h"
@ -84,8 +84,8 @@ public:
int writeIndex;
u8 fifo[32];
int dac;
private:
private:
int timer;
bool enabled;
};
@ -118,17 +118,20 @@ void Gba_Pcm::apply_control( int idx )
ch = ioMem[SGCNT0_H + 1] >> (idx * 4) & 3;
Blip_Buffer* out = 0;
switch ( ch )
{
case 1: out = stereo_buffer->right(); break;
case 2: out = stereo_buffer->left(); break;
case 3: out = stereo_buffer->center(); break;
switch (ch) {
case 1:
out = stereo_buffer->right();
break;
case 2:
out = stereo_buffer->left();
break;
case 3:
out = stereo_buffer->center();
break;
}
if ( output != out )
{
if ( output )
{
if (output != out) {
if (output) {
output->set_modified();
pcm_synth[0].offset(blip_time(), -last_amp, output);
}
@ -149,19 +152,16 @@ void Gba_Pcm::end_frame( blip_time_t time )
void Gba_Pcm::update(int dac)
{
if ( output )
{
if (output) {
blip_time_t time = blip_time();
dac = (s8)dac >> shift;
int delta = dac - last_amp;
if ( delta )
{
if (delta) {
last_amp = dac;
int filter = 0;
if ( soundInterpolation )
{
if (soundInterpolation) {
// base filtering on how long since last sample was output
int period = time - last_time;
@ -181,22 +181,18 @@ void Gba_Pcm::update( int dac )
void Gba_Pcm_Fifo::timer_overflowed(int which_timer)
{
if ( which_timer == timer && enabled )
{
if (which_timer == timer && enabled) {
/* Mother 3 fix, refined to not break Metroid Fusion */
if ( count == 16 || count == 0 )
{
if (count == 16 || count == 0) {
// Need to fill FIFO
int saved_count = count;
CPUCheckDMA(3, which ? 4 : 2);
if (saved_count == 0 && count == 16)
CPUCheckDMA(3, which ? 4 : 2);
if ( count == 0 )
{
if (count == 0) {
// Not filled by DMA, so fill with 16 bytes of silence
int reg = which ? FIFOB_L : FIFOA_L;
for ( int n = 8; n--; )
{
for (int n = 8; n--;) {
soundEvent(reg, (u16)0);
soundEvent(reg + 2, (u16)0);
}
@ -216,8 +212,7 @@ void Gba_Pcm_Fifo::write_control( int data )
enabled = (data & 0x0300) ? true : false;
timer = (data & 0x0400) ? 1 : 0;
if ( data & 0x0800 )
{
if (data & 0x0800) {
// Reset
writeIndex = 0;
readIndex = 0;
@ -246,8 +241,7 @@ static void apply_control()
static int gba_to_gb_sound(int addr)
{
static const int table [0x40] =
{
static const int table[0x40] = {
0xFF10, 0, 0xFF11, 0xFF12, 0xFF13, 0xFF14, 0, 0,
0xFF16, 0xFF17, 0, 0, 0xFF18, 0xFF19, 0, 0,
0xFF1A, 0, 0xFF1B, 0xFF1C, 0xFF1D, 0xFF1E, 0, 0,
@ -265,8 +259,7 @@ static int gba_to_gb_sound( int addr )
void soundEvent(u32 address, u8 data)
{
int gb_addr = gba_to_gb_sound(address);
if ( gb_addr )
{
if (gb_addr) {
ioMem[address] = data;
gb_apu->write_register(blip_time(), gb_addr, data);
@ -282,14 +275,12 @@ static void apply_volume( bool apu_only = false )
if (!apu_only)
soundVolume_ = soundVolume;
if ( gb_apu )
{
if (gb_apu) {
static float const apu_vols[4] = { 0.25, 0.5, 1, 0.25 };
gb_apu->volume(soundVolume_ * apu_vols[ioMem[SGCNT0_H] & 3]);
}
if ( !apu_only )
{
if (!apu_only) {
for (int i = 0; i < 3; i++)
pcm_synth[i].volume(0.66 / 256 * soundVolume_);
}
@ -305,8 +296,7 @@ static void write_SGCNT0_H( int data )
void soundEvent(u32 address, u16 data)
{
switch ( address )
{
switch (address) {
case SGCNT0_H:
write_SGCNT0_H(data);
break;
@ -370,8 +360,7 @@ void flush_samples(Multi_Buffer * buffer)
int const out_buf_size = soundBufferLen / sizeof *soundFinalWave;
// Keep filling and writing soundFinalWave until it can't be fully filled
while ( buffer->samples_avail() >= out_buf_size )
{
while (buffer->samples_avail() >= out_buf_size) {
buffer->read_samples((blip_sample_t*)soundFinalWave, out_buf_size);
if (soundPaused)
soundResume();
@ -389,8 +378,7 @@ static void apply_filtering()
int const base_freq = (int)(32768 - soundFiltering_ * 16384);
int const nyquist = stereo_buffer->sample_rate() / 2;
for ( int i = 0; i < 3; i++ )
{
for (int i = 0; i < 3; i++) {
int cutoff = base_freq >> i;
if (cutoff > nyquist)
cutoff = nyquist;
@ -400,8 +388,7 @@ static void apply_filtering()
void psoundTickfn()
{
if ( gb_apu && stereo_buffer )
{
if (gb_apu && stereo_buffer) {
// Run sound hardware to present
end_frame(SOUND_CLOCK_TICKS);
@ -423,11 +410,9 @@ static void apply_muting()
// PCM
apply_control();
if ( gb_apu )
{
if (gb_apu) {
// APU
for ( int i = 0; i < 4; i++ )
{
for (int i = 0; i < 4; i++) {
if (soundEnableFlag >> i & 1)
gb_apu->set_output(stereo_buffer->center(),
stereo_buffer->left(), stereo_buffer->right(), i);
@ -457,8 +442,7 @@ static void remake_stereo_buffer()
pcm[1].pcm.init();
// APU
if ( !gb_apu )
{
if (!gb_apu) {
gb_apu = new Gb_Apu; // TODO: handle out of memory
reset_apu();
}
@ -483,8 +467,7 @@ static void remake_stereo_buffer()
void soundShutdown()
{
if (soundDriver)
{
if (soundDriver) {
delete soundDriver;
soundDriver = 0;
}
@ -574,16 +557,12 @@ long soundGetSampleRate()
void soundSetSampleRate(long sampleRate)
{
if ( soundSampleRate != sampleRate )
{
if ( systemCanChangeSoundQuality() )
{
if (soundSampleRate != sampleRate) {
if (systemCanChangeSoundQuality()) {
soundShutdown();
soundSampleRate = sampleRate;
soundInit();
}
else
{
} else {
soundSampleRate = sampleRate;
}
@ -593,9 +572,15 @@ void soundSetSampleRate(long sampleRate)
static int dummy_state[16];
#define SKIP( type, name ) { dummy_state, sizeof (type) }
#define SKIP(type, name) \
{ \
dummy_state, sizeof(type) \
}
#define LOAD( type, name ) { &name, sizeof (type) }
#define LOAD(type, name) \
{ \
&name, sizeof(type) \
}
static struct {
gb_apu_state_t apu;
@ -606,8 +591,7 @@ static struct {
} state;
// Old GBA sound state format
static variable_desc old_gba_state [] =
{
static variable_desc old_gba_state[] = {
SKIP(int, soundPaused),
SKIP(int, soundPlay),
SKIP(int, soundTicks),
@ -684,8 +668,7 @@ static variable_desc old_gba_state [] =
{ NULL, 0 }
};
variable_desc old_gba_state2 [] =
{
variable_desc old_gba_state2[] = {
LOAD(u8[0x20], state.apu.regs[0x20]),
SKIP(int, sound3Bank),
SKIP(int, sound3DataSize),
@ -694,8 +677,7 @@ variable_desc old_gba_state2 [] =
};
// New state format
static variable_desc gba_state [] =
{
static variable_desc gba_state[] = {
// PCM
LOAD(int, pcm[0].readIndex),
LOAD(int, pcm[0].count),
@ -744,7 +726,6 @@ static variable_desc gba_state [] =
{ NULL, 0 }
};
#ifdef __LIBRETRO__
void soundSaveGame(u8*& out)
#else
@ -769,8 +750,7 @@ static void skip_read( gzFile in, int count )
{
char buf[512];
while ( count )
{
while (count) {
int n = sizeof buf;
if (n > count)
n = count;

View File

@ -1,7 +1,7 @@
#include "Sram.h"
#include "Flash.h"
#include "GBA.h"
#include "Globals.h"
#include "Flash.h"
#include "Sram.h"
u8 sramRead(u32 address)
{

View File

@ -1,10 +1,10 @@
#include <stdio.h>
#include <string.h>
#include "../System.h"
#include "../common/Port.h"
#include "GBA.h"
#include "Globals.h"
#include "../common/Port.h"
#include "../System.h"
#define debuggerWriteHalfWord(addr, value) \
WRITE16LE((u16*)&map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask], (value))
@ -23,8 +23,7 @@ bool agbPrintWrite(u32 address, u16 value)
debuggerWriteHalfWord(address, value);
return true;
} else {
if(agbPrintProtect &&
((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
if (agbPrintProtect && ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
|| (address >= 0x8fd0000 && address <= 0x8fdffff)
|| (address >= 0x9fd0000 && address <= 0x9fdffff))) {
debuggerWriteHalfWord(address, value);

View File

@ -191,14 +191,16 @@ const Opcodes armOpcodes[] = {
{ 0x00000000, 0x00000000, "[ ??? ]" }
};
char* addStr(char *dest, const char *src){
char* addStr(char* dest, const char* src)
{
while (*src) {
*dest++ = *src++;
}
return dest;
}
char* addHex(char *dest, int siz, u32 val){
char* addHex(char* dest, int siz, u32 val)
{
if (siz == 0) {
siz = 28;
while ((((val >> siz) & 15) == 0) && (siz >= 4))
@ -212,7 +214,8 @@ char* addHex(char *dest, int siz, u32 val){
return dest;
}
int disArm(u32 offset, char *dest, int flags){
int disArm(u32 offset, char* dest, int flags)
{
u32 opcode = debuggerReadMemory(offset);
const Opcodes* sp = armOpcodes;
@ -241,16 +244,14 @@ int disArm(u32 offset, char *dest, int flags){
case 'r':
dest = addStr(dest, regs[(opcode >> ((*(++src) - '0') * 4)) & 15]);
break;
case 'o':
{
case 'o': {
*dest++ = '$';
int off = opcode & 0xffffff;
if (off & 0x800000)
off |= 0xff000000;
off <<= 2;
dest = addHex(dest, 32, offset + 8 + off);
}
break;
} break;
case 'i':
if (opcode & (1 << 25)) {
dest = addStr(dest, "#0x");
@ -466,23 +467,19 @@ int disArm(u32 offset, char *dest, int flags){
else
dest = addStr(dest, decVals[(opcode >> 20) & 15]);
break;
case 'R':
{
case 'R': {
src++;
int reg = 4 * (*src - '0');
*dest++ = 'c';
dest = addStr(dest, decVals[(opcode >> reg) & 15]);
}
break;
case 'V':
{
} break;
case 'V': {
int val = (opcode >> 5) & 7;
if (val) {
dest = addStr(dest, ", ");
dest = addStr(dest, decVals[val]);
}
}
break;
} break;
case 'L':
if (opcode & (1 << 22))
*dest++ = 'l';
@ -526,7 +523,8 @@ int disArm(u32 offset, char *dest, int flags){
return 4;
}
int disThumb(u32 offset, char *dest, int flags){
int disThumb(u32 offset, char* dest, int flags)
{
u32 opcode = debuggerReadHalfWord(offset);
const Opcodes* sp = thumbOpcodes;
@ -578,16 +576,14 @@ int disThumb(u32 offset, char *dest, int flags){
dest = addStr(dest, "#0x");
dest = addHex(dest, 0, (opcode >> 6) & 7);
break;
case 'h':
{
case 'h': {
src++;
int reg = (opcode >> (*src - '0')) & 7;
src++;
if (opcode & (1 << (*src - '0')))
reg += 8;
dest = addStr(dest, regs[reg]);
}
break;
} break;
case 'O':
dest = addStr(dest, "#0x");
dest = addHex(dest, 0, (opcode & 0xff));
@ -596,10 +592,8 @@ int disThumb(u32 offset, char *dest, int flags){
*dest++ = '$';
dest = addHex(dest, 32, (offset & 0xfffffffc) + 4 + ((opcode & 0xff) << 2));
break;
case 'J':
{
u32 value = debuggerReadMemory((offset&0xfffffffc)+4+
((opcode & 0xff)<<2));
case 'J': {
u32 value = debuggerReadMemory((offset & 0xfffffffc) + 4 + ((opcode & 0xff) << 2));
*dest++ = '$';
dest = addHex(dest, 32, value);
const char* s = elfGetAddressSymbol(value);
@ -607,10 +601,8 @@ int disThumb(u32 offset, char *dest, int flags){
*dest++ = ' ';
dest = addStr(dest, s);
}
}
break;
case 'K':
{
} break;
case 'K': {
u32 value = (offset & 0xfffffffc) + 4 + ((opcode & 0xff) << 2);
*dest++ = '$';
dest = addHex(dest, 32, value);
@ -619,8 +611,7 @@ int disThumb(u32 offset, char *dest, int flags){
*dest++ = ' ';
dest = addStr(dest, s);
}
}
break;
} break;
case 'b':
if (opcode & (1 << 10))
*dest++ = 'b';
@ -651,8 +642,7 @@ int disThumb(u32 offset, char *dest, int flags){
dest = addStr(dest, "#0x");
dest = addHex(dest, 0, (opcode & 0x7f) << 2);
break;
case 'l':
{
case 'l': {
int rlst = opcode & 0xff;
int msk = 0;
int not_first = 0;
@ -676,8 +666,7 @@ int disThumb(u32 offset, char *dest, int flags){
} else
msk++;
}
}
break;
} break;
case 'm':
*dest++ = '$';
dest = addHex(dest, 8, opcode & 0xff);
@ -696,8 +685,7 @@ int disThumb(u32 offset, char *dest, int flags){
dest = addHex(dest, 32, offset + 4 + add);
}
break;
case 'A':
{
case 'A': {
int nopcode = debuggerReadHalfWord(offset + 2);
int add = opcode & 0x7ff;
if (add & 0x400)
@ -713,8 +701,7 @@ int disThumb(u32 offset, char *dest, int flags){
*dest++ = ')';
}
ret = 4;
}
break;
} break;
}
src++;
}

View File

@ -3,9 +3,9 @@
#include <stdlib.h>
#include "GBA.h"
#include "bios.h"
#include "GBAinline.h"
#include "Globals.h"
#include "bios.h"
s16 sineTable[256] = {
(s16)0x0000, (s16)0x0192, (s16)0x0323, (s16)0x04B5, (s16)0x0645, (s16)0x07D5, (s16)0x0964, (s16)0x0AF1,
@ -136,8 +136,7 @@ void BIOS_BitUnPack()
int len = CPUReadHalfWord(header);
// check address
if(((source & 0xe000000) == 0) ||
((source + len) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + len) & 0xe000000) == 0)
return;
int bits = CPUReadByte(header + 2);
@ -256,8 +255,7 @@ void BIOS_CpuSet()
u32 dest = reg[1].I;
u32 cnt = reg[2].I;
if(((source & 0xe000000) == 0) ||
((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + (((cnt << 11) >> 9) & 0x1fffff)) & 0xe000000) == 0)
return;
int count = cnt & 0x1FFFFF;
@ -318,8 +316,7 @@ void BIOS_CpuFastSet()
u32 dest = reg[1].I;
u32 cnt = reg[2].I;
if(((source & 0xe000000) == 0) ||
((source + (((cnt << 11)>>9) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + (((cnt << 11) >> 9) & 0x1fffff)) & 0xe000000) == 0)
return;
// needed for 32-bit mode!
@ -368,8 +365,7 @@ void BIOS_Diff8bitUnFilterWram()
u32 header = CPUReadMemory(source);
source += 4;
if(((source & 0xe000000) == 0) ||
(((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0))
if (((source & 0xe000000) == 0) || (((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0))
return;
int len = header >> 8;
@ -401,8 +397,7 @@ void BIOS_Diff8bitUnFilterVram()
u32 header = CPUReadMemory(source);
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return;
int len = header >> 8;
@ -444,8 +439,7 @@ void BIOS_Diff16bitUnFilter()
u32 header = CPUReadMemory(source);
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return;
int len = header >> 8;
@ -529,8 +523,7 @@ void BIOS_HuffUnComp()
u32 header = CPUReadMemory(source);
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return;
u8 treeSize = CPUReadByte(source++);
@ -675,8 +668,7 @@ void BIOS_LZ77UnCompVram()
u32 header = CPUReadMemory(source);
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return;
int byteCount = 0;
@ -764,8 +756,7 @@ void BIOS_LZ77UnCompWram()
u32 header = CPUReadMemory(source);
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return;
int len = header >> 8;
@ -957,8 +948,7 @@ void BIOS_RLUnCompVram()
u32 header = CPUReadMemory(source & 0xFFFFFFFC);
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return;
int len = header >> 8;
@ -1026,8 +1016,7 @@ void BIOS_RLUnCompWram()
u32 header = CPUReadMemory(source & 0xFFFFFFFC);
source += 4;
if(((source & 0xe000000) == 0) ||
((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
if (((source & 0xe000000) == 0) || ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0)
return;
int len = header >> 8;
@ -1114,8 +1103,7 @@ u32 const base2 = 0x04000080;
static bool BIOS_SndDriver_ba4(u32 r0, u32 r4r12) // 0xba4
{
if (r4r12)
{
if (r4r12) {
r4r12 = r4r12 & ~0xFE000000;
r4r12 += r0;
if (!((r0 & 0x0E000000) && (r4r12 & 0x0E000000)))
@ -1146,22 +1134,18 @@ static void BIOS_SndDriver_b4c(u32 r0, u32 r1, u32 r2) // 0xb4c
#endif
// 0b56
if ( !ok )
{
if (!ok) {
u32 r5 = 0; //v8
if (r2 >= (1 << (27 - 1))) //v6
{
r5 = r1 + r4;
if ( r2 >= (1<<(25-1)) )
{
if (r2 >= (1 << (25 - 1))) {
u32 r3 = CPUReadMemory(r0);
while ( r1 < r5 )
{
while (r1 < r5) {
CPUWriteMemory(r1, r3);
r1 += 4;
}
}
else // @todo 0b6e
} else // @todo 0b6e
{
#if 0
while ( v5 < v9 )
@ -1173,8 +1157,7 @@ static void BIOS_SndDriver_b4c(u32 r0, u32 r1, u32 r2) // 0xb4c
}
#endif
}
}
else // @todo 0b78
} else // @todo 0b78
{
#if 0
v12 = (unsigned int)v3 >> 1;
@ -1217,15 +1200,13 @@ static s32 BIOS_SndDriver_3e4(u32 const r0a, u32 const r1a) // 0x3e4
r0 = -r0;
r2 = r1;
do
{
do {
gtr = (r2 >= r0 >> 1);
if (r2 <= r0 >> 1)
r2 *= 2;
} while (!gtr);
while ( 1 )
{
while (1) {
v5 += (r0 >= (u32)r2) + v5;
if (r0 >= (u32)r2)
r0 -= r2;
@ -1251,15 +1232,12 @@ static void BIOS_SndDriverSub1(u32 p1) // 0x170a
u32 r0 = (0x31e8 + (local1 << 1)) - 0x20;
// @todo read from bios region
if (r0 == 0x31D0)
{
if (r0 == 0x31D0) {
r0 = 0xE0;
}
else if (r0 == 0x31E0)
{
} else if (r0 == 0x31E0) {
r0 = 0x2C0;
}
else r0 = CPUReadHalfWord(r0+0x1E);
} else
r0 = CPUReadHalfWord(r0 + 0x1E);
CPUWriteMemory(puser1 + 0x10, r0);
u32 r1 = 0x630;
@ -1363,40 +1341,34 @@ void BIOS_SndDriverMode() //0x179c
u32 const puser1 = CPUReadMemory(0x3007FF0); // 7FC0 + 0x30
u32 user1 = CPUReadMemory(puser1);
if ( user1 == 0x68736D53 )
{
if (user1 == 0x68736D53) {
CPUWriteMemory(puser1, (++user1)); // this guard is common for funcs, unify
// reverb values at bits 0...7
u8 revb = (input & 0xFF);
if ( revb )
{
if (revb) {
revb >>= 1; // shift out the 7th enable bit
CPUWriteByte(puser1 + 5, revb);
}
// direct sound multi channels at bits 8...11
u8 chc = (input & 0xF00) >> 8;
if ( chc > 0 )
{
if (chc > 0) {
CPUWriteByte(puser1 + 6, chc);
u32 puser2 = puser1 + 7 + 0x49;
int count = 12;
while (count--)
{
while (count--) {
CPUWriteByte(puser2, 0);
puser2 += 0x40;
}
}
// direct sound master volume at bits 12...15
u8 chv = (input & 0xF000) >> 12;
if ( chv > 0 )
{
if (chv > 0) {
CPUWriteByte(puser1 + 7, chv);
}
// DA converter bits at bits 20...23
u32 dab = (input & 0x00B00000);
if ( dab )
{
if (dab) {
dab &= 0x00300000;
dab >>= 0xE;
u8 adv = CPUReadByte(puser1 + 9) & ADBITS_MASK; // @todo verify offset
@ -1405,8 +1377,7 @@ void BIOS_SndDriverMode() //0x179c
}
// Playback frequency at bits 16...19
u32 pbf = (input & 0x000F0000);
if ( pbf )
{
if (pbf) {
// Modifies puser1/user1
BIOS_SndDriverVSyncOff();
@ -1430,15 +1401,13 @@ void BIOS_SndDriverMain() // 0x1dc4 -> 0x08004024 phantasy star
CPUWriteMemory(puser1, (++user1)); // this guard is common for funcs, unify
int const user2 = CPUReadMemory(puser1 + 0x20);
if ( user2 )
{
if (user2) {
int const par1 = CPUReadMemory(puser1 + 0x24);
// Call 0x2102 sub_16A8 - -> param r1
}
int const userfunc = CPUReadMemory(puser1 + 0x28);
switch (userfunc)
{
switch (userfunc) {
case 0x1709: //phantasy star
default:
break;
@ -1448,8 +1417,7 @@ void BIOS_SndDriverMain() // 0x1dc4 -> 0x08004024 phantasy star
u8 const user4 = CPUReadByte(puser1 + 4) - 1;
u32 user41 = 0;
if ( user4 > 0 )
{
if (user4 > 0) {
user41 = CPUReadByte(puser1 + 0x0B);
user41 -= user4;
user41 *= v2;
@ -1460,48 +1428,52 @@ void BIOS_SndDriverMain() // 0x1dc4 -> 0x08004024 phantasy star
int user6 = r5c + 0x630; //r6
int user5 = CPUReadByte(puser1 + 0x5); //r3
if ( user5 )
{
if (user5) {
// @todo 0x1e1a
}
else // 0x1e74
} else // 0x1e74
{
r5 = r5c;
int count = v2 >> 4; //r1...v13
if ( !(v2 >> 3) )
{
if (!(v2 >> 3)) {
CPUWriteMemory(r5, 0);
CPUWriteMemory(user6, 0);
r5+=4; user6+=4;
r5 += 4;
user6 += 4;
}
if (!(v2 >> 1)) //0x1e7c
{
CPUWriteMemory(r5, 0);
CPUWriteMemory(user6, 0);
r5+=4; user6+=4;
r5 += 4;
user6 += 4;
CPUWriteMemory(r5, 0);
CPUWriteMemory(user6, 0);
r5+=4; user6+=4;
r5 += 4;
user6 += 4;
}
do // 0x1e8e
{
// @todo optimize this memset
CPUWriteMemory(r5, 0);
CPUWriteMemory(user6, 0);
r5+=4; user6+=4;
r5 += 4;
user6 += 4;
CPUWriteMemory(r5, 0);
CPUWriteMemory(user6, 0);
r5+=4; user6+=4;
r5 += 4;
user6 += 4;
CPUWriteMemory(r5, 0);
CPUWriteMemory(user6, 0);
r5+=4; user6+=4;
r5 += 4;
user6 += 4;
CPUWriteMemory(r5, 0);
CPUWriteMemory(user6, 0);
r5+=4; user6+=4;
r5 += 4;
user6 += 4;
count -= 1;
} while (count > 0);
@ -1513,8 +1485,7 @@ void BIOS_SndDriverMain() // 0x1dc4 -> 0x08004024 phantasy star
int r12 = CPUReadMemory(r4 + 0x18);
u32 i = CPUReadByte(r4 + 0x6);
for (r4+=0x10; i > 0; i-- )
{
for (r4 += 0x10; i > 0; i--) {
r4 += 0x40;
/*lbl_0x1eb0:*/
u32 r3 = CPUReadMemory(r4 + 0x24);
@ -1538,22 +1509,17 @@ void BIOS_SndDriverMain() // 0x1dc4 -> 0x08004024 phantasy star
u8 r2a = CPUReadByte(r3 + 0x3); // seems to be LABEL_20e4
if ((r2a & 0xC0)) // 1ee4
{
}
goto lbl_0x1f46;
}
else
{
} else {
//lbl_0x1eee:
r5 = CPUReadByte(r4 + 0x9); //
if ((r6 & 0x4) != 0) // @todo 0x1ef4
{
}
if ((r6 & 0x40) != 0) // @todo 0x1f08
{
}
if ((r6 & 0x03) == 2) // 0x1f2a
@ -1563,22 +1529,19 @@ void BIOS_SndDriverMain() // 0x1dc4 -> 0x08004024 phantasy star
r5 >>= 8;
u8 cmp1 = CPUReadByte(r4 + 0x6);
if (r5 <= cmp1)
{
if (r5 <= cmp1) {
r5 = cmp1;
// @todo beq @ 0x1f3a -> ??
r6--;
CPUWriteByte(r4, r6);
}
}
else if ( (r6 & 0x03) == 3) // 0x1f44
} else if ((r6 & 0x03) == 3) // 0x1f44
{
lbl_0x1f46: //@todo check if there is really another path to here
u8 add1 = CPUReadByte(r4 + 0x4);
r5 += add1;
if (r5>=0xff)
{
if (r5 >= 0xff) {
r6--;
r5 = 0xff;
CPUWriteByte(r4, r6);
@ -1607,7 +1570,6 @@ lbl_0x1f46: //@todo check if there is really another path to here
user0 = r6 & 0x10;
if (user0 != 0) // @todo 0x1f76
{
}
r5 = r5c; // @todo below r5 is used and updated
@ -1621,23 +1583,20 @@ lbl_0x1f46: //@todo check if there is really another path to here
u8 r0a = CPUReadByte(r4 + 0x1);
if ((r0a & 8)) //@todo 0x1fa8
{
}
u32 r7 = CPUReadMemory(r4 + 0x1c);
u32 r14 = CPUReadMemory(r4 + 0x20);
lbl_0x2004: // LABEL_52:
while ( r7 >= 4 * r9 )
{
while (r7 >= 4 * r9) {
if (r2 <= 4) // @todo 0x2008, no phant
goto lbl_204c;
r2 -= 4;
r3 += 4;
r7 -= 4 * r9;
}
if ( r7 >= 2 * r9 )
{
if (r7 >= 2 * r9) {
if (r2 <= 2) // @todo 0x2008, no phant
goto lbl_204c;
r2 -= 2;
@ -1646,23 +1605,16 @@ lbl_0x2004:// LABEL_52:
}
if (r7 < r9)
goto lbl_207c;
do
{
do {
lbl_204c: // LABEL_59:
--r2;
if ( r2 )
{
if (r2) {
++r3;
}
else
{
} else {
r2 = user0; //0x2054
if ( r2 )
{
if (r2) {
r3 = CPUReadMemory(reg[13].I + 0xC); // @todo stack pull 0x205c
}
else
{
} else {
CPUWriteByte(r4, r2);
goto lbl_20e4;
}
@ -1670,8 +1622,7 @@ lbl_204c: // LABEL_59:
r7 -= r9;
} while (r7 >= r9);
lbl_207c:
while ( 1 )
{
while (1) {
s32 r0a = CPUReadByte(r3);
s32 r1a = CPUReadByte(r3 + 0x1);
@ -1717,13 +1668,11 @@ void BIOS_SndDriverVSync()
u32 const puser1 = CPUReadMemory(0x3007FF0); // @todo some sound area, make it common.
u32 const user1 = CPUReadMemory(puser1);
if ( user1 == 0x68736D53 )
{
if (user1 == 0x68736D53) {
u8 v1 = CPUReadByte(puser1 + 4);
s8 v1i = v1 - 1;
CPUWriteByte(puser1 + 4, v1i);
if ( v1 <= 1 )
{
if (v1 <= 1) {
u8 v2 = CPUReadByte(puser1 + 0xB); //11
u32 base2 = 0x040000D2;
CPUWriteByte(puser1 + 4, v2);
@ -1741,8 +1690,7 @@ void BIOS_SndDriverVSyncOff() // 0x1878
u32 const puser1 = CPUReadMemory(0x3007FF0); // 7FC0 + 0x30
u32 user1 = CPUReadMemory(puser1);
if ( user1 == 0x68736D53 || user1 == 0x68736D54 )
{
if (user1 == 0x68736D53 || user1 == 0x68736D54) {
CPUWriteMemory(puser1, (++user1)); // this guard is common for funcs, unify
CPUWriteHalfWord(base1 + 0x6, 0);
@ -1770,27 +1718,23 @@ void BIOS_SndChannelClear() //0x1824
u32 const puser1 = CPUReadMemory(0x3007FF0); // 7FC0 + 0x30
u32 user1 = CPUReadMemory(puser1);
if ( user1 == 0x68736D53 )
{
if (user1 == 0x68736D53) {
CPUWriteMemory(puser1, (++user1));
u32 puser2 = puser1 + 0x7 + 0x49;
int count = 12;
while (count--)
{
while (count--) {
CPUWriteByte(puser2, 0);
puser2 += 0x40;
}
reg[4].I = CPUReadMemory(puser1 + 0x1c); //r5 -> some user thing
if ( reg[4].I != 0 )
{
if (reg[4].I != 0) {
reg[3].I = 1; // r4 -> channel counter?
int puser4 = puser1 + 0x2c;
//reg[0].I = reg[3].I = 1; // r0 & r4 => 1
while (reg[3].I <= 4)
{
while (reg[3].I <= 4) {
// @todo does user func modify these?
reg[0].I = reg[3].I << 24;
reg[0].I >>= 24;

View File

@ -36,10 +36,10 @@
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if (defined __WIN32__ || defined _WIN32)
#define fileno _fileno
@ -197,17 +197,14 @@ extern FILE *dexp_in, *dexp_out;
/* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \
do \
{ \
do { \
/* Undo effects of setting up dexp_text. */ \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg); \
*yy_cp = (yy_hold_char); \
YY_RESTORE_YY_MORE_OFFSET \
(yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
YY_RESTORE_YY_MORE_OFFSET(yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
YY_DO_BEFORE_ACTION; /* set up dexp_text again */ \
} \
while ( 0 )
} while (0)
#define unput(c) yyunput(c, (yytext_ptr))
@ -218,8 +215,7 @@ typedef size_t yy_size_t;
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
{
struct yy_buffer_state {
FILE* yy_input_file;
char* yy_ch_buf; /* input buffer */
@ -277,7 +273,6 @@ struct yy_buffer_state
* just pointing dexp_in at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
};
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
@ -344,8 +339,7 @@ void dexp_free (void * );
{ \
if (!YY_CURRENT_BUFFER) { \
dexp_ensure_buffer_stack(); \
YY_CURRENT_BUFFER_LVALUE = \
dexp__create_buffer(dexp_in,YY_BUF_SIZE ); \
YY_CURRENT_BUFFER_LVALUE = dexp__create_buffer(dexp_in, YY_BUF_SIZE); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
}
@ -354,8 +348,7 @@ void dexp_free (void * );
{ \
if (!YY_CURRENT_BUFFER) { \
dexp_ensure_buffer_stack(); \
YY_CURRENT_BUFFER_LVALUE = \
dexp__create_buffer(dexp_in,YY_BUF_SIZE ); \
YY_CURRENT_BUFFER_LVALUE = dexp__create_buffer(dexp_in, YY_BUF_SIZE); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
}
@ -399,22 +392,18 @@ static void yy_fatal_error (yyconst char msg[] );
#define YY_END_OF_BUFFER 31
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
{
struct yy_trans_info {
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[51] =
{ 0,
static yyconst flex_int16_t yy_accept[51] = { 0,
0, 0, 31, 28, 30, 27, 25, 28, 23, 20,
21, 17, 14, 15, 16, 11, 10, 28, 28, 28,
28, 28, 28, 28, 28, 28, 9, 8, 24, 28,
22, 26, 13, 11, 0, 10, 18, 19, 29, 5,
6, 3, 4, 2, 7, 1, 1, 1, 12, 0
} ;
6, 3, 4, 2, 7, 1, 1, 1, 12, 0 };
static yyconst flex_int32_t yy_ec[256] =
{ 0,
static yyconst flex_int32_t yy_ec[256] = { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -442,39 +431,31 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1
} ;
1, 1, 1, 1, 1 };
static yyconst flex_int32_t yy_meta[36] =
{ 0,
static yyconst flex_int32_t yy_meta[36] = { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 2, 2, 1, 1, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 1,
1, 1, 3, 1, 1
} ;
1, 1, 3, 1, 1 };
static yyconst flex_int16_t yy_base[55] =
{ 0,
static yyconst flex_int16_t yy_base[55] = { 0,
0, 0, 71, 72, 72, 72, 72, 0, 72, 72,
72, 72, 72, 72, 72, 41, 23, 52, 50, 0,
37, 36, 14, 44, 39, 33, 72, 72, 72, 28,
72, 72, 0, 33, 0, 35, 72, 72, 0, 72,
72, 0, 0, 0, 72, 32, 39, 0, 0, 72,
55, 54, 57, 52
} ;
55, 54, 57, 52 };
static yyconst flex_int16_t yy_def[55] =
{ 0,
static yyconst flex_int16_t yy_def[55] = { 0,
50, 1, 50, 50, 50, 50, 50, 51, 50, 50,
50, 50, 50, 50, 50, 52, 50, 50, 50, 53,
53, 53, 53, 53, 53, 53, 50, 50, 50, 53,
50, 50, 51, 52, 54, 50, 50, 50, 53, 50,
50, 53, 53, 53, 50, 30, 30, 53, 54, 0,
50, 50, 50, 50
} ;
50, 50, 50, 50 };
static yyconst flex_int16_t yy_nxt[108] =
{ 0,
static yyconst flex_int16_t yy_nxt[108] = { 0,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 17, 17, 18, 19, 20, 21,
20, 20, 22, 23, 24, 20, 25, 26, 20, 27,
@ -486,11 +467,9 @@ static yyconst flex_int16_t yy_nxt[108] =
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50
} ;
50, 50, 50, 50, 50, 50, 50 };
static yyconst flex_int16_t yy_chk[108] =
{ 0,
static yyconst flex_int16_t yy_chk[108] = { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -502,8 +481,7 @@ static yyconst flex_int16_t yy_chk[108] =
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 50, 50,
50, 50, 50, 50, 50, 50, 50
} ;
50, 50, 50, 50, 50, 50, 50 };
static yy_state_type yy_last_accepting_state;
static char* yy_last_accepting_cpos;
@ -521,9 +499,9 @@ int dexp__flex_debug = 0;
char* dexp_text;
#line 1 "debugger-expr.l"
#line 2 "debugger-expr.l"
#include "debugger-expr-yacc.hpp"
#include <stdio.h>
#include <string.h>
#include "debugger-expr-yacc.hpp"
#ifdef _MSC_VER
#define YY_NO_UNISTD_H
@ -637,7 +615,11 @@ static int input (void );
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
#define ECHO do { if (fwrite( dexp_text, dexp_leng, 1, dexp_out )) {} } while (0)
#define ECHO \
do { \
if (fwrite(dexp_text, dexp_leng, 1, dexp_out)) { \
} \
} while (0)
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@ -645,34 +627,27 @@ static int input (void );
*/
#ifndef YY_INPUT
#define YY_INPUT(buf, result, max_size) \
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
if (YY_CURRENT_BUFFER_LVALUE->yy_is_interactive) { \
int c = '*'; \
size_t n; \
for ( n = 0; n < max_size && \
(c = getc( dexp_in )) != EOF && c != '\n'; ++n ) \
for (n = 0; n < max_size && (c = getc(dexp_in)) != EOF && c != '\n'; ++n) \
buf[n] = (char)c; \
if (c == '\n') \
buf[n++] = (char)c; \
if (c == EOF && ferror(dexp_in)) \
YY_FATAL_ERROR("input in flex scanner failed"); \
result = n; \
} \
else \
{ \
} else { \
errno = 0; \
while ( (result = fread(buf, 1, max_size, dexp_in))==0 && ferror(dexp_in)) \
{ \
if( errno != EINTR) \
{ \
while ((result = fread(buf, 1, max_size, dexp_in)) == 0 && ferror(dexp_in)) { \
if (errno != EINTR) { \
YY_FATAL_ERROR("input in flex scanner failed"); \
break; \
} \
errno = 0; \
clearerr(dexp_in); \
} \
}\
\
}
#endif
@ -734,8 +709,7 @@ YY_DECL
#line 732 "debugger-expr-lex.cpp"
if ( !(yy_init) )
{
if (!(yy_init)) {
(yy_init) = 1;
#ifdef YY_USER_INIT
@ -753,8 +727,7 @@ YY_DECL
if (!YY_CURRENT_BUFFER) {
dexp_ensure_buffer_stack();
YY_CURRENT_BUFFER_LVALUE =
dexp__create_buffer(dexp_in,YY_BUF_SIZE );
YY_CURRENT_BUFFER_LVALUE = dexp__create_buffer(dexp_in, YY_BUF_SIZE);
}
dexp__load_buffer_state();
@ -774,29 +747,24 @@ YY_DECL
yy_current_state = (yy_start);
yy_match:
do
{
do {
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
if ( yy_accept[yy_current_state] )
{
if (yy_accept[yy_current_state]) {
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) {
yy_current_state = (int)yy_def[yy_current_state];
if (yy_current_state >= 51)
yy_c = yy_meta[(unsigned int)yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int)yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 72 );
} while (yy_base[yy_current_state] != 72);
yy_find_action:
yy_act = yy_accept[yy_current_state];
if ( yy_act == 0 )
{ /* have to back up */
if (yy_act == 0) { /* have to back up */
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);
yy_act = yy_accept[yy_current_state];
@ -806,8 +774,7 @@ yy_find_action:
do_action: /* This label is used only to access EOF actions. */
switch ( yy_act )
{ /* beginning of action switch */
switch (yy_act) { /* beginning of action switch */
case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = (yy_hold_char);
@ -818,22 +785,26 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 32 "debugger-expr.l"
dexp_lval.number=atoi((char *)(dexp_text+1)); return TOK_REGISTER;
dexp_lval.number = atoi((char*)(dexp_text + 1));
return TOK_REGISTER;
YY_BREAK
case 2:
YY_RULE_SETUP
#line 33 "debugger-expr.l"
dexp_lval.number = 13; return TOK_REGISTER;
dexp_lval.number = 13;
return TOK_REGISTER;
YY_BREAK
case 3:
YY_RULE_SETUP
#line 34 "debugger-expr.l"
dexp_lval.number = 14; return TOK_REGISTER;
dexp_lval.number = 14;
return TOK_REGISTER;
YY_BREAK
case 4:
YY_RULE_SETUP
#line 35 "debugger-expr.l"
dexp_lval.number = 15; return TOK_REGISTER;
dexp_lval.number = 15;
return TOK_REGISTER;
YY_BREAK
case 5:
YY_RULE_SETUP
@ -863,22 +834,26 @@ return TOK_LBRACKET;
case 10:
YY_RULE_SETUP
#line 41 "debugger-expr.l"
dexp_lval.number=atoi(dexp_text); return TOK_NUMBER;
dexp_lval.number = atoi(dexp_text);
return TOK_NUMBER;
YY_BREAK
case 11:
YY_RULE_SETUP
#line 42 "debugger-expr.l"
sscanf(dexp_text, "%x", &dexp_lval.number); return TOK_NUMBER;
sscanf(dexp_text, "%x", &dexp_lval.number);
return TOK_NUMBER;
YY_BREAK
case 12:
YY_RULE_SETUP
#line 43 "debugger-expr.l"
sscanf((char *)(dexp_text + 2), "%x", &dexp_lval.number); return TOK_NUMBER;
sscanf((char*)(dexp_text + 2), "%x", &dexp_lval.number);
return TOK_NUMBER;
YY_BREAK
case 13:
YY_RULE_SETUP
#line 44 "debugger-expr.l"
sscanf((char *)(dexp_text + 1), "%x", &dexp_lval.number); return TOK_NUMBER;
sscanf((char*)(dexp_text + 1), "%x", &dexp_lval.number);
return TOK_NUMBER;
YY_BREAK
case 14:
YY_RULE_SETUP
@ -958,7 +933,8 @@ printf("Unrecognised token: %s\n", dexp_text);
case 29:
YY_RULE_SETUP
#line 60 "debugger-expr.l"
dexp_lval.string=dexp_text; return TOK_ID;
dexp_lval.string = dexp_text;
return TOK_ID;
YY_BREAK
case 30:
YY_RULE_SETUP
@ -969,8 +945,7 @@ ECHO;
case YY_STATE_EOF(INITIAL):
yyterminate();
case YY_END_OF_BUFFER:
{
case YY_END_OF_BUFFER: {
/* Amount of text matched not including the EOB char. */
int yy_amount_of_matched_text = (int)(yy_cp - (yytext_ptr)) - 1;
@ -978,8 +953,7 @@ case YY_STATE_EOF(INITIAL):
*yy_cp = (yy_hold_char);
YY_RESTORE_YY_MORE_OFFSET
if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
{
if (YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW) {
/* We're scanning a new file or input source. It's
* possible that this happened because the user
* just pointed dexp_in at a new source and called
@ -1001,8 +975,7 @@ case YY_STATE_EOF(INITIAL):
* end-of-buffer state). Contrast this with the test
* in input().
*/
if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
{ /* This was really a NUL. */
if ((yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]) { /* This was really a NUL. */
yy_state_type yy_next_state;
(yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
@ -1022,29 +995,25 @@ case YY_STATE_EOF(INITIAL):
yy_bp = (yytext_ptr) + YY_MORE_ADJ;
if ( yy_next_state )
{
if (yy_next_state) {
/* Consume the NUL. */
yy_cp = ++(yy_c_buf_p);
yy_current_state = yy_next_state;
goto yy_match;
}
else
{
else {
yy_cp = (yy_c_buf_p);
goto yy_find_action;
}
}
else switch ( yy_get_next_buffer( ) )
{
case EOB_ACT_END_OF_FILE:
{
else
switch (yy_get_next_buffer()) {
case EOB_ACT_END_OF_FILE: {
(yy_did_buffer_switch_on_eof) = 0;
if ( dexp_wrap( ) )
{
if (dexp_wrap()) {
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
* dexp_text, we can now set up
@ -1060,8 +1029,7 @@ case YY_STATE_EOF(INITIAL):
goto do_action;
}
else
{
else {
if (!(yy_did_buffer_switch_on_eof))
YY_NEW_FILE;
}
@ -1069,8 +1037,7 @@ case YY_STATE_EOF(INITIAL):
}
case EOB_ACT_CONTINUE_SCAN:
(yy_c_buf_p) =
(yytext_ptr) + yy_amount_of_matched_text;
(yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
yy_current_state = yy_get_previous_state();
@ -1079,8 +1046,7 @@ case YY_STATE_EOF(INITIAL):
goto yy_match;
case EOB_ACT_LAST_MATCH:
(yy_c_buf_p) =
&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
(yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
yy_current_state = yy_get_previous_state();
@ -1116,18 +1082,15 @@ static int yy_get_next_buffer (void)
YY_FATAL_ERROR(
"fatal flex scanner internal error--end of buffer missed");
if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
{ /* Don't try to fill the buffer, so this is an EOF. */
if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
{
if (YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0) { /* Don't try to fill the buffer, so this is an EOF. */
if ((yy_c_buf_p) - (yytext_ptr)-YY_MORE_ADJ == 1) {
/* We matched a single character, the EOB, so
* treat this as a final EOF.
*/
return EOB_ACT_END_OF_FILE;
}
else
{
else {
/* We matched some text prior to the EOB, first
* process it.
*/
@ -1149,22 +1112,17 @@ static int yy_get_next_buffer (void)
*/
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
else
{
int num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
else {
int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */
while (num_to_read <= 0) { /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf);
int yy_c_buf_p_offset = (int)((yy_c_buf_p)-b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
if (b->yy_is_our_buffer) {
int new_size = b->yy_buf_size * 2;
if (new_size <= 0)
@ -1175,8 +1133,7 @@ static int yy_get_next_buffer (void)
b->yy_ch_buf = (char*)
/* Include room in for 2 EOB chars. */
dexp_realloc((void*)b->yy_ch_buf, b->yy_buf_size + 2);
}
else
} else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = 0;
@ -1186,9 +1143,7 @@ static int yy_get_next_buffer (void)
(yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
number_to_move - 1;
num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
}
if (num_to_read > YY_READ_BUF_SIZE)
@ -1201,19 +1156,15 @@ static int yy_get_next_buffer (void)
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
if ( (yy_n_chars) == 0 )
{
if ( number_to_move == YY_MORE_ADJ )
{
if ((yy_n_chars) == 0) {
if (number_to_move == YY_MORE_ADJ) {
ret_val = EOB_ACT_END_OF_FILE;
dexp_restart(dexp_in);
}
else
{
else {
ret_val = EOB_ACT_LAST_MATCH;
YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
YY_BUFFER_EOF_PENDING;
YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING;
}
}
@ -1246,16 +1197,13 @@ static int yy_get_next_buffer (void)
yy_current_state = (yy_start);
for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
{
for (yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp) {
register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] )
{
if (yy_accept[yy_current_state]) {
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) {
yy_current_state = (int)yy_def[yy_current_state];
if (yy_current_state >= 51)
yy_c = yy_meta[(unsigned int)yy_c];
@ -1277,13 +1225,11 @@ static int yy_get_next_buffer (void)
register char* yy_cp = (yy_c_buf_p);
register YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] )
{
if (yy_accept[yy_current_state]) {
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
while (yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state) {
yy_current_state = (int)yy_def[yy_current_state];
if (yy_current_state >= 51)
yy_c = yy_meta[(unsigned int)yy_c];
@ -1303,22 +1249,18 @@ static int yy_get_next_buffer (void)
/* undo effects of setting up dexp_text */
*yy_cp = (yy_hold_char);
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2) { /* need to shift things up to make room */
/* +2 for EOB chars. */
register int number_to_move = (yy_n_chars) + 2;
register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
register char *source =
&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
register char* dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
register char* source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
while (source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf)
*--dest = *--source;
yy_cp += (int)(dest - source);
yy_bp += (int)(dest - source);
YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
if (yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2)
YY_FATAL_ERROR("flex scanner push-back overflow");
@ -1343,8 +1285,7 @@ static int yy_get_next_buffer (void)
*(yy_c_buf_p) = (yy_hold_char);
if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
{
if (*(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR) {
/* yy_c_buf_p now points to the character we want to return.
* If this occurs *before* the EOB characters, then it's a
* valid NUL; if not, then we've hit the end of the buffer.
@ -1353,13 +1294,11 @@ static int yy_get_next_buffer (void)
/* This was really a NUL. */
*(yy_c_buf_p) = '\0';
else
{ /* need more input */
else { /* need more input */
int offset = (yy_c_buf_p) - (yytext_ptr);
++(yy_c_buf_p);
switch ( yy_get_next_buffer( ) )
{
switch (yy_get_next_buffer()) {
case EOB_ACT_LAST_MATCH:
/* This happens because yy_g_n_b()
* sees that we've accumulated a
@ -1376,8 +1315,7 @@ static int yy_get_next_buffer (void)
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
case EOB_ACT_END_OF_FILE: {
if (dexp_wrap())
return EOF;
@ -1415,8 +1353,7 @@ static int yy_get_next_buffer (void)
if (!YY_CURRENT_BUFFER) {
dexp_ensure_buffer_stack();
YY_CURRENT_BUFFER_LVALUE =
dexp__create_buffer(dexp_in,YY_BUF_SIZE );
YY_CURRENT_BUFFER_LVALUE = dexp__create_buffer(dexp_in, YY_BUF_SIZE);
}
dexp__init_buffer(YY_CURRENT_BUFFER, input_file);
@ -1439,8 +1376,7 @@ static int yy_get_next_buffer (void)
if (YY_CURRENT_BUFFER == new_buffer)
return;
if ( YY_CURRENT_BUFFER )
{
if (YY_CURRENT_BUFFER) {
/* Flush out information for old buffer. */
*(yy_c_buf_p) = (yy_hold_char);
YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
@ -1588,8 +1524,7 @@ void dexp_push_buffer_state (YY_BUFFER_STATE new_buffer )
dexp_ensure_buffer_stack();
/* This block is copied from dexp__switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
if (YY_CURRENT_BUFFER) {
/* Flush out information for old buffer. */
*(yy_c_buf_p) = (yy_hold_char);
YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
@ -1640,9 +1575,7 @@ static void dexp_ensure_buffer_stack (void)
* immediate realloc on the next call.
*/
num_to_alloc = 1;
(yy_buffer_stack) = (struct yy_buffer_state**)dexp_alloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
);
(yy_buffer_stack) = (struct yy_buffer_state**)dexp_alloc(num_to_alloc * sizeof(struct yy_buffer_state*));
if (!(yy_buffer_stack))
YY_FATAL_ERROR("out of dynamic memory in dexp_ensure_buffer_stack()");
@ -1659,10 +1592,8 @@ static void dexp_ensure_buffer_stack (void)
int grow_size = 8 /* arbitrary grow size */;
num_to_alloc = (yy_buffer_stack_max) + grow_size;
(yy_buffer_stack) = (struct yy_buffer_state**)dexp_realloc
((yy_buffer_stack),
num_to_alloc * sizeof(struct yy_buffer_state*)
);
(yy_buffer_stack) = (struct yy_buffer_state**)dexp_realloc((yy_buffer_stack),
num_to_alloc * sizeof(struct yy_buffer_state*));
if (!(yy_buffer_stack))
YY_FATAL_ERROR("out of dynamic memory in dexp_ensure_buffer_stack()");
@ -1682,9 +1613,7 @@ YY_BUFFER_STATE dexp__scan_buffer (char * base, yy_size_t size )
{
YY_BUFFER_STATE b;
if ( size < 2 ||
base[size-2] != YY_END_OF_BUFFER_CHAR ||
base[size-1] != YY_END_OF_BUFFER_CHAR )
if (size < 2 || base[size - 2] != YY_END_OF_BUFFER_CHAR || base[size - 1] != YY_END_OF_BUFFER_CHAR)
/* They forgot to leave room for the EOB's. */
return 0;
@ -1772,8 +1701,7 @@ static void yy_fatal_error (yyconst char* msg )
#undef yyless
#define yyless(n) \
do \
{ \
do { \
/* Undo effects of setting up dexp_text. */ \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg); \
@ -1782,8 +1710,7 @@ static void yy_fatal_error (yyconst char* msg )
(yy_hold_char) = *(yy_c_buf_p); \
*(yy_c_buf_p) = '\0'; \
dexp_leng = yyless_macro_arg; \
} \
while ( 0 )
} while (0)
/* Accessor methods (get/set functions) to struct members. */
@ -1965,10 +1892,7 @@ void dexp_free (void * ptr )
#line 62 "debugger-expr.l"
void dexp_flush()
{
dexp__flush_buffer(YY_CURRENT_BUFFER);
}

View File

@ -116,21 +116,18 @@
#define TOK_NUMBER 276
#define TOK_ID 277
/* Copy the first part of user declarations. */
#line 1 "src/sdl/debugger-expr.y"
#include <stdio.h>
#include "../System.h"
#include "GBA.h"
#include "../common/Port.h"
#include "GBA.h"
#include <string>
#include <map>
#include <iostream>
#include <map>
#include <string>
unsigned int dexp_result = 0;
extern int dexp_error(char*);
@ -148,9 +145,6 @@ std::map<std::string, u32> dexp_vars;
#define readByte(addr) \
map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]
/* Enabling traces. */
#ifndef YYDEBUG
#define YYDEBUG 0
@ -184,11 +178,8 @@ typedef union YYSTYPE
#define YYSTYPE_IS_TRIVIAL 1
#endif
/* Copy the second part of user declarations. */
/* Line 216 of yacc.c. */
#line 188 "src/sdl/debugger-expr-yacc.cpp"
@ -268,8 +259,7 @@ static int
YYID(int i)
#else
static int
YYID (i)
int i;
YYID(i) int i;
#endif
{
return i;
@ -306,7 +296,10 @@ YYID (i)
#ifdef YYSTACK_ALLOC
/* Pacify GCC's `empty if-body' warning. */
# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
#define YYSTACK_FREE(Ptr) \
do { /* empty */ \
; \
} while (YYID(0))
#ifndef YYSTACK_ALLOC_MAXIMUM
/* The OS might guarantee only one guard page at the bottom of the stack,
and a page size can be as small as 4096 bytes. So we cannot safely
@ -345,14 +338,12 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */
#endif
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
#if (!defined yyoverflow \
&& (!defined __cplusplus \
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
/* A type that is properly aligned for any stack member. */
union yyalloc
{
union yyalloc {
yytype_int16 yyss;
YYSTYPE yyvs;
};
@ -374,13 +365,11 @@ union yyalloc
__builtin_memcpy(To, From, (Count) * sizeof(*(From)))
#else
#define YYCOPY(To, From, Count) \
do \
{ \
do { \
YYSIZE_T yyi; \
for (yyi = 0; yyi < (Count); yyi++) \
(To)[yyi] = (From)[yyi]; \
} \
while (YYID (0))
} while (YYID(0))
#endif
#endif
@ -390,15 +379,13 @@ union yyalloc
stack. Advance YYPTR to a properly aligned location for the next
stack. */
#define YYSTACK_RELOCATE(Stack) \
do \
{ \
do { \
YYSIZE_T yynewbytes; \
YYCOPY(&yyptr->Stack, Stack, yysize); \
Stack = &yyptr->Stack; \
yynewbytes = yystacksize * sizeof(*Stack) + YYSTACK_GAP_MAXIMUM; \
yyptr += yynewbytes / sizeof(*yyptr); \
} \
while (YYID (0))
} while (YYID(0))
#endif
@ -424,8 +411,7 @@ union yyalloc
((unsigned int)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
static const yytype_uint8 yytranslate[] =
{
static const yytype_uint8 yytranslate[] = {
0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
@ -459,16 +445,14 @@ static const yytype_uint8 yytranslate[] =
#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
static const yytype_uint8 yyprhs[] =
{
static const yytype_uint8 yyprhs[] = {
0, 0, 3, 5, 7, 9, 13, 17, 20, 23,
27, 31, 35, 39, 43, 47, 51, 55, 57, 61,
65, 69
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
{
static const yytype_int8 yyrhs[] = {
24, 0, -1, 25, -1, 21, -1, 22, -1, 25,
3, 25, -1, 25, 4, 25, -1, 4, 25, -1,
14, 25, -1, 25, 5, 25, -1, 25, 6, 25,
@ -480,8 +464,7 @@ static const yytype_int8 yyrhs[] =
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
static const yytype_uint8 yyrline[] = {
0, 56, 56, 59, 60, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
83, 84
@ -491,8 +474,7 @@ static const yytype_uint8 yyrline[] =
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
static const char* const yytname[] = {
"$end", "error", "$undefined", "TOK_PLUS", "TOK_MINUS", "TOK_DIVIDE",
"TOK_MULTIPLY", "TOK_LSHIFT", "TOK_RSHIFT", "TOK_LPAREN", "TOK_RPAREN",
"TOK_OR", "TOK_AND", "TOK_XOR", "TOK_NEGATE", "TOK_BBRACKET",
@ -504,8 +486,7 @@ static const char *const yytname[] =
#ifdef YYPRINT
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
token YYLEX-NUM. */
static const yytype_uint16 yytoknum[] =
{
static const yytype_uint16 yytoknum[] = {
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
275, 276, 277
@ -513,16 +494,14 @@ static const yytype_uint16 yytoknum[] =
#endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
static const yytype_uint8 yyr1[] = {
0, 23, 24, 25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
25, 25
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
static const yytype_uint8 yyr2[] = {
0, 2, 1, 1, 1, 3, 3, 2, 2, 3,
3, 3, 3, 3, 3, 3, 3, 1, 3, 3,
3, 3
@ -531,8 +510,7 @@ static const yytype_uint8 yyr2[] =
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
STATE-NUM when YYTABLE doesn't specify something else to do. Zero
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
static const yytype_uint8 yydefact[] = {
0, 0, 0, 0, 0, 0, 0, 0, 17, 3,
4, 0, 2, 7, 0, 8, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -541,16 +519,14 @@ static const yytype_uint8 yydefact[] =
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
static const yytype_int8 yydefgoto[] = {
-1, 11, 12
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
#define YYPACT_NINF -2
static const yytype_int8 yypact[] =
{
static const yytype_int8 yypact[] = {
25, 25, 25, 25, 25, 25, 25, 25, -2, -2,
-2, 13, 113, 122, 4, 122, 45, 62, 79, 96,
-2, 25, 25, 25, 25, 25, 25, 25, 25, 25,
@ -559,8 +535,7 @@ static const yytype_int8 yypact[] =
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
static const yytype_int8 yypgoto[] = {
-2, -2, -1
};
@ -569,8 +544,7 @@ static const yytype_int8 yypgoto[] =
number is the opposite. If zero, do what YYDEFACT says.
If YYTABLE_NINF, syntax error. */
#define YYTABLE_NINF -1
static const yytype_uint8 yytable[] =
{
static const yytype_uint8 yytable[] = {
13, 14, 15, 16, 17, 18, 19, 21, 22, 23,
24, 25, 26, 20, 30, 27, 28, 29, 28, 29,
35, 36, 37, 38, 39, 40, 41, 42, 43, 1,
@ -587,8 +561,7 @@ static const yytype_uint8 yytable[] =
26, 0, 0, 27, 28, 29
};
static const yytype_int8 yycheck[] =
{
static const yytype_int8 yycheck[] = {
1, 2, 3, 4, 5, 6, 7, 3, 4, 5,
6, 7, 8, 0, 10, 11, 12, 13, 12, 13,
21, 22, 23, 24, 25, 26, 27, 28, 29, 4,
@ -607,8 +580,7 @@ static const yytype_int8 yycheck[] =
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
static const yytype_uint8 yystos[] = {
0, 4, 9, 14, 15, 16, 17, 18, 20, 21,
22, 24, 25, 25, 25, 25, 25, 25, 25, 25,
0, 3, 4, 5, 6, 7, 8, 11, 12, 13,
@ -625,7 +597,6 @@ static const yytype_uint8 yystos[] =
#define YYABORT goto yyabortlab
#define YYERROR goto yyerrorlab
/* Like YYERROR except do call yyerror. This remains here temporarily
to ease the transition to the new meaning of YYERROR, for GCC.
Once GCC version 2 has supplanted version 1, this can go. */
@ -635,8 +606,8 @@ static const yytype_uint8 yystos[] =
#define YYRECOVERING() (!!yyerrstatus)
#define YYBACKUP(Token, Value) \
do \
if (yychar == YYEMPTY && yylen == 1) \
\
do if (yychar == YYEMPTY && yylen == 1) \
{ \
yychar = (Token); \
yylval = (Value); \
@ -649,13 +620,12 @@ do \
yyerror(YY_("syntax error: cannot back up")); \
YYERROR; \
} \
\
while(YYID(0))
#define YYTERROR 1
#define YYERRCODE 256
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */
@ -664,24 +634,18 @@ while (YYID (0))
#ifndef YYLLOC_DEFAULT
#define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (YYID (N)) \
{ \
if (YYID(N)) { \
(Current).first_line = YYRHSLOC(Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC(Rhs, 1).first_column; \
(Current).last_line = YYRHSLOC(Rhs, N).last_line; \
(Current).last_column = YYRHSLOC(Rhs, N).last_column; \
} \
else \
{ \
(Current).first_line = (Current).last_line = \
YYRHSLOC (Rhs, 0).last_line; \
(Current).first_column = (Current).last_column = \
YYRHSLOC (Rhs, 0).last_column; \
} else { \
(Current).first_line = (Current).last_line = YYRHSLOC(Rhs, 0).last_line; \
(Current).first_column = (Current).last_column = YYRHSLOC(Rhs, 0).last_column; \
} \
while (YYID(0))
#endif
/* YY_LOCATION_PRINT -- Print the location on the stream.
This macro was not mandated originally: define only if we know
we won't break user code: when these are the locations we know. */
@ -697,7 +661,6 @@ while (YYID (0))
#endif
#endif
/* YYLEX -- calling `yylex' with the right arguments. */
#ifdef YYLEX_PARAM
@ -715,22 +678,28 @@ while (YYID (0))
#endif
#define YYDPRINTF(Args) \
do { \
\
do \
{ \
if (yydebug) \
YYFPRINTF Args; \
} while (YYID (0))
\
} \
while (YYID(0))
#define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
do { \
if (yydebug) \
\
do \
{ \
if (yydebug) { \
YYFPRINTF(stderr, "%s ", Title); \
yy_symbol_print(stderr, \
Type, Value); \
YYFPRINTF(stderr, "\n"); \
} \
} while (YYID (0))
\
} \
while (YYID(0))
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
@ -757,14 +726,12 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep)
#else
YYUSE(yyoutput);
#endif
switch (yytype)
{
switch (yytype) {
default:
break;
}
}
/*--------------------------------.
| Print this symbol on YYOUTPUT. |
`--------------------------------*/
@ -813,11 +780,14 @@ yy_stack_print (bottom, top)
}
#define YY_STACK_PRINT(Bottom, Top) \
do { \
\
do \
{ \
if (yydebug) \
yy_stack_print((Bottom), (Top)); \
} while (YYID (0))
\
} \
while (YYID(0))
/*------------------------------------------------.
| Report that the YYRULE is going to be reduced. |
@ -840,21 +810,23 @@ yy_reduce_print (yyvsp, yyrule)
YYFPRINTF(stderr, "Reducing stack by rule %d (line %lu):\n",
yyrule - 1, yylno);
/* The symbols being reduced. */
for (yyi = 0; yyi < yynrhs; yyi++)
{
for (yyi = 0; yyi < yynrhs; yyi++) {
fprintf(stderr, " $%d = ", yyi + 1);
yy_symbol_print(stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
);
&(yyvsp[(yyi + 1) - (yynrhs)]));
fprintf(stderr, "\n");
}
}
#define YY_REDUCE_PRINT(Rule) \
do { \
\
do \
{ \
if (yydebug) \
yy_reduce_print(yyvsp, Rule); \
} while (YYID (0))
\
} \
while (YYID(0))
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
@ -866,7 +838,6 @@ int yydebug;
#define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
#define YYINITDEPTH 200
@ -883,8 +854,6 @@ int yydebug;
#define YYMAXDEPTH 10000
#endif
#if YYERROR_VERBOSE
#ifndef yystrlen
@ -922,8 +891,7 @@ static char *
yystpcpy(char* yydest, const char* yysrc)
#else
static char*
yystpcpy (yydest, yysrc)
char *yydest;
yystpcpy(yydest, yysrc) char* yydest;
const char* yysrc;
#endif
{
@ -949,14 +917,12 @@ yystpcpy (yydest, yysrc)
static YYSIZE_T
yytnamerr(char* yyres, const char* yystr)
{
if (*yystr == '"')
{
if (*yystr == '"') {
YYSIZE_T yyn = 0;
char const* yyp = yystr;
for (;;)
switch (*++yyp)
{
switch (*++yyp) {
case '\'':
case ',':
goto do_not_strip_quotes;
@ -1000,8 +966,7 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
if (!(YYPACT_NINF < yyn && yyn <= YYLAST))
return 0;
else
{
else {
int yytype = YYTRANSLATE(yychar);
YYSIZE_T yysize0 = yytnamerr(0, yytname[yytype]);
YYSIZE_T yysize = yysize0;
@ -1044,10 +1009,8 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
yyfmt = yystpcpy(yyformat, yyunexpected);
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) {
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) {
yycount = 1;
yysize = yysize0;
yyformat[sizeof yyunexpected - 1] = '\0';
@ -1069,22 +1032,17 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
if (yysize_overflow)
return YYSIZE_MAXIMUM;
if (yyresult)
{
if (yyresult) {
/* Avoid sprintf, as that infringes on the user's name space.
Don't have undefined behavior even if the translation
produced a string with the wrong number of "%s"s. */
char* yyp = yyresult;
int yyi = 0;
while ((*yyp = *yyf) != '\0')
{
if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
{
while ((*yyp = *yyf) != '\0') {
if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) {
yyp += yytnamerr(yyp, yyarg[yyi++]);
yyf += 2;
}
else
{
} else {
yyp++;
yyf++;
}
@ -1094,7 +1052,6 @@ yysyntax_error (char *yyresult, int yystate, int yychar)
}
}
#endif /* YYERROR_VERBOSE */
/*-----------------------------------------------.
| Release the memory associated to this symbol. |
@ -1119,14 +1076,12 @@ yydestruct (yymsg, yytype, yyvaluep)
yymsg = "Deleting";
YY_SYMBOL_PRINT(yymsg, yytype, yyvaluep, yylocationp);
switch (yytype)
{
switch (yytype) {
default:
break;
}
}
/* Prevent warnings from -Wmissing-prototypes. */
@ -1144,8 +1099,6 @@ int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
/* The look-ahead symbol. */
int yychar;
@ -1155,8 +1108,6 @@ YYSTYPE yylval;
/* Number of syntax errors so far. */
int yynerrs;
/*----------.
| yyparse. |
`----------*/
@ -1164,21 +1115,17 @@ int yynerrs;
#ifdef YYPARSE_PARAM
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (void *YYPARSE_PARAM)
int yyparse(void* YYPARSE_PARAM)
#else
int
yyparse (YYPARSE_PARAM)
void *YYPARSE_PARAM;
yyparse(YYPARSE_PARAM) void* YYPARSE_PARAM;
#endif
#else /* ! YYPARSE_PARAM */
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
yyparse (void)
int yyparse(void)
#else
int
yyparse ()
int yyparse()
#endif
#endif
@ -1216,8 +1163,6 @@ yyparse ()
YYSTYPE* yyvs = yyvsa;
YYSTYPE* yyvsp;
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
YYSIZE_T yystacksize = YYINITDEPTH;
@ -1226,7 +1171,6 @@ yyparse ()
action routines. */
YYSTYPE yyval;
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
@ -1259,8 +1203,7 @@ yyparse ()
yysetstate:
*yyssp = yystate;
if (yyss + yystacksize - 1 <= yyssp)
{
if (yyss + yystacksize - 1 <= yyssp) {
/* Get the current used size of the three stacks, in elements. */
YYSIZE_T yysize = yyssp - yyss + 1;
@ -1272,7 +1215,6 @@ yyparse ()
YYSTYPE* yyvs1 = yyvs;
yytype_int16* yyss1 = yyss;
/* Each stack pointer address is followed by the size of the
data in use in that stack, in bytes. This used to be a
conditional around just the two extra args, but that might
@ -1299,8 +1241,7 @@ yyparse ()
{
yytype_int16* yyss1 = yyss;
union yyalloc *yyptr =
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
union yyalloc* yyptr = (union yyalloc*)YYSTACK_ALLOC(YYSTACK_BYTES(yystacksize));
if (!yyptr)
goto yyexhaustedlab;
YYSTACK_RELOCATE(yyss);
@ -1316,7 +1257,6 @@ yyparse ()
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
YYDPRINTF((stderr, "Stack size increased to %lu\n",
(unsigned long int)yystacksize));
@ -1344,19 +1284,15 @@ yybackup:
/* Not known => get a look-ahead token if don't already have one. */
/* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
if (yychar == YYEMPTY)
{
if (yychar == YYEMPTY) {
YYDPRINTF((stderr, "Reading a token: "));
yychar = YYLEX;
}
if (yychar <= YYEOF)
{
if (yychar <= YYEOF) {
yychar = yytoken = YYEOF;
YYDPRINTF((stderr, "Now at end of input.\n"));
}
else
{
} else {
yytoken = YYTRANSLATE(yychar);
YY_SYMBOL_PRINT("Next token is", yytoken, &yylval, &yylloc);
}
@ -1367,8 +1303,7 @@ yybackup:
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
goto yydefault;
yyn = yytable[yyn];
if (yyn <= 0)
{
if (yyn <= 0) {
if (yyn == 0 || yyn == YYTABLE_NINF)
goto yyerrlab;
yyn = -yyn;
@ -1395,7 +1330,6 @@ yybackup:
goto yynewstate;
/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state. |
`-----------------------------------------------------------*/
@ -1405,7 +1339,6 @@ yydefault:
goto yyerrlab;
goto yyreduce;
/*-----------------------------.
| yyreduce -- Do a reduction. |
`-----------------------------*/
@ -1423,19 +1356,19 @@ yyreduce:
GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1 - yylen];
YY_REDUCE_PRINT(yyn);
switch (yyn)
{
switch (yyn) {
case 2:
#line 56 "src/sdl/debugger-expr.y"
{dexp_result = (yyvsp[(1) - (1)].number);}
break;
{
dexp_result = (yyvsp[(1) - (1)].number);
} break;
case 3:
#line 59 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (1)].number); }
break;
{
(yyval.number) = (yyvsp[(1) - (1)].number);
} break;
case 4:
#line 60 "src/sdl/debugger-expr.y"
@ -1446,98 +1379,114 @@ yyreduce:
YYABORT;
}
(yyval.number) = dexp_vars[v];
}
break;
} break;
case 5:
#line 68 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) + (yyvsp[(3) - (3)].number); }
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) + (yyvsp[(3) - (3)].number);
} break;
case 6:
#line 69 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) - (yyvsp[(3) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) - (yyvsp[(3) - (3)].number);
} break;
case 7:
#line 70 "src/sdl/debugger-expr.y"
{ (yyval.number) = -(yyvsp[(2) - (2)].number);}
break;
{
(yyval.number) = -(yyvsp[(2) - (2)].number);
} break;
case 8:
#line 71 "src/sdl/debugger-expr.y"
{ (yyval.number) = ~(yyvsp[(2) - (2)].number);}
break;
{
(yyval.number) = ~(yyvsp[(2) - (2)].number);
} break;
case 9:
#line 72 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) / (yyvsp[(3) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) / (yyvsp[(3) - (3)].number);
} break;
case 10:
#line 73 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) * (yyvsp[(3) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) * (yyvsp[(3) - (3)].number);
} break;
case 11:
#line 74 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) << (yyvsp[(3) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) << (yyvsp[(3) - (3)].number);
} break;
case 12:
#line 75 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) >> (yyvsp[(3) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) >> (yyvsp[(3) - (3)].number);
} break;
case 13:
#line 76 "src/sdl/debugger-expr.y"
{ (yyval.number)=(yyvsp[(2) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(2) - (3)].number);
} break;
case 14:
#line 77 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) & (yyvsp[(3) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) & (yyvsp[(3) - (3)].number);
} break;
case 15:
#line 78 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number);}
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number);
} break;
case 16:
#line 79 "src/sdl/debugger-expr.y"
{ (yyval.number) = (yyvsp[(1) - (3)].number) ^ (yyvsp[(3) - (3)].number); }
break;
{
(yyval.number) = (yyvsp[(1) - (3)].number) ^ (yyvsp[(3) - (3)].number);
} break;
case 17:
#line 80 "src/sdl/debugger-expr.y"
{ (yyval.number) = reg[(yyvsp[(1) - (1)].number)].I; }
break;
{
(yyval.number) = reg[(yyvsp[(1) - (1)].number)].I;
} break;
case 18:
#line 81 "src/sdl/debugger-expr.y"
{ (yyval.number) = readByte((yyvsp[(2) - (3)].number)); }
break;
{
(yyval.number) = readByte((yyvsp[(2) - (3)].number));
} break;
case 19:
#line 82 "src/sdl/debugger-expr.y"
{ (yyval.number) = readHalfWord((yyvsp[(2) - (3)].number)); }
break;
{
(yyval.number) = readHalfWord((yyvsp[(2) - (3)].number));
} break;
case 20:
#line 83 "src/sdl/debugger-expr.y"
{ (yyval.number) = readWord((yyvsp[(2) - (3)].number)); }
break;
{
(yyval.number) = readWord((yyvsp[(2) - (3)].number));
} break;
case 21:
#line 84 "src/sdl/debugger-expr.y"
{ (yyval.number) = readWord((yyvsp[(2) - (3)].number)); }
break;
{
(yyval.number) = readWord((yyvsp[(2) - (3)].number));
} break;
/* Line 1267 of yacc.c. */
#line 1534 "src/sdl/debugger-expr-yacc.cpp"
default: break;
default:
break;
}
YY_SYMBOL_PRINT("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@ -1547,7 +1496,6 @@ yyreduce:
*++yyvsp = yyval;
/* Now `shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
number reduced by. */
@ -1562,22 +1510,19 @@ yyreduce:
goto yynewstate;
/*------------------------------------.
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
/* If not already recovering from an error, report this error. */
if (!yyerrstatus)
{
if (!yyerrstatus) {
++yynerrs;
#if !YYERROR_VERBOSE
yyerror(YY_("syntax error"));
#else
{
YYSIZE_T yysize = yysyntax_error(0, yystate, yychar);
if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
{
if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) {
YYSIZE_T yyalloc = 2 * yysize;
if (!(yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
yyalloc = YYSTACK_ALLOC_MAXIMUM;
@ -1586,20 +1531,16 @@ yyerrlab:
yymsg = (char*)YYSTACK_ALLOC(yyalloc);
if (yymsg)
yymsg_alloc = yyalloc;
else
{
else {
yymsg = yymsgbuf;
yymsg_alloc = sizeof yymsgbuf;
}
}
if (0 < yysize && yysize <= yymsg_alloc)
{
if (0 < yysize && yysize <= yymsg_alloc) {
(void)yysyntax_error(yymsg, yystate, yychar);
yyerror(yymsg);
}
else
{
} else {
yyerror(YY_("syntax error"));
if (yysize != 0)
goto yyexhaustedlab;
@ -1608,21 +1549,15 @@ yyerrlab:
#endif
}
if (yyerrstatus == 3)
{
if (yyerrstatus == 3) {
/* If just tried and failed to reuse look-ahead token after an
error, discard it. */
if (yychar <= YYEOF)
{
if (yychar <= YYEOF) {
/* Return failure if at end of input. */
if (yychar == YYEOF)
YYABORT;
}
else
{
} else {
yydestruct("Error: discarding",
yytoken, &yylval);
yychar = YYEMPTY;
@ -1633,7 +1568,6 @@ yyerrlab:
token. */
goto yyerrlab1;
/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR. |
`---------------------------------------------------*/
@ -1653,21 +1587,17 @@ yyerrorlab:
yystate = *yyssp;
goto yyerrlab1;
/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR. |
`-------------------------------------------------------------*/
yyerrlab1:
yyerrstatus = 3; /* Each real token shifted decrements this. */
for (;;)
{
for (;;) {
yyn = yypact[yystate];
if (yyn != YYPACT_NINF)
{
if (yyn != YYPACT_NINF) {
yyn += YYTERROR;
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
{
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) {
yyn = yytable[yyn];
if (0 < yyn)
break;
@ -1678,7 +1608,6 @@ yyerrlab1:
if (yyssp == yyss)
YYABORT;
yydestruct("Error: popping",
yystos[yystate], yyvsp);
YYPOPSTACK(1);
@ -1691,14 +1620,12 @@ yyerrlab1:
*++yyvsp = yylval;
/* Shift the error token. */
YY_SYMBOL_PRINT("Shifting", yystos[yyn], yyvsp, yylsp);
yystate = yyn;
goto yynewstate;
/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here. |
`-------------------------------------*/
@ -1731,8 +1658,7 @@ yyreturn:
this YYABORT or YYACCEPT. */
YYPOPSTACK(yylen);
YY_STACK_PRINT(yyss, yyssp);
while (yyssp != yyss)
{
while (yyssp != yyss) {
yydestruct("Cleanup: popping",
yystos[*yyssp], yyvsp);
YYPOPSTACK(1);
@ -1749,10 +1675,8 @@ yyreturn:
return YYID(yyresult);
}
#line 86 "src/sdl/debugger-expr.y"
bool dexp_eval(char* expr, u32* result)
{
extern void dexp_flush();
@ -1761,7 +1685,6 @@ bool dexp_eval(char *expr, u32 *result)
dexp_flush();
dexprString = expr;
dexprCol = 0;

View File

@ -2,10 +2,10 @@
#include <stdlib.h>
#include <string.h>
#include "GBA.h"
#include "../common/Port.h"
#include "elf.h"
#include "../NLS.h"
#include "../common/Port.h"
#include "GBA.h"
#include "elf.h"
#define elfReadMemory(addr) \
READ32LE((&map[(addr) >> 24].address[(addr)&map[(addr) >> 24].mask]))
@ -185,7 +185,6 @@ enum ELFRegMode {
REG_REGISTER
};
struct ELFFrameStateRegister {
ELFRegMode mode;
int reg;
@ -483,8 +482,7 @@ ELFfde *elfGetFde(u32 address)
if (elfFdes) {
int i;
for (i = 0; i < elfFdeCount; i++) {
if(address >= elfFdes[i]->address &&
address < elfFdes[i]->end) {
if (address >= elfFdes[i]->address && address < elfFdes[i]->end) {
return elfFdes[i];
}
}
@ -511,8 +509,7 @@ void elfExecuteCFAInstructions(ELFFrameState *state, u8 *data, u32 len,
case DW_CFA_offset:
reg = op & 0x3f;
state->registers.regs[reg].mode = REG_OFFSET;
state->registers.regs[reg].offset = state->dataAlign *
(s32)elfReadLEB128(data, &bytes);
state->registers.regs[reg].offset = state->dataAlign * (s32)elfReadLEB128(data, &bytes);
data += bytes;
break;
case DW_CFA_restore:
@ -539,8 +536,7 @@ void elfExecuteCFAInstructions(ELFFrameState *state, u8 *data, u32 len,
reg = elfReadLEB128(data, &bytes);
data += bytes;
state->registers.regs[reg].mode = REG_OFFSET;
state->registers.regs[reg].offset = state->dataAlign *
(s32)elfReadLEB128(data, &bytes);
state->registers.regs[reg].offset = state->dataAlign * (s32)elfReadLEB128(data, &bytes);
data += bytes;
break;
case DW_CFA_restore_extended:
@ -653,17 +649,14 @@ void elfPrintCallChain(u32 address)
memcpy(&newRegs[0], &regs[0], sizeof(reg_pair) * 15);
u32 addr = 0;
for (int i = 0; i < 15; i++) {
ELFFrameStateRegister *r = &state->registers.
regs[i];
ELFFrameStateRegister* r = &state->registers.regs[i];
switch (r->mode) {
case REG_NOT_SET:
newRegs[i].I = regs[i].I;
break;
case REG_OFFSET:
newRegs[i].I = elfReadMemory(regs[state->cfaRegister].I +
state->cfaOffset +
r->offset);
newRegs[i].I = elfReadMemory(regs[state->cfaRegister].I + state->cfaOffset + r->offset);
break;
case REG_REGISTER:
newRegs[i].I = regs[r->reg].I;
@ -757,14 +750,12 @@ u32 elfDecodeLocation(Function *f, ELFBlock *o, LocationType *type, u32 base)
location = *loc->data - 0x50;
*type = LOCATION_register;
break;
case DW_OP_fbreg:
{
case DW_OP_fbreg: {
int bytes;
s32 off = elfReadSignedLEB128(loc->data + 1, &bytes);
location = framebase + off;
*type = LOCATION_memory;
}
break;
} break;
default:
fprintf(stderr, "Unknown location %02x\n", *loc->data);
break;
@ -850,8 +841,8 @@ ELFSectionHeader *elfGetSectionByName(const char *name)
{
for (int i = 0; i < elfSectionHeadersCount; i++) {
if (strcmp(name,
&elfSectionHeadersStringTable[READ32LE(&elfSectionHeaders[i]->
name)]) == 0) {
&elfSectionHeadersStringTable[READ32LE(&elfSectionHeaders[i]->name)])
== 0) {
return elfSectionHeaders[i];
}
}
@ -1004,8 +995,7 @@ ELFAbbrev **elfReadAbbrevs(u8 *data, u32 offset)
while (name) {
if ((abbrev->numAttrs % 4) == 0) {
abbrev->attrs = (ELFAttr*)realloc(abbrev->attrs,
(abbrev->numAttrs + 4) *
sizeof(ELFAttr));
(abbrev->numAttrs + 4) * sizeof(ELFAttr));
}
abbrev->attrs[abbrev->numAttrs].name = name;
abbrev->attrs[abbrev->numAttrs++].form = form;
@ -1116,8 +1106,7 @@ void elfParseCFA(u8 *top)
fde->dataLen = (u32)(dataEnd - data);
if ((elfFdeCount % 10) == 0) {
elfFdes = (ELFfde **)realloc(elfFdes, (elfFdeCount+10) *
sizeof(ELFfde *));
elfFdes = (ELFfde**)realloc(elfFdes, (elfFdeCount + 10) * sizeof(ELFfde*));
}
elfFdes[elfFdeCount++] = fde;
}
@ -1219,8 +1208,7 @@ void elfParseLineInfo(CompileUnit *unit, u8 *top)
while (!endSeq) {
int op = *data++;
switch (op) {
case DW_LNS_extended_op:
{
case DW_LNS_extended_op: {
data++;
op = *data++;
switch (op) {
@ -1235,8 +1223,7 @@ void elfParseLineInfo(CompileUnit *unit, u8 *top)
fprintf(stderr, "Unknown extended LINE opcode %02x\n", op);
exit(-1);
}
}
break;
} break;
case DW_LNS_copy:
// fprintf(stderr, "Address %08x line %d (%d)\n", address, line, file);
elfAddLine(l, address, file, line, &max);
@ -1345,8 +1332,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
Type** type)
{
switch (abbrev->tag) {
case DW_TAG_typedef:
{
case DW_TAG_typedef: {
u32 typeref = 0;
char* name = NULL;
for (int i = 0; i < abbrev->numAttrs; i++) {
@ -1373,11 +1359,9 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
if (name)
(*type)->name = name;
return;
}
break;
} break;
case DW_TAG_union_type:
case DW_TAG_structure_type:
{
case DW_TAG_structure_type: {
Type* t = (Type*)calloc(sizeof(Type), 1);
if (abbrev->tag == DW_TAG_structure_type)
t->type = TYPE_struct;
@ -1419,8 +1403,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
ELFAbbrev* abbr = elfGetAbbrev(unit->abbrevs, num);
switch (abbr->tag) {
case DW_TAG_member:
{
case DW_TAG_member: {
if ((index % 4) == 0)
s->members = (Member*)realloc(s->members,
sizeof(Member) * (index + 4));
@ -1462,10 +1445,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
}
}
index++;
}
break;
case DW_TAG_subprogram:
{
} break;
case DW_TAG_subprogram: {
Function* fnc = NULL;
data = elfParseFunction(data, abbr, unit, &fnc);
if (fnc != NULL) {
@ -1475,8 +1456,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
unit->functions = fnc;
unit->lastFunction = fnc;
}
}
break;
} break;
case DW_TAG_inheritance:
// TODO: add support
data = elfSkipData(data, abbr, unit->abbrevs);
@ -1500,10 +1480,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
}
*type = t;
return;
}
break;
case DW_TAG_base_type:
{
} break;
case DW_TAG_base_type: {
Type* t = (Type*)calloc(sizeof(Type), 1);
t->type = TYPE_base;
@ -1534,10 +1512,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
fprintf(stderr, "Unexpected children for base type\n");
*type = t;
return;
}
break;
case DW_TAG_pointer_type:
{
} break;
case DW_TAG_pointer_type: {
Type* t = (Type*)calloc(sizeof(Type), 1);
t->type = TYPE_pointer;
@ -1563,10 +1539,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
fprintf(stderr, "Unexpected children for pointer type\n");
*type = t;
return;
}
break;
case DW_TAG_reference_type:
{
} break;
case DW_TAG_reference_type: {
Type* t = (Type*)calloc(sizeof(Type), 1);
t->type = TYPE_reference;
@ -1592,10 +1566,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
fprintf(stderr, "Unexpected children for ref type\n");
*type = t;
return;
}
break;
case DW_TAG_volatile_type:
{
} break;
case DW_TAG_volatile_type: {
u32 typeref = 0;
for (int i = 0; i < abbrev->numAttrs; i++) {
@ -1615,10 +1587,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
fprintf(stderr, "Unexpected children for volatile type\n");
*type = elfParseType(unit, typeref);
return;
}
break;
case DW_TAG_const_type:
{
} break;
case DW_TAG_const_type: {
u32 typeref = 0;
for (int i = 0; i < abbrev->numAttrs; i++) {
@ -1638,10 +1608,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
fprintf(stderr, "Unexpected children for const type\n");
*type = elfParseType(unit, typeref);
return;
}
break;
case DW_TAG_enumeration_type:
{
} break;
case DW_TAG_enumeration_type: {
Type* t = (Type*)calloc(sizeof(Type), 1);
t->type = TYPE_enum;
Enum* e = (Enum*)calloc(sizeof(Enum), 1);
@ -1674,8 +1642,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
ELFAbbrev* abbr = elfGetAbbrev(unit->abbrevs, num);
switch (abbr->tag) {
case DW_TAG_enumerator:
{
case DW_TAG_enumerator: {
count++;
e->members = (EnumMember*)realloc(e->members,
count * sizeof(EnumMember));
@ -1695,8 +1662,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
attr->name);
}
}
}
break;
} break;
default:
fprintf(stderr, "Unknown enum tag %02x\n", abbr->tag);
data = elfSkipData(data, abbr, unit->abbrevs);
@ -1709,10 +1675,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
e->count = count;
*type = t;
return;
}
break;
case DW_TAG_subroutine_type:
{
} break;
case DW_TAG_subroutine_type: {
Type* t = (Type*)calloc(sizeof(Type), 1);
t->type = TYPE_function;
FunctionType* f = (FunctionType*)calloc(sizeof(FunctionType), 1);
@ -1741,8 +1705,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
ELFAbbrev* abbr = elfGetAbbrev(unit->abbrevs, num);
switch (abbr->tag) {
case DW_TAG_formal_parameter:
{
case DW_TAG_formal_parameter: {
Object* o;
data = elfParseObject(data, abbr, unit, &o);
if (f->args)
@ -1750,8 +1713,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
else
f->args = o;
lastVar = o;
}
break;
} break;
case DW_TAG_unspecified_parameters:
// no use in the debugger yet
data = elfSkipData(data, abbr, unit->abbrevs);
@ -1771,10 +1733,8 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
}
*type = t;
return;
}
break;
case DW_TAG_array_type:
{
} break;
case DW_TAG_array_type: {
u32 typeref = 0;
int i;
Array* array = (Array*)calloc(sizeof(Array), 1);
@ -1806,8 +1766,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
ELFAbbrev* abbr = elfGetAbbrev(unit->abbrevs, num);
switch (abbr->tag) {
case DW_TAG_subrange_type:
{
case DW_TAG_subrange_type: {
if (maxBounds == index) {
maxBounds += 4;
array->bounds = (int*)realloc(array->bounds,
@ -1828,8 +1787,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
}
}
index++;
}
break;
} break;
default:
fprintf(stderr, "Unknown array tag %02x\n", abbr->tag);
data = elfSkipData(data, abbr, unit->abbrevs);
@ -1846,8 +1804,7 @@ void elfParseType(u8 *data, u32 offset, ELFAbbrev *abbrev, CompileUnit *unit,
t->array = array;
*type = t;
return;
}
break;
} break;
default:
fprintf(stderr, "Unknown type TAG %02x\n", abbrev->tag);
exit(-1);
@ -2038,8 +1995,7 @@ u8 *elfParseBlock(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
case DW_TAG_lexical_block:
data = elfParseBlock(data, abbrev, unit, func, lastVar);
break;
case DW_TAG_subprogram:
{
case DW_TAG_subprogram: {
Function* f = NULL;
data = elfParseFunction(data, abbrev, unit, &f);
if (f != NULL) {
@ -2049,10 +2005,8 @@ u8 *elfParseBlock(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
unit->functions = f;
unit->lastFunction = f;
}
}
break;
case DW_TAG_variable:
{
} break;
case DW_TAG_variable: {
Object* o;
data = elfParseObject(data, abbrev, unit, &o);
if (o->startScope == 0)
@ -2064,18 +2018,15 @@ u8 *elfParseBlock(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
else
func->variables = o;
*lastVar = o;
}
break;
} break;
case DW_TAG_inlined_subroutine:
// TODO:
data = elfSkipData(data, abbrev, unit->abbrevs);
break;
default:
{
default: {
fprintf(stderr, "Unknown block TAG %02x\n", abbrev->tag);
data = elfSkipData(data, abbrev, unit->abbrevs);
}
break;
} break;
}
}
}
@ -2267,8 +2218,7 @@ u8 *elfParseFunction(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
case DW_TAG_label: // not needed
data = elfSkipData(data, abbrev, unit->abbrevs);
break;
case DW_TAG_subprogram:
{
case DW_TAG_subprogram: {
Function* fnc = NULL;
data = elfParseFunction(data, abbrev, unit, &fnc);
if (fnc != NULL) {
@ -2278,15 +2228,11 @@ u8 *elfParseFunction(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
unit->lastFunction->next = fnc;
unit->lastFunction = fnc;
}
}
break;
case DW_TAG_lexical_block:
{
} break;
case DW_TAG_lexical_block: {
data = elfParseBlock(data, abbrev, unit, func, &lastVar);
}
break;
case DW_TAG_formal_parameter:
{
} break;
case DW_TAG_formal_parameter: {
Object* o;
data = elfParseObject(data, abbrev, unit, &o);
if (func->parameters)
@ -2294,10 +2240,8 @@ u8 *elfParseFunction(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
else
func->parameters = o;
lastParam = o;
}
break;
case DW_TAG_variable:
{
} break;
case DW_TAG_variable: {
Object* o;
data = elfParseObject(data, abbrev, unit, &o);
if (func->variables)
@ -2305,11 +2249,9 @@ u8 *elfParseFunction(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
else
func->variables = o;
lastVar = o;
}
break;
} break;
case DW_TAG_unspecified_parameters:
case DW_TAG_inlined_subroutine:
{
case DW_TAG_inlined_subroutine: {
// todo
for (int i = 0; i < abbrev->numAttrs; i++) {
data = elfReadAttribute(data, &abbrev->attrs[i]);
@ -2319,14 +2261,11 @@ u8 *elfParseFunction(u8 *data, ELFAbbrev *abbrev, CompileUnit *unit,
if (abbrev->hasChildren)
nesting++;
}
break;
default:
{
} break;
default: {
fprintf(stderr, "Unknown function TAG %02x\n", abbrev->tag);
data = elfSkipData(data, abbrev, unit->abbrevs);
}
break;
} break;
}
}
}
@ -2386,8 +2325,7 @@ u8 *elfParseCompileUnitChildren(u8 *data, CompileUnit *unit)
while (abbrevNum) {
ELFAbbrev* abbrev = elfGetAbbrev(unit->abbrevs, abbrevNum);
switch (abbrev->tag) {
case DW_TAG_subprogram:
{
case DW_TAG_subprogram: {
Function* func = NULL;
data = elfParseFunction(data, abbrev, unit, &func);
if (func != NULL) {
@ -2397,13 +2335,11 @@ u8 *elfParseCompileUnitChildren(u8 *data, CompileUnit *unit)
unit->functions = func;
unit->lastFunction = func;
}
}
break;
} break;
CASE_TYPE_TAG:
data = elfSkipData(data, abbrev, unit->abbrevs);
break;
case DW_TAG_variable:
{
case DW_TAG_variable: {
Object* var = NULL;
data = elfParseObject(data, abbrev, unit, &var);
if (lastObj)
@ -2411,8 +2347,7 @@ u8 *elfParseCompileUnitChildren(u8 *data, CompileUnit *unit)
else
unit->variables = var;
lastObj = var;
}
break;
} break;
default:
data = elfParseUnknownData(data, abbrev, unit->abbrevs);
break;
@ -2424,7 +2359,6 @@ u8 *elfParseCompileUnitChildren(u8 *data, CompileUnit *unit)
return data;
}
CompileUnit* elfParseCompUnit(u8* data, u8* abbrevData)
{
int bytes;
@ -2631,16 +2565,14 @@ bool elfReadProgram(ELFHeader *eh, u8 *data, int& size, bool parseDebug)
// i, ph->type, ph->offset, ph->vaddr, ph->paddr,
// ph->filesz, ph->memsz, ph->flags, ph->align);
if (cpuIsMultiBoot) {
if(READ32LE(&ph->paddr) >= 0x2000000 &&
READ32LE(&ph->paddr) <= 0x203ffff) {
if (READ32LE(&ph->paddr) >= 0x2000000 && READ32LE(&ph->paddr) <= 0x203ffff) {
memcpy(&workRAM[READ32LE(&ph->paddr) & 0x3ffff],
data + READ32LE(&ph->offset),
READ32LE(&ph->filesz));
size += READ32LE(&ph->filesz);
}
} else {
if(READ32LE(&ph->paddr) >= 0x8000000 &&
READ32LE(&ph->paddr) <= 0x9ffffff) {
if (READ32LE(&ph->paddr) >= 0x8000000 && READ32LE(&ph->paddr) <= 0x9ffffff) {
memcpy(&rom[READ32LE(&ph->paddr) & 0x1ffffff],
data + READ32LE(&ph->offset),
READ32LE(&ph->filesz));
@ -2681,16 +2613,13 @@ bool elfReadProgram(ELFHeader *eh, u8 *data, int& size, bool parseDebug)
// sh[i]->link, sh[i]->info);
if (READ32LE(&sh[i]->flags) & 2) { // load section
if (cpuIsMultiBoot) {
if(READ32LE(&sh[i]->addr) >= 0x2000000 &&
READ32LE(&sh[i]->addr) <= 0x203ffff) {
memcpy(&workRAM[READ32LE(&sh[i]->addr) & 0x3ffff], data +
READ32LE(&sh[i]->offset),
if (READ32LE(&sh[i]->addr) >= 0x2000000 && READ32LE(&sh[i]->addr) <= 0x203ffff) {
memcpy(&workRAM[READ32LE(&sh[i]->addr) & 0x3ffff], data + READ32LE(&sh[i]->offset),
READ32LE(&sh[i]->size));
size += READ32LE(&sh[i]->size);
}
} else {
if(READ32LE(&sh[i]->addr) >= 0x8000000 &&
READ32LE(&sh[i]->addr) <= 0x9ffffff) {
if (READ32LE(&sh[i]->addr) >= 0x8000000 && READ32LE(&sh[i]->addr) <= 0x9ffffff) {
memcpy(&rom[READ32LE(&sh[i]->addr) & 0x1ffffff],
data + READ32LE(&sh[i]->offset),
READ32LE(&sh[i]->size));
@ -2785,8 +2714,7 @@ bool elfRead(const char *name, int& siz, FILE *f)
int res = fread(elfFileData, 1, size, f);
fclose(f);
if (res < 0)
{
if (res < 0) {
free(elfFileData);
elfFileData = NULL;
return false;
@ -2794,9 +2722,7 @@ bool elfRead(const char *name, int& siz, FILE *f)
ELFHeader* header = (ELFHeader*)elfFileData;
if(READ32LE(&header->magic) != 0x464C457F ||
READ16LE(&header->e_machine) != 40 ||
header->clazz != 1) {
if (READ32LE(&header->magic) != 0x464C457F || READ16LE(&header->e_machine) != 40 || header->clazz != 1) {
systemMessage(0, N_("Not a valid ELF file %s"), name);
free(elfFileData);
elfFileData = NULL;

View File

@ -1,7 +1,9 @@
#ifndef ELF_H
#define ELF_H
enum LocationType { LOCATION_register, LOCATION_memory, LOCATION_value };
enum LocationType { LOCATION_register,
LOCATION_memory,
LOCATION_value };
#define DW_ATE_boolean 0x02
#define DW_ATE_signed 0x05

View File

@ -1,5 +1,5 @@
#include <stdio.h>
#include <locale>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -15,7 +15,6 @@ char rom_info[19];
char Signature[0x29] = "E-Reader Dotcode -Created- by CaitSith2";
unsigned char ShortDotCodeHeader[0x30] = {
0x00, 0x30, 0x01, 0x01,
0x00, 0x01, 0x05, 0x10,
@ -56,7 +55,6 @@ unsigned char LongDotCodeHeader[0x30] = {
0x4E, 0x54, 0x45, 0x4E, 0x44, 0x4F, 0x00, 0x22,
0x00, 0x09, //Constant data
0x00, 0x00, //Header, last 8 bytes
0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
@ -138,39 +136,29 @@ int LoadDotCodeData(int size, u32* DCdata, unsigned long MEM1, unsigned long MEM
CPUWriteMemory((MEM2 - 8) + i, 0);
for (i = 0; i < 0x1860; i += 4)
CPUWriteMemory(temp1 + i, 0);
if(DCdata != NULL)
{
if(size==0xB60)
{
for(i=0;i<28;i++)
{
for(j=0,scantotal=0;j<0x68;j+=4)
{
if (DCdata != NULL) {
if (size == 0xB60) {
for (i = 0; i < 28; i++) {
for (j = 0, scantotal = 0; j < 0x68; j += 4) {
scantotal += DCdata[((i * 0x68) + j) >> 2];
}
if (scantotal)
scanmap[i] = longdotcodescan[i];
}
for(i=0;i<size;i+=4)
{
for (i = 0; i < size; i += 4) {
CPUWriteMemory(temp1 + i + 0x9C0, DCdata[i >> 2]);
}
}
else if (size==0x750)
{
for(i=0;i<18;i++)
{
} else if (size == 0x750) {
for (i = 0; i < 18; i++) {
if ((DCdata[0] == 0x02011394) && (DCdata[1] == 0x0203E110) && (i == 0))
continue;
for(j=0,scantotal=0;j<0x68;j+=4)
{
for (j = 0, scantotal = 0; j < 0x68; j += 4) {
scantotal += DCdata[((i * 0x68) + j) >> 2];
}
if (scantotal)
scanmap[i] = longdotcodescan[i];
}
for(i=0;i<size;i+=4)
{
for (i = 0; i < size; i += 4) {
CPUWriteMemory(temp1 + i, DCdata[i >> 2]);
}
}
@ -178,16 +166,11 @@ int LoadDotCodeData(int size, u32* DCdata, unsigned long MEM1, unsigned long MEM
CPUWriteMemory(MEM2 - 8, 0x1860);
CPUWriteMemory(MEM2 - 4, temp1);
if(size==0xB60)
{
if(loadraw)
{
if (size == 0xB60) {
if (loadraw) {
for (i = 0; i < 28; i++)
CPUWriteByte(MEM2 + 0x18 + i, scanmap[i]);
}
else
{
} else {
CPUWriteMemory(MEM2 + 0x18, 0xF1F1F1F1);
CPUWriteMemory(MEM2 + 0x18 + 4, 0xF1F1F1F1);
CPUWriteMemory(MEM2 + 0x18 + 8, 0xF1F1F1F1);
@ -198,16 +181,11 @@ int LoadDotCodeData(int size, u32* DCdata, unsigned long MEM1, unsigned long MEM
}
CPUWriteMemory(MEM2 + 0x40, 0x19);
CPUWriteMemory(MEM2 + 0x44, 0x34);
}
else if (size==0x750)
{
if(loadraw)
{
} else if (size == 0x750) {
if (loadraw) {
for (i = 0; i < 18; i++)
CPUWriteByte(MEM2 + i, scanmap[i]);
}
else
{
} else {
CPUWriteMemory(MEM2, 0xF1F1F1F1);
CPUWriteMemory(MEM2 + 4, 0xF1F1F1F1);
CPUWriteMemory(MEM2 + 8, 0xF1F1F1F1);
@ -225,8 +203,7 @@ int LoadDotCodeData(int size, u32* DCdata, unsigned long MEM1, unsigned long MEM
void EReaderWriteMemory(u32 address, u32 value)
{
switch(address >> 24)
{
switch (address >> 24) {
case 2:
WRITE32LE(((u32*)&workRAM[address & 0x3FFFF]), value);
break;
@ -240,7 +217,6 @@ void EReaderWriteMemory(u32 address, u32 value)
}
}
void BIOS_EReader_ScanCard(int swi_num)
{
@ -253,58 +229,47 @@ void BIOS_EReader_ScanCard(int swi_num)
//Open dotcode bin/raw
if(swi_num == 0xE0)
{
if (swi_num == 0xE0) {
dotcodepointer = 0;
dotcodeinterleave = 0;
decodestate = 0;
const char* loadDotCodeFile = GetLoadDotCodeFile();
if (loadDotCodeFile == 0)
{
if (loadDotCodeFile == 0) {
reg[0].I = 0x301;
return;
}
f = fopen(loadDotCodeFile, "rb");
//f=fopen(filebuffer,"rb");
//f=fopen("dotcode4.raw","rb");
if(f==NULL)
{
if (f == NULL) {
reg[0].I = 0x303;
return;
}
fseek(f, 0, SEEK_END);
i = ftell(f);
fseek(f, 0, SEEK_SET);
if((i==0xB60) || (i==0x750))
{
if ((i == 0xB60) || (i == 0x750)) {
dotcodetype = 0;
}
else if ((i==0x81C) || (i==0x51C))
{
} else if ((i == 0x81C) || (i == 0x51C)) {
dotcodetype = 1;
}
else
{
} else {
fclose(f);
reg[0].I = 0x303;
return;
}
DotCodeData = (unsigned char*)malloc(i);
if(DotCodeData == NULL)
{
if (DotCodeData == NULL) {
reg[0].I = 0x303;
return;
}
fread(DotCodeData, 1, i, f);
fclose(f);
if(dotcodetype == 0)
{
if (dotcodetype == 0) {
switch(CheckEReaderRegion())
{
switch (CheckEReaderRegion()) {
case 1: //US
LoadDotCodeData(i, (u32*)DotCodeData, 0x2032D14, 0x2028B28, 1);
EReaderWriteMemory(0x80091BA, 0x46C0DFE2);
@ -320,18 +285,14 @@ void BIOS_EReader_ScanCard(int swi_num)
}
reg[0].I = 0;
free(DotCodeData);
}
else
{
} else {
//dotcodesize = i;
if (i == 0x81C)
dotcodesize = 0xB60;
else
dotcodesize = 0x750;
switch(CheckEReaderRegion())
{
switch (CheckEReaderRegion()) {
case 1: //US
LoadDotCodeData(dotcodesize, (u32*)NULL, 0x2032D14, 0x2028B28, 0);
EReaderWriteMemory(0x80091BA, 0x46C0DFE1);
@ -348,12 +309,9 @@ void BIOS_EReader_ScanCard(int swi_num)
reg[0].I = 0;
dotcodesize = i;
}
}
else if (swi_num == 0xE1)
{
} else if (swi_num == 0xE1) {
switch(CheckEReaderRegion())
{
switch (CheckEReaderRegion()) {
case 1: //US
EReaderWriteMemory(0x80091BA, 0xF8A5F03B);
EReaderWriteMemory(0x3002F7C, 0xEFE40000); //Beginning of Reed-Solomon decoder
@ -386,8 +344,7 @@ void BIOS_EReader_ScanCard(int swi_num)
for (i = 0, j = 0; i < 12; i++)
j ^= DotCodeData[i];
if(dotcodesize == 0x81C)
{
if (dotcodesize == 0x81C) {
LongDotCodeHeader[0x2E] = j;
LongDotCodeHeader[0x0D] = DotCodeData[0];
LongDotCodeHeader[0x0C] = DotCodeData[1];
@ -403,12 +360,10 @@ void BIOS_EReader_ScanCard(int swi_num)
LongDotCodeHeader[0x2C] = DotCodeData[10];
LongDotCodeHeader[0x2D] = DotCodeData[11];
LongDotCodeHeader[0x12] = 0x10; //calculate Global Checksum 1
LongDotCodeHeader[0x02] = 1; //Do not calculate Global Checksum 2
for(i=0x0C,j=0;i<0x81C;i++)
{
for (i = 0x0C, j = 0; i < 0x81C; i++) {
if (i & 1)
j += DotCodeData[i];
else
@ -422,10 +377,8 @@ void BIOS_EReader_ScanCard(int swi_num)
for (i = 0, j = 0; i < 0x2F; i++)
j += LongDotCodeHeader[i];
j &= 0xFF;
for(i=1,global2=0;i<0x2C;i++)
{
for(k=0,global1=0;k<0x30;k++)
{
for (i = 1, global2 = 0; i < 0x2C; i++) {
for (k = 0, global1 = 0; k < 0x30; k++) {
global1 ^= DotCodeData[((i - 1) * 0x30) + k + 0x0C];
}
global2 += global1;
@ -435,10 +388,7 @@ void BIOS_EReader_ScanCard(int swi_num)
global2 ^= 0xFF;
LongDotCodeHeader[0x2F] = global2;
}
else
{
} else {
ShortDotCodeHeader[0x2E] = j;
ShortDotCodeHeader[0x0D] = DotCodeData[0];
ShortDotCodeHeader[0x0C] = DotCodeData[1];
@ -457,8 +407,7 @@ void BIOS_EReader_ScanCard(int swi_num)
ShortDotCodeHeader[0x12] = 0x10; //calculate Global Checksum 1
ShortDotCodeHeader[0x02] = 1; //Do not calculate Global Checksum 2
for(i=0x0C,j=0;i<0x51C;i++)
{
for (i = 0x0C, j = 0; i < 0x51C; i++) {
if (i & 1)
j += DotCodeData[i];
else
@ -472,10 +421,8 @@ void BIOS_EReader_ScanCard(int swi_num)
for (i = 0, j = 0; i < 0x2F; i++)
j += ShortDotCodeHeader[i];
j &= 0xFF;
for(i=1,global2=0;i<0x1C;i++)
{
for(k=0,global1=0;k<0x30;k++)
{
for (i = 1, global2 = 0; i < 0x1C; i++) {
for (k = 0, global1 = 0; k < 0x30; k++) {
global1 ^= DotCodeData[((i - 1) * 0x30) + k + 0x0C];
}
global2 += global1;
@ -486,11 +433,9 @@ void BIOS_EReader_ScanCard(int swi_num)
ShortDotCodeHeader[0x2F] = global2;
}
}
else if (swi_num == 0xE2) //Header
{
switch(CheckEReaderRegion())
} else if (swi_num == 0xE2) //Header
{
switch (CheckEReaderRegion()) {
case 1: //US
EReaderWriteMemory(0x80091BA, 0xF8A5F03B);
EReaderWriteMemory(0x300338C, 0xEFE30000);
@ -513,15 +458,11 @@ void BIOS_EReader_ScanCard(int swi_num)
ARM_PREFETCH
else
THUMB_PREFETCH
}
else if ((swi_num == 0xE3) || (swi_num == 0xE5)) //Dotcode data
{
if((reg[0].I >= 0) && (reg[0].I <= 0x10))
{
if(decodestate == 0)
{
for(i=0x17;i>=0;i--)
} else if ((swi_num == 0xE3) || (swi_num == 0xE5)) //Dotcode data
{
if ((reg[0].I >= 0) && (reg[0].I <= 0x10)) {
if (decodestate == 0) {
for (i = 0x17; i >= 0; i--) {
if ((0x17 - i) < 8)
j = CPUReadByte(GFpow + CPUReadByte(GFpow + 0x200 + i));
else
@ -536,11 +477,8 @@ void BIOS_EReader_ScanCard(int swi_num)
dotcodedata[(i * 0x68) + j] = dotcodeheader[(i * 2) + j];
dotcodeinterleave = dotcodeheader[7];
decodestate = 1;
}
else
{
for(i=0x3F;i>=0;i--)
{
} else {
for (i = 0x3F; i >= 0; i--) {
if ((0x3F - i) < 0x30)
j = CPUReadByte(GFpow + CPUReadByte(GFpow + 0x200 + i));
else
@ -549,10 +487,8 @@ void BIOS_EReader_ScanCard(int swi_num)
}
dotcodepointer++;
if((dotcodepointer == dotcodeinterleave))
{
switch(dotcodeinterleave)
{
if ((dotcodepointer == dotcodeinterleave)) {
switch (dotcodeinterleave) {
case 0x1C:
j = 0x724;
k = 0x750 - j;
@ -563,34 +499,26 @@ void BIOS_EReader_ScanCard(int swi_num)
break;
}
dotcodepointer = 0;
for(i=2;i<j;i++)
{
for (i = 2; i < j; i++) {
if ((i % 0x68) == 0)
i += 2;
dotcodedata[i] = dotcodetemp[dotcodepointer++];
}
if(swi_num == 0xE3)
{
if (swi_num == 0xE3) {
const char* loadDotCodeFile = GetLoadDotCodeFile();
f = fopen(loadDotCodeFile, "rb+");
if(f!=NULL)
{
if (f != NULL) {
fwrite(dotcodedata, 1, j, f);
fclose(f);
}
}
else
{
} else {
const char* saveDotCodeFile = GetSaveDotCodeFile();
if (saveDotCodeFile)
{
if (saveDotCodeFile) {
f = fopen(saveDotCodeFile, "wb");
if(f!=NULL)
{
if (f != NULL) {
fwrite(dotcodedata, 1, j, f);
fwrite(Signature, 1, 0x28, f);
if(j==0x724)
{
if (j == 0x724) {
fputc(0x65, f);
fputc(0x02, f);
fputc(0x71, f);
@ -618,14 +546,10 @@ void BIOS_EReader_ScanCard(int swi_num)
reg[15].I += 2;
THUMB_PREFETCH
}
}
else if (swi_num == 0xE4)
{
} else if (swi_num == 0xE4) {
reg[12].I = reg[13].I;
if(decodestate == 0)
{
for(i=0;i<0x18;i++)
{
if (decodestate == 0) {
for (i = 0; i < 0x18; i++) {
if (dotcodesize == 0x81C)
j = longheader[i];
else
@ -638,13 +562,9 @@ void BIOS_EReader_ScanCard(int swi_num)
CPUWriteByte(GFpow + 0x200 + (0x17 - i), j);
}
}
else
{
if(dotcodepointer == 0)
{
for(i=0;i<0x30;i++)
{
} else {
if (dotcodepointer == 0) {
for (i = 0; i < 0x30; i++) {
if (dotcodesize == 0x81C)
j = LongDotCodeHeader[i];
else
@ -654,11 +574,8 @@ void BIOS_EReader_ScanCard(int swi_num)
CPUWriteByte(GFpow + 0x200 + (0x3F - i), j);
}
}
else
{
for(i=0;i<0x30;i++)
{
} else {
for (i = 0; i < 0x30; i++) {
j = DotCodeData[((dotcodepointer - 1) * 0x30) + 0x0C + i];
j = CPUReadByte(GFpow + 0x100 + j);
@ -669,6 +586,4 @@ void BIOS_EReader_ScanCard(int swi_num)
CPUWriteByte(GFpow + 0x258 + i, 1); //16 Erasures on the parity bytes, to have them calculated.
}
}
}

View File

@ -33,8 +33,7 @@ void gbafilter_pal(u16 * buf, int count)
unsigned pix;
u8 red, green, blue;
while (count--)
{
while (count--) {
pix = *buf;
s = curve[(pix >> systemGreenShift) & 0x1f];
@ -52,35 +51,47 @@ void gbafilter_pal(u16 * buf, int count)
temp[7] = s * influence[7];
temp[8] = s * influence[8];
if (temp[0] < temp[3]) swap(temp[0], temp[3]);
if (temp[0] < temp[6]) swap(temp[0], temp[6]);
if (temp[3] < temp[6]) swap(temp[3], temp[6]);
if (temp[0] < temp[3])
swap(temp[0], temp[3]);
if (temp[0] < temp[6])
swap(temp[0], temp[6]);
if (temp[3] < temp[6])
swap(temp[3], temp[6]);
temp[3] <<= 1;
temp[0] <<= 2;
temp[0] += temp[3] + temp[6];
red = ((int(temp[0]) * 160) >> 17) + 4;
if (red > 31) red = 31;
if (red > 31)
red = 31;
if (temp[2] < temp[5]) swap(temp[2], temp[5]);
if (temp[2] < temp[8]) swap(temp[2], temp[8]);
if (temp[5] < temp[8]) swap(temp[5], temp[8]);
if (temp[2] < temp[5])
swap(temp[2], temp[5]);
if (temp[2] < temp[8])
swap(temp[2], temp[8]);
if (temp[5] < temp[8])
swap(temp[5], temp[8]);
temp[5] <<= 1;
temp[2] <<= 2;
temp[2] += temp[5] + temp[8];
blue = ((int(temp[2]) * 160) >> 17) + 4;
if (blue > 31) blue = 31;
if (blue > 31)
blue = 31;
if (temp[1] < temp[4]) swap(temp[1], temp[4]);
if (temp[1] < temp[7]) swap(temp[1], temp[7]);
if (temp[4] < temp[7]) swap(temp[4], temp[7]);
if (temp[1] < temp[4])
swap(temp[1], temp[4]);
if (temp[1] < temp[7])
swap(temp[1], temp[7]);
if (temp[4] < temp[7])
swap(temp[4], temp[7]);
temp[4] <<= 1;
temp[1] <<= 2;
temp[1] += temp[4] + temp[7];
green = ((int(temp[1]) * 160) >> 17) + 4;
if (green > 31) green = 31;
if (green > 31)
green = 31;
pix = red << systemRedShift;
pix += green << systemGreenShift;
@ -96,8 +107,7 @@ void gbafilter_pal32(u32 * buf, int count)
unsigned pix;
u8 red, green, blue;
while (count--)
{
while (count--) {
pix = *buf;
s = curve[(pix >> systemGreenShift) & 0x1f];
@ -115,9 +125,12 @@ void gbafilter_pal32(u32 * buf, int count)
temp[7] = s * influence[7];
temp[8] = s * influence[8];
if (temp[0] < temp[3]) swap(temp[0], temp[3]);
if (temp[0] < temp[6]) swap(temp[0], temp[6]);
if (temp[3] < temp[6]) swap(temp[3], temp[6]);
if (temp[0] < temp[3])
swap(temp[0], temp[3]);
if (temp[0] < temp[6])
swap(temp[0], temp[6]);
if (temp[3] < temp[6])
swap(temp[3], temp[6]);
temp[3] <<= 1;
temp[0] <<= 2;
temp[0] += temp[3] + temp[6];
@ -125,9 +138,12 @@ void gbafilter_pal32(u32 * buf, int count)
//red = ((int(temp[0]) * 160) >> 17) + 4;
red = ((int(temp[0]) * 160) >> 14) + 32;
if (temp[2] < temp[5]) swap(temp[2], temp[5]);
if (temp[2] < temp[8]) swap(temp[2], temp[8]);
if (temp[5] < temp[8]) swap(temp[5], temp[8]);
if (temp[2] < temp[5])
swap(temp[2], temp[5]);
if (temp[2] < temp[8])
swap(temp[2], temp[8]);
if (temp[5] < temp[8])
swap(temp[5], temp[8]);
temp[5] <<= 1;
temp[2] <<= 2;
temp[2] += temp[5] + temp[8];
@ -135,9 +151,12 @@ void gbafilter_pal32(u32 * buf, int count)
//blue = ((int(temp[2]) * 160) >> 17) + 4;
blue = ((int(temp[2]) * 160) >> 14) + 32;
if (temp[1] < temp[4]) swap(temp[1], temp[4]);
if (temp[1] < temp[7]) swap(temp[1], temp[7]);
if (temp[4] < temp[7]) swap(temp[4], temp[7]);
if (temp[1] < temp[4])
swap(temp[1], temp[4]);
if (temp[1] < temp[7])
swap(temp[1], temp[7]);
if (temp[4] < temp[7])
swap(temp[4], temp[7]);
temp[4] <<= 1;
temp[1] <<= 2;
temp[1] += temp[4] + temp[7];
@ -161,8 +180,7 @@ void gbafilter_pal32(u32 * buf, int count)
void gbafilter_pad(u8* buf, int count)
{
union
{
union {
struct
{
u8 r;
@ -171,26 +189,22 @@ void gbafilter_pad(u8 * buf, int count)
u8 a;
} part;
unsigned whole;
}
mask;
} mask;
mask.whole = 0x1f << systemRedShift;
mask.whole += 0x1f << systemGreenShift;
mask.whole += 0x1f << systemBlueShift;
switch (systemColorDepth)
{
switch (systemColorDepth) {
case 24:
while (count--)
{
while (count--) {
*buf++ &= mask.part.r;
*buf++ &= mask.part.g;
*buf++ &= mask.part.b;
}
break;
case 32:
while (count--)
{
while (count--) {
*((u32*)buf) &= mask.whole;
buf += 4;
}

File diff suppressed because it is too large Load Diff