English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 19 June 2022, 14:52   #1
Csoft
Registered User

 
Join Date: Apr 2021
Location: Italy
Posts: 10
Floppy keeps spinning after fread

Hello all,

I'm developing a game in C, in my code I load assets from floppy with fread/fclose functions, it works, but the floppy keeps spinning even after the load is completed.

How can I solve it?

Thank you in advance,

Lorenzo
Csoft is offline  
Old 19 June 2022, 15:41   #2
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 48
Posts: 8,477
Quote:
Originally Posted by Csoft View Post
Hello all,

I'm developing a game in C, in my code I load assets from floppy with fread/fclose functions, it works, but the floppy keeps spinning even after the load is completed.

How can I solve it?

Thank you in advance,

Lorenzo
Are you shutting down the system after loading files or stopping multitasking with Forbid?
Galahad/FLT is offline  
Old 19 June 2022, 15:55   #3
Csoft
Registered User

 
Join Date: Apr 2021
Location: Italy
Posts: 10
Quote:
Originally Posted by Galahad/FLT View Post
Are you shutting down the system after loading files or stopping multitasking with Forbid?
No, I'm not shutting down the system at all. I'm trying to keep everything OS friendly.
Csoft is offline  
Old 19 June 2022, 19:28   #4
alkis
Registered User

 
Join Date: Dec 2010
Location: Athens/Greece
Age: 51
Posts: 670
what's the flow?
fopen/fread/fclose? (c library)
Open/Read/Close? (OS)
alkis is offline  
Old 21 June 2022, 17:36   #5
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,178
Quote:
Originally Posted by Csoft View Post
No, I'm not shutting down the system at all. I'm trying to keep everything OS friendly.
Then there is no reason it could ever happen. And it should be easy to isolate the problem with some test code doing fopen/fread/fclose.

Is it some strange file system? Or standard FFS?
Note, that a running motor for a few seconds after the last access is normal.
phx is offline  
Old 21 June 2022, 21:52   #6
Csoft
Registered User

 
Join Date: Apr 2021
Location: Italy
Posts: 10
Quote:
Originally Posted by phx View Post
Then there is no reason it could ever happen. And it should be easy to isolate the problem with some test code doing fopen/fread/fclose.

Is it some strange file system? Or standard FFS?
Note, that a running motor for a few seconds after the last access is normal.
Simply this, with standard Amiga FFS, it keeps spinning forever:

Code:
FILE *fp = fopen(filename, "rb");
    if (fp) {
        fread(dest, sizeof(unsigned char), size, fp);
    } else {
        printf("error: file '%s' not found\n", filename);
    }
    fclose(fp);
Csoft is offline  
Old 21 June 2022, 22:31   #7
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 1,777
Please post a complete source. For example, you could run into a buffer overrun here, overwriting some Os variables if "dest" is smaller than "size" bytes. Thus, what is "dest", and "size", and how are they allocated? A standard "fread" (or an underlying Read()) will not cause this.
Thomas Richter is offline  
Old 21 June 2022, 22:41   #8
Asman
68k

Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 797
Quote:
Originally Posted by Csoft View Post
Simply this, with standard Amiga FFS, it keeps spinning forever:

Code:
FILE *fp = fopen(filename, "rb");
    if (fp) {
        fread(dest, sizeof(unsigned char), size, fp);
    } else {
        printf("error: file '%s' not found\n", filename);
    }
    fclose(fp);
What about such code, it still keeps spinning forever ?

Code:
FILE *fp = fopen(filename, "rb");

if (fp)
{
    fread(dest, sizeof(unsigned char), size, fp);
    fclose(fp);
}
else
{
    printf("error: file '%s' not found\n", filename);
}
Furthermore you can also print value from fclose, should be 0.
Asman is offline  
Old 22 June 2022, 15:09   #9
Olaf Barthel
Registered User
 
Join Date: Aug 2010
Location: Germany
Posts: 311
Quote:
Originally Posted by Csoft View Post
Hello all,

I'm developing a game in C, in my code I load assets from floppy with fread/fclose functions, it works, but the floppy keeps spinning even after the load is completed.
Which operating system version are you developing and testing your game on? Are you using timer.device I/O requests in your game? Any chance you might be using a vertical blanking interrupt handler in your game?

It's the job of the file system to tell the floppy disk drive to spin down and give it a rest. This should happen within 3-4 seconds of no file system activity taking place, such as the last read or write operation. Because the file system uses timer.device to schedule periodic tests for activity, accidentally knocking out timer.device processing may cause the spindown never to take place (trackdisk.device does not spin down on its own accord).

Question is whether your game code might be responsible for that.
Olaf Barthel is offline  
Old 22 June 2022, 17:03   #10
Csoft
Registered User

 
Join Date: Apr 2021
Location: Italy
Posts: 10
Quote:
Originally Posted by Olaf Barthel View Post
Which operating system version are you developing and testing your game on? Are you using timer.device I/O requests in your game? Any chance you might be using a vertical blanking interrupt handler in your game?

It's the job of the file system to tell the floppy disk drive to spin down and give it a rest. This should happen within 3-4 seconds of no file system activity taking place, such as the last read or write operation. Because the file system uses timer.device to schedule periodic tests for activity, accidentally knocking out timer.device processing may cause the spindown never to take place (trackdisk.device does not spin down on its own accord).

Question is whether your game code might be responsible for that.
I'm working on 3.0. No use of timer.device, but I DO use a vblank interrupt, yes. Could be this the source of the problem?
Csoft is offline  
Old 22 June 2022, 20:09   #11
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 1,777
If the system timer is not run, yes. What is the return code of your code? Note, in particular, that your code shall return with Z flag set as otherwise the exec interrupt handler assumes that your code handled the interrupt completely, and will not call the remaining system interrupt handlers, including the one of the timer.device.
Thomas Richter is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
(A1200) Chinon FZ-354 Floppy Drive is spinning randomly Sim085 support.Hardware 3 07 January 2022 08:54
CD Spinning Problems spawnerbr support.Hardware 0 21 August 2020 06:46
Standard C libraries? aka fopen,fread,fwrite FirstNE Coders. C/C++ 8 07 August 2020 22:05
Problem with fread while booting game from adf MacSpain Coders. General 5 16 May 2020 11:34
Amiga 500 Panasonic floppy drive only spinning sometimes. h4tt3n support.Hardware 5 24 January 2016 16:20

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:08.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.
Page generated in 0.08964 seconds with 15 queries