Tuesday, October 16, 2012

Non-volatile N64 Controller Pak

Ever since I read this post on the BenHeck forums about modding an N64 Controller Pak to eliminate the need for a battery to maintain the save data.  I decided to take it one step further and build one from scratch.  The first step was to draw up the schematic for the existing Controller Pak, and modify it from there.  For that, I needed a pinout for the card edge.  I found one with a few errors, used it to fill out the schematic, and determined the function of the remaining contacts from there.  Here's the working pinout:

  Pin   Name
--------------
  1     GND
  2     A14
  3     A12
  4     A7
  5     A6
  6     A5
  7     A4
  8     A3
  9     A2
  10    A1
  11    A0
  12    D0
  13    D1
  14    Detect*
  15    3V3
  16    D2

  17    GND
  18    CE1
  19    /CE2
  20    /WE
  21    A13
  22    A8
  23    A9
  24    A11
  25    /OE
  26    A10
  27    D7
  28    D6
  29    D5
  30    D4
  31    3V3
  32    D3

The Detect line is pulled low inside the controller through a pull-down resistor.  The Controller Pak connects Detect to 3V3 to indicate the presence of a cart in the slot (this is true for both the Controller Pak and the Rumble Pak;  the controller determines which type of cart it is by strobing a specific address and reading the response).

From this, it's fairly trivial to connect an FRAM chip in place of the original SRAM.  I chose to use the Ramtron FM28V020, though the any of the FM18*08 chips should work as well.  If we don't really care about the dual CE lines, we can ignore CE1 and connect /CE2 directly to the RAM.  After that, all that is needed is a pull-up resistor on the /CE line (10Kohm is a good value) and a smoothing cap between 3V3 and GND (100nF is good).

I'll be working on a 4x version soon, using a 1Mbit FRAM chip (Ramtron FM28V100).  The basic wiring for this is the same as above, but add pull-up resistors on the A15 and A16 lines, then connect those lines to a 4-position switch that connects to GND.  Use diodes to isolate the connections between the address lines and the switch, since one position on the switch will pull both lines to GND, but you don't want *every* position to do that.

If you'd like to buy a pre-assembled, nonvolatile N64 Controller Pak (1x or 4x), shoot me an email.  I have a lot of extras sitting around...

Wednesday, August 29, 2012

Progress on Parallel Worlds

Well, in case you haven't seen it (or haven't seen it recently), head over to http://parallelworldsmaps.appspot.com to check out the new visual overhaul I've finally given to my mapping project for the game Legend of Zelda: Parallel Worlds.  For those of you who don't know, Parallel Worlds is a ROM hack of Legend of Zelda: A Link to the Past, resulting in a completely new game, with all an all-new story, fully redone dungeons and maps, and some minor graphical changes to go with all that.  The game is HARD.  Like, Contra hard.  And what's worse is, because the map and dungeons are all new, there aren't any maps to show you where everything is when you inevitably get lost.  I have found a single walkthrough floating around on the internet that has maps, but other than that, you're s.o.l.  So, I took it upon myself to map the entire game, in full, lossless resolution.  After completing the Light World Overworld map (well, I still have some touch-up work to do...), I discovered an awesome piece of software called Worldkit which would allow me to turn my shiny new really-big-picture into a fully interactive map with zoom and pan, as well as geotag annotations for tagging items and important landmarks.  So I got it all loaded up and decided to host it on Google's App Engine framework (which is kind of a weird use of the App Engine framework, but there are plenty of other people hosting static websites on GAE, so whatever...).  As of yet, I can't seem to get annotations working on the web (they work great on the local dev server that comes with the GAE SDK... frustrating), but I have finally gotten around to giving the page itself a facelift from the previous blank-page-with-embedded-flash-object-slapped-into-the-corner.  It is now a presentable web page, with a nice template that will allow me to easily deploy new pages as I finish the maps.  Also, speaking of finishing maps, I managed to map all of Din's Catacombs, which is a pretty nice achievement (if I do say so myself) in that the entire dungeon is normally pitch-black, making mapping via screenshot extremely tedious at best and nearly impossible at worst.  The walkthrough I mentioned earlier with screenshots of all of the dungeons actually doesn't have one for Din's Catacombs.  So I may be the first to have mapped it.  Go me :)  Anyway, the Din's Catacombs page is a bit of a mess right now, I was trying out a different template which really isn't working so well, but I'll fix it up soon.  I've also started work on the Icy World Overworld map, which I currently have about 20% complete, so hopefully that will be online soon as well.

