XBAND, Mega Net 2, and Mega Drive Keyboards

Ask anything your want about Megadrive/Genesis programming.

Moderator: BigEvilCorporation

Natsumi
Very interested
Posts: 82
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Natsumi » Tue Dec 27, 2016 7:05 pm

Hello, we are doing some research, and investigating if it would be possible to be able to acquire a keyboard and a ROM to verify it works, write few test ROMs and documentation, and in the end get it emulated on emulators that are currently being worked on (GPGX comes to mind first). The cool thing is, we found a repo for what appears to be XBAND source code(!), which would help a lot after we have acquired the keyboard, to write code to interact with it. However, after analyzing the JP BIOS (because US does not seem to be dumped), it does not appear to match the source. (Because of few interesting strings that are supposed to exist in it, and some basic disassembly I did) I can not verify this 100%, because I know nothing about compiling C code for Genny. Also, newer tools may not help, but I believe this page may have download with appropriate tools. I would appreciate if someone would help compiling it into a binary for comparisons. Furthermore, if indeed the JP XBAND does not match, I would want to know if anyone can dump an US version. My friend told he can help in getting one. If we can dump the ROM, and verify the source code in fact is from XBAND, we can be sure a keyboard accessory exists or should exist. It is also likely, that the Tectoy's keyboard in Brazil is same or similar in nature! So next, is the hard part; getting a keyboard and compatible cart to test on, and of course writing code to read the keyboard stats, write to it, etc. When I can get enough money, I am willing to either borrow, or buy one in order to write code, test, and document it. We have located one Mega Net 2 unit with the keyboard, however this is from a collector and we are yet unaware if he is willing to help us.

So, based on the knowledge I have atm, the plan of action is as follows:
*Compile this source code and compare it with available dumps of XBAND
*Dump US XBAND (or XBAND 2 if it makes a difference)
*Compare the US XBAND dumps with the compiled source
*Acquire a keyboard that is meant for Mega Net 2 or XBAND, and a cart that the keyboard will work with
*Poke at the bastard thing to find out how it works, write sample code and documentation
*Annoy emu authors about this until they implement it in their emulators >=)

Now, any additional information about this would be appreciated as well'
(Oh, on a side note, the source code is hilarious and you should read it. It makes me feel it was non-professionals work though which makes me question it a bit)

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Sik » Wed Dec 28, 2016 6:56 pm

There's no XBand dump as far as I know, the one labeled "Japanese" is actually Game Library (Toshokan) which has nothing to do with it.

And yeah I had gone over the keyboard code long ago, it relies on an adapter to connect an AT keyboard to the console:

Code: Select all

REQUIREMENTS:

   - TH and TR are always output
   - TL is always input
   - Other bits depend on action

HANDSHAKE:

   - Set TH and TR high ($60)
   - Wait a bit (two NOPs)
   - Read bits 3-0 (should be %0011)
   
   - Set TH low, TR high ($20)
   - Read bits 3-0 (should become %1100)
   - Keep reading if still not %1100
   
   - Set TH and TR low ($00)
   - Wait until TL goes low
   - Read bits 3-0 (should be %0110)

READING:

   - Do handshake
   - Make bits 3-0 input lines
   
   - Set TH low, TR high ($20)
   - Wait until TL goes high
   - Read bits 3-0 (count)
   
   - Do this "count" times:
      - Set TH low and TR ($00)
      - Wait until TL goes low
      - Read bits 3-0 (high nibble of byte)
      
      - Set TH low, TR high ($20)
      - Wait until TL goes high
      - Read bits 3-0 (low nibble of byte)
   - (loop end)
   
   - Set TH and TR high ($60)
   
WRITING:

   - Do handshake
   - Make bits 3-0 output lines
   
   - Set bits 3-0 to %0000
   - Set TH low, TR high ($20)
   - Wait until TL goes high
   
   - Set bits 3-0 to %0001 (2)
   - Set TH and TR low ($00)
   - Wait until TL goes low
   
   - Set bits 3-0 to %0000
   - Set TH low, TR high ($20)
   - Wait until TL goes high
   
   - Set bits 3-0 to %0000
   - Set TH and TR low ($00)
   - Wait until TL goes low
   
   - Set bits 3-0 to high nibble of byte to write
   - Set TH low, TR high ($20)
   - Wait until TL goes high
   
   - Set bits 3-0 to low nibble of byte to write
   - Set TH and TR low ($00)
   - Wait until TL goes low
   
   - Make bits 3-0 input lines (or set them to %1111?)
   - Set TH and TR high ($60)

