Archive for the ‘Programming’ Category

Running OSX86 in VMWare Server 2.0

Saturday, September 26th, 2009

For those of you who want to run OSX in a virtual machine, its not terribly difficult to setup if you’ve got the right instructions.  If not, it takes a lot of experimenting and guess work to get it working properly.  I tried to do it myself with limited success.  I could get it to install 100% of the time but only once did I ever get it to reboot into the main OS.  I wiped it out (thinking I had it down) so that I could try and fix  the booting.  I never got it to work on my own again after that.

I was fortunate to find a tutorial that worked perfectly for me the first time.  I was then able to upgrade to OS 10.5.7 so that I could install the iPhone 3.0 SDK.  Now when there’s a slow day at work I can develop for my phone without having to bring in my personal computer! Woot!  The link to the tutorial is below. I’ll copy and paste its contents as well in the event that it ever goes down.  My best advice to you is take VM snapshots along the way as you get individual portions working.  Also note that you cannot boot the VM without the installation DVD mounted.  If you forget to install osx86 tools, you can download it here.

Link to a direct download of the 10.5.7 update from Apple itself.  Here are the upgrade instructions I followed.

VMWare configuration instructions courtesy of Bob’s Mental Moshpit.  Thanks Bob.  Note that this installs “Darwin-64.” You do not need to be running a 64-bit OS for this.  It’s working just fine for me on Windows XP 32 Bit.

Installing Mac OS X 10.5.6 under VMware 6.5.2

One of the current “Holy Grails” of virtual machinery is getting a functional installation of Mac OS X into a VMware virtual machine.   There’s a lot of Google talk out there about how to do it, but not everybody seems to be successful.  I certainly wasn’t for quiet some time.  However, I sat down today and decided to give it my best shot again, and this time I succeeded!  Not only did I succeed with iDeneb 1.4 (which installs Mac OS X 10.5.6), I successfully upgraded that release to 10.5.7.  Cool.  :)

I’m documenting here the steps I followed (many times, just to make sure they worked for me) to achieve a successful Mac OS X 10.5.x install in a VMware Workstation 6.5.2 machine.  There is no sound, but there is networking, which is far more important to me.  If you find a way to get audio working, you might post it here.

Be aware that these steps worked for me, but YMMV.  If you are not successful using them, there’s not much I can do to help you out.  I had to experiment over and over to find these working steps; you will probably have to do the same to overcome your problems.  For the purposes of this tutorial, I’ll be using the file “iDeneb_v1.4_10.5.6.iso”.

Here We Go

1. First, of course, you need to grab the iDeneb 1.4 distribution (Mac OS X 10.5.6).  Google it, or use your favorite torrent search engine.
2. Mount the iDeneb ISO as a drive (using something like UltraISO or Virtual CloneDrive).  Note the drive letter of the DVD.
3. Create a new virtual machine in VMware.  The following sequence of screen grabs should show you all the settings you need to create for the new environment:

Snap1
Tell VMware that you will install the operating system later:
Snap2
For operating system type, Select “Other”, and then “FreeBSD 64-bit”:
Snap3
I named it “10.5″ because I will upgrade from the 10.5.6 on the iDeneb 1.4 image to 10.5.7. You can call it whatever you like, of course:
Snap4
Choose the number of processors to let the OS use:
Snap5
Allocate an amount of memory to use:
Snap6
Unless you know what you’re doing, select “Bridged networking”:
Snap7
Drive-type settings:
Snap8
Snap9
Snap10
Set the space available on the disc. The installation will consume 6-7GB, and the update will consume even more. If you need to do more on the drive, increase that size here:
Snap11
Don’t power on the machine yet:
Snap12

4. Edit the machine settings, and set the CD/DVD drive to use the one that you noted earlier where the iDeneb 1.4 image is mounted:

Snap13

