April 23, 2010

Powering an Xbox 360 dvd drive

While I was waiting to be able to power my experimental/half working xbox 360 I decided to see if I could easily get the firmware keys off the drive (Note: this not for piracy, the dvd drive is not working and I would like to replace it at some point.) First off, the dvd drive is a sata drive, however it does not run off of a sata power connector, instead it has a 12 pin connector where 10 of the pins are used. Pins 1-2 are not used on the connector, pins 3-4 & 6 are +3.3v, pins 5,7,9,11 are ground, pin 8 is +5v and finally pins 10 & 12 are +12v. I was able to figure out this pinout using the post here.


Sadly, I was not able to get the key off the drive this time, however I was able to create a simple xbox 360 dvd power adaptor which was powered by a standard computer power supply, or in my case a power adaptor for powering a single computer drive. In the picture you can see my simple power supply on a breadboard, most of this is straight forward, the only tricky part is you need a 3.3v regulator to drop the +5v line down to the 3.3v the drive needs. You can see the regulator at the top of the board with two capacitors keeping the output clean at a stable +3.3v.  I did not use a switch to eject the drive, because from what I can tell, the drive motor controller is damaged and will only make a minor movement before freezing and not responding again.

While an interesting side project, it was somewhat pointless as now I can just use the 360 to power it. However it was convent to move this smaller adaptor vs a whole opened 360. Eventually I will take another stab at getting the key off, but not till I have had my fill of xbl arcade.

April 20, 2010

XBox 360 Cooling Experiments



I have an older xbox 360 that a friend had given me a while ago, it had no power brick, controller or av, and I was told that the DVD drive was not working.  As I have limited expendable money right now, it sat in storage for a few months waiting for a time where I had extra money or a reason to get it up and running again.  However, with the upcoming summer release of Hydro Thunder Hurricane I decided it would be worth finally getting the 360 ready.


I was able to snag a used power brick off bay for around $10 with shipping, so all that was left was to check out the guts while I was waiting for snail mail to arrive. First off I quickly released why the GPU overheats in 360's, the DVD drive sits on top of it, and the front has no air vents what so ever to let in fresh air.  Second the fans in the back have a single shroud instead of separate channels for the CPS and GPU, so most of the air is just pulled from just the larger CPU heat sink. I remedied this by building a wall to separate the shroud into two separate paths, forcing the right side fan to pull as much air as possible from the GPS heat sink.  Next, I add a third fan as an air intake, this was placed over the open area inside the case in front of the CPU heat sink.  I also added a plastic wall the cuts the fan air intake into two parts, half is blown into the CPU heat sink, while the other half is blown under the DVD drive so fresh cool air is available to the GPU intake. It was easy to mount a fan that fits the space, as the thin metal shield cover for the 360 has holes already drilled in an attempt to allow a pitiful amount of air to be drawn in, the holes will fit two normal sized fan screws and holds it nicely against the top of the side wall.  I removed the extra metal around the fan intake and then drilled a same sized hole into the white plastic cover above this.  Screen mesh was added to cover the fan intake and protect it. Finally, I used metal heating duct foil tape to cover the fan sides as well as do some plugging of gaps in the heat sink shroud connections.
I have never owned a 360 before, so I will have to do some heat comparisons, but it does not feel like an excessive amount of heat is being blown out the back, so I am assuming this does work to cool the insides better, or at least that is the standard thinking as I have seen that many other people have added an intake fan in this location.

March 29, 2010

DIY Fog Chiller

I have owned a fog machine for many years now, but I had always wanted to make a fog chiller to get a crawling fog effect. However, due to the wind around my house in the fall, it makes it usually pointless for halloween, so until now I had held off on spending any money on it. But when low lying fog was needed for a youth play I was helping setup and run lighting for, I finally had the excuse I needed.

So before any details, a bit of physics… A simple fog machine works by vaporizing a fluid (usually made of mineral oil, glycol, or glycol and water mixture) into a heat exchanger, where the fluid is quickly vaporized. This means that fog is usually somewhat warm, as it does cool down quickly as it expands, similar to compressed air. However it is still warm enough that it always rises as it is released. To remedy this, a fog chiller is used to cool down the fog faster so it lays low and clings to the ground. Some simple examples can be found on youtube that use a metal pipe or plate and ice to cool down the fog, which to my surprise does not need a lot of ice to achieve the task. Though watching expensive professional fog machines run is rather impressive. [Check it out]


Still I wanted to do something more than a simple metal tube, so after purchasing the cheapest plastic bin I could find ($5) I gathered up some PVC tube, mesh window screen, a 120mm computer fan and a plastic sandwich bag.

As you can see from my pictures the mesh is bent and woven into a wave shape for a clear path the smoke can move through, this ensures maximum exposure to the ice is possible and allows the fog to fill the container. Next the mesh smoke path is placed between the PVC inlet and the outlet fan using the lip in the container to to hold it up. Ice is filled all around the mesh as well as in between the gaps between the smoke path. A variable voltage transformer and a remote controlled outlet is used to control power and the speed of the fan. It is pointless to leave the fan running all the time as it will melt the ice faster. Finally a plastic bag with a stiff edge is used as a simple laminar to help smooth and direct the fog to the ground for a gentle rolling effect. While I did not get a chance to take a video of it in action I have included a video of another person's fog chiller which produced the same effect. (AKA, It is not my home, and I do not own such a sketchy rug...)



I was quite happy with the results, the ice lasted and with plenty to spare, while sitting in-between uses for a good hour. And produced a good layer of fog for the two scenes that needed it. Interestingly enough a chiller seems to works better in cold air than warm, due to it keeping the fog cool longer, which is the opposite of what I assumed, as I thought it would be better to have warm ambient air to keep the fog as the cooler sinking air. Also the slower the fog is, the lower it will stay, so if you have a container to pump it into first before cooling it will help slow it, but I will save that for the v2. As you can see from my results, if you own or want a standard fog machine (quite cheap now a-days) you need to make a fog chiller, also don't buy a combined model as they only produce a slow steady output of fog, which is only is useful for an small indoor room.

March 24, 2010

Poking with ajax

I have played with Ajax before and even used it in a few projects, but never in a way that it was obvious.  With the next round of CADY site updates I have finally had a chance to put ajax to some real use. For the upcoming parent network, which is more or less a very simplified forum I am coding from scratch, I needed a simple and easy to use registration page for parents. Setting up a page is easy, making it point out peoples mistakes in a dynamic non refresh ways is not.

It is good HCI practice to limit any screen refreshes to just when locations are actually changing, it is what people expect. Where as if a user submit a form only to have it return and to say you missed something is not as intuitive, because the user has already moved on in their thought process.  This is where javascript and ajax usually come in.  By allowing the page to call remote content you can check form fields on changes and then update the user to missed fields or issues before they submit. You could extend the process and prevent even the submit if things are not correct, however this falls outside my current beliefs on how applications should handle user control.  If the user wants to submit the page with missing items even after being notified, let them, however have it fail the submit on the server side and then bring them back to the restored page with a notice of what they missed.  This forces the user to learn that finishing a form properly the first time is worth not having to remember what they where filling out.

You can check out the CADY Parent Network Registration Page to see my progress and fancy ajax trimmings, however please do not sign up unless you are actually a parent who is interested.

March 9, 2010

Growth Issues,SN Java BufferedImage Transition

With my SN Project slowly coming closer to completion, I decided that I would try out making a simple game to see what needs work, however like always, my plans where derailed quite quickly. I had a small library of images that was working quite well at the time, however after increasing the library to a couple thousand images, I quickly noticed that things where not working quite right, well… actually not at all, it was throwing a java.lang.OutOfMemoryError and crashing. The memory error that as an easy fix, adding a VMOptions tag to the info.plist with -Xmx1024m allowed for me to set the max memory to a much greater amount, however this was nothing more than a temporary fix, I knew there was a much greater issue behind this problem.

