| retrohackers.org http://retrohackers.org/ |
|
| cc65 -> fseek() not available, so what now? http://retrohackers.org/viewtopic.php?f=6&t=338 |
Page 1 of 1 |
| Author: | lodger [ Mon Jan 28, 2008 12:29 pm ] |
| Post subject: | cc65 -> fseek() not available, so what now? |
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!! |
|
| Author: | groepaz [ Mon Jan 28, 2008 3:37 pm ] |
| Post subject: | |
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) |
|
| Author: | lodger [ Mon Jan 28, 2008 5:23 pm ] |
| Post subject: | |
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 |
|
| Author: | RaveGuru [ Tue Jan 29, 2008 12:00 am ] |
| Post subject: | |
Is there a fseek equivalent in CBM DOS for non-REL files? |
|
| Author: | groepaz [ Tue Jan 29, 2008 2:59 am ] |
| Post subject: | |
nope. REL files dont really allow fseek either |
|
| Author: | MagerValp [ Tue Jan 29, 2008 11:15 am ] |
| Post subject: | |
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? |
|
| Author: | lodger [ Tue Jan 29, 2008 12:25 pm ] |
| Post subject: | |
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 ... |
|
| Author: | hannenz [ Tue Jan 29, 2008 4:33 pm ] |
| Post subject: | |
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. |
|
| Author: | groepaz [ Tue Jan 29, 2008 5:18 pm ] |
| Post subject: | |
i made a whacked up half working fseek once.... basically skip bytes when seeking forward, and close/reopen/skip when seeking backwards. very ugly |
|
| Author: | RaveGuru [ Tue Jan 29, 2008 8:01 pm ] |
| Post subject: | |
@lodger: well in that case I think REL is your only friend in the C= realm |
|
| Author: | MagerValp [ Wed Jan 30, 2008 11:25 am ] |
| Post subject: | |
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. |
|
| Author: | lodger [ Wed Jan 30, 2008 3:11 pm ] |
| Post subject: | |
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! |
|
| Author: | MagerValp [ Thu Jan 31, 2008 12:15 am ] |
| Post subject: | |
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). |
|
| Page 1 of 1 | All times are UTC [ DST ] |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|