Skip to content

Instantly share code, notes, and snippets.

@TheZoq2
Created October 14, 2015 09:20
Show Gist options
  • Save TheZoq2/3d993babf9d4fd46e6a8 to your computer and use it in GitHub Desktop.
Save TheZoq2/3d993babf9d4fd46e6a8 to your computer and use it in GitHub Desktop.
CLOCK_PER_MILLIS = 218
TONE_TIME = 200
TONE_FREQS = {
"c":261.63,
"c2":523.25,
"d":293.66,
"e":329.63,
"f":349.23,
"g":392,
"a":440,
"b":493.88,
"c#":277,
"d#":311,
"f#":369,
"g#":415,
"a#":466,
"a2": 880,
"g#2": 830.61,
"g2": 783.99,
"f#2": 739.99,
"f2": 698.46,
"e2": 659.25,
"d#2": 622.25,
"d2": 587.33,
"c#2": 554.37,
"no": 50
}
song = [
("a", 1.0),
("a", 1.0),
("a", 1.0),
("f", 3/4),
("c", 1/4),
("a", 1.0),
("f", 3/4),
("c", 1/4),
("a", 2.0),
("e2", 1),
("e2", 1),
("e2", 1),
("f2", 3/4),
("c", 1/4),
("g#", 1),
("f", 3/4),
("c", 1/4),
("a", 2),
("a2", 1),
("a", 3/4),
("a", 1/4),
("a2", 1),
("g#2", 3/4),
("g2", 1/4),
("f#2", 1/4),
("f2", 1/4),
("f#2", 1/2),
("no", 1/2),
("a#", 1/2),
("d#2", 1),
("d2", 3/4),
("c#2", 1/4),
("c2", 1/4),
("b", 1/4),
("c2", 1/2),
("no", 1/2),
("f", 1/2),
("g#", 1),
("f", 3/4),
("g#", 1/4),
("c2", 1),
("g#", 3/4),
("c2", 1/4),
("e2", 2),
]
addr = 0x6000
for note in song:
freq = TONE_FREQS[note[0]]
period = 1/freq * 1000
cycles = round(period * CLOCK_PER_MILLIS)
toneLength = round(TONE_TIME / period * note[1])
print(" DC.W ${0:x}".format(cycles));
print(" DC.W #${0:x}".format(toneLength));
print(" DC.W #$1108")
print(" DC.W #$2")
#print(" MOVE.W #${0:x},${1:x}".format(cycles, addr));
#addr += 2
#print(" MOVE.W #${0:x},${1:x}".format(toneLength, addr));
#addr += 2
#print(" MOVE.W #$1108,${0:x}".format(addr))
#addr += 2
#print(" MOVE.W #$2,${0:x}".format(addr))
#addr += 2
print(" DC.W #0");
#print(" MOVE.W #0,${0:x}".format(addr));
#print(" MOVE.B #228,D7")
#print(" TRAP #14")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment