Load data from tape

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
w00tguy
New member
Posts: 9
Joined: Thu Aug 24, 2017 11:38 pm

Load data from tape

Post by w00tguy »

There is a function for this in the spectrum library (tape_load_block), but I can't get it to do anything. Maybe I'm using it improperly or not using the right compiler flags?

This is the program, compiled with +zx -clib=sdcc_iy:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <spectrum.h>

void main(void)
{
        tape_load_block(0x7000, 1, 0xff);
        printf("Data loaded from tape?\n");
        while(1); // wait for me to check the memory
}
At first this wouldn't compile (symbol '_tape_load_block_callee' not defined), so I've just copied the asm files into my project for now. It looks like the tape loading function is only defined in the classic library, but I need to use sdcc_iy in order to arrange segments (my previous thread).

Anyway, the tape is cued up to read the test data when the program starts:

Image

but nothing happens after it runs. The tape browser still points to the header and nothing was copied to 0xB000. The TEST block was created with appmake +zx -b test.bin --org 0xB000 -o test.tap --noloader --blockname TEST

I tried to learn from an example (console/adv_a.c uses tape_load_block), but it doesn't compile. The readme says to use zcc +[machine] [file.c] but using zcc +zx adv_a.c results in:

Code: Select all

Error at file '/tmp/tmpXXZaDYLM.asm' line 49: symbol 'close' not defined
Error at file '/tmp/tmpXXy8kdo9.asm' line 79: symbol 'writebyte' not defined
2 errors occurred during assembly
w00tguy
New member
Posts: 9
Joined: Thu Aug 24, 2017 11:38 pm

Post by w00tguy »

Edit:
Wrong arguments used in the above post. Should be:
tape_load_block(0xB000, 23, 1);
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

For classic compiles you have to add "-lndos" to the compile line (ndos = no dos, just a bunch of stubs put in to fill the disk spot in classic's stdio). This is why you're getting close and writebyte not defined.

The tape functions are not in the newlib as you've discovered but I will look into adding them tonight.
w00tguy
New member
Posts: 9
Joined: Thu Aug 24, 2017 11:38 pm

Post by w00tguy »

That'd be great, thanks!

The example compiles with -lndos and I can see how this is supposed to work now (wasn't sure I was even using the emulator correctly).
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

It's in the newlib now for the +zx and +zxn targets but it won't be available via nightly until the August 31 build.
https://github.com/z88dk/z88dk/blob/mas ... h/zx.h#L59

If you are using git you can rebuild the newlib by running "Winmake zx zxn" or "make TARGET=zx" and "make TARGET=zxn" from z88dk/libsrc/_DEVELOPMENT after updating the source code.

I may add aliases to keep the same function names as classic but at the moment the functions are "zx_tape_load", "zx_tape_save" and "zx_tape_verify". The implementation is also improved :- border colour as set by zx_border will be preserved, handling of errors is done without resorting to using the system variables (still compatible with divmmc trapping), and the proper ei/di state is preserved. So if you have interrupts disabled before the tape access, you will have interrupts disabled after the tape access.

Code: Select all

#include <arch/zx.h>

void main(void)
{
        zx_border(INK_RED);
        zx_tape_save(0, 0x1000, ZXT_TYPE_DATA);
        zx_border(INK_GREEN);
        zx_tape_load((void*)50000, 3737, ZXT_TYPE_DATA);
}
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Oh yeah, the functions will return 0 if they were successful.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Changed names to zx_tape_load_block, zx_tape_save_block, zx_tape_verify_block before the first build. They do not perform an entire load/save operation which involves looking at tape header and the tape data but they only load/save a raw block from tape.

Code: Select all

#include <arch/zx.h>

void main(void)
{
    zx_border(INK_RED);
    zx_tape_save_block(0, 0x1000, ZXT_TYPE_DATA);
    zx_border(INK_GREEN);
    zx_tape_load_block((void*)50000, 3737, ZXT_TYPE_DATA);
}
w00tguy
New member
Posts: 9
Joined: Thu Aug 24, 2017 11:38 pm

Post by w00tguy »

Good stuff. It works as expected. :)
Post Reply