Author Topic: Writing a binary file from PCW Locomotive BASIC  (Read 1085 times)

0 Members and 1 Guest are viewing this topic.

Offline JonB

  • 6128 Plus
  • ******
  • Posts: 752
  • Country: gb
  • Liked: 203
  • Likes Given: 48
Writing a binary file from PCW Locomotive BASIC
« on: 14:13, 23 February 17 »
Hi

I need to write a binary file on the PCW from a BASIC program. I can't find a manual for this version of BASIC anywhere online and I'm away from my printed manuals.

I tried OPEN and PRINT# but this only seems to like 7 bit ASCII characters. I used "O" mode, but can't find a description of the other modes.

I also tried SAVE "file", B, start_addr, length per the 6128 manual (I found a download) but it is not implemented on the PCW so it gives a syntax error.

Could anyone have a look in the PCW manual for me and let me know how to do this, please? My binary data is currently in a memory block from &HD000 and it's 4096 bytes long.


Thanks
JonB

Offline GeoffB17

  • 6128 Plus
  • ******
  • Posts: 617
  • Country: gb
  • PCW since '85
  • Liked: 135
  • Likes Given: 7
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #1 on: 15:28, 23 February 17 »
Jon,


Checking my manual, which I do have to hand...


You need something like this..


open "R", #1, "FILE.BIN", 1
field #1, 1 as data0
count = &HD000
for i = 1 to 4096
  data1 = peek(count)
   data2 = chr$(data1)
   lset data0 = data2
  put #1
  count = count + 1
next
close #1


I might have got some little bits wrong, maybe I should actually do it, but why spoil your fun.


Important things, use a RANDOM file, with record length of 1 byte.
Get the data from RAM 1 byte at a time, write data to the file 1 byte at a time.   PUT command will default to next record anyway.


That (or something VERY like) should give you a binary file of the m/code.


Geoff


PS bits re LSET now added.

« Last Edit: 15:43, 23 February 17 by GeoffB17 »

Offline JonB

  • 6128 Plus
  • ******
  • Posts: 752
  • Country: gb
  • Liked: 203
  • Likes Given: 48
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #2 on: 22:49, 23 February 17 »
That's pretty non intuitive. What's wrong with open "WB", 1, "file.com" then print #1 chr$(byte)?


Thank you, Locomotive Software...


Geoff, again, thank you. I'll give it a whirl. Main thing here is to limit the amount of typing, because this program is the one I mentioned to retrieve the uIDE FID driver from the DOM image and reconstitute it on A: and users will have to manually type it into their PCWs. So KISS approach applies...

Offline JonB

  • 6128 Plus
  • ******
  • Posts: 752
  • Country: gb
  • Liked: 203
  • Likes Given: 48
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #3 on: 23:13, 23 February 17 »
Well, Geoff, the only problem was that data0 should be a string, but other than that:

Code: [Select]
open "R",#1,"file.bin",1
field #1,1 as data0$
for addr%=&HD000 to &HDFFF
  lset data0$=chr$(peek(ddr%))
  put #1
next addr%
close #1

It's slow, but appears to work. Banzai!

Cheers
JonB

Offline 1024MAK

  • Supporter
  • 464 Plus
  • *
  • Posts: 341
  • Country: gb
  • Touching the hot end of an iron will hurt!
  • Liked: 145
  • Likes Given: 196
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #4 on: 20:32, 24 February 17 »
Well, Geoff, the only problem was that data0 should be a string, but other than that:

Code: [Select]
open "R",#1,"file.bin",1
field #1,1 as data0$
for addr%=&HD000 to &HDFFF
  lset data0$=chr$(peek(ddr%))
  put #1
next addr%
close #1

It's slow, but appears to work. Banzai!

Cheers
JonB


Jon, have you lost an 'a' from the variable used by the PEEK function?
Should it be
Code: [Select]
lset data0$=chr$(peek(addr%))
?

Mark
Looking forward to summer in Somerset :-)

Offline JonB

  • 6128 Plus
  • ******
  • Posts: 752
  • Country: gb
  • Liked: 203
  • Likes Given: 48
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #5 on: 22:04, 24 February 17 »
Yeah, typo.


Program appears to work but there's a bug somewhere. Gonna hunt & destroy!

Offline GeoffB17

  • 6128 Plus
  • ******
  • Posts: 617
  • Country: gb
  • PCW since '85
  • Liked: 135
  • Likes Given: 7
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #6 on: 23:17, 24 February 17 »
Jon,


Found your bug yet?


Is the resultant file the right length, 4096 bytes?


One thing to check, is addr% ok as an int?   Maybe it's too big, might actually be running as minus.   May need to be SNG, ! rather than %, i.e. addr!   INT can be -32768 to +32767, and I think the addr range you're using is over 32767 and will therefore be treated as minus.   So the count +1 will go the wrong way.


Geoff

Offline JonB

  • 6128 Plus
  • ******
  • Posts: 752
  • Country: gb
  • Liked: 203
  • Likes Given: 48
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #7 on: 23:45, 24 February 17 »
Yeah, I noticed, and you're probably right.


I could change them all to floating points, but first need to have a good look at the diffs between the fid and recreated fid. I have a "suspicion".... (he said, mysteriously.)

Offline JonB

  • 6128 Plus
  • ******
  • Posts: 752
  • Country: gb
  • Liked: 203
  • Likes Given: 48
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #8 on: 00:09, 25 February 17 »
Looking at the Mallard manual, it seems to imply that a 2's complement integer can be turned into a positive value under certain circumstances, but it's not clear what these are. Section 2.9 and 2.10 pertain here.


A short program:


Code: [Select]
for x%=&HD000 to &HD500
if x% mod 16 = 0 then print: print hex$(x%,4);" ";
print hex$(peek(x%),2);" ";
next x%


This produces a hex dump of the bit of memory where the binary file is loaded to. If the variable x% wasn't incrementing properly, the line addresses would be wrong. But it works. So I think when you PRINT X% it gets interpreted as a negative number during the print formatting, but it's still a positive 16 bit integer for the purposes of incrementing and peek().


At least, that is what the evidence suggests.

Offline GeoffB17

  • 6128 Plus
  • ******
  • Posts: 617
  • Country: gb
  • PCW since '85
  • Liked: 135
  • Likes Given: 7
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #9 on: 03:02, 25 February 17 »
Hmm, yes.  Probably?


Seems that Mallard Basic does not allow the explicit definition of an integer as 'unsigned', but in certain places (such as PEEK and POKE) the system accepts that the integer MUST be unsigned (cannot have a minus memory address) so the value is interpreted as unsigned.   I assume that the value is still STORED as signed.


This conversion may well take place within the PEEK or POKE code?


It may well work, but seems to me that there may be a hazard lurking there.


I would tend to follow KISS.   Using Integer type will gain a little speed, but it that so vital here?


Geoff


Offline JonB

  • 6128 Plus
  • ******
  • Posts: 752
  • Country: gb
  • Liked: 203
  • Likes Given: 48
Re: Writing a binary file from PCW Locomotive BASIC
« Reply #10 on: 12:45, 26 February 17 »
Finally got it working!


I will update the WIKI with the program. You will need to type it in yourself. And it will only work if you have one of my DOMs, because I will load the driver onto each one before shipping.