It is currently Tue Sep 16, 2014 11:26 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: Mon Jan 28, 2008 1:29 pm 
Offline

Joined: Thu May 17, 2007 3:00 pm
Posts: 72
Location: Duesseldorf, Germany
Okay, I know that (unfortunately) there is no fseek() available with cc65 on the c64 platform. So how do I implement random access files then? Is there a way to do it the old "REL file" way utilizing cbm_open / cbm_read / cbm_write ?! Any help will be apprecitated!!

_________________
LOAD ":*",8,1
READY.
RUN


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 4:37 pm 
Offline

Joined: Thu Jan 12, 2006 11:47 am
Posts: 110
i dont think REL files are supported, you could do it with direct t/s access ...

(and you really should ask this on the cc65 mailinglist =P)

_________________
http://hitmen.c02.at/html/tools_rr.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 28, 2008 6:23 pm 
Offline

Joined: Thu May 17, 2007 3:00 pm
Posts: 72
Location: Duesseldorf, Germany
groepaz wrote:
i dont think REL files are supported, you could do it with direct t/s access ...


hmm, that's the one method I tried to avoid so far ...

groepaz wrote:
(and you really should ask this on the cc65 mailinglist =P)


hmm... I guess those gurus have more important things to do than answer stupid newbie questions :oops: . But that's probably the only choice I have then ...

_________________
LOAD ":*",8,1
READY.
RUN


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 1:00 am 
Offline
Site Admin

Joined: Wed Jan 11, 2006 12:22 pm
Posts: 845
Is there a fseek equivalent in CBM DOS for non-REL files?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 3:59 am 
Offline

Joined: Thu Jan 12, 2006 11:47 am
Posts: 110
nope. REL files dont really allow fseek either :)

_________________
http://hitmen.c02.at/html/tools_rr.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 12:15 pm 
Offline

Joined: Sat Oct 14, 2006 9:30 am
Posts: 140
REL files let you read any record, which is close enough - you can just read and discard a few bytes to move to the proper position.

A little custom drive code would do the trick though. What are you working on?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 1:25 pm 
Offline

Joined: Thu May 17, 2007 3:00 pm
Posts: 72
Location: Duesseldorf, Germany
Well, I'm working on a generic routine to take data in a struct e.g. an address record like this:

record_no: 1
name: tom
surname: thompson
phone: 1234

and write it to a file. the next record wil be appended to the existing file. If I want to change a single record, I just want to access and manipulate this particular record and not load the whole data (all records) into ram. with fseek this is not too complicated, but it gets complicated without it, me thinks ...

I'm just surprised that there is fread() and fwrite() but no ftell() and fseek() - for whatever reasons that is ...

_________________
LOAD ":*",8,1
READY.
RUN


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 5:33 pm 
Offline

Joined: Thu Jan 12, 2006 9:04 am
Posts: 116
Location: Germany / 88471
the simple reason for fseek & friends not existent is that the cbm dos simply offers no way to alter the "file pointer" if you can speak of such a thing. i had a similar problem lately when writing some std libs for Power-C, and i could implement fseek(offs, SEEK_CUR) but that's all there is to do: skipping bytes. Everything else is simply not available (without going beyond DOS level) - for your application the normal way would be to read the whole file once, then do all modifications in RAM and at last write the whole stuff back to file - or: use REL files: they are predestined for your purpose and let you access each single record, but handling REL files is not quite easy, at least i never really dealed with'em, so i can't tell you more.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 6:18 pm 
Offline

Joined: Thu Jan 12, 2006 11:47 am
Posts: 110
i made a whacked up half working fseek once.... basically skip bytes when seeking forward, and close/reopen/skip when seeking backwards. very ugly :)

_________________
http://hitmen.c02.at/html/tools_rr.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 9:01 pm 
Offline
Site Admin

Joined: Wed Jan 11, 2006 12:22 pm
Posts: 845
@lodger: well in that case I think REL is your only friend in the C= realm :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 12:25 pm 
Offline

Joined: Sat Oct 14, 2006 9:30 am
Posts: 140
Yes, as RaveGuru says REL is the way to go. It's basically a simple database format, where you can read and edit any record at will.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 30, 2008 4:11 pm 
Offline

Joined: Thu May 17, 2007 3:00 pm
Posts: 72
Location: Duesseldorf, Germany
Hmm... looks like I'll have to go back to BASIC after more than 16 years and check out REL file handling (using the examples in the 1541 drive manual) then. And I'll have to do it in (cc65) C afterwards.

Regarding my current project: I've written some code that makes up a small, simple and very lightweight "text adventure creator" (very, very simple!). It's far from being finished and currently all room and object data is stored in memory and then - after editing all data is done - written back to disk using cbm_write (just as hannez suggested). Unfortunately this takes a lot of time. If I split "editor" and "game engine" into two separate parts, this may be a useful workaround (until I know how to do the REL file stuff).

Anyway, thanks for helping me out here! :)

_________________
LOAD ":*",8,1
READY.
RUN


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 1:15 am 
Offline

Joined: Sat Oct 14, 2006 9:30 am
Posts: 140
I would suggest working with a memory expansion for the editor. cc65 comes with drivers for the popular ones. After editing is done you can write down a packed file to disk. Doing read-only random access is, perhaps not easy, but at least a solved problem (i.e. IFFL loaders).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group