home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d136 / asmtoolbox.lha / AsmToolBox / at1.doc < prev    next >
Text File  |  1988-03-19  |  12KB  |  300 lines

  1. Assembler Toolkit #1 by Warren A. Ring   2/8/88
  2.  
  3. This tool box is, as of this date, scheduled to be featured in the March,
  4. April, and May 1988 issues of Amazing Computing.
  5.  
  6. This is the first in what I hope will be a series of assembler toolboxes
  7. created to make interfacing between assembler programs and AmigaDOS easy. 
  8. Each toolbox consists of a macro file and a library file.  The primary
  9. vehicle for getting data to and from these routines is a data structure I
  10. call the "string buffer".  It can contain text strings, but can just as
  11. easily be used for disk buffers.  A string buffer may contain either binary
  12. or ASCII data, and is structured to have overrun protection and fast
  13. manipulation.  String buffers consist of three fields, shown in the following
  14. example:  
  15.  
  16.            CNOP    0,2
  17.        Buffer1Length equ 10
  18.        Buffer1
  19.            DC.L    Buffer1Length   ;Capacity of the data field
  20.            DC.L    0               ;Current useage of the data field
  21.            DS.B    Buffer1Length   ;Data field
  22.            CNOP    0,2
  23.  
  24. The first field is a long integer specifying the physical size, in bytes, of
  25. the data field (the maximum length of a string you wish to hold).  This
  26. allows routines that write into the string buffer to know the physical size
  27. of the data field, and thus avoid writing beyond the end of that string
  28. buffer, destroying unrelated data or stack variables.  The second is a long
  29. integer specifying the current useage (the length of the string CURRENTLY in
  30. the buffer), in bytes, of the data field.  The third is the data field
  31. itself.  In the above example, the current useage is zero, and the data field
  32. is uninitialized.  The CNOP statement is an assembler directive that aligns
  33. the program counter to the next word boundary.  If Buffer1Length is an odd
  34. number, then the assembler will throw in an extra byte at the end of the
  35. buffer, so that whatever follows will be word-aligned.
  36.  
  37. So what functions are in this package?  Disk I/O, string manipulation, and
  38. Integer/ASCII conversion are the primary functions, as shown in the following
  39. table.
  40.  
  41. In this table, arguments are defined as follows:
  42.  
  43.    [filename]      the address of a string buffer containing the name
  44.    [old-filename]  of a file
  45.    [new-filename]
  46.  
  47.    [file-handle]   the address of a 4-byte file handle
  48.  
  49.    [data]          the address of a string buffer containing data
  50.    [from-data]
  51.    [to-data]
  52.  
  53.    [seek-location] the number of bytes, zero being the beginning of file,
  54.                    at which the next disk read or write is to take place
  55.  
  56.    [text]          an ASCII text operand.  May be values separated by
  57.                    commas, or literal text in quotes
  58.  
  59.    [label]         a label
  60.  
  61.    [length]        the length of a string buffer
  62.  
  63.  
  64.                           --- Function Table ---
  65.  
  66. Name       Function/Format
  67. ---------- ----------------------------------------
  68.  
  69. General:
  70.  
  71. Start      Performs housekeeping at the beginning
  72.               of a program, sets scanning to the
  73.               command line residue
  74.            Format: Start
  75.  
  76. Exit       Performs housekeeping at the end of a
  77.               program, and exits
  78.            Format: Exit
  79.  
  80.  
  81. Disk I/O:
  82.  
  83. Open       Opens a disk file
  84.            Format: Open [filename],[file-handle]
  85.            Upon return, if the zero flag is set, then there is no such file.
  86.  
  87. Create     Creates a disk file
  88.            Format: Create [filename],[file-handle]
  89.            Upon return, if the zero flag is set, then the file could not
  90.            be created.
  91.  
  92. Delete     Deletes a disk file
  93.            Format: Delete [filename]
  94.            Upon return, if the zero flag is set, then the file did not exist,
  95.            or had its protection attribute set.
  96.  
  97. Close      Closes a disk file
  98.            Format: Close [file-handle]
  99.  
  100. Rename     Rename a disk file
  101.            Format: Rename [old-filename],[new-filename]
  102.            Upon return, if the zero flag is set, then the file did not exist,
  103.            or had its protection attribute set.
  104.  
  105. Read       Reads from a disk file
  106.            Format: Read [file-handle],[data]
  107.            This routine attempts to read a full string buffer of data.
  108.            Upon return, the current useage of the string buffer used
  109.            as the disk I/O buffer indicates the number of bytes
  110.            successfully read from the file.  If the current useage is
  111.            zero, then you have reached the end of file.
  112.  
  113. Write      Writes to a disk file
  114.            Format: Write [file-handle],[data]
  115.            This routine attempts to write the number of bytes specified
  116.            by the current useage to the file.
  117.  
  118. Seek       Seeks to a specified position in a disk file
  119.            Format: Seek [file-handle],[seek-location]
  120.  
  121.  
  122. These functions handle I/O to the console:
  123.  
  124. ReadCon    Gets a line from the console
  125.            Format: ReadCon [data]
  126.  
  127. WritCon    Writes to the console
  128.            Format: WritCon [data]
  129.  
  130. Display    Displays an immediate text string
  131.            Format: Display <[text]>
  132.  
  133. Crlf       Displays a CR/LF
  134.            Format: Crlf
  135.  
  136. Space      Displays a space character
  137.            Format: Space
  138.  
  139.  
  140. These functions handle scanning of a string buffer
  141. to pick up words (including punctuation),
  142. alphanumeric words, or single characters:
  143.  
  144. SetScan    Sets scanning to the beginning of a specified string buffer
  145.            Format: SetScan [data]
  146.            Default scanning is on the command line residue
  147.  
  148. Scanw      Sets [data] to the next text word in the command line residue
  149.            or the string buffer specified in the most recent SetScan command
  150.            Format: Scanw [data]
  151.  
  152. Scana      Sets [data] to the next alphanumeric word in the command line
  153.            residue or the string buffer specified in the most recent
  154.            SetScan command
  155.            Format: Scana [data]
  156.  
  157. Scanc      Sets [data] to the next character in the command line residue
  158.            or the string buffer specified in the most recent SetScan command
  159.  
  160.  
  161. These functions perform string handling, best
  162. described by BASIC or C language equivalent
  163. expressions:  
  164.  
  165. StrCpy     A$=B$, copies one string to another
  166.            Format: StrCpy [from-data],[to-data]
  167.  
  168. StrCat     A$=A$+B$, appends one string to another
  169.            Format: StrCat [from-data],[to-data]
  170.  
  171. StrCmp     Compares one string with another
  172.            Format: StrCmp [data],[data]
  173.  
  174. StrLen     I=LEN(A$), gets a string length
  175.            Format: StrLen [data]
  176.  
  177. Left       A$=LEFT$(B$,I), gets I left-most chars
  178.            Format: Left [from-data],I,[to-data]
  179.  
  180. Mid        A$=MID$(A$,I,J), gets I middle chars from position J
  181.            Format: Mid [from-data],I,J,[to-data]
  182.  
  183. Right      A$=RIGHT$(A$,I), gets I right-most chars
  184.            Format: Right [from-data],I,[to-data]
  185.  
  186. ItoA       A$=STR$(I), converts a long integer to an ASCII string
  187.            Format: ItoA I,[data]
  188.  
  189. AtoI       I=VAL(A$), converts an ASCII string to a long integer
  190.            Format: AtoI [data],I
  191.  
  192. HAtoI      I=HEX$(A$), converts a string of hex ASCII chars to an integer
  193.            Format: HAtoI [data],I
  194.  
  195. ItoHA8     A$=HEX8$(I), converts a 4-byte integer
  196.               to a string of 8 hex-ASCII chars
  197.            Format: ItoHA8 I,[data]
  198.  
  199. ItoHA4     A$=HEX4$(I), converts a 2-byte integer
  200.               to a string of 4 hex-ASCII chars
  201.            Format: ItoHA4 I,[data]
  202.  
  203. ItoHA2     A$=HEX2$(I), converts a 1-byte integer
  204.               to a string of 2 hex-ASCII chars
  205.            Format: ItoHA2 I,[data]
  206.  
  207. ItoHA1     A$=HEX1$(I), converts a 4-bit integer
  208.               to a string of 1 hex-ASCII char
  209.            Format: ItoHA1 I,[data]
  210.  
  211.  
  212. These functions create string buffers:
  213.  
  214. StrBuf     Directs the assembler to define an uninitialized string buffer
  215.            Format: StrBuf [label],[length]
  216.  
  217. String     Directs the assembler to define an initialized string buffer
  218.            Format: String [label],<[text]>
  219.  
  220.  
  221.                               General Notes
  222.  
  223. Notice that in the test programs, arguments that reference string buffers
  224. are generally IMMEDIATE, shown with a pound sign before the label.  Arguments
  225. that are integers are generally DIRECT, shown simply as a label.  Depending
  226. on what you want to do, there may be exceptions to this rule.
  227.  
  228. Included in this package are 6 example programs.  They should help you see
  229. how these functions are invoked.
  230.  
  231.  
  232.                               How to Invoke
  233.  
  234. I use the Metacomco assembler.  You can get it, and the Metascope debugger
  235. from Abel Supply in Sevierville, Tennessee.  You call up their modem number
  236. at (615) 453-0643, peruse or download their list of literally hundreds of
  237. Amiga items, enter your VISA or MasterCard number, and in a few days, your
  238. order shows up on your door step.  Their voice number is (615) 428-5100.  You
  239. can get the Metacomco assembler for $54.75, and the MetaScope debugger for
  240. $54.68, a discount form list of about 40%.  
  241.  
  242. To assemble your program, enter the following:
  243.  
  244.    assem test.asm -o test.o -l test.lst
  245.  
  246. This produces object file "test.o" and list file "test.lst".  Assuming you
  247. have no errors, you copy the "amiga.lib" file from the Metacomco disk to the
  248. directory you have assigned to libs:, and enter:
  249.  
  250.    alink test.o to test library libs:amiga.lib
  251.  
  252.  
  253.                           Seeking in Disk Files
  254.  
  255. Some background on how the AmigaDOS disk I/O calls work is in order here. 
  256. AmigaDOS correctly assumes that most files read or written are "sequential"
  257. files, meaning you either read an existing file from beginning to end, or you
  258. create a file and write sequentially until you close it.  Each file has a
  259. position marker, or "cursor" associated with it that indicates where in the
  260. file (how many bytes into the file) the next read or write is to take place. 
  261. Each time you read or write in a file, AmigaDOS automatically moves this
  262. cursor to the end of the record you just read or wrote, making the assumption
  263. that you wish to read or write the following record in the file.  If you wish
  264. read or write in another place in the file, you must use the Seek command to
  265. change the cursor position.  
  266.  
  267. The figure AmigaDOS will accept can be relative to the beginning of the file,
  268. current position, or end of file.  In this toolbox, we make all cursor
  269. positioning arguments relative to the beginning of the file.
  270.  
  271. String buffers are used as disk I/O buffers as well as text buffers.  When
  272. you write to disk, the current useage of the string buffer is the number of
  273. bytes to be written to disk.  Conversely, when we read from disk, the maximum
  274. length of the string buffer is the number of bytes that we wish to read from
  275. disk, and the read routine sets the current useage of the string buffer to
  276. the actual number of bytes read from disk.  Thus, AmigaDOS tries to fill the
  277. string buffer, and the string buffer's current useage is set to the correct
  278. value.  
  279.  
  280.  
  281.                              Reference Works
  282.  
  283. I recommend you get "Programmer's Guide to the Amiga" by Robert Peck (Sybex).
  284. I have gotten a copy of this book, and noticed that although it is written
  285. primarily for C users, it has much that applies to ALL users.  It tells WHY
  286. you perform certain procedures, as well as how.  I also strongly recommend
  287. the book "68000 Assembly Language Techniques for Building Programs" by Donald
  288. Krantz and James Stanley (Addison-Wesley).  This book you tells everything
  289. you want to know about generic 68000 programming, including what addressing
  290. modes are legal for each instruction, and why the special instructions and
  291. address modes are so great.  
  292.  
  293.  
  294.                              How to Reach Me
  295.  
  296. If you have questions or comments, you may contact me at either of two BBS
  297. systems I regularly visit: the Los Angeles Amiga User's Group BBS (LAAUG
  298. Line) at (213) 559-7367, and the "1939" BBS at (818) 368-4248.
  299.  
  300.