Skip to content

Commit

Permalink
Update core 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
infval committed Jul 3, 2019
1 parent c25b147 commit 219e45d
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 135 deletions.
2 changes: 1 addition & 1 deletion Makefile.psp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PSP_FW_VERSION=200
export PSP_FW_VERSION

PSP_APP_NAME=Potator PSP
PSP_APP_VER=1.0.4
PSP_APP_VER=1.0.5

TARGET=potator
EXTRA_TARGETS=EBOOT.PBP
Expand Down
29 changes: 15 additions & 14 deletions common/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static uint16 rgb555(uint8 r, uint8 g, uint8 b)

static SV_MapRGBFunc mapRGB = rgb555;

const static uint8 palettes[SV_COLOR_SCHEME_COUNT][12] = {
static const uint8 palettes[SV_COLOR_SCHEME_COUNT][12] = {
{
252, 252, 252,
168, 168, 168,
Expand Down Expand Up @@ -162,6 +162,9 @@ void gpu_set_ghosting(int frameCount)
if (screenBuffers[0] == NULL) {
for (i = 0; i < SB_MAX; i++) {
screenBuffers[i] = malloc(SV_H * SV_W / 4);
if (screenBuffers[i] == NULL) {
return;
}
}
}
for (i = 0; i < SB_MAX; i++) {
Expand Down Expand Up @@ -191,30 +194,28 @@ static void add_ghosting(uint32 scanline, uint16 *backbuffer, uint8 innerx, uint
uint8 innerInd = (j & 3) * 2;
uint8 c = (b >> innerInd) & 3;
int pixInd = (x + lineCount * SV_W) / 4;
if (c == 0) {
if (c != 3) {
for (i = 0; i < ghostCount; i++) {
uint8 sbInd = (curSB + (SB_MAX - 1) - i) % SB_MAX;
innerInd = ((screenBufferInnerX[sbInd] + x) & 3) * 2;
c = (screenBuffers[sbInd][pixInd] >> innerInd) & 3;
if (c != 0) {
uint8 innerInd_ = ((screenBufferInnerX[sbInd] + x) & 3) * 2;
uint8 c_ = (screenBuffers[sbInd][pixInd] >> innerInd_) & 3;
if (c_ > c) {
#if 0
backbuffer[x] = palette[3 - 3 * i / ghostCount];
#else
uint8 r = palettes[paletteIndex][c * 3 + 0];
uint8 g = palettes[paletteIndex][c * 3 + 1];
uint8 b = palettes[paletteIndex][c * 3 + 2];
r = r + (palettes[paletteIndex][0] - r) * i / ghostCount;
g = g + (palettes[paletteIndex][1] - g) * i / ghostCount;
b = b + (palettes[paletteIndex][2] - b) * i / ghostCount;
uint8 r = palettes[paletteIndex][c_ * 3 + 0];
uint8 g = palettes[paletteIndex][c_ * 3 + 1];
uint8 b = palettes[paletteIndex][c_ * 3 + 2];
r = r + (palettes[paletteIndex][c * 3 + 0] - r) * i / ghostCount;
g = g + (palettes[paletteIndex][c * 3 + 1] - g) * i / ghostCount;
b = b + (palettes[paletteIndex][c * 3 + 2] - b) * i / ghostCount;
backbuffer[x] = mapRGB(r, g, b);
#endif
break;
}
}
}
else {
screenBuffers[curSB][pixInd] |= c << innerInd;
}
screenBuffers[curSB][pixInd] |= c << innerInd;
}

if (lineCount == SV_H - 1) {
Expand Down
145 changes: 87 additions & 58 deletions common/m6502/m6502.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/** Alex Krasivsky 1996 **/
/** Steve Nickolas 2002 **/
/** Portions by Holger Picker 2002 **/
/** ADC and SBC instructions provided by Scott Hemphill **/
/** You are not allowed to distribute this software **/
/** commercially. Please, notify me, if you make any **/
/** changes to this file. **/
Expand Down Expand Up @@ -115,64 +116,43 @@
#define M_TRB(Data) R->P = (R->P & ~Z_FLAG) | ((Data & R->A) == 0 ? Z_FLAG : 0); \
Data &= ~R->A;

#ifdef NO_DECIMAL

#define M_ADC(Rg) \
K.W=R->A+Rg+(R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=(~(R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? C_FLAG:0)|ZNTable[K.B.l]; \
R->A=K.B.l

/* Warning! C_FLAG is inverted before SBC and after it */
#define M_SBC(Rg) \
K.W=R->A-Rg-(~R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=((R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? 0:C_FLAG)|ZNTable[K.B.l]; \
R->A=K.B.l

#else /* NO_DECIMAL */

#define M_ADC(Rg) \
if(R->P&D_FLAG) \
{ \
K.B.l=(R->A&0x0F)+(Rg&0x0F)+(R->P&C_FLAG); \
if(K.B.l>9) K.B.l+=6; \
K.B.h=(R->A>>4)+(Rg>>4)+(K.B.l>15? 1:0); \
R->A=(K.B.l&0x0F)|(K.B.h<<4); \
R->P=(R->P&~C_FLAG)|(K.B.h>15? C_FLAG:0); \
} \
else \
{ \
K.W=R->A+Rg+(R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=(~(R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? C_FLAG:0)|ZNTable[K.B.l]; \
R->A=K.B.l; \
}

/* Warning! C_FLAG is inverted before SBC and after it */
#define M_SBC(Rg) \
if(R->P&D_FLAG) \
{ \
K.B.l=(R->A&0x0F)-(Rg&0x0F)-(~R->P&C_FLAG); \
if(K.B.l&0x10) K.B.l-=6; \
K.B.h=(R->A>>4)-(Rg>>4)-((K.B.l&0x10)>>4); \
if(K.B.h&0x10) K.B.h-=6; \
R->A=(K.B.l&0x0F)|(K.B.h<<4); \
R->P=(R->P&~C_FLAG)|(K.B.h>15? 0:C_FLAG); \
} \
else \
{ \
K.W=R->A-Rg-(~R->P&C_FLAG); \
R->P&=~(N_FLAG|V_FLAG|Z_FLAG|C_FLAG); \
R->P|=((R->A^Rg)&(R->A^K.B.l)&0x80? V_FLAG:0)| \
(K.B.h? 0:C_FLAG)|ZNTable[K.B.l]; \
R->A=K.B.l; \
}

#endif /* NO_DECIMAL */

/* The following code was provided by Mr. Scott Hemphill. Thanks a lot! */
#define M_ADC(Rg) \
{ \
register unsigned int w; \
if ((R->A ^ Rg) & 0x80) { \
R->P &= ~V_FLAG; } \
else { \
R->P |= V_FLAG; } \
if (R->P&D_FLAG) { \
w = (R->A & 0xf) + (Rg & 0xf) + (R->P & C_FLAG); \
if (w >= 10) w = 0x10 | ((w+6)&0xf); \
w += (R->A & 0xf0) + (Rg & 0xf0); \
if (w >= 160) { \
R->P |= C_FLAG; \
if ((R->P&V_FLAG) && w >= 0x180) R->P &= ~ V_FLAG; \
w += 0x60; \
} else { \
R->P &= ~C_FLAG; \
if ((R->P&V_FLAG) && w < 0x80) R->P &= ~V_FLAG; \
} \
} else { \
w = R->A + Rg + (R->P&C_FLAG); \
if (w >= 0x100) { \
R->P |= C_FLAG; \
if ((R->P & V_FLAG) && w >= 0x180) R->P &= ~V_FLAG; \
} else { \
R->P &= ~C_FLAG; \
if ((R->P&V_FLAG) && w < 0x80) R->P &= ~V_FLAG; \
} \
} \
R->A = (unsigned char)w; \
R->P = (R->P & ~(Z_FLAG | N_FLAG)) | (R->A >= 0x80 ? N_FLAG : 0) | (R->A == 0 ? Z_FLAG : 0); \
}


#define M_SBC(Rg) SBCInstruction(R, Rg)


#define M_CMP(Rg1,Rg2) \
Expand All @@ -198,6 +178,55 @@
R->P&=~C_FLAG;R->P|=Rg&C_FLAG;Rg=K.B.l; \
M_FL(Rg)

/* The following code was provided by Mr. Scott Hemphill. Thanks a lot again! */
static void SBCInstruction(M6502 *R, register unsigned char val) {
register unsigned int w;
register unsigned int temp;

if ((R->A ^ val) & 0x80) {
R->P |= V_FLAG;
}
else {
R->P &= ~V_FLAG;
}

if (R->P&D_FLAG) { /* decimal subtraction */
temp = 0xf + (R->A & 0xf) - (val & 0xf) + (R->P & C_FLAG);
if (temp < 0x10) {
w = 0;
temp -= 6;
}
else {
w = 0x10;
temp -= 0x10;
}
w += 0xf0 + (R->A & 0xf0) - (val & 0xf0);
if (w < 0x100) {
R->P &= ~C_FLAG;
if ((R->P&V_FLAG) && w < 0x80) R->P &= ~V_FLAG;
w -= 0x60;
}
else {
R->P |= C_FLAG;
if ((R->P&V_FLAG) && w >= 0x180) R->P &= ~V_FLAG;
}
w += temp;
}
else { /* standard binary subtraction */
w = 0xff + R->A - val + (R->P&C_FLAG);
if (w < 0x100) {
R->P &= ~C_FLAG;
if ((R->P & V_FLAG) && w < 0x80) R->P &= ~V_FLAG;
}
else {
R->P |= C_FLAG;
if ((R->P&V_FLAG) && w >= 0x180) R->P &= ~V_FLAG;
}
}
R->A = (unsigned char)w;
R->P = (R->P & ~(Z_FLAG | N_FLAG)) | (R->A >= 0x80 ? N_FLAG : 0) | (R->A == 0 ? Z_FLAG : 0);
} /* SBCinstruction */

/** Reset6502() **********************************************/
/** This function can be used to reset the registers before **/
/** starting execution with Run6502(). It sets registers to **/
Expand Down
Loading

0 comments on commit 219e45d

Please sign in to comment.