; /-----------------------------------------------------------------------/
; file:		tcpip.s
; function:	Transport Layer Library
; opcode:		
; part of:	Infitra
;
; author:		E Kuik
; company:	Merciful Software (1997)
; /-----------------------------------------------------------------------/

; Ronald:
; This is my TCP/IP library special written for asm

.include "xlib.i"
.include "tcpip.i"

.macro Call_TCP function
	move.l	#function,d0
	jsr	_Call_TCPIP
.endm

.globl TCP_init
TCP_init:
	Get_cookie #"STiK",d1
	beq	Error
	move.l	d1,transport_pointer
	Find_str	#TCPmagic,d1
	bne	Error
	move.l	transport_pointer,a0

	move.l	get_dftab(a0),drvheader	; pointer to drvheader routine
	beq	Error			; zero
	move.l	etm_exec(a0),etmexec	; pointer to exec module
	move.l	cfg(a0),tcpconfig		; pointer to stikconfig
	move.l	get_dftab(a0),a6		; get pointer to tpl

/* build in savety */
	Super	#0
	move.l	d0,-(sp)
	move.l	sp,stack			; save stack
/* reset the bus exeption vector and address exeption vector */
	move.l	$08,old_vec		; the new exeption
	move.l	#new_vec,$08		; vectors in place!
	move.l	$0c,old_vec+4
	move.l	#new_vec,$0c
	moveq	#0,d0
	pea	Hello_TCP			; string "TRANSPORT_TCPIP" etc.
	jsr	(a6)
	addq.l	#4,sp			; adj stack
	bra.b	no_error
new_vec:	moveq	#0,d0			; Yahoo, exeption fired!
	move.l	stack,sp			; restore stack
no_error:	move.l	old_vec,$08		; restore old vectors
	move.l	old_vec+4,$0c
	move.l	d0,transporter		; hello tpl
	move.l	(sp)+,d0
	Super	d0
	rts

.globl _KRmalloc
_KRmalloc:
	move.l	d0,-(sp)
	Call_TCP	_trnsp_malloc
	addq.l	#4,sp
	Return	d0

.globl _KRfree
_KRfree:
	pea	(a0)
	Call_TCP	_trnsp_free
	addq.l	#4,sp
	Return	d0

.globl _KRgetfree
_KRgetfree:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_getfree
	addq.l	#2,sp
	Return	d0

.globl _KRrealloc
_KRrealloc:
	move.l	d0,-(sp)
	pea	(a0)
	Call_TCP	_trnsp_realloc
	addq.l	#8,sp
	Return	d0

.globl _get_err_text
_get_err_text:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_get_errtext
	addq.l	#2,sp
	Return	d0

.globl _getvstr
_getvstr:
	pea	(a0)
	Call_TCP	_trnsp_get_vstr
	addq.l	#4,sp
	Return	d0

.globl _carrier_detect
_carrier_detect:
	Call_TCP	_trnsp_carrier_detect
	Return	d0

.globl _TCP_open
_TCP_open:
	move.w	d3,-(sp)
	move.w	d2,-(sp)
	move.w	d1,-(sp)
	move.l	d0,-(sp)
	Call_TCP	_trnsp_TCP_open
	lea	10(sp),sp
	Return	d0

.globl _TCP_close
_TCP_close:
	move.w	d1,-(sp)
	move.w	d0,-(sp)
	Call_TCP	_trnsp_TCP_close
	addq.l	#4,sp
	Return	d0

.globl _TCP_send
_TCP_send:
	move.w	d1,-(sp)
	pea	(a0)
	move.w	d0,-(sp)
	Call_TCP	_trnsp_TCP_send
	addq.l	#8,sp
	Return	d0

.globl _TCP_wait_state
_TCP_wait_state:
	move.w	d2,-(sp)
	move.w	d1,-(sp)
	move.w	d0,-(sp)
	Call_TCP	_trnsp_TCP_wait_state
	addq.l	#6,sp
	Return	d0

