#!/usr/bin/python

conv_factor = 53693100.0 / 0x7e000000

def ym2612_hz(fnum, block):
    return fnum * (2 ** block) * conv_factor

def ym2612_vals(hz):
    fnum = hz / conv_factor
    block = 0
    while fnum >= 2048:
        fnum /= 2.0
        block += 1
    return (block, int(round(fnum)))

print ym2612_hz(1083, 4) # ~ 440 Hz
print ym2612_vals(440)   # Should give us 4, 1083 back
print ym2612_vals(523)   # Should give us 4, 1287

@@ -259,22 +259,14 @@
     
-return (block,
+fnum =
  int
@@ -282,148 +282,897 @@
 um))
-)%0A%0Aprint ym2612_hz(1083, 4) # ~ 440 Hz%0Aprint ym2612_vals(440)   # Should give us 4, 1083 back%0Aprint ym2612_vals(523)   # Should give us 4, 1287
+%0A    return (block %3C%3C 11) %7C fnum%0A%0Adef freq(noteval, octave):%0A    val = 4 * 12 + 10  # A-440%0A    target = octave * 12 + noteval%0A    step = 2.0 ** (1.0 / 12)%0A    return ym2612_vals(440.0 * (step ** (target - val)))%0A%0Anotes = %5Bfreq(x, 4) for x in %5B1, 3, 5, 6, 8, 10, 12, 13%5D%5D%0Aprint %22        defb    $3C,$21,$30,$71,$34,$0D,$38,$33,$3C,$01%22%0Aprint %22        defb    $40,$23,$44,$2D,$48,$26,$4C,$00,$50,$5F%22%0Aprint %22        defb    $54,$99,$58,$5F,$5C,$94,$60,$05,$64,$05%22%0Aprint %22        defb    $68,$05,$6C,$07,$70,$02,$74,$02,$78,$02%22%0Aprint %22        defb    $7C,$02,$80,$11,$84,$11,$88,$11,$8C,$A6%22%0Aprint %22        defb    $90,$00,$94,$00,$98,$00,$9C,$00,$B0,$32%22%0Aprint %22        defb    $B4,$C0,$A4,$%2502X,$A0,$%2502X,$28,$F0%22 %25 (notes%5B0%5D %3E%3E 8, notes%5B0%5D & 0xff)%0Afor note in notes%5B1:%5D:%0A    print %22        defb    $3C,$03,$A4,$%2502X,$A0,$%2502X,$28,$F0%22 %25 (note %3E%3E 8, note & 0xff)%0Aprint %22        defb    $00%22
 %0A

Create a scale with a 'grand piano' instrument preset