Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
Snes: Secret of Mana 2
SS: Die Hard Arcade
  • Loading branch information
psakhis committed Nov 12, 2022
1 parent 46ae9b7 commit da1154f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
20 changes: 10 additions & 10 deletions mednafen/src/drivers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,11 +1404,11 @@ static int GameLoop(void *arg)
else
MDFNI_Emulate(&espec);

//psakhis: activate change on switch thread
if (resolution_to_change && (use_native_resolution || use_super_resolution || use_switchres)) {
NeedResolutionChange++; //redundant
//psakhis: activate change on switch thread
if (!NeedResolutionChange && resolution_to_change && (use_native_resolution || use_super_resolution || use_switchres)) {
NeedResolutionChange++; //redundant only if not changing
MThreading::Sem_Post(STWakeupSem);
resolution_to_change = false;
resolution_to_change = false;
}
//psakhis end

Expand Down Expand Up @@ -1500,13 +1500,13 @@ static int SwitchLoop(void *arg)
{
if ((current_game_resolution_w != resolution_to_change_w) || (current_game_resolution_h != resolution_to_change_h)) {
printf("SWITCH - Activated - Current resolution %dx%d - Changing to %dx%d@%f\n",current_game_resolution_w,current_game_resolution_h,resolution_to_change_w,resolution_to_change_h,resolution_to_change_vfreq);
NeedResolutionRefresh = Video_ChangeResolution(CurGame,resolution_to_change_w,resolution_to_change_h,resolution_to_change_vfreq);
NeedResolutionRefresh = Video_ChangeResolution(CurGame,resolution_to_change_w,resolution_to_change_h,resolution_to_change_vfreq);
}
else {
printf("SWITCH - Activated - Bypassed from %dx%d@%f\n",resolution_to_change_w,resolution_to_change_h,resolution_to_change_vfreq);
//printf("SWITCH - Activated - Bypassed from %dx%d@%f\n",resolution_to_change_w,resolution_to_change_h,resolution_to_change_vfreq);
NeedResolutionChange--;
}
}
}
}
}
}

Expand Down Expand Up @@ -2451,13 +2451,13 @@ for(int zgi = 1; zgi < argc; zgi++)// start game load test loop
//
NeedVideoSync = 0;
}
// SLK + psakhis
// SLK + psakhis
if(MDFN_LIKELY(NeedResolutionChange) && MDFN_LIKELY(NeedResolutionRefresh))
{
printf("MAIN - VIDEO - Refresh blitter after a resolution change\n");
Video_BlitRefresh();
NeedResolutionChange--;
NeedResolutionRefresh--;
NeedResolutionRefresh--;
}
// SLK + psakhis END

Expand Down
11 changes: 8 additions & 3 deletions mednafen/src/drivers/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,10 +918,11 @@ int Video_ChangeResolution(MDFNGI *gi, int w, int h, double vfreq)
int sr_x_scale_before_switch = sr_x_scale;
int xres_before_switch = video_settings.xres;
Video_SetSwitchres(w,h,vfreq);

if (video_settings.xres == xres_before_switch && h == current_game_resolution_h) { //no switch requiered
current_game_resolution_w = w;
printf(" VIDEO - Video_ChangeResolution - Switchres resolution change bypassed. Only apply scaling scale (%d,%d) \n",sr_x_scale,sr_y_scale);
MarkNeedBBClear();
MarkNeedBBClear();
return (sr_x_scale_before_switch != sr_x_scale);
}
current_game_resolution_w = w;
Expand Down Expand Up @@ -1003,7 +1004,7 @@ int Video_ChangeResolution(MDFNGI *gi, int w, int h, double vfreq)
default: SMDRect.y = video_settings.yres - SMDRect.h - 64;
}
SMDRect.w = video_settings.xres; // OSD rect w

return 1;

}
Expand Down Expand Up @@ -2288,11 +2289,15 @@ void BlitScreen(MDFN_Surface *msurface, const MDFN_Rect *DisplayRect, const int3
}
else
{
// printf(" src_rect: %dx%d - X:%d, cmdY:%d rect.x %d\n",src_rect.w,src_rect.h,src_rect.x,src_rect.y,screen_dest_rect.x);
//printf(" src_rect: %dx%d - X:%d, cmdY:%d rect.x %d\n",src_rect.w,src_rect.h,src_rect.x,src_rect.y,screen_dest_rect.x);
sub_dest_rect.x = screen_dest_rect.x;
sub_dest_rect.w = screen_dest_rect.w;
sub_dest_rect.y = screen_dest_rect.y + (last_y - src_rect.y) * screen_dest_rect.h / src_rect.h;
sub_dest_rect.h = sub_src_rect.h * screen_dest_rect.h / src_rect.h;

//printf(" Output - PSAKHIS sub_src_rect: %dx%d %d,%d\n",sub_src_rect.w,sub_src_rect.h,sub_src_rect.x,sub_src_rect.y);
//printf(" Output - PSAKHIS sub_dest_rect: %dx%d %d,%d\n",sub_dest_rect.w,sub_dest_rect.h,sub_dest_rect.x,sub_dest_rect.y);
//printf(" Output - PSAKHIS sub_screen_rect: %dx%d %d,%d\n",screen_dest_rect.w,screen_dest_rect.h,screen_dest_rect.x,screen_dest_rect.y);
}

if(!sub_dest_rect.h) // May occur with small yscale values in certain cases, so prevent triggering an assert()
Expand Down
27 changes: 22 additions & 5 deletions mednafen/src/snes/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ static std::vector<uint32> ColorMap; // [32768]
int prev_resolution_w;
int prev_resolution_h;
// SLK - end
// PSAKHIS
int max_resolution_w;
// PSAKHIS - end

static void BuildColorMap(MDFN_PixelFormat &format, uint8* CustomColorMap)
{
Expand Down Expand Up @@ -133,6 +136,7 @@ static INLINE uint32 BlendFunc(const uint32 pp, const uint32 p, const uint32 pn)

void bSNES_v059::Interface::video_scanline(uint16_t *data, unsigned line, unsigned width, unsigned height, bool interlaced, bool field)
{

const int ppline = PrevLine;

//if(rand() & 1)
Expand Down Expand Up @@ -213,6 +217,17 @@ void bSNES_v059::Interface::video_scanline(uint16_t *data, unsigned line, unsign

tlw[(y << interlaced) + field] = width;
tdr->w = width;

//PSAKHIS
if (line <= 1) {
max_resolution_w = 0;
}
if (width > max_resolution_w)
{
max_resolution_w = width;
}
//END PSAKHIS

tdr->h = height << interlaced;

es->InterlaceOn = interlaced;
Expand Down Expand Up @@ -910,13 +925,15 @@ static void Emulate(EmulateSpecStruct *espec)
bSNES_v059::ppu.enable_renderer(true);

// SLK - guess SNES active resolution
//printf("SNES Interface - Emulate - %dx%d - %d,%d\n",tdr->w,tdr->h,tdr->x,tdr->y);
if(tdr->h > 10 && tdr->w > 10 && tdr->w != prev_resolution_w)
//printf("SNES Interface - Emulate - %dx%d - %d,%d, (%d)\n",tdr->w,tdr->h,tdr->x,tdr->y,max_resolution_w);
// PSAKHIS
// replace tdr->w from line to w frame
if(tdr->h > 10 && max_resolution_w > 10 && max_resolution_w != prev_resolution_w)
{
resolution_to_change = true;
resolution_to_change_w = tdr->w;
resolution_to_change = true;
resolution_to_change_w = max_resolution_w;
}
if(tdr->h > 10 && tdr->w > 10 && tdr->h != prev_resolution_h)
if(tdr->h > 10 && max_resolution_w > 10 && tdr->h != prev_resolution_h)
{
resolution_to_change = true;
if(tdr->h <= 400)
Expand Down
8 changes: 4 additions & 4 deletions mednafen/src/snes_faust/ppu_common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1029,13 +1029,13 @@ static uint32 PPU_Update(uint32 timestamp)
if(!SkipFrame)
PPU_MTRENDER::MTIF_ResetLineTarget(PAL, InterlaceOnSample, (bool)(Status[1] & 0x80));
}

if(MDFN_LIKELY(!VBlank))
{
{
if(scanline > 0 && scanline < 240 && !SkipFrame)
{
PPU_MTRENDER::MTIF_RenderLine(scanline);
}
}
}

LineCounter += 534 - RenderLineDelay;
Expand Down Expand Up @@ -1387,7 +1387,7 @@ void PPU_StartFrame(EmulateSpecStruct* espec)
es->DisplayRect.h = SLDRH;
//
//
PPU_MTRENDER::MTIF_StartFrame(espec, HFilter);
PPU_MTRENDER::MTIF_StartFrame(espec, HFilter);
//
INPUT_UpdatePhysicalState();
}
Expand Down
21 changes: 19 additions & 2 deletions mednafen/src/ss/vdp2_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ static uint8 prev_VRes = 0;
static bool prev_BorderMode = 0;
// SLK end

//PSAKHIS
static bool prob_false_change = false; //reduce false positive changes
// PSAKHIS end

//
static struct
{
Expand Down Expand Up @@ -562,7 +566,19 @@ static INLINE void RegsWrite(uint32 A, uint16 V)
VRes = (V >> 4) & 0x3;
HRes = (V >> 0) & 0x7;
// SLK
if(InterlaceMode != prev_InterlaceMode || HRes != prev_HRes)
//PSAKHIS
if(InterlaceMode == prev_InterlaceMode && (HRes < prev_HRes && !prob_false_change))
{
printf("VDP2 Render - Television mode changed?: %d\n",V);
prob_false_change = true;
}
else
{
prob_false_change = false;
}
//END PSAKHIS
//if(InterlaceMode != prev_InterlaceMode || HRes != prev_HRes)
if(InterlaceMode != prev_InterlaceMode || (HRes != prev_HRes && !prob_false_change)) //psakhis: only change if a valid hres for more than 1
{
printf("VDP2 Render - Television mode changed: %d\n",V);
printf(" BorderMode: %d\n",BorderMode);
Expand All @@ -573,7 +589,8 @@ static INLINE void RegsWrite(uint32 A, uint16 V)
prev_BorderMode = BorderMode;
prev_InterlaceMode = InterlaceMode;
prev_VRes = VRes;
prev_HRes = HRes;
prev_HRes = HRes;
prob_false_change = false; //Psakhis reduce false positives
// HRES
switch(HRes){
case 0:
Expand Down

0 comments on commit da1154f

Please sign in to comment.