Files
z80/z80analyze.cpp
Raimon Zamora 3fd28136f6 - [NEW] ui::placetext() i ui::placechar, pa ficar text en qualsevol pixel
- [NEW] [Z80Analize] backspace esborra tots els tags
- [NEW] [zx-128bankviewer] Es mostra quina pàgina de memòria està asignada a cada bank
- [FIX] [zx_128mem] es filtra el port al que escolta la memòria
- [NEW] [zx_screen] Es mostra en quina pantalla estem (normal o shadow)
- [FIX] [zx_screen] tots els tipos per al calcul de adreces passats a uint32_t
- [NEW] [zx_ula] afegides combinacions de cursors per a major comoditat
2025-07-22 13:31:21 +02:00

145 lines
4.5 KiB
C++

#include "z80analyze.h"
#include "z80.h"
#include "z80debug.h"
#include "z80mem.h"
#include <SDL2/SDL.h>
#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 = z80mem::get()->getSize();
//for (int i=0; i<size; ++i) z80mem::get()->setTag(i, z80mem::get()->getTag(i) & ~MEMTAG_TOUCHED);
for (int i=0; i<size; ++i) z80mem::get()->setTag(i, MEMTAG_NONE);
refresh();
z80debug::refresh();
}
}
return true;
}
void show()
{
if (!win)
{
win = SDL_CreateWindow("Z80 Analyzer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 512, 512, SDL_WINDOW_SHOWN);
ren = SDL_CreateRenderer(win, -1, 0);
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 256, 256);
uitex = ui::createtexture(ren);
ui::window::registerWindow(SDL_GetWindowID(win), handleEvent);
}
refresh();
}
char tmp[10];
void refreshTitle()
{
if (mx>=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 = z80mem::get()->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();
}
}
}