ABORT:

   - Set TH high, TR low ($40)
   - Wait a while
   - Set TH and TR high ($60)

NOTES:

   - Keyboard seems to use the same scancodes and commands as AT keyboards
   - Command $FF (no arguments) initializes the keyboard
   - Command $ED (one byte arg.) sets the keyboard leds
Sik is pronounced as "seek", not as "sick".

Natsumi
Very interested
Posts: 82
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Natsumi » Wed Dec 28, 2016 8:16 pm

Yeah, I was not quite sure so I went with what the dumps say. However it seems really apparent they are not related. As far as that doc, I had a look at it earlier, but I can't confirm it is correct, and I can't therefore also create a test ROM to use without the keyboard, which is why I'd like to have it.

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Mask of Destiny » Fri Dec 30, 2016 8:14 pm

I have a US XBAND, but I've had some trouble dumping it on my current setup (modified Retron 5). It's possible it depends on a signal that is not present on that device. Doing a proper dump is on my todo list, but hasn't been a priority and requires either new hardware or fixing one of my Sega CDs.

Was the XBAND keyboard adapter ever released? I was under the impression it never got past the prototype stage. I think the only keyboard peripheral (as in actual keyboard, not the ten key pad) that actually got released was the one made by Tec Toy for the Brazilian version of Meganet. Those keyboards do not seem to be easy to find outside of Brazil unfortunately. There's one on Mercado Libre presently. I'd be tempted to buy it, but I'd need someone in Brazil to act as my proxy.

The Saturn keyboard adapter can be used with the Megadrive/Genesis with a passive Saturn -> DB9 adapter. Saturn controller connectors are a pain to get (I hacked one off of a Saturn controller -> USB adapter), but the keyboard adapter is easy to acquire.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Sik » Sat Dec 31, 2016 3:12 am

Mask of Destiny wrote:I have a US XBAND, but I've had some trouble dumping it on my current setup (modified Retron 5). It's possible it depends on a signal that is not present on that device. Doing a proper dump is on my todo list, but hasn't been a priority and requires either new hardware or fixing one of my Sega CDs.
Maybe it's tripping on bank switching? (it needs to runs the games somehow, you know) Also I forgot to which addresses the modem was mapped, but you probably don't want to touch those either. You'll probably need to get it do a smaller dump.
Mask of Destiny wrote:Was the XBAND keyboard adapter ever released? I was under the impression it never got past the prototype stage.
I have no idea, I only ever found a single page mention it years ago (source code aside) and it said they had gotten some Korean company make an adapter with a microcontroller (EDIT: nevermind, only the components were Korean :P). That's as far as we know.

Google is of no help, it likes to ignore keywords at random now (usually the most important ones at that, argh - good job making it hard to find obscure information! -_-)

EDIT: omfg my past self saved my ass this time:
http://www.brouhaha.com/~eric/pic/segakb.html

EDIT 2: well shit it exists http://xband411.tumblr.com/post/8028173 ... manual-and
At least assuming that box isn't a fake. Can confirm the SNES keyboard though, it comes up everywhere.
Sik is pronounced as "seek", not as "sick".

cero
Very interested
Posts: 338
Joined: Mon Nov 30, 2015 1:55 pm

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by cero » Sun Jan 01, 2017 5:22 pm

Lots of Brazilian sega fans on sega-16?

Nemesis
Very interested
Posts: 791
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Nemesis » Thu Jan 05, 2017 12:36 am

I did a dump from my XBAND about a billion years ago. Here it is:
http://www.filedropper.com/xband
That would have been dumped by loading a resident dumping program into RAM and effectively "hotswapping" the XBAND into the cartridge slot. I believe the XBAND does its own address decoding or something of that nature, so it needs to be mapped in at 0x0. Don't expect the ROM to do much of anything by itself though. It's trying to handshake with its own custom hardware. I just spun it up in a debugger to take a look, and it seems the cartridge itself relies on being "mirrored" to 0x020000 at the very least, and there's some kind of hardware mapped in around 0xFF00 or there abouts its waiting on. A good step would probably be to open it up and trace the address bus mappings, to confirm what is mapped where.

Nemesis
Very interested
Posts: 791
Joined: Wed Nov 07, 2007 1:09 am
Location: Sydney, Australia

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Nemesis » Thu Jan 05, 2017 12:41 am

Took a look at the source you linked, I can definitely confirm it's related to the XBAND ROM I dumped, some magic strings are present in both the source and the ROM.

Natsumi
Very interested
Posts: 82
Joined: Mon Oct 05, 2015 3:00 pm
Location: 0x0
Contact:

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Natsumi » Thu Jan 05, 2017 11:41 am

