CPCWiki forum

General Category => Programming => Topic started by: Joseman on 00:36, 03 March 18

Title: CPChessNet [developing]
Post by: Joseman on 00: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 (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624) 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:

(http://i68.tinypic.com/nb1wg4.jpg)
Title: Re: CPChessNet [developing]
Post by: Duke on 08:13, 03 March 18
Good idea :)

Quote from: Joseman on 00:36, 03 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624) 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.
Title: Re: CPChessNet [developing]
Post by: Joseman on 14:41, 03 March 18
hi @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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!!
Title: Re: CPChessNet [developing]
Post by: Duke on 18:13, 03 March 18
Quote from: Joseman on 14:41, 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)
Title: Re: CPChessNet [developing]
Post by: Gryzor on 19:01, 03 March 18
You're doing a chess game? Respect.
Title: Re: CPChessNet [developing]
Post by: Joseman on 01:15, 04 March 18
Quote from: Gryzor on 19:01, 03 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

Title: Re: CPChessNet [developing]
Post by: GUNHED on 12: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!  :) :) :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 14:16, 04 March 18
Quote from: GUNHED on 12: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!  :) :) :)

Yes, i've been waiting ages for the IDE program enviroment for symbos, years later, i've decided to code on plain asm :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 14:18, 04 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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!
Title: Re: CPChessNet [developing]
Post by: Duke on 16:15, 04 March 18
Quote from: Joseman on 14:18, 04 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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 ?
Title: Re: CPChessNet [developing]
Post by: GUNHED on 18: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.  :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 22:22, 04 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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!
 

Title: Re: CPChessNet [developing]
Post by: Duke on 23:03, 04 March 18
Quote from: Joseman on 22:22, 04 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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
Title: Re: CPChessNet [developing]
Post by: Joseman on 01: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:

