- [NEW] el analitzador pot mostrar les instruccions repetides des de l'ultim estat - [NEW] gestió de opcodes usats
99 lines
2.7 KiB
C++
99 lines
2.7 KiB
C++
#include "z80analyze.h"
|
|
#include "z80.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;
|
|
|
|
void refreshTitle();
|
|
|
|
bool handleEvent(SDL_Event *e)
|
|
{
|
|
if (e->type == SDL_MOUSEBUTTONUP)
|
|
{
|
|
if (e->button.button == 1)
|
|
z80::clearMemTouched();
|
|
else
|
|
z80::fixMemTouched();
|
|
refresh();
|
|
}
|
|
if (e->type == SDL_MOUSEMOTION)
|
|
{
|
|
refreshTitle();
|
|
refresh();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void show()
|
|
{
|
|
if (!win)
|
|
{
|
|
SDL_ShowCursor(SDL_DISABLE);
|
|
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()
|
|
{
|
|
int mx, my;
|
|
SDL_GetMouseState(&mx, &my);
|
|
mx/=2; my/=2;
|
|
SDL_SetWindowTitle(win, SDL_itoa(mx+my*256, tmp, 16));
|
|
}
|
|
void refresh()
|
|
{
|
|
if (!win) return;
|
|
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::getMemTouched(i);
|
|
pixels[i] = tag==MEMTAG_NONE ? 0x808080 : tag==MEMTAG_DATA ? 0x0000FF : tag==MEMTAG_REPEAT ? 0xFF0000 : 0x00FF00;
|
|
}
|
|
pixels[z80::getPC()] = 0xFFFFFF;
|
|
|
|
int mx, my;
|
|
SDL_GetMouseState(&mx, &my);
|
|
mx/=2; my/=2;
|
|
pixels[(mx-2)+(my)*256] = 0x000000;
|
|
pixels[(mx-1)+(my)*256] = 0x000000;
|
|
pixels[(mx+1)+(my)*256] = 0x000000;
|
|
pixels[(mx+2)+(my)*256] = 0x000000;
|
|
pixels[(mx)+(my-1)*256] = 0x000000;
|
|
pixels[(mx)+(my-2)*256] = 0x000000;
|
|
pixels[(mx)+(my+1)*256] = 0x000000;
|
|
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;
|
|
}
|
|
}
|