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

  1.  ; Program Name: PRG_6HP.S
  2.  ;      Version: 1.001
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in PC-relative mode and save with a TOS extension.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;     Execute from the desktop.
  11.  
  12.  ; Program Function:
  13.  
  14.  ; A shorter version of PRG_6GP.S.  In addition this program provides a way
  15.  ; to verify that the trap #13 system function corrupts the stack.
  16.  
  17.  ; Just before the trap #13 function is invoked to print a character, three
  18.  ; words of data must be pushed onto the stack.  This having been done once,
  19.  ; it should thenceforth be sufficient to simply move character data into the
  20.  ; appropriate location within the stack to continue printing characters, as
  21.  ; long as the stack pointer is not altered by the program.
  22.  
  23.  ; Unfortunately, the location at which the trap #13 function number is
  24.  ; pushed or stored is corrupted by the trap when it is invoked, therefore,
  25.  ; it is necessary to restore the function number each time, just before the
  26.  ; trap is invoked again.  So we lose an advantage.
  27.  
  28.  ; But the device to which the character is printed is not changed, so we
  29.  ; can take advantage of that to store it once, before we start printing 
  30.  ; characters.
  31.  
  32.  ; Only after all characters are printed is the stack repositioned to the
  33.  ; top of the stack.  In fact, in this program, I wait until after the
  34.  ; wait_for_keypress algorithm has been executed before repositioning the
  35.  ; stack pointer.
  36.  
  37. mainline:
  38.  lea        stack, a7           ; Point A7 to this program's stack.
  39.  
  40. execute_subroutine_in_supervisor_mode:
  41.  pea        subroutine          ; Push address of subroutine onto stack.
  42.  move.w     #$26, -(sp)         ; Function = superexec = XBIOS $26 (dec 38).
  43.  trap       #14                 ; XBIOS call.
  44.  addq.l     #6, sp
  45.  
  46. terminate:
  47.  move.w     #0, -(sp)           ; Function = p_term_old = GEMDOS $0.
  48.  trap       #1                  ; GEMDOS call.
  49.  
  50. subroutine:         
  51.  move.b     #6, $484            ; Turn keyclick off.
  52.  pea        message             ; Push address of first string.
  53.  move.w     #$9, -(sp)          ; GEMDOS function $9 = c_conws.
  54.  trap       #1                  ; Print first string.
  55.  addq.l     #6, sp
  56.  lea        message_2, a3       ; Load address of second string.
  57. SET_UP_STACK:                   ; DO THIS BEFORE CHARACTER PRINTING COMMENCES.
  58.  MOVE.W     #0, -(SP)           ; MAKE ROOM FOR CHARACTER TO BE PRINTED.
  59.  MOVE.W     #2, -(SP)           ; OUTPUT DEVICE = SCREEN.
  60.  MOVE.W     #3, -(SP)           ; FUNCTION = BIOS #3.
  61.  MOVE.W     #3, D4              ; BECAUSE TRAP #13 CORRUPTS STACK.
  62. print_string:
  63.  move.b     (a3)+, d3
  64.  beq.s      wait_for_keypress
  65.  move.w     d4, (sp)            ; Restore BIOS function number because
  66.  move.w     d3, 4(sp)           ; Trap #13 corrupts stack.
  67.  trap       #13
  68.  bra.s      print_string        ; Branch until NULL detected.
  69. wait_for_keypress: 
  70.  move.w     #8, -(sp)           ; Function = c_necin = GEMDOS $8.
  71.  trap       #1                  ; GEMDOS call.
  72.  addq.l     #8, sp              ; Reposition stack pointer at top of stack.
  73.  rts
  74.  
  75.  data
  76. message:     dc.b 'This string printed with GEMDOS function $9.',$D,$A,0
  77. message_2:   dc.b 'This string printed with BIOS function $3.',$D,$A,0
  78.  align
  79.  bss
  80.              ds.l    48         ; Stack.  Must be large enough for system
  81.                                 ; use when the switch to supervisor mode
  82.                                 ; is accomplished by GEMDOS $26.
  83. stack:       ds.l     0         
  84. program_end: ds.l     0
  85.  end
  86.