The size of the image library was around 150Mb, which when loaded to memory would be larger due to it being uncompressed, however it should not have been much larger than 2X the base size or 300Mb as an upper limit. I was shocked when memory needed skyrocketed to well over 700 Mb, whereas the standard max for the Java VM is around 100Mb. So I went looking for a memory leak. Java handles most memory issues, but it still can have problems with large collections of data gathered in a short period of time, due to the built in garbage collection running only occasionally as needed. After doing some research via Google, I stumbled upon a complaint about the MediaTracker keeping references to the images it tracks, which while in small numbers is not an issue, but can quickly build up as more images are tracked. This was exactly what I was doing wrong.

The standard Image class in java does not load the image into memory right away, instead it acts as a reference until it is needed. This behavior could be seen when removing the method calls to add images to a MediaTracker, the memory used would only increase to around 50Mb and slowly grow as images where loaded when needed. The problem with this is that it causes an issues with flickering in animations. When each frame is used for the first time, it actually draws it on the second call after the first call forces it to be loaded into memory. The standard practice at the time of Java 1.3 to 1.4 was to use a MediaTracker to force the images to load and for my initial use worked quite well. However my project has finally grown beyond the simple use of a MediaTracker. The next step I took was to try some suggestions on limiting the memory retention by removing images from the tracker when they are loaded, or by using separate trackers for each image as well as forcing garbage collection with System.gc(). A mix of these solutions did lower my memory use, however as usual the trade off for space was time and this setup slowed my image loading algorithm to a crawl.

It was quite apparent that I needed something better, and after a bit more research I decided to transition my SN Project from using the base Image class to the improved BufferedImage class available in Java 1.5+. I had actually been using the BufferedImage class for a few things already, but a total transition was not a simple matter. For the most part you can use BufferedImage anywhere you are already using Image, due to the BufferedImage extending the Image class. One huge benefit was that the ImageIO class, instead of the awt Toolkit, loaded the whole image to memory so a MediaTracker is not needed and this sped things up greatly and removed my memory leak. Compared to before, now it only was using around 230Mb, which was well inside my expected limits.

The big problem that I ran into while changing over my code was that the sneaky way I was loading my animation class into my image array on the engine side would no longer be feasible. Originally, I had found a nifty solution to my space problem, with a bit of tweaking my animation class could extend the Image class and then be inserted into my image array for quickly accessing both the game animations and images through one simple method call. It also only needed minimal conditional checks which I already had in place. While this worked well with Image, there is no such luck with BufferedImage. You can serialize a class that extends BufferedImage, but you cannot deserialize it, because as it lacks the "no argument" constructor needed to reconstruct the base class. This left me frustrated and quite annoyed, by this point the editor was ready and working, but the engine would not accept the image data.

A few hours later, I had separated the animations from the image array and while I was sad that I had to abandon my unique solution, it was probably for the best as it is easier to figure out what the code is doing now. This is where big problem two popped up. I was using a PixelGrabber to export my images to an int array and then reconstructing them with MemoryImageSource and the awt Toolkit to load them back into an Image and then forcing them into memory with a MediaTracker. This was not going to work as I was now avoiding the Toolkit and MediaTracker classes. With some more research I finally pieced together that I could do a similar process but this time to a byte array. A simple example of what I am doing is listed below.

Exporting is the same as saving the image, but to a byte stream instead of a file.

ByteArrayOutputStream bstream = new ByteArrayOutputStream();
ImageIO.write(img, "png", bstream);
byte bytearray[] = bstream.toByteArray();

To convert the image back you can read the byte array using a ByteArrayInputStream.
BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytearray));

At this point, around ten hours after I started, I now had a working engine and editor again, however it was rendering slower than before. I commented out a most of the drawing and logic method calls and found that the engine would run around 50 FPS with minimal drawing, on the other hand, with all calls back on it ran around 8 FPS. Interestingly enough, the logic was the issue, instead drawing a single large transparent image of the GUI was causing a 40 FPS reduction. I was aware that transparency always causes a speed reduction due to increased processes needed to render it, but not by that much!

