diff --git a/.gitignore b/.gitignore index f18038a..564f2d8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ z80 .vscode/* +build/* \ No newline at end of file diff --git a/curses_test.c b/curses_test.c deleted file mode 100644 index 4cce6c4..0000000 --- a/curses_test.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include - -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; -} \ No newline at end of file diff --git a/lagueirtofile b/lagueirtofile new file mode 100644 index 0000000..218ceda --- /dev/null +++ b/lagueirtofile @@ -0,0 +1,5 @@ +libs = -lSDL2 +cppflags = -g +executable = z80 +sourcepath = . +buildpath = build diff --git a/zx_disk.cpp b/zx_disk.cpp index b0e5d4d..501b4cd 100644 --- a/zx_disk.cpp +++ b/zx_disk.cpp @@ -72,7 +72,7 @@ namespace zx_disk uint8_t current_drive = 0; uint8_t current_track = 0; uint8_t current_sector = 0; - uint8_t current_byte = 0; + uint16_t current_byte = 0; uint16_t bytes_to_read = 0; uint8_t eot = 0; @@ -137,15 +137,15 @@ namespace zx_disk sector.size = buffer[pos+0x03]; sector.st1 = buffer[pos+0x04]; sector.st2 = buffer[pos+0x05]; - sector.data_length = buffer[pos+0x06] + (buffer[pos+0x07]<<8); - if (sector.data_length==0) sector.data_length = sector.size<<8; + sector.data_length = buffer[pos+0x06] + uint16_t((buffer[pos+0x07])<<8); + if (sector.data_length==0) sector.data_length = uint16_t(sector.size)<<8; pos += 8; } if (pos&0xff) pos = (pos & 0xffffff00) + 0x100; for (int j=0; j (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); + debug::printResult(); return val; } @@ -278,6 +282,7 @@ namespace zx_disk // =================================================================== uint8_t process_command_specify(uint8_t command) { + debug::composeCommand(command); switch (call_count) { case 1: srt = (command & 0xf0) >> 4; @@ -290,6 +295,7 @@ namespace zx_disk call_count=0; process_current_command = nullptr; mode = ZX_FDC_MODE_IDLE; + debug::printCommand(); break; } return 0; @@ -307,13 +313,17 @@ namespace zx_disk current_drive = command & 0x3; call_count = 0; mode = ZX_FDC_MODE_RESULT; + debug::composeCommand(command); + debug::printCommand(); break; case ZX_FDC_MODE_RESULT: { process_current_command = nullptr; mode = ZX_FDC_MODE_IDLE; const uint8_t val = ST3(); - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); + debug::printResult(); return val; } } @@ -334,6 +344,8 @@ namespace zx_disk seeking = true; process_current_command = nullptr; mode = ZX_FDC_MODE_IDLE; + debug::composeCommand(command); + debug::printCommand(); break; } return 0; @@ -348,9 +360,11 @@ namespace zx_disk { case 0: { + debug::printCommand(); call_count++; const uint8_t val = ST0(); - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 1: @@ -359,7 +373,9 @@ namespace zx_disk seeking = false; call_count = 0; mode = ZX_FDC_MODE_IDLE; - printf("--> (returning 0x%02x)\n", current_track); + //printf("--> (returning 0x%02x)\n", current_track); + debug::composeResult(current_track); + debug::printResult(); return current_track; } return 0; @@ -370,6 +386,7 @@ namespace zx_disk // =================================================================== uint8_t process_command_seek(uint8_t command) { + debug::composeCommand(command); switch (call_count) { case 1: @@ -384,6 +401,7 @@ namespace zx_disk process_current_command = nullptr; call_count = 0; mode = ZX_FDC_MODE_IDLE; + debug::printCommand(); break; } return 0; @@ -402,6 +420,8 @@ namespace zx_disk call_count = 0; current_sector = 0; mode = ZX_FDC_MODE_RESULT; + debug::composeCommand(command); + debug::printCommand(); break; case ZX_FDC_MODE_RESULT: { @@ -413,42 +433,48 @@ namespace zx_disk fdd0busy = 1; const uint8_t val = ST0(); fdd0busy = 0; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 1: { call_count++; const uint8_t val = 0x00; // ST1 - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 2: { call_count++; const uint8_t val = 0x00; // ST2 - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 3: { call_count++; const uint8_t val = current_track; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 4: { call_count++; const uint8_t val = current_head; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 5: { call_count++; const uint8_t val = current_sector+1; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 6: @@ -457,7 +483,9 @@ namespace zx_disk process_current_command = nullptr; mode = ZX_FDC_MODE_IDLE; const uint8_t val = disk.tracks[current_track].sectors[current_sector].size; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); + debug::printResult(); return val; } } @@ -474,6 +502,7 @@ namespace zx_disk switch (mode) { case ZX_FDC_MODE_COMMAND: + debug::composeCommand(command); switch (call_count) { case 1: @@ -503,15 +532,14 @@ namespace zx_disk break; case 7: call_count++; - // GPL; break; case 8: - call_count++; if ( (bytes_to_read==0) && (command != 0xff) ) bytes_to_read = command; bytes_to_read = bytes_to_read << 8; current_byte = 0; call_count = 0; mode = ZX_FDC_MODE_EXECUTION; + debug::printCommand(); break; } break; @@ -519,26 +547,24 @@ namespace zx_disk case ZX_FDC_MODE_EXECUTION: { const uint8_t val = disk.tracks[current_track].sectors[current_sector].data[current_byte]; + + current_byte++; + if (current_byte == disk.tracks[current_track].sectors[current_sector].data_length) { + current_byte = 0; + current_sector++; + if (current_sector == disk.tracks[current_track].num_sectors) { + current_track++; + current_sector = 0; + } + } + bytes_to_read--; if (bytes_to_read==0) { st1 = disk.tracks[current_track].sectors[current_sector].st1; st2 = disk.tracks[current_track].sectors[current_sector].st2; - if (current_sector+1 == disk.tracks[current_track].num_sectors) { - current_track++; - current_sector = 0; - } else { - current_sector++; - } - current_byte = 0; mode = ZX_FDC_MODE_RESULT; - } else { - current_byte++; - if (current_byte == disk.tracks[current_track].sectors[current_sector].data_length) { - current_byte = 0; - current_sector++; - // [TODO] Detectar si s'ha acabat la pista - } } + return val; break; } @@ -553,42 +579,48 @@ namespace zx_disk fdd0busy = 1; const uint8_t val = ST0(); fdd0busy = 0; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 1: { call_count++; const uint8_t val = st1; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 2: { call_count++; const uint8_t val = st2; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 3: { call_count++; const uint8_t val = current_track; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 4: { call_count++; const uint8_t val = current_head; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 5: { call_count++; const uint8_t val = current_sector+1; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); return val; } case 6: @@ -597,7 +629,9 @@ namespace zx_disk process_current_command = nullptr; mode = ZX_FDC_MODE_IDLE; const uint8_t val = disk.tracks[current_track].sectors[current_sector].size; - printf("--> (returning 0x%02x)\n", val); + //printf("--> (returning 0x%02x)\n", val); + debug::composeResult(val); + debug::printResult(); return val; } } @@ -607,4 +641,38 @@ namespace zx_disk return 0; } + + namespace debug + { + uint8_t values[9]; + uint8_t num_values = 0; + + void composeCommand(const uint8_t value) + { + values[num_values++] = value; + } + + void composeResult(const uint8_t value) + { + values[num_values++] = value; + } + + void printCommand() + { + printf("FDC COMMAND %02x: ( ", values[0] & 0x1f); + for (int i=0; i namespace zx_disk { void init(); void reset(); void load(const char *filename); + + namespace debug + { + void composeCommand(const uint8_t value); + void composeResult(const uint8_t value); + + void printCommand(); + void printResult(); + } }