Apache Strike

One of our favourite games, Apache Strike, is now partially working. The game has a weird way of checking machine memory by writing/reading value beyond RAM space, which had just to be handled with special case to not raise a page mapping error from virtual memory system. The music (it’s using Sound Driver) is working OK, and main menu is shown properly:

However, some unresolved CPU bug seems to be causing the 3D rendering to fail, with only vertical lines appearing on the screen. Also controls don’t work yet, but it might be because we don’t yet completely support moving the mouse location by writing to low memory cursor globals from applications.

Here’s a short video with just the main menu and the music playing in background:

Disassembler

Pukka had been working long on the disassembler, and we were finally able to get first version of it integrated with the emulator. Below is a simple partial disassembly of Tetris audio mixer VBL, executed from Xcode debugger command prompt:

Partial disassembly of the Tetris 6-channel audio mixer VBL handler

Although the disassembler itself still has some minor quirks to fix, there were some interesting bits we found about the Tetris mixer code in this disassembly:

  • Unlike Sound Driver, which has 4-channel mixer, Tetris uses a 6-channel mixer
  • The audio is downsampled from 22256 Hz to 11128 Hz by writing each sampled byte twice (the $7000(A6) at 00030C18 is supposed to be 2(A6) in disassembly)
  • The division of summed samples by 6 is done by pre-calculated lookup table (which has 6×256 = 1536 entries)
  • The pitch of channels is controlled by directly writing the fixed-point pitch into mixer code at addi.l instructions from 30BAA to 30BC8

SANE, and Railroad Tycoon map generation

After we got the Railroad Tycoon main menu to work, we were able to proceed all the way until map generation. This part of the code uses Pack4 (FP68K) dispatcher to run some certain floating-point operations, so we had to implement the following SANE operations:

  • FINTX
  • FMULS
  • FDIVS
  • FS2X
  • FX2S
  • FI2X
  • FX2I
  • FL2X

The tricky part was, that SANE operates on 80-bit extended floating-point numbers, but modern CPUs use only 32- and 64-bit floating point numbers. Following the conventions Apple used in the SANE implementation for PowerPC, we convert the 80-bit extended numbers into 64-bit “double” values for calculation, and convert them to required destination format (depending on operation, usually the 80-bit extended) again.

Map of europe in Railroad Tycoon, after passing through map generation

I’m however not sure if the 80-bit conversion is correctly implemented at the moment, but it seems to work for now, as after adding these couple operations, we immediately got the map generator to pass through successfully:

Railroad Tycoon runs now successfully through map generation, until crashing at unimplemented List Manager dispatcher

Dragging things around

As work on Window Manager was advancing quickly, and things are getting more and more complete for the phase 1, next up was one key feature: Dragging the windows. The Toolbox uses a generic “DragTheRgn” routine, which is shared by a few key parts:

  • Window dragging
  • Scroll bar thumb dragging
  • DragGrayRgn trap

So when we implemented this routine, we got got core support for all of them (except scroll bar thumb, as the scroll bar CDEF 1 was not yet implemented).

DragWindow works, in this case 3-D Maze main window

Thanks to DragGrayRgn, the “1000 Miles” game is now playable as it uses it to drag cards around the deck. It’s however still missing some secondary features: Menu selection, multi-line text drawing and Standard File Package are not yet implemented at this point.

The “1000 Miles” is now playable

Dark Castle (and BDC) almost works

During the Christmas holidays, Pukka was busy fixing 68K emulator bugs (including or.b/w/l and move.m instructions), and we can now play Dark Castle (without sound) at least through a few rooms, until it finally crashes in Shield 3:

Dark Castle is now almost working in MACE. No sound yet, but Shield 1 and Shield 2 can be played until crash in Shield 3

And as a bonus, here’s title screen of Beyond Dark Castle:

Title screen of Beyond Dark Castle

PICT version 2 support (monochrome)

As we got Railroad Tycoon intro to load further, we encountered one PICT resource which was a bit different from the others: It was a version 2 picture, while all previous pictures in the same game were simple version 1 PICTs. It appears that when apple added support for the new version 2, they also added rudimentary system software patches to the old-style QuickDraw on “Classic” type macs to handle the new opcodes. Without support for these opcodes, the classic QD would just ignore picture data and display nothing.

The interesting part of these version 2 format patches is the fact, that it allows non-color QuickDraw to take PixMap data, and map it using a simple 50% threshold to either black or white in a regular monochrome bitmap. Also, any unsupported picture opcodes get ignored using the simple dummy StdOpcodeProc implementation for non-color QuickDraw. So, to make this type of pictures show, we had to implement all of this color mapping functionality, resulting in this:

Almost got it right on the first attempt…

Well, almost got it…just accidentally incremented a pointer twice during the color mapping loop. After quick fix, this is what we had:

There we go! Nice version 2 PICT color-mapped and displayed correctly

Tetris

With recent updates to Control Manager, and fixes to CPU emulation, we can now proceed in Tetris all the way to gameplay:

It’s not perfect yet, as clearing horizontal rows causes weird graphical corruption on screen – but it appears to be quite stable, music working and levels can be played through (although the graphical glitch makes it playing bit difficult). Here’s also a short video of the status of running Tetris in MACE at this point (with audio):

Tetris intro and one level running on MACE

Merry Christmas from MACE team!

What could possibly be better way celebrate the holidays, than implementing SecondsToDate trap in time to get the Dark Castle Christmas day easter egg visible? 🙂

Christmas tree in Dark Castle’s Great Hall on 25th of December 🙂

In the land of odd bugs

These few weeks have been mostly bug fixing, and improving things to get the test applications to run further. This includes fixing the OR masking bug in Dark Castle, adding keyboard controls so we can actually move the character, and trying out different things. A lot has improved, but there’s still work to be done. At this point it might be appropriate to document some of the most strange bugs we had so far:

Broken bird sprite in Dark Castle

Most of Dark Castle levels load, but Fireball 1 crashes because of a buggy bird sprite.

Helicopter “trails” in Stunt Copter

There’s something wrong in the 68K code Stunt Copter uses to translate mouse movement to copter speed, causing trails to be left on screen after exceeding movement speed. Another issue with Stunt Copter is that it runs way too fast, but after experimentation we formulated a toolbox patch which would allow throttling the speed to make game actually playable.

Teleporting boulders in Dark Castle

And although Dark Castle starts to get playable, we still have issue of boulders teleporting around, and character falling through the floor 🙂

Control Manager, Icon Quest and Dark Castle main menu

One critical part of UI was still missing at this point, the Control Manager. Luckily implementing it was quite simple, as like with Window Manager, a lot of the core functionality depends on QuickDraw to do the difficult things.

IconQuest intro dialog

With support for Controls, we could now use buttons, like one in the above IconQuest introduction dialog, and the buttons below in Dark Castle main menu using ModalDialog:

Dark Castle main menu, almost working

The buttons still need titles, checkbox implementation is not complete, and TrackControl is implemented as a immediate return, but that is enough to allow entering The Great Hall in Dark Castle:

The Great Hall, with some bugs to iron out…

With this test case, Pukka identified a bunch of CPU bugs, including lack of BCD (Binary Coded Decimal) support which Dark Castle uses to display the values at bottom of the screen, which will be fixed next.