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

  1.  ; Program Name: PRG_8AR.S
  2.  ;      Version: 1.006
  3.  
  4.  ; MAJOR NOTE:
  5.  
  6.  ;      THIS PROGRAM MAY NOT FUNCTION CORRECTLY IF TURBO ST IS INSTALLED.
  7.  
  8.  ; Assembly Instructions:
  9.  
  10.  ;      Assemble in Relocatable mode and save with a PRG extension.  From
  11.  ; the desktop, change the extension to ACC.  Programs that are to function
  12.  ; as desk accessories MUST be assembled in Relocatable mode.  If you design
  13.  ; a desk accessory so that it can be assembled in PC-relative mode, and if
  14.  ; you attempt to load that accessory via MultiDesk, you will receive an
  15.  ; error pertaining to the attempt to read in the accessory.  If you place
  16.  ; that accessory in the boot directory, the system will reset every time
  17.  ; it attempts to load the accessory.  Sei gewarnt! 
  18.  
  19.  ; Function:
  20.  
  21.  ;      This program is used to observe system corruption of AES arrays
  22.  ; during the execution of AES functions.  Data is output into a file which
  23.  ; assumes the name declared at the variable "filename".  You may wish to
  24.  ; alter the file's path to something like "A:\PRG_8DR.DAT" if you decide to
  25.  ; assemble and execute the program.
  26.  
  27.  ;      The program's output data is written with GEMDOS function $9, the write
  28.  ; string to screen function.  But the data is redirected to the file with
  29.  ; GEMDOS function $46, the f_force function.
  30.  
  31.  ; Execution Instructions:
  32.  
  33.  ;      Place PRG_8AR.ACC in the root directory of your boot disk.  During
  34.  ; the next power-up cycle, the program will be installed in memory as a desk
  35.  ; accessory; assuming that it is not blocked by a program that permits desk
  36.  ; accessory loading selections.  Of course, if you use MultiDesk, you need
  37.  ; not power up to use PRG_8AR.ACC immediately.
  38.  
  39.  ;      The desk accessory is identified as a menu selection by the name
  40.  ; Accessory Arrays.  Choose the desk accessory twice so that the contents
  41.  ; of the arrays will be printed twice from within the message handler.  The
  42.  ; message handler is disabled after it has been invoked twice.
  43.  
  44.  ; MAJOR NOTE:
  45.  
  46.  ;      Although accessories such as MultiDesk add significant power to a ST
  47.  ; system; and although initial testing of a desk accessory program can be
  48.  ; accomplished via MultiDesk loading of the program, thereby alleviating the
  49.  ; the testing process, the program under test cannot be pronounced correct
  50.  ; until it has been permitted to load normally from the boot disk.
  51.  
  52.  ;      For example, if the first statement of this program, which loads the
  53.  ; stack's address into A7, is moved to a location following any instruction
  54.  ; that requires stack usage, the accessory will function perfectly when it is
  55.  ; loaded and executed via MultiDesk; but it will bomb during boot because, at
  56.  ; that time, no default stack has yet been assigned by the system.
  57.  
  58.  ; REMEMBER:  Programs executed during boot MUST provide their own stacks.
  59.  
  60.  ; NOTE: Within the program, registers are used as variables as much as
  61.  ;       possible to speed things up.
  62.  
  63.  lea        stack(pc), a7        ; This must be the first instruction.
  64.  
  65. create_output_file:              ; COMPUTE! TOS book page 270.
  66.  move.w     #0, -(sp)            ; File attribute = read/write.
  67.  pea        filename(pc)
  68.  move.w     #$3C, -(sp)          ; Function = f_create = GEMDOS $3C.
  69.  trap       #1                   ; File handle is returned in D0.
  70.  addq.l     #8, sp
  71.  move.w     d0, handle
  72.  
  73. redirect_output_bound_for_screen:
  74.  
  75.  ; NOTE: If the output file's handle is exchanged with the video screen's
  76.  ;       handle, then the printline function = GEMDOS $9 can be used to 
  77.  ;       write to the file.
  78.  
  79. redirect_output:                 ; Exchange file handle with screen's handle.
  80.  move.w     handle(pc), -(sp)    ; This is the disk file's handle.
  81.  move.w     #1, -(sp)            ; This is the video screen's handle.
  82.  move.w     #$46, -(sp)          ; Function = f_force = GEMDOS $46.
  83.  trap       #1
  84.  addq.l     #6, sp
  85.  
  86. initialize_register_variables:
  87.  move.w     #$C8, d3             ; *** D3 is variable for AES call number.
  88.  lea        aes_pb(pc), a5       ; A5 is pointer to array address block.
  89.  lea        control(pc), a4      ; A4 is pointer for array 'control'.
  90.  lea        hex_table(pc), a3    ; A3 points to hexadecimal ASCII digits.
  91.  
  92.  ; For each test point, the contents of each AES array are printed.
  93.  
  94.  ;                           
  95.  ;                 TEST POINT 0: Before appl_init     
  96.  ;                           
  97.  bsr        print_arrays
  98.  
  99. initialize_application:          ; COMPUTE! AES book page 223.
  100.  
  101.  ; Application identification = apid returned in int_out[0] and global[2].
  102.  
  103.  move.w     #$A, (a4)            ; Function = appl_init = AES $A.
  104.  move.w     #0, 2(a4)            ; Input no 16-bit integer parameters.
  105.  move.w     #1, 4(a4)            ; Return one 16-bit integer parameter.
  106.  move.w     #0, 6(a4)            ; Input no 32-bit pointer parameters.
  107.  move.w     #0, 8(a4)            ; Return no 32-bit pointer parameters.
  108.  bsr        aes                  ; Invoke trap #2 AES exception.
  109.  
  110.  ;
  111.  ;          TEST POINT 1: After appl_init, before menu_register
  112.  ;
  113.  bsr        print_arrays
  114.  
  115. menu_installation:               ; COMPUTE! AES book page 248.
  116.  
  117.  ; Menu identification number returned in int_out[0].
  118.              
  119.  move.w     #$23, (a4)           ; Function = menu_register = AES $23.
  120.  move.w     #1, 2(a4)            ; Input one 16-bit integer parameter.
  121.  move.w     #1, 4(a4)            ; Return one 16-bit integer parameter.    
  122.  move.w     #1, 6(a4)            ; Input one 32-bit pointer parameter.
  123.  move.w     #0, 8(a4)            ; Return no 32-bit pointer parameters.
  124.  lea        global(pc), a0       ; Fetch address of global array.
  125.  move.w     4(a0), int_in        ; Application identification to int_in[0].
  126.  move.l     #menu_text, addr_in  ; Menu text address to addr_in[0].
  127.  bsr        aes                 
  128.  move.w     int_out(pc), menu_id ; Store menu identification number.
  129.  
  130.  ; MAIN ACCESSORY LOOP
  131.  
  132.  ;
  133.  ;          TEST POINT 2: After menu_register, before evnt_mesag
  134.  ;
  135.  bsr        print_arrays
  136.  
  137.  move.l     #message, addr_in    ; Address of message array to addr_in. 
  138. wait_for_message:                ; COMPUTE! AES book page 235.
  139.  move.w     #$17, (a4)           ; Function = evnt_mesag = AES $17.
  140.  move.w     #0, 2(a4)            ; Input one 16-bit integer parameter.
  141.  move.w     #1, 4(a4)            ; Return one 16-bit integer parameter.    
  142.  move.w     #1, 6(a4)            ; Input one 32-bit pointer parameter.
  143.  move.w     #0, 8(a4)            ; Return no 32-bit pointer parameters.
  144.  bsr        aes
  145.  
  146.  ; When a message is received it is placed in array 'message'.
  147.  
  148.  ; ****************************************************************************
  149.  ; ****************************************************************************
  150.  
  151. message_handler:                 ; Entrance point when message is received.
  152.  lea        message(pc), a0      ; Fetch address of array 'message'.
  153.  cmpi.w     #$28, (a0)           ; Compare ACCESSORY OPEN code with message[0].
  154.  bne.s      wait_for_message     ; Execute the evnt_mesag function.
  155.  move.w     8(a0), d0            ; The menu item selected is stored in element
  156.                                  ; four (message[4]) of array 'message'.  This
  157.                                  ; application's id # is in menu_id.
  158.  cmp.w      menu_id(pc), d0      ; Was this application selected.
  159.  bne.s      wait_for_message     ; Execute the evnt_mesag function.
  160.  
  161.  ; ****************************************************************************
  162.  ; ****************************************************************************
  163.  
  164.  ; Execution proceeds past this point only when this application has been
  165.  ; selected from the menu.
  166.  
  167.  cmpi.w     #5, test             ; Have five array groups been printed?
  168.  beq        wait_for_message     ; Disable message handler if true.
  169.  ;
  170.  ;          TEST POINT 3: In message handler, before evnt_mesag
  171.  ;
  172.  bsr        print_arrays
  173.  cmpi.w     #5, test             ; Branch after 2nd entrance in message handler.
  174.  beq.s      close_file         
  175.  bra        wait_for_message     ; Execute the evnt_mesag function.
  176.  
  177. close_file:
  178.  move.w     handle(pc), -(sp) 
  179.  move.w     #$3E, -(sp)          ; Function = GEMDOS $3E = f_close.
  180.  trap       #1
  181.  addq.l     #4, sp
  182. redirect_screen_output:
  183.  move.w     #1, -(sp)            ; This is the screen's handle.
  184.  move.w     handle(pc), -(sp)    ; This is the file's handle.
  185.  move.w     #$46, -(sp)          ; Function = f_force = GEMDOS $46.
  186.  trap       #1
  187.  addq.l     #6, sp
  188.  bra        wait_for_message
  189.  
  190.  ;
  191.  ; SUBROUTINES
  192.  ;
  193.  
  194. print_arrays:
  195.  lea        newline(pc), a0       
  196.  bsr        print_line        
  197.  lea        test_header(pc), a0  ; Setup to fetch test point header.
  198.  move.w     test(pc), d0         ; Load test point number into D0.
  199.  lsl.w      #2, d0               ; Multiply by 4 to reach next pointer slot.     
  200.  movea.l    0(a0,d0.w), a0       ; Print test point header.
  201.  bsr        print_line
  202.  lea        pre_spaces(pc), a0   ; Print spaces before column headers.
  203.  bsr        print_line
  204.  lea        aes_names(pc), a0    ; Print AES array column headers.
  205.  bsr        print_line
  206.  lea        pre_spaces(pc), a0   ; Print spaces before underline.
  207.  bsr        print_line
  208.  lea        aes_underline(pc), a0; Print AES underline.
  209.  bsr        print_line
  210.  moveq.l    #0, d7               ; D7 is up counter to print 5 rows.
  211.  moveq.l    #4, d6               ; D6 is down counter to print 5 elements.
  212. put_row:
  213.  lea        buffer(pc), a0       ; Buffer is an 80 byte line buffer.
  214.  movea.l    a5, a6               ; Copy aes parameter block address.
  215.  move.w     #5, d5               ; D5 is array counter for 6 arrays.
  216.  move.w     #11, d0              ; Print beginning spaces to line up columns.
  217. put_space:
  218.  move.b     #$20, (a0)+
  219.  dbra       d0, put_space
  220. put_element:                     ; Print contents of array element.
  221.  move.w     d7, d0               ; Print array element number.
  222.  andi.b     #$F, d0              ; Mask most significant nibble.
  223.  move.b     0(a3,d0.w), d0       ; Store appropriate hex character in D0.
  224.  move.b     d0, (a0)+
  225.  move.b     #$3A, (a0)+          ; A colon.
  226.  move.b     #$20, (a0)+          ; A space.
  227.  move.w     d7, d0               ; Multiply contents of D7 by 2 in D0 to
  228.  lsl.w      #1, d0               ; obtain offset for next array element.
  229.  movea.l    (a6)+, a1            ; Copy array address into A1 and increment
  230.                                  ; A6 to point to next array address.
  231.  move.w     0(a1,d0.w), d0       ; Fetch contents of array element.
  232.  moveq      #3, d2               ; D2 is loop counter for ASCII conversion.
  233. convert_digit:                   ; Convert a nibble, then print it.
  234.  rol.w      #4, d0               ; Rotate most significant nibble to the
  235.                                  ; least significant nibble position.
  236.  move.b     d0, d1               ; Copy least significant byte of D0 to D1.
  237.  andi.b     #$F, d1              ; Mask out most significant nibble of D1.
  238.  ext.w      d1                   ; Extend to word length.
  239.  move.b     0(a3,d1.w), d1       ; Fetch ASCII hex digit to D1.
  240. put_digit:
  241.  move.b     d1, (a0)+
  242.  dbra       d2, convert_digit    ; Loop until D2 = -1.
  243. _put_spaces:
  244.  move.b     #$20, (a0)+
  245.  move.b     #$20, (a0)+
  246.  dbra       d5, put_element
  247.  move.b     #0, (a0)             ; Store NULL at end of string.
  248.  lea        buffer(pc), a0
  249.  bsr        print_line
  250.  lea        newline(pc), a0      ; Print a newline.
  251.  bsr        print_line
  252.  addi.w     #1, d7               ; Increment up counter.
  253.  dbra       d6, put_row
  254.  add.w      #1, test             ; Increment test for next test point.
  255.  rts
  256.  
  257. aes:                             ; COMPUTE! AES book page 13,
  258.  move.l     a5, d1               ; Address of aes_pb.
  259.  move.w     d3, d0               ; AES identifier = $C8.
  260.  trap       #2
  261.  rts
  262.  
  263. print_line:
  264.  move.l     a0, -(sp)            ; Push string onto stack.
  265.  move.w     #9, -(sp)            ; Function = c_conws.
  266.  trap       #1
  267.  addq.l     #6, sp
  268.  rts
  269.  
  270.  data
  271. aes_pb:       dc.l  control,global,int_in,int_out,addr_in,addr_out
  272. test_header:  dc.l  zero,one,two,three,four
  273. zero:
  274.  dc.b $D,$A,'TEST POINT 0: Before appl_init',$D,$A,$D,$A,0
  275. one:
  276.  dc.b $D,$A,'TEST POINT 1: After appl_init, before menu_register',$D,$A,$D,$A,0
  277. two:
  278.  dc.b $D,$A,'TEST POINT 2: After menu_register, before evnt_mesag',$D,$A,$D,$A,0
  279. three:
  280.  dc.b $D,$A,'TEST POINT 3: In message handler, before evnt_mesag',$D,$A,$D,$A,0
  281. four:
  282.  dc.b $D,$A,'TEST POINT 4: In message handler second time',$D,$A,$D,$A,0
  283.  
  284. hex_table:    dc.b   '0123456789ABCDEF'
  285. newline:      dc.b   $D,$A,0
  286. aes_header:   dc.b   '                                AES ARRAYS',$D,$A,0
  287. aes_names:    dc.b   'CONTROL  GLOBAL   INT_IN   INT_OUT  ADDR_IN  '
  288.               dc.b   'ADDR_OUT',$D,$A,0
  289. aes_underline:dc.b   '-------  -------  -------  -------  -------  '
  290.               dc.b   '--------',$D,$A,0
  291. pre_spaces:   dc.b   '            ',0
  292. spaces:       dc.b   '  ',0
  293. menu_text:    dc.b   '  Accessory Arrays ',0
  294. filename:     dc.b   'E:\PRG_8\PRG_8AR.DAT',0
  295.  
  296.  bss
  297.  align
  298.  
  299.  ;
  300.  ; AES ARRAYS:
  301.  ;
  302.  
  303.  ;     The addresses of the arrays declared below will be stored in the pointer
  304.  ; array 'aes_pb'.  That happens because the program is assembled in Relocatable
  305.  ; mode.  The sizes declared for the arrays are identical simply because I am
  306.  ; making it easy to line up the program's output.
  307.  
  308. control:      ds.w     5  ; Control parameters.
  309. global:       ds.w     5  ; Global parameters.
  310. int_in:       ds.w     5  ; Input parameters.
  311. int_out:      ds.w     5  ; Output parameters.
  312. addr_in:      ds.w     5  ; Input addresses.
  313. addr_out:     ds.w     5  ; Output addresses.
  314.  
  315.  ;
  316.  ; APPLICATION VARIABLES
  317.  ;
  318.  
  319. handle:       ds.w     1
  320. test:         ds.w     1
  321. message:      ds.l     4  ; 16 byte array.
  322. menu_id:      ds.w     1
  323. buffer:       ds.b    80
  324.               ds.l   300  ; Program stack.
  325. stack:        ds.l     0  ; Address of program stack.
  326.  end
  327.  
  328.