5. Power on the machine. You’ll want to be sure you click in the window immediately so it captures the mouse/keyboard focus. When prompted to press “F8″ for startup options, press it. Then, at the “boot:” prompt, you can enter options you want for starting the installer. I use the following (’-v’ means show diagnostic messages; I recommend entering at least that):

Snap14

6. Now, if you’re lucky, at this point you should boot into the iDeneb installer. When you get to the installation prompt, you’ll want to go to the “Utilities” menu, and launch “Disk Utility”. From this interface, select the VM disc, and then select the “Partition” tab:

Snap15

7. Create a single-partition layout, leaving the volume type as “Mac OS Extended (Journaled)”. This volume type is important: I was unable to get the VM to boot with any other type:

Snap16

8. Select the “Options” button, and change the disc to use a “Master Boot Record” partition. The other types failed to work for me:

Snap17

9. “Apply” your partition settings, and exit the “Disk Utility”.
10. Proceed with the installation, selecting your VM disc as the target partition (it will be the only one, if you followed these instructions).
11. When the installation completes, you’ll be prompted to restart. Do so, but when the machine gets back to the boot prompt, “Stop” it immediately (don’t worry, this won’t harm anything) so that you are back to the VMware desktop and the VM is powered off.
12. Change the “CD/DVD” settings of the VM from the specific iDeneb drive back to “Auto”. DO NOT UNMOUNT THE DVD. You’ll want to leave the iDeneb DVD mounted in the operating system, because it seems to be the only way to allow the VM to actually boot correctly.
13. Shut down VMware.
14. Open the .vmx file of the new iDeneb machine (e.g., “Mac OS X 10.5.vmx”), and find the line that starts with “guestOS”. It should contain the entry “freebsd-64″. Change this to “darwin-64″, and save the file.
15. Re-start VMware, and power on the Mac OS X VM. Let the boot screen time out, and if the gods are smiling down upon you, you will boot into Mac OS X 10.5.6.

Post-installation Booting

Of course, things did not go this smoothly for me.  It took me a couple of boot attempts to get the operating system to come up (boot-hang-kill-repeat).  When it did, I did all the set up stuff, and it took me into the OS X desktop. Once I get everything set up that is boot dependent (like updates and screen resolution), I plan to simply suspend the VM so that I can unmount the iDeneb DVD, and then simply power on the VM whenever I need it.

Screen Resolution

There are two ways to control the screen resolution.  You can enter it at the boot prompt (see the previous image), but this is cumbersome, and can typically lead to a failed boot.  Or, you can change the com.apple.Boot.plist file to make the resolution permament (my preferred approach).  Both approaches require a boot up sequence in order to be successful.  You can read about implementing both approaches here.

Good Luck

If you’ve been looking for a successful way to create a portable Macintosh, I hope this approach works for you. Being a software engineer, it’s really fantastic to be able to carry Linux, Mac OS X, and Vista along with me on a single machine when I’m away from home.

iHackintosh Upgrade instructions:

  • Download AppleDecrypt.kext  Click HERE.
  • Download IntelCPUPMDisabler.kext  Click HERE.
  • Edit : AppleIntelCPUPM Disabler.kexts will be in /Extra

Open the terminal & perform following command’s without quotes.

”sudo –s”

*type password*

”while sleep 1;”

”do rm –rf /System/Library/Extensions/AppleIntelCPUPowerManagement.kext;done”

Open 10.5.7 Update Installer.

Run update BUT DO NOT RESTART.

Go back to your terminal and press Control C to end the script.

In terminal type:

”vi /System/InstallAtStartup/scripts/1”

Replace the line Dont Steal Mac OS X.kext with dsmos.kext if any exists.

Don’t restart.

Open osx86tools  >>> Check repair permissions >>> Set kext permissions >>> Clear extensions cache >>> Restart.

Boot using -v to see if any errors.

Tradewars 2002 Again

Friday, March 7th, 2008

So, a friend of mine decided to start hosting a BBS off his internet connection at home so that a bunch of us could play our old favorite door games again.  He only has two that I am really interested in, Legend of The Red Dragon, and Tradewars.

A lot of the people playing Tradewars are using helper programs that can automate trading, maping out the universe, and things like that.  I’m not a huge fan of using something like that to play the game, but I don’t really say too much about it to them. But, I’ve gotten tired of trying to keep all of the sector information in a notepad type document.

So, I wrote a script that goes through and parses all of that information out of the game by executing commands on the ship computer and then storing them in a database.  I’m also going to be unable to play for a week and so I’ve decided to write a script to do something useful with my turns in my absence. It’ll run as a cron script while I am gone.

All that playing around with scripting has made me decide that I want to write my own helper program that uses my own experience with the game.  It will basically do all of the same things that current database script does but will allow me to interact with the game while it silently logs what is going on.

I’m going to have it do things like remember who owns any planets I see, keep track of where I encounter fighter nets, and allow me to insert notes about sectors.  I also want it to have a UI that draws a map of the entire universe and allows me to zoom in and out, rotate the map three dimensionally, select nearby sectors to view them, and  stuff like that.  It will also remember successful trade values when working on a port pair so that I have a basis to use to try and maximize my exp when trading.  Also handy would be a database that keeps track of where I’ve been caught stealing, and when so that I know if it is safe to steal from a port again (when I am playing evil).

Eventually, I might make a non-interactive version that tries to play “alien” traders with enough intelligence to give a little extra challenge to human players.

So far, I’ve been doing all the scripting in Perl using the expect module.  I’m thinking about making the map using java and have it pull database information out of a central server that corp mates can use to share their travel information real time.  We’ll see how sophisticated this ends up being.  Either way, it has been pretty fun to work on.

Global Variables are Bad (Usually)

Tuesday, August 14th, 2007

I’m working on an embedded software product that decodes network video and renders it to a monitor.  The application is designed to run 24×7, with up to four streams running through it at a time.  I didn’t write all the code from scratch, I took it over from someone else and am now responsible for bug fixes as well as advancing the functionality. When I inherited the project, I also inherited a bug that was caused by a global variable.  I had made almost a dozen releases with this bug, but it never manifested itself.

The global variable was a wrapper written around the sem_t that handled all of the initialization, destruction, etc.  Someone went into an old C style source file and threw a global instance of that class to provide multi-threaded support.  That might seem fine and dandy, but when unloading the library from memory, a race condition existed that wasn’t very obvious.  Some functions needed to be called in the library during cleanup that relied on the semaphore.  As long as that code was able to execute before the global variable was destroyed, everything worked fine.

The problem is, you have no guarantee of the destruction order of objects.  So, after a bunch of problem free releases, some subtle change had caused the semaphore to be destroyed before the library finished cleaning up.  The application would crash then once the library started to clean up.

I enabled core files and it became pretty obvious that the problem had to do with the semaphore.  It wasn’t the most disgusting global variable problem one might encounter.  I’m just so surprised that people continue to use globals so freely.  I’m positive whoever put that in there did it because it was quick and easy.

There’s no reason that this C file couldn’t have been turned into a class.  It would have only taken a few minutes.  If this person felt that the sem_t was really needed globally to these functions, they could have used some quick regular expressions to make the proper conversions.

So, when is it okay to use a global variable? Almost never.  I can’t give you an example off the top of my head because it’s almost never appropriate.  If you can think of a good example, post it as a comment.

Stack Trace in Linux

Friday, June 22nd, 2007

This is incase I forget how to print out my current stack in linux:

#include <execinfo.h>

size_t sz;
void *bt[20];
char **strings;

sz = backtrace(bt, 20);
strings = backtrace_symbols(bt, sz);

for(int i = 0; i < sz; ++i)
fprintf(stderr, “%s\n”, strings[i]);

The joys of interlaced video

Wednesday, April 25th, 2007

