home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / STAMPEDE / STAMP2_1.MSA / HINTS2.S < prev    next >
Text File  |  1987-04-21  |  7KB  |  237 lines

  1.  
  2. **************************************************************************
  3.  
  4. ;HITS AND TIPS II FOR STAMPEDE ATARI ST JUNE ISSUE 1990.
  5. ;Compiled by Stew.
  6.  
  7. ;This requires a full working version of Devpac to run
  8.  
  9. ;the following code is aimed at new comers to the 68000.
  10. ;all the routines below may be freely used and we hope that
  11. ;you find the comments very useful.
  12.  
  13. ;This months stampede is a routine which allows you to load up
  14. ;a standard degas PI1 file in medium resolution and display it. The
  15. ;program, when run prompts you for a file name. Enter the name of you
  16. ;picture and press return. The disk drive should start up and the
  17. ;picture will be loaded in. All going well, the picture will be
  18. ;displayed and the program will way for you to press a key. Control
  19. ;will then be passed to GEM.
  20. ;As a example, try entering GUABTITL.PI1 and see the picture load up.
  21. ;Don't forget to specify the drive "A:GUABTITL.PI1".
  22.  
  23. ;If you don't fully understand the code but are trying to learn, I
  24. ;would suggest purchasing books like the ATARI ST INTERNALS published
  25. ;by Abacus Software, and/or SYBEX Programming The 68000.
  26.  
  27.  
  28. ;first lets assign some variables using the EQUate function.
  29.  
  30. lowres    equ    0
  31. medres    equ    1
  32. hires    equ    2
  33.  
  34. ;now the code begins. the entire program has been split up
  35. ;into routines which are called using BSR (branch to subroutine)
  36. ;and the routine is finished using RTS (return from subroutine)
  37.  
  38. codego    dc.w    $a00a    ;turn off mouse
  39.     bsr    mypalette    ;set screen colors
  40.     bsr    savemode    ;save current screen mode
  41.     bsr    setmode    ;low res screen
  42.     bsr    inputname    ;get the filename
  43.     bsr    loadfile    ;get the data into a file
  44.     bsr    displayfile    ;show what has been loaded
  45.     bsr    waitkey    ;wait for user response
  46.     bsr    restorepalette    ;restore gem palette
  47.     bsr    restoremode    ;back to old screen mode
  48. exittogem    clr.w    -(sp)    ;function 0-terminate program
  49.     trap    #1    ;now go back to gem
  50.  
  51. ;now that the main routines have been executed we tell the
  52. ;program to halt and wait for the user to press a key. this
  53. ;is done via the trap #1 call.
  54.  
  55. waitkey    move.w    #$0001,-(sp)    ;function 1-conin
  56.     trap    #1    ;wait for a key
  57.     addq.l    #2,sp
  58.     rts
  59.  
  60. ;the following routines simply set the st's screen
  61. ;colours using trap #14, function 6. the colours are
  62. ;actually placed into the hardware locations $ffff8240.
  63.  
  64. restorepalette    move.l    #gempal,-(sp)    ;address of palette in memory
  65.     move.w    #$0006,-(sp)    ;function 6-setpalette
  66.     trap    #14    ;set the palette
  67.     addq.l    #6,sp
  68.     rts
  69.  
  70. ;as the st has more than 1 mode and we wish to use mode 0, low res,
  71. ;we must save the current screen mode (a number between 0 and 2)
  72. ;in a variable for resetting later. Trap 14, function 4, gets the
  73. ;mode number and returns it in d0
  74.  
  75. savemode    move.w    #4,-(sp)
  76.     trap    #14
  77.     addq.w    #2,sp
  78.     move.w    d0,oldrez
  79.     rts
  80.  
  81. ;now we set the screen mode using function 5-trap 14. this also
  82. ;allows us to set where the st fetches the data for the screen.
  83.  
  84. setmode    move.w    #lowres,-(sp)    ;place mode required on stack
  85.     move.l    #-1,-(sp)    ;dont effect screen address
  86.     move.l    #-1,-(sp)    ;dont effect screen address
  87.     move.w    #$0005,-(sp)    ;function 5-setscreen
  88.     trap    #14    ;set the screen resolution
  89.     add.l    #12,sp
  90.     rts
  91.  
  92. ;now that the program has finished we must restore the screenmode
  93. ;to its original mode using trap 14, function 5, setscreen.
  94. ;the mode is pulled from the variable oldscreenmode.
  95.  
  96. restoremode    move.w    oldrez,-(sp)
  97.     pea    -1
  98.     pea    -1
  99.     move.w    #5,-(sp)
  100.     trap    #14
  101.     add.w    #12,sp
  102.     rts
  103.  
  104. ;firstly we prompt the user to enter a filename
  105.  
  106. inputname    pea    introtext
  107.     move.w    #$09,-(sp)
  108.     trap    #1
  109.     addq.w    #6,sp
  110.  
  111.     pea    filename
  112.     move.w    #$0a,-(sp)
  113.     trap    #1
  114.     addq.w    #6,sp
  115.     rts
  116.  
  117. ;now we load the file specified in introtext into picturebuffer
  118. ;we know where the file is, what it is called and that it is 32066
  119. ;bytes long.
  120. ;to load a file into memory we must first open the file, then read
  121. ;all the data and finally close the file. because gem can handle
  122. ;more than 1 file being open at once it must be able to recognise
  123. ;the individual files. this is done using the file handle. when
  124. ;a file is open or created it is given a unique filehandle and to
  125. ;access the file for read/write/close the filehandle must be given.
  126.  
  127. loadfile    move.w    #0,-(sp)    ;read file only
  128.     pea    filestart    ;name of file
  129.     move.w    #$3d,-(sp)    ;function
  130.     trap    #1    ;open the file
  131.     addq.w    #8,sp
  132.     tst.l    d0    ;error occured ?
  133.     bmi    errorreturn    ;yes, quit load
  134.     move.w    d0,filehandle
  135.  
  136.     pea    loadingmessage    ;start of text
  137.     move.w    #9,-(sp)
  138.     trap    #1
  139.     addq.w    #6,sp
  140.  
  141.     pea    picturebuffer    ;start of where to load
  142.     pea    32066    ;size of file
  143.     move.w    filehandle,-(sp)
  144.     move.w    #$3f,-(sp)
  145.     trap    #1
  146.     add.w    #12,sp
  147.     tst.l    d0    ;error occured in load?
  148.     bmi    errorreturn    ;yes, quit load
  149.  
  150.     move.w    filehandle,-(sp)
  151.     move.w    #$3e,-(sp)    ;close file
  152.     trap    #1
  153.     addq.w    #4,sp
  154. errorreturn    rts
  155.  
  156. ;now we display the file. this is done through 3 routines, getscreenbase,
  157. ;setpalette and drawpicture.
  158.  
  159. displayfile    bsr    getscreenbase
  160.     bsr    setpalette
  161.     bsr    drawpicture
  162.     rts
  163.  
  164. ;now that the file has been loaded, we can display the data on the
  165. ;screen. the first thing to do is to get the address in memory
  166. ;of the screen. this is not fixed. 520 st's have a different
  167. ;screen location to 1040 st's. trap #14 function 2 returns the
  168. ;screen address in d0
  169.  
  170. getscreenbase    move.w    #2,-(sp)
  171.     trap    #14
  172.     addq.w    #2,sp
  173.     move.l    d0,screenbase
  174.     rts
  175.  
  176. ;the palette for a degas screen is stored 2 bytes into the picture
  177. ;and is 32 bytes long.
  178.  
  179. setpalette    move.l    #picturebuffer+2,-(sp)    ;address of palette in memory
  180.     move.w    #$0006,-(sp)    ;function 6-setpalette
  181.     trap    #14    ;set the palette
  182.     addq.l    #6,sp
  183.     rts
  184.  
  185. ;degas stores the actual screen data 34 bytes into the file. to display
  186. ;this we must copy the data up to the screen location.
  187.  
  188. drawpicture    lea    picturebuffer+34,a0 ;get the data from here
  189.     move.l    screenbase,a1    ;put the data here
  190.     move.w    #32000-1,d7    ;loop counter
  191. copyiton    move.b    (a0)+,(a1)+    ;copy data up
  192.     dbra    d7,copyiton    ;do all screen data
  193.     rts
  194.  
  195. ;change the palette to out own colours
  196.  
  197. mypalette    pea    mypal    ;palette address
  198.     move.w    #6,-(sp)
  199.     trap    #14
  200.     addq.w    #6,sp
  201.     rts
  202.  
  203. **************************************************************************
  204.  
  205. ;reserved space for variables
  206.  
  207. loadingmessage    dc.b    13,10,10,"Loading file....",0
  208.  
  209. introtext    dc.b    "Screen displayer",13,10,10
  210.     dc.b    "Please enter a filename",13,10
  211.     dc.b    "Maximum of 40 characters",13,10,10
  212.     dc.b    0
  213.  
  214. filename    dc.b    40    ;40 characters long
  215.     dc.b    0    ;length of string input
  216. filestart    ds.b    40    ;the data starts here
  217.     even
  218.  
  219. oldrez    dc.w    0
  220. screenbase    dc.l    0
  221. filehandle    dc.w    0
  222.  
  223. gempal    dc.w    $777,$700,$070,$000,$111,$222,$333,$444
  224.     dc.w    $555,$000,$001,$010,$100,$200,$020,$002
  225. mypal    dc.w    $777,$007,$007,$007,$007,$007,$007,$007
  226.     dc.w    $007,$007,$007,$007,$007,$007,$007,$007
  227.  
  228. ;the following buffer is used to store the picture before it is
  229. ;drawn onto the screen. the section bss is a special command
  230. ;used on devpac which tells the program to reserve the memory
  231. ;allocated in the ds. sections on loading the assembled program.
  232. ;this simply saves disk space.
  233.  
  234.  
  235.     section    bss
  236. picturebuffer    ds.b    32066    ;save for piccy
  237.