-Anem a usar ncurses

This commit is contained in:
2024-04-10 14:36:17 +02:00
parent d1982fc8b5
commit 1dec5f7a30
6 changed files with 89 additions and 16 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
z80

View File

@@ -1 +0,0 @@
test

51
curses_test.c Normal file
View File

@@ -0,0 +1,51 @@
#include <ncurses.h>
#include <stdlib.h>
int main()
{
initscr();
if (has_colors() == FALSE) {
endwin();
printf("Your terminal does not support color\n");
exit(1);
}
int w, h;
getmaxyx(stdscr, h, w);
start_color();
//init_pair(1, COLOR_WHITE, COLOR_BLACK);
init_pair(1, COLOR_YELLOW, COLOR_BLUE);
WINDOW *win_regs = newwin(10,20,0,0);
WINDOW *win_mem = newwin(10,w-20,0,20);
WINDOW *win_code = newwin(h-10,w,10,0);
refresh();
box(win_mem,0,0);
mvwprintw(win_mem, 0, 2, " MEMORY: ");
mvwprintw(win_mem, 1, 2, "%ix%i", w, h);
wrefresh(win_mem);
box(win_regs,0,0);
mvwprintw(win_regs, 0, 2, " REGISTERS: ");
mvwprintw(win_regs, 1, 2, "AF: 00");
mvwprintw(win_regs, 2, 2, "BC: 00");
mvwprintw(win_regs, 3, 2, "DE: 00");
mvwprintw(win_regs, 4, 2, "HL: 00");
wrefresh(win_regs);
box(win_code,0,0);
wattron(win_code, COLOR_PAIR(1));
mvwprintw(win_code, 1, 1, "Hello world %s !!!", "hola");
wattroff(win_code, COLOR_PAIR(1));
wrefresh(win_code);
refresh();
getch();
endwin();
return 0;
}

View File

@@ -18,9 +18,6 @@ void ula_out(int val)
int main(int argc, char *argv[])
{
const char *peiv = "HOLA %s\n";
printf(peiv, "mundo");
FILE* f = fopen("48.rom", "rb");
fread(memory, 1024, 16, f);
fclose(f);
@@ -32,7 +29,10 @@ int main(int argc, char *argv[])
while(!should_exit)
{
uint16_t PC = z80::getPC();
printf("[%04x] %s", PC, z80dis::getAsm(&memory[PC]));
printf("[%04x] ", PC);
z80dis::printAsm(&memory[PC]);
t += z80::step();
getchar();
}

View File

@@ -4,8 +4,8 @@
namespace z80dis
{
char buffer[256];
//char buffer[256];
int opcode_size = 0;
// $%04x
// $%02x
// %hhd
@@ -29,42 +29,64 @@ namespace z80dis
const char *getBase(const uint8_t *memory)
{
if (*memory == 0xCB) {
opcode_size=2;
return cb_opcodes[*(memory+1)];
} else if (*memory == 0xDD) {
if (*(memory+1) == 0xCB) {
opcode_size=4;
return ix_bit_opcodes[*(memory+3)];
} else {
opcode_size=2;
return ix_opcodes[*(memory+1)];
}
} else if (*memory == 0xED) {
opcode_size=2;
return misc_opcodes[(*(memory+1))-64];
} else if (*memory == 0xFD) {
if (*(memory+1) == 0xCB) {
opcode_size=4;
return iy_bit_opcodes[*(memory+3)];
} else {
opcode_size=2;
return iy_opcodes[*(memory+1)];
}
} else {
opcode_size=1;
return base_opcodes[*memory];
}
}
const char *getAsm(const uint8_t *memory)
void printOpcode(const uint8_t *memory)
{
for (int i=0; i<4;++i) if (opcode_size>i) printf("%02x ", *(memory+i)); else printf(" ");
}
void printAsm(const uint8_t *memory)
{
opcode_size = 0;
const char *base = getBase(memory);
if (strstr(base, "4x")) {
opcode_size+=2;
printOpcode(memory);
const uint16_t word = *(uint16_t*)(memory+1);
sprintf(buffer, base, word);
return buffer;
printf(base, word);
} else if (strstr(base, "2x")) {
sprintf(buffer, base, *(memory+1));
return buffer;
opcode_size+=1;
printOpcode(memory);
printf(base, *(memory+1));
} else if (strstr(base, "hhd")) {
sprintf(buffer, base, (int8_t)*(memory+1));
return buffer;
opcode_size+=1;
printOpcode(memory);
if (opcode_size>4) {
opcode_size=4;
printf(base, (int8_t)*(memory+2));
} else {
printf(base, (int8_t)*(memory+1));
}
} else {
return base;
printOpcode(memory);
printf(base);
}
}
}

View File

@@ -4,5 +4,5 @@
namespace z80dis
{
const char *getAsm(const uint8_t *memory);
void printAsm(const uint8_t *memory);
}