home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / magazi~1 / 225 / analog.46 / dx.s < prev    next >
Encoding:
Text File  |  1987-10-18  |  9.8 KB  |  237 lines

  1.  
  2. *     Note: in the comments to the following code, the symbol " -> "
  3. *           means "pointer to" or "contains a pointer to".
  4.  
  5.  
  6. *************************************************************************
  7. *** This version is compatible with the AS68 assembler included in the
  8. ***     Atari Developer's Kit.
  9. *** INITIALIZATION: these should be the first instructions in your
  10. ***    program...
  11. sys_start:
  12.           move.l    4(a7),a5            a5 == base page address
  13.           lea.l     $80(a5),a2          point to command line
  14.           clr.l     d0                  clear for byte size value
  15.           move.b    (a2)+,d0            get byte count
  16.  
  17. ***  a2 -> command line
  18. ***  d0 == byte count of command line
  19.           move.l    #flags,-(sp)        base of flags area
  20.           move.l    #code_nr,-(sp)      nr of flags in table
  21.           bsr       init_flags          initialize flags
  22.           addq.l    #8,sp               pop args
  23.  
  24. *** process command line codes
  25.           move.l    #code_scale,-(sp)
  26.           move.l    #code_nr,-(sp)      number of codes possible
  27.           move.l    #codes,-(sp)        table of codes
  28.           move.l    d0,-(sp)            byte count
  29.           move.l    a2,-(sp)            address of command line
  30.           bsr       check_c_args        set flags 
  31.           add.l     #20,sp              pop args
  32.  
  33. *** ...the rest of your program follows here...
  34.  
  35.      
  36. *************************************************************************
  37. *** SUBROUTINES: these are called from the main program (above).
  38. *****
  39. *
  40. * init_flags-- initializes a standard table of (byte-size) flags to
  41. *              FALSE.
  42. *    at entry:
  43. *              a6 + 8  -> size of table.
  44. *              a6 + 12 -> base of table.
  45. *    at exit:
  46. *              table  is initialized.
  47. *              all registers preserved.
  48. *
  49. *****
  50. init_flags:
  51.           link      a6,#0          set frame pointer
  52.           movem.l   a0/d0,-(sp)    save registers
  53.           movea.l   12(a6),a0      base of table
  54.           move.l    8(a6),d0       size of table
  55.           bra.s     initf_test     now start         
  56. initf_loop:
  57.           move.b    #FALSE,(a0)+   initialize a flag
  58. initf_test:   
  59.           dbra      d0,initf_loop  go till end
  60.           movem.l   (sp)+,a0/d0    restore registers
  61.           unlk      a6             deallocate frame
  62.           rts                      and return
  63.  
  64. *****
  65. * parse_word-- returns a word (delimited by a space or end of string)
  66. *               from a string.
  67. *              the word must be <= 76 chars (ARG_SIZE, == size of local
  68. *               area reserved by caller).
  69. * at entry:
  70. *              a6 + 8  -> address of string.
  71. *              a6 + 12 -> byte count of string.
  72. *              a6 + 16 -> area into which to copy word (null-terminated).
  73. * at exit:     
  74. *              a0 -> next word of original string.
  75. *              d0 == updated byte count (0 if string exhausted).
  76. *              a1 -> word returned (terminated by 0).
  77. *              d1 == byte count of word.
  78. *              if error, d0 == -1 ('BAD').
  79. *              all other registers preserved.
  80. *
  81. *****
  82. parse_word:
  83.           link      a6,#0          set frame pointer
  84.           movea.l   8(a6),a0       get string address
  85.           move.l    12(a6),d0      get byte count
  86.           bgt.s     p_w_001        if count > 0, continue
  87.           move.l    #BAD,d0        else return error
  88.           bra       w_f_002        and leave
  89. p_w_001:
  90.           movea.l   16(a6),a1      point to copy space
  91.           movem.l   a1/d2,-(sp)    save it and count register
  92.           clr.l     d1             clear word count
  93.           move.l    #ARG_SIZE-1,d2   start control count (-1 for null)
  94. parse_loop:
  95.           cmp.b     #BLANK,(a0)    blank?
  96.           bne.s     p_l_001        if not
  97.           subq.l    #1,d0          else decrement string count
  98.           addq.l    #1,a0          point to next char
  99.           bra       p_w_exit       and return word
  100. p_l_001:
  101.           subq.l    #1,d0          else decrement string count
  102.           bne.s     p_l_002        continue if string not exhausted
  103.           addq.l    #1,d1          else count this last char...
  104.           move.b    (a0)+,(a1)+    copy last valid char...
  105.           bra       p_w_exit       and return final word
  106. p_l_002:
  107.           move.b    (a0)+,(a1)+    copy char
  108.           addq.l    #1,d1          count this one
  109.           subq.l    #1,d2          decrement control count
  110.           bne.s     p_l_003        if > 0, continue
  111.           subq.l    #1,d0          else decrement string count
  112.           bra       p_w_exit       and leave
  113. p_l_003: 
  114.           bra       parse_loop     keep going
  115. p_w_exit:
  116.           move.b    #0,(a1)+       terminate word with null
  117. w_f_001:
  118.           movem.l   (sp)+,a1/d2    point back to start of return word
  119. *                                   and restore d2
  120. w_f_002:
  121.           unlk      a6             deallocate frame
  122.           rts                      and return
  123.  
  124.  
  125. *****
  126. *
  127. * check_c_args-- checks one-letter command-line arguments and sets 
  128. *                internal flags as appropriate.
  129. * at entry:
  130. *              a6 + 8  -> address of command line string.
  131. *              a6 + 12 -> byte count of command line string.
  132. *              a6 + 16 -> base address of array of char codes to
  133. *                                look for.
  134. *              a6 + 20 -> nr of char codes in array.
  135. *              a6 + 24 -> code table scale factor.
  136. * at exit:
  137. *              d0 == completion code (returns GOOD if there's
  138. *                   anything else on command line-- even only spaces).
  139. *              flags will be set TRUE or FALSE as appropriate.
  140. *              all other registers preserved.
  141. *                
  142. *****
  143. check_c_args:
  144.           link      a6,#-ARG_SIZE       set frame pointer   
  145.           movem.l   a0-a2/d1-d4,-(sp)   save registers
  146.           move.l    12(a6),d0           command line byte count
  147.           bgt.s     c_c_a001            if count > 0, continue
  148.           move.l    #BAD,d0             else load error code
  149.           bra.s     c_c_exit            and leave
  150. c_c_a001:     
  151.           movea.l   8(a6),a0            command line address 
  152.           move.l    24(a6),d3           scale factor
  153.           subq.l    #1,d3               -1 to allow for address reg inc 
  154.           clr.l     d4                  holds byte for comparisons        
  155. c_c_word:
  156.           tst.l     d0                  anything left in command line?
  157.           bne.s     c_c_w001            if so, continue
  158.           move.l    #GOOD,d0            else load success code
  159.           bra.s     c_c_exit            and leave
  160. c_c_w001:
  161.           pea       -ARG_SIZE(a6)       local space address
  162.           move.l    d0,-(sp)            current command line count
  163.           move.l    a0,-(sp)            rest of command line
  164.           bsr       parse_word          get next word
  165.           add.l     #12,sp              pop args
  166. *** (a1) -> code to check; d1 == count; (a0) -> rest of cmdline;
  167. ***         d0 == bytes left
  168.           cmp.l     #1,d1               one-char arg?
  169.           beq.s     c_c_scan            if so, continue
  170.           bra.s     c_c_word            else skip this one
  171. c_c_scan:
  172.           move.l    20(a6),d2           nr of codes to check
  173.           movea.l   16(a6),a2           base of codes table
  174.           bra.s     c_c_stest           start checking
  175. c_c_sloop:
  176.           move.b    (a2)+,d4            next byte
  177.           cmp.b     (a1),d4             code found?
  178. c_c_stest:
  179.           dbeq      d2,c_c_sloop        if not and more codes to check
  180.           tst.w     d2                  really a match?
  181.           bmi.s     c_c_s001            if not
  182.           move.b    #TRUE,0(a2,d3.l)    else set flag = TRUE
  183. c_c_s001:
  184.           bra.s     c_c_word            and get next word 
  185. c_c_exit:
  186.           movem.l   (sp)+,a0-a2/d1-d4   restore registers
  187.           unlk      a6                  deallocate local space
  188.           rts                           and return                 
  189.  
  190. *************************************************************************
  191. *** DATA DECLARATIONS:
  192. *****
  193. *
  194. * standard flags table.
  195. *
  196. *****
  197. GOOD      equ       0         return code == success
  198. BAD       equ       -1        return code == fail
  199. ARG_SIZE  equ       76        max total length of command line arguments
  200. TRUE      equ       1         == C "true" cond
  201. FALSE     equ       0         == C "false" cond
  202. BLANK     equ       32        ascii space == " "
  203.  
  204.                even
  205. code_base      equ       *                   base of codes table
  206.  
  207. *** now comes a list of the characters you want to use
  208. codes          dc.b      'O','G'             command line codes
  209.                dc.b      'V','P','R','A','B','C'
  210.                dc.b      'N','S','D'   
  211.  
  212. *** the next four lines do not change!
  213. code_nr        equ       *-code_base         size of table
  214. code_count     dc.l      code_nr             save it
  215. code_scale     equ       *-code_base         index between codes and flags
  216. flags          equ       *                   base of flags table
  217.  
  218. *** these are the flags which correspond to the characters listed above.
  219. ***   If the codes are changed, then the flags must also be changed to
  220. ***   maintain a one-to-one corrspondence. If a valid character code
  221. ***   (one of those listed above) is found on the command line, then its
  222. ***   corresponding flag will be set to "true" after the routine
  223. ***   'check_c_args' is called; otherwise it remains "false".
  224. okidata        ds.b      1                   oki printer
  225. star           ds.b      1                   star/gemini printer
  226. verbose        ds.b      1
  227. print_it       ds.b      1
  228. small_prt      ds.b      1
  229. drive_a        ds.b      1
  230. drive_b        ds.b      1
  231. drive_c        ds.b      1
  232. set_title      ds.b      1
  233. set_stack      ds.b      1
  234. search         ds.b      1                   alternate search level
  235.  
  236.