(http://i64.tinypic.com/2ypi1le.jpg)




Title: Re: CPChessNet [developing]
Post by: Joseman on 21:52, 05 March 18
Hi @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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:


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!!





Title: Re: CPChessNet [developing]
Post by: Duke on 06:55, 06 March 18
Quote from: Joseman on 21:52, 05 March 18


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


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.
Title: Re: CPChessNet [developing]
Post by: Joseman on 13:18, 06 March 18
Hi again @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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!
Title: Re: CPChessNet [developing]
Post by: Duke on 16: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.

Title: Re: CPChessNet [developing]
Post by: Joseman on 20:46, 06 March 18
Hi again again @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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?
Title: Re: CPChessNet [developing]
Post by: Duke on 22:00, 06 March 18
Quote from: Joseman on 20:46, 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.

Title: Re: CPChessNet [developing]
Post by: Joseman on 03: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!


(http://i64.tinypic.com/21oxx90.jpg)
Title: Re: CPChessNet [developing]
Post by: robcfg on 10:44, 07 March 18
Awesome!  8)


When will be able to play it?
Title: Re: CPChessNet [developing]
Post by: Joseman on 13:51, 07 March 18
Quote from: robcfg on 10:44, 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...
Title: Re: CPChessNet [developing]
Post by: Joseman on 16:50, 07 March 18
Hi (again) @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

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?



Title: Re: CPChessNet [developing]
Post by: Duke on 16:57, 07 March 18
@Joseman (http://www.cpcwiki.eu/forum/index.php?action=profile;u=135)
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.
Title: Re: CPChessNet [developing]
Post by: Joseman on 17:15, 07 March 18
Quote from: Duke on 16:57, 07 March 18
Of course always check for disconnection on the status and go through the entire re-connection process if so.

can be disconnections even if the other side didn't send the command disconnect?
Title: Re: CPChessNet [developing]
Post by: Duke on 17:57, 07 March 18
Quote from: Joseman on 17:15, 07 March 18
can be disconnections even if the other side didn't send the command disconnect?
Errors can occur that will lead to a disconnection, check the error codes I pasted earlier.
Title: Re: CPChessNet [developing]
Post by: GUNHED on 22:51, 07 March 18
Congratulations!!! So this means that one only need two CPC's and a WiFi-device and they can talk. Or is it two CPC connected by two Wifi-devides via the internet. Sorry for asking, but I'm not into PC stuff that much. Ok, now it's CPC stuff too.  :) :) :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 11:59, 08 March 18
Quote from: GUNHED on 22:51, 07 March 18
Congratulations!!! So this means that one only need two CPC's and a WiFi-device and they can talk. Or is it two CPC connected by two Wifi-devides via the internet. Sorry for asking, but I'm not into PC stuff that much. Ok, now it's CPC stuff too.  :) :) :)

2 cpc + 2 m4 (and a router of course), it can be in local lan on your house or internet around the world (untested XD)
Title: Re: CPChessNet [developing]
Post by: Joseman on 14:56, 08 March 18
ok

today i achieve board send between the 2 cpc's and turn change

right know the 2 cpc's knows the white moves and what is the turn (white move or black move)

i'm afraid that i'm not programming any check on connection errors, in lan works well, on internet... well we will see...

now i'll return to do the piece moves and when all white and black moves are done, the first beta will be released

i need to program the "board reversal" too, who plays with black will play with black on the bottom, who plays with white will play with white on the bottom too, but i think that only repaiting in accordance whith this is enough, the move code is the same after all... isn't it?


Title: Re: CPChessNet [developing]
Post by: blackdalek on 13:16, 09 March 18
I haven't played chess in years, but I am wiling to give this game a try when it is finished. 8)
Add me to your list of potential players.  :P

I'd also be interested if someone coded a CPC Scrabble game over WIFI too.
Title: Re: CPChessNet [developing]
Post by: Joseman on 21:34, 10 March 18
Hi

At this point all the piece moves are done...

The castling too (minus the possible check)

next is the check, checkmate and En Passant.

If i don't forget anything, the game will be done when this things are completed.


(http://i67.tinypic.com/dw9k01.jpg)

Title: Re: CPChessNet [developing]
Post by: Joseman on 03:41, 13 March 18
Hi!

ok, the check ('jaque' in spanish) is 100% done, the 2 kings always knows  if they are in check by any piece in any place of the board.

this will allow me to complete the castling (they cant do castling if any walk of the king to make the castling is in check)

at this point  playing a chess  game is totally possible (only lacking checkmate (you can't do anything if checkmate but the game doesn't stops), em pasant and promotion)

Soon the first beta (i think)

(http://i66.tinypic.com/v6mzoj.jpg)
Title: Re: CPChessNet [developing]
Post by: Takis Kalatzis on 10:50, 13 March 18
Great work Joseman!


Couple of questions : Will you need a memory expansion in order to use your online chess and chat or only the M4 board? Also, will there be an English UI for us who are not familiar with Spanish?


Best regards,


Takis
Title: Re: CPChessNet [developing]
Post by: Joseman on 10:56, 13 March 18
Quote from: Takis Kalatzis on 10:50, 13 March 18
Great work Joseman!


Couple of questions : Will you need a memory expansion in order to use your online chess and chat or only the M4 board? Also, will there be an English UI for us who are not familiar with Spanish?


Best regards,


Takis

The game has to work on a plain 464 (even from cassette), i only tested in a 6128.

Yes, i started to put the messages in spanish because the first idea of the program was to play with a good friend of mine from here. But it will had english text too. anyway chess itself and 2 more keys doesn't need any language  :) .
Title: Re: CPChessNet [developing]
Post by: Joseman on 03:14, 14 March 18
Hi

OMG the 'en passant' move was a hell to code, i didn't expect that!

https://en.wikipedia.org/wiki/En_passant (https://en.wikipedia.org/wiki/En_passant)

you can only use the en passant move if the enemy pawn makes a double-step (to avoid your pawn) and you ONLY can do the move in the next turn!, if you don't see it, the next time you cant make the 'en passant' move!, AND if the enemy pawn didn't do double-step (he reach with a 1+1 move) you need to control that your pawn don't make the 'en passant' move!!!!!

with the complexity of the move  i have no other choice that make 2 tables for the status of the pawns and send 1 table to the other cpc via net with the enemy pawns that are 'en passant' in the next turn, if we don't do the 'en passant' move (or is not possible) the 2 tables are reinitiated and so on...

the problem once i made the initial code, was to debug it, we have two possible bugs, on the move code itself (and trust me there were bugs) AND the possible bugs on the LAN code (and trust me there were bugs), the problem with the lan/m4 code is that you have to do all BLIND. i only have 2 functions to test the LAN code, one changes the border, and the other display the last stack entry (handy to display what values has a variable, a register... simply do 'push de : call check_stack' or ld a,(de) :push af: call check_stack'... as you can see hell in earth!!  :laugh:
Title: Re: CPChessNet [developing]
Post by: Joseman on 03:15, 14 March 18
(see previous post)
Title: Re: CPChessNet [developing]
Post by: Skunkfish on 12:50, 15 March 18
I'm such an amateur when it comes to chess, I wasn't even aware of the 'en passant' move!
Title: Re: CPChessNet [developing]
Post by: Joseman on 16:00, 16 March 18
Hi

...And for the ones who thought that coding the 'en passant' move was hard, the next chapter: coding the checkmate detection.

with the checkmate code i can assure you one thing now: i know why nobody coded a netchess on cpc before... it is a hell, trust me a HELL to code it.

hours and hours and hours (and hours) of debugging the checkmate code...

there are many ways for the detection of checkmate, but they do more or less the same (or so i have read): you do all the possible moves of your pieces in the next turn and if no move can prevent your king for being in checkmate you're lost.

i approach  the move a little differently, i look in the 8 directions of the king (plus the knights moves), while i look step by step i save the steps on an array, if any direction is in check, i end the function with carry activated.

if carry is activated (king in check) i already have the steps of the enemy piece to achieve the check condition. Next i move the king in all 8 directions and check (again, because the check function can be called separately) if in any direction the king is not in check, if any direction prevent the king for being in check (and the king can move to that direction), then there is not checkmate. But if the king can't move in 8 directions, next i look for all the pieces of my color in the board (minus the king) and try to intercept the check seeing the array of steps of the enemy piece, if any of my pieces can do the move, then this means that at least one of my pieces can 'eat' the enemy piece or put itself on the way to checkmate (with the knight only can 'eat'). BUT there is a last check! if we can intercept the check, but there is a double check (2 pieces threating the king) then our king will be still in check!. we have to double check the check condition intercepting one piece and seeing if the king is still in check!! in that case is checkmate

Ok, one thing is to say that and other thing is to CODE that... and trust me you DONT WANT to code something like this!!  :laugh:

anyway checkmate code is finished and working (or not if any bug still remains).

this means that the last move that can prevent cpchessnet to see the light of day is DONE.

now only a little more and game finished (i hope!)





Title: Re: CPChessNet [developing]
Post by: Skunkfish on 17:16, 16 March 18
Wow, sounds complicated! How long does the checkmate detection take to run?
Title: Re: CPChessNet [developing]
Post by: Joseman on 18:02, 16 March 18
Quote from: Skunkfish on 17:16, 16 March 18
Wow, sounds complicated! How long does the checkmate detection take to run?

they are easy calculations (a lot, and hard to debug), the cpc is almost idle with the game XD, even i have to slowdown the keyboard detection, if i detect the keyboard keys in every game loop, the pieces are almost impossible to select because the cursor is too fast, even you don't see the cursor when you press the keys because it is doing the same moves 100 times or more in one key press!
Title: Re: CPChessNet [developing]
Post by: Targhan on 01:00, 17 March 18
This is really an interesting project. Do you intend to release the sources once it is done?


As for you complex "check mate" code, this is typically the kind of code that would benefit from Z80 test units so that you can be sure your code works as expected and won't break as the code progresses. But maybe you've done so.
Title: Re: CPChessNet [developing]
Post by: mr_lou on 01:51, 17 March 18
As I kid I was very interested in chess at one point. So I wished for one of those chess computers for Christmas one year.

17 years later I beat it!

Yea... it's safe to say I'm no expert chess player.  :)

CPC networked games is intriguing. Using the CPC for e-mail and IRC and a few games is intriguing. But in order for it to succeed, a lot of people have to have their CPC setup for Internet. So you can sit on IRC on #cpc, and go "Hey! Anyone up for a game of CPChessNet?" and 5 people will go: "Me!"

Oh, that gives me an idea: Could it be made possible to have spectators for a game?
Title: Re: CPChessNet [developing]
Post by: robcfg on 10:30, 17 March 18
That would be certainly interesting!


You get to watch the match and have group chat.
Title: Re: CPChessNet [developing]
Post by: Joseman on 17:43, 17 March 18
Hi

Pawn Promotion done!

This was a easy one! only intercept the pawn_move rutine with is the pawn on the last line? then call pawn_promote, change the piece type for what is selected on the pawn promotion menu and ret to pawn_move

Quote from: Targhan on 01:00, 17 March 18
As for you complex "check mate" code, this is typically the kind of code that would benefit from Z80 test units so that you can be sure your code works as expected and won't break as the code progresses.

to be honest... i don't have idea of what Z80 test units are! if you can explain...

Quote from: mr_lou on 01:51, 17 March 18
CPC networked games is intriguing. Using the CPC for e-mail and IRC and a few games is intriguing. But in order for it to succeed, a lot of people have to have their CPC setup for Internet. So you can sit on IRC on #cpc, and go "Hey! Anyone up for a game of CPChessNet?" and 5 people will go: "Me!"

Oh, that gives me an idea: Could it be made possible to have spectators for a game?

is not impossible to allow more clients to connect only to repaint the board on his side... but @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624) can tell us if there are limits on the number of clients conected!

But i think that only watch a chess game must be a hell of boring! and anyway the chat is only 3 lines, i have no more room for it... i don't know if it makes any sense. i'll be happy if the game works 100% correct, and i know for sure that actually it doesnt  :laugh:

Maybe the real interesting thing is to make a pc client, to allow to play chess with non cpc users... but i don't have patience to make a pc client right now!

if anyone wants to do a pc client... only have to read a little table with the board pieces and send it back when the move is done.

OR better!! some emulator with M4 emulation!!!

pic of promotion:


(http://i64.tinypic.com/aaaj3o.jpg)
Title: Re: CPChessNet [developing]
Post by: Targhan on 18:05, 17 March 18
Quoteto be honest... i don't have idea of what Z80 test units are! if you can explain...


It's a code, that you run from time to time, that will call some other code and checks that the result is fine. Let's say you have a multiplication code:



MultiplyBy4
  add hl,hl
  add hl,hl
  ret


To make sure that this code works, and will continue to work, you will make another code that will do this:

ld hl,10
call MultiplyBy4
;Checks the result: must be 40.
ld de,40
or a
sbc hl,de
jr z,OK
;Error!



You can do such code for all small subcodes, or on larger scale. For example, your test unit could:
- Create a chessboard (in memory) with a checkmate situation.
- Call the "isCheckMate" call
- Make sure the result is "true".


And you would create as many situations as possible to make sure the checkmate code works for them (and also for situatiosn where the checkmate returns false). Now, with such code, you KNOW that you checkmate code works, even after you make the checkmate code evolve.


Of course, it takes time to make such code, but it is extremely valuable to be sure that algorithms work perfectly; now and later.

Title: Re: CPChessNet [developing]
Post by: Gryzor on 09:23, 18 March 18
PROMOCION DEL PEON!


That's my new favourite phrase after Basket Master's "CANASTA!" :D
Title: Re: CPChessNet [developing]
Post by: Joseman on 03:44, 19 March 18
Hi

Castling move finished, now the kings can't do castling if any of the square that the king needs walk to do the move is in threat. Fixed 1  (serious) bug in the routine too.

At this point i can tell you that all the moves & all the rules are finished, CPChessnet is almost finished.

I'll do a win/lose screen and the options to restart the game or go to the main menu, make the net code more reliable and the game will be uploaded for all who wants to betatest the game!.




Title: Re: CPChessNet [developing]
Post by: blackdalek on 09:44, 19 March 18
Quote from: Joseman on 03:44, 19 March 18
Hi

Castling move finished, now the kings can't do castling if any of the square that the king needs walk to do the move is in threat. Fixed 1  (serious) bug in the routine too.

At this point i can tell you that all the moves & all the rules are finished, CPChessnet is almost finished.

I'll do a win/lose screen and the options to restart the game or go to the main menu, make the net code more reliable and the game will be uploaded for all who wants to betatest the game!.
I'll help you beta test (pending any catastrophic hardware failure of my cpc that may occur beforehand)

Sent from my 4013X using Tapatalk

Title: Re: CPChessNet [developing]
Post by: Joseman on 15:59, 19 March 18
Hi @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

I'm looking again the net code, and there is a problem with the connection...

if i setup the server, put it listening for a client and only after of this setup the client, the conexion works well, BUT

if i setup first the client and put it listening for a server and after of this, setup the server, the conexion doesn't work NEVER

what can i doing bad?

And other question, this is from the start, but never looked back again until the game is nearly finished...

my client/server cpc's create a socket, but i never close the sockets, the first time they choose 01h, if i reset the cpc, they choose 02h and so on...

what is the correct way of closing a socket, and this way the cpc's always use 01h?

thankyou for all !!
Title: Re: CPChessNet [developing]
Post by: Duke on 19:06, 19 March 18
Quote from: Joseman on 15:59, 19 March 18
if i setup first the client and put it listening for a server and after of this, setup the server, the conexion doesn't work NEVER

what can i doing bad?

Check the status byte. You cannot connect to a server which does not exist so it should time out and give you an error.

Quote
And other question, this is from the start, but never looked back again until the game is nearly finished...

my client/server cpc's create a socket, but i never close the sockets, the first time they choose 01h, if i reset the cpc, they choose 02h and so on...

what is the correct way of closing a socket, and this way the cpc's always use 01h?
When you no longer need the connection (say user exits), you simply close the socket you were given (ie. 1) and it will be available next time.
Also if an error occurs, you should close the socket and re-create it.
Title: Re: CPChessNet [developing]
Post by: Joseman on 21:29, 19 March 18
Thankyou @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

to close a socket i understand that this is the code:

exit_close:
            ld    hl,cmdclose
            call    sendcmd           
            ret


but i cant see  where the number of socket to be closed is specified... maybe in the a register?

if i do this code alone (without specifying socket) sometimes it appears to close the open socket but other times it just freeze...
Title: Re: CPChessNet [developing]
Post by: Duke on 22:03, 19 March 18
Quote from: Joseman on 21:29, 19 March 18
but i cant see  where the number of socket to be closed is specified... maybe in the a register?

if i do this code alone (without specifying socket) sometimes it appears to close the open socket but other times it just freeze...

Yes, you need to send the socket number you want to close aswell.


cmdclose: db &03
dw    C_NETCLOSE
clsocket: db &0                <----------- put socket number here


You can also find parameters for all M4 commands here:
http://www.spinpoint.org/cpc/m4info.txt (http://www.spinpoint.org/cpc/m4info.txt)  under "Developer information".

C_NETCLOSE      0x4333      Implemented v1.0.9.   data[0] = socket. 
Title: Re: CPChessNet [developing]
Post by: Joseman on 10:09, 20 March 18
Hi!

Thankyou for the answers!

Quote from: Duke on 22:03, 19 March 18
You can also find parameters for all M4 commands here:
http://www.spinpoint.org/cpc/m4info.txt (http://www.spinpoint.org/cpc/m4info.txt)  under "Developer information".

C_NETCLOSE      0x4333      Implemented v1.0.9.   data[0] = socket. 


Yes yes, i read the documentation but for someone like me starting with M4 and protocols is a little hard to understand some things!

for example C_NETCLOSE is 2 times repeated with different ports, wich can be fine, but it's a little obscure, i didn't know what to use until i saw in your client code that C_NETCLOSE    equ &4333!

and "C_NETCLOSE Implemented v1.0.9.    data[0] = socket"

it took me a little while to understand that data[0] is
cmdclose:        db    &03  <---- data[0]
            dw    C_NETCLOSE

maybe it's just me, but maybe the instructions are a little advanced to people trying to understand whats goin' on with protocols, m4 and client/server applications!  :laugh:

Title: Re: CPChessNet [developing]
Post by: Duke on 10:42, 20 March 18
Quote from: Joseman on 10:09, 20 March 18
it took me a little while to understand that data[0] is
cmdclose:        db    &03  <---- data[0]
            dw    C_NETCLOSE
It's not correct, this is how it works:
cmdclose: db &03           <---- Size of command+data to be sent
dw    C_NETCLOSE         <---- command (size 2)
clsocket: db &0               <---- data[0] (size 1)

Quote
maybe it's just me, but maybe the instructions are a little advanced to people trying to understand whats goin' on with protocols, m4 and client/server applications!  :laugh:
Sorry ;) - Maybe that's why so few used it. I did provide examples, so usage should be self explanatory... oh well.
Title: Re: CPChessNet [developing]
Post by: Joseman on 10:54, 20 March 18
Quote from: Duke on 10:42, 20 March 18
It's not correct, this is how it works:
cmdclose: db &03           <---- Size of command+data to be sent
dw    C_NETCLOSE         <---- command (size 2)
clsocket: db &0               <---- data[0] (size 1)
Sorry ;) - Maybe that's why so few used it. I did provide examples, so usage should be self explanatory... oh well.
sorry, thats is how i understood it!! the first is the size data, yesterday i saw it, today morning... oh well XD

Enviado desde mi GT-N7100 mediante Tapatalk

Title: Re: CPChessNet [developing]
Post by: Joseman on 15:06, 20 March 18
Hi @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)


if i do this piece of code in my program:

wait_connect:

                        ;wait for ESC to press, if it's pressed then i do the cmdclose command
       
            ld    a,(ix)    ; get socket status  (0 ==IDLE (OK), 1 == connect in progress,
                                        ; 2 == send in progress)
           

                        cp    1 ; connect in progress?
            jr    z,wait_connect
            cp    0
            jr    z,connect_ok
             jp no_connect



I'm waiting for ESC to press to go back to the menu, while the bucle wait_connect is made...

when i hit esc, i go to a sub that performs the cmdclose command and jump to the main menu.

But not always returns to main menu, sometimes it returns, but sometimes is just hangs on the cmdclose command (i know it because i change to red border just after the cmdclose command, and because if i disconnect the M4 from power it goes back to the menu!)

Why is the M4 hanging in the cmdclose (but not always)?

on the no_connect jump i jump back to the cmdconnect command continue to the wait_connect command

can i call the cmdconnect command as many times as i want or there is a limit, or is supossed to call only one time?
Title: Re: CPChessNet [developing]
Post by: Duke on 15:22, 20 March 18
Quote from: Joseman on 15:06, 20 March 18

Why is the M4 hanging in the cmdclose (but not always)?

Do you store the socket number when you open it, so you are sure you are closing the right socket?

Quote
on the no_connect jump i jump back to the cmdconnect command continue to the wait_connect command

can i call the cmdconnect command as many times as i want or there is a limit, or is supossed to call only one time?
You are only supposed to call it one time. Of course if it eventually gives an error code, you can jump to it again, but as long as it returns "connect in progress" (1), you should not send a connect command again.
Just read status byte and check when it is connected (or error occurs).
Title: Re: CPChessNet [developing]
Post by: Joseman on 15:28, 20 March 18
Quote from: Duke on 15:22, 20 March 18
Do you store the socket number when you open it, so you are sure you are closing the right socket?

yes, on the server and on the client, just when you save the socket on (csocket) i save it to another variable (using_socket), when i go to close de socket
i do ld a,(using_socket) ld (cLsocket),a --> cmdclose



QuoteYou are only supposed to call it one time. Of course if it eventually gives an error code, you can jump to it again, but as long as it returns "connect in progress" (1), you should not send a connect command again.
Just read status byte and check when it is connected (or error occurs).

one question:

if i do

; connect to server
           
            ld    hl,cmdconnect
            call    sendcmd
            ld    a,(iy+3)
            cp    255 ;#FF error
            jp    z,error_conectando_server

.error_conectando_server
call 0


if i put an inexistent ip (192.168.0.50) i suposse that the cpc it's going to reboot

BUT it doesnt reboot, it reach the wait_connect bucle!
Title: Re: CPChessNet [developing]
Post by: Duke on 15:44, 20 March 18
Quote from: Joseman on 15:28, 20 March 18
yes, on the server and on the client, just when you save the socket on (csocket) i save it to another variable (using_socket), when i go to close de socket
i do ld a,(using_socket) ld (cLsocket),a --> cmdclose
Also make sure that when you opened the socket, its a valid socket (1 to 4 ).
Quote
if i put an inexistent ip (192.168.0.50) i suposse that the cpc it's going to reboot

BUT it doesnt reboot, it reach the wait_connect bucle!
It will not know at that point, that the IP does not exist.
You will have to check the status byte from the read only address for the corresponding socket.
Title: Re: CPChessNet [developing]
Post by: Joseman on 15:55, 20 March 18
Quote from: Duke on 15:44, 20 March 18
Also make sure that when you opened the socket, its a valid socket (1 to 4 ).

added  check port 1 to 4 to my code (server and client code)! [/quote]

Quote
It will not know at that point, that the IP does not exist.
You will have to check the status byte from the read only address for the corresponding socket.

then the cp #ff, jump z,error

when activates? only when on the other side is another cpchessnet server but for some reason didn't accept the connection?
Title: Re: CPChessNet [developing]
Post by: Duke on 16:04, 20 March 18
Quote from: Joseman on 15:55, 20 March 18
then the cp #ff, jump z,error

when activates? only when on the other side is another cpchessnet server but for some reason didn't accept the connection?
The 0xFF error only occurs, if the socket is out of range (less than 1 or bigger than 4).
Title: Re: CPChessNet [developing]
Post by: Joseman on 17:00, 20 March 18
Quote from: Duke on 16:04, 20 March 18
The 0xFF error only occurs, if the socket is out of range (less than 1 or bigger than 4).

almost i have it...

BUT

sometimes the cmdsocket command retuns '0' socket, if i understand is the local M4 not giving any free socket to the local cpc.

i compare that IF it's 0 then try to do another cmdsocket (without close anyting, i understand that at this point there isnt any conexion to close)

and again the m4 hangs in the cmdsocket :(, why?

sorry for so many questions and thankyou Duke.
Title: Re: CPChessNet [developing]
Post by: Joseman on 17:57, 20 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

AT LAST, AT LAST IT WORKS!!!!

you can believe it? i was disabling the upper rom in one routine!

then the socket readed was 0, or what the screen had  :laugh:





Title: Re: CPChessNet [developing]
Post by: Duke on 19:15, 20 March 18
Quote from: Joseman on 17:57, 20 March 18
AT LAST, AT LAST IT WORKS!!!!

you can believe it? i was disabling the upper rom in one routine!

Good, 'cause I could not find anywhere the netsocket would return 0 :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 04:45, 21 March 18
CPChessNet 1.0b is reality at last!

*Net code is a lot stable now (connect/listen), not perfect, but very reliable,  there is no code to test if any conection lost occurs (i don't know how the game will perfom on internet)
*screen win/lose added, and the possibility of restart a game (it is tricky to assure that is correct, because of the thousands variables that the game is using, i don't know if there is any variable not initialice between games... time will tell)

very very soon the game on your cpc's to test.

@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624), i suspect that there is need to open the router port 1234 for cpchessnet server?

Pic:
(http://i63.tinypic.com/2dbr02e.jpg)



Title: Re: CPChessNet [developing]
Post by: Duke on 07:04, 21 March 18
Quote from: Joseman on 04:45, 21 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624), i suspect that there is need to open the router port 1234 for cpchessnet server?
Yes, if you used same port as the example it is port 4660 (0x1234). Also on the server you will need to forward the port to your CPC IP.
Title: Re: CPChessNet [developing]
Post by: Joseman on 18:46, 21 March 18
Quote from: Duke on 07:04, 21 March 18
Yes, if you used same port as the example it is port 4660 (0x1234). Also on the server you will need to forward the port to your CPC IP.

Do you think that i should include a port election and not attach the game only to one port?


pic:
(http://i65.tinypic.com/o0xwlc.jpg)
Title: Re: CPChessNet [developing]
Post by: Duke on 20:03, 21 March 18
Quote from: Joseman on 18:46, 21 March 18
Do you think that i should include a port election and not attach the game only to one port?
Yes, that would be a good choice.
Play as server/host, enter port (default to something, so you can just press enter).
Cool loading screen !
Title: Re: CPChessNet [developing]
Post by: remax on 13:10, 22 March 18
Nice Game Gear screen simulation  :-X
Title: Re: CPChessNet [developing]
Post by: Joseman on 13:45, 22 March 18
Quote from: remax on 13:10, 22 March 18
Nice Game Gear screen simulation  :-X

game gear?
Title: Re: CPChessNet [developing]
Post by: remax on 16:33, 22 March 18
Quote from: Joseman on 13:45, 22 March 18
game gear?


Having both at home (multiple copies) i can tell you that your last screenshot has far more in common with the screen of a Game Gear than with the screen of a CPC  :D .


To compare, just take a look at the photograph you took a few posts before !


Anyway, i long for playing this game ;)
Title: Re: CPChessNet [developing]
Post by: Joseman on 19:00, 22 March 18
Quote from: remax on 16:33, 22 March 18

Having both at home (multiple copies) i can tell you that your last screenshot has far more in common with the screen of a Game Gear than with the screen of a CPC  :D .


To compare, just take a look at the photograph you took a few posts before !


Anyway, i long for playing this game ;)


yes, it's the winape screenshot option, nothing like the real hardware
Title: Re: CPChessNet [developing]
Post by: Joseman on 20:03, 22 March 18
Hi

time has come!

Added the port option!

the default port is 6128  ;D

it was complicated for me to add a dec to hex port! i do in the nasty way, if you put 64321 i multiply 6x10000, 4x1000, 3x100,2x10,1x1, add all the result to a variable, then load the variable on a 16bit register (hl) and i do. ld de,#0000 , inc de, dec hl cp #0000, if not repeat bucle. at the end of the bucle, de has the hex por number  :laugh:

You can see the slowness of the routine if you put a high port, for example 60000, it take a while to go to the next screen!

oh, and is not the first time that i'm doing another things and found a bug on things that i thinked that it worked!!

this means that CPChessNET 1.0b has the 100% of possibilites to have bugs... take this on mind .

Here it is!

CPChessNET 1.0b for you.

REMEMBER to open the port 6128 (or whatever you choose) on the server router!!

I think that while CPChessNET is not free of bugs, better not upload it on your webpages or repositories!
Title: Re: CPChessNet [developing]
Post by: Duke on 20:35, 22 March 18
Cool, congrats on the release.  Look forward to try it.

Now someone pm with their IP if they want to play a game over the inet :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 20:39, 22 March 18
Quote from: Duke on 20:35, 22 March 18
Cool, congrats on the release.  Look forward to try it.

Now someone pm with their IP if they want to play a game over the inet :)

are you good at chess?  ;D
Title: Re: CPChessNet [developing]
Post by: Duke on 20:40, 22 March 18
Quote from: Joseman on 20:39, 22 March 18
are you good at chess?  ;D
Decent, I guess :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 20:42, 22 March 18
Quote from: Duke on 20:40, 22 March 18
Decent, I guess :)

