test_task won't copy to DOS4_ on QPC2

Nagging hardware related question? Post here!
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

test_task won't copy to DOS4_ on QPC2

Post by stevepoole »

Hi,
I have written a random number generator in superbasic, which makes no use of RANDOMISE or RND().
After much testing it works well in basic, and compiles OK. It is pretty fast on QPC2.
The test_task was transferred from QPC2 to my QL via a floppy disk. It ran Ok on the QL.
But, it is impossible to copy the test_task to my dos4_ USB Key, which itself functions Ok for all other programs.
That is, the file transfers OK, but none of my computers can then EXEC it... as they will with flp1_ !
Any suggestions ?
Regards,
Steve Poole.
I


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: test_task won't copy to DOS4_ on QPC2

Post by tofro »

Copying executables to non-QDOS media looses the file header information and thus makes it impossible for QDOS to run them as executables.

Either use zip and unzip to transfer (this retains file header information) or rebuild the file header on the target with the below one-liner:

Code: Select all

a = alchp (<flen>):LBYTES (<file>,a):sexec (<file>,a, <dataspace size>):rechp a
<flen> is the length of the file, <file> obviously the filename on a QDOS medium, and <dataspace size> the size of the dataspace you used when compiling.

Another possibility would be to create an win_ image on the USB stick.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: test_task won't copy to DOS4_ on QPC2

Post by dilwyn »

How many times does this have to be repeated on the QL scene?


RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: test_task won't copy to DOS4_ on QPC2

Post by RWAP »

dilwyn wrote:How many times does this have to be repeated on the QL scene?
The better solution would be to ensure that all emulators and QLs supported the q-emulator method of saving direct to (and of course loading / executing from) DOS formatted devices so that those new to the QL scene (or returning after many years) would not even have this query!


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: test_task won't copy to DOS4_ on QPC2

Post by stevepoole »

Hi,
Thanks for your useful replies.

First I must confess I don't possess ZIP...

I tried the SEXEC method, but to no avail. So this is what I did :

NEW PC :
OPEN#3,ram1_test_task : f=FLEN : CLOSE#3 : ( nb: f was 9548 : data_space was 2 ko )
a=ALCHP(f) : LBYTES ram1_test_task,a : SBYTES dos4_test_bytes,a,f+2048 : RECHP a

OLD PC :
b=ALCHP(9548) : LBYTES dos4_test_bytes,b : SEXEC win1_rnd_task,b,9548,2048 : EX win1_rnd_task : RECHP b

The task transferred successsfully, and executed correctly on the other PC !
Maybe I should try to dig out ZIP from a QLToday CD... ?

Regards,
Steve Poole.


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: test_task won't copy to DOS4_ on QPC2

Post by dilwyn »

Another method which can be useful purely for file transfer is to use the JOB2BAS program on my website. Converts executables into BASIC programs which survive passing through non-QDOSMS environments and rebuild themselves when run at the destination end.

http://www.dilwyn.me.uk/arch/index.html

Code: Select all

