diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index b6c926de..28e1e645 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -1303,6 +1303,10 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) ClientToScreen(hAppWnd, (LPPOINT) &pt); //Convert client area x,y to screen x,y TrackPopupMenu(hfceuxcontextsub,0,(pt.x),(pt.y),TPM_RIGHTBUTTON,hWnd,0); //Create menu } + else + { + mouseb=wParam; + } } case WM_MOVE: diff --git a/src/input/zapper.cpp b/src/input/zapper.cpp index 96095522..9f27eb5f 100644 --- a/src/input/zapper.cpp +++ b/src/input/zapper.cpp @@ -76,16 +76,52 @@ static void ZapperFrapper(int w, uint8 *bg, uint8 *spr, uint32 linets, int final } endo: ZD[w].zappo=final; + + //if this was a miss, clear out the hit + if(ZD[w].mzb&2) + ZD[w].zaphit=0; + } static INLINE int CheckColor(int w) { FCEUPPU_LineUpdate(); - if((ZD[w].zaphit+100)>=(timestampbase+timestamp) - && !(ZD[w].mzb&2)) return(0); + if(newppu) + { + int x = (int)ZD[w].mzx; + int y = (int)ZD[w].mzy; + int b = (int)ZD[w].mzb; + bool block = (b&2)!=0; - return(1); + int mousetime = y*256+x; + int nowtime = scanline*256 + g_rasterpos; + + if(!block && mousetime < nowtime && mousetime >= nowtime - 384) + { + extern uint8 *XBuf; + uint8 *pix = XBuf+(ZD[w].mzy<<8); + uint8 a1 = pix[ZD[w].mzx]; + a1&=63; + uint32 sum=palo[a1].r+palo[a1].g+palo[a1].b; + //return ZD[w].zaphit = sum != 0; + ZD[w].zaphit = (sum>=100*3)?1:0; + } + else + { + ZD[w].zaphit = 0; + } + + return ZD[w].zaphit?0:1; + } + + + if((ZD[w].zaphit+100)>=(timestampbase+timestamp)) + { + return 0; + } + + return 1; } static uint8 ReadZapperVS(int w) @@ -133,14 +169,25 @@ static void UpdateZapper(int w, void *data, int arg) { uint32 *ptr=(uint32 *)data; - if(ZD[w].bogo) - ZD[w].bogo--; - if(ptr[2]&3 && (!(ZD[w].mzb&3))) - ZD[w].bogo=5; + bool newclicked = (ptr[2]&3)!=0; + bool oldclicked = (ZD[w].lastInput)!=0; + + if(ZD[w].bogo) + { + ZD[w].bogo--; + } + + ZD[w].lastInput = ptr[2]&3; + + //woah.. this looks like broken bit logic. + if(newclicked && !oldclicked) + { + ZD[w].bogo=5; + ZD[w].mzb=ptr[2]; + ZD[w].mzx=ptr[0]; + ZD[w].mzy=ptr[1]; + } - ZD[w].mzx=ptr[0]; - ZD[w].mzy=ptr[1]; - ZD[w].mzb=ptr[2]; } static void LogZapper(int w, MovieRecord* mr) diff --git a/src/input/zapper.h b/src/input/zapper.h index bffac43d..a106294f 100644 --- a/src/input/zapper.h +++ b/src/input/zapper.h @@ -10,6 +10,7 @@ struct ZAPPER uint8 bogo; int zappo; uint64 zaphit; + uint32 lastInput; }; #endif diff --git a/src/ppu.cpp b/src/ppu.cpp index d2cdd402..e9f3d0f4 100644 --- a/src/ppu.cpp +++ b/src/ppu.cpp @@ -345,6 +345,7 @@ static int maxsprites=8; //scanline is equal to the current visible scanline we're on. int scanline; +int g_rasterpos; static uint32 scanlines_per_frame; uint8 PPU[4]; @@ -2244,6 +2245,7 @@ int FCEUX_PPU_Loop(int skip) { for(int sl=0;sl<241;sl++) { spr_read.start_scanline(); + g_rasterpos = 0; ppur.status.sl = sl; const int yp = sl-1; @@ -2270,7 +2272,6 @@ int FCEUX_PPU_Loop(int skip) { for(int xt=0;xt<32;xt++) { bgdata.main[xt+2].Read(); - //ok, we're also going to draw here. //unless we're on the first dummy scanline if(sl != 0) { @@ -2283,7 +2284,7 @@ int FCEUX_PPU_Loop(int skip) { //check all the conditions that can cause things to render in these 8px const bool renderspritenow = SpriteON && rendersprites && (xt>0 || SpriteLeft8); const bool renderbgnow = ScreenON && renderbg && (xt>0 || BGLeft8); - for(int xp=0;xp<8;xp++,rasterpos++) { + for(int xp=0;xp<8;xp++,rasterpos++,g_rasterpos++) { //bg pos is different from raster pos due to its offsetability. //so adjust for that here @@ -2518,7 +2519,8 @@ int FCEUX_PPU_Loop(int skip) { //first one on every second frame, then this delay simply doesn't exist. if (ppur.status.end_cycle == 341) runppu(1); - } + + } //scanline loop if(MMC5Hack && PPUON) MMC5_hb(240); diff --git a/src/ppu.h b/src/ppu.h index 0e15114d..9d855291 100644 --- a/src/ppu.h +++ b/src/ppu.h @@ -33,6 +33,7 @@ extern uint8 FASTCALL FFCEUX_PPURead_Default(uint32 A); void FFCEUX_PPUWrite_Default(uint32 A, uint8 V); extern int scanline; +extern int g_rasterpos; extern uint8 PPU[4]; enum PPUPHASE {