JoyWIP v0.0

Announce (tech) demos or games releases

Moderator: Mask of Destiny

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri May 25, 2012 5:13 pm

Stef wrote:Yep i already added SR control in the wip SGDK as we need it at some point.
Indeed the teamplayer and mouse eats sometime and it's preferable to disable them when not needed :) I am also trying to keep the library overhead as low as possible as we don't have many CPU resource to waste on that type of system ;)
Hmmm - so should mouse/teamplay start as disabled, too? Only default to pads being on, and the rest be enabled as needed?

Unless the teamplay is the only thing detected... then default it to on.

All the changes you made looks good, thanks again for that !
You're welcome. One thing I thought of since it uses the same hardware - I'm also going to add Zero Tolerance cable support. I've got the cable already, but haven't done anything with it.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri May 25, 2012 5:35 pm

Chilly Willy wrote: Hmmm - so should mouse/teamplay start as disabled, too? Only default to pads being on, and the rest be enabled as needed?
Unless the teamplay is the only thing detected... then default it to on.
Honestly yeah, i think it's better to disable them by default as in 99% of case we won't use them, except of course if a teamplay or mouse is detected at init time :)
You're welcome. One thing I thought of since it uses the same hardware - I'm also going to add Zero Tolerance cable support. I've got the cable already, but haven't done anything with it.
This is the cable for "network" play ?? how does that work ? from ext controller port ?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri May 25, 2012 8:48 pm

Stef wrote:
Chilly Willy wrote: Hmmm - so should mouse/teamplay start as disabled, too? Only default to pads being on, and the rest be enabled as needed?
Unless the teamplay is the only thing detected... then default it to on.
Honestly yeah, i think it's better to disable them by default as in 99% of case we won't use them, except of course if a teamplay or mouse is detected at init time :)
Yeah, makes more sense to enable them ONLY if they are the only detected input device, otherwise default to off. That's easy enough to do. The teamplay in particular will probably be the only thing when it's being used, but not always.

You're welcome. One thing I thought of since it uses the same hardware - I'm also going to add Zero Tolerance cable support. I've got the cable already, but haven't done anything with it.
This is the cable for "network" play ?? how does that work ? from ext controller port ?
Yeah, the network cable for Zero Tolerance. You connect it between the controller ports (ZT is hard coded for port 2 for both, but you could actually use it between any controller ports as long as the software handled it). It passes RLDU straight through (one MD will be outputting while the other is inputting), and cross wires the TH and TR lines, like this:

Code: Select all

TH <----\/------> TH
TR -----/\------- TR
TL
R ---------------> R
L ---------------> L
D ---------------> D
U ---------------> U
To avoid a race condition on who sets TH low first (via their TR line), I imagine you make one console the "Master" and the other the "Slave". Only the Master would start a packet transfer. It would set the nibble to out, set the nibble, then set TR low to create an int on the slave MD. The slave int handler would set the nibble to in, read the nibble, then set TR low to acknowledge transfer. The Master would set the next nibble, set TR high, and wait for the slave to set TR high. Repeat for a full packet, then switch to inputting data from the slave (if needed).

You could actually make everything about the transfer interrupt driven the master wouldn't wait for ACK, it would exit and the int handler would occur when ACK was sent. Of course, then you are limited in transfer rate to how fast ints can be handled. That's good for very small amounts of data. If you need lots of data transferred, or can't put up with high int rates, just use the int to start the transfer and do the rest in a loop as described above.

Anywho, I was thinking pass JOY_SUPPORT_ZTC_MASTER / JOY_SUPPORT_ZTC_SLAVE to JOY_setSupport(). I'm open to suggestions on the packet functions... maybe something like

JOY_ztcSendPacket(pkt);

It queues the packet, then if it's the master, the queue is processed instantly; if it's the slave, it waits until the master starts a transfer before processing the queue.

pkt = JOY_ztcGetPacket(flags);

If flags == WAIT, it waits until a packet has been received, otherwise it returns NULL if no packet has been received. If there is a packet on the input queue, it dequeues it and returns a pointer to it.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sat May 26, 2012 12:39 am

Chilly Willy wrote: Yeah, the network cable for Zero Tolerance. You connect it between the controller ports (ZT is hard coded for port 2 for both, but you could actually use it between any controller ports as long as the software handled it). It passes RLDU straight through (one MD will be outputting while the other is inputting), and cross wires the TH and TR lines, like this:

Code: Select all

TH <----\/------> TH
TR -----/\------- TR
TL
R ---------------> R
L ---------------> L
D ---------------> D
U ---------------> U
...

Anywho, I was thinking pass JOY_SUPPORT_ZTC_MASTER / JOY_SUPPORT_ZTC_SLAVE to JOY_setSupport(). I'm open to suggestions on the packet functions... maybe something like

JOY_ztcSendPacket(pkt);

It queues the packet, then if it's the master, the queue is processed instantly; if it's the slave, it waits until the master starts a transfer before processing the queue.

pkt = JOY_ztcGetPacket(flags);

If flags == WAIT, it waits until a packet has been received, otherwise it returns NULL if no packet has been received. If there is a packet on the input queue, it dequeues it and returns a pointer to it.
Ok i see :) similar to null modem cable and "protocol" we had on PC :)
Thanks for the explanation.

About the defines and functions name, it sounds pretty specific to Zero Tolerance and actually it is ! Do you think it is possible to separate the support for this cable from "JOY_" unit ? For me it's more "COM_" than "JOY_" but that's just a matter of organization and maybe that will produce many code duplication :-/
By the way i updated SGDK library but just on the repository:
http://code.google.com/p/sgdk/source/browse/
I fixed some stuff, added improved joystick support with your code :) and also support for the external interrupt (i know you already did it but i needed it at some point too so...).

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat May 26, 2012 3:17 am

Stef wrote: Ok i see :) similar to null modem cable and "protocol" we had on PC :)
Thanks for the explanation.

About the defines and functions name, it sounds pretty specific to Zero Tolerance and actually it is ! Do you think it is possible to separate the support for this cable from "JOY_" unit ? For me it's more "COM_" than "JOY_" but that's just a matter of organization and maybe that will produce many code duplication :-/
That would be better, but quite a bit of the underlying code is virtually the same as handling controllers. Perhaps the underlying joy stuff can be private, and use COM_ as the public interface.

Hmm - the cable IDs as unknown, so I could just leave the port as unknown/support off, then put all the handling code in com.c. There would be a little duplication, but it would be cleaner than trying to shoehorn this into the JOY_ interface.

By the way i updated SGDK library but just on the repository:
http://code.google.com/p/sgdk/source/browse/
I fixed some stuff, added improved joystick support with your code :) and also support for the external interrupt (i know you already did it but i needed it at some point too so...).
I'll merge with what I'm working on. I'll probably be another week with finishing out the menacer support along with adding COM. COM will also use the external int.

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sat May 26, 2012 12:09 pm

Chilly Willy wrote: That would be better, but quite a bit of the underlying code is virtually the same as handling controllers. Perhaps the underlying joy stuff can be private, and use COM_ as the public interface.

Hmm - the cable IDs as unknown, so I could just leave the port as unknown/support off, then put all the handling code in com.c. There would be a little duplication, but it would be cleaner than trying to shoehorn this into the JOY_ interface.
Cool, i also prefer see that in COM_ than JOY_ even if there is a bit of duplication :)
I'll merge with what I'm working on. I'll probably be another week with finishing out the menacer support along with adding COM. COM will also use the external int.
No problems take your time ! You are actually a lot faster than me :p
I will probably fix the waitXXX methods as suggested in the other topic.
And i'm still working on my bad apple video when i have a bit of time but it progress so slowly that i really wonder if i will get it done somedays :p

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Sat May 26, 2012 12:23 pm

If you're able to make a full working COM port, I'll be very interested !
I'm working on some dev stuff using EXT port, which need COM communication...

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat May 26, 2012 5:22 pm

Stef wrote:Cool, i also prefer see that in COM_ than JOY_ even if there is a bit of duplication :)
Right! Sounds like the way to go. :D
No problems take your time ! You are actually a lot faster than me :p
I will probably fix the waitXXX methods as suggested in the other topic.
And i'm still working on my bad apple video when i have a bit of time but it progress so slowly that i really wonder if i will get it done somedays :p
I know what you mean. I still have some tests to do for 32X video decompression I need to work on.
KanedaFr wrote:If you're able to make a full working COM port, I'll be very interested !
I'm working on some dev stuff using EXT port, which need COM communication...
The communication is as I described above - a way to send nibbles between two MDs thru a cable connected to a controller port on each. Stef suggested the name COM for the functions, but it could just as easily be NET or ZTC. It's nothing to do with the EXT port on older Model 1 MDs, or to do with serial, or to do with communicating with a PC. You might check out the Technopop web site if you haven't or don't remember them too well:

