static void viewreg_lock_alloc(NP2VIEW_T *view, void *src) { if (view->lock) { if (view->buf1.type != ALLOCTYPE_REG) { if (viewcmn_alloc(&view->buf1, view->memsize)) { view->lock = FALSE; viewmenu_lock(view); } else { view->buf1.type = ALLOCTYPE_REG; CopyMemory(view->buf1.ptr, src, view->memsize); } viewcmn_putcaption(view); } } }
static void viewasm_paint(NP2VIEW_T *view, RECT *rc, HDC hdc) { LONG x, y, i; UINT32 seg4; UINT16 off, prevoff; UINT32 pos; UINT8 *p; UINT8 buf[16]; TCHAR str[16]; _UNASM una; int step; #if defined(UNICODE) TCHAR cnv[64]; #endif COLORREF bkcol; if (view->lock) { if ((view->buf1.type != ALLOCTYPE_SEG) || (view->buf1.arg != view->seg)) { if (viewcmn_alloc(&view->buf1, view->memsize)) { view->lock = FALSE; viewmenu_lock(view); } else { view->buf1.type = ALLOCTYPE_SEG; view->buf1.arg = view->seg; viewmem_read(&view->dmem, seg_to_real(view->buf1.arg), (BYTE *)view->buf1.ptr, view->memsize); view->buf2.type = ALLOCTYPE_NONE; } viewcmn_putcaption(view); } } seg4 = seg_to_real(view->seg); pos = view->pos; if ((view->buf2.type != ALLOCTYPE_ASM) || (view->buf2.arg != (seg4 + view->off))) { if (viewcmn_alloc(&view->buf2, view->maxline*2)) { pos = 0; } else { DWORD i; UINT16 *r; r = (UINT16 *)view->buf2.ptr; view->buf2.type = ALLOCTYPE_ASM; view->buf2.arg = seg4 + view->off; off = view->off; for (i=0; i<(view->maxline - 1); i++) { *r++ = off; step = viewasm_unasm_next(NULL, buf, view, off); off += (UINT16)step; } *r = off; } } prevoff = off = viewasm_line_to_off(view, view->pos); for (y=0; y<rc->bottom; y+=viewcfg.font_height) { x = 0; // Emphasize wrapping if(prevoff > off) { viewpaint_line_fill(rc, hdc, y, 2, viewcfg.color_hilite); } bkcol = viewpaint_line_set_colors(view, rc, hdc, y, off, CPU_CS, CPU_IP); viewpaint_print_addr(hdc, x, y, view->seg, off, TRUE); SetBkColor(hdc, bkcol); step = viewasm_unasm_next(&una, buf, view, off); p = buf; if (!step) { break; } x += 11 * np2viewfontwidth; for(i = 0; i < step; i++) { wsprintf(str + (i*2), _T("%02x"), *p); p++; } TextOut(hdc, x, y, str, i * 2); x += 15 * np2viewfontwidth; #if defined(UNICODE) TextOut(hdc, x, y, cnv, MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, una.mnemonic, -1, cnv, NELEMENTS(cnv))); #else TextOut(hdc,x, y, una.mnemonic, lstrlen(una.mnemonic)); #endif x += 7 * np2viewfontwidth; if (una.operand[0]) { #if defined(UNICODE) TextOut(hdc, x, y, cnv, MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, una.operand, -1, cnv, NELEMENTS(cnv))); #else TextOut(hdc, x, y, una.operand, lstrlen(una.operand)); #endif } prevoff = off; off += (UINT16)step; } }
LRESULT CALLBACK viewasm_proc(NP2VIEW_T *view, HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { UINT step = 0; LONG newcursor = view->cursor; switch (msg) { case WM_SYSKEYDOWN: case WM_KEYDOWN: switch(wp) { case VK_UP: view->cursorline--; break; case VK_DOWN: view->cursorline++; break; case VK_PRIOR: view->cursorline -= view->step; break; case VK_NEXT: view->cursorline += view->step; break; } // Clamp if(view->cursorline < 0) { view->cursorline = 0; } else if((UINT32)view->cursorline > (view->maxline - 1)) { view->cursorline = view->maxline - 1; } viewer_scroll_fit_line(view, view->cursorline); newcursor = viewasm_line_to_off(view, view->cursorline); break; case WM_COMMAND: switch(LOWORD(wp)) { case IDM_EDIT_MEMORY: viewer_edit_dlg(view, hwnd); break; case IDM_BREAK_TOGGLE: viewasm_toggle_breakpoint(view); break; case IDM_SEGCS: set_viewseg(hwnd, view, CPU_CS); break; case IDM_SEGDS: set_viewseg(hwnd, view, CPU_DS); break; case IDM_SEGES: set_viewseg(hwnd, view, CPU_ES); break; case IDM_SEGSS: set_viewseg(hwnd, view, CPU_SS); break; case IDM_SEGTEXT: set_viewseg(hwnd, view, 0xa000); break; case IDM_VIEWMODELOCK: view->lock ^= 1; viewmenu_lock(view); viewcmn_putcaption(view); InvalidateRect(hwnd, NULL, TRUE); break; case IDM_GOTO: view->seg = lp >> 16; view->off = lp & 0xffff; break; } break; case WM_LBUTTONDOWN: { POINTS mpos = MAKEPOINTS(lp); view->cursorline = view->pos + (mpos.y / viewcfg.font_height); newcursor = viewasm_line_to_off(view, view->cursorline); } break; case WM_PAINT: viewcmn_paint(view, viewasm_paint); break; default: return(DefWindowProc(hwnd, msg, wp, lp)); } if(newcursor != view->cursor) { view->cursor = newcursor + seg_to_real(view->seg); InvalidateRect(hwnd, NULL, TRUE); } return(0L); }
static void viewsnd_paint(NP2VIEW_T *view, RECT *rc, HDC hdc) { int x; LONG y; UINT pos; const UINT8 *p; TCHAR str[16]; HFONT hfont; UINT reg; UINT16 mask; hfont = CreateFont(16, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH, np2viewfont); SetTextColor(hdc, 0xffffff); SetBkColor(hdc, 0x400000); hfont = (HFONT)SelectObject(hdc, hfont); if (view->lock) { if (view->buf1.type != ALLOCTYPE_SND) { if (viewcmn_alloc(&view->buf1, 0x400)) { view->lock = FALSE; viewmenu_lock(view); } else { view->buf1.type = ALLOCTYPE_SND; CopyMemory(view->buf1.ptr, opn.reg, 0x400); CopyMemory(view->buf1.ptr, &psg1.reg, 0x10); CopyMemory(((UINT8 *)view->buf1.ptr) + 0x200, &psg2.reg, 0x10); } viewcmn_putcaption(view); } } pos = view->pos; for (y=0; (y<rc->bottom) && (pos<NELEMENTS(fmsndtbl)); y+=16, pos++) { if (fmsndtbl[pos].str) { TextOut(hdc, 0, y, fmsndtbl[pos].str, lstrlen(fmsndtbl[pos].str)); } else { reg = fmsndtbl[pos].reg; mask = fmsndtbl[pos].mask; wsprintf(str, _T("%04x"), reg & 0x1ff); TextOut(hdc, 0, y, str, 4); if (view->lock) { p = (UINT8 *)view->buf1.ptr; p += reg; } else if (reg & 0x1ff) { p = opn.reg + reg; } else if (reg & 0x200) { p = (UINT8 *)&psg2.reg; } else { p = (UINT8 *)&psg1.reg; } for (x=0; x<16; x++) { if (mask & 1) { str[0] = viewcmn_hex[*p >> 4]; str[1] = viewcmn_hex[*p & 15]; str[2] = 0; TextOut(hdc, (6 + x*3) * 8, y, str, 2); } p++; mask >>= 1; } } }