I found a Link tutorial once, and this is the part for sending/receiving:
Code: ;=========================linktutorial example program by merlijn===============
;=================================www.ti-merlijn.tk=============================
#define player saferam1
#define errors saferam1+1
start:
bcall(_cleargbuf)
ld a,55
ld (penrow),a
ld a,53
ld (pencol),a
ld hl,presskey
bcall(_vputs)
ld a,1
ld (errors),a
ld a,0ffh ;resets the keypad.
out (1),a
waitkey:
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 2
jp z,setup2
ld a,0D1h
out (0),a ;required syntax
ld a,1
ld (player),a
ld a,50
ld (xcoord),a
ld hl,0
waitplayer:
inc hl
IN A,(0) ; check linkport
AND 3 ; upper bits are not important
CP 0
jp z,intro
ld a,KeyRow_Top
out (1),a
in a,(1)
cp KMode
ret z
jp waitplayer
setup2:
ld a,2
ld (player),a
ld a,26
ld (xcoord),a
ld a,0D2h
out (0),a ; required syntax
waitothercomes:
IN A,(0) ; check linkport
AND 3 ; upper bits are not important
CP 1
jp nz,waitothercomes
...;variable initialization here
mainloop:
...
call sendreceive;call sendreceive routine
...
jp mainloop
...
sendreceive:
ld a,(player) ;the stored byte
cp 1
jp z,send_than_receive;to have a fast link calcs have to do the opposite
cp 2
jp z,receive_than_send;to have a fast link calcs have to do the opposite
send_than_receive:
ld a,(xcoord) ;the byte you want to send
ld c,a ;we actually send c
call sendbyte ;call send routine
call receivebyte;call receive routine
ld a,e ;we actually receive e
ld (xopp),a ;save received byte
ret ;return to mainloop
receive_than_send:
call receivebyte;call receive routine
ld a,e ;we actually receive e
ld (xopp),a ;save received byte
ld a,(xcoord) ;the byte you want to send
ld c,a ;we actually send c
call sendbyte ;call send routine
ret ;return to mainloop
;=========================================the routines============================================
;====================send routines from venus and synchronising by Merlijn=======================
sendbyte: ;input: white active, output: continue if red and white active
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 1 ;1 means white is active
ret z ;if true other player wants to send
ld a,0D2h ;set white wire active
out (0),a ;required syntax to send a to the linkport
sendbytewait:
ld a,KeyRow_Top
out (1),a
in a,(1)
cp KGraph ;emergency quit key
jp z,error ;it is possible to got stuck here if the connection got lost
cp kDel ;graph will quit to ion and del will try to restore
ret z
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 0 ;0 means red and white are active
jp nz,sendbytewait;not true check again
reswait:
ld a,0 ;set timer to zero
wait2: ;create small delay so other can check port for double activety
inc a ;increase timer
cp 10 ;compare to 20
jp nz,wait2 ;not true increase more
;-----------end of synchronising-------------
vnSendByte:
ld b,8
vnSendByteLoop:
rr c
vnSendBit0:
ld a,$01
jr nc,vnSendBit
vnSendBit1:
inc a
vnSendBit:
ld de,0
out (0),a
vnSendBitLoop1:
dec de
ld a,e
or d
jr z,vnSendQuit
in a,(0)
and 03h
jr nz,vnSendBitLoop1
vnSendQuit:
out (0),a
cp d
ret z
ld d,a
ld e,a
vnSendBitLoop2:
dec de
ld a,d
or e
ret z
in a,(0)
and 03h
cp 03h
jr nz,vnSendBitLoop2
djnz vnSendByteLoop
inc a
ld a,0D0h ;ld set no wire active for next session
out (0),a ;required syntax
ret
;=========================End of send routine====================================================
;=========================receive routine from venus and synchronising by Merlijn================
receivebyte:
;input: red active, output: continue if red and white active
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 2 ;1 means red is active
ret z ;if true other player wants to receive
ld a,0D1h ;ld set red wire active
out (0),a ;required syntax
receivebyte2:
ld a,KeyRow_Top
out (1),a
in a,(1)
cp KGraph ;emergency quit key
jp z,error ;it is possible to got stuck here if the connection got lost
cp kDel ;graph will quit to ion and del will try to restore
ret z
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 0 ;0 means red and white are active
jp nz,receivebyte2;not true check again
ld a,0 ;set timer to zero
wait: ;create small delay so other can check port for double activety
inc a ;increase timer
cp 30 ;compare to 40
jp nz,wait ;not true increase again
;-----------end of synchronising-------------
vnReceiveByte:
ld b,8
vnReceiveByteLoop:
ld hl,0
vnReceiveBitLoop1:
dec hl
ld a,h
or l
ret z
in a,(0)
and 03h
xor 03h
jr z,vnReceiveBitLoop1
ld d,a
xor 03h
cp 02h
rr c
out (0),a
ld hl,0
vnReceiveBitLoop2:
dec hl
ld a,h
or l
jr z,vnReceiveQuit
in a,(0)
and d
jr z,vnReceiveBitLoop2
vnReceiveQuit:
ld a,$00
out (0),a
ret z
djnz vnReceiveByteLoop
ld e,c
ld a,0D0h ;ld set no wire active for next session
out (0),a ;required syntax
ret
;=======================End of receive routine============
error:
xor a
ld (errors),a
ret
presskey: .db "Connecting..",0
Last edited by Guest on 20 Sep 2003 09:32:45 am; edited 1 time in total |