My task was simple. My code needed to (a) replay the full pop song sample (preferably using the YM2149 chip), whilst (b) simultaneously displaying one or more visual effect(s) for the audience to watch (preferably using the Shifter chip). To fit the heritage aesthetic of the work I elected to implement a traditional 16 pixel-wide vertical scroll-text, complemented by a modern, "new school" colour flashing logo. All effects would be delivered in buttery-smooth 50fps, and surrounded by Stiffler's Mom's pixel-perfect art.
However, identifying the effects was but the easy part. Much more tricky was the fact that I had never programmed so much as a central heating timer until now, let alone an Atari ST. I needed expert advice - and fast. At a time like this there is only one place to turn, and that is Atari Forum.
At no other location on the internet is there such intense concentration of Atari ST programming and technical knowledge - a living, breathing encyclopaedia of all things Atari. With some trepidation I registered an account, and made my first tentative post: a general enquiry about the best programming language through which to replay a full pop song. As I refreshed my browser, within seconds terse and dispassionate replies began to appear. By the five minute mark, I had been utterly overwhelmed by responses consisting of impenetrably dense jargon, including but not limited to:
(i) XaAES
(ii) ATW800/2
(iii) NoSTalgia
(iv) PiSCI
(v) FreeMiNT
(vi) CTR14 Gerber
(vii) rmac
(viii) Cornolio 0.8
(ix) Phase Scrolling Using The BLiTTER and Shifter Chips
(x) Aranym
(xi) ThorstenOtto
(xii) Squid Proxy
In short, I had absolutely no fucking idea what was going on. But things were to take an even worse turn: my entirely innocent follow-up post was misconstrued as besmirching EmuTos, leading to a permanent ban from the forum in under seven minutes!
I tried to regroup. Luckily, I still could access the forum in an unofficial "read only" capacity, allowing just enough wiggle room to conduct a rapid scoping review of popular Atari ST programming languages. I quickly ruled out 68000 assembly language (too difficult), Pure C (too difficult), GFA Basic (too cliquey), STOS Basic (too odd) and Omicron Basic (too niche). However, an inadvertent tangent down a general MIDI forum wormhole drew my attention to one "FAST Basic". This hitherto-unknown language immediately stood out, as I assumed it to be both fast (meaning that it uses little CPU, therefore is apposite for creating buttery-smooth 50fps demo effects) and basic (meaning that it is ideally suited to the level of a beginner such as I). Perfect!
With my language selected, my attention turned to tech. The primary function of the demo was to replay a full pop song, hence I surmised that sample playback had to form the core of the demo's code. Thankfully, FAST Basic offers a simple command - foo = SamplePlay (freq,length,mempos) - which is designed exactly for this purpose. Even more helpfully, the command returns true if the sample at mempos is software-detected as reflecting a full pop song. This functionality is particularly helpful as it adds a level of anti-hacker assurance to the code; the intro cleanly exits to GEM if no full pop song is detected.
Within minutes, I had Marrowfat's sample blasting through my earphones like it was 1995! However, I then hit an immediate problem. The Atari STMF is equipped with five programmable interrupt timers ("A" through "E"), and SamplePlay commissions all of them in service of its sonic sorcery. Whilst this multi-interrupt approach provides an exquisitely high level of audio fidelity, as a trade off over 98% of CPU is used by the command, regardless of sample frequency. How on earth could a buttery-smooth 50fps 16 pixel-width vertical scrolling text be displayed in addition to this full pop song playback?
I should not have worried - demosceners of yore were ready to sweep heroically to my rescue. Back in 1987, a coding technique was invented that revolutionised the Atari ST demoscene - the so-called "sync scrolling" method. Named after the Swedish crew SYNC, this ingenious approach remained a closely guarded secret for decades. In these more open and democratic times, it is now widely accepted that the sync scrolling "trick" is to reprogramme the IKBD keyboard processor to enable pixel-perfect adjustment of the video screen pointer. This enables lightning-fast scrolling of the entire screen. In fact, sync scrolling is so fast that it actually uses negative CPU, physically moving the electron beam upwards and thereby unlocking precious cycles for the hungry democoder to devour.
Sync scrolling is a highly specialist technique which must therefore be treated with caution by newcomers. Thankfully though, FAST Basic comes with its own sync scrolling module, which can be accessed through a simple and user-friendly command set. There was just one final problem to solve: sync scrolling moves the entire visible 320x200 screen, whereas I needed to shift only a 16x180 pixel column of scrolling text. The solution is well known to any seasoned demo coder: by simply redrawing the entire rest of the screen every frame, the seamless illusion that only the scroll-text is in motion is created.
With relative ease, I now had Marrowfat's sample replaying perfectly, accompanied by a buttery-smooth vertical scroll-text snaking up the screen in arcade quality 50fps. The satisfaction was immense, and incredibly, my source code was still only five lines long! The final piece of the jigsaw was to sprinkle some contemporary "freshness" into the work with a modern, colour-flashing logo effect. Thankfully, with 20% CPU still remaining and a generous 8mb of RAM, I was able to integrate an "animation" of 16 sequentially-displayed logos, each drawn using a different colour, without negatively impacting upon frame rate. Whilst pre-calculation of this kind is typically frowned upon in the demoscene, I considered it a defensible compromise given the ever-mounting technical complexity of the intro.
My work was done. In total, the codebase for this demo took only 16 minutes to create, with 12 of those minutes spent commenting the source. I sat back, both satisfied and satiated, in front of an A+ intro that was suddenly approaching completion. The only downside was that, for reasons I could not fully understand, the intro failed to run on STEs - never mind though! What a journey so far - now, it was the turn of Stiffler's Mom to board the Scatman train!

No comments:
Post a Comment