MasterDOS Hook Codes

Information from Frode Tennebø from the Sam Coupé Scrapbook

MasterDOS provides hook (command) codes which enable the machinecode programmer to use the DOS’s facilities without having to return to or call SAM BASIC.

If an error occurs, MasterDOS puts an error number into the A register; otherwise the A register will be zero.

The Hook Codes currently available are:

  • INIT 128 (80H)
      Look for an AUTO file on the current disk. Noaction (or error) occurs if there is no AUTO file, otherwise it isloaded (and executed if it is an auto-running Basic or CODEfile). This Hook can only be used in sections B and C of the memorymap.
  • HGTHD 129 (81H)
      Get file header. This routine should be calledwith IX pointing to the UIFA, which should hold the file type required(at IX+0) and the file name (at IX+1 to IX+10). The routine looks forthe file in the current directory on the current drive and eitherreturns with an error code, or transfers the data from the filedirectory entry to IX+80 dec, in UIFA form. The calling code and theUIFA can be in sections B, C or D of the memory map. (Note: this hookworks correctly in SAMDOS, provided IX=4BOOH.)
  • HLOAD 130 (82H)
      Load data from the file you have just got theheader of using HGTHD above. HL must point to the destination address,paged in between 8000H and BFFFH, i.e. in section C of the memorymap. The C register should hold the number of 16K pages in the file,and DE should hold the length MOD 16K. These values can be read fromthe header loaded by HGTHD. See also Hook 143.
  • HVERY 131 (83H)
      Like HLOAD, but verify the data on the diskagainst the data in memory. Error code 93 dec if verify failed.
  • HSAVE 132 (84H)
      Save the file whose UIFA is pointed to byIX. All relevant data in the UIFA must be complete - for a CODE file,type, name, start, length and execute address. If in doubt, try a SAVEfrom BASIC and then look at 4500H-4B47H to find the requiredvalues.
  • HSKSF 133 (85H)
      Seek Safe. On some machines, pressing the Resetbutton can corrupt the disk sector under the drive head. This is oftenon the track containing the last sector of the last fileloaded. MasterDOS tries to minimise the problem by parking the drivehead on the last track in the directory, after a LOAD or a SAVE. Thistrack will be unused unless the directory is fairly full. Using theHSKSF hook will move the head of the current drive to the last trackin the directory, unless this would be track 4 (which contains thefirst sector of DOS) in which case track 3 is used instead.
  • HAUTO 136 (88H)
      Like Hook 128, but an error code of 101 dec isreturned if there is no AUTO file.
  • HSKTD 137 (89H)
      Seek Track D. Move the drive head of thecurrent drive to the track specified in the D register.
  • HFMTK 138 (8AH)
      Format Track. Format the track under the drivehead, using the D register to supply the track number and the Eregister as the number of the first sector (1-10). Later sectors willbe numbered 1 higher till 10 is reached and numbering goes back to1. [Does not exist?]
  • HVAR 139 (8BH)
      Supply the address of a DVAR by putting it onthe floating point calculator stack. On entry, the FPCS should holdthe desired DVAR number. Note: it is probably easier to page in DOS(the DOS page is held at 5BC2H) and read the disk variablesdirectly. DVAR 0 is at an offset of 0220H within the page - this willnot change.
  • HEOF 140 (8CH)
      Supply the End-Of-File status (1 or 0) of aspecified stream. The stream number should be on the FPCS. It will bereplaced by the EOF status.
  • HPTR 141 (8DHl)
      Supply the PTR value for a specifiedstream. The stream number on the FPCS is replaced by the PTRvalue.
  • HPATH 142 (8EH)
      Supply the current PATH$ on the FPCS Use CALL0124H (JSTKFETCH) to get page (A) offset (DE) and length (BC) of thestring.
  • HLUPG 143 (8FH)
      As Hook 130, but on entry the A register shouldhold the page number of the destination address. This need not bepaged in.
  • HVEPG 144 (90H)
      As Hook 131, but on entry the A register holdsthe page to verify against.
  • HSDIR 145 (9lH)
      Select Directory. Similar to DIR=”name” inBasic. On entry, the registers hold details of the location and lengthof the desired subdirectory name. DE is the offset, A is the page ofthe name start, and BC is the name length.
  • HOFSM 146 (92H)
      Open a File Sector Map for an OPENTYPE file. IXmust point to the UIFA. The routine will create the map and clear thedisk buffer.
  • HOFLE 147 (93H)
      Open a file on the disk. IX must point to theUIFA. The routine will create a sector address map, and save a 9-byteheader to the disk buffer.
  • HSBYT 148 (94H)
      Save the byte in the A register to the diskfile (If the buffer is full it will be written to the disk and thebyte will go into the start of the next buffer.)
  • HWSAD 149 (95H)
      Write Single Sector. On entry, the A registeris the drive number (1-7) which is used to access the table at DVAR111 to get the actual drive to use. D holds the destination track, andE the sector. HL points to the source in memory, which must be insections B, C or D of the memory map. 512 bytes will be written todisk.
  • HKSB 150 (96H)
      Save a block of data to the disk file. The Aregister holds the length to save in pages, and DE holds the lengthMOD 16K. HL points to the start of the data to save, paged intosection C of the memory map.
  • HDBOP 151 (97H)
      Save BC bytes to the disk file. DE points tothe start of the data to save, paged into section C of the memorymap. Used by DOS to write strings to OPENTYPE files.
  • HCFSM 152 (98H)
      Close a file. This routine writes the lastbuffer to a disk file and creates a directory entry for it. IX shouldpoint to the UIFA.
  • HORDER 153 (99H)
      Sort list into ASCII order. HL should point tothe start of the list in sections B, C or D of the memory map. The BCregister should hold the length of each item in the list, and the DEregister the number of items. The A register specifies the number ofcharacters to sort on. No paging is performed so the entire list mustbe paged in by the user before this hook is called.
  • HGFLE 158 (9EH)
      Get a file from the disk. The IX register mustpoint to the UIFA. The return is made with the first sector of thefile loaded into the disk buffer and RPT pointing to the firstbyte.
  • HRSAD 160 (A0H)
      Read Single Sector. On entry, the A register isthe drive number (1-7) which is used to access the table at DVAR 111to get the actual drive to use. D holds the source track, and E thesector. HL points to the destination in memory, which must be insections B, C or D of the memory map. 512 bytes will be read from thedisk.
  • HLDBK 161 (A1H)
      Load a block of data from the current diskfile. HL points to the destination of the data in memory, paged intosection C of the memory map. The A register is the length to load, inpages, and DE holds the length MOD 16K.
  • HMRSAD 162 (A2H)
      Read Multiple Sectors. Equivalent to READ ATin Basic. The A register is the drive to use (1-7, using DVAR 111table), D holds the track, E the sector, C the page and HL the offset(8000H-BFFFH) of the destination. IX holds the number of sectors toload.
  • HMWSAD 163 (A3H)
      Write Multiple Sectors. Equivalent to WRITE ATin Basic. As above, but C and HL hold the source address, rather thanthe destination.
  • HREST 164 (A4H)
      Restore. Move drive head to track 0. The diskneed not be formatted.
  • HP2IR 165 (A5H)
      Print directory. If the A register holds 2,print a simple directory. If it holds 4, print a detaileddirectory. Neither option does a CLS first. The current stream is usedto output.
  • HERAZ 166 (A6H)
      ERASE a file from disk. The file name should beat IX+1 to IX+10.
  • HCHRD 168 (A8H)
      Read character from the disk file whose UIFA ispointed to by IX. The character and flags are passed out in thealternate BC register: EXX, PUSH BC, EXX, POP AF gives the characterin A, and the carry flag set if the read was OK, else we hit end offile.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.