Skip to content

Instantly share code, notes, and snippets.

@marcan
Created December 22, 2018 10:09
Show Gist options
  • Save marcan/87fc1bdaecdbcfef9aac225311deed15 to your computer and use it in GitHub Desktop.
Save marcan/87fc1bdaecdbcfef9aac225311deed15 to your computer and use it in GitHub Desktop.
Alesis Vortex Wireless 2 patch to send MIDI messages when pressing the ribbon bank buttons
from asm import *
blob = open("image.bin", "rb").read()
start_addr = 0x08003000
patch_start = start_addr + len(blob)
assert patch_start % 4 == 0
code = """
.syntax unified
.thumb_func
send_event_and_change_ribbon:
push {r3-r5, lr}
mov r4, r0
mov r5, r1
bl %(change_ribbon_bank)d
add r4, #102
strb r4, [sp,#1]
strb r5, [sp,#2]
mov r0, #0xb0
strb r0, [sp]
movs r1, #3
mov r0, sp
bl %(send_midi_event_a)d
movs r1, #3
mov r0, sp
bl %(send_midi_event_b)d
movs r1, #3
mov r0, sp
bl %(send_midi_event_c)d
pop {r3-r5, pc}
""" % {
"change_ribbon_bank": 0x08008645,
"send_midi_event_a": 0x080045Ad,
"send_midi_event_b": 0x080043F1,
"send_midi_event_c": 0x080046A1,
}
patch_locs = [
0x08005862,
0x0800588E,
0x080058BA,
]
c = THUMBAsm(code, patch_start)
c.objdump()
blob += c.data
for i in patch_locs:
p = THUMBAsm("bl %d" % (c.send_event_and_change_ribbon+1), i)
#p.objdump()
#print(len(p.data))
assert p.start == i
assert len(p.data) == 4
blob = blob[:p.start - start_addr] + p.data + blob[p.end - start_addr:]
open("patched_image.bin", "wb").write(blob)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment