- [NEW] load binary to memory from inside or as arguments to exe

- Trying berserk
This commit is contained in:
2024-04-25 06:41:35 +02:00
parent b05ce14a95
commit 7eb5df248f
7 changed files with 65 additions and 6 deletions

View File

@@ -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);
//}
zxscreen::refresh(dt);
}
}

27
test.asm Normal file
View File

@@ -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

View File

@@ -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; }
}

2
z80.h
View File

@@ -21,4 +21,6 @@ namespace z80
uint16_t getIY();
uint16_t getSP();
uint16_t getPC();
void setPC(const uint16_t addr);
}

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -2,6 +2,7 @@
#include "z80.h"
#include "zx_ula.h"
#include <SDL2/SDL.h>
#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);