home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / STAMPEDE / STAMP7_1.MSA / TUT7.S < prev    next >
Encoding:
Text File  |  2006-02-17  |  5.4 KB  |  225 lines

  1.  
  2. ;*************************************************************************
  3.  
  4. ;PROGRAMMING TUTORIAL FILE FOR STAMPEDE NOVEMBER 1990.
  5. ;Complied by Stew.
  6.  
  7. ;this requires a full working version of Devpac or compatible to run
  8. ;set tab setting to 8 for best editing
  9.  
  10. ;first lets assign some variables using the EQUate function.
  11.  
  12. lowres    equ    0
  13. medres    equ    1
  14. hires    equ    2
  15.  
  16. screen1    equ    $70000
  17. screen2    equ    $78000
  18.  
  19. ;now the code begins. the entire program has been split up
  20. ;into routines which are called using BSR (branch to subroutine)
  21. ;and the routine is finished using RTS (return from subroutine)
  22.  
  23. codego    bsr    supermode    ;allow access to the hardware
  24.     dc.w    $a00a        ;turn off mouse
  25.     bsr    setpalette    ;program palette set here
  26.     bsr    setscreen    ;set the screen mode
  27.     bsr    waitvbl
  28.  
  29. mainloop
  30.     bsr    flip        ;adjust screen pointers
  31.     bsr    waitvbl        ;wait for vertical blank
  32.     move.w    #$0700,$ffff8240
  33.     bsr    clearscreen    ;erase screen data
  34.     move.w    #$0777,$ffff8240
  35.     bsr    sprite
  36.     clr.w    $ffff8240
  37.  
  38.     bsr    readkey        ;till done
  39.     cmp.b    #" ",d0        ;space pressed ?
  40.     bne.s    mainloop    ;no, loop
  41.  
  42.     bsr    restorepalette    ;restore gem palette
  43.     bsr    usermode    ;back to user mode
  44.     clr.w    -(sp)        ;function 0-terminate program
  45.     trap    #1        ;now go back to gem
  46.  
  47. ;before any of the st's hardware registers can be used, we must
  48. ;place the 68000 into supervisor mode.
  49. ;the super mode instruction effects the status register bit #13.
  50. ;note: the trap #1 call with paramater $0020 actually toggles
  51. ;  the user mode/super mode status. so calling the routine
  52. ;  twice will restore the processor to its previous state.
  53.  
  54. supermode
  55.     clr.l    -(sp)        ;push parameters for supermode
  56.     move.w    #$0020,-(sp)    ;onto the stack
  57.     trap    #1        ;call the gemdos routine
  58.     addq.w    #6,sp        ;correct the stack
  59.     move.l    d0,savesp    ;save the old stack value
  60.     rts            ;exit the routine
  61.  
  62. ;once the program has been executed, we place the 68000 back
  63. ;into usermode ready for the return to gem. this actually
  64. ;clears the supervisor mode bit in the status register.
  65.  
  66. usermode
  67.     move.l    savesp,-(sp)    ;push on old stack value
  68.     move.w    #$0020,-(sp)    ;function $0020-user mode
  69.     trap    #1        ;put 68000 into user mode
  70.     addq.w    #6,sp        ;correct stack after the 2 pushes
  71.     rts
  72.  
  73. ;now that the main routines have been executed we tell the
  74. ;program to halt and wait for the user to press a key. this
  75. ;is done via the trap #1 call.
  76.  
  77. readkey
  78.     move.w    #$00ff,-(sp)
  79.     move.w    #$0006,-(sp)    ;function 6-readkey
  80.     trap    #1        ;wait for a key
  81.     addq.w    #4,sp        ;return key in d0
  82.     rts
  83.  
  84. ;now we set the screen mode using function 5-trap 14. this also
  85. ;allows us to set where the st fetches the data for the screen.
  86.  
  87. setscreen
  88.     move.w    #lowres,-(sp)    ;place mode required on stack
  89.     move.l    #-1,-(sp)    ;dont effect screen address
  90.     move.l    #-1,-(sp)    ;dont effect screen address
  91.     move.w    #$0005,-(sp)    ;function 5-setscreen
  92.     trap    #14        ;set the screen resolution
  93.     add.w    #12,sp
  94.     rts
  95.  
  96. ;the following two routines simply set the st's screen
  97. ;colours using trap #14, function 6. the colours are
  98. ;actually placed into the hardware locations $ffff8240.
  99.  
  100. setpalette
  101.     move.l    #mypal,-(sp)    ;address of palette in memory
  102.     move.w    #$0006,-(sp)    ;function 6-setpalette
  103.     trap    #14        ;set the palette
  104.     addq.w    #6,sp
  105.     rts
  106.  
  107. restorepalette
  108.     move.l    #gempal,-(sp)    ;address of palette in memory
  109.     move.w    #$0006,-(sp)    ;function 6-setpalette
  110.     trap    #14        ;set the palette
  111.     addq.w    #6,sp
  112.     rts
  113.  
  114. ;this routine simply waits for the vertical blank to occur. this
  115. ;simply makes the graphic updates smoother.  try removing this to
  116. ;see what happens!
  117.  
  118. waitvbl
  119.     move.w    #37,-(sp)
  120.     trap    #14
  121.     addq.w    #2,sp
  122.     rts
  123.  
  124. ;this routine simply sets up the new screen addresses and then flips
  125. ;the screen pointer addresses.
  126.  
  127. flip    move.l    visscreen,d0
  128.     move.l    currentscreen,visscreen
  129.     move.l    d0,currentscreen
  130.  
  131.     move.w    #-1,-(sp)
  132.     move.l    visscreen,-(sp)
  133.     move.l    currentscreen,-(sp)
  134.     move.w    #5,-(sp)
  135.     trap    #14
  136.     add.w    #12,sp
  137.     rts
  138.  
  139. ;this routine is very simple. it simply clears the screen using
  140. ;a loop. note: 200 lines are cleared of 160 bytes each.
  141.  
  142. clearscreen
  143.     move.l    currentscreen,a0
  144.     moveq    #0,d0
  145.     move.w    #200-1,d7
  146. sf    rept    40
  147.     move.l    d0,(a0)+
  148.     endr
  149.     dbra    d7,sf
  150.     rts
  151.  
  152. ;display sprite at d0,d1 (x,y)
  153.  
  154. sprite
  155.     addq.w    #1,xpos
  156.     addq.w    #1,ypos
  157.     and.w    #$007f,xpos
  158.     and.w    #$007f,ypos
  159.  
  160.     move.w    xpos,d0
  161.     move.w    ypos,d1
  162.     mulu.w    #160,d1
  163.     move.l    currentscreen,a1
  164.     add.w    d1,a1
  165.     move.w    d0,d6
  166.     lsr.w    #1,d0
  167.     and.w    #$fff8,d0
  168.     add.w    d0,a1
  169.     and.w    #$000f,d6
  170.     moveq    #16-1,d7
  171.     lea    spritedata,a0
  172.  
  173. ;a0=data  a1=screen  d6=shifts  d7=loop
  174.  
  175. drawit    moveq    #0,d0
  176.     move.w    (a0)+,d0
  177.     ror.l    d6,d0
  178.     or.w    d0,(a1)
  179.     swap    d0
  180.     or.w    d0,8(a1)
  181.     lea    160(a1),a1
  182.     dbra    d7,drawit
  183.     rts
  184.  
  185. **************************************************************************
  186.  
  187. xpos    dc.w    0
  188. ypos    dc.w    0
  189.  
  190. ;graphics data
  191.  
  192. spritedata
  193.     dc.w    %1111111111111111
  194.     dc.w    %1111111111111111
  195.     dc.w    %1111111111111111
  196.     dc.w    %1111111111111111
  197.     dc.w    %1111111111111111
  198.     dc.w    %1111111111111111
  199.     dc.w    %1111111111111111
  200.     dc.w    %1111111111111111
  201.     dc.w    %1111111111111111
  202.     dc.w    %1111111111111111
  203.     dc.w    %1111111111111111
  204.     dc.w    %1111111111111111
  205.     dc.w    %1111111111111111
  206.     dc.w    %1111111111111111
  207.     dc.w    %1111111111111111
  208.     dc.w    %1111111111111111
  209.  
  210. ;reserved space for variables
  211.  
  212. visscreen    
  213.     dc.l    screen1
  214.  
  215. currentscreen
  216.     dc.l    screen2
  217.  
  218. savesp    dc.l    0
  219.  
  220. mypal    dc.w    $007,$777,$000,$777,$000,$000,$000,$000
  221.     dc.w    $707,$770,$000,$000,$000,$000,$000,$777
  222.  
  223. gempal    dc.w    $001,$777,$777,$777,$777,$777,$777,$777
  224.     dc.w    $777,$777,$777,$777,$777,$777,$777,$777
  225.