CODINGDDI-1 Firmware: The Complete CPC 464 DISC Operating System ROM Specification

DDI-1 Firmware: Chapter 3. AMSDOS (2/3)
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

Chapter 3 - AMSDOS

3.5 Intercepted Cassette Firmware Routines

When AMSDOS is initialized it copies the relevant cassette jumpblock entries into its own data area. When DISC is selected the cassette jumpblock entries are overwritten by AMSDOS entries, when TAPE is selected the original cassette entries are restored.

Initially the disc routines are selected.

In order to intercept the jumpblock entries the following procedure should be observed: copy the three bytes from the required jumpblock entry into your own data area - do not make any assumption as to what these three bytes are. Replace the jumpblock entry with your own JMP, RST or whatever. When you receive control restore the jumpblock entry, and CALL it. When you receive control once again save the jumpblock entry and replace it with your own. This procedure will work no matter what the jumpblock entry contains.

Note: when intercepting AMSDOS routines the above procedure must be followed, merely executing a copy of the jumpblock entry will not work, it must be restored to its original place in the jumpblock.

So far as it is possible the AMSDOS routines all have the same interface as their cassette counterparts, although in some cases the interpretation of the return parameters is different. Errors which are detected by both the cassette and disc routines are returned carry false, zero false. Errors which are only detected by the disc routines are returned carry false, zero true. This latter case corresponds to the cassette routine BREAK condition. In both cases register A contains an error number.

When a routine fails (carry false) it returns a six bit error number in the A register. Bit 6 is zero and bit 7 is one if the error has already been reported to the user. The error numbers are as follows:

  • #0E the file is not open as expected.
  • #0F hard end of file.
  • #1A soft end of file.
  • #20 bad command, usually caused by an incorrect filenan
  • #21 file already exists.
  • #22 file doesn't exist.
  • #23 directory is full.
  • #24 disc is full.
  • #25 disc has been changed with files open on it.
  • #26 file is read-only.

Errors detected by the floppy disc controller are reported as a bit significant value between #40..#7F, i.e. bit 6 is always one and bit 7 is zero. The other bits are returned as follows:

  • bit 5 data error - CRC error on data or ID field,
  • bit 4 overrun error.
  • bit 3 drive not ready -there is no disc in the drive,
  • bit 2 no data -can't find the sector,
  • bit1 not writable -disc is write protected.
  • bit0 address mark missing.

On the following pages are the interfaces to the intercepted routines:

125 CAS IN OPEN (DISC)#BC77

Open a file for input.

Action:

  • Set up the read stream for reading a file and read the header if there is one, otherwise create a fake header in store.

Entry conditions:

  • B contains the length of the filename.
  • HL contains the address of the filename.
  • DE contains the address of a 2K buffer to use.

Exit conditions:

If the file was opened OK:

  • Carry true.
  • Zero false.
  • HL contains the address of a buffer containing the file header.
  • DE contains the data location (from the header).
  • BC contains the logical file length (from the header).
  • A contains the file type (from the header).

If the stream is already open:

  • Carry false.
  • Zero false.
  • A = error number, #0E.
  • BC, DE and HL corrupt.

If the open failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.
  • BC, DE and HL corrupt.

Always:

  • IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • The 2K buffer (2048 bytes) supplied is used to store the contents of the file when it is read from disc. It will remain in use until the file is closed by calling either CAS IN CLOSE or CAS IN ABANDON. The buffer may lie anywhere in memory, even underneath a ROM.
  • The filename must conform to the AMSDOS conventions with no wild cards. The filename may lie anywhere in RAM, even underneath a ROM.
  • If the type part of the filename is omitted AMSDOS will attempt to open, in turn, a file with the following type parts BAS', BIN', If none of these exist then the open will fail.
  • When the file is opened the first record of the file is read immediately. If this record contains a header then it is copied into store, otherwise a fake header is constructed in store. The address of the area where the header is stored is passed back to the user so that information can be extracted from it. This area will lie in the central 32K of RAM. The user is not allowed to write to the header, only to read from it. AMSDOS uses some fields in the header for its own purposes and so these may differ from those read from the disc. The file type, logical length, entry point and all user fields will remain unchanged.
126 CAS IN CLOSE (DISC)#BC7AClose the input file properly.

Action:

  • Mark the read stream as closed.

Entry conditions:

  • No conditions.

Exit conditions:

If the stream was closed OK:

  • Carry true.
  • Zero false.
  • A corrupt.

If the stream is not open:

  • Carry false.
  • Zero false.
  • A = error number, #0E.

If the close failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.

Always:

  • BC, DE, HL and other flags corrupt.
  • All other registers preserved.

Notes:

  • This routine should be called to close a file after reading from it using either CAS IN CHAR or CAS IN DIRECT.
  • The user may reclaim the buffer passed to CAS IN OPEN after calling this routine.
  • The drive motor is turned off immediately after the input file is closed. This is done so that a loaded program which takes over the machine is not left with the motor running indefinitely.
