Compare commits

..

2 Commits

Author SHA1 Message Date
7cb6ae527b - Treballant en que funcione al temps correcte
- Treballant en el só
2024-12-01 21:50:20 +01:00
7eb5df248f - [NEW] load binary to memory from inside or as arguments to exe
- Trying berserk
2024-04-25 06:41:35 +02:00
8 changed files with 114 additions and 10 deletions

View File

@@ -10,6 +10,8 @@
#include <string.h>
uint8_t memory[65536];
uint32_t time = 0;
uint32_t t_states = 0;
int main(int argc, char *argv[])
{
@@ -26,11 +28,16 @@ int main(int argc, char *argv[])
zx_ula::sound_init();
zx_tape::load("manic.tap");
zx_tape::load("abusimbel.tap");
if (argc==3) { z80debug::loadngo(argv[1], argv[2]); }
bool should_exit = false;
SDL_Event e;
time = SDL_GetTicks();
t_states = 0;
while (!should_exit)
{
while (SDL_PollEvent(&e))
@@ -81,6 +88,7 @@ int main(int argc, char *argv[])
}
}
}
if (!z80debug::debugging()) {
if (z80debug::isbreak(z80::getPC(), 9)) {
z80debug::stop();
@@ -88,11 +96,17 @@ int main(int argc, char *argv[])
} else {
//if (z80::getPC()==0x05C8) zx_tape::go_berserk();
uint8_t dt = z80::step();
t_states += dt;
zx_tape::update(dt);
//if (!zx_tape::berserk()) {
zx_ula::sound_update(dt);
//}
zx_ula::sound_update(dt);
zxscreen::refresh(dt);
if (t_states>=350000)
{
while (SDL_GetTicks()<time+100) {}
t_states -= 350000;
time = SDL_GetTicks();
}
}
}
}

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

View File

@@ -57,6 +57,8 @@ namespace zx_ula
static uint8_t ear = 0;
static uint8_t mic = 0;
static uint16_t last_1 = 0;
void update_zx_keyboard()
{
const uint8_t *keys = SDL_GetKeyboardState(NULL);
@@ -220,15 +222,33 @@ namespace zx_ula
void audioCallback(void * userdata, uint8_t * stream, int len)
{
const uint16_t top = sound_pos < len ? sound_pos : len;
printf("top: %i, len: %i, pos: %i\n", top, len, sound_pos);
memcpy(stream, sound_buffer, top);
if (top<len) memchr(&stream[top], sound_buffer[top-1], len-top);
sound_pos=0;
if (top<sound_pos)
{
if (last_1>top)
{
memcpy(sound_buffer, &sound_buffer[top], sound_pos-top);
sound_pos=sound_pos-top;
last_1=last_1-top;
}
else
{
sound_pos=last_1=0;
}
}
else
{
sound_pos=last_1=0;
}
}
void sound_init()
{
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
sound_enable();
}
void sound_enable()
@@ -244,9 +264,20 @@ namespace zx_ula
void sound_update(const uint8_t dt)
{
t_sound += dt;
if (t_sound>=317) {
t_sound-=317;
sound_buffer[sound_pos++] = ear*128;
if (t_sound>=318) {
t_sound-=318;
//sound_pos = (sound_pos+1) & 0x3ff;
//sound_buffer[sound_pos] = ear*128;
if (sound_pos<1024)
{
sound_buffer[sound_pos++] = ear*128;
if (ear) last_1 = sound_pos;
}
/*else
{
printf("WARNING! Sound buffer overflow!\n");
}*/
}
}
}