Skip to content

Commit

Permalink
Zeta 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Jul 16, 2023
1 parent 1a16a41 commit 5e31f21
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ static u16 incdec_dir(cpu_state* cpu, u16 reg, u16 amount) {
}
}

u32 cpu_get_ip(cpu_state *cpu) {
u16 cs = cpu->seg[SEG_CS], ip = cpu->ip;
if (((cpu->ip & 0xFF00) == 0x1100) && (cpu->seg[SEG_CS] == 0xF000)) {
// If we're inside an HLE interrupt handler, try to retrieve the actual IP.
// TODO: This still points to a system library, most likely.
// A "real" call stack will be necessary.
ip = ram_u16(cpu, SEG(SEG_SS, cpu->sp));
cs = ram_u16(cpu, SEG(SEG_SS, cpu->sp + 2));
}
return ip | (cs << 16);
}

void cpu_set_ip(cpu_state* cpu, u16 cs, u16 ip) {
cpu->seg[SEG_CS] = cs;
cpu->ip = ip;
Expand Down
1 change: 1 addition & 0 deletions src/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void cpu_push16(cpu_state* cpu, u16 v);
u16 cpu_pop16(cpu_state* cpu);

void cpu_emit_interrupt(cpu_state* cpu, u8 intr);
u32 cpu_get_ip(cpu_state *cpu);
void cpu_set_ip(cpu_state* cpu, u16 cs, u16 ip);

// external
Expand Down
9 changes: 7 additions & 2 deletions src/posix_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#define MAX_FILES_START 16
#define MAX_FILES_LIMIT 256

#define DEBUG_VFS
// #define DEBUG_VFS

static FILE **file_pointers;
static char **file_pointer_names;
Expand Down Expand Up @@ -538,9 +538,14 @@ int vfs_open(const char* filename, int mode) {
fprintf(stderr, "posix vfs: opened %s (%s) at %d\n", path, mode_str, i+1);
#endif
file_pointers[i] = file;
#ifdef HAS_DEVELOPER_MODE
if (vfs_debug_enabled) {
file_pointer_names[i] = strdup(path_filename);
file_pointer_names[i] = malloc(strlen(path_filename) + 20);
if (file_pointer_names[i] != NULL) {
sprintf(file_pointer_names[i], "%s @ %04X:%04X", path_filename, zzt_get_ip() >> 16, zzt_get_ip() & 0xFFFF);
}
}
#endif
return i+1;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/sdl/frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,18 @@ void cpu_ext_log(const char *s) {

void zeta_show_developer_warning(const char *format, ...) {
char debug_message[4097];
char debug_title[129];
va_list val;

if (!developer_mode) return;
debug_title[128] = 0;
snprintf(debug_title, 128, "Developer Warning @ %04X:%04X", zzt_get_ip() >> 16, zzt_get_ip() & 0xFFFF);
debug_message[4096] = 0;
va_start(val, format);
vsnprintf(debug_message, 4096, format, val);
va_end(val);

SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Developer Warning", debug_message, NULL);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, debug_title, debug_message, NULL);
}

int zeta_has_feature(int feature) {
Expand Down
5 changes: 5 additions & 0 deletions src/zzt.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdbool.h>
#include <string.h>
#include "audio_shared.h"
#include "cpu.h"
#include "ui.h"
#include "zzt.h"
#include "zzt_ems.h"
Expand Down Expand Up @@ -124,6 +125,10 @@ typedef struct {

zzt_state zzt;

u32 zzt_get_ip(void) {
return cpu_get_ip(&zzt.cpu);
}

int zzt_get_cycles(void) {
return zzt.cpu.cycles;
}
Expand Down
3 changes: 3 additions & 0 deletions src/zzt.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ typedef struct {

USER_FUNCTION
zzt_key_t zzt_key_pop(void);
USER_FUNCTION
u32 zzt_get_ip(void);
USER_FUNCTION
int zzt_get_cycles(void);

USER_FUNCTION
Expand Down

0 comments on commit 5e31f21

Please sign in to comment.