********************* *********************** ****** . . ****** **** . . . Init & Exit code . " **** *** ' . """""""""""""""" . *** ** . . . . . " . . ** ** " written in a hurry for . . ** *** . : . . """""""""""""""""""""" . *** **** #Amycoders' starfield compo by **** ****** . """"""""""""""""""""""""""" morbid ********************* *********************** j bsr.b CloseWB ; Flush view and disable multitasking bsr.w OpenScreen ; Set pointers and sync jsr Starfield_init ;Init starfield ** ************************************************************ ************************************************************ ** ** >>> M A I N <<< ** Main btst #6,$bfe001 beq.w Exit ************************************************************ bsr.w DisplayScreen jsr Starfield ;call starfield (a0=Bitplane) bra.b Main ** ************************************************************ ** ** Flush view & disable system ** CloseWB movea.l 4.w,a6 ; exec base jsr -132(a6) ; Forbid jsr -120(a6) ; Disable lea GfxName(pc),a1 ; graphics.library moveq #0,d0 ; whatever verision jsr -552(a6) ; open it ! move.l d0,GfxBase ; store gfxbase movea.l d0,a6 ; gfxbase in a6 move.l $22(a6),OldView ; store system view move.l $26(a6),OldCop ; store system copper sub.l a1,a1 jsr -222(a6) ; flush view (LoadView) jsr -270(a6) ; WaitTOF jsr -270(a6) ; twice for interlaced views move.w $dff002,OldDMAcon ; store old dma control register ori.w #$8000,OldDMAcon ; set bit #15 move.w #$7fff,$dff096 move.w #$8380,$dff096 rts GfxName dc.b 'graphics.library',0 even GfxBase dc.l 0 OldView dc.l 0 OldCop dc.l 0 OldDMAcon dc.w 0 cnop 0,4 ** ************************************************************* ** ** Display Screen ** DisplayScreen movem.l d0-d1,-(sp) move.b $bfe801,d0 .wait cmp.b $bfe801,d0 beq.b .wait move.l screen_logical(pc),d0 move.l screen_physical(pc),screen_logical move.l d0,screen_physical lea copper_bpl,a0 move.w d0,6(a0) ; lower part of bpl address swap d0 move.w d0,2(a0) ; higher word movea.l screen_logical(pc),a0 moveq #0,d0 move.l #(320/32)*256-1,d1 .clear move.l d0,(a0)+ ; clear logical screen dbf d1,.clear lea -(320/8)*256(a0),a0 movem.l (sp)+,d0-d1 rts screen_physical dc.l 0 screen_logical dc.l 0 ** ************************************************************* ** ** Open Screen ** OpenScreen lea $dff000,a5 move.l #Copper,$80(a5) move.w #$2c81,$08e(a5) ; display window start pos move.w #$2cc1,$090(a5) ; display window stop pos move.w #$0038,$092(a5) ; data fetch start pos move.w #$00d0,$094(a5) ; data fetch stop pos move.l #ScreenA,screen_logical move.l #ScreenB,screen_physical bsr.w DisplayScreen rts ** ************************************************************** ** ** Open WB ** Exit lea $dff000,a5 move.w #$7fff,$96(a5) ; clear dmacon move.w OldDMAcon(pc),$96(a5) ; set old bits move.l GfxBase(pc),a6 ; gfxbase in a6 move.l OldCop(pc),$80(a5) ; restart old copperlist move.l OldView(pc),a1 jsr -222(a6) ; Load system view move.l a6,a1 move.l 4.w,a6 jsr -414(a6) ; close graphics.library jsr -126(a6) ; Enable jsr -138(a6) ; Permit rts ************************************************************************ section screens,bss_c ScreenA ds.b (320*256)/8 ScreenB ds.b (320*256)/8 ************************************************************************ section copperlist,data_c Copper dc.l $01001000 ; bplcon0 dc.l $01080000 ; bpl1mod dc.l $010a0000 ; bpl2mod dc.l $01800000 ; colour 0 = black dc.l $01820fff ; colour 1 = white copper_bpl dc.l $00e00000 ; bpl1pth dc.l $00e20000 ; bpl1ptl dc.l $fffffffe ************************************************************************** ************************************************************************** ** ** ** Your starfield code starts here ** ** ************************************************************************** ************************************************************************** section code,code ;put your code here ********************************************* ** Do all initialisations here ********************************************* Starfield_init: a ; real coders do without! =) b rts ;-------------------------------- rndseed dc.l 0 ; = ;-------------------------------- ********************************************* ** This routine is called once a frame ** ** The destination Bitplane is given in a0 ********************************************* Starfield: c stars set 512 lea data,a1 ; data pointer move #320,d4 ; screen x size moveq #127,d5 ; screen y size / 2 move #stars-1,d7 ; dbf counter loop subq #1,(a1) ; 'move' stars bgt.b old ; in front of visitor (z>0)? lea (a1),a2 ; no, we need a new star moveq #2,d6 ; dbf counter 3 random numbers random rol #4,d0 ; get some numbers... add d7,d0 move.l d0,d1 divu #15000,d1 ; a star is stored as swap d1 ; z, x, y (each .w) lsr #1,d1 bcc.b keep neg.l d1 keep move d1,(a2)+ ; store value dbf d6,random old and d5,(a1) ; max. z is 127 movem (a1)+,d0-d2 ; load star coords addq #1,d0 ; avoid division by zero divs d0,d1 ; shrink x divs d0,d2 ; shrink y add #159,d1 ; center screen x blt.b dbf ; beyond left limit? cmp d4,d1 ; beyond right limit? bge.b dbf add d5,d2 ; center screen y blt.b dbf ; beyond upper limit? cmp #256,d2 ; beyond lower limit? bge.b dbf mulu d4,d2 ; y * linesize in bit(!) add d1,d2 ; + x position in bit(!) [*] lsr.l #3,d2 ; /8 - now we have byte offset not d1 ; correct offset for bitset bset d1,(a0,d2.w) ; hmmmm...stars dbf dbf d7,loop ; do it again, sam d rts ;--- printt "Length of code:" printv ((b-a)+(d-c)) section bss,bss ;put your tables heres data ds.w stars*3 ; (z,x,y) 'stars' times ;--- ; ; [*] Normally we would do the following to get the correct offsets: ; (assuming d1=x_pos, d2=y_pos) ; ; mulu #320/8,d2 ; size one line in byte ; move d1,d3 ; save x position ; lsr #3,d1 ; byte offset x ; add d1,d2 ; byte offset x + y ; not d3 ; for bitset ; : ; : ; ; but we can save some bytes the way it was done above. but there is ; one thing that can happen: if we have a star in line 204 we get ; 204*320=$ff00 as bit offset. if the x offset (in bit) is now >255 ; we have an overflow since the add command is .w not .l - what happens ; is that for one frame the star is printed at a location in the upper ; left corner of the screen. but you will never notice that, especially ; if there are more than 3 or 4 stars around...i just wanted to mention ; it... ;) ; ; note that since d7 (dbf counter) is involved in the random number ; generator you need at least two stars, otherwise only useless data ; are generated. excellent performance with 512 stars. ; ; ; GORE DESIGN - if it works, we didn't do it...greetings to my pal Flynn! ; ____ ; / / ;_______________________________________________________________________ / / /_ ; / / / ; Dark Angel of Gore Design ____ / / / ; e-mail: wir96fme@studserv.uni-leipzig.de \ \/ / / ;______________________________________________ powered by AMIGA \ \ \/ /_____ ; \_\_\/ .