Archive for January, 2011

Detecting Wii Remote via Mac OSX Terminal

Sunday, January 2nd, 2011

The type of Wii Hacks that interest me involve using the Wii Remote as an input device. The Wii Remote offers a lot of possibilities because it has several buttons, an accelerometer and an IR camera.

My first step into this world has involved basic detection of the device. Without using any fancy graphics or animations, and using code that I have found on different websites, I have been able to put together an application that uses the Mac Terminal to detect the Wii Remote. I am not yet able to connect to the Wii Remote or fetch any output from the Wii Remote.

Detect The Device
The first programming step is to detect the device. I had never done any Bluetooth programming and knew very little about the technology. Outside of Apple’s official documentation, it was a struggle to find much help in this area. Eventually I was able to piece something together.

#include <Foundation/Foundation.h>
#include <Cocoa/Cocoa.h>
#include <IOBluetooth/objc/IOBluetoothDeviceInquiry.h>
#include <IOBluetoothUI/IOBluetoothUI.h>

int main (int argc, const char * argv[]) {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@”start bluetooth search”);

// Setup the inquiry to search for available devices
IOBluetoothDeviceInquiry *d = [[IOBluetoothDeviceInquiry new] init];
[d setInquiryLength: 5];
[d setUpdateNewDeviceNames: TRUE];
[d start];

[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 7]];
[d stop];

// Create an array of foundDevices
NSArray *deviceList = [d foundDevices];
NSLog(@”found %d devices”, [deviceList count]);

// Loop through all the foundDevices
for(int i=0;i < [deviceList count]; i++) {

NSScanner *theScanner = [NSScanner scannerWithString:[NSString stringWithFormat:@"%@", [deviceList objectAtIndex:i]]];

NSString *tagDeviceName = @”mName – “;
NSString *tagEndLine = @”\n”;

NSString *currentDeviceName;

// extract the mName from the current array value
while ([theScanner isAtEnd] == NO) {
[theScanner scanUpToString:tagDeviceName intoString:NULL];
[theScanner scanString:tagDeviceName intoString:NULL];
[theScanner scanUpToString:tagEndLine intoString:&currentDeviceName];
} // end [theScanner isAtEnd]

NSLog(@”device name: %@”, currentDeviceName);

} // end for loop

[pool release];
return 0;

}

That is all I have at the moment, and it has been a bit of a struggle to get this far. I have found very little sample code, so I am piecing this together bit by bit.

This should work with any Bluetooth device and will work with multiple devices at the same time. If you are using a Wii Remote, you need to press the 1 and 2 buttons at the same time, during the detection.

DASM on Mac OSX

Saturday, January 1st, 2011

Today I started getting setup for Atari 2600 on my Macbook Pro. I am running 10.6.4, and while I had made an attempt at Atari development several years ago, I am coming into this with basically no knowledge of how it all works. I quickly found that there is not a lot of help out there for Atari Homebrewers who work on Mac OSX, so I thought it would be useful to document my steps along the way.

The first step to making an Atari 2600 Homebrew Game is to get DASM running on your system. DASM is an assembler, which essentially allows you to turn a plain text file (saved as myfile.asm) into a .bin file that can be read by an Atari emulator.


Download DASM

While you can find several versions of DASM on “The Official DASM Homepage“, I ended up using DASM Version 2.20.11, which for some reason is not on the DASM Homepage.


Install DASM
Once you have downloaded DASM Version 2.20.11, unzip the file and drag the entire unzipped file to a permanent location. I created a folder named ‘Atari’ inside my ‘Applications’ folder. I copied the unzipped ‘DASM’ folder and put it in the ‘Atari’ folder.

Next, you need to open the Terminal program. This program should be located in ../Applications/Utilities/

Terminal will require some basic knowledge of how to navigate folders using a text interface. If you do not know how to do this, I suggest you checkout Navigating Folders Using Terminal.

In Terminal, navigate to ../Applications/Atari/DASM/ (your DASM folder). Once you are inside the DASM folder, you need to install DASM by typing the word ‘make’ (without quotes). You will see a bunch of text scroll across the screen. Once that is done, DASM should be installed on your system.


Test DASM
The best way to test if DASM has been properly installed is to try assembling a test program. You can use the Atari 2600 Clock program provided by Atari Age. I suggest right-clicking on the Atari 2600 Clock link and choosing “Save Linked File As…” , or you can view the file in your web browser, copy-and-paste into TextEdit, and save it.

Save the file in the ../Applications/Atari/DASM/machines/atari2600/ folder as clock.asm

Return to Terminal and navigate to ../Applications/Atari/DASM/machines/atari2600/

To assemble the clock.asm file, type this into Terminal: ../../bin/dasm clock.asm -f3 -oclock.bin

If DASM has been properly installed on your system, you should see nothing more than a new line appear in Terminal. Use the Finder to navigate to ../Applications/Atari/DASM/test/atari2600/ and see if clock.bin has been created in that folder. If you are able to open clock.bin in your emulator (we will cover this in the next post), then you have properly installed DASM and assembled you first Atari 2600 program.


About Atari 2600 Clock
The Atari 2600 Clock program will display 12:00 when it first loads. You can change the time using the arrow keys, which represent your joystick.


Helpful Links
AtariAge.com 2600 Programming Guide