RS232GUI


;******************************************************************************
;****************************RS232 COM V0.9**********************************
;***************************BY HENRIK STOLPE***********************************
;******************************************************************************
execbase = 4
GetMsg = -372
Wait = -318
ReplyMsg = -378
DrawBorder = -108
PrintLText = -216
OpenWorkBench = -210	
Read = -42
Open = -30
Mode_old = 1005
Mode_new = 1006
OpenLib = -408
CloseLib = -414

	incdir	"dh0:assembler/include/"
	include	exec/exec_lib.i
	include	intuition/intuition.i
	include	intuition/intuition_lib.i


s:
	bsr	makegad
	bsr	openall
	bsr	interface
	bsr	initserial
	bsr	again		;set to again to debug
	rts


openall:
	moveq	#100,d4			
	moveq	#INTUITION_REV,d0	
	lea	int_name(pc),a1
	CALLEXEC OpenLibrary
	tst.l	d0
	beq	exit_false		
	move.l	d0,_IntuitionBase	
	move.l	_IntuitionBase,a6
	jsr	OpenWorkBench(a6)

openwin:
	lea	windowdef,a0	
	CALLINT	OpenWindow
	move.l	d0,MyWindow		
	


opendos:
	move.l	execbase,a6
	lea	dosname,a1
	moveq	#0,d0
	jsr	OpenLib(a6)
	move.l	d0,dosbase
	
openfile:
	move.l	dosbase,a6
	move.l	filename,d1
	move.l	#1006,d2
	jsr	Open(a6)
	move.l	d0,filehd
	rts


filehd:
	dc.l	0
	
filename:
	dc.b	'dh0:testfile0',0
	

dosname:
	dc.l	'dos.library',0,0

dosbase:
	dc.l	0		


interface:
	bsr	lines
	bsr	textpr
	rts


lines:
	lea	box,a1
	move	#14,d0
	move	#14,d1
	bsr	drawit
	rts	

drawit:
	move.l	_IntuitionBase,a6
	move.l	MyWindow,a0
	move.l	50(a0),a0
	jsr	DrawBorder(a6)
	rts
		
textpr:
	lea	text,a1
	move	#14,d0
	move	#80,d1
	bsr	printit
	rts	
	

printit:
	move.l	_IntuitionBase,a6
	move.l	MyWindow,a0
	move.l	50(a0),a0
	jsr	PrintLText(a6)
	rts


loop:
	move.l	MyWindow(pc),a0
           move.l	wd_UserPort(a0),a0
	moveq	#0,d1
	move.b	MP_SIGBIT(a0),d1
	moveq	#0,d0
	bset	d1,d0
	move.l	execbase,a6
	CALLEXEC Wait
	move.l	#0,d4
	bsr	again

again:
	move.l	MyWindow,a0
	move.l	wd_UserPort(a0),a0
	move.l	execbase,a6
	jsr 	GetMsg(a6)
	move.l	d0,a1
	moveq.l	#0,d6
	moveq	#0,d7
	move.l	$14(a1),d6		;IDCPM Class
	move.l	$1c(a1),a2		;Adress	
	move	38(a2),d7		;gadget Id in Adress
*;	jsr	ReplyMsg(a6)	;disable to debug
	cmp.l	#$200,d6
	beq	slut
*;	cmp	#1,d7
*;	beq	load
	cmp	#2,d7
	beq	sndascii
*;	cmp	#3,d7
*;	bne	filter
	bne	again			;set to again to debug
	rts

;routines

initserial:
	lea	data,a3
	moveq	#0,d3
	move.l	#dataend-data,d3		;calculate lenght
	clr.l	d5
	moveq	#0,d2
	move.l	#$fff,d2
	rts

waitbuf:	
	cmp	#0,d2
	dbeq	d2,waitbuf

sndascii:
	move.b	(a3)+,d5
	move.b	d5,$dff030		;wr bufferand start transmitting
	cmp	#0,d3
	move.l	#$fff,d2
	dbeq	d3,waitbuf
	bsr	initserial
	bsr	again
	rts


data:
	dc.b	'this is a very boring text',0
dataend:
	

