[A86] Re: A86: TI-0S Link Routines


[Prev][Next][Index][Thread]

[A86] Re: A86: TI-0S Link Routines




Thanks for the answers concering the OS link routines,
It seems the OS wants to make things difficult for us =)
I'll stick with the easier ztetris linkroutines.

I got the ztetris link routines working and optimized/generalized (doesnt use op1, saves hl, good timeout 
value) and added an example.

Here is the updated link routines (commented) if anyone wants them.
---------------------------------------------------------------
;LINK ROUTINES
; Originally by Pascal Bouron and Jimmy Mardell
; and  [Assembly Coder's Zenith] www.acz.org
; updated by Ricky Cobb arcadesdude@operamail.com
;linkget = ReceiveByte
;linksend = SendByte
;---------------------------------------------

;To see how to use this uncomment these two lines
;----------------
;#define EXAMPLE
;#include "ti86asm.inc"
;----------------
;and then compile it, it shows how to send a byte and recieve a byte
;over the link port and give each calc a unique id for futher linkplay

;run the example from inside of a shell (otherwise the ti-os silent link
;will send data and the recieving calc will mistake this for the byte sent)
;(or you can run them from the home screen at nearly the same time)

;linkget is for one way data
;linkgetwait is for two way data (server/client model)

;|--------------------|BEGIN EXAMPLE|---------------------------|

#ifdef EXAMPLE


.org _asm_exec_ram


 call _clrLCD
 call _flushallmenus
 call _homeup

recieveit:
 call linkget
; or a		;if a==0:no byte recived. (or a is done in routine)
 jr nz,showit ;otherwise show it
sendit:
 call _homeup
 ld hl,sendbytetxt
 call _puts
 call _homeup
 ld a,1  ;1 is the byte to send
 call linksend
showit:
 inc a ;if 0 then p1, if 1 then p2
 ld (player),a ;store it
 call _homeup
 ld hl,youareplayertxt
 call _puts
 ld a,(player)
 ld l,a
 xor a
 ld h,a
 ld bc,$1600
 call _dispAHL
 jp pause ;ends here
; ret 

cancelsend:
 call _clrLCD
 call _homeup
 ld hl,canceltxt
 call _puts
 jp pause ;ends here
; ret

pause:
 halt 
 halt
 call _get_key
 cp K_ENTER
 jr nz,pause
 ret

player:
.db 0

sendbytetxt:
 .text "Sending Byte"
canceltxt:
 .text "canceled"
youareplayertxt:
 .text "You are player"

#endif

;|--------------------|END EXAMPLE|---------------------------|

;This routine here is for sending the same info
;both ways to both calcs (the example above shows how to send data
;just one way). Define it if you want to use it.

#define uselinkgetwait  ;stays in routine until byte got

#ifdef uselinkgetwait
linkgetwait:
;this routine is called
; ld a,%00111111 ;checks keyport if exit is pressed
; out (1),a
; in a,(1)
; bit 6,a
 push hl
 call _get_key
 pop hl
 cp K_EXIT
 jp z,exitlinkgetwait
 call linkget
 jr z,linkgetwait
 ret
exitlinkgetwait:
 pop de ; pop linkgetwait call
 jp cancelsend
#endif


;------------------------------------------------------------------------------------
linkget: ;RECIEVES A BYTE
 push hl ;save hl
 ld hl,16383 ;timeout value you may change this if you want (you could also
             ;use the d register here for a smaller timeout)
 ld e,1 ;e is for the or'ing below
 ld c,0 ; byte that will be received
 ld b,8 ; 8 bits = 1 byte counter
 ld a,$C0 ;both wires active
 out (7),a ;send to port
checkresponse:
 call checktimeoutget   ;check timeout
 in a,(7) ;read from port
 and 3    ;mask off the rest of a reg
 cp 3     ;if its 3 then both wires are still active
		  ;(meaning no response from other calc yet)
 jr z,checkresponse ;if not 3 then other calc says 'ready'
othercalcready:
 cp 2     ;if the send routine on other calc says bit 1 of a (a=2 now)
		  ;is sent then it is a zero that will be sent
		  ;(white is active, red is not, so go turn red wire on)
 jr z,getlinkzero ;if so go get the zero
 ld a,c
 or e    ;this makes the bit of the current bit ((8-bitcounter)+1)
		 ;and turns on that bit and
 ld c,a  ;stores it back to a
 ld a,$D4 ;turn on white wire
 out (7),a ;send to linkport
 jr sendgotbit
getlinkzero:
 ld a,$E8 ;red wire on  (red = 0, white = 1)
 out (7),a ;send to port
sendgotbit:
 call checktimeoutget
 in a,(7) ;check to see if both wires not active 
;(sending calc said i got your response that you got that bit)
 and 3
 jr z,sendgotbit
 ld a,$C0 ;both wires on
 out (7),a
 rl e ;next bit to do
 djnz checkresponse
 ld a,c ;byte recived.
 or a   ;do the comparision
 pop hl ;get saved hl
 ret    ;return back with recieved byte
checktimeoutget:
 dec hl ;hl-1 ->hl
 ld a,l ;if hl=0
 or h   ;
 ret nz ;return if hl!=0 (it starts at 16383)
 pop hl ;get saved hl
 pop de ;trash last stack address so youll 
;return to the lable that called linkget
 xor a ;say no byte reciecved
 ret   ;return back (timeout occured)
;------------------------------------------------------------------------------------
linksend: ;SENDS A BYTE
 ld b,8 ;bit counter
 ld c,a ;byte to send
 ld a,$C0 ;both wires active
 out (7),a ;send to port
checkreceivecalc:
 call checksendcanceled
 in a,(7) ;read from port
 and 3    ;mask off all but the first two (bit 0,and 1) of a
 cp 3     ;if 3 then other calc has both wires active 
;(other calc is ready)
 jr nz,checkreceivecalc ;other calc is ready if both wires active
;reloop untill other calc is ready or you press exit
othercalcready2:
 ld a,c ;byte to send into a
 and 1  ;only the first bit of it counts (its checked like this):
        ;a reg =                  % 0 0 0 0  0 0 0 0
        ;bit number                 7 6 5 4  3 2 1 0
        ;and'ing by 1 gets rid of all but  --------^----- that bit there
 jr z,linksendone ;if so send bit == 1
linksendzero:
 ld a,$E8 ;red wire on
 out (7),A ;send to port
 jr checkifbitgot
linksendone:
 ld a,$D4 ;white wire on (on and active are same thing)
 out (7),A ;send it to linkport
checkifbitgot:
 call checksendcanceled
 in a,(7) ;read from port
 and 3 ; if its anything other than 3 that means
;other calc (recieveing end) got the bit
 jr nz,checkifbitgot ;reloop until bit got
 ld a,$C0   ;both wires active
 out (7),A  ;send to port
 srl c      ;next bit of c to be checked (shifts it all one to right)
 djnz checkreceivecalc
 xor a ;a=0 byte=sent
 ret        ;go back to where linksend was called
checksendcanceled:
; ld a,%00111111 ;checks keyport if exit is pressed
; out (1),a
; in a,(1)
; bit 6,a
 push hl
 call _get_key
 pop hl
 cp K_EXIT
 ret nz
 pop de ;trash checksendcanceled call
 pop de ;trash linksend call
 jp cancelsend  ;do this in your code -> cancelsend = somelableyouwanttojumptoifcanceled
                ;or change jp cancelsend to ret if you want the program to quit



---------------------------------------------------------------



Ricky Cobb
http://tiparadise.any.za.net/
arcadesdude@operamail.com
[IM]
icq 41440378
msn arcadesdude
y!  arcadesdude
aim arcadesdude