Friday, August 17, 2012

New Zelda: Parallel Worlds Interactive Map

I have discovered a means to make my Zelda Parallel Worlds mapping project much more interesting and useful by creating a fully interactive map with navigation and annotation features using an awesome piece of software called WorldKit.  I am hosting the project using Google's App Engine framework, and have uploaded my current Light World overworld map to test the software and deployment functionality.  I have not yet added any annotations (and I probably won't until I have the Icy World map done), but you can test the zoom and pan features.  Unfortunately, the zoomify software I'm using to generate the zoom tiles only works with JPEG images, so it does get lossy at full zoom, but I suppose that's really the best route to go anyway, then I can offer the full-resolution, lossless PNG for download from a separate link.  I'm still brushing up on my HTML so I can actually have a nice page rather than the current blank page with the embedded map viewer.  It's a work in progress, but check it out at http://parallelworldsmaps.appspot.com/

Tuesday, July 24, 2012

The Legend of Zelda: Parallel Worlds Mapping Project

I've decided to undertake the mapping of the Zelda 3 ROM hack called Parallel Worlds.  Being a hack, not a lot of documentation exists out there other than a few walkthroughs, almost all of which are exclusively text-based, and many of which are incomplete.  I've decided to create a full-resolution map of all areas of the game, starting with the overworld(s) and then moving on to the dungeons.  So far, I have a significant portion of the Light World Overworld completed, and so I've decided to start a page to publish my progress.  You can check it out here.  You can check out the hack's homepage at https://sites.google.com/site/zeldaparallelworlds/

Friday, July 13, 2012

Arduino HID Gamepad, part 1

Note: This post mostly outlines my shield design and a quick test of the hardware using the Mouse example included with the Arduino library.  If you're looking for the actual HID gamepad implementation, have a look at part 2

I have been thinking for quite some time about a project which I hope to shape into a Senior Project for my Embedded Systems and Software Engineering degrees, but I've gotten a bit impatient and have kind of jumped the gun to start working on it.  The first step in this project requires implementing a generic HID gamepad.  The Arduino Leonardo recently launched with USB HID profile support, thanks to the on-chip USB support of the on-board Atmega32U4 microcontroller.  This makes prototyping much simpler, and it actually reduces the cost of the Leonardo compared to the Uno--which is otherwise the most comparable Arduino model out there--due to not needing a separate microcontroller to handle the USB-serial connection.  Now, I know there are a lot of Arduino haters out there, but the fact is, it is fantastic for prototyping.  I get as annoyed as anybody when I see somebody enclose an entire Arduino into a finished product rather than redesigning for the bare microcontroller (which I fully intend to do), but it's a nice prototyping platform with great community support.

Anyway, I got my Leonardo today and immediately loaded up the button mouse example sketch to try it out and lo and behold, it just worked.  Well, it would have just worked if I had built the circuit the way I was supposed to.  As it was, I didn't feel like breadboarding it with pull-down resistors, so I changed the code around to enable the internal pull-up resistors and then changed the logic to be low-triggered rather than high-triggered:


const int upButton = 2;     
const int downButton = 3;        
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;

int range = 5;     // output range of X or Y movement; affects movement speed
int responseDelay = 10;     // response delay of the mouse, in ms

void setup() {
  // initialize the buttons' inputs:
  pinMode(upButton, INPUT);       
  pinMode(downButton, INPUT);       
  pinMode(leftButton, INPUT);       
  pinMode(rightButton, INPUT);       
  pinMode(mouseButton, INPUT);
  
  digitalWrite(upButton, HIGH);
  digitalWrite(downButton, HIGH);
  digitalWrite(leftButton, HIGH);
  digitalWrite(rightButton, HIGH);
  digitalWrite(mouseButton, HIGH);
  
  // initialize mouse control:
  Mouse.begin();
}

