Skip to content

Commit

Permalink
sms, basic gamegear support
Browse files Browse the repository at this point in the history
  • Loading branch information
irixxxx committed Oct 14, 2021
1 parent 0df7401 commit 466fa07
Show file tree
Hide file tree
Showing 16 changed files with 449 additions and 212 deletions.
106 changes: 57 additions & 49 deletions pico/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void blockcpy_or(void *dst, void *src, size_t n, int pat)
for (; n; n--)
*pd++ = (unsigned char) (*ps++ | pat);
}
#define blockcpy memcpy
#define blockcpy memmove
#endif

#define TileNormMaker_(pix_func,ret) \
Expand Down Expand Up @@ -1642,21 +1642,28 @@ void FinalizeLine555(int sh, int line, struct PicoEState *est)

PicoDrawUpdateHighPal();

if (Pico.video.reg[12]&1) {
len = 320;
} else {
len = 256;
}

if ((*est->PicoOpt & POPT_EN_SOFTSCALE) && len == 256) {
switch (PicoIn.filter) {
case 3: h_upscale_bl4_4_5(pd, 320, ps, 256, 256, f_pal); break;
case 2: h_upscale_bl2_4_5(pd, 320, ps, 256, 256, f_pal); break;
case 1: h_upscale_snn_4_5(pd, 320, ps, 256, 256, f_pal); break;
default: h_upscale_nn_4_5(pd, 320, ps, 256, 256, f_pal); break;
}
if ((PicoIn.AHW & PAHW_SMS) && (Pico.m.hardware & 0x3) == 0x3)
len = 160;
else if (Pico.video.reg[12]&1) len = 320;
else len = 256;

if ((*est->PicoOpt & POPT_EN_SOFTSCALE) && len < 320) {
if (len == 256)
switch (PicoIn.filter) {
case 3: h_upscale_bl4_4_5(pd, 320, ps, 256, len, f_pal); break;
case 2: h_upscale_bl2_4_5(pd, 320, ps, 256, len, f_pal); break;
case 1: h_upscale_snn_4_5(pd, 320, ps, 256, len, f_pal); break;
default: h_upscale_nn_4_5(pd, 320, ps, 256, len, f_pal); break;
}
else if (len == 160)
switch (PicoIn.filter) {
case 3:
case 2: h_upscale_bl2_1_2(pd, 320, ps, 160, len, f_pal); break;
default: h_upscale_nn_1_2(pd, 320, ps, 160, len, f_pal); break;
}
} else {
if (!(*est->PicoOpt & POPT_DIS_32C_BORDER) && len == 256) pd += 32;
if (!(*est->PicoOpt & POPT_DIS_32C_BORDER) && len < 320)
pd += (320-len) / 2;
#if 1
h_copy(pd, 320, ps, 320, len, f_pal);
#else
Expand All @@ -1670,18 +1677,19 @@ void FinalizeLine555(int sh, int line, struct PicoEState *est)
}
#endif

static void FinalizeLine8bit(int sh, int line, struct PicoEState *est)
void FinalizeLine8bit(int sh, int line, struct PicoEState *est)
{
unsigned char *pd = est->DrawLineDest;
unsigned char *ps = est->HighCol+8;
int len;
static int dirty_line;

if (Pico.m.dirtyPal == 1)
{
// a hack for mid-frame palette changes
if (!(est->rendstatus & PDRAW_SONIC_MODE) | (line - dirty_line > 4)) {
// store a maximum of 2 additional palettes in SonicPal
if (est->SonicPalCount < 2)
// store a maximum of 3 additional palettes in SonicPal
if (est->SonicPalCount < 3)
est->SonicPalCount ++;
dirty_line = line;
est->rendstatus |= PDRAW_SONIC_MODE;
Expand All @@ -1690,35 +1698,33 @@ static void FinalizeLine8bit(int sh, int line, struct PicoEState *est)
Pico.m.dirtyPal = 2;
}

if (Pico.video.reg[12]&1) {
len = 320;
} else {
len = 256;
}
if ((PicoIn.AHW & PAHW_SMS) && (Pico.m.hardware & 0x3) == 0x3)
len = 160;
else if (Pico.video.reg[12]&1) len = 320;
else len = 256;

if (DrawLineDestIncrement == 0)
pd = est->HighCol+8;

if ((PicoIn.opt & POPT_EN_SOFTSCALE) && len == 256) {
unsigned char *ps = est->HighCol+8;
if ((PicoIn.opt & POPT_EN_SOFTSCALE) && len < 320) {
unsigned char pal = 0;

if (!sh && (est->rendstatus & PDRAW_SONIC_MODE))
pal = est->SonicPalCount*0x40;
if (DrawLineDestIncrement == 0)
pd = est->HighCol+8;
// Smoothing can't be used with CLUT, hence it's always Nearest Neighbour.
// use reverse version since src and dest ptr may be the same.
rh_upscale_nn_4_5(pd, 320, ps, 256, len, f_or);
} else if (DrawLineDestIncrement == 0) {
if (!sh && (est->rendstatus & PDRAW_SONIC_MODE))
blockcpy_or(est->HighCol+8, est->HighCol+8, len, est->SonicPalCount*0x40);
if (len == 256)
// use reverse version since src and dest ptr may be the same.
rh_upscale_nn_4_5(pd, 320, ps, 256, len, f_or);
else
rh_upscale_nn_1_2(pd, 320, ps, 256, len, f_or);
} else {
if (!(PicoIn.opt & POPT_DIS_32C_BORDER))
pd += 32;
if (!sh && (est->rendstatus & PDRAW_SONIC_MODE)) {
if (!(*est->PicoOpt & POPT_DIS_32C_BORDER) && len < 320)
pd += (320-len) / 2;
if (!sh && (est->rendstatus & PDRAW_SONIC_MODE))
// select active backup palette
blockcpy_or(pd, est->HighCol+8, len, est->SonicPalCount*0x40);
} else {
blockcpy(pd, est->HighCol+8, len);
}
blockcpy_or(pd, ps, len, est->SonicPalCount*0x40);
else if (pd != ps)
blockcpy(pd, ps, len);
}
}

Expand Down Expand Up @@ -1893,32 +1899,34 @@ PICO_INTERNAL void PicoFrameStart(void)

static void DrawBlankedLine(int line, int offs, int sh, int bgc)
{
if (PicoScanBegin != NULL)
PicoScanBegin(line + offs);
int skip = skip_next_line;

if (PicoScanBegin != NULL && skip == 0)
skip = PicoScanBegin(line + offs);

if (skip) {
skip_next_line = skip - 1;
return;
}

BackFill(bgc, sh, &Pico.est);

if (FinalizeLine != NULL)
FinalizeLine(sh, line, &Pico.est);

if (PicoScanEnd != NULL)
PicoScanEnd(line + offs);
skip_next_line = PicoScanEnd(line + offs);

Pico.est.HighCol += HighColIncrement;
Pico.est.DrawLineDest = (char *)Pico.est.DrawLineDest + DrawLineDestIncrement;
}

static void PicoLine(int line, int offs, int sh, int bgc)
{
int skip = 0;

if (skip_next_line > 0) {
skip_next_line--;
return;
}
int skip = skip_next_line;

Pico.est.DrawScanline = line;
if (PicoScanBegin != NULL)
if (PicoScanBegin != NULL && skip == 0)
skip = PicoScanBegin(line + offs);

if (skip) {
Expand Down
Loading

0 comments on commit 466fa07

Please sign in to comment.