http://www.technopop.net/

KanedaFr
Administrateur
Posts: 1139
Joined: Tue Aug 29, 2006 10:56 am
Contact:

Post by KanedaFr » Sat May 26, 2012 9:37 pm

Yes, I know the ZT cable... I though you were also working on a COM (serial) lib, which the ZT cable will use
Sorry, my happyness made me half-blind LOL

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sat May 26, 2012 10:34 pm

KanedaFr wrote:Yes, I know the ZT cable... I though you were also working on a COM (serial) lib, which the ZT cable will use
Sorry, my happyness made me half-blind LOL
The ZT cable isn't capable of serial as it cross wires the TH and TR lines. Serial would require cross wiring TL and TR. Serial is limited to 4800 baud, so you can see why they thought transferring nibbles to be better than serial. Serial would have been easier to deal with for low bandwidth data streams.
:(

HardWareMan
Very interested
Posts: 745
Joined: Sat Dec 15, 2007 7:49 am
Location: Kazakhstan, Pavlodar

Post by HardWareMan » Sun May 27, 2012 11:43 am

I researched ZT protocol a long time ago. First, when you press the "start", the console puts a request to link on couple of seconds. If there is no answer - goes into the slave mode, if the answer comes - it becomes the master.
The protocol is simple enough. Set data nibble, then toggle request and wait toggle of answer. Then process repeats.
The first 4 nibbles is a WORD that size of the package. Then the package itself. Last one goes simple checksum. Then do toggle request to change of direction. The response packet has the same structure. Packet sizes are not large. The total window of time is about 16ms. If the package is not passed on time - there is a common timeout and data are ignored. Timeout for a few sessions in a row leads to a loss of communication.
Very, very curious thing, I tell you. I researched it in order to find a way to transfer data at a greater distance than 5 meters of cable (yes, I have a cable, built it myself), the ideal transmission Ethernet at the MAC frames. If it possible, I will show you results here. ;)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun May 27, 2012 6:27 pm

Good description - that's pretty much how I planned to handle it myself. We don't need to be identical to how ZT does it, but what you describe is about the most efficient and simple way to do it. Do you know how they do the "checksum"? I was just planning on adding all the bytes together. That's the most common simple "checksum" you tend to find. :lol:

I like the way they decide who will be master/slave - just whoever starts the game first is slave. Very simple. 8)

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Thu May 31, 2012 6:18 pm

