News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_teopl

Insert textual BASIC file created on PC to a CPC DSK file

Started by teopl, 19:22, 01 June 19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

teopl

Hi, I lost few hours trying to solve this, so maybe someone had similar issue... I only did quick forum search sorry if this is asked before.

Problem:

I want to transfer textual basic file created on PC to a existing (or new) DSK file. (I need to put some dynamic content for MEMORY and LOAD commands)

I tried to use tools like: iDSK and CpcDiskXp, but I did not manage to insert it correctly.

Steps:

1. generate textual file LOADER.BAS (on PC using text editor)
2. fix new lines (tried both unix and windows)
3. iDSK.exe teopl.dsk -i LOADER.BAS -t 1 -c 170 -f
4. iDSK.exe teopl.dsk -b LOADER.BAS(this gives me strange result)

Did anyone manage to do something like this?

I know about AMSDOS header, but nothing much other then it exists.

Fessor

ASCII-Files doesn't have a header. I have no knowlede about iDSK.exe but if you are using WinApe you could simply "Edit Disc" and drag the file out of windows file-explorer to winapes disk-window.



teopl

I tried to pass "-t 0" option to iDSK which should use ASCII file type but no luck.

Anyway, I managed to do this manually by entering a program in CPC, saved it and then downloading .BAS to the PC via M4 interface.
What I got was something which looks like 128 byte header plus basic code.
Then when I automatically inserted downloaded file in .DSK and all is good.

But I would like to avoid this manual work since I will probably need to do this on every build, so I am looking for some automated solution.

Strident

I must admit that I too just use WinApe for this type of stuff... as you can simply drag and drop the text file onto the emulated disk from your PC. It's one of the best features about WinApe... I even use it to quickly get stuff onto Spectrum +3 disks.
8-Bit Adventure Gamer / 8bitAG.com - 8bitAG.com/info - 8bitAG.com/games

ZbyniuR

Auto-Type (Ctrl+F5) in WinAPE emulator work fine with short text, but it's slow for long listing.

I prefer (PC) program ManageDsk to put file from PC into DSK file.  http://www.cpcwiki.eu/index.php/ManageDsk

Just save Basic listing in PC editor as normal Windows TXT file. Line ending in PC and CPC are the same.  And in ManageDsk choose DSK, and after that click button [Add file(s)], and left default ASCII option, press [Validate], Rename file if it nessesery, and [Save DSK]. Thats it. :)

Maybe you have problem because you have Serbian Cyrilic alphabet in Windows as default language for TXT. In thats case maybe latin leters are save as 2 byte not as 1, in TXT file.
In STARS, TREK is better than WARS.

teopl

Hey ZbyniuR, thanks for your tip because it lead me to the solution and this is how:

In the manual for the program you mentioned (ManageDSK) there is sentence "For ascii files, no need to specify starting address and execution."

That lead me to examine the line I was using previously to insert .BAS file automatically:
iDSK.exe teopl.dsk -i LOADER.BAS -t 0 -c 170 -f

Turns out that if I use both "-t 0" (ASCII type) and "-c 170" (loading address), the file is saved as BINARY and that caused the problem with iDSK.

Now, when I just remove the loading address option, all is good:

iDSK.exe teopl.dsk -i LOADER.BAS -t 0 -f


teopl

Nope, I may be wrong after all... So iDSK looks like it does ignore the ASCII type like I said, but now I am getting a bunch of zeros at the file end (1024) so LOAD does not work...

I see that ManageDSK also has command line options, I may try with that...

teopl

I have no idea what was the problem, so there were probably few of them  :)

- I did replaced unix newlines (since I am on linux with cygwin) with: (my script constantly updated them  :picard: )flip -m LOADER.BAS

- I inserted BAS file with ManageDsk like this:
ManageDsk -Lteopl.dsk -ALOADER.BAS -Steopl.dsk