So the world is moving from SD television to HD television.  There are now several different video formats available to broadcasters incuding 480p 720p and 1080i.  Many people wanted to move away from interlaced video completely and only support progressive scan video. But, our government, in its infinite wisdom, standardized everything at 1080i.  I don’t understand that at all.  Interlaced video creates all sorts of interesting challenges, espcially in the era of digital content.

I have a problem at work right now that is specific to interlaced video that I cannot figure out how to overcome.  My problem is that I need to draw basic primitives to the overlay channel.  These primitives aren’t supposed to obstruct or detract from the video but are generated based on user defined areas and the video’s content.   These overlays have to be drawn on coax (via NTSC/PAL), or a S/VGA display.

The VGA output is non-interlaced while the coax is interlaced.  What this means is that my primitives look absolutely beautiful on VGA but have a very annoying flicker over coax.  For those of you unfamiliar with interlaced versus non-interlaced video it is because a VGA monitor draws the entire screen every time it paints.  A video monitor (TV, etc) is interlaced and draws every other line and then goes back and draws the lines that it skipped the first time.  These two different draw periods are referred to as fields.

This means that if you had a horizontal line that was one pixel wide, it would be drawn in  one field and not drawn at all in the next field.  This causes the line to disappear, only to be drawn again.  That is where the flicker comes in.  Just doubling the thickness of the line would likely result in having two lines flickerin on and off right next to each other.

Well, I don’t have a problem with my horizontal lines, but I do with diagonal lines.   What I am doing is this.  If I am going to turn on pixel (x,y) then I would also turn on (x,y+1).  I’d then paint pixels (x,y+2), (x,y+3), (x,y-1) and (x,y-2) with the gradient color.  That way every field will have one pixel for the line and one pixel on each side of the line for the gradient color.  That combined with the persistence of the phosphors in the previous field should blur everything to the eye and make it look more consistent.  At least, that is what I would think.

I’m still getting flicker, however.  Not only am I getting flicker, but it also seems to be worse on lines where the slope is greater than 1.

I’m absolutely perplexed by this and I can’t figure out how to resolve my flickering issue.  I’ve tried to decrease the intensity of the colors that I am using by half and that makes the flicker less noticable but does not remove it completely.

I’m completely stumped.  I’m going to go talk to one of our senior hardware engineers to see if he has any idea.  He knows analog video very well.  If he has any thoughts, I’ll be sure to share them.  Otherwise, please give me any thoughts you have.

xargs + sed

Tuesday, April 17th, 2007

I always forget how to chain xargs w/ sed. I use it so rarely that I always have to look it up again. Here its an example for future reference. Note that the command is `sed -i single quote single quote` not a double quote.

find . -name Makefile | xargs sed -i ” -e ’s/–parents/-p/’

Mechcommander 2 Source Code

Friday, September 8th, 2006

Mechcommander 2 came out in I think 2000 or 2001.  I bought the game and played it and found it to be enjoyable.  Probably better than the first one.  It reminds me of the old Jason Youngblood games that came out during the DOS days.  I can’t remember the name of them but I rather enjoyed them.

Well today I was downloading some Office updates.  While I was waiting for the install to finish, I scrolled down to the bottom of the download page.  It recommended that I download the source code for Mechcommander 2.  I assume this is because I had previously downloaded the XNA Beta.  The source is available here.

I have downloaded the source and am actually in the process of building it.  I thought this would be rather educational and interesting.  It’s not very often that someone outside of the gaming industry gets the full source code for a title produced by a major company.  I’m looking forward to being able to tweak the code and seeing how it affects game play.  I’ll get thechance to see how hard it can be to balance game play.

For those who are interested, there were 0 errors but 107 warnings on my build.

Microsoft XNA Development tools Beta

Thursday, September 7th, 2006

