games/md: add shadow/hilight support

This commit is contained in:
aiju 2014-06-15 19:02:06 +02:00
parent 838163670c
commit 1bacbf5651
2 changed files with 43 additions and 11 deletions

View file

@ -52,6 +52,7 @@ enum {
IE0 = 0x20, IE0 = 0x20,
IE1 = 0x10, IE1 = 0x10,
DMAEN = 0x10, DMAEN = 0x10,
SHI = 0x08,
WIDE = 0x01, WIDE = 0x01,

View file

@ -9,7 +9,8 @@ u16int vdpstat = 0x3400;
int vdpx, vdpy; int vdpx, vdpy;
u16int hctr; u16int hctr;
static int xmax, xdisp, ymax = 262, yvbl = 234; static int xmax, xdisp, ymax = 262, yvbl = 234;
static int sx, snx, col, pri; static int sx, snx, col, pri, lum;
enum { DARK, NORM, BRIGHT };
void void
vdpmode(void) vdpmode(void)
@ -53,6 +54,16 @@ pixeldraw(int x, int y, int v)
} }
} }
static u32int
shade(u32int v, int l)
{
if(l == 1)
return v;
if(l == 2)
return v << 1 & 0xefefef;
return v >> 1 & 0xf7f7f7;
}
static void static void
pixel(int v, int p) pixel(int v, int p)
{ {
@ -153,7 +164,7 @@ planeinit(void)
} }
static void static void
plane(int n, int w) plane(int n, int vis)
{ {
struct pctxt *p; struct pctxt *p;
u8int v, pr; u8int v, pr;
@ -166,10 +177,13 @@ plane(int n, int w)
v = p->c >> 28; v = p->c >> 28;
p->c <<= 4; p->c <<= 4;
} }
if(v != 0 && w != 0){ if(vis != 0){
v |= p->t >> 9 & 48; if(v != 0){
pr = 2 - (n & 1) + (p->t >> 13 & 4); v |= p->t >> 9 & 48;
pixel(v, pr); pr = 2 - (n & 1) + (p->t >> 13 & 4);
pixel(v, pr);
}
lum |= p->t >> 15;
} }
if(++p->tnx == 8){ if(++p->tnx == 8){
p->tnx = 0; p->tnx = 0;
@ -288,15 +302,28 @@ sprites(void)
else{ else{
set = 1 | p->t & 0x8000; set = 1 | p->t & 0x8000;
col = p->t >> 9 & 48 | v; col = p->t >> 9 & 48 | v;
} }
} }
if(set) if(set)
pixel(col, set >> 13 | 2); if((reg[MODE4] & SHI) != 0)
if((col & 0xfe) == 0x3e)
lum = col & 1;
else{
pixel(col, set >> 13 | 2);
if((col & 0xf) == 0xe)
lum = 1;
else
lum |= set >> 15;
}
else
pixel(col, set >> 13 | 2);
} }
void void
vdpstep(void) vdpstep(void)
{ {
u32int v;
if(vdpx == 0){ if(vdpx == 0){
planeinit(); planeinit();
spritesinit(); spritesinit();
@ -305,11 +332,15 @@ vdpstep(void)
if(vdpx < xdisp){ if(vdpx < xdisp){
col = reg[BGCOL] & 0x3f; col = reg[BGCOL] & 0x3f;
pri = 0; pri = 0;
lum = 0;
planes(); planes();
sprites(); sprites();
if((reg[MODE2] & 0x40) != 0 && (vdpx >= 8 || (reg[MODE1] & 0x20) == 0)) if((reg[MODE2] & 0x40) != 0 && (vdpx >= 8 || (reg[MODE1] & 0x20) == 0)){
pixeldraw(vdpx, vdpy, cramc[col]); v = cramc[col];
else if((reg[MODE4] & SHI) != 0)
v = shade(v, lum);
pixeldraw(vdpx, vdpy, v);
}else
pixeldraw(vdpx, vdpy, 0); pixeldraw(vdpx, vdpy, 0);
}else }else
pixeldraw(vdpx, vdpy, 0xcccccc); pixeldraw(vdpx, vdpy, 0xcccccc);