Support Forum

Please or Register to create posts and topics.

LoadSD Respecting data folder?

I am experimenting with the this compiler for the Next and using some of the examples, they seem to have files in a subfolder called data that are used by the LoadSD command.  What puzzles me is that on my PC after compiling and running under CSpect, it appears to work, so it must load the files from the data folder, however, if I take the compiled SNX file to my Next with the data folder structure and place it under where i place the SNX file, it does not work.  If I place the "contents" of the data folder inside the same directory as the SNX file itself, then it does work, so everything has to exist in the same folder.  It seems as tho on the real hardware it does not respect  file structure using the LoadSD command from the sub folder "data".   I tried compiling the program with a data\ and a .\data\ and data/ and ./data/ on the LoadSD commands, and each time it completes compilation and runs the emulator, it fails to load the files.  The same is also true on real Hardware at this point.   I assume I am missing something obvious like a compiler option reference or something.  I have also tried the !data -f command to force the copy of the data files to my destination location, it i also did not appear to work.

What I am ultimately trying to achieve is a way to compile an SNX with associated source files and place them in a specific location on my C drive, which is then using the NextSync program to sync the contents over to my actual Next over Wifi.   I simply run a .syncfast command and a .run test.snx to download and execute the newly compiled program (and technically any associated data files should come over aswell)

 

Would appreciate some pointers as to where I am going wrong, or if anyone else has any better suggestions.

For reference, the sample I am trying to get to work at the moment it; TileMapScroll/TestMap.bas

But I have tried others also, and failed.

Thanks in advance,

Jason B

Hi,

The files are relative to your SNX file so on the Next you do not need a data folder, simply put your files in the same folder as your SNX. The data path is passed to CSpect as an MMC location as was an easy way to keep assets together.

ok thanks em00k, understood.

In that case, it would be nice to be able to still do what i was thinking about, that is transferring the relevant files to a static location for wifi transfer using nextsync for easy testing on real hardware instead of cspect.

I have had a look through the compile.bat and compilenext.bat but it seems a bit beyond me.

How does the compiler create the snx file from the directive !sna as i dont see that in the batch files.  It looks like it should only handle sna to me; also the !data directive doesnt appear to be being respected as i get no copy of the data directory in my destination location.  Also note that I have to create the destination directory that the !sna directive would write to - it doesnt appear to be able to autocreate the folder structure should it not exist, which would be a nice touch if it could.

Could you expand upon the batch file how the directives are handled, or is it done somewhere else?

Are there other libraries for the next that are useful in addition to nextlib.bas - thinking for example that the nextreg dialect is a bit much for beginners and wonder if anyone has made a more "basic" syntax to turn features on and off instead of poking registers?

Appreciate any feedback to point me in the right direction.

Regards

Jason

So after a lot of debugging, i fathomed our that it was the postcompiler.exe file that was transferring the file and not respecting the !data -f directive.

Luckily the Purebasic source code is included, so i was able to re-compile a new postcompiler.exe file that did what i needed.  I noticed that there was no !data directive code in the postcompiler.pb file.

So a little bit of coding later, it now identifies the "!data -f " directive and moves the \data files to the root file location as specified in the directive string.  Other !data -{x} options have no function as yet.

It also now on the !sna and !data directive, creates the folder should it not exist.

It does not respect the -v directive yet for the !data code part, so will look at that after now i have tested and confirmed the changes work.

I will post the purebasic and recompiled postcompiler.exe later on after work, incase anyone else needs it.

seems i am unable to upload the files - everytime is reports file types of that type are not allowed, even .txt or zips.

Herewith revise code as text pasted, if you wish to re-assemble for yourself.

 

; assume this is the proper dir
OpenConsole()
Global fullpath$=ProgramParameter(0)
Global startaddress$=ProgramParameter(1)
;'fullpath$="Z:\GoogleDrive\speccy\boriel\codes\nextlibs\dmatest6.bas"

Debug startaddress$
path$=GetPathPart(fullpath$)
file$=GetFilePart(fullpath$)
Global verb.b=0

PrintN(fullpath$)
PrintN(path$)
PrintN(file$)
Declare makeplus3(target$,file$,type)

Procedure ReplaceLine(iFileID, sFileName.s, iRepLineNum.i, sReplacement.s, iMode.i)
;-------------------------------------------------------------
iReturnVal = #False

Size = FileSize(sFileName)

If Size > 0
; replace text in file
If ReadFile(iFileID,sFileName)
*Buffer = AllocateMemory(Size)
If *Buffer

If ReadData(iFileID, *Buffer, Size) = Size
CloseFile(iFileID)

CreateFile(iFileID, sFileName)

i = 1 : n = 0
While i < iRepLineNum
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
If PeekA(*Buffer + n) = $0D : i + 1 : EndIf
CompilerElse
If PeekA(*Buffer + n) = $0A : i + 1 : EndIf
CompilerEndIf
n + 1
Wend
;Debug PeekS(*Buffer + n, 100)

