home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / books / 68k_book / arp_src / makefile.s < prev    next >
Makefile  |  1985-11-20  |  4KB  |  102 lines

  1.  ; Program Name: MAKEFILE.S
  2.  ;      Version: 1.001
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;    Assemble in PC-relative mode and save with a TOS suffix.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;    This program is spawned by PRG_8CR.ACC.  Both programs must reside in
  11.  ; the same directory.
  12.  
  13.  ; Function:
  14.  
  15.  ;    This program creates disk file specified in the first environmental string
  16.  ; and stores therein the data contained in PRG_8CR.ACC's buffer.  The purpose
  17.  ; of this exercise is to illustrate an elegant method of creating a disk file
  18.  ; for a desk accessory, writing data to the file and invoking proper file
  19.  ; closure.
  20.  
  21. fetch_command_line_address:
  22.  lea        -$82(pc), a3
  23.  
  24. fetch_environmental_string_address:
  25.  lea        -$54(a3), a4         ; Fetch address of string pointer.
  26.  movea.l    (a4), a4             ; Fetch address of string.
  27.  
  28.  ; The data in the command line is a string of eight ASCII hexadecimal digits
  29.  ; passed from PRG_8CR.ACC when that program spawned this one.  There are no
  30.  ; characters before that string and none following.  The string is the address
  31.  ; of PRG_8CR.ACC's buffer, in which data that is to be written to a disk file
  32.  ; has been stored.  The address must be converted from an ASCII hexadecimal
  33.  ; string to a binary longword.
  34.  
  35.  ; The data in the environmental string can be used as it exist.
  36.  
  37. process_command_line:            ; Convert ASCII hexadecimal string to binary.
  38.  moveq.l    #0, d0               ; Accumulator.
  39.  moveq.l    #7, d2               ; Loop counter.
  40. convert_string:
  41.  move.b     (a3)+, d1            ; D1 is used for each character conversion.
  42.  cmpi.b     #$39, d1             ; Character greater than 9 test.
  43.  bgt        not_decimal
  44.  cmpi.b     #$30, d1             ; Character less than 0 test.
  45.  blt        not_valid
  46.  subi.b     #$30, d1             ; Convert ASCII hex character to binary.
  47.  bra.s      accumulate
  48. not_decimal:
  49.  cmpi.b     #$41, d1             ; Character less than A test.
  50.  blt        not_valid
  51.  cmpi.b     #$46, d1             ; Character greater than F test.
  52.  bgt        not_valid
  53.  subi.b     #$37, d1             ; Convert ASCII hex character to binary.
  54. accumulate:
  55.  lsl.l      #4, d0               ; Shift one nibble = one hex character.
  56.  add.b      d1, d0
  57.  dbra       d2, convert_string
  58.  move.l     d0, a3               ; Address of buffer is in D0.
  59.  movea.l    a3, a0               ; Copy for buffer byte count.
  60.  
  61. count_bytes_in_buffer:
  62.  moveq.l    #0, d0               ; NULL byte test register.
  63.  moveq.l    #0, d3               ; Byte count accumulator.
  64. count:
  65.  move.b     (a0)+, d0            ; Look at each character in buffer and
  66.  beq        create_file          ; accumulate count until NULL is found at
  67.  addq.l     #1, d3               ; end of buffer.
  68.  bra.s      count
  69.  
  70. create_file:                     ; COMPUTE! TOS book page 270.
  71.  move.w     #0, -(sp)            ; File attribute = read/write.
  72.  pea        (a4)                 ; Environmental string has file's path.
  73.  move.w     #$3C, -(sp)          ; Function = f_create = GEMDOS $3C.
  74.  trap       #1                   ; File handle is returned in D0.
  75.  addq.l     #8, sp
  76.  move.w     d0, d4               ; Save file handle in D4.
  77.  
  78. write_buffer_to_file:            ; Function = f_write.  COMPUTE! TOS p.274.
  79.  pea        (a3)                 ; Push buffer's address.
  80.  move.l     d3, -(sp)            ; Push byte count length.
  81.  move.w     d4, -(sp)            ; COMPUTE!'s TOS book incorrectly specifies
  82.  move.w     #$40, -(sp)          ; a longword operation here; see page 274.
  83.  trap       #1
  84.  lea        $C(sp), sp
  85.  
  86. close_output_file:               ; COMPUTE! TOS book page 272.
  87.  move.w     d4, -(sp)            ; Push file handle. 
  88.  move.w     #$3E, -(sp)          ; Function = GEMDOS $3E = f_close.
  89.  trap       #1
  90.  addq.l     #4, sp
  91.  
  92. not_valid:
  93. terminate:
  94.  move.w     #0, -(sp)
  95.  trap       #1
  96.  
  97.  data
  98.  align
  99.  bss
  100. program_end:  ds.l  0
  101.  end
  102.