Converting .BIN files to .PRG (Split/moved from HW/Tech)

Basic and Machine Language

Moderator: Moderators

Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Converting .BIN files to .PRG (Split/moved from HW/Tech)

Post by Boray »

I suspect all files even sequencial files have those two bytes. So I think it would be best to go outside of the vic (or Vice) to make a converter. A program on the PC for example...
Last edited by Boray on Tue Dec 05, 2006 7:03 am, edited 1 time in total.
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
User avatar
eslapion
ultimate expander
Posts: 5458
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Post by eslapion »

Boray wrote:I suspect all files even sequencial files have those two bytes. So I think it would be best to go outside of the vic (or Vice) to make a converter. A program on the PC for example...
Nope, a sequential file does not have an address header. It is a sequence... of data.

Programming, at least to me, is a lot more complicated on the PC than it is on a VIC or 64...
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

You are right of course... How else would all my text converting programs work! ;)
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
User avatar
eslapion
ultimate expander
Posts: 5458
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Post by eslapion »

Boray wrote:You are right of course... How else would all my text converting programs work! ;)
If you programmed text converting software then you must be able to tell me how to do the conversion I want to do with .bin to .prg and .prg to .bin, right?
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

I thought you wanted to do it yourself?

The problem is that it's very slow to read byte by byte (with GET#) so the program will get very slow...

something like this maybe:

(bin to prg)

10 open 1,8,0,"input"
20 open 2,8,1,"output"
30 print #2,chr$(b1);chr$(b2); :rem address bytes

50 get#1,a$
60 if st<>0 then close1:close2:end
70 print#2,a$;
80 goto 50
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

It speeds up quite a bit by reading more than one byte at a time:

get #1,a$,b$,c$,d$

print #2,a$;b$;c$;d$;

But the trouble is then that the end of the file won't be exact. You will most likely get some extra bytes, but I have used this in my converting programs anyway...
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
Boray
Musical Smurf
Posts: 4064
Joined: Mon May 03, 2004 10:47 am

Post by Boray »

Maybe some moderator should move this topic to the programming forum?
PRG Starter - a VICE helper / Vic Software (Boray Gammon, SD2IEC music player, Vic Disk Menu, Tribbles, Mega Omega, How Many 8K etc.)
User avatar
eslapion
ultimate expander
Posts: 5458
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Post by eslapion »

Boray wrote:The trouble is then that the end of the file won't be exact. You will most likely get some extra bytes, but I have used this in my converting programs anyway...
.BIN files for rom images are always a multiple of 1024 so, unless I use more than 1024 bytes transfered at a time, there shouldn't be any problems.

In your program, there is an "output" opened channel but I expected this only to write the .bin to memory at an address of my choosing.

Doing the file the way you tell me seems to work as it created a new file with 2 extra bytes at the beginning, however the result is also a sequential file and not a prg.

I think what I want, judging from what you gave me here, should be more like:

5 rem acquisition routine by Boray
10 open 1,8,0,"input"
15 t=0
20 get#1,a%
30 poke8192+t,a%
40 t=t+1
50 if st<>0 then close 1:goto70
60 goto20
65 rem save routime given by Mike
70 SYS57809"myprgfile",8,1:POKE193,0:POKE194,32
80 POKE780,193:POKE781,0:POKE782,(8192+(t+1)/256):SYS65496

Assuming I want to have 8192 as a starting address.

If there is any major errors here, and particularly on lines 20-30, by all means, please tell me.
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

I am an Emacs person. Unless the source or destination file has to be on a Commodore disk image, I would use Emacs to add or remove two bytes at the beginning of a file. Other editors might work as well, but not all are binary safe.

I think some PC side CBM tool has built-in functions for doing this, but I'm not sure which.
Anders Carlsson

Image Image Image Image Image
carlsson
Class of '6502
Posts: 5516
Joined: Wed Mar 10, 2004 1:41 am

Post by carlsson »

eslapion wrote: 20 get#1,a%
30 poke8192+t,a%
You can only GET# (and GET) string variables, so it should read:

20 GET#1,A$:IFA$=""THENA$=CHR$(0)
30 POKE8192+T,ASC(A$)

The IF statement is because empty string will cause error with ASC.
Anders Carlsson

Image Image Image Image Image
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

eslapion wrote:I think what I want, judging from what you gave me here, should be more like:

5 rem acquisition routine by Boray [...]
An even better version is:

Code: Select all

10 DEFFNHI(X)=INT(X/256)
20 DEFFNLO(X)=X-256*FNHI(X)
30 OPEN2,8,2,"input,p,r":S=8192:T=S
40 GET#2,A$:IFST=0THENPOKET,ASC(A$+CHR$(0)):T=T+1:GOTO40
50 CLOSE2:SYS57809"myprgfile",8,1:POKE193,FNLO(S):POKE194,FNHI(S)
60 POKE780,193:POKE781,FNLO(T):POKE782,FNHI(T):SYS65496
Note: ASC operates only on the first character of its argument.

Michael
User avatar
eslapion
ultimate expander
Posts: 5458
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Post by eslapion »

Hey! Mike to the rescue again!

Thanks!

Now what's missing is how to go the other way around...
User avatar
Jeff-20
Denial Founder
Posts: 5759
Joined: Wed Dec 31, 1969 6:00 pm

Post by Jeff-20 »

Boray wrote:Maybe some moderator should move this topic to the programming forum?
Are you not a mod in this forum? :lol: :wink:
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

If you are on a unix-like system you could do this...

bin2prg:

Code: Select all

echo -e -n '\x00\x40' | cat - file.bin > file.prg
(load addr $4000 in the example)

prg2bin:

Code: Select all

dd if=file.prg of=file.bin bs=1 skip=2
(any load addr)
User avatar
eslapion
ultimate expander
Posts: 5458
Joined: Fri Jun 23, 2006 7:50 pm
Location: Canada
Occupation: 8bit addict

Post by eslapion »

tlr wrote:If you are on a unix-like system you could do this...

bin2prg:

Code: Select all

echo -e -n '\x00\x40' | cat - file.bin > file.prg
(load addr $4000 in the example)

prg2bin:

Code: Select all

dd if=file.prg of=file.bin bs=1 skip=2
(any load addr)
Sorry, I am a slave to Bill... I'm a Windows guy and I don't even know how to make programs under that OS...
Post Reply