Author Topic: CPChessNet [developing]  (Read 12605 times)

0 Members and 1 Guest are viewing this topic.

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
CPChessNet [developing]
« on: 01:36, 03 March 18 »

Here it is!!

CPChessNET 1.6b

http://www.cpcwiki.eu/forum/programming/cpchessnet-(developing)/?action=dlattach;attach=25021

[old]
Hi

I have been working on a Chess program for the CPC.

The idea is to use the M4 to connect 2 cpc via tcp/ip and the people can play chess all over the world!

At this point I can start to code the Net part of the program, the problem is that i have no idea.

The game doesn't use firmware, doesn't use ints, only pure (sloppy) asm :)

@Duke can you help me with the m4 and the process to access the hardware to make a connection between 2 cpcs?

I never coded any client/server tcp/ip program, i suspect that with the M4 is easy... how can i start?

thankyou!

1 pic of the program:

« Last Edit: 21:16, 26 March 18 by Joseman »

Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #1 on: 09:13, 03 March 18 »
Good idea :)

@Duke can you help me with the m4 and the process to access the hardware to make a connection between 2 cpcs?

I never coded any client/server tcp/ip program, i suspect that with the M4 is easy... how can i start?

Start by playing with the samples I made at:
https://github.com/M4Duke/M4examples

There's "tcp.s" which is a tcp/ip client. Run this on one CPC.
On another CPC run "tcpserv.s" which is a tcp/ip server.

This is the basics you need to transfer moves from one CPC to another. And probably the simplest method.
In your chess game, you would have to select if you want to be "host" (server) or join a server (be client).

You can also use the PC server (main.c) for some tests to understanding how it works. Advantage with that is you can install the awesome Wireshark program and monitor all packets closely.

Anyway have a look and I will be glad to help if there's anything.

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #2 on: 15:41, 03 March 18 »
hi @Duke

Thanks for the help!

seems very easy to make it, i'm trying it

one question,  when you read the buffer of the m4, how can you know the end of the buffer on every command?

thanks!!
« Last Edit: 17:20, 03 March 18 by Joseman »

Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #3 on: 19:13, 03 March 18 »
one question,  when you read the buffer of the m4, how can you know the end of the buffer on every command?

(socket*16)+2    received: (2 bytes)    - data received in internal buffer (ready to get with C_NETRECV)

Once there is nothing in the incoming buffer (00 00)

Online Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 16.911
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 4029
  • Likes Given: 7251
Re: CPChessNet [developing]
« Reply #4 on: 20:01, 03 March 18 »
You're doing a chess game? Respect.

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #5 on: 02:15, 04 March 18 »
You're doing a chess game? Respect.

Well... i'm doing (trying to do) a NETchess, no computer AI, "only" piece moves, a little chat and move the board information between the 2 cpc's :D

 

Offline GUNHED

  • 6128 Plus
  • ******
  • Posts: 2.693
  • Country: de
  • Reincarnation of TFM
    • FutureOS - The quickest OS for the CPC and Plus
  • Liked: 1266
  • Likes Given: 2961
Re: CPChessNet [developing]
« Reply #6 on: 13:55, 04 March 18 »
Oh, interesting project! I'm not really updated what exactly is possible with the M4 and SymbOS. But maybe it's the best idea just to use all the Wifi-/Net-stuff from SymbOS instead of doing every thing new? - IIRC SymbOS 3 provides quite so great routines for Wifi-Connection.  :)


Yes, of course it's fun to code something by oneself!  :) :) :)
http://futureos.de --> Get the revolutionary FutureOS (Update: 2021.01.24)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.07.15)

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #7 on: 15:16, 04 March 18 »
Oh, interesting project! I'm not really updated what exactly is possible with the M4 and SymbOS. But maybe it's the best idea just to use all the Wifi-/Net-stuff from SymbOS instead of doing every thing new? - IIRC SymbOS 3 provides quite so great routines for Wifi-Connection.  :)


Yes, of course it's fun to code something by oneself!  :) :) :)

Yes, i've been waiting ages for the IDE program enviroment for symbos, years later, i've decided to code on plain asm :)

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #8 on: 15:18, 04 March 18 »
@Duke

C_NETBIND is giving me ramdom #FC code error (in my program), your program seems to connect right

sometimes it works some time not...

what can i be doing wrong?

thanks!

Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #9 on: 17:15, 04 March 18 »
@Duke

