Converting .BIN files to .PRG (Split/moved from HW/Tech)
Moderator: Moderators
Converting .BIN files to .PRG (Split/moved from HW/Tech)
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: 5458
- Joined: Fri Jun 23, 2006 7:50 pm
- Location: Canada
- Occupation: 8bit addict
Nope, a sequential file does not have an address header. It is a sequence... of data.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...
Programming, at least to me, is a lot more complicated on the PC than it is on a VIC or 64...
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.)
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
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.)
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...
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.)
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: 5458
- Joined: Fri Jun 23, 2006 7:50 pm
- Location: Canada
- Occupation: 8bit addict
.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.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...
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.
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.
I think some PC side CBM tool has built-in functions for doing this, but I'm not sure which.
Anders Carlsson
- Mike
- Herr VC
- Posts: 4888
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
An even better version is:eslapion wrote:I think what I want, judging from what you gave me here, should be more like:
5 rem acquisition routine by Boray [...]
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
Michael
If you are on a unix-like system you could do this...
bin2prg:
(load addr $4000 in the example)
prg2bin:
(any load addr)
bin2prg:
Code: Select all
echo -e -n '\x00\x40' | cat - file.bin > file.prg
prg2bin:
Code: Select all
dd if=file.prg of=file.bin bs=1 skip=2
- eslapion
- ultimate expander
- Posts: 5458
- Joined: Fri Jun 23, 2006 7:50 pm
- Location: Canada
- Occupation: 8bit addict
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...tlr wrote:If you are on a unix-like system you could do this...
bin2prg:(load addr $4000 in the example)Code: Select all
echo -e -n '\x00\x40' | cat - file.bin > file.prg
prg2bin:(any load addr)Code: Select all
dd if=file.prg of=file.bin bs=1 skip=2