diff --git a/mylittle-nocomment/Gfx #1.3.h b/mylittle-nocomment/Gfx #1.3.h index 0ad9b00..5449224 100644 --- a/mylittle-nocomment/Gfx #1.3.h +++ b/mylittle-nocomment/Gfx #1.3.h @@ -143,6 +143,8 @@ EXPORT void CALL DllTest ( HWND hParent ); EXPORT void CALL ReadScreen(void **dest, long *width, long *height); +EXPORT void CALL DllCrtFree(void *p); // mupen specific + /****************************************************************** Function: DrawScreen Purpose: This function is called when the emulator receives a diff --git a/mylittle-nocomment/main.cpp b/mylittle-nocomment/main.cpp index 7ebfa50..a0097ed 100644 --- a/mylittle-nocomment/main.cpp +++ b/mylittle-nocomment/main.cpp @@ -1,16 +1,21 @@ #include "z64.h" #include "Gfx #1.3.h" +#include "shlwapi.h" extern const int screen_width = 1024, screen_height = 768; LPDIRECTDRAW7 lpdd = 0; -LPDIRECTDRAWSURFACE7 lpddsprimary; +LPDIRECTDRAWSURFACE7 lpddsprimary; LPDIRECTDRAWSURFACE7 lpddsback; DDSURFACEDESC2 ddsd; HRESULT res; RECT dst, src; INT32 pitchindwords; +UINT32 FrameBuffer[PRESCALE_WIDTH * PRESCALE_HEIGHT]; +UINT32 FinalizedFrameBuffer[PRESCALE_WIDTH * PRESCALE_HEIGHT]; +extern int oldlowerfield; + FILE* zeldainfo = 0; int ProcessDListShown = 0; extern int SaveLoaded; @@ -25,80 +30,158 @@ void rdp_process_list(void); extern INLINE void popmessage(const char* err, ...); extern INLINE void fatalerror(const char* err, ...); - -EXPORT void CALL CaptureScreen ( char * Directory ) +static char config_path[MAX_PATH + 1] = { 0 }; +static BOOL BobDeinterlacer = TRUE; +static const char* WeaveActiveStr = "Do you want to switch the AVI deinterlacer from Weave to Bob?"; +static const char* BobActiveStr = "Do you want to switch the AVI deinterlacer from Bob to Weave?"; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { + if (fdwReason == DLL_PROCESS_ATTACH) + { + GetModuleFileName(hinstDLL, config_path, sizeof(config_path)); + PathRemoveFileSpec(config_path); + PathAppend(config_path, "mylittle_config.bin"); + FILE* f = fopen(config_path, "r+b"); + if (!f) + { + BobDeinterlacer = TRUE; + f = fopen(config_path, "wb"); + if (!f) + { + popmessage("Unable to create config file"); + } + else + { + UINT8 i = TRUE; + fwrite(&i, 1, 1, f); + fclose(f); + } + } + else + { + UINT8 o = TRUE; + fread(&o, 1, 1, f); + BobDeinterlacer = !!o; + fclose(f); + } + } + return TRUE; } - -EXPORT void CALL ChangeWindow (void) +EXPORT void CALL CaptureScreen(char* Directory) { } - -EXPORT void CALL CloseDLL (void) + +EXPORT void CALL ChangeWindow(void) { - } - -EXPORT void CALL DllAbout ( HWND hParent ) + +EXPORT void CALL CloseDLL(void) { - popmessage("angrylion's RDP, unpublished beta. MESS source code used."); } - -EXPORT void CALL DllConfig ( HWND hParent ) + +EXPORT void CALL DllAbout(HWND hParent) { - popmessage("Nothing to configure"); + popmessage("angrylion's RDP, unpublished beta. MESS source code used."); } - -EXPORT void CALL DllTest ( HWND hParent ) +EXPORT void CALL DllConfig(HWND hParent) { + int res = MessageBoxA(0, BobDeinterlacer ? BobActiveStr : WeaveActiveStr, "Config", MB_YESNO | MB_ICONINFORMATION); + if (res == IDYES) + { + BobDeinterlacer = !BobDeinterlacer; + FILE* f = fopen(config_path, "wb"); + if (f) + { + UINT8 i = BobDeinterlacer; + fwrite(&i, 1, 1, f); + fclose(f); + } + else + { + popmessage("Unable to update config file"); + } + } } -UINT32 FrameBuffer[PRESCALE_WIDTH * PRESCALE_HEIGHT]; -EXPORT void CALL ReadScreen(void **dest, long *width, long *height) +EXPORT void CALL DllTest(HWND hParent) +{ +} + +EXPORT void CALL ReadScreen(void** dest, long* width, long* height) { UINT32 w = PRESCALE_WIDTH; UINT32 h = src.bottom; - if (h < 480) + if (h < 640) // progressive; double the height { - UINT32* s = FrameBuffer + (h - 1) * w; - UINT32* d = FrameBuffer + ((h * 2) - 1) * w; + UINT32* s = FrameBuffer; + UINT32* d = FinalizedFrameBuffer; + UINT32 dw = w * 2; for (UINT32 i = 0; i < h; i++) { - memcpy(d, s, w * sizeof (UINT32)); - memcpy(d - w, s, w * sizeof(UINT32)); - d -= w * 2; - s -= w; + memcpy(d, s, w * sizeof(UINT32)); + memcpy(d + w, s, w * sizeof(UINT32)); + s += w; + d += dw; } h *= 2; } + else // interlaced; deinterlace + { + if (BobDeinterlacer) + { + UINT32* s = FrameBuffer + oldlowerfield * w; + UINT32* d = FinalizedFrameBuffer; + UINT32 dw = w * 2; + UINT32 hh = h / 2; + for (UINT32 i = 0; i < hh; i++) + { + memcpy(d, s, w * sizeof(UINT32)); + memcpy(d + w, s, w * sizeof(UINT32)); + s += dw; + d += dw; + } + } + else // result is already weaved + { + UINT32* s = FrameBuffer; + UINT32* d = FinalizedFrameBuffer; + for (UINT32 i = 0; i < h; i++) + { + memcpy(d, s, w * sizeof(UINT32)); + s += w; + d += w; + } + } + } + *width = w; *height = h; *dest = malloc(w * h * 3); if (!*dest) { fatalerror("Could not allocate memory for ReadScreen()!"); - return; } - UINT32* fb = FrameBuffer + (h - 1) * w; + UINT32* finalfb = FinalizedFrameBuffer + w * (h - 1); UINT8* ret = (UINT8*)(*dest); for (UINT32 i = 0; i < h; i++) { for (UINT32 j = 0; j < w; j++) { UINT8* d = &ret[j * 3]; - UINT32 p = fb[j]; - d[0] = p >> 0 & 0xFF; - d[1] = p >> 8 & 0xFF; + UINT32 p = finalfb[j]; + d[0] = p >> 0 & 0xFF; + d[1] = p >> 8 & 0xFF; d[2] = p >> 16 & 0xFF; } - fb -= w; + finalfb -= w; ret += w * 3; } } @@ -109,36 +192,33 @@ EXPORT void CALL DllCrtFree(void* p) free(p); } - -EXPORT void CALL DrawScreen (void) + +EXPORT void CALL DrawScreen(void) { } - -EXPORT void CALL GetDllInfo ( PLUGIN_INFO * PluginInfo ) + +EXPORT void CALL GetDllInfo(PLUGIN_INFO* PluginInfo) { - PluginInfo->Version = 0x0103; - PluginInfo->Type = PLUGIN_TYPE_GFX; - sprintf (PluginInfo->Name, "My little plugin"); - - - - PluginInfo->NormalMemory = TRUE; - PluginInfo->MemoryBswaped = TRUE; + PluginInfo->Version = 0x0103; + PluginInfo->Type = PLUGIN_TYPE_GFX; + sprintf(PluginInfo->Name, "My little plugin"); + PluginInfo->NormalMemory = TRUE; + PluginInfo->MemoryBswaped = TRUE; } - + GFX_INFO gfx; -EXPORT BOOL CALL InitiateGFX (GFX_INFO Gfx_Info) +EXPORT BOOL CALL InitiateGFX(GFX_INFO Gfx_Info) { - gfx = Gfx_Info; - - return TRUE; + gfx = Gfx_Info; + + return TRUE; } - -EXPORT void CALL MoveScreen (int xpos, int ypos) + +EXPORT void CALL MoveScreen(int xpos, int ypos) { RECT statusrect; POINT p; @@ -148,17 +228,9 @@ EXPORT void CALL MoveScreen (int xpos, int ypos) OffsetRect(&dst, p.x, p.y); GetClientRect(gfx.hStatusBar, &statusrect); dst.bottom -= statusrect.bottom; - - - - - - - - } - + EXPORT void CALL ProcessDList(void) { if (!ProcessDListShown) @@ -168,21 +240,15 @@ EXPORT void CALL ProcessDList(void) } } - + EXPORT void CALL ProcessRDPList(void) { - - - - - - rdp_process_list(); return; } - -EXPORT void CALL RomClosed (void) + +EXPORT void CALL RomClosed(void) { rdp_close(); if (lpddsback) @@ -205,13 +271,13 @@ EXPORT void CALL RomClosed (void) command_counter = 0; } - -EXPORT void CALL RomOpen (void) + +EXPORT void CALL RomOpen(void) { RECT bigrect, smallrect, statusrect; - - GetWindowRect(gfx.hWnd,&bigrect); - GetClientRect(gfx.hWnd,&smallrect); + + GetWindowRect(gfx.hWnd, &bigrect); + GetClientRect(gfx.hWnd, &smallrect); int rightdiff = screen_width - smallrect.right; int bottomdiff = screen_height - smallrect.bottom; if (gfx.hStatusBar) @@ -220,29 +286,26 @@ EXPORT void CALL RomOpen (void) bottomdiff += statusrect.bottom; } MoveWindow(gfx.hWnd, bigrect.left, bigrect.top, bigrect.right - bigrect.left + rightdiff, bigrect.bottom - bigrect.top + bottomdiff, TRUE); - DDPIXELFORMAT ftpixel; LPDIRECTDRAWCLIPPER lpddcl; res = DirectDrawCreateEx(0, (LPVOID*)&lpdd, IID_IDirectDraw7, 0); - if(res != DD_OK) + if (res != DD_OK) fatalerror("Couldn't create a DirectDraw object"); res = IDirectDraw_SetCooperativeLevel(lpdd, gfx.hWnd, DDSCL_NORMAL); - if(res != DD_OK) + if (res != DD_OK) fatalerror("Couldn't set a cooperative level. Error code %x", res); memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - + res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsprimary, 0); - if(res != DD_OK) + if (res != DD_OK) fatalerror("CreateSurface for a primary surface failed. Error code %x", res); - ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = PRESCALE_WIDTH; @@ -258,10 +321,9 @@ EXPORT void CALL RomOpen (void) res = IDirectDraw_CreateSurface(lpdd, &ddsd, &lpddsback, 0); if (res == DDERR_INVALIDPIXELFORMAT) fatalerror("ARGB8888 is not supported. You can try changing desktop color depth to 32-bit, but most likely that won't help."); - else if(res != DD_OK) + else if (res != DD_OK) fatalerror("CreateSurface for a secondary surface failed. Error code %x", res); - res = IDirectDrawSurface_GetSurfaceDesc(lpddsback, &ddsd); if (res != DD_OK) fatalerror("GetSurfaceDesc failed."); @@ -269,7 +331,6 @@ EXPORT void CALL RomOpen (void) fatalerror("Pitch of a secondary surface is either not 32 bit aligned or two small."); pitchindwords = ddsd.lPitch >> 2; - res = IDirectDraw_CreateClipper(lpdd, 0, &lpddcl, 0); if (res != DD_OK) fatalerror("Couldn't create a clipper."); @@ -280,14 +341,10 @@ EXPORT void CALL RomOpen (void) if (res != DD_OK) fatalerror("Couldn't attach a clipper to a surface."); - - src.top = src.left = 0; + src.top = src.left = 0; src.bottom = 0; src.right = PRESCALE_WIDTH; - - - POINT p; p.x = p.y = 0; GetClientRect(gfx.hWnd, &dst); @@ -296,8 +353,6 @@ EXPORT void CALL RomOpen (void) GetClientRect(gfx.hStatusBar, &statusrect); dst.bottom -= statusrect.bottom; - - DDBLTFX ddbltfx; ddbltfx.dwSize = sizeof(DDBLTFX); ddbltfx.dwFillColor = 0; @@ -306,55 +361,48 @@ EXPORT void CALL RomOpen (void) res = IDirectDrawSurface_Blt(lpddsback, &src, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); rdp_init(); - - } - -EXPORT void CALL ShowCFB (void) + +EXPORT void CALL ShowCFB(void) { rdp_update(); } - -EXPORT void CALL UpdateScreen (void) + +EXPORT void CALL UpdateScreen(void) { rdp_update(); - - - - } - -EXPORT void CALL ViStatusChanged (void) + +EXPORT void CALL ViStatusChanged(void) { } - -EXPORT void CALL ViWidthChanged (void) + +EXPORT void CALL ViWidthChanged(void) { } - + EXPORT void CALL FBWrite(DWORD, DWORD) { - } - -EXPORT void CALL FBWList(FrameBufferModifyEntry *plist, DWORD size) + +EXPORT void CALL FBWList(FrameBufferModifyEntry* plist, DWORD size) { } - + EXPORT void CALL FBRead(DWORD addr) { } -EXPORT void CALL FBGetFrameBufferInfo(void *pinfo) +EXPORT void CALL FBGetFrameBufferInfo(void* pinfo) { } diff --git a/mylittle-nocomment/mylittle.vcxproj b/mylittle-nocomment/mylittle.vcxproj index 5421ead..a8aaee6 100644 --- a/mylittle-nocomment/mylittle.vcxproj +++ b/mylittle-nocomment/mylittle.vcxproj @@ -100,6 +100,7 @@ true $(OutDir)mylittle.lib MachineX86 + kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;Shlwapi.lib;%(AdditionalDependencies) diff --git a/mylittle-nocomment/tctables.h b/mylittle-nocomment/tctables.h index 8ebcc1d..d830710 100644 --- a/mylittle-nocomment/tctables.h +++ b/mylittle-nocomment/tctables.h @@ -2,70 +2,70 @@ #define _TCTABLES_H const INT32 norm_point_table[64] = { -0x4000, -0x3f04, -0x3e10, -0x3d22, -0x3c3c, -0x3b5d, -0x3a83, -0x39b1, -0x38e4, -0x381c, -0x375a, -0x369d, -0x35e5, -0x3532, -0x3483, -0x33d9, -0x3333, -0x3291, -0x31f4, -0x3159, -0x30c3, -0x3030, -0x2fa1, -0x2f15, -0x2e8c, -0x2e06, -0x2d83, -0x2d03, -0x2c86, -0x2c0b, -0x2b93, -0x2b1e, -0x2aab, -0x2a3a, -0x29cc, -0x2960, -0x28f6, -0x288e, -0x2828, -0x27c4, -0x2762, -0x2702, -0x26a4, -0x2648, -0x25ed, -0x2594, -0x253d, -0x24e7, -0x2492, -0x243f, -0x23ee, -0x239e, -0x234f, -0x2302, -0x22b6, -0x226c, -0x2222, -0x21da, -0x2193, -0x214d, -0x2108, -0x20c5, -0x2082, -0x2041 +0x4000, +0x3f04, +0x3e10, +0x3d22, +0x3c3c, +0x3b5d, +0x3a83, +0x39b1, +0x38e4, +0x381c, +0x375a, +0x369d, +0x35e5, +0x3532, +0x3483, +0x33d9, +0x3333, +0x3291, +0x31f4, +0x3159, +0x30c3, +0x3030, +0x2fa1, +0x2f15, +0x2e8c, +0x2e06, +0x2d83, +0x2d03, +0x2c86, +0x2c0b, +0x2b93, +0x2b1e, +0x2aab, +0x2a3a, +0x29cc, +0x2960, +0x28f6, +0x288e, +0x2828, +0x27c4, +0x2762, +0x2702, +0x26a4, +0x2648, +0x25ed, +0x2594, +0x253d, +0x24e7, +0x2492, +0x243f, +0x23ee, +0x239e, +0x234f, +0x2302, +0x22b6, +0x226c, +0x2222, +0x21da, +0x2193, +0x214d, +0x2108, +0x20c5, +0x2082, +0x2041 }; const INT32 norm_slope_table[64] = {