then i will lost, i'm only know how to move pieces (and how to program it)  :laugh:


Title: Re: CPChessNet [developing]
Post by: Joseman on 20:44, 22 March 18
Quote from: Joseman on 20:42, 22 March 18
then i will lost, i'm only know how to move pieces (and how to program it)  :laugh:

also i'm taking a drink to celebrate the release, and this doesnt help!
Title: Re: CPChessNet [developing]
Post by: villain on 20:51, 22 March 18
Quote from: Joseman on 20:42, 22 March 18
then i will lost, i'm only know how to move pieces (and how to program it)  :laugh:


Then your next board game port could be Ludo/Mensch ärgere Dich nicht.
Title: Re: CPChessNet [developing]
Post by: XeNoMoRPH on 21:13, 22 March 18
donwloading .. thx for this online game  :o
Title: Re: CPChessNet [developing]
Post by: Joseman on 21:17, 22 March 18
it 's working on internet!!

duke and me are playing a game right now!
Title: Re: CPChessNet [developing]
Post by: Duke on 22:43, 22 March 18

Thanks @Joseman (http://www.cpcwiki.eu/forum/index.php?action=profile;u=135) for a good game :)

PS: the tower loss was trap (ho ho, well almost).
Title: Re: CPChessNet [developing]
Post by: zhulien on 01:55, 23 March 18
I wonder if you'd be interested in putting support for 8bitology.net into it?  This includes lobby and achievements (can be number of wins by person, by country, by anything)...


The server parts of 8bitology.net are up and running. (I'm hoping Prodatron will adopt it soon too within Symbos). Only parts of the 8bitology.net GUI are not done, but they aren't required for in-game... only for web, and 8bml.
Title: Re: CPChessNet [developing]
Post by: Takis Kalatzis on 15:17, 23 March 18
Hi, I would also like to check this fabulous program! It would be a child dream's come true.


I have started the server, if anyone is available please PM me to send the IP address.


Thanks,


Takis
Title: Re: CPChessNet [developing]
Post by: Joseman on 21:22, 23 March 18
Hi

just enter to say that there is a big bug in CPChessNET 1.0.b

if you have a chat window open and the other cpc send the move, the move get lost, because in the chat window there isn't any comprobation if a message is received!

happen to Duke and I the other day, we were chatting for  15 minutes thinking that the other didn't do the move  :laugh:

i'm fixing it

Meanwhile, don't chat a lot!!
Title: Re: CPChessNet [developing]
Post by: Joseman on 21:34, 23 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

it's safe to use #FF as a byte signal, or the m4 on any error, or on any situation fills the buffer with #FF (or maybe other bytes?)

Title: Re: CPChessNet [developing]
Post by: Duke on 21:45, 23 March 18
Quote from: Joseman on 21:34, 23 March 18
@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

it's safe to use #FF as a byte signal, or the m4 on any error, or on any situation fills the buffer with #FF (or maybe other bytes?)
Sure, you can use any value you want. It wont fill the buffer FF's unless its receiving them,
Title: Re: CPChessNet [developing]
Post by: Joseman on 21:55, 23 March 18
Quote from: Duke on 21:45, 23 March 18
Sure, you can use any value you want. It wont fill the buffer FF's unless its receiving them,
is there any possibilty of corrupted data being received if a packet gets corrupted on its way trought internet?

Enviado desde mi GT-N7100 mediante Tapatalk

Title: Re: CPChessNet [developing]
Post by: Joseman on 17:49, 24 March 18
Hi @Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)

why if i still call wait_send: until i have a message i'm sending the board, the M4 just hangs after 10-15 calls to wait_send?

when i wait for a board confirmation, if the other cpc has a chat open, it will not send a message to the cpc that is on wait_send bucle, then the cpc that it is in bucle, just  hangs M4 on wait_send
Title: Re: CPChessNet [developing]
Post by: Duke on 20:14, 24 March 18
Quote from: Joseman on 17:49, 24 March 18
why if i still call wait_send: until i have a message i'm sending the board, the M4 just hangs after 10-15 calls to wait_send?

when i wait for a board confirmation, if the other cpc has a chat open, it will not send a message to the cpc that is on wait_send bucle, then the cpc that it is in bucle, just  hangs M4 on wait_send
It should not.
Anyway best practice is to put wait_send before sending, this way you are wasting less cpu time for the actual send.
Title: Re: CPChessNet [developing]
Post by: Kris on 20:30, 24 March 18
Congrats for this amazing game: next game should a LAP or similar game like we use to play during meeting :)

