Author Topic: Establish Link Connection  (Read 5169 times)

0 Members and 1 Guest are viewing this topic.

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Establish Link Connection
« on: March 08, 2011, 06:34:57 pm »
Can someone give me some Axe code that causes a calculator to check for another calculator, if it finds one, it jumps to one label, if it doesn't it jumps to another. This must work even if the two calcs run the same code at the same time, because, in the final product, they will. You can then assign master/slave, but this is not a necessity.

Thanks.
« Last Edit: March 08, 2011, 07:46:03 pm by ACagliano »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Establish Link Connection
« Reply #1 on: March 09, 2011, 01:19:59 am »
There is a small problem I need to clarify.  You are saying these programs are run at the same time?  Are they run at *precisely* the same time, or not?  I am assuming that they are being run from the homescreen, and so there will always be a small difference in time right?  One program is inevitably going to start running first, and the only way it can know if there is another calculator connected is to wait for it to send something.  There needs to be some way to get out of the loop though, or else it would keep waiting forever if there was no calculator connected.  So i propose a different solution:

Would it work to have a screen saying "connecting... press clear to abort" or something like that?  It would wait for the other person to connect, and when the connection is established, it would run the game or whatever, or if the connection is aborted, quit.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Establish Link Connection
« Reply #2 on: March 09, 2011, 07:42:01 am »
I can't give you a routine, but I can give you a way for the calculators to actually see each other.  First of all, pause for a random amount of time (Optional, because as builderboy said, it's highly unlikely they'll be run at the exact same second).  Then, check line A of the link port. (Line A and B is just how I'll reference them) if it is set (the other program set it in this case) then just set line B, and then just wait until the first calc resets line A (at which point, reset line B and whoever had calc A is the main calc).  If line A is not set when you check it, set it.  Wait until the other calc sets B, or abort if it doesn't after a certain amount of time.

Now for actual communication, I would suggest using one line as sort of a clock.  When line A toggles, you check line B for the actual data.  Also, note, that what you read and what you write are essentially inverses of each other.  And when I say set, I mean that the line is pulled low.  Reset meaning the normal state.  Always write a value of 0 to the port before leaving.

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: Establish Link Connection
« Reply #3 on: March 09, 2011, 10:22:13 am »
There is a small problem I need to clarify.  You are saying these programs are run at the same time?  Are they run at *precisely* the same time, or not?  I am assuming that they are being run from the homescreen, and so there will always be a small difference in time right?  One program is inevitably going to start running first, and the only way it can know if there is another calculator connected is to wait for it to send something.  There needs to be some way to get out of the loop though, or else it would keep waiting forever if there was no calculator connected.  So i propose a different solution:

Would it work to have a screen saying "connecting... press clear to abort" or something like that?  It would wait for the other person to connect, and when the connection is established, it would run the game or whatever, or if the connection is aborted, quit.

What you suggest is perfect. However, I'm having issues with my method. The routine just exits, without doing anything,

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Establish Link Connection
« Reply #4 on: March 09, 2011, 11:23:07 am »
I can't give you a routine, but I can give you a way for the calculators to actually see each other.  First of all, pause for a random amount of time (Optional, because as builderboy said, it's highly unlikely they'll be run at the exact same second).  Then, check line A of the link port. (Line A and B is just how I'll reference them) if it is set (the other program set it in this case) then just set line B, and then just wait until the first calc resets line A (at which point, reset line B and whoever had calc A is the main calc).  If line A is not set when you check it, set it.  Wait until the other calc sets B, or abort if it doesn't after a certain amount of time.

Now for actual communication, I would suggest using one line as sort of a clock.  When line A toggles, you check line B for the actual data.  Also, note, that what you read and what you write are essentially inverses of each other.  And when I say set, I mean that the line is pulled low.  Reset meaning the normal state.  Always write a value of 0 to the port before leaving.

Axe has get and send commands ;) I think this can be made a lot easier:

Code: [Select]
Send(1,200)
While 1
Get->A
EndIf A!=-1 Or getKey(15)
Send(2,200)
If A!=-1
Goto 2PL
End
Goto 1PL

This code will wait for either the other calculator to connect, or for you to press clear.  If the other calculator connects, it will jump to Label 2PL, otherwise, it will jump to label 1PL.  It has the added advantage of giving the first calculator to connect a 1 in A, and the second calculator to connect a 2 in A, so you can distinguish between player 1 and player 2 :)

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: Establish Link Connection
« Reply #5 on: March 09, 2011, 12:06:14 pm »
Thank you. Are you sure this works?

Also, How would you construct a send/receive routine that exchanges a minimum of five bytes with another calc every time it runs, but makes sure that all data is successfully transferred? I have some ideas on this, but they all seem to fall apart when I think about the fact that the other calc may not actually receive the data.
« Last Edit: March 09, 2011, 03:05:22 pm by ACagliano »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Establish Link Connection
« Reply #6 on: March 09, 2011, 05:41:25 pm »
I am not 100% sure it will work, but you can try it for yourself if you have more than one calc.  I don't have a working link cable so I can't test it D: It's worked in the past tho.  As for the transferring of bytes, there are ways, but it all depends, and I'm unsure of how to do it.  My best advice would just be to experiment, there really isn't just a single way

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: Establish Link Connection
« Reply #7 on: March 09, 2011, 06:25:41 pm »
Is there an Axiom out there for CalcNET yet? That would be muy perfecto.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Establish Link Connection
« Reply #8 on: March 09, 2011, 06:28:30 pm »
I don't think so, but you could talk to Kerm about how to implement it yourself :D On that note, I might try to put together a tutorial on linking if I can figure it out myself...

Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: Establish Link Connection
« Reply #9 on: March 09, 2011, 06:29:08 pm »
I don't think so, but you could talk to Kerm about how to implement it yourself :D On that note, I might try to put together a tutorial on linking if I can figure it out myself...

Kerm told me to nag you guys about it.  :)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Establish Link Connection
« Reply #10 on: March 09, 2011, 06:30:12 pm »
Lol well in that case I better get working on that tutorial

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Establish Link Connection
« Reply #11 on: March 09, 2011, 07:41:46 pm »
This problem is really simple. I can't remember the exact code off the top of my head, but it goes something like this:

Code: [Select]
0->C
Disp "WAITING...",i,"PRESS ANY KEY",i,"TO CANCEL",i
Repeat C
 Get->A
 Send(100,1000
 !If A-100
  2->C
 End
 If getKey
  1->C
 End
End
!If C-1
Goto <FailLabel>
End
Disp "SUCCESS!"
Goto <PassLabel>

Similar code is in Eitrix, if you want to see it in action.
« Last Edit: March 09, 2011, 07:42:25 pm by Compynerd255 »
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com



Offline ACagliano

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 919
  • Rating: +32/-2
    • View Profile
    • ClrHome Productions
Re: Establish Link Connection
« Reply #12 on: March 10, 2011, 06:54:49 pm »
When using inline calls in Axe (calcnet), do you still need to switch the high and low bytes?

Offline Compynerd255

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 336
  • Rating: +53/-4
  • Betafreak Games
    • View Profile
    • Betafreak Games
Re: Establish Link Connection
« Reply #13 on: March 10, 2011, 11:55:28 pm »
Yes, since its hex code. It's compiled directly to Z80 instructions. Unless, of course, you don't need to flip the addresses to begin with.
The Slime: On Hold, preparing to add dynamic tiles

Axe Eitrix: DONE

Betafreak Games: Fun filled games for XBox and PC. Check it out at http://www.betafreak.com