LKDOS Machine Language CALLs Explained

See all articles from Sinc-Link v10 n5
Author(s): Steve Gunhouse
Publication: Sinc-Link
Pub Details: Sinc-Link v10 n5 (Volume 10, Issue 5)
Date: September/October 1992
Pages: 15-16

Several years ago (see the Sept. ’89 issue), I sent in a list of routines I had discovered by examining my LKDOS cartridge ROM (at that time, version A2). No real explanations were included, an unfortunate oversight on my part. Last year at about this time, I wrote a new version of Grafix24 and Autoboot, and included some additional details on a few of the routines I had listed earlier.

Below is a table of the routines mentioned in that article with explanations. While I am working from LKDOS for the AERCO disk i/f, most of these will be appropriate to any version of LKDOS. Any differences between different versions that I am aware of will be mentioned in the descriptions.

One addition to the memory map from that article. Location 200F hex (8207 decimal) is a sequential file open flag. It is 0 if there is no file open, 40h (64) if there is a file open for reading (by PRINT #4: OPEN #n,”filename IN”), and 80h (128) if there is a file open for writing. Code which intends to access the disk using LKDOS ROM routines should test this byte to see if they can safely access the disk.

Routines accessible without the cartridge enabled:

0062h 98 This address is used by ml to access the cartridge.

0064 100 This is one method to access LKDOS BASIC commands.

0066 102 the address used by any NMI.

006A 106 used by LKDOS channels except “dd”. The calling channel is identified by the D register. Set D=0 to D=2 for LKDOS windows w0 to w2, D=3 for “lp”, and D=4 or D=5 for file OUT and IN respectively.

006C 108 used by LKDOS channel “dd” (as in PRINT #4)

006E 110 LKDOS PEEK command. See LKDOS manual.

Other LKDOS routines:

0078h 120 write track. Copies data from 2070h-346Fh to current drive and track.

007B 123 read track. Copies data from current drive and track to 2070h-346Fh.

007E 126 seek track. Enables the current drive and steps to the track number stored at 201Dh (8221).

0081 129 next track. Step to the next numbered track on disk. Note: on AERCO cartridge, does not enable drive!

0084 132 Find name in directory. Expects name to be stored at 2022h. Generates error T if can’t read track, sets 2020h (8224) to 0Ah (10) if name is not found in directory, otherwise sets 2031h to point to entry.

0087 135 Copy directory entry to 203Ah (8250). Presumes 2031h points to directory entry. (see previous routine and 00A2)

008A 138 Pop string and check as valid filename. Reads value from BASIC, copies it to 2022h, and checks for “.A”, “.B”, or “.C” in string. Error F otherwise.

008D 141 Find BASIC terminator. Adjusts machine language variable CH_ADD to point to the end of the current BASIC statement (: or ENTER).

0090 144 Evaluate unsigned integer. Reads value from BASIC, and converts it to an integer in the BC register. Standard errors if too big or not a number.

0093 147 Error message: T File Not Found. Displays error message and quits.

0096 150 Test Write Protect. Check to see if disk is write-protected. Notes: on A2, destroys data in 2070h-346Fh by reading track 0. On A3, moves drive to track 0 but does not read track.

0099 153 De-allocate file and find free tracks. Removes tracks from current directory entry (as copied to 203Ah by routine 0087 above) and adds list of free tracks at end of entry. Used for ERASE and before SAVE.

009C 156 Evaluate String. Evaluate BASIC value and copy it to 2022h (8226). Does not check it as a filename. Error if not a string.

009F 159 Call a routine in Home ROM. Expects two addresses, HL to contain address in 2068 ROM, DE corresponding address in Spectrum ROM. Tests CHANS to determine which address to use.

00A2 162 Add name to directory. Expects you to have used 0084h and not found name. Creates directory entry for name at 2022h, and sets 2031h to it. Error U if directory full.

00A5 165 Print number between 0-255. Always prints leading 0’s. Expects number in A register at start.

00A8 168 Allocate tracks and update directory. Expects new directory entry at 203Ah with F5h for unused track and 2035h to point to end of track list, pointer to old directory entry in 2031h. If (2002h)=0, quits, otherwise returns.

00AB 171 Open stream as “dd”. Expects stream number in 2030h (8240).

00AE 174 Print error message. Expects HL set to text of message. Quits when done.

00B1 177 Erase block header. Erase data from 2070h-2087h (the track header info for the current track). Used before setting up header for new track.

00B4 180 Set up block header. Set up track header info (2070h-2087h) based on LKDOS variables (201Dh=track, 2022h-202Fh=name&block start&block length, current line and VARS, and 2004h=total length).

00B7 183 Find a BASIC variable. Used by SAVE DATA to find an array. Expects appropriate single character in 2037h (8247). Use ASCII code for lowercase letter to find simple variable, ASCII code +32 to find numeric arrray, ASCII code -32 for simple string, ASCII code +96 to find string array. See 2068 User’s guide, Appendix C.

00BA 186 Disable cartridge and turn off drive. Be careful whether to use this in ml or LD A,(0062h) if you don’t need to turn off the drive.

00BD 189 CALL MAKE_ROOM in Home ROM. Used to call appropriate 2068 or Spectrum routine to make space for BASIC line or variable. See 2068 Technical Manual for more details.

00C0 192 CALL DELREC in Home ROM. Routine to delete BASIC line or variable. See 2068 technical manual for more details.

00C3 195 Error Message: X Cat Data Error. Prints message and quits.

00C6 198 First part of LOAD. Used by start-up and autoboot with 2002h set to 1. Acts differently depending on 2002h.

00C9 201 Second part of LOAD. Use this after 00C6h if 2002h is set to 0Bh.

00CC 204 First part of SAVE. Do not use with 2002h set to 1.

00CF 207 Second part of SAVE. Use this after 00CCh if 2002h is set to 0Bh.