#include "z80analyze.h" #include "z80.h" #include "z80debug.h" #include "zx_mem.h" #include #include "ui_window.h" #include "ui.h" namespace z80analyze { SDL_Window *win = nullptr; SDL_Renderer *ren = nullptr; SDL_Texture *tex = nullptr; SDL_Texture *uitex = nullptr; uint16_t address = 0; int mx, my; bool needs_refresh = true; void refreshTitle(); bool handleEvent(SDL_Event *e) { if (e->type == SDL_MOUSEBUTTONUP) { //if (z80::getMemTag(address)!=MEMTAG_INST) address = find_previous_opcode(address); z80debug::setcursor(address); z80debug::refresh(); /*if (e->button.button == 1) z80::clearMemTouched(); //z80::clearMemTag(); else z80::fixMemTouched();*/ refresh(); } if (e->type == SDL_MOUSEMOTION) { if (e->motion.windowID == SDL_GetWindowID(win)) { SDL_ShowCursor(SDL_DISABLE); mx = e->motion.x/2; my = e->motion.y/2; refreshTitle(); needs_refresh=true; focus(); } } if (e->type == SDL_KEYDOWN) { if (e->key.keysym.scancode == SDL_SCANCODE_RETURN) { /* z80::fixMemTouched(); refresh(); z80debug::refresh(); */ } else if (e->key.keysym.scancode == SDL_SCANCODE_BACKSPACE) { const uint32_t size = mem::getSize(); //for (int i=0; i=0 && my>=0 && mx<256 && my<256) { address = mx+my*256; SDL_SetWindowTitle(win, SDL_itoa(address, tmp, 16)); } } void refresh(const bool conditional) { if (!win) return; if (conditional && !needs_refresh) return; needs_refresh = false; ui::setrenderer(ren, uitex); Uint32 *pixels; int pitch; SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch); for (int i=0; i<65536; ++i) { //uint8_t tag = z80::getMemTag(i); //pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_MIXED ? 0xFF00FF : 0x00FF00; uint32_t none_color = i<0x4000 ? 0x101010 : i<0x5800 ? 0x202020 : i<0x5b00 ? 0x404040 : 0x808080; uint8_t tag = mem::getTag(i); pixels[i] = !(tag & MEMTAG_TOUCHED) ? none_color : (tag & MEMTAG_TINST) ? 0x00FF00 : (tag & MEMTAG_TREPEAT) ? 0xFF0000 : 0x0000FF; } pixels[z80::getPC()] = 0xFFFFFF; if (mx>=0 && my>=0 && mx<256 && my<256) { if (mx>2) pixels[(mx-2)+(my)*256] = 0x000000; if (mx>1) pixels[(mx-1)+(my)*256] = 0x000000; if (mx<255) pixels[(mx+1)+(my)*256] = 0x000000; if (mx<254) pixels[(mx+2)+(my)*256] = 0x000000; if (my>1) pixels[(mx)+(my-1)*256] = 0x000000; if (my>2) pixels[(mx)+(my-2)*256] = 0x000000; if (my<255) pixels[(mx)+(my+1)*256] = 0x000000; if (my<254) pixels[(mx)+(my+2)*256] = 0x000000; } SDL_UnlockTexture(tex); SDL_RenderCopy(ren, tex, NULL, NULL); SDL_RenderPresent(ren); refreshTitle(); } void hide() { ui::window::unregisterWindow(SDL_GetWindowID(win)); SDL_DestroyTexture(uitex); uitex = nullptr; SDL_DestroyTexture(tex); tex = nullptr; SDL_DestroyRenderer(ren); ren = nullptr; SDL_DestroyWindow(win); win = nullptr; } void focus() { if (win) { SDL_RaiseWindow(win); refresh(); } } }