127 CAS IN ABANDON (DISC)#BC7D

Close the input file immediately.

Action:

  • Abandon reading from the read stream and close it.

Entry conditions:

  • No conditions.

Exit conditions:

  • AF, BC, DE and HL corrupt.
  • All other registers preserved.

Notes:

  • This routine is intended for use after an error or in similar circumstances.
  • The user may reclaim the buffer passed to CAS IN OPEN after calling this routine.
128 CAS IN CHAR (DISC)#BC80

Read a character from the input file.

Action:

  • Read a character from the input stream.

Entry conditions:

  • No conditions.

Exit conditions:

If the character was read OK:

  • Carry true.
  • Zero false.
  • A contains the character read from the file.

If the end of the file was found, or stream not open as expected:

  • Carry false.
  • Zero false.
  • A = error number, #0E, #0F, #1A.

If failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.

Always:

  • IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • Once the first character has been read from a file the rest of the file may only be read character by character (using CAS IN CHAR). It is not possible to switch to direct reading (by CAS IN DIRECT).
  • The CP/M end of file character is treated as end of file (carry false, zero false), however, it is possible to continue reading characters until the hard end of file. A is set to #1A for the CP/M end of file and # OF for hard end of file.
  • This action of spotting #1A is not performed by the equivalent cassette routine. It is necessary in order to deal with CP/M files generated by other programs. Thus special action will be required if the file is known to contain binary data, viz soft eof must be ignored. The version 1.0 cassette routine CAS IN CHAR never returns the value # 1A when carry is false.
129 CAS IN DIRECT (DISC)#BC83Read the input file into store.

Action:

  • Read the input file directly into store in one go rather than one character at a time.

Entry conditions:

  • HL contains the address to put the file (anywhere in RAM).

Exit conditions:

If the file was read OK:

  • Carry true.
  • Zero false.
  • HL contains the entry address (from the header).
  • A corrupt.

If the stream is not open as expected:

  • Carry false.
  • Zero false.
  • A = error number, #0E.
  • HL corrupt.

If the read failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.
  • HL corrupt.

Always:

  • BC, DE, IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • The read stream must be newly opened (by CAS IN OPEN). If the stream has been used for character access (by calling CAS IN CHAR or CAS TEST EOF) then it is not possible to directly read the file. Neither is it possible to directly read from the file more than once. (Any attempt to do so will corrupt the copy of the file read.)
  • If the file has a header then the number of bytes read is that recorded in the 24 bit file length field (bytes 64. .66 of the disc file header). If there is no header the file is read until hard end of file.
  • The CP/M end of file character, #1A, is not treated as end of file.
130 CAS RETURN (DISC)#BC86Put the last character read back.

Action:

  • Put the last character read by CAS IN CHAR back into the read buffer. The character will be re-read next time CAS IN CHAR is called.

Entry conditions:

  • No conditions.

Exit conditions:

  • All registers and flags preserved.

Notes:

  • It is only possible to use this routine to return the last character that has been read by CAS IN CHAR. At least one character must have been read since:
    the stream was opened
    or the last character was returned
    or the last test for the end of file was made.
131 CAS TEST EOF (DISC)#BC89Have we reached the end of the input file yet?

Action:

  • Test if the end of the input file has been reached.

Entry conditions:

  • No conditions.

Exit conditions:

If the end of the file was not found:

  • Carry true.
  • Zero false.
  • A corrupt.

If the end of the file was found or stream not open as expected:

  • Carry false.
  • Zero false.
  • A = error number. #0E, #0F, #1A.

If failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.

Always:

  • IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • This routine will report end of file if either there are no more characters in the file or if the next character to be read is the CP/M end of file character, # 1 A.
  • Calling this routine puts the stream into character input mode. It is not possible to use direct reading after calling this routine.
  • It is not possible to call CAS RETURN after this routine has been called. A character must be read first.
132 CAS OUT OPEN (DISC)#BC8COpen a file for output.

Action:

  • Set up the write stream for output.

Entry conditions:

  • B contains the length of the filename.
  • HL contains the address of the filename.
  • DE contains the address of a 2K buffer to use.

Exit conditions:

If the file was opened OK:

  • Carry true.
  • Zero false.
  • HL contains the address of a buffer containing the header.
  • A corrupt.

If the stream is open already:

  • Carry false.
  • Zero false.
  • A = error number, #0E.
  • HL corrupt.

If the open failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.
  • HL corrupt.

Always:

  • BC, DE, IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • When characters are output to the file using CAS OUT CHAR the 2K buffer supplied is used by AMSDOS to buffer the output. It will remain in use until the file is closed by calling either CAS OUT CLOSE or CAS OUT ABANDON. The buffer may reside anywhere in memory - even underneath a ROM.
133 CAS OUT CLOSE (DISC)#BC8F

Close the output file properly.

Action:

  • Mark the write stream as closed and give it its correct name.

Entry conditions:

  • No conditions.

