home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1992 / USERAU92.MSA / ASSEMBLY_JUNE_PROG0006.S < prev    next >
Text File  |  1992-03-13  |  4KB  |  124 lines

  1. *****************************************************************
  2. *  Atari ST User Assembler Tutorial Series Program PROG0006.S   *
  3. *  This program should be assembled to disk as PROG0006.PRG or  *
  4. *  PROG0006.TOS. It can then be executed by double-clicking on  *
  5. *  the program file created.                    *
  6. *****************************************************************
  7. * This program is an example of using the CoMPare and Branch    *
  8. * instructions to control the execution of a program.        *
  9. * When run, a ball bounces about the screen. The CMP and TST    *
  10. * instructions are used to check for the ball hitting the edge  *
  11. * and also for a key being pressed.                *
  12. *****************************************************************
  13. start:
  14. *
  15.     MOVE.W    #4,-(SP)    ;XBIOS 4 returns the screen mode
  16.     TRAP    #14        ;in register D0
  17.     ADDQ.L    #2,SP        ;Correct the Stack Pointer
  18. *
  19.     TST.W    D0        ;Test Screen Mode...
  20.     BEQ    low_res        ;0 = Low Resolution
  21. * We must be in Medium or High resolution
  22.     MOVE.B    #80,width    ;Make screen width 80 characters
  23.     BRA    cont        ;and carry on.
  24. low_res:
  25.     MOVE.B    #40,width    ;Make screen width 40 characters
  26. cont:
  27.     MOVE.B    #1,D7        ;Use D7 as X velocity
  28.     MOVE.B    #1,D6        ;Use D6 as Y velocity
  29.     MOVE.B    #20,D5        ;Use D5 as X position
  30.     MOVE.B    #20,D4        :Use D4 as Y position
  31.     MOVE.B    D5,x_pos    ;Store X pos (see comments later
  32.     ADD.B    #31,x_pos    ;for explanation of adding 31)
  33.     MOVE.B    D4,y_pos    ;Store Y pos
  34.     ADD.B    #31,y_pos
  35. *
  36.     MOVE.L    #cls,-(SP)    ;Clear screen
  37.     MOVE.W    #9,-(SP)    ;using GEMDOS 9 to print
  38.     TRAP    #1        ;call GEMDOS
  39.     ADD.L    #6,SP        ;Correct the Stack
  40. *
  41. loop:
  42.     MOVE.L    #pos,-(SP)    ;Position the cursor by printing
  43.     MOVE.W    #9,-(SP)    ;the sequence at pos using GEMDOS 9
  44.     TRAP    #1        ;call GEMDOS
  45.     ADD.L    #6,SP        ;Correct the Stack
  46. *
  47.     MOVE.W    #' ',-(SP)    ;Now print a space to erase the ball
  48.     MOVE.W    #2,-(SP)    ;using GEMDOS 2
  49.     TRAP    #1
  50.     ADD.L    #4,SP        ;Correct the Stack
  51. *
  52.     ADD.B    D7,D5        ;Update the x position
  53.     ADD.B    D6,D4        ;Update the y position
  54.     MOVE.B    D5,x_pos    ;Store X pos (see comments later
  55.     ADD.B    #31,x_pos    ;for explanation of adding 31)
  56.     MOVE.B    D4,y_pos    ;Store Y pos
  57.     ADD.B    #31,y_pos
  58. *
  59.     MOVE.L    #pos,-(SP)    ;Position the cursor by printing
  60.     MOVE.W    #9,-(SP)    ;the sequence at pos using GEMDOS 9
  61.     TRAP    #1        ;call GEMDOS
  62.     ADD.L    #6,SP        ;Correct the Stack
  63. *
  64.     MOVE.W    #'O',-(SP)    ;Now print an 'O' as the ball
  65.     MOVE.W    #2,-(SP)    ;using GEMDOS 2
  66.     TRAP    #1
  67.     ADD.L    #4,SP        ;Correct the Stack
  68. *
  69. test:    CMP.B    width,D5    ;Check X position for edge of screen
  70.     BLT    ok_1        ;X < edge - carry on
  71. *
  72.     MOVE.B    #-1,D7        ;Change X velocity to move left
  73.     BRA    check_y        ;Now go check Y position
  74. *
  75. ok_1:    CMP.B    #2,D5        ;Check X position for left edge
  76.     BGE    check_y        ;X > edge - carry on
  77. *
  78.     MOVE.B    #1,D7
  79. *
  80. check_y:
  81.     CMP.B    depth,D4    ;Check Y position for bottom of screen
  82.     BLT    ok_2        ;Y < bottom - carry on
  83. *
  84.     MOVE.B    #-1,D6        ;Change Y velocity to go up
  85.     BRA    ok_3        ;and carry on
  86. *
  87. ok_2:    CMP.B    #2,D4        ;Check Y position for top of screen
  88.     BGE    ok_3        ;Y > top - carry on
  89. *
  90.     MOVE.B    #1,D6
  91. *
  92. ok_3:    MOVE.W    #$B,-(SP)    ;GEMDOS $B checks for key presses
  93.     TRAP    #1        ;Call GEMDOS
  94.     ADD.L    #2,SP        ;Correct the stack
  95.     TST.W    D0        ;Test D0 (returned from GEMDOS $B
  96.     BEQ    loop        ; No key pressed - keep looping
  97.  
  98. * .. and finally exit back to the desktop
  99.     CLR.W    -(SP)        ;0 is TERM
  100.     TRAP    #1        ;Call GEMDOS
  101. ******************************************************************
  102. * The section of program following contains the Data used by the *
  103. * program which is assembled and saved as part of the program.   *
  104.     SECTION DATA
  105. *
  106. width:    DC.B    0
  107. depth:    DC.B    24
  108. *
  109. *
  110. cls:    DC.B    27,'E',27,'f',0    ;Clear screen and make sure cursor off
  111.     EVEN
  112. *
  113. * A little explanation of the below may be in order. To position *
  114. * the cursor the sequence of characters 27,'Y',y,x can be used.  *
  115. * In this case, y is actually the row number on the screen + 31, *
  116. * and x is the column number + 31.                               *
  117. *
  118. pos:    DC.B    27,'Y'
  119. y_pos:    DC.B    40        ;Y position of ball
  120. x_pos:    DC.B    40        ;X position of ball
  121.     DC.B    0        ;Terminating 0
  122.  
  123.     
  124. *****************************************************************