6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 5:25 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Using fopen() in cc65
PostPosted: Tue Oct 03, 2017 12:41 pm 
Offline
User avatar

Joined: Tue Oct 03, 2017 10:56 am
Posts: 13
Hey guyz,

I am coding a game for Atari 8bit, and want to use fopen() in cc65 to read some game related data.

I used mkatr.exe to create a bootable ATR, containing only my prog and data file.
However, I cannot seem open the file (I tried both upper and lower case filename).
fopen("myfile.dat") always return 0.

Does anyone know if a specific ATR format (SpartaDOS...) is required for fopen() to work?

Cheers,
Tony

_________________
8bit-Slicks is coming out soon, register for the closed-beta!
Image


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 03, 2017 8:47 pm 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
No reason it should. The Ataris CIO is the moderator between your code and the actual disk OS, and it standardized all of the conventional I/O operations. (Extended stuff would have to be done via the equivalent of the XIO call, which is mostly just a raw call to CIO).

I don't know what a "bootable ATR" is, but if you're loading your code straight from the boot segment (or, say, a ROM Cartridge), vs having DOS load it via a command or whatever the equivalent of "autorun" your DOS uses, you probably don't have DOS loaded at all. That would explain the failure as well.


Top
 Profile  
Reply with quote  
PostPosted: Tue Oct 03, 2017 10:21 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
8bit-Dude wrote:
fopen("myfile.dat") always return 0.

Doesn't fopen() typically require two arguments?

FILE * fopen ( const char * filename, const char * mode );

Mike B.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 04, 2017 10:58 am 
Offline
User avatar

Joined: Tue Oct 03, 2017 10:56 am
Posts: 13
Thanks for the replies guys!

Here is a sample of my code:

Code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <unistd.h>

void LoadBitmap(char *filename)
{
   FILE* fp;
   
   // Open Map File
   fp = fopen(filename, "rb");   
   
    if (fp>0) {
        printf("Loading...\n");
        fread((char*)(0xA100), 1, 0x1E00, fp);
        fclose(fp);
    } else {
        printf("File not found...\n");
    }
}

int main (void)
{
    // Try loading file
    LoadBitmap("freeway.dat");
    printf("Ready to start MGM\n");
    cgetc ();
       
    // Done
    return EXIT_SUCCESS;
}


When loading the resulting ATR file (with compiled prog and data file), I get the message file not found.
I have attached the ATR file (loadable in Altirra) and Sources.


Attachments:
freeway.zip [31.5 KiB]
Downloaded 94 times

_________________
8bit-Slicks is coming out soon, register for the closed-beta!
Image
Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 04, 2017 11:43 am 
Offline

Joined: Thu Mar 03, 2011 5:56 pm
Posts: 284
Note that fp is a pointer; the check should be "fp != NULL" (or possibly "fp != 0"), not "fp > 0"...

... assuming Unix-like (or POSIX-like) semantics of fopen.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 04, 2017 11:52 am 
Offline

Joined: Wed Oct 04, 2017 11:46 am
Posts: 4
As alluded to above, you need some form of DOS on the disk as well (or at least the A8 needs to have a DOS loaded). While the ATR is in SpartaDOS/X format, it doesn't actually contain SDX itself. Of course, you might be booting SDX from cartridge.

Attached (hopefully) is an ATR with Atari DOS 2.5 on it, with your program (renamed to AUTORUN.SYS) and data file on it. When booting this in Altirra, I no longer get the error message.

I've left the whole Atari DOS 2.5 on the image, but some of this can be deleted.

Jeremy


Attachments:
File comment: ATR Image
freeway-dos25.zip [40.8 KiB]
Downloaded 109 times
Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 04, 2017 11:56 am 
Offline
User avatar

Joined: Tue Oct 03, 2017 10:56 am
Posts: 13
Ed, that's a fantastic reply, thank you so much!

Could you kindly tell me how I can compile such disk myself?
Did you use mkatr, or some other program?

_________________
8bit-Slicks is coming out soon, register for the closed-beta!
Image


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 04, 2017 12:13 pm 
Offline

Joined: Wed Oct 04, 2017 11:46 am
Posts: 4
I'm at work without access to hobby stuff, so I cheated a bit by taking an existing ATR from a program I developed, deleted my program using Tools > Disk Explorer in Altirra then dragged and dropped your files into the image. I then renamed FREEWAY.COM to AUTORUN.SYS (again in Disk Explorer).

I can't remember exactly where I got the Atari DOS 2.5 ATR from, but it was easy enough to find online at the time I was writing the program.

Disk images are available here for various DOSes.

https://atariwiki.org/wiki/Wiki.jsp?page=Atari%20DOS%202

Hopefully this helps.

Jeremy


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 04, 2017 12:50 pm 
Offline
User avatar

Joined: Tue Oct 03, 2017 10:56 am
Posts: 13
SUP, I got the same idea working with "atadim.exe"!

If you may have a little extra time, could you please look into my next problem here: viewtopic.php?f=2&t=4933

Thank you in advance!!

_________________
8bit-Slicks is coming out soon, register for the closed-beta!
Image


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 04, 2017 2:40 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Wow, Jeremy, you jumped right in out of nowhere and provided some excellent help! Thank you. You should Introduce yourself and tell us a bit about your background.

Mike B.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 18 guests


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: