home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / zsm23.lbr / LIB.DZC / LIB.DOC
Text File  |  1991-08-28  |  39KB  |  1,074 lines

  1. This library uses the parameter passing mecanism of the standard c library:
  2. in a procedure call of the form
  3.  
  4.     aa = _proc(bb, cc);
  5.  
  6. the assembler code would be
  7.  
  8. ;    evaluate cc to hl (or de or bc)
  9.     push    hl
  10. ;    evaluate bb to hl
  11.     push    hl
  12.     call    _proc
  13.     pop    de
  14.     pop    de            ; restore stack
  15. ;
  16. ;    aa is returned in hl
  17.  
  18. Through any of these procedure calls, bc, ix & iy are guaranteed, de can
  19. be destroyed, and the returned value comes back in hl, otherwise hl will
  20. be destroyed.
  21.  
  22. Strings are passed as pointers to arrays of characters, so to set a string
  23. on the stack, a typical sequence might be:
  24.  
  25.     ld    hl,str
  26. .dseg
  27. str:    db    'This is a string\0'    NOTE the 0 byte to end it
  28. .cseg
  29.     push    hl
  30.  
  31. The parameter passed is the address of the string, and strings are always
  32. terminated by a zero byte.
  33.  
  34. As shown above, when there are multiple arguments, they are pushed in reverse
  35. order: i.e. the last (rightmost) argument is pushed first, then the next
  36. going left, and so on till the leftmost argument has been pushed. Note also
  37. that these words pushed on the stack are sometimes destroyed, so in
  38. a case such as:
  39.  
  40.     ld    hl,(_value)
  41.     push    hl
  42.     call    _something
  43.     pop    de
  44.  
  45. de cannot be guaranteed to contain (_value) after it has been popped.
  46.  
  47.  
  48. _open:    _open("name", fcb)
  49.  
  50. Open a file for block based (i.e. 128 byte chunk) I/O. The first parameter
  51. is the name of the file, the second is the address of a 36 byte area of
  52. memory to use to hold the fcb. If the call succedes, the fcb address is
  53. returned, otherwise -1 is returned. This call will fail if the name is not
  54. a valid CP/M filename, or if the file does not exist.
  55.  
  56.  
  57. _creat:    _create("name", fcb)
  58.  
  59. Create is similar to open, except that if the file exists it is truncated
  60. to zero length. as open, it returns the fcb, or -1 for an error. Errors
  61. are: bad name, no room in directory, or file exists and is read only.
  62.  
  63.  
  64. _close: _close(fcb)
  65.  
  66. After a file has been written or modified, this call closes the file.
  67.  
  68.  
  69. _read: _read(fcb, buffer, nbl)
  70.  
  71. Read takes and fcb, the address of a buffer, and a count of blocks to read,
  72. and reads the number specified into the buffer. It returns the number of
  73. blocks (128 bytes per block) read, which is usually the same as the number
  74. specified, except at end of file. For example if a file holds seven blocks,
  75. _read(fcb, buffer, 4) returns 4, reading 4 blocks, the next
  76. _read(fcb, buffer, 4) only returns 3, and all subsequent reads will return
  77. zero.
  78.  
  79.  
  80. _write: _write(fcb, buffer, nbl)
  81.  
  82. Just like read, except that it writes to the file. Consider it an error
  83. (usually disk full) if write returns less than the number specified.
  84.  
  85.  
  86. _tell: _tell(fcb)
  87.  
  88. Tell returns the number of the next block to be written or read in the fcb
  89. given. Note that files bigger than 65536 records will cause trouble, as
  90. the largest value that can be returned is a 16 bit integer.
  91.  
  92.  
  93. _seek: _seek(fcb, offset, whence)
  94.  
  95. Move the read / write position around in the file. This permits random
  96. access to the file, by specifying that reads and writes happen in
  97. different places. offset is a number of blocks which may be negative.
  98. whence specifies how the offset is to be applied: if 0 the offset is from
  99. the beginning of the file, and should be greater than or equal to zero,
  100. if 1 it is relative to the current position, and can take any value, and
  101. if 2, offset is worked relative to the end of the file. To give some
  102. examples: _seek(fcb, 0, 0) rewinds the file to the start, seek(fcb, 15, 0)
  103. will access block 15 (blocks are numbered from zero), seek(fcb, -1, 1)
  104. steps back a block, causing the most recently processed block to be
  105. used again, seek(fcb, 0, 2) moves to the end of the file.
  106.  
  107.  
  108. _printf
  109. _sprintf
  110. _fprintf
  111. _xprintf:
  112.  
  113. These four form a family of routines used for formatted output. Each one
  114. takes a format string and a list of arguments to be output with the
  115. format, but they all output in different ways. They all scan the format
  116. string, and copy characters one for one, until a '%' is encountered. The '%'
  117. means that an argument is to be converted, and a letter is used to specify
  118. the type of conversion. %c simply outputs the argument as a character, %s
  119. assumes that the argument is the address of a string, and outputs the
  120. string, %d prints the argument as a signed decimal number, %u prints it
  121. as an unsigned decimal number, %x prints as a hexadecimal number, %o
  122. prints in octal, and %b prints in binary. In order to print a '%'
  123. character, use '%%' in the format string: this prints a '%', but does not
  124. use an argument in the way that (say) %d does. In addition, by specifying a
  125. number between the '%' and the format specifier, a minimum field width
  126. can be given: the output will be padded so that it's size is at least
  127. as big as given: so %5d would convert 100 to "  100". Note that if the
  128. field width is too small it is not an error, output continues till everything
  129. has been printed, so %2d with 1234 would print "1234". In addition if the
  130. width specifier has a leading zero (e.g. %06x) numeric output is zero padded
  131. instead of being space filled: %04x with 1024 (400 hex) would print
  132. "0400", whereas %4x would just print " 400". Field width is always
  133. ignored for character conversion - %c outputs exactly one character.
  134. Field width can be supplied dynamically: if the width is given as a '*'
  135. then an argument is consumed to provide the width. Note that argument
  136. conversion procedes from left to right, and in the case of a '*' width
  137. specifier, the width is taken first. Note that a '0' can still be
  138. given before a '*' to create zero fill: %0*o with 10 and 2048 will
  139. print "0000004000", and the 10 should be on the left of the 2048.
  140. To provide a full example:
  141.  
  142.     _printf("%d hello %% >%6s< %04x ]%*u[", 42, "xyz", 100, 6, -1)
  143.  
  144. would output
  145.  
  146.     "42 hello % >   xyz< 0064 ] 65535["
  147.  
  148. and return 33. All four routines return the number of characters output.
  149. As shown above, _printf expects to have all the arguments pushed, and the
  150. format as the last thing. The other three expect an additional parameter
  151. prior to the format: _fprintf expects a file pointer as returned by _fopen
  152. (q.v.), _sprintf expects that address of a buffer: instead of outputting
  153. the data, it is placed in the buffer, and a zero byte is added at the end
  154. to terminate the string, and _xprintf expects to receive the address of a
  155. function to call to deal with generated characters. What will happen is
  156. that _xprintf will push a word containing the character, and then call the
  157. supplied function. This function MUST adhere to the standard calling
  158. convention (preserve bc, ix, iy), and the word pushed is cleaned up
  159. by _xprintf. So a _fprintf call might be:
  160.  
  161.     _fprintf(fp, "Error: %s", string)
  162.  
  163. where fp is the file pointer. _fprintf, _sprintf and _xprintf all expect their
  164. respective additional parameters to be first (i.e. pushed last). Note
  165. also that none of these add a trailing newline: if such is desired it must
  166. be included in the format string, and it is acceptable to output several
  167. lines with one _printf call by having several newlines in the format string.
  168.  
  169.  
  170.  
  171. _puts:    _puts(string)
  172. _fputs: _fputs(string, fp)
  173.  
  174. These two are used to simply print a string, no conversion of any kind
  175. is done, they just send out the characters till a zero byte is found.
  176. _puts sends to the screen, whereas _fputs sends to the file specified
  177. with fp - which was obtained from _fopen (q.v.)
  178.  
  179.  
  180. _gets:    _gets(buffer)
  181. _fgets: _fgets(buffer, fp)
  182.  
  183. These two read a line from the keyboard (_gets) or a file (_fgets).
  184. In both cases the end of line (<cr> for the keyboard, or <cr><lf> for
  185. file input) is not part of the line, so if the line above were input,
  186. the last character would be the 'r' of the second word 'for'. The strings
  187. are returned with a zero byte to mark the end, and both routines return
  188. the number of characters in the buffer (i.e. an empty lines gives zero).
  189. As a special case, _fgets returns -1 to signify end of file.
  190.  
  191.  
  192. _fwrite:    n2 = _fwrite(fp, buff, n1);
  193.  
  194. _fwrite & _fread (see below) provide raw file access something like
  195. _write and _read, except that they use file pointers as provided by
  196. _fopen (q.v.). Note that these routines use repeated calls to _putc &
  197. _getc (qq.v.) to interface to the file, so to prevent <cr><lf>
  198. compression/expansion, the file should be open in object mode. In the
  199. above example, fp is a file pointer as returned by _fopen, buff is the
  200. address of the buffer used for the data transfer, and n1 is the number
  201. of bytes to be transferred, n2 is the number of bytes actually transferred,
  202. consider it an error if n2 is not equal to n1.
  203.  
  204.  
  205. _fread:        n2 = _fread(fp, buff, n1);
  206.  
  207. read n1 bytes to buff from file accessed through fp, n2 will differ from
  208. n1 on an end of file condition, and after that successive calls will
  209. return n2 as zero.
  210.  
  211.  
  212. _fopen:        fp = fopen(name, mode, buffer);
  213.  
  214. In this example, name is a standard CP/M name, presented as a string
  215. with a zero byte to end it, mode is the mode in which the file is
  216. opened: "r" for read, "w" for write, "a" for append. These modes are
  217. passed as strings. Because _getc and _putc usually expects to work
  218. on text files, they usually do <cr><lf> compression/expansion. To
  219. prevent this, for reading an executable file byte by byte, prefix the
  220. mode by an 'o' char: "or", "ow", "oa". _fopen expects to be handed a
  221. buffer which is used for all the I/O for the file in question - the
  222. address of this buffer is the third parameter. The buffer should be
  223. fbsize bytes long, as defined in STDHDR.I. A typical calling sequence
  224. might be:
  225.  
  226.  
  227.     ; assume the name pointer is already in hl
  228.         ld    de,buff            ; get buffer address
  229.     .useg
  230.     buff:    ds    fbsize
  231.     .cseg
  232.         push    de            ; & save it
  233.         ld    de,mode
  234.     .dseg
  235.     mode:    db    'r\0'
  236.     .cseg
  237.         push    de            ; save the mode
  238.         push    hl            ; and the filename
  239.         call    _fopen
  240.         pop    de
  241.         pop    de
  242.         pop    de            ; restore the stack
  243.         ld    a,h
  244.         or    l            ; check for NULL in hl
  245.         jr    z,error            ; error if so
  246.  
  247. If _fopen goes ok, the third arg is returned UNLESS the name is the name
  248. of a logical CP/M device (CON: RDR: etc.), in which case a special fp is
  249. returned. _putc, _getc, _fprintf etc. etc. treat these special fp's
  250. just like normal file fp's, so there is nothing special that needs to
  251. be done to use them. If there was an error, hl is returned with zero
  252. in it. There is a special CP/M device NUL: if it is opened for input
  253. then it returns continuous EOF's, and when opened for output, whatever
  254. it is handed vanishes into a black hole. The full list of CP/M devices
  255. is: "CON:", "r" - read from keyboard, "CON:", "w" - write to screen,
  256. "RDR:", "r" - read from modem port, "PUN:", "w" - write to modem port,
  257. "LST:", "w" - write to printer port, plus "NUL:" for both read and
  258. write as specified above. In addition, the file BDOS.I holds .var
  259. variable definitions for these special devices: stdin is standard
  260. input, stdout is standard output. stdrdr, stdpun, stdlst, are the
  261. RDR:, PUN:, and LST: ports respectively; stderr is the screen, and
  262. stdkbd is the keyboard. stdin defaults to the same as stdkbd, and stdout
  263. defaults to the same as stderr, except that it is possible to "redirect"
  264. input or output, by using RARX.O or PARX.O. If RARX.O is used and the
  265. program is invoked A>PROG <FILE then stdkbd would still read from the
  266. keyboard, but stdin would now read from file FILE. See ARX.DOC for a
  267. more complete description of redirection.
  268.  
  269.  
  270. _fncheck:    fp = _fncheck(name, extlist, buffer)
  271.  
  272. This routine opens a file, checking for various single letter extensions
  273. on the filename. Name is a filename, except that if it has an extension
  274. (following the '.' in the filename) it must consist of exactly one letter.
  275. Extlist is a list of extensions that the file can legally have, and buffer
  276. is a fp buffer as given to _fopen. The action of _fncheck depends on
  277. whether name has an extension. If it does, it verified against extlist.
  278. If the extension character is not in the list, hl returns zero. If the
  279. extension is in extlist, then _fncheck attempts to _fopen name for
  280. read, and returns a vaild fp or zero as appropriate. If name has no
  281. extension, _fncheck repeatedly tries to find a file by using the
  282. characters in extlist one at a time until it finds a file, or it runs
  283. out of characters. To give some examples:
  284.  
  285.     _fncheck("file.q", "az", buffer) will fail: q not in "az"
  286.     _fncheck("file.a", "az", buffer) will try to open file.a and
  287.         return a value as appropriate.
  288.     _fncheck("file", "az", buffer) will first try file.a, if that
  289.         fails it wil then try file.z. If either succede than
  290.         a valid fp is returned, otherwise zero.
  291.  
  292.  
  293. _fclose:    _fclose(fp)
  294.  
  295. After _fopen or _fncheck have opened a file, _fclose will close it,
  296. flushing any pending writes, and using the BDOS file close function to
  297. finish up everything. This is not needed for files that were open for
  298. read, but it does no harm in such a case, however it MUST be called for
  299. files that were opened for write or append.
  300.  
  301.  
  302. _rename:    status = _rename(oldname, newname)
  303.  
  304. Rename a file: this changes oldname to newname: both names are passed as
  305. strings, complete with zero bytes on the end. This invokes the BDOS rename
  306. function on the specified file. status (i.e. hl) contains zero if all went
  307. well, or -1 if there was an error. Note that a drive specifier (leading "B:")
  308. can be given with either or both of the names, but if two different
  309. drives are given it is considered an error. If no drive specifier is
  310. provided, then the default drive is used.
  311.  
  312.  
  313. _unlink:    status = _unlink(name)
  314.  
  315. Erases name from the disk. status returns 0 if it succeded, or -1
  316. on an error (file not found, or file R/O).
  317.  
  318.  
  319. _putchar:    _putchar(ch);
  320. _putc:        _putc(ch, fp);
  321.  
  322. These two do character output. _putchar(ch) sends ch to stdout, note
  323. that '\n' (linefeed) maps to <cr><lf> , so it is not necessary to _putchar
  324. an explicit '\r' (carriage return). _putc(ch, fp) sends ch to file fp:
  325. fp is returned from _fopen. Both of these return the output character
  326. in hl, except that if _putc is writing to a file, and the write fails
  327. (usually because of disk full, or a file open for read), then it will
  328. return EOF, or -1 to signify the error. _putchar usually writes to
  329. the screen unless output redirection has occurred - see fopen above
  330. and ARX.DOC for an explanation of redirection.
  331.  
  332.  
  333. _kbhit:        test = _kbhit();
  334.  
  335. This checks if there is a character waiting at the keyboard, and returns
  336. true if there is keyboard input waiting to be processed.
  337.  
  338.  
  339. _getchar:    ch = _getchar();
  340. _getc:        ch = _getc(fp);
  341.  
  342. _getchar() returns the next character from stdin, which will respect
  343. redirection, and _getc(fp) gets the next character from the file
  344. referenced by fp. As does _putc, _getc knows about stdrdr etc. etc.
  345.  
  346.  
  347. _ungetc:    ch = ungetc(ch, fp)
  348.  
  349. This "pushes" a character back onto an input stream: the next call to
  350. _getc for the fp given returns ch, just as if it were a character in
  351. the file. This is guaranteed only for one char push back, and only if
  352. at least one character has been read. It returns the pushed back character,
  353. or EOF on an error. fp must be a read filepointer returned by fopen, or one
  354. of the stdin / stdkbd read filepointers.
  355.  
  356.  
  357. _stty:        _stty(fp, mode);
  358.  
  359. _stty changes the "mode" of CP/M devices and files:
  360. for all CP/M "std" devices except stdkbd (keyboard input), mode is
  361.     0 => do <cr><lf> compression / expansion, or
  362.     1 => don't.
  363. stdkbd allows four modes:
  364.     0 => normal buffered input (use BDOS call for buffered input)
  365.     1 => unbuffered input with <cr> mapped to <lf>
  366.     2 => unbuffered input without <cr> mapping
  367.     3 => unbuffered input without echo
  368. for files:
  369.     0 => change to text mode (i.e. fopen (name, "r" / "w" / "a", ...)
  370.     1 => change to object mode (i.e. fopen (name, "or" / "ow" / "oa", ...)
  371. Note for files, text mode means that 0x1a (control Z) flags an end of file,
  372. and that <cr><lf> pairs come in as just a single <lf> (newline). Object
  373. mode means read the file as is, i.e. no compression of <cr><lf> pairs, and
  374. EOF is only flagged when the physical end of file is hit (i.e. last character
  375. in the last block).
  376.  
  377.  
  378. _scnwld:    count = _scnwld(name, function)
  379.  
  380. This processes a CP/M wildcard file specifications: _scnwld takes the
  381. wildcard name (a la B:*.* or C:ABC*.?Q?), and calls function once for each
  382. file that matches, returning the count of calls that it made. function
  383. should expect to receive the filename as a string pushed immediately
  384. before the call, and must rspect the usual calling convention (i.e. preserve
  385. bc, ix, iy).
  386.  
  387.  
  388. _pfile:        name = _pfile(fcb);
  389.  
  390. This decodes the filename from a CP/M fcb as might be given back by _open,
  391. (or by directly creating a CP/M fcb), or a fp given by _fopen. name will
  392. be a pointer to a string that contains the decoded name, given that fcb
  393. points to either a CP/M fcb (i.e. what open returns), or to a fp. The string
  394. is returned in a buffer that is valid to the next call of _pfile, at which
  395. time it will be overwritten. Note that several other routines use this same
  396. buffer: notably _itoa and _scrypt (in xlib.l). Because of this, the best
  397. thing to do is to use the buffer immediately: either print it (_puts or
  398. _printf), or use _strcpy (q.v.) to make a copy in a local buffer.
  399.  
  400.  
  401. _stat:        mode = stat(file, mask, bits);
  402.  
  403. Changes the R/O and SYS bits of the file, whose name is passed as a string
  404. with a zero byte at the end; and returns the new value. The R/O bit is
  405. bit 0, and the SYS bit is bit 1. To change either of these bits, set the
  406. corresponding bit in mask, and provide the desired value in bits:
  407. i.e. mask == 1, bits == 1 would set the file R/O, without altering the SYS
  408. bit, and would return the new bit pair. In particular, this means it is
  409. possible to enquire the current value by just setting mask to zero.
  410.  
  411.  
  412. _swapin:    size = _swapin(file, address)
  413.  
  414. This loads the file given into memory at the specified address, returning
  415. the size in bytes, or -1 on an error - file not found or bad filename. If
  416. the filename has no extension then swapin wil automatically add a .OVR to it.
  417.  
  418.  
  419. _upper:        _upper(str)
  420. _lower:        _lower(str)
  421.  
  422. These expect the address of a zero byte terminated string, and on return
  423. the string will be completely in upper or lower case, as appropriate.
  424.  
  425.  
  426. _inchr:        offset = _inchr(str, ch)
  427.  
  428. This finds the offset into a string of a character: it returns the position
  429. of first occurence of ch in str, or -1 if no match: so _inchr("hello", 'l')
  430. would return 2 (bytes are numbered from zero), and _inchr("hello", 'q') would
  431. return -1.
  432.  
  433.  
  434. _instr:        offset = _instr(str, sub)
  435.  
  436. This is just like _inchr, except that it looks for a substring rather than
  437. a single character, returns count to first char of substring, or -1 on no
  438. match: _instr("hello", "lo") returns 3 (bytes numbered from zero),
  439. whereas _instr("hello", "elo") returns -1.
  440.  
  441.  
  442. _rinchr:    offset = _rinchr(str, ch)
  443. _rinstr:    offset = _rinstr(str, sub)
  444.  
  445. These two are just like _inchr and _instr above, except that instead of
  446. giving the offset to the first occurance, they give the offset to the
  447. last, so for example _rinchr("hello", 'l') returns 3. Note that they still
  448. return -1 if no match is to be found.
  449.  
  450.  
  451. _index:        addr = _index(str, ch)
  452. _insdex:    addr = _insdex(str, sub)
  453. _rindex:    addr = _rindex(str, ch)
  454. _rinsdex:    addr = _rinsdex(str, sub)
  455.  
  456. These four match the above four one to one (_inchr and _index, _instr and
  457. _insdex, etc.) except that instead of returning the offset into the
  458. string, they return the actual address of the first or last occurance, as
  459. appropriate. Note also that in a no match situation, they return zero rather
  460. than -1.
  461.  
  462.  
  463. _tinstr:    offset = _tinstr(str, sub)
  464.  
  465. This finds a substring in a string as a token: it is similar to _instr,
  466. but it also inspects the context of any substring it finds: if either
  467. end of the substring is an alphanumeric (first or last char) and the char
  468. in the main string that extends just beyond that char is also alphanumeric
  469. then the substring is rejected:
  470.  
  471.     _tinstr("...push.de", "pu")
  472.  
  473. would return -1: there is an 's' after the 'u' in the main string, whereas:
  474.  
  475.     _tinstr("...push.de", "de")
  476.  
  477. would work: _tinstr knows about the ends of the main string.
  478.  
  479.  
  480. _nconv:        _nconv(str)
  481.  
  482. This converts a string with alphabetic words to "name" format. What it does is
  483. to scan for groups of alphabetic characters in either upper or lower case,
  484. surrounded by non alphabetic characters. What it then does is to force the
  485. first letter in each of these groups to be upper case, while converting the
  486. rest to lower case: so "HeLLo woRLd" would become "Hello World".
  487.  
  488.  
  489. _prefix:    test = _prefix(str, sub);
  490. _suffix:    test = _suffix(str, sub);
  491.  
  492. This checks to see if sub is a prefix / suffix of str, and returns true
  493. if so, false if not. Hence _prefix("Hello World", "Hel") returns true,
  494. whereas prefix("Hello World", "xyz") returns false.
  495.  
  496.  
  497. _chrcnt:    count = _chrcnt(str, ch)
  498.  
  499. _chrcnt    returns a count of how many times character ch occurs in string str:
  500. _chrcnt("Hello World", 'l') returns 3: there are three 'l's in the string.
  501.  
  502.  
  503. _chrcat:    _chrcat(str, ch)
  504.  
  505. This takes character ch, and appends it to str: so if str contained "hel"
  506. on entry, and ch was 'p', str on exit would be "help", complete with a new
  507. trailing zero byte. _chrcat assumes that the string pointer provided
  508. addresses a buffer with sufficient space: it does no error checking at all.
  509.  
  510.  
  511. _detab:        _detab(dest, src)
  512. _entab:        _entab(dest, src)
  513.  
  514. _detab copies from string src, making a new string at dest, but as it copies
  515. it converts tabs to the correct number of spaces. It assumes that tab stops
  516. are every eight characters. _entab reverses this operation: it converts
  517. groups of spaces to tabs wherever possible. Note that entab can be given the
  518. same string as both source and destination, but if this is tried with _detab
  519. it may cause a program crash.
  520.  
  521.  
  522. _strip:        _strip(str)
  523.  
  524. _strip simply removes any trailing white space from str: it does this
  525. by placing a new zero byte after the last non-white space character in str.
  526.  
  527.  
  528. _trim:        _trim(str, n)
  529.  
  530. _trim checks the length of string str, and if it is greater than n then
  531. a zero byte is inserted to make its length equal to n. If its length is
  532. less than n then no action is taken.
  533.  
  534.  
  535. _byp:        dest = _byp(str)
  536. _unbyp:        dest = _unbyp(str)
  537.  
  538. _byp returns the address of the first non-white space character in its
  539. argument string, effectively bypassing leading white space. _unbyp is
  540. similar, except that it returns the address of the first white space
  541. character: instead of stepping over white space, it steps over everything
  542. but white space.
  543.  
  544.  
  545. _strcmp:    val = _strcmp(s, t)
  546.  
  547. _strcmp returns a value telling whether s is greater than, equal to, or
  548. less than t, i.e. it returns a number greater than zero if s comes after
  549. t in a dictionary, 0 if they are the same, and a negative number if s comes
  550. before t. Full ASCII ordering is used: the strings can containany ASCII
  551. character from ^A (0x01) to DEL (0x7f). Characters above DEL can cause
  552. unpredictable results in ordering, however differences are always detected.
  553. Note that for equality s need not be the same as t, what is being tested is
  554. if the bytes addressed by the two pointers are the same.
  555.  
  556.  
  557. _strequ:    val = _strequ(s, t)
  558.  
  559. Check if s and t point to similar strings: return true (i.e. non-zero) if so,
  560. false (zero) if not.
  561.  
  562.  
  563. _strlen:    val = _strlen(s)
  564.  
  565. This gets the length of a string, and return it as an integer.
  566.  
  567.  
  568. _strcpy:    _strcpy(s, t)
  569.  
  570. _strcpy reads the string at t and makes a copy of it in the buffer addressed
  571. by s. This is useful to save permanent copies of the strings returned by
  572. procedures such as _pfile or _itoa (qq.v.). Note that no error checking is
  573. done: s must address enough memory to receive the string, also unpredictable
  574. results may occur if s and t overlap.
  575.  
  576.  
  577. _strcat:    strcat(s, t)
  578.  
  579. This takes string t, and adds it to the end of string s. It leaves the
  580. current contents of s alone, up to but not including the terminating zero.
  581. (What happens is that the terminating zero on s gets replaced by the first
  582. char of t, and the rest of t is copied over up to and including the zero on
  583. the end of t. As in _strcpy it is the responsibility of the caller to ensure
  584. that there is enough memory addressed by s to receive the new bytes, and the
  585. caller should ensure that s and t don't overlap.
  586.  
  587.  
  588. _strrev:    _strrev(s)
  589.  
  590. This takes its argument string and reverses the bytes in place: so on entry
  591. if s pointed to "hello", on exit it would point to "olleh". The terminating
  592. zero byte is left undisturbed.
  593.  
  594.  
  595. _strswp:    _strswp(s, t)
  596.  
  597. _strswp moves the bytes addressed by t to s, and the bytes addressed by s to t
  598. effectively swapping the two strings. Note that it there has to be enough
  599. memory to do this, if s is shorter than t, there must still be enough memory
  600. in the buffer addressed by s to take all of t. As in _strcpy and _strcat,
  601. unpredictable results will follow if s and t overlap.
  602.  
  603.     
  604. _strmov:    _strmov(s, t)
  605.  
  606. This is very similar to _strcat in that it moves the string t to s, however
  607. unlike _strcpy it does not move the zero byte terminator. This makes it
  608. useful for replacing a small part of a large string without disturbing the
  609. rest of it.
  610.  
  611.  
  612. _strncmp:    val = _strncmp(s, t, n)
  613.  
  614. Just like _strcmp, this compares two strings, however it also takes a third
  615. parameter which is a maximum count to compare: i.e. if no differences have
  616. found in the first n bytes then the strings are considered equal, and zero
  617. gets returned.
  618.  
  619.  
  620. _strnequ:    val = _strnequ(s, t, n)
  621.  
  622. This is like _strequ: it tests for equality, but it stops after n bytes of
  623. testing, and returns true if no differences were found.
  624.  
  625.  
  626. _strncpy:    _strncpy(s, t, n)
  627.  
  628. This copies string t to string s, but will copy no more than n characters.
  629. Note that it will at most move n + 1 characters because it always adds a
  630. trailing zero, and this is not included in the count.
  631.  
  632.  
  633. _strncat:    _strncat(s, t, n)
  634.  
  635. This adds t to the end of s, but like _strncpy it stops after n characters.
  636. As in _strncpy, the zero terminator is always added, but never included in
  637. the count n.
  638.  
  639.  
  640. _strnrev:    _strnrev(s, n)
  641.  
  642. This reverses the string s, but if it's length exceeds n then only the first
  643. n bytes are affected, the remainder are left undisturbed. For example if s
  644. points to "hello", and n is 3, then on exit s would point to "lehlo": the
  645. first three bytes in the buffer have been reversed and the rest is left
  646. alone.
  647.  
  648.  
  649. _strnmov:    _strnmov(s, t, n)
  650.  
  651. This does a limited (i.e. max n bytes move) string copy from t to s, however
  652. like _strmov it does not move the zero byte terminator.
  653.  
  654.  
  655. _memcmp:    val = _memcmp(s, t, n)
  656.  
  657. This is similar to _strncmp in that it compares the bytes in two memory
  658. buffers, and is set to compare a maximum of n bytes, however unlike _strncmp
  659. it will not stop at the end of a string, it always compares exactly n bytes.
  660.  
  661.  
  662. _memequ:    val = _memequ(s, t, n)
  663.  
  664. Like _strnequ this checks memory for equality, however like _memcmp it does
  665. not stop at the end of a string, it keeps going till it has checked n bytes.
  666.  
  667.         
  668. _memcpy:    _memcpy(s, t, n)
  669.  
  670. Move bytes from t to s: this simply moves n bytes, no more and no less. Note
  671. that for this procedure, s and t can overlap: checks are made before the
  672. copy is started so that data is moved in the right order (head first or
  673. tail first).
  674.  
  675.  
  676. _memrev:    _memrev(s, n)
  677.  
  678. This just reverses n bytes addressed by s - like _strnrev but without the
  679. checking for end of string.
  680.  
  681.  
  682. _memset:    _memset(s, v, n)
  683.  
  684. Set n bytes, addressed by s, to contain value v.
  685.  
  686.  
  687. _memswp:    _memswp(s, t, n)
  688.  
  689. This just swaps the first n bytes addressed by s and t.
  690.  
  691.  
  692. _toupper:    i = _toupper(ch)
  693.  
  694. This returns ch untouched unless ch is lower case ('a' - 'z'), in which case
  695. it is converted to upper case. Note that for _toupper, _tolower and all the
  696. _is????? routines, only the least significant byte of the argument is
  697. considered, i.e. if hl is used to push it, then only l will be significant:
  698. h can contain anything.
  699.  
  700.  
  701. _tolower:    i = _tolower(ch)
  702.  
  703. Returns ch converted to lower case if necessary.
  704.  
  705.  
  706. _isupper:    i = _isupper(ch)
  707.  
  708. Returns true (non-zero) if ch is an upper case letter, false otherwise.
  709.  
  710.  
  711. _islower:    i = _islower(ch)
  712.  
  713. Returns true if ch is a lower case letter.
  714.  
  715.  
  716. _isdigit:    i = _isdigit(ch)
  717.  
  718. Returns true if ch is a digit ('0' - '9')
  719.  
  720.  
  721. _isprint:    i = _isprint(ch)
  722.  
  723. Returns true if ch is a printable char (' ' - '~')
  724.  
  725.  
  726. _isgraph:    i = _isgraph(ch)
  727.  
  728. Returns true if ch is a graphic char ('!' - '~')
  729.  
  730.  
  731. _isascii:    i = _isascii(ch)
  732.  
  733. Returns true if ch is a valid ascii char (0 - 0x7f)
  734.  
  735.  
  736. _isalpha:    i = _isalpha(ch)
  737.  
  738. Returns true if ch is alphabetic ('A' - 'Z' or 'a' - 'z')
  739.  
  740.  
  741. _isalnum:    i = _isalnum(ch)
  742.  
  743. Returns true if ch is alphanumeric ('A' - 'Z', 'a' - 'z' or '0' - '9')
  744.  
  745.  
  746. _isxdigit:    i = _isxdigit(ch)
  747.  
  748. Returns true if ch is a hexadecimal digit ('A' - 'F', 'a' - 'f' or '0' - '9')
  749.  
  750.  
  751. _isspace:    i = _isspace(ch)
  752.  
  753. Returns true if ch is a white space char (tab - 0x09, lf - 0x0a, ff - 0x0c,
  754. cr - 0x0d, or ' ')
  755.  
  756.  
  757. _iscntrl:    i = _iscntrl(ch)
  758.  
  759. Returns true if ch is a control char (0 - 0x1f or 0x7f)
  760.  
  761.  
  762. _ispunct:    i = _ispunct(ch)
  763.  
  764. Returns true if ch is a punctuation char: i.e. not a control char or an
  765. alphanumeric
  766.  
  767.  
  768. _atoi:        val = _atoi(s)
  769.  
  770. If string s contains a number (e.g. "1234") then _atoi returns the value
  771. of this number: a leading '-' creates a negative number. Leading white
  772. space in the string is skipped.
  773.  
  774.  
  775. _atoix:        val = _atoix(s)
  776.  
  777. This is just like _atoi in that it converts a string to a number, but
  778. it also recognises hexadecimal constants starting with 0x (eg 0x7fff),
  779. or octal (leading 0) or binary (leading 0b). Hence "76", "0x4c", "0114"
  780. and "0b1001100" all give the same value. As in _atoi, leading white
  781. space is skipped.
  782.  
  783.  
  784. _itoa:        str = _itoa(val)
  785.  
  786. This reverses atoi: it takes an integer argument, and returns the address
  787. of a buffer that holds the number printed as a string. This is the same
  788. buffer as used by _pfile, so the same precautions should be observed
  789. regarding use and saving of the string.
  790.  
  791.  
  792. _isqr:        i = _isqr(j)
  793.  
  794. _isqr returns the integer square root of an unsigned argument.
  795.  
  796.  
  797. _abs:        i = _abs(j)
  798.  
  799. _abs returns the absolute value of its argument taken as a signed integer.
  800.  
  801.  
  802. _sgn:        i = _sgn(j)
  803.  
  804. _sgn returns the "sign" of its argument taken as a signed integer: if it
  805. is greater than 0 then 1 is returned, if less than zero -1, if zero then
  806. zero is returned.
  807.  
  808.  
  809. _min:        i = _min(j, k)
  810. _max:        i = _max(j, k)
  811.  
  812. These return the minimum or maximum (as appropriate) of two signed
  813. integer arguments.
  814.  
  815.  
  816. _umin:        i = _umin(j, k)
  817. _umax:        i = _umax(j, k)
  818.  
  819. These return the minimum or maximum (as appropriate) of two unsigned
  820. integer arguments.
  821.  
  822.  
  823. _lcm:        i = _lcm(j, k)
  824.  
  825. This returns the lowest common multiple of two integer arguments, i.e.
  826. the smallest number that both can divide. Note that if such a number
  827. is greater than 65535, then the return value will be undefined.
  828.  
  829.  
  830. _gcd:        i = _gcd(j, k)
  831.  
  832. This returns the greatest common divisor of two arguments, i.e. the biggest
  833. number that will divide into both.
  834.  
  835.  
  836. _swab:        _swab(dest, src, n)
  837.  
  838. This transfers n bytes from src to dest (like _memcpy), but it swaps
  839. adjecent bytes as it goes. Note that if n is given odd, it is reduced
  840. by 1 to make it even.
  841.  
  842.  
  843. _bdos:        hl = _bdos(c, de)
  844.  
  845. This calls into bdos, with arguments as shown, returns value is what
  846. bdos gives back in hl.
  847.  
  848.  
  849. _bios:        a = bios(n, bc, de)
  850.  
  851. This calls the nth entry in bios table (1 is warm boot), with bc and de
  852. registers set as shown. The return value is whatever comes back in a or hl
  853. as appropriate to the routine in question.
  854.  
  855.  
  856. _inp:        ch = _inp(port)
  857.  
  858. This inputs a byte from one of the Z80's I/O ports.
  859.  
  860.  
  861. _outp:        _outp(ch, port)
  862.  
  863. This output a byte to one of the Z80's I/O ports.
  864.  
  865.  
  866. _signal:    _signal(mode)
  867.  
  868. This manipulates the way that ^C's are handled. mode can be one of three
  869. things: if zero then normal ^C trapping is enabled, i.e. a reboot occurs;
  870. if 1 then ^C's are ignored:, in fact the jump to zero is intercepted, and
  871. control is passed back into bdos to do the input again; any other value is
  872. taken as the address of a jump_buffer created by _setjmp, which is used
  873. to cause a _longjmp to the environment saved in the jump_buffer.
  874.  
  875.  
  876. _setjmp:    val = _setjmp(env);
  877.  
  878. When called in normal flow, _setjmp sets up data for a non-local goto. It
  879. saves it's environment in the array provided (which must be 4 words long),
  880. and returns zero.
  881.  
  882.  
  883. _longjmp:    _longjmp(env, val);
  884.  
  885. This executes a non-local goto, which also cleans up the stack & frame
  886. pointers: instead of returning to the caller of _longjmp, this call causes
  887. execution to continue as if the call to _setjmp that initiated the
  888. environment env had just returned. Note however that the value "returned"
  889. by _setjmp in this case is val, which if non-zero provides a means to
  890. determine if it was a "setup" call to _setjmp or a subsequent call to
  891. _longjmp somewhere else. This call restores sp, bc, and ix to their
  892. original values. If the environment is no longer valid then control
  893. returns back out of _longjmp - this in itself implies an error.
  894.  
  895.  
  896. _resrv:        _resrv(n)
  897.  
  898. Successive calls to _sbrk keep on taking more memory, this determines
  899. how much should be reserved for the stack, without any calls to _resrv,
  900. the default is 1K, however it can be made as small or large as is needed.
  901.  
  902.  
  903. _sbrk:        ptr = _sbrk(n)
  904.  
  905. This returns a pointer to a block of memory n bytes long that can be used
  906. exclusively by the caller of sbrk. Note that successive calls return higher
  907. and higher addresses, and when the space available is exhausted, _sbrk
  908. returns -1 to show the error. Note also that successive blocks will be
  909. contiguous, so space for a string can be dynamically allocated by
  910. repeated _sbrk(1) calls.
  911.  
  912.  
  913. _sleep:        _sleep(n)
  914.  
  915. This just waits for n seconds.
  916.  
  917.  
  918. _pause:        _pause(n)
  919.  
  920. This waits for n milliseconds - these previous two assume a 4MHz Z80 - with
  921. other processors / clock speeds, the constant will have to be altered in
  922. _pause.
  923.  
  924.  
  925. _pack:        _pack(p, r, n)
  926. _unpack:    _unpack(p, r, n)
  927.  
  928. These two handle rad50 compression: pack reads plain text from p, and
  929. packs it rad50 into r, packing a total of n triplets. _unpack reverses this:
  930. it unpacks n rad50 triplets reading from r, and placing the unpacked plain
  931. text at p.
  932.  
  933.  
  934. _call:        hl = _call(addr, hl, a, de, bc)
  935. _calla:        a = _calla(addr, hl, a, de, bc)
  936.  
  937. These two allow calling of an arbitrary machine language address: they both
  938. call the routine at addr, with hl, a, de, and bc set as shown, however
  939. _call returns whatever came back in hl, whereas _calla returns whatever came
  940. back in a.
  941.  
  942.  
  943. _exit:        _exit
  944.  
  945. This is not a procedure per se, instead each of the arx.o modules have
  946. _exit defined in such a way that a call to _exit will terminate the
  947. program, closing stdout properly if needed.
  948.  
  949.  
  950. The rest of these routines are system subroutines, these all have a #
  951. prefix.
  952.  
  953.  
  954. #mul:        integer multiply - returns hl * de in hl - destroys de & a
  955.  
  956.  
  957. #udiv:        unsigned integer divide - returns hl / de in hl, hl % de in
  958.         de. hl % de is the remainder on division when hl is divided
  959.         by de. destroys a
  960. #div:        signed integer divide - de and hl behave as above, also
  961.         destroys a
  962.  
  963.  
  964. #muldiv:    returns hl * de / bc in hl, with remainder in de, this will
  965.         give better accuracy than calls to #mul & #div as it retains
  966.         a full 32 bit inner product. destroys a & bc
  967.  
  968.  
  969. #shl:        shift left: returns hl left shifted de times in hl (with
  970.         zero fill), destroys de & a
  971. #shr:        shift right: returns hl right shifted de times in hl, (with
  972.         zero fill), destroys de & a
  973.  
  974.  
  975. #rotate:    returns hl rotated left de times in hl, destroys de & a
  976.  
  977.  
  978. #neg:        returns -hl in hl, destroys a
  979. #cpl:        returns bitwise not hl in hl, destroys a (~ in zsm exprs.)
  980. #not:        returns logical not hl in hl, destroys a (! in zsm exprs.)
  981.  
  982.  
  983. #and:        returns hl and de in hl, destroys a
  984. #or:        returns hl or de in hl, destroys a
  985. #xor:        returns hl xor de in hl, destroys a
  986.  
  987. #arg2:        after entry to a routine of the type _proc(aa, bb), get
  988.         aa to de & bb to hl. Correct exit with maintenance of
  989.         stack discipline (i.e. matching your pushes and pops),
  990.         is a 'ret' instruction.
  991.  
  992.  
  993. #arg2b:        works like #arg2 getting two arguments to hl & de, except
  994.         that it also pushes bc, so with correct stack discipline,
  995.         the return from a routine that enters with an #arg2b would
  996.         be a 'pop bc' followed by a 'ret'.
  997.  
  998.  
  999. #arg3:        similar to #arg2b: for a routine _proc(aa, bb, cc), get
  1000.         aa to de, bb to hl & cc to bc - leaves old bc on stack
  1001.         so correct exit with maintenance of stack discipline is
  1002.         a 'pop bc' followed by a 'ret'.
  1003.  
  1004.  
  1005. #csv:        save bc & ix on stack & set ix from sp as initialisation
  1006.         for a procedure: allows ix to be used as a frame pointer
  1007. #cret:        any procedure that uses #csv MUST return by jumping to
  1008.         #cret to restore ix & bx - note that stack discipline need
  1009.         not be maintained as long as the data on the stack from ix
  1010.         up has not been altered, and ix itself is unchanged: typical
  1011.         usage is
  1012.  
  1013.         proc:    call    #csv
  1014.             ld    hl,-76
  1015.             add    hl,sp
  1016.             ld    sp,hl        ; allocate local variables
  1017.             ld    l,(ix+6)
  1018.             ld    h,(ix+7)    ; get the first arg to hl
  1019.             ld    (ix-2),l
  1020.             ld    (ix-1),h    ; save for later
  1021.  
  1022.         etc. etc. etc.
  1023.  
  1024.             jp    #cret        ; return
  1025.  
  1026.         in the above example, arguments to proc are accessible
  1027.         at ix+6/7, ix+8/9, ix+10/11 etc. for the 1st. 2nd. 3rd. args,
  1028.         and local variable space starts at (ix-1) and proceeds down.
  1029.         sp has been altered by proc, however since sp & ix are
  1030.         equal on exit from #csv, the first thing #cret does is to
  1031.  
  1032.             ld    sp,ix
  1033.  
  1034.         hence resetting sp.
  1035.  
  1036.  
  1037. #csvx,
  1038. #cretx:        expanded csv & cret - in addition to saving ix & bc, these
  1039.         also save iy, hl', de' and bc'; due to increased stack
  1040.         usage arguments start at ix+14/15 etc.
  1041.  
  1042.  
  1043. #ucsa:        force char in a upper case
  1044. #lcsa:        force char in a lower case
  1045. #iswa:        return with z flag set iff char in a is white space
  1046.  
  1047.  
  1048. #byp
  1049. #unbyp:        these are direct assembler interfaces to _byp and _unbyp:
  1050.         the only difference is that they take the parameter
  1051.         directly in hl, rather than requiring that it be pushed
  1052.         in the stack as is the usual convention.
  1053.  
  1054. #setcmp:    set signed hl and de for an unsigned compare: all this does
  1055.         is to add 0x8000 to both hl and de. For unsigned values it
  1056.         is possible to test hl >= de simply by doing a 'or a' and a
  1057.         'sbc hl,de' and testing the carry. This does not work on
  1058.         signed values, however if a pair of signed integers are
  1059.         passed into setcmp then the resulting values can be compared
  1060.         by doing a 'sbc hl,de'. Destroys a
  1061. #setch:        do the above, but to hl only: i.e. add 0x8000 to hl. destroys
  1062.         a
  1063.  
  1064. The following is a list of further external labels that are reserved - these
  1065. are used by the above routines and their names should not clash with any
  1066. external labels in the program being linked.
  1067.  
  1068.  
  1069. #bsave        #cbdos        #cconv        #cpylp        #ctop
  1070. #digfms        #digfmt        #doprnt        #fcb        #flags
  1071. #kbdbf        #kbdhd        #kbdpc        #rdrpc        #sbuff
  1072. #spad        #spsav        #ssiz        #stdin        #stdout
  1073. #wfcb        #xxfp        #xxstr
  1074.