English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 18 May 2017, 16:46   #1
majikeyric
Registered User
 
majikeyric's Avatar
 
Join Date: Oct 2015
Location: France
Posts: 82
Using DOS routines after a system take over

Hi!

When the system has been taken over (multi-task stopped, IRQs/DMAS/ADKCON registers modified, blitter owned, user copperlist running...etc.).
What is the minimum requirement to be able to use the DOS open/read/write routines ?

Thanks.
majikeyric is offline  
Old 18 May 2017, 18:51   #2
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,303
as long as you're not tampering with memory you don't own, it should work fine. Not sure about multitask, but calling Forbid & Permit at the proper locations should fix that.

A lot of games use DOS to load files, and don't use the rest of the libraries, but use their own VBL interrupt and hardware banging (using OwnBlitter/DisownBlitter also helps). Also backup system copperlist before overwriting in case you want a chance to return to the OS on exit.
jotd is offline  
Old 18 May 2017, 19:08   #3
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,335
DOS absolutely needs multitask to work and will actually violate Forbid state.
IRQ/DMA probably need to be restored.
User coplist and blitter owned are no problem as long as no system request can be displayed as result of these Dos calls.
meynaf is offline  
Old 18 May 2017, 19:24   #4
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,534
timer.device is the most important (CIA timers = level 2/6 interrupts and vblank). Floppy access of course needs disk DMA, ADKCON floppy bits etc.. (and blitter if KS 1.x). You may get away without timers with some HD controllers..

I recommend to always temporarily restore INTENA properly and free blitter when calling system routines. Only important DMA channel is floppy DMA.
Toni Wilen is online now  
Old 18 May 2017, 19:26   #5
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,344
Set your pr_WindowPtr to -1 to suppress DOS requesters (e.g. read/write error, insert volume ... etc.).
mark_k is offline  
Old 18 May 2017, 20:36   #6
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Have a look at this,
http://eab.abime.net/showthread.php?t=70691
last post has source code that loads a file from floppy while starfield is running.

Hope it helps.
alkis is offline  
Old 01 June 2017, 12:39   #7
majikeyric
Registered User
 
majikeyric's Avatar
 
Join Date: Oct 2015
Location: France
Posts: 82
Thanks all for your information

I have successfully managed to load files using standard dos routines after a system take over by restoring the DMACON, INTENA, ADKCON registers, the IRQs vectors and doing a DisownBlitter().

Last edited by majikeyric; 01 June 2017 at 12:51.
majikeyric is offline  
Old 01 June 2017, 17:02   #8
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,423
Just a quick note here, in my experience the above works fine. But saving files is a different story. There seems to be no way to check if Amiga OS is done writing to a file, so you'd have to guess (as in - wait <x> seconds after the close call returns and hope that was long enough).

Maybe there is a way to do this in a nicer way, but I haven't found one.
roondar is offline  
Old 01 June 2017, 20:32   #9
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
Quote:
Originally Posted by roondar View Post
Maybe there is a way to do this in a nicer way, but I haven't found one.
There is. Write your own disk routines (trackloader). Never use the OS when you have taken over the system. You are calling for problems.
phx is offline  
Old 01 June 2017, 20:53   #10
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,534
So in your opinion whdload should only support floppies?
Toni Wilen is online now  
Old 01 June 2017, 23:26   #11
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,423
Well, a trackloader/saver would be a nice option, but I've not found a good tutorial/example on those yet. That is, I did find several example trackloaders with source but no tracksavers at all.
roondar is offline  
Old 03 June 2017, 00:26   #12
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
Quote:
Originally Posted by Toni Wilen View Post
So in your opinion whdload should only support floppies?
Certainly not. The question was for a nicer way to do it. It doesn't feel nice to me to reanimate the OS after you have taken over everything. Whdload has not much choice, though.

Quote:
Originally Posted by roondar View Post
I did find several example trackloaders with source but no tracksavers at all.
trackdisk.asm from the Solid Gold source (Aminet) can also write to disk (single blocks, and/or format tracks).

