From f3a9477fbfa5684d7503415c0729629298d0d2f8 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Tue, 4 Mar 2008 19:38:10 +0200 Subject: [PATCH] imported winuaesrc1500b6.zip --- archivers/lha/util.c | 2 +- jit/compemu_raw_x86.c | 7 +- main.c | 4 +- memory.c | 9 +- od-win32/dinput.c | 6 +- od-win32/dxwrap.c | 66 ++++++++--- od-win32/dxwrap.h | 10 +- od-win32/mman.c | 161 ++++++++++++++++++++++---- od-win32/picasso96_win.c | 191 ++++++++++++++---------------- od-win32/picasso96_win.h | 2 +- od-win32/resources/winuae.rc | 1 + od-win32/win32.h | 4 +- od-win32/win32_scale2x.c | 68 +++++------ od-win32/win32gfx.c | 217 +++++++++++++++++------------------ od-win32/win32gui.c | 30 +++-- od-win32/win32gui_extra.c | 2 +- od-win32/winuaechangelog.txt | 30 ++++- p96_blit.c | 7 +- 18 files changed, 496 insertions(+), 321 deletions(-) diff --git a/archivers/lha/util.c b/archivers/lha/util.c index 0d89c7d5..3c9c0c9a 100755 --- a/archivers/lha/util.c +++ b/archivers/lha/util.c @@ -76,7 +76,7 @@ strdup(buf) */ /* ------------------------------------------------------------------------ */ -#if defined(NOBSTRING) && !defined(__STDC__) +#if 0 && defined(NOBSTRING) && !defined(__STDC__) void * memmove(dst, src, cnt) register char *dst, *src; diff --git a/jit/compemu_raw_x86.c b/jit/compemu_raw_x86.c index b194f5e8..b091bcd3 100755 --- a/jit/compemu_raw_x86.c +++ b/jit/compemu_raw_x86.c @@ -1697,7 +1697,8 @@ static uae_u8 *veccode; #define ctxPC (pContext->Eip) #endif -int EvalException ( LPEXCEPTION_POINTERS blah, int n_except ) +extern int mman_guard_exception (LPEXCEPTION_POINTERS); +int EvalException (LPEXCEPTION_POINTERS blah, int n_except) { PEXCEPTION_RECORD pExceptRecord = NULL; PCONTEXT pContext = NULL; @@ -1709,7 +1710,9 @@ int EvalException ( LPEXCEPTION_POINTERS blah, int n_except ) int dir=-1; int len=0; - if( n_except != STATUS_ACCESS_VIOLATION || !canbang) + if (n_except == STATUS_GUARD_PAGE_VIOLATION) + return mman_guard_exception (blah); + if (n_except != STATUS_ACCESS_VIOLATION || !canbang) return EXCEPTION_CONTINUE_SEARCH; pExceptRecord = blah->ExceptionRecord; diff --git a/main.c b/main.c index cd8af1c0..bed2470d 100755 --- a/main.c +++ b/main.c @@ -652,8 +652,8 @@ void leave_program (void) static void real_main2 (int argc, char **argv) { -#if defined (JIT) && (defined ( _WIN32 ) || defined (_WIN64)) && !defined ( NO_WIN32_EXCEPTION_HANDLER ) - extern int EvalException ( LPEXCEPTION_POINTERS blah, int n_except ); +#if defined (JIT) && (defined (_WIN32) || defined (_WIN64)) && !defined (NO_WIN32_EXCEPTION_HANDLER) + extern int EvalException (LPEXCEPTION_POINTERS blah, int n_except); __try #endif { diff --git a/memory.c b/memory.c index f2b639cf..42b3a55c 100755 --- a/memory.c +++ b/memory.c @@ -2872,8 +2872,15 @@ uae_u8 *mapped_malloc (size_t s, char *file) id = shmget (IPC_PRIVATE, s, 0x1ff, file); if (id == -1) { + static int recurse; + uae_u8 *p; nocanbang(); - return mapped_malloc (s, file); + if (recurse) + return NULL; + recurse++; + p = mapped_malloc (s, file); + recurse--; + return p; } answer = shmat (id, 0, 0); shmctl (id, IPC_RMID, NULL); diff --git a/od-win32/dinput.c b/od-win32/dinput.c index d6155c1a..99a86cca 100755 --- a/od-win32/dinput.c +++ b/od-win32/dinput.c @@ -855,10 +855,8 @@ static BOOL CALLBACK di_enumcallback (LPCDIDEVICEINSTANCE lpddi, LPVOID *dd) } #ifdef DI_DEBUG - write_log ("GUID=%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X:\n", - lpddi->guidInstance.Data1, lpddi->guidInstance.Data2, lpddi->guidInstance.Data3, - lpddi->guidInstance.Data4[0], lpddi->guidInstance.Data4[1], lpddi->guidInstance.Data4[2], lpddi->guidInstance.Data4[3], - lpddi->guidInstance.Data4[4], lpddi->guidInstance.Data4[5], lpddi->guidInstance.Data4[6], lpddi->guidInstance.Data4[7]); + write_log ("I=%s ", outGUID (&lpddi->guidInstance)); + write_log ("P=%s\n", outGUID (&lpddi->guidProduct)); write_log ("'%s' '%s' %08.8X [%s]\n", lpddi->tszProductName, lpddi->tszInstanceName, lpddi->dwDevType, typetxt); #endif diff --git a/od-win32/dxwrap.c b/od-win32/dxwrap.c index f203a4bd..6de36be4 100755 --- a/od-win32/dxwrap.c +++ b/od-win32/dxwrap.c @@ -32,6 +32,7 @@ static void freemainsurface (void) DirectDraw_SetClipper (NULL); releaser (dxdata.dclip, IDirectDrawClipper_Release); } + releaser (dxdata.palette, IDirectDrawPalette_Release); releaser (dxdata.flipping[1], IDirectDrawSurface7_Release); releaser (dxdata.flipping[0], IDirectDrawSurface7_Release); releaser (dxdata.primary, IDirectDrawSurface7_Release); @@ -103,6 +104,8 @@ HRESULT restoresurface (LPDIRECTDRAWSURFACE7 surf) ddrval = IDirectDrawSurface7_Restore (surf); if (FAILED (ddrval)) write_log ("IDirectDrawSurface7_Restore: %s\n", DXError (ddrval)); + if (surf == dxdata.primary && dxdata.palette) + IDirectDrawSurface7_SetPalette (dxdata.primary, dxdata.palette); return ddrval; } @@ -229,14 +232,14 @@ HRESULT DirectDraw_CreateMainSurface (int width, int height) write_log ("IDirectDraw7_CreateSurface: %s\n", DXError (ddrval)); return ddrval; } + ddrval = IDirectDrawSurface7_GetSurfaceDesc (dxdata.primary, &dxdata.native); + if (FAILED (ddrval)) + write_log ("IDirectDrawSurface7_GetSurfaceDesc: %s\n", DXError (ddrval)); if (dxdata.fsmodeset) clearsurface (dxdata.primary); dxdata.backbuffers = desc.dwBackBufferCount; clearsurface (dxdata.flipping[0]); clearsurface (dxdata.flipping[1]); - ddrval = IDirectDrawSurface7_GetSurfaceDesc (dxdata.primary, &dxdata.native); - if (FAILED (ddrval)) - write_log ("IDirectDrawSurface7_GetSurfaceDesc: %s\n", DXError (ddrval)); surf = allocsurface (width, height); if (surf) { dxdata.secondary = surf; @@ -310,7 +313,7 @@ HRESULT DirectDraw_SetClipper(HWND hWnd) } -char *outGUID (GUID *guid) +char *outGUID (const GUID *guid) { static char gb[64]; if (guid == NULL) @@ -368,8 +371,6 @@ RGBFTYPE DirectDraw_GetSurfacePixelFormat(LPDDSURFACEDESC2 surface) return RGBFB_B5G6R5PC; if (b == 0x7C00 && g == 0x03E0 && r == 0x001F) return RGBFB_B5G5R5PC; - /* This happens under NT - with r == b == g == 0 !!! */ - write_log ("Unknown 16 bit format %d %d %d\n", r, g, b); break; case 24: @@ -558,21 +559,34 @@ int DirectDraw_BlitToPrimary (RECT *rect) return result; } -static void quickblit (LPDIRECTDRAWSURFACE7 dst, LPDIRECTDRAWSURFACE7 src) +static void DirectDraw_Blt (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *srcrect) { HRESULT ddrval; - while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, NULL, src, NULL, DDBLT_WAIT, NULL))) { + if (dst == NULL) + dst = getlocksurface (); + while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, dstrect, src, srcrect, DDBLT_WAIT, NULL))) { if (ddrval == DDERR_SURFACELOST) { ddrval = restoresurface (dst); if (FAILED (ddrval)) break; } else if (ddrval != DDERR_SURFACEBUSY) { - write_log ("quickblit: %s\n", DXError (ddrval)); + write_log ("DirectDraw_Blit: %s\n", DXError (ddrval)); break; } } } +void DirectDraw_Blit (LPDIRECTDRAWSURFACE7 dst, LPDIRECTDRAWSURFACE7 src) +{ + DirectDraw_Blt (dst, NULL, src, NULL); +} + +void DirectDraw_BlitRect (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *scrrect) +{ + DirectDraw_Blt (dst, dstrect, src, scrrect); +} + + extern int vblank_skip; static void flip (void) { @@ -596,17 +610,17 @@ static void flip (void) ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_INTERVAL2); } else { ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - quickblit (dxdata.flipping[1], dxdata.primary); + DirectDraw_Blit (dxdata.flipping[1], dxdata.primary); ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); } } } else { ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); } - quickblit (dxdata.flipping[1], dxdata.primary); + DirectDraw_Blit (dxdata.flipping[1], dxdata.primary); } else if(dxdata.backbuffers == 1) { ddrval = IDirectDrawSurface7_Flip(dxdata.primary, NULL, flags); - quickblit (dxdata.flipping[0], dxdata.primary); + DirectDraw_Blit (dxdata.flipping[0], dxdata.primary); } if (ddrval == DDERR_SURFACELOST) { static int recurse; @@ -621,7 +635,6 @@ static void flip (void) } } - int DirectDraw_Flip (int wait) { if (getlocksurface () != dxdata.secondary) { @@ -631,3 +644,30 @@ int DirectDraw_Flip (int wait) } return 1; } + +HRESULT DirectDraw_SetPaletteEntries (int start, int count, PALETTEENTRY *palette) +{ + HRESULT ddrval = DDERR_NOPALETTEATTACHED; + if (dxdata.palette) + ddrval = IDirectDrawPalette_SetEntries(dxdata.palette, 0, start, count, palette); + return ddrval; +} +HRESULT DirectDraw_SetPalette (int remove) +{ + HRESULT ddrval; + if (!dxdata.fsmodeset || (!dxdata.palette && !remove)) + return DD_FALSE; + ddrval = IDirectDrawSurface7_SetPalette (dxdata.primary, remove ? NULL : dxdata.palette); + if (FAILED (ddrval)) + write_log ("IDirectDrawSurface7_SetPalette: %s\n", DXError (ddrval)); + return ddrval; +} +HRESULT DirectDraw_CreatePalette (LPPALETTEENTRY pal) +{ + HRESULT ddrval; + ddrval = IDirectDraw_CreatePalette (dxdata.maindd, DDPCAPS_8BIT | DDPCAPS_ALLOW256, pal, &dxdata.palette, NULL); + if (FAILED (ddrval)) + write_log ("IDirectDraw_CreatePalette: %s\n", DXError (ddrval)); + return ddrval; +} + diff --git a/od-win32/dxwrap.h b/od-win32/dxwrap.h index 1ae3d1e7..43b63411 100755 --- a/od-win32/dxwrap.h +++ b/od-win32/dxwrap.h @@ -12,6 +12,7 @@ struct ddstuff LPDIRECTDRAW7 maindd; LPDIRECTDRAWCLIPPER dclip; LPDIRECTDRAWSURFACE7 primary, secondary, flipping[2]; + LPDIRECTDRAWPALETTE palette; int fsmodeset, backbuffers; int width, height, depth, freq; int swidth, sheight; @@ -128,7 +129,7 @@ typedef enum } DirectDraw_Mask_e; extern const char *DXError (HRESULT hr); -extern char *outGUID (GUID *guid); +extern char *outGUID (const GUID *guid); HRESULT DirectDraw_GetDisplayMode (void); void DirectDraw_Release(void); @@ -166,5 +167,12 @@ void DirectDraw_GetPrimaryPixelFormat (DDSURFACEDESC2 *desc); HRESULT DirectDraw_FlipToGDISurface (void); int DirectDraw_Flip (int wait); int DirectDraw_BlitToPrimary (RECT *rect); +void DirectDraw_Blit (LPDIRECTDRAWSURFACE7 dst, LPDIRECTDRAWSURFACE7 src); +void DirectDraw_BlitRect (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *scrrect); + +HRESULT DirectDraw_SetPaletteEntries (int start, int count, PALETTEENTRY *palette); +HRESULT DirectDraw_SetPalette (int remove); +HRESULT DirectDraw_CreatePalette (LPPALETTEENTRY pal); + #endif diff --git a/od-win32/mman.c b/od-win32/mman.c index d002c3cb..f949526a 100755 --- a/od-win32/mman.c +++ b/od-win32/mman.c @@ -17,24 +17,19 @@ #define BARRIER 32 static struct shmid_ds shmids[MAX_SHMID]; - -static int memorylocking = 0; - +static int memwatchok = 0; uae_u8 *natmem_offset = NULL; - static uae_u8 *p96mem_offset; +static int p96mem_size; +static SYSTEM_INFO si; static void *virtualallocwithlock(LPVOID addr, SIZE_T size, DWORD allocationtype, DWORD protect) { void *p = VirtualAlloc (addr, size, allocationtype, protect); - if (p && memorylocking) - VirtualLock(p, size); return p; } static void virtualfreewithlock(LPVOID addr, SIZE_T size, DWORD freetype) { - if (memorylocking) - VirtualUnlock(addr, size); VirtualFree(addr, size, freetype); } @@ -75,9 +70,113 @@ static uae_u32 lowmem (void) return change; } -static uae_u32 max_allowed_mman; +typedef UINT (CALLBACK* GETWRITEWATCH) + (DWORD,PVOID,SIZE_T,PVOID*,PULONG_PTR,PULONG); +#define TEST_SIZE (2 * 4096) +static int testwritewatch (void) +{ + GETWRITEWATCH pGetWriteWatch; + void *mem; + void *pages[16]; + ULONG_PTR gwwcnt; + ULONG ps; + int ret = 0; + + ps = si.dwPageSize; + + pGetWriteWatch = (GETWRITEWATCH)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetWriteWatch"); + if (pGetWriteWatch == NULL) { + write_log ("GetWriteWatch(): missing!?\n"); + return 0; + } + mem = VirtualAlloc (NULL, TEST_SIZE, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_EXECUTE_READWRITE); + if (mem == NULL) { + write_log ("GetWriteWatch(): MEM_WRITE_WATCH not supported!? err=%d\n", GetLastError()); + return 0; + } + if (VirtualAlloc (mem, TEST_SIZE, MEM_COMMIT, PAGE_EXECUTE_READWRITE) == NULL) { + write_log ("GetWriteWatch(): test memory area MEM_COMMIT failed!? err=%d\n", GetLastError()); + goto end; + } + ResetWriteWatch (mem, TEST_SIZE); + ((uae_u8*)mem)[1] = 0; + gwwcnt = TEST_SIZE / ps; + if (GetWriteWatch(WRITE_WATCH_FLAG_RESET, mem, TEST_SIZE, pages, &gwwcnt, &ps)) { + write_log ("GetWriteWatch(): failed!? err=%d\n", GetLastError ()); + goto end; + } + if (ps != si.dwPageSize) { + write_log ("GetWriteWatch(): pagesize %d != %d!?\n", si.dwPageSize, ps); + goto end; + } + if (gwwcnt != 1) { + write_log ("GetWriteWatch(): modified pages returned %d != 1!?\n", gwwcnt); + goto end; + } + if (pages[0] != mem) { + write_log ("GetWriteWatch(): modified page was wrong!?\n"); + goto end; + } + write_log ("GetWriteWatch() test ok\n"); + ret = 1; + memwatchok = 1; +end: + if (mem) { + VirtualFree (mem, TEST_SIZE, MEM_DECOMMIT); + VirtualFree (mem, TEST_SIZE, MEM_RELEASE); + } + return ret; +} + +static uae_u8 *memwatchtable; + +int mman_GetWriteWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize, PVOID *lpAddresses, PULONG_PTR lpdwCount, PULONG lpdwGranularity) +{ + int i, j; + + if (memwatchok) + return GetWriteWatch (WRITE_WATCH_FLAG_RESET, lpBaseAddress, dwRegionSize, lpAddresses, lpdwCount, lpdwGranularity); + j = 0; + for (i = 0; i < p96mem_size / si.dwPageSize; i++) { + if (j >= *lpdwCount) + break; + if (memwatchtable[i]) + lpAddresses[j++] = p96mem_offset + i * si.dwPageSize; + } + *lpdwCount = j; + *lpdwGranularity = si.dwPageSize; + return 0; +} +void mman_ResetWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize) +{ + if (!memwatchok) { + DWORD op; + memset (memwatchtable, 0, p96mem_size / si.dwPageSize); + if (!VirtualProtect (lpBaseAddress, dwRegionSize, PAGE_READWRITE | PAGE_GUARD, &op)) + write_log ("VirtualProtect() failed, err=%d\n", GetLastError ()); + } +} + +int mman_guard_exception (LPEXCEPTION_POINTERS p) +{ + PEXCEPTION_RECORD record = p->ExceptionRecord; + PCONTEXT context = p->ContextRecord; + ULONG_PTR addr = record->ExceptionInformation[1]; + int rw = record->ExceptionInformation[0]; + ULONG_PTR p96addr = (ULONG_PTR)p96mem_offset; + + if (memwatchok) + return EXCEPTION_CONTINUE_SEARCH; + if (addr < p96addr || addr >= p96addr + p96mem_size) + return EXCEPTION_CONTINUE_EXECUTION; + addr -= p96addr; + addr /= si.dwPageSize; + memwatchtable[addr] = 1; + return EXCEPTION_CONTINUE_EXECUTION; +} + static uae_u64 size64; - typedef BOOL (CALLBACK* GLOBALMEMORYSTATUSEX)(LPMEMORYSTATUSEX); +typedef BOOL (CALLBACK* GLOBALMEMORYSTATUSEX)(LPMEMORYSTATUSEX); void preinit_shm (void) { @@ -86,7 +185,9 @@ void preinit_shm (void) MEMORYSTATUS memstats; GLOBALMEMORYSTATUSEX pGlobalMemoryStatusEx; MEMORYSTATUSEX memstatsex; + uae_u32 max_allowed_mman; + GetSystemInfo (&si); max_allowed_mman = 1536; if (os_64bit) max_allowed_mman = 2048; @@ -116,8 +217,11 @@ void preinit_shm (void) if (max_allowed_mman * 1024 * 1024 > size64) max_allowed_mman = size64 / (1024 * 1024); max_z3fastmem = (max_allowed_mman - (max_allowed_mman >> 3)) * 1024 * 1024; + if (max_z3fastmem < 512 * 1024 * 1024) + max_z3fastmem = 512 * 1024 * 1024; write_log ("Max Z3FastRAM %dM. Total physical RAM %uM\n", max_z3fastmem >> 20, totalphys64 >> 20); + testwritewatch (); canbang = 1; } @@ -159,13 +263,23 @@ int init_shm (void) shmids[i].name[0] = 0; } natmemsize = size + z3size; + if (!currprefs.gfxmem_size) { + natmemsize += si.dwPageSize; + } else { + xfree (memwatchtable); + memwatchtable = 0; + if (!memwatchok) { + write_log ("GetWriteWatch() not supported, using guard pages, performance will be slower.\n"); + memwatchtable = xcalloc (currprefs.gfxmem_size / si.dwPageSize + 1, 1); + } + } for (;;) { int change; - blah = VirtualAlloc(NULL, natmemsize, MEM_RESERVE, PAGE_EXECUTE_READWRITE); + blah = VirtualAlloc (NULL, natmemsize, MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (blah) break; - write_log ("NATMEM: %dM area failed to allocate, err=%d\n", natmemsize >> 20, GetLastError()); + write_log ("NATMEM: %dM area failed to allocate, err=%d\n", natmemsize >> 20, GetLastError ()); change = lowmem (); totalsize -= change; if (change == 0 || totalsize < 0x10000000) { @@ -174,14 +288,18 @@ int init_shm (void) } } natmem_offset = blah; - p96mem_offset = VirtualAlloc(natmem_offset + size + z3size, currprefs.gfxmem_size + 4096, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_EXECUTE_READWRITE); - if (!p96mem_offset) { - currprefs.gfxmem_size = changed_prefs.gfxmem_size = 0; - write_log ("NATMEM: failed to allocate special Picasso96 GFX RAM\n"); + if (currprefs.gfxmem_size) { + p96mem_size = currprefs.gfxmem_size + si.dwPageSize; + p96mem_offset = VirtualAlloc (natmem_offset + size + z3size, p96mem_size, + MEM_RESERVE | (memwatchok ? MEM_WRITE_WATCH : 0), PAGE_READWRITE); + if (!p96mem_offset) { + currprefs.gfxmem_size = changed_prefs.gfxmem_size = 0; + write_log ("NATMEM: failed to allocate special Picasso96 GFX RAM, err=%d\n", GetLastError ()); + } } if (!natmem_offset) { - write_log ("NATMEM: No special area could be allocated! (1)\n"); + write_log ("NATMEM: No special area could be allocated! (1) err=%d\n", GetLastError ()); } else { write_log ("NATMEM: Our special area: 0x%p-0x%p (%08x %dM)\n", natmem_offset, (uae_u8*)natmem_offset + natmemsize, @@ -265,6 +383,7 @@ void *shmat(int shmid, void *shmaddr, int shmflg) void *result = (void *)-1; BOOL got = FALSE; int p96special = FALSE; + DWORD protect = PAGE_READWRITE; #ifdef NATMEM_OFFSET unsigned int size=shmids[shmid].size; @@ -323,6 +442,8 @@ void *shmat(int shmid, void *shmaddr, int shmflg) p96ram_start = p96mem_offset - natmem_offset; shmaddr = natmem_offset + p96ram_start; size += BARRIER; + if (!memwatchok) + protect |= PAGE_GUARD; } if(!strcmp(shmids[shmid].name,"bogo")) { shmaddr=natmem_offset+0x00C00000; @@ -370,16 +491,14 @@ void *shmat(int shmid, void *shmaddr, int shmflg) got = FALSE; if (got == FALSE) { if (shmaddr) - virtualfreewithlock(shmaddr, size, MEM_DECOMMIT); - result = virtualallocwithlock(shmaddr, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); + virtualfreewithlock (shmaddr, size, MEM_DECOMMIT); + result = virtualallocwithlock (shmaddr, size, MEM_COMMIT, protect); if (result == NULL) { result = (void*)-1; write_log ("VirtualAlloc %08.8X - %08.8X %x (%dk) failed %d\n", (uae_u8*)shmaddr - natmem_offset, (uae_u8*)shmaddr - natmem_offset + size, size, size >> 10, GetLastError()); } else { - if (memorylocking) - VirtualLock(shmaddr, size); shmids[shmid].attached = result; write_log ("VirtualAlloc %08.8X - %08.8X %x (%dk) ok%s\n", (uae_u8*)shmaddr - natmem_offset, (uae_u8*)shmaddr - natmem_offset + size, diff --git a/od-win32/picasso96_win.c b/od-win32/picasso96_win.c index 6b0ce683..aca3baaf 100755 --- a/od-win32/picasso96_win.c +++ b/od-win32/picasso96_win.c @@ -56,6 +56,9 @@ static int hwsprite = 0; #include "picasso96_win.h" #include "win32gfx.h" +int mman_GetWriteWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize, PVOID *lpAddresses, PULONG_PTR lpdwCount, PULONG lpdwGranularity); +void mman_ResetWatch (PVOID lpBaseAddress, SIZE_T dwRegionSize); + //#define P96TRACING_ENABLED 1 int p96hack_vpos, p96hack_vpos2, p96refresh_active; @@ -71,7 +74,6 @@ int p96hsync_counter, palette_changed; #define P96TRACING_LEVEL 1 #endif static void flushpixels(void); -static void flushpixels_lock(void); #ifdef P96TRACING_ENABLED #define P96TRACE(x) do { write_log x; } while(0) #define P96TRACE_SPR(x) do { write_log x; } while(0) @@ -169,20 +171,7 @@ static uae_u32 p2ctab[256][2]; static int set_gc_called = 0, init_picasso_screen_called = 0; //fastscreen static uaecptr oldscr = 0; -void PICASSO96_Unlock(void) -{ - if(picasso_on) { - flushpixels_lock(); - gfx_unlock_picasso (); - } -} -void PICASSO96_Lock(void) -{ - if(picasso_on) { - picasso96_state.HostAddress = gfx_lock_picasso (); - } -} static void endianswap (uae_u32 *vp, int bpp) { @@ -517,13 +506,13 @@ static int renderinfo_is_current_screen (struct RenderInfo *ri) * Fill a rectangle in the screen. */ STATIC_INLINE void do_fillrect_frame_buffer (struct RenderInfo *ri, int X, int Y, - int Width, int Height, uae_u32 Pen, int Bpp, - RGBFTYPE RGBFormat) + int Width, int Height, uae_u32 Pen, int Bpp) { int cols; uae_u32 *p; uae_u8 *src, *dst; int lines; + int bpr = ri->BytesPerRow / 4; /* Do our virtual frame-buffer memory. First, we do a single line fill by hand */ dst = src = ri->Memory + X * Bpp + Y * ri->BytesPerRow; @@ -532,36 +521,37 @@ STATIC_INLINE void do_fillrect_frame_buffer (struct RenderInfo *ri, int X, int Y switch (Bpp) { case 1: - memset (p, Pen, Width); + for (lines = 0; lines < Height; lines++, p += bpr) { + memset (p, Pen, Width); + } break; case 2: Pen |= Pen << 16; - for (cols = 0; cols < Width / 2; cols++) - *p++ = Pen; - if (Width & 1) - ((uae_u16*)p)[0] = Pen; + for (lines = 0; lines < Height; lines++, p += bpr) { + for (cols = 0; cols < Width / 2; cols++) + p[cols] = Pen; + if (Width & 1) + ((uae_u16*)(p + cols))[0] = Pen; + } break; case 3: - for (cols = 0; cols < Width; cols++) { - *dst++ = Pen >> 16; - *dst++ = Pen >> 8; - *dst++ = Pen; + for (lines = 0; lines < Height; lines++, p += bpr) { + uae_u8 *d = (uae_u8*)p; + for (cols = 0; cols < Width; cols++) { + *d++ = Pen >> 16; + *d++ = Pen >> 8; + *d++ = Pen; + } } break; case 4: - for (cols = 0; cols < Width; cols++) - *p++ = Pen; + for (lines = 0; lines < Height; lines++, p += bpr) { + for (cols = 0; cols < Width; cols++) + p[cols] = Pen; + } + return; break; } - dst = src + ri->BytesPerRow; - /* next, we do the remaining line fills via memcpy() for > 1 BPP, otherwise some more memset() calls */ - if(Bpp > 1) { - for (lines = 0; lines < Height - 1; lines++, dst += ri->BytesPerRow) - memcpy (dst, src, Width * Bpp); - } else { - for (lines = 0; lines < Height - 1; lines++, dst += ri->BytesPerRow) - memset (dst, Pen, Width); - } } static void disablemouse (void) @@ -648,8 +638,8 @@ void picasso_handle_vsync (void) return; vsynccnt = 0; } - - PICASSO96_Unlock(); + flushpixels (); + gfx_unlock_picasso (); } static int set_panning_called = 0; @@ -765,6 +755,7 @@ void picasso_refresh (void) #include "p96_blit.c" #define BLT_NAME BLIT_30_32 #define BLT_FUNC(s,d) tmp = *d ; *d = *s; *s = tmp; +#define BLT_TEMP #include "p96_blit.c" #undef BLT_SIZE #undef BLT_MULT @@ -815,6 +806,7 @@ void picasso_refresh (void) #include "p96_blit.c" #define BLT_NAME BLIT_30_16 #define BLT_FUNC(s,d) tmp = *d ; *d = *s; *s = tmp; +#define BLT_TEMP #include "p96_blit.c" #undef BLT_SIZE #undef BLT_MULT @@ -865,6 +857,7 @@ void picasso_refresh (void) #include "p96_blit.c" #define BLT_NAME BLIT_30_8 #define BLT_FUNC(s,d) tmp = *d ; *d = *s; *s = tmp; +#define BLT_TEMP #include "p96_blit.c" #undef BLT_SIZE #undef BLT_MULT @@ -874,10 +867,10 @@ void picasso_refresh (void) /* * Functions to perform an action on the frame-buffer */ -STATIC_INLINE void do_blitrect_frame_buffer(struct RenderInfo *ri, struct -RenderInfo *dstri, unsigned long srcx, unsigned long srcy, +STATIC_INLINE void do_blitrect_frame_buffer (struct RenderInfo *ri, struct + RenderInfo *dstri, unsigned long srcx, unsigned long srcy, unsigned long dstx, unsigned long dsty, unsigned long width, unsigned -long height, uae_u8 mask, BLIT_OPCODE opcode) + long height, uae_u8 mask, BLIT_OPCODE opcode) { uae_u8 *src, *dst, *tmp, *tmp2, *tmp3; @@ -885,7 +878,6 @@ long height, uae_u8 mask, BLIT_OPCODE opcode) unsigned long total_width = width * Bpp; unsigned long linewidth = (total_width + 15) & ~15; unsigned long lines; - int can_do_visible_blit = 0; src = ri->Memory + srcx * Bpp + srcy * ri->BytesPerRow; dst = dstri->Memory + dstx * Bpp + dsty * dstri->BytesPerRow; @@ -893,7 +885,9 @@ long height, uae_u8 mask, BLIT_OPCODE opcode) write_log ("WARNING - BlitRect() has mask 0x%x with Bpp %d.\n", mask, Bpp); } + P96TRACE (("(%dx%d)=(%dx%d)=(%dx%d)=%d ", srcx, srcy, dstx, dsty, width, height, opcode)); if (mask == 0xFF || Bpp > 1) { + if(opcode == BLIT_SRC) { /* handle normal case efficiently */ if (ri->Memory == dstri->Memory && dsty == srcy) { @@ -1270,8 +1264,9 @@ static void updatesprcolors (void) switch (picasso_vidinfo.pixbytes) { case 1: - cursorrgbn[0] = 0; - cursorrgbn[i] = i; + cursorrgbn[0] = 16; + /* use custom chip sprite palette */ + cursorrgbn[i] = i + 16; break; case 2: vx = 0xff00ff; @@ -1315,7 +1310,8 @@ static uae_u32 setspriteimage (uaecptr bi) updatesprcolors (); P96TRACE_SPR (("SetSpriteImage(%08x,%08x,w=%d,h=%d,hires=%d,double=%d,%08x)\n", - bi, get_long (bi + PSSO_BoardInfo_MouseImage), w, h, hiressprite - 1, doubledsprite, bi + PSSO_BoardInfo_MouseImage)); + bi, get_long (bi + PSSO_BoardInfo_MouseImage), w, h, + hiressprite - 1, doubledsprite, bi + PSSO_BoardInfo_MouseImage)); bpp = picasso_vidinfo.pixbytes; if (!w || !h || get_long (bi + PSSO_BoardInfo_MouseImage) == 0) { @@ -1771,6 +1767,10 @@ uae_u32 REGPARAM2 picasso_InitCard (struct regstruct *regs) write_log ("P96: uaegfx.card: no hardware sprite support\n"); put_word (AmigaBoardInfo + PSSO_BoardInfo_SoftSpriteFlags, picasso96_pixel_format); } + if (!(flags & BIF_BLITTER)) + write_log ("P96: no blitter support, bogus uaegfx.card!?\n"); + if (flags & BIF_NOBLITTER) + write_log ("P96: blitter disabled in devs:monitors/uaegfx!\n"); put_long (AmigaBoardInfo + PSSO_BoardInfo_Flags, flags); put_word (AmigaBoardInfo + PSSO_BoardInfo_MaxHorResolution + 0, planar.width); @@ -1897,7 +1897,7 @@ uae_u32 REGPARAM2 picasso_SetSwitch (struct regstruct *regs) sprintf (p96text, "Picasso96 %dx%dx%d (%dx%dx%d)", picasso96_state.Width, picasso96_state.Height, picasso96_state.BytesPerPixel * 8, picasso_vidinfo.width, picasso_vidinfo.height, picasso_vidinfo.pixbytes * 8); - write_log ("SetSwitch() - trying to show %s screen\n", flag ? p96text : "amiga"); + write_log ("SetSwitch() - %s\n", flag ? p96text : "amiga"); /* Put old switch-state in D0 */ @@ -1997,6 +1997,7 @@ static void init_picasso_screen(void) picasso_refresh (); } init_picasso_screen_called = 1; + mman_ResetWatch (p96ram_start + natmem_offset, allocated_gfxmem); } /* @@ -2222,10 +2223,11 @@ uae_u32 REGPARAM2 picasso_FillRect (struct regstruct *regs) if (Mask == 0xFF) { /* Do the fill-rect in the frame-buffer */ - do_fillrect_frame_buffer (&ri, X, Y, Width, Height, Pen, Bpp, RGBFormat); + do_fillrect_frame_buffer (&ri, X, Y, Width, Height, Pen, Bpp); result = 1; } else { + /* We get here only if Mask != 0xFF */ if (Bpp != 1) { write_log ("WARNING - FillRect() has unhandled mask 0x%x with Bpp %d. Using fall-back routine.\n", Mask, Bpp); @@ -2306,7 +2308,6 @@ STATIC_INLINE int BlitRectHelper (void) uae_u8 Bpp = GetBytesPerPixel(ri->RGBFormat); unsigned long total_width = width * Bpp; unsigned long linewidth = (total_width + 15) & ~15; - int can_do_visible_blit = 0; if(opcode == BLIT_DST) { write_log ( "WARNING: BlitRect() being called with opcode of BLIT_DST\n" ); @@ -2322,12 +2323,10 @@ STATIC_INLINE int BlitRectHelper (void) * and we need to put the results on the screen from the frame-buffer. */ if (dstri == NULL || dstri->Memory == ri->Memory) { - if(mask != 0xFF && Bpp > 1) + if (mask != 0xFF && Bpp > 1) mask = 0xFF; dstri = ri; - can_do_visible_blit = 1; } - /* Do our virtual frame-buffer memory first */ do_blitrect_frame_buffer (ri, dstri, srcx, srcy, dstx, dsty, width, height, mask, opcode); return 1; @@ -2385,7 +2384,7 @@ uae_u32 REGPARAM2 picasso_BlitRect (struct regstruct *regs) uae_u32 result = 0; P96TRACE(("BlitRect(%d, %d, %d, %d, %d, %d, 0x%x)\n", srcx, srcy, dstx, dsty, width, height, Mask)); - result = BlitRect(renderinfo, (uaecptr)NULL, srcx, srcy, dstx, dsty, width, height, Mask, BLIT_SRC); + result = BlitRect (renderinfo, (uaecptr)NULL, srcx, srcy, dstx, dsty, width, height, Mask, BLIT_SRC); return result; } @@ -2580,31 +2579,29 @@ uae_u32 REGPARAM2 picasso_BlitPattern (struct regstruct *regs) int bit_set = data & 0x8000; data <<= 1; if (bit_set) { - uae_u32 fgpen = pattern.FgPen; switch (Bpp) { case 1: { - uae_u8 *addr = uae_mem2 + bits; - do_put_mem_byte (addr, (uae_u8)(do_get_mem_byte (addr) ^ 0xff)); + uae_mem2[bits] ^= 0xff; } break; case 2: { - uae_u16 *addr = ((uae_u16 *)uae_mem2) + bits; - do_put_mem_word (addr, (uae_u16)(do_get_mem_word (addr) ^ fgpen)); + uae_u16 *addr = (uae_u16 *)uae_mem2; + addr[bits] ^= 0xffff; } break; case 3: { uae_u32 *addr = (uae_u32 *)(uae_mem2 + bits * 3); - do_put_mem_long (addr, do_get_mem_long (addr) ^ (fgpen & 0x00FFFFFF)); + do_put_mem_long (addr, do_get_mem_long (addr) ^ 0xffffff); } break; case 4: { - uae_u32 *addr = ((uae_u32 *)uae_mem2) + bits; - do_put_mem_long (addr, do_get_mem_long (addr) ^ fgpen); + uae_u32 *addr = (uae_u32 *)uae_mem2; + addr[bits] ^= 0xffffffff; } break; } @@ -2661,7 +2658,7 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs) if (CopyRenderInfoStructureA2U (rinf, &ri) && CopyTemplateStructureA2U (tmpl, &tmp)) { Bpp = GetBytesPerPixel(ri.RGBFormat); - uae_mem = ri.Memory + Y*ri.BytesPerRow + X*Bpp; /* offset into address */ + uae_mem = ri.Memory + Y * ri.BytesPerRow + X * Bpp; /* offset into address */ if (tmp.DrawMode & INVERS) inversion = 1; @@ -2674,7 +2671,6 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs) if(tmp.DrawMode == COMP) { write_log ("WARNING - BlitTemplate() has unhandled mask 0x%x with COMP DrawMode. Using fall-back routine.\n", Mask); - flushpixels(); //only need in the windows Version return 0; } else { result = 1; @@ -2682,12 +2678,7 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs) } else { result = 1; } -#if 1 - if (tmp.DrawMode == COMP) { - /* workaround, let native blitter handle COMP mode */ - return 0; - } -#endif + if(result) { uae_u32 fgpen, bgpen; @@ -2757,31 +2748,30 @@ uae_u32 REGPARAM2 picasso_BlitTemplate (struct regstruct *regs) int bit_set = (byte & 0x80); byte <<= 1; if (bit_set) { - fgpen = tmp.FgPen; switch (Bpp) { case 1: { - uae_u8 *addr = uae_mem2 + bits; - do_put_mem_byte (addr, (uae_u8)(do_get_mem_byte (addr) ^ 0xff)); + uae_u8 *addr = uae_mem2; + addr[bits] ^= 0xff; } break; case 2: { - uae_u16 *addr = ((uae_u16 *)uae_mem2) + bits; - do_put_mem_word (addr, (uae_u16)(do_get_mem_word (addr) ^ fgpen)); + uae_u16 *addr = (uae_u16 *)uae_mem2; + addr[bits] ^= 0xffff; } break; case 3: { uae_u32 *addr = (uae_u32 *)(uae_mem2 + bits * 3); - do_put_mem_long (addr, do_get_mem_long (addr) ^ (fgpen & 0x00FFFFFF)); + do_put_mem_long (addr, do_get_mem_long (addr) ^ 0x00FFFFFF); } break; case 4: { - uae_u32 *addr = ((uae_u32 *)uae_mem2) + bits; - do_put_mem_long (addr, do_get_mem_long (addr) ^ fgpen); + uae_u32 *addr = (uae_u32 *)uae_mem2; + addr[bits] ^= 0xffffffff; } break; } @@ -3125,13 +3115,11 @@ uae_u32 REGPARAM2 picasso_BlitPlanar2Direct (struct regstruct *regs) return result; } - -static void flushpixels_x (void) +static void flushpixels (void) { int i; int rowwidth_dst = picasso_vidinfo.width * picasso_vidinfo.pixbytes; int rowwidth_src = picasso96_state.Width * picasso96_state.BytesPerPixel; - ULONG_PTR gwwcnt; uae_u8 *src = p96ram_start + natmem_offset; int off = picasso96_state.XYOffset - gfxmem_start; uae_u8 *src_start = src + (off & ~gwwpagemask); @@ -3139,15 +3127,20 @@ static void flushpixels_x (void) int maxy = -1; int miny = picasso96_state.Height - 1; int lock = 0; + uae_u8 *dst = NULL; + ULONG_PTR gwwcnt; if (!picasso_vidinfo.extra_mem || !gwwbuf) return; for (;;) { - uae_u8 *dst; + gwwcnt = 0; if (palette_changed) { - picasso_palette (); + if (picasso_palette ()) { + reloadcursor = 1; + setspriteimage (cursorbi); + } gwwcnt = allocated_gfxmem / gwwpagesize; for (i = 0; i < gwwcnt; i++) gwwbuf[i] = src + i * gwwpagesize; @@ -3155,21 +3148,23 @@ static void flushpixels_x (void) } else { ULONG ps; gwwcnt = gwwbufsize; - if (GetWriteWatch(WRITE_WATCH_FLAG_RESET, src, allocated_gfxmem, gwwbuf, &gwwcnt, &ps)) - break;; + if (mman_GetWriteWatch (src, allocated_gfxmem, gwwbuf, &gwwcnt, &ps)) + break; } if (gwwcnt == 0) break; - if(DirectDraw_IsLocked() == FALSE) { - if (!lock) - dst = gfx_lock_picasso (); - lock = 1; - } else { - dst = picasso96_state.HostAddress; + if (dst == NULL) { + if(DirectDraw_IsLocked() == FALSE) { + if (!lock) + dst = gfx_lock_picasso (); + lock = 1; + } else { + dst = picasso96_state.HostAddress; + } } - if (!dst) + if (dst == NULL) break; for (i = 0; i < gwwcnt; i++) { @@ -3191,7 +3186,7 @@ static void flushpixels_x (void) dst2 = dst + y * picasso_vidinfo.rowbytes; /* merge nearby pieces */ - while (i + 1 < gwwcnt && (uae_u8*)gwwbuf[i + 1] <= p + 2 * gwwpagesize) { + while (i + 1 < gwwcnt && (uae_u8*)gwwbuf[i + 1] <= p + 1 * gwwpagesize) { pscnt += gwwpagesize; p += gwwpagesize; i++; @@ -3293,21 +3288,13 @@ static void flushpixels_x (void) } if(lock) - gfx_unlock_picasso(); + gfx_unlock_picasso (); + if (dst && gwwcnt) + mman_ResetWatch (src, allocated_gfxmem); if (maxy >= 0) DX_Invalidate (0, miny, picasso96_state.Width, maxy - miny + 1); } - -static void flushpixels(void) -{ - flushpixels_x (); -} -static void flushpixels_lock (void) -{ - flushpixels(); -} - static uae_u32 REGPARAM2 gfxmem_lgetx (uaecptr addr) { uae_u32 *m; diff --git a/od-win32/picasso96_win.h b/od-win32/picasso96_win.h index 9e364395..1d97592e 100755 --- a/od-win32/picasso96_win.h +++ b/od-win32/picasso96_win.h @@ -509,7 +509,7 @@ extern void picasso_refresh (void); extern void picasso_handle_vsync (void); extern void init_hz_p96 (void); extern void picasso_handle_hsync (void); -extern void picasso_palette (void); +extern int picasso_palette (void); extern uae_u8 *gfxmemory; diff --git a/od-win32/resources/winuae.rc b/od-win32/resources/winuae.rc index 7d4d3f24..2578df4b 100755 --- a/od-win32/resources/winuae.rc +++ b/od-win32/resources/winuae.rc @@ -132,6 +132,7 @@ BEGIN EDITTEXT IDC_SLOWRAM,243,25,30,12,ES_CENTER | ES_READONLY RTEXT "Fast:",IDC_FASTTEXT,24,51,20,10,SS_CENTERIMAGE CONTROL "Slider1",IDC_FASTMEM,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,54,47,50,20 + EDITTEXT IDC_FASTRAM,105,53,30,12,ES_CENTER | ES_READONLY RTEXT "Z3 Fast:",IDC_Z3TEXT,139,51,30,10,SS_CENTERIMAGE CONTROL "Slider1",IDC_Z3FASTMEM,"msctls_trackbar32",TBS_AUTOTICKS | TBS_TOP | WS_TABSTOP,179,47,60,20 EDITTEXT IDC_Z3FASTRAM,243,50,30,12,ES_CENTER | ES_READONLY diff --git a/od-win32/win32.h b/od-win32/win32.h index 1b5b36bf..6eb92861 100755 --- a/od-win32/win32.h +++ b/od-win32/win32.h @@ -15,9 +15,9 @@ #define GETBDM(x) (((x) - ((x / 10000) * 10000)) / 100) #define GETBDD(x) ((x) % 100) -#define WINUAEBETA 5 +#define WINUAEBETA 6 #define WINUAEPUBLICBETA 1 -#define WINUAEDATE MAKEBD(2008, 3, 1) +#define WINUAEDATE MAKEBD(2008, 3, 4) #define WINUAEEXTRA "" #define WINUAEREV "" diff --git a/od-win32/win32_scale2x.c b/od-win32/win32_scale2x.c index 2036fec2..15059864 100755 --- a/od-win32/win32_scale2x.c +++ b/od-win32/win32_scale2x.c @@ -109,40 +109,19 @@ void S2X_render (void) int dst_height2 = dst_height; int dst_width3 = dst_width; int dst_height3 = dst_height; - int scale2 = scale; - - if (currprefs.gfx_filter_upscale) { - dst_width2 = amiga_width; - dst_height2 = amiga_height; - dst_width3 = amiga_width * scale; - dst_height3 = amiga_height * scale; - scale2 = 1; - } sptr = gfxvidinfo.bufmem; - v = (dst_width2 - amiga_width) / 2; - aw += v; + v = (dst_width - amiga_width * scale) / 2; sptr -= v * (amiga_depth / 8); - v = (dst_height2 - amiga_height) / 2; - ah += v; + v = (dst_height - amiga_height * scale) / 2; sptr -= v * gfxvidinfo.rowbytes; - endsptr = gfxvidinfo.bufmemend; v = currprefs.gfx_filter ? currprefs.gfx_filter_horiz_offset : 0; - v += (dst_width3 / scale - amiga_width) / 8; - sptr += (int)(-v * 4.0 / 10.0) * (amiga_depth / 8); - aw -= (int)(-v * 4.0 / 10); + sptr += (int)(-v * amiga_width / 1000.0) * (amiga_depth / 8); v = currprefs.gfx_filter ? currprefs.gfx_filter_vert_offset : 0; - v += (dst_height3 / scale - amiga_height) / 8; - sptr += (int)(-v * 4.0 / 10.0) * gfxvidinfo.rowbytes; - ah -= (int)(-v * 4.0 / 10); - - if (aw * scale > dst_width) - aw = dst_width / scale; - if (ah * scale > dst_height) - ah = dst_height / scale; + sptr += (int)(-v * amiga_height / 1000.0) * gfxvidinfo.rowbytes; if (ah < 16) return; @@ -153,21 +132,36 @@ void S2X_render (void) currprefs.gfx_filter_horiz_zoom_mult != 1000 || currprefs.gfx_filter_vert_zoom_mult != 1000 || currprefs.gfx_filter_upscale)) { - int wz = dst_width3 * currprefs.gfx_filter_horiz_zoom_mult / 1000; - int hz = dst_height3 * currprefs.gfx_filter_vert_zoom_mult / 1000; - - wz += currprefs.gfx_filter_horiz_zoom / 4; - hz += currprefs.gfx_filter_vert_zoom / 4; + double hz = currprefs.gfx_filter_horiz_zoom / 1000.0 * currprefs.gfx_filter_horiz_zoom_mult; + double vz = currprefs.gfx_filter_vert_zoom / 1000.0 * currprefs.gfx_filter_vert_zoom_mult; - sr.left = (dst_width3 - wz) / 2; - sr.top = (dst_height3 - hz) / 2; - sr.right = sr.left + wz; - sr.bottom = sr.top + hz; + sr.left = (dst_width - amiga_width * scale) / 2; + sr.top = (dst_height - amiga_height * scale) / 2; + sr.right = amiga_width * scale + sr.left; + sr.bottom = amiga_height * scale + sr.top; dr.left = dr.top = 0; dr.right = dst_width; dr.bottom = dst_height; + hz *= amiga_width / 2000.0; + if (hz > 0) { + dr.left += hz; + dr.right -= hz; + } else { + sr.left -= hz; + sr.right += hz; + } + vz *= amiga_height / 2000.0; + if (vz > 0) { + dr.top += vz; + dr.bottom -= vz; + } else { + sr.top -= vz; + sr.bottom += vz; + } + + if (sr.left >= sr.right) { sr.left = dst_width / 2 - 1; sr.right = dst_width / 2 + 1; @@ -292,10 +286,10 @@ void S2X_render (void) } else if (usedfilter->type == UAE_FILTER_PAL) { /* 16/32/1X */ if (amiga_depth == 32 && dst_depth == 32) { - PAL_1x1_32((uae_u32*)sptr, gfxvidinfo.rowbytes, (uae_u32*)dptr, pitch, aw, ah); + PAL_1x1_32 ((uae_u32*)sptr, gfxvidinfo.rowbytes, (uae_u32*)dptr, pitch, aw, ah); ok = 1; } else if (amiga_depth == 16 && dst_depth == 16) { - PAL_1x1_16((uae_u16*)sptr, gfxvidinfo.rowbytes, (uae_u16*)dptr, pitch, aw, ah); + PAL_1x1_16 ((uae_u16*)sptr, gfxvidinfo.rowbytes, (uae_u16*)dptr, pitch, aw, ah); ok = 1; } @@ -324,7 +318,7 @@ void S2X_render (void) end: if (temp_needed) { IDirectDrawSurface7_Unlock (dds, NULL); - //DirectDraw_Blt (DirectDraw_GetLockableType(), &dr, temporary_surface, &sr, 0); + DirectDraw_BlitRect (NULL, &dr, tempsurf, &sr); } else { DirectDraw_SurfaceUnlock (); } diff --git a/od-win32/win32gfx.c b/od-win32/win32gfx.c index e5298d9f..517b7879 100755 --- a/od-win32/win32gfx.c +++ b/od-win32/win32gfx.c @@ -84,8 +84,8 @@ struct winuae_currentmode { int current_width, current_height, current_depth; int amiga_width, amiga_height; int frequency; - int mapping_is_mainscreen; int initdone; + int fullfill; LPPALETTEENTRY pal; }; @@ -185,6 +185,8 @@ void centerdstrect (RECT *dr, RECT *sr) OffsetRect(dr, amigawin_rect.left, amigawin_rect.top); if (currentmode->flags & DM_W_FULLSCREEN) { int dx, dy; + if (currentmode->fullfill) + return; OffsetRect (dr, (currentmode->native_width - currentmode->current_width) / 2, (currentmode->native_height - currentmode->current_height) / 2); dx = (dr->right - dr->left) - currentmode->current_width; @@ -306,6 +308,8 @@ static int set_ddraw (void) currentmode->pitch = DirectDraw_GetSurfacePitch (); DirectDraw_SurfaceUnlock (); } + if (bits == 8) + DirectDraw_CreatePalette (currentmode->pal); } write_log ("set_ddraw() called, and is %dx%d@%d-bytes\n", width, height, bits); @@ -334,7 +338,7 @@ static HRESULT CALLBACK modesCallback (LPDDSURFACEDESC2 modeDesc, LPVOID context depth = 3; else if (ct & RGBMASK_32BIT) depth = 4; - if (depth == 0 || depth == 1) + if (depth == 0) return DDENUMRET_OK; i = 0; while (DisplayModes[i].depth >= 0) { @@ -701,9 +705,10 @@ void flush_clear_screen (void) uae_u8 *gfx_lock_picasso (void) { - uae_u8 *p = ddraw_dolock (); - picasso_vidinfo.rowbytes = DirectDraw_GetSurfacePitch(); - return p; + if (!DirectDraw_SurfaceLock ()) + return 0; + picasso_vidinfo.rowbytes = DirectDraw_GetSurfacePitch (); + return (uae_u8*)DirectDraw_GetSurfacePointer (); } /* For the DX_Invalidate() and gfx_unlock_picasso() functions */ @@ -715,21 +720,12 @@ void gfx_unlock_picasso (void) { DirectDraw_SurfaceUnlock(); if (p96_double_buffer_needs_flushing) { - /* Here, our flush_block() will deal with a offscreen-plain (back-buffer) to visible-surface (front-buffer) */ - BOOL relock = FALSE; - if (DirectDraw_IsLocked()) { - relock = TRUE; - unlockscr(); - } picasso_putcursor (p96_double_buffer_firstx, p96_double_buffer_first, p96_double_buffer_lastx - p96_double_buffer_firstx + 1, p96_double_buffer_last - p96_double_buffer_first + 1); DX_Blit (p96_double_buffer_firstx, p96_double_buffer_first, p96_double_buffer_lastx - p96_double_buffer_firstx + 1, p96_double_buffer_last - p96_double_buffer_first + 1); picasso_clearcursor (); - if (relock) { - lockscr(); - } p96_double_buffer_needs_flushing = 0; } } @@ -769,14 +765,44 @@ static void close_hwnds (void) hStatusWnd = 0; } +static void update_gfxparams (void) +{ + updatewinfsmode (&currprefs); +#ifdef PICASSO96 + if (screen_is_picasso) { + currentmode->current_width = picasso96_state.Width; + currentmode->current_height = picasso96_state.Height; + currentmode->frequency = abs (currprefs.gfx_refreshrate > default_freq ? currprefs.gfx_refreshrate : default_freq); + } else { +#endif + currentmode->current_width = currprefs.gfx_size.width; + currentmode->current_height = currprefs.gfx_size.height; + currentmode->frequency = abs (currprefs.gfx_refreshrate); +#ifdef PICASSO96 + } +#endif + currentmode->current_depth = (currprefs.color_mode == 0 ? 8 + : currprefs.color_mode == 1 ? 15 + : currprefs.color_mode == 2 ? 16 + : currprefs.color_mode == 3 ? 8 + : currprefs.color_mode == 4 ? 8 : 32); + if (screen_is_picasso && currprefs.win32_rtgmatchdepth && isfullscreen () > 0) { + int pbits = picasso96_state.BytesPerPixel * 8; + if (pbits >= 8) + currentmode->current_depth = pbits; + } + currentmode->amiga_width = currentmode->current_width; + currentmode->amiga_height = currentmode->current_height; +} + static int open_windows (void) { int ret, i; reset_sound(); in_sizemove = 0; - updatewinfsmode (&currprefs); + updatewinfsmode (&currprefs); if (!DirectDraw_Start (displayGUID)) return 0; write_log ("DirectDraw GUID=%s\n", outGUID (displayGUID)); @@ -784,31 +810,7 @@ static int open_windows (void) ret = -2; do { if (ret < -1) { -#ifdef PICASSO96 - if (screen_is_picasso) { - currentmode->current_width = picasso96_state.Width; - currentmode->current_height = picasso96_state.Height; - currentmode->frequency = abs (currprefs.gfx_refreshrate > default_freq ? currprefs.gfx_refreshrate : default_freq); - } else { -#endif - currentmode->current_width = currprefs.gfx_size.width; - currentmode->current_height = currprefs.gfx_size.height; - currentmode->frequency = abs (currprefs.gfx_refreshrate); -#ifdef PICASSO96 - } -#endif - currentmode->current_depth = (currprefs.color_mode == 0 ? 8 - : currprefs.color_mode == 1 ? 15 - : currprefs.color_mode == 2 ? 16 - : currprefs.color_mode == 3 ? 8 - : currprefs.color_mode == 4 ? 8 : 32); - if (screen_is_picasso && currprefs.win32_rtgmatchdepth && isfullscreen () > 0) { - int pbits = picasso96_state.BytesPerPixel * 8; - if (pbits >= 15) - currentmode->current_depth = pbits; - } - currentmode->amiga_width = currentmode->current_width; - currentmode->amiga_height = currentmode->current_height; + update_gfxparams (); } ret = doInit (); } while (ret < 0); @@ -1072,8 +1074,6 @@ static int get_color (int r, int g, int b, xcolnr * cnp) void init_colors (void) { -// HRESULT ddrval; - if (ncols256 == 0) { alloc_colors256 (get_color); memcpy (xcol8, xcolors, sizeof xcol8); @@ -1093,9 +1093,7 @@ void init_colors (void) { case 1: memcpy (xcolors, xcol8, sizeof xcolors); - //ddrval = DirectDraw_SetPaletteEntries(0, 256, colors256); - //if (FAILED(ddrval)) - // write_log ("DX_SetPalette() failed with %s/%d\n", DXError (ddrval), ddrval); + DirectDraw_SetPaletteEntries(0, 256, colors256); break; case 2: @@ -1141,41 +1139,38 @@ void DX_SetPalette_vsync (void) { } -void picasso_palette (void) +int picasso_palette (void) { - int i; + int i, changed; + changed = 0; for (i = 0; i < 256; i++) { int r = picasso96_state.CLUT[i].Red; int g = picasso96_state.CLUT[i].Green; int b = picasso96_state.CLUT[i].Blue; - picasso_vidinfo.clut[i] = (doMask256 (r, red_bits, red_shift) + uae_u32 v = (doMask256 (r, red_bits, red_shift) | doMask256 (g, green_bits, green_shift) | doMask256 (b, blue_bits, blue_shift)); + if (v != picasso_vidinfo.clut[i]) { + picasso_vidinfo.clut[i] = v; + changed = 1; + } } + if (changed) + DX_SetPalette (0,256); + return changed; } void DX_SetPalette (int start, int count) { if (!screen_is_picasso) return; - if (picasso_vidinfo.pixbytes != 1) return; - - /* Set our DirectX palette here */ -#if 0 - if(currentmode->current_depth == 8) { - HRESULT ddrval; - if (SUCCEEDED(DirectDraw_SetPalette(0))) { - ddrval = DirectDraw_SetPaletteEntries(start, count, (LPPALETTEENTRY)&(picasso96_state.CLUT[start])); - if (FAILED(ddrval)) - gui_message("DX_SetPalette() failed with %s/%d\n", DXError (ddrval), ddrval); - } - } else { - write_log ("ERROR - DX_SetPalette() pixbytes %d\n", currentmode->current_depth >> 3); - } -#endif + if(currentmode->current_depth > 8) + return; + if (SUCCEEDED (DirectDraw_SetPalette (0))) + DirectDraw_SetPaletteEntries (start, count, (LPPALETTEENTRY)&(picasso96_state.CLUT[start])); } void DX_Invalidate (int x, int y, int width, int height) @@ -1256,19 +1251,33 @@ static int reopen (int full) #ifdef PICASSO96 -static int modeswitchneeded (void) +static int modeswitchneeded (struct winuae_currentmode *wc) { if (isfullscreen () > 0) { - if (picasso96_state.Width != currentmode->current_width || - picasso96_state.Height != currentmode->current_height) - return -1; + if (screen_is_picasso) { + if (picasso96_state.Width != wc->current_width || + picasso96_state.Height != wc->current_height || + (picasso96_state.BytesPerPixel * 8 != wc->current_depth && currprefs.win32_rtgmatchdepth)) + return -1; + } else { + if (currentmode->current_width != wc->current_width || + currentmode->current_height != wc->current_height || + currentmode->current_depth != wc->current_depth) + return -1; + } } else if (isfullscreen () == 0) { - if (picasso96_state.Width != currentmode->current_width || - picasso96_state.Height != currentmode->current_height) - return 1; + if (screen_is_picasso) { + if (picasso96_state.Width != wc->current_width || + picasso96_state.Height != wc->current_height) + return 1; + } else { + if (currentmode->current_width != wc->current_width || + currentmode->current_height != wc->current_height) + return 1; + } } else { - if (picasso96_state.Width > currentmode->native_width || - picasso96_state.Height > currentmode->native_height) + if (picasso96_state.Width > wc->native_width || + picasso96_state.Height > wc->native_height) return -1; } return 0; @@ -1276,30 +1285,30 @@ static int modeswitchneeded (void) void gfx_set_picasso_state (int on) { + struct winuae_currentmode wc; int mode; if (screen_is_picasso == on) return; screen_is_picasso = on; - mode = modeswitchneeded (); - currentmode->current_width = picasso96_state.Width; - currentmode->current_height = picasso96_state.Height; - picasso_vidinfo.width = picasso96_state.Width; - picasso_vidinfo.height = picasso96_state.Height; + memcpy (&wc, currentmode, sizeof (wc)); + update_gfxparams (); if (currprefs.gfx_afullscreen != currprefs.gfx_pfullscreen) { mode = 1; - } else if (!mode) { - return; + } else { + mode = modeswitchneeded (&wc); + if (!mode) + return; } if (mode < 0) { open_windows (); } else { - open_screen (); + open_screen (); // reopen everything } } void gfx_set_picasso_modeinfo (uae_u32 w, uae_u32 h, uae_u32 depth, RGBFTYPE rgbfmt) { - if (screen_is_picasso && modeswitchneeded()) + if (screen_is_picasso && modeswitchneeded(currentmode)) open_screen (); } #endif @@ -1635,6 +1644,7 @@ static void updatemodes (void) { DWORD flags; + currentmode->fullfill = 0; flags = DM_DDRAW; if (isfullscreen () > 0) flags |= DM_DX_FULLSCREEN; @@ -1654,6 +1664,8 @@ static void updatemodes (void) } #endif currentmode->flags = flags; + if (flags & DM_SWSCALE) + currentmode->fullfill = 1; } static BOOL doInit (void) @@ -1832,7 +1844,7 @@ static BOOL doInit (void) #if defined (GFXFILTER) if (currentmode->flags & DM_SWSCALE) { - S2X_init (currentmode->current_width, currentmode->current_height, + S2X_init (currentmode->native_width, currentmode->native_height, currentmode->amiga_width, currentmode->amiga_height, mult, currentmode->current_depth, currentmode->native_depth); } @@ -1880,49 +1892,32 @@ oops: void WIN32GFX_PaletteChange(void) { -#if 0 - HRESULT hr; - - if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) return; + if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) + return; if (currentmode->current_depth > 8) return; - hr = DirectDraw_SetPalette (1); /* Remove current palette */ - if (FAILED(hr)) - write_log ("SetPalette(1) failed, %s\n", DXError (hr)); - hr = DirectDraw_SetPalette (0); /* Set our real palette */ - if (FAILED(hr)) - write_log ("SetPalette(0) failed, %s\n", DXError (hr)); -#endif + DirectDraw_SetPalette (1); /* Remove current palette */ + DirectDraw_SetPalette (0); /* Set our real palette */ } int WIN32GFX_ClearPalette(void) { -#if 0 - HRESULT hr; if (currentmode->current_depth > 8) return 1; - if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) return 1; - hr = DirectDraw_SetPalette (1); /* Remove palette */ - if (FAILED(hr)) - write_log ("SetPalette(1) failed, %s\n", DXError (hr)); - return SUCCEEDED(hr); -#endif - return 0; + if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) + return 1; + DirectDraw_SetPalette (1); /* Remove palette */ + return 1; } int WIN32GFX_SetPalette(void) { -#if 0 - HRESULT hr; - if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) return 1; + if (!(currentmode->flags & DM_DDRAW) || (currentmode->flags & DM_D3D)) + return 1; if (currentmode->current_depth > 8) return 1; - hr = DirectDraw_SetPalette (0); /* Set palette */ - if (FAILED(hr)) - write_log ("SetPalette(0) failed, %s\n", DXError (hr)); - return SUCCEEDED(hr); -#endif - return 0; + DirectDraw_SetPalette (0); /* Set palette */ + return 1; } void WIN32GFX_WindowMove (void) { diff --git a/od-win32/win32gui.c b/od-win32/win32gui.c index e76c2517..fd650b63 100755 --- a/od-win32/win32gui.c +++ b/od-win32/win32gui.c @@ -446,7 +446,6 @@ static char *favoritepopup (HWND hwnd) str = my_strdup (tmp2); fname = my_strdup (tmp2); } - str = my_strdup (tmp2); paths[idx2] = fname; values[idx2] = str; } @@ -481,7 +480,7 @@ static char *favoritepopup (HWND hwnd) } for (i = 0; i < idx; i++) { xfree (values[i]); - if (i + 1 != ret) + if (i != ret - 1) xfree (paths[i]); } if (ret == 0) @@ -4018,16 +4017,14 @@ static void init_display_mode (HWND hDlg) d = 16; break; case 5: - d = 32; - break; default: - d = 8; + d = 32; break; } if (workprefs.gfx_afullscreen) { d2 = d; - if ((index = WIN32GFX_AdjustScreenmode(&workprefs.gfx_size_fs.width, &workprefs.gfx_size_fs.height, &d2)) >= 0) { + if ((index = WIN32GFX_AdjustScreenmode (&workprefs.gfx_size_fs.width, &workprefs.gfx_size_fs.height, &d2)) >= 0) { switch (d2) { case 15: @@ -4039,13 +4036,10 @@ static void init_display_mode (HWND hDlg) d = 2; break; case 32: + default: workprefs.color_mode = 5; d = 4; break; - default: - workprefs.color_mode = 0; - d = 1; - break; } } } else { @@ -4059,7 +4053,7 @@ static void init_display_mode (HWND hDlg) cnt = 0; gui_display_depths[0] = gui_display_depths[1] = gui_display_depths[2] = -1; for (i = 0; DisplayModes[i].depth >= 0; i++) { - if (DisplayModes[i].residx == DisplayModes[index].residx) { + if (DisplayModes[i].depth > 1 && DisplayModes[i].residx == DisplayModes[index].residx) { char tmp[64]; sprintf (tmp, "%d", DisplayModes[i].depth * 8); SendDlgItemMessage(hDlg, IDC_RESOLUTIONDEPTH, CB_ADDSTRING, 0, (LPARAM)tmp); @@ -4201,7 +4195,7 @@ static void init_resolution_combo (HWND hDlg) SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_RESETCONTENT, 0, 0); while (DisplayModes[i].depth >= 0) { - if (DisplayModes[i].residx != idx) { + if (DisplayModes[i].depth > 1 && DisplayModes[i].residx != idx) { sprintf (tmp, "%dx%d", DisplayModes[i].res.width, DisplayModes[i].res.height); SendDlgItemMessage(hDlg, IDC_RESOLUTION, CB_ADDSTRING, 0, (LPARAM)tmp); idx = DisplayModes[i].residx; @@ -5828,7 +5822,7 @@ static void values_from_cpudlg (HWND hDlg) #ifdef JIT oldcache = workprefs.cachesize; jitena = IsDlgButtonChecked (hDlg, IDC_JITENABLE) ? 1 : 0; - workprefs.cachesize = SendMessage(GetDlgItem(hDlg, IDC_CACHE), TBM_GETPOS, 0, 0) * 1024; + workprefs.cachesize = SendMessage (GetDlgItem(hDlg, IDC_CACHE), TBM_GETPOS, 0, 0) * 1024; if (!jitena) { cachesize_prev = workprefs.cachesize; comptrust_prev = workprefs.comptrustbyte; @@ -7536,9 +7530,11 @@ static int diskselectmenu (HWND hDlg, WPARAM wParam) char *s = favoritepopup (hDlg); if (s) { int num = id == IDC_DF0QQ ? 0 : 1; - diskselect (hDlg, id, &workprefs, num, s); + char tmp[MAX_DPATH]; + strcpy (tmp, s); + xfree (s); + diskselect (hDlg, id, &workprefs, num, tmp); } - xfree (s); return 1; } return 0; @@ -8946,7 +8942,6 @@ static void enable_for_hw3ddlg (HWND hDlg) ew (hDlg, IDC_FILTERPRESETSAVE, filterpreset_builtin < 0); ew (hDlg, IDC_FILTERPRESETLOAD, filterpreset_selected > 0); ew (hDlg, IDC_FILTERPRESETDELETE, filterpreset_selected > 0 && filterpreset_builtin < 0); - CheckDlgButton(hDlg, IDC_FILTERUPSCALE, workprefs.gfx_filter_upscale); } static void makefilter(char *s, int x, int flags) @@ -9019,6 +9014,9 @@ static void values_to_hw3ddlg (HWND hDlg) struct uae_filter *uf; UAEREG *fkey; + CheckDlgButton(hDlg, IDC_FILTERUPSCALE, workprefs.gfx_filter_upscale); + CheckDlgButton(hDlg, IDC_FILTERAUTORES, workprefs.gfx_autoresolution); + SendDlgItemMessage(hDlg, IDC_FILTERHZ, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); SendDlgItemMessage(hDlg, IDC_FILTERHZ, TBM_SETPAGESIZE, 0, 1); SendDlgItemMessage(hDlg, IDC_FILTERVZ, TBM_SETRANGE, TRUE, MAKELONG (-999, +999)); diff --git a/od-win32/win32gui_extra.c b/od-win32/win32gui_extra.c index 46d8322b..50739eb9 100755 --- a/od-win32/win32gui_extra.c +++ b/od-win32/win32gui_extra.c @@ -25,7 +25,7 @@ #include "win32.h" #include "win32gui.h" -static int max_w, max_h, mult, pointsize; +static int max_w = 800, max_h = 600, mult = 100, pointsize; #include typedef struct { diff --git a/od-win32/winuaechangelog.txt b/od-win32/winuaechangelog.txt index 04ec2b4d..eb0187f7 100755 --- a/od-win32/winuaechangelog.txt +++ b/od-win32/winuaechangelog.txt @@ -1,9 +1,28 @@ +Beta 6: + +NOTE: Do not use filters, do not use vsync. + +- real 8-bit RTG mode work (fullscreen only) +- buffer overflow in floppy image favorite shortcut code +- disappeared Z2 fast ram amount box is back +- Z3 but no RTG RAM allocation failure fixed +- Picasso96 BltPattern and BltTemplate COMPLEMENT-mode uses now native + code +- Picasso96 "new" mode is now Windows 2000 compatible. NOTE: this is + not 100% correct yet, graphics errors possible. W2K workaround mode + is also slower than Windows XP+ mode +- Picasso96 RectFill() optimization (2x speedup here) +- some mode switching crashes/graphics errors fixed +- write warning to log if blitter is forced off in devs:monitors/uaegfx +- 8-bit modes removed from display-panel GUI. Native (custom chipset) + display modes need at least 16-bit color depth now. RTG 8-bit still + supported. + Beta 5: NOTE: filters are currently not supported, they may or may not work -NOTE: filter support rewrite coming soon.. -NOTE: vsync not supported. expect flashes or other issues.. +NOTE: vsync not supported. expect flashing or other issues.. - "favorite path" editing added. Path added is always last opened path from any file select dialog. (later..) @@ -24,9 +43,10 @@ NOTE: vsync not supported. expect flashes or other issues.. still work and are automatically converted to 16/32-bit - "Match RTG color depth" option added to misc-panel. If checked fullscreen RTG mode uses Amiga-side color depth (as previously) - Not checked = always use Display panel depth setting. - Windowed mode always uses desktop color depth - + Not checked = always use Display panel depth setting. (if you have + programs that switch modes but you don't want Windows-side display + mode changes) Windowed mode always uses desktop color depth +- GUI debugger updates (KB) Beta 4: diff --git a/p96_blit.c b/p96_blit.c index a2d37c96..45529b28 100755 --- a/p96_blit.c +++ b/p96_blit.c @@ -6,12 +6,14 @@ static void NOINLINE BLT_NAME (unsigned int w, unsigned int h, uae_u8 *src, uae_ uae_u32 *src2_32 = (uae_u32*)src; uae_u32 *dst2_32 = (uae_u32*)dst; unsigned int y, x, ww, xxd; +#ifdef BLT_TEMP #if BLT_SIZE == 4 uae_u32 tmp; #elif BLT_SIZE == 2 uae_u16 tmp; #else uae_u8 tmp; +#endif #endif if (w < 8 * BLT_MULT) { @@ -97,4 +99,7 @@ static void NOINLINE BLT_NAME (unsigned int w, unsigned int h, uae_u8 *src, uae_ } } #undef BLT_NAME -#undef BLT_FUNC \ No newline at end of file +#undef BLT_FUNC +#ifdef BLT_TEMP +#undef BLT_TEMP +#endif \ No newline at end of file -- 2.47.3