Random line of code thread
category: code [glöplog]
Code:
@panic
; oh god oh fuck
ld hl,DS_TempSP
ld a,[hl]
inc l
ld h,[hl]
ld l,a
ld sp,hl
jp DevSound_StopMusic
actually 9 lines but whatever
One-liner which plays DRM protected content from Audible using ffplay, ffprobe & rainbowcrack:
Code:
ffplay -activation_bytes $(./rcrack . -h $(ffprobe $1 2>&1 | grep 'file checksum == ' | awk -F ' == ' '{print $2}') | grep 'hex:' | awk -F ':' '{print $2}') $1
Oh and it's inAudible-NG's build of rainbowcrack I was referring to. It contains pre-generated rainbow tables to retrieve your Audible activation code.
Code:
lea $180+PatchCodeSize_NTSC(a0),a2
Code:
#include <Windows.h>
#include <set>
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
std::set<int> rates;
DEVMODE mode, current;
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, ¤t);
int i = 0;
while (EnumDisplaySettings(NULL, i++, &mode)) {
if (mode.dmPelsWidth == current.dmPelsWidth && mode.dmPelsHeight == current.dmPelsHeight && mode.dmBitsPerPel == current.dmBitsPerPel) {
rates.insert(mode.dmDisplayFrequency);
}
}
char key = '1';
for (int rate : rates) {
RegisterHotKey(NULL, rate, MOD_CONTROL | MOD_ALT | MOD_WIN, key++);
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
if (msg.message == WM_HOTKEY) {
int rate = static_cast<int>(msg.wParam);
if (rates.count(rate)) {
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, ¤t);
current.dmDisplayFrequency = rate;
ChangeDisplaySettings(¤t, CDS_UPDATEREGISTRY);
}
}
}
return 0;
}
Code:
//https://stackoverflow.com/questions/277772/avoid-trailing-zeroes-in-printf
//adapted from paxdiablo (removed truncating)
char StringForDouble[50];
char *PointerInString;
void PrintDouble(double number) {
sprintf(StringForDouble,"%.10f",number); // convert number to string
PointerInString=strchr(&StringForDouble[0],'.'); // find decimal point, if any
if(PointerInString!=NULL) {
PointerInString=strchr(&PointerInString[0],'\0'); // find end of string
PointerInString--;
while(PointerInString[0]=='0') { // remove trailing zeros
PointerInString[0]='\0';
PointerInString--;
}
if (PointerInString[0]=='.') { PointerInString[0]='\0'; } // if all decimals were zeros, remove "."
}
fprintf(filep,"%s",&StringForDouble[0]);
}
Code:
int pos=(int(sin(y/80.0-n*10)*100+sin(-y/50.0+n-frameCount/23.0)*100+200)+frameCount*8)%256;
When looking back at it this morning. Is it any better?
Code:
//https://stackoverflow.com/questions/277772/avoid-trailing-zeroes-in-printf
//adapted from paxdiablo (removed truncating)
char StringForDouble[50];
char *PointerInString;
void PrintDouble (double number) {
sprintf(StringForDouble,"%.10f",number); // convert number to string
PointerInString=strchr(&StringForDouble[0],'.'); // find decimal point, if any
if(PointerInString!=NULL) {
PointerInString=strchr(&PointerInString[0],'\0'); // find end of string
do{
PointerInString--;
} while(PointerInString[0]=='0'); // remove trailing zeros
if (PointerInString[0]=='.') { // if all decimals were zeros, remove "."
PointerInString[0]='\0';
} else {
PointerInString[1]='\0'; //otherwise put EOS after the first non zero char
}
}
printf("%s",&StringForDouble[0]);
}
col -= foo(vec2(s*0.000000000000000000000674022 * uv.yx));
Code:
char I[1<<28];size_t K=0,H;long J,_,E;double O,L;
size_t R(){return I[K++];}
long ri(){for(L=_=1,J=0;H=R()-43,H<3&&(_=1-H)||H-5<10&&(J=J*10+H-5,1);L*=10);return J;}
double rf(){O=ri();E=_;H<4?O+=ri()/L:0;return(H-26<33?pow(10,ri()*_):1)*O*E;}
int main() {
fread(I,1,sizeof I,stdin);
// use ri()*_ to read longs or rf() to read doubles
}
Code:
cmp.w C64TimerAValue(a6),d0
U-boot time!
Code:
# Now it's time for some trickery: are we running on a Zybo or a Zybo-Z7?
#
# The Z7 has 1 GiB of RAM, compared to 512 MiB on the old Zybo. I.e. the latter only
# has 0x2000_0000 DRAM bytes, while the Zynq SoC maps the entire
# 0x0000_0000..0x3fff_ffff address range to DRAM. Thus, the old Zybo simply
# mirrors 0x2000_0000..0x3fff_ffff to 0x0000_0000..0x1fff_ffff .
#
# Why is this interesting to us? Well, we can write one pattern to 0x2400_0000,
# another to 0x0400_0000, and see if 0x2400_0000 suddenly contains the second
# pattern written to the low address. If so, we are running an old Zybo.
# Fill memory areas
mw ${testaddr_lma_hi} 0x69420 8
mw ${testaddr_lma} 0x1337 8
if cmp ${testaddr_lma} ${testaddr_lma_hi} 8; then
echo "Running on Zybo 1st ed"
# [snip] (load zybo dtb)
else
echo "Running on Zybo-Z7"
# [snip] (load zybo-z7 dtb)
fi
Quote:
move.l #($4eae<<16)|(-636&$ffff),d0
Code:
armi.a1=atan2((-l2*sin(armi.a2)*x+(l1+l2*cos(armi.a2))*y),(l2*sin(armi.a2)*y+(l1+l2*cos(armi.a2))*x));
today i implemented a switch in a switch... you don't do that very often, so i felt very xzibit
Code:
two_pints = 2 * math.pi * n * t
Quote:
:DCode:two_pints = 2 * math.pi * n * t
taunting us with that one
Code:
cmp.b #(($c00000-$80000)>>16),d1
Code:
static sF32 loc_sum_partials(const sF32 *_tbl, sU16 *_phases, const sU16 *_speeds, const sF32 *_amps) {
sF32 r = 0.0f;
for(sUI i = 0u; i < 256u/*sample->num_partials*/; i++)
{
r += _tbl[_phases[i]] * _amps[i];
_phases[i] += _speeds[i];
}
return r;
}
(you need an FFT for this. sounds *lush*)
Code:
// TODO: urgent, must fix before 1st release!
How many years after the first release was the line unearthed?
It's fiction. I can't recall if I have seen it or not.
Code:
ld hl,DFP_UpdateFlags
push bc
ld a,0
inc c
scf
: rla
and a
dec c
jr nz,:-
or [hl]
ld [hl],a
pop bc