Writing RSC files in C

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
itaboy
Captain Atari
Captain Atari
Posts: 196
Joined: Sun May 04, 2014 6:24 pm

Writing RSC files in C

Post by itaboy »

Hello guys, someone has an example of how to write back to disk a RSC file, after it has been modified in memory (e.g. after having translated or modified parts of it). I need a C routine (Pure C or Lattice C is tha same... I'll adapt)

Thank you guys!

Enrico
ijor
Hardware Guru
Hardware Guru
Posts: 4012
Joined: Sat May 29, 2004 7:52 pm
Contact:

Re: Writing RSC files in C

Post by ijor »

If you have a RSC file, why not use a RSC editor?

But probably the source of an RSC editor, which does more or less what you might want, might be useful.
ThorstenOtto
Atari God
Atari God
Posts: 1159
Joined: Sun Aug 03, 2014 5:54 pm

Re: Writing RSC files in C

Post by ThorstenOtto »

itaboy wrote:Hello guys, someone has an example of how to write back to disk a RSC file, after it has been modified in memory (e.g. after having translated or modified parts of it)
That largely depends upon how you loaded it, and what modifications you made. If you loaded it with rsrc_load(), and only modified the contents of the strings (but not the pointers to them), all you have to do is convert back all pointers into offsets from the header start, then write it back to disk. You get the address of the header, as well as the filesize from the aes global array after the rsrc_load() call. If you modified pointers to some area outside of the original resource data, or deleted/added objects, or the resource contains color icons, things are getting more complicated. Then you have to count all the invidiual objects, tedinfos, bitblks, strings etc, allocate space for it then copy your resource data over, calculating the offsets while you do. Dunno wether it helps, but at
http://www.retroarchive.org/cpm/archive ... gemrcs.zip you will find the source of DRI's RCS.
AtariZoll
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2978
Joined: Mon Feb 20, 2012 4:42 pm
Contact:

Re: Writing RSC files in C

Post by AtariZoll »

Plenty of good RSC editors available.
Structure of RSC files is well decsribed in Atari ProfiBuch, so you can go on it even without some C source :D
But I really don't see why do it at all now.
Famous Schrodinger's cat hypothetical experiment says that cat is dead or alive until we open box and see condition of poor animal, which deserved better logic. Cat is always in some certain state - regardless from is observer able or not to see what the state is.
itaboy
Captain Atari
Captain Atari
Posts: 196
Joined: Sun May 04, 2014 6:24 pm

Re: Writing RSC files in C

Post by itaboy »

Hi guys, first of all thank you for the replies. What I am doing is writing a RSC file translator. That is a program that has the only specific purpose to be able to adapt the text within the existing objects in a given rsc file to a different language.
The difference between this program and a full fledged resource editor is that a program like this makes it much easier and convenient to prepare 1 original resource file and to add a text file which contains all the different variations in any given language.
The beta version is already up and running, and works pretty well, I must say. I have been able to work on different rsc files of other programs and map the strings within. This way it is really much much easier to prepare translations (the only constraint being that the translated text must never be longer than the original text).
My only problem is in writing back the modified rsc file to disk. I assume I am making some errors during the conversion of pointers to offests, as ThorstenOtto suggested... I'll double check for that!

Thanks again!
User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12908
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Writing RSC files in C

Post by wongck »

itaboy wrote: My only problem is in writing back the modified rsc file to disk. I assume I am making some errors during the conversion of pointers to offests, as ThorstenOtto suggested... I'll double check for that!

Thanks again!
Also make sure you do not change the sequence of indexes. PRG needs the index not changed.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list
User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2503
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: Writing RSC files in C

Post by lp »

A long time ago I wrote a desk accessory for dumping RSC files from ram to disk. A sort of rsc ripping tool. Thorsten is correct, it can get complicated with certain object types. Simplifying translations sounds like an interesting project. I hope you get it sorted.
ThorstenOtto
Atari God
Atari God
Posts: 1159
Joined: Sun Aug 03, 2014 5:54 pm

Re: Writing RSC files in C

Post by ThorstenOtto »

itaboy wrote:What I am doing is writing a RSC file translator. That is a program that has the only specific purpose to be able to adapt the text within the existing objects in a given rsc file to a different language.
Sounds like you only want to modify the text of existing resource file of foreign programs? Then the attached routines might help. They are simplified versions of ones i used in other programs, and i did only a quick check after the modifications, but they look ok. There is almost no error checking except for a failed fopen(), and especially the rsc_write() function assumes that all pointers still point to some area in the originally allocated area.
What's left to be done is to convert the object coordinates.
You do not have the required permissions to view the files attached to this post.
itaboy
Captain Atari
Captain Atari
Posts: 196
Joined: Sun May 04, 2014 6:24 pm

Re: Writing RSC files in C

Post by itaboy »

Thanks ThorstenOtto, I'll check straight away! :)
itaboy
Captain Atari
Captain Atari
Posts: 196
Joined: Sun May 04, 2014 6:24 pm

Re: Writing RSC files in C

Post by itaboy »

OK, if any of you is curious, I have made a test program.
It is just a proof of concept, not a full fledged app... but it works.
You can load a RSC file, go through all the strings and change (translate) the ones you want.
When you're done you can save back to disk the new RSC file and use it...

Now it works... thanks Thorsten!
You do not have the required permissions to view the files attached to this post.
User avatar
DrCoolZic
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2261
Joined: Mon Oct 03, 2005 7:03 pm
Location: France
Contact:

Re: Writing RSC files in C

Post by DrCoolZic »

ThorstenOtto wrote:
Then the attached routines might help. They are simplified versions of ones i used in other programs, and i did only a quick check after the modifications, but they look ok. There is almost no error checking except for a failed fopen(), and especially the rsc_write() function assumes that all pointers still point to some area in the originally allocated area.
What's left to be done is to convert the object coordinates.
Very interesting. In you code you include a gem.h file not included in your zip archive. Can you please provide or is it the same as the gembind.h from DRI?

EDIT: your DRI reference is for Intel version. Do you know if source code exist for Atari 68K?
User avatar
DrCoolZic
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2261
Joined: Mon Oct 03, 2005 7:03 pm
Location: France
Contact:

Re: Writing RSC files in C

Post by DrCoolZic »

itaboy wrote:OK, if any of you is curious, I have made a test program.
It is just a proof of concept, not a full fledged app... but it works.
You can load a RSC file, go through all the strings and change (translate) the ones you want.
When you're done you can save back to disk the new RSC file and use it...

Now it works... thanks Thorsten!
I like the idea of the program. But does not work for me.
Tested under Steem / STE / TOS 1.62
Run program, load emalib2.rsc, change one character on first entry, write under emalib3.rsc ==> program bomb and write a zero byte file :(
ThorstenOtto
Atari God
Atari God
Posts: 1159
Joined: Sun Aug 03, 2014 5:54 pm

Re: Writing RSC files in C

Post by ThorstenOtto »

Can you please provide or is it the same as the gembind.h from DRI
In my case this was gem.h from gnu-c's gemlib, but you should be able to use other gem libraries too, as long as it defines the needed types (especially the CICONBLK structure might not be present in very old libraries).
your DRI reference is for Intel version
What do you mean with DRI reference?
User avatar
DrCoolZic
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2261
Joined: Mon Oct 03, 2005 7:03 pm
Location: France
Contact:

Re: Writing RSC files in C

Post by DrCoolZic »

ThorstenOtto wrote:
Can you please provide or is it the same as the gembind.h from DRI
In my case this was gem.h from gnu-c's gemlib, but you should be able to use other gem libraries too, as long as it defines the needed types (especially the CICONBLK structure might not be present in very old libraries).
It would be nice if you can provide a link to the gnu gemlib you are refering to? There are so many references to GEM on the web 8O
What do you mean with DRI reference?
The DRI GEM3RSC archive http://www.retroarchive.org/cpm/archive ... gemrcs.zip
The source code is for Intel processor (lot's of Intel ASM sources). I was wandering if you would know where I can find the same (or similar) source for Atari 68K
User avatar
DrCoolZic
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2261
Joined: Mon Oct 03, 2005 7:03 pm
Location: France
Contact:

Re: Writing RSC files in C

Post by DrCoolZic »

Actually after digging a bit more I found a version completely in C as well as executable.
When trying to run the executable APP it crashes but it might be possible to recompile it …
If you are interested the code can be found here https://www.seasip.info/Gem/gengem.html (source for GEM itself)
ThorstenOtto
Atari God
Atari God
Posts: 1159
Joined: Sun Aug 03, 2014 5:54 pm

Re: Writing RSC files in C

Post by ThorstenOtto »

Gemlib can be found https://github.com/freemint/gemlib here with latest automated build being available here, or http://tho-otto.de/crossmint.php here, or http://arnaud.bercegeay.free.fr/gemlib/ here (somewhat older version), or https://launchpad.net/~vriviere/+archive/ubuntu/ppa here

I think i never used DRI's RCS, but M.Bernstein once compiled a version that should work on ST: http://www.mbernstein.de/download/pc/
If you are interested the code can be found here
Thanks but i prefer to use my own Editor ;)
User avatar
DrCoolZic
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2261
Joined: Mon Oct 03, 2005 7:03 pm
Location: France
Contact:

Re: Writing RSC files in C

Post by DrCoolZic »

Very interesting references. Many thanks
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2703
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Writing RSC files in C

Post by charles »

here is a program , I have never used but it primarily seems to do what your program does.....
You do not have the required permissions to view the files attached to this post.
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
Post Reply

Return to “C / PASCAL etc.”