Title: Re: CPChessNet [developing]
Post by: Joseman on 22:24, 24 March 18
Hi

CPChessNET 1.3b uploaded!!

fix:
*added board received check, no more boards lost on the infinite internet
*added chat byte ID, no more rubbish on the chat if someting goes wrong sending chat lines.

features added:
*added sound for move recived, you don't have to check for pal moves looking at the screen, just hear the sound!.
*the chat scan is less precise, so no repat letters are printed.
*added some chars for chat: ?, &, ! are now avaliable on cursors when chat is open.


as i can't prevent the M4 to hang when i do a bucle for receive a message, i added a timer, you have 20 minutes to have the window chat open and send a message. I don' think that anybody is going to spent 20 minutes to send a line chat!!, but if you do, the m4 willl hang! take care of this!

If a chat message is send or received between a board send, the board has priority, the line chats are omitted.

Please update to 1.3b and use the same version on client/server!!
Title: Re: CPChessNet [developing]
Post by: Takis Kalatzis on 11:06, 25 March 18
Hi, if anyone is interested in a quick game of chess using latest Joseman's version 1.3b, please PM me.


Thanks,


Takis
Title: Re: CPChessNet [developing]
Post by: Joseman on 11:21, 25 March 18
Quote from: Takis Kalatzis on 11:06, 25 March 18
Hi, if anyone is interested in a quick game of chess using latest Joseman's version 1.3b, please PM me.