100 REMark JOB2BAS_bas - convert an executable job to a BASIC program
110 REMark by Dilwyn Jones, September 2011
120 :
130 REMark configuration options
140 line_no%        = 1 : REMark first line number of the outputted S*BASIC program.
150 line_inc%       = 1 : REMark line number increment steps of S*BASIC program
160 datas_per_line% = 4 : REMark number of DATA values per line
170 :
180 CLS : CLS #0
190 :
200 INPUT #0,'Enter name of program to convert to BASIC data > ';ip$
210 IF ip$ = '' THEN STOP
220 :
230 INPUT #0,'Filename of BASIC program to save > ';op$
240 IF op$ = '' THEN STOP
250 :
260 OPEN_IN #3,ip$
270 IF FTYP (#3) <= 0 THEN
280   REMark no need to convert data files or S*BASIC programs
290   CLOSE #3
300   PRINT #0,'No need to convert this file type.'
310   STOP
320 END IF
330 :
340 file_len   = FLEN(#3) : REMark length of original program
350 data_space = FDAT(#3) : REMark dataspace of original program
360 :
370 IF file_len <= 0 OR data_space <= 0 THEN
380   CLOSE #3
390   PRINT #0,'Unsuitable program file.'
400   STOP
410 END IF
420 :
430 REMark how many long words and any extra (1-3 bytes) in Job file?
440 no_of_words     = INT(file_len/2)
450 oddbytes        = file_len-(2*no_of_words)
460 :
470 base = ALCHP(file_len) : REMark use RESPR instead if your system has no ALCHP extension
480 IF base <= 0 THEN
490   CLOSE #3
500   PRINT #0,'Unable to allocate memory to hold the original job.'
510   STOP
520 END IF
530 :
540 PRINT #0,'Loading'!ip$!'...'
550 LBYTES ip$,base
560 PRINT #0,'Building output S*BASIC program...'
570 :
580 OPEN_NEW #4,op$
590 :
600 REMark comment start of the S*BASIC equivalent...
610 PRINT #4,line_no%&' REMark '&ip$&' as an S*BASIC program.'
620 line_no% = line_no% + line_inc%
630 :
640 REMark comment how to recreate the Job program file
650 PRINT #4,line_no%&' REMark just RUN this program to recreate the original Job file'
660 line_no% = line_no% + line_inc%
670 :
680 REMark add code to output BASIC program to recreate original Job
690 PRINT #4,line_no%&' :'                                                             : line_no% = line_no%+line_inc%
700 PRINT #4,line_no%&' CLS : CLS #0 : RESTORE'                                        : line_no% = line_no%+line_inc%
710 PRINT #4,line_no%&' READ words,oddbytes'                                           : line_no% = line_no%+line_inc%
720 PRINT #4,line_no%&' READ orig_name$,orig_dspace'                                   : line_no% = line_no%+line_inc%
730 PRINT #4,line_no%&' base = ALCHP((2*words)+oddbytes) : REM or use RESPR()'         : line_no% = line_no%+line_inc%
740 PRINT #4,line_no%&' FOR a = 0 TO words-1'                                          : line_no% = line_no%+line_inc%
750 PRINT #4,line_no%&'   READ value : POKE_W base+(2*a),value'                        : line_no% = line_no%+line_inc%
760 PRINT #4,line_no%&' END FOR a'                                                     : line_no% = line_no%+line_inc%
770 PRINT #4,line_no%&' IF oddbytes > 0 THEN'                                          : line_no% = line_no%+line_inc%
780 PRINT #4,line_no%&'   READ value : POKE base+(2*words),value'                      : line_no% = line_no%+line_inc%
790 PRINT #4,line_no%&' END IF'                                                        : line_no% = line_no%+line_inc%
800 PRINT #4,line_no%&' PRINT #0,"Original filename was ";orig_name$'                  : line_no% = line_no%+line_inc%
810 PRINT #4,line_no%&' INPUT #0,"Save as filename > ";op$'                            : line_no% = line_no%+line_inc%
820 PRINT #4,line_no%&' IF op$ = "" THEN STOP'                                         : line_no% = line_no%+line_inc%
830 PRINT #4,line_no%&' PRINT #0,"Saving ";op$'                                        : line_no% = line_no%+line_inc%
840 PRINT #4,line_no%&' SEXEC op$,base,2*words+oddbytes,orig_dspace'                   : line_no% = line_no%+line_inc%
850 PRINT #4,line_no%&' RECHP base : REMark remove if using RESPR() above'             : line_no% = line_no%+line_inc%
860 PRINT #4,line_no%&' PRINT #0,"Program finished"'                                   : line_no% = line_no%+line_inc%
870 PRINT #4,line_no%&' STOP'                                                          : line_no% = line_no%+line_inc%
880 PRINT #4,line_no%&' :'                                                             : line_no% = line_no%+line_inc%
890 :
900 REMark how many long words and any extra bytes...
910 PRINT #4,line_no%&' DATA '&no_of_words&','&oddbytes&' : REMark number of LONG WORDS and ODD BYTES at end'
920 line_no% = line_no% + line_inc%
930 :
940 REMark what was the original filename?
950 PRINT #4,line_no%&" DATA '"&ip$&"' : REMark original Job program's filename."
960 line_no% = line_no% + line_inc%
970 :
980 REMark what was the original dataspace?
990 PRINT #4,line_no%&' DATA '&data_space&' : REMark original dataspace'
1000 line_no% = line_no% + line_inc%
1010 PRINT #4,line_no%&' :' : REMark just a spacer line
1020 line_no% = line_no% + line_inc%
1030 :
1040 REMark start to assemble the program data
1050 dpl% = 0 : REMark how many DATA items on current line so far?
1060 lne$ = line_no%&' DATA '
1070 :
1080 FOR a = base TO base+file_len-1 STEP 2
1090   word = PEEK_W(a) : REMark get a word
1100   IF dpl% >= datas_per_line% THEN
1110     PRINT #4,lne$ : REMark output the line
1120     line_no% = line_no% + line_inc%
1130     lne$ = line_no% & ' DATA '&word
1140     dpl% = 1
1150   ELSE
1160     REMark still room on this line
1170     REMark add a comma before value (unless this is the first item after DATA)
1180     IF dpl% > 0 THEN lne$ = lne$&','
1190     lne$ = lne$ & word : REMark add to DATA list
1200     dpl% = dpl% + 1
1210   END IF
1220 NEXT a
1230   IF dpl% > 0 THEN PRINT #4,lne$ : REMark part line to output
1240 END FOR a
1250 :
1260 IF oddbytes THEN
1270   REMark any odd bytes (1 to 3) to add?
1280   line_no% = line_no%+line_inc%
1290   lne$ = line_no%&' DATA '
1300   FOR a = 1 TO oddbytes
1310     IF a > 1 THEN lne$ = lne$&','
1320     lne$=lne$&PEEK(base+file_len-oddbytes)
1330   END FOR a
1340   PRINT #4,lne$
1350 END IF
1360 :
1370 REMark finished, so tidy up
1380 CLOSE #3 : REMark input JOB file
1390 CLOSE #4 : REMark output BASIC file
1400 RECHP base : REMark REM out this line if no RECHP command on your system
1410 :
1420 REMark tell user we have finished
1430 PRINT #0,'Program finished.'
1440 PRINT 'Transfer'!op$!'to'!'the'!'required'!'system,'!'then'!'just'!'RUN'!'it'!'to'!'recreate'!'the'!'Job'!'program'!'file!'
1450 STOP
This doesn't involve learning and using zip and unzip - just click on 'select all' then CTRL-C to copy the code then just transfer it to your emulator or QL system in the normal way, then it should load as a normal S*BASIC program. I tried attaching the files unzipped, but the Forum is one step ahead of me and for security won't allow files with most extensions (or no extensions). Of course, it doesn't store files in executable format, it just changes them to BASIC programs which aren't affected by being in a non-QDOS environment, so is only really useful for file transfer, not day to day storage.

I agree with Rich that all emulators using a common format for executables outside the QDOS/SMSQ environments would be an ideal system. At the moment, I get sent a lot of material in Qemulator or SMSQmulator format which people often fail to think before sending if it will run on any other system - of course it doesn't (program is modified to preserve headers) and it never makes it to my website because I don't get time to convert it back to standard QL format so everyone can use it. To "de-convert" it only involves copying the executable from the emulator's own native media format to a QDOS media such as ramdisk or floppy disk and zip it up from there instead of lazily zipping it and sending it from the native directory.


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: test_task won't copy to DOS4_ on QPC2

Post by tofro »

RWAP wrote:
dilwyn wrote:How many times does this have to be repeated on the QL scene?
The better solution would be to ensure that all emulators and QLs supported the q-emulator method of saving direct to (and of course loading / executing from) DOS formatted devices so that those new to the QL scene (or returning after many years) would not even have this query!
Rich,

I don't think so. I have just recently come across a number of files that were zipped up in a QDOS zip file and had Q-Emulator headers in front them (And obviously didn't run as well - Oh my). That's just going to add to the confusion.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: test_task won't copy to DOS4_ on QPC2

Post by stevepoole »

Hi,
Many thanks to Tofro, Dilwyn & Rwap for your suggestions.
My problem with non_QDOS file_task transfers is now solved.
Perhaps we could now write TASK_SAVE() and TASK_LOAD() keywords, if there is any demand ?
Regards,
Steve Poole.


Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: test_task won't copy to DOS4_ on QPC2

Post by Martin_Head »

Or you could use floppy disk image files. QPC2 supports floppy images. Or even my MDI/FDI drivers(plug, plug)


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: test_task won't copy to DOS4_ on QPC2

Post by NormanDunbar »

Martin_Head wrote:Or you could use floppy disk image files. QPC2 supports floppy images. Or even my MDI/FDI drivers(plug, plug)
You could, but they are interesting to use if, like me, QPC2 runs under WINE on Linux.

If I navigate my way to a floppy image at startup, and choose it, I get told off as the "Path was not found". However, as my images live in /data/FloppyImages/ then I can type in the full path for the flp1_ and flp2_ drives as \\?\unix\data\FloppyImages\whatever.img and it will be recognised as a floppy image. Yes, the question mark is required!

I'm not logging this as a bug, it's one of the foibles of running Windows software on a proper operating system! :D :D :D

Now, let's see if I can figure out why Text87Plus4 won't run under QPC2 4.00 on Linux........


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Post Reply