--- np2/win9x/dialog/d_mpu98.cpp 2003/10/31 03:40:10 1.4 +++ np2/win9x/dialog/d_mpu98.cpp 2007/12/29 12:56:22 1.12 @@ -2,12 +2,13 @@ #include "strres.h" #include "resource.h" #include "np2.h" +#include "oemtext.h" #include "commng.h" #include "sysmng.h" #include "dialog.h" #include "dialogs.h" -#include "bit2res.h" #include "pccore.h" +#include "dipswbmp.h" #ifdef __cplusplus @@ -20,91 +21,72 @@ extern COMMNG cm_mpu98; } #endif -static const char *mpuinterrupt[4] = {str_int0, str_int1, str_int2, str_int5}; +static const CBPARAM cpInt[] = +{ + {MAKEINTRESOURCE(IDS_INT0), 0}, + {MAKEINTRESOURCE(IDS_INT1), 1}, + {MAKEINTRESOURCE(IDS_INT2), 2}, + {MAKEINTRESOURCE(IDS_INT5), 3}, +}; -static BYTE mpu = 0; +static UINT8 mpu = 0; - -static void setmpuiopara(HWND hWnd, WORD res, BYTE value) { - - SendDlgItemMessage(hWnd, res, CB_SETCURSEL, - (WPARAM)((value >> 4) & 15), (LPARAM)0); +static void setmpuio(HWND hWnd, UINT8 cValue) +{ + dlgs_setcbcur(hWnd, IDC_MPUIO, (cValue & 0xf0)); } -static BYTE getmpuio(HWND hWnd, WORD res) { - - char work[8]; - - GetDlgItemText(hWnd, res, work, sizeof(work)); - return((milstr_solveHEX(work) >> 6) & 0xf0); +static UINT8 getmpuio(HWND hWnd) +{ + return dlgs_getcbcur(hWnd, IDC_MPUIO, 0x00); } -static void setmpuintpara(HWND hWnd, WORD res, BYTE value) { - - SendDlgItemMessage(hWnd, res, CB_SETCURSEL, - (WPARAM)(value & 3), (LPARAM)0); +static void setmpuint(HWND hWnd, UINT8 cValue) +{ + dlgs_setcbcur(hWnd, IDC_MPUINT, (cValue & 0x03)); } -static BYTE getmpuint(HWND hWnd, WORD res) { - - char work[8]; - BYTE ret; - - GetDlgItemText(hWnd, res, work, sizeof(work)); - ret = work[3] - '0'; - if (ret >= 3) { - ret = 3; - } - return(ret); +static UINT8 getmpuint(HWND hWnd) +{ + return dlgs_getcbcur(hWnd, IDC_MPUINT, 0x00); } -static void setmpujmp(HWND hWnd, BYTE value, BYTE bit) { - - if ((mpu ^ value) & bit) { - mpu &= ~bit; - mpu |= value; +static void setmpujmp(HWND hWnd, UINT8 cValue, UINT8 cBit) +{ + if ((mpu ^ cValue) & cBit) + { + mpu &= ~cBit; + mpu |= cValue; InvalidateRect(GetDlgItem(hWnd, IDC_MPUDIP), NULL, TRUE); } } -static void setmpuiodip(BYTE *image, int px, int py, int align, BYTE v) { - - int i, j, y; - - px *= 9; - px++; - py *= 9; - for (i=0; i<4; i++, px+=9, v<<=1) { - y = py + ((v&0x80)?5:9); - for (j=0; j<3; j++) { - dlgs_linex(image, px, y+j, 7, align, 2); - } - } -} - -static void setmpuintdip(BYTE *image, int px, int py, int align, BYTE v) { - - dlgs_setjumpery(image, px + 3 - (mpu & 3), py, align); -} - // ---- -static void mpucreate(HWND hWnd) { - +static void mpucreate(HWND hWnd) +{ UINT i; - char buf[8]; + TCHAR szBuf[8]; + int nIndex; HWND sub; mpu = np2cfg.mpuopt; - for (i=0; i<16; i++) { - wsprintf(buf, str_4X, 0xC0D0 + (i << 10)); - SendDlgItemMessage(hWnd, IDC_MPUIO, - CB_INSERTSTRING, (WPARAM)i, (LPARAM)buf); - } - setmpuiopara(hWnd, IDC_MPUIO, mpu); - SETLISTSTR(hWnd, IDC_MPUINT, mpuinterrupt); - setmpuintpara(hWnd, IDC_MPUINT, mpu); + for (i=0; i<16; i++) + { + wsprintf(szBuf, tchar_4X, 0xC0D0 + (i << 10)); + nIndex = (int)SendDlgItemMessage(hWnd, IDC_MPUIO, CB_ADDSTRING, + 0, (LPARAM)szBuf); + if (nIndex >= 0) + { + SendDlgItemMessage(hWnd, IDC_MPUIO, CB_SETITEMDATA, + (WPARAM)nIndex, (LPARAM)(i << 4)); + } + } + setmpuio(hWnd, mpu); + + dlgs_setcbitem(hWnd, IDC_MPUINT, cpInt, NELEMENTS(cpInt)); + setmpuint(hWnd, mpu); dlgs_setlistmidiout(hWnd, IDC_MPU98MMAP, np2oscfg.mpu.mout); dlgs_setlistmidiin(hWnd, IDC_MPU98MDIN, np2oscfg.mpu.min); @@ -124,10 +106,10 @@ static void mpucreate(HWND hWnd) { static void mpuupdate(HWND hWnd) { union { - char mmap[MAXPNAMELEN]; - char mmdl[64]; - char mdef[MAX_PATH]; - char mdin[MAXPNAMELEN]; + OEMCHAR mmap[MAXPNAMELEN]; + OEMCHAR mmdl[64]; + OEMCHAR mdef[MAX_PATH]; + OEMCHAR mdin[MAXPNAMELEN]; } s; UINT update; @@ -136,19 +118,19 @@ static void mpuupdate(HWND hWnd) { np2cfg.mpuopt = mpu; update |= SYS_UPDATECFG | SYS_UPDATEMIDI; } - GetDlgItemText(hWnd, IDC_MPU98MMAP, s.mmap, sizeof(s.mmap)); + GetDlgItemText(hWnd, IDC_MPU98MMAP, s.mmap, NELEMENTS(s.mmap)); if (milstr_cmp(np2oscfg.mpu.mout, s.mmap)) { - milstr_ncpy(np2oscfg.mpu.mout, s.mmap, sizeof(np2oscfg.mpu.mout)); + milstr_ncpy(np2oscfg.mpu.mout, s.mmap, NELEMENTS(np2oscfg.mpu.mout)); update |= SYS_UPDATEOSCFG | SYS_UPDATEMIDI; } - GetDlgItemText(hWnd, IDC_MPU98MDIN, s.mdin, sizeof(s.mdin)); + GetDlgItemText(hWnd, IDC_MPU98MDIN, s.mdin, NELEMENTS(s.mdin)); if (milstr_cmp(np2oscfg.mpu.min, s.mdin)) { - milstr_ncpy(np2oscfg.mpu.min, s.mdin, sizeof(np2oscfg.mpu.min)); + milstr_ncpy(np2oscfg.mpu.min, s.mdin, NELEMENTS(np2oscfg.mpu.min)); update |= SYS_UPDATEOSCFG | SYS_UPDATEMIDI; } - GetDlgItemText(hWnd, IDC_MPU98MMDL, s.mmdl, sizeof(s.mmdl)); + GetDlgItemText(hWnd, IDC_MPU98MMDL, s.mmdl, NELEMENTS(s.mmdl)); if (milstr_cmp(np2oscfg.mpu.mdl, s.mmdl)) { - milstr_ncpy(np2oscfg.mpu.mdl, s.mmdl, sizeof(np2oscfg.mpu.mdl)); + milstr_ncpy(np2oscfg.mpu.mdl, s.mmdl, NELEMENTS(np2oscfg.mpu.mdl)); update |= SYS_UPDATEOSCFG | SYS_UPDATEMIDI; } @@ -156,9 +138,9 @@ static void mpuupdate(HWND hWnd) { if (cm_mpu98) { cm_mpu98->msg(cm_mpu98, COMMSG_MIMPIDEFEN, np2oscfg.mpu.def_en); } - GetDlgItemText(hWnd, IDC_MPU98DEFF, s.mdef, sizeof(s.mdef)); + GetDlgItemText(hWnd, IDC_MPU98DEFF, s.mdef, NELEMENTS(s.mdef)); if (milstr_cmp(np2oscfg.mpu.def, s.mdef)) { - milstr_ncpy(np2oscfg.mpu.def, s.mdef, sizeof(np2oscfg.mpu.def)); + milstr_ncpy(np2oscfg.mpu.def, s.mdef, NELEMENTS(np2oscfg.mpu.def)); if (cm_mpu98) { cm_mpu98->msg(cm_mpu98, COMMSG_MIMPIDEFFILE, (long)s.mdef); } @@ -172,11 +154,13 @@ static void mpucmddipsw(HWND hWnd) { RECT rect1; RECT rect2; POINT p; - BYTE bit; + BOOL redraw; + UINT8 bit; GetWindowRect(GetDlgItem(hWnd, IDC_MPUDIP), &rect1); GetClientRect(GetDlgItem(hWnd, IDC_MPUDIP), &rect2); GetCursorPos(&p); + redraw = FALSE; p.x += rect2.left - rect1.left; p.y += rect2.top - rect1.top; p.x /= 9; @@ -187,47 +171,21 @@ static void mpucmddipsw(HWND hWnd) { if ((p.x >= 2) && (p.x < 6)) { bit = 0x80 >> (p.x - 2); mpu ^= bit; - setmpuiopara(hWnd, IDC_MPUIO, mpu); - InvalidateRect(GetDlgItem(hWnd, IDC_MPUDIP), NULL, TRUE); + setmpuio(hWnd, mpu); + redraw = TRUE; } else if ((p.x >= 9) && (p.x < 13)) { - bit = (BYTE)(12 - p.x); + bit = (UINT8)(12 - p.x); if ((mpu ^ bit) & 3) { mpu &= ~0x3; mpu |= bit; - setmpuintpara(hWnd, IDC_MPUINT, mpu); - InvalidateRect(GetDlgItem(hWnd, IDC_MPUDIP), NULL, TRUE); + setmpuint(hWnd, mpu); + redraw = TRUE; } } -} - -static void mpudrawdipsw(HWND hWnd, HDC hdc) { - - BITMAPINFO *bmi; - HBITMAP hbmp; - BYTE *image; - int align; - BYTE *imgbtm; - HDC hmdc; - - bmi = (BITMAPINFO *)_MALLOC(bit2res_getsize(&mpudip), "bitmap"); - if (bmi == NULL) { - return; + if (redraw) { + InvalidateRect(GetDlgItem(hWnd, IDC_MPUDIP), NULL, TRUE); } - bit2res_sethead(bmi, &mpudip); - hbmp = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, - (void **)&image, NULL, 0); - bit2res_setdata(image, &mpudip); - align = ((mpudip.x + 7) / 2) & ~3; - imgbtm = image + align * (mpudip.y - 1); - setmpuiodip(imgbtm, 2, 1, align, mpu); - setmpuintdip(imgbtm, 9, 1, align, mpu); - hmdc = CreateCompatibleDC(hdc); - SelectObject(hmdc, hbmp); - BitBlt(hdc, 0, 0, mpudip.x, mpudip.y, hmdc, 0, 0, SRCCOPY); - DeleteDC(hmdc); - DeleteObject(hbmp); - _MFREE(bmi); } LRESULT CALLBACK MidiDialogProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp) { @@ -249,17 +207,17 @@ LRESULT CALLBACK MidiDialogProc(HWND hWn break; case IDC_MPUIO: - setmpujmp(hWnd, getmpuio(hWnd, IDC_MPUIO), 0xf0); + setmpujmp(hWnd, getmpuio(hWnd), 0xf0); return(FALSE); case IDC_MPUINT: - setmpujmp(hWnd, getmpuint(hWnd, IDC_MPUINT), 0x03); + setmpujmp(hWnd, getmpuint(hWnd), 0x03); return(FALSE); case IDC_MPUDEF: mpu = 0x82; - setmpuiopara(hWnd, IDC_MPUIO, mpu); - setmpuintpara(hWnd, IDC_MPUINT, mpu); + setmpuio(hWnd, mpu); + setmpuint(hWnd, mpu); InvalidateRect(GetDlgItem(hWnd, IDC_MPUDIP), NULL, TRUE); return(FALSE); @@ -275,7 +233,8 @@ LRESULT CALLBACK MidiDialogProc(HWND hWn case WM_DRAWITEM: if (LOWORD(wp) == IDC_MPUDIP) { - mpudrawdipsw(hWnd, ((LPDRAWITEMSTRUCT)lp)->hDC); + dlgs_drawbmp(((LPDRAWITEMSTRUCT)lp)->hDC, + dipswbmp_getmpu(mpu)); } return(FALSE);