Skip to content

Instantly share code, notes, and snippets.

@moonheart08
Last active February 26, 2021 15:19
Show Gist options
  • Save moonheart08/eae1fb1764e0375d523c65a476960590 to your computer and use it in GitHub Desktop.
Save moonheart08/eae1fb1764e0375d523c65a476960590 to your computer and use it in GitHub Desktop.
' All are unrolled, as they are presumably in HUBRAM so branching == bad
' UNTESTED, may contain stupidity and/or nuts
' BAD CODE AHEAD YAY
encode_1b and inp, #$7F
_ret_ getbyte out, inp, #0
encode_2b mov tmp1, inp
and inp, #$7F
getbyte out, inp, #0
sar tmp1, #7
and tmp1, #$7F
or tmp1, #$80
_ret_ setbyte out, tmp1, #1
encode_4b skip ##%1000000000000
encode_3b altr _zero, #tmp1
and inp, #$7F
getbyte out, tmp1, #0
sar inp, #7
altr _zero, #tmp1
and inp, #$7F
or tmp1, #$80 '8
setbyte out, tmp1, #1
sar inp, #7
altr _zero, #tmp1
and inp, #$7F
or tmp1, #$80
_ret_ setbyte out, tmp1, #2
setbyte out, tmp1, #2
sar inp, #7
altr _zero, #tmp1
and inp, #$7F
or tmp1, #$80
_ret_ setbyte out, tmp1, #3
' too lazy to write branchless routine, just reusing code instead.
' for maximum speed(tm) this should be it's own thing
encode_any_s abs tmp2, inp
encode_any encod tmp2, tmp2
cmp tmp2, #7
if_le mov len, #1
if_le jmp encode_1b
cmp tmp2, #14
if_le mov len, #2
if_le jmp encode_2b
cmp tmp2, #21
if_le mov len, #3
if_le jmp encode_3b
mov len, #4
jmp encode_4b
{
cmp tmp2, #28
if_le jmp encode_4b
jmp error ' oh no!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment