From 327e3ca0bc1acd933d5cf62616c5aba5f87e8bbb Mon Sep 17 00:00:00 2001 From: dgis Date: Mon, 3 Dec 2018 21:25:18 +0000 Subject: [PATCH] --- app/src/main/cpp/win32-layer.c | 39 ++++++++++++++++--- app/src/main/cpp/win32-layer.h | 6 +++ .../regis/cosnier/emu48/MainScreenView.java | 10 +++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index bcfb96c..da79496 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -687,6 +687,8 @@ BOOL DeleteObject(HGDIOBJ ho) { switch(ho->handleType) { case HGDIOBJ_TYPE_PALETTE: { ho->handleType = 0; + if(ho->paletteLog) + free(ho->paletteLog); ho->paletteLog = NULL; free(ho); return TRUE; @@ -710,7 +712,11 @@ HPALETTE CreatePalette(CONST LOGPALETTE * plpal) { HGDIOBJ handle = (HGDIOBJ)malloc(sizeof(_HGDIOBJ)); memset(handle, 0, sizeof(_HGDIOBJ)); handle->handleType = HGDIOBJ_TYPE_PALETTE; - handle->paletteLog = (PLOGPALETTE)plpal; // Can be free -> we have to make a copy + if(plpal && plpal->palNumEntries >= 0 && plpal->palNumEntries <= 256) { + size_t structSize = sizeof(LOGPALETTE) + sizeof(PALETTEENTRY) * (size_t)(plpal->palNumEntries - 1); + handle->paletteLog = malloc(structSize); + memcpy(handle->paletteLog, plpal, structSize); + } return handle; } HPALETTE SelectPalette(HDC hdc, HPALETTE hPal, BOOL bForceBkgd) { @@ -806,6 +812,9 @@ BOOL StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdc float destinationStride = androidBitmapInfo.stride; // Destination always 4 bytes RGBA LOGD("StretchBlt(%08x, x:%d, y:%d, w:%d, h:%d, %08x, x:%d, y:%d, w:%d, h:%d) -> sourceBytes: %d", hdcDest->hdcCompatible, xDest, yDest, wDest, hDest, hdcSrc, xSrc, ySrc, wSrc, hSrc, sourceBytes); + PALETTEENTRY * palPalEntry = hdcSrc->selectedPalette && hdcSrc->selectedPalette->paletteLog && hdcSrc->selectedPalette->paletteLog->palPalEntry ? + hdcSrc->selectedPalette->paletteLog->palPalEntry : NULL; + for (float y = yDest; y < dst_maxy; y++) { float src_curx = xSrc; @@ -820,10 +829,18 @@ BOOL StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdc // -> ARGB_8888 switch (sourceBytes) { case 1: - destinationPixel[0] = sourcePixel[0]; - destinationPixel[1] = sourcePixel[0]; - destinationPixel[2] = sourcePixel[0]; - destinationPixel[3] = 255; + if(palPalEntry) { + BYTE colorIndex = sourcePixel[0]; + destinationPixel[0] = palPalEntry[colorIndex].peRed; + destinationPixel[1] = palPalEntry[colorIndex].peGreen; + destinationPixel[2] = palPalEntry[colorIndex].peBlue; + destinationPixel[3] = 255; + } else { + destinationPixel[0] = sourcePixel[0]; + destinationPixel[1] = sourcePixel[0]; + destinationPixel[2] = sourcePixel[0]; + destinationPixel[3] = 255; + } break; case 3: destinationPixel[0] = sourcePixel[0]; @@ -855,7 +872,17 @@ BOOL StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdc return FALSE; } UINT SetDIBColorTable(HDC hdc, UINT iStart, UINT cEntries, CONST RGBQUAD *prgbq) { - //TODO + if(prgbq + && hdc && hdc->selectedPalette && hdc->selectedPalette->paletteLog && hdc->selectedPalette->paletteLog->palPalEntry + && hdc->selectedPalette->paletteLog->palNumEntries > 0 && iStart < hdc->selectedPalette->paletteLog->palNumEntries) { + PALETTEENTRY * palPalEntry = hdc->selectedPalette->paletteLog->palPalEntry; + for (int i = iStart, j = 0; i < cEntries; i++, j++) { + palPalEntry[i].peRed = prgbq[j].rgbRed; + palPalEntry[i].peGreen = prgbq[j].rgbGreen; + palPalEntry[i].peBlue = prgbq[j].rgbBlue; + palPalEntry[i].peFlags = 0; + } + } return 0; } HBITMAP CreateDIBitmap( HDC hdc, CONST BITMAPINFOHEADER *pbmih, DWORD flInit, CONST VOID *pjBits, CONST BITMAPINFO *pbmi, UINT iUsage) { diff --git a/app/src/main/cpp/win32-layer.h b/app/src/main/cpp/win32-layer.h index b3b8c64..cdc4866 100644 --- a/app/src/main/cpp/win32-layer.h +++ b/app/src/main/cpp/win32-layer.h @@ -573,6 +573,11 @@ extern HPALETTE CreatePalette(CONST LOGPALETTE * plpal); // DC +enum DC_TYPE { + DC_TYPE_INVALID = 0, + DC_TYPE_MEMORY, + DC_TYPE_DISPLAY +}; enum HDC_TYPE { HDC_TYPE_INVALID = 0, HDC_TYPE_DC @@ -582,6 +587,7 @@ typedef struct _HDC * HDC; struct _HDC{ enum HDC_TYPE handleType; HDC hdcCompatible; + enum DC_TYPE dcType; HBITMAP selectedBitmap; HPALETTE selectedPalette; }; diff --git a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java index b0c7de5..760f345 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java +++ b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java @@ -157,6 +157,16 @@ public class MainScreenView extends SurfaceView { vkmap.put(KeyEvent.KEYCODE_NUMPAD_7, 0x67); // VK_NUMPAD7 vkmap.put(KeyEvent.KEYCODE_NUMPAD_8, 0x68); // VK_NUMPAD8 vkmap.put(KeyEvent.KEYCODE_NUMPAD_9, 0x69); // VK_NUMPAD9 + vkmap.put(KeyEvent.KEYCODE_0, 0x60); // VK_NUMPAD0 + vkmap.put(KeyEvent.KEYCODE_1, 0x61); // VK_NUMPAD1 + vkmap.put(KeyEvent.KEYCODE_2, 0x62); // VK_NUMPAD2 + vkmap.put(KeyEvent.KEYCODE_3, 0x63); // VK_NUMPAD3 + vkmap.put(KeyEvent.KEYCODE_4, 0x64); // VK_NUMPAD4 + vkmap.put(KeyEvent.KEYCODE_5, 0x65); // VK_NUMPAD5 + vkmap.put(KeyEvent.KEYCODE_6, 0x66); // VK_NUMPAD6 + vkmap.put(KeyEvent.KEYCODE_7, 0x67); // VK_NUMPAD7 + vkmap.put(KeyEvent.KEYCODE_8, 0x68); // VK_NUMPAD8 + vkmap.put(KeyEvent.KEYCODE_9, 0x69); // VK_NUMPAD9 vkmap.put(KeyEvent.KEYCODE_NUMPAD_MULTIPLY, 0x6A); // VK_MULTIPLY vkmap.put(KeyEvent.KEYCODE_NUMPAD_ADD, 0x6B); // VK_ADD vkmap.put(KeyEvent.KEYCODE_NUMPAD_SUBTRACT, 0x6D); // VK_SUBTRACT