	opt c- o+
cxmin:		equ	0
cxmax:		equ	319
cymin:		equ	0
cymax:		equ	199
NumStars	equ	80
vbl_vec:	equ	$70
key_vec:	equ	$118
hbl_vec:	equ	$120
bpwidth:	equ	320
bpheight:	equ	200
start:
	clr.l   -(SP)           ;Go into supervisor mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
        move.l  D0,savesup
	dc.w	$a00a

	lea	palsave,a0
	move.l	#$ff8240,a1
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+
	move.l	(a1)+,(a0)+

	move.w	#4,-(sp)
	trap	#14
	addq.l	#2,sp
	move.w	d0,ressave

	move.w	#0,-(sp)	;set to low res
	move.l	#-1,-(sp)
	move.l	#-1,-(sp)
	move.w	#5,-(sp)
	trap	#14
	add.l	#12,sp
	bsr	getscrn
	bsr	plotinit
	lea	greypalette,a0
	bsr	mydocolors


mainloop:
	move.w	#160,x1
	move.w	#100,y1
	move.w	#300,x2
	move.w	#190,y2
	bsr	plotline

	bsr	keyboard
	bra	mainloop


flag:	dc.w	0
plotline:
	move.w	#0,flag		;flag for how many coords swapped
	move.w	x1,d0
	cmp.w	x2,d0
	blt.s	noexgx
	move.w	x2,x1
	move.w	d0,x2
	or.w	#1,flag
noexgx:
	move.w	y1,d0
	cmp.w	y2,d0
	blt.s	noexgy
	move.w	y2,y1
	move.w	d0,y2
	or.w	#2,flag
noexgy:
*	cmpi.w	#0,flag
*	beq.s	noshit
*	cmpi.w	#3,flag
*	beq.s	noshit
*	cmpi.w	#1,flag
*	bne.s	noshit1
*	move.w	x1,d0
*	move.w	x2,x1
*	move.w	d0,x2
*	bra.s	noshit
*noshit1:
*	cmpi.w	#2,flag
*	bne.s	noshit
*	move.w	y1,d0
*	move.w	y2,y1
*	move.w	d0,y2
noshit:
	move.w	x1,d0
	sub.w	x2,d0
	bge.s	li10
	neg.w	d0
li10:
	move.w	y1,d1
	sub.w	y2,d1
	bge.s	li20
	neg.w	d1
li20:
	cmp.w	d0,d1
	bgt	ymajor

	move.w	d1,d4
	sub.w	d0,d4
	move.w	d4,d5
	add.w	d4,d4
	add.w	d1,d5
	move.w	d1,d3
	add.w	d1,d3

	move.w	x2,d6
	cmp.w	x1,d6
	bge.s	li30
	move.w	y2,d7
	move.w	x1,d2
	bra.s	li40
li30:
	move.w	x1,d6
	move.w	y1,d7
	move.w	x2,d2
li40:
xmajor1:
	cmpi.w	#0,flag
	beq.s	stayxm1
	cmpi.w	#3,flag
	bne.s	xmajor2
stayxm1:
	move.w	d6,d0
	move.w	d7,d1
	bsr	singleplot
	bra.s	xm1li80
xm1li50:
	addq.w	#1,d6
	tst.w	d5
	bge.s	xm1li60
	add.w	d3,d5
	bra.s	xm1li70
xm1li60:
	addq.w	#1,d7
	add.w	d4,d5
xm1li70:
	move.w	d6,d0
	move.w	d7,d1
	bsr	singleplot
xm1li80:
	cmp.w	d6,d2
	bge.s	xm1li50
	rts
xmajor2:
	cmpi.w	#1,flag
	bne.s	skk
	move.w	y2,d7
	bra	skkk
skk:
	cmpi.w	#2,flag
	bne.s	skkk
	move.w	y2,d7
skkk:
	move.w	d6,d0
	move.w	d7,d1
	bsr	singleplot
	bra.s	xm2li80
xm2li50:
	addq.w	#1,d6
	tst.w	d5
	bge.s	xm2li60
	add.w	d3,d5
	bra.s	xm2li70
