Disk rom routine 4010H (DISKIO) behaviour

Page 2/2
1 |

By sd_snatcher

Prophet (3448)

sd_snatcher's picture

11-02-2021, 13:14

snake wrote:

Thank you all for help. Target of the project are all Msx 2 (64 kb ram, no memory mapper, no Dos2).

Why not just make a normal MSX-DOS App with separate files then? It would make everyone's life easier: It would be HDD installable, and no floppy emulation would be necessary.

By zeilemaker54

Champion (298)

zeilemaker54's picture

11-02-2021, 17:05

ro wrote:

Hai Arjan, good to "see" you again Smile

I am a regular vistor of msx.org, so you should be able to 'see' me here often Cool

By konamiman

Paragon (1119)

konamiman's picture

12-02-2021, 16:46

As a general rule, DSKIO and all the other DiskROM routines aren't designed to be called directly by user programs, but only by the MSX-DOS kernel, which is already aware of all the shenanigans/context needed for doing such calls.

Have you considered using the BIOS routine PHYDIO instead (https://github.com/Konamiman/MSX2-Technical-Handbook/blob/ma...)? This is how user code is supposed to directly interact with disk sectors (other than using MSX-DOS function calls, which I don't think would be the best route for ROM code).

By snake

Resident (51)

snake's picture

16-02-2021, 09:50

THANK YOU ALL FOR HELP AND SUGGESTIONS

Yes, i got it. The area from HIMEM to F380h is the reserved ram for floppy drives. Of course, disk rom too relies on it. If no drive is installed, HIMEM points directly to F380.

Now i have endless spinning issues with Philips disk rom. I have to shut down the drive manually (401F disk rom routine), but on the real thing (my Philips 8245), if i attempt to read again from disk after a 401F call, the drive always gives error, and works again only after a further reading attempt.

I must do other experiments. I want to try to use memory over HIMEM (i have to look for documentation). I will post working code.

Unfortunately 144H doesn't work. I suppose it's even more picky than 4010H. And my target environment is my plain and gorgeous 8245 (only Fm Pac is allowed as upgrade) Smile

By NYYRIKKI

Enlighted (5745)

NYYRIKKI's picture

16-02-2021, 11:03

snake wrote:

I have to shut down the drive manually (401F disk rom routine), but on the real thing (my Philips 8245), if i attempt to read again from disk after a 401F call, the drive always gives error, and works again only after a further reading attempt.

Yeah, don't do that... I remember trying that my self and it ended up with pretty complete mayhem. Yes, ok, it did stop the floppy ok, but it also did spin down my HDD. (did not start again before complete reboot) On the left side of my computer the rapidly ejecting Zip-disk noise stole my attention while on the right side CD-ROM tray silently pushed my coffee mug to the floor. I did not feel too happy about the end result.

Instead make sure you don't mess up the interrupt handlers. If you want to make your own interrupt handler, please make sure to take a backup copy of the existing one and execute it after your own code is done.

By snake

Resident (51)

snake's picture

17-02-2021, 14:40

NYYRIKKI wrote:

Yeah, don't do that... I remember trying that my self and it ended up with pretty complete mayhem. Yes, ok, it did stop the floppy ok, but it also did spin down my HDD. (did not start again before complete reboot) On the left side of my computer the rapidly ejecting Zip-disk noise stole my attention while on the right side CD-ROM tray silently pushed my coffee mug to the floor. I did not feel too happy about the end result.

I have found these discussions about disk stop:

https://www.msx.org/forum/development/msx-development/fd9f-i...
https://www.msx.org/forum/msx-talk/development/accessing-dis...

I think the routine that crashed your coffee cup is 4029 :D
401F should affect only disk drives managed by the disk rom currently mounted on page 1; on certain machines it's called by the interrupt after a few time since the last disk access, but i hooked the interrupt directly, so i have to call 401F manually.

By NYYRIKKI

Enlighted (5745)

NYYRIKKI's picture

17-02-2021, 22:41

snake wrote:

I think the routine that crashed your coffee cup is 4029 Big smile

Ah, indeed, I remembered wrong.

Quote:

401F should affect only disk drives managed by the disk rom currently mounted on page 1; on certain machines it's called by the interrupt after a few time since the last disk access, but i hooked the interrupt directly, so i have to call 401F manually.

I guess that is ok... Some times I have just used some "Press any key to start" to make sure disk drive is stopped before I kill the interrupt system... Can naturally be something like logo animation etc. as well... Not very helpful idea though if you plan to load in multiple parts.

By snake

Resident (51)

snake's picture

26-02-2021, 20:49

Finally, my ugly code to use 4010H with SDCC, tested on several Sony Msx 2 and 2+ (emulated), Turbo-R ST (real thing), NMS 8245 (real thing). It's provided without warranty. I'm not responsable if your cup of tea falls over your powered-on Turbo-R GT Smile

// input values:

volatile char * diskio_buffer; // memory buffer (* see remarks)
volatile char diskio_drive; // 0: a, 1: b
volatile unsigned char diskio_media; // 248: 360 kb; 249: 720 kb. (* see remarks)
volatile unsigned short diskio_start; // start sector
volatile char diskio_number; // number of sectors to read/write
volatile char diskio_operation; // 0: read; 1: write

// output values:

volatile char diskio_result; // 0: success; 1: error.

void diskio () __naked {
__asm__ ("push af"); __asm__ ("push bc"); __asm__ ("push de"); // save registers
__asm__ ("push hl"); __asm__ ("push ix"); __asm__ ("push iy");

__asm__ ("ld hl,(_diskio_start)"); __asm__ ("ld d,h"); __asm__ ("ld e,l"); // de: start sector
__asm__ ("ld hl,(_diskio_buffer)"); // hl: buffer
__asm__ ("ld a,(_diskio_number)"); __asm__ ("ld b,a"); // b: number of sectors
__asm__ ("ld a,(_diskio_media)"); __asm__ ("ld c,a"); // c: floppy size
__asm__ ("ld a,(_diskio_operation)"); __asm__ ("neg"); // carry flag: operation
__asm__ ("ld a,(_diskio_drive)");
__asm__ ("call #16400"); // 4010h routine
__asm__ ("push af"); __asm__ ("pop bc"); // result on carry flag (0: ok, 1: error)
__asm__ ("ld a,c"); __asm__ ("and #1"); __asm__ ("ld (_diskio_result),a");

__asm__ ("pop iy"); __asm__ ("pop ix"); __asm__ ("pop hl"); // restore registers
__asm__ ("pop de"); __asm__ ("pop bc"); __asm__ ("pop af");
__asm__ ("ret");
}

// to stop motors
void diskstop () __naked { __asm__ ("call #16415"); __asm__ ("ret"); }

Remarks:

Disk rom must be mounted on page 1 and interrupt disabled. Interrupt can be hooked directly at 38H address.

1 sector = 512 byte (your data must be padded if not 512 or multiple)

Depending on machines, you have to stop drive motors after the end of operations, or warm them with a dumb reading of sector 0 before the beginning. So, always do that to improve compatibility (it doesn't harm).

Memory buffer must be between 32768 and the beginning of disk system variables (F197/61847); this worked on all machines i tested, however officially is HIMEM (a lot lower). Don't overwrite code and stack.

If disc size is unknown, you can read the code from byte 21 of sector 0. You can read sector 0 by using 248 as media code (it works on 720 kb floppies too).

Page 2/2
1 |