Author Topic: Updated BASFILE/BIN2BAS programs. Generates MUCH smaller code.  (Read 2089 times)

0 Members and 1 Guest are viewing this topic.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
I have updated the BASFILE (BIN2BAS previously) code to use the new _DEFLATE/_INFLATE commands which drastically shrinks the outputed BAS code.

BASFILE/BIN2BAS converts binary files to BAS code that when run can recreate the binary file.  Here's the new version for QB64GL 1.4.

- Dav

NOTE: Code now updated to v0.21 to fix problem with the @ symbol when posting code to forum.

Code: QB64: [Select]
  1. '==================
  2. ' BASFILE.BAS v0.21
  3. '==================
  4. 'Coded by Dav for QB64GL 1.4, MAY/2020
  5.  
  6. 'Fixed in v0.21: Replaced the @ symbol in encoded BAS output to a forum
  7. '                friendly character so code can be pasted in the QB64 forum
  8. '                without breaking it.
  9.  
  10. 'Added in v0.20: Now uses _DEFLATE/INFLATE to make smaler output
  11.  
  12. '======
  13. 'ABOUT :
  14. '======
  15.  
  16. 'BASFILE helps you include binary files INSIDE your QB64 compiled programs.
  17. 'It does this by converting file to BAS code that you add to your program
  18. 'that will recreate the file when you wish to use it.
  19.  
  20. 'BASFILE will ask you for a file to convert, and will output the BAS code.
  21.  
  22. '=========================================================================
  23.  
  24. DEFINT A-Z
  25.  
  26. PRINT "============="
  27. PRINT "BASFILE v0.21"
  28. PRINT "============="
  29.  
  30. INPUT "INPUT File --> ", IN$: IF IN$ = "" THEN END
  31. INPUT "OUTPUT File -> ", OUT$: IF OUT$ = "" THEN END
  32. IF LOF(1) = 0 THEN
  33.     CLOSE: KILL IN$
  34.     PRINT UCASE$(IN$); " not found!": END
  35.  
  36. 'Grab whole file as a string
  37. INDATA$ = (INPUT$(LOF(1), 1))
  38.  
  39. 'Compress it
  40. INDATA$ = _DEFLATE$(INDATA$)
  41.  
  42. PRINT: PRINT "Encoding file...";
  43.  
  44. Q$ = CHR$(34) 'quotation mark
  45. PRINT #2, "A$ = "; Q$; Q$
  46. PRINT #2, "A$ = A$ + "; Q$;
  47.  
  48. BC& = 1
  49.  
  50.     a$ = MID$(INDATA$, BC&, 3)
  51.     BC& = BC& + 3: LL& = LL& + 4
  52.     IF LL& = 60 THEN
  53.         LL& = 0
  54.         PRINT #2, E$(a$);: PRINT #2, Q$
  55.         PRINT #2, "A$ = A$ + "; Q$;
  56.     ELSE
  57.         PRINT #2, E$(a$);
  58.     END IF
  59.     IF LEN(INDATA$) - BC& < 3 THEN
  60.         a$ = MID$(INDATA$, LEN(INDATA$) - BC&, 1): B$ = E$(a$)
  61.         SELECT CASE LEN(B$)
  62.             CASE 0: a$ = Q$
  63.             CASE 1: a$ = "%%%" + B$ + Q$
  64.             CASE 2: a$ = "%%" + B$ + Q$
  65.             CASE 3: a$ = "%" + B$ + Q$
  66.         END SELECT: PRINT #2, a$;: EXIT DO
  67.     END IF
  68. LOOP: PRINT #2, ""
  69.  
  70. PRINT #2, "btemp$="; Q$; Q$
  71. PRINT #2, "FOR i&=1TO LEN(A$) STEP 4:B$=MID$(A$,i&,4)"
  72. PRINT #2, "IF INSTR(1,B$,"; Q$; "%"; Q$; ") THEN"
  73. PRINT #2, "FOR C%=1 TO LEN(B$):F$=MID$(B$,C%,1)"
  74. PRINT #2, "IF F$<>"; Q$; "%"; Q$; "THEN C$=C$+F$"
  75. PRINT #2, "NEXT:B$=C$:END IF:FOR j=1 TO LEN(B$)"
  76. PRINT #2, "IF MID$(B$,j,1)="; Q$; "#"; Q$; " THEN"
  77. PRINT #2, "MID$(B$,j)="; Q$; "@"; Q$; ":END IF:NEXT"
  78. PRINT #2, "FOR t%=LEN(B$) TO 1 STEP-1"
  79. PRINT #2, "B&=B&*64+ASC(MID$(B$,t%))-48"
  80. PRINT #2, "NEXT:X$="; Q$; Q$; ":FOR t%=1 TO LEN(B$)-1"
  81. PRINT #2, "X$=X$+CHR$(B& AND 255):B&=B&\256"
  82. PRINT #2, "NEXT:btemp$=btemp$+X$:NEXT"
  83. PRINT #2, "BASFILE$=_INFLATE$(btemp$):btemp$="; Q$; Q$
  84. PRINT #2, "'==================================="
  85. PRINT #2, "'EXAMPLE: SAVE BASFILE$ TO DISK"
  86. PRINT #2, "'==================================="
  87. PRINT #2, "'OPEN "; Q$; IN$; Q$; " FOR OUTPUT AS #1"
  88. PRINT #2, "'PRINT #1, BASFILE$;"
  89. PRINT #2, "'CLOSE #1"
  90.  
  91. PRINT "Done!"
  92. PRINT UCASE$(OUT$); " saved."
  93.  
  94. FUNCTION E$ (B$)
  95.  
  96.     FOR T% = LEN(B$) TO 1 STEP -1
  97.         B& = B& * 256 + ASC(MID$(B$, T%))
  98.     NEXT
  99.  
  100.     a$ = ""
  101.     FOR T% = 1 TO LEN(B$) + 1
  102.         g$ = CHR$(48 + (B& AND 63)): B& = B& \ 64
  103.         'If @ is here, replace it with # to fix the
  104.         'problem posting code with @ in the QB64 forum.
  105.         'It wil be restored during the decoding process.
  106.         IF g$ = "@" THEN g$ = "#"
  107.         a$ = a$ + g$
  108.     NEXT: E$ = a$
  109.  
  110.  
