Topic: Phaser1 on Arduino
Continuing the least imaginative way, here is second port of a ZX beeper engine to Arduino, in C.
This time it is an interleaving type engine. Porting approach is totally naive, just a timer interrupt at the bit output frequency, similar to the Octode implementation, but doubled because of the interleaving, with two alternating code paths. It easily works on its original sample rate of 23972 Hz (47945 Hz interrupts), and actually can work even at 44100 Hz (88200 Hz interrupts!). Didn't try higher rates because it was near the timer resolution limit with selected prescaler.
The most difficult part in the porting process was the Phaser1 format itself, it is quite tricky as you know. I chose the Beepola version, so you can just compile Phaser1 songs in Beepola and export them as BIN without player. Just don't forget that if you change the compile address in Beepola, you have to change the COMPILE_ADR in the C code too. Only the 'digital drums' version is implemented.
The song in the demo build is Mister Beep's Greetings to C64.
As for code tricks, nothing special here. The only tricky moment was catching the carry for 16-bit addition. It was done by checking if the value become lesser than it was before addition (normally should become greater), like that:
add hl,bc
jr c,...
n=acc;
acc+=add;
if(acc<n) ...