diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/config.c | 5 | ||||
-rw-r--r-- | source/gui.c | 142 | ||||
-rw-r--r-- | source/keyboard.c | 37 | ||||
-rw-r--r-- | source/main.c | 50 | ||||
-rw-r--r-- | source/tapes.c | 15 | ||||
-rw-r--r-- | source/z80.c | 65 | ||||
-rw-r--r-- | source/zx81.c | 40 |
7 files changed, 344 insertions, 10 deletions
diff --git a/source/config.c b/source/config.c index 433b5d6..55141ba 100644 --- a/source/config.c +++ b/source/config.c @@ -35,6 +35,7 @@ const char *conf_entry[DS81_NUM_CONFIG_ITEMS]= "sticky_shift", "average_touchscreen", "static_ram_at_0x2000", + "load_default_snapshot" }; @@ -44,6 +45,7 @@ int DS81_Config[DS81_NUM_CONFIG_ITEMS]= { TRUE, FALSE, + FALSE, FALSE }; @@ -128,6 +130,9 @@ const char *ConfigDesc(DS81_ConfigItem item) case DS81_STATIC_RAM_AT_0x2000: return "RAM AT 8192"; + case DS81_LOAD_DEFAULT_SNAPSHOT: + return "LOAD DEFAULT SNAPSHOT"; + default: return "UNKNOWN"; } diff --git a/source/gui.c b/source/gui.c index ed30706..0400197 100644 --- a/source/gui.c +++ b/source/gui.c @@ -28,6 +28,8 @@ #include <sys/dir.h> #include "framebuffer.h" +#include "zx81.h" +#include "keyboard.h" #include "config.h" @@ -712,3 +714,143 @@ int GUI_FileSelect(char pwd[], char selected_file[], const char *filter) return ret; } + + +int GUI_InputName(char name[], int maxlen) +{ + struct + { + SoftKey key; + int ascii; + } keymap[] = + { + {SK_1, '1'}, + {SK_2, '2'}, + {SK_3, '3'}, + {SK_4, '4'}, + {SK_5, '5'}, + {SK_6, '6'}, + {SK_7, '7'}, + {SK_8, '8'}, + {SK_9, '9'}, + {SK_0, '0'}, + {SK_A, 'A'}, + {SK_B, 'B'}, + {SK_C, 'C'}, + {SK_D, 'D'}, + {SK_E, 'E'}, + {SK_F, 'F'}, + {SK_G, 'G'}, + {SK_H, 'H'}, + {SK_I, 'I'}, + {SK_J, 'J'}, + {SK_K, 'K'}, + {SK_L, 'L'}, + {SK_M, 'M'}, + {SK_N, 'N'}, + {SK_O, 'O'}, + {SK_P, 'P'}, + {SK_Q, 'Q'}, + {SK_R, 'R'}, + {SK_S, 'S'}, + {SK_T, 'T'}, + {SK_U, 'U'}, + {SK_V, 'V'}, + {SK_W, 'W'}, + {SK_X, 'X'}, + {SK_Y, 'Y'}, + {SK_Z, 'Z'}, + {0, 0} + }; + + SoftKeyEvent ev; + char text[1024]; + int done = FALSE; + int accept = FALSE; + int update = TRUE; + + SK_DisplayKeyboard(); + ZX81SuspendDisplay(); + + name[0] = 0; + + while(!done) + { + if (update) + { + sprintf(text, "enter the snapshot name:\n" + "\"%s%%l%%\"" + "\n\n\npress enter to accept.\n" + "press period to backspace.\n" + "press space/break to cancel\n", + name); + + ZX81DisplayString(text); + + update = FALSE; + } + + while(SK_GetBareEvent(&ev)) + { + if (!ev.pressed) + { + size_t l; + int f; + int ascii; + + l = strlen(name); + + switch(ev.key) + { + case SK_PERIOD: + if (l) + { + name[--l] = 0; + update = TRUE; + } + break; + + case SK_SPACE: + done = TRUE; + accept = FALSE; + break; + + case SK_NEWLINE: + done = TRUE; + accept = TRUE; + break; + + default: + if (l < maxlen) + { + f = 0; + ascii = 0; + + while(!ascii && keymap[f].ascii) + { + if (ev.key == keymap[f].key) + { + ascii = keymap[f].ascii; + } + + f++; + } + + if (ascii) + { + name[l++] = ascii; + name[l] = 0; + update = TRUE; + } + } + break; + } + } + } + + swiWaitForVBlank(); + } + + return accept; +} + diff --git a/source/keyboard.c b/source/keyboard.c index d2e7aa7..6483b1c 100644 --- a/source/keyboard.c +++ b/source/keyboard.c @@ -26,6 +26,7 @@ #include "framebuffer.h" #include "touchwrap.h" #include "keyb_bin.h" +#include "stream.h" /* ---------------------------------------- STATIC DATA */ @@ -409,3 +410,39 @@ const char *SK_KeyName(SoftKey k) } +void SK_SaveSnapshot(FILE *fp) +{ + STRPUT(fp, pad_left_key); + STRPUT(fp, pad_right_key); + STRPUT(fp, pad_up_key); + STRPUT(fp, pad_down_key); + STRPUT(fp, pad_A_key); + STRPUT(fp, pad_B_key); + STRPUT(fp, pad_X_key); + STRPUT(fp, pad_Y_key); + STRPUT(fp, pad_R_key); + STRPUT(fp, pad_L_key); + STRPUT(fp, pad_start_key); + STRPUT(fp, pad_select_key); + STRPUT(fp, key_state); +} + + +void SK_LoadSnapshot(FILE *fp) +{ + STRGET(fp, pad_left_key); + STRGET(fp, pad_right_key); + STRGET(fp, pad_up_key); + STRGET(fp, pad_down_key); + STRGET(fp, pad_A_key); + STRGET(fp, pad_B_key); + STRGET(fp, pad_X_key); + STRGET(fp, pad_Y_key); + STRGET(fp, pad_R_key); + STRGET(fp, pad_L_key); + STRGET(fp, pad_start_key); + STRGET(fp, pad_select_key); + STRGET(fp, key_state); +} + + diff --git a/source/main.c b/source/main.c index 5bef185..c196608 100644 --- a/source/main.c +++ b/source/main.c @@ -35,10 +35,13 @@ #include "config.h" #include "textmode.h" #include "monitor.h" +#include "snapshot.h" #include "splashimg_bin.h" #include "rom_font_bin.h" +#include "ds81_debug.h" + #ifndef DS81_VERSION #define DS81_VERSION "DEV " __TIME__ "/" __DATE__ #endif @@ -53,6 +56,12 @@ static const char *main_menu[]= "Configure", "Map Joypad to Keys", "Machine Code Monitor", +#ifndef DS81_DISABLE_FAT + "Save Memory Snapshot", + "Load Memory Snapshot", + "Save Joypad Mappings", + "Load Joypad Mappings", +#endif "Cancel", NULL }; @@ -64,6 +73,12 @@ typedef enum MenuConfigure, MenuMapJoypad, MenuMonitor, +#ifndef DS81_DISABLE_FAT + MenuSaveSnapshot, + MenuLoadSnapshot, + MenuSaveMappings, + MenuLoadMappings +#endif } MenuOpt; /* ---------------------------------------- IRQ FUNCS @@ -83,8 +98,9 @@ static void Splash(void) " " "Welcome to DS81, a ZX81 emulator for the Ninetendo DS. " "You can safely ignore this message. I was just bored for half an " - "hour. " - "Thanks to Slay Radio for coding fuel." + "hour. And no retro item is complete without a side-scroller... " + "Thanks to Slay Radio, the Genki Rockets and the High Voltage SID " + "Collection for coding fuel." }; static const char *text[]= @@ -144,6 +160,7 @@ static void Splash(void) if (res) { ZX81EnableFileSystem(TRUE); + SNAP_Enable(TRUE); FB_Centre("Found a FAT device.",y,COL_WHITE,COL_TRANSPARENT); y += 8; @@ -167,6 +184,7 @@ static void Splash(void) else { ZX81EnableFileSystem(FALSE); + SNAP_Enable(FALSE); FB_Centre("Sorry, but you don't have a",y,COL_WHITE,COL_TRANSPARENT); y += 8; @@ -374,10 +392,20 @@ int main(int argc, char *argv[]) SK_SetSticky(SK_SHIFT,DS81_Config[DS81_STICKY_SHIFT]); + if (DS81_Config[DS81_LOAD_DEFAULT_SNAPSHOT]) + { + SNAP_Load(z80, "AUTO"); + } + while(1) { + static unsigned cycle; + SoftKeyEvent ev; + DS81_DEBUG_STATUS("PC = %4.4x I = %u", z80->PC, cycle); + cycle++; + Z80Exec(z80); while(SK_GetEvent(&ev)) @@ -412,6 +440,24 @@ int main(int argc, char *argv[]) case MenuMonitor: MachineCodeMonitor(z80); break; + +#ifndef DS81_DISABLE_FAT + case MenuSaveSnapshot: + SNAP_Save(z80); + break; + + case MenuLoadSnapshot: + SNAP_Load(z80, NULL); + break; + + case MenuSaveMappings: + // TODO + break; + + case MenuLoadMappings: + // TODO + break; +#endif } SK_DisplayKeyboard(); diff --git a/source/tapes.c b/source/tapes.c index 26bbd24..2220778 100644 --- a/source/tapes.c +++ b/source/tapes.c @@ -36,13 +36,15 @@ #include "mazogs_bin.h" #include "mazogs_inlay_bin.h" +#include "ds81_debug.h" + /* ---------------------------------------- STATIC DATA */ typedef struct { const u8 *tape; - const u32 *tape_len; + const u8 *tape_end; sImage img; const void *source_pcx; SoftKey *keys; @@ -105,7 +107,7 @@ static Tape tapes[NO_TAPES]= { { maze_bin, - &maze_bin_size, + maze_bin_end, {0}, maze_inlay_bin, maze_keys, @@ -123,7 +125,7 @@ static Tape tapes[NO_TAPES]= }, { mazogs_bin, - &mazogs_bin_size, + mazogs_bin_end, {0}, mazogs_inlay_bin, mazogs_keys, @@ -141,7 +143,7 @@ static Tape tapes[NO_TAPES]= }, { cpatrol_bin, - &cpatrol_bin_size, + cpatrol_bin_end, {0}, cpatrol_inlay_bin, cpatrol_keys, @@ -162,7 +164,7 @@ static Tape tapes[NO_TAPES]= }, { sabotage_bin, - &sabotage_bin_size, + sabotage_bin_end, {0}, sabotage_inlay_bin, sabotage_keys, @@ -260,7 +262,8 @@ void SelectTape(void) int f; done=TRUE; - ZX81SetTape(tapes[current].tape,*tapes[current].tape_len); + ZX81SetTape(tapes[current].tape, + tapes[current].tape_end - tapes[current].tape); for(f=0;tapes[current].keys[f]!=NUM_SOFT_KEYS;f+=2) { diff --git a/source/z80.c b/source/z80.c index 36c5793..d4205c5 100644 --- a/source/z80.c +++ b/source/z80.c @@ -31,6 +31,8 @@ #include "z80.h" #include "z80_private.h" +#include "stream.h" + static const char ident[]="$Id$"; static const char ident_z80_header[]=Z80_H; static const char ident_z80_private_header[]=Z80_PRIVATE_H; @@ -328,4 +330,67 @@ const char *Z80Disassemble(Z80 *cpu, Z80Word *pc) #endif } + +void Z80SaveSnapshot(Z80 *cpu, FILE *fp) +{ + STRPUT(fp, cpu->PC); + STRPUT(fp, cpu->AF); + STRPUT(fp, cpu->BC); + STRPUT(fp, cpu->DE); + STRPUT(fp, cpu->HL); + STRPUT(fp, cpu->AF_); + STRPUT(fp, cpu->BC_); + STRPUT(fp, cpu->DE_); + STRPUT(fp, cpu->HL_); + STRPUT(fp, cpu->IX); + STRPUT(fp, cpu->IY); + STRPUT(fp, cpu->SP); + STRPUT(fp, cpu->IFF1); + STRPUT(fp, cpu->IFF2); + STRPUT(fp, cpu->IM); + STRPUT(fp, cpu->I); + STRPUT(fp, cpu->R); + STRPUT(fp, cpu->R); + + STRPUT(fp, cpu->priv->cycle); + STRPUT(fp, cpu->priv->halt); + STRPUT(fp, cpu->priv->shift); + STRPUT(fp, cpu->priv->raise); + STRPUT(fp, cpu->priv->devbyte); + STRPUT(fp, cpu->priv->nmi); + STRPUT(fp, cpu->priv->callback); + STRPUT(fp, cpu->priv->last_cb); +} + +void Z80LoadSnapshot(Z80 *cpu, FILE *fp) +{ + STRGET(fp, cpu->PC); + STRGET(fp, cpu->AF); + STRGET(fp, cpu->BC); + STRGET(fp, cpu->DE); + STRGET(fp, cpu->HL); + STRGET(fp, cpu->AF_); + STRGET(fp, cpu->BC_); + STRGET(fp, cpu->DE_); + STRGET(fp, cpu->HL_); + STRGET(fp, cpu->IX); + STRGET(fp, cpu->IY); + STRGET(fp, cpu->SP); + STRGET(fp, cpu->IFF1); + STRGET(fp, cpu->IFF2); + STRGET(fp, cpu->IM); + STRGET(fp, cpu->I); + STRGET(fp, cpu->R); + STRGET(fp, cpu->R); + + STRGET(fp, cpu->priv->cycle); + STRGET(fp, cpu->priv->halt); + STRGET(fp, cpu->priv->shift); + STRGET(fp, cpu->priv->raise); + STRGET(fp, cpu->priv->devbyte); + STRGET(fp, cpu->priv->nmi); + STRGET(fp, cpu->priv->callback); + STRGET(fp, cpu->priv->last_cb); +} + /* END OF FILE */ diff --git a/source/zx81.c b/source/zx81.c index c0af981..a8620c3 100644 --- a/source/zx81.c +++ b/source/zx81.c @@ -31,10 +31,14 @@ #include "zx81.h" #include "gui.h" +#include "stream.h" + #include "config.h" #include "zx81_bin.h" +#include "ds81_debug.h" + #ifndef TRUE #define TRUE 1 #endif @@ -77,6 +81,9 @@ static int hires=FALSE; static int hires_dfile; static int last_I; +static unsigned prev_lk1; +static unsigned prev_lk2; + #define SCR_W 256 #define SCR_H 192 #define TXT_W 32 @@ -313,7 +320,7 @@ static FILE *OpenTapeFile(Z80Word addr, int *cancelled) if (!(fp = fopen(fn,"rb"))) { - char full_fn[FILENAME_MAX+11] = "/ZX81SNAP/"; + char full_fn[FILENAME_MAX] = DEFAULT_SNAPDIR; strcat(full_fn,fn); fp = fopen(full_fn,"rb"); @@ -603,7 +610,6 @@ static void FindHiresDFILE(void) */ static void ZX81HouseKeeping(Z80 *z80) { - static unsigned prev_lk1,prev_lk2; unsigned row; unsigned lastk1; unsigned lastk2; @@ -1073,4 +1079,34 @@ void ZX81Reconfigure(void) } +void ZX81SaveSnapshot(FILE *fp) +{ + STRPUT(fp, mem); + STRPUT(fp, matrix); + STRPUT(fp, waitkey); + STRPUT(fp, started); + STRPUT(fp, RAMBOT); + STRPUT(fp, RAMTOP); + STRPUT(fp, prev_lk1); + STRPUT(fp, prev_lk2); +} + + +void ZX81LoadSnapshot(FILE *fp) +{ + STRGET(fp, mem); + STRGET(fp, matrix); + STRGET(fp, waitkey); + STRGET(fp, started); + STRGET(fp, RAMBOT); + STRGET(fp, RAMTOP); + STRGET(fp, prev_lk1); + STRGET(fp, prev_lk2); + + /* Reset last_I to force hi/lo res detection + */ + last_I = 0; +} + + /* END OF FILE */ |