void loop() {
  // read the buttons:
  int upState = digitalRead(upButton);
  int downState = digitalRead(downButton);
  int rightState = digitalRead(rightButton);
  int leftState = digitalRead(leftButton);
  int clickState = digitalRead(mouseButton);

  // calculate the movement distance based on the button states:
  int  xDistance = (leftState - rightState)*range;
  int  yDistance = (upState - downState)*range;

  // if X or Y is zero, move:
  if ((xDistance == 0) || (yDistance == 0)) {
    Mouse.move(xDistance, yDistance, 0);
  }

  // if the mouse button is pressed:
  if (clickState == LOW) {
    // if the mouse is not pressed, press it:
    if (!Mouse.isPressed(MOUSE_LEFT)) {
      Mouse.press(MOUSE_LEFT); 
    }
  } 
  // else the mouse button is not pressed:
  else {
    // if the mouse is pressed, release it:
    if (Mouse.isPressed(MOUSE_LEFT)) {
      Mouse.release(MOUSE_LEFT); 
    }
  }

  // a delay so the mouse doesn't move too fast:
  delay(responseDelay);
}


Anyway, the next thing to do was to build myself a gamepad that I could plug in to the Leonardo for testing.  I plan to use the SNES controller in my final project, but for prototyping, I decided to go with NES instead.  The NES uses the exact same control protocol as the SNES, just with fewer buttons, so that meant fewer parts, as well as fewer IO pins for my debug setup.  I had a few empty protoshields lying around, so I figured that would be perfect for this build.  I also had a CD4021 shift register in my parts drawer from an NES controller I cannibalized awhile back.  If you're looking to build a DIY NES controller, please, for heaven's sake, just go out and buy a 4021 and a few resistors and do it from scratch.  Don't destroy an NES controller just for its IC.  I've seen so many awesome mods that just piss me off because after all that hard work, they have this wiring on the inside.  Seriously, this is all you need (plus a couple of resistors).  Or, if you want to get really fancy, hit me up for one of these (scroll down to my last post for a picture with a size comparison to an SD card.  Anyway, despite that rant, I used the IC from an original controller, because I had already used the rest of the controller for various other stuff, and happened to have the IC left over.  I have a stash of the SMD 4021's, but alas, the protoshield's SOIC footprint is only 14 pins, so I needed the DIP version, and this one was the only one I had.

Ok, now that I'm done with that rant, time for pictures :)

I ran out of solder, so nothing is connected yet.  However, all of the parts are mounted, so I just need to get more solder (and perhaps some finer gauge wire than what I have on hand at the moment would be good too).  Apparently, RadioShack no longer carries through-hole mounted tact switches, but thankfully, the spacing on the SMD feet lined up well enough with the board holes.  The plan is to hook each button up directly to a digital I/O, as well as hooking them up to the 4021 and connecting its latch, clock, and data lines to the remaining digital IO's in order to implement the NES protocol as well.  This way, I can read the buttons either directly or via the NES protocol all from the same shield configuration.


Also, in case you're looking for the correct stacking headers for the Arduino shields, I've managed to track down a manufacturer that makes them.  Unfortunately, the stackable header kits on SparkFun and elsewhere don't actually have the right pin counts.  They sell kits with 2x6-pin headers and 2x8-pin headers.  Arduino shields actually use 1x6, 2x8, and 1x10.  You don't, strictly speaking, need the other four pins, but all of the official shields have them.  Digikey carries these headers, but they don't seem to carry them with tails quite as long as the ones on official shields.  There's not a lot of clearance with the ones I have.  So anyway, here are part numbers for the headers that you'll want, they aren't quite the same as the ones Digikey has (DK carries the -03 variety rather than the -04, which I explain below).


Samtec
1x10 pins: SSQ-110-04-T-S
1x8 pins: SSQ-108-04-T-S
1x6 pins: SSQ-106-04-T-S


Some variations on these part numbers:
-04 is the length of the tail.  -03 or shorter will make for very little clearance above the barrel jack.  On the older boards with full-sized USB-B plugs, you won't be able to clear the USB jack.  However, Digikey doesn't seem to carry anything longer than -03.  If you can find another distributor that stocks the longer tails, let me know in the comments


-T is tin plated pins, replace it with -G for gold plated.
The -110, -108, and -106 are the pin count.  If you want dual row, the numbering is -2XX (i.e. -205 would be 2x5 pins, etc.).

Anyway, that's it for now.  I'm super busy working two jobs this summer, so hopefully I'll get some free time now and then to work on some of this stuff.  Once I get USB HID down, I plan to move on to bluetooth HID (which is just a simple wrapper around the USB HID protocol, so it should be simple enough).  Then I'll be working on building the host module.  Fun times.

Friday, June 22, 2012

Today is a good day.  On Monday, I randomly made an image and posted it on Twitter, @wilw (Wil Wheaton).  He called it "awesome" and reposted it to the world.  "Awesome" is exactly how I feel right now.

Monday, December 26, 2011

Migrating your Droid X to CyanogenMod

I recently migrated from a stock Gingerbread Moto Blur install of Android on my VZW Droid X to CyanogenMod7 (specifically RevNumbers's CM4DX-GB kang, if you happen to care) and found it to be a rather arduous task to carry all of my data and settings to the new ROM.  I was talking to my cousin over Christmas break and she was curious to learn how to go about doing it as she had never installed a custom ROM before and needed step-by-step instructions (as she didn't feel like bricking like I did a good dozen times or so while I was figuring all of this out).  So I figured I would try to compile a step-by-step guide of how to go from stock to CM7 with *almost* everything still intact.

I will start by outlining the process and then going back and filling in the details as I get the chance, so this may be a bit sparse in some steps until I get more time.  I'll probably do a ToC section link block too eventually, but it's late and I'm just throwing this all down before I go to bed.  Also, there are steps in here specific to the Droid X because that's what I have, but some of this information may be useful to other phones as well.

Update your device
NOTE: If you are currently on Froyo and have already rooted your phone, you need to back up your apps and data first, then sbf to a fresh install of Froyo, then continue.  Updating to stock GB from rooted Froyo messes up your ability to root on GB.  If you have never rooted before, these aren't the warnings you're looking for, move along.

To begin with, you want to make sure you are running the most up-to-date version of Android available from Verizon.  The reason for using an official update is that there are some things that cannot be updated (or are more difficult to update) from unofficial sources.  These include the kernel and the baseband (the firmware for your phone's radio), and perhaps other things I don't know about.  You can check what version you are currently running by pressing the Menu key and selecting Settings>About Phone.

As of this posting, the current Android System version available from Verizon for the Droid X is 2.3.3, and the current Baseband version is BP_C_01.09.13P.  If you have these versions, you're set.  Otherwise, hit Check For Updates.  Go ahead and let the update finish and your phone should reboot.

Root your device
Once you're running stock Gingerbread, you can go ahead and root your phone.  Read up on how to do that here (it says it's for the Droid 3, but it works just fine for the Droid X).  NOTE:  DO NOT TRY THIS IF YOU PREVIOUSLY HAD ROOT ON FROYO WHEN YOU UPDATED TO GB.  If this is the case, you will have to sbf before rooting, meaning you won't be able to do a full backup.  Backup what you can, sbf, and then root.

Install useful tools
The 3 most useful applications I have found for dealing with data backup, ROM customization, and other stuff here are ROM Manager, ROM Toolbox, and Titanium Backup.  All 3 of these have free versions and are available in the Android Market.  I suggest purchasing the Pro versions of each, they have additional features and plus you'll be supporting the developers that make this stuff possible.  If you don't want to purchase them all, I would say ROM Toolbox and Titanium Backup are the most worth it.  Regardless, install whichever version you wish but get all 3 apps.

Install ClockworkMod Recovery
Open ROM Manager and click Flash ClockworkMod Recovery. If you're on the Droid X, when it asks you to confirm phone model, you have the choice between Droid X and Droid X (2nd init).  Select the one that says 2nd init.  The other option is currently useless because 2nd-init is required since the bootloader is locked and it won't work without 2nd-init.  If it prompts you for superuser access, say yes and check the box to remember (basically just do this any time you get this prompt as long as you trust the app; the 3 apps I am using in this guide are all trustworthy).

Understanding each type of backup
There are two main backups going on here, a NANDroid backup and a Titanium Backup, then there is the SMS backup.  There is a reason you are doing both of these.  The NANDroid backup is a system image that allows you to restore your entire phone back to the state it was in at the moment you create the backup.  The Titanium backup backs up all of your applications and associated data in a format that you can then reinstall once you have flashed your new ROM.  This allows you to reinstall all of your apps without having to download them all, and also retains all of your data like game saves and such.  Backing up your SMS allows you to keep all of your text messages (but so far there doesn't seem to be a way to back up your MMS, so you'll need to have saved any photos to your SD card manually).  The SMS database in the stock ROM is incompatible with the one that CyanogenMod uses, so you'll have to use a 3rd party backup solution that stores the messages in a separate format.

Create a Nandroid (system image) backup
Note:  The size of a Nandroid backup will vary, but I would suggest having at least 1.5-2GB free on your SD card before attempting this
Once you have flashed ClockworkMod Recovery, click Reboot into Recovery.  Your phone should reboot and you will be in a text based menu.  You navigate the menu with the volume up/down buttons, the camera button to select, and the hardware "back" button to return to the previous menu.  The power button just turns the screen on and off so if you accidentally hit it and the screen goes off, just hit it again and it will come back.  Select backup and restore->backup and then just wait for it to complete.  Once it's done, back out to the main menu and select reboot phone now.

Backup your applications and data
Note:  The size of the backup will vary greatly depending on how many apps you have installed and what you choose to back up.  Again, I suggest having at least 1GB free on your SD card before attempting the backup.
Open Titanium Backup and press the hardware Menu button and select Batch.  At the very least, select Backup all user apps, but you can backup system data if you want too.  You won't be able to restore the system data into an incompatible ROM, but if it gives you peace of mind to have it backed up, go for it.

Backup your text messages
There are many ways to backup SMS messages, but if you use a 3rd party SMS client, it may very likely have the option to back up your messages.  I use GoSMS Pro, and the option is found by pressing the hardware Menu button and going to the Services tab and selecting SMS B&R.

Install CyanogenMod (CM4DX-GB)
Because the Droid X has still not received a stable release of CyanogenMod, you're stuck installing a nightly release.  Also, the mainline CM7 does not support the Gingerbread kernel, so you'll want to install the RevNumbers releases, which do support the GB kernel.  The kernel does not get updated when you install a ROM, so you need to already have the correct kernel installed before you flash the ROM or you will brick your phone.  Open ROM Toolbox (since the RevNumbers Nightlies in ROM Manager are not kept up-to-date) and select ROM Manager (the button inside of ROM Toolbox, not the app named ROM Manager).  Under the ROM list select RevNumbers CM7 Nightlies (you can pick any ROM you want, but I highly suggest CM7, at least for your first ROM).  Pick the newest version and select download.  Wait for the download to finish.  Also download the latest version of Google Apps, or you won't have an Android Market.

Update: For more up-to-date releases of CM4DX-GB, follow this thread, as ROM Toolbox hasn't updated their list in quite awhile.

I'm going to outline how to install the ROM manually, since ROM Toolbox hasn't been working right with automating ClockworkMod Recovery tasks, although they may have fixed that, I don't know...

In the main menu of ROM Toolbox, select Rebooter, then Reboot Recovery, and you should be back to the text menu of ClockworkMod Recovery.  Select Factory Reset/wipe data, then select install update zip.  Choose select zip from sd card and browse to romtoolbox/downloads/RevNumbers and select the zip in that folder (or browse to the location where you downloaded it, if you got an updated release from the forum thread above).  Repeat with romtoolbox/downloads/gapps.  Now reboot your phone and (if all goes well), it should boot into CyanogenMod.  The first boot WILL take a long time, but if it just plain doesn't boot, check out the troubleshooting guide below.

Restore your applications
Install Titanium Backup.  Batch>Restore User Apps (NOT system data)

Restore your text messages
Use the same app you used to back them up in the first place

TROUBLESHOOTING

Unbricking
It's late, I'm getting tired, for now, Google "[your phone model] Gingerbread sbf" to get the files and  probably a guide.  You'll also need an app called RSD Lite, the latest version (AFAIK) is 4.9.  There is a bug in the software resulting in an error, something like invalid file or filename or something I don't remember, but that error is bogus and there is a workaround I'll get around to posting later... bah... should be enough info to get started, so for now goodnight.