Cassette tape based file options?

Discussion about other targets
Wysardry
Member
Posts: 10
Joined: Sun Sep 04, 2022 8:46 pm

Cassette tape based file options?

Post by Wysardry »

Does z88dk include cassette tape based file save and load options for data as standard? This would be for saving and loading game progress.

I'm especially interested in the Enterprise and Sharp MZ-700 computers, but would like the option to save and load data for multiple platforms.
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

There isn't an api to load or save tape data for all targets AFAIK. the zx and zx81 targets have target specific functionality to do this, but the mz700 doesn't it seems. According to the rom disassembly at https://original.sharpmz.org/mz-700/monirom.html there's a WTAPE entry point that can write data to tape. I'd suggest looking into invoking that.

As for the enterprise target, there's a function named exos_write_block. Maybe that will do what you need
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Cassette tape based file options?

Post by Timmy »

You might be surprised to hear that while many 8 bit systems have tapes, but there are also many that don't use them.

So a generic tape saving system is probably of little use.

The problem is also that some people are playing on emulators or disk based systems or handhelds, and none of those platforms really have tape saving support. Even disk saving is not easy.

As an example, for the 3 platforms I use the most, on the Spectrum, I usually use the emulator so tape support is a chore there. The MSX has such a great emulator with rewind options, and they usually use disks and ROMS so tape is also not an option. The Gameboy obviously don't have tape options.

Something completely different and completely irrelevant, perhaps it is time to port my text adventure (+engine) to other 8 bit systems, but I haven't explored how to do it yet. (But I'll make a different thread for that.) In my engine I just have the line "Saving and Loading from tape is not supported." and I would have no idea how to improve that.
Wysardry
Member
Posts: 10
Joined: Sun Sep 04, 2022 8:46 pm

Re: Cassette tape based file options?

Post by Wysardry »

pjshumphreys: Am I going to need to find a similar solution for every platform I want to support?


Timmy: I'm from the UK, where the majority of the early machines were sold without a disk drive. It wasn't until Amstrad released their CPC series that I even saw one in a store.

Anyone here who owns or buys a used physical machine is likely to have a tape drive or digital recorder. I've heard there are SD card or hard drive addons for some machines, but none of the machines I've seen on Ebay UK have one included.

Given that most of the software sold in the UK was also on tape, I find it surprising that emulators don't include tape based utilities, even if only for conversion purposes. I know there are some available for the Enterprise and that was never a popular computer.

Luckily, I will not need to support the Gameboy or other handhelds, as a keyboard will be needed for input (I'm also looking to create text adventures).

For your text adventure system, you might want to consider including a "ramsave" command. That became a common feature in tape based games, as saving and loading could be tiresome.
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

I think you will unfortunately. But remember, each machine with a cassette interface has code to load and save cassette data in its ROM somewhere because that's how user BASIC programs were read/written originally. There will likely be assembly entry points you can invoke that will have the memory location to read/write in the HL register and the byte length in the BC register. Or something similar to that anyway :)

You can build wrapper functions containing #ifdef directives that select what to do for each machine type at compile time.

The other, probably easier alternative is to encode the game state in a password, like it was done in the 1980s! :)
Wysardry
Member
Posts: 10
Joined: Sun Sep 04, 2022 8:46 pm

Re: Cassette tape based file options?

Post by Wysardry »

I guess it will be easier than trying to create a system that outputs code in all the different BASIC dialects at least. I'm just a little surprised that I'm the first person to need to load and save from tape on any of the less popular systems.

I'll also have to enlist the help of others to test sound files for physical machines.

Unfortunately, I'm intending to create text adventures, so the game state would change quite a lot during play. I would imagine a password would be uncomfortably large to hold all the necessary information.
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

The BASIC dialect the machine uses doesn't matter if you just want the load/save a collection of bytes. However, you would need to write some machine specific code.

If you use 32 different characters (maybe A to V and 0 to 9 only?) you can store 80 binary digits in a 16 character password. That's 80 different items the player might have or not. Maybe you could group some bits together to repesent the player location or bank balance.

You'll probably want to include some kind of checksum character as well.
Wysardry
Member
Posts: 10
Joined: Sun Sep 04, 2022 8:46 pm

Re: Cassette tape based file options?

Post by Wysardry »

What I meant was, adding code to z88dk for multiple computers would be easier than trying to create a system that could produce BASIC code to run on each of those machines.

To save a player's progress in a game you would need to store the location of every object (in case the player moved any), the current location of the player and more than a few flags (whether a door been opened, if a lamp is lit etc.). 80 bytes would probably not be enough, let alone 80 bits.
Timmy
Well known member
Posts: 392
Joined: Sat Mar 10, 2012 4:18 pm

Re: Cassette tape based file options?

Post by Timmy »

Wysardry wrote: Mon Sep 05, 2022 2:58 pm Timmy: I'm from the UK, where the majority of the early machines were sold without a disk drive. It wasn't until Amstrad released their CPC series that I even saw one in a store.
Oh, cool. I'm not from the UK, but I do own a Spectrum (and a tape deck). I also played many many text adventures on the Spectrum, on tapes, as well as in other ways.