Exit conditions:

If the stream was closed OK:

  • Carry true.
  • Zero false.
  • A corrupt.

If the stream is not open:

  • Carry false.
  • Zero false.
  • A = error number, #0E.

If the close failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.

Always:

  • BC, DE, HL, IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • It is necessary to call this routine after using CAS OUT CHAR or CAS OUT DIRECT to ensure that all the data is written to the disc, to write the header to the start of the file and to give the file its true name.
  • If no data has been written to the file then it is abandoned and nothing is written to disc. This is for compatability with cassette routines.

When the file was opened it was given the type part of ‘. $$$'. This routine will rename the file to its true name and rename any existing version to have a ‘. B A K' type part. This ensures that any previous version of the file is automatically kept as a backup. Any existing ‘. BAK' version is deleted. If, when the file was opened, the caller did not specify a type part then AMSDOS will use the type part ‘. B A S ' for BASIC files, ‘. BIN' for binary files and ‘. 'for any other, as specified by the file type field in the header.

If the actual length of the file is not a multiple of 128 bytes (a CP/M record) then a CP/M end of file character, # 1A, is added to the file. This additional character is not recorded in the length of the file.

If writing is to be abandoned then CAS OUT ABANDON should be called as this does not write any more data to disc.

The user may reclaim the buffer passed to CAS OUT OPEN after calling this routine.

134 CAS OUT ABANDON (DISC)#BC92Close the output file immediately.

Action:

  • Abandon the output file and mark the write stream closed. Any unwritten data is discarded and not written to disc.

Entry conditions:

No conditions.

  • Exit conditions:
  • AF, BC, DE and HL corrupt.
  • All other registers preserved.

Notes:

  • This routine is intended for use after an error or in similar circumstances.
  • If more than one 16K physical extent has already been written to disc then the file will appear in the disc directory with a type part of ‘. $ $ $'. Otherwise the file will disappear. This is because each 16K of a file requires a directory entry. A directory entry is not written to disc until the 16K has been written or the file is closed (CAS OUT CLOSE).
135 CAS OUT CHAR (DISC)#BC95Write a character to the output file.

Action:

  • Add a character to the buffer for the write stream. If the buffer is already full then it is written to disc before the new character is inserted.

Entry conditions:

  • A contains the character to write.

Exit conditions:

If the character was written OK:

  • Carry true.
  • Zero false.
  • A corrupt.

If the stream is not open as expected:

  • Carry false.
  • Zero false.
  • A = error number, #0E.

If failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.

Always:

  • IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • It is necessary to call CAS OUT CLOSE after sending all the characters to the file to ensure that the file is correctly written to disc.
  • Once this routine has been called it is not possible to switch to directly writing the file (CAS OUT DIRECT).
136 CAS OUT DIRECT (DISC)#BC98

Write the output file directly from store.

Action:

Write the contents of store directly out to the output file.

Entry conditions:

  • HL contains the address of the data to write (to go into the header).
  • DE contains the length of the data to write (to go into the header).
  • BC contains the entry address (to go into the header).
  • A contains the file type (to go into the header).

Exit conditions:

If the file was written OK:

  • Carry true.
  • Zero false.
  • A corrupt.

If the stream is not open as expected:

  • Carry false.
  • Zero false.
  • A = error number, #0E.

If failed for any other reason:

  • Carry false.
  • Zero true.
  • A = error number.

Always:

  • BC, DE, HL, IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • After writing the file it must be closed using CAS OUT CLOSE to ensure that the file is written to disc.
  • It is not possible to change the method for writing files from character output (using CAS OUT CHAR) to direct output (using CAS OUT DIRECT) or vice versa once the method has been chosen. Nor is it possible to directly write a file in two or more parts by calling CAS OUT DIRECT more than once - this will write corrupt data.
137 CAS CATALOG (DISC) #BC9B

Display the disc directory.

Action:

  • Display the disc directory for the current drive and current user. The directory is sorted into alphabetical order and displayed in as many columns as will fit in the current text window (stream #0). The size in Kbytes is shown along side each file. The total amount of free space on the disc is also shown.

Entry conditions:

  • DE contains the address of a 2K buffer to use.

Exit conditions:

If the cataloging went OK:

  • Carry true.
  • Zero false.
  • A corrupt.

If failed for any reason:

  • Carry false.
  • Zero true.
  • A = error number.

Always:

  • BC, DE, HL, IX and other flags corrupt.
  • All other registers preserved.

Notes:

  • Files marked SYS are not shown.
  • Files marked R/O are shown with a ‘ ' after the file name.
  • Unlike the cassette version of this routine, the disc/cassette input stream is not required. (Note: BASIC abandons both the input and output streams when CATaloging.)

★ AUTHOR: Paul OVERELL
★ NOTE: RÉF SOFT158A

Page précédente : DDDI-1 Firmware: Chapter 3. AMSDOS (1/3)
Je participe au site:

» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop
Page créée en 850 millisecondes et consultée 346 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.