Awesome, thank you! The point of getting the ROM was not to play it, but to verify a few things, and if needed, extract the machine code out of it.

GeoffLedak
Interested
Posts: 16
Joined: Thu Jan 05, 2017 10:14 pm

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by GeoffLedak » Sat Jan 07, 2017 5:38 am

Hey everyone, new guy here.

I've been doing some research for the past week or so on how I can interface a keyboard with the Genesis. I have learned that the XBAND modem ROM includes keyboard support and my current plan is to attempt to simulate the keyboard protocol with an Arduino Uno microcontroller. I currently have the Arduino properly simulating a 3 button controller and I bought a used XBAND modem on ebay for testing which I should receive next week.
Sik wrote:EDIT: omfg my past self saved my ass this time:
http://www.brouhaha.com/~eric/pic/segakb.html
Hey Sik. I'm ChEeZeBaLL on the Sonic Retro forum and I resurrected your keyboard thread a few days ago.
Sik wrote:EDIT 2: well shit it exists http://xband411.tumblr.com/post/8028173 ... manual-and
At least assuming that box isn't a fake. Can confirm the SNES keyboard though, it comes up everywhere.
Oh wow! As far as I knew the keyboard only existed as a prototype in the United States, that thought was based off of this post:
http://xband411.tumblr.com/post/7280850 ... rd-were-on

The post that you linked to looks pretty legit with the box and all, perhaps it was released in the US in very limited quantities.

I was unsure if the keyboard released in Brazil used the same protocol. The fact that it looks identical to the XBAND keyboard minus the logos makes me pretty positive that they are the same.

As I mentioned in my post on the Sonic Retro forum, the keyboard routines are located in SegaOS/GameLib/controls.c of the XBAND source:
https://github.com/X-Band/SegaOS/blob/m ... controls.c

According to Eric Smith, "The keyboard interface plugs into the second controller port on the Genesis, and uses a four bit bidirectional bus with handshaking. The protocol is similar to what is used by the Sega Team Player adapter."

The high level explanation of the keyboard protocol that Sik provided is helpful; thanks for that.
Natsumi wrote:So, based on the knowledge I have atm, the plan of action is as follows:
*Compile this source code and compare it with available dumps of XBAND
After looking through the source, it doesn't appear to be complete. For instance, GameLib/controls.c imports a header file called "SegaOS.h" which doesn't appear to be included with the source release. I don't think you'll be able to compile your own complete ROM, but we should have everything we need regarding the keyboard in controls.c

It looks like the function that would be part of the main program loop for reading input is _ControllerVBL (line 184). According to the comment at the top of the function: "to avoid sucking down too much CPU, we do a few things based on a phase counter. We read the controls 15 times per second (instead of 60), and every two seconds, we replace a controller read with a controller-type sample. This allows the user to change controllers and we'll figure it out."

_ControllerVBL calls a function called FindESKeyboard which is defined on line 559. This function appears to handle the handshaking.
_ControllerVBL also calls functions called ReadESKeyboard and WriteESKeyboard, defined on lines 752 and 848. I believe these functions handle reading key presses and I'd assume setting the keyboard status lights (such as caps lock) [someone please correct me if I'm wrong about this].

I have this somewhat crazy dream of building a simple command line operating system for the Genesis (think IBM PC DOS 1.0). My first goal is to successfully simulate keyboard input with the XBAND. If I can successfully simulate the keyboard protocol, my next step would be to build my own simple ROM that would allow keyboard input and typing text onto the screen. The next step from there would be to develop a simple file system.

If I ever get all that working, the final step would be to develop a Genesis ethernet interface that would plug into the cartridge slot, and then chat on IRC with it. Why? Because why not? :)

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Sik » Sat Jan 07, 2017 1:15 pm

