home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / STAMPEDE / STAMP4_1.MSA / HINTS3.S < prev    next >
Encoding:
Text File  |  1985-11-19  |  9.3 KB  |  321 lines

  1.  
  2. **************************************************************************
  3.  
  4. ;HITS AND TIPS III FOR STAMPEDE ATARI ST JULY 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 issue is designed to show you how data tables work.
  14. ;the program features coloured blocks which fade
  15.  
  16. ;next month we will show you how to fade the screen colors
  17.  
  18. ;If you don't fully understand the code but are trying to learn, I
  19. ;would suggest purchasing books like the ATARI ST INTERNALS published
  20. ;by Abacus Software, and/or SYBEX Programming The 68000.
  21.  
  22. ;first lets assign some variables using the EQUate function.
  23.  
  24. lowres    equ    0
  25. medres    equ    1
  26. hires    equ    2
  27.  
  28. ;now the code begins. the entire program has been split up
  29. ;into routines which are called using BSR (branch to subroutine)
  30. ;and the routine is finished using RTS (return from subroutine)
  31.  
  32. codego    dc.w    $a00a    ;turn off mouse
  33.     bsr    supermode
  34.     bsr    mypalette    ;set screen colors
  35.     bsr    getscreenbase
  36.     bsr    savemode    ;save current screen mode
  37.     bsr    setmode    ;low res screen
  38.     bsr    clearscreen    ;erase all the data
  39.     bsr    message
  40.     bsr    drawblocks
  41.     bsr    tableroutine
  42.     bsr    restorepalette    ;restore gem palette
  43.     bsr    restoremode    ;back to old screen mode
  44. exittogem    clr.w    -(sp)    ;function 0-terminate program
  45.     trap    #1    ;now go back to gem
  46.  
  47. ;as we wish to access the hardware in the st (the color pallete)
  48. ;we must put the 68000 into supervisor mode. this is done using
  49. ;the following routine
  50.  
  51. supermode    clr.l    -(sp)
  52.     move.w    #$0020,-(sp)    ;trap 1-function $20
  53.     trap    #1
  54.     addq.w    #6,sp
  55.     rts
  56.  
  57. ;change the palette to out own colours
  58.  
  59. mypalette    pea    clearpal    ;palette address
  60.     move.w    #6,-(sp)
  61.     trap    #14
  62.     addq.w    #6,sp
  63.     rts
  64.  
  65. ;the following routines simply set the st's screen
  66. ;colours using trap #14, function 6. the colours are
  67. ;actually placed into the hardware locations $ffff8240.
  68.  
  69. restorepalette
  70.     move.l    #gempal,-(sp)    ;address of palette in memory
  71.     move.w    #$0006,-(sp)    ;function 6-setpalette
  72.     trap    #14    ;set the palette
  73.     addq.w    #6,sp
  74.     rts
  75.  
  76. ;as the st has more than 1 mode and we wish to use mode 0, low res,
  77. ;we must save the current screen mode (a number between 0 and 2)
  78. ;in a variable for resetting later. Trap 14, function 4, gets the
  79. ;mode number and returns it in d0
  80.  
  81. savemode    move.w    #4,-(sp)
  82.     trap    #14
  83.     addq.w    #2,sp
  84.     move.w    d0,oldrez
  85.     rts
  86.  
  87. ;now we set the screen mode using function 5-trap 14. this also
  88. ;allows us to set where the st fetches the data for the screen.
  89.  
  90. setmode    move.w    #lowres,-(sp)    ;place mode required on stack
  91.     move.l    #-1,-(sp)    ;dont effect screen address
  92.     move.l    #-1,-(sp)    ;dont effect screen address
  93.     move.w    #$0005,-(sp)    ;function 5-setscreen
  94.     trap    #14    ;set the screen resolution
  95.     add.w    #12,sp
  96.     rts
  97.  
  98. ;now that the program has finished we must restore the screenmode
  99. ;to its original mode using trap 14, function 5, setscreen.
  100. ;the mode is pulled from the variable oldscreenmode.
  101.  
  102. restoremode    move.w    oldrez,-(sp)
  103.     pea    -1
  104.     pea    -1
  105.     move.w    #5,-(sp)
  106.     trap    #14
  107.     add.w    #12,sp
  108.     rts
  109.  
  110. ;now that the file has been loaded, we can display the data on the
  111. ;screen. the first thing to do is to get the address in memory
  112. ;of the screen. this is not fixed. 520 st's have a different
  113. ;screen location to 1040 st's. trap #14 function 2 returns the
  114. ;screen address in d0
  115.  
  116. getscreenbase    move.w    #2,-(sp)
  117.     trap    #14
  118.     addq.w    #2,sp
  119.     move.l    d0,screenbase
  120.     rts
  121.  
  122. ;before we write to the screen we must clear out all the data. this
  123. ;is done using a small routine which simply loops for all the
  124. ;data on the screen. a0 is pointed to the start of the block in
  125. ;memory where the screen is and then d7 is used to loop for
  126. ;all the data on screen.
  127.  
  128. clearscreen    move.l    screenbase,a0    ;start of screen
  129.     move.w    #32000-1,d7
  130. clearloop    clr.l    (a0)+
  131.     dbra    d7,clearloop
  132.     rts
  133.  
  134. ;display the main message string on the screen using printline
  135.  
  136. message    pea    messagetx    ;address of string
  137.     move.w    #9,-(sp)    ;function 9
  138.     trap    #1    ;print string
  139.     addq.w    #6,sp    ;correct stack
  140.     rts
  141.  
  142. ;this routine display all the blocks on the screen
  143. ;there are 16 blocks which are display in colours 0-15
  144. ;each block is 16 pixels high
  145.  
  146. drawblocks    move.l    screenbase,a0    ;where to place
  147.     add.w    #(2*8)+(92*160),a0 ;position on screen
  148.     lea    blockdata,a1    ;data to place on screen
  149.     moveq    #0,d7    ;loop counter
  150. allblocks    movem.w    (a1)+,d0-d3    ;grab plane data
  151.     moveq    #0,d5    ;offset
  152.     moveq    #16-1,d6    ;loop for height of block
  153. height    movem.w    d0-d3,0(a0,d5.w) ;put data on screen
  154.     add.l    #160,d5    ;down a screen line
  155.     dbra    d6,height    ;do all block
  156.     addq.w    #8,a0    ;across screen
  157.     addq.w    #1,d7    ;next block
  158.     cmp.w    #16,d7    ;16 colours
  159.     bne.s    allblocks    ;loop for all of them
  160.     rts
  161.  
  162. ;this routine simply sets up the register a0 with the pallete colour
  163. ;required and the calls the fader routine to do the actual fade
  164.  
  165. tableroutine    lea    temppal,a0
  166.     moveq    #16-1,d7
  167. clearpalloop    clr.w    (a0)+
  168.     dbra    d7,clearpalloop
  169.     lea    pal1,a0
  170.     bsr    fader
  171.     lea    clearpal,a0
  172.     bsr    fader
  173.  
  174.     lea    pal1,a0
  175.     bsr    fader
  176.     lea    whites,a0
  177.     bsr    fader
  178.     lea    reds,a0
  179.     bsr    fader
  180.     lea    greens,a0
  181.     bsr    fader
  182.     lea    blues,a0
  183.     bsr    fader
  184.     lea    yellows,a0
  185.     bsr    fader
  186.     lea    cyans,a0
  187.     bsr    fader
  188.  
  189.     lea    clearpal,a0
  190.     bsr    fader
  191.     rts
  192.  
  193. ;this routine fades the current screen pallete to the colours
  194. ;specified in the table at (a0)+. the pallete is 32 bytes long.
  195. ;the vbl routine is called so that the colour transfer is
  196. ;smooth (the colour is changed off the visible screen area)
  197.  
  198. fader    move.l    a0,fadeaddr    ;save the address for later
  199. fadego    clr.w    counter    ;setup counter
  200. fadedelay    bsr    vbl    ;wait for top of screen
  201.     addq.w    #1,counter    ;adjust counter
  202.     cmp.w    #5,counter    ;delayed for a second
  203.     bne.s    fadedelay    ;if not, delay for fader
  204.     bsr    adjustcolours    ;change color
  205.     bsr    copycols    ;set pallete values
  206.     move.l    fadeaddr,a0    ;start of destination pallete
  207.     lea    temppal,a1    ;current pallete
  208.     moveq    #16-1,d7    ;number of colours
  209. checkloop    move.w    (a0)+,d0    ;dest colour
  210.     cmp.w    (a1)+,d0    ;reached required colour
  211.     bne.s    fadego    ;no, go again
  212.     dbra    d7,checkloop
  213.     rts
  214.  
  215. ;this is the heart of the fader. the rgb colours are adjusted either
  216. ;up or down.
  217.  
  218. adjustcolours    move.l    fadeaddr,a0
  219.     lea    temppal,a1
  220.     moveq    #16-1,d7    ;16 colour pallete
  221. fadeloop    moveq    #$01,d0
  222.     moveq    #$07,d1
  223.     moveq    #3-1,d6    ;rgb loop
  224. adjustloop    move.w    (a0),d2    ;pull current colour
  225.     move.w    (a1),d3    ;destination colour
  226.     and.w    d1,d2    ;issolate blue/green/red
  227.     and.w    d1,d3
  228.     cmp.w    d2,d3    ;reached value ?
  229.     beq.s    gotcolour
  230.     blt.s    addtocolour
  231.     sub.w    d0,(a1)
  232.     bra.s    gotcolour
  233. addtocolour    add.w    d0,(a1)
  234. gotcolour    lsl.w    #4,d0    ;move through bgr
  235.     lsl.w    #4,d1
  236.     dbra    d6,adjustloop
  237.     addq.w    #2,a0
  238.     addq.w    #2,a1
  239.     dbra    d7,fadeloop
  240.     rts
  241.  
  242. ;this routine is very simple. it copies the pallete values
  243. ;in memory into the actual pallete. this is prefered over
  244. ;directly changing the pallete colours at location $ffff8240
  245. ;as this is a hardware register which may not always return
  246. ;the correct value when read.
  247. ;the MOVEMultiple instructions are very useful, they allow
  248. ;large chucks of memory to be read directly into registers
  249. ;rather than doing several moves.
  250.  
  251. copycols    movem.l    temppal,d0-d7    ;setup pallete
  252.     movem.l    d0-d7,$ffff8240
  253.     rts
  254.  
  255. ;wait until the raster beam hits the top of the screen
  256.  
  257. vbl    move.w    #37,-(sp)
  258.     trap    #14
  259.     addq.w    #2,sp
  260.     rts
  261.  
  262. **************************************************************************
  263.  
  264. ;reserved space for variables
  265.  
  266. ;the data for each block is stored in the table below.
  267. ;there are 4 words which make up the 4 bit planes for the color.
  268. ;e.g. color 13 is %1101
  269.  
  270. blockdata    dc.w    $0000,$0000,$0000,$0000    ;0
  271.     dc.w    $ffff,$0000,$0000,$0000    ;1
  272.     dc.w    $0000,$ffff,$0000,$0000    ;2
  273.     dc.w    $ffff,$ffff,$0000,$0000    ;3
  274.     dc.w    $0000,$0000,$ffff,$0000    ;4
  275.     dc.w    $ffff,$0000,$ffff,$0000    ;5
  276.     dc.w    $0000,$ffff,$ffff,$0000    ;6
  277.     dc.w    $ffff,$ffff,$ffff,$0000    ;7
  278.     dc.w    $0000,$0000,$0000,$ffff    ;8
  279.     dc.w    $ffff,$0000,$0000,$ffff    ;9
  280.     dc.w    $0000,$ffff,$0000,$ffff    ;10
  281.     dc.w    $ffff,$ffff,$0000,$ffff    ;11
  282.     dc.w    $0000,$0000,$ffff,$ffff    ;12
  283.     dc.w    $ffff,$0000,$ffff,$ffff    ;13
  284.     dc.w    $0000,$ffff,$ffff,$ffff    ;14
  285.     dc.w    $ffff,$ffff,$ffff,$ffff    ;15
  286.  
  287. gempal    dc.w    $777,$700,$070,$000,$111,$222,$333,$444
  288.     dc.w    $555,$000,$001,$010,$100,$200,$020,$002
  289.  
  290. pal1    dc.w    $000,$003,$005,$007,$030,$050,$070,$333
  291.     dc.w    $555,$777,$300,$500,$700,$330,$550,$770
  292. clearpal    dc.w    $000,$000,$000,$000,$000,$000,$000,$000
  293.     dc.w    $000,$000,$000,$000,$000,$000,$000,$000
  294. whites    dc.w    $000,$777,$777,$777,$777,$777,$777,$777
  295.     dc.w    $777,$777,$777,$777,$777,$777,$777,$777
  296. reds    dc.w    $000,$700,$700,$700,$700,$700,$700,$700
  297.     dc.w    $700,$700,$700,$700,$700,$700,$700,$700
  298. greens    dc.w    $000,$070,$070,$070,$070,$070,$070,$070
  299.     dc.w    $070,$070,$070,$070,$070,$070,$070,$070
  300. blues    dc.w    $000,$007,$007,$007,$007,$007,$007,$007
  301.     dc.w    $007,$007,$007,$007,$007,$007,$007,$007
  302. purples    dc.w    $000,$707,$707,$707,$707,$707,$707,$707
  303.     dc.w    $707,$707,$707,$707,$707,$707,$707,$707
  304. yellows    dc.w    $000,$770,$770,$770,$770,$770,$770,$770
  305.     dc.w    $770,$770,$770,$770,$770,$770,$770,$770
  306. cyans    dc.w    $000,$077,$077,$077,$077,$077,$077,$077
  307.     dc.w    $077,$077,$077,$077,$077,$077,$077,$077
  308.  
  309. temppal    ds.w    16
  310.  
  311. counter    dc.w    0
  312. oldrez    dc.w    0
  313. screenbase    dc.l    0
  314. fadeaddr    dc.l    0
  315.  
  316. messagetx    dc.b    "   STAMPEDE HINTS AND TIPS-JULY ISSUE",13,10
  317.     dc.b    "            * COLOUR FADER *",0
  318.     even
  319.  
  320.     end
  321.