Friday 11 September 2009

...And on to the Amiga

Like many companies in the 1980s I decided to take my first steps onto the Amiga in the time-honoured traditional manner - by cutting and pasting my existing Atari ST code into Devpac Amiga and fiddling the screen output routines a bit. Okay it was slightly more effort than that, but not much. Most of the effort was put into removing code rather than adding it.

Although the screenshot doesn't seem to show much happening the screen is nicely divided up under the control of the copper coprocessor, with a 320x43x4 planes (16 colours) logo at the top, a 4-plane screenbuffer in the middle for rendering effects to (double buffered, naturally) and a 1-bitplane scrolling message along the bottom. There's also a protracker module playing in the background. Because the screen splits are all handled by the copper there's no interrupt uncertainty so the splits are 100% rock solid and no CPU time is lost.

The great thing here is the 'red bar of doom' code profiling method is in effect (turn the border red when your frameloop starts, turn it black when you're done and the thicker the red area the less CPU time you have) but there's nothing showing. If you remember I said the scroller alone on the ST used about 15% of the CPU time. In the Amiga code the bar doesn't even show.

This is what I love about the Amiga - the flexibility of the display hardware. It's a pain to set up (out of 3 days trying to get this going about half was spent just trying to get the screen setup without crashing the OS) but well worth it once you manage it. The ST version worked with an off-screen buffer 336 pixels wide (1 screen plus space for one character) and every frame each byte of graphics data had to be loaded, moved 2 bits to the left, the overflow put into the preceding byte and everything written back. It also had to be copied to the screen (not even using the fast block copies due to the annoying ST plane format) in the correct place.

The Amiga version is more cunning - the scroll buffer is now 84 bytes wide (twice as wide as it was) and each frame the hardware fine scroll is incremented by 2. when that overflows after moving 16 pixels the screen address is incremented 2 words until we've moved along to the right of the buffer. So where do we go then? well every 8 frames we draw the new character twice, so by the time we reach the right hand side of the buffer the left contains an identical copy of it so we can seamlessly snap back to the beginning. This means instead of moving 672 bytes left 2 pixels, then copying those 672 bytes to the screen as on the ST we're just writing 2 bytes every frame (for the fine scrolling), and 70 bytes every 8 frames (2 new characters to draw and to reset the graphics pointer).

Even with an increased resolution of 320x256 and an extra bitplane to bring us up to 32 colours it looks like there's going to be a lot more time on the Amiga for doing stuff.

..and I haven't even touched the blitter yet.


No comments:

Post a Comment