Thanks,


Takis

if you want an easy game, i'm here :)
Title: Re: CPChessNet [developing]
Post by: Joseman on 12:29, 25 March 18
Good one @Takis Kalatzis (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1719) !!!

and another game that i lost!

the board now is 100% safe to reach the other cpc and this is the most important.

the chat... mmmm i'll think more on it...

take in mind that there is still not check for connection losts!

if a cpc is turn off or lost the connection the other cpc will wait forever for the board!  :laugh:

@Duke (http://www.cpcwiki.eu/forum/index.php?action=profile;u=1624) what do you think is the timing to wait and realize that the connection is lost?
Title: Re: CPChessNet [developing]
Post by: blackdalek on 12:35, 25 March 18
Should there be a dedicated IRC channel for people to meet on in order to arrange games? Maybe on FEFnet or Freenode or something?
Title: Re: CPChessNet [developing]
Post by: Joseman on 12:39, 25 March 18
Quote from: blackdalek on 12:35, 25 March 18
Should there be a dedicated IRC channel for people to meet on in order to arrange games? Maybe on FEFnet or Freenode or something?

or a thread here, the vast number of cpc users are here!  :laugh:

or maybe twitter?

there is a channel on irc that i connected sometime ago from symbos and his irc client too...
Title: Re: CPChessNet [developing]
Post by: blackdalek on 12:46, 25 March 18
I just thought meeting through an IRC channel could be done more in real time, rather than posting a forum message then waiting for someone to read it (which could potentially happen days later). Having that "live chat" aspect of IRC means you can instantly (usually) see if anyone else is available for a game at that same time.... well, it worked for scrabble players  :-\
Title: Re: CPChessNet [developing]
Post by: Joseman on 12:48, 25 March 18
Quote from: blackdalek on 12:46, 25 March 18
I just thought meeting through an IRC channel could be done more in real time, rather than posting a forum message then waiting for someone to read it (which could potentially happen days later). Having that "live chat" aspect of IRC means you can instantly (usually) see if anyone else is available for a game at that same time.... well, it worked for scrabble players  :-\

trust me that on twitter the people is reading constantly (even at work)  :laugh:

if not, the problem will be the same on IRC, if people is at job or not in home the problem is the same!
Title: Re: CPChessNet [developing]
Post by: blackdalek on 15:20, 26 March 18
So.... I've recently rediscovered #cpc channel on freenode IRC servers.
If anyone want to try CPChess with me I could be hanging out in there waiting. Or alternatively message me on the forum so we can arrange a time.

@Joseman (http://www.cpcwiki.eu/forum/index.php?action=profile;u=135) will there be an english language  version of the interface forthcoming at a later date?

I should also mention, I am terrible at chess and haven't played in at least 20 years ;)

Title: Re: CPChessNet [developing]
Post by: Joseman on 19:12, 26 March 18
ok!

time for 1.6b version!!

*this version has HUGE improvements in the chat code, no more chats lost in favour of a board move, first i do the move, next i see if any message is pending to receive or send. This was really hard to make it work!! I hope there is no problems! Only it can lost a message if a board is send and casually the chat message is lost on any packet on internet, but i suposse is difficult that happens.

*Little sound for the chat receive message, same as board move, you don't have to stay looking at the screen waiting for a move or chat.

*Now you can chat in the end screen, you can laugh at the loser or arrange another game!

KNOW PROBLEM:

*if a chat window is open when the end game ID is sent the end game ID gets lost (same as happenned with the board move on 1.0b version), this is for the same reason, no end game ID confirm is send back... No big problem at all... one side will display the end screen, the other simply will can't do anything because the king is on checkmate, the code will not allow to do anything on this situation, only to chat, and this is almost the same you can do on the end screen!.

*if the program has to check if any message is pending on the other side when it needs to send the board, then it will enter a bucle (that prevents the m4 to hang), it will delay 3-5 seconds...no big deal...


***as there is a lot of internal changes it can be some bug that didn't exist before**

play all you can!!





Title: Re: CPChessNet [developing]
Post by: Joseman on 22:43, 26 March 18
Quote from: blackdalek on 15:20, 26 March 18
@Joseman (http://www.cpcwiki.eu/forum/index.php?action=profile;u=135) will there be an english language  version of the interface forthcoming at a later date?

Yes, but i need to know that the program is almost 100% bug free before induce potential bugs on the char arrays changing the language!

anyway: cursor keys to move cursor, space to select/move. T for chat, enter to send chat. that's all
Title: Re: CPChessNet [developing]
Post by: Joseman on 00:45, 28 March 18
Hi!

version 1.7b ready to download!!

*English language added!

of course different languages can play together!

As English is not my mother tongue, please let me know any spelling, grammatical errors or bad translation!


Title: Re: CPChessNet [developing]
Post by: Emu on 20:49, 05 April 21
@Joseman (https://www.cpcwiki.eu/forum/index.php?action=profile;u=135) : I stumbled across CPCchessNet via the M4 board documentation. I like it very much. Its complete appearance is highly professional, even beautiful, I think. And of course, it works. Thank you for providing it!

Are you interested in a German translation? I offer to translate the texts if you send the English version of them to me in a file.
Title: Re: CPChessNet [developing]
Post by: Joseman on 01:00, 12 April 21
Quote from: Emu on 20:49, 05 April 21
@Joseman (https://www.cpcwiki.eu/forum/index.php?action=profile;u=135) : I stumbled across CPCchessNet via the M4 board documentation. I like it very much. Its complete appearance is highly professional, even beautiful, I think. And of course, it works. Thank you for providing it!

Are you interested in a German translation? I offer to translate the texts if you send the English version of them to me in a file.
Hi
Thanks for the compliments  :)
The appearance is far from professional. The pieces are copied from Colossus Chess, and the texts are a simple font with that simple frames.
And it doesn't work always!! on local LAN it works without problem, but, on internet, if a packet is lost, the program waits forever for it... I never managed to fix that problem... If you chat a lot, you'll see the problem...
send me a mail to sjoseman@hotmail.com and i'll send you the text files
Regards
Title: Re: CPChessNet [developing]
Post by: zhulien on 20:35, 20 April 21
I have created most of a lobby system which I was hoping there would be some interest in it needs a first game... it also supports chat (email like).  Did you create a lobby yet? I also have achievement and leaderboards. At 8bitology.net
Title: Re: CPChessNet [developing]
Post by: Joseman on 11:33, 28 April 21
No, the game has a little chat integrated (that is the source of the problems with the packets lost), i ended tired of trying to fix that and the game is as is on the final version. On local lan never fails but on internet... well, the game can end stuck on a packet lost.
Title: Re: CPChessNet [developing]
Post by: Joseman on 12:59, 13 December 21
Hi @Duke (https://www.cpcwiki.eu/forum/index.php?action=profile;u=1624)
I want to fix the problem with CPChessNet and the infinite loop when a packet lost happens on internet.
can you help me a little (again)
Thankyou!
Title: Re: CPChessNet [developing]
Post by: Emu on 22:55, 19 April 22
@Joseman : Hi, I've been working on CPCemu in the recent months and stumbled over a strange behaviour of CPChessNet while debugging my M4 emulation network code (and preparing it for IPv6). The user can specify the port number to be used by the chess server. The server binds to this port when started for the first time. If the server is started again it does not use the port number specified by the user, but it increments the previously used port number by the specified value. Is this intended?

There is some strange arithmetic around $8458 (ADD HL, DE with DE containing the user-specified value; this happens also before at $83fe, $841c and $843a). These additions seem to be the origin of the - from my perspective wrong - increasing port number.

Title: Re: CPChessNet [developing]
Post by: Joseman on 10:04, 20 April 22
Quote from: Emu on 22:55, 19 April 22@Joseman : Hi, I've been working on CPCemu in the recent months and stumbled over a strange behaviour of CPChessNet while debugging my M4 emulation network code (and preparing it for IPv6). The user can specify the port number to be used by the chess server. The server binds to this port when started for the first time. If the server is started again it does not use the port number specified by the user, but it increments the previously used port number by the specified value. Is this intended?

There is some strange arithmetic around $8458 (ADD HL, DE with DE containing the user-specified value; this happens also before at $83fe, $841c and $843a). These additions seem to be the origin of the - from my perspective wrong - increasing port number.



Hi, i don't remember much about the code, but i'm pretty sure that is not intended that the server port is incremented with the new value, i'll take a look, thanks!!

One question, how the debugger part of the CPCEmu is going? i found it somewhat "obscure", it can help a lot for a future debugging of my buggy Net code on CPChessnet :)

Title: Re: CPChessNet [developing]
Post by: Emu on 22:41, 20 April 22
Well, the debugger is a quick-and-dirty port from the DOS version. I've only modified it to enable CRTC single-stepping. I was thinking of adding a GDB remote stub, but seeing that there are only very few Z80-compatible GDB implementations, I gave up the idea. It's not worth the effort.

One of my less important projects is to change the UI interface of CPCemu to a more modern system, but this would be little fun only, so I tend to postpone this. However, it's no fun to use the debugger, either, so I could imagine to start with the debugger as it is rather independent of the rest and indeed needs some polishing.
Title: Re: CPChessNet [developing]
Post by: Joseman on 18:05, 23 March 23
Hi @Duke 

Sorry for bringing up an old topic

One question

Sometimes when you do cmdsocket you receive a number upper than number 1.

It happens more and more if you don't reset the M4.

how can i make sure that only will receive the socket number 1?

maybe i have to close the open sockets?

how can i do that? if i receive for example number 3, close sockets 3, 2, 1 and try to get this time socket number 1

Regards
Title: Re: CPChessNet [developing]
Post by: Duke on 08:22, 24 March 23
Quote from: Joseman on 18:05, 23 March 23Hi @Duke

Sorry for bringing up an old topic

One question

Sometimes when you do cmdsocket you receive a number upper than number 1.

It happens more and more if you don't reset the M4.

how can i make sure that only will receive the socket number 1?

maybe i have to close the open sockets?

how can i do that? if i receive for example number 3, close sockets 3, 2, 1 and try to get this time socket number 1

Regards
You should only need to make sure that socket 1 was closed on last use, then the next C_NETSOCKET should pick that socket first.
Title: Re: CPChessNet [developing]
Post by: Joseman on 12:56, 24 March 23
Quote from: Duke on 08:22, 24 March 23
Quote from: Joseman on 18:05, 23 March 23Hi @Duke

Sorry for bringing up an old topic

One question

Sometimes when you do cmdsocket you receive a number upper than number 1.

It happens more and more if you don't reset the M4.

how can i make sure that only will receive the socket number 1?

maybe i have to close the open sockets?

how can i do that? if i receive for example number 3, close sockets 3, 2, 1 and try to get this time socket number 1

Regards
You should only need to make sure that socket 1 was closed on last use, then the next C_NETSOCKET should pick that socket first.

yes, but sometimes if you reset the cpc (only the cpc) or the program hangs (and you need to reset the cpc too), the socket keeps open forever.

how can you close a socket in this case?, where the actual program still didn't make any socket
Title: Re: CPChessNet [developing]
Post by: Duke on 11:05, 26 March 23
Quote from: Joseman on 12:56, 24 March 23
Quote from: Duke on 08:22, 24 March 23You should only need to make sure that socket 1 was closed on last use, then the next C_NETSOCKET should pick that socket first.

yes, but sometimes if you reset the cpc (only the cpc) or the program hangs (and you need to reset the cpc too), the socket keeps open forever.

how can you close a socket in this case?, where the actual program still didn't make any socket

You can try to close the socket before using it, I think it should work ok, even if it isn't open.
Title: Re: CPChessNet [developing]
Post by: Joseman on 08:34, 29 March 23
Hi @Duke 

I'm unabled to get socket1 and only socket1

the first time it's ok, I get socket 1.

Reset the cpc (not the M4), socket1 remains open

Execute the routine get_socket, and I do a "if socket >1 --> close socket"

do a bucle until socket1 free

but it never exist the bucle

it's like that the M4 is not closing sockets and then the bucle never exist

are you sure that the M4 is capable to close sockets that was open on old connections before reset the CPC?

maybe i'm doing something wrong, but i followed your source code as you explain
Title: Re: CPChessNet [developing]
Post by: Duke on 09:01, 29 March 23
Quote from: Joseman on 08:34, 29 March 23Hi @Duke

I'm unabled to get socket1 and only socket1

the first time it's ok, I get socket 1.

Reset the cpc (not the M4), socket1 remains open

Execute the routine get_socket, and I do a "if socket >1 --> close socket"

do a bucle until socket1 free

but it never exist the bucle

it's like that the M4 is not closing sockets and then the bucle never exist

are you sure that the M4 is capable to close sockets that was open on old connections before reset the CPC?

maybe i'm doing something wrong, but i followed your source code as you explain
You should close the socket before opening it, to ensure it is closed after the reset/crash.

Ie.
; close socket 1 first thing
ld hl,cmdclose
call sendcmd

; you can check return value, if -1, then the socket was not open, thus could not be closed.
; ...

; then open a new socket
; ...

ld hl,cmdsocket
call sendcmd
; should return socket 1 (first avaiable socket)
; ...

ret

cmdclose:
db &03
dw C_NETCLOSE
db 1 ; socket 1

cmdsocket:
db 5
dw C_NETSOCKET
db &0,&0,&6 ; domain, type, protocol (TCP/IP)

Title: Re: CPChessNet [developing]
Post by: Joseman on 10:19, 29 March 23
Quote from: Duke on 09:01, 29 March 23
Quote from: Joseman on 08:34, 29 March 23Hi @Duke

I'm unabled to get socket1 and only socket1

the first time it's ok, I get socket 1.

Reset the cpc (not the M4), socket1 remains open

Execute the routine get_socket, and I do a "if socket >1 --> close socket"

do a bucle until socket1 free

but it never exist the bucle

it's like that the M4 is not closing sockets and then the bucle never exist

are you sure that the M4 is capable to close sockets that was open on old connections before reset the CPC?

maybe i'm doing something wrong, but i followed your source code as you explain
You should close the socket before opening it, to ensure it is closed after the reset/crash.

Ie.
; close socket 1 first thing
ld hl,cmdclose
call sendcmd

; you can check return value, if -1, then the socket was not open, thus could not be closed.
; ...

; then open a new socket
; ...

ld hl,cmdsocket
call sendcmd
; should return socket 1 (first avaiable socket)
; ...

ret

cmdclose:
db &03
dw C_NETCLOSE
db 1 ; socket 1

cmdsocket:
db 5
dw C_NETSOCKET
db &0,&0,&6 ; domain, type, protocol (TCP/IP)


At last!!! it seems to work!! thankyou!!

One question:

if all the sockets are opened in old connections, and only close socket1, the m4 will allways try to get first socket1? or there is some case that it will try first to open socket>1

thankyou!!
Title: Re: CPChessNet [developing]
Post by: Duke on 10:32, 29 March 23
Quote from: Joseman on 10:19, 29 March 23One question:

if all the sockets are opened in old connections, and only close socket1, the m4 will allways try to get first socket1? or there is some case that it will try first to open socket>1

thankyou!!

Yes, sockets are always opened in the order 1,2,3,4 - if a socket is in use it will check the next one.
Title: Re: CPChessNet [developing]
Post by: Joseman on 15:00, 29 March 23
Now the big problem with chessnet

sometimes when the program is doing certain things, there isn't any check if a new message is received (board move or chat).

When this occurs, if a board move is not received, the cpc that sent the move, change turn, but the other (not receiving board move), doesn't change turn, then the 2 cpc are thinking that the other cpc is that move next and keep waiting for a new board move that never will occur.

I was thinking that maybe, if i create an interrupt that checks for new messages, when receive a new notification, priorice this new message (inside the int) do the things (actualice the board table, actualice the chat table), exit the int and continue doing what was doing before the int.

what do you think about this solution, may work?
Title: Re: CPChessNet [developing]
Post by: Duke on 15:24, 30 March 23
Quote from: Joseman on 15:00, 29 March 23Now the big problem with chessnet

sometimes when the program is doing certain things, there isn't any check if a new message is received (board move or chat).

When this occurs, if a board move is not received, the cpc that sent the move, change turn, but the other (not receiving board move), doesn't change turn, then the 2 cpc are thinking that the other cpc is that move next and keep waiting for a new board move that never will occur.

I was thinking that maybe, if i create an interrupt that checks for new messages, when receive a new notification, priorice this new message (inside the int) do the things (actualice the board table, actualice the chat table), exit the int and continue doing what was doing before the int.

what do you think about this solution, may work?
I think it is a good solution to check for incoming messages via an interrupt, probably you should do both send and receive from the interrupt and just prepare the data to be send from your game loop and set a flag that you have a package to be sent.
Title: Re: CPChessNet [developing]
Post by: andycadley on 17:23, 30 March 23
The classic way to solve a problem like this is to number messages and then include an acknowledgement into the protocol. If the sender doesn't receive a matching acknowledgement after a while it just re-sends it. If the client receives a duplicate message, it just re-sends an acknowledgement and ignores the message.

It's not perfect and on a really unreliable connection could theoretically loop forever, but practically speaking it solves the problem most of the time.
Title: Re: CPChessNet [developing]
Post by: Joseman on 17:58, 30 March 23
Quote from: andycadley on 17:23, 30 March 23The classic way to solve a problem like this is to number messages and then include an acknowledgement into the protocol. If the sender doesn't receive a matching acknowledgement after a while it just re-sends it. If the client receives a duplicate message, it just re-sends an acknowledgement and ignores the message.

It's not perfect and on a really unreliable connection could theoretically loop forever, but practically speaking it solves the problem most of the time.
i like this idea (number the messages), the reality is that chat messages doesn't mind me, if a chat line is missing, well, if the message was important, just retype it again. But the board message is crucial to be received.

maybe a mix of the 2 things are a good idea, number the board messages and do the receive message on an int.

Talking about ints, i know how an int code works, but i never used one on any of my programs.

The CPC has 6 ints... an int occurs every 52 scanlines (52 * 64 NOPS). I'm right about this?

we can wait for refresh int, and use it as "our" int 1, in chessnet this int can be where i check for incomming message. The rest of the ints are ignored (please correct me if i'm wrong on something)

If what i'm talking is right... then the next thing: what's the correct timing for checking messages, i suposse that checking the M4 every int1 is too fast for checking a message... if this is right, what will be the correct timing to check for incoming messages?

thakyou for your help!




Title: Re: CPChessNet [developing]
Post by: Joseman on 12:40, 01 April 23
Hi @Duke 

i see this annotation on your source code

" ld bc,250 ; max size, prevent overflow because I am too lazy to re-write the sendcmd... "

what's supposed to mean this annotation?

any problem with the buffer if >250?

Title: Re: CPChessNet [developing]
Post by: Joseman on 08:24, 05 April 23
Hi @Duke 

I'm having a problem with understanding your sourcecode on the cmdsend command

on tcp.s you write this on the code:

cmdsend: db 0 ; we can ignore this byte (part of early design)
dw C_NETSEND
sendsock: db 0
sendsize: dw 0 ;size
sendtext: ds 255

But the code do this after send the cmdsend command:

ld hl,5
add hl,bc (bc, data length)
ex de,hl
ld hl,cmdsend
ld (hl),e
call sendcmd

you are writing a calculated value on the " db 0 ; we can ignore this byte (part of early design) "

If i ignore this write (as you say on the comment) the command doesn't work, and i have to do it as you do.

What is this value you're writing there? I really don't understand how it works.

Thankyou!!
Title: Re: CPChessNet [developing]
Post by: Duke on 10:35, 09 April 23
Quote from: Joseman on 12:40, 01 April 23Hi @Duke

i see this annotation on your source code

" ld bc,250 ; max size, prevent overflow because I am too lazy to re-write the sendcmd... "

what's supposed to mean this annotation?

any problem with the buffer if >250?


It only means that the function called sendcmd fetches the first byte of the prepared buffer pointed to by HL and uses it as counter value in the outi loop.
Title: Re: CPChessNet [developing]
Post by: Duke on 10:37, 09 April 23
Quote from: Joseman on 08:24, 05 April 23you are writing a calculated value on the " db 0 ; we can ignore this byte (part of early design) "

If i ignore this write (as you say on the comment) the command doesn't work, and i have to do it as you do.

What is this value you're writing there? I really don't understand how it works.

Thankyou!!
Yes the value is ignored by the M4 board itself, but its not ignored by the sendcmd function, hence I was too lazy to rewrite it at that time, so re-write the send cmd (I probably did that later in some of the other sources, I dont remember) if you dont want to be stuck with the 8 bit value.
Title: Re: CPChessNet [developing]
Post by: Joseman on 10:43, 09 April 23
Quote from: Duke on 10:37, 09 April 23
Quote from: Joseman on 08:24, 05 April 23you are writing a calculated value on the " db 0 ; we can ignore this byte (part of early design) "

If i ignore this write (as you say on the comment) the command doesn't work, and i have to do it as you do.

What is this value you're writing there? I really don't understand how it works.

Thankyou!!
Yes the value is ignored by the M4 board itself, but its not ignored by the sendcmd function, hence I was too lazy to rewrite it at that time, so re-write the send cmd (I probably did that later in some of the other sources, I dont remember) if you dont want to be stuck with the 8 bit value.

Hi @Duke 

Thanks for the kind answers, i'll look to the sendcmd and try to rewrite it.

CPChessNET is actualy working with interrups (one to see if something new, another to read it, another to apply it)

And works like a charm!! Realtime chat, no board lost in any case, no chat lost in any case.

I'm very very happy!!
Title: Re: CPChessNet [developing]
Post by: Joseman on 10:35, 10 April 23
mode 1, 22 colours at the same time for credits menu.

It was necessary? no.

It's cool? Hell yeah!

(https://i.ibb.co/VB5FCKX/22coloresrealcpc.jpg)
Title: Re: CPChessNet [developing]
Post by: Joseman on 11:14, 11 April 23
Hi @Duke 

I've been testing chessnet with Xenomorph.

There is one thing that failed on my code (because there is some things that i still don't understand)

we were connected, playing. Then xeno closed the game.

On my side noting happens, but if i send a chat msg (xeno closed) then chessnet goes for a routine where i stop the code.

the part of the code involucrate (i think is part of the code that i don't understand):

ld hl,cmdrecv
call sendcmd

ld bc,0
ld a,(iy+3) ;IY response_bufferM4
cp 0 ; all good ?
jr z,msg_OK

the question what are you asking on (iy+3) with the cmdrecv and comparing with 0?

what other values can return (iy+3) on cmdrecv?

thankyou!!
Title: Re: CPChessNet [developing]
Post by: Duke on 18:35, 11 April 23
Quote from: Joseman on 11:14, 11 April 23the question what are you asking on (iy+3) with the cmdrecv and comparing with 0?

what other values can return (iy+3) on cmdrecv?
It's a bit of a dummy as my documentation say it is = 0 and you have to refer to the socket status structure to read the status.
However it can return -1 if the socket is out of range (ie. not 1-4).

EDIT:
You should read and see the socket info structure status == 3 -> remote closed connection in your tests.

Socket info structure (ptr read from 0xFF06), there is a total of 4 sockets for use and "socket 0" reserved C_NETHOSTIP. User sockets are 1-4.
offset:
(socket*16)+0   status  : current status 0=idle, 1=connect in progress, 2=send in progress, 3=remote closed connection,
               4=wait incoming (accept), 5=dnslookup in progress, 240-255 = error code
(socket*16)+1   lastcmd : last command updating sock status 0=none, 1=send, 2=dnslookup, 3=connect, 4=accept, 5=recv, 6=error handler
(socket*16)+2   received: (2 bytes)   - data received in internal buffer (ready to get with C_NETRECV)
(socket*16)+4   ip_addr :   (4 bytes)   - ip addr of connected client in passive mode
(socket*16)+8   port    :   (2 bytes)   - port of the same..
(socket*16)+10   reserved: (6 bytes)   - not used yet (alignment!).
Title: Re: CPChessNet [developing]
Post by: Joseman on 19:19, 11 April 23
Quote from: Duke on 18:35, 11 April 23
Quote from: Joseman on 11:14, 11 April 23the question what are you asking on (iy+3) with the cmdrecv and comparing with 0?

what other values can return (iy+3) on cmdrecv?
It's a bit of a dummy as my documentation say it is = 0 and you have to refer to the socket status structure to read the status.
However it can return -1 if the socket is out of range (ie. not 1-4).

EDIT:
You should read and see the socket info structure status == 3 -> remote closed connection in your tests.

Socket info structure (ptr read from 0xFF06), there is a total of 4 sockets for use and "socket 0" reserved C_NETHOSTIP. User sockets are 1-4.
offset:
(socket*16)+0 status  : current status 0=idle, 1=connect in progress, 2=send in progress, 3=remote closed connection,
 4=wait incoming (accept), 5=dnslookup in progress, 240-255 = error code
(socket*16)+1 lastcmd : last command updating sock status 0=none, 1=send, 2=dnslookup, 3=connect, 4=accept, 5=recv, 6=error handler
(socket*16)+2 received: (2 bytes) - data received in internal buffer (ready to get with C_NETRECV)
(socket*16)+4 ip_addr : (4 bytes) - ip addr of connected client in passive mode
(socket*16)+8 port    : (2 bytes) - port of the same..
(socket*16)+10 reserved: (6 bytes) - not used yet (alignment!).

one question, when i do a cmdclose, the other cpc receive somekind of data? or only the socket status is actualized?

if it's this way (only socket status)

should I read the socket status always before send any command?

thankyou for your help!
Title: Re: CPChessNet [developing]
Post by: Joseman on 19:41, 11 April 23
Forget my last question

I'm a little retarded

I was modifying the client/server connect routines (not the game routines, now on int)

now the remote closed is correctly detected!

thankyou for your patience!
Powered by SMFPacks Menu Editor Mod