1

Topic: dot commands and interrupts

Hi there,

I've just been adding an esxdos interface to z88dk for the zx spectrum and zx next targets.  The toolchain will allow the generation of standard programs or dot commands from C and asm source.

I have a question about dot commands and interrupts.  I have an old email from a few years back that mentions whenever a dot command is active, im1 interrupts will only hit an ei/reti inside esxdos.  I also read a few things here and there about im2 mode loading.

Normally in an environment that must cooperate with basic, z88dk will disable interrupts.  This is because the compiler / library will use the iy register which is incompatible with basic's isr.  Do I have to worry about dot commands and interrupts making iy unavailable if I leave interrupts enabled?  Am I allowed to disable interrupts while a dot command runs?

2

Re: dot commands and interrupts

Hi,

When a dot command is running, divIDE/MMC is paged in so an interrupt will just return as you say. esxDOS syscalls do use IY but it is pushed and popped when exiting.

IM2 loading works from BASIC and from machine code (not from .TAP files for now), but the IM2 routine must be set to normal Speccy RAM.

3 (edited by Alcoholics Anonymous 2017-07-31 20:23:07)

Re: dot commands and interrupts

lordcoxis wrote:

When a dot command is running, divIDE/MMC is paged in so an interrupt will just return as you say. esxDOS syscalls do use IY but it is pushed and popped when exiting.

Awesome, I should have realized esxdos would preserve iy since it too has to play well with basic.  I've been saving iy around esxdos calls and that has been cluttering up the c interface a little bit.

IM2 loading works from BASIC and from machine code (not from .TAP files for now), but the IM2 routine must be set to normal Speccy RAM.

ok.  Normal operation is not to do im2 loading correct?  If im2 loading is enabled, is there any information on what areas of ram are reserved by esxdos?  Or is it up to the user to set up the im2 table and routine?  I actually have no real information on it.  Besides doing regular dot commands, I'd like to look at extended dot commands that can make use of ram above ramtop and I wouldn't want to run into anything by accident.

I have a list of esxdos defines that I'm using in the api implementation:
https://github.com/z88dk/z88dk/blob/mas … _esxdos.m4

And the asm implementation of the api:
https://github.com/z88dk/z88dk/tree/mas … esxdos/z80

If you have spare time and feel like having a look, would you mind doing a quick scan of the defines in particular to see if there is something obviously wrong?

4

Re: dot commands and interrupts

First successful dot command compiled from C and emulated in ZEsarUx:
https://drive.google.com/file/d/0B6XhJJ … sp=sharing

.bmp2next zxnext.bmp zx-new.bmp

converts a 256-colour bmp image of arbitrary size to a 256-colour bmp using the Spectrum Next's RRRGGGBB palette.

I clearly have some of the mode bits for file open wrong.

Here is what I am using now:

# File Access Mode