Surprisingly, while I make a lot of games for the Spectrum (see the screenshots page on the main z88dk site), I also released a text adventure on the MSX https://www.msxdev.org/2018/10/29/msxde ... asure-day/ using z88dk.
Anyone here who owns or buys a used physical machine is likely to have a tape drive or digital recorder. I've heard there are SD card or hard drive addons for some machines, but none of the machines I've seen on Ebay UK have one included.
SD cards didn't exist back then. And hard drives were seen as very expensive, and easy-to-copy so they usually come as separate purchases.

But that's not the point. The point is that in 2022, games have to be made to cater to owners of original machines with all kinds of saving mechanisms, as well as people who play on (online or offline) emulators without any kind of saving mechanisms. It's a difficult balancing act.
Given that most of the software sold in the UK was also on tape, I find it surprising that emulators don't include tape based utilities, even if only for conversion purposes. I know there are some available for the Enterprise and that was never a popular computer.
The problem with that, is that tape loading and saving are very delicate processes. This is not something that should be done during an emulation. :)
For your text adventure system, you might want to consider including a "ramsave" command. That became a common feature in tape based games, as saving and loading could be tiresome.
I might have implemented a ramsave (and ramload) command (I have to look it up) but that wasn't very relevant in this discussion so I omitted this earlier. Thanks for the tip. :)
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

If you were able to know what memory location the ramsave was saving to, you could print instructions on how to save that block then exit the program back to the BASIC prompt. The user could then use the printed instructions to save the block to tape using BASIC. Of course, you'd have to be careful your game doesn't alter the contents of the block when it's loaded.
Wysardry
Member
Posts: 10
Joined: Sun Sep 04, 2022 8:46 pm

Re: Cassette tape based file options?

Post by Wysardry »

pjshumphreys wrote: Tue Sep 06, 2022 3:46 pm If you were able to know what memory location the ramsave was saving to, you could print instructions on how to save that block then exit the program back to the BASIC prompt...
I'm not sure it would be possible to implement that in the same way for multiple machines, as most of them load BASIC into a different area of RAM when a machine code program is exited.

Some machines don't even have BASIC on ROM. For example, with the Sharp MZ series the BASIC interpreter is loaded from tape or disk.

My gut feeling is that your earlier suggestion to use the existing firmware routines of each machine for loading and saving would be more practical.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Cassette tape based file options?

Post by stefano »

Time ago I thought at an universal SAVE routine, working with the same tricks I used for the bit banging sound routines.
The timing wouldn't have been simple to tune, though, and the LOAD in many cases would be impossible.
For those few targets already enabled with hw specific load/save, look at adv_a.c and its gamesave option
Wysardry
Member
Posts: 10
Joined: Sun Sep 04, 2022 8:46 pm

Re: Cassette tape based file options?

Post by Wysardry »

You mean the adv_a.c file in z88dk/examples/console?

Either way, that file will be useful, as I'm hoping to use z88dk to create text adventures games, albeit indirectly.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Cassette tape based file options?

Post by stefano »

Yup.
https://github.com/z88dk/z88dk/blob/910 ... _a.c#L2615

Tape_save_block gets three parameters: the data block position, the block length and a "block type" byte, which makes the loader skip the unwantend data (on those targets supporting it) and getting the first block matching the same "type byte" only.

The only targets supporting it are at the moment: ZX Spectrum, TS2068, ZX81, Jupiter ACE, S-OS
The function is target specific and in most of the cases a saved block can't be loaded by a different target computer.
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

After having briefly read though a disassembly of the MZ-700's rom, it seems that the tape_load_block and tape_save_block functions could be implemented for that target as well fairly easily, but such code obviously doesn't exist today :)
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Cassette tape based file options?

Post by stefano »

I see. A MONITOR call is not advisable, there are different versions.
https://github.com/z88dk/techdocs/blob/ ... 9.asm#L449


Better to borrow the whole routine ?
nuc1e0n
Member
Posts: 49
Joined: Wed Jun 10, 2020 12:34 am

Re: Cassette tape based file options?

Post by nuc1e0n »

It's not up to me of course and it's not something I need personally right now, although having tape_load_block and tape_save_block available for more targets would probably be useful in the long run.

However, if I were to implement these functions for the sharp machines, I wouldn't want to be the one to excerpt potentially copyrighted material. The jump block at the start of memory seems to have jumps to equivalent code at the same memory locations (memory location 0x0023?), comparing the line

Code: Select all

WRDAT:  JP      QWRD		; WRITE DATA
in the mz700 pal rom disassembly I linked to previously to the

Code: Select all