It took some more searching to figure out what was wrong. In Java images come in a few different types running in different modes, examples of these would be Image, VolatileImage and BufferedImage. I found VolatileImage quite fascinating as it is the fastest since it is always stored in the graphics hardware memory, but the trade off is that it always may or may not be available due to the possibility of it being overwritten by something else in the limited space of video memory. You must repeatedly check to see if it is still there, the descriptions of this made me think of trying to arrange a large group of very hyper children into a pattern, but at any point they may scatter. Luckily, with new changes in the BufferedImage class it too tries to run in video memory if possible, but only if it is setup to be compatible with the current video configuration. Apparently, using the ImageIO read method does not always create the fastest images, it was suggested that you create a more compatible image using the current graphics configuration and draw the image onto that. This also seems to only cause a minimal increase in processing that is easily outweighed by the huge increase of rendering speed. After converting all the SNEngine's BufferedImage objects with the GraphicsConfiguration createCompatibleImage() method a huge increase could be seen, going from 8FPS to around 35FPS, my target being 30FPS.

I still have some more work to do on increasing efficiency, but this tedious transition was an eye opening experience. As usual I have learned more than I expected, but this new information on Java graphics will probably come in handy later. (NOTE: This was found to be true on OSX 10.6 compiling for Java 1.5+, while most things would be similar on other platforms, the low level hardware acceleration for graphics does slightly differ on each operation system and JDK.)

March 1, 2010

Java JNI Custom About Box

It is silly just how long it took me to figure out this one line of code... A few months ago, I had finished porting over my SN Project from standard Java to then new JNI Library in Xcode 3.2. However, no matter how much I poked and prodded and searched, I could not figure out how to override the simple About Box I am assuming is provided by the JavaApplicationStub.

Luckily, today I finally stumbled on the answer in an obscure thread on the Apple Mailing List. The short answer is that I was not telling the event that it was already handled before letting the method end, the default box was called as a result of this.

You can see below that you need to add setHandled(true); to the handleAbout ApplicationEvent that is in the OSXAppAdaptor class provided with the JNI Template, or where ever you are handling the EAWT action calls.