C_NETBIND is giving me ramdom #FC code error (in my program), your program seems to connect right

sometimes it works some time not...

what can i be doing wrong?

The error codes are:
-1      Out of memory error.   
-2      Buffer error.           
-3      Timeout                 
-4      Routing problem.       
-5      Operation in progress   
-6      Illegal value.         
-7      Operation would block. 
-8      Address in use.         
-9      Already connected.     
-10     Connection aborted.     
-11     Connection reset.       
-12     Connection closed.     
-13     Not connected.         
-14     Illegal argument.       

So you get -4, routing problem!

Don't know what you do wrong, without seeing the code.

Remember to always close a socket, even if you have an error or you will have to power off/on M4 to free it, maybe that's it ?

Offline GUNHED

  • 6128 Plus
  • ******
  • Posts: 2.693
  • Country: de
  • Reincarnation of TFM
    • FutureOS - The quickest OS for the CPC and Plus
  • Liked: 1266
  • Likes Given: 2961
Re: CPChessNet [developing]
« Reply #10 on: 19:54, 04 March 18 »
Also Shining did some work with the WiFi for his great defence game, which can save highscores in the network IIRC. Maybe he can give some hints. Anyway good luck with the project.  :)
http://futureos.de --> Get the revolutionary FutureOS (Update: 2021.01.24)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.07.15)

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #11 on: 23:22, 04 March 18 »
@Duke

finally i did it!

i have 2 cpc connected (or so they say  ;D )

The thing is... they don't connect always

the cpc server seems to display my connected msg every now and then... but the cpc client always display my connected msg (even if the cpc server don't display it!)

i suspect that the cpc server get stuck on :

cp    4    ; incoming connection in progress?
jp z,wait_client

i say "suspect" because is a PAIN to code totally blind when you have to debug the m4 code  :laugh:

what do you think is the problem?

when i have to close socket?

thankyou!
 


Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #12 on: 00:03, 05 March 18 »
@Duke

finally i did it!

i have 2 cpc connected (or so they say  ;D )
Cool  8)
Quote
The thing is... they don't connect always
Is it the same when using my examples (tcp client & tcp server)?

Quote
the cpc server seems to display my connected msg every now and then... but the cpc client always display my connected msg (even if the cpc server don't display it!)

i suspect that the cpc server get stuck on :

cp    4    ; incoming connection in progress?
jp z,wait_client

i say "suspect" because is a PAIN to code totally blind when you have to debug the m4 code  :laugh:
At this point, it may be a good idea to use the pc tcp server example for testing, it's easy throw in debug output there to make sure everything is going is it should from the client side.
Quote
what do you think is the problem?
No idea with the current information, sorry :)
Quote
when i have to close socket?
When you are done using a socket and the connection is no longer needed or an error occurred and you want to create a new socket.
There is only 4 sockets, so if you run the same test on cpc without closing the sockets (or power cycle) you will run out.


Btw. to compile the PC tcp server on windows, just install MinGW and copy main.c + makefile into a dir and type make
« Last Edit: 00:09, 05 March 18 by Duke »

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #13 on: 02:50, 05 March 18 »
OMG i made it!!!

it was blood, sweat, and tears programming the M4 almost blindly!!

But i made it, client/server and the first transmisions (their nicks!).

is the first time that i start to believe that cpchessnet can be made!

pic:







Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #14 on: 22:52, 05 March 18 »
Hi @Duke

One question, i have a little chat on the game, if i send a msg from the client to the server, but the server is checking the game parts, the client will wait forever for the server to receive the msg...

how can i tell the M4 to send the msg, and just continue with his things on the client side?

i suspect that this part of the code is the key:

Code: [Select]
wait_send:    ld    a,(ix)
            cp    2            ; send in progress?
            jr    z,wait_send    ; Could do other stuff here!
            cp    0
            call    nz,error_envio   

i don't want to "wait_send" just put the message out and continue...

maybe i need to do a variable called "message_pending" and if message_pending=1 then retry the send ony 1 time? make my things, retry another time...if message send then  "message_pending=0"

i'm learning for the first time client/server programming and i'm a little lost!

thankyou!!






Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #15 on: 07:55, 06 March 18 »


i suspect that this part of the code is the key:

Code: [Select]
wait_send:    ld    a,(ix)
            cp    2            ; send in progress?
            jr    z,wait_send    ; Could do other stuff here!
            cp    0
            call    nz,error_envio   

