[A83] Re: linkport
[Prev][Next][Index][Thread]
[A83] Re: linkport
On Wed, 2 Jan 2002 13:45:19 +0100, "Maarten Blomme" <maartenblomme@hotmail.com> wrote...
>How do I have to use the linkport in asm?
>
>MB
>
>
>
>_________________________________________________________________
>Meld je aan bij de grootste e-mailservice wereldwijd met MSN Hotmail:
>http://www.hotmail.com/nl
Hehe, that's Dutch :)
I once downloaded this "linktutorial.txt" from ticalc.org. I hope Merlijn (whoever he is) doesn't mind :)
================================================================================================
===================================Link Tutorial by Merlijn=====================================
===========================================for ti83=============================================
._______________________________________________________________________________________________.
| |
| I'm programming for the ti83 for a year now and I always wanted to make a link |
| game. But there was no link tutorial availeble. I asked around and everybody said |
| that the Ztetris source should help me. Sadly enough doesn't zeteris' link work at |
| all. Therefor did I decide to make a link tutorial for all you out there. |
| Aim of this tutorial send and receive bytes for multiplayer games. |
| E-mail me for questions, bugs, modifications and improvements. Mezzy30@hotmail.com |
| Special thanx to Tijl Coosemans for his routines. |
|_______________________________________________________________________________________________|
Disclaimer:
I'm not responsible for damage to your calc, health ect. No one may publish this tutorial
whithout my permission. If you use this routine give me credits.
First you should know that the Ti-83 and other calcs use three cables to link. A white,
a Red and a Yellow. The Yellow one the zero, so you can't set power on that one.
The Red and the White can be changed into high or low. Usually the lines are both set
low. This also accures after every romcall. The linkport is port number '0'.
Now to set the lines use the following code:
ld a,0d1h ;load value of lines into a, set red high
out (0),a ;syntax for linkport, linkport has been set
for other set values look in the table below.
0d0h both lines low
0d1h red high, white low
0d2h white high, red low
0d3h both lines high
If you want to read the port use this:
in a,(0) ; check linkport
and 3 ; upper bits are not important
cp 2 ; 2 means white is active
for other read values look in the table below.
3 both lines low
2 red high, white low
1 white high, red low
0 both lines high
It is important to know that if one of the calcs sets the red wire high and the other sets
the white wire high it will result that when you read the linkport both lines are high (0).
0d0h 3 both lines low
0d1h 2 red high, white low
0d2h 1 white high, red low
0d3h 0 both lines high
0d1h+0d2h=>0 (every calc have to set one of the wires)
I've written a program, 'READSET' to set and to read the port. 'READSET' can be found at ticalc.org
Now we want to send bytes and receive bytes. I used the send/receive code from venus and added a
synchronising routine made myselve to it. Take a look at the source it will explain itselve.
-----header-----
#define player saferam1
start:
in a,(0) ;check linkport
and 3 ;upper bits are not important
cp 2 ;1 means red is high
jp z,youplayertwo ;if true other player wants to receive
ld a,0D1h ;ld set red wire high
out (0),a ;required syntax
youplayerone:
ld a,1 ;set you player one
ld (player),a ;save it
in a,(0) ;check linkport
and 3 ;upper bits are not important
cp 0 ;0 means both high, wait until player two has entered
jp z,intro ;if true other player wants to rec
ld a,0ffh ;resets the keypad.
out (1),a
ld a,KeyRow_Pad ;enables the arrow keys
out (1),a
ld a,KeyRow_Top ;enables the top keys
out (1),a
in a,(1) ;check keys
cp KMode ;quit if mode pressed
ret z
jp youplayerone
youplayertwo:
ld a,2 ;set you player two
ld (player),a ;save it
ld a,0D2h ;set white wire high, so playerone continues
out (0),a ;required syntax
delay:
in a,(0) ;check linkport
and 3 ;upper bits are not important
cp 1 ;1 means white high, this happens if playerone set both low
jp nz,delay ;check again
intro:
bcall(_cleargbuf) ;this will set both lines low and clear the graphbuffer
mainloop:
----your program----
call sendreceive ;call sendreceive routine
jp mainloop ;loop again
sendreceive:
ld a,(player)
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,(byte_to_send) ;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 (received_byte) ;save received byte
ret ;return to mainloop
receive_than_send:
call receivebyte ;call receive routine
ld a,e ;we actually receive e
ld (received_byte) ;save received byte
ld a,(byte_to_send) ;the byte you want to send
ld c,a ;we actually send c
call sendbyte ;call send routine
ret ;return to mainloop
;====================send routines from venus and synchronising by Merlijn=======================
sendbyte: ;input: white high, output: continue if red and white high
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 1 ;1 means white is high
ret z ;if true other player wants to send
ld a,0D2h ;ld set white wire high
out (0),a ;required syntax to send a to the linkport
sendbytewait:
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 0 ;0 means red and white are high
jp nz,sendbytewait ;not true check again
ld a,0 ;set timer to zero
wait2: ;create small delay so other can check port for double activety
inc a ;increase timer
cp 20 ;compare to 20
jp nz,wait2 ;not true increase more
;-----------end of synchronising-------------
di
ld b,8
vnSendByteLoop:
rr c ;c is the byte to send
vnSendBit0:
ld a,0D1h
jr nc,vnSendBit
vnSendBit1:
inc a
vnSendBit:
out (0),a
ld de,0
vnSendBitLoop1:
dec de
ld a,d
or e
ret z
in a,(0)
and 0Ch
jr nz,vnSendBitLoop1
ld a,0D0h
out (0),a
ld de,0
vnSendBitLoop2:
dec de
ld a,d
or e
ret z
in a,(0)
and 0Ch
cp 0Ch
jr nz,vnSendBitLoop2
djnz vnSendByteLoop
or a
ld a,0D0h ;ld set no wire high for next transmission
out (0),a ;required syntax
ret
;=========================End of send routine====================================================
;=========================receive routine from venus and synchronising by Merlijn================
receivebyte: ;input: red high, output: continue if red and white high
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 2 ;2 means red is high
ret z ;if true other player wants to receive
ld a,0D1h ;ld set red wire high
out (0),a ;required syntax
receivebyte2:
IN A,(0) ;check linkport
AND 3 ;upper bits are not important
CP 0 ;0 means red and white are high
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 40 ;compare to 40
jp nz,wait ;not true increase again
;-----------end of synchronising-------------
di
ld b,8
vnReceiveByteLoop:
in a,(0)
and 0Ch
ld d,8
cp d
vnReceiveBit1:
ld a,0D1h
jr nz,vnReceiveBit
vnReceiveBit0:
inc a
ld d,4
vnReceiveBit:
rr e ;e is the received byte
out (0),a
ld hl,0
vnReceiveBitLoop:
dec hl
ld a,h
or l
ret z
in a,(0)
and d
jr z,vnReceiveBitLoop
ld a,0D0h
out (0),a
ld d,16
vnBitReceivedLoop:
dec d
jr nz,vnBitReceivedLoop
djnz vnReceiveByteLoop
or a
ld a,0D0h ;ld set no wire high for next transmission
out (0),a ;required syntax
ret
;=======================End of receive routine===================================================
Test it and make great link games.