-Anem a usar ncurses
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
z80
|
||||||
51
curses_test.c
Normal file
51
curses_test.c
Normal 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;
|
||||||
|
}
|
||||||
8
main.cpp
8
main.cpp
@@ -18,9 +18,6 @@ void ula_out(int val)
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *peiv = "HOLA %s\n";
|
|
||||||
printf(peiv, "mundo");
|
|
||||||
|
|
||||||
FILE* f = fopen("48.rom", "rb");
|
FILE* f = fopen("48.rom", "rb");
|
||||||
fread(memory, 1024, 16, f);
|
fread(memory, 1024, 16, f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -32,7 +29,10 @@ int main(int argc, char *argv[])
|
|||||||
while(!should_exit)
|
while(!should_exit)
|
||||||
{
|
{
|
||||||
uint16_t PC = z80::getPC();
|
uint16_t PC = z80::getPC();
|
||||||
printf("[%04x] %s", PC, z80dis::getAsm(&memory[PC]));
|
printf("[%04x] ", PC);
|
||||||
|
|
||||||
|
z80dis::printAsm(&memory[PC]);
|
||||||
|
|
||||||
t += z80::step();
|
t += z80::step();
|
||||||
getchar();
|
getchar();
|
||||||
}
|
}
|
||||||
|
|||||||
42
z80dis.cpp
42
z80dis.cpp
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
namespace z80dis
|
namespace z80dis
|
||||||
{
|
{
|
||||||
char buffer[256];
|
//char buffer[256];
|
||||||
|
int opcode_size = 0;
|
||||||
// $%04x
|
// $%04x
|
||||||
// $%02x
|
// $%02x
|
||||||
// %hhd
|
// %hhd
|
||||||
@@ -29,42 +29,64 @@ namespace z80dis
|
|||||||
const char *getBase(const uint8_t *memory)
|
const char *getBase(const uint8_t *memory)
|
||||||
{
|
{
|
||||||
if (*memory == 0xCB) {
|
if (*memory == 0xCB) {
|
||||||
|
opcode_size=2;
|
||||||
return cb_opcodes[*(memory+1)];
|
return cb_opcodes[*(memory+1)];
|
||||||
} else if (*memory == 0xDD) {
|
} else if (*memory == 0xDD) {
|
||||||
if (*(memory+1) == 0xCB) {
|
if (*(memory+1) == 0xCB) {
|
||||||
|
opcode_size=4;
|
||||||
return ix_bit_opcodes[*(memory+3)];
|
return ix_bit_opcodes[*(memory+3)];
|
||||||
} else {
|
} else {
|
||||||
|
opcode_size=2;
|
||||||
return ix_opcodes[*(memory+1)];
|
return ix_opcodes[*(memory+1)];
|
||||||
}
|
}
|
||||||
} else if (*memory == 0xED) {
|
} else if (*memory == 0xED) {
|
||||||
|
opcode_size=2;
|
||||||
return misc_opcodes[(*(memory+1))-64];
|
return misc_opcodes[(*(memory+1))-64];
|
||||||
} else if (*memory == 0xFD) {
|
} else if (*memory == 0xFD) {
|
||||||
if (*(memory+1) == 0xCB) {
|
if (*(memory+1) == 0xCB) {
|
||||||
|
opcode_size=4;
|
||||||
return iy_bit_opcodes[*(memory+3)];
|
return iy_bit_opcodes[*(memory+3)];
|
||||||
} else {
|
} else {
|
||||||
|
opcode_size=2;
|
||||||
return iy_opcodes[*(memory+1)];
|
return iy_opcodes[*(memory+1)];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
opcode_size=1;
|
||||||
return base_opcodes[*memory];
|
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);
|
const char *base = getBase(memory);
|
||||||
|
|
||||||
if (strstr(base, "4x")) {
|
if (strstr(base, "4x")) {
|
||||||
|
opcode_size+=2;
|
||||||
|
printOpcode(memory);
|
||||||
const uint16_t word = *(uint16_t*)(memory+1);
|
const uint16_t word = *(uint16_t*)(memory+1);
|
||||||
sprintf(buffer, base, word);
|
printf(base, word);
|
||||||
return buffer;
|
|
||||||
} else if (strstr(base, "2x")) {
|
} else if (strstr(base, "2x")) {
|
||||||
sprintf(buffer, base, *(memory+1));
|
opcode_size+=1;
|
||||||
return buffer;
|
printOpcode(memory);
|
||||||
|
printf(base, *(memory+1));
|
||||||
} else if (strstr(base, "hhd")) {
|
} else if (strstr(base, "hhd")) {
|
||||||
sprintf(buffer, base, (int8_t)*(memory+1));
|
opcode_size+=1;
|
||||||
return buffer;
|
printOpcode(memory);
|
||||||
|
if (opcode_size>4) {
|
||||||
|
opcode_size=4;
|
||||||
|
printf(base, (int8_t)*(memory+2));
|
||||||
|
} else {
|
||||||
|
printf(base, (int8_t)*(memory+1));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return base;
|
printOpcode(memory);
|
||||||
|
printf(base);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user