define(`__ESXDOS_MODE_READ', 0x01)            # read access
define(`__ESXDOS_MODE_WRITE', 0x02)           # write access
define(`__ESXDOS_MODE_OPEN_EXIST', 0x00)      # open if exists else error
define(`__ESXDOS_MODE_OPEN_CREAT', 0x08)      # open if exists else create
define(`__ESXDOS_MODE_CREAT_NOEXIST', 0x04)   # create if no exist
define(`__ESXDOS_MODE_CREAT_TRUNC', 0x0c)     # create and/or truncate
define(`__ESXDOS_MODE_USE_HEADER', 0x40)      # use +3DOS header passed in DE

I'm hoping you can correct / add info about the file open mode flags.

Thanks!

5

Re: dot commands and interrupts

Hi,

That should be right (for 0.8.x at least). Which bits do you suspect are wrong?

6

Re: dot commands and interrupts

lordcoxis wrote:

That should be right (for 0.8.x at least). Which bits do you suspect are wrong?

There's some confusion about what the bits are doing.  Some emulator authors are using at least one of the modes to open files for append writes, which I seem to recall esxdos doesn't do.  (I don't have real hardware so I have to test under emulation).

For example, I opened a file with flags "ESXDOS_MODE_W | ESXDOS_MODE_OC" (0x0a) and the emulation caused all writes to append to an existing file.

Maybe this can be sorted out if a description of the mode bits can be spelled out:

# File Access Mode

There is one file pointer shared by read and write

define(`__ESXDOS_MODE_READ', 0x01)            # read access
define(`__ESXDOS_MODE_WRITE', 0x02)           # write access

define(`__ESXDOS_MODE_OPEN_EXIST', 0x00)
Open if the file exists else return an error.
The file pointer points at the beginning of the file.
Writes will overwrite file contents as the fp moves forward.

define(`__ESXDOS_MODE_OPEN_CREAT', 0x08)
Open if the file exists else create a new file.
The file pointer points at the beginning of the file.
Writes will overwrite file contents as the fp moves forward.

define(`__ESXDOS_MODE_CREAT_NOEXIST', 0x04)
If the file exists return error else create a new file.

define(`__ESXDOS_MODE_CREAT_TRUNC', 0x0c)
Create a new file or empty an existing one.

define(`__ESXDOS_MODE_USE_HEADER', 0x40)      # use +3DOS header passed in DE


Also I want to confirm that files opened with both RW mode enabled is allowed.  They share the same file pointer so that you can alternate reads/writes and seek through the file.  The emulators are not allowing this.

In the bmp2next.c dot command in the zip I linked, I'm doing this for the case where bmp2next is not given an output filename as in ".bmp2next zxnext.bmp".  In this case the file "zxnext.bmp" is opened in RW mode so that it can be modified in place.  The program reads X bytes into a buffer, operates on it, seeks backward by X bytes and then writes X bytes.  This repeats until the entire file has been processed.

7

Re: dot commands and interrupts

Hi,

Your description is indeed correct. There is no append mode and r/w is of course supported (.TAP emulator uses it for instance). If you are using one of these emulators that trap rst $08 calls then that's probably the issue...

8

Re: dot commands and interrupts

Cheers lordcoxis.  I'm pretty sure I have things right now.  Hopefully the emulators will catch up soon.

9

Re: dot commands and interrupts

Another question about the system drive, drive '$'.

I'm adding a way to create extended dot commands which will be a dot command that has one part at 0x2000 and the other part loaded above ramtop in main ram.  The second part's binary will also reside in the BIN directory, so an extended dot command would have two files "FOO" ad "FOO.DTX" in the BIN directory.  FOO will check ramtop to ensure there is space and then load FOO.DTX into main ram before starting.  (Can FOO.DTX be accidentally loaded via dot command as in ".foo.dtx"?  I'm assuming it can't otherwise I may have to add an error at its start).

To load FOO.DTX into main memory, I want to open the file using drive $ which I assume is for finding the BIN directory.  The question is what's the base path for drive $?  Is it just the root directory so that I would have to open file BIN/FOO.DTX or is it inside BIN so that I would just open FOO.DTX?

This is something the emulators won't know about too.

10

Re: dot commands and interrupts

Hi,

Drive '$' just points to the drive here the system files reside. So you need to open /BIN/FOO.DTX. I don't actually remember but I think if you type .foo.dtx it will try to load it yes (I'm working on v0.9.x right now, where it's different). The music tracker players by gasman (playstc, playpt3 and playsqt) do try to allocate memory from main RAM to load the musics (if needed), and return Out of Memory error if they fail.

11

Re: dot commands and interrupts

lordcoxis wrote:

\
Drive '$' just points to the drive here the system files reside. So you need to open /BIN/FOO.DTX. I don't actually remember but I think if you type .foo.dtx it will try to load it yes (I'm working on v0.9.x right now, where it's different). The music tracker players by gasman (playstc, playpt3 and playsqt) do try to allocate memory from main RAM to load the musics (if needed), and return Out of Memory error if they fail.

Yep, thanks I have it working.

What I'm doing is checking RAMTOP when the 0x2000 portion is loaded and if RAMTOP is too high, it exits with "M RAMTOP no good (nnnnn)" where n = is the max RAMTOP value required by the program.  So if that error comes up, the user is expected to "CLEAR n-1" and restart the dot command.

I have a few test programs here:
https://drive.google.com/file/d/0B6XhJJ … sp=sharing

dzx7 is the zx7 command line decompressor rewritten as a dot command.  This one reserves memory in the main bank for an output buffer as the file is decompressed.  It does the RAMTOP thing.

nextgrab is a sprite/tile grabber from bitmaps for the zx next originally written by Jim Bagley for PCs.  I can't test this on emulators but I think it works.  Again, buffers are allocated in main memory and RAMTOP is enforced.  In this program a window on the input bitmap file is kept in memory and loaded on demand from disk.  I think I'll refine this idea so that it can be generally used and better applied.

I do have extended dot commands compiling too.  This splits the executable across 0x2000 and main memory with RAMTOP check.  I may extend this to do 16k bankswitched banks.  I don't have an example yet but I think a version of zx7 for esxdos will need it and if not maybe I will do a sudoku solver in dot command form to act as an example.