
*********************************
*	stars demo       	*
*********************************
numstars:	equ	70
inc:		equ	3
magic:		equ	150
buttondat:	equ	$26e6
start:  clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,spv_sp
*	move.b	#0,$484
*	move.l	#$58000,$436
	bsr	mousof
	bsr	getscrn
*	bsr	darkcolors
*	bsr	loadscr
*	bsr	colors
	bsr	linea
*	bsr	clearsc
	move.w	$26e0,d0
	bsr	randomseed
*	move.b	#0,$ff8260
*	move.l	#$31415926,$426
*	move.l	#amiga2,$42a
*******************************************

test:
	move.w	#250,d0
	bsr	randomplus
	move.w	d0,destx
	move.w	#150,d0
	bsr	randomplus
	move.w	d0,desty
	bsr	putparams


bp:	move.l	#mypb,a6
	dc.w	$a007

	tst.w	$26e6
	bne	ov
	bra	test

ov:	bra	gem



*******************************
putparams:
	lea	mypb,a0
	move.w	#50,(a0)	;width in pixels
	move.w	#50,2(a0)	;height in pixels
	move.w	#4,4(a0)	;number of planes
	move.w	#1,6(a0)	;?
	move.w	#1,8(a0)	;?
	move.b	#3,10(a0)	;logic ops
	move.b	#3,11(a0)
	move.b	#3,12(a0)
	move.b	#3,13(a0)
	move.w	#0,14(a0)	;minimum source x
	move.w	#0,16(a0)	;minimum source y
	move.l	screen,18(a0)	;source base ad
	move.w	#8,22(a0)	;words in line
	move.w	#160,24(a0)	;lines in plane ???
	move.w	#2,26(a0)	;always 2 ???
	move.w	destx,28(a0)	;min destination x
	move.w	desty,30(a0)	;min destination y
	move.l	screen,32(a0)	;destination base ad
	move.w	#8,36(a0)	;words in line
	move.w	#160,38(a0)	;lines in plane as above
	move.w	#2,40(a0)	;always 2
	move.w	#0,42(a0)	;ad of pattern buffer 0=none
	rts

mypb:	blk.w	100,0
destx:	blk.w	1,0
desty:	blk.w	1,0

***************************************
*               RETURN TO GEM

gem:
*	move.w	#$2700,sr
*        move.w  #34,-(sp)
*        trap    #14
*        addq.l  #2,sp
*        move.l  d0,a0
*        move.l  oldmouse,16(a0)

*        move.b  #7,$484
*       MOVE.W  #1,-(SP)        ;WAIT FOR A KEY
*        TRAP    #1
*        ADDQ.L  #2,SP

        move.w  #-1,-(sp)
        move.l  screen1,-(sp)
        move.l  screen1,-(sp)
        move.w  #5,-(sp)
        trap    #14
        addi.l  #12,sp
        

        move.l  spv_sp,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,(SP)



illegal
        CLR.W   -(SP)           ;RETURN TO GEM
   
        TRAP    #1

spv_sp: blk.l   1               ;supervisor SP store


*************************************************
linea:  dc.w    $a000
        move.l  a0,linepar
        move.l  8(a0),intin
        move.l  12(a0),ptsin
        rts

*************************************************

***********************fancy clear screen****************
clearsc:move.l  #99,d0
        move.l  screen,a0
cl1:    move.w  #159,d1
cl2:    move.w  #0,(a0)+
        dbf     d1,cl2
        addi.l  #160,a0
        dbf     d0,cl1
        move.w  #99,d0
        move.l  screen,a0
        addi.l  #160,a0
cl3:    move.w  #159,d1
cl4:    move.w  #0,(a0)+
        dbf     d1,cl4
        addi.l  #160,a0
        dbf     d0,cl3
        rts


cldel:  move.w  #3000,d2
cdel1:  nop
        dbf     d2,cdel1
        rts
*************puts my mouse interupt in***************** 


putrout:move.w  #34,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,a0
        move.l  16(a0),oldmouse
        move.l  #myrout,16(a0)
        rts
**************my ubeut mouse interupt*******************

myrout: tst.b   $0027e7
        bne    .L home
        movem.l d0-d7/a0-a6,-(sp)
        move.b  (a0),d0
        move.b  d0,d1
        and.b   #$00f8,d1
        cmp.b   #$00f8,d1
        bne    .L nearhome
        and.w   #$0003,d0
        lsr.b   #1,d0
        bcc    .L test1
        bset    #$0001,d0
test1:  move.b  $0027de,d1
        and.w   #$0003,d1
        cmp.b   d1,d0
        beq    .S test2
        move.w  d1,-(sp)
        move.l  $002900,a1
        jsr     (a1)
        move.w  (sp)+,d1
        move.w  d0,$0026e6
        eor.b   d0,d1
        ror.b   #2,d1
        or.b    d1,d0
        move.b  d0,$0027de
test2:  move.b  $0001(a0),d0
        or.b    $0002(a0),d0
        bne    .S test3
        bclr    #$0005,$0027de
        bra    .S nearhome
test3:  bset    #$0005,$0027de
        move.w  $0026e0,d0
        move.b  $0001(a0),d1
        ext.w   d1
        add.w   d1,d0
        move.w  $0026e2,d1
        move.b  $0002(a0),d3
        ext.w   d3
        add.w   d3,d1
        bsr    .S extra
        move.l  $002908,a1
        jsr     (a1)
        bsr    .S extra
        move.w  d0,$0026e0
        move.w  d1,$0026e2
        move.l  $002904,a1
        jsr     (a1)
nearhome:movem.l (sp)+,d0-d7/a0-a6
home:   rts
extra:  cmp.w   mmin,d0
        bge    .S extra1
        move.w  mmin,d0
        bra    .S extra2
extra1: cmp.w   mmax,d0
        ble    .S extra2
        move.w  mmax,d0
extra2: tst.w   d1
        bge    .S extra3
        move.w  #199,d1
        rts
extra3: cmp.w   $002688,d1
        ble    .S extra4
        move.w  #0,d1
extra4: rts


mmin:	blk.w	1,0
mmax:	blk.w	1,0
************get screen address***************
getscrn:move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,screen
        move.l  d0,screen1
        move.l  d0,screen2
        subi.l  #$8000,screen2
        move.l  screen2,screen3
        subi.l  #$8000,screen3
	move.l	screen3,screen4
	subi.l	#$8000,screen4
        move.l  screen1,seen
        move.l  screen2,hiden
        rts


screen4:	blk.l	1,0
************change colors****************
colors: move.l #palette,-(sp)
        move.w #6,-(sp)
        trap #14
        addq.l #6,sp
        rts
************change colors****************
darkcolors:
        move.l #palette2,-(sp)
        move.w #6,-(sp)
        trap #14
        addq.l #6,sp
        rts

*****************wait for a key*********************
wait:   move.w  $26e6,d0
        cmpi.w  #2,d0
        beq     wback
        bra     wait
wback:  rts
***************turn mouse off***********************
mousof: dc.w    $a00a   
        rts

*******************************************************************
; SYSNOPSIS
;    RandomSeed( SeedValue )
;                   D0

randomseed:     ADD.L   D0,D1           ;user seed in d0 (d1 too)
                MOVEM.L D0/D1,RND

; drops through to the main random function (not user callable)

LongRnd:        MOVEM.L D2-D3,-(SP)     
                MOVEM.L RND,D0/D1       ;D0=LSB's, D1=MSB's of random number
                ANDI.B  #$0E,D0         ;ensure upper 59 bits are an...
                ORI.B   #$20,D0         ;...odd binary number
                MOVE.L  D0,D2
                MOVE.L  D1,D3
                ADD.L   D2,D2           ;accounts for 1 of 17 left shifts
                ADDX.L  D3,D3           ;[D2/D3] = RND*2
                ADD.L   D2,D0
                ADDX.L  D3,D1           ;[D0/D1] = RND*3
                SWAP    D3              ;shift [D2/D3] additional 16 times
                SWAP    D2
                MOVE.W  D2,D3
                CLR.W   D2
                ADD.L   D2,D0           ;add to [D0/D1]
                ADDX.L  D3,D1
                MOVEM.L D0/D1,RND       ;save for next time through
                MOVE.L  D1,D0           ;most random part to D0
                MOVEM.L (SP)+,D2-D3
                RTS

; SYSNOPSIS
;    RndNum = Random( UpperLimit )
;      D0                 D0

random:         MOVE.W  D2,-(SP)
                MOVE.W  D0,D2           ;save upper limit
                BEQ.S   r1              ;range of 0 returns 0 always
                BSR.S   LongRnd         ;get a longword random number
                CLR.W   D0              ;use upper word (it's most random)
                SWAP    D0
                ext.l   d0
                DIVs    D2,D0           ;divide by range...
                CLR.W   D0              ;...and use remainder for the value
                SWAP    D0              ;result in D0.W
r1:             MOVE.W  (SP)+,D2
                RTS

randomplus:     MOVE.W  D2,-(SP)
                MOVE.W  D0,D2           ;save upper limit
                BEQ.S   r2              ;range of 0 returns 0 always
                BSR.S   LongRnd         ;get a longword random number
                CLR.W   D0              ;use upper word (it's most random)
                SWAP    D0
                DIVu    D2,D0           ;divide by range...
                CLR.W   D0              ;...and use remainder for the value
                SWAP    D0              ;result in D0.W
r2:             MOVE.W  (SP)+,D2
                RTS





*********************************************************
*       a brilliant routine courtesy of janko to        *
*       insert the vbi addresses in the jump table      *
*       lea address of routine in a0 do a jsr           *
*       putvbl and thats it!!!                          *
*********************************************************


putvbl: lea     $452,a1
        move.w  #1,(a1)
        moveq   #7,d1
        lea     $456,a1
        move.l  (a1),a1
vbl3:   subq.b  #1,d1
        cmpi.b  #0,d1
        beq.s   vbl4
        move.l  (a1)+,d0
        cmpi.l  #0,d0
        bne.S   vbl3
        suba.l  #4,a1
        move.l  a0,(a1)
vbl4:   rts



*********************************************************
*       my routines for loading in the screens          *
*       note i use degas format even though I           *
*       hate the package,due to it's simple format      *
*       ie: 32l for pallette and straight 32k screen    *
*       dump                                            *
*********************************************************

loadscr:move    #0,-(SP)        ;Open file
        move.l  #filename,-(SP) ;Address of filename
        move    #$3D,-(SP)
        trap    #1              ;Get handle number in D0
        addq.l  #8,SP
                
        move    D0,-(SP)        ;Save handle

        move.l  #dummy,-(SP)    ;load pallette into safe area
        move.l  #128,-(SP)       ;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        addi.l   #12,SP
        move    (sp),d0        
               
        move.l  screen,-(SP)    ;load it straight onto screen
        move.l  #32000,-(SP)    ;length to read in
        move    D0,-(SP)        ;Handle
        move    #$3F,-(SP)      ;bios number
        trap    #1              ;Read file in
        addi.l   #12,SP
                
        move    #$3E,-(SP)      ;Handle already on stack
        trap    #1              ;Close file
        addq.l  #4,SP
        rts

*******************blocks for rotated sprites*************
screen3:blk.l   1,0
pblock: blk.l   50
screen: blk.l   1
off:    blk.w   1
ynflg:  blk.w   1
screen2:blk.l   1
screen1:blk.l   1
dummy:  blk.l   32
xvel:   blk.w   1
yvel:   blk.w   1
brhits:	blk.w	1,0
filename:
       dc.b    'amiga.emu',0  
even
line:   blk.b   10
pos:    blk.l   1
col:    blk.l   1
number: blk.w   1
whichblock:     blk.l   1,0
shipx:  blk.w   1,0
shipy:  blk.w   1,0
shootx: blk.w   1,0
shooty: blk.w   1,0
bigshootx:      blk.w   1,0
bigshooty:      blk.w   1,0
shotxvel:       blk.w   1,0
shotyvel:       blk.w   1,0
levpos:         dc.b    27,89,41,64,0
scorepos:       dc.b    27,89,38,64,0
shippos:        dc.b    27,89,45,65,0
backcol:        dc.b    27,99,2,0
greencol:       dc.b    27,98,10,0

even
ships:	blk.w	1,0
intin:  blk.l   1
ptsin:  blk.l   1
putpix: equ     $a001
getpix: equ     $a002
seen:   blk.l   1
hiden:  blk.l   1
bigflg: blk.w   1,-1
palette2:
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000,$0000,$0000
        dc.w    $0000

*************************************STORAGE*******************************
shooting:       blk.w   1,-1
rnd:            blk.l   2,0
beatflg:        blk.w   1,0
brtimer:        blk.w   1,0
lastbr:         blk.w   1,0
grtimer:        blk.w   1,0
levsp:          blk.l   1,0
levtim:         blk.w   1,0
pdflg:          blk.w   1,0
whsp:           blk.l   1,0
tempsp:         blk.w   500,0
oldsp:          blk.w   1,-1
oldht:          blk.w   1,0
oldwt:          blk.w   1,0
oldscr:         blk.l   1,0
tempsh:         blk.l   1,0
score:          blk.w   1,0
level:          blk.w   1,0
oldmouse:       blk.l   1,0
linepar:        blk.l   1,0
mmin2:           blk.w   1,0
mmax2:           blk.w   1,0
byebye:         blk.w   1,-1
blockad:        blk.l   1,0


palette:dc.w	$0000,$0003,$0004,$0005,$0006,$0007,$0027,$0037
	dc.w	$0077,$0057,$0027,$0007,$0507,$0707,$0704,$0432