public void handleAbout(final ApplicationEvent e)
{
   e.setHandled(true);

I actually feel a bit stupid for not noticing this sooner as a few of the other action call methods already are setting handleAbout but it was not that clear what it was doing so I completely over looked it. Well, with this fixed I now have all the kinks worked out, now on to finishing up the features and finally hitting a stable 1.0 release, though it may take another year.

February 13, 2010

You should have seen it coming! EpicGame on iPhone!


Well, after a few days of learning the ins and outs of UIView and the CGContext classes in Objective C, I went to work porting the classes from the original VB EpicGame to iPhone friendly Objective C classes. This was rather straight forward and other than changing the method formatting almost all the logic was still sound. The big difference that did require some tweaking was that Quartz or CoreImage uses a diffrent orgin point, it is the bottom left, not top left as almost everything else. Oddly enough all the images just needed to be flipped in PhotoShop and all was fine, with little to no code change.

What is different is that there are no keys, you move left and right by holding the left or right edges of the screen. A tap will shoot, and a swipe up makes epic box jump. Pritty niffty I must say.

I quickly found out that the drawing class CGContext was annoying near the end, as you are forced to rely of the Touch OS to draw when it is ready, vs forcing a redraw when needed as I am used to. This takes a huge hit on speed, but I am lazy and do not want to spend an entire extra week of studying just to use OpenGL ES instead. It is large complex and annoying, plus way too much for a simple game like this. Oh, and thanks Apple for not making the iPhone simulator actually match the real speed of an iPhone, for others as a warning, the simulator runs graphic calls around 100 times faster than a real iPod 1G, don't be fooled!

You can grab a copy here, sorry non JailBreakers no portable EpicGame for you, as I am not paying $99 to Apple to distribute a free app, plus the music would most likely prevent it from being approved anyway, as it is used without permission, but without it, it just would not be the same.

Other then the code and the can monster art, I claim no ownership of the rest of the art and music, and as such I am posting the App as free for use as is, enjoy.

January 25, 2010

Coinco 9300-CL Reverse Engineering Part 1


A while back I was able to get several parts to a vending system off of school surplus. Which I was quite excited about, because it was something I had always wanted to be able to play with. However I quickly ran into problems in trying to use it as there was nothing online to help. But, finally with the arduino that I now have, I believe I can make it all work. So I started out by seeing if I can get just the coin changer to interface with my computer via the arduino.

The coin changer is a coinco 9300-CL which from what I can tell is the same as the 9300-L model, but with it requiring 117 instead of a lower voltage. Both seem to have the option of a 15 pin or 12 pin plus, the CL has a 12 pin plug. Using the service manual found here. It explains the pinout and basic operation of the coin changer. However the image for any details of the communication is rather blurry and almost impossible to understand, so I had to do some poking to figure out what was what. To start out the 12 pin plug has 6 vertical pins and then 6 more pins that alternate vertical and horizontal. Pin 1 is the first vertical pin of the all vertical group, starting on the left and then 2 in the middle and finally pin 3 on the right. The rest of the pins follow suit in numbering from left to right on each row. Luckily I had a connector that came from the vending device, so I simple had to use my multimeter to find the connected point on the female connector for the main board. Which was nice as it had the two 117 volt pins removed so I could not accidentally destroy anything!

Using the service manual I have compiled a much easier to read version for the pinout as it was on the female header end of the plug.  You will notice pin 10 and 12 are missing as there is no need for them because another pair of separate wires run to my power supply for those pins.  For basic use it looks like you simple need pin 1 and 2 hooked up to +5 and ground on the arduino and then 3 to a digital output pin and 4 and 5 to digital input pins.  Pin 3 is your TX pin for the serial communication where pin 5 is the RX.  However pin 4 is used as an interrupt that signals when data is going to be sent.  Sadly the service manual only covers a single example of when a coin is used.  This states that when a coin is entered it will send an interrupt to the controller via pin 4 and then wait for a signal on pin 3, which after receiving it will finally send a message with information on the coin and other states.  This is nice, but what I needed is how to connect to it at startup as well. It looks like when the coin changer is first turned on it sends a status request to the controller and will not fully activate until the request is answered.  This is preventing me from actually using it in any way.

So to get around this I hooked everything up to the controller board I already have, that came with the parts, and started intercepting the communication between the coin changer and the controller, using my simple oscilloscope and the arduino to read the serial communication.  For the most part the serial communication is simple enough, however I have yet to figure out the actual protocol used.  From what I have seen online I believe the 9300-CL uses some form of the MDB protocol however I have not been able to quite narrow it down to the 9 bits it should be using if that is the case.  I have tried many different timing setups in order to catch the correct bits, 2400 and 3300 microsecond delays between bits seem to get the best results so far, which I would happily use, if not for the fact that I also need to talk to the coin changer, not just read what it spits out.  So I am now waiting for a reply from coinco tech support to see if they can shed some light on the matter, otherwise it will be a slow process of trial and error till I get the right timing and figure out the correct protocol.

January 18, 2010

SSH Messenger


As a request, I have finished my second full Objective C project. If someone is on a computer wearing headphones and is not in convenient shouting range this app makes it simple to still get their attention.  It would also make a good admin tool, or a awesome way to prank/annoy someone. It is a simple application that will connect to a remote computer via SSH and then use the built in osascript libraries to cause a dialog prompt to appear. However instead of requiring some terminal skills, instead just enter the IP, username and password of the remote computer and then type your message. A handy shell script takes care of all the rest. Click here to check it out. (Universal Binary, Mac OS X 10.5+)

This was an interesting project, not so much on the Objective C side, which I am getting quite good at, instead the shell scripting was a challenge this time. In order to have the SSH command work without setting up key pairs, I needed to delve into the world of Expect. Expect is a handy command set that allows you to set up automation of terminal entry. In short you can have it "expect" some input and then after finding it, send some output to the terminal, which in my case was the password entry for ssh. The ssh command does not have a password argument, so it needed expect to look for the password prompt and then enter a password for the user.  It also led to a nice way to do some general result checking in the case of a prompt with two or more button options.

Expect while a little strange at first was not that hard to figure out and only took about an hour and a half to have down pat and working the way I wanted it to.  Sadly as it is based out of /usr/bin/expect you cannot use echo command, which made it slightly harder to learn when something was not working.

Check out the base script I came up with below...

#!/usr/bin/expect -f
#log_user 0
set addr [lindex $argv 0]
set usr [lindex $argv 1]
set pas [lindex $argv 2]
set message [lindex $argv 3]
set from [lindex $argv 4]
# now connect to remote UNIX box (addr) with given script to execute
spawn ssh $usr@$addr -o StrictHostKeyChecking=no
match_max 100000
# Look for any ssh issue that needs exit
set timeout 4
expect "ssh:" {exit 2}
# Look for password prompt(s)
expect "*?assword:*" {send "$pas\r"}
# Look for password rejection and exit
expect "*?assword:*" {exit 1}
set timeout 10
# send osascript commands for popup
send "osascript -e 'tell application \"Finder\" to activate'\r"
#send "osascript -e 'tell application \"Finder\" to display dialog \"$message\"'\r"
send "osascript -e 'tell app \"Finder\" to display dialog \"$message\" buttons \"Ok\" default button 1 with title \"Message From $from\" with icon caution'\r"
# Look for reply
expect "button returned:Ok" {
 send "logout\r"
 exit 0
}
send "logout\r"
exit;

Another important thing to note is that I was rather annoyed to find out it required the curly braces to be placed how they are, due to it being based on Tcl. However it was only a minor inconvenience until I realized that is why if kept having errors.  The script above takes 5 arguments Address, User, Password, Message and From, and is the general Alert script used in the SSH Messenger.

This makes the first Objective C and Shell combo app that I have done, which is a nice change from the Java Shell combo I am more used to working with.  That and it was a good refresher in shell scripting.

January 1, 2010

A look back before a step forward...

With the passing of Dec 31, it is now 2010 and I have been think back on the past year.  All and all it was not too bad a year, although not exactly perfect either.  Looking back...

GOOD...
Graduated from College (with, in my opinion, flying colors)
Caught up on some good reading
Spent time with family
Had fun with friends
Could actually enjoy the full Christmas Season
Finished some very cool projects

BAD...
Still no full time job, (but part time is better than nothing)
No personal car (not huge, but annoying at times)
Paying back school loans (easy to do, but I hate seeing the money leave)

As you can see, the good easily outweighed the bad, which hopefully in this next year will be finish off completely.  Because, all and all, other than the lack of full time job, life is not too bad. Thus, I do not think I have much of a right to complain.

After looking at the past year, I got to thinking back on the fact that ten years have passed from the year 2000, and all the changes that have happened in the last ten years.  Some of the things I realized where quite amusing.

10 Years ago...
I was happy using dial up (3.5 Kb/s!)
Had never formally programed (but was used to html!)
Used a black & white powerbook duo (system 6.5)
Listened to all my music on cd/cassette player
Never put up a halloween display
Had only hiked one mountain
Lived in a different house
Had a small messy room
Watched way more tv
Could not drive

However a few things have not changed even after ten years...
Still put up a Christmas tree in my room each year
Still chase and poke crabs each summer
Still working with circuits (but much better at it)
Still get along well with my parents
Still fixing things
Still use a Mac

Looking at just these changes over a decade of my life, I have to wonder what will the next ten years bring!

December 28, 2009

Colour My - Game Series

A while back I found great enjoyment in playing a simple flash game called Colour My Heart. It was a release for valentines of 2009 on Newgrounds, and ranks right up there with several of the other artistic games I have posted about in the past. Instead of being a challenging game, it is more of a piece of interactive art with a simple story. As SilverStitch, the author puts it, "This is not a 'hardcore gaming experience'...its just simple and more artistic". I was blown away by how well the simple pencil like graphics and backgrounds could come together to be as immersive as it ends up being. See Example Below...


I was very happy to recently find out see that the author has continued the Colour My - Series with several other titles all with a similar poetic twist on a deeper love and relationship theme. However, what is truly nice about the series is that you do not need to be a hardcore gamer, instead some basic platforming ability and the ability to figure a few puzzles is all that is necessary to enjoy it. I strongly recommend taking a look at the series by visiting the links below.





December 25, 2009

Merry Christmas!

Hopefully everyone has a Merry Christmas today.