« Last Edit: May 13, 2020, 04:10:04 pm by Dav »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH small code.
« Reply #1 on: May 12, 2020, 12:59:12 pm »
THANK YOU! I used your previous version for my GUI adaptation and I had been racking my brain trying to figure out how to use the _DEFLATE$ and _INFLATE$ with it! You are awesome!
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH small code.
« Reply #2 on: May 12, 2020, 10:34:11 pm »
Glad to do it.  The only thing is that _DEFLATE doesn't help much on files that are already compressed before encoding, like zip, jpg, rar, etc.  But on other files you should notice a great size reduction on the encoded BAS output.

- Dav
« Last Edit: May 12, 2020, 10:45:46 pm by Dav »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH small code.
« Reply #3 on: May 13, 2020, 12:07:18 am »
The posted BASFILE program is only set up to encode files.  But with a little modification you can use it to encode screen memory instead.    I thought I'd mention this for those of you who have always wanted to include resource images in your EXE instead of having to include them as separate image files.   With this program you can do that.  Like this example program below does, it loads an image to screen and never has to extract an image file to disk first to use.  So the image data stays in the EXE.   (I can post that modified version if you want it).

EDIT: Code below now works - made with program v0.21

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(150, 150, 32)
  2. DIM m AS _MEM: m = _MEMIMAGE(0)
  3.  
  4. 'decode screen memory...
  5.  
  6. A$ = ""
  7. A$ = A$ + "haIkMf2NDld4479BTHAR49FT8AR59BTaR4ITHA69B\AR49FT8o;OOc\I[iZ]"
  8. A$ = A$ + "fJV\Kb]g7QBDll`Mk]O<c_=m<MgC??i9?iomToaeKNe;6dkNm;gKje_l53ji"
  9. A$ = A$ + "?kY32GSR>f?_AQ[R>o4jWOe;NnPn`KOEEGmU?nPdWNg[7TbG<SM\OnS2G5MJ"
  10. A$ = A$ + ";fN4dWo`K7dg_lCEmkOnS1mgonW1mOogOW[bWOSnc_oEEolkOK#Gmi?<X?N3"
  11. A$ = A$ + "KmAR_:j5?oI3:leS75^:J;hYgoVGEeGodk64HYol[OF5HWKnWkDP_H6kGohZ"
  12. A$ = A$ + "1Qc=\;bf6En:<fiW2G55^:jDG:?1FZXOle??8UUF:?II\aOoOoc_7TbG5QaL"
  13. A$ = A$ + "Qk]<Gac?5^:J;iY_lag>8`B<?Qil]FfI9LUbG51OL1njE_likdX_d2OMJZ`E"
  14. A$ = A$ + "AkKFRSe7h9e_D3nVJ\?_>^KSM#`L<SPaVScc?onG[2O6kC[K?f[[27;la5kW"
  15. A$ = A$ + "O<VNU_2S5^:LeS;5^:J[h98h[8`Cojj_?8f7EEF1\39`GEfiZ_FeeGMiDm]M"
  16. A$ = A$ + "273c_gZ[9=mLbcA5lU6Cl<V[`EQ[>_5JWOk=fk:RmYM?N2ZjKYKVKFA8nc5Q"
  17. A$ = A$ + "nGH7Uo^;_YooBR1`e_8fVFAhg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h_S_Oem0?lnHAQW2G5^jh`GHoK\8=^Rm6K^M<m;PgLn=CG[#^nl"
  88. A$ = A$ + "U`A>KMch9bWJm6K^^GMn_R_Y2G5^jDF^lP0R[OTml_`lH8fnH\O7nML=K#T;"
  89. A$ = A$ + "W3jUGN]h:nkDNRO7CiYSModiV2G5^:LEhZcAeR_:2kS9XVnibmmk[de?XkHL"
  90. A$ = A$ + "caD[YOjoWi:<f=foJ:?aech`CQ[2GMN8=_0IYlEA]Z?JmZY8>oPYeHTNaNTU"
  91. A$ = A$ + "enWTWemRcWF?k2?5^:LeiWL[93dGlUbn\kXjUcO]I]i<SCJN?g]F2ITbCLlm"
  92. A$ = A$ + "^?e5mX`EQ[>=EhZX35SifS>em4]:G<FgT:JF^g#O76OV;6AJ^gkZG#]H97?M"
  93. A$ = A$ + "OgG#R2G5^jlCX_PgobJ5_JgJ<dE[CGRZn=gXMn_JJ>^`a?f]6o>f]UAQ[R>\"
  94. A$ = A$ + "l5gGQmi^eFG8j>fkE`C`N<k_=MN77kf]X`EAQ[2GmhCJOG]NWbkYQ=ZEcJ^_"
  95. A$ = A$ + "dDB>NjFc<J>NF4n\SMKDDhZXC;eR_6V[hH=4M;T;?GJ]Wa7MnY`EA72nb]6Q"
  96. A$ = A$ + "gWZ5?M\OnS2G5MnX`E7FmoAY%%L2"
  97. btemp$ = ""
  98. FOR i& = 1 TO LEN(A$) STEP 4: B$ = MID$(A$, i&, 4)
  99.     IF INSTR(1, B$, "%") THEN
  100.         FOR C% = 1 TO LEN(B$): F$ = MID$(B$, C%, 1)
  101.             IF F$ <> "%" THEN C$ = C$ + F$
  102.         NEXT: B$ = C$: END IF: FOR j = 1 TO LEN(B$)
  103.         IF MID$(B$, j, 1) = "#" THEN
  104.     MID$(B$, j) = "@": END IF: NEXT
  105.     FOR t% = LEN(B$) TO 1 STEP -1
  106.         B& = B& * 64 + ASC(MID$(B$, t%)) - 48
  107.         NEXT: X$ = "": FOR t% = 1 TO LEN(B$) - 1
  108.         X$ = X$ + CHR$(B& AND 255): B& = B& \ 256
  109. NEXT: btemp$ = btemp$ + X$: NEXT
  110. BASFILE$ = _INFLATE$(btemp$): btemp$ = ""
  111.  
  112. 'Load to screen memory
  113. _MEMPUT m, m.OFFSET, BASFILE$
  114.  
  115.  
  116.  