i don't want to "wait_send" just put the message out and continue...

You don't need to wait around for the message being sent, but you must just make sure it is sent before sending the next message.

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #16 on: 14:18, 06 March 18 »
Hi again @Duke

I think that some questions are more related to client/server aplications, hope this thread can be useful for another people  :laugh:

For example:

When you stablish a socket, do this socket need to be "renewed" some times? or keep alive? or when you stablish the socket, it remains forever stablished?

and this commands: cmdbind, cmdlisten, cmdaccept. they are sent to the M4 only one time? (stablish socket part).

I mean, first stablish socket, ok then later in the code, after do "chess things", at the end of the loop, only need to do wait_client and wait_recv, or only wait_recv. Or i have to do again cmdbind, cmdlisten and cmdaccept?.

Sorry for so many questions, it think i'm near to understand all, but is just that now it doesn't work correctly

Thankyou!

Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #17 on: 17:30, 06 March 18 »

You do not need to renew a socket, unless there is a disconnection. In that case you will need to close the socket and create it again.
On server side you *can* get away with keeping the socket and wait for a new incoming connection, but it may be safer to close the socket and re-do it all.

In your chess loop, you do not need to wait for anything unless you see something in the buffer.  Anyting in buffer ? if yes, wait recv, if no continue game loop.


Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #18 on: 21:46, 06 March 18 »
Hi again again @Duke

I think i have sorted the problem...

when i can interchange nicks, before it the socket is  in status 4 (wait incoming)

but, when i enter the game, and try to receive a chat message from the client, the socket is status 0 (inactive)

how can i put the socket in wait incoming?

Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #19 on: 23:00, 06 March 18 »
when i can interchange nicks, before it the socket is  in status 4 (wait incoming)

but, when i enter the game, and try to receive a chat message from the client, the socket is status 0 (inactive)

how can i put the socket in wait incoming?
"wait incoming" is for establishing a connection to the host, after connection established you will only need to check if there is something for you:
(socket*16)+2    received: (2 bytes)    - data received in internal buffer (ready to get with C_NETRECV)
Check this in the socket status, if there is anything, use C_NETRECV.


Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #20 on: 04:22, 07 March 18 »
I don't even bother to say how many hours took me to do this... finally there is a real chat client -> server working on cpchessnet!




Offline robcfg

  • Supporter
  • 6128 Plus
  • *
  • Posts: 2.412
  • Country: se
  • 8-Bit Technomancer
    • index.php?action=treasury
  • Liked: 1093
  • Likes Given: 2673
Re: CPChessNet [developing]
« Reply #21 on: 11:44, 07 March 18 »
Awesome!  8)


When will be able to play it?

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #22 on: 14:51, 07 March 18 »
Awesome!  8)


When will be able to play it?

Well, the net part took me days... the chess part was stalled, only 3 pieces knows their moves  :laugh:

next i will try to send the board to the client (after white move) and repaint the board on the client...

Offline Joseman

  • 6128 Plus
  • ******
  • Posts: 801
  • Country: es
  • Liked: 672
  • Likes Given: 474
Re: CPChessNet [developing]
« Reply #23 on: 17:50, 07 March 18 »
Hi (again) @Duke

Right know i have a chat between the 2 cpc's

what i do is:

key t --> open chat ---> enter message --> send message to the other cpc --> update the chat_buffer on local  with local message -->repaint chat

on the other side: wait for a message --> yes? ---> move message to chat_buffer on local --> repaint chat

The thing is... what about if the other side don't receive the message (by a net error) but i update my local chat?

on a local net, there isn't virtually errors, and the chat works very well... but on Inet.. what do you think?

do i have to make sure the other side received the message? before update the local chat?

and if the other side didn't receive the message just send it again?




Offline Duke

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.250
  • Country: dk
    • spinpoint.org
  • Liked: 1464
  • Likes Given: 1182
Re: CPChessNet [developing]
« Reply #24 on: 17:57, 07 March 18 »
@Joseman
If the other end did not receive the message (even if send was succesful). You could add your own handshake.

Ie one side send a message "hello other guy", now make a counter a long with the message ie. 01,00,"hello other guy".
In the other end if it receives the message, it would reply 01,00,"OK" or something, so you check for confirmation on the side that is sending, that it's actually received.
Have a timeout and if it doesn't get a response, re-send the message.

Of course always check for disconnection on the status and go through the entire re-connection process if so.