19 June 2022, 14:52 | #1 |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
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 |
19 June 2022, 15:41 | #2 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
Are you shutting down the system after loading files or stopping multitasking with Forbid?
|
19 June 2022, 15:55 | #3 |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
|
19 June 2022, 19:28 | #4 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
|
what's the flow?
fopen/fread/fclose? (c library) Open/Read/Close? (OS) |
21 June 2022, 17:36 | #5 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Is it some strange file system? Or standard FFS? Note, that a running motor for a few seconds after the last access is normal. |
|
21 June 2022, 21:52 | #6 | |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
Quote:
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); |
|
21 June 2022, 22:31 | #7 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
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.
|
21 June 2022, 22:41 | #8 | |
68k
Join Date: Sep 2005
Location: Somewhere
Posts: 828
|
Quote:
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); } |
|
22 June 2022, 15:09 | #9 | |
Registered User
Join Date: Aug 2010
Location: Germany
Posts: 532
|
Quote:
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. |
|
22 June 2022, 17:03 | #10 | |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
Quote:
|
|
22 June 2022, 20:09 | #11 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
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.
|
30 August 2022, 23:11 | #12 | |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
Quote:
Read everything I must read from disk. Wait for 5 seconds. The floppy stops to spin. After 5 seconds I install the CIA interrupt and the floppy restarts to spin!!! I'm using FS-Uae. |
|
31 August 2022, 10:04 | #13 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
Assuming the emulator isn't faulty, I'd say your CIA ISR setup is (wrongly) messing with some CIA registers which then causes the floppy to turn on.
|
31 August 2022, 10:21 | #14 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
Quote:
In short: You cannot "partially" stop AmigaOs. Use the Os, dude! |
|
31 August 2022, 11:47 | #15 | |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
Quote:
This problem persists even if I don't disable the OS at all. Probabily is the ptplayer routine which do some mess with CIA, I'll check it. |
|
31 August 2022, 13:02 | #16 | |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
Quote:
1) I do NOT call Forbid() anymore. 2) I do NOT install my VBlank 3) I do NOT install CIA interrupt (ptplayer) 3) After all disk read I wait 10 seconds and the spin stops. I found the source of the problem: 4) The first time I play a sound the spin sound restarts!!!!!!! This happens on both FS-Uae and Winuae, so I think it's not an emulator related issue. |
|
31 August 2022, 14:32 | #17 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
Paula is unrelated to the floppy motor control, which is in the hands of CIA, resp. the trackdisk.device controlling CIA. Thus, if this is related to playing sounds, probably something is wrong with your player function.
|
31 August 2022, 14:44 | #18 | |
Registered User
Join Date: Apr 2021
Location: Italy
Posts: 21
|
Quote:
Code:
UWORD audioDmaBits[] = { DMAF_AUD0, DMAF_AUD1, DMAF_AUD2, DMAF_AUD3 }; /** * @brief Play the sound * * Period = 1 / (samplerate * 2,81937 * 10^-7) * * @param sound * @param period * @param volume * @param audiochannel */ void playsound(sound* sound,UWORD period,UWORD volume,USHORT audiochannel) { if (!mt_Enable) { // Stop audiochannel's DMA in case there is an already playing sound in the audiochannel custom.dmacon = audioDmaBits[audiochannel]; custom.aud[audiochannel].ac_ptr = sound->sampledata; custom.aud[audiochannel].ac_len = sound->size; custom.aud[audiochannel].ac_per = period; custom.aud[audiochannel].ac_vol = volume; custom.dmacon = DMAF_SETCLR | audioDmaBits[audiochannel]; // Start sound playback } // The following is called if I'm using ptplayer, which have its own playback facilities // the problem IS present even in this case else { SfxStructure pt_sound; pt_sound.sfx_ptr = sound->sampledata; pt_sound.sfx_len = sound->size; pt_sound.sfx_per = period; pt_sound.sfx_vol = volume; pt_sound.sfx_cha = audiochannel; pt_sound.sfx_pri = 127; mt_playfx(&custom,&pt_sound); } } |
|
31 August 2022, 15:26 | #19 |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
When the floppy spin sound restarts, does the floppy light onscreen turn on with the sound or does it stay off?
|
31 August 2022, 19:09 | #20 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,038
|
audioChannel is 0-3 and audioDmaBits is { 1, 2, 4, 8 }?
|
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 |
|
|