home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / alt / sys / amiga / demos / 1965 < prev    next >
Encoding:
Internet Message Format  |  1992-12-12  |  10.9 KB

  1. Path: sparky!uunet!noc.near.net!hri.com!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!aun.uninett.no!nuug!ifi.uio.no!larshaug
  2. From: larshaug@ifi.uio.no (Lars Haugseth)
  3. Newsgroups: alt.sys.amiga.demos
  4. Subject: Source : Horizontal scroller
  5. Message-ID: <1992Dec12.193243.14082@ifi.uio.no>
  6. Date: 12 Dec 92 19:32:43 GMT
  7. Sender: larshaug@ifi.uio.no (Lars Haugseth)
  8. Organization: Dept. of Informatics, University of Oslo, Norway
  9. Lines: 403
  10. Nntp-Posting-Host: yrsa.ifi.uio.no
  11. Originator: larshaug@yrsa.ifi.uio.no
  12.  
  13.  
  14.  
  15.  
  16. It's time to hit the hardware again, and maybe earn
  17. some more flames. 8)
  18.  
  19. Ok, here is small program I made that simply scrolls
  20. a 5 bitplane 320x256 pixels picture leftwards, and inserts
  21. new graphics at the right edge of the screen. The graphics are
  22. built up by 16x16 pixel blocks. I have included some example
  23. block-data as a uuencoded LhA-archive. (Separate posting)
  24.  
  25. The scrolling works as follows:
  26.  
  27. After smooth-scrolling the picture 16 pixel with the BLTCON1 register,
  28. I add 2 bytes to the bitplane-pointers, and blit new blocks into the
  29. memory which lies off the right edge of the screen. It's as simple as
  30. that. It's very simple to extend the program to scroll in both directions,
  31. but that part you must figure out yourselves.
  32.  
  33. The memory usage for the graphics are [ SW * (SH + MX) ] bytes,
  34. where SW is the screenwidth in bytes, SH is the screenheight in
  35. pixels, and MX is the maximum number of screenwidths you can scroll.
  36. I have set MX=32, which means you can scroll 352x32 pixels, which
  37. should be more than enough for most vertical scrolling games.
  38.  
  39. Time usage is about 4 rasterlines pr.frame when scrolling 1 pixel at a time.
  40. If you'd like to scroll more pixel pr.frame, the time increases, but
  41. it's still pretty fast.
  42.  
  43. +-----------------------------------------------------------+
  44. | Lars Haugseth                                             +-+
  45. | Dept. of Informatics,               <larshaug@ifi.uio.no> | |
  46. | University of Oslo, Norway                                | |
  47. |                                                           | |
  48. |          If idiots could fly, this would be an airport... | |
  49. +-+---------------------------------------------------------+ |
  50.   +-----------------------------------------------------------+
  51.  
  52.  
  53.  
  54.  
  55.  
  56. ;-------------------------------------------------------------------------
  57. ; BLOCK-SCROLLER
  58. ;-------------------------------------------------------------------------
  59. ; Programmed by Lars Haugseth 9/12-92
  60. ;-------------------------------------------------------------------------
  61. ; CONSTANTS
  62. ;-------------------------------------------------------------------------
  63.  
  64. EXECBASE    = 4
  65.  
  66. CUSTOMBASE    = $DFF000        ; Custom-chips register offset
  67.  
  68. OpenLibrary    = -408            ; Library function offsets
  69. CloseLibrary    = -414
  70. VBeamPos    = -384
  71.  
  72. SW        = 44            ; Width of screen in bytes
  73. SH        = 256            ; Height of screen in pixels
  74. MX        = 32            ; Maximum pages of scrolling
  75.  
  76. ;-------------------------------------------------------------------------
  77. ; MACROS
  78. ;-------------------------------------------------------------------------
  79.  
  80. WRAST:    MACRO                ; Wait for a specific rasterpos.
  81.     movem.l    d0-a6,-(SP)
  82.     move.l    GFXBASE,a6
  83. \@1    jsr    VBeamPos(a6)
  84.     cmp.w    #\1,d0
  85.     bne.s    \@1
  86.     movem.l    (SP)+,d0-a6
  87.     ENDM
  88.  
  89. WBLIT:    MACRO                ; Wait for the blitter to finish
  90.     btst    #6,$02(a5)
  91.     bne.s    \@1
  92.     bra.s    \@2
  93. \@1    nop
  94.     nop
  95.     btst    #6,$02(a5)
  96.     bne.s    \@1
  97. \@2
  98.     ENDM
  99.  
  100. ;-------------------------------------------------------------------------
  101. ; PROGRAM
  102. ;-------------------------------------------------------------------------
  103.  
  104.     SECTION    "code",code_p
  105.  
  106. STARTPROG:
  107.  
  108.     move.l    EXECBASE,a6        ; Open graphics.library
  109.     lea    GFXNAME,a1
  110.     moveq    #0,d0
  111.     jsr    OpenLibrary(a6)
  112.     move.l    d0,GFXBASE
  113.     beq    EXIT
  114.  
  115.     lea    CUSTOMBASE,a5
  116.     move.l    GFXBASE,a6
  117.  
  118.     move.l    $26(a6),OLDCOPPERLIST    ; Save copperlist
  119.     move.w    $1C(a5),OLDINTERRUPTS    ; Save enabled interrupts
  120.     move.w    $02(a5),OLDDMACONTROL    ; Save dmacontrol
  121.  
  122.     move.w    #$87E0,$96(a5)        ; Enable some DMAs
  123.     move.w    #$7FFF,$9A(a5)        ; Disable all interrupts
  124.  
  125. ;-------------------------------------------------------------------------
  126.  
  127. INITMAP:
  128.  
  129.     lea    SCROLLMAP,a0
  130.     moveq    #0,d7
  131. IMAP1:    cmp.w    #320,d7
  132.     blt.s    IMAP2
  133.     bsr    GETRANDOM
  134.     bra.s    IMAP3
  135. IMAP2:    move.w    d7,d0
  136. IMAP3:    move.w    d0,(a0)+
  137.     addq    #1,d7
  138.     cmp.w    #[SW*8]*MX,d7
  139.     bne.s    IMAP1
  140.  
  141. ;-------------------------------------------------------------------------
  142.  
  143. INITCOPPER:                ; Initialize copperlist
  144.  
  145.     lea    COLOURS,a0        ; Insert palette
  146.     lea    COP1PALETTE+2,a1
  147.     move.w    #31,d7
  148. ICOP1:    move.w    (a0)+,(a1)
  149.     addq.w    #4,a1
  150.     dbf    d7,ICOP1
  151.  
  152.     move.l    #BLANKS,d0        ; Insert blank sprites
  153.     move.w    d0,COP1SPRITES+06
  154.     move.w    d0,COP1SPRITES+14
  155.     move.w    d0,COP1SPRITES+22
  156.     move.w    d0,COP1SPRITES+30
  157.     move.w    d0,COP1SPRITES+38
  158.     move.w    d0,COP1SPRITES+46
  159.     move.w    d0,COP1SPRITES+54
  160.     move.w    d0,COP1SPRITES+62
  161.     swap    d0
  162.     move.w    d0,COP1SPRITES+02
  163.     move.w    d0,COP1SPRITES+10
  164.     move.w    d0,COP1SPRITES+18
  165.     move.w    d0,COP1SPRITES+26
  166.     move.w    d0,COP1SPRITES+34
  167.     move.w    d0,COP1SPRITES+42
  168.     move.w    d0,COP1SPRITES+50
  169.     move.w    d0,COP1SPRITES+58
  170.  
  171.     move.l    #SCROLLPLANES+[0*SW],d0    ; Insert Bitplane pointers
  172.     move.l    #SCROLLPLANES+[1*SW],d1
  173.     move.l    #SCROLLPLANES+[2*SW],d2
  174.     move.l    #SCROLLPLANES+[3*SW],d3
  175.     move.l    #SCROLLPLANES+[4*SW],d4
  176.     add.l    d5,d0
  177.     add.l    d5,d1
  178.     add.l    d5,d2
  179.     add.l    d5,d3
  180.     add.l    d5,d4
  181.     move.w    d0,COP1PLANE1+6
  182.     move.w    d1,COP1PLANE2+6
  183.     move.w    d2,COP1PLANE3+6
  184.     move.w    d3,COP1PLANE4+6
  185.     move.w    d4,COP1PLANE5+6
  186.     swap    d0
  187.     swap    d1
  188.     swap    d2
  189.     swap    d3
  190.     swap    d4
  191.     move.w    d0,COP1PLANE1+2
  192.     move.w    d1,COP1PLANE2+2
  193.     move.w    d2,COP1PLANE3+2
  194.     move.w    d3,COP1PLANE4+2
  195.     move.w    d4,COP1PLANE5+2
  196.  
  197.     move.l    #COPPERLIST,$80(a5)    ; Start copperlist
  198.     clr.w    $88(a5)
  199.  
  200. ;-------------------------------------------------------------------------
  201.  
  202. MAINLOOP:
  203.  
  204.     WRAST    $110            ; Wait for rasterpos $111
  205.     WRAST    $111
  206.  
  207.     move.w    #$722,$180(a5)        ; Scroll screen, and set
  208.     bsr    SCROLLER        ; a red background colour
  209.     move.w    #$000,$180(a5)        ; to measure time
  210.  
  211.     btst    #6,$BFE001        ; Loop until LMB is pressed
  212.     bne.s    MAINLOOP
  213.  
  214. ;-------------------------------------------------------------------------
  215.  
  216. EXITPROGRAM:
  217.  
  218.     move.l    EXECBASE,a6        ; Close graphics.library
  219.     move.l    GFXBASE,a1
  220.     jsr    CloseLibrary(a6)
  221.  
  222. EXIT:    lea    CUSTOMBASE,a5        ; Restore old values and exit
  223.     or.w    #$8000,OLDDMACONTROL
  224.     or.w    #$8000,OLDINTERRUPTS
  225.     move.w    OLDDMACONTROL,$96(a5)
  226.     move.w    OLDINTERRUPTS,$9A(a5)
  227.     move.l    OLDCOPPERLIST,$80(a5)
  228.     clr.w    $88(a5)
  229.     moveq    #0,d0
  230.     rts
  231.  
  232. ;-------------------------------------------------------------------------
  233.  
  234. GETRANDOM:
  235.  
  236.     moveq    #0,d0            ; Get a 'random' byte
  237.     moveq    #0,d1
  238.     move.b    $DFF007,d0
  239.     move.b    $BFD800,d1
  240.     eor.b    d1,d0
  241.     rts
  242.  
  243. ;-------------------------------------------------------------------------
  244.  
  245. SCROLLER:                ; Scrolling routine
  246.  
  247.     btst    #2,$DFF016        ; Skip if RMB is pressed
  248.     beq.w    SCRLX
  249.  
  250.     move.w    SCROLLPOS,d1        ; Lowest 4 bits into BPLCON1
  251.     and.w    #15,d1
  252.     sub.w    #15,d1
  253.     neg    d1
  254.     mulu    #$11,d1
  255.     move.w    d1,COP1SCROLL+2
  256.  
  257.     move.w    SCROLLPOS,d5        ; Add words to Bitplane-pointers
  258.     lsr.w    #4,d5
  259.     add.w    d5,d5
  260.     and.l    #$FFFE,d5
  261.  
  262.     move.l    #SCROLLPLANES+[0*SW],d0    ; Update pointers in
  263.     move.l    #SCROLLPLANES+[1*SW],d1    ; copperlist
  264.     move.l    #SCROLLPLANES+[2*SW],d2
  265.     move.l    #SCROLLPLANES+[3*SW],d3
  266.     move.l    #SCROLLPLANES+[4*SW],d4
  267.     add.l    d5,d0
  268.     add.l    d5,d1
  269.     add.l    d5,d2
  270.     add.l    d5,d3
  271.     add.l    d5,d4
  272.     move.l    d0,COPYADR        ; Store address where new
  273.     add.l    #SW-2,COPYADR        ; blocks are to copied
  274.     move.w    d0,COP1PLANE1+6
  275.     move.w    d1,COP1PLANE2+6
  276.     move.w    d2,COP1PLANE3+6
  277.     move.w    d3,COP1PLANE4+6
  278.     move.w    d4,COP1PLANE5+6
  279.     swap    d0
  280.     swap    d1
  281.     swap    d2
  282.     swap    d3
  283.     swap    d4
  284.     move.w    d0,COP1PLANE1+2
  285.     move.w    d1,COP1PLANE2+2
  286.     move.w    d2,COP1PLANE3+2
  287.     move.w    d3,COP1PLANE4+2
  288.     move.w    d4,COP1PLANE5+2
  289.  
  290.     bsr    COPYBLOCK            ; Copy a block at right edge
  291.  
  292.     cmp.w    #8*SW*[MX-1],SCROLLPOS        ; Scroll 1 pixel left
  293.     bge.s    SCRLX
  294.     addq.w    #1,SCROLLPOS
  295.  
  296. SCRLX:    rts
  297.  
  298. ;-------------------------------------------------------------------------
  299.  
  300. COPYBLOCK:                    ; Copy a block onto screen
  301.  
  302.     lea    SCROLLMAP,a0            ; Get block number from
  303.     add.w    SCROLLPOS,a0            ; the map
  304.     add.w    SCROLLPOS,a0
  305.     move.w    (a0),d0
  306.  
  307.     lea    BLOCKS,a0            ; Calculate address for
  308.     mulu    #160,d0                ; the block data
  309.     add.l    d0,a0
  310.  
  311.     move.w    SCROLLPOS,d1            ; Calculate address that
  312.     and.l    #15,d1                ; the block is copied into
  313.     mulu    #5*16*SW,d1
  314.     move.l    COPYADR,a1
  315.     add.l    d1,a1
  316.  
  317.     lea    CUSTOMBASE,a5            ; Blit block onto screen
  318.     WBLIT
  319.     move.l    a0,$50(a5)            ; BLTAPTR
  320.     move.l    a1,$54(a5)            ; BLTDPTR
  321.     move.l    #$0000002A,$64(a5)        ; BLTAMOD BLTDMOD
  322.     move.l    #$09F00000,$40(a5)        ; BLTCON0 BLTCON1
  323.     move.w    #$1401,$58(a5)            ; BLTSIZE
  324.     WBLIT
  325.     rts
  326.  
  327. ;-------------------------------------------------------------------------
  328. ; PUBLICMEM STORAGE
  329. ;-------------------------------------------------------------------------
  330.  
  331.         SECTION "publicdata",data_p
  332.  
  333. OLDCOPPERLIST:    dc.l    0
  334. OLDINTERRUPTS:    dc.l    0
  335. OLDDMACONTROL:    dc.l    0
  336.  
  337. SCROLLPOS:    dc.w    0        ; Scrollposition in pixels
  338.  
  339. COPYADR:    dc.l    0        ; Where to copy new blocks on screen
  340.  
  341. COLOURS:    dc.w    $000,$FFF,$EEE,$DDD,$CCC,$BBC,$AAB,$99A    ; Palette
  342.         dc.w    $889,$777,$666,$555,$444,$333,$222,$111
  343.         dc.w    $F87,$E65,$C43,$911,$800,$600,$400,$300
  344.         dc.w    $500,$B98,$DB9,$FDC,$846,$956,$A67,$A79
  345.  
  346. SCROLLMAP:    blk.w    [SW*8]*MX,0    ; Block map
  347.  
  348. GFXBASE:    dc.l    0
  349. GFXNAME:    dc.b    "graphics.library",0
  350.  
  351. ;-------------------------------------------------------------------------
  352. ; COPPERLIST
  353. ;-------------------------------------------------------------------------
  354.  
  355.         SECTION "chipdata",data_c
  356.  
  357. COPPERLIST:    dc.w    $008E,$2C81,$0090,$2CC1    ; DisplayWindow
  358.         dc.w    $0092,$0030,$0094,$00D0    ; DataFetch
  359.         dc.w    $0108,$00B2,$010A,$00B2    ; BitplaneModulo
  360.         dc.w    $0102,$0000,$0104,$0000    ; BPLCON1 & BPLCON2
  361.  
  362. COP1SPRITES:    dc.w    $0120,$0000,$0122,$0000    ; Sprite pointers
  363.         dc.w    $0124,$0000,$0126,$0000
  364.         dc.w    $0128,$0000,$012A,$0000
  365.         dc.w    $012C,$0000,$012E,$0000
  366.         dc.w    $0130,$0000,$0132,$0000
  367.         dc.w    $0134,$0000,$0136,$0000
  368.         dc.w    $0138,$0000,$013A,$0000
  369.         dc.w    $013C,$0000,$013E,$0000
  370.  
  371. COP1PALETTE:    dc.w    $0180,$0000,$0182,$0000    ; Palette
  372.         dc.w    $0184,$0000,$0186,$0000
  373.         dc.w    $0188,$0000,$018A,$0000
  374.         dc.w    $018C,$0000,$018E,$0000
  375.         dc.w    $0190,$0000,$0192,$0000
  376.         dc.w    $0194,$0000,$0196,$0000
  377.         dc.w    $0198,$0000,$019A,$0000
  378.         dc.w    $019C,$0000,$019E,$0000
  379.         dc.w    $01A0,$0000,$01A2,$0000
  380.         dc.w    $01A4,$0000,$01A6,$0000
  381.         dc.w    $01A8,$0000,$01AA,$0000
  382.         dc.w    $01AC,$0000,$01AE,$0000
  383.         dc.w    $01B0,$0000,$01B2,$0000
  384.         dc.w    $01B4,$0000,$01B6,$0000
  385.         dc.w    $01B8,$0000,$01BA,$0000
  386.         dc.w    $01BC,$0000,$01BE,$0000
  387.  
  388. COP1PLANE1:    dc.w    $00E0,$0000,$00E2,$0000    ; Bitplane pointers
  389. COP1PLANE2:    dc.w    $00E4,$0000,$00E6,$0000
  390. COP1PLANE3:    dc.w    $00E8,$0000,$00EA,$0000
  391. COP1PLANE4:    dc.w    $00EC,$0000,$00EE,$0000
  392. COP1PLANE5:    dc.w    $00F0,$0000,$00F2,$0000
  393.  
  394. COP1SCROLL:    dc.w    $0102,$0000        ; FineScrolling BPLCON1
  395.  
  396.         dc.w    $2C07,$FFFE,$0100,$5200    ; Turn on bitplanes at line $2C
  397.  
  398.         dc.w    $FFDF,$FFFE        ; Wait below line $100
  399.  
  400.         dc.w    $2C07,$FFFE,$0100,$0000    ; Turn off bitplanes at $12C
  401.  
  402.         dc.w    $FFFF,$FFFE        ; End copperlist
  403.  
  404. ;-------------------------------------------------------------------------
  405. ; CHIPMEM STORAGE
  406. ;-------------------------------------------------------------------------
  407.  
  408. SCROLLPLANES:    blk.b    5*SW*[SH+MX],0        ; Scroll bitplanes
  409.  
  410.         incdir "df0:"            ; Where to load includes
  411. BLOCKS:        incbin "blocks.raw"        ; Block image data
  412.  
  413. BLANKS:        dc.l    0,0            ; Blank sprite
  414.  
  415. ;-------------------------------------------------------------------------
  416.