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

Basic and Machine Language

Moderator: Moderators

User avatar
Boray
Musical Smurf
Posts: 4026
Joined: Mon May 03, 2004 10:47 am

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

Postby Boray » Thu Jul 20, 2006 1:59 am

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.)

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

Postby eslapion » Thu Jul 20, 2006 2:50 am

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...

User avatar
Boray
Musical Smurf
Posts: 4026
Joined: Mon May 03, 2004 10:47 am

Postby Boray » Thu Jul 20, 2006 3:04 am

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.)

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

Postby eslapion » Thu Jul 20, 2006 5:40 am

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?

User avatar
Boray
Musical Smurf
Posts: 4026
Joined: Mon May 03, 2004 10:47 am

Postby Boray » Thu Jul 20, 2006 6:16 am

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.)

User avatar
Boray
Musical Smurf
Posts: 4026
Joined: Mon May 03, 2004 10:47 am

Postby Boray » Thu Jul 20, 2006 6:20 am

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.)

User avatar
Boray
Musical Smurf
Posts: 4026
Joined: Mon May 03, 2004 10:47 am

Postby Boray » Thu Jul 20, 2006 6:42 am

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.)

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

Postby eslapion » Thu Jul 20, 2006 8:55 am

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.

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

Postby carlsson » Thu Jul 20, 2006 8:58 am

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

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

Postby carlsson » Thu Jul 20, 2006 9:00 am

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: 3016
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Postby Mike » Thu Jul 20, 2006 10:56 am

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

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

Postby eslapion » Thu Jul 20, 2006 11:58 am

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: 5451
Joined: Wed Dec 31, 1969 6:00 pm

Postby Jeff-20 » Thu Jul 20, 2006 12:17 pm

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 Afficionado
Posts: 438
Joined: Mon Oct 04, 2004 10:53 am

Postby tlr » Thu Jul 20, 2006 1:26 pm

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)

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

Postby eslapion » Thu Jul 20, 2006 3:54 pm

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...


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest