home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / books / 68k_book / arp_src / prg_8br.s < prev    next >
Text File  |  1985-11-20  |  12KB  |  285 lines

  1.  ; Program Name: PRG_8BR.S
  2.  ;      Version: 1.002
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;      Assemble in Relocatable mode and save with a PRG extension.  From
  7.  ; the desktop, change the extension to ACC.  Programs that are to function
  8.  ; as desk accessories MUST be assembled in Relocatable mode.  If you design
  9.  ; a desk accessory so that it can be assembled in PC-relative mode, and if
  10.  ; you attempt to load that accessory via MultiDesk, you will receive an
  11.  ; error pertaining to the attempt to read in the accessory.  If you place
  12.  ; that accessory in the boot directory, the system will reset every time
  13.  ; it attempts to load the accessory.  Sei gewarnt! 
  14.  
  15.  ; Function:
  16.  
  17.  ;      This program is used to observe system corruption of AES arrays
  18.  ; during the execution of AES functions, as does PRG_8AR.S, and this program
  19.  ; also creates a file in which to store its output data, but this program
  20.  ; does not write its data via GEMDOS function $9 and redirection; instead it
  21.  ; stores the data in a buffer, then writes the contents of the buffer to the
  22.  ; file using GEMDOS function $40.
  23.  
  24.  ;      Also note some of the short cuts taken to prepare the control array
  25.  ; for each AES function.
  26.  
  27.  ; Execution Instructions:
  28.  
  29.  ;      Place PRG_8BR.ACC in the root directory of your boot disk.  During the
  30.  ; next power-up cycle, the desk accessory will be installed.  From the desktop
  31.  ; select 'Accessory Arrays' two times in order to store the pertinent data in
  32.  ; the file buffer.  After the second selection, the file will be created and
  33.  ; the buffer's contents will be written thereto.  You can execute the desk
  34.  ; accessory from within MultiDesk if you desire.  You may want to change the
  35.  ; path for the file so that it is created on another disk or partition.
  36.  
  37.  lea        stack, a7            ; This must be the first instruction.
  38.  
  39. initialize_register_variables:
  40.  lea        buffer(pc), a5       ; A5 is pointer to buffer.
  41.  lea        control(pc), a4      ; A4 is pointer for array 'control'.
  42.  lea        hex_table(pc), a3    ; A3 points to hexadecimal ASCII digits.
  43.  
  44.  ; For each test point, the contents of each AES array are printed.
  45.  
  46.  ;                           
  47.  ;                 TEST POINT 0: Before appl_init     
  48.  ;                           
  49.  bsr        print_arrays
  50.  
  51. initialize_application:          ; COMPUTE! AES book page 223.
  52.  
  53.  ; Application identification = apid returned in int_out[0] and global[2].
  54.  
  55.  move.w     #$A, (a4)            ; Function = appl_init = AES $A.
  56.  move.w     #1, 4(a4)            ; Return one 16-bit integer parameter.
  57.  bsr        aes                  ; Invoke trap #2 AES exception.
  58.  
  59.  ;
  60.  ;          TEST POINT 1: After appl_init, before menu_register
  61.  ;
  62.  bsr        print_arrays
  63.  
  64. menu_installation:               ; COMPUTE! AES book page 248.
  65.  
  66.  ; Menu identification number returned in int_out[0].
  67.              
  68.  move.w     #$23, (a4)           ; Function = menu_register = AES $23.
  69.  move.w     #1, 2(a4)            ; Input one 16-bit integer parameter.
  70.  move.w     #1, 6(a4)            ; Input one 32-bit pointer parameter.
  71.  lea        global(pc), a0       ; Fetch address of global array.
  72.  move.w     4(a0), int_in        ; Application identification to int_in[0].
  73.  move.l     #menu_text, addr_in  ; Menu text address to addr_in[0].
  74.  bsr        aes                 
  75.  move.w     int_out(pc), menu_id ; Store menu identification number.
  76.  
  77.  ; MAIN ACCESSORY LOOP
  78.  
  79.  ;
  80.  ;          TEST POINT 2: After menu_register, before evnt_mesag
  81.  ;
  82.  bsr        print_arrays
  83.  
  84.  move.l     #message, addr_in    ; Address of message array to addr_in. 
  85.  move.w     #$17, (a4)           ; Function = evnt_mesag = AES $17.
  86.  move.w     #0, 2(a4)            ; Input one 16-bit integer parameter.
  87.  move.w     #1, 4(a4)            ; Return one 16-bit integer parameter.    
  88.  move.w     #1, 6(a4)            ; Input one 32-bit pointer parameter.
  89. wait_for_message:
  90.  bsr        aes
  91.  
  92.  ; When a message is received it is placed in array 'message'.
  93.  
  94.  ; ****************************************************************************
  95.  ; ****************************************************************************
  96.  
  97. message_handler:                 ; Entrance point when message is received.
  98.  lea        message(pc), a0      ; Fetch address of array 'message'.
  99.  cmpi.w     #$28, (a0)           ; Compare ACCESSORY OPEN code with message[0].
  100.  bne.s      wait_for_message     ; Execute the evnt_mesag function.
  101.  move.w     8(a0), d0            ; The menu item selected is stored in element
  102.                                  ; four (message[4]) of array 'message'.  This
  103.                                  ; application's id # is in menu_id.
  104.  cmp.w      menu_id(pc), d0      ; Was this application selected.
  105.  bne.s      wait_for_message     ; Execute the evnt_mesag function.
  106.  
  107.  ; ****************************************************************************
  108.  ; ****************************************************************************
  109.  
  110.  ; Execution proceeds past this point only when this application has been
  111.  ; selected from the menu.
  112.  
  113.  ;
  114.  ;          TEST POINT 3: In message handler, before evnt_mesag
  115.  ;
  116.  cmpi.w     #5, test             ; Have five array groups been printed.
  117.  beq        wait_for_message     ; This effectively disables the handler.
  118.  bsr        print_arrays
  119.  cmpi.w     #5, test             ; Branch after 2nd entrance in message handler.
  120.  beq.s      store_in_file        ; Create file and store buffer contents.
  121.  bra        wait_for_message     ; Execute the evnt_mesag function.
  122.  
  123. store_in_file:
  124.  lea        buffer(pc), a6       ; Fetch start address.
  125.  suba.l     a6, a5               ; Calculate number of bytes stored in buffer.
  126.  
  127. create_file:                     ; COMPUTE! TOS book page 270.
  128.  move.w     #0, -(sp)            ; File attribute = read/write.
  129.  pea        filename(pc)
  130.  move.w     #$3C, -(sp)          ; Function = f_create = GEMDOS $3C.
  131.  trap       #1                   ; File handle is returned in D0.
  132.  addq.l     #8, sp
  133.  move.w     d0, d4               ; Save file handle in D4.
  134.  
  135. write_buffer_to_file:            ; Function = f_write.  COMPUTE! TOS p.274.
  136.  pea        (a6)                 ; Push buffer's address.
  137.  move.l     a5, -(sp)            ; Push byte count length.
  138.  move.w     d4, -(sp)            ; COMPUTE!'s TOS book incorrectly specifies
  139.  move.w     #$40, -(sp)          ; a longword operation here; see page 274.
  140.  trap       #1
  141.  lea        $C(sp), sp
  142.  
  143. close_output_file:               ; COMPUTE! TOS book page 272.
  144.  move.w     d4, -(sp)            ; Push file handle. 
  145.  move.w     #$3E, -(sp)          ; Function = GEMDOS $3E = f_close.
  146.  trap       #1
  147.  addq.l     #4, sp
  148.  bra        wait_for_message     ; Execute the evnt_mesag function.
  149.  
  150.  ;
  151.  ; SUBROUTINES
  152.  ;
  153.  
  154. print_arrays:
  155.  lea        newline(pc), a0       
  156.  bsr        store_line        
  157.  lea        test_header(pc), a0  ; Setup to fetch test point header.
  158.  move.w     test(pc), d0         ; Load test point number into D0.
  159.  lsl.w      #2, d0               ; Multiply by 4 to reach next pointer slot.     
  160.  movea.l    0(a0,d0.w), a0       ; Print test point header.
  161.  bsr        store_line
  162.  lea        pre_spaces(pc), a0   ; Print spaces before column headers.
  163.  bsr        store_line
  164.  lea        aes_names(pc), a0    ; Print AES array column headers.
  165.  bsr        store_line
  166.  lea        pre_spaces(pc), a0   ; Print spaces before underline.
  167.  bsr        store_line
  168.  lea        aes_underline(pc), a0; Print AES underline.
  169.  bsr        store_line
  170.  moveq.l    #0, d7               ; D7 is up counter to print 5 rows.
  171.  moveq.l    #4, d6               ; D6 is down counter to print 5 elements.
  172. put_row:
  173.  lea        aes_pb(pc), a6       ; Fetch parameter block address.
  174.  move.w     #5, d5               ; D5 is array counter for 6 arrays.
  175.  move.w     #11, d0              ; Print beginning spaces to line up columns.
  176. put_space:
  177.  move.b     #$20, (a5)+
  178.  dbra       d0, put_space
  179. put_element:                     ; Print contents of array element.
  180.  move.w     d7, d0               ; Print array element number.
  181.  andi.b     #$F, d0              ; Mask most significant nibble.
  182.  move.b     0(a3,d0.w), d0       ; Store appropriate hex character in D0.
  183.  move.b     d0, (a5)+
  184.  move.b     #$3A, (a5)+          ; A colon.
  185.  move.b     #$20, (a5)+          ; A space.
  186.  move.w     d7, d0               ; Multiply contents of D7 by 2 in D0 to
  187.  lsl.w      #1, d0               ; obtain offset for next array element.
  188.  movea.l    (a6)+, a1            ; Copy array address into A1 and increment
  189.                                  ; A6 to point to next array address.
  190.  move.w     0(a1,d0.w), d0       ; Fetch contents of array element.
  191.  moveq      #3, d2               ; D2 is loop counter for ASCII conversion.
  192. convert_digit:                   ; Convert a nibble, then print it.
  193.  rol.w      #4, d0               ; Rotate most significant nibble to the
  194.                                  ; least significant nibble position.
  195.  move.b     d0, d1               ; Copy least significant byte of D0 to D1.
  196.  andi.b     #$F, d1              ; Mask out most significant nibble of D1.
  197.  ext.w      d1                   ; Extend to word length.
  198.  move.b     0(a3,d1.w), d1       ; Fetch ASCII hex digit to D1.
  199. put_digit:
  200.  move.b     d1, (a5)+
  201.  dbra       d2, convert_digit    ; Loop until D2 = -1.
  202. _put_spaces:
  203.  move.b     #$20, (a5)+
  204.  move.b     #$20, (a5)+
  205.  dbra       d5, put_element
  206.  lea        newline(pc), a0      ; Print a newline.
  207.  bsr        store_line
  208.  addi.w     #1, d7               ; Increment up counter.
  209.  dbra       d6, put_row
  210.  add.w      #1, test             ; Increment test for next test point.
  211.  rts
  212.  
  213. aes:                             ; COMPUTE! AES book page 13,
  214.  move.l     #aes_pb, d1          ; Address of aes_pb.
  215.  move.w     #$C8, d0             ; AES identifier = $C8.
  216.  trap       #2
  217.  rts
  218.  
  219. store_line:
  220.  move.b     (a0)+, d0
  221.  beq.s      end_of_string
  222.  move.b     d0, (a5)+            ; Store byte in buffer.
  223.  bra.s      store_line
  224. end_of_string:
  225.  rts
  226.  
  227.  data
  228. aes_pb:          dc.l control,global,int_in,int_out,addr_in,addr_out
  229. test_header:     dc.l zero,one,two,three,four
  230. zero:
  231.  dc.b $D,$A,'TEST POINT 0: Before appl_init',$D,$A,$D,$A,0
  232. one:
  233.  dc.b $D,$A,'TEST POINT 1: After appl_init, before menu_register',$D,$A,$D,$A,0
  234. two:
  235.  dc.b $D,$A,'TEST POINT 2: After menu_register, before evnt_mesag',$D,$A,$D,$A,0
  236. three:
  237.  dc.b $D,$A,'TEST POINT 3: In message handler, before evnt_mesag',$D,$A,$D,$A,0
  238. four:
  239.  dc.b $D,$A,'TEST POINT 4: In message handler second time',$D,$A,$D,$A,0
  240.  
  241. hex_table:      dc.b  '0123456789ABCDEF'
  242. newline:        dc.b  $D,$A,0
  243. aes_header:     dc.b  '                                AES ARRAYS',$D,$A,0
  244. aes_names:      dc.b  'CONTROL  GLOBAL   INT_IN   INT_OUT  ADDR_IN  '
  245.                 dc.b  'ADDR_OUT',$D,$A,0
  246. aes_underline:  dc.b  '-------  -------  -------  -------  -------  '
  247.                 dc.b  '--------',$D,$A,0
  248. pre_spaces:     dc.b  '            ',0
  249. spaces:         dc.b  '  ',0
  250. menu_text:      dc.b  '  Accessory Arrays ',0
  251. filename:       dc.b  'E:\PRG_8\PRG_8BR.DAT',0
  252.  
  253.  bss
  254.  align
  255.  ;
  256.  ; AES ARRAYS:
  257.  ;
  258.  
  259.  ;     The addresses of the arrays declared below will be stored in the pointer
  260.  ; array 'aes_pb'.  That happens because the program is assembled in Relocatable
  261.  ; mode.  The sizes declared for the arrays are identical simply because I am
  262.  ; making it easy to line up the program's output.
  263.  
  264. control:      ds.w     5  ; Control parameters.
  265. global:       ds.w     5  ; Global parameters.
  266. int_in:       ds.w     5  ; Input parameters.
  267. int_out:      ds.w     5  ; Output parameters.
  268. addr_in:      ds.w     5  ; Input addresses.
  269. addr_out:     ds.w     5  ; Output addresses.
  270.  
  271.  ;
  272.  ; APPLICATION VARIABLES
  273.  ;
  274.  
  275. file_handle:  ds.w     1
  276. test:         ds.w     1
  277. message:      ds.l     4  ; 16 byte array.
  278. menu_id:      ds.w     1
  279. buffer:       ds.l $2000
  280.               ds.l   300  ; Program stack.
  281. stack:        ds.l     0  ; Address of program stack.
  282.  end
  283.  
  284.  
  285.