« Last Edit: May 13, 2020, 04:08:01 pm by Dav »

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH small code.
« Reply #4 on: May 13, 2020, 06:51:11 am »
That's dang cool! I really appreciate all the work you guys do with your little programs y'all make. When I try to run your code snippet I keep getting an error on line 1615 saying memory region out of range. I tried it in both 32 and 64 bit versions of QB64 v1.4
« Last Edit: May 13, 2020, 06:58:31 am by SpriggsySpriggs »
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH small code.
« Reply #5 on: May 13, 2020, 09:00:33 am »
Sorry, SpriggsySpriggs.  Looks like the forum won't let me post BAS code properly that has the @ symbol in it.  Looks like the forum is seeing it as a member tag and changing the code.   

At first I thought the code was too large, put I've posted a smaller one and it still messes up code because of the @ symbol.  I wonder it there is a way to turn off that @ conversion in the code box?  If not I could update BASFILE to work around the @ problem.

EDIT:  Yep, that's it.  See, I can't post an"PRINT @ Dav"  (without the space between @ and Dav". 

Code: QB64: [Select]
  1. PRINT "[member=33]Dav[/member]"
  2.  
- Dav
« Last Edit: May 13, 2020, 09:09:34 am by Dav »

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH smaller code.
« Reply #6 on: May 13, 2020, 04:14:09 pm »
I have updated the BASFILE program in the original post at top to fix the @ in code problem with the forum.  Encoded BAS Code now can be pasted in the forum without it breaking it.    Also, I replaced the broken program example in the embedded image post above to a working one..

- Dav

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH smaller code.
« Reply #7 on: May 15, 2020, 02:14:00 pm »
That's freaking cool, Dav. I tried it out and it worked perfectly. That's amazing!
Shuwatch!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH smaller code.
« Reply #8 on: May 15, 2020, 02:28:00 pm »
I think it's amazing how just adding:
Code: QB64: [Select]
  1. _ICON m.IMAGE
allows you to use the embedded picture. I've never messed with MEM before so I guess I'll have to start! And if you can post that version that encodes screen memory that would be awesome.
« Last Edit: May 15, 2020, 02:48:30 pm by SpriggsySpriggs »
Shuwatch!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Updated BASFILE/BIN2BAS programs. Generates MUCH smaller code.
« Reply #9 on: May 17, 2020, 08:27:39 pm »
Yes, _ICON is very handy.    I will finish up and post the companion program, called BASIMAGE, to use for specifically adding screen images this way.  It will load an image, convert it to BAS code that you can use to easily make a callable image handles to use by _PUTIMAGE. 

- Dav