home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / genie-commodore-file-library / Information / ACE-R11-PRG.DOC < prev    next >
Encoding:
Text File  |  2019-04-13  |  77.8 KB  |  1,601 lines

  1. ACE-128/64 PROGRAMMER'S REFERENCE GUIDE  (version 1.2b, for Release #11)
  2.  
  3. by Craig Bruce  <csbruce@ccnga.uwaterloo.ca>  02-Feb-1994, Rev. 21-Sep-1994.
  4.  
  5. 1. INTRODUCTION
  6.  
  7. ACE is a program for the Commodore 128 and Commodore 64 that provides a
  8. command shell environment that is similar to that of Unix.  It is still in the
  9. development stage, but enough of it is complete to be useful.  BTW, "ACE"
  10. means "Advanced Computing Environment" (well, advanced for the 128/64).
  11.  
  12. So what is ACE all about?  Well, originally I tried a very ambitious project
  13. of writing a multitasking operating system for the 128.  It got it partially
  14. working, but it was much too fragile and incomplete to be released.  It was a
  15. white-elephant project.  So, then then it came to me that I was aiming much
  16. too high.  What I needed was a much simpler system, one that would give the
  17. type of programming interface and built-in features that I wanted, but one
  18. that was close enough to the Commodore Kernal that it would not require much
  19. of a programming effort to hack together a minimal implementation.  And thus,
  20. there was ACE-128 Release #1.  And I saw it was good.
  21.  
  22. What I wanted was a system that would be easier to program than the Commodore
  23. Kernal with all its weird and wonderful device types, non-existent memory
  24. management, and single-application design.  The first important feature of
  25. this environment was to be able to pass arguments from a command line to an
  26. application program by typing them on the command line of the shell.  It is so
  27. annoying to load up a program in BASIC, run it, and have it ask you for
  28. filenames in some highly inconvenient way.
  29.  
  30. Another important system feature is to make near and far memory management
  31. part of the system, and to make far memory convenient to use for storing
  32. massively bulky data.  And so it was.  Also, we want to use custom device
  33. drivers.  Commodore didn't really come through with the device drivers it
  34. provided.  They are all REALLY SLOW.  And so that was, also, although more
  35. custom device drivers are needed.  We want to have the capability of making
  36. programs work together, rather than having programs that are totally
  37. incompatible.  This functionality is still under construction.  Programs will
  38. work together in this uni-tasking environment by allowing a program to execute
  39. another program as a sub-task, and then having control return to the calling
  40. program upon exit.  Finally, we want some good quality applications and a
  41. powerful command shell.  This is still being worked on and progress is coming
  42. slowly.  Oh, almost forgot; we also want all programs to work on both the C64
  43. and C128, and they do.
  44.  
  45. 2. SYSTEM INTERFACE
  46.  
  47. This section describes the interface between user programs and the ACE kernel.
  48. I am very careful throughout this interface specification about revealing any
  49. internal details that you do not strictly need to know.  The interface with
  50. ACE is not specified in terms of absolute addresses; to aid in portability and
  51. extensibility, all interfaces are specified in terms of symbolic assembler
  52. labels.  All of the ACE code is currently written for the Buddy-128 assembler.
  53. Also, because these interface absolute addresses are subject to change from
  54. version to version of the kernel, executables compiled for use with an old
  55. version of ACE may not work with a new version.
  56.  
  57. 2.1. ZERO-PAGE VARIABLES
  58.  
  59. There are four zero-page variables used for passing arguments in most system
  60. calls.  They are as follows:
  61.  
  62. SYMBOL   BYTES   DESCRIPTION
  63. -------  -----   -----------
  64. zp           2   zeropage pointer
  65. zw           2   zeropage word
  66. mp           4   memory pointer
  67. syswork     16   system work area / arguments
  68.  
  69. The first two, "zp" and "zw" are used in most calls.  They store simple 16-bit
  70. values; "zp" usually stores pointers to strings in RAM0 memory.  The "mp"
  71. variable is 32-bits in length and is used exclusively for passing far memory
  72. pointers for use with the far memory routines.  All three of these variables
  73. will remain unchanged inside of system call unless they will contain a return
  74. value.  "syswork" is a 16-byte array used mainly when there are too many
  75. arguments for other variables to hold, and all non-input and non-output bytes
  76. of "syswork" are subject to change by the kernel.  All input arguments placed
  77. in the "syswork" locations will be preserved unless otherwise indicated.
  78.  
  79. 2.2. SYSTEM VARIABLES
  80.  
  81. There are several non-zeropage variables for storing system status and return
  82. values:
  83.  
  84. SYMBOL          BYTES   DESCRIPTION
  85. ----------      -----   -----------
  86. errno               1   error number code returned by failed system calls
  87. aceID               2   proof that user program is running on top of ACE
  88. aceArgc             2   argument count for current process
  89. aceArgv             2   argument vector address for current process
  90. aceMemTop           2   highest address, plus one, that user prog can use
  91. aceShellPath      256   storage for search path for executable programs
  92. aceShellAlias     256   storage for shell command aliases
  93. aceCurDirName     128   storage for the current directory name
  94. aceExitData       256   storage for exit status from the last called prg
  95. aceDirentBuffer <next>  storage for directory entries read from disk
  96. aceDirentLength     -   really a constant: length in bytes of "aceDirentBuffer"
  97. aceDirentBytes      4   bytes in file (usually inexact)
  98. aceDirentDate       8   date of file in "YY:YY:MM:DD:HH:MM:SS:TW" format
  99. aceDirentType       4   type of file in null-terminated string
  100. aceDirentFlags      1   flags of file, "drwx*-et" format
  101. aceDirentUsage      1   more flags of file, "ulshm---" format
  102. aceDirentNameLen    1   length of name of file
  103. aceDirentName      17   null-terminated name of file
  104.  
  105. ERRNO: "errno" is used to return error codes from system calls.  When a system
  106. call ends in error, it sets the carry flag to "1", puts the error code in
  107. "errno", and returns to the user program, after undoing any system work
  108. completed at the time the error is encountered and aborting the operation.  An
  109. error code number is stored in binary in the single-byte "errno" location. The
  110. symbolic names for the possible error codes are given in the next section. If
  111. no error occurs in a system call, the carry flag will be cleared on return
  112. from the call.  Note that not all system calls can run into errors, so not all
  113. set the carry flag accordingly.
  114.  
  115. ID: "aceID" is a two-byte variable.  Its purpose is to allow user programs to
  116. be sure that they are executing on top of ACE.  The low byte (i.e., the first
  117. byte) must be equal to the symbolic constant "aceID1", and the high, "aceID2".
  118. This will allow ACE applications to inform idiot users that they cannot simply
  119. BOOT the program from BASIC, but rather they must run ACE first.
  120.  
  121. ARGC: "aceArgc" is a two-byte unsigned number.  It gives the number of
  122. arguments passed to the application by the program (usually the command shell)
  123. that called the application.  The first argument is always the name of the
  124. application program, so the count will always be at least one.  Other
  125. arguments are optional.
  126.  
  127. ARGV: "aceArgv" is a two-byte RAM0 pointer.  Pay attention.  This pointer
  128. points to the first entry of an array of two-byte pointers which point to the
  129. null-terminated strings that are the arguments passed to the application
  130. program by the caller.  (A null-terminated string is one that ends with a zero
  131. byte).  To find the address of the N-th argument to an application, multiply N
  132. by two, add the "aceArgv" contents to that, and fetch the pointer from that
  133. address.  In this scheme, the ever-present application name is the 0-th
  134. argument.  The argv[argc] element of the argument vector will always contain a
  135. value of $0000, a null pointer.
  136.  
  137. MEM-TOP: "aceMemTop" is a two-byte RAM0 pointer.  This points to one byte past
  138. the highest byte that the application program is allowed to use.  All
  139. application programs are loaded into memory at address "aceAppAddress" (next
  140. section), and all memory between the end of the progam code and "aceMemTop"
  141. can be used for temporary variables, file buffers, etc.  The main problem with
  142. this approach is that there are no guarantees about how much memory your
  143. application will get to play with.  Many applications, such as simple file
  144. utilities, can simply use all available memory for a file buffer, but other
  145. programs, such as a file compressor, may have much greater demand for "near"
  146. memory.
  147.  
  148. SHELL-PATH: "aceShellPath" is a 256-byte array of characters.  This stores the
  149. pathnames of directories to search through in order to find executable files.
  150. Each pathname is stored as a null-terminated string, and the list is
  151. terminated by an empty string (containing only the zero character).  This is
  152. intended to be used by the shell program, or any other program that is so
  153. inclined, to examine or alter the search path.  The search paths specified in
  154. the path page are global variables and are used by all programs that make the
  155. "exec" system call.  This mechanism for reading/altering the executable search
  156. path may be changed in the future.
  157.  
  158. SHELL-ALIAS: "aceShellAlias" is a 256-byte array of characters.  This stores
  159. the aliases to be used with the command shell.  An alias is a string that is
  160. substituted in the place of a command name on a shell command line whenever a
  161. certain command name comes up.  For example, you might specify if the user
  162. enters the command "list a:" that the command name "list" be string-replaced
  163. with "cls;xls -l".  Each alias is stored with the command name first, followed
  164. by an equals character ("="), followed by the string to substitute, followed
  165. by a zero.  The alias list is terminated by an empty string.  This mechanism
  166. may be extended in the future to allow multiple pages of aliases, or may be
  167. changed completely.
  168.  
  169. CUR-DIR-NAME: "aceCurDirName" is a 128-byte array of characters.  It contains
  170. the null-terminated string indicating the current directory.  The user is not
  171. supposed to modify this value, and the value will not always give a full
  172. pathname.  The implementation of this feature may need to change in future
  173. versions of ACE.
  174.  
  175. ACE-EXIT-DATA: "aceExitData" is a 256-byte array.  It is the 256-byte buffer
  176. allocated for user programs to give detailed return information upon exiting
  177. back to their parent program.  See the "exit" system call.  User programs are
  178. allowed to read and write this storage.  An example use of this feature would
  179. be a compiler program returning the line number and character position, and
  180. description of a compilation error to a text editor, so the editor can
  181. position the cursor and display the error message for user convenience.  The
  182. implementation of this feature may need to change in future versions of ACE.
  183.  
  184. DIRENT-BUFFER: "aceDirentBuffer" is a buffer used for storing directory
  185. information read with the "dirread" system call, and is "aceDirentLength"
  186. bytes long.  Only a single directory entry is (logically) read from disk at a
  187. time.  The individual fields of a read directory entry are accessed by the
  188. fields described next.  This field is also used for returning disk name
  189. information and the number of bytes free on a disk drive (see the "dirread"
  190. system call).
  191.  
  192. DIRENT-BYTES: "aceDirentBytes" is a four-byte (32-bit) unsigned field.  As
  193. always, the bytes are addressed from least significant to most significant.
  194. This field gives the number of bytes in the file.  Note that this value may
  195. not be exact, since Commodore decided to store sizes in disk blocks rather
  196. than bytes.  For devices that report only block counts (i.e., every disk
  197. device currently supported), the number of bytes returned is the number of
  198. blocks multiplied by 254.  This field, as well and the other dirent fields are
  199. absolute addresses, not offsets from aceDirentBuffer.
  200.  
  201. DIRENT-DATE: "aceDirentDate" is an eight-byte array of binary coded decimal
  202. values, stored from most significant digits to least significant.  The first
  203. byte contains the BCD century, the second the year, and so on, and the last
  204. byte contains the number of tenths of seconds in its most significant nybble
  205. and a code for the day-of-week in its least significant nybble.  Sunday has
  206. code 1, Monday 2, etc., Saturday 7, and a code of 0 means "unknown".  This is
  207. the standard format for all dates used in ACE.  This format is abstracted as
  208. "YY:YY:MM:DD:HH:MM:SS:TW".  For disk devices that don't support dates, this
  209. field will be set to all zeroes, which can be conveniently interpreted as the
  210. NULL date, negative infinity, or as the time that J.C. was a seven-year-old
  211. boy.
  212.  
  213. DIRENT-TYPE: "aceDirentType" is a three-character (four-byte) null-terminated
  214. string.  It indicates what type the file is, in lowercase PETSCII.  Standard
  215. types such as "SEQ" and "PRG" will be returned, as well and other
  216. possibilities for custom device drivers.
  217.  
  218. DIRENT-FLAGS: "aceDirentFlags" is a one-byte field that is interpreted as
  219. consisting of eight independent one-bit fields.  The abstract view of the
  220. fields is "drwx*-et".  "d" means that the item is a subdirectory (otherwise it
  221. is a regular file), "r" means the item is readable, "w" means the item is
  222. writable, and "x" means the item is executable.  The "x" option is really not
  223. supported currently.  "*" means the item is improperly closed (a "splat" file
  224. in Commodore-DOS terminology).  The "-" field is currently undefined.  "e"
  225. means that the value given in the "aceDirentBytes" field is actually exact,
  226. and "t" means the file should be interpreted as being a "text" file
  227. (otherwise, its type is either binary or unknown).  The bit fields are all
  228. booleans; a value of "1" means true, "0", false.  The "d" bit occupies the
  229. 128-bit position, etc.
  230.  
  231. DIRENT-USAGE: "aceDirentFlags" is a one-byte field very much like
  232. "aceDirentFlags".  The abstract view of the fields is "ulshm---".  "u"
  233. indicates whether the directory entry is used (current) or not (deleted).
  234. The directory system calls will not read a directory entry that is deleted, so
  235. you will never see this bit not set; it is used internally.  "l" indicates
  236. whether the directory entry is for an actual file (==0, normal) or a "link"
  237. (==1) to another file.  The "s" and "h" bits indicate which type a link is:
  238. "soft" or "hard", respectively.  These both work similarly to Unix hard and
  239. soft links.  The "m" flag indicates whether a file has been modified since
  240. the last time that a backup program cleared the "m" bit for the file, allowing
  241. incremental backups.
  242.  
  243. DIRENT-NAME-LEN: "aceDirentNameLen" is a one-byte number.  It gives the number
  244. of characters in the filename.  It is present for convenience.
  245.  
  246. DIRENT-NAME: "aceDirentName" is a 16-character (17-byte) null-terminated
  247. character string field.  It gives the name of the file or directory or disk.
  248. Filenames used with ACE are limited to 16 characters.
  249.  
  250. 2.3. SYSTEM CONSTANTS
  251.  
  252. There are several symbolic constants that are used with the ACE system
  253. interface:
  254.  
  255. SYMBOL                   DESCRIPTION
  256. -------------------      -------------------------
  257. aceAppAddress            the start address of applications
  258. aceID1                   the id characters used to identify ACE applications
  259. aceID2                   ...
  260. aceID3                   ...
  261. aceMemNull               the far memory type code used to indicate null ptrs
  262. aceMemREU                far mem type code for Ram Expansion Unit memory
  263. aceMemInternal           far mem type code for internal memory
  264. aceMemRLREU              far mem type code for REU memory accessed thru RAMLink
  265. aceMemRL                 far mem type code for direct-access RAMLink memory
  266. aceErrStopped            error code for syscall aborted by STOP key
  267. aceErrTooManyFiles       err: too many files already opened to open another
  268. aceErrFileOpen           err: don't know what this means
  269. aceErrFileNotOpen        err: the given file descriptor is not actually open
  270. aceErrFileNotFound       err: named file to open for reading does not exist
  271. aceErrDeviceNotPresent   err: the specified physical device is not online
  272. aceErrFileNotInput       err: file cannot be opened for reading
  273. aceErrFileNotOutput      err: file cannot be opened for writing
  274. aceErrMissingFilename    err: pathname component is the null string
  275. aceErrIllegalDevice      err: the specified device cannot do what you want
  276. aceErrWriteProtect       err: trying to write to a disk that is write-protected
  277. aceErrFileExists         err: trying to open for writing file that exists
  278. aceErrFileTypeMismatch   err: you specified the file type incorrectly
  279. aceErrNoChannel          err: too many open files on disk drive to open another
  280. aceErrInsufficientMemory err: ACE could not allocate the memory you requested
  281. aceErrOpenDirectory      err: you are trying to open a dir as if it were a file
  282. aceErrDiskOnlyOperation  err: trying to perform disk-only op on char device
  283. aceErrNullPointer        err: trying to dereference a null far pointer
  284. aceErrInvalidFreeParms   err: bad call to "pagefree": misaligned/wrong size
  285. aceErrFreeNotOwned       err: trying to free far memory you don't own
  286. aceErrInvalidWindowParms err: invalid window dimensions were given
  287. aceErrInvlaidConParms    err: invalid console parameters were given
  288. aceErrInvalidFileMode    err: opening a file for other-than "r","w", or "a"
  289. aceErrNotImplemented     err: system call or option is not (yet) implemented
  290. aceErrBloadTruncated     err: a bload operation stopped before exceeding limit
  291. aceErrPermissionDenied   err: attempt to read or write a file without perms
  292. stdin                    file descriptor reserved for stdin input stream
  293. stdout                   file descriptor reserved for stdout output stream
  294. stderr                   file descriptor reserved for stderr output stream
  295.  
  296. "aceAppAddress", as discussed before, is the address that application programs
  297. are loaded into memory at.  They must, of course, be compiled to execute
  298. starting at this address.
  299.  
  300. The "aceMem" group of constants are for use with the "pagealloc" system call,
  301. except for "aceMemNull", which may be used by application programs for
  302. indicating null far pointers.  The "pagealloc" call allows you to specify what
  303. types of memory you are willing to accept.  This is important because the
  304. difference types of memory have different performance characteristics.  ACE
  305. will try to give you the fastest memory that is available.  Ram Expansion Unit
  306. memory has startup and byte-transfer times of about 60 us (microseconds) and 1
  307. us, respectively.  This is the fastest type of far memory.  Internal memory
  308. has a startup time of 24 us and a byte-transfer time of between 7 and 14 us
  309. (depending on whether accessing RAM0 or RAM1+).  REU memory accessed through a
  310. RAMLink has a terrible startup time of 1000 us and a byte-transfer time of 2
  311. us.  Direct-access RAMLink memory has a startup time of 1000 us and a
  312. byte-transfer time of 16 us.  All these times are for the C128 in 2 MHz mode.
  313.  
  314. The "aceErr" group gives the error codes returned by system calls.  The error
  315. codes are returned in the "errno" variable.  Not all possible error codes from
  316. Commodore disk drives are covered, but the important ones are.  Finally, the
  317. "std" files group give the symbolic file descriptor identifiers of the default
  318. input, output, and error output file streams.
  319.  
  320. 2.4. SYSTEM CALLS
  321.  
  322. All system calls are called by setting up arguments in specified processor
  323. registers and memory locations, executing a JSR to the system call address,
  324. and pulling the return values out of processor registers and memory locations.
  325.  
  326. 2.4.1. FILE CALLS
  327.  
  328. NAME   :  open
  329. PURPOSE:  open a file
  330. ARGS   :  (zp) = pathname
  331.           .A   = file mode ("r", "w", or "a")
  332. RETURNS:  .A   = file descriptor number
  333.           .CS  = error occurred flag
  334. ALTERS :  .X, .Y, errno
  335.  
  336. Opens a file.  The name of the file is given by a pointer to a null-terminated
  337. string, and may contain device names and pathnames as specified in the ACE
  338. user documentation.  The file mode is a PETSCII character.  "r" means to open
  339. the file for reading, "w" means to open the file for writing, and "a" means to
  340. open the file for appending (writing, starting at the end of the file).  An
  341. error will be returned if you attempt to open for reading or appending a file
  342. that does not exist, or if you attempt to open for writing a file that does
  343. already exist.  If you wish to overwrite an existing file, you will have to
  344. call "remove" to delete the old version before opening the new version for
  345. writing.
  346.  
  347. The function returns a file descriptor number, which is a small unsigned
  348. integer that is used with other file calls to specify the file that has been
  349. opened.  File descriptors numbered 0, 1, and 2 are used for stdin, stdout, and
  350. stderr, respectively.  The file descriptor returned will be the minimum number
  351. that is not currently in use.  These numbers are system-wide (rather than
  352. local to a process as in Unix), and this has some implications for I/O
  353. redirection (see the "fdswap" call below).
  354.  
  355. Restrictions: only so many Kernal files allowed to be open on a disk device,
  356. and there is a system maximum of open files.  You will get a "too many files"
  357. error if you ever exceed this limit.  Also, because of the nature of
  358. Commodore-DOS, there may be even tighter restrictions on the number of files
  359. that can be simultaneously open on a single disk device, resulting in a "no
  360. channel" error.  Note that this call checks the status channel of Commodore
  361. disk drives on each open, so you don't have to (and should not anyway).
  362.  
  363. If the current program exits either by calling "exit" or simply by doing the
  364. last RTS, all files that were opened by the program and are still open will be
  365. automatically closed by the system before returning to the parent program.
  366.  
  367. NAME   :  close
  368. PURPOSE:  close an open file
  369. ARGS   :  .A   = File descriptor number
  370. RETURNS:  .CS  = error occurred flag
  371. ALTERS :  .A, .X, .Y, errno
  372.  
  373. Closes an open file.  Not much to say about this one.
  374.  
  375. NAME   :  read
  376. PURPOSE:  read data from an open file
  377. ARGS   :  .X   = File descriptor number
  378.           (zp) = pointer to buffer to store data into
  379.           .AY  = maximum number of bytes to read
  380. RETURNS:  .AY  = (zw) = number of bytes actually read in
  381.           .CS  = error occurred flag
  382.           .ZS  = EOF reached flag
  383. ALTERS :  .X, errno
  384.  
  385. Reads data from the current position of an open file.  Up to the specified
  386. maximum number of bytes will be read.  You should not give a maximum of zero
  387. bytes, or you may misinterpret an EOF (end of file).  The buffer must be at
  388. least the size of the maximum number of bytes to read.  The data are not
  389. interpreted in any way, so it is the programmer's responsibility to search for
  390. carriage return characters to locate lines of input, if he so desires.
  391. However, for the console the input is naturally divided up into lines, so each
  392. call will return an entire line of bytes if the buffer is large enough.  There
  393. are no guarantees about the number of bytes that will be returned, except that
  394. it will be between 1 and the buffer size.  So, if you wish to read a certain
  395. number of bytes, you may have to make multiple read calls.
  396.  
  397. The call returns the number of bytes read in both the .AY register pair and in
  398. (zw), for added convenience.  A return of zero bytes read means that the end
  399. of the file has been reached.  An attempt to read beyond the end of file will
  400. simply give another EOF return.  End of file is also returned in the .Z flag
  401. of the processor.
  402.  
  403. NAME   :  write
  404. PURPOSE:  write data to an open file
  405. ARGS   :  .X   = file descriptor number
  406.           (zp) = pointer to data to be written
  407.           .AY  = length of data to be written in bytes
  408. RETURNS:  .CS  = error occurred
  409. ALTERS :  .A, .X, .Y, errno
  410.  
  411. Writes data at the current position of an open file.  'Nuff said.
  412.  
  413. NAME   :  fastopen
  414. PURPOSE:  open a file for fast reading
  415. ARGS   :  (zp) = Name
  416.           .A   = file mode (must be "r")
  417. RETURNS:  .A   = file descriptor number
  418.           .CS  = error occurred flag
  419. ALTERS :  .X, .Y, errno
  420.  
  421. This performs the same function as the regular "open" call, except this style
  422. of file accessing will allow files to be read much faster than the other.  On
  423. devices that are so equipped, the "fastload" burst command is used (similar
  424. shortcuts may be possible with other devices too).  The drawback of this
  425. increased speed is that no other device I/O can take place while a file is
  426. opened for "fast" access, not even to other devices, except for output to the
  427. console.  Other files can be open, just not accessed.  You also cannot open
  428. more than one "fast" file at a time.  Interrupts will be disabled while a file
  429. is open for fast accessing, so the user cannot re-enable them, for technical
  430. reasons.  The arguments to this call are exactly the same as the regular
  431. "open" to make it easy to switch from using one to the other.  [Note: in
  432. Release #10, these "fast" calls are simply short-circuited to the regular
  433. file calls].
  434.  
  435. NAME   :  fastclose
  436. PURPOSE:  close the file that was opened for fast reading
  437. ARGS   :  .A   = File descriptor number
  438. RETURNS:  .CS  = error occurred flag
  439. ALTERS :  .A, .X, .Y, errno
  440.  
  441. Closes the file that was opened for fast reading.
  442.  
  443. NAME   :  fastread
  444. PURPOSE:  read data from the file opened for fast reading
  445. ARGS   :  .X   = File descriptor number
  446.           (zp) = pointer to buffer to store data into
  447.           .AY  = maximum number of bytes to read
  448. RETURNS:  .AY  = (zw) = number of bytes actually read in
  449.           .CS  = error occurred flag
  450.           .ZS  = EOF reached flag
  451. ALTERS :  .X, errno
  452.  
  453. Read data from the (one) file that is currently opened for "fast" reading. The
  454. arguments and semantics are equivalent to the regular "read" call.
  455.  
  456. NAME   :  bload
  457. PURPOSE:  binary load
  458. ARGS   :  (zp) = pathname
  459.           .AY  = address to load file
  460.           (zw) = highest address that file may occupy, plus one
  461. RETURNS:  .AY  = end address of load, plus one
  462.           .CS  = error occurred flag
  463. ALTERS :  .X, errno
  464.  
  465. Binary-load a file directly into memory.  If the file will not fit into the
  466. specified space, an error will be returned and the load truncated if the
  467. device supports truncation; otherwise, important data may be overwritten.
  468.  
  469. NAME   :  remove
  470. PURPOSE:  delete a file
  471. ARGS   :  (zp) = pathname
  472. RETURNS:  .CS  = error occurred flag
  473. ALTERS :  .A, .X, .Y, errno
  474.  
  475. Delete the named file.
  476.  
  477. NAME   :  rename
  478. PURPOSE:  rename a file or directory
  479. ARGS   :  (zp) = old filename
  480.           (zw) = new filename
  481. RETURNS:  .CS  = error occurred flag
  482. ALTERS :  .A, .X, .Y, errno
  483.  
  484. Renames a file or directory.  If a file with the new name already exists, then
  485. the operation will be aborted and a "file exists" error will be returned.  On
  486. most devices, the file to be renamed must be in the current directory and the
  487. new name may not include any path, just a filename.
  488.  
  489. NAME   :  devinfo
  490. PURPOSE:  give information about device
  491. ARGS   :  .X   = file descriptor number
  492. RETURNS:  .A   = device type code (0=console, 1=char-dev, 2=disk-dev)
  493.           .X   = number of columns on device
  494.           .Y   = number of rows per "page" of device
  495.           .CS  = error occurred flag
  496. ALTERS :  errno
  497.  
  498. This call returns information about the device of an open file.  There are
  499. four possible values for the device type code: 0==console,
  500. 1==character-oriented device, and 2==disk device.  The number of rows and
  501. columns per "page" of the device are also returned.  For the console, this
  502. will be the current window size.  For a character-oriented device, it will be
  503. the natural size (typically 80 columns by 66 rows), and for a disk, it will be
  504. 40 columns in 64 mode or 80 columns in 128 mode, both by 66 rows.
  505.  
  506. NAME   :  fdswap
  507. PURPOSE:  swap two file descriptor numbers
  508. ARGS   :  .X   = first file descriptor number
  509.           .Y   = second file descriptor number
  510. RETURNS:  .CS  = error occurred flag
  511. ALTERS :  .A, .X, .Y, errno
  512.  
  513. This call swaps meanings of two file descriptor numbers.  The file descriptors
  514. may be either in use or not use when the call is made.  This call is intended
  515. to be used to redirect the stdin, stdout, and stderr file streams.  To do
  516. this, simply open the new file intended to be, for example, stdout, and swap
  517. the file descriptor number returned from the open with file descriptor number
  518. 1 (stdout).  Poof.  Then call your subroutine or external program, and on
  519. return, swap the two file descriptors back, and close the redirection file.
  520.  
  521. 2.4.2. DIRECTORY CALLS
  522.  
  523. NAME   :  diropen
  524. PURPOSE:  open a directory for scanning its directory entries
  525. ARGS   :  (zp) = directory pathname
  526. RETURNS:  .A   = file descriptor number
  527.           .CS  = error occurred flag
  528. ALTERS :  .X, .Y, errno
  529.  
  530. This call opens a directory for reading its entries.  It returns a "file"
  531. descriptor number to you to use for reading successive directory entires with
  532. the "dirread" call.  The pathname that you give to this call must be a proper
  533. directory name like "a:" or "c:2//c64/games/:", ending with a colon character.
  534. You can have directories from multiple devices open for reading at one time,
  535. but you cannot have the directory of one device open multiple times.  Also
  536. note that you cannot pass wildcards to this call; you will receive the entire
  537. directory listing.
  538.  
  539. NAME   :  dirclose
  540. PURPOSE:  close a directory opened for scanning
  541. ARGS   :  .A   = file descriptor number
  542. RETURNS:  .CS  = error occurred flag
  543. ALTERS :  .A, .X, .Y, errno
  544.  
  545. Closes a directory that is open for reading.  You can make this call at any
  546. point while scanning a directory; you do not have to finish scanning an entire
  547. directory first.
  548.  
  549. NAME   :  dirread
  550. PURPOSE:  read the next directory entry from an open directory
  551. ARGS   :  .X   = file descriptor number
  552. RETURNS:  .Z   = end of directory flag
  553.           .CS  = error occurred flag
  554.           aceDirentBuffer = new directory entry data
  555. ALTERS :  .A, .X, .Y, errno
  556.  
  557. Reads the next directory entry from the specified open directory into the
  558. system interface global variable "aceDirentBuffer" described earlier.  After
  559. opening a directory for reading, the first time you call this routine, you
  560. will receive the name of the disk (or directory).  The "aceDirentNameLen" and
  561. "aceDirentName" fields are the only ones that will contain information; the
  562. rest of the fields should be ignored.
  563.  
  564. Each subsequent call to this routine will return the next directory entry in
  565. the directory.  All of the "dirent" fields will be valid for these.
  566.  
  567. Then, after all directory entries have been read through, the last call will
  568. return a directory entry with a null (zero-length) name.  This corresponds to
  569. the "blocks free" line in a Commodore disk directory listing.  The
  570. "aceDirentBytes" field for this last entry will be set to the number of bytes
  571. available for storage on the disk.  On a Commodore disk drive, this will be
  572. the number of blocks free multiplied by 254.  After reading this last entry,
  573. you should close the directory.
  574.  
  575. At any time, if something bizarre happens to the listing from the disk that is
  576. not considered an error (I don't actually know if this is possible or not),
  577. then the .Z flag will be set, indicating the abrupt ending of the directory
  578. listing.
  579.  
  580. NAME   :  isdir
  581. PURPOSE:  determine whether the given pathname is for a file or a directory
  582. ARGS   :  (zp) = pathname
  583. RETURNS:  .A   = device identifier
  584.           .X   = is a disk device flag
  585.           .Y   = is a directory flag
  586.           .CS  = error occurred flag
  587. ALTERS :  errno
  588.  
  589. Given a properly formatted directoryname or filename, this routine will return
  590. whether the name is for a file or a directory, whether the device of the file
  591. or directory is a disk or character device, and the system identifier for the
  592. device.  The two flags return $FF for true and $00 for false.  The device
  593. identifier is superfluous for now, but a "devinfo" call may be added later.
  594. Note that this file does not indicate whether the file/directory actually
  595. exists or not.
  596.  
  597. NAME   :  chdir
  598. PURPOSE:  change the current working directory
  599. ARGS   :  (zp) = new directory pathname
  600. RETURNS:  .CS  = error occurred flag
  601. ALTERS :  .A, .X, .Y, errno
  602.  
  603. Changes the current working directory to the named directory.  Too bad the
  604. Commodore Kernal doesn't have a similar call.  Unlike the "cd" shell command,
  605. the argument has to be a properly formatted directory name.  Note that only
  606. directories in native partitions on CMD devices are supported by this command;
  607. the 1581's crummy idea of partitions is not supported.
  608.  
  609. NAME   :  cdhome
  610. PURPOSE:  change the current working directory back to the "home" directory
  611. ARGS   :  <none>
  612. RETURNS:  .CS  = error occurred flag
  613. ALTERS :  .A, .X, .Y, errno
  614.  
  615. Changes the current working directory back to the "home" directory that is
  616. defined in the "config.sys" file as the initial directory.
  617.  
  618. NAME   :  mkdir
  619. PURPOSE:  create a new directory
  620. ARGS   :  (zp) = pathname of new directory
  621. RETURNS:  .CS  = error occurred flag
  622. ALTERS :  .A, .X, .Y, errno
  623.  
  624. Creates a new directory.  I'm not sure, but I think that the current directory
  625. has to be the parent directory of the directory you want to create.  This may
  626. be required by CMD devices, which will be the lowest common denominator for
  627. directory support.  [Note: in Release #10, this call only accepts a "flat"
  628. directory name].
  629.  
  630. NAME   :  rmdir
  631. PURPOSE:  delete an empty existing directory
  632. ARGS   :  (zp) = pathname of empty directory to remove
  633. RETURNS:  .CS  = error occurred flag
  634. ALTERS :  .A, .X, .Y, errno
  635.  
  636. Deletes an existing directory.  The directory must be empty (have no directory
  637. entries) in order for this command to succeed.  Again, I am pretty sure that
  638. you have to be "in" the parent directory of the one to be deleted, since this
  639. is probably required by CMD devices.  [Note: in Release #10, this call only
  640. accepts a "flat" directory name].
  641.  
  642. 2.4.3. MEMORY CALLS
  643.  
  644. The calls given in this section are to be used for accessing "far" memory in
  645. ACE, which includes all REU, RAMLink, RAM1 and above, and sections of RAM0
  646. that are not in the application program area.  Applications are not allowed to
  647. access "far" memory directly, because the practice of bypassing the operating
  648. system would undoubtedly lead to problems (can you say "MS-DOS"?).
  649.  
  650. All of these calls use a 32-bit pointer that is stored in the zero-page
  651. argument field "mp" (memory pointer).  This field is to be interpreted as
  652. consisting of low and high words.  The low word, which of course come first,
  653. is the offset into the memory "bank" that is contained in the high word. Users
  654. may assume that offsets within a bank are continuous, so operations like
  655. addition may be performed without fear on offsets, to access subfields of a
  656. structure, for example.  You may not, however, make any interpretation of the
  657. bank word.  An application should only access far memory that it has allocated
  658. for itself via the "pagealloc" call.
  659.  
  660. NAME   :  zpload
  661. PURPOSE:  load zeropage storage from far memory
  662. ARGS   :  [mp] = source far memory pointer
  663.           .X   = destination zero-page address
  664.           .Y   = transfer length
  665. RETURNS:  .CS  = error occurred flag
  666. ALTERS :  .A, .X, .Y, errno
  667.  
  668. Load zero-page locations with the contents of far memory.  "mp", of course,
  669. gives the address of the first byte of far memory to be retrieved.  The X
  670. register is loaded with the first address of the storage space for the data on
  671. zero page.  It must be in the application zero-page space.  The Y register
  672. holds the number of bytes to be transferred, which, considering that transfers
  673. must be to the application zero-page storage, must be 126 bytes or less.  This
  674. routine will return a "reference through null pointer" if [mp] contains a null
  675. pointer.
  676.  
  677. NAME   :  zpstore
  678. PURPOSE:  store zeropage data to far memory
  679. ARGS   :  .X   = source zero-page address
  680.           [mp] = destination far memory pointer
  681.           .Y   = transfer length
  682. RETURNS:  .CS  = error occurred flag
  683. ALTERS :  .A, .X, .Y, errno
  684.  
  685. This routine is the complement of "zpload"; this transfers data from zero page
  686. to far memory.  The arguments and restrictions are the same as "zpload".
  687.  
  688. NAME   :  fetch
  689. PURPOSE:  load near RAM0 storage from far memory
  690. ARGS   :  [mp] = source far memory pointer
  691.           (zp) = destination RAM0 pointer
  692.           .AY  = transfer length
  693. RETURNS:  .CS  = error occurred flag
  694. ALTERS :  .A, .X, .Y, errno
  695.  
  696. This routine will fetch up to 64K of data from far memory into RAM0 memory
  697. where it can be accessed directly by the processor.  The arguments should
  698. mostly speak for themselves.  You should not fetch into RAM0 memory that is
  699. not specifically allocated to the application.  You will get an error if you
  700. try to use a null far pointer.
  701.  
  702. NAME   :  stash
  703. PURPOSE:  store near RAM0 data to far memory
  704. ARGS   :  (zp) = source RAM0 pointer
  705.           [mp] = destination far memory pointer
  706.           .AY  = transfer length
  707. RETURNS:  .CS  = error occurred flag
  708. ALTERS :  .A, .X, .Y, errno
  709.  
  710. This is the complement of "fetch" and operates analogously, except that it
  711. transfers data from RAM0 to far memory.
  712.  
  713. NAME   :  pagealloc
  714. PURPOSE:  allocate pages of far memory to current process
  715. ARGS   :  .A   = requested number of pages to be allocated
  716.           .X   = starting "type" of memory to search
  717.           .Y   = ending "type" of memory to search, inclusive
  718. RETURNS:  [mp] = far memory pointer to start of allocated memory
  719.           .CS  = error occurred flag
  720. ALTERS :  .A, .X, .Y, errno
  721.  
  722. This routine allocates a given number of contiguous far-memory pages for use
  723. by the application, and returns a pointer to the first byte of the first page.
  724. On calling, the accumulator contains the number of pages to allocate (a page
  725. is 256 contiguous bytes aligned on a 256-byte address (i.e., the low byte of a
  726. page address is all zeros)).
  727.  
  728. The X and Y registers contain the start and end "types" of far memory to
  729. search for the required allocation.  The possible types are mentioned in the
  730. System Constants section.  The numeric values for the "aceMem" constants are
  731. arranged in order of accessing speed.  So, if your application has speed
  732. requirements that dictate, for example, that RAMLink memory should not be
  733. used, then you would call "pagealloc" with a search range of .X=0 to
  734. .Y=aceMemInternal.  If you wanted to say you are willing to accept any memory
  735. the system can give to you, you would specify .X=0 to .Y=255.  The values of 0
  736. and 255 will be converted to the fastest and slowest memory available.  ACE
  737. will give you the fastest type of memory, from what you specify as acceptable,
  738. that it can.  If you had an application that you didn't want to waste the
  739. high-speed memory on, you could first call "pagealloc" asking for slow memory,
  740. such as .X=aceMemRLREU to .Y=255, and if there is none of that type of memory
  741. left, make another call with .X=0 to .Y=aceMemRLREU-1.
  742.  
  743. This routine will then search its available free memory for a chunk fitting
  744. your specifications.  If it cannot find one, the routine will return a
  745. "insufficient memory" error and a null pointer.  Note that this error may
  746. occur if there is actually the correct amount of memory free but just not in a
  747. big enough contiguous chunk.  If successful, this routine will return in "mp"
  748. a pointer to the first byte of the first page of the allocated memory.
  749.  
  750. If you call a subprogram with the "exec" call while the current program is
  751. holding far memory, that far memory will be kept allocated to your program and
  752. will be safe while the child program is executing.  If you don't deallocate
  753. the memory with "pagefree" before exiting back to your parent program, then
  754. the system will automatically deallocate all memory allocated to you.  So,
  755. have no fear about calling "exit" if you are in the middle of complicated far
  756. memory manipulation when a fatal error condition is discovered and you don't
  757. feel like figuring out what memory your program owns and deallocating it.
  758.  
  759. Some applications will want to have the most amount of memory to work with,
  760. and if there is free space in the application program area that the program is
  761. not using directly, then you may want to use that as "far" memory.  To do
  762. this, you will need to write your own stub routines that manage page
  763. allocation and deallocation requests to the near memory, and calls the
  764. "pagealloc" and "pagefree" routines to manage the far memory.  The "sort"
  765. program distributed with ACE does this.  Please note that you CANNOT simply
  766. free the unused memory of the application program area and expect the system
  767. to manage it.  Bad stuff would happen.
  768.  
  769. Some applications will want to have a byte-oriented memory allocation service
  770. rather than a page-oriented service.  You can build a byte-oriented service on
  771. top of the page-oriented service in your application programs that manage
  772. memory for the application and ask the system for pages whenever more memory
  773. is required by the application.  Note that this still means that allocated
  774. memory will be freed automatically when an application exits.  The "sort"
  775. program implements this byte-oriented service, so you can check its source
  776. code to see how this is done (or to simply cut and paste the code into your
  777. own program).
  778.  
  779. NAME   :  pagefree
  780. PURPOSE:  free pages of far memory allocated to current process
  781. ARGS   :  [mp] = far memory pointer to start of memory to be freed
  782.           .A   = number of pages to be freed
  783. RETURNS:  .CS  = error occurred flag
  784. ALTERS :  [mp], .A, .X, .Y, errno
  785.  
  786. This deallocates memory that was allocated to a process by using the
  787. "pagealloc" system call.  You will get an error return if you try to
  788. deallocate memory that you don't own.
  789.  
  790. 2.4.4. SCREEN CONTROL CALLS
  791.  
  792. This section describes the system calls that are available to application
  793. programmers for full-screen applications.  These calls are intended to be
  794. general enough to handle different screen hardware (the VIC and VDC chips and
  795. a VIC soft-80-column bitmap screen, and possibly others).  These calls are
  796. also designed to be efficient as possible, to discourage progammers from
  797. attempting to bypass using them.  Bypassing these calls would be a bad thing.
  798.  
  799. The calls are designed around the C-128/PET concept of a window.  There is
  800. only one active window on the display at a time, which may be is large as the
  801. entire screen or as small as 1x1 character cells.  This window is very cheap
  802. to setup and tear down.  An application can have multiple windows on the
  803. screen by switching the active window around.
  804.  
  805. In the calls below, all mention of "sw" in the arguments and return values
  806. refer to the "syswork" array.  For many calls, there is a "char/color/
  807. high-attribute" argument.  This argument determines which parts of a screen
  808. location will be modified.  There are three components to each screen
  809. location: the character code, the color code, and the high-attributes.  The
  810. character code is exactly the same as the PETSCII code for the character that
  811. you want to display (unlike the screen-code arrangement that Commodore chose).
  812. There are 128 individual characters in the normal PETSCII positions, and 128
  813. reversed images of the characters in the most sensible other positions.  The
  814. codes are as follows:
  815.  
  816. CODES (hex)   DESCRIPTION
  817. -----------   -----------
  818. $00-$1f       reverse lowercase letters
  819. $20-$3f       digits and punctuation
  820. $40-$5f       lowercase letters
  821. $60-$7f       reverse graphics characters
  822. $80-$9f       reverse uppercase letters
  823. $a0-$bf       graphics characters
  824. $c0-$df       uppercase letters
  825. $e0-$ef       reverse digits and punctuation
  826.  
  827. There are sixteen color codes, occupying the lower four bits of the color
  828. value.  These are RGBI codes, as follows:
  829.  
  830. CODE(dec)   (hex)   (bin)   DESCRIPTION
  831. ---------   -----   -rgbi   -----------
  832.         0      $0   %0000   black
  833.         1      $1   %0001   dark grey
  834.         2      $2   %0010   blue
  835.         3      $3   %0011   light blue
  836.         4      $4   %0100   green
  837.         5      $5   %0101   light green
  838.         6      $6   %0110   dark cyan on VDC, medium grey on VIC-II
  839.         7      $7   %0111   cyan
  840.         8      $8   %1000   red
  841.         9      $9   %1001   light red
  842.        10      $a   %1010   purple
  843.        11      $b   %1011   light purple on VDC, orange on VIC-II
  844.        12      $c   %1100   brown
  845.        13      $d   %1101   yellow
  846.        14      $e   %1110   light grey
  847.        15      $f   %1111   white
  848.  
  849. Finally, there are the high-attribute bits.  These occupy the four most
  850. significant bits of the color value.  Depending on the type of display (VIC
  851. text, VDC text, or VIC/VDC bitmap), these bits have one of three meanings:
  852. character attributes, background character color, or no effect.  Thus, care
  853. must be taken in using these bits; they will have different effects on
  854. different displays.  The background color codes are the same as the foreground
  855. color codes listed above.  The character attributes have the following
  856. meanings:
  857.  
  858. BIT VALUE   (dec)   (hex)   DESCRIPTION
  859. -avub----   -----   -----   -----------
  860. %10000000     128     $80   alternate characterset (italic)
  861. %01000000      64     $40   reverse character
  862. %00100000      32     $20   underline
  863. %00010000      16     $10   blink
  864.  
  865. These values are additive (or, should I say, "or-ative"); you can use any
  866. combination of them at one time.  Normally, you may wish to leave the
  867. high-attribute bits alone, unless you take the values to give them from the
  868. color palettes (next section).  To specify which of you wish to have changed,
  869. set bits in the "char/color/high-attribute" argument to system calls.  The
  870. flags have the following values.  They are or-ative as well:
  871.  
  872. BIT VALUE   (dec)   (hex)   DESCRIPTION
  873. -cah-----   -----   -----   -----------
  874. %10000000     128     $80   modify character
  875. %01000000      64     $40   modify color
  876. %00100000      32     $20   modify high-attribute bits
  877.  
  878. The screen calls that deal with placing characters on the screen refer to
  879. screen locations using absolute addresses of locations in screen memory.  This
  880. scheme is used for increased efficiency.  You can obtain information about the
  881. absolute screen address of the top left-hand corner of the current window and
  882. the number of screen addresses between successive rows, to figure out screen
  883. addresses for your applications.  For added convenience, there is a call which
  884. will accept row and column numbers and return the corresponding absolute
  885. screen address.  Each successive column of a row has an absolute screen
  886. address that is 1 higher than the previous, for all displays.
  887.  
  888. The screen-control system calls are as follows:
  889.  
  890. NAME   :  winmax
  891. PURPOSE:  set window to maximum size
  892. ARGS   :  <none>
  893. RETURNS:  <none>
  894. ALTERS :  .A, .X, .Y
  895.  
  896. Sets the current window to cover the entire screen.
  897.  
  898. NAME   :  winclear
  899. PURPOSE:  clear window
  900. ARGS   :  .A   = char/color/high-attribute modification flags
  901.           .X   = character fill value
  902.           .Y   = color fill value
  903. RETURNS:  <none>
  904. ALTERS :  .A, .X, .Y
  905.  
  906. This call "clears" the current window by filling it with the character/color
  907. you specify.  You can use the char/color/hi-attr to limit what gets cleared.
  908.  
  909. NAME   :  winset
  910. PURPOSE:  set dimensions of window
  911. ARGS   :  .A   = number of rows in window
  912.           .X   = number of columns in window
  913.           sw+0 = absolute screen row of top left corner of window
  914.           sw+1 = absolute screen column of top left corner of window
  915. RETURNS:  .CS  = error occurred flag
  916. ALTERS :  .A, .X, .Y, errno
  917.  
  918. Sets the current window to the size you specify.  You will get an error return
  919. if the window will not fit on the screen or of it does not contain at least
  920. one character.
  921.  
  922. NAME   :  winsize
  923. PURPOSE:  return dimensions of window
  924. ARGS   :  <none>
  925. RETURNS:  .A   = number of rows in window
  926.           .X   = number of columns in window
  927.           sw+0 = absolute screen row of top left corner of window
  928.           sw+1 = absolute screen column of top left corner of window
  929.          (sw+2)= screen address of top left corner
  930.          (sw+4)= screen address increment between successive rows on screen
  931. ALTERS :  <none>
  932.  
  933. Returns information about the current window.
  934.  
  935. NAME   :  winput
  936. PURPOSE:  put characters and color onto screen
  937. ARGS   : (sw+0)= absolute screen address to start putting data at
  938.          (sw+2)= character string pointer
  939.           .X   = length of character string
  940.           .Y   = color
  941.           .A   = char/color/high-attribute modification flags
  942.           sw+4 = fill character
  943.           sw+5 = total field length
  944. RETURNS:  <none>
  945. ALTERS :  .A, .X, .Y
  946.  
  947. Puts text onto the screen.  The output region is given by the absolute
  948. starting screen address and the total field length.  This region must be
  949. contained on one line of the current window, or bad things will happen.  A
  950. pointer to the characters to be printed is given, as well as the length of the
  951. character array.  Control characters in this string are ignored; they are
  952. poked literally onto the screen, including the null character.  The length of
  953. the character string must be less than or equal to the total length of the
  954. field.  Remaining spaces in the field will be filled in with the "fill
  955. character".
  956.  
  957. The color of the total field length will be filled in with "color".  You can
  958. use the "char/color/hi-attr" modification flags to specify what is to be
  959. changed.  If you were to, for example, specify that the colors of the field
  960. are not to be changed, then the call would execute faster.
  961.  
  962. NAME   :  wincolor
  963. PURPOSE:  set screen and border colors
  964. ARGS   :  .X   = new RGBI screen color
  965.           .Y   = new RGBI border color
  966.           .A   = which colors to change ($80=screen + $40=border)
  967. RETURNS:  .X   = resulting RGBI screen color
  968.           .Y   = resulting RGBI border color
  969. ALTERS :  .A
  970.  
  971. Sets the color of the screen and border.  You may optionally set one, the
  972. other, both, or neither.  The resulting colors for colors changed, and the
  973. existing colors for colors unchaned will be returned.  Note that not all
  974. screens have an adjustable color, so the border argument may be ignored.
  975.  
  976. NAME   :  winpos
  977. PURPOSE:  return screen address of given row and col
  978. ARGS   :  .A   = row
  979.           .X   = column
  980. RETURNS: (sw+0)= screen memory address of position
  981. ALTERS :  .A, .X, .Y
  982.  
  983. Given a row and column in the current window, returns the corresponding
  984. absolute screen memory location for use with other calls.  No errors are
  985. returned, so garbage in, garbage out.
  986.  
  987. NAME   :  wincursor
  988. PURPOSE:  activate/deactivate cursor
  989. ARGS   : (sw+0)= screen address to place cursor
  990.           .A   = enable flag ($ff=cursor-on / $00=cursor-off)
  991.           .Y   = color to show cursor in
  992. RETURNS:  <none>
  993. ALTERS :  .A, .X, .Y
  994.  
  995. Displays or undisplays the cursor at the given screen address.  This call
  996. returns immediately in either case.  No errors are returned.  Do not display
  997. anything in or scroll the window while the cursor is being displayed, do not
  998. display the cursor twice, and do not undisplay the cursor twice in a row or
  999. bad things will happen.  Also, make sure you give the same address when
  1000. undisplaying the cursor as you did when displaying the cursor.  When the
  1001. system starts, the cursor will be in its undisplayed state (duh!).  You also
  1002. get to specify the color you want the cursor to be shown in.  The
  1003. high-attribute bits of this color are ignored.
  1004.  
  1005. NAME   :  winscroll
  1006. PURPOSE:  scroll window
  1007. ARGS   :  .A   = flags: char/color/hi-attr + $08=up + $04=down
  1008.           .X   = number of rows to scroll up/down
  1009.           sw+4 = fill character
  1010.           .Y   = fill color
  1011. RETURNS:  <none>
  1012. ALTERS :  .A, .X, .Y
  1013.  
  1014. Scrolls the contents of the current window up or down.  You can scroll any
  1015. number of rows at a time.  After scrolling, the bottom (or top) rows will be
  1016. filled with the fill character and color.  You can limit whether the
  1017. characters and/or colors are to be scrolled by using the "flags" byte in the
  1018. usual way.  Scrolling only the characters, for example, will be twice as fast
  1019. as scrolling both characters and attributes.  Whether to scroll up or down is
  1020. specified also using bits in the "flags" field, as indicated in the input
  1021. arguments above.  You can specify scrolling in more than one way, and the
  1022. result will be to scroll in each specified direction in turn, in the order up,
  1023. then down.  In the future, scrolling left and right may be added to this call.
  1024. [Note: in Release #10, scrolling the screen downward is not implemented.]
  1025.  
  1026. 2.4.5. CONSOLE CALLS
  1027.  
  1028. The calls in this section refer to the system "console", which includes the
  1029. screen and keyboard.  The screen-related calls are at a higher level than the
  1030. calls in the previous section.
  1031.  
  1032. NAME   :  conread
  1033. PURPOSE:  read input line from console
  1034. ARGS   :  (zp) = pointer to buffer to store data into
  1035.           .AY  = maximum number of bytes to read
  1036. RETURNS:  .AY  = (zw) = number of bytes actually read in
  1037.           .ZS  = EOF reached flag
  1038. ALTERS :  .X
  1039.  
  1040. Same as the "read" system call, except this always reads from the console, and
  1041. there are no errors.
  1042.  
  1043. NAME   :  conwrite
  1044. PURPOSE:  write data to console
  1045. ARGS   :  (zp) = data to print
  1046.           .AY  = bytes of data to print
  1047. RETURNS:  <none>
  1048. ALTERS :  .A, .X, .Y, errno
  1049.  
  1050. Same as the "write" system call, except this always writes to the console, and
  1051. no errors are possible.
  1052.  
  1053. NAME   :  conputchar
  1054. PURPOSE:  write character to console
  1055. ARGS   :  .A   = character
  1056. RETURNS:  <none>
  1057. ALTERS :  .A, .X, .Y, errno
  1058.  
  1059. Write a single character to the console.  Control characters are interpreted
  1060. as per usual.  The control characters are as follows:
  1061.  
  1062. CODE(hex)   CODE(dec)   NAME   DESCRIPTION
  1063. ---------   ---------   ----   -----------
  1064. $07         7           BEL    ring the bell
  1065. $09         9           TAB    move cursor to next 8-char tab stop
  1066. $0a         10          LF     move cursor to beginning of current line
  1067. $0d         13          CR     go to start of next line
  1068. $14         20          BS     non-destructive backspace
  1069. $93         147         CLR    clear the screen
  1070.  
  1071. NAME   :  conputlit
  1072. PURPOSE:  write literal character to console
  1073. ARGS   :  .A   = character
  1074. RETURNS:  <none>
  1075. ALTERS :  .A, .X, .Y, errno
  1076.  
  1077. Same as the "conputchar" system call, except that control characters are not
  1078. interpreted.
  1079.  
  1080. NAME   :  stopkey
  1081. PURPOSE:  check if stop key is being held down
  1082. ARGS   :  <none>
  1083. RETURNS:  .CS  = stop key pressed
  1084. ALTERS :  .A, .X, .Y, errno
  1085.  
  1086. Indicates whether the STOP (RUN/STOP) key is currently being held down by the
  1087. user.  If so, carry flag is set on return (and clear if not).  If the stop key
  1088. is discovered to be pressed by this call, then the keyboard buffer will also
  1089. be cleared.
  1090.  
  1091. NAME   :  getkey
  1092. PURPOSE:  get a key code from the keyboard buffer
  1093. ARGS   :  <none>
  1094. RETURNS:  .A   = keyboard character
  1095. ALTERS :  .X, .Y
  1096.  
  1097. Waits for the user to type a key (or takes a previous keystroke from the
  1098. keyboard buffer).  Regular characters are returned in their regular PETSCII
  1099. codes, but there are many special control keystrokes.  I still haven't figured
  1100. out what all of the special codes should be, but all 256 possible character
  1101. values will be covered.  Special codes like "page up", etc. should help in
  1102. standardizing control keystrokes for applications.  Note that these
  1103. definitions of keycodes is only suggested; your full-screen application can
  1104. interpret them however it wants.  The key code is returned in the accumulator.
  1105. No errors are possible.
  1106.  
  1107. The tables below summarize the meanings of the various key codes.  Not all of
  1108. the C64 keys have been decided yet.  Note that the keys for "@" to "_", used
  1109. in association with shifting keys, are "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_".
  1110. "CT" means Control, "SH" means Shift, "AL" means Alternate, and "CO" means
  1111. Commodore.  I haven't decided how to define Alternate on a C64 yet.
  1112.  
  1113. CODE(s)   C128 KEY(s)    C64 KEY(s)     DESCRIPTION
  1114. -------   ------------   ------------   -----------
  1115. $20-$3f   SPACE to "?"   SPACE to "?"   Regular numbers and punctuation
  1116. $40-$5f   "@" to "_"     "@" to "_"     Regular lowercase letters
  1117. $60-$7f   AL-@ to AL-_   <undecided>    Alternate keys
  1118. $a0-$bf   CO-@ to CO-_   CO-@ to CO-_   Commodore keys
  1119. $c0-$df   "`" to HOUSE   "`" to HOUSE   Regular uppercase letters
  1120. $e0-$ef   CT-@ to CT-_   CT-@ to CT-_   Control keys
  1121.  
  1122. CODE(s)   C128 KEY(s)    C64 KEY(s)     DESCRIPTION
  1123. -------   ------------   ------------   -----------
  1124. $00       <none>         <none>         <cannot be generated>
  1125. $01       CT-RETURN      CT-RETURN      EOF
  1126. $02       SH-TAB         <undecided>    Backtab
  1127. $03       STOP           STOP           Stop some operations
  1128. $04       SH-HELP        <undecided>    Context-insensitive help
  1129. $05       CT-2           CT-2           White
  1130. $06       SH-LEFT        <undecided>    Word left
  1131. $07       SH-LINEFEED    <undecided>    <undecided>
  1132. $08       CO-DEL         CO-DEL         Rubout character under cursor
  1133. $09       TAB            <undecided>    Tab
  1134. $0a       LINEFEED       <undecided>    Linefeed
  1135. $0b       SH-RIGHT       <undecided>    Word right
  1136. $0c       CO-UP          <undecided>    Goto top of document
  1137. $0d       RETURN         RETURN         Return
  1138. $0e       SH-ESCAPE      <undecided>    <undecided>
  1139. $0f       CO-DOWN        <undecided>    Goto bottom of document
  1140. $10       CO-LEFT        <undecided>    Goto beginning of line
  1141. $11       DOWN           DOWN           Cursor down
  1142. $12       CT-9           CT-9           Rvs
  1143. $13       HOME           HOME           Home
  1144. $14       DEL            DEL            Backspace
  1145. $15       CO-RIGHT       <undecided>    Goto end of line
  1146. $16       CT-UP          <undecided>    Page up
  1147. $17       CT-DOWN        <undecided>    Page down
  1148. $18       CT-TAB         <undecided>    <undecided>
  1149. $19       CT-LEFT        <undecided>    Page left
  1150. $1a       CT-RIGHT       <undecided>    Page right
  1151. $1b       ESCAPE         <undecided>    Escape
  1152. $1c       CT-3           CT-3           Red
  1153. $1d       RIGHT          RIGHT          Cursor right
  1154. $1e       CT-6           CT-6           Green
  1155. $1f       CT-7           CT-7           Blue
  1156.  
  1157. CODE(s)   C128 KEY(s)    C64 KEY(s)     DESCRIPTION
  1158. -------   ------------   ------------   -----------
  1159. $80       CT-F1          CT-F1          Function key 9
  1160. $81       CO-1           CO-1           Orange/Purple(?)
  1161. $82       CT-F3          CT-F3          Function key 10
  1162. $83       SH-STOP        SH-STOP        <undecided>
  1163. $84       HELP           <undecided>    Context-sensitive help
  1164. $85       F1             F1             Function key 1
  1165. $86       F3             F3             Function key 3
  1166. $87       F5             F5             Function key 5
  1167. $88       F7             F7             Function key 7
  1168. $89       SH-F1          SH-F1          Function key 2
  1169. $8a       SH-F3          SH-F3          Function key 4
  1170. $8b       SH-F5          SH-F5          Function key 6
  1171. $8c       SH-F7          SH-F7          Function key 8
  1172. $8d       SH-RETURN      SH-RETURN      <undecided>
  1173. $8e       CT-F5          CT-F5          Function key 11
  1174. $8f       CT-F7          CT-F7          Function key 12
  1175. $90       CT-1           CT-1           Black
  1176. $91       UP             UP             Cursor up
  1177. $92       CT-0           CT-0           Rvs off
  1178. $93       SH-HOME        SH-HOME        Clear screen
  1179. $94       SH-DELETE      SH-DELETE      Insert one space
  1180. $95       CO-2           CO-2           Brown
  1181. $96       CO-3           CO-3           Light red
  1182. $97       CO-4           CO-4           Dark gray
  1183. $98       CO-5           CO-5           Medium gray/dark cyan(?)
  1184. $99       CO-6           CO-6           Light green
  1185. $9a       CO-7           CO-7           Light blue
  1186. $9b       CO-8           CO-8           Light gray
  1187. $9c       CT-5           CT-5           Magenta
  1188. $9d       LEFT           LEFT           Cursor left
  1189. $9e       CT-8           CT-8           Yellow
  1190. $9f       CT-4           CT-4           Cyan
  1191.  
  1192. NAME   :  concolor
  1193. PURPOSE:  set the console main text and cursor colors
  1194. ARGS   :  .A   = which colors to modify: $02=character + $01=cursor 
  1195.                  + $20=modify high-attributes of colors
  1196.           .X   = new RGBI character color
  1197.           .Y   = new RGBI cursor color
  1198. RETURNS:  .X   = resulting character color
  1199.           .Y   = resulting cursor color
  1200. ALTERS :  .A
  1201.  
  1202. Sets the character and cursor colors to be used by the console for the "read"
  1203. and "write" system calls that refer to files opened to the console device. You
  1204. can use the flags argument to limit what gets changed.
  1205.  
  1206. NAME   :  conpalette
  1207. PURPOSE:  get standard color palette for current screen
  1208. ARGS   :  <none>
  1209. RETURNS:  sw+0 = main character color
  1210.           sw+1 = cursor color
  1211.           sw+2 = status character color
  1212.           sw+3 = separator character color
  1213.           sw+4 = highlight character color
  1214.           sw+5 = alert character color
  1215.           sw+6 = screen border color
  1216.           sw+7 = screen background color
  1217. ALTERS :  .A, .X, .Y
  1218.  
  1219. Returns the palette of colors that are recommended to be used in applications.
  1220. These colors are chosen by the user in the system configuration, so they can
  1221. be interpreted as being what the user wants and expects applications to use. A
  1222. different selection is made by the user for each different screen type, and
  1223. the palette returned will be for the screen type currently in use.  The
  1224. high-attribute bits of these colors are valid.  Eight colors are included in
  1225. the palette, and you may interpret their meaning according to the application.
  1226. The suggested usages are given in the return arguments listed above.
  1227.  
  1228. NAME   :  conscreen
  1229. PURPOSE:  set the screen size
  1230. ARGS   :  .A   = number of text rows required, minimum
  1231.           .X   = number of text columns required, minimum
  1232. RETURNS:  .A   = number of text rows you get
  1233.           .X   = number of text columns you get
  1234.           .CS  = error occurred flag (requested size cannot be given)
  1235. ALTERS :  .Y, errno
  1236.  
  1237. This call selects an appropriate display device, screen, and layout for
  1238. displaying text.  You ask for the minimum number of rows and columns you
  1239. require on the screen, and the call returns to you what you receive.  If the
  1240. system cannot match your minimum requirements, an error will be returned, and
  1241. the current screen will be unchanged.  The clock speed of the processor will
  1242. be changed to match the screen selected, if appropriate.  If you pass either
  1243. number of rows or columns as 0, then the system default value for the current
  1244. screen type will be used.  If you pass either parameter having value 255, then
  1245. the system will use the maximum possible value.
  1246.  
  1247. NAME   :  conpos
  1248. PURPOSE:  set cursor location
  1249. ARGS   :  .A   = row
  1250.           .X   = column
  1251. RETURNS:  .CS  = error encountered flag
  1252. ALTERS :  .A, .X, .Y
  1253.  
  1254. This call will set the screen location that the next console "read" or "write"
  1255. system call will operate from.  If the "cursor" position is outside the
  1256. boundaries of the current window on the screen, an error will be returned.
  1257.  
  1258. 2.4.6. PROCESS CONTROL CALLS
  1259.  
  1260. This section describes calls that are used to control the execution of
  1261. processes (active programs).  From within one program, you can call for the
  1262. execution of another program, have it execute, and then return to the calling
  1263. program.  Since only one program is allowed in memory at a time, some special
  1264. problems arise.
  1265.  
  1266. NAME   :  exec
  1267. PURPOSE:  execute external program as a child process
  1268. ARGS   :  (zp) = program name of executable
  1269.           (zw) = start address of argument vector
  1270.           .AY  = number of arguments
  1271.           [mp] = pointer to far memory volatile storage
  1272. RETURNS:  .A   = exit code
  1273.           .X   = number of bytes in "aceExitData" used
  1274.           (zp) = given argument count
  1275.           (zw) = given argument vector pointer
  1276.           [mp] = pointer to far memory volatile storage
  1277.           .CS  = error occurred flag
  1278. ALTERS :  .Y, errno
  1279.  
  1280. Calling this routine will cause a new "frame" to be set up on the "system
  1281. stack" (lowering the available application area memory a little), the
  1282. specified program to be loaded into memory over top of the current one, the
  1283. new program to be executed, the old program to be reloaded from whatever disk
  1284. unit it came from originally upon exit of the new program, and control to be
  1285. returned to the old process with the return values from the executed program.
  1286. This is a complicated procedure and many things can go wrong.
  1287.  
  1288. The first thing that a process that wants to call another program must do is
  1289. set up the arguments to be passed in.  All arguments must be null-terminated
  1290. strings.  These arguments are to be put into high memory, starting from one
  1291. less than the location pointed to by "aceMemTop" and working downward.  It
  1292. does not matter in which order the strings are placed, as long as they are all
  1293. grouped together.  Then, immediately below the strings comes the vector of
  1294. two-byte RAM0 pointers that point to the strings.  This array must be in
  1295. order, with the lowest entry pointing to the first (zero subscript) string,
  1296. etc., the second highest entry pointing to the last string, and the highest
  1297. entry containing the value $0000.  An asciigram follows:
  1298.  
  1299.   HIGHER ADDRESSES
  1300. |           |
  1301. |           | <--(aceMemTop)
  1302. +-----------+
  1303. |           |
  1304. | string    |
  1305. |           |         : collection of null-terminated strings
  1306. |  contents |
  1307. |           |
  1308. |           |
  1309. +-----------+
  1310. |   $0000   |         : argv[N] : null argument pointer
  1311. +-----------+
  1312. | strptrN-1 |         : argv[N-1]
  1313. +-----------+
  1314. | strptrN-2 |         : argv[N-2]
  1315. +-----------+
  1316. .           .
  1317. .           .
  1318. +-----------+
  1319. | strptr 1  |         : argv[1] : first actual argument
  1320. +-----------+
  1321. | strptr 0  | <--(zw) : argv[0] : filename of program to be executed
  1322. +-----------+
  1323. |           |
  1324.   LOWER ADDRESSES
  1325.  
  1326. The first entry should indicate the filename or command name of the program
  1327. being executed, and the subsequent arguments are the actual input arguments to
  1328. the program being called.  The address of the first argument vector table
  1329. entry is loaded into (zw), and the number of arguments is loaded into .AY.
  1330. Note that this value also includes the command name, so if, for example, you
  1331. were to call program "wc" to count two filenames "hello" and "goodbye", then
  1332. you would pass an argument count of 3.  The name pointed to by "argv[0]" does
  1333. not actually have to be the literal command name, but the one pointed to by
  1334. (zp) does.  If a relative executable name is given in (zp), then the search
  1335. path will be used to locate the executable.  Oh, don't screw up the
  1336. organization of the arguments or bad things will happen; there is no structure
  1337. checking.
  1338.  
  1339. After setting up the arguments, you'll want to set up any redirections of
  1340. stdin, stdout, or stderr you'll be needing.  Because there is only one open
  1341. file table in the whole uni-tasking system, you'll have to manipulate existing
  1342. entries using the "fdswap" system call described earlier.  The open file table
  1343. is inherited by the child process.  Note that if it closes any of the open
  1344. files it inherited, then they are also closed to your use also.  If the child
  1345. accidentally leaves open any files it opened, they will be closed by the
  1346. system before you are reactivated.
  1347.  
  1348. Finally, before the call is made, you have to save any volatile local
  1349. information into "far" memory.  All application zeropage and application area
  1350. memory will be modified by the called program, so you must save whatever you
  1351. will need to continue after the return to be able to continue.  As mentioned
  1352. earlier, all of the "far" memory that a parent program owns will be safe, so
  1353. you can save your volatile information there, in any format you wish.  All you
  1354. have to do is save the pointer to the far memory into the [mp] pointer.  Upon
  1355. return of the child process, the value you put into [mp] will be restored, and
  1356. you can then restore your volatile information out of far storage.  If you
  1357. wish to save no volatile information, then you can just leave garbage in the
  1358. [mp] value, since it will not be interpreted by the system.
  1359.  
  1360. Alright, so now you call the "exec" primitive, the child program is loaded,
  1361. executed, and it returns.
  1362.  
  1363. At this time, the parent program (that's you) is reloaded from wherever it was
  1364. loaded originally and you are returned to the instruction immediately
  1365. following the "jsr exec", with your processor stack intact but the rest of
  1366. your volatile storage invalid.  Even if there is an error return (carry flag
  1367. set), your volatile storage will still need to be restored, since the
  1368. application area may have been overwritten before the error was discovered.
  1369. In the case of an error return, the child process will not have been executed.
  1370. If the system is unable to reload the parent program (you), then an error
  1371. return is given to your parent, and so on, as far back as necessary.  (This is
  1372. a minor exception to the rule that an error return indicates that a child
  1373. didn't execute; in this case, the child didn't complete).
  1374.  
  1375. You are also returned an "exit code", which will have application-specific
  1376. meaning, although standard programs (e.g., shell script) interpret the value
  1377. as: 0==normal exit, anything else==error exit.  The X register is also set to
  1378. indicate the amount of "aceExitData" that is used, to allow for more
  1379. complicated return values.  [Note: this call is still not implemented in
  1380. Release #10.]
  1381.  
  1382. NAME   :  execsub
  1383. PURPOSE:  execute internal subroutine as a separate process
  1384. ARGS   :  (zp) = address of subroutine
  1385.           (zw) = address of argument vector
  1386.           .AY  = argument count
  1387.           [mp] = far memory pointer
  1388. RETURNS:  .A   = exit code
  1389.           .X   = number of bytes in "aceExitData" used
  1390.           (zp) = given argument count
  1391.           (zw) = given argument vector pointer
  1392.           [mp] = given far memory pointer
  1393.           .CS  = error occurred flag
  1394. ALTERS :  .Y, errno
  1395.  
  1396. This call is very similar to "exec", except that it calls an internal
  1397. subroutine rather than an external program.  Thus, you don't have to save or
  1398. restore your volatile storage, or worry about loading the child or reloading
  1399. the parent.  You do, however, set up the arguments and file redirections as
  1400. you would for a full "exec".
  1401.  
  1402. NAME   :  exit
  1403. PURPOSE:  exit current program, return to parent
  1404. ARGS   :  .A   = exit code
  1405.           .X   = number of bytes in "aceExitData" used
  1406. RETURNS:  <there is no return, brah-ha-ha-ha-ha-ha!!!>
  1407. ALTERS :  <don't bloody well matter to you>
  1408.  
  1409. This call causes the current program to exit back to its parent. A program
  1410. that exits simply by returning to its environment will give back an exit code
  1411. of 0, which should be interpreted as a normal return.  If you wish to indicate
  1412. a special return, you should use some exit code other than zero.  Many
  1413. utilities will interpret non-zero error codes as actual errors and may abort
  1414. further operations because of this.
  1415.  
  1416. You may set up a return data in "aceExitData", up to 255 bytes worth, and load
  1417. the number of bytes used into .X if you wish.  It is recommended that the
  1418. first field of this data be a special identifier code so programs that cannot
  1419. interpret your data will not try.  You cannot give any far pointers in your
  1420. return data, since all far memory allocated to you will be freed by the system
  1421. before returning to your parent.
  1422.  
  1423. NAME   :  memstat
  1424. PURPOSE:  get "far" memory status plus process id
  1425. ARGS   :  .X   = zero-page address to store status information
  1426. RETURNS:  .A   = current process id
  1427.          [.X+0]= amount of "far" memory free
  1428.          [.X+4]= total amount of "far" memory
  1429. ALTERS :  .X, .Y
  1430.  
  1431. This call returns the current process id, the number of bytes of far memory
  1432. currently free, and the total amount of far memory.
  1433.  
  1434. 2.4.7. MISCELLANEOUS CALLS
  1435.  
  1436. NAME   :  utoa
  1437. PURPOSE:  convert unsigned 32-bit number to a decimal PETSCII string
  1438. ARGS   :  .A   = minimum length for return string
  1439.           .X   = zero-page address of 32-bit number
  1440.           (zp) = pointer to string buffer to store string
  1441. RETURNS:  .Y   = length of string
  1442. ALTERS :  .A, .X
  1443.  
  1444. This is a utility call in the kernel.  It is really not necessary for it to be
  1445. in the kernel, but so many programs make use of it that it makes sense for it
  1446. to be factored out.  You give a pointer to a 32-bit unsigned value in zero
  1447. page memory, a pointer to a buffer to store that string that is at least as
  1448. long as necessary to store the value plus the null-character terminator that
  1449. will be put on the end of the string, and a minimum length value for the
  1450. string.  If the number requires fewer digits than the minimum length, the
  1451. string will be padded with spaces on the left.  Since a 32-bit quantity can
  1452. only contain an maximum of ten decimal digits, the string buffer will only
  1453. need to be a maximum of eleven bytes in size.
  1454.  
  1455. NAME   :  getdate
  1456. PURPOSE:  get the current date and time
  1457. ARGS   : (.AY) = address of buffer to put BCD-format date into
  1458. RETURNS:  <none>
  1459. ALTERS :  .A, .X, .Y
  1460.  
  1461. Returns the current date and time in the BCD format described in the paragraph
  1462. on "aceDirentDate".  It puts it into the at-least-eight-byte storage area
  1463. pointed to by (.AY).
  1464.  
  1465. NAME   :  setdate
  1466. PURPOSE:  set the current date and time
  1467. ARGS   : (.AY) = address of date in BCD format
  1468. RETURNS:  <none>
  1469. ALTERS :  .A, .X, .Y
  1470.  
  1471. Sets the current date and time in the system.  (.AY) points to the BCD date
  1472. string whose format is discussed in the paragraph on "aceDirentDate".  No
  1473. validity checking is performed on the date given.
  1474.  
  1475. NAME   :  cmdopen
  1476. PURPOSE:  open command channel to Commodore disk drives
  1477. ARGS   :  (zp) = device name
  1478. RETURNS:  .A   = file descriptor number
  1479.           .CS  = error occurred flag
  1480. ALTERS :  .X, .Y, errno
  1481.  
  1482. This "cmd" set of system calls really should not be present, but they will be
  1483. needed until the full complement of disk-utility system calls are implemented.
  1484. It is really not recommended that any application program rely on these calls
  1485. being around very long.  This call opens the command channel on the named
  1486. device (standard ACE device name string) and returns the file descriptor
  1487. number to use thereafter.
  1488.  
  1489. NAME   :  cmdclose
  1490. PURPOSE:  close command channel to Commodore disk drives
  1491. ARGS   :  .A   = file descriptor number
  1492. RETURNS:  .CS  = error occurred flag
  1493. ALTERS :  .A, .X, .Y, errno
  1494.  
  1495. This closes an opened command channel to a disk drive.  Closing the status
  1496. will NOT affect any other open files on the disk unit at the time.
  1497.  
  1498. NAME   :  cmdsend
  1499. PURPOSE:  send command over command channel to Commodore disk drives
  1500. ARGS   :  .X   = file descriptor number
  1501.          (.AY) = pointer to null-terminated command string
  1502. RETURNS:  .CS  = error occurred flag
  1503. ALTERS :  .A, .X, .Y, errno
  1504.  
  1505. This sends a command string to a disk drive.  Since a null-terminated string
  1506. representation is used, not all Commodore/CMD-DOS commands can be sent, but
  1507. the important ones can be.
  1508.  
  1509. NAME   :  cmdstatus
  1510. PURPOSE:  receive current status from command channel of Commodore disk drives
  1511. ARGS   :  .X   = file descriptor number
  1512.          (.AY) = pointer to buffer for null-terminated status string
  1513. RETURNS:  .A   = status code in binary
  1514.           .CS  = error occurred
  1515. ALTERS :  .X, .Y, errno
  1516.  
  1517. This returns the status of a disk drive in a string as well as the binary disk
  1518. status number in the accumulator.  The given status buffer must be at least 50
  1519. or so characters long (whatever is the longest possible disk status string).
  1520.  
  1521. 3. USER PROGRAM ORGANIZATION
  1522.  
  1523. The ACE system itself is written using the Buddy-128 assembler, so it is
  1524. recommended that applications be written in this also.  User programs for ACE
  1525. have a very simple structure.  Here is the standard "hello, world" example
  1526. program written in Buddy assembler for ACE:
  1527.  
  1528. -----=-----
  1529. .seq acehead.s
  1530. .org aceAppAddress
  1531. .obj "@0:hello"
  1532.  
  1533. jmp main
  1534. .byte aceID1,aceID2,aceID3
  1535. .byte 64,0
  1536.  
  1537. main = *
  1538.    lda #<helloMsg
  1539.    ldy #>helloMsg
  1540.    sta zp+0
  1541.    sty zp+1
  1542.    lda #<helloMsgEnd-helloMsg
  1543.    ldy #>helloMsgEnd-helloMsg
  1544.    ldx #stdout
  1545.    jsr write
  1546.    rts
  1547.  
  1548. helloMsg = *
  1549.    .asc "Hello, cruel world."
  1550.    .byte 13
  1551. helloMsgEnd = *
  1552. -----=-----
  1553.  
  1554. This would normally be put into a file called "hello.s".  The ".s" extension
  1555. means that this is an assembler file (a la Unix).  The first thing this
  1556. program does is include the "acehead.s" file.  This is the Buddy assembler
  1557. file that contains the header information declarations required to access the
  1558. ACE system interface.  The next line gives the start address to start
  1559. assembling to; it must be "aceAppAddress", which is the address that ACE will
  1560. load the program at.  The next line is a directive to the assembler to write
  1561. the executable code to a Commodore-DOS "PRG" file named "hello".  This will be
  1562. the command to enter at the ACE shell prompt.
  1563.  
  1564. The next eight bytes of object code (which are the first eight bytes of a
  1565. loaded program) describe the header required by ACE programs.  The first three
  1566. bytes must be a JMP to the main routine of the program.  The next three bytes
  1567. must have the values "aceID1", "aceID2", and "aceID3", respectively.  The next
  1568. two bytes are the minimum stack requirements and flags, respectively.  The
  1569. stack requirement is for the processor stack, and ACE will make sure your
  1570. program has at least this much space before your program starts.  The flags
  1571. field is currently undefined, but you must give it a value of 0.  And that's
  1572. all there is to it.  The rest of the program can be organized however you want
  1573. it to be.
  1574.  
  1575. In this example, we set up the arguments for the "write" system call to print
  1576. the string "Hello, cruel world." plus a carriage return to standard output.
  1577. Note that this string does not need a terminating null ($00) character since
  1578. the write call takes a buffer length.  The program then returns to its calling
  1579. environment via an RTS.  This will cause an implied "exit(0)" to be performed
  1580. by the system, returning to the parent program.
  1581.  
  1582. Although this program does not take advantage of this, an application program
  1583. may use zero-page locations $0002 through $007f for storage without fear of
  1584. having the storage trodden upon by the system.
  1585.  
  1586. Finally, an application program starts at location "aceAppAddress" (plus six)
  1587. and is allowed to use memory all the way up to one byte less than the address
  1588. pointed to by "aceMemTop" for its own purposes.  Currently, this amount of
  1589. space is on the order of magnitude of about 20K.  This will be increased in
  1590. the future.
  1591.  
  1592. Application programs are not to access I/O features or even change the current
  1593. memory configuration during execution.  All I/O and other unusual contortions
  1594. must be performed by ACE system calls; otherwise, we could end up in as bad a
  1595. shape as MESS-DOS.
  1596.  
  1597. 4. CONCLUSION
  1598.  
  1599. Cool, eh?
  1600. -----------------------------------------------------------------------=END=--
  1601.