home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1992 / USERAU92.MSA / ASSEMBLY_PROG0010.S < prev    next >
Text File  |  1992-05-23  |  8KB  |  249 lines

  1. *****************************************************************
  2. *  Atari ST User Assembler Tutorial Series Program PROG0010.S   *
  3. *  This program should be assembled to disk as PROG0010.PRG or  *
  4. *  PROG0010.TOS. It can then be executed by double-clicking on  *
  5. *  the program file created.                    *
  6. *  Note that this program looks for the two Degas format files  *
  7. *  SOURCE.PI1 and DEST.PI1 in the same folder from which the    *
  8. *  program was run.                        *
  9. *****************************************************************
  10. * This program demonstrates the use of the BLIT routine and     *
  11. * Logical Operations. As set up, it uses logical operation 7    *
  12. * which is 'OR'. Change the line commented to any value from    *
  13. * 0 to 15 to see different effects.                *
  14. *****************************************************************
  15. start:    MOVE.L    #stack,SP    ;Set up our own stack
  16.     BSR    init        ;Initialize everything
  17.     BSR    show_blit    ;Do a few blits
  18. finish:
  19.     MOVE.W    #1,-(SP)    ;Get a key
  20.     TRAP    #1
  21.     ADDQ.L    #2,SP
  22. * Reset the screen resolution
  23.     MOVE.W    old_rez,-(SP)
  24.     MOVE.L    #-1,-(SP)
  25.     MOVE.L    #-1,-(SP)
  26.     MOVE.W    #5,-(SP)
  27.     TRAP    #14
  28.     LEA    12(SP),SP
  29. *
  30.     CLR.W    -(SP)        ;Finish the program
  31.     TRAP    #1
  32. **************************************************
  33. * INIT - Initialize the variables ready to start *
  34. **************************************************
  35. init:    
  36. * Store the current screen resolution (so we can return to it on exit)
  37.     MOVE.W    #4,-(SP)    ;XBIOS 4 returns graphics resolution
  38.     TRAP    #14        ;in D0 (0-Low, 1-Medium, 2-High)
  39.     ADDQ.L    #2,SP
  40.     MOVE.W    D0,old_rez    ;Store resolution
  41. * And set Low resolution
  42.     CLR.W    -(SP)        ;0 = low resolution
  43.     MOVE.L    #-1,-(SP)    ;Don't change screen addresses
  44.     MOVE.L    #-1,-(SP)
  45.     MOVE.W    #5,-(SP)
  46.     TRAP    #14
  47.     LEA    12(SP),SP
  48. * Get addresses of two screens
  49.     MOVE.W    #2,-(SP)    ;XBIOX 2 returns current screen address
  50.     TRAP    #14        ;in D0
  51.     ADDQ.L    #2,SP
  52.     MOVE.L    D0,screen_1    ;Store as screen 1
  53.     SUB.L    #32000,D0    ;Subtract 32000
  54.     MOVE.L    D0,screen_2    ;and store as screen 2
  55.     SUB.L    #32000,D0    ;Subtract 32000
  56. *
  57. * Now load the destination screen into memory
  58.     MOVE.L    screen_1,A3    ;Address to load it
  59.     MOVE.L    #dst_file,A1    ;Address of file name
  60.     MOVE.L    #pic_mode,A2    ;Address to store mode/palette
  61.     BSR    PI1_load    ;Subroutine to load PI1 files
  62. * Set the colour palette
  63.     PEA    palette
  64.     MOVE.W    #6,-(SP)
  65.     TRAP    #14
  66.     ADDQ.L    #6,SP
  67. *
  68. * Now load the source picture into memory
  69.     MOVE.L    screen_2,A3    ;Address to load it
  70.     MOVE.L    #src_file,A1    ;Address of file name
  71.     MOVE.L    #pic_mode,A2    ;Address to store mode/palette
  72.     BSR    PI1_load    ;Subroutine to load PI1 files
  73.     RTS
  74. **********************************************
  75. * PI1_load - Loads a Degas PI1 picture file. *
  76. * A3 - Holds address to load picture data    *
  77. * A1 - Holds address of file name            *
  78. * A2 - Holds address to put first 34 bytes   *
  79. **********************************************
  80. PI1_load:    
  81. * First open the file.
  82.     MOVE.W    #0,-(SP)    ;Open for reading
  83.     MOVE.L    A1,-(SP)    ;File Name to open
  84.     MOVE.W    #$3D,-(SP)    ;Open file
  85.     TRAP    #1
  86.     ADDQ.L    #8,SP    
  87. *
  88.     TST.L    D0        ;Error?
  89.     BMI    file_error    ;Yep - give up and go home!
  90. *
  91.     MOVE.W    D0,handle    ;Store file handle
  92. *
  93.     MOVE.L    A2,-(SP)    ;Where to put first 34 bytes
  94.     MOVE.L    #34,-(SP)    ;How many bytes to read
  95.     MOVE.W    D0,-(SP)    ;Which file?
  96.     MOVE.W    #$3F,-(SP)    ;Read
  97.     TRAP    #1
  98.     LEA    12(SP),SP    ;Correct stack
  99. *
  100.     TST.L    D0        ;Error?
  101.     BMI    file_error    ;Yep - Oh well, better luck next time!
  102. *
  103.     MOVE.L    A3,-(SP)    ;Where to put last 32000 bytes
  104.     MOVE.L    #32000,-(SP)    ;How many bytes to read
  105.     MOVE.W    handle,-(SP)    ;Which file?
  106.     MOVE.W    #$3F,-(SP)    ;Read
  107.     TRAP    #1
  108.     LEA    12(SP),SP    ;Correct stack
  109. *
  110.     TST.L    D0        ;Error?
  111.     BMI    file_error    ;Yep - Oh well, better luck next time!
  112. *
  113.     RTS
  114. *
  115. ****************************************************************
  116. * file_error label handles any file error - not very well, but *
  117. * at least we let the player know that something is wrong!     *
  118. file_error:
  119.     PEA    err1        ;Print an error message
  120.     MOVE.W    #9,-(SP)    
  121.     TRAP    #1
  122.     ADDQ.L    #6,SP
  123. *
  124.     MOVE.W    #1,-(SP)    ;Get a Keypress
  125.     TRAP    #1
  126.     ADDQ.L    #2,SP
  127. *
  128.     CLR.W    -(SP)        ;End the Program
  129.     TRAP    #1
  130. *************************************************************************
  131. * show_blit - A demonstration of the different logical operators when   *
  132. * used with the Blit routine.                        *
  133. *************************************************************************
  134. show_blit:
  135.     MOVE.L    screen_2,A0    ;Address of Source Screen
  136.     MOVE.L    screen_1,A1    ;Address of Destination Screen
  137.     MOVE.W    #0,D0        ;Left From
  138.     MOVE.W    #0,D1        ;Top From
  139.     MOVE.W    #0,D2        ;Left To
  140.     MOVE.W    #0,D3        ;Top To
  141.     MOVE.W    #320,D4        ;Width
  142.     MOVE.W    #12,D5        ;Height
  143.     MOVE.B    #07,D7        ;Logical Operation (OR)
  144. * Change the above value to anything from 0-15 to see the other effects.
  145.  
  146. sb_loop:
  147.     BSR    blit        ;Blit it
  148.     ADD.W    #13,D3        ;Update Destination Y coordinate
  149.     CMP.W    #194,D3        ;Finished?
  150.     BLT.S    sb_loop        ;No - Continue round the loop
  151.     RTS
  152. *************************************************************************
  153. * BLIT - Perform a blit from screen to screen. Uses, but preserves    *
  154. * the following registers...                        *
  155. * A0 - Address of screen FROM.                        *
  156. * A1 - Address of screen TO.                        *
  157. * D0 - Left FROM                            *
  158. * D1 - Top FROM                                *
  159. * D2 - Left TO                                *
  160. * D3 - Top TO                                *
  161. * D4 - WIDTH                                *
  162. * D5 - HEIGHT                                *
  163. * D6 - unused                                *
  164. * D7 - Logical Operation                         *
  165. *************************************************************************
  166. blit:    MOVEM.L    D0-D7/A0-A6,-(SP)    ;Preserve Registers
  167.     LEA    bitblt(PC),A6        ;Address of blit table
  168.     MOVE.L    A0,18(A6)        ;Store 'From' address
  169.     MOVE.L    A1,32(A6)        ;Store 'To' Address
  170.     MOVE.W    D0,14(A6)        ;Store Left from position
  171.     MOVE.W    D1,16(A6)        ;Store Top from position
  172.     MOVE.W    D2,28(A6)        ;Store Left To position
  173.     MOVE.W    D3,30(A6)        ;Store Top To position
  174.     MOVE.W    D4,0(A6)        ;Store width. 
  175.     MOVE.W    D5,2(A6)        ;Store height.
  176. *
  177. low_rez:
  178.     MOVE.W    #4,4(A6)        ;Set up Blit variables
  179.     MOVE.W    #8,22(A6)        ;for Low resolution
  180.     MOVE.W    #8,36(A6)
  181. *
  182. any_rez:
  183.     MOVE.L    #0,42(A6)        ;Set up Blit variables 
  184.     MOVE.B    D7,10(A6)        ;for any resolution
  185.     MOVE.W    #0,6(A6)
  186.     MOVE.W    #0,8(A6)
  187. *
  188.     DC.W    $A007            ;Do the Blit!
  189. blit_exit:
  190.     MOVEM.L    (SP)+,D0-D7/A0-A6    ;Restore registers
  191.  
  192.     RTS                ;and return.
  193. *
  194. *****************************
  195. * Data for the Blit Routine *
  196. *****************************
  197.     EVEN
  198. bitblt:    DC.W    0    ;Width
  199.     DC.W    0    ;Height
  200.     DC.W    0    ;No. Planes
  201.     DC.W    0    ;fg_col
  202.     DC.W    0    ;bg_col
  203.     DC.B    0,0,0,0    ;log. ops
  204.     DC.W    0    ;left source x
  205.     DC.W    0    ;top source y
  206.     DC.L    0    ;Source screen top address
  207.     DC.W    8    ;word in line (8=low 4=med)
  208.     DC.W    160    ;160 for med/low
  209.     DC.W    2
  210.     DC.W    0    ;left dest x
  211.     DC.W    0    ;top dest y
  212.     DC.L    0    ;dest screen top address
  213.     DC.W    8    ;word in line
  214.     DC.W    160    ;line in plane
  215.     DC.W    2
  216.     DC.L    0    ;Pattern Address
  217.     DC.W    0
  218.     DC.W    0
  219.     DC.W    0
  220.     DS.B    30
  221. *************************
  222. * End of BLIT Data      *
  223. *************************
  224.     EVEN
  225. old_rez:    DC.W    0    ;Used to store old screen rez.
  226. *
  227. handle:        DC.W    0    ;File Handle
  228. *
  229. screen_1:    DC.L    0    ;Address of the screens
  230. screen_2:    DC.L    0    ;Address of another screen
  231. *
  232. pic_mode:    DS.W    1    ;1 word for picture's mode
  233. palette:    DS.W    16    ;16 words for palette
  234. *
  235. * An error message, just in case the program can't find the pictures.
  236. *
  237. err1:        DC.B    27,'E'
  238.         DC.B    'Unable to load necessary file',13,10
  239.         DC.B    'Press a key',0
  240.         EVEN
  241. * The file name of our Source screen. You can change this to hold
  242. * the full pathname if necessary.
  243. src_file:    DC.B    'source.pi1',0
  244.         EVEN
  245. * The file name of our Destination screen
  246. dst_file:    DC.B    'dest.pi1',0
  247.         EVEN
  248.         DS.L    100    ;Save some space for the Stack
  249. stack