I got a Menacer and have added support - I have no trouble with the position, but the buttons don't read. I'm assuming that after you trigger the "long reset" which they say is needed to read the buttons, then you have to wait until the IR sensor gets the buttons from the gun. Any idea on how long that is? The lightgun pdf just says to trigger the long reset at the start of the vertical blank, read the buttons (it makes it sound like you can read them immediately, but that doesn't return any data), then trigger the short reset at the end of the vertical blank in preparation for reading the beam position.

So far, I've tried immediately, and after ~100 usecs. No buttons.

Eke
Very interested
Posts: 884
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Thu May 31, 2012 11:44 pm

As said in introduction, this document is based on the analysis of lightgun games (T2 : arcade game and menacer game pack), not from using a real menacer so i may have missed something like an init sequence required to acquire buttons data.
The "reset" stuff come from reading the patent, i tried to guess how this was related to TR/TL outputs but it might be incorrect as well.

Have you tried doing the exact same sequence as detailled in the pdf regarding TR/TL (11 - 01 - 11 - 01) before reading data port ? As far as i recall, read was pretty much imediate or at least following data port writes in the same subroutine with relative short delay. Maybe doing a "counter reset" (11-00-11) is required first, i don't know.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Fri Jun 01, 2012 1:55 am

Thanks, but I looked at T2 and Body Count (they both use the same code) to see what was going on. The pdf has WHAT you need to do right, but no timing, which is CRITICAL on the Menacer. It's a persnickety piece of junk. :lol:

Getting the position is no problem, but to get the buttons, in the vertical blank you have to first do a mandatory wait... why? Because when the gun is at the bottom of the screen, you're so close to the vblank that the gun needs more time as a gap between the position IR signal and the button IR signals. Then you disable reset, wait a small time, enable the long reset and wait just long enough for the Menacer to reset, then disable reset and almost immediately enable long reset again. Then wait about 1.5 msec (yes MILLISECONDS) for the buttons to be read and read them. Then disable reset and almost immediately enable short reset to clear the beam position counter.

Notes: The buttons seem to have troubles at the edges of the screen... all of them. They are only stable on screen, and well offscreen. At the edges, you get glitchy buttons. Also, when START is pressed, you ALWAYS get another button (A or B 99% of the time) at the same time, and no other buttons respond (you cannot press START + C, for example). A, B, and C are no problem and can be pressed in any combination. When START is pressed, I guess you're supposed to just ignore all the other buttons. My current code returns the codes just as reported, which means START + B or START + A.

The Justifier is a MUCH better lightgun, having none of these issues. The Menacer needs to be treated with kid gloves.

Here's the current code and the sample app. There are three binaries: "trackball2.bin" sets port 2 to trackball mode (which works great - just like a mouse), "blue2.bin" only sets blue gun support on port 2 if a justifier is there (you have both guns in port 1), and "both.bin" which uses both guns on either port for the justifier.

Supported and tested on real hardware (in either port):
3 button pad
6 button pad
megamouse
team player (up to eight controllers)
menacer
justifier (one or two guns)
trackball

There's also code for the EA 4-Way-Play, but I can't really test it as I don't have one.

Emulator notes: Neither Gens/GS nor Fusion 3.63 report a correct ID for the TeamPlayer - they both report ID 0, which is a Menacer. So neither emulator works with TeamPlayer with this code. The ID code is standard and works on real hardware, so it's clearly a bug in both emulators. The Menacer and Justifier support in Fusion works with this code just fine. Pads and mice also work fine. So it's only multitap that's currently an issue in the emulators.

http://www.mediafire.com/?7zekr7duerwb09i

Stef: I can commit the code to the repo if you want... it's just joy.c and joy.h that changed. I worked from the latest rev (58 ). I noticed while compiling the library that timer.c reports an implicit declaration of SYS_isInVIntCallback(). It still compiles, but you might want to add the include file to avoid the warning.

Further notes: The trackball cannot be IDed - the first time you run the standard ID, it reports 0x0F (unknown), and every time after that until you power off, it reports 0x00 (Menacer). I had to put special conditions into the menacer support to distinguish between enabling the Menacer support and enabling the trackball support. So if you want to use a trackball in port 2, you just do JOY_setSupport(PORT_2, JOY_SUPPORT_TRACKBALL); and hope the user plugged a trackball into port 2. But it does work nice!

EDIT: Actually, Gens/GS's EA 4-Way Play support DOES work with this code, but a slight booboo makes it think there's two Menacers in place. In JOY_init(), you find

Code: Select all

        /* EA 4-Way Play detected */
        portSupport[PORT_1] = JOY_SUPPORT_EA4WAYPLAY;
        portSupport[PORT_2] = JOY_SUPPORT_OFF;
needs to be

Code: Select all

        /* EA 4-Way Play detected */
        portType[PORT_1] = PORT_TYPE_EA4WAYPLAY;
        portType[PORT_2] = PORT_TYPE_EA4WAYPLAY;
        portSupport[PORT_1] = JOY_SUPPORT_EA4WAYPLAY;
        portSupport[PORT_2] = JOY_SUPPORT_OFF;
You can see I forgot to set the portType when I discovered the EA 4-Way Play.

Note: Gens/GS always acts like there's an EA 4-Way when you turn on TeamPlayer/EA 4-Way support on port 1. There's no choosing one or the other. It also doesn't ID TeampPlayer correctly. Looking at the io code in Gens/GS for TP, it doesn't check if the direction register is 0x40 (which means it's doing the ID) or 0x60 9which means it's doing a transfer); it just assumes it's doing a transfer and so returns the wrong values for the ID code.

EDIT 2: Checking in Fusion, it has the same issue with EA 4-Way Play - it DOES work, but thinks there's two menacers. The fix above should fix Fusion as well as Gens/GS.

EDIT 3: Again in Fusion, TeamPlayer is now working... not sure why. Maybe I just goofed setting the settings the first time I tested it. So TeamPlayer IS working in Fusion. Sorry about any confusion.
:lol:

Post Reply