Now all looks ok (I hope it's not false alarm again :D ) - except I can t automatically start .BAS file from M4 web interface (but that's fine for now).
I guess this is due to the fact the address is not 170, so I must load it manually.

ronaldo

Quote from: teopl on 20:43, 02 June 19
Hey ZbyniuR, thanks for your tip because it lead me to the solution and this is how:
In the manual for the program you mentioned (ManageDSK) there is sentence "For ascii files, no need to specify starting address and execution."
That lead me to examine the line I was using previously to insert .BAS file automatically:
iDSK.exe teopl.dsk -i LOADER.BAS -t 0 -c 170 -f
Turns out that if I use both "-t 0" (ASCII type) and "-c 170" (loading address), the file is saved as BINARY and that caused the problem with iDSK.
Now, when I just remove the loading address option, all is good:
iDSK.exe teopl.dsk -i LOADER.BAS -t 0 -f

That's because you are inserting an ASCII file and, as @Fessor sais, ASCII files are just a list of ASCII characters without a header. If they don't have a header, they don't have any place where to put their "loading address". That information goes in headers. And they don't have it because they don't need it. You do not load ASCII files into memory. You load binary files into memory. Therefore, what BASIC does is interpret the ASCII file and write down the binary code for its BASIC interpretation in memory.

So, when you add -c 170 you are making iDSK import it as binary, even if you already specified -t 0. Then iDSK adds a header and your file is loaded as if it was a binary file. That obviously ruins the file.

For simplicity, I tested it with some files and iDSK and works flawlesly:

iDSK test.dsk -t 0 -i FILE.BAS

After that, I run the file in WINAPE and everythin works without any problem.

However, I'm not sure if this method may have problems with big ASCII files. BASIC could run out of memory while parsing. Didn't try it, but seams plausible.

freemac


ZbyniuR

I don't know how M4 work with load programs.

CPC Basic keep listings in memory as tokens (1 byte for each command etc.), and the same way looks BAS file on disc. This kind files need header and loading address as &170. And maybe M4 need this header to start file.

But if you save listing by   SAVE"name",a    <-- this ",a" change way of stored listing, now will be as ASCII TXT file without header and each character in command is 1 byte, so for example PRINT take 5 byte, not 1, like in normal tokens way.

If you create listing in PC editor, you save file as ASCII, so if you want change it into proper tokens Basic file, you have to load it in CPC (or emulator) and save back.
load"name
save"name

Thats it. Now new version of file, write with tokens and with proper header. Maybe this kind file is work from M4.
Don't try add header to ASCII file is useless. The same if you cut out header from BAS files. :)
In STARS, TREK is better than WARS.

teopl

@ronaldo, you are totally right, the:

iDSK test.dsk -t 0 -i FILE.BAS
works as expected.
Reason I didn't manage to make it work previously are not important now... I may have corrupted ASCII file and uploaded it like that (with unix newlines and/or header)...

Anyway, I would like to start the .BAS file on the CPC machine (not the emulator), automatically.

For that I am using M4 interface like this: (basically it's a request I got from sniffing the traffic when you use M4 web frontend)
curl 192.168.0.123/config.cgi?run2=%2Ftmp%2Fteopl.dsk%2FLOADER.BAS
and this works very well when .BAS file is a basic file with a header and a loading address.

Now, problem is that this method does not work when .BAS file is ASCII file, so I must manually type "LOAD" and "RUN" commands on CPC every time.

So, in short, I need this:

Does someone know a way to solve this?
Can a BASIC file load and start another BASIC file? (then I could save that file in binary format and start it)

One solution would be to find a way to add a header to ASCII file (make .BAS file binary) on the PC and then upload it with "-t 1 -c 170" option.

teopl

Ah, to answer my own question:

I can load and start another basic program with:

10 RUN "LOADER.BAS"

:picard2:

Please ignore me if I write more on this thread  :laugh:

Powered by SMFPacks Menu Editor Mod