WriteData(iFileID, *Buffer, n)
WriteStringN(iFileID, sReplacement, iMode)

i = n
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
While PeekA(*Buffer + i) <> $0D
CompilerElse
While PeekA(*Buffer + i) <> $0A
CompilerEndIf
i + 1
Wend
i + 1
;Debug PeekS(*Buffer + i, 100)

WriteData(iFileID, *Buffer + i, Size - i)

iReturnVal = #True

EndIf

FreeMemory(*Buffer)

EndIf
CloseFile(iFileID)
EndIf
EndIf

ProcedureReturn(iReturnVal)

EndProcedure

If ReadFile(0,path$+file$) ; open file
While Not Eof(0)
; FoundLine+1
line$=LCase(ReadString(0)) ; read line from text file

If FindString(line$,"'!v")
verb=1
EndIf

If FindString(line$,"'!outfile") ; did we find this?
outfile$=Trim(StringField(line$,2," "),#DQUOTE$)

PrintN("Outfile = "+outfile$+" "+Str(FoundLine)) ; Yes, now get outfile
PrintN("Copying temp.bin to "+path$+outfile$)
If CopyFile(path$+"temp.bin",path$+outfile$)
PrintN("Success")
Else
PrintN("Fail")
EndIf

EndIf
If FindString(line$,"'!bin") ; did we find this?
target$=Trim(StringField(line$,2," "),#DQUOTE$)
PrintN("Bin = "+target$+" "+Str(FoundLine) ) ; Yes, now get outfile

PrintN("Copying temp.bin to "+target$)
If CopyFile(path$+"temp.bin",target$)
; If CopyFile(path$+"temp.bin","h:\temp.bin")
If verb=1
MessageRequester("Copied",target$)
EndIf

If FindString(line$,"-a")
;tpath$=Left(GetPathPart(target$),Len(GetPathPart(target$))-3)
;tpath$="c:\"+tpath$
file$=GetFilePart(LCase(target$))

tpath$=GetPathPart(target$)

makeplus3(tpath$,file$,1)
EndIf

PrintN("Success")
Else
PrintN("Fail")
EndIf

EndIf

If FindString(line$,"'!data") ; did we find this?
If FindString(line$,"-f") ; did we find this?
target$=Trim(StringField(line$,3," "),#DQUOTE$)
PrintN("Data Target="+target$)
CreateDirectory(target$)
CopyDirectory(path$+"\data",target$,"")
If verb=1
MessageRequester("Data Copied",path$+"data to "+target$)
EndIf
EndIf
EndIf

If FindString(line$,"'!sna") ; did we find this?
target$=Trim(StringField(line$,2," "),#DQUOTE$)
PrintN("Target= "+target$+" "+Str(FoundLine) ) ; Yes, now get outfile

PrintN("Copying compiled.sna to "+target$)
If CopyFile(path$+"compiled.sna",target$)
If verb=1
MessageRequester("Copied",path$+"compiled.sna to "+target$)
EndIf

If FindString(line$,"-a")
PrintN("SNA -a specified")
; ndrive$=Left(LCase(ProgramParameter(0)),2)
; npath$=Mid(LCase(ProgramParameter(0)),4)
; If Right(npath$,1)="\"
; npath$=Left(npath$,Len(npath$)-1)
; EndIf
file$=GetFilePart(LCase(target$))

tpath$=GetPathPart(target$)
CreateDirectory(tpath$)

PrintN("targetpath="+tpath$)
PrintN("File="+file$)
; tpath$="c:\"+tpath$
Debug tpath$
Debug target$
makeplus3(tpath$,file$,0)
EndIf

PrintN("Success")
Else
PrintN("Fail")
EndIf

EndIf

If FindString(line$,"'!exec") ; did we find this?

exec$=StringField(line$,2,#DQUOTE$)
PrintN("exec = "+exec$+" "+Str(FoundLine) ) ; Yes, now get outfile
target$=Trim(StringField(line$,2," "),#DQUOTE$)
If verb=1
MessageRequester("exec =","Running "+exec$)
EndIf
If RunProgram("cmd.exe","/c "+exec$,path$)
Else
MessageRequester("exec =","failed!!")
EndIf

EndIf
If FindString(line$,"'!noemu") ; did we find this?
noemu=10
PrintN("noemu = 1 "+Str(FoundLine) ) ; Yes, now get outfile

EndIf
FoundLine+1
Wend
CloseFile(0)

; If ReplaceLine(0,path$+conf$,a,"CompilerZXB = "+compiler$, #PB_Ascii)
; Debug "CompilerZXB = Line replaced with "+compiler$+" "+Str(c)
; EndIf
; If ReplaceLine(0,path$+conf$,b,"LastDir = "+path$+"Sources\", #PB_Ascii)
; Debug "LastDir = Line replaced with "+path$+"Sources\"
; EndIf
Else
PrintN("Could not open "+path$+conf$)

EndIf

End noemu

; If CreateFile(0,"Scripts\Path.bat",#PB_Ascii)
; If WriteString(0,"echo "+path$)
; Debug "path.bat written"
; EndIf
; CloseFile(0)
; RunProgram(path$+"\BorIDE\BorIDE_previewR5_0A.exe","",path$+"\BorIDE\")
; Else
; Debug "Could not open scripts\path.bat"
; EndIf
;
;
Procedure makeplus3(target$,file$,type)

*memory=AllocateMemory(512)
stadd=Val(startaddress$) : newaddress$=Str(stadd-1)
hb=Int(stadd/256)
lb=stadd-(hb*256)
If type=1
PokeS(?Line10+5,newaddress$,-1,#PB_Ascii|#PB_String_NoZero ) ; clear
PokeB(?Line10+13,lb)
PokeB(?Line10+14,hb)
PokeS(?BinRun+1,startaddress$,5,#PB_Ascii|#PB_String_NoZero ) ; load "" code
PokeB(?BinRun+9,lb)
PokeB(?BinRun+10,hb)
PokeS(?BinRun+19,startaddress$,5,#PB_Ascii|#PB_String_NoZero ) ; run usr xxxxx
PokeB(?BinRun+27,lb)
PokeB(?BinRun+28,hb)
EndIf
CopyMemory(?Header,*memory,128)
CopyMemory(?Line10,*memory+128,?BinRun-?Line10)
If Len(target$)<4
PokeB(*memory+128+17,$ef)
filename$="c:\"+file$
Else

;clear line

If type=1
PokeB(*memory+128+17,$a0) ;cd
filename$="c"+Mid(target$,2)+#DQUOTE$+":"+Chr($ef)+#DQUOTE$+file$
EndIf
EndIf

If type=1 ; bin save -a
poke$=filename$+#DQUOTE$
binlen=?BinRunEnd-?BinRun
CopyMemory(?BinRun,*memory+128+19+Len(poke$),binlen)
linelen=Len(poke$)+19+binlen
linelen2=Len(poke$)+2+26
PokeS(*memory+128+19,poke$,linelen,#PB_Ascii |#PB_String_NoZero) ;
Else
CopyMemory(?SNA,*memory+128,?SNAEND-?SNA)
poke$="c"+Mid(target$,2)+Chr($22)+Chr($3a)+Chr($a3)+#DQUOTE$+file$+#DQUOTE$+Chr($0d)
linelen=Len(poke$)+6
linelen2=Len(poke$)+6
PokeS(*memory+128+6,poke$,linelen,#PB_Ascii |#PB_String_NoZero) ;
EndIf

; linelen=Len(poke$)+19+binlen
; linelen2=Len(poke$)+2+26

PokeB(*memory+11,128+linelen)
PokeB(*memory+16,linelen)
PokeB(*memory+20,linelen)
PokeB(*memory+130,linelen2)

For x=0 To 126 ; make flag byte
a + Mod (PeekB(*memory+x),256)
Next
Debug Hex(a)
PokeB(*memory+127,a)

ShowMemoryViewer(*memory,128+linelen)

If OpenFile(1,"autoexec.bas")
WriteData(1,*memory,128+linelen)
CloseFile(1)
CopyFile("autoexec.bas","h:\nextzxos\autoexec.bas")
If verb=1
MessageRequester("Autolaunch","h:\nextzxos\autoexec.bas")
EndIf

EndIf
FreeMemory(*memory)

DataSection
Header:
Data.b 080,076,085,083,051,068,079,083
Data.b 026,001,000,148,000,000,000,000
Data.b 020,000,000,000,020,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,000
Data.b 000,000,000,000,000,000,000,052
SNA:
Data.b $00,$0A,$0F,$00,$A0,$22
SNAEND:
SNA2:
Data.b $00,$0A,$0F,$00,$A0,$22
SNAEND2:

Line10:
; Data.b $00,$0A,$0F,$00,$A3,$22,$63,$3A,$5C,$74,$65,$73,$74,$2E,$73,$6E,$61,$22,$0D
; Data.b $00,$0A,$30,$00,$FD,$32,$34,$35,$37,$35,$0E,$00,$00,$FF,$5F,$00,$3A,$EF,$22
Data.b $00,$0A,$30,$00,$FD,$32,$34,$35,$37,$35,$0E,$00,$00,$FF,$5F,$00,$3A,$EF,$22
BinRun:
Data.b $AF,$32,$34,$35,$37,$36,$0E,$00,$00,$00,$60,$00,$0D,$00,$14,$0E,$00,$F9,$C0,$32,$34,$35,$37,$36,$0E,$00,$00,$00,$60,$00,$0D
BinRunEnd:
; EF= LOAD
; A3=SPECTRUM
; AF=CODE
EndDataSection
EndProcedure
; IDE Options = PureBasic 5.72 (Windows - x64)
; ExecutableFormat = Console
; CursorPosition = 139
; FirstLine = 50
; Folding = 5
; Markers = 117,257
; EnableXP
; Executable = postcompile.exe
; CommandLine = C:\NextBuildv5\Sources\spinngtiles\petscii2.bas 32768