When nowadays writing to disks (like high scores, etc.) I would recommend to format a whole track with the data and don't care about read/write errors. Most disks have become so bad that errors are common, and you don't want that they render your game useless.
phx is offline  
Old 03 June 2017, 00:48   #13
Galahad/FLT
Going nowhere
 
Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 9,014
Quote:
Originally Posted by Toni Wilen View Post
So in your opinion whdload should only support floppies?
You do realise WHDLoad performs ram saves whilst the game is running, and when you use the quit key it then writes the files out to hard drive?
Galahad/FLT is offline  
Old 03 June 2017, 02:21   #14
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Quote:
Originally Posted by Galahad/FLT View Post
You do realise WHDLoad performs ram saves whilst the game is running, and when you use the quit key it then writes the files out to hard drive?
I had been thinking for a way to save high scores on my HD installable versions and this was the only solution I could come up with also. Short of making the game system friendly....
alpine9000 is offline  
Old 03 June 2017, 18:56   #15
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,423
Quote:
Originally Posted by phx View Post
trackdisk.asm from the Solid Gold source (Aminet) can also write to disk (single blocks, and/or format tracks).

When nowadays writing to disks (like high scores, etc.) I would recommend to format a whole track with the data and don't care about read/write errors. Most disks have become so bad that errors are common, and you don't want that they render your game useless.
I'll definitely check that out, thanks!
roondar is offline  
Old 03 June 2017, 19:33   #16
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
Quote:
Originally Posted by roondar View Post
There seems to be no way to check if Amiga OS is done writing to a file, so you'd have to guess (as in - wait <x> seconds after the close call returns and hope that was long enough).

Maybe there is a way to do this in a nicer way, but I haven't found one.
I don't get it. What does mean there seems to be no way to check if OS done writing to a file ? I don't see where is the problem. Could you explain a bit more. Thank you.
Asman is offline  
Old 03 June 2017, 19:52   #17
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,423
Quote:
Originally Posted by Asman View Post
I don't get it. What does mean there seems to be no way to check if OS done writing to a file ? I don't see where is the problem. Could you explain a bit more. Thank you.
It means that you can write to a file, tell the operating system you are done but the OS is still writing after that and won't tell you when it's done. So effectively, your program can't know when the OS is done writing to disk and a program would have to guess.

Which can mean guessing a too short delay and losing the file or corrupting the disk

On other operating systems, you can usually force the OS to finish writing to disk before telling you it's done with the file, not on the Amiga - its OS assumes you'll be running under multitasking all the time and therefore don't need to know that the OS is still busy writing.

As phx rightly said, trying to work around that is messy and not something that one should really do (and I'll admit being guilty immediately, never to old to learn and all that!)
roondar is offline  
Old 03 June 2017, 20:57   #18
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 828
Thanks roondar for explanation. But with your approach (OS is still writting after I am done) you will never known (mean your program which call Write for example ) if there was an error during writting. If I use Write from dos.library then this function will return how many bytes were written. Of course I must wait till floppy motor will be off after read/write, but there is no guessing - 2 seconds should be enough. If I am wrong then please correct me.
Asman is offline  
Old 03 June 2017, 21:07   #19
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,423
Quote:
Originally Posted by Asman View Post
Thanks roondar for explanation. But with your approach (OS is still writting after I am done) you will never known (mean your program which call Write for example ) if there was an error during writting. If I use Write from dos.library then this function will return how many bytes were written. Of course I must wait till floppy motor will be off after read/write, but there is no guessing - 2 seconds should be enough. If I am wrong then please correct me.
Ah, sadly you are wrong. The Write call will return before all bytes are actually written (it will return when the given bytes are all in the write buffer, which is not the same). You can even see that the OS returns prior to finishing when you save a file in an OS legal program. These almost always give you control back before disk activity is finished.

And you can't use the floppy motor as indicator either, because the OS sometimes turns it off and then on again during writing (I've noticed this many times).

Which is why waiting a longer time is often used. And usually, that works - but you can't guarantee it. I've had test programs cause corrupted disks this way more than once.
roondar is offline  
Old 03 June 2017, 21:21   #20
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,534
Write will return quickly (may even return practically instantly) if used filesystem and/or device driver has write buffers that are flushed later.

Sending ACTION_FLUSH directly to filesystem should force write buffer flush but I don't know if all filesystems support it. And even if it worked, there is still device driver layer that may ignore any flush attempts (CMD_UPDATE should do it)..
Toni Wilen is online now  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cd32 audio read routines using hardware jotd Coders. Asm / Hardware 40 23 January 2024 18:07
decompression routines Toni Wilen Coders. General 12 17 May 2017 00:30
Using System DOS commands within SAS-C Zetr0 Coders. System 5 23 April 2017 18:14
OSTER's assembler routines & tricks Shoonay Coders. Tutorials 8 17 November 2016 15:41
Checksum routines in games Joejoe Coders. Tutorials 11 26 December 2009 20:24

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 20:37.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09795 seconds with 13 queries