Re: A85: TI85 Link in games
[Prev][Index][Thread]
Re: A85: TI85 Link in games
>I've played around with the linkrout.h and ZTetris source code, but >still
>I can't seem to figure it out - when I send a byte, does >it "wait" untill
>the other calc checks the linkport? Or does the >receiving calc have to be
>ready to recieve the byte(s) before they >are sent?!?
I modified linkrout.h for use in my program, Checkers 8X (has anyone ever
actually used it?). I've pasted my modified copy into this email. Be warned,
I'm writing the code below from memory only, and it hasn't been tested. It
also isn't optimized because I'm using dummy variables so you can work in
the most general case. but Ideally, the sbyte, rbyte, and hrflag variables
would be pointless.
First define a few variables:
hrflag = TEXT_MEM ;0 = try to receive for a bit, 1 = wait until
;reception
lcounter = TEXT_MEM+1 ;counter for delay when hrflag = 0
sbyte1 = TEXT_MEM+2 ;dummy variable to put in first byte to send
sbyte2 = TEXT_MEM+3 ;second byte to send
rbyte1 = TEXT_MEM+4 ;1st byte received
rbyte2 = TEXT_MEM+5 ;2nd byte received
dominant = TEXT_MEM+6 ;tells which calculator is dominant (goes
;first)
Start your program by defining the dominant calculator (which sends a byte
first)
ProgramStart:
xor a ;A = 0
ld (hrflag),a ;load that to hrflag, so only a slight delay
call &ReceiveByte ;Try to receive byte
or a ;Does A = 0?
jr nz,NoWait ;If byte gotten, then other calc was waiting
ld a,1 ;A = 1
call &SendByte ;Send 1 over the link, and wait for response
xor a ;Response gotten, now make your number different
NoWait:
ld (dominant),a ;Load what other calculator sent into A
inc a
ld (hrflag),a ;load anything but zero, so you'll now wait for
;receptions
... rest of program code follows
Later in the file when you need to send bytes...
Load the 2 bytes you wish to send into sbyte1 and sbyte2
Then when you want to exchange 2 bytes, do this:
Exchange2BytesBetweenTwoCalculators:
ld a,(dominant) ;Check if you were the first calculator to wait
or a ;Is A = 0?
jr nz,ReceiveFirst ;If not, then you receive first
call &SendTwoBytes ;Send sbyte1 and sbyte2
ReceiveTwoBytes:
call &ReceiveByte ;Wait to receive something
ld (rbyte1),a ;other calc's sbyte1 into rbyte1
call &ReceiveByte ;Wait again
ld (rbyte2),a ;load other calc's sbyte2 into rbyte2
ret
ReceiveFirst:
call &ReceiveTwoBytes ;Receive sbyte1 and sbyte2 of other calc
SendTwoBytes:
ld a,(sbyte1) ;A = 1st byte to send
call &SendByte ;Send it and wait until other calculator receives
ld a,(sbyte2) ;A = 2nd byte to send
jp &SendByte ;Send it and wait until other calculator receives
This inputs sbyte1 and sbyte2, and outputs rbyte1 and rbyte2. If you really
want two calculators to "shake hands", then you'll have to load the rbyte
values into the corresponding sbyte.
Switch2Bytes:
call &Exchange2BytesBetweenTwoCalculators ;send the bytes
ld a,(rbyte1)
ld (sbyte1),a
ld a,(rbyte2)
ld (sbyte2),a ; make the switches
ret
It should work, but no promises.
Hope this helps,
Sam
LINKROUT.H
;
; SOME VERY NICE LINK ROUTINES MADE BY PASCAL BOURON
;
; I've made some modifications so it fits ZTetris
; SAM made changes for Checkers
ReceiveByte:
ld hl,0
ld (lcounter),hl
ld e,1 ; for the OR
ld c,0 ; byte receive
ld b,8 ; counter
ld a,$C0
out (7),a
rb_w_Start:
in a,(7)
and 3
cp 3
jr nz,rb_get_bit
call &Test_ON
jr rb_w_Start
rb_get_bit:
cp 2
jr z,rb_receive_zero
ld a,c
or e
ld c,a
ld a,$D4
out (7),a
jr rb_waitStop
rb_receive_zero:
ld a,$E8
out (7),a
rb_waitStop:
call &Test_ON
in a,(7)
and 3
jr z,rb_waitStop
ld a,$c0
out (7),a
rl e
djnz rb_w_Start
ld a,c
ret
SendByte:
ld hl,0
ld (lcounter),hl
ld b,8
ld c,a ;byte to send
ld a,$C0
out (7),a
w_setport3:
in a,(7)
and 3
cp 3
jr z,calc_bit
call &SendTest_ON
jr w_setport3
calc_bit:
ld a,c
and 1
jr z,send_one
send_zero:
ld a,$E8
out (7),A
jr wait_setport
send_one:
ld a,$D4
out (7),A
wait_setport:
call &SendTest_ON
in a,(7)
and 3
jr nz,wait_setport
ld a,$C0
out (7),A
srl c
djnz w_setport3
xor a
ret
Test_ON:
ld a,(hrflag)
or a
jr z,ShortWait
SendTest_ON:
call GET_KEY
cp K_EXIT
ret nz
pop hl
pop hl
ret
ShortWait:
ld a,(lcounter)
inc a
ld (lcounter),a
cp 255
ret nz
pop hl ;Back to the place you were before. Gotta love it!
xor a
ret
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com