@mikecios, post #422
@nogorg, post #429
@nogorg, post #431
@nogorg, post #432
@nogorg, post #433
/*mod.obbfuscated.c #obbe A @ @ = < */char *msg = /* 2 */"This C source " /* */"code file is a " /* 8 */"Protracker " /* @ */"module.\n" /* ( B @ @*/"This Protracker "/* */"module is a " /*1 1*/"C source code " /* , */"file which " /* */"implements a\n" /* ( */"pattern data " /* ( */"scrambler."; /* ( Cheers to everyone at GERP 2015 @ M.K. › / + [:0S] » ‘ -Q ^ 6 ^ ]A¦@ G x› x5 +}X x› x xI x X 0 G +T ¬]@ ¬}E T -9ST +@T G] D T G@ : ]'¬@ G 4 7 ®.^ W G ¬ ]D¬p pG a 7 + x +@]B GT x› S ^M0 7 $ 7 " 0 7 + T S]P xB 8 ¬U pG + T S] + T ¬]T + ] ¬T C:}km f X ' E X' 9 «@T T + }) + T S]T + S¶ }@ p6 SE 8 €» T c¬T + T S]E¬ ¬T hM1 7 / [SMa G [hMb pG . + ‡-c T ;.] / + [ :0S]@@/@G xS +T ¬]" 3 5 ¬< ¦M\ % 8 @ G 7 4 b + ]W ST 7 Y x› , x2 ¬& G Y G x› 4 x› x` ¬TrM` p7 + }H + ^ ¬]G» V xR 7 ¬ G T :@}]E@ T ¬M2 pY¬ x› x SR @ @VM7 X 8 T \; h]P ]0:@ST S Y ʹ$ P¬@ + ]1 }T €]@@ Y +S\0 2 @ + ]5 ST MX x› x% ]'h@ p7¬S3XMS x› + ^0 x R ¬S=8 @ P .; @M$ » :@G -®T % xb G xa pG x› xc ¬ B: ]:@ST 0 pY S 8 Q ' x 8 8 . T :0™S] S 3 x› x@ + G@ 7 G x( p8 9 xa S F —0 @ ¬» ]B¬0ST C : T :@}]E Y @ ] ¬T % G 2 8 ®.^ @ « ^0 x€ ]( ¬T R ¬kh9.f f ! SB 8 » T ST : ]4¬@ p7 @ } F » ]:@ST 6 ) Ts G x0 x S 7 x› xF : T :0}]5 S G x› 7 T G xG ¦» X › I - 1 p7» T’:@L - / [SMa G [hMb G c T ;.] b@ ]#@@ Y + 8 @ pG + T ¬] + ]Q ¬T + T ¬]! 0 C 7€» T 2¬T R € ] G¬T + F@ 7 x› ( x S E Y pX +T ¬](¦® ¦0S) G 8 D0 « T P¬T + ^0 x @ Y + T ¬]U T ¬M 7¬]2 @ SP H ¬ ]Q¬@ p7 S F ¬1 G S\ ¦M¬\ 0@T‘:MD€ T G¬] ¬VMT x› , x1}hm".f f pG / 5 / T ¬M# 7 ( 7 TsM5 7 Q 7 ¦M' +T ¬] @ 7 « ^0 x' x1 x . T :0™S]H @a « T R¬T W ! + T S]# } D « T $ST » €0 ]S}@ « T ¬T xb G xa G c + S@ 7 4 ST :M T -TST xS ʶ3 U S Y R » %0 ® ¬M" , + ] }T +@]8 GT ¬ G C x" & pG ^ 7 : ]@@ p6 :@ 8» T :0}] :@ P@ ]GS@ G Y:® €0@X: %€0 » ]):0ST ¬3SSS.» 8\0 ®¬» ]& ST ]9¬@ p7 + V 2 G ' + SM ® ` » ]5:@ST T S] ! R «T 5¬T ¬» T 0ST 9 « T S¬T ( @®T x `0 ¬L H A 0 [:0}] « T 2ST P ¬» T 8ST 3 « T S]W ]a . G ]b . pG¬ T’¦@8S]A S G G X S T SM 9 D « T ST .Y «@T AT H H x› L p7 F B G@ ¬ ]P ST + @ G x3 T :@}]%:» `:0 : T :@}]» T :0}] } + "@ 8 ¬T ¬M8 7¬» ] ¬T ( ` 7 + } S C ʶ 0 ‡« ] }T P @ c x » T ST :@ A 7 .9 ] ST ¬ ]¬p G x` x + ]9 }T Q + T ]# ‡ @» T F¬T S$ G x@ x C D : :0 5 ‡ G W €» T ¬T 6 xI :@ + ]" ¬T x› b G x› a pG . + ‡-c ! + T ¬]@ @@ p8 ® [0.]H } ) G T ”M pG ]6@ p6 Sb G Y :M @» T 6¬T ¬ x› X ](}@ 8 G + B¬@ p7 9 M ¬k hf\b f ]E G Y Y 7 x› 4 . V\0S Q & G › T :@}]V x› x S4 ® :0 ) x H 0 Q pG H x› @MV , ]Uh@ 7 FX@G x› x ‡4 7 G 6 G@ ]:@ST X «@T ]S¬ ]bX@ G + ' p G x› x D 7 » T :QST x› xW S :® €0@ F +T ¬]B x› ]b . G ]a . G x› xc 7 x› ( — b G « T bST + ]S”@ G¬¬]h@ 7 + :0 + }7 +@T G]( + ]@ ¬T @VMG A G ¬ [¦@S] + T @]Y 9 P 5 Sc G@ ]( ¬T » T :@}]E « T ¬]@ ]”@ G +] T €+::@ H ‘ ‘@ ]R€0¬T » T UST ¬ ]Y¬@ p7 # x2 x ]5@ 8¬ ]G¬@ 7 9 ¬ +¬4¦0 ] @ X x› x A}@ 8@ T ¬]1 x› x3 ¬]D@ p7 Ts¬M' 7 G 5 D ] G « 4¦0 ¬» T’ x2STs:¬]S@ pG b , « \0 ¬ G G x› x :@ x 8 » ]!:0ST x› ]b . G ]a . G c - . » ]D:@ST x› x@ + ¬@ G}k@m& f x› xB P ¬ ^ ^ « T ST X€» T Q¬T ]¦@8ST x" x x› G x› ¬M4 : ]}@ C p7¬ T 8S]) ]'¬@ 7 ¬^ 3 G@ ]@@ X « ¦0 :M ¬ G x3 x› # € ] ¬T SSS¬S x" p7 # G A x ^ $ G x› 0 «@T ]' x› C ¬4 G W « T ¬T :@ R T :@}]" x› T €» T U¬T ) :M2 ` + T ¦@8S]B S $ ( ! x› x6 › x .:@ - MV x› xA x x› L P + b@ p7¬‘hk.o m& c ¦® ¦0S ]C}@ x› xY @ @» T 8¬T @ T ¬]' S8 G G@ ¬» ]7:0ST @9 « 4\0 8 4}» -` x› G ! 7 ʶ ¬ T 8S] ^ ^ M% x S 8 C ¬\ P & x) 8 + ¬@ p7 x( 8 P 7 7 ¬^% G +T ]% +@T ]¬» ]7¬0ST x› H @6 ' 7 xT x› x » ]I ST ʹ I ¦Sk mU f: [:0S]9 ¬]@ 7 + S@ 7 ' I :M x› E +S\0 E H¬» T’¦@8S] $ b TsV G ] ST € ]H€@G¬T x› ` ¬ T’¦@8S]I + E ® ^ ¬]! ¬M9 $ s M% ST 1¬T ¬khf.f + T ¦@8S]! - T \;h]# A + T S]9 . -4 + r }c G + }G G B xR + ]C }T (¬ ]H ¬T a ® ¬}[¬}3P \ a @ Y M' x› @ G ` G G X } D Y ®P D + p G 8 x" x S 8 € ]I€@G¬T A @ ' «T ¬]U @6 « T ¬T ]}@ 8 ¬TrSM p7 S 8 T V ¬¬T SM3 G W:@ x› x » ]a:@ST ]7¬@ '@ ] @@ G :@Y 9 E 0 2 X G # $ + T ¬] E / } G€» ]V ¬T 7 X¬¬]h@ p7. x› @G x G xP ¬S 8 ]a¬@ ' " ¬ x¬» T IST R Y x› x! @ ]@@ G ¬ G x› x ®[ ]€ T €@G¬] ʹ9 F x" x 7 X p7 ®[ ] «T ¬]B @ x› x 0 4 + ]"0.T ¬¬T ¬} G x @® T x› U « ( R + }4 ¬ x` ]:@ST 7 7 C @ @ + T S]Y ¬A G Q -U +¬¦0 F 3 B x› x€» T (¬T @¬VXM` Ts G « T !ST ¬ G + 0X@GXdr ¦MQ U X & SP G « T 6¬T x1 ® ^ ¬]# S + ]V@ p6 F 7 x› x` W X€ ]F G¬T } $+ 8€0@ Y 1:» Q:0 « T ¬]8¬» T :0™S]W + T ¦@8S]c ]):@ST «@T AT ¬ G + }7 ]G}@ ' x xD x + T S] + SM ¬ ]& ¬T x› 3 P ¬9 G ¬]W@ }P ^M8 G SG 8 6 T $ ¬» T RST 1 B 7+ €0@ ]Y¦@8ST + #¬@ 7 x› x2 x› , x A 6 3: [:0S]¬» ]1 ST $ ‡ pX Q p7 V 7 ‡0 ' ¬^ H p7 ]7 G » ]2 ST : T€0 x› F + T S] % + ]X¬@ pX X xA¬ S¬} S x› xG x› X ) 7 6 Y¬=1¬p }P 6 G C G 7 » T0 ® EX@G I G xW 8 .» &\0 ® + ^ ¬]3 ^ M X # I +@T ]6 + )¬@ p7 :@ % 0 G ]Fh@ 7 ! @» T Y¬T V ' ^ MV G x› XM , xW « @T 6T S+ 8¦0S €» T I¬T G } $ « T S] X Y A 4 C =I@ + C@ ' ʹ + T ¦@8S]3 ʶ # + @ X 3 » T :8ST @» ]&€0¬T xV » T :@}]1 & ` P @ c MH U @ ]€0¬T 9 S S+ I¦0S @5 + T ¦@8S] x› x@» ]9€0¬T ( 7 V X„E ¬^ # p7 S ¬]B@ 7@3 XM1@S W¬ ]0 ST x› xU @T +S='S@ P x› x`€ ]¬@ Y SP G x" x C G x› V x R G ¬])S@ 7» €0 (”k@mT f: T :0}] » T ST ¬ S¬}8 S $}@ 6 xF x x› x% @ T ‡« ] }T Ts¬M` 7 +T ¬]V +] T Y F G + ]T0.T +T @]9 +]BS@ SP H $ 6S G R X¬L ¬ ]I¬0ST ( P + T ¦@8S]1 U ¬^ 2 G 7 T ]9 S` 8 ]¬@ p' V SW hMG 7 x@ Z & ¬]¬@ G T ]" $ Y@ ] @ Y + r:M# G SD G € T €@G¬]c@¬S XMXS ' x› a x› x @ @® ^ x7 ¬» ]@:0ST + }% ¬E 8 ^ # 7 SH pG ]h@ 7 4 p7 + }@ Y + ]T}@ 6 x x› xU ]¬@ ' ‡$ X¬ ]! ST } ) ¬ x› x & 7 ]D@ 8 S % x3 p7 $ ] @ G(» + T:@ G¬¬T hM 7 T ¬MA X @& ]@@ X @ Y @ ]¬@ pX€» ]c ¬T Q G » 0 & ¬4 2ST 0 [:0}]E « T QST S G¬ ] ¬0ST « T 2ST . '\0S :@ ¬ ]:0ST 0 c &@ ¬}! M5 T ¬M G + 7@ 7 7 —0 ! S5 } I @5 x› , x@ ]'@ 8 U ¬ ]1X@ pG xI ¬^¦M G Y x› Ts¬M) G ¬]!@ 7 € T G¬] + @ pY¬ ]Y¬@ p7 + T S] W # 8 7 G x› x'® :00 ) 1 ¬ B B c % 7 ¬ ]F ST + 4@ ' Q 3 7€» T a¬T ¬» T’ xSSTs x› x# › x :» S ¬]'@ pG x› xC G Y ‡) p' ^M 7 + ¬:@Y:: ]Q:@ST + ):0 R x } " R ‡W G 7 6 xW¬ ]:0ST 3 D ¬» T :0™S]a }@ 8 SX@G ]5@ p7 D x› x4 ¬@ x› x0 ]}@ p' x5 @A x› G¬S XMESS "@ ¬TrM 7 ) C x› P +h]@ p7 U ¬^ 6 p7 ^ ^ S! pG T S] & ¬» ]I ¬T x› x ¬]( G x› 6 + \@M p8 2 x› xU x S( G % }@ : :0 + €) x ® [0.]0 S G ¿»»)1,6GIHPNQMOUSVY\_bcefhijkkjhYB;)Ǻ&**& 4YUE—G_h$* „€€€€¦›» 0/,:|?mg`7hH+@DP ·ͨ««›•„€·€€€€ “µ(`#C?V SUh-{PHK8xmPmHw~0oD ?+((€€€€€‡€€€€€€7€ 3’ P+$;7\ ?x@U(7}Pmh1W `.H_gD ,(€µ€Ҫ€€€€ȩ舳€ ¬ԶX+ GJE+h?`_ed`=@dJ5D;V oa(87n&; €&€€€€¶„€€®€€€/(70P>k+}lS_H{|~U`/Ov0~*4$0@-€ €€€נ€€‡̘•€€·™Ĭ €⨼ » (3аk3] "tKHGD*(<+?oxP ?,د €€?€߸—اݶ‡ @€O»@¦G 2-#/ [ P‹4? ) BH MP. =( 4 N?T2o<cp ?H'!MW ‘·ү·©$¶ (BW7@U+@/?8$kH((C?$ P ·١ǘȭر°2/; M'8J?2b'@2O : /ڲ߰ߤݵ 3( D ,!< 2 + $! 2 '" & " ȵ»kUjV; ȸ»kUV j-[D[JSH`OXY\w@+<о 0))"'!-%)*,9 SdPMcUC^i-<{|``||t|jYrfHmo*QX ¶¬—’‘‘“„‰„€“‰•±€ $*06;AFKPUY]beiloruwy{|}~~~~}|{ywurolieb]YUPKFA;60*$ ĵ¦–“†„‚€‚„†“–¦ «<J{™}%m!7(”3 E˼)W\_†9‚‰}q©g"F«0o¶u.”Yi€M…Y@X< EF_8«$µVK=Y„$<,k-d7©·ө›1~-M±2s $fޮ],G•E_w7f{F}ַm8@]mx ev' gq»9•S‘Z¶R?Ҵ] OL…S¬6D„$€J5C?x“–y \‘,R·op›ػ`D]G&qj}lq*R5.Y*DGۧgz‚“±`U۫f'y±x¶ Dn^&®(V fDw’`{`iak»»̢D‘tF:~Y!F¶{››-t=‹oQMn~G Nٯ‚pv|\‡/‘Zz•|_7\o{Kt“ī Z •%Yt|ol,1Ƶ›\ͺ9qs8xMwYS9<‰s+!)V$a=‹K19#kԮ5˷)Bw2«z4f T©P,ױ»J’D†”KI®–—O—“µ›·:+qtT±‹‹•:…$”Do{L€8z¶DƃZ]l}m—‰»™"y%~™>g„€)?‚8%¦81Kul)H&dlLy\-x5v„1֢U‰@ޫ7<UQ©UFcP<US')^B3=Gw€'t^p]/4n0¦w©”\Z©H„]9bbm”‰‘^%®a=« #-™A^6BX‚øG›‹5?X@†2p%,),4V1˦`.vbd_1x–g™tu^L—~¦5@±†!4rl~C_‘Ū±™kJOrǭ–©::mGIy{qF[…kifːxN“-@n‹g••®¶‚0d‚p»?S‰$4l( pjGTb/‘‚fTwµ6:pt‹营{-Xl#.‘slm±t‰%"—‡N>–,xnlLa‡jOgv3{–27€¶ O L'‘'O GC6#ă©jb}‘=»9 b_X=s#*:6t%Ae7}ڣazSSr1~(·۬G 1g‰Nvm.>U=®kDT'3vwF3u“?i'†%1\›>gE†>ࡽdwzZ‚*‰µg8«܁qE)&n¬«Mb'p'k5k_s[»u!6( ߁ŲF»r¶a w-&eM:MoD8?j·%L *²]_±Q€}d^)u7N¶“wժwJTD( „Gh)B ™+e“U#M¬)aOW$1v2©I;AÁ@F…=Yj5€&"{EDU@N F#…vfI·gW#{n)X;›J¶;OFU6y‹Yf«’ϐ WsPk•·ԮBwo1;w!™ݰ},"•‡ȫd•*ܧz 35WѴ‰(]@&LY·v®p{ BjϫͥMGHPLs[+2,–¦ 4rwGµx+s(·~ D“I»† <Nf/p–,€•e8M^`MBuƲ©‚=h±/Y«],»F+wvz5]eEbrsnAۣz”w–•[¦~աDymb‰t”c“Mmwm0-?‰!>%,±K[6$l X¬\Fµz|=UByTԷl8U[»©&$MKcA‰O…"«f‹z“}ꯨ@}%jB--mM©v))‹0—kpB¶y6/’|SS:fG'?V‘#*f©*mµ2qdZ‰e5%«'[h\J—‹s„!Ek«‚z}“z-m,x@d_lҷ|»pahS„S]–-u1Y4»– ‡HCSd!EhT<|V7F{S+5sHܲKt©¬_ZUV|-&>&** W/B—R\MHSP‡꩷‚;6zMy07 fEXja:x<: cJΰ*wbJ€„a٢'c"2d'I¶j/JgK`}]@l;·z/dm–‹?ݭ—$lo9¶eǯ…JX*)+8·|‘u5xv Qư™F`BZftF’m{@d :?•,hJF=€jc}L’‘EŬ\©<>›Xl_ a¶,Rsx3‚lX“5d5U ;±!!X™© 2cx“l f_>‰~-@R-‚a WK@u¬BµBL#X+^J«!2>umMy›µ‘‹eo'K}ֱ_xOF|¦@p/73Vt‘¶x¬C›”]Dͧ߯SS2N±JELX€7#Ma%\nYsG%RtXx7A%1¬\7Ig\b}o(l4e4›„‘҈•$‰v–9Sx){^z$e,zixBv˽6yP‡h6{{V3 ¶ ™exµH‡U†kn;N¦r3;l}<Zc2N aBuG“GSrf>]OVO± g±q«_“ñI†W}c13m#3–±H† ”EP©xB‘Q/JµvtO/gP‹~ E/=k‰g 6 –›Sn'_:ݩsr-… I‰‰t#„+#A¶D ½»д16IPQOSY_cfikjY;&* RTEIIPURQNNUWUYceB%) » SdPMcUC^i-<{|``||t|jYrfHmo*QX ¶¬—’‘‘“„‰„€“‰•±€ SdPMcUC^i-<{|``||t|jYrfHmo*QX ¶¬—’‘‘“„‰„€“‰•±€ SdPMcUC^i-<{|``||t|jYrfHmo*QX ¶¬—’‘‘“„‰„€“‰•±€ */ /* This is mod.obbfuscated.c. Compile with a C99 compiler. */ #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef DEBUG #define dprintf printf("%s():%d ", __func__, __LINE__); printf #else #define dprintf if(0) printf #endif static const uint8_t CMD_JUMP = 0x7; static const long O_MK = 1080; static const long O_SONGLEN = 950; static const long O_SONGPOS = 952; static const long O_PATTERNDATA = 1084; static const int POSLEN = 128; static const int LLEN = 4*4; static const int PLEN = 0x40*4*4; /* Module state */ static struct { /* Each source line has a "next" line where the linear succession is copied. */ int *nextline; /* Allocation state */ int *linepool; /* Source pattern data, destination pattern data */ uint8_t *srcp, *dstp; uint8_t songlen; /* 1..64 (128) (number of positions) */ uint8_t hipattern; /* 0..63 */ } p = {NULL, NULL, NULL, NULL, 0, 0}; /* Source file, destination file */ FILE *sf = NULL, *df = NULL; void init(void) { fseek(sf, O_SONGLEN, SEEK_SET); p.songlen = fgetc(sf); /* Truncate because PT supports only 64 patterns. */ p.songlen = 64 < p.songlen ? 64 : p.songlen; p.srcp = malloc(p.songlen*PLEN); p.dstp = malloc(p.songlen*PLEN); /* Make a linear copy of file pattern data to p.srcp */ for (int i = 0; i < p.songlen; i++) { fseek(sf, O_SONGPOS+i, SEEK_SET); int j = fgetc(sf); fseek(sf, O_PATTERNDATA+j*PLEN, SEEK_SET); fread(p.srcp+i*PLEN, 1, PLEN, sf); } fseek(sf, O_SONGPOS, SEEK_SET); for (int i = 0; i < POSLEN; i++) { int j = fgetc(sf); p.hipattern = j > p.hipattern ? j : p.hipattern; } p.linepool = malloc(p.songlen*0x40*sizeof(int)); p.nextline = malloc(p.songlen*0x40*sizeof(int)); for (int i = 0; i < p.songlen*0x40; i++) { p.linepool[i] = i; p.nextline[i] = -1; } } /* Allocate a line having number n in any pattern, or nothing. */ int lines_allocmod(int n) { n%=0x40; while (n < p.songlen*0x40) { if (-1 != p.linepool[n]) { p.linepool[n] = -1; return n; } n+=0x40; } return -1; } /* Allocate any line. */ int lines_allocany(void) { for(int i = 0; i < p.songlen*0x40; i++) { int n = p.linepool[i]; if (-1 != n) { p.linepool[i] = -1; return n; } } return -1; } static const int JUMP_NONE = -2; static const int JUMP_ANY = -1; int jumptype(int l) { int absval, abs=0, any=0; uint8_t *entry = &p.srcp[l*4*4]; for (int i = 0; i < 4; i++) { if (0 == ((entry[2] & 0xf) | entry[3])) { any++; } else if (CMD_JUMP == (entry[2] & 0xf)) { abs=1; absval=entry[3] % 0x40; } entry+=4; } if (abs && any) { return absval; } else if (1 < any) { return JUMP_ANY; } else { return JUMP_NONE; } } /* Find and allocate absolute line allocations. */ void pass1(void) { int i, jt, n=0; lines_allocmod(0); for (i = 0; i < p.songlen*0x40-1; i++) { /* Get preference */ jt = jumptype(i); if (0 <= jt) { /* Absolute allocation */ n = lines_allocmod(jt); if (-1 == n) { printf("ABS: i=0x%04x, n=0x%04x, jt=0x%04x: allocation: FAIL\n", i, n, jt); } else { dprintf("ABS: i=0x%04x, n=0x%04x, jt=0x%04x: allocation: PASS\n", i, n, jt); p.nextline[i] = n; } } else if (JUMP_ANY == jt) { /* This is an ANY allocation: processed in next pass. */ } else { printf("NONE: i=0x%04x, n=0x%04x, jt=0x%04x: allocation: FAIL\n", i, n, jt); } } /* Force jump from last line to first. */ p.nextline[i] = 0; } /* Arrange the n elements of array in random order. */ void shuffle(int *array, int n) { for (int i = 0; i < n-1; i++) { int j = i + rand() / (RAND_MAX / (n - i) + 1); int t = array[j]; array[j] = array[i]; array[i] = t; } } void pass2(void) { /* First randomize the remaining lines */ shuffle(p.linepool, p.songlen*64); for (int i = 0; i < p.songlen*0x40; i++) { /* Get preference */ int jt = jumptype(i); int n = p.nextline[i]; if (JUMP_NONE != jt) { /* Absolute or any allocation */ if (-1 == n) { /* Not already allocated (could also be unresolved absolute jumps. */ int a; a = lines_allocany(); dprintf("ANY: i=0x%04x, a=0x%04x: allocation: PASS\n", i, a); p.nextline[i] = a; } } else { printf("NONE: i=0x%04x, n=0x%04x, jt=0x%04x: allocation: FAIL\n", i, n, jt); } } { int a; while (-1 != (a = lines_allocany())) { printf("Unallocated line: a=0x%04x: FAIL\n", a); } } /* Verify */ for (int i = 0; i < p.songlen*0x40; i++) { /* Get preference */ int m = p.nextline[i]; if (m == -1) { printf("i=0x%04x has no next line installed: FAIL\n", i); } for (int j = 0; j < p.songlen*0x40; j++) { int n = p.nextline[j]; if ((m == n) && (i != j)) { printf("Loop detected: i=0x%02x, j=0x%02x, n=0x%02x: FAIL\n", i, j, n); } } } } void setjump(uint8_t *entry, int jt, int dline) { uint8_t pos = dline/64; uint8_t row = dline%64; /* B command must be BEFORE D command */ if (JUMP_NONE == jt) { /* do nothing */ } else if (JUMP_ANY == jt) { int found = 0; for (int i = 0; i < 4; i++) { if (0 == ((entry[2] & 0x0f) | entry[3])) { if (0 == found) { entry[2] |= 0x0b; entry[3] = pos; } else if (1 == found) { entry[2] |= 0x0d; /* Next position of the song and the row row. */ /* Silly decimal representation! */ entry[3] = (row/10)*16 | (row%10); } found++; } entry+=4; } } else { /* JUMP_ABS */ int bdone = 0; for (int i = 0; i < 4; i++) { uint8_t cmd = entry[2] & 0x0f; if (CMD_JUMP == cmd) { entry[2] &= 0xf0; entry[3] = 0x00; } if ((0 == (cmd | entry[3])) || (CMD_JUMP == cmd)) { if (0 == bdone) { entry[2] |= 0x0b; entry[3] = pos; } else if (1 == bdone) { entry[2] |= 0x0d; entry[3] = (row/10)*16 | (row%10); } bdone++; } entry+=4; } } } /* Copy each source line to destination. */ void pass3(void) { int dl; dl = 0; for (int sl = 0; sl < p.songlen*64; sl++) { memcpy(&p.dstp[dl*LLEN], &p.srcp[sl*LLEN], LLEN); int next = p.nextline[sl]; int jt = jumptype(sl); setjump(&p.dstp[dl*LLEN], jt, next); dl = next; } } void dump(void) { char c; int i; fseek(sf, 0, SEEK_SET); for(i = 0; i < O_SONGLEN; i++) { c = fgetc(sf); fputc(c, df); } fputc(p.songlen, df); fputc(127, df); for (i = 0; i < p.songlen; i++) { fputc(i, df); } for (;i < POSLEN; i++) { fputc(0, df); } fwrite("M.K.", 1, 4, df); fwrite(p.dstp, PLEN, p.songlen, df); fseek(sf, O_PATTERNDATA+(p.hipattern+1)*PLEN, SEEK_SET); while ( EOF != (i = fgetc(sf))) { fputc(i, df); } } void tryopen(int argc, char *argv[]) { if (argc < 3) { printf("%s SOURCE DEST\n", argv[0]); exit(EXIT_FAILURE); } if (NULL == (sf = fopen(argv[1], "r"))) { printf("%s: open failed\n", argv[1]); exit(EXIT_FAILURE); } if (NULL == (df = fopen(argv[2], "wb"))) { printf("%s: open failed\n", argv[2]); exit(EXIT_FAILURE); } fseek(sf, O_MK, SEEK_SET); char buf[4]; fread(buf, 1, 4, sf); if (strncmp(buf, "M.K.", 4)) { puts("No Protracker magic string"); exit(EXIT_FAILURE); } } int main(int argc, char *argv[]) { puts(msg); tryopen(argc, argv); init(); pass1(); pass2(); pass3(); dump(); return EXIT_SUCCESS; }
@nogorg, post #432
od paru lat i mnie pata si podobna idea po gowie tym e zastanawiaem si czy da si wygenerowa tego typu cae akordy, ktre nadal bd miay rozmiar nadajcy si do chiptune. Matematycznie wzgldnie atwo jest wyliczy odpowied natomiast dwikowo mona dopuci si pewnych niedokadnoci i zaokrgle.