diff --git a/main.cpp b/main.cpp index 671e923..96d3ea3 100644 --- a/main.cpp +++ b/main.cpp @@ -28,6 +28,8 @@ int main(int argc, char *argv[]) zx_tape::load("manic.tap"); + if (argc==3) { z80debug::loadngo(argv[1], argv[2]); } + bool should_exit = false; SDL_Event e; @@ -86,12 +88,10 @@ int main(int argc, char *argv[]) z80debug::stop(); zxscreen::redraw(); } else { - //if (z80::getPC()==0x05C8) zx_tape::go_berserk(); + if (z80::getPC()==0x05C8) zx_tape::go_berserk(); uint8_t dt = z80::step(); zx_tape::update(dt); - //if (!zx_tape::berserk()) { - zx_ula::sound_update(dt); - //} + zx_ula::sound_update(dt); zxscreen::refresh(dt); } } diff --git a/test.asm b/test.asm new file mode 100644 index 0000000..c4b8160 --- /dev/null +++ b/test.asm @@ -0,0 +1,27 @@ + .org $8000 + + ei +START: + ld a, 2 + out ($fe), a + ld b, 255 + ld de, TILES + ld hl, $4000 +LOOP: + ld a, (de) + ld (hl), a + inc e + inc h + djnz LOOP + ld a, (de) + ld hl, $5800 + ld (hl), a + + ld a, 0 + out ($fe), a + + halt + jr START + +TILES: db $81, $42, $24, $18, $18, $24, $42, $81, $4d + diff --git a/z80.cpp b/z80.cpp index f2b59aa..f47b291 100644 --- a/z80.cpp +++ b/z80.cpp @@ -684,7 +684,7 @@ namespace z80 if (exit_from_halt) { exit_from_halt = false; } else { - printf("HALT\n"); + //printf("HALT\n"); rPC--; } } @@ -2697,4 +2697,5 @@ namespace z80 uint16_t getPC() { return rPC; } + void setPC(const uint16_t addr) { rPC = addr; } } \ No newline at end of file diff --git a/z80.h b/z80.h index d618c1f..8240d2c 100644 --- a/z80.h +++ b/z80.h @@ -21,4 +21,6 @@ namespace z80 uint16_t getIY(); uint16_t getSP(); uint16_t getPC(); + + void setPC(const uint16_t addr); } \ No newline at end of file diff --git a/z80debug.cpp b/z80debug.cpp index e79413c..39955be 100644 --- a/z80debug.cpp +++ b/z80debug.cpp @@ -74,7 +74,7 @@ namespace z80debug void show() { - is_debugging = true; + is_debugging = false; if (win) return; win = SDL_CreateWindow("Z80 Debugger", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 71*CHR_W, 34*CHR_H, SDL_WINDOW_RESIZABLE); ren = SDL_CreateRenderer(win, -1, 0); @@ -421,6 +421,14 @@ namespace z80debug int address = getnum(cmd); if (address<0 || address>65536) { strcpy(console_error, "Illegal memory address"); return; } mem_viewer_pos = address; + } else if (strcmp(cmd, "l")==0 || strcmp(cmd, "load")==0) { + getcmd(); + char filename[256]; + strcpy(filename, cmd); + getcmd(); + char address[256]; + strcpy(address, cmd); + loadngo(filename, address); } } @@ -441,4 +449,20 @@ namespace z80debug { mem_modified[addr] = true; } + + void loadngo(const char* filename, const char* addr) + { + int address = getnum(addr); + if (address<0 || address>65536) { strcpy(console_error, "Illegal offset"); return; } + + FILE *f = fopen(filename, "rb"); + fseek(f, 0, SEEK_END); + int size = ftell(f); + fseek(f, 0, SEEK_SET); + uint8_t *memory = z80::getMem(); + fread(memory+address, size, 1, f); + fclose(f); + z80::setPC(address); + is_debugging = false; + } } \ No newline at end of file diff --git a/z80debug.h b/z80debug.h index 32210be..15eeec9 100644 --- a/z80debug.h +++ b/z80debug.h @@ -17,4 +17,6 @@ namespace z80debug const bool isbreak(const uint16_t address, const uint8_t type=1); uint32_t next(); + + void loadngo(const char* filename, const char* addr); } \ No newline at end of file diff --git a/zx_screen.cpp b/zx_screen.cpp index a0e5cfb..168de53 100644 --- a/zx_screen.cpp +++ b/zx_screen.cpp @@ -2,6 +2,7 @@ #include "z80.h" #include "zx_ula.h" #include +#include "zx_tape.h" namespace zxscreen { @@ -143,6 +144,8 @@ namespace zxscreen void redraw() { + if (zx_tape::berserk()) return; + Uint32* pixels; int pitch; SDL_LockTexture(tex, NULL, (void**)&pixels, &pitch);