| version 1.9, 2003/11/04 19:23:03 | version 1.22, 2011/03/07 09:54:11 | 
| Line 1 | Line 1 | 
| #include        "compiler.h" | /** | 
| #include        <prsht.h> | * @file        d_serial.cpp | 
| #include        "strres.h" | * @brief       Serial configure dialog procedure | 
| #include        "resource.h" | * | 
| #include        "np2.h" | * @author      $Author$ | 
| #include        "dosio.h" | * @date        $Date$ | 
| #include        "commng.h" | */ | 
| #include        "sysmng.h" |  | 
| #include        "np2class.h" | #include "compiler.h" | 
| #include        "dialog.h" | #include <prsht.h> | 
| #include        "dialogs.h" | #include "strres.h" | 
| #include        "bit2res.h" | #include "resource.h" | 
| #include        "pccore.h" | #include "np2.h" | 
| #include        "iocore.h" | #include "dosio.h" | 
| #include        "pc9861k.h" | #include "commng.h" | 
|  | #include "sysmng.h" | 
|  | #include "np2class.h" | 
| static const char str_none[] = "NONE"; | #include "dialog.h" | 
| static const char str_com1[] = "COM1"; | #include "dialogs.h" | 
| static const char str_com2[] = "COM2"; | #include "pccore.h" | 
| static const char str_com3[] = "COM3"; | #include "iocore.h" | 
| static const char str_com4[] = "COM4"; | #include "pc9861k.h" | 
| static const char str_midi[] = "MIDI"; | #include "dipswbmp.h" | 
| static const char str_odd[] = "ODD"; |  | 
| static const char str_even[] = "EVEN"; | #if !defined(__GNUC__) | 
| static const char str_one[] = "1"; | #pragma comment(lib, "comctl32.lib") | 
| static const char str_onehalf[] = "1.5"; | #endif  // !defined(__GNUC__) | 
| static const char str_two[] = "2"; |  | 
|  | static const CBPARAM cpPort[] = | 
| static const char *rsport[] = {str_none, str_com1, str_com2, str_com3, | { | 
| str_com4, str_midi}; | {MAKEINTRESOURCE(IDS_NONCONNECT),       COMPORT_NONE}, | 
| static const UINT32 rscharsize[] = {5, 6, 7, 8}; | {MAKEINTRESOURCE(IDS_COM1),                     COMPORT_COM1}, | 
| static const char *rsparity[] = {str_none, str_odd, str_even}; | {MAKEINTRESOURCE(IDS_COM2),                     COMPORT_COM2}, | 
| static const char *rsstopbit[] = {str_one, str_onehalf, str_two}; | {MAKEINTRESOURCE(IDS_COM3),                     COMPORT_COM3}, | 
|  | {MAKEINTRESOURCE(IDS_COM4),                     COMPORT_COM4}, | 
|  | {MAKEINTRESOURCE(IDS_MIDI),                     COMPORT_MIDI}, | 
|  | }; | 
 |  |  | 
| static const char str_seropt[] = "Serial option"; | static const CBNPARAM cpChars[] = | 
|  | { | 
|  | {5,     0x00}, | 
|  | {6,     0x04}, | 
|  | {7,     0x08}, | 
|  | {8,     0x0c}, | 
|  | }; | 
|  |  | 
|  | static const CBPARAM cpParity[] = | 
|  | { | 
|  | {MAKEINTRESOURCE(IDS_PARITY_NONE),  0x00}, | 
|  | {MAKEINTRESOURCE(IDS_PARITY_ODD),   0x20}, | 
|  | {MAKEINTRESOURCE(IDS_PARITY_EVEN),      0x30}, | 
|  | }; | 
|  |  | 
|  | static const CBPARAM cpSBit[] = | 
|  | { | 
|  | {MAKEINTRESOURCE(IDS_1),                    0x40}, | 
|  | {MAKEINTRESOURCE(IDS_1HALF),                0x80}, | 
|  | {MAKEINTRESOURCE(IDS_2),                        0xc0}, | 
|  | }; | 
 |  |  | 
 |  |  | 
 | #ifdef __cplusplus | #ifdef __cplusplus | 
| Line 49  extern COMMNG cm_pc9861ch2; | Line 72  extern COMMNG cm_pc9861ch2; | 
 |  |  | 
 | enum { | enum { | 
 | ID_PORT         = 0, | ID_PORT         = 0, | 
 |  |  | 
 | ID_SPEED, | ID_SPEED, | 
 | ID_CHARS, | ID_CHARS, | 
 | ID_PARITY, | ID_PARITY, | 
 | ID_SBIT, | ID_SBIT, | 
 |  |  | 
 | ID_MMAP, | ID_MMAP, | 
 | ID_MMDL, | ID_MMDL, | 
 | ID_DEFE, | ID_DEFE, | 
| Line 63  enum { | Line 88  enum { | 
 | }; | }; | 
 |  |  | 
 | typedef struct { | typedef struct { | 
| WORD    idc[ID_MAX]; | UINT16          idc[ID_MAX]; | 
| COMMNG  *cm; | COMMNG          *cm; | 
| COMCFG  *cfg; | COMCFG          *cfg; | 
| const WORD      *com_item; | const UINT16    *com_item; | 
| const WORD      *midi_item; | const UINT16    *midi_item; | 
| UINT    update; | UINT            update; | 
 | } DLGCOM_P; | } DLGCOM_P; | 
 |  |  | 
 |  |  | 
| static const WORD com1serial[8] = { | static const UINT16 com1serial[8] = { | 
 | IDC_COM1STR00, IDC_COM1STR01, IDC_COM1STR02, IDC_COM1STR03, | IDC_COM1STR00, IDC_COM1STR01, IDC_COM1STR02, IDC_COM1STR03, | 
 | IDC_COM1STR04, IDC_COM1STR05, IDC_COM1STR06, IDC_COM1STR07}; | IDC_COM1STR04, IDC_COM1STR05, IDC_COM1STR06, IDC_COM1STR07}; | 
 |  |  | 
| static const WORD com1rsmidi[3] = { | static const UINT16 com1rsmidi[3] = { | 
 | IDC_COM1STR10, IDC_COM1STR11, IDC_COM1STR12}; | IDC_COM1STR10, IDC_COM1STR11, IDC_COM1STR12}; | 
 |  |  | 
 | static const DLGCOM_P res_com1 = | static const DLGCOM_P res_com1 = | 
| Line 88  static const DLGCOM_P res_com1 = | Line 113  static const DLGCOM_P res_com1 = | 
 | com1serial, com1rsmidi, SYS_UPDATESERIAL1}; | com1serial, com1rsmidi, SYS_UPDATESERIAL1}; | 
 |  |  | 
 |  |  | 
| static const WORD com2serial[8] = { | static const UINT16 com2serial[8] = { | 
 | IDC_COM2STR00, IDC_COM2STR01, IDC_COM2STR02, IDC_COM2STR03, | IDC_COM2STR00, IDC_COM2STR01, IDC_COM2STR02, IDC_COM2STR03, | 
 | IDC_COM2STR04, IDC_COM2STR05, IDC_COM2STR06, IDC_COM2STR07}; | IDC_COM2STR04, IDC_COM2STR05, IDC_COM2STR06, IDC_COM2STR07}; | 
 |  |  | 
| static const WORD com2rsmidi[3] = { | static const UINT16 com2rsmidi[3] = { | 
 | IDC_COM2STR10, IDC_COM2STR11, IDC_COM2STR12}; | IDC_COM2STR10, IDC_COM2STR11, IDC_COM2STR12}; | 
 |  |  | 
 | static const DLGCOM_P res_com2 = | static const DLGCOM_P res_com2 = | 
| Line 104  static const DLGCOM_P res_com2 = | Line 129  static const DLGCOM_P res_com2 = | 
 | com2serial, com2rsmidi, SYS_UPDATESERIAL1}; | com2serial, com2rsmidi, SYS_UPDATESERIAL1}; | 
 |  |  | 
 |  |  | 
| static const WORD com3serial[8] = { | static const UINT16 com3serial[8] = { | 
 | IDC_COM3STR00, IDC_COM3STR01, IDC_COM3STR02, IDC_COM3STR03, | IDC_COM3STR00, IDC_COM3STR01, IDC_COM3STR02, IDC_COM3STR03, | 
 | IDC_COM3STR04, IDC_COM3STR05, IDC_COM3STR06, IDC_COM3STR07}; | IDC_COM3STR04, IDC_COM3STR05, IDC_COM3STR06, IDC_COM3STR07}; | 
 |  |  | 
| static const WORD com3rsmidi[3] = { | static const UINT16 com3rsmidi[3] = { | 
 | IDC_COM3STR10, IDC_COM3STR11, IDC_COM3STR12}; | IDC_COM3STR10, IDC_COM3STR11, IDC_COM3STR12}; | 
 |  |  | 
 | static const DLGCOM_P res_com3 = | static const DLGCOM_P res_com3 = | 
| Line 120  static const DLGCOM_P res_com3 = | Line 145  static const DLGCOM_P res_com3 = | 
 | com3serial, com3rsmidi, SYS_UPDATESERIAL1}; | com3serial, com3rsmidi, SYS_UPDATESERIAL1}; | 
 |  |  | 
 |  |  | 
| static void dlgcom_show(HWND hWnd, int ncmd, const WORD *item, int items) { | static void dlgcom_show(HWND hWnd, int ncmd, const UINT16 *item, int items) { | 
 |  |  | 
 | while(items--) { | while(items--) { | 
 | ShowWindow(GetDlgItem(hWnd, *item++), ncmd); | ShowWindow(GetDlgItem(hWnd, *item++), ncmd); | 
| Line 141  static void dlgcom_items(HWND hWnd, cons | Line 166  static void dlgcom_items(HWND hWnd, cons | 
 | } | } | 
 |  |  | 
 |  |  | 
 |  | static void setChars(HWND hWnd, UINT uID, UINT8 cValue) | 
 |  | { | 
 |  | dlgs_setcbcur(hWnd, uID, cValue & 0x0c); | 
 |  | } | 
 |  |  | 
 |  | static UINT8 getChars(HWND hWnd, UINT uID, UINT8 cDefault) | 
 |  | { | 
 |  | return dlgs_getcbcur(hWnd, uID, cDefault & 0x0c); | 
 |  | } | 
 |  |  | 
 |  |  | 
 |  | static void setParity(HWND hWnd, UINT uID, UINT8 cValue) | 
 |  | { | 
 |  | cValue = cValue & 0x30; | 
 |  | if (!(cValue & 0x20)) | 
 |  | { | 
 |  | cValue = 0; | 
 |  | } | 
 |  | dlgs_setcbcur(hWnd, uID, cValue); | 
 |  | } | 
 |  |  | 
 |  | static UINT8 getParity(HWND hWnd, UINT uID, UINT8 cDefault) | 
 |  | { | 
 |  | return dlgs_getcbcur(hWnd, uID, cDefault & 0x30); | 
 |  | } | 
 |  |  | 
 |  |  | 
 |  | static void setStopBit(HWND hWnd, UINT uID, UINT8 cValue) | 
 |  | { | 
 |  | cValue = cValue & 0xc0; | 
 |  | if (!cValue) | 
 |  | { | 
 |  | cValue = 0x40; | 
 |  | } | 
 |  | dlgs_setcbcur(hWnd, uID, cValue); | 
 |  | } | 
 |  |  | 
 |  | static UINT8 getStopBit(HWND hWnd, UINT uID, UINT8 cDefault) | 
 |  | { | 
 |  | return dlgs_getcbcur(hWnd, uID, cDefault & 0xc0); | 
 |  | } | 
 |  |  | 
 |  |  | 
 |  |  | 
 |  |  | 
 |  |  | 
 |  |  | 
 | static LRESULT CALLBACK dlgitem_proc(HWND hWnd, UINT msg, | static LRESULT CALLBACK dlgitem_proc(HWND hWnd, UINT msg, | 
 | WPARAM wp, LPARAM lp, const DLGCOM_P *m) { | WPARAM wp, LPARAM lp, const DLGCOM_P *m) { | 
 |  |  | 
| DWORD   d; | UINT32  d; | 
| BYTE    b; | UINT8   b; | 
 | LRESULT r; | LRESULT r; | 
 | union { | union { | 
| char    mmap[MAXPNAMELEN]; | OEMCHAR mmap[MAXPNAMELEN]; | 
| char    mmdl[64]; | OEMCHAR mmdl[64]; | 
| char    mdef[MAX_PATH]; | OEMCHAR mdef[MAX_PATH]; | 
 | } str; | } str; | 
 | COMCFG  *cfg; | COMCFG  *cfg; | 
 | UINT    update; | UINT    update; | 
| Line 159  static LRESULT CALLBACK dlgitem_proc(HWN | Line 231  static LRESULT CALLBACK dlgitem_proc(HWN | 
 | switch (msg) { | switch (msg) { | 
 | case WM_INITDIALOG: | case WM_INITDIALOG: | 
 | cfg = m->cfg; | cfg = m->cfg; | 
| SETLISTSTR(hWnd, m->idc[ID_PORT], rsport); | dlgs_setcbitem(hWnd, m->idc[ID_PORT], cpPort, NELEMENTS(cpPort)); | 
 | SETLISTUINT32(hWnd, m->idc[ID_SPEED], cmserial_speed); | SETLISTUINT32(hWnd, m->idc[ID_SPEED], cmserial_speed); | 
| SETLISTUINT32(hWnd, m->idc[ID_CHARS], rscharsize); | dlgs_setcbnumber(hWnd, m->idc[ID_CHARS], | 
| SETLISTSTR(hWnd, m->idc[ID_PARITY], rsparity); | cpChars, NELEMENTS(cpChars)); | 
| SETLISTSTR(hWnd, m->idc[ID_SBIT], rsstopbit); | dlgs_setcbitem(hWnd, m->idc[ID_PARITY], | 
| for (d=0; d<(sizeof(cmserial_speed)/sizeof(UINT32))-1; d++) { | cpParity, NELEMENTS(cpParity)); | 
|  | dlgs_setcbitem(hWnd, m->idc[ID_SBIT], cpSBit, NELEMENTS(cpSBit)); | 
|  | for (d=0; d<(NELEMENTS(cmserial_speed) - 1); d++) { | 
 | if (cmserial_speed[d] >= cfg->speed) { | if (cmserial_speed[d] >= cfg->speed) { | 
 | break; | break; | 
 | } | } | 
| Line 174  static LRESULT CALLBACK dlgitem_proc(HWN | Line 248  static LRESULT CALLBACK dlgitem_proc(HWN | 
 |  |  | 
 | b = cfg->param; | b = cfg->param; | 
 | d = (b >> 2) & 3; | d = (b >> 2) & 3; | 
| SendDlgItemMessage(hWnd, m->idc[ID_CHARS], |  | 
| CB_SETCURSEL, (WPARAM)d, (LPARAM)0); | setChars(hWnd, m->idc[ID_CHARS], b); | 
| if (b & 0x10) { | setParity(hWnd, m->idc[ID_PARITY], b); | 
| d = ((b >> 5) & 1) + 1; | setStopBit(hWnd, m->idc[ID_SBIT], b); | 
| } |  | 
| else { |  | 
| d = 0; |  | 
| } |  | 
| SendDlgItemMessage(hWnd, m->idc[ID_PARITY], |  | 
| CB_SETCURSEL, (WPARAM)d, (LPARAM)0); |  | 
| d = (b >> 6) & 3; |  | 
| if (d) { |  | 
| d--; |  | 
| } |  | 
| SendDlgItemMessage(hWnd, m->idc[ID_SBIT], |  | 
| CB_SETCURSEL, (WPARAM)d, (LPARAM)0); |  | 
 |  |  | 
 | dlgs_setlistmidiout(hWnd, m->idc[ID_MMAP], cfg->mout); | dlgs_setlistmidiout(hWnd, m->idc[ID_MMAP], cfg->mout); | 
 | SETLISTSTR(hWnd, m->idc[ID_MMDL], cmmidi_mdlname); | SETLISTSTR(hWnd, m->idc[ID_MMDL], cmmidi_mdlname); | 
| Line 198  static LRESULT CALLBACK dlgitem_proc(HWN | Line 260  static LRESULT CALLBACK dlgitem_proc(HWN | 
 | SetDlgItemText(hWnd, m->idc[ID_DEFF], cfg->def); | SetDlgItemText(hWnd, m->idc[ID_DEFF], cfg->def); | 
 |  |  | 
 | d = cfg->port; | d = cfg->port; | 
| if (d >= (sizeof(rsport)/sizeof(char *))) { | if (d >= NELEMENTS(cpPort)) | 
|  | { | 
 | d = 0; | d = 0; | 
 | } | } | 
| SendDlgItemMessage(hWnd, m->idc[ID_PORT], | dlgs_setcbcur(hWnd, m->idc[ID_PORT], d); | 
| CB_SETCURSEL, (WPARAM)d, (LPARAM)0); |  | 
|  |  | 
 | dlgcom_items(hWnd, m, d); | dlgcom_items(hWnd, m, d); | 
 | return(TRUE); | return(TRUE); | 
 |  |  | 
 | case WM_COMMAND: | case WM_COMMAND: | 
| if (LOWORD(wp) == m->idc[ID_PORT]) { | if (LOWORD(wp) == m->idc[ID_PORT]) | 
| r = SendDlgItemMessage(hWnd, m->idc[ID_PORT], | { | 
| CB_GETCURSEL, (WPARAM)0, (LPARAM)0); | dlgcom_items(hWnd, m, | 
| if (r != CB_ERR) { | dlgs_getcbcur(hWnd, m->idc[ID_PORT], COMPORT_NONE)); | 
| dlgcom_items(hWnd, m, (UINT)r); |  | 
| } |  | 
 | } | } | 
| else if (LOWORD(wp) == m->idc[ID_DEFB]) { | else if (LOWORD(wp) == m->idc[ID_DEFB]) | 
|  | { | 
 | dlgs_browsemimpidef(hWnd, m->idc[ID_DEFF]); | dlgs_browsemimpidef(hWnd, m->idc[ID_DEFF]); | 
 | } | } | 
 | break; | break; | 
 |  |  | 
 | case WM_NOTIFY: | case WM_NOTIFY: | 
| if ((((NMHDR *)lp)->code) == (UINT)PSN_APPLY) { | if ((((NMHDR *)lp)->code) == (UINT)PSN_APPLY) | 
|  | { | 
 | cfg = m->cfg; | cfg = m->cfg; | 
 | update = 0; | update = 0; | 
| r = SendDlgItemMessage(hWnd, m->idc[ID_PORT], | r = dlgs_getcbcur(hWnd, m->idc[ID_PORT], COMPORT_NONE); | 
| CB_GETCURSEL, (WPARAM)0, (LPARAM)0); | if (cfg->port != (UINT8)r) | 
| if (r != CB_ERR) { | { | 
| if ((UINT)r >= (sizeof(rsport)/sizeof(char *))) { | cfg->port = (UINT8)r; | 
| r = 0; | update |= SYS_UPDATEOSCFG; | 
| } | update |= m->update; | 
| if (cfg->port != (BYTE)r) { |  | 
| cfg->port = (BYTE)r; |  | 
| update |= SYS_UPDATEOSCFG; |  | 
| update |= m->update; |  | 
| } |  | 
 | } | } | 
 | r = SendDlgItemMessage(hWnd, m->idc[ID_SPEED], | r = SendDlgItemMessage(hWnd, m->idc[ID_SPEED], | 
 | CB_GETCURSEL, (WPARAM)0, (LPARAM)0); | CB_GETCURSEL, (WPARAM)0, (LPARAM)0); | 
 | if (r != CB_ERR) { | if (r != CB_ERR) { | 
| if ((UINT)r >= (sizeof(cmserial_speed)/sizeof(UINT32))) { | if ((UINT)r >= NELEMENTS(cmserial_speed)) { | 
 | r = 0; | r = 0; | 
 | } | } | 
 | if (cfg->speed != cmserial_speed[r]) { | if (cfg->speed != cmserial_speed[r]) { | 
| Line 250  static LRESULT CALLBACK dlgitem_proc(HWN | Line 306  static LRESULT CALLBACK dlgitem_proc(HWN | 
 | } | } | 
 |  |  | 
 | b = 0; | b = 0; | 
| r = SendDlgItemMessage(hWnd, m->idc[ID_CHARS], | b |= getChars(hWnd, m->idc[ID_CHARS], cfg->param); | 
| CB_GETCURSEL, (WPARAM)0, (LPARAM)0); | b |= getParity(hWnd, m->idc[ID_PARITY], cfg->param); | 
| if (r != CB_ERR) { | b |= getStopBit(hWnd, m->idc[ID_SBIT], cfg->param); | 
| b |= (BYTE)(((UINT)r & 3) << 2); |  | 
| } |  | 
| r = SendDlgItemMessage(hWnd, m->idc[ID_PARITY], |  | 
| CB_GETCURSEL, (WPARAM)0, (LPARAM)0); |  | 
| if (r != CB_ERR) { |  | 
| if ((UINT)r) { |  | 
| b |= 0x10; |  | 
| b |= (BYTE)((((UINT)r - 1) & 1) << 5); |  | 
| } |  | 
| } |  | 
| r = SendDlgItemMessage(hWnd, m->idc[ID_SBIT], |  | 
| CB_GETCURSEL, (WPARAM)0, (LPARAM)0); |  | 
| if (r != CB_ERR) { |  | 
| b |= (BYTE)((((UINT)r + 1) & 3) << 6); |  | 
| } |  | 
 | if (cfg->param != b) { | if (cfg->param != b) { | 
 | cfg->param = b; | cfg->param = b; | 
 | update |= SYS_UPDATEOSCFG; | update |= SYS_UPDATEOSCFG; | 
| Line 275  static LRESULT CALLBACK dlgitem_proc(HWN | Line 317  static LRESULT CALLBACK dlgitem_proc(HWN | 
 | } | } | 
 |  |  | 
 | GetDlgItemText(hWnd, m->idc[ID_MMAP], | GetDlgItemText(hWnd, m->idc[ID_MMAP], | 
| str.mmap, sizeof(str.mmap)); | str.mmap, NELEMENTS(str.mmap)); | 
 | if (milstr_cmp(cfg->mout, str.mmap)) { | if (milstr_cmp(cfg->mout, str.mmap)) { | 
| milstr_ncpy(cfg->mout, str.mmap, sizeof(cfg->mout)); | milstr_ncpy(cfg->mout, str.mmap, NELEMENTS(cfg->mout)); | 
 | update |= SYS_UPDATEOSCFG; | update |= SYS_UPDATEOSCFG; | 
 | update |= m->update; | update |= m->update; | 
 | } | } | 
 | GetDlgItemText(hWnd, m->idc[ID_MMDL], | GetDlgItemText(hWnd, m->idc[ID_MMDL], | 
| str.mmdl, sizeof(str.mmdl)); | str.mmdl, NELEMENTS(str.mmdl)); | 
 | if (milstr_cmp(cfg->mdl, str.mmdl)) { | if (milstr_cmp(cfg->mdl, str.mmdl)) { | 
| milstr_ncpy(cfg->mdl, str.mmdl, sizeof(cfg->mdl)); | milstr_ncpy(cfg->mdl, str.mmdl, NELEMENTS(cfg->mdl)); | 
 | update |= SYS_UPDATEOSCFG; | update |= SYS_UPDATEOSCFG; | 
 | update |= m->update; | update |= m->update; | 
 | } | } | 
 |  |  | 
| cfg->def_en = GetDlgItemCheck(hWnd, m->idc[ID_DEFE]); | cfg->def_en = (UINT8)GetDlgItemCheck(hWnd, m->idc[ID_DEFE]); | 
 | cm = *m->cm; | cm = *m->cm; | 
 | if (cm) { | if (cm) { | 
 | cm->msg(cm, COMMSG_MIMPIDEFEN, cfg->def_en); | cm->msg(cm, COMMSG_MIMPIDEFEN, cfg->def_en); | 
 | } | } | 
 | GetDlgItemText(hWnd, m->idc[ID_DEFF], | GetDlgItemText(hWnd, m->idc[ID_DEFF], | 
| str.mdef, sizeof(str.mdef)); | str.mdef, NELEMENTS(str.mdef)); | 
 | if (milstr_cmp(cfg->def, str.mdef)) { | if (milstr_cmp(cfg->def, str.mdef)) { | 
| milstr_ncpy(cfg->def, str.mdef, sizeof(cfg->def)); | milstr_ncpy(cfg->def, str.mdef, NELEMENTS(cfg->def)); | 
 | update |= SYS_UPDATEOSCFG; | update |= SYS_UPDATEOSCFG; | 
 | if (cm) { | if (cm) { | 
 | cm->msg(cm, COMMSG_MIMPIDEFFILE, (long)str.mdef); | cm->msg(cm, COMMSG_MIMPIDEFFILE, (long)str.mdef); | 
| Line 333  static LRESULT CALLBACK Com3Proc(HWND hW | Line 375  static LRESULT CALLBACK Com3Proc(HWND hW | 
 |  |  | 
 | // -------------------------------------------------------------------- | // -------------------------------------------------------------------- | 
 |  |  | 
| static  BYTE    pc9861_s[3]; | static  UINT8   pc9861_s[3]; | 
| static  BYTE    pc9861_j[6]; | static  UINT8   pc9861_j[6]; | 
 |  |  | 
 | typedef struct { | typedef struct { | 
 | int             idc_speed; | int             idc_speed; | 
 | int             idc_int; | int             idc_int; | 
 | int             idc_mode; | int             idc_mode; | 
| BYTE    *dip_mode; | UINT8   *dip_mode; | 
| BYTE    *dip_int; | UINT8   *dip_int; | 
| BYTE    sft_int; | UINT8   sft_int; | 
 | } PC9861MODE_T; | } PC9861MODE_T; | 
 |  |  | 
 | static const PC9861MODE_T pc9861mode[2] = { | static const PC9861MODE_T pc9861mode[2] = { | 
| Line 367  enum { | Line 409  enum { | 
 | PC9861J4_Y              = 7 | PC9861J4_Y              = 7 | 
 | }; | }; | 
 |  |  | 
| static const UINT32 pc9861kint1[] = {0, 1, 2, 3}; | static const CBNPARAM cpInt1[] = | 
| static const UINT32 pc9861kint2[] = {0, 4, 5, 6}; | { | 
|  | {0,     0x00}, | 
| static const char sync0[] = "Start-Stop"; | {1,     0x02}, | 
| static const char sync1[] = "ST1"; | {2,     0x01}, | 
| static const char sync2[] = "ST2"; | {3,     0x03}, | 
| static const char sync3[] = "RD-Sync"; | }; | 
| static const char *pc9861sync[] = {sync0, sync1, sync2, sync3}; |  | 
|  |  | 
| static const UINT pc9861d2sync[] = {1, 2, 3, 0}; |  | 
| static const UINT pc9861d2int[] = {0, 2, 1, 3}; |  | 
|  |  | 
 |  |  | 
| static void setdip(BYTE *image, int px, int py, int align, BYTE v, BYTE c) { | static const CBNPARAM cpInt2[] = | 
|  | { | 
|  | {0,     0x00}, | 
|  | {4,     0x08}, | 
|  | {5,     0x04}, | 
|  | {6,     0x0c}, | 
|  | }; | 
 |  |  | 
| int             i, y; | static const CBPARAM cpSync[] = | 
|  | { | 
|  | {MAKEINTRESOURCE(IDS_SYNC),             0x03}, | 
|  | {MAKEINTRESOURCE(IDS_ASYNC),    0x00}, | 
|  | {MAKEINTRESOURCE(IDS_ASYNC16X), 0x01}, | 
|  | {MAKEINTRESOURCE(IDS_ASYNC64X), 0x02}, | 
|  | }; | 
 |  |  | 
| px *= 9; | static void pc9861setspeed(HWND hWnd, const PC9861MODE_T *m) | 
| px++; | { | 
| py *= 9; | UINT8   cMode; | 
| while(c--) { | UINT    uSpeed; | 
| y = py + ((v&0x01)?5:9); |  | 
| for (i=0; i<3; i++) { | cMode = *(m->dip_mode); | 
| dlgs_linex(image, px, y+i, 7, align, 0); | uSpeed = (((~cMode) >> 2) & 0x0f) + 1; | 
| } | if (cMode) | 
| px+=9; | { | 
| v>>=1; | if (uSpeed > 4) | 
|  | { | 
|  | uSpeed -= 4; | 
|  | } | 
|  | else | 
|  | { | 
|  | uSpeed = 0; | 
|  | } | 
|  | } | 
|  | if (uSpeed > (NELEMENTS(pc9861k_speed) - 1)) | 
|  | { | 
|  | uSpeed = NELEMENTS(pc9861k_speed) - 1; | 
 | } | } | 
 | } |  | 
 |  |  | 
| static void setjmp(BYTE *image, int px, int py, int align, BYTE v, BYTE c) { | SendDlgItemMessage(hWnd, m->idc_speed, | 
|  | CB_SETCURSEL, (WPARAM)uSpeed, (LPARAM)0); | 
| while(c--) { |  | 
| if (v & 0x01) { |  | 
| dlgs_setjumpery(image, px, py, align); |  | 
| } |  | 
| px++; |  | 
| v >>= 1; |  | 
| } |  | 
 | } | } | 
 |  |  | 
| static void pc9861getspeed(HWND hWnd, const PC9861MODE_T *m) { | static void pc9861getspeed(HWND hWnd, const PC9861MODE_T *m) | 
|  | { | 
|  | UINT8   cMode; | 
 | LRESULT r; | LRESULT r; | 
| BYTE    mode; | UINT    uSpeed; | 
 |  |  | 
| mode = *(m->dip_mode); | cMode = *(m->dip_mode); | 
 | r = SendDlgItemMessage(hWnd, m->idc_speed, CB_GETCURSEL, 0, 0); | r = SendDlgItemMessage(hWnd, m->idc_speed, CB_GETCURSEL, 0, 0); | 
| if (r != CB_ERR) { | if (r != CB_ERR) | 
| DWORD speed = r; | { | 
| if (speed > ((sizeof(pc9861k_speed) / sizeof(UINT32)) - 1)) { | uSpeed = (UINT)r; | 
| speed = (sizeof(pc9861k_speed) / sizeof(UINT32)) - 1; | if (uSpeed > (NELEMENTS(pc9861k_speed) - 1)) | 
| } | { | 
| if (mode & 2) { | uSpeed = NELEMENTS(pc9861k_speed) - 1; | 
| speed += 3; | } | 
| } | if (cMode & 2) | 
| else { | { | 
| if (speed) { | uSpeed += 3; | 
| speed--; | } | 
|  | else | 
|  | { | 
|  | if (uSpeed) | 
|  | { | 
|  | uSpeed--; | 
 | } | } | 
 | } | } | 
| mode &= 3; | cMode &= 3; | 
| mode |= ((~speed) & 0x0f) << 2; | cMode |= ((~uSpeed) & 0x0f) << 2; | 
| *(m->dip_mode) = mode; | *(m->dip_mode) = cMode; | 
 | } | } | 
 | } | } | 
 |  |  | 
| static void pc9861getint(HWND hWnd, const PC9861MODE_T *m) { | static void pc9861setsync(HWND hWnd, const PC9861MODE_T *m) | 
|  | { | 
| LRESULT r; | UINT8   cMode; | 
| UINT    i; |  | 
 |  |  | 
| r = SendDlgItemMessage(hWnd, m->idc_int, CB_GETCURSEL, 0, 0); | cMode = *(m->dip_mode); | 
| if (r != CB_ERR) { | dlgs_setcbcur(hWnd, m->idc_mode, cMode & 0x03); | 
| for (i=0; i<(sizeof(pc9861d2int)/sizeof(UINT)); i++) { |  | 
| if (pc9861d2int[i] == (UINT)(r & 3)) { |  | 
| *(m->dip_int) &= ~(0x03 << (m->sft_int)); |  | 
| *(m->dip_int) |= (BYTE)(i << (m->sft_int)); |  | 
| break; |  | 
| } |  | 
| } |  | 
| } |  | 
 | } | } | 
 |  |  | 
| static void pc9861getmode(HWND hWnd, const PC9861MODE_T *m) { | static void pc9861getsync(HWND hWnd, const PC9861MODE_T *m) | 
|  | { | 
|  | UINT8   cMode; | 
|  | UINT8   cNewMode; | 
 |  |  | 
| LRESULT r; | cMode = *(m->dip_mode); | 
| BYTE    i; | cNewMode = (UINT8)dlgs_getcbcur(hWnd, m->idc_mode, cMode & 0x03); | 
|  | *(m->dip_mode) = (UINT8)((cMode & (~3)) | cNewMode); | 
| r = SendDlgItemMessage(hWnd, m->idc_mode, CB_GETCURSEL, 0, 0); |  | 
| if (r != CB_ERR) { |  | 
| for (i=0; i<(sizeof(pc9861d2sync)/sizeof(UINT)); i++) { |  | 
| if (pc9861d2sync[i] == (UINT)(r & 3)) { |  | 
| *(m->dip_mode) &= (~3); |  | 
| *(m->dip_mode) |= i; |  | 
| break; |  | 
| } |  | 
| } |  | 
| } |  | 
 | } | } | 
 |  |  | 
| static void pc9861setmode(HWND hWnd, const PC9861MODE_T *m) { | static void pc9861setint(HWND hWnd, const PC9861MODE_T *m) | 
|  | { | 
|  | UINT8   cMask; | 
|  | UINT8   cMode; | 
 |  |  | 
| DWORD   speed; | cMask = 3 << (m->sft_int); | 
| DWORD   mode; | cMode = *(m->dip_int); | 
| DWORD   intnum; | dlgs_setcbcur(hWnd, m->idc_int, cMode & cMask); | 
| BYTE    modedip; | } | 
 |  |  | 
| modedip = *(m->dip_mode); | static void pc9861getint(HWND hWnd, const PC9861MODE_T *m) | 
| speed = (((~modedip) >> 2) & 0x0f) + 1; | { | 
| if (modedip & 0x02) { | UINT8   cMask; | 
| if (speed > 4) { | UINT8   cMode; | 
| speed -= 4; | UINT8   cNewMode; | 
| } |  | 
| else { |  | 
| speed = 0; |  | 
| } |  | 
| } |  | 
| if (speed > ((sizeof(pc9861k_speed) / sizeof(UINT32)) - 1)) { |  | 
| speed = (sizeof(pc9861k_speed) / sizeof(UINT32)) - 1; |  | 
| } |  | 
 |  |  | 
| SendDlgItemMessage(hWnd, m->idc_speed, | cMask = 3 << (m->sft_int); | 
| CB_SETCURSEL, (WPARAM)speed, (LPARAM)0); | cMode = *(m->dip_int); | 
|  | cNewMode = (UINT8)dlgs_getcbcur(hWnd, m->idc_int, cMode & cMask); | 
|  | *(m->dip_int) = (cMode & (~cMask)) | cNewMode; | 
|  | } | 
 |  |  | 
| mode = pc9861d2sync[modedip & 3]; | static void pc9861setmode(HWND hWnd, const PC9861MODE_T *m) | 
| SendDlgItemMessage(hWnd, m->idc_mode, | { | 
| CB_SETCURSEL, (WPARAM)mode, (LPARAM)0); | pc9861setspeed(hWnd, m); | 
|  | pc9861setint(hWnd, m); | 
| intnum = pc9861d2int[((*(m->dip_int)) >> (m->sft_int)) & 3]; | pc9861setsync(hWnd, m); | 
| SendDlgItemMessage(hWnd, m->idc_int, |  | 
| CB_SETCURSEL, (WPARAM)intnum, (LPARAM)0); |  | 
 | } | } | 
 |  |  | 
 | static void pc9861cmddipsw(HWND hWnd) { | static void pc9861cmddipsw(HWND hWnd) { | 
| Line 506  static void pc9861cmddipsw(HWND hWnd) { | Line 544  static void pc9861cmddipsw(HWND hWnd) { | 
 | RECT    rect1; | RECT    rect1; | 
 | RECT    rect2; | RECT    rect2; | 
 | POINT   p; | POINT   p; | 
| BYTE    bit; | UINT8   bit; | 
 |  |  | 
 | GetWindowRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect1); | GetWindowRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect1); | 
 | GetClientRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect2); | GetClientRect(GetDlgItem(hWnd, IDC_PC9861DIP), &rect2); | 
| Line 522  static void pc9861cmddipsw(HWND hWnd) { | Line 560  static void pc9861cmddipsw(HWND hWnd) { | 
 | } | } | 
 | else if ((p.x >= 10) && (p.x < 14)) {           // S2 | else if ((p.x >= 10) && (p.x < 14)) {           // S2 | 
 | pc9861_s[1] ^= (1 << (p.x - 10)); | pc9861_s[1] ^= (1 << (p.x - 10)); | 
| pc9861setmode(hWnd, pc9861mode); | pc9861setint(hWnd, pc9861mode); | 
| pc9861setmode(hWnd, pc9861mode+1); | pc9861setint(hWnd, pc9861mode+1); | 
 | } | } | 
 | else if ((p.x >= 17) && (p.x < 23)) {           // S3 | else if ((p.x >= 17) && (p.x < 23)) {           // S3 | 
 | pc9861_s[2] ^= (1 << (p.x - 17)); | pc9861_s[2] ^= (1 << (p.x - 17)); | 
| Line 558  static void pc9861cmddipsw(HWND hWnd) { | Line 596  static void pc9861cmddipsw(HWND hWnd) { | 
 | } | } | 
 | } | } | 
 |  |  | 
 | static void pc9861drawdipsw(HWND hWnd, HDC hdc) { |  | 
 |  |  | 
 | BITMAPINFO      *bmi; |  | 
 | HBITMAP         hbmp; |  | 
 | BYTE            *image; |  | 
 | int                     align; |  | 
 | BYTE            *imgbtm; |  | 
 | HDC                     hmdc; |  | 
 |  |  | 
 | bmi = (BITMAPINFO *)_MALLOC(bit2res_getsize(&pc9861dip), "bitmap"); |  | 
 | if (bmi == NULL) { |  | 
 | return; |  | 
 | } |  | 
 | bit2res_sethead(bmi, &pc9861dip); |  | 
 | hbmp = CreateDIBSection(hdc, bmi, DIB_RGB_COLORS, |  | 
 | (void **)&image, NULL, 0); |  | 
 | bit2res_setdata(image, &pc9861dip); |  | 
 | align = ((pc9861dip.x + 7) / 2) & ~3; |  | 
 | imgbtm = image + align * (pc9861dip.y - 1); |  | 
 | setdip(imgbtm, PC9861S1_X, PC9861S_Y, align, pc9861_s[0], 6); |  | 
 | setdip(imgbtm, PC9861S2_X, PC9861S_Y, align, pc9861_s[1], 4); |  | 
 | setdip(imgbtm, PC9861S3_X, PC9861S_Y, align, pc9861_s[2], 6); |  | 
 | setjmp(imgbtm, PC9861J1_X, PC9861J1_Y, align, pc9861_j[0], 6); |  | 
 | setjmp(imgbtm, PC9861J2_X, PC9861J1_Y, align, pc9861_j[1], 6); |  | 
 | setjmp(imgbtm, PC9861J3_X, PC9861J1_Y, align, pc9861_j[2], 2); |  | 
 | setjmp(imgbtm, PC9861J4_X, PC9861J4_Y, align, pc9861_j[3], 8); |  | 
 | setjmp(imgbtm, PC9861J5_X, PC9861J4_Y, align, pc9861_j[4], 6); |  | 
 | setjmp(imgbtm, PC9861J6_X, PC9861J4_Y, align, pc9861_j[5], 6); |  | 
 | hmdc = CreateCompatibleDC(hdc); |  | 
 | SelectObject(hmdc, hbmp); |  | 
 | BitBlt(hdc, 0, 0, pc9861dip.x, pc9861dip.y, hmdc, 0, 0, SRCCOPY); |  | 
 | DeleteDC(hmdc); |  | 
 | DeleteObject(hbmp); |  | 
 | _MFREE(bmi); |  | 
 | } |  | 
 |  |  | 
 | static LRESULT CALLBACK pc9861mainProc(HWND hWnd, UINT msg, | static LRESULT CALLBACK pc9861mainProc(HWND hWnd, UINT msg, | 
 | WPARAM wp, LPARAM lp) { | WPARAM wp, LPARAM lp) { | 
 |  |  | 
 | HWND    sub; | HWND    sub; | 
| BYTE    r; | UINT8   r; | 
 | UINT    update; | UINT    update; | 
 |  |  | 
 | switch (msg) { | switch (msg) { | 
| Line 607  static LRESULT CALLBACK pc9861mainProc(H | Line 609  static LRESULT CALLBACK pc9861mainProc(H | 
 | CopyMemory(pc9861_j, np2cfg.pc9861jmp, 6); | CopyMemory(pc9861_j, np2cfg.pc9861jmp, 6); | 
 | SETLISTUINT32(hWnd, IDC_CH1SPEED, pc9861k_speed); | SETLISTUINT32(hWnd, IDC_CH1SPEED, pc9861k_speed); | 
 | SETLISTUINT32(hWnd, IDC_CH2SPEED, pc9861k_speed); | SETLISTUINT32(hWnd, IDC_CH2SPEED, pc9861k_speed); | 
| SETLISTUINT32(hWnd, IDC_CH1INT, pc9861kint1); | dlgs_setcbnumber(hWnd, IDC_CH1INT, cpInt1, NELEMENTS(cpInt1)); | 
| SETLISTUINT32(hWnd, IDC_CH2INT, pc9861kint2); | dlgs_setcbnumber(hWnd, IDC_CH2INT, cpInt2, NELEMENTS(cpInt2)); | 
| SETLISTSTR(hWnd, IDC_CH1MODE, pc9861sync); | dlgs_setcbitem(hWnd, IDC_CH1MODE, cpSync, NELEMENTS(cpSync)); | 
| SETLISTSTR(hWnd, IDC_CH2MODE, pc9861sync); | dlgs_setcbitem(hWnd, IDC_CH2MODE, cpSync, NELEMENTS(cpSync)); | 
 |  |  | 
 | SendDlgItemMessage(hWnd, IDC_PC9861E, BM_GETCHECK, | SendDlgItemMessage(hWnd, IDC_PC9861E, BM_GETCHECK, | 
 | np2cfg.pc9861enable & 1, 0); | np2cfg.pc9861enable & 1, 0); | 
| Line 626  static LRESULT CALLBACK pc9861mainProc(H | Line 628  static LRESULT CALLBACK pc9861mainProc(H | 
 | switch (LOWORD(wp)) { | switch (LOWORD(wp)) { | 
 | case IDC_CH1SPEED: | case IDC_CH1SPEED: | 
 | pc9861getspeed(hWnd, pc9861mode); | pc9861getspeed(hWnd, pc9861mode); | 
| pc9861setmode(hWnd, pc9861mode); | pc9861setspeed(hWnd, pc9861mode); | 
 | break; | break; | 
 |  |  | 
 | case IDC_CH1INT: | case IDC_CH1INT: | 
 | pc9861getint(hWnd, pc9861mode); | pc9861getint(hWnd, pc9861mode); | 
| pc9861setmode(hWnd, pc9861mode); | pc9861setint(hWnd, pc9861mode); | 
 | break; | break; | 
 |  |  | 
 | case IDC_CH1MODE: | case IDC_CH1MODE: | 
| pc9861getmode(hWnd, pc9861mode); | pc9861getsync(hWnd, pc9861mode); | 
| pc9861setmode(hWnd, pc9861mode); | pc9861setsync(hWnd, pc9861mode); | 
 | break; | break; | 
 |  |  | 
 | case IDC_CH2SPEED: | case IDC_CH2SPEED: | 
 | pc9861getspeed(hWnd, pc9861mode+1); | pc9861getspeed(hWnd, pc9861mode+1); | 
| pc9861setmode(hWnd, pc9861mode+1); | pc9861setspeed(hWnd, pc9861mode+1); | 
 | break; | break; | 
 |  |  | 
 | case IDC_CH2INT: | case IDC_CH2INT: | 
 | pc9861getint(hWnd, pc9861mode+1); | pc9861getint(hWnd, pc9861mode+1); | 
| pc9861setmode(hWnd, pc9861mode+1); | pc9861setint(hWnd, pc9861mode+1); | 
 | break; | break; | 
 |  |  | 
 | case IDC_CH2MODE: | case IDC_CH2MODE: | 
| pc9861getmode(hWnd, pc9861mode+1); | pc9861getsync(hWnd, pc9861mode+1); | 
| pc9861setmode(hWnd, pc9861mode+1); | pc9861setsync(hWnd, pc9861mode+1); | 
 | break; | break; | 
 |  |  | 
 | case IDC_PC9861DIP: | case IDC_PC9861DIP: | 
| Line 687  static LRESULT CALLBACK pc9861mainProc(H | Line 689  static LRESULT CALLBACK pc9861mainProc(H | 
 |  |  | 
 | case WM_DRAWITEM: | case WM_DRAWITEM: | 
 | if (LOWORD(wp) == IDC_PC9861DIP) { | if (LOWORD(wp) == IDC_PC9861DIP) { | 
| pc9861drawdipsw(hWnd, ((LPDRAWITEMSTRUCT)lp)->hDC); | dlgs_drawbmp(((LPDRAWITEMSTRUCT)lp)->hDC, | 
|  | dipswbmp_get9861(pc9861_s, pc9861_j)); | 
 | } | } | 
 | return(FALSE); | return(FALSE); | 
 | } | } | 
| Line 697  static LRESULT CALLBACK pc9861mainProc(H | Line 700  static LRESULT CALLBACK pc9861mainProc(H | 
 |  |  | 
 | // -------------------------------------------------------------------------- | // -------------------------------------------------------------------------- | 
 |  |  | 
| void dialog_serial(HWND hWnd) { | void dialog_serial(HWND hWnd) | 
|  | { | 
| HINSTANCE               hinst; | HINSTANCE               hInstance; | 
 | PROPSHEETPAGE   psp; | PROPSHEETPAGE   psp; | 
 | PROPSHEETHEADER psh; | PROPSHEETHEADER psh; | 
 | HPROPSHEETPAGE  hpsp[4]; | HPROPSHEETPAGE  hpsp[4]; | 
 |  | TCHAR                   szTitle[128]; | 
 |  |  | 
| hinst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); | hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE); | 
 |  |  | 
 | ZeroMemory(&psp, sizeof(psp)); | ZeroMemory(&psp, sizeof(psp)); | 
 | psp.dwSize = sizeof(PROPSHEETPAGE); | psp.dwSize = sizeof(PROPSHEETPAGE); | 
 | psp.dwFlags = PSP_DEFAULT; | psp.dwFlags = PSP_DEFAULT; | 
| psp.hInstance = hinst; | psp.hInstance = hInstance; | 
 |  |  | 
 | psp.pszTemplate = MAKEINTRESOURCE(IDD_SERIAL1); | psp.pszTemplate = MAKEINTRESOURCE(IDD_SERIAL1); | 
 | psp.pfnDlgProc = (DLGPROC)Com1Proc; | psp.pfnDlgProc = (DLGPROC)Com1Proc; | 
| Line 727  void dialog_serial(HWND hWnd) { | Line 731  void dialog_serial(HWND hWnd) { | 
 | psp.pfnDlgProc = (DLGPROC)Com3Proc; | psp.pfnDlgProc = (DLGPROC)Com3Proc; | 
 | hpsp[3] = CreatePropertySheetPage(&psp); | hpsp[3] = CreatePropertySheetPage(&psp); | 
 |  |  | 
 |  | loadstringresource(IDS_SERIALOPTION, szTitle, NELEMENTS(szTitle)); | 
 |  |  | 
 | ZeroMemory(&psh, sizeof(psh)); | ZeroMemory(&psh, sizeof(psh)); | 
 | psh.dwSize = sizeof(PROPSHEETHEADER); | psh.dwSize = sizeof(PROPSHEETHEADER); | 
 | psh.dwFlags = PSH_NOAPPLYNOW | PSH_USEHICON | PSH_USECALLBACK; | psh.dwFlags = PSH_NOAPPLYNOW | PSH_USEHICON | PSH_USECALLBACK; | 
 | psh.hwndParent = hWnd; | psh.hwndParent = hWnd; | 
| psh.hInstance = hinst; | psh.hInstance = hInstance; | 
| psh.hIcon = LoadIcon(hinst, MAKEINTRESOURCE(IDI_ICON2)); | psh.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON2)); | 
 | psh.nPages = 4; | psh.nPages = 4; | 
 | psh.phpage = hpsp; | psh.phpage = hpsp; | 
| psh.pszCaption = str_seropt; | psh.pszCaption = szTitle; | 
 | psh.pfnCallback = np2class_propetysheet; | psh.pfnCallback = np2class_propetysheet; | 
 | PropertySheet(&psh); | PropertySheet(&psh); | 
 | InvalidateRect(hWnd, NULL, TRUE); | InvalidateRect(hWnd, NULL, TRUE); |