Oh I was remembering loading and embedding multiple image files. I don't know a file is a file, just a bunch of ones and zeros, no?
Yes a file is just a file. What I was trying to avoid was just the tedium of typing out over 100 EMBED statements. Dav had a great idea which gave me this.
Code: (Select All)
Data "gm34.isc","lgm29.isc","gm39.isc","gm30.isc","gp60.isc","lgm56.isc","gm81.isc","lgp46.isc"
Data "lgm21.isc","lgm61.isc","lgp49.isc","lgm51.isc","gm10.isc","gm101.isc","lgm88.isc","gm29.isc"
Data "lgp67.isc","lgm04.isc","gm02.isc","gm08.isc","gm53.isc","gm07.isc","gp46.isc","lgm20.isc"
Data "./","gm06.isc","lgm108.isc","gm47.isc","gm117.isc","gp39.isc","gp82.isc","lgm30.isc","gm20.isc"
Data "lgm82.isc","lgm12.isc","lgm34.isc","lgm02.isc","gp40.isc","lgm11.isc","lgm67.isc","gm13.isc"
Data "gm11.isc","gm25.isc","gp37.isc","gm33.isc","lgm16.isc","lgm74.isc","lgm31.isc","lgp43.isc"
Data "gm31.isc","lgm101.isc","gm28.isc","gm12.isc","lgp39.isc","lgm49.isc","gm19.isc","lgm01.isc"
Data "gm97.isc","lgm09.isc","gm88.isc","gm74.isc","gm67.isc","lgm109.isc","gp67.isc","gm63.isc"
Data "gm09.isc","lgm35.isc","lgm37.isc","gm82.isc","lgp37.isc","gp49.isc","lgm15.isc","gm56.isc"
Data "lgm26.isc","lgm14.isc","lgm57.isc","gm109.isc","gm26.isc","gm21.isc","lgm06.isc","lgm28.isc"
Data "lgm27.isc","lgm13.isc","lgm03.isc","lgm25.isc","lgm63.isc","gm14.isc","gm04.isc","gm37.isc"
Data "gm05.isc","gm60.isc","lgp60.isc","gm15.isc","gm03.isc","../","gm77.isc","lgm72.isc","gm51.isc"
Data "lgm53.isc","gp42.isc","lgm22.isc","gp43.isc","gm87.isc","lgm47.isc","gm48.isc","gm72.isc"
Data "lgm07.isc","lgp42.isc","lgp36.isc","gm27.isc","lgm08.isc","gm61.isc","gm18.isc","lgm77.isc"
Data "lgm33.isc","gm23.isc","lgm23.isc","gm108.isc","lgm81.isc","gm22.isc","gm49.isc","gm35.isc"
Data "lgm97.isc","lgm60.isc","lgm117.isc","lgp82.isc","gm16.isc","lgm10.isc","gm57.isc","lgm87.isc"
Data "lgm05.isc","lgm39.isc","gm01.isc","lgp40.isc","lgm19.isc","gp36.isc","lgm18.isc"
Data "0000"
f$ = _Files$("isc/*.*") 'wherever the files are located
D$ = "DATA "
f$ = _Files$("isc/*.*") 'wherever the files are located
Do While Len(f$) > 0
D$ = D$ + Chr$(34) + f$ + Chr$(34) + " ,"
f$ = _Files$
If Len(f$) = 0 Or Len(D$) > 100 Then
D$ = Left$(D$, Len(D$) - 1)
Print #2, D$
D$ = "DATA "
End If
Loop
If D$ = "DATA " Then
D$ = "DATA " + Chr$(34) + "0000" + Chr$(34)
Else
D$ = D$ + Chr$(34) + "0000" + Chr$(34)
End If
Print #2, D$
Print #2, ""
Print #2, ""
iscIndx = 1
slash$ = "/"
f$ = _Files$("isc/*.*") 'wherever the files are located
Do While Len(f$) > 0
If Left$(f$, 1) <> "." Then
f$ = "./isc" + slash$ + f$
handle$ = "iscHandle" + _Trim$(Str$(iscIndx))
Print #2, "$EMBED:'"; f$; "','"; handle$; "'"
iscIndx = iscIndx + 1
End If
f$ = _Files$
Loop
Close 2
Problem solved. Pretty straigtforward from here to do the extractions. The whole point of this exercise is to have one distributable executable that will do the job that right now requires the installation of PHP, A PHP program from on Github Repo and the mid2vgm program from another, Then knitting the chain together with bash or powershell (depending on platform !)
I'm trying to make things easier for other X16 Developers at the expense of a little tedium from me. I already have the bash script thing working for the conversion !
PHP install will still be required but that's still a lot simpler thing to ask of an end user than the alternative !
11-14-2025, 10:25 PM (This post was last modified: 11-14-2025, 10:28 PM by Petr.)
This way works not as expected (can not extract embeded files to harddrive from EXE). QB64PE requires a quoted literal string to unpack the file to disk. Cannot use a variable!
Code: (Select All)
ff = FreeFile
Open "to_source.txt" For Output As ff
e$ = _Files$("*.*")
ReDim As String handles(0)
ReDim As String fileNames(0)
Do While Len(e$) > 0
e$ = _Files$
Print e$
count = count + 1
If count > 1 And Len(e$) > 0 Then
handle$ = "h" + _Trim$(Str$(count))
ReDim _Preserve handles(count) As String
ReDim _Preserve fileNames(count) As String
handles(count) = handle$
fileNames(count) = e$
Print #ff, "'$Embed " + e$ + " ' ," + handle$
End If
Loop
'write to text file filenames and handles for you
Print #ff, "DATA" + Str$(count) 'total files in exe
For FilesAndHandles = 1 To count - 1
If FilesAndHandles > 2 Then
call$ = Chr$(34) + fileNames(FilesAndHandles) + Chr$(34) + ", " + Chr$(34) + handles(FilesAndHandles) + Chr$(34)
Print #ff, "DATA " + call$
End If
Next
(11-14-2025, 10:25 PM)Petr Wrote: This way works not as expected (can not extract embeded files to harddrive from EXE). QB64PE requires a quoted literal string to unpack the file to disk. Cannot use a variable!
Code: (Select All)
ff = FreeFile
Open "to_source.txt" For Output As ff
e$ = _Files$("*.*")
ReDim As String handles(0)
ReDim As String fileNames(0)
Do While Len(e$) > 0
e$ = _Files$
Print e$
count = count + 1
If count > 1 And Len(e$) > 0 Then
handle$ = "h" + _Trim$(Str$(count))
ReDim _Preserve handles(count) As String
ReDim _Preserve fileNames(count) As String
handles(count) = handle$
fileNames(count) = e$
Print #ff, "'$Embed " + e$ + " ' ," + handle$
End If
Loop
'write to text file filenames and handles for you
Print #ff, "DATA" + Str$(count) 'total files in exe
For FilesAndHandles = 1 To count - 1
If FilesAndHandles > 2 Then
call$ = Chr$(34) + fileNames(FilesAndHandles) + Chr$(34) + ", " + Chr$(34) + handles(FilesAndHandles) + Chr$(34)
Print #ff, "DATA " + call$
End If
Next
I didn't really look at the code to closely, This part I've actually done plenty of times. Doesn't sound right that you can't use a variable. I often use string variables as filenames for file I/O ?
The whole point of my ask here was to avoid typing out a bunch of embeds. Writing the code to generate that code is really what I needed and I think it will turn out fine. I really do appreciate the attention this has recieved. Simple file I/O operations are well within my skill set to figure out though !. Writefile is probably the easiest way to do this code but it wouldn't be hard to do it with PUT either !
11-14-2025, 11:37 PM (This post was last modified: 11-14-2025, 11:48 PM by Petr.)
It was a struggle. I finally got it running, but what surprised me was that when I forgot to call _Embedded$, it created 2-byte files on disk.
Then I realized it. So this builds a BAS file and dumps the files in the folder into it. Some of the files the resulting program doesn't see it, I don't know where the problem is again. No DATA blocks are needed, it's just written straight in the literal version. I don't understand this "treatment". Really not. Why not varibles?
Code: (Select All)
ff = FreeFile
Open "to_source.bas" For Output As ff
e$ = _Files$("*.*")
ReDim As String handles(0)
ReDim As String fileNames(0)
Do While Len(e$) > 0
e$ = _Files$
Print e$
count = count + 1
If count > 1 And Len(e$) > 0 Then
handle$ = "h" + _Trim$(Str$(count))
ReDim _Preserve handles(count) As String
ReDim _Preserve fileNames(count) As String
handles(count) = handle$
fileNames(count) = e$
Print #ff, "$Embed '" + _Trim$(e$) + "' ," + "'" + handle$ + "'"
End If
Loop
'write to text file filenames and handles for you
For FilesAndHandles = 2 To count - 1
'Print #ff, "S = _Sndopen (" + Chr$(34) + handles(FilesAndHandles) + Chr$(34) + "," + Chr$(34) + " memory" + Chr$(34) + ") "
Print #ff, "File$ = _Embedded$ (" + Chr$(34) + handles(FilesAndHandles) + Chr$(34) + ")"
Print #ff, "_WriteFile " + Chr$(34) + "copy" + fileNames(FilesAndHandles) + Chr$(34) + ", file$"
Next
(11-14-2025, 11:37 PM)Petr Wrote: It was a struggle. I finally got it running, but what surprised me was that when I forgot to call _Embedded$, it created 2-byte files on disk.
Then I realized it. So this builds a BAS file and dumps the files in the folder into it. Some of the files the resulting program doesn't see it, I don't know where the problem is again. No DATA blocks are needed, it's just written straight in the literal version. I don't understand this "treatment". Really not. Why not varibles?
Code: (Select All)
ff = FreeFile
Open "to_source.bas" For Output As ff
e$ = _Files$("*.*")
ReDim As String handles(0)
ReDim As String fileNames(0)
Do While Len(e$) > 0
e$ = _Files$
Print e$
count = count + 1
If count > 1 And Len(e$) > 0 Then
handle$ = "h" + _Trim$(Str$(count))
ReDim _Preserve handles(count) As String
ReDim _Preserve fileNames(count) As String
handles(count) = handle$
fileNames(count) = e$
Print #ff, "$Embed '" + _Trim$(e$) + "' ," + "'" + handle$ + "'"
End If
Loop
'write to text file filenames and handles for you
For FilesAndHandles = 2 To count - 1
'Print #ff, "S = _Sndopen (" + Chr$(34) + handles(FilesAndHandles) + Chr$(34) + "," + Chr$(34) + " memory" + Chr$(34) + ") "
Print #ff, "File$ = _Embedded$ (" + Chr$(34) + handles(FilesAndHandles) + Chr$(34) + ")"
Print #ff, "_WriteFile " + Chr$(34) + "copy" + fileNames(FilesAndHandles) + Chr$(34) + ", file$"
Next
Close ff
I'm planning on using the data to recreate the original filenames. I have the handles suffixed with a numerical value so I should be able to write them all out in a loop 1 by 1. I've been working on 4 different projects so at the moment this one is a bit on the back burner but I try to think ahead when doing my preps. AGAIN, This is just automating a process that I've already gotten working a different way. I basically want a way to distribute the whole package without another developer having to reproduce every step I did to get the process working !
Okay. I understand. But I was also interested in this topic, so I was digging into it. However, I would approach it differently, in my own way. I have my own file archiver written in QB64PE. It can pack multiple files into a single binary PMF2 file. It doesn't support subdirectories (it might take them, I haven't tried that), but I could work around that. But it's a complicated procedure. Then you don't need to write anything about the files in the source code at all. Just about the one that contains everything. More about it here: https://qb64phoenix.com/forum/showthread.php?tid=1533
(11-15-2025, 12:39 AM)Petr Wrote: Okay. I understand. But I was also interested in this topic, so I was digging into it. However, I would approach it differently, in my own way. I have my own file archiver written in QB64PE. It can pack multiple files into a single binary PMF2 file. It doesn't support subdirectories (it might take them, I haven't tried that), but I could work around that. But it's a complicated procedure. Then you don't need to write anything about the files in the source code at all. Just about the one that contains everything. More about it here: https://qb64phoenix.com/forum/showthread.php?tid=1533
You were write about something I wasn't getting. _EMBEDDED handle must be a literal string. So I did more code to write other code and got this. Still Using my DATA block I generated along with this !
Code: (Select All)
SUB WRITE_ISC_FILES
Dim OutFile$, filedata$
RESTORE ISCDATA
11-15-2025, 05:10 AM (This post was last modified: 11-15-2025, 09:39 AM by ahenry3068.)
(11-15-2025, 12:39 AM)Petr Wrote: Okay. I understand. But I was also interested in this topic, so I was digging into it. However, I would approach it differently, in my own way. I have my own file archiver written in QB64PE. It can pack multiple files into a single binary PMF2 file. It doesn't support subdirectories (it might take them, I haven't tried that), but I could work around that. But it's a complicated procedure. Then you don't need to write anything about the files in the source code at all. Just about the one that contains everything. More about it here: https://qb64phoenix.com/forum/showthread.php?tid=1533
Got this working on Linux perfectly (main program is MIDI2ZSM.BAS)
I have some conditionals in the source for a Windows build but it's after midnight and I'll get the Windows build going tomorrow evening
(might work as is , but I usually don't get things right the first time !)
Used this code to write out a *.bi and a *.bm with both the EMBEDS and a SUB to write them back to disc.
Code: (Select All)
ChDir _StartDir$
If _FileExists("isc.bi") Then Kill "isc.bi"
Open "isc.bi" For Output As #2
Print #2, "ISCDATA:"
f$ = _Files$("isc/*.*") 'wherever the files are located
D$ = "DATA "
f$ = _Files$("isc/*.*") 'wherever the files are located
Do While Len(f$) > 0
If Left$(f$, 1) <> "." Then
D$ = D$ + Chr$(34) + f$ + Chr$(34) + " ,"
If Len(f$) = 0 Or Len(D$) > 100 Then
D$ = Left$(D$, Len(D$) - 1)
Print #2, D$
D$ = "DATA "
End If
End If
f$ = _Files$
Loop
D$ = D$ + Chr$(34) + "0000" + Chr$(34)
Print #2, D$
Print #2, ""
Print #2, ""
iscIndx = 1
slash$ = "/"
f$ = _Files$("isc/*.*") 'wherever the files are located
Do While Len(f$) > 0
If Left$(f$, 1) <> "." Then
f$ = "./isc" + slash$ + f$
handle$ = "iscHandle" + _Trim$(Str$(iscIndx))
Print #2, "$EMBED:'"; f$; "','"; handle$; "'"
iscIndx = iscIndx + 1
End If
f$ = _Files$
Loop
Print #2, ""
Print #2, ""
Close #2
If _FileExists("isc.bm") Then Kill "isc.bm"
Open "isc.bm" For Output As #2
11-15-2025, 09:43 AM (This post was last modified: 11-15-2025, 09:49 AM by Petr.)
The zip file contains an EXE file of 24 KB in size. Windows Defender is screaming like crazy. It says it's a trojan. That's why I gave up trying to unpack the ZIP file.