xm2li60:
	subq.w	#1,d7
	add.w	d4,d5
xm2li70:
	move.w	d6,d0
	move.w	d7,d1
	bsr	singleplot
xm2li80:
	cmp.w	d6,d2
	bge.s	xm2li50
	rts

ymajor:
	move.w	d0,d4
	sub.w	d1,d4
	move.w	d4,d5
	add.w	d4,d4
	add.w	d0,d5
	move.w	d0,d3
	add.w	d0,d3
	move.w	y2,d6
	cmp.w	y1,d6
	bge.s	li30b
	move.w	x2,d7
	move.w	y1,d2
	bra.s	li40b
li30b:
	move.w	y1,d6
	move.w	x1,d7
	move.w	y2,d2
li40b:
ymajor1:
	cmpi.w	#0,flag
	beq.s	stayym1
	cmpi.w	#3,flag
	bne.s	ymajor2
stayym1:
	move.w	d7,d0
	move.w	d6,d1
	bsr	singleplot
	bra.s	ym1li80
ym1li50:
	addq.w	#1,d6
	tst.w	d5
	bge.s	ym1li60
	add.w	d3,d5
	bra.s	ym1li70
ym1li60:
	addq.w	#1,d7
	add.w	d4,d5
ym1li70:
	move.w	d7,d0
	move.w	d6,d1
	bsr	singleplot
ym1li80:
	cmp.w	d6,d2
	bge.s	ym1li50
	rts
ymajor2:
	cmpi.w	#1,flag
	bne.s	skkb
	move.w	x2,d7
	bra	skkkb
skkb:
	cmpi.w	#2,flag
	bne.s	skkkb
	move.w	x2,d7
skkkb:
	move.w	d7,d0
	move.w	d6,d1
	bsr	singleplot
	bra.s	ym2li80
ym2li50:
	addq.w	#1,d6
	tst.w	d5
	bge.s	ym2li60
	add.w	d3,d5
	bra.s	ym2li70
ym2li60:
	subq.w	#1,d7
	add.w	d4,d5
ym2li70:
	move.w	d7,d0
	move.w	d6,d1
	bsr	singleplot
ym2li80:
	cmp.w	d6,d2
	bge.s	ym2li50
	rts



****************************************
keyboard:
	move.w	#$ff,-(sp)
	move.w	#$6,-(sp)
	trap	#1
	addq.l	#4,sp
	tst.l	d0
	beq	keyback
	swap	d0

	cmp.b	#16,d0		*space
	beq	gem		*yes/no
keyback:
	rts

*****************************************
*	number in d0.l			*
*	d1.l is base			*
*	d2,x cursor			*
*	d3,y cursor			*
*****************************************
prtnum:
	movem.l	d0/d1,-(sp)
	lea	posstring,a0
	add.w	#32,d3
	move.b	d3,2(a0)	
	move.b	d3,10(a0)	
	add.w	#32,d2
	move.b	d2,3(a0)
	move.b	d2,11(a0)	
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	movem.l	(sp)+,d0/d1

	lea	linebuffer,a0
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
	clr.l	(a0)+
loop1:
	divu	d1,d0
	swap	d0
	addi	#'0',d0
	cmpi.w	#'9',d0
	ble.s	ok
	addq.w	#7,d0
ok:
	move.b	d0,-(a0)
	clr	d0
	swap	d0
	bne	loop1
loop2:
	move.l	a0,-(sp)
	move.w	#9,-(sp)
	trap	#1
	addq.l	#6,sp
	rts


linebuffer:
	ds.l	5
digits:
	dc.b	0
posstring:	dc.b	27,'Y',0,0,' ',' ',' ',' ',27,'Y',0,0,0
	even



***********************************
mydocolors:
	move.l	#$ff8240,a1
	moveq	#15,d0
mdcloop:
	move.w	(a0)+,(a1)+
	dbf	d0,mdcloop
	rts

************get screen address***************
getscrn:move.w  #2,-(sp)
        trap    #14
        addq.l  #2,sp
        move.l  d0,seen
	rts


******************************************
*               RETURN TO GEM
gem:
*	move.b	#%11111110,$ff820a
	move.l	#$ff8240,a0
	lea	palsave,a1
	moveq	#15,d7
rspl:
	move.w	(a1)+,d0
	and.w	#$0777,d0
	move.w	d0,(a0)+
	dbf	d7,rspl

*	move.l	vblslot,a0
*	move.l	#0,(a0)

        move.w  ressave,-(sp)
        move.l  seen,-(sp)
        move.l  seen,-(sp)
        move.w  #5,-(sp)
        trap    #14
        add.l  #12,sp

	move.l  savesup,-(SP)    ;Back to user mode
        move.w  #$20,-(SP)
        trap    #1
        addq.l  #6,SP
*illegal
	clr.w	-(sp)
	trap	#1





********************************************
* Atari ST hi-speed plotting subroutine    *
* For Low-resolution mode only		   *
********************************************
plotinit:
	move.l	seen,a0
	move.b	#200,d1
	lea	ytable1,a1
iloop:
	move.l	a0,(a1)+
	adda.w	#160,a0
	subq.b	#1,d1
	bne	iloop
	rts
**********************************************
singleplot:
	movem.l d0-d5/a0-a1,-(sp)
*	move.w	pixelx,d0
	cmp.w	#cxmax,d0
	bgt	pltxit
	cmpi.w	#cxmin,d0
	blt	pltxit
	move.w	d0,d3
	andi.w	#15,d3
*	move.w	pixely,d1
	cmp.w	#cymax,d1
	bgt	pltxit
	cmpi.w	#cymin,d1
	blt	pltxit
	lsl.w	#2,d1
	move.w	pixelcolor,d2

	lsr.w	#1,d0
	and.w	#$00f8,d0
	move.w	d0,a0
	lea	ytable1,a1
	adda.l	(a1,d1.w),a0

	move.w #$8000,d4
	lsr.w d3,d4
	move.l #$80008000,d5
	lsr.l d3,d5
	eor.l #$ffffffff,d5
******************************
*    Turn off old pixel!     *
******************************
myphere:
	and.l d5,(a0)	     ;turn off old pixel
	and.l d5,4(a0)	     ;(both longwords)

******************************
* Now turn on the new pixel! *
******************************
	btst #0,d2
	beq bit2
	or.w d4,(a0)
bit2:
	btst #1,d2
	beq bit4
	or.w d4,2(a0)
bit4:
	btst #2,d2
	beq bit8
	or.w d4,4(a0)
bit8:
	btst #3,d2
	beq pltxit
	or.w d4,6(a0)
pltxit:
	movem.l (sp)+,d0-d5/a0-a1
	rts
pltxit2:
	movem.l (sp)+,d0-d5/a0-a1
	moveq	#-1,d0
	rts
pltxit3:
	movem.l (sp)+,d0-d5/a0-a1
	moveq	#-2,d0
	rts



rvsave:	dc.l	0
resave:	dc.l	0
	even
savesup:	dc.l	0
ressave:	dc.w	0
filename:	dc.l	0
greypalette:
*	incbin	'ste.pal'
	dc.w	$0000,$0222,$0444,$000f,$0fff,$000f,$000f
	dc.w	$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f,$000f
	dc.w	$000f,$000f
save_usp:
	dc.l	0
wfnc:
	dc.w	0
save_stk:
	dc.l	0
pointer:	dc.l	0
pixelx:		dc.w	0
pixely:	dc.w	0
pixelcolor:	dc.w	15
flip:	dc.w	0
flip2:	dc.w	0
seen:	dc.l	0
hiden:	dc.l	0
clrbuffseen:	dc.l	0
clrbuffhiden:	dc.l	0
screen:	dc.l	0
	ds.w	16
*	section	bss
x1:	ds.w	1
y1:	ds.w	1
x2:	ds.w	1
y2:	ds.w	1

number:	ds.w	1
palsave:
	ds.w	16
vblslot:	ds.l	1
d7emulator:	ds.w	1
ytable1:	ds.w	200