Yeah I was interested in downloading this and playing around with it.  I don’t really do GUI or game development but I thought that I might have some fun and maybe learn some things.  My ultimate goal was to be able to write silly little things for the Xbox360.  For instance, I wanted to make a simple puzzle game for Windows (which you can already get) which I could then port over to the 360 for fun.  I wanted to write my own version of the game strictly for educational purposes.  So I figured I might as well use XNA so that I could play on the xbox also.

The problem being that I have Visual Studio 2005 at home and not VS2005 Express.  I can’t install the free version of XNA unless I install the free version of Visual Studio.  That seems silly to me.  If I have a full fledged version of VS I ought to be able to use free tools just like people who didn’t acquire the full version.  Silly Microsoft.

LSI Raid cards

Monday, August 21st, 2006

So we shipped a whole bunch of products out into the field that use LSI raid cards.  The controller cards have cache on them, as do the drives.  The drive cache was left on and it ended up causing a bunch of headaches for us in the field.  Obviously it is bad to cache on both the hard drive and the controller.  If the drive loses power before it writes its cache to disk, the controller will think everything is ok when, in fact, the cached data was never written out.  It has caused drives to fail in the field and sometimes arrays do not rebuild when a drive is replaced.

So, since I did the hardware abstraction layer, which interacts with the LSI cards through their “megalib” library, I was tasked with writing an application that would disable the drive cache on all of the hard drives.  The drives in question are SATA drives, but the LSI card makes them appear as SCSI devices to Linux.

In order to disable the cache, I have to send a command directly to the drives using a pass through function in the controller cards.  After finding some good resources on SCSI commands, I found it wasn’t actually a difficult task.  But the LSI Library’s pass through is somewhat confusing to me and not very well documented.  You pass in a CDB structure (command descriptor block) that tells the drive what you want it to do (in this case modify the drive cache settings). 

The problem being that I need to modify just one bit of an entire byte.  So I have to know the value of the rest of that byte.  So I sent in a command to read the drive information.  Using the serial output on the LSI card, I can see that it is reading the HDD configuration, but I see no change in the output with write cache enabled and disabled.

The pass through function provided by LSI requires you pass in a CDB which also has a pointer to memory used for input or output (depending on the command you send).  When I try to just set the first three bytes (which are all I should need to modify the drive cache), it fails. 

So, not only does it not seem to be reading the data properly, but it doesn’t seem to write it either.  Most likely, I’m doing something wrong.  But the fact that there is no satisfactory documentation, and that I have to wait to hear from one of their developers, kind of irritates me.

But, I cannot say a whole lot here because the code my work puts out almost completely lacks documentation.  I’ve written general classes to do some basic things only to be told by someone later that we already had a class written to perform that task.  Of course, I couldn’t have possibly known that unless I delved through our source.  The problem being that we have millions of lines of code!

Edit: I forgot, I was going to put some links to some great resources that I found.
This one from answers.com talks about all the different commands you might want to issue to a SCSI device.
Here is one from Apple that shows where the WCE (write cache enable) bit is changed.

Shameless plug

Thursday, August 17th, 2006

Ok, here I am putting in a shameless plug for a friend of mine.  He wrote a time clock or time sheet program for windows.  You can find it here.

Alright, I’m not just putting it here as a shameless plug.  I think it is pretty cool.  He spent a lot of time and effort developing it in his free time.  What I find so remarkable about it is that he wrote it using pascal.  I thought it was an interesting choice.  I don’t know anything about pascal, to speak of.  I didn’t even have a class on it at school.  I’m not at all remotely interested in it as a language.  Granted that Delphi is still supposed to be pretty popular.  There are sites devoted to it.  But this friend of mine hasn’t had to do pascal programming at work for years.

If I had a lot of viewers, I’d probably get flamed for being so marvelled by the use of pascal.  But I guess it’s just a change in the wind, all programming languages tend to get phased out.  It’s sink or swim in this world.  I’ll likely have to learn some languages that I had never dreamed of some day.