JP      SAVE2           ; File - write data to tape (cassette)
line in the mz800 rom disassembly you refer to. I'd recommend to anyone wanting to implement tape_load_block and tape_save_block for sharp machines to make calls to those jump block locations instead of excerpting the rom functions themselves or referring to the locations of the function bodies in the rom (which are likely different from one rom version to another).
nuc1e0n
Member
Posts: 49
Joined: Wed Jun 10, 2020 12:34 am

Re: Cassette tape based file options?

Post by nuc1e0n »

"JP QWRD/SAVE2" is at 0x0026
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Cassette tape based file options?

Post by stefano »

Yes, I'm trying to get a library basing on those monitor entries.
I'm not sure I'm able to test it properly, though.
Moreover, not all the existing monitors include support for cassette player, e.g. the QD one on the mz800 replaced the entries, nor I'm sure an old mz80a will run it.
Wysardry
Member
Posts: 10
Joined: Sun Sep 04, 2022 8:46 pm

Re: Cassette tape based file options?

Post by Wysardry »

I'm reasonably sure the MZ-80A had disk drives. The MZ-80B and MZ-80K had a cassette deck though.

The MZ-700 series could have either. I believe it was also available with neither, but you could use an external cassette recorder with it.
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

page 121 of the MZ-80A owners manual pdf as at https://eaw.app/Downloads/Manuals/Sharp ... Manual.pdf shows a similar jump block
on the MZ-80A as well.
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Cassette tape based file options?

Post by stefano »

yes, but different location, if I'm not wrong.
I'm also sure that at least one monitor version on the mz800 does not support the cassette tape at all,.

This means that depending on the monitor version and on the mz model the command I'm working on could not work.
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

I've OCRed the relevant part of page 121 of the MZ-80a manual:

Code: Select all

09 0000 C34A00 JP START
11 0003 C3A807 JP ?GETL
13 0006 C38009 JP ?LTNL
15 0009 C37B09 JP ?NL
17 000C C39309 JP ?PRIS
19 000F C38409 JP ?PRTT
21 0012 C39509 JP ?PRNT
23 9015 C39308 JP ?MSG
23 0018 C3A108 JP ?MSGI
27 OO1B C3B308 JP ?GET
29 OO1E C32100 JP ?BRK
31 0021 C33604 JP ?WRI
33 0024 C37004 JP ?WRD
35 0027 C3CF04 JP ?RDI
37 002A C3EF04 JP ?RDD
There's the block of code of the MZ-700 rom, starting at "org 0000h":

Code: Select all

MONIT:  JP      START		; MONITOR ON
GETL:   JP      QGETL		; GET LINE (END "CR")
LETNL:  JP      QLTNL		; NEW LINE
NL:     JP      QNL		;
PRNTS:  JP      QPRTS		; PRINT SPACE
PRNTT:  JP      QPRTT		; PRINT TAB
PRNT:   JP      QPRNT		; 1 CHARACTER PRINT
MSG:    JP      QMSG		; 1 LINE PRINT (END "0DH")
MSGX:   JP      QMSGX		; RST 18H
GETKY:  JP      QGET		; GET KEY
BRKEY:  JP      QBRK		; GET BREAK
WRINF:  JP      QWRI		; WRITE INFORMATION
WRDAT:  JP      QWRD		; WRITE DATA
RDINF:  JP      QRDI		; READ INFORMATION
RDDAT:  JP      QRDD		; READ DATA
and the block of code starting at "org 0000h" of https://github.com/z88dk/techdocs/blob/ ... Z5Z009.asm:

Code: Select all

        JP      STARTP          ; Monitor / Basic  -  Home entry
        JP      GETL            ; Get line from keyboard to memory (DE).
        JP      CR1             ; Output newline to screen
        JP      CR2             ; Line feed when cursor is not at beginning of line
        JP      CRT1S           ; print a space on the screen
        JP      PRNTT           ; Move cursor to next tab position
        JP      CRT1C           ; Display accu on screen (execution of control characters)
        JP      CRTMSG          ; Output text (DE) on screen (execution of control characters)
        JP      IOSVC           ; Software - execute command (RST _DOCMD: RST3 supervisor call entry)
        JP      INKEY0          ; Query whether key is pressed
BRKCHK: JP      BRKEY           ; Query whether (Shift) - BREAK is pressed
        JP      SAVE1           ; File - write identifier on tape (cassette)
        JP      SAVE2           ; File - write data to tape (cassette)
        JP      LOAD1           ; Read file identifier from tape (cassette)
        JP      LOAD2           ; File - read data from tape (cassette)
The tape loading and saving jp locations are the same for all 3 of these machines, but the locations that these instructions jump to are different
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Re: Cassette tape based file options?

Post by stefano »

Tanks, at the moment I'm focusing on the mz700, I hope to need your help for testing soon
pjshumphreys
Member
Posts: 66
Joined: Sat Feb 06, 2021 2:32 pm

Re: Cassette tape based file options?

Post by pjshumphreys »

I don't have any physical Sharp machines myself right now, but I'll help by testing with a bunch of different emulators to begin with. I might also be able to temporarily access some real machines to test with.
Post Reply