makegad:
	lea	gad1,a4
	move.l	#gad2,(a4)+
	move.w	#25,(a4)+
	move.w	#20,(a4)+
	move.w	#80,(a4)+
	move.w	#9,(a4)+
	move.w	#%00000000,(a4)+
	move.w	#3,(a4)+
	move.w	#1,(a4)+
	move.l	#bord,(a4)+
	move.l	#0,(a4)+
	move.l	#gad1text,(a4)+
	move.l	#1,(a4)+
	move.l	#1,(a4)+
	move.w	#1,(a4)+
	move.l	#0,(a4)
	rts
	
slut:
closewin:
	move.l	MyWindow(pc),a0
	CALLINT CloseWindow

closeint
	move.l	_IntuitionBase(pc),a1
	CALLEXEC CloseLibrary

closedos:
	move.l	dosbase,a1
	move.l	execbase,a6
	jsr	CloseLib(a6)


exit_false
	moveq	#0,d4
	move.l	d4,d0			
	rts

;structures
_IntuitionBase	dc.l	0		
MyWindow	dc.l	0
INTUITION_REV	equ	31		v1.1
int_name	INTNAME

windowdef:
	dc.w	300
	dc.w	15
	dc.w	300
	dc.w	100
	dc.b	2
	dc.b	1
	dc.l	$220
	dc.l	$200320e
	dc.l	gad1
	dc.l	0
	dc.l	windowname
	
screenhd:
	dc.l	0
	dc.l	0
	dc.w	230
	dc.w	100
	dc.w	320
	dc.w	200
	dc.w	1

windowname:
	dc.b	'SERIAL INTERFACE HANDLER',0
	even
	
windowhd:
	dc.l	0
        even

gad1:
	blk.w	22
	
gad1text:
	dc.b	3,0
	dc.b	1
	even
	dc.w	22,1
	dc.l	0
	dc.l	gd1txt
	dc.l	0

gd1txt:
	dc.b	"LDA",0
	even



gad2:
	dc.l	gad3
	dc.w	25,40
	dc.w	80,9
	dc.w	%00000000
	dc.w	$3		;relverify/gadgimmediate,($100 = toggleselect)
	dc.w	1
	dc.l	bord
	dc.l	0
	dc.l	gad2text
	dc.l	0
	dc.l	0
	dc.w	2
	dc.l	0

gad2text:
	dc.b	3,0
	dc.b	1
		even
	dc.w	22,1
	dc.l	0
	dc.l	gd2txt
	dc.l	0

gd2txt:
	dc.b	"SND",0
	even



gad3:
	dc.l	0
	dc.w	25,60
	dc.w	80,9
	dc.w	%00000000
	dc.w	$3		;relverify/gadgimmediate,($100 = toggleselect)
	dc.w	1
	dc.l	bord
	dc.l	0
	dc.l	gad3text
	dc.l	0
	dc.l	0
	dc.w	3
	dc.l	0

gad3text:
	dc.b	3,0
	dc.b	1
	even
	dc.w	16,1
	dc.l	0
	dc.l	gd3txt
	dc.l	0

gd3txt:
	dc.b	"RCV",0
	even



bord:
	dc.w	0,0
	dc.b	1,3
	dc.b	0
	dc.b	5
	dc.l	cords
	dc.l	border2

border2:
	dc.w	0,0
	dc.b	2,3
	dc.b	0
	dc.b	3
	dc.l	cords2
	dc.l	0

cords:
	dc.w	-2,-2
	dc.w	80,-2
	dc.w	80,11
	dc.w	-2,11
	dc.w	-2,-2

cords2:
	dc.w	80,-2
	dc.w	-2,-2
	dc.w	-2,11


box:
	dc.w	0,0
	dc.b	1,3
	dc.b	0
	dc.b	5
	dc.l	boxcords
	dc.l	box2


box2:
	dc.w	0,0
	dc.b	2,3
	dc.b	0
	dc.b	3
	dc.l	box2cords
	dc.l	0

boxcords:
	dc.w	0,0
	dc.w	100,0
	dc.w	100,61
	dc.w	0,61
	dc.w	0,0

box2cords:
	dc.w	100,0
	dc.w	0,0
	dc.w	0,61

text:
	dc.b	1,0
	dc.b	1
	even
	dc.w	0,0
	dc.l	0
	dc.l	txt
	dc.l	text2

txt:
	dc.b	"By Henrik Stolpe",0
	even

text2:
	dc.b	1,0
	dc.b	1
	even
	dc.w	0,8
	dc.l	0
	dc.l	txt2
	dc.l	0
txt2:
	dc.b	"100% assembler!",0