diff options
author | Ian C <ianc@noddybox.co.uk> | 2008-12-12 00:19:08 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2008-12-12 00:19:08 +0000 |
commit | 3cf17ecef2ac48e92910ac971fec9ea5b3eeb1d3 (patch) | |
tree | b22b3ac08fa108630f85f8a3c8f330366272a4ed /source/zx81.c | |
parent | 9ebec735c488e2f7ac29933fb51b4e6e65c7b93f (diff) |
Implemented snapshots and SAVE.
Diffstat (limited to 'source/zx81.c')
-rw-r--r-- | source/zx81.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/source/zx81.c b/source/zx81.c index 00d6015..b8143cd 100644 --- a/source/zx81.c +++ b/source/zx81.c @@ -62,6 +62,7 @@ #define SLOW_TSTATES 16000 #define FAST_TSTATES 64000 +#define E_LINE 16404 #define LASTK1 16421 #define LASTK2 16422 #define MARGIN 16424 @@ -103,6 +104,7 @@ static Z80Word RAMTOP=0; /* Tape */ static int enable_filesystem; +static int allow_save; static const Z80Byte *tape_image; static int tape_len; @@ -254,12 +256,13 @@ static Z80Byte FromASCII(char c) /* Open a tape file the passed address */ -static FILE *OpenTapeFile(Z80Word addr, int *cancelled) +static FILE *OpenTapeFile(Z80Word addr, int *cancelled, const char *mode) { static const char zx_chars[] = "\"#$:?()><=+-*/;,." "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; FILE *fp; + char full_fn[FILENAME_MAX] = DEFAULT_SNAPDIR; char fn[FILENAME_MAX]; int f; int done; @@ -291,7 +294,7 @@ static FILE *OpenTapeFile(Z80Word addr, int *cancelled) { if (GUI_FileSelect(last_dir,fn,".P")) { - fp = fopen(fn,"rb"); + fp = fopen(fn, mode); } else { @@ -306,12 +309,11 @@ static FILE *OpenTapeFile(Z80Word addr, int *cancelled) fn[f++] = 'P'; fn[f] = 0; - if (!(fp = fopen(fn,"rb"))) - { - char full_fn[FILENAME_MAX] = DEFAULT_SNAPDIR; + strcat(full_fn,fn); - strcat(full_fn,fn); - fp = fopen(full_fn,"rb"); + if (!(fp = fopen(full_fn, mode))) + { + fp = fopen(fn, mode); } } @@ -339,6 +341,21 @@ static void LoadExternalTape(FILE *tape, Z80 *z80) } +static void SaveExternalTape(FILE *tape, Z80 *z80) +{ + int f; + int end; + + f = 0x4009; + end = WORD(E_LINE); + + while(f <= end) + { + fputc(mem[f++], tape); + } +} + + static void ClearBitmap(void) { uint16 *s; @@ -744,6 +761,17 @@ static int EDCallback(Z80 *z80, Z80Val data) switch((Z80Byte)data) { case ED_SAVE: + if (allow_save && z80->DE.w<0x8000) + { + FILE *fp; + int cancel; + + if ((fp=OpenTapeFile(z80->HL.w, &cancel, "wb"))) + { + SaveExternalTape(fp,z80); + fclose(fp); + } + } break; case ED_LOAD: @@ -757,7 +785,7 @@ static int EDCallback(Z80 *z80, Z80Val data) FILE *fp; int cancel; - if ((fp=OpenTapeFile(z80->DE.w,&cancel))) + if ((fp=OpenTapeFile(z80->DE.w, &cancel, "rb"))) { LoadExternalTape(fp,z80); fclose(fp); @@ -1068,6 +1096,8 @@ void ZX81Reconfigure(void) RAMBOT = 0x4000; memcpy(mem+ROMLEN,mem,ROMLEN); } + + allow_save = enable_filesystem && DS81_Config[DS81_ALLOW_TAPE_SAVE]; } |