.globl _TCP_ack_wait
_TCP_ack_wait:
	move.w	d1,-(sp)
	move.w	d0,-(sp)
	Call_TCP	_trnsp_TCP_ack_wait
	addq.l	#4,sp
	Return	d0

.globl _UDP_open
_UDP_open:
	move.w	d1,-(sp)
	move.l	d0,-(sp)
	Call_TCP	_trnsp_UDP_open
	addq.l	#6,sp
	Return	d0

.globl _UDP_close
_UDP_close:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_UDP_close
	addq.l	#2,sp
	Return	d0

.globl _UDP_send
_UDP_send:
	move.w	d1,-(sp)
	pea	(a0)
	move.w	d0,-(sp)
	Call_TCP	_trnsp_UDP_send
	addq.l	#8,sp
	Return	d0

.globl _CNkick
_CNkick:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_CN_kick
	addq.l	#2,sp
	Return	d0

.globl _CNbyte_count
_CNbyte_count:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_CN_bcount
	addq.l	#2,sp
	Return	d0

.globl _CNget_char
_CNget_char:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_CN_getchar
	addq.l	#2,sp
	Return	d0

.globl _CNget_NDB
_CNget_NDB:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_CN_getNDB
	addq.l	#2,sp
	Return	d0

.globl _CNget_block
_CNget_block:
	move.w	d1,-(sp)
	pea	(a0)
	move.w	d0,-(sp)
	Call_TCP	_trnsp_CN_getblock
	addq.l	#8,sp
	Return	d0

.globl _housekeep
_housekeep:
	Call_TCP	_trnsp_housekeep
	Return	d0

.globl _resolve
_resolve:
	move.w	d0,-(sp)
	pea	(a2)
	pea	(a1)
	pea	(a0)
	Call_TCP	_trnsp_resolve
	lea	14(sp),sp
	Return	d0

.globl _ser_disable
_ser_disable:
	Call_TCP	_trnsp_ser_disable
	Return	d0

.globl _ser_enable
_ser_enable:
	Call_TCP	_trnsp_ser_enable
	Return	d0

.globl _set_flag
_set_flag:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_set_flag
	addq.w	#2,sp
	Return	d0

.globl _clear_flag
_clear_flag:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_clr_flag
	addq.l	#2,sp
	Return	d0

.globl _CNgetinfo
_CNgetinfo:
	move.w	d0,-(sp)
	Call_TCP	_trnsp_CN_getinfo
	addq.l	#2,sp
	Return	d0

.globl _on_port
_on_port:
	pea	(a0)
	Call_TCP	_trnsp_on_port
	addq.l	#4,sp
	Return	d0

.globl _off_port
_off_port:
	pea	(a0)
	Call_TCP	_trnsp_off_port
	addq.l	#4,sp
	Return	d0

.globl _setvstr
_setvstr:
	pea	(a1)
	pea	(a0)
	Call_TCP	_trnsp_set_vstr
	addq.l	#8,sp
	Return	d0

.globl _query_port
_query_port:
	pea	(a0)
	Call_TCP	_trnsp_query_port
	addq.l	#4,sp
	Return	d0

_Call_TCPIP:
	tst.l	transporter
	beq	Error
	move.l	transporter,a0
	move.l	0(a0,d0.l),d0
	beq	Error
	sub.l	a0,a0
	jmp	0(a0,d0.l)
Error:	Return	#0

.data
TCPmagic:	dc.b	"STiKmagic",0

Hello_TCP:
	dc.b	"TRANSPORT_TCPIP",0
	dc.b	"User-Agent: Infitra 1.0 (beta)",0
	dc.b	"STiK",0,0,0,0
	dc.b	"Eabe Kuik",0

.bss
transport_pointer:	ds.l	1
transporter:	ds.l	1

drvheader:	ds.l	1
etmexec:		ds.l	1
tcpconfig:	ds.l	1

old_vec:		ds.l	2
stack:		ds.l	1