; --------------------------------------
; "Buttonmaster" - V1.0P  -  CLI-Utility
; Coded by Doctor Mabsue of Alpha Flight
; November 1989
; ( Now for CJ 21 Assembler Lession 5 )
; --------------------------------------
openlibrary=	-408			; Offsets
closelibrary=	-414
write=		-48
output=		-60
waitforch=	-204
execbase=	$4
; --------------------------------------
; Attention! In the init routine the
; string from the CLI start is taken and
; analised. Starting from the SEKA this
; data is not given. So when you want to
; develope those routine set the regis-
; ters d0 and a0 with test values!
; --------------------------------------
beg:
movem.l 	d0-d7/a0-a6,-(a7)	; Aktuelle Register retten
move.w		d0,status		; Uebergabestring retten
move.l		a0,status+2
move.l		execbase,a6		; Dos-Library oeffnen
lea		dosname,a1
jsr		openlibrary(a6)
move.l		d0,dosbase
move.l		dosbase,a6		; Ausgabe Kanal holen
jsr		Output(a6)
move.l		d0,outhandle
move.w		status,d0		; Uebergebene Buchstabenzahl
subq		#1,d0
beq		message			; Kein Parameter vorhanden
subq		#2,d0
bmi		nomsg			; Keine Nachricht vorhanden
move.l		dosbase,a6		; Message ausgeben
move.l		outhandle,d1
move.l		status+2,d2
add.w		#2,d2
move.w		status,d3
sub.w		#3,d3
jsr		write(a6)
move.l		outhandle,d1		; Returnzeichen ausgeben
move.l		dosbase,a6
move.l		#msgx,d2
move.w		#1,d3
jsr		write(a6)
nomsg:
move.w		msgh+310,d1
move.l		status+2,a0
sub.w		#$4d61,d1
; ------- Parameter vergleichen --------
cmp.b		#"l",(a0)
beq		l1
cmp.b		#"L",(a0)
beq		l1
cmp.b		#"r",(a0)
beq		l2
cmp.b		#"R",(a0)
beq		l2
cmp.b		#"f",(a0)
beq		l3
cmp.b		#"F",(a0)
beq		l3
cmp.b		#"k",(a0)
beq		l4
cmp.b		#"K",(a0)
beq		l4
bra		message			; Ungueltige Eingabe
; --------------------------------------
l1:
btst		#6,$bfe001		; Linker Mausknopf
bne.s		l1
bra		ready
l2:
btst		#2,$dff016		; Rechter Mausknopf
bne.s		l2
bra		ready
tst.w		d1
bne		l2
l3:
btst		#7,$bfe001		; Joystick Feuer
bne.s		l3
bra		ready
l4:
cmp.b		#$77,$bfec01		; Taste gedrueckt
bne		l4
ready:
move.l		execbase,a6		; Dos-Library schliessen
move.l		dosbase,a1
jsr		closelibrary(a6)
cmp.w		#$6120,msgh+324
bne		ready
movem.l		(a7)+,d0-d7/a0-a6	; Register zurueckholen
rts					; Programmaussprung
message:
move.l		dosbase,a6
move.l		outhandle,d1
move.l		#msgh,d2
move.w		#msge-msgh,d3
jsr		write(a6)
bra		ready
; ------------------------------
msgh:
dc.b	$0a,$9b,"1m---- THIS IS BUTTONMASTER V1.0 ----",$9b,"0m",$0a
dc.b	"L -  Continue with left Mousebutton",$0a
dc.b	"R -               Right Mousebutton",$0a
dc.b	"F -             Joystick Firebutton",$0a
dc.b	"K -                Press Return Key",$0a
dc.b	"After the  Parameter you may append",$0a
dc.b	"      a message, for example:      ",$0a
dc.b	">> button f Press fire sucker!!! <<",$0a
dc.b	$9b,"1m Coding Dr. Mabuse of Alpha Flight ",$9b,"0m",$0a,$0a
msge:
msgx:		dc.b	$0a
even
status:		dc.w	0,0,0
dosname:	dc.b	"dos.library",0
dosbase:	dc.l	0
outhandle:	dc.l	0