GeoffLedak wrote:I was unsure if the keyboard released in Brazil used the same protocol. The fact that it looks identical to the XBAND keyboard minus the logos makes me pretty positive that they are the same.
Meganet also embeds its modem in the cartridge just like XBAND does. Makes me wonder if Meganet is reusing the same technology from XBAND for both modem and keyboard.
GeoffLedak wrote:According to Eric Smith, "The keyboard interface plugs into the second controller port on the Genesis, and uses a four bit bidirectional bus with handshaking. The protocol is similar to what is used by the Sega Team Player adapter."
Yeah, although according to that page it's implied it was a separate adapter ("an interface between the Sega Genesis game system and an IBM-compatible keyboard"). I'm going to guess that they decided to embed it into the keyboard directly at some point, as this looks to have been written while it was still under development.
GeoffLedak wrote:After looking through the source, it doesn't appear to be complete. For instance, GameLib/controls.c imports a header file called "SegaOS.h" which doesn't appear to be included with the source release. I don't think you'll be able to compile your own complete ROM, but we should have everything we need regarding the keyboard in controls.c
Yeah the code is not complete - in particular, the modem code is completely missing x_x (now you know why I had focused all my efforts on the keyboard instead)
GeoffLedak wrote:It looks like the function that would be part of the main program loop for reading input is _ControllerVBL (line 184). According to the comment at the top of the function: "to avoid sucking down too much CPU, we do a few things based on a phase counter. We read the controls 15 times per second (instead of 60), and every two seconds, we replace a controller read with a controller-type sample. This allows the user to change controllers and we'll figure it out."
Yeah, that part was stupid >.> (reading controllers is cheap, jeez)

Also there's code to simulate the controllers through the keyboard, albeit it doesn't look like the XBAND one. I think that they had written it so they could test the program on a computer during development (hence the keyboard acting as a placeholder for a controller).
GeoffLedak wrote:I have this somewhat crazy dream of building a simple command line operating system for the Genesis (think IBM PC DOS 1.0). My first goal is to successfully simulate keyboard input with the XBAND. If I can successfully simulate the keyboard protocol, my next step would be to build my own simple ROM that would allow keyboard input and typing text onto the screen. The next step from there would be to develop a simple file system.
Sowwy (・ω・`) (though I may redesign the UI a bit)

EDIT: broke all the quote blocks x_X
Sik is pronounced as "seek", not as "sick".

GeoffLedak
Interested
Posts: 16
Joined: Thu Jan 05, 2017 10:14 pm

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by GeoffLedak » Sat Jan 07, 2017 9:09 pm

Sik wrote:Sowwy (・ω・`) (though I may redesign the UI a bit)
Very impressive. I may be passing several questions your way.

Something that I was curious about that you might know the answer to: I noticed that some of the XBAND source code includes inline assembly which uses a simple syntax with the asm keyword and curly brackets:

Code: Select all

	asm
		{
		move.l		#0,sp
		move.l		sp,a6
		move.l		sp,usp
		link		A6,#0x0000
		}
Do you know which compiler they might have been using, or any other that supports that syntax? It's very easy to read.

EDIT: There's a comment on line 98 of ROMMain.c which mentions the PsyQ development system; perhaps they were using the PsyQ Mega-CD SDK (I don't know if that provides any clues regarding my question above).
Last edited by GeoffLedak on Sun Jan 08, 2017 4:57 am, edited 1 time in total.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by Sik » Sun Jan 08, 2017 2:41 am

That particular snippet seems to be resetting the stack (i.e. removing everything that was on it). Is that some sort of init code or the like?

EDIT: also no, no idea which compiler it is =P
Sik is pronounced as "seek", not as "sick".

GeoffLedak
Interested
Posts: 16
Joined: Thu Jan 05, 2017 10:14 pm

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by GeoffLedak » Sun Jan 08, 2017 2:58 am

Sik wrote:That particular snippet seems to be resetting the stack (i.e. removing everything that was on it). Is that some sort of init code or the like?

EDIT: also no, no idea which compiler it is =P
Yeah it's some code to reset the stack at the very beginning of main() in ROMMain.c. I just grabbed it as an example of the inline assembly syntax.

Here's the complete main function for context (I had a pretty good laugh at the variable names and comments):

Code: Select all

main( short fucker )
{
short	generateLinkFucker;

	asm
		{
// this shit puts the psyq in writeable mode
//		moveq		#0,d0
//		dc.w		0xa008
		
		/* reset the stack to unfuck the sega crap. (sega seems to like to put the stack */
		/* at 0xfffff200). We may want to think about moving ours... */
		
		move.l		#0,sp
		move.l		sp,a6
		move.l		sp,usp
		link		A6,#0x0000
		}

	/* call the real os startup code. we should never return from here... */
	BootStrap ();
			
	/* reference these so they goes in the link map */
	DefaultException();
	DispatchToProc();
}

jtn0514
Interested
Posts: 17
Joined: Sat Dec 28, 2013 9:33 pm

Re: XBAND, Mega Net 2, and Mega Drive Keyboards

Post by jtn0514 » Mon Jan 23, 2017 6:31 pm

MegaNet2 IS xband basically. the cartridge is slightly different obviously but its the same os, and there is some info about catapult striking a deal with tectoy in brazil on this.

Post Reply