some more formating things etc
This commit is contained in:
parent
a49edee427
commit
48086ba62f
997
src/gb/GB.cpp
997
src/gb/GB.cpp
File diff suppressed because it is too large
Load Diff
|
@ -1,16 +1,16 @@
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../System.h"
|
||||
#include "../NLS.h"
|
||||
#include "../System.h"
|
||||
#include "../Util.h"
|
||||
|
||||
#include "../common/ConfigManager.h"
|
||||
#include "gb.h"
|
||||
#include "gbCheats.h"
|
||||
#include "gbGlobals.h"
|
||||
#include "gb.h"
|
||||
#include "../common/ConfigManager.h"
|
||||
|
||||
gbCheat gbCheatList[MAX_CHEATS];
|
||||
int gbCheatNumber = 0;
|
||||
|
@ -72,7 +72,6 @@ void gbCheatsReadGame(gzFile gzFile, int version)
|
|||
gbCheatUpdateMap();
|
||||
}
|
||||
|
||||
|
||||
void gbCheatsReadGameSkip(gzFile gzFile, int version)
|
||||
{
|
||||
if (version <= 8) {
|
||||
|
@ -100,7 +99,6 @@ void gbCheatsReadGameSkip(gzFile gzFile, int version)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void gbCheatsSaveCheatList(const char* file)
|
||||
{
|
||||
if (gbCheatNumber == 0)
|
||||
|
@ -214,16 +212,11 @@ bool gbAddGsCheat(const char *code, const char *desc)
|
|||
strcpy(gbCheatList[i].cheatCode, code);
|
||||
strcpy(gbCheatList[i].cheatDesc, desc);
|
||||
|
||||
gbCheatList[i].code = GBCHEAT_HEX_VALUE(code[0]) << 4 |
|
||||
GBCHEAT_HEX_VALUE(code[1]);
|
||||
gbCheatList[i].code = GBCHEAT_HEX_VALUE(code[0]) << 4 | GBCHEAT_HEX_VALUE(code[1]);
|
||||
|
||||
gbCheatList[i].value = GBCHEAT_HEX_VALUE(code[2]) << 4 |
|
||||
GBCHEAT_HEX_VALUE(code[3]);
|
||||
gbCheatList[i].value = GBCHEAT_HEX_VALUE(code[2]) << 4 | GBCHEAT_HEX_VALUE(code[3]);
|
||||
|
||||
gbCheatList[i].address = GBCHEAT_HEX_VALUE(code[6]) << 12 |
|
||||
GBCHEAT_HEX_VALUE(code[7]) << 8 |
|
||||
GBCHEAT_HEX_VALUE(code[4]) << 4 |
|
||||
GBCHEAT_HEX_VALUE(code[5]);
|
||||
gbCheatList[i].address = GBCHEAT_HEX_VALUE(code[6]) << 12 | GBCHEAT_HEX_VALUE(code[7]) << 8 | GBCHEAT_HEX_VALUE(code[4]) << 4 | GBCHEAT_HEX_VALUE(code[5]);
|
||||
|
||||
gbCheatList[i].compare = 0;
|
||||
|
||||
|
@ -231,8 +224,7 @@ bool gbAddGsCheat(const char *code, const char *desc)
|
|||
|
||||
int gsCode = gbCheatList[i].code;
|
||||
|
||||
if ((gsCode !=1) && ((gsCode & 0xF0) !=0x80) && ((gsCode & 0xF0) !=0x90) &&
|
||||
((gsCode & 0xF0) !=0xA0) && ((gsCode) !=0xF0) && ((gsCode) !=0xF1))
|
||||
if ((gsCode != 1) && ((gsCode & 0xF0) != 0x80) && ((gsCode & 0xF0) != 0x90) && ((gsCode & 0xF0) != 0xA0) && ((gsCode) != 0xF0) && ((gsCode) != 0xF1))
|
||||
systemMessage(MSG_WRONG_GAMESHARK_CODE,
|
||||
N_("Wrong GameShark code type : %s"), code);
|
||||
else if (((gsCode & 0xF0) == 0xA0) || ((gsCode) == 0xF0) || ((gsCode) == 0xF1))
|
||||
|
@ -248,10 +240,7 @@ bool gbVerifyGgCode(const char *code)
|
|||
{
|
||||
size_t len = strlen(code);
|
||||
|
||||
if(len != 11 &&
|
||||
len != 7 &&
|
||||
len != 6 &&
|
||||
len != 0)
|
||||
if (len != 11 && len != 7 && len != 6 && len != 0)
|
||||
return false;
|
||||
|
||||
if (len == 0)
|
||||
|
@ -287,10 +276,7 @@ bool gbVerifyGgCode(const char *code)
|
|||
// int replace = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
|
||||
// GBCHEAT_HEX_VALUE(code[1]);
|
||||
|
||||
int address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
|
||||
(GBCHEAT_HEX_VALUE(code[4]) << 4) +
|
||||
(GBCHEAT_HEX_VALUE(code[5])) +
|
||||
((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
|
||||
int address = (GBCHEAT_HEX_VALUE(code[2]) << 8) + (GBCHEAT_HEX_VALUE(code[4]) << 4) + (GBCHEAT_HEX_VALUE(code[5])) + ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
|
||||
|
||||
if (address >= 0x8000 && address <= 0x9fff)
|
||||
return false;
|
||||
|
@ -301,8 +287,7 @@ bool gbVerifyGgCode(const char *code)
|
|||
if (code[7] == 0 || code[8] == '0')
|
||||
return true;
|
||||
|
||||
int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
|
||||
(GBCHEAT_HEX_VALUE(code[10]));
|
||||
int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) + (GBCHEAT_HEX_VALUE(code[10]));
|
||||
compare = compare ^ 0xff;
|
||||
compare = (compare >> 2) | ((compare << 6) & 0xc0);
|
||||
compare ^= 0x45;
|
||||
|
@ -337,20 +322,15 @@ bool gbAddGgCheat(const char *code, const char *desc)
|
|||
strcpy(gbCheatList[i].cheatDesc, desc);
|
||||
|
||||
gbCheatList[i].code = 0x101;
|
||||
gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) +
|
||||
GBCHEAT_HEX_VALUE(code[1]);
|
||||
gbCheatList[i].value = (GBCHEAT_HEX_VALUE(code[0]) << 4) + GBCHEAT_HEX_VALUE(code[1]);
|
||||
|
||||
gbCheatList[i].address = (GBCHEAT_HEX_VALUE(code[2]) << 8) +
|
||||
(GBCHEAT_HEX_VALUE(code[4]) << 4) +
|
||||
(GBCHEAT_HEX_VALUE(code[5])) +
|
||||
((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
|
||||
gbCheatList[i].address = (GBCHEAT_HEX_VALUE(code[2]) << 8) + (GBCHEAT_HEX_VALUE(code[4]) << 4) + (GBCHEAT_HEX_VALUE(code[5])) + ((GBCHEAT_HEX_VALUE(code[6]) ^ 0x0f) << 12);
|
||||
|
||||
gbCheatList[i].compare = 0;
|
||||
|
||||
if (len != 7 && len != 8) {
|
||||
|
||||
int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) +
|
||||
(GBCHEAT_HEX_VALUE(code[10]));
|
||||
int compare = (GBCHEAT_HEX_VALUE(code[8]) << 4) + (GBCHEAT_HEX_VALUE(code[10]));
|
||||
compare = compare ^ 0xff;
|
||||
compare = (compare >> 2) | ((compare << 6) & 0xc0);
|
||||
compare ^= 0x45;
|
||||
|
@ -358,10 +338,8 @@ bool gbAddGgCheat(const char *code, const char *desc)
|
|||
gbCheatList[i].compare = compare;
|
||||
//gbCheatList[i].code = 0;
|
||||
gbCheatList[i].code = 0x100; // fix for compare value
|
||||
|
||||
}
|
||||
|
||||
|
||||
gbCheatList[i].enabled = true;
|
||||
|
||||
gbCheatMap[gbCheatList[i].address] = true;
|
||||
|
@ -380,8 +358,7 @@ void gbCheatRemove(int i)
|
|||
}
|
||||
|
||||
if ((i + 1) < gbCheatNumber) {
|
||||
memcpy(&gbCheatList[i], &gbCheatList[i+1], sizeof(gbCheat)*
|
||||
(gbCheatNumber-i-1));
|
||||
memcpy(&gbCheatList[i], &gbCheatList[i + 1], sizeof(gbCheat) * (gbCheatNumber - i - 1));
|
||||
}
|
||||
|
||||
gbCheatNumber--;
|
||||
|
@ -449,7 +426,7 @@ bool gbCheatReadGSCodeFile(const char *fileName)
|
|||
}
|
||||
|
||||
// Used to emulated GG codes
|
||||
u8 gbCheatRead(u16 address)
|
||||
uint8_t gbCheatRead(uint16_t address)
|
||||
{
|
||||
if (!cheatsEnabled)
|
||||
return gbMemoryMap[address >> 12][address & 0xFFF];
|
||||
|
@ -470,12 +447,10 @@ u8 gbCheatRead(u16 address)
|
|||
return gbMemoryMap[address >> 12][address & 0xFFF];
|
||||
}
|
||||
|
||||
|
||||
// Used to emulate GS codes.
|
||||
void gbCheatWrite(bool reboot)
|
||||
{
|
||||
if(cheatsEnabled)
|
||||
{
|
||||
if (cheatsEnabled) {
|
||||
u16 address = 0;
|
||||
|
||||
if (gbNextCheat >= gbCheatNumber)
|
||||
|
@ -484,8 +459,7 @@ void gbCheatWrite(bool reboot)
|
|||
for (int i = gbNextCheat; i < gbCheatNumber; i++) {
|
||||
if (gbCheatList[i].enabled) {
|
||||
address = gbCheatList[i].address;
|
||||
if ((!reboot) && (address >= 0x8000) && !((address>=0xA000) && (address<0xC000)))
|
||||
{ // These codes are executed one per one, at each Vblank
|
||||
if ((!reboot) && (address >= 0x8000) && !((address >= 0xA000) && (address < 0xC000))) { // These codes are executed one per one, at each Vblank
|
||||
switch (gbCheatList[i].code) {
|
||||
case 0x01:
|
||||
gbWriteMemory(address, gbCheatList[i].value);
|
||||
|
@ -514,8 +488,7 @@ void gbCheatWrite(bool reboot)
|
|||
gbNextCheat = i + 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else // These codes are only executed when the game is booted
|
||||
} else // These codes are only executed when the game is booted
|
||||
{
|
||||
switch (gbCheatList[i].code & 0xF0) {
|
||||
case 0x80:
|
||||
|
|
|
@ -12,10 +12,10 @@ struct gbXxCheat {
|
|||
struct gbCheat {
|
||||
char cheatCode[20];
|
||||
char cheatDesc[32];
|
||||
u16 address;
|
||||
uint16_t address;
|
||||
int code;
|
||||
u8 compare;
|
||||
u8 value;
|
||||
uint8_t compare;
|
||||
uint8_t value;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ void gbCheatRemove(int);
|
|||
void gbCheatRemoveAll();
|
||||
void gbCheatEnable(int);
|
||||
void gbCheatDisable(int);
|
||||
u8 gbCheatRead(u16);
|
||||
uint8_t gbCheatRead(u16);
|
||||
void gbCheatWrite(bool);
|
||||
bool gbVerifyGsCode(const char* code);
|
||||
bool gbVerifyGgCode(const char* code);
|
||||
|
|
171
src/gb/gbCodes.h
171
src/gb/gbCodes.h
|
@ -22,8 +22,7 @@ break;
|
|||
case 0x05:
|
||||
// DEC B
|
||||
BC.B.B1--;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[BC.B.B1] | ((BC.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[BC.B.B1] | ((BC.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
break;
|
||||
case 0x06:
|
||||
// LD B, NN
|
||||
|
@ -45,8 +44,7 @@ break;
|
|||
case 0x09:
|
||||
// ADD HL,BC
|
||||
tempRegister.W = (HL.W + BC.W) & 0xFFFF;
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ BC.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) |
|
||||
(((long)HL.W + (long)BC.W) & 0x10000 ? C_FLAG : 0);
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ BC.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) | (((long)HL.W + (long)BC.W) & 0x10000 ? C_FLAG : 0);
|
||||
HL.W = tempRegister.W;
|
||||
break;
|
||||
case 0x0a:
|
||||
|
@ -65,8 +63,7 @@ break;
|
|||
case 0x0d:
|
||||
// DEC C
|
||||
BC.B.B0--;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[BC.B.B0] | ((BC.B.B0 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[BC.B.B0] | ((BC.B.B0 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
break;
|
||||
case 0x0e:
|
||||
// LD C, NN
|
||||
|
@ -114,8 +111,7 @@ break;
|
|||
case 0x15:
|
||||
// DEC D
|
||||
DE.B.B1--;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[DE.B.B1] | ((DE.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[DE.B.B1] | ((DE.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
break;
|
||||
case 0x16:
|
||||
// LD D,NN
|
||||
|
@ -134,8 +130,7 @@ break;
|
|||
case 0x19:
|
||||
// ADD HL,DE
|
||||
tempRegister.W = (HL.W + DE.W) & 0xFFFF;
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ DE.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) |
|
||||
(((long)HL.W + (long)DE.W) & 0x10000 ? C_FLAG : 0);
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ DE.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) | (((long)HL.W + (long)DE.W) & 0x10000 ? C_FLAG : 0);
|
||||
HL.W = tempRegister.W;
|
||||
break;
|
||||
case 0x1a:
|
||||
|
@ -154,8 +149,7 @@ break;
|
|||
case 0x1d:
|
||||
// DEC E
|
||||
DE.B.B0--;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[DE.B.B0] | ((DE.B.B0 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[DE.B.B0] | ((DE.B.B0 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
break;
|
||||
case 0x1e:
|
||||
// LD E,NN
|
||||
|
@ -197,8 +191,7 @@ break;
|
|||
case 0x25:
|
||||
// DEC H
|
||||
HL.B.B1--;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[HL.B.B1] | ((HL.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[HL.B.B1] | ((HL.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
break;
|
||||
case 0x26:
|
||||
// LD H,NN
|
||||
|
@ -221,8 +214,7 @@ break;
|
|||
case 0x29:
|
||||
// ADD HL,HL
|
||||
tempRegister.W = (HL.W + HL.W) & 0xFFFF;
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ HL.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) |
|
||||
(((long)HL.W + (long)HL.W) & 0x10000 ? C_FLAG : 0);
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ HL.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) | (((long)HL.W + (long)HL.W) & 0x10000 ? C_FLAG : 0);
|
||||
HL.W = tempRegister.W;
|
||||
break;
|
||||
case 0x2a:
|
||||
|
@ -241,8 +233,7 @@ break;
|
|||
case 0x2d:
|
||||
// DEC L
|
||||
HL.B.B0--;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[HL.B.B0] | ((HL.B.B0 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[HL.B.B0] | ((HL.B.B0 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
break;
|
||||
case 0x2e:
|
||||
// LD L,NN
|
||||
|
@ -284,8 +275,7 @@ break;
|
|||
case 0x35:
|
||||
// DEC (HL)
|
||||
tempValue = gbReadMemory(HL.W) - 1;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[tempValue] | ((tempValue & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[tempValue] | ((tempValue & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
gbWriteMemory(HL.W, tempValue);
|
||||
break;
|
||||
case 0x36:
|
||||
|
@ -307,8 +297,7 @@ break;
|
|||
case 0x39:
|
||||
// ADD HL,SP
|
||||
tempRegister.W = (HL.W + SP.W) & 0xFFFF;
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ SP.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) |
|
||||
(((long)HL.W + (long)SP.W) & 0x10000 ? C_FLAG : 0);
|
||||
AF.B.B0 = (AF.B.B0 & Z_FLAG) | ((HL.W ^ SP.W ^ tempRegister.W) & 0x1000 ? H_FLAG : 0) | (((long)HL.W + (long)SP.W) & 0x10000 ? C_FLAG : 0);
|
||||
HL.W = tempRegister.W;
|
||||
break;
|
||||
case 0x3a:
|
||||
|
@ -327,8 +316,7 @@ break;
|
|||
case 0x3d:
|
||||
// DEC A
|
||||
AF.B.B1--;
|
||||
AF.B.B0 =
|
||||
N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[AF.B.B1] | ((AF.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (AF.B.B0 & C_FLAG) | ZeroTable[AF.B.B1] | ((AF.B.B1 & 0x0F) == 0x0F ? H_FLAG : 0);
|
||||
break;
|
||||
case 0x3e:
|
||||
// LD A,NN
|
||||
|
@ -611,165 +599,142 @@ break;
|
|||
case 0x80:
|
||||
// ADD B
|
||||
tempRegister.W = AF.B.B1 + BC.B.B1;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x81:
|
||||
// ADD C
|
||||
tempRegister.W = AF.B.B1 + BC.B.B0;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x82:
|
||||
// ADD D
|
||||
tempRegister.W = AF.B.B1 + DE.B.B1;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x83:
|
||||
// ADD E
|
||||
tempRegister.W = AF.B.B1 + DE.B.B0;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x84:
|
||||
// ADD H
|
||||
tempRegister.W = AF.B.B1 + HL.B.B1;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x85:
|
||||
// ADD L
|
||||
tempRegister.W = AF.B.B1 + HL.B.B0;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x86:
|
||||
// ADD (HL)
|
||||
tempValue = gbReadMemory(HL.W);
|
||||
tempRegister.W = AF.B.B1 + tempValue;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x87:
|
||||
// ADD A
|
||||
tempRegister.W = AF.B.B1 + AF.B.B1;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ AF.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ AF.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x88:
|
||||
// ADC B:
|
||||
tempRegister.W = AF.B.B1 + BC.B.B1 + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x89:
|
||||
// ADC C
|
||||
tempRegister.W = AF.B.B1 + BC.B.B0 + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x8a:
|
||||
// ADC D
|
||||
tempRegister.W = AF.B.B1 + DE.B.B1 + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x8b:
|
||||
// ADC E
|
||||
tempRegister.W = AF.B.B1 + DE.B.B0 + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x8c:
|
||||
// ADC H
|
||||
tempRegister.W = AF.B.B1 + HL.B.B1 + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x8d:
|
||||
// ADC L
|
||||
tempRegister.W = AF.B.B1 + HL.B.B0 + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x8e:
|
||||
// ADC (HL)
|
||||
tempValue = gbReadMemory(HL.W);
|
||||
tempRegister.W = AF.B.B1 + tempValue + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x8f:
|
||||
// ADC A
|
||||
tempRegister.W = AF.B.B1 + AF.B.B1 + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ AF.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ AF.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x90:
|
||||
// SUB B
|
||||
tempRegister.W = AF.B.B1 - BC.B.B1;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x91:
|
||||
// SUB C
|
||||
tempRegister.W = AF.B.B1 - BC.B.B0;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x92:
|
||||
// SUB D
|
||||
tempRegister.W = AF.B.B1 - DE.B.B1;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x93:
|
||||
// SUB E
|
||||
tempRegister.W = AF.B.B1 - DE.B.B0;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x94:
|
||||
// SUB H
|
||||
tempRegister.W = AF.B.B1 - HL.B.B1;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x95:
|
||||
// SUB L
|
||||
tempRegister.W = AF.B.B1 - HL.B.B0;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x96:
|
||||
// SUB (HL)
|
||||
tempValue = gbReadMemory(HL.W);
|
||||
tempRegister.W = AF.B.B1 - tempValue;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x97:
|
||||
|
@ -780,58 +745,50 @@ break;
|
|||
case 0x98:
|
||||
// SBC B
|
||||
tempRegister.W = AF.B.B1 - BC.B.B1 - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x99:
|
||||
// SBC C
|
||||
tempRegister.W = AF.B.B1 - BC.B.B0 - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x9a:
|
||||
// SBC D
|
||||
tempRegister.W = AF.B.B1 - DE.B.B1 - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x9b:
|
||||
// SBC E
|
||||
tempRegister.W = AF.B.B1 - DE.B.B0 - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x9c:
|
||||
// SBC H
|
||||
tempRegister.W = AF.B.B1 - HL.B.B1 - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x9d:
|
||||
// SBC L
|
||||
tempRegister.W = AF.B.B1 - HL.B.B0 - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x9e:
|
||||
// SBC (HL)
|
||||
tempValue = gbReadMemory(HL.W);
|
||||
tempRegister.W = AF.B.B1 - tempValue - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0x9f:
|
||||
// SBC A
|
||||
tempRegister.W = AF.B.B1 - AF.B.B1 - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ AF.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ AF.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0xa0:
|
||||
|
@ -960,45 +917,38 @@ break;
|
|||
case 0xb8:
|
||||
// CP B:
|
||||
tempRegister.W = AF.B.B1 - BC.B.B1;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xb9:
|
||||
// CP C
|
||||
tempRegister.W = AF.B.B1 - BC.B.B0;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ BC.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xba:
|
||||
// CP D
|
||||
tempRegister.W = AF.B.B1 - DE.B.B1;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xbb:
|
||||
// CP E
|
||||
tempRegister.W = AF.B.B1 - DE.B.B0;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ DE.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xbc:
|
||||
// CP H
|
||||
tempRegister.W = AF.B.B1 - HL.B.B1;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B1 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xbd:
|
||||
// CP L
|
||||
tempRegister.W = AF.B.B1 - HL.B.B0;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ HL.B.B0 ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xbe:
|
||||
// CP (HL)
|
||||
tempValue = gbReadMemory(HL.W);
|
||||
tempRegister.W = AF.B.B1 - tempValue;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xbf:
|
||||
// CP A
|
||||
|
@ -1056,8 +1006,7 @@ case 0xc6:
|
|||
// ADD NN
|
||||
tempValue = gbReadOpcode(PC.W++);
|
||||
tempRegister.W = AF.B.B1 + tempValue;
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0xc7:
|
||||
|
@ -1114,8 +1063,7 @@ case 0xce:
|
|||
// ADC NN
|
||||
tempValue = gbReadOpcode(PC.W++);
|
||||
tempRegister.W = AF.B.B1 + tempValue + (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0xcf:
|
||||
|
@ -1175,8 +1123,7 @@ case 0xd6:
|
|||
// SUB NN
|
||||
tempValue = gbReadOpcode(PC.W++);
|
||||
tempRegister.W = AF.B.B1 - tempValue;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0xd7:
|
||||
|
@ -1235,8 +1182,7 @@ case 0xde:
|
|||
// SBC NN
|
||||
tempValue = gbReadOpcode(PC.W++);
|
||||
tempRegister.W = AF.B.B1 - tempValue - (AF.B.B0 & C_FLAG ? 1 : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B1 = tempRegister.B.B0;
|
||||
break;
|
||||
case 0xdf:
|
||||
|
@ -1286,8 +1232,7 @@ case 0xe8:
|
|||
// ADD SP,NN
|
||||
offset = (s8)gbReadOpcode(PC.W++);
|
||||
tempRegister.W = SP.W + offset;
|
||||
AF.B.B0 = ((SP.W ^ offset ^ tempRegister.W) & 0x100 ? C_FLAG : 0) |
|
||||
((SP.W ^ offset ^ tempRegister.W) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = ((SP.W ^ offset ^ tempRegister.W) & 0x100 ? C_FLAG : 0) | ((SP.W ^ offset ^ tempRegister.W) & 0x10 ? H_FLAG : 0);
|
||||
SP.W = tempRegister.W;
|
||||
break;
|
||||
case 0xe9:
|
||||
|
@ -1365,8 +1310,7 @@ case 0xf8:
|
|||
// LD HL,SP+NN
|
||||
offset = (s8)gbReadOpcode(PC.W++);
|
||||
tempRegister.W = SP.W + offset;
|
||||
AF.B.B0 = ((SP.W ^ offset ^ tempRegister.W) & 0x100 ? C_FLAG : 0) |
|
||||
((SP.W ^ offset ^ tempRegister.W) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = ((SP.W ^ offset ^ tempRegister.W) & 0x100 ? C_FLAG : 0) | ((SP.W ^ offset ^ tempRegister.W) & 0x10 ? H_FLAG : 0);
|
||||
HL.W = tempRegister.W;
|
||||
break;
|
||||
case 0xf9:
|
||||
|
@ -1402,8 +1346,7 @@ case 0xfe:
|
|||
// CP NN
|
||||
tempValue = gbReadOpcode(PC.W++);
|
||||
tempRegister.W = AF.B.B1 - tempValue;
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] |
|
||||
((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
AF.B.B0 = N_FLAG | (tempRegister.B.B1 ? C_FLAG : 0) | ZeroTable[tempRegister.B.B0] | ((AF.B.B1 ^ tempValue ^ tempRegister.B.B0) & 0x10 ? H_FLAG : 0);
|
||||
break;
|
||||
case 0xff:
|
||||
// RST 38
|
||||
|
|
|
@ -5,22 +5,19 @@
|
|||
#include "gbGlobals.h"
|
||||
|
||||
typedef struct {
|
||||
u8 mask;
|
||||
u8 value;
|
||||
uint8_t mask;
|
||||
uint8_t value;
|
||||
const char* mnen;
|
||||
} GBOPCODE;
|
||||
|
||||
#define GB_READ(x) gbMemoryMap[(x) >> 12][(x)&0xfff]
|
||||
|
||||
static const char *registers[] =
|
||||
{ "B", "C", "D", "E", "H", "L", "(HL)", "A" };
|
||||
static const char* registers[] = { "B", "C", "D", "E", "H", "L", "(HL)", "A" };
|
||||
|
||||
static const char *registers16[] =
|
||||
{ "BC", "DE", "HL", "SP", // for some operations
|
||||
static const char* registers16[] = { "BC", "DE", "HL", "SP", // for some operations
|
||||
"BC", "DE", "HL", "AF" }; // for push/pop
|
||||
|
||||
static const char *cond[] =
|
||||
{ "NZ", "Z", "NC", "C" };
|
||||
static const char* cond[] = { "NZ", "Z", "NC", "C" };
|
||||
|
||||
static char hexDigits[16] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
|
@ -114,14 +111,14 @@ static GBOPCODE cbOpcodes[] = {
|
|||
{ 0x00, 0x00, "DB CBh,%B" }
|
||||
};
|
||||
|
||||
static char *addHex(char *p, u8 value)
|
||||
static char* addHex(char* p, uint8_t value)
|
||||
{
|
||||
*p++ = hexDigits[value >> 4];
|
||||
*p++ = hexDigits[value & 15];
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *addHex16(char *p, u16 value)
|
||||
static char* addHex16(char* p, uint16_t value)
|
||||
{
|
||||
p = addHex(p, value >> 8);
|
||||
return addHex(p, value & 255);
|
||||
|
@ -135,15 +132,15 @@ static char *addStr(char *p, const char *s)
|
|||
return p;
|
||||
}
|
||||
|
||||
int gbDis(char *buffer, u16 address)
|
||||
int gbDis(char* buffer, uint16_t address)
|
||||
{
|
||||
char* p = buffer;
|
||||
int instr = 1;
|
||||
u16 addr = address;
|
||||
uint16_t addr = address;
|
||||
sprintf(p, "%04x ", address);
|
||||
p += 12;
|
||||
|
||||
u8 opcode = GB_READ(address);
|
||||
uint8_t opcode = GB_READ(address);
|
||||
address++;
|
||||
const char* mnen;
|
||||
GBOPCODE* op;
|
||||
|
@ -155,11 +152,12 @@ int gbDis(char *buffer, u16 address)
|
|||
} else {
|
||||
op = opcodes;
|
||||
}
|
||||
while(op->value != (opcode & op->mask)) op++;
|
||||
while (op->value != (opcode & op->mask))
|
||||
op++;
|
||||
mnen = op->mnen;
|
||||
|
||||
u8 b0, b1;
|
||||
s8 disp;
|
||||
uint8_t b0, b1;
|
||||
int8_t disp;
|
||||
int shift;
|
||||
|
||||
while (*mnen) {
|
||||
|
@ -223,7 +221,7 @@ int gbDis(char *buffer, u16 address)
|
|||
*p++ = *mnen++;
|
||||
}
|
||||
for (int i = 0; i < instr; i++) {
|
||||
u16 a = addr + i;
|
||||
uint16_t a = addr + i;
|
||||
addHex(buffer + 5 + i * 2, GB_READ(a));
|
||||
}
|
||||
*p = 0;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <memory.h>
|
||||
|
||||
#include "../common/Types.h"
|
||||
#include "../Util.h"
|
||||
#include "../common/Types.h"
|
||||
#include "gbGlobals.h"
|
||||
#include "gbSGB.h"
|
||||
|
||||
|
@ -108,8 +108,6 @@ void gbRenderLine()
|
|||
if ((register_LCDC & 0x01 || gbCgbMode) && (layerSettings & 0x0100)) {
|
||||
while (x < 160) {
|
||||
|
||||
|
||||
|
||||
u8 tile_a = 0;
|
||||
u8 tile_b = 0;
|
||||
|
||||
|
@ -175,7 +173,6 @@ void gbRenderLine()
|
|||
|
||||
sy = gbSCYLine[x + (gbSpeed ? 11 : 5) + SpritesTicks];
|
||||
|
||||
|
||||
tx = ((sx + x) >> 3) & 0x1f;
|
||||
|
||||
sy += y;
|
||||
|
@ -206,13 +203,10 @@ void gbRenderLine()
|
|||
// Use gbBgp[0] instead of 0 (?)
|
||||
// (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++)
|
||||
{
|
||||
for (int i = 0; i < 160; i++) {
|
||||
u16 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;
|
||||
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;
|
||||
gbLineBuffer[i] = 0;
|
||||
}
|
||||
|
@ -226,8 +220,7 @@ void gbRenderLine()
|
|||
int i = 0;
|
||||
// Fix (accurate emulation) for most of the window display problems
|
||||
// (ie. Zen - Intergalactic Ninja, Urusei Yatsura...).
|
||||
if ((gbWindowLine == -1) || (gbWindowLine>144))
|
||||
{
|
||||
if ((gbWindowLine == -1) || (gbWindowLine > 144)) {
|
||||
inUseRegister_WY = oldRegister_WY;
|
||||
if (register_LY > oldRegister_WY)
|
||||
gbWindowLine = 146;
|
||||
|
@ -253,7 +246,6 @@ void gbRenderLine()
|
|||
if ((register_LCDC & 0x40) != 0)
|
||||
tile_map = 0x1c00;
|
||||
|
||||
|
||||
tx = 0;
|
||||
ty = gbWindowLine >> 3;
|
||||
|
||||
|
@ -262,8 +254,7 @@ void gbRenderLine()
|
|||
|
||||
// Tries to emulate the 'window scrolling bug' when wx == 0 (ie. wx-7 == -7).
|
||||
// Nothing close to perfect, but good enought for now...
|
||||
if (wx == -7)
|
||||
{
|
||||
if (wx == -7) {
|
||||
swx = 7 - ((gbSCXLine[0] - 1) & 7);
|
||||
bx >>= ((gbSCXLine[0] + ((swx != 1) ? 1 : 0)) & 7);
|
||||
if (swx == 1)
|
||||
|
@ -271,15 +262,12 @@ void gbRenderLine()
|
|||
|
||||
//bx >>= ((gbSCXLine[0]+(((swx>1) && (swx != 7)) ? 1 : 0)) & 7);
|
||||
|
||||
if (swx == 7)
|
||||
{
|
||||
if (swx == 7) {
|
||||
//wx = 0;
|
||||
if ((gbWindowLine > 0) || (wy == 0))
|
||||
swx = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(wx < 0) {
|
||||
} else if (wx < 0) {
|
||||
bx >>= (-wx);
|
||||
wx = 0;
|
||||
}
|
||||
|
@ -297,8 +285,10 @@ void gbRenderLine()
|
|||
tile_map_address++;
|
||||
|
||||
if ((register_LCDC & 16) == 0) {
|
||||
if(tile < 128) tile += 128;
|
||||
else tile -= 128;
|
||||
if (tile < 128)
|
||||
tile += 128;
|
||||
else
|
||||
tile -= 128;
|
||||
}
|
||||
|
||||
tile_pattern_address = tile_pattern + tile * 16 + by * 2;
|
||||
|
@ -332,8 +322,7 @@ void gbRenderLine()
|
|||
u8 c = (tile_a & bx) != 0 ? 1 : 0;
|
||||
c += ((tile_b & bx) != 0 ? 2 : 0);
|
||||
|
||||
if (x>=0)
|
||||
{
|
||||
if (x >= 0) {
|
||||
if (attrs & 0x80)
|
||||
gbLineBuffer[x] = 0x300 + c;
|
||||
else
|
||||
|
@ -376,8 +365,10 @@ void gbRenderLine()
|
|||
attrs = bank1[tile_map_line_y + tx];
|
||||
|
||||
if ((register_LCDC & 16) == 0) {
|
||||
if(tile < 128) tile += 128;
|
||||
else tile -= 128;
|
||||
if (tile < 128)
|
||||
tile += 128;
|
||||
else
|
||||
tile -= 128;
|
||||
}
|
||||
tile_pattern_address = tile_pattern + tile * 16 + by * 2;
|
||||
}
|
||||
|
@ -387,9 +378,7 @@ void gbRenderLine()
|
|||
gbWindowLine++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (gbWindowLine == -2)
|
||||
{
|
||||
} else if (gbWindowLine == -2) {
|
||||
inUseRegister_WY = oldRegister_WY;
|
||||
if (register_LY > oldRegister_WY)
|
||||
gbWindowLine = 146;
|
||||
|
@ -400,8 +389,7 @@ void gbRenderLine()
|
|||
u16 color = gbColorOption ? gbColorFilter[0x7FFF] : 0x7FFF;
|
||||
if (!gbCgbMode)
|
||||
color = gbColorOption ? gbColorFilter[gbPalette[0] & 0x7FFF] : gbPalette[0] & 0x7FFF;
|
||||
for(int i = 0; i < 160; i++)
|
||||
{
|
||||
for (int i = 0; i < 160; i++) {
|
||||
gbLineMix[i] = color;
|
||||
gbLineBuffer[i] = 0;
|
||||
}
|
||||
|
@ -423,8 +411,7 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
|||
|
||||
int init = 0x0000;
|
||||
|
||||
for (int i = 0; i<4; i++)
|
||||
{
|
||||
for (int i = 0; i < 4; i++) {
|
||||
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;
|
||||
}
|
||||
|
@ -462,7 +449,8 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
|||
if ((b & mask))
|
||||
c += 2;
|
||||
|
||||
if(c==0) continue;
|
||||
if (c == 0)
|
||||
continue;
|
||||
|
||||
int xxx = xx + x;
|
||||
if (flipx)
|
||||
|
@ -502,7 +490,6 @@ void gbDrawSpriteTile(int tile, int x,int y,int t, int flags,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
gbLineBuffer[xxx] = 0x200 + spriteNumber;
|
||||
|
||||
// make sure that sprites will work even in CGB mode
|
||||
|
@ -567,11 +554,9 @@ void gbDrawSprites(bool draw)
|
|||
if ((size && t >= 0 && t < 16) || (!size && t >= 0 && t < 8)) {
|
||||
if (draw)
|
||||
gbDrawSpriteTile(tile, x - 8, yc, t, flags, size, i);
|
||||
else
|
||||
{
|
||||
else {
|
||||
for (int j = x - 8; j < 300; j++)
|
||||
if (j>=0)
|
||||
{
|
||||
if (j >= 0) {
|
||||
if (gbSpeed)
|
||||
gbSpritesTicks[j] += 5;
|
||||
else
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <cstdlib>
|
||||
#include "../common/Types.h"
|
||||
#include <cstdlib>
|
||||
|
||||
u8* gbMemoryMap[16];
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "gbMemory.h"
|
||||
#include "../System.h"
|
||||
#include "../common/Port.h"
|
||||
#include "gbGlobals.h"
|
||||
#include "gbMemory.h"
|
||||
#include "gb.h"
|
||||
#include "gbGlobals.h"
|
||||
u8 gbDaysinMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
const u8 gbDisabledRam[8] = { 0x80, 0xff, 0xf0, 0x00, 0x30, 0xbf, 0xbf, 0xbf };
|
||||
extern int gbGBCColorType;
|
||||
|
@ -43,9 +43,7 @@ void mapperMBC1ROM(u16 address, u8 value)
|
|||
if (gbDataMBC1.mapperRomBank0Remapping == 3) {
|
||||
tmpAddress = (value & 0xf) << 14;
|
||||
tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 18;
|
||||
}
|
||||
else
|
||||
if(gbDataMBC1.mapperMemoryModel == 0) {
|
||||
} else if (gbDataMBC1.mapperMemoryModel == 0) {
|
||||
// model is 16/8, so we have a high address in use
|
||||
tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19;
|
||||
}
|
||||
|
@ -59,10 +57,8 @@ void mapperMBC1ROM(u16 address, u8 value)
|
|||
break;
|
||||
case 0x4000: // RAM bank select
|
||||
if (gbDataMBC1.mapperMemoryModel == 1) {
|
||||
if (!gbRamSize)
|
||||
{
|
||||
if (gbDataMBC1.mapperRomBank0Remapping == 3)
|
||||
{
|
||||
if (!gbRamSize) {
|
||||
if (gbDataMBC1.mapperRomBank0Remapping == 3) {
|
||||
gbDataMBC1.mapperROMHighAddress = value & 0x03;
|
||||
tmpAddress = (gbDataMBC1.mapperROMHighAddress) << 18;
|
||||
tmpAddress &= gbRomSizeMask;
|
||||
|
@ -74,8 +70,8 @@ void mapperMBC1ROM(u16 address, u8 value)
|
|||
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x5000];
|
||||
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x6000];
|
||||
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x7000];
|
||||
}
|
||||
else gbDataMBC1.mapperRomBank0Remapping = 0;
|
||||
} else
|
||||
gbDataMBC1.mapperRomBank0Remapping = 0;
|
||||
}
|
||||
// 4/32 model, RAM bank switching provided
|
||||
value = value & 0x03;
|
||||
|
@ -123,15 +119,14 @@ void mapperMBC1ROM(u16 address, u8 value)
|
|||
gbMemoryMap[0x0a] = &gbRam[gbDataMBC1.mapperRAMAddress];
|
||||
gbMemoryMap[0x0b] = &gbRam[gbDataMBC1.mapperRAMAddress + 0x1000];
|
||||
gbDataMBC1.mapperRomBank0Remapping = 0;
|
||||
}
|
||||
else gbDataMBC1.mapperRomBank0Remapping |=2;
|
||||
} else
|
||||
gbDataMBC1.mapperRomBank0Remapping |= 2;
|
||||
|
||||
gbDataMBC1.mapperRAMBank = value;
|
||||
gbDataMBC1.mapperRAMAddress = tmpAddress;
|
||||
|
||||
tmpAddress = gbDataMBC1.mapperROMBank << 14;
|
||||
|
||||
|
||||
tmpAddress &= gbRomSizeMask;
|
||||
gbMemoryMap[0x04] = &gbRom[tmpAddress];
|
||||
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
|
||||
|
@ -177,26 +172,20 @@ u8 mapperMBC1ReadRAM(u16 address)
|
|||
|
||||
if (!genericflashcardEnable)
|
||||
return 0xff;
|
||||
else
|
||||
if ((address & 0x1000) >= 0x1000)
|
||||
{
|
||||
else if ((address & 0x1000) >= 0x1000) {
|
||||
// The value returned when reading RAM while it's disabled
|
||||
// is constant, exept for the GBASP hardware.
|
||||
// (actually, is the address that read is out of the ROM, the returned value if 0xff...)
|
||||
if (PC.W >= 0xff80)
|
||||
return 0xff;
|
||||
else
|
||||
if ((gbHardware & 0x08) && (gbGBCColorType == 2))
|
||||
{
|
||||
else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) {
|
||||
if (address & 1)
|
||||
return 0xfb;
|
||||
else
|
||||
return 0x7a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return 0x0a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return gbDisabledRam[address & 7];
|
||||
}
|
||||
|
||||
|
@ -218,9 +207,7 @@ void memoryUpdateMapMBC1()
|
|||
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
|
||||
gbMemoryMap[0x06] = &gbRom[tmpAddress + 0x2000];
|
||||
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (gbDataMBC1.mapperMemoryModel == 0) {
|
||||
// model is 16/8, so we have a high address in use
|
||||
tmpAddress |= (gbDataMBC1.mapperROMHighAddress & 3) << 19;
|
||||
|
@ -359,8 +346,7 @@ void memoryUpdateMBC3Clock()
|
|||
gbDataMBC3.mapperDays %= 512;
|
||||
gbDataMBC3.mapperControl |= 0x80;
|
||||
}
|
||||
gbDataMBC3.mapperControl = (gbDataMBC3.mapperControl & 0xfe) |
|
||||
(gbDataMBC3.mapperDays>255 ? 1 : 0);
|
||||
gbDataMBC3.mapperControl = (gbDataMBC3.mapperControl & 0xfe) | (gbDataMBC3.mapperDays > 255 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
gbDataMBC3.mapperLastTime = now;
|
||||
|
@ -488,26 +474,20 @@ u8 mapperMBC3ReadRAM(u16 address)
|
|||
|
||||
if (!genericflashcardEnable)
|
||||
return 0xff;
|
||||
else
|
||||
if ((address & 0x1000) >= 0x1000)
|
||||
{
|
||||
else if ((address & 0x1000) >= 0x1000) {
|
||||
// The value returned when reading RAM while it's disabled
|
||||
// is constant, exept for the GBASP hardware.
|
||||
// (actually, is the address that read is out of the ROM, the returned value if 0xff...)
|
||||
if (PC.W >= 0xff80)
|
||||
return 0xff;
|
||||
else
|
||||
if ((gbHardware & 0x08) && (gbGBCColorType == 2))
|
||||
{
|
||||
else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) {
|
||||
if (address & 1)
|
||||
return 0xfb;
|
||||
else
|
||||
return 0x7a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return 0x0a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return gbDisabledRam[address & 7];
|
||||
}
|
||||
|
||||
|
@ -619,33 +599,26 @@ u8 mapperMBC5ReadRAM(u16 address)
|
|||
|
||||
if (!genericflashcardEnable)
|
||||
return 0xff;
|
||||
else
|
||||
if ((address & 0x1000) >= 0x1000)
|
||||
{
|
||||
else if ((address & 0x1000) >= 0x1000) {
|
||||
// The value returned when reading RAM while it's disabled
|
||||
// is constant, exept for the GBASP hardware.
|
||||
// (actually, is the address that read is out of the ROM, the returned value if 0xff...)
|
||||
if (PC.W >= 0xff80)
|
||||
return 0xff;
|
||||
else
|
||||
if ((gbHardware & 0x08) && (gbGBCColorType == 2))
|
||||
{
|
||||
else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) {
|
||||
if (address & 1)
|
||||
return 0xfb;
|
||||
else
|
||||
return 0x7a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return 0x0a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return gbDisabledRam[address & 7];
|
||||
}
|
||||
|
||||
void memoryUpdateMapMBC5()
|
||||
{
|
||||
int tmpAddress = (gbDataMBC5.mapperROMBank << 14) |
|
||||
(gbDataMBC5.mapperROMHighAddress << 22) ;
|
||||
int tmpAddress = (gbDataMBC5.mapperROMBank << 14) | (gbDataMBC5.mapperROMHighAddress << 22);
|
||||
|
||||
tmpAddress &= gbRomSizeMask;
|
||||
gbMemoryMap[0x04] = &gbRom[tmpAddress];
|
||||
|
@ -747,26 +720,20 @@ u8 mapperMBC7ReadRAM(u16 address)
|
|||
|
||||
if (!genericflashcardEnable)
|
||||
return 0xff;
|
||||
else
|
||||
if ((address & 0x1000) >= 0x1000)
|
||||
{
|
||||
else if ((address & 0x1000) >= 0x1000) {
|
||||
// The value returned when reading RAM while it's disabled
|
||||
// is constant, exept for the GBASP hardware.
|
||||
// (actually, is the address that read is out of the ROM, the returned value if 0xff...)
|
||||
if (PC.W >= 0xff80)
|
||||
return 0xff;
|
||||
else
|
||||
if ((gbHardware & 0x08) && (gbGBCColorType == 2))
|
||||
{
|
||||
else if ((gbHardware & 0x08) && (gbGBCColorType == 2)) {
|
||||
if (address & 1)
|
||||
return 0xfb;
|
||||
else
|
||||
return 0x7a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return 0x0a;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return gbDisabledRam[address & 7];
|
||||
}
|
||||
|
||||
|
@ -882,8 +849,7 @@ void mapperMBC7RAM(u16 address, u8 value)
|
|||
if (gbDataMBC7.count == 1) {
|
||||
gbDataMBC7.state = 4;
|
||||
gbDataMBC7.count = 0;
|
||||
gbDataMBC7.buffer = (gbMemory[0xa000+gbDataMBC7.address*2]<<8)|
|
||||
(gbMemory[0xa000+gbDataMBC7.address*2+1]);
|
||||
gbDataMBC7.buffer = (gbMemory[0xa000 + gbDataMBC7.address * 2] << 8) | (gbMemory[0xa000 + gbDataMBC7.address * 2 + 1]);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
|
@ -1028,7 +994,6 @@ mapperHuC3 gbDataHuC3 = {
|
|||
0 // RAM read value
|
||||
};
|
||||
|
||||
|
||||
// HuC3 ROM write registers
|
||||
void mapperHuC3ROM(u16 address, u8 value)
|
||||
{
|
||||
|
@ -1076,8 +1041,7 @@ void mapperHuC3ROM(u16 address, u8 value)
|
|||
// HuC3 read RAM
|
||||
u8 mapperHuC3ReadRAM(u16 address)
|
||||
{
|
||||
if(gbDataHuC3.mapperRAMFlag > 0x0b &&
|
||||
gbDataHuC3.mapperRAMFlag < 0x0e) {
|
||||
if (gbDataHuC3.mapperRAMFlag > 0x0b && gbDataHuC3.mapperRAMFlag < 0x0e) {
|
||||
if (gbDataHuC3.mapperRAMFlag != 0x0c)
|
||||
return 1;
|
||||
return gbDataHuC3.mapperRAMValue;
|
||||
|
@ -1090,8 +1054,7 @@ void mapperHuC3RAM(u16 address, u8 value)
|
|||
{
|
||||
int* p;
|
||||
|
||||
if(gbDataHuC3.mapperRAMFlag < 0x0b ||
|
||||
gbDataHuC3.mapperRAMFlag > 0x0e) {
|
||||
if (gbDataHuC3.mapperRAMFlag < 0x0b || gbDataHuC3.mapperRAMFlag > 0x0e) {
|
||||
if (gbDataHuC3.mapperRAMEnable) {
|
||||
if (gbRamSize) {
|
||||
gbMemoryMap[address >> 12][address & 0x0fff] = value;
|
||||
|
@ -1115,16 +1078,10 @@ void mapperHuC3RAM(u16 address, u8 value)
|
|||
*(p + gbDataHuC3.mapperRegister1++) = value & 0x0f;
|
||||
if (gbDataHuC3.mapperRegister1 > 6)
|
||||
gbDataHuC3.mapperRegister1 = 0;
|
||||
gbDataHuC3.mapperAddress =
|
||||
(gbDataHuC3.mapperRegister6 << 24) |
|
||||
(gbDataHuC3.mapperRegister5 << 16) |
|
||||
(gbDataHuC3.mapperRegister4 << 8) |
|
||||
(gbDataHuC3.mapperRegister3 << 4) |
|
||||
(gbDataHuC3.mapperRegister2);
|
||||
gbDataHuC3.mapperAddress = (gbDataHuC3.mapperRegister6 << 24) | (gbDataHuC3.mapperRegister5 << 16) | (gbDataHuC3.mapperRegister4 << 8) | (gbDataHuC3.mapperRegister3 << 4) | (gbDataHuC3.mapperRegister2);
|
||||
break;
|
||||
case 0x40:
|
||||
gbDataHuC3.mapperRegister1 = (gbDataHuC3.mapperRegister1 & 0xf0) |
|
||||
(value & 0x0f);
|
||||
gbDataHuC3.mapperRegister1 = (gbDataHuC3.mapperRegister1 & 0xf0) | (value & 0x0f);
|
||||
gbDataHuC3.mapperRegister2 = (gbDataHuC3.mapperAddress & 0x0f);
|
||||
gbDataHuC3.mapperRegister3 = ((gbDataHuC3.mapperAddress >> 4) & 0x0f);
|
||||
gbDataHuC3.mapperRegister4 = ((gbDataHuC3.mapperAddress >> 8) & 0x0f);
|
||||
|
@ -1135,8 +1092,7 @@ void mapperHuC3RAM(u16 address, u8 value)
|
|||
gbDataHuC3.mapperRAMValue = 0;
|
||||
break;
|
||||
case 0x50:
|
||||
gbDataHuC3.mapperRegister1 = (gbDataHuC3.mapperRegister1 & 0x0f) |
|
||||
((value << 4)&0x0f);
|
||||
gbDataHuC3.mapperRegister1 = (gbDataHuC3.mapperRegister1 & 0x0f) | ((value << 4) & 0x0f);
|
||||
break;
|
||||
default:
|
||||
gbDataHuC3.mapperRAMValue = 1;
|
||||
|
@ -1213,7 +1169,6 @@ mapperTAMA5 gbDataTAMA5 = {
|
|||
(time_t)-1 // last time
|
||||
};
|
||||
|
||||
|
||||
void memoryUpdateTAMA5Clock()
|
||||
{
|
||||
if ((gbDataTAMA5.mapperYears & 3) == 0)
|
||||
|
@ -1246,20 +1201,16 @@ void memoryUpdateTAMA5Clock()
|
|||
if (gbDataTAMA5.mapperHours > 23) {
|
||||
gbDataTAMA5.mapperHours -= 24;
|
||||
diff++;
|
||||
|
||||
}
|
||||
|
||||
time_t days = diff;
|
||||
while (days)
|
||||
{
|
||||
while (days) {
|
||||
gbDataTAMA5.mapperDays++;
|
||||
days--;
|
||||
if (gbDataTAMA5.mapperDays>gbDaysinMonth[gbDataTAMA5.mapperMonths-1])
|
||||
{
|
||||
if (gbDataTAMA5.mapperDays > gbDaysinMonth[gbDataTAMA5.mapperMonths - 1]) {
|
||||
gbDataTAMA5.mapperDays = 1;
|
||||
gbDataTAMA5.mapperMonths++;
|
||||
if (gbDataTAMA5.mapperMonths>12)
|
||||
{
|
||||
if (gbDataTAMA5.mapperMonths > 12) {
|
||||
gbDataTAMA5.mapperMonths = 1;
|
||||
gbDataTAMA5.mapperYears++;
|
||||
if ((gbDataTAMA5.mapperYears & 3) == 0)
|
||||
|
@ -1271,18 +1222,13 @@ void memoryUpdateTAMA5Clock()
|
|||
}
|
||||
}
|
||||
gbDataTAMA5.mapperLastTime = now;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TAMA5 RAM write
|
||||
void mapperTAMA5RAM(u16 address, u8 value)
|
||||
{
|
||||
if ((address & 0xffff) <= 0xa001)
|
||||
{
|
||||
switch (address & 1)
|
||||
{
|
||||
if ((address & 0xffff) <= 0xa001) {
|
||||
switch (address & 1) {
|
||||
case 0: // 'Values' Register
|
||||
{
|
||||
value &= 0xf;
|
||||
|
@ -1294,8 +1240,7 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
|
||||
if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 0) // Read Command !!!
|
||||
{
|
||||
gbDataTAMA5.mapperROMBank = gbDataTAMA5.mapperCommands[0] |
|
||||
(gbDataTAMA5.mapperCommands[1]<<4);
|
||||
gbDataTAMA5.mapperROMBank = gbDataTAMA5.mapperCommands[0] | (gbDataTAMA5.mapperCommands[1] << 4);
|
||||
|
||||
int tmpAddress = (gbDataTAMA5.mapperROMBank << 14);
|
||||
|
||||
|
@ -1306,23 +1251,16 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
gbMemoryMap[0x07] = &gbRom[tmpAddress + 0x3000];
|
||||
|
||||
gbDataTAMA5.mapperCommands[0x0f] = 0;
|
||||
}
|
||||
else if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 4)
|
||||
{
|
||||
} else if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 4) {
|
||||
gbDataTAMA5.mapperCommands[0x0f] = 1;
|
||||
if (gbDataTAMA5.mapperCommandNumber == 4)
|
||||
gbDataTAMA5.mapperCommands[5] = 0; // correct ?
|
||||
}
|
||||
else if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 6)
|
||||
{
|
||||
gbDataTAMA5.mapperRamByteSelect = (gbDataTAMA5.mapperCommands[7]<<4) |
|
||||
(gbDataTAMA5.mapperCommands[6]&0x0f);
|
||||
} else if ((gbDataTAMA5.mapperCommandNumber & 0xe) == 6) {
|
||||
gbDataTAMA5.mapperRamByteSelect = (gbDataTAMA5.mapperCommands[7] << 4) | (gbDataTAMA5.mapperCommands[6] & 0x0f);
|
||||
|
||||
// Write Commands !!!
|
||||
if (gbDataTAMA5.mapperCommands[0x0f] && (gbDataTAMA5.mapperCommandNumber == 7))
|
||||
{
|
||||
int data = (gbDataTAMA5.mapperCommands[0x04] & 0x0f) |
|
||||
(gbDataTAMA5.mapperCommands[0x05] <<4);
|
||||
if (gbDataTAMA5.mapperCommands[0x0f] && (gbDataTAMA5.mapperCommandNumber == 7)) {
|
||||
int data = (gbDataTAMA5.mapperCommands[0x04] & 0x0f) | (gbDataTAMA5.mapperCommands[0x05] << 4);
|
||||
|
||||
// Not sure when the write command should reset...
|
||||
// but it doesn't seem to matter.
|
||||
|
@ -1330,8 +1268,7 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
|
||||
if (gbDataTAMA5.mapperRamByteSelect == 0x8) // Timer stuff
|
||||
{
|
||||
switch (data & 0xf)
|
||||
{
|
||||
switch (data & 0xf) {
|
||||
case 0x7:
|
||||
gbDataTAMA5.mapperDays = ((gbDataTAMA5.mapperDays) / 10) * 10 + (data >> 4);
|
||||
break;
|
||||
|
@ -1348,14 +1285,12 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
gbDataTAMA5.mapperYears = ((gbDataTAMA5.mapperYears) % 1000) + (data >> 4) * 1000;
|
||||
break;
|
||||
case 0xc:
|
||||
gbDataTAMA5.mapperYears = (gbDataTAMA5.mapperYears%100) + (gbDataTAMA5.mapperYears/1000)*1000 +
|
||||
(data >>4)*100;
|
||||
gbDataTAMA5.mapperYears = (gbDataTAMA5.mapperYears % 100) + (gbDataTAMA5.mapperYears / 1000) * 1000 + (data >> 4) * 100;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (gbDataTAMA5.mapperRamByteSelect == 0x18) // Timer stuff again
|
||||
} else if (gbDataTAMA5.mapperRamByteSelect == 0x18) // Timer stuff again
|
||||
{
|
||||
memoryUpdateTAMA5Clock();
|
||||
gbDataTAMA5.mapperLSeconds = gbDataTAMA5.mapperSeconds;
|
||||
|
@ -1378,8 +1313,7 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
int Years3 = (gbDataTAMA5.mapperLYears / 100) % 10;
|
||||
int Years4 = (gbDataTAMA5.mapperLYears / 1000);
|
||||
|
||||
switch (data & 0x0f)
|
||||
{
|
||||
switch (data & 0x0f) {
|
||||
// I guess cases 0 and 1 are used for secondsL and secondsH
|
||||
// so the game would update the timer values on screen when
|
||||
// the seconds reset to 0... ?
|
||||
|
@ -1420,28 +1354,20 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
time(&gbDataTAMA5.mapperLastTime);
|
||||
|
||||
gbMemoryMap[0xa][0] = 1;
|
||||
}
|
||||
else if (gbDataTAMA5.mapperRamByteSelect == 0x28) // Timer stuff again
|
||||
} else if (gbDataTAMA5.mapperRamByteSelect == 0x28) // Timer stuff again
|
||||
{
|
||||
if ((data & 0xf) == 0xb)
|
||||
gbDataTAMA5.mapperYears = ((gbDataTAMA5.mapperYears >> 2) << 2) + (data & 3);
|
||||
}
|
||||
else if (gbDataTAMA5.mapperRamByteSelect == 0x44)
|
||||
{
|
||||
} else if (gbDataTAMA5.mapperRamByteSelect == 0x44) {
|
||||
gbDataTAMA5.mapperMinutes = (data / 16) * 10 + data % 16;
|
||||
}
|
||||
else if (gbDataTAMA5.mapperRamByteSelect == 0x54)
|
||||
{
|
||||
} else if (gbDataTAMA5.mapperRamByteSelect == 0x54) {
|
||||
gbDataTAMA5.mapperHours = (data / 16) * 10 + data % 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect] = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case 1: // 'Commands' Register
|
||||
{
|
||||
gbMemoryMap[0xa][1] = gbDataTAMA5.mapperCommandNumber = value;
|
||||
|
@ -1450,8 +1376,7 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
// However as I couldn't find any 'copy' command
|
||||
// (that seems to be needed for the saving system to work)
|
||||
// I put it there...
|
||||
if (value == 0x0a)
|
||||
{
|
||||
if (value == 0x0a) {
|
||||
for (int i = 0; i < 0x10; i++)
|
||||
for (int j = 0; j < 0x10; j++)
|
||||
if (!(j & 2))
|
||||
|
@ -1461,13 +1386,9 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
gbMemoryMap[0xe][k] = gbTAMA5ram[k];*/
|
||||
|
||||
gbMemoryMap[0xa][0] = gbDataTAMA5.mapperRAMEnable = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((value & 0x0e) == 0x0c)
|
||||
{
|
||||
gbDataTAMA5.mapperRamByteSelect = gbDataTAMA5.mapperCommands[6] |
|
||||
(gbDataTAMA5.mapperCommands[7]<<4);
|
||||
} else {
|
||||
if ((value & 0x0e) == 0x0c) {
|
||||
gbDataTAMA5.mapperRamByteSelect = gbDataTAMA5.mapperCommands[6] | (gbDataTAMA5.mapperCommands[7] << 4);
|
||||
|
||||
u8 byte = gbTAMA5ram[gbDataTAMA5.mapperRamByteSelect];
|
||||
|
||||
|
@ -1479,9 +1400,7 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (gbDataTAMA5.mapperRAMEnable) {
|
||||
if (gbDataTAMA5.mapperRAMBank != -1) {
|
||||
if (gbRamSize) {
|
||||
|
@ -1493,14 +1412,12 @@ void mapperTAMA5RAM(u16 address, u8 value)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// TAMA5 read RAM
|
||||
u8 mapperTAMA5ReadRAM(u16 address)
|
||||
{
|
||||
return gbMemoryMap[address >> 12][address & 0xfff];
|
||||
}
|
||||
|
||||
|
||||
void memoryUpdateMapTAMA5()
|
||||
{
|
||||
int tmpAddress = (gbDataTAMA5.mapperROMBank << 14);
|
||||
|
@ -1552,8 +1469,7 @@ void mapperMMM01ROM(u16 address, u8 value)
|
|||
if (gbDataMMM01.mapperMemoryModel == 0) {
|
||||
// model is 16/8, so we have a high address in use
|
||||
tmpAddress |= (gbDataMMM01.mapperROMHighAddress) << 19;
|
||||
}
|
||||
else
|
||||
} else
|
||||
tmpAddress |= gbDataMMM01.mapperRomBank0Remapping << 18;
|
||||
|
||||
tmpAddress &= gbRomSizeMask;
|
||||
|
@ -1658,7 +1574,6 @@ void mapperGGROM(u16 address, u8 value)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// GS3 Used to emulate the GS V3.0 rom bank switching
|
||||
mapperGS3 gbDataGS3 = { 1 }; // ROM bank
|
||||
|
||||
|
@ -1685,8 +1600,7 @@ void mapperGS3ROM(u16 address, u8 value)
|
|||
gbDataGS3.mapperROMBank = value;
|
||||
gbMemoryMap[0x04] = &gbRom[tmpAddress];
|
||||
gbMemoryMap[0x05] = &gbRom[tmpAddress + 0x1000];
|
||||
}
|
||||
else
|
||||
} else
|
||||
gbMemoryMap[address >> 12][address & 0x0fff] = value;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include "../System.h"
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
|
||||
u8 gbPrinterStatus = 0;
|
||||
int gbPrinterState = 0;
|
||||
|
@ -19,8 +19,7 @@ bool gbPrinterCheckCRC()
|
|||
crc += gbPrinterPacket[i];
|
||||
}
|
||||
|
||||
int msgCrc = gbPrinterPacket[6+gbPrinterDataSize] +
|
||||
(gbPrinterPacket[7+gbPrinterDataSize]<<8);
|
||||
int msgCrc = gbPrinterPacket[6 + gbPrinterDataSize] + (gbPrinterPacket[7 + gbPrinterDataSize] << 8);
|
||||
|
||||
return msgCrc == crc;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../System.h"
|
||||
#include "../common/Port.h"
|
||||
#include "../Util.h"
|
||||
#include "../common/Port.h"
|
||||
#include "gb.h"
|
||||
#include "gbGlobals.h"
|
||||
|
||||
|
@ -111,19 +111,15 @@ void gbSgbShutdown()
|
|||
void gbSgbFillScreen(u16 color)
|
||||
{
|
||||
switch (systemColorDepth) {
|
||||
case 16:
|
||||
{
|
||||
case 16: {
|
||||
for (int y = 0; y < 144; y++) {
|
||||
int yLine = (y+gbBorderRowSkip+1)*(gbBorderLineSkip+2) +
|
||||
gbBorderColumnSkip;
|
||||
int yLine = (y + gbBorderRowSkip + 1) * (gbBorderLineSkip + 2) + gbBorderColumnSkip;
|
||||
u16* dest = (u16*)pix + yLine;
|
||||
for (register int x = 0; x < 160; x++)
|
||||
gbSgbDraw16Bit(dest++, color);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 24:
|
||||
{
|
||||
} break;
|
||||
case 24: {
|
||||
for (int y = 0; y < 144; y++) {
|
||||
int yLine = (y + gbBorderRowSkip) * gbBorderLineSkip + gbBorderColumnSkip;
|
||||
u8* dest = (u8*)pix + yLine * 3;
|
||||
|
@ -132,10 +128,8 @@ void gbSgbFillScreen(u16 color)
|
|||
dest += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 32:
|
||||
{
|
||||
} break;
|
||||
case 32: {
|
||||
for (int y = 0; y < 144; y++) {
|
||||
int yLine = (y + gbBorderRowSkip + 1) * (gbBorderLineSkip + 1) + gbBorderColumnSkip;
|
||||
u32* dest = (u32*)pix + yLine;
|
||||
|
@ -143,8 +137,7 @@ void gbSgbFillScreen(u16 color)
|
|||
gbSgbDraw32Bit(dest++, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,8 +210,6 @@ void gbSgbDrawBorderTile(int x, int y, int tile, int attr)
|
|||
u8 c = *tileAddress2++;
|
||||
u8 d = *tileAddress2++;
|
||||
|
||||
|
||||
|
||||
u8 yyy;
|
||||
if (!flipY)
|
||||
yyy = yy;
|
||||
|
@ -419,13 +410,11 @@ void gbSgbAttributeBlock()
|
|||
|
||||
for (u8 y = 0; y < 18; y++) {
|
||||
for (u8 x = 0; x < 20; x++) {
|
||||
if(x < startH || y < startV ||
|
||||
x > endH || y > endV) {
|
||||
if (x < startH || y < startV || x > endH || y > endV) {
|
||||
// outside
|
||||
if (controlCode & 0x04)
|
||||
*toAddress = (paletteDesignation >> 4) & 0x03;
|
||||
} else if(x > startH && x < endH &&
|
||||
y > startV && y < endV) {
|
||||
} else if (x > startH && x < endH && y > startV && y < endV) {
|
||||
// inside
|
||||
if (controlCode & 0x01)
|
||||
*toAddress = paletteDesignation & 0x03;
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "../gba/Sound.h"
|
||||
#include "../Util.h"
|
||||
#include "../gba/Sound.h"
|
||||
#include "gb.h"
|
||||
#include "gbGlobals.h"
|
||||
#include "gbSound.h"
|
||||
#include "gb.h"
|
||||
|
||||
#include "../apu/Gb_Apu.h"
|
||||
#include "../apu/Effects_Buffer.h"
|
||||
#include "../apu/Gb_Apu.h"
|
||||
|
||||
extern long soundSampleRate; // current sound quality
|
||||
|
||||
|
@ -62,8 +62,7 @@ static void apply_effects()
|
|||
stereo_buffer->config().surround = gb_effects_config_current.surround;
|
||||
stereo_buffer->apply_config();
|
||||
|
||||
for ( int i = 0; i < chan_count; i++ )
|
||||
{
|
||||
for (int i = 0; i < chan_count; i++) {
|
||||
Multi_Buffer::channel_t ch = { 0, 0, 0 };
|
||||
if (prevSoundEnable >> i & 1)
|
||||
ch = stereo_buffer->channel(i);
|
||||
|
@ -86,8 +85,7 @@ static void apply_volume()
|
|||
|
||||
void gbSoundTick()
|
||||
{
|
||||
if ( gb_apu && stereo_buffer )
|
||||
{
|
||||
if (gb_apu && stereo_buffer) {
|
||||
// Run sound hardware to present
|
||||
end_frame(SOUND_CLOCK_TICKS * ticks_to_time);
|
||||
|
||||
|
@ -95,7 +93,8 @@ void gbSoundTick()
|
|||
|
||||
// Update effects config if it was changed
|
||||
if (memcmp(&gb_effects_config_current, &gb_effects_config,
|
||||
sizeof gb_effects_config ) || soundGetEnable() != prevSoundEnable )
|
||||
sizeof gb_effects_config)
|
||||
|| soundGetEnable() != prevSoundEnable)
|
||||
apply_effects();
|
||||
|
||||
if (soundVolume_ != soundGetVolume())
|
||||
|
@ -122,8 +121,7 @@ static void reset_apu()
|
|||
static void remake_stereo_buffer()
|
||||
{
|
||||
// APU
|
||||
if ( !gb_apu )
|
||||
{
|
||||
if (!gb_apu) {
|
||||
gb_apu = new Gb_Apu; // TODO: handle errors
|
||||
reset_apu();
|
||||
}
|
||||
|
@ -133,7 +131,8 @@ static void remake_stereo_buffer()
|
|||
stereo_buffer = 0;
|
||||
|
||||
stereo_buffer = new Simple_Effects_Buffer; // TODO: handle out of memory
|
||||
if ( stereo_buffer->set_sample_rate( soundSampleRate ) ) { } // TODO: handle out of memory
|
||||
if (stereo_buffer->set_sample_rate(soundSampleRate)) {
|
||||
} // TODO: handle out of memory
|
||||
stereo_buffer->clock_rate(gb_apu->clock_rate);
|
||||
|
||||
// Multi_Buffer
|
||||
|
@ -141,7 +140,8 @@ static void remake_stereo_buffer()
|
|||
Multi_Buffer::wave_type + 1, Multi_Buffer::wave_type + 2,
|
||||
Multi_Buffer::wave_type + 3, Multi_Buffer::mixed_type + 1
|
||||
};
|
||||
if ( stereo_buffer->set_channel_count( chan_count, chan_types ) ) { } // TODO: handle errors
|
||||
if (stereo_buffer->set_channel_count(chan_count, chan_types)) {
|
||||
} // TODO: handle errors
|
||||
|
||||
// Volume Level
|
||||
apply_effects();
|
||||
|
@ -150,17 +150,16 @@ static void remake_stereo_buffer()
|
|||
|
||||
void gbSoundSetDeclicking(bool enable)
|
||||
{
|
||||
if ( declicking != enable )
|
||||
{
|
||||
if (declicking != enable) {
|
||||
declicking = enable;
|
||||
if ( gb_apu )
|
||||
{
|
||||
if (gb_apu) {
|
||||
// Can't change sound hardware mode without resetting APU, so save/load
|
||||
// state around mode change
|
||||
gb_apu_state_t state;
|
||||
gb_apu->save_state(&state);
|
||||
reset_apu();
|
||||
if ( gb_apu->load_state( state ) ) { } // ignore error
|
||||
if (gb_apu->load_state(state)) {
|
||||
} // ignore error
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,16 +219,12 @@ void gbSoundReset()
|
|||
|
||||
void gbSoundSetSampleRate(long sampleRate)
|
||||
{
|
||||
if ( soundSampleRate != sampleRate )
|
||||
{
|
||||
if ( systemCanChangeSoundQuality() )
|
||||
{
|
||||
if (soundSampleRate != sampleRate) {
|
||||
if (systemCanChangeSoundQuality()) {
|
||||
soundShutdown();
|
||||
soundSampleRate = sampleRate;
|
||||
soundInit();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
soundSampleRate = sampleRate;
|
||||
}
|
||||
|
||||
|
@ -244,14 +239,19 @@ static struct {
|
|||
|
||||
static char dummy_state[735 * 2];
|
||||
|
||||
#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) \
|
||||
}
|
||||
|
||||
// Old save state support
|
||||
|
||||
static variable_desc gbsound_format [] =
|
||||
{
|
||||
static variable_desc gbsound_format[] = {
|
||||
SKIP(int, soundPaused),
|
||||
SKIP(int, soundPlay),
|
||||
SKIP(int, soundTicks),
|
||||
|
@ -310,8 +310,7 @@ static variable_desc gbsound_format [] =
|
|||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
static variable_desc gbsound_format2 [] =
|
||||
{
|
||||
static variable_desc gbsound_format2[] = {
|
||||
SKIP(int, sound1ATLreload),
|
||||
SKIP(int, freq1low),
|
||||
SKIP(int, freq1high),
|
||||
|
@ -326,8 +325,7 @@ static variable_desc gbsound_format2 [] =
|
|||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
static variable_desc gbsound_format3 [] =
|
||||
{
|
||||
static variable_desc gbsound_format3[] = {
|
||||
SKIP(u8[2 * 735], soundBuffer),
|
||||
SKIP(u8[2 * 735], soundBuffer),
|
||||
SKIP(u16[735], soundFinalWave),
|
||||
|
@ -336,17 +334,33 @@ static variable_desc gbsound_format3 [] =
|
|||
|
||||
enum {
|
||||
nr10 = 0,
|
||||
nr11, nr12, nr13, nr14,
|
||||
nr20, nr21, nr22, nr23, nr24,
|
||||
nr30, nr31, nr32, nr33, nr34,
|
||||
nr40, nr41, nr42, nr43, nr44,
|
||||
nr50, nr51, nr52
|
||||
nr11,
|
||||
nr12,
|
||||
nr13,
|
||||
nr14,
|
||||
nr20,
|
||||
nr21,
|
||||
nr22,
|
||||
nr23,
|
||||
nr24,
|
||||
nr30,
|
||||
nr31,
|
||||
nr32,
|
||||
nr33,
|
||||
nr34,
|
||||
nr40,
|
||||
nr41,
|
||||
nr42,
|
||||
nr43,
|
||||
nr44,
|
||||
nr50,
|
||||
nr51,
|
||||
nr52
|
||||
};
|
||||
|
||||
static void gbSoundReadGameOld(int version, gzFile gzFile)
|
||||
{
|
||||
if ( version == 11 )
|
||||
{
|
||||
if (version == 11) {
|
||||
// Version 11 didn't save any state
|
||||
// TODO: same for version 10?
|
||||
state.apu.regs[nr50] = 0x77; // volume at max
|
||||
|
@ -384,8 +398,7 @@ static void gbSoundReadGameOld(int version,gzFile gzFile)
|
|||
|
||||
// New state format
|
||||
|
||||
static variable_desc gb_state [] =
|
||||
{
|
||||
static variable_desc gb_state[] = {
|
||||
LOAD(int, state.version), // room_for_expansion will be used by later versions
|
||||
|
||||
// APU
|
||||
|
|
Loading…
Reference in New Issue