diff --git a/.gitignore b/.gitignore index e5fb2f49..7e768cef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ syntax: glob .vs/ +.vscode/ bin/** *.sym *.SYM diff --git a/docs/DRIVER.ASM b/docs/DRIVER.ASM index 3daaf7ec..07b7ec05 100644 --- a/docs/DRIVER.ASM +++ b/docs/DRIVER.ASM @@ -1,4 +1,4 @@ - ; Dummy disk driver for Nextor 2.0 + ; Dummy disk driver for Nextor 2.1 ; By Konamiman, 8/2018 ; ; This code can be used as the basis for developing @@ -21,7 +21,7 @@ DRV_START: ;This is a 2 byte buffer to store the address of code to be executed. ;It is used by some of the kernel page 0 routines. -CODE_ADD: equ 0F84Ch +CODE_ADD: equ 0F1D0h ;----------------------------------------------------------------------------- diff --git a/docs/Nextor 2.1 Driver Development Guide.md b/docs/Nextor 2.1 Driver Development Guide.md index b32343d2..62e63ae0 100644 --- a/docs/Nextor 2.1 Driver Development Guide.md +++ b/docs/Nextor 2.1 Driver Development Guide.md @@ -102,7 +102,9 @@ [5. Change history](#5-change-history) -[5.1. v2.1.0 beta 1](#51-v210-beta-1) +[5.1. v2.1.0 beta 2](#51-v210-beta-2) + +[5.2. v2.1.0 beta 1](#52-v210-beta-1) ## 1. Introduction @@ -428,7 +430,7 @@ Input: Address of code to invoke in (CODE_ADD). Output: AF, BC, DE, HL, IX, IY returned from the called routine. ``` -Note: the address of CODE_ADD is F84Ch. +Note: the address of CODE_ADD is F1D0h. #### 4.2.4. CALBNK (4042h) @@ -611,13 +613,13 @@ Please note also the following: #### 4.4.4. DRV_BASSTAT (4139h) -This is the entry for the BASIC extended statements ("CALLs") handler. It works the same way as the standard handlers (see _MSX2 Technical Handbook_, chapter 2, for details), except that if the handled statements have parameters, the MSX BIOS routine CALBAS (needed to invoke the MSX BASIC interpreter helper routines) can't be used directly; instead, it must be invoked via the CALLB0 entry in kernel page 0. +This is the entry for the BASIC extended statements ("CALLs") handler. It works the same way as the standard handlers (see [MSX2 Technical Handbook, chapter 2](https://github.com/Konamiman/MSX2-Technical-Handbook/blob/master/md/Chapter2.md), for details), except that if the handled statements have parameters, the MSX BIOS routine CALBAS (needed to invoke the MSX BASIC interpreter helper routines) can't be used directly; instead, it must be invoked via [the CALLB0 entry](#423-callb0-403fh) in kernel page 0. If the driver does not handle BASIC extended statements, it must simply set the carry flag and return. #### 4.4.5. DRV_BASDEV (413Ch) -This is the entry for the BASIC extended devices handler. It works the same way as the standard handlers (see _MSX2 Technical Handbook_, chapter 2, for details), but see the note on DRV_BASSTAT about CALBAS. +This is the entry for the BASIC extended devices handler. It works the same way as the standard handlers (see [MSX2 Technical Handbook, chapter 2](https://github.com/Konamiman/MSX2-Technical-Handbook/blob/master/md/Chapter2.md), for details), but see the note about CALBAS on [DRV_BASSTAT](#444-drv_basstat-4139h). If the driver does not handle BASIC extended devices, it must simply set the carry flag and return. @@ -1018,6 +1020,12 @@ This section contains the change history for the different versions of Nextor. O This list contains the changes for the 2.1 branch only. For the change history of the 2.0 branch see the _[Nextor 2.0 Driver Development Guide](../../../blob/v2.0/docs/Nextor%202.0%20Driver%20Development%20Guide.md#5-change-history)_ document. -### 5.1. v2.1 beta 1 +### 5.1. v2.1.0 beta 2 + +- **BREAKING CHANGE:** The address of CODE_ADD, used by [the CALLB0 routine](#423-callb0-403fh), has changed to F1D0h (it was F84Ch). + +- Fix: there was Nextor kernel code in the 1K free area in pages 0 and 3, so putting anything here caused problems, e.g. DOS 1 mode didn't work. + +### 5.2. v2.1.0 beta 1 Added the "User is requesting reduced drive count" flag to the input of [the DRV_INIT routine](#443-drv_init-4136h) and [the DRV_CONFIG routine](#448-drv_config-4151h). diff --git a/docs/Nextor 2.1 Getting Started Guide.md b/docs/Nextor 2.1 Getting Started Guide.md index ca551c83..940b2759 100644 --- a/docs/Nextor 2.1 Getting Started Guide.md +++ b/docs/Nextor 2.1 Getting Started Guide.md @@ -1,4 +1,4 @@ -# Nextor 2.0 Getting Started Guide +# Nextor 2.1 Getting Started Guide ## Index @@ -39,11 +39,11 @@ Note: in this guide the following Nextor tools will be used: MAPDRV.COM, LOCK.CO This section explains the steps needed to setup blueMSX in order to follow this guide. The blueMSX emulator can be downloaded at http://www.bluemsx.com. -a. Download the following files from [Konamiman's MSX page](https://www.konamiman.com/msx/msx-e.html#nextor): +a. Download the following files from [the lastest release of Nextor in GitHub](https://github.com/Konamiman/Nextor/releases/latest): -* Nextor kernel with Sunrise IDE driver. +* Nextor kernel with Sunrise IDE driver. Please choose the file with _.SunriseIDE.emulators.ROM_ extension (the _.SunriseIDE.ROM_ version works but only recgonizes the slave IDE device in emulators). -* Nextor tools disk image +* Nextor tools disk image (_tools.dsk.zip_). b. Run blueMSX and select the _Tools - Machine Editor_ menu. @@ -67,15 +67,15 @@ Now you have an emulated MSX2 with a Sunrise IDE controller that has the Nextor If you want to follow the steps of this guide by using a real MSX computer with a Sunrise IDE controller and a floppy disk drive instead of an emulator, you will need to do the following: -* Download the Nextor kernel with Sunrise IDE driver. +* Download the Nextor kernel with Sunrise IDE driver (the file with extension _.SunriseIDE.ROM_). * Copy the NEXTOR.SYS and COMMAND2.COM files and the Nextor tools to a floppy disk. You have two options: * Download the Nextor tools disk image file and transfer its contents to a floppy disk. - * Download the Nextor tools LZH file and uncompress it to a floppy disk, together with the NEXTOR.SYS and COMMAND2.COM files. + * Download the Nextor tools ZIP file (_tools.zip_) and uncompress it to a floppy disk, together with the NEXTOR.SYS and COMMAND2.COM files. -Note: The Nextor kernel, NEXTOR.SYS and the Nextor tools are available at [Konamiman's MSX page](https://www.konamiman.com/msx/msx-e.html#nextor). +Note: The Nextor kernel, NEXTOR.SYS and the Nextor tools are available as assets in [the lastest release of Nextor in GitHub](https://github.com/Konamiman/Nextor/releases/latest). * Copy the MSXDOS.SYS and COMMAND.COM files to the floppy disk, these are necessary for the steps that involve booting in MSX-DOS 1 mode. These files are included in the Nextor tools disk image file, but can be found on other places on Internet too (search for "MSXDOS.SYS" on any search engine). @@ -92,7 +92,9 @@ a. Boot your MSX. You will see that you boot in the COMMAND2 prompt in drive B:, ![](img/gsg/NextorPrompt.png) -***What has happened?*** Nextor has assigned one drive to the Sunrise IDE driver (A:) and two drives to the floppy disk drive (B: and C:). Then it has attempted to search a suitable FAT12 or FAT16 partition in the attached hard disk in order to assign it to drive A:, but since the hard disk has no partitions yet, drive A: has been left unassigned. Drive B:, assigned to the floppy disk, is the first valid drive, and so it is used as the boot drive. +***What has happened?*** Nextor has assigned one drive to the Sunrise IDE driver (A:) and one drive to the floppy disk drive (B:). Then it has attempted to search a suitable FAT12 or FAT16 partition in the attached hard disk in order to assign it to drive A:, but since the hard disk has no partitions yet, drive A: has been left unassigned. Drive B:, assigned to the floppy disk, is the first valid drive, and so it is used as the boot drive. + +**Note:** You may be wondering why the floppy disk drive gets only one drive letter assigned, and not two as usual. That's because by default Nextor inverts the behavior of the CTRL key at boot time. There's a way to customize this, see ["Boot key inverters" in the Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md#291-boot-key-inverters). b. Type BASIC and then CALL FDISK to invoke the device partitioning tool. @@ -112,6 +114,8 @@ j. Press "S" to see the defined partitions. You should see four partitions, as i ![](img/gsg/FourPartitionsList.png) +Note: the asterisk "*" next to the partition number means that the partition will be created with the "active" flag set in the partition table. We'll see what this implies in next section. + k. Press ESC to return to the main menu, then press "W" to create the partitions on the disk. Press "y" on the data destroy warning prompt. l. Reset your MSX. You will see that the computer boots in the BASIC prompt. @@ -150,13 +154,21 @@ COPY NEXTOR.SYS D: COPY COMMAND2.COM D: ``` -d. Create an empty file named NEXTOR.DAT in drive D:. You can achieve this by executing a `COPY CON D:NEXTOR.DAT` command, then pressing CTRL+Z, then pressing Enter. +d. Type BASIC and then CALL FDISK to invoke the device partitioning tool. + +e. Press "1" to select the Sunrise IDE driver, then "1" again to select the hard disk, then "1" again to select the first logical unit, then "S" to show the partitions list. + +f. Press "1" and then "y" to remove the "active" flag from the first partition in the partition table. -e. Reset your MSX, and when you are in the COMMAND2 prompt, perform a DIR command and check that this time drive A: is assigned to the second (25MB big) partition: +g. Press "2" and then "y" to set the "active" flag for the second partition in the partition table. + +h. Reset your MSX, and when you are in the COMMAND2 prompt, perform a DIR command and check that this time drive A: is assigned to the second (25MB big) partition: ![](img/gsg/DirWithNextorDat.png) -***What has happened?*** When performing the automatic drive to device and partition mapping assignment at boot time, Nextor normally selects the first valid (FAT12 or FAT16) partition available. But if there are partitions with a file named "NEXTOR.DAT" in the root directory, then these partition have preference in the assignment process. The contents of the NEXTOR.DAT file are irrelevant in this version of Nextor. +***What has happened?*** When performing the automatic drive to device and partition mapping assignment at boot time, Nextor selects the first valid (FAT12 or FAT16) partition available that has the "active" flag set in the partition table. You can set and reset this flag for any of the first 9 partitions in the device using FDISK (either partitions that you are creating, or already existing partitions). + +If none of the existing partitions has the "active" flag set in the partition table, then the first suitable partition found will be mapped. We'll see this in the next section. ## 5. Booting in MSX-DOS 1 mode @@ -187,21 +199,23 @@ e. Map partition 4 to drive D: by executing the following: B:MAPDRV D: 4 1 1 -f. Copy the MSX-DOS 1 system files to drive D: as you did in step b, then create an empty NEXTOR.DAT file in drive D: as you did in the previous section. +f. Copy the MSX-DOS 1 system files to drive D: as you did in step b + +g. Go to BASIC, run FDISK and go to the partitions list for the first device, as you did in the previous section. This time set the "active" flag for partition 4. You should see that both partitions 2 and 4 are active now: -g. Boot the computer while keeping pressed the "1" key. You will boot in MSX-DOS 1 mode and in the COMMAND.COM prompt again. Issue a DIR command and you should see the following (notice the 9M free space): +![](img/gsg/Partitions2And4Active.png) + +h. Boot the computer while keeping pressed the "1" key. You will boot in MSX-DOS 1 mode and in the COMMAND.COM prompt again. Issue a DIR command and you should see the following (notice the 9M free space): ![](img/gsg/DirInDos1ModeWithNextorDat.png) -***What has happened?*** The rule "give priority to partitions holding a file named NEXTOR.DAT at the root directory during the automatic drive to device and partition assignment at boot time" is valid when booting in MSX-DOS 1 mode too, but this time only the MSX-DOS 1 compatible partitions are checked (partitions 3 and 4 in this case, being partition 4 the "winner" partition). +***What has happened?*** The rule "give priority to partitions having the 'active' flag set during the automatic drive to device and partition assignment at boot time" is valid when booting in MSX-DOS 1 mode too, but this time only the MSX-DOS 1 compatible partitions are checked (partitions 3 and 4 in this case, being partition 4 the "winner" partition). The remaining steps will leave the environment ready for the next section. -h. Boot the computer in normal mode. - -i. You should have booted with partition 2 (the one 25M big) mapped to drive A:. If so, simply delete the NEXTOR.DAT file in that drive (`DEL NEXTOR.DAT`). If not, map partition 2 to drive D: (`B:MAPDRV D: 2 1 1`) and then delete the file (`DEL D:NEXTOR.DAT`). +i. Boot the computer in normal mode. -j. Map partition 4 to drive D: and then delete the NEXTOR.DAT file. +j. Go to BASIC, run FDISK and reset the "active" flag of both partitions 2 and 4, so that none of the partitions has the flag set. ## 6. Using a second storage device @@ -213,63 +227,69 @@ a. Select the _File - Hard Disk - IDE Sunrise Secondary - Insert New Disk Image_ b. Reset the computer, go to BASIC and invoke the device partitioning tool with CALL FDISK. -c. Partition the device as you did in [3. Booting and creating partitions](#3-booting-and-creating-partitions). This time, however, you should select device 2 in the device selection screen; and you should create just two partitions, the first one having a size of 85M and the second one of 15M. +c. Partition the device as you did in [3. Booting and creating partitions](#3-booting-and-creating-partitions). This time, however, you should select device 2 in the device selection screen; and you should create just two partitions, the first one having a size of 85M and the second one of 15M. Also, please remove the "active" flag from the first partition (you can do this either before or after writing the partitions in the device). d. Reset the computer. Once in the COMMAND2 prompt, issue a _DIR_ command and check that drive A: has 50M free. Then issue a _DIR B:_ command and check that drive B: has 85M free (again, please be patient, especially with the second DIR command): ![](img/gsg/DirAAndDirB.png) -***What has happened?*** This time, Nextor has assigned two drives (A: and B:) to the Sunrise IDE driver, since two devices have been detected; the floppy disk controller has now drives C: and D: assigned. At boot time, Nextor assigns as many drives as devices are available to each controller (for device-based controllers only; see the _[Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md)_ for details about the controller types). +***What has happened?*** This time, Nextor has assigned two drives (A: and B:) to the Sunrise IDE driver, since two devices have been detected; the floppy disk controller has now drive C: assigned. At boot time, Nextor assigns as many drives as devices are available to each controller (for device-based controllers only; see the _[Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md)_ for details about the controller types). Drive A: has been mapped to the first available partition on the first available device, as usual. However, once this has been done, Nextor has searched for more suitable partitions on additional devices to be mapped to drive B:. So drive A: is mapped to the first partition in the master device (50M big) and drive B: is mapped to the first partition in the slave device (85M big). -e. Create an empty NEXTOR.DAT file in drive B:. Also, copy the NEXTOR.SYS and COMMAND2.COM files to drive B:. +e. Copy the NEXTOR.SYS and COMMAND2.COM files to drive B:. + +f. Go to BASIC, run FDISK and set the "active" flag of partition 1 (85M) in the device with number 2. -f. Reset your computer and issue a _DIR_ command, then a _DIR B:_ command. Notice that the mapping is reversed relative to the previous case (A: is mapped to the 85M partition on slave device, B: is mapped to the 50M partition on master device): +g. Reset your computer and issue a _DIR_ command, then a _DIR B:_ command. Notice that the mapping is reversed relative to the previous case (A: is mapped to the 85M partition on slave device, B: is mapped to the 50M partition on master device): ![](img/gsg/DirAAndDirBWithFiles.png) -***What has happened?*** The rule "give priority to partitions holding a file named NEXTOR.DAT at the root directory during the automatic drive to device and partition assignment at boot time" applies to all partitions on all devices, not only to the first device. Taking in account both the master and the slave devices, the only partition having a NEXTOR.DAT file is the first partition on the slave device, and therefore this one is assigned to drive A:. After this is done, other devices are scanned for a partition to be mapped to drive B:; in this case the only "other device" available is the master device, and thus its first partition is mapped to drive B:. +***What has happened?*** The rule "give priority to partitions having the 'active' flag set during the automatic drive to device and partition assignment at boot time" applies to all partitions on all devices, not only to the first device. Taking in account both the master and the slave devices, the only partition having the 'active' flag set is the first partition on the slave device, and therefore this one is assigned to drive A:. After this is done, other devices are scanned for a partition to be mapped to drive B:; in this case the only "other device" available is the master device, and thus its first partition is mapped to drive B:. -g. Map partition 2 of slave device to drive B: (`C:MAPDRV B: 2 2 1`). Copy the MSXDOS.SYS and COMMAND.COM files to drive B:. +h. Map partition 2 of slave device to drive B: (`C:MAPDRV B: 2 2 1`). Copy the MSXDOS.SYS and COMMAND.COM files to drive B: (remember the floppy holding these files is now mapped in C:). -h. Reset the computer while keeping pressed the "1" key. You will boot in MSX-DOS 1 mode and in the `COMMAND.COM` prompt. Issue a `DIR` command, then a `DIR B:` command. Notice that in the first case you get 16M of free space, and in the second case you get 15M: +i. Reset the computer while keeping pressed the "1" key. You will boot in MSX-DOS 1 mode and in the `COMMAND.COM` prompt. Issue a `DIR` command, then a `DIR B:` command. Notice that in the first case you get 16M of free space, and in the second case you get 15M: ![](img/gsg/DirAAndDirBDos1Mode.png) ***What has happened?*** Drive A: has been mapped to the first available partition on the master device, and drive B: has been mapped to the first available partition on the slave device, as in the previous case. However, this time only the MSX-DOS 1 compatible partitions have been taken in account. These are partitions 3 and 4 in the master device (partition 3, 16M big, is selected) and partition 2 in the slave device (15M big). -i. Create an empty NEXTOR.DAT file in drive B:. +j. Go to BASIC, run FDISK and set the "active" flag of partition 2 (15M) in the device with number 2. -j. Reset the computer while keeping pressed the "1" key. You will boot in MSX-DOS 1 mode and in the `COMMAND.COM` prompt. Issue a `DIR` command, then a `DIR B:` command. Notice that the mapping is reversed relative to the previous case (A: is mapped to the 15M partition on slave device, B: is mapped to the 16M partition on master device): +k. Reset the computer while keeping pressed the "1" key. You will boot in MSX-DOS 1 mode and in the `COMMAND.COM` prompt. Issue a `DIR` command, then a `DIR B:` command. Notice that the mapping is reversed relative to the previous case (A: is mapped to the 15M partition on slave device, B: is mapped to the 16M partition on master device): ![](img/gsg/DirAAndDirBDos1ModeWithNextorDat.png) -***What has happened?*** You should have guessed it already: both devices have been scanned for partitions, only the MSX-DOS 1 partitions have been taken in account, and the partition having a NEXTOR.DAT file has been given priority in the mapping process and thus it has been mapped to drive A:. +***What has happened?*** You should have guessed it already: both devices have been scanned for partitions, only the MSX-DOS 1 partitions have been taken in account, and the partition having the "active" flag set has been given priority in the mapping process and thus it has been mapped to drive A:. -k. Delete the NEXTOR.DAT from drive A:. Reset your computer in normal mode, delete the NEXTOR.DAT from drive A: again, and reset once more. You should be in the COMMAND2 prompt and have the 50M partition mapped to drive A:. +l. Go to BASIC, run FDISK and reset the "active" flag from all partitions having it set in both devices. + +m. Reset your computer in normal mode, you should be in the COMMAND2 prompt and have the 50M partition mapped to drive A:. ## 7. Locking drives In this section we'll try the drive lock feature. -a. Execute the following command: `C:LOCK C: ON` +a. Create a small text file in the tools floppy disk. You can do that by executing `COPY CON C:TEST`, then writing something, then pressing CTRL+Z. + +b. Execute the following command: `C:LOCK C: ON` -b. Issue a `DIR C:` command. You will see a directory listing of the Nextor tools floppy disk. +c. Execute the following: `TYPE C:TEST`. You will see the contents of the text file you just created. -c. Remove the floppy disk from the drive (if you are using blueMSX, select the `File - Disk Drive A - Eject: nextor.dsk` menu option). +d. Remove the floppy disk from the drive (if you are using blueMSX, select the `File - Disk Drive A - Eject: nextor.dsk` menu option). -d. Issue a `DIR C:` command again. You will see the same directory listing again instead of getting a "Not Ready" error, even though the disk has been removed from the drive. +e. Execute `TYPE C:TEST` again. You will see the file contents again instead of getting a "Not Ready" error, even though the disk has been removed from the drive. ***What has happened?*** Whenever Nextor is about to access the contents of a drive (and the drive is not mapped to a fixed device on a device-based driver), it first asks the driver if the associated storage media has changed. If the answer is "Yes" or "Not sure", then it takes the appropriate actions: for devices on a device-based driver, it assigns the first available partition on the device to the drive; for other drivers (MSX-DOS legacy drivers and drive-based drivers), it simply clears sector buffers and creates again the disk parameters block for the drive. (The "Not sure" response gets actually a special treatment; see the Nextor user manual for more details) When a drive is locked, Nextor will never ask the driver for device change status when accessing that drive, and will instead assume that the device will never change. This improves performance as it saves both CPU processing and device access. -In this case, we have locked the floppy disk drive, whose change status would otherwise be checked on each disk access (floppy disk drives usually report a change status of "Not sure" always). When issuing the second DIR command, Nextor assumes that the disk has not changed, and since it still has the directory and FAT sectors cached in memory, it can display the disk contents even if the disk has been removed from the drive. +In this case, we have locked the floppy disk drive, whose change status would otherwise be checked on each disk access (floppy disk drives usually report a change status of "Not sure" always). When displaying the file contents the second time, Nextor assumes that the disk has not changed, and since it still has the file contents sector cached in memory, it can display it even if the disk has been removed from the drive. -Nextor will clear then cached sector for a drive at the moment of locking it, therefore if you had reversed the order of steps a and b you would have effectively got a "Not Ready" error. +Nextor will clear the cached sector for a drive at the moment of locking it, therefore if you had reversed the order of steps b and c you would have effectively got a "Not Ready" error. -e. Insert the Nextor tools floppy disk in its drive again. +f. Insert the Nextor tools floppy disk in its drive again. ## 8. The reduced/zero allocation information mode @@ -302,8 +322,6 @@ f. Issue again the `DIR` and `DIR B:` commands. Notice that this time the free s ***What has happened?*** When an environment item named ZALLOC exists and has the value ON (case insensitive), the reduced allocation information mode becomes the zero allocation information mode, causing the ALLOC function to return zero free space available for the drives that are in this mode. You can use this mode if you have a very large drive and/or are using a very slow device, to prevent the computer from hanging for a few seconds every time a DIR command is issued. -Note: the zero allocation information mode is available since Nextor 2.0.3. - ## 9. Using the boot keys We have seen that if key "1" is kept pressed while the computer is booting, Nextor starts in MSX-DOS 1 mode. Now we'll see other useful keys that can be used to alter the way Nextor boots; see the _[Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md)_ for a full list of the available keys. @@ -316,15 +334,15 @@ b. Issue a `CALL SYSTEM` command. c. Copy the DRIVERS tool to drive A: with the following command: `COPY C:DRIVERS.COM A:` -d. Execute the DRIVERS tool. You will see that the IDE controller had been assigned two drives at boot time, and the same happens with the floppy disk controller: +d. Execute the DRIVERS tool. You will see that the IDE controller had been assigned two drives at boot time, and the floppy disk controller has been assigned one: ![](img/gsg/DriversTwoDrives.png) -e. Reset your computer while keeping the "CTRL" key pressed. Once in the COMMAND2.COM prompt, execute the DRIVERS tool again. You will see that both the IDE controller and the floppy disk drive have been assigned only one drive each: +e. Reset your computer while keeping the "5" key pressed. Once in the COMMAND2.COM prompt, execute the DRIVERS tool again. You will see that both the IDE controller and the floppy disk drive have been assigned only one drive each: ![](img/gsg/DriversOneDrive.png) -***What has happened?*** When the "CTRL" key is kept pressed at boot time, Nextor will assign one single drive to Nextor drivers, regardless of the number of attached devices (for device-based controllers only; see the _[Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md)_ for details about the controller types). The same behavior is exhibited by the floppy disk controller as usual. +***What has happened?*** When the "5" key is kept pressed at boot time, Nextor will assign one single drive to Nextor drivers, regardless of the number of attached devices (for device-based controllers only; see the _[Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md)_ for details about the controller types). f. Reset your computer while keeping the "SHIFT" key pressed. Once in the COMMAND2.COM prompt, execute the DRIVERS tool again. You will see that no drives have been assigned to the floppy disk drive: @@ -332,13 +350,13 @@ f. Reset your computer while keeping the "SHIFT" key pressed. Once in the COMMAN ***What has happened?*** When the "SHIFT" key is kept pressed at boot time, all the storage controllers with a MSX-DOS kernel (including the floppy disk drive controller) will disable themselves, but Nextor will not. This is useful to maximize the amount of available memory, especially in MSX-DOS 1 mode, as shown in the next step. (There are boot keys to selectively disable the Nextor kernels as well; see the _[Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md)_ for details) -g. Reset your computer while keeping the "1" and "3" keys pressed simultaneously. Once in the BASIC prompt, issue a `PRINT FRE(0)` command. You will see that there are about 20K free for BASIC code. +g. Reset your computer while keeping the "1" and "3" keys pressed simultaneously. Once in the BASIC prompt, issue a `PRINT FRE(0)` command. You will see that there are about 23K free for BASIC code. -h. Reset your computer while keeping the "1", "3", "SHIFT" and "CTRL" keys pressed simultaneously. Once in the BASIC prompt, issue a `PRINT FRE(0)` command again. You will see that now the free memory is about 25K. Also, if you execute a `CALL DRVINFO` command, you will see that indeed, there is only one drive assigned: +h. Reset your computer while keeping the "1", "3", "5" and "SHIFT" keys pressed simultaneously. Once in the BASIC prompt, issue a `PRINT FRE(0)` command again. You will see that now the free memory is about 25K. Also, if you execute a `CALL DRVINFO` command, you will see that indeed, there is only one drive assigned: ![](img/gsg/DrvinfoInBasic.png) -**Note:** of course, you do not need to keep the "CTRL" key pressed while booting if you have only one device attached to your Nextor controller (unless you want to keep the floppy disk drive active but with only one drive assigned). +**Note:** of course, you do not need to keep the "5" key pressed while booting if you have only one device attached to your Nextor controller. ## 10. Change history diff --git a/docs/Nextor 2.1 Programmers Reference.md b/docs/Nextor 2.1 Programmers Reference.md index 5bf71e51..1def19f3 100644 --- a/docs/Nextor 2.1 Programmers Reference.md +++ b/docs/Nextor 2.1 Programmers Reference.md @@ -1,4 +1,4 @@ -# Nextor 2.0 Programmers Reference +# Nextor 2.1 Programmers Reference ## Index @@ -66,9 +66,21 @@ [6.2. Changing the NEXTOR.SYS version number](#62-changing-the-nextorsys-version-number) -[7. Change history](#7-change-history) +[7. Nextor internals](#7-nextor-internals) -[7.1. v2.1.0 beta 1](#71-v210-beta-1) +[7.1. One-time boot keys](#71-one-time-boot-keys) + +[7.2. Disk emulation mode](#72-disk-emulation-mode) + +[7.2.1. Disk emulation data file format](#721-disk-emulation-data-file-format) + +[7.2.2. Entering disk emulation mode](#722-entering-disk-emulation-mode) + +[8. Change history](#8-change-history) + +[8.1. v2.1.0 beta 2](#81-v210-beta-2) + +[8.2. v2.1.0 beta 1](#82-v210-beta-1) ## 1. Introduction @@ -299,7 +311,7 @@ Results: A = error code BC = extra space in bytes ``` -This function returns the total or free space for a drive. The space information is always returned in Kilobytes, regardless of the type and the cluster size of the filesystem mapped to the drive. +This function returns the total or free space for a drive. The space information in HL:DE is always returned in Kilobytes, regardless of the type and the cluster size of the filesystem mapped to the drive. The "extra free space in bytes" result will be different from zero only when the minimum allocation unit of the drive is not a whole number of kilobytes. In case of FAT drives, it will be non-zero (specifically, it will be 512) only when the drive uses one sector per cluster and the cluster count is odd. For example, for a drive having one sector per cluster and 15 free clusters, this function will return HL=0, DE=7 and BC=512 when called with A=0 for that drive. @@ -413,9 +425,9 @@ The information returned in the data buffer is as follows: 0 for drive-based drivers and MSX-DOS drivers) +5: Logical unit index (for device-based drivers only; 0 for drive-based drivers and MSX-DOS drivers) -+5..+8: First device sector number (for devices in device-based drivers only; ++6..+9: First device sector number (for devices in device-based drivers only; always zero for drive-based drivers and MSX-DOS drivers) -+9..+63: Reserved (currently always zero) ++10..+63: Reserved (currently always zero) ``` If a file is mounted in the drive, the information returned in the data buffer is insetad as follows: @@ -442,13 +454,20 @@ Parameters: C = 7AH (_GPART) D = Device index E = Logical unit index H = Primary partition number (1 to 4) + H:7 = 0: Get information about the partition + 1: Get the device sector number that holds + the partition table entry L = Extended partition number (0 for an entry in the primary partition table) Results: A = Error code - B = Partition type code, - 0 if the specified partition does not exist - HL:DE = Starting device absolute sector number of the partition + If partition information is requested: + B = Partition type code + C = Status byte of the partition + HL:DE = Starting device absolute sector number of the partition + IX:IY = Partition size in sectors + If the sector number of the partition table entry is requested: + HL:DE = Device sector number that holds the partition table entry ``` Returns information about a device partition. This function works in MSX-DOS 1 mode. @@ -464,7 +483,7 @@ The partition type code returns information about the filesystem that the partit 1: FAT12 4: FAT16, smaller than 32MB (obsolete) 5: Extended (see below) -6: FAT16 +6: FAT16 (CHS) 14: FAT16 (LBA) ``` @@ -474,11 +493,11 @@ A device can have up to four primary partitions, numbered 1 to 4. In order to ac In order to enumerate all the partitions existing in a device , the following procedure should be followed, to take in account the possible presence of extended partitions: - 1. Search partition 1-0 (primary number 1, extended number 0). +1. Search partition 1-0 (primary number 1, extended number 0). 2. Search partition 2-0. If it exists and is of type "Extended", search partitions 2-1, 2-2, 2-3, etc, until a partition code 0 is returned. -3. If partition 2-0 does not exist or is not of type "Extended", search partitions 3-0 and 3-4. +3. If partition 2-0 does not exist or is not of type "Extended", search partitions 3-0 and 4-0. Note that it is possible that a device has no partitions at all. In this case, it is still possible that the device contains a valid filesystem, mapped to the absolute device sector zero; this is indeed the case of floppy disks and devices with very small capacity. @@ -486,7 +505,16 @@ When a partition is mapped to a drive letter, the partition first sector will al Nextor needs to read the device in order to search for partitions. If there is any error when accessing the device (for example, not ready), an error code will be returned. The standard system error handling routine (or the user error handling routine, if one is defined with _DEFER) will NOT be invoked. -When the specified partition does not exist in the device (for example, when a primary partition number larger than 4 is specified, or when an extended partition number is specified for a non-extended primary partition), then B=0 and A=.IPART will be returned. +When the specified partition does not exist in the device (for example, when a primary partition number larger than 4 is specified, or when an extended partition number is specified for a non-extended primary partition), then A=.IPART will be returned. + +Starting with Nextor 2.1.0 beta 2, it is possible to request the device sector number that holds the partition table, instead of requesting information about the partition; this is useful for applications intended for modifying the partition table entries. The way to locate the partition table entry in the returned sector is as follows: + +* If a primary partition was requested (extended number was 0), then the sector number returned is always 0, and the offset for the partition table entry in the sector is 1BEh, 1CEh, 1DEh and 1EEh for primary partition numbers 1, 2, 3 and 4 respectively. + +* If an extended partition is requested (primary partition number is 2, extended partition number is not 0) then the partition table entry is the first one in the returned sector (at offset 1BEh). + +For more information on the partition table structure see [Master Boot Record on Wikipedia](https://en.wikipedia.org/wiki/Master_boot_record). + ### 3.11. Call a routine in a device driver (_CDRVR, 7Bh) @@ -583,8 +611,8 @@ Parameters: C = 7DH (_Z80MODE) A = Driver slot number B = 00H => get current Z80 access mode 01H => set Z80 access mode - D = 00H => disable Z80 access mode (only if A=01H) - FFH => enable Z80 access mode (only if A=01H) + D = 00H => disable Z80 access mode (only if B=01H) + FFH => enable Z80 access mode (only if B=01H) Results: A = Error code D = Current Z80 access mode for the specified driver, @@ -708,13 +736,101 @@ Of course this change is temporary and it will cease to have effect (that is, th All of this applies only if the loaded version of NEXTOR.SYS is 2.0 beta 2 or newer. -## 7. Change history +## 7. Nextor internals + +This section details how some of the Nextor features work internally. This may be useful to develop applications that make use of these features as an alternative to the supplied Nextor tools. + +## 7.1. One-time boot keys + +The [one-time boot keys mechanism](Nextor%202.1%20User%20Manual.md#292-one-time-boot-keys) kicks in at boot time when the zero-terminated signature string NEXTOR_BOOT_KEYS is found at address A100h. In that case, the status of the alphanumeric keys are taken from the bytes that follow the signature, instead of being read from the keyboard, as the following table shows; a bit set to 1 means that the key is considered to be pressed. + +| Address | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +|:-------:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:| +| A111h | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +| A112h | F | E | D | C | B | A | 9 | 8 | +| A113h | N | M | L | K | J | I | H | G | +| A114h | V | U | T | S | R | Q | P | O | +| A115h | | |CTRL|SHFT| Z | Y | X | W | + +Note that currently not all keys are actually used by Nextor at boot time (e.g. numbers 6 to 9); but if any future version of Nextor makes use of any of the currently unused keys in the table, the key status will be expected to be at the position defined in this table when using the one-time boot keys mechanism. + +## 7.2. Disk emulation mode + +This section explains some details about the [disk emulation mode](Nextor%202.1%20User%20Manual.md#39-disk-emulation-mode). + +### 7.2.1. Disk emulation data file format + +The disk emulation data file, used by Nextor to know which disk image files must be used during an emulation session, consists of a header followed by a table with information about each of the disk image files. The header has the following contents: + +| Offset | Meaning | +|:------:|---------| +| +0 | Signature string `NEXTOR_EMU_DATA`, zero terminated | +| +16 | Number of entries in the disk image files table | +| +17 | 1-based index of the file to mount at boot time | +| +18 | Address to use as work area during the emulation session, or 0 if this area must be allocated (2 bytes, little endian) | +| +20 | Reserved, must be zero (4 bytes) | + +Each entry in the disk image files table is as follows: + +| Offset | Meaning | +|:------:|---------| +| +0 | Number of the device that contains the file (0 = same as emulation data file) | +| +1 | Number of the logical unit that contains the file (if device number is not 0) | +| +2 | Absolute device sector number where the file starts (4 bytes, little endian) | +| +6 | Size of the file in sectors (2 bytes, little endian) | + +If the device number in a disk image files table entry is zero, then Nextor will assume that the disk image file is located at the same device and logical unit as the emulation data file (the logical unit number in the table entry is ignored in this case). The `EMUFILE.COM` tool sets the device number to 0 for all entries if all the disk image files are located in the same device and logical unit as the emulation data file that is being created. + +Any contents in the emulation data file past the last entry in the disk images file table is ignored by the Nextor kernel. The `EMUFILE.COM` tool places here a printable list of the disk image filenames, it can be displayed by executing `TYPE /B datafile` in the command prompt. + +### 7.2.2. Entering disk emulation mode + +At boot time Nextor will enter disk emulation mode if it finds a pointer to the disk emulation data file. This pointer consists simply of a device+logical unit number and an absolute device sector number. + +Note that although this documentation and [the user manual](Nextor%202.1%20User%20Manual.md) use the term "emulation data file", an actual file isn't required - the Nextor kernel is only concerned about the sector number where the emulation data is located, regardless of whether this sector is part of a file or not. Using a file is usually the most convenient way to store this information, but a tool could be developed to use e.g. a reserved sector right before the FAT for this purpose. + +Nextor will enter the one-time disk emulation mode if it finds the following information in RAM at boot time: + +| Address | Contents | +|:-------:|---------| +| A000h | Signature string `NEXTOR_EMU_DATA`, zero terminated | +| A010h | Number of the device that contains the emulation data | +| A011h | Number of the logical unit that contains the emulation data | +| A012h | Absolute device sector number that contains the emulation data (4 bytes, little endian) | + +If the above information is not found, Nextor will enter the persistent disk emulation mode if it finds the following information in the first partition table entry of any of the available devices in the primary Nextor controller: + +| Sector offset | Partition table entry offset | Partition table meaning | Nextor meaning | +|:-------------:|:----------------------------:|-------------------------|----------------| +| 1BEh | +0 | Status byte | Bit 0 set = enter disk emulation mode | +| 1BFh | +1 | Start CHS | Number of the device that contains the emulation data | +| 1C0h | +2 | Start CHS | Number of the logical unit that contains the emulation data | +| 1C1h | +3 | Start CHS | MSB of the absolute device sector number that contains the emulation data | +| 1C2h | +4 | Partition type | Must be non zero | +| 1C3h | +5 | End CHS | 3rd byte of the absolute device sector number that contains the emulation data | +| 1C4h | +6 | End CHS | 2nd byte of the absolute device sector number that contains the emulation data | +| 1C5h | +7 | End CHS | LSB of the absolute device sector number that contains the emulation data | + +For example, if the emulation data is located at device 1, logical unit 2, sector 33445566h, and the partition is FAT16 (partition type 0Eh) and has the "active" flag set in the status byte, then the start of the partition table entry set for persistent emulation would look like this (in hexadecimal): + + 81 01 02 33 0E 44 55 66 + +Note that the condition for Nextor entering emulation mode is that bit 0 of the status byte must be set **and** the partition type code must be non-zero (but can be any other value, not necessarily FAT). Also note that the device and logical unit information here refers to the emulation data file only - the disk image files themselves can be located at a different device. + +Also worth noting: Nextor will check that the emulation data actually starts with the `NEXTOR_EMU_DATA` signature, and if that's not the case then it will boot normally without entering disk emulation mode. + + +## 8. Change history This section contains the change history for the different versions of Nextor. Only the changes that are meaningful from the application developer point of view are listed. For information on changes in general, please look at the _[Nextor 2.1 User Manual](Nextor%202.1%20User%20Manual.md)_ document. For information on changes related to driver development, please look at the _[Nextor 2.1 Driver Development Guide](Nextor%202.1%20Driver%20Development%20Guide.md)_ document. This list contains the changes for the 2.1 branch only. For the change history of the 2.0 branch see the _[Nextor 2.0 Programmers Reference](../../../blob/v2.0/docs/Nextor%202.0%20Programmers%20Reference.md#7-change-history)_ document. -### 7.1. v2.1.0 beta 1 +### 8.1. v2.1.0 beta 2 + +* [_GPART](#310-get-information-about-a-device-partition-_gpart-7ah) now returns the status byte of the partition, and allows to retrieve the device sector number that holds the partition table entry instead of information about the partition. + +### 8.2. v2.1.0 beta 1 * [_GDRVR](#38-get-information-about-a-device-driver-_gdrvr-78h) now returns an extra flag that tells if the driver implements the DRV_CONFIG routine. diff --git a/docs/Nextor 2.1 User Manual.md b/docs/Nextor 2.1 User Manual.md index d167472d..b3131fbf 100644 --- a/docs/Nextor 2.1 User Manual.md +++ b/docs/Nextor 2.1 User Manual.md @@ -30,6 +30,10 @@ [2.9. Boot keys](#29-boot-keys) +[2.9.1. Boot key inverters](#291-boot-key-inverters) + +[2.9.2. One-time boot keys](#292-one-time-boot-keys) + [2.10. Built-in partitioning tool](#210-built-in-partitioning-tool) [2.11. Embedded MSX-DOS 1](#211-embedded-msx-dos-1) @@ -74,6 +78,10 @@ [3.4.10. NSYSVER: the NEXTOR.SYS version changer](#3410-nsysver-the-nextorsys-version-changer) +[3.4.11. NEXBOOT: the one-time boot keys configuration tool](#3411-nexboot-the-one-time-boot-keys-configuration-tool) + +[3.4.12. EMUFILE: the disk emulation mode tool](#3412-emufile-the-disk-emulation-mode-tool) + [3.5. The built-in partitioning tool](#35-the-built-in-partitioning-tool) [3.6. Extensions to Disk BASIC](#36-extensions-to-disk-basic) @@ -126,7 +134,9 @@ [5. Change history](#5-change-history) -[5.1. v2.1.0 beta 1](#51-v210-beta-1) +[5.1. v2.1.0 beta 2](#51-v210-beta-2) + +[5.2. v2.1.0 beta 1](#52-v210-beta-1) ## 1. Introduction @@ -239,6 +249,8 @@ MSX-DOS 2 provides a set mapper support routines, which allow applications to al The boot time configuration of Nextor can be modified by keeping pressed some special keys while the system is booting. These keys and their behavior are: +* **0**: Disable permanent disk emulation mode by deleting the emulation data file pointer from the partition table. See _[3.9. Disk emulation mode](#39-disk-emulation-mode)_. + * **1**: Force boot in MSX-DOS 1 mode. If the computer is a MSX Turbo-R, switches CPU to Z80 mode. * **2**: Force boot in MSX-DOS 1 mode. If the computer is a MSX Turbo-R, switches CPU to R800-ROM mode. Note that in MSX-DOS 1 mode, the active CPU is never changed when accessing disk drives; this may cause some storage devices to not work properly, especially those mapped to MSX-DOS drivers such as floppy disk drives. @@ -249,7 +261,7 @@ The boot time configuration of Nextor can be modified by keeping pressed some sp * **5**: Assign only one drive to each Nextor kernel with a device-based driver regardless of the number of devices controlled by the driver. This overrides the normal behavior, in which Nextor assigns one drive per device found (see _[3.2. Booting Nextor](#32-booting-nextor)_). This is just the default behavior, though - drivers can override it they implement [the DRV_CONFIG routine](Nextor%202.1%20Driver%20Development%20Guide.md#448-drv_config-4151h)). -* **CTRL**: The state of this key is passed to MSX-DOS kernels on initialization. Typically this will cause the internal floppy disk drive to disable it second "ghost" drive, allowing to free some extra memory, especially in MSX-DOS 1 mode. +* **CTRL**: The state of this key is passed to MSX-DOS kernels on initialization. Typically this will cause the internal floppy disk drive to disable it second "ghost" drive, allowing to free some extra memory, especially in MSX-DOS 1 mode. Note that this key is inverted by default so you'll get the opposite behavior unless you customize the Nextor ROM (see _[2.9.1. Boot key inverters](#291-boot-key-inverters)_). * **SHIFT**: Prevent MSX-DOS kernels from booting, but allow Nextor kernels to boot normally. This is useful to disable the internal floppy disk drive in order to get some extra TPA memory, especially in MSX-DOS 1 mode. @@ -264,6 +276,47 @@ The boot time configuration of Nextor can be modified by keeping pressed some sp Example: if your Nextor kernel is in primary slot 1, press Q to prevent it from booting. If you have it in slot 2-3, press F. +#### 2.9.1. Boot key inverters + +The Nextor kernel has two bytes, at offsets 512 and 513 in the ROM that act as _boot key inverters_. There's one bit assigned to each of the keys that affect the booting process (not including the slot keys), and when that bit it set, then the meaning of the key is inverted. For example, if the bit for the SHIFT key is pressed, then MSX-DOS drivers will be disabled unless SHIFT is pressed while booting. + +Being hardcoded values, the only way to customize them is to modify the Nextor ROM file before flashing it into your device. The MKNEXROM.EXE tool can be used for that, or you can do it manually using a hexadecimal editor. + +Here's how bits are assigned to each key: + +* First byte (offset 512): + + * Bits 1 to 5: keys 1 to 5 + +* Second byte (offset 513): + + * Bit 5: CTRL key + * Bit 4: SHIFT key + +All other bits are currently unused and should always be 0 to ensure compatibility with possible future extensions. + +If you use MKNEXROM.EXE you need to supply a 16 bit hexadecimal value with the `/k` parameter. You should build that number by adding the values for each key as follows: + + * 1: 0002 + * 2: 0004 + * 3: 0008 + * 4: 0010 + * 5: 0020 + * CTRL: 2000 + * SHIFT: 1000 + +e.g. `/k:3002` to invert the 1, CTRL and SHIFT keys. + +By default (when using the "official" ROM files) only the CTRL key is inverted, so that by default internal floppy disk drives will boot with only one drive letter assigned. + +#### 2.9.2. One-time boot keys + +There's an alternative way to modify the Nextor booting procedure: the _one-time boot keys_. If at boot time Nextor finds a certain signature at a certain position in RAM, it will read a handful of bytes following that signature and use them as the values for the boot keys (including the slot keys), ignoring the keyboard. The RAM area used is at page 2, therefore this only works on computers with at least 32K RAM. + +Being a RAM based mechanism, it's "one-time" in the sense that it won't work again on the next computer reset unless the signature and the key data is put on memory again. The signature is explicitly erased by Nextor after being read to make this behavior consistent. + +The [NEXBOOT.COM tool](#3411-nexboot-the-one-time-boot-keys-configuration-tool) can be used to easily set this data and reset the computer, but all the tool does is writing to RAM, and thus any other tool could be used instead. The details on the location and format of the data used by this mechanism are in the _[Nextor 2.1 Programmers Reference](Nextor%202.1%20Programmers%20Reference.md)_ document. + ### 2.10. Built-in partitioning tool The Nextor kernel has a built-in device partitioning tool that can be started by just executing CALL FDISK in the BASIC prompt. It can be used to create partitions of any size between 100KB and 4GB on devices controlled by Nextor device based drivers. See _[3.5. The built-in partitioning tool](#35-the-built-in-partitioning-tool)_. @@ -301,6 +354,8 @@ Nextor consists of the following components: **Note:** two variants of the NEXTOR.SYS file exist. See _[4.3. Reduced NEXTOR.SYS without Japanese error messages](#43-reduced-nextorsys-without-japanese-error-messages)_. +**Note:** starting with Nextor 2.1.0 beta 2, the kernel will try to load MSXDOS2.SYS if NEXTOR.SYS is not found. However in this case the Nextor command line tools won't work. + In order to boot in the MSX-DOS 1 prompt, you need the usual MSXDOS.SYS and COMMAND.COM files. Also, if you have just the kernel and no NEXTOR.SYS or MSXDOS.SYS files, Nextor will boot in the BASIC prompt (running AUTOEXEC.BAS if present). Therefore, in order to "install" Nextor, you have two options: @@ -325,7 +380,7 @@ Also, note that the Sunrise IDE driver supplied with Nextor 2.0 is an experiment The Nextor booting procedure is similar to the one performed by MSX-DOS 2. However, if Nextor device-based drivers are present, things are a little different since it is necessary to perform a drive to device and partition mapping for all the drives attached to Nextor drivers (if you are not using any Nextor kernel with a device-based driver attached, then the booting procedure is identical to MSX-DOS 2). -At boot time, Nextor will perform a query to all the available device-based drivers to find out how many devices are being controlled by these drivers (actually, how many logical units, but devices will usually have one single logical unit), and will assign to each driver as many drives as devices are controlled by the driver. If CTRL is pressed at boot time, only one drive is assigned to each driver instead (see _[2.9. Boot keys](#29-boot-keys)_). +At boot time, Nextor will perform a query to all the available device-based drivers to find out how many devices are being controlled by these drivers (actually, how many logical units, but devices will usually have one single logical unit), and will assign to each driver as many drives as devices are controlled by the driver. If 5 is pressed at boot time, only one drive is assigned to each driver instead (see _[2.9. Boot keys](#29-boot-keys)_). For example, assume that you have two Nextor kernels with a device-based driver attached. The kernel in slot 1 controls one device, while the kernel in slot 2 controls three devices. Then the initial drive assignment would be as follows: @@ -335,37 +390,25 @@ B:, C:, D: for driver on slot 2 E:, F: for the internal disk drive ``` -If you boot while pressing CTRL, the assignment will be: +If you boot while pressing 5, the assignment will be: ``` A: for driver on slot 1 B: for driver on slot 2 -C: for the internal disk drive (which is affected by CTRL as well) +C:, D: for the internal disk drive ``` The internal disk drive would not have any drives attached if you pressed SHIFT while booting (see _[2.9. Boot keys](#29-boot-keys)_). -After all drives have been assigned to drivers, a device and partition to drive automatic mapping procedure will be run for each of these drives. The procedure is repeated for each driver and is as follows: - -1. Start with the first drive associated to the first Nextor device-based driver found. - -2. Start with the first logical unit on the first device available. - -3. Scan all the existing primary partitions. If one of them has a FAT12 or FAT16 filesystem which has a file named NEXTOR.DAT in the root directory, map it to the drive. (If the drive has no valid partition table, search for one single filesystem at device sector zero) - -4. If step 3 fails, repeat it with the next logical unit available in the device. +After all drives have been assigned to drivers, a device and partition to drive automatic mapping procedure will be run for each of these drives. Each drive is mapped to the first partition found that meets the following conditions: -5. If step 3 fails for all the logical units on the device, repeat it with the next device. +1. Is a valid FAT12 or FAT16 partition (only FAT12 when booting in MSX-DOS 1 mode) +2. Has the "active" flag set in the partition table (this can be set using [FDISK](#35-the-built-in-partitioning-tool)) +3. No drives have been already mapped to partitions in the same device -6. If step 3 fails for all the devices, repeat from step 1 but this time do not search a NEXTOR.DAT file (that is, map the first FAT12 or FAT16 partition available). +If no partitions are found that meet all three conditions, then the search is started over, but this time skipping the "active" flag check. If this fails again, absolute sector 0 of the device is checked (to see if the device doesn't have partitions but holds a valid FAT filesystem) as a last resort before leaving the drive unmapped. -7. If step 6 fails (there are no usable partitions available), leave the drive unmapped. - -8. Repeat steps 2-7 for the other drives assigned to the driver (if any), but skipping the logical units already assigned to a drive. - -9. Go to the next device-based driver (if any), and repeat from step 2. - -In short: available devices having a FAT12 or FAT16 partition are assigned to the available drives in device and logical unit number order, but the first partition having a NEXTOR.DAT file in the root directory has preference. Note that the contents of the NEXTOR.DAT file is irrelevant, it may even be an empty file (in future versions of Nextor this file is likely to contain some system configuration information). Also, note that only primary partitions are examined in the automatic mapping procedure. +Note that in order to speed up the botting procedure, only the first 9 partitions of each device are scanned during this procedure; consequently, [FDISK](#35-the-built-in-partitioning-tool) allows to change the "active" flag on these first 9 partitions only. Starting with Nextor 2.0.5, device-based drivers can tell Nextor how many drives they want at boot time and which devices should be mapped to these drivers, bypassing part of this automatic procedure (partitions are still selected automatically). This feature is optional, and must be implemented by the driver developer. @@ -373,7 +416,7 @@ After the automatic mapping is finished, the boot procedure will continue with t 1. If the "3" key is being pressed, the system displays the BASIC prompt. -2. Otherwise, if the NEXTOR.SYS and COMMAND2.COM files are present in the boot drive (the first drive that is not unmapped), the DOS prompt is shown after AUTOEXEC.BAT is executed (if present). +2. Otherwise, if the NEXTOR.SYS (or MSXDOS2.SYS) and COMMAND2.COM files are present in the boot drive (the first drive that is not unmapped), the DOS prompt is shown after AUTOEXEC.BAT is executed (if present). 3. Otherwise, if the boot drive has a MSX-DOS 1 or MSX-DOS 2 boot sector, its boot code is executed as in the case of MSX-DOS: first in the BASIC environment with the carry flag reset, then in the DOS environment with the carry flag set. This will usually cause MSXDOS.SYS and COMMAND.COM to be loaded if present. @@ -381,6 +424,8 @@ After the automatic mapping is finished, the boot procedure will continue with t Note that step 3 will not be done if the disk has a standard boot sector (not created by MSX-DOS 1 or MSX-DOS 2). The built-in disk partitioning tool will create MSX-DOS 2 boot sectors for all partitions of 32MB or less, and standard boot sectors for larger partitions. +Starting with Nextor 2.1.0 beta 2, the Nextor kernel will load MSXDOS2.SYS if present when NEXTOR.SYS is not found, thus allowing booting from old MSX-DOS 2 disks. Note however that in this case the Nextor command line tools won't work. + #### 3.2.1. Booting in DOS 1 mode Nextor kernel can boot in MSX-DOS 1 mode. This will happen if anything of the following conditions is met: @@ -598,6 +643,45 @@ Note: the version number change performed by this tool is temporary and it will Note: do not use this tool with NEXTOR.SYS versions older than 2.0 beta 2. +#### 3.4.11. NEXBOOT: the one-time boot keys configuration tool + +The NEXBOOT.COM tool allows to easily configure the keys to be used as [one-time boot keys](#292-one-time-boot-keys) in the next reset. The syntax is: + +``` +NEXBOOT |. [ [... ]] +``` + +where the boot keys are the numeric keys, C for CTRL and S for shift, and `` are the slot numbers of the Nextor kernels to be disabled. For example `NEXBOOT 1C` will invert CTRL and 1 keys, `NEXBOOT S 1 23` will invert the SHIFT keys and disable the Nextor kernels in slots 1 and 2-3, and `NEXBOOT . 2` will just disable the Nextor kernel in slot 2. + +In all cases, the tool resets the computer immediately after apporpriately setting the keys information in RAM. + +#### 3.4.12. EMUFILE: the disk emulation mode tool + +The EMUFILE.COM tool allows to create disk emulation mode data files and to enter disk emulation mode. The syntax for creating an emulation data file is: + +``` +emufile [] [ ...] +``` + +`` is the name of the emulation data file that will be created (default extension is .EMU), and `` are the disk image files that will be used for the emulation (these can contain wildcards). Numbers (for disk change) are assigned to the disk image files in the same order as they are specified; when using wildcards, in the order they are found in the storage device that contains them (the same order that you see when you do run the DIR command). + +The `-b ` option allows you to specify the number of the disk image file that will be used to boot when the emulation session starts, default is 1. + +The `-a
` option allows you to specify the page 3 address that Nextor will use as work area (about 16 bytes) during the emulation session, must be a hexadecimal number in page 3 (C000 or higher). If not specified, this area will be allocated by Nextor before starting the emulation session. + +The `-p` option will print all the filenames and associated keys after creating the data file. Note however that you can see this same information afterwards if you `TYPE /B` the emulation data file. + +The syntax for starting a disk emulation session is as follows: + +``` +emufile set [o|p[[]]] +``` + +`o` will start the emulation using the one-time variant (this is the default), and `p` will start the emulation using the persistent variant. For the later, by default the emulation file data pointer will be written to the device where `` is stored, but you can specify a different `` and also optionally a ``. The default LUN index is 1 (i.e. `p3` is the same as `p31`). + +Note that in both variants the computer will reset immediately after `EMUFILE.COM` writes the emulation data file pointer to the appropriate place. + + ### 3.5. The built-in partitioning tool The Nextor kernel has an embedded utility for partitioning storage devices attached to Nextor device-based drivers. To start it, just invoke CALL FDISK from the BASIC prompt. It works properly on both 40 columns and 80 columns mode. Please note that starting the FDISK tool will delete the current BASIC program from memory. @@ -614,12 +698,12 @@ The tool has a user interface based on menus, so anyone should be able to use it * Partitions up to 32MB will have a MSX-DOS 2 boot sector, partitions of 33MB and more will have a standard boot sector. -* If four partitions or less are defined, they will be created as primary partitions. If five partitions or more are defined, then the first one will be primary and the others will be extended partitions contained within the second primary partition. Remember that Nextor only scans primary partitions during the automatic drive to device and partition mapping process. - * To get an optimum cluster size, it is recommended to define the partition sizes as powers of two (that is: 1M, 2M, 4M, 8M, 16M or 32M for FAT12 partitions; 64M, 128M, 256M, 512M, 1G, 2G or 4G for FAT16 partitions). If this is not possible, it is better to select the partition size as slightly smaller than the closest power of two than slightly higher (that is, for example 31M is better than 33M). Remember that Nextor can handle devices with FAT16 partitions and standard boot sectors; if you use a factory-partitioned device of 2GB or less you probably don't need to partition it, unless you want to create MSX-DOS 1 compatible partitions (4GB devices are usually shipped with a FAT32 partition, so you will need to partition it with FDISK anyway). +When creating new partitions you can choose which one(s) will have the "active" flag set, thus being eligible for automatic mapping at boot time (see _[3.2. Booting Nextor](#32-booting-nextor)_); it is also possible change the flag on already existing partitions. + The partitioning tool works in MSX-DOS 1 mode too. Note however that the tool will always allow you to create partitions larger than 16M, which are not compatible with MSX-DOS 1. ### 3.6. Extensions to Disk BASIC @@ -927,16 +1011,22 @@ ATTRIB +R TOOLS.DSK --> Error ### 3.9. Disk emulation mode -Since version 2.1 Nextor allows to boot in disk emulation mode. In this mode the usies a disk image file (or a set of swappable files) as the boot device instead of a regular device. This is ideal for playing disks that were released in floppy disk and can't be run from a modern storage device, because they don't have a filesystem or because they need to run in MSX-DOS 1 mode. +Since version 2.1 Nextor allows to boot in disk emulation mode. In this mode Nextor uses a disk image file (or a set of swappable files) as the boot device instead of a regular device. This is ideal for playing disks that were released in floppy disk and can't be run from a modern storage device, because they don't have a filesystem or because they need to run in MSX-DOS 1 mode. + +The technical details about how the disk emulation mode works are in the _[Nextor 2.1 Programmers Reference](Nextor%202.1%20Programmers%20Reference.md)_ document in case you are interested in building your own tool instead of using `EMUFILE.COM`. #### 3.9.1. Entering and exiting the disk emulation mode -Nextor will boot in disk emulation mode if it finds a file named `NEXT_DSK.DAT` in the root directory of a primary partition in a device controlled by the primary Nextor controller. This file contains information about the disk image files to be used for the emulation. +First of all, the data needed during a disk emulation mode session (which disk image files will be used and where are they located) must exist in a file with a certain format, the _disk emulation data file_. You can create these files using [the `EMUFILE.COM` tool](#3412-emufile-the-disk-emulation-mode-tool). These files can have any name and will typically have the .EMU extension, but that's not mandatory. + +Second, in order to tell Nextor to boot in disk emulation mode, a pointer to the appropriate disk emulation data file must exist at a special location while the computer boots. There are two variants of the emulation mode, each requiring a different location for the emulation data file pointer: + +* **One-time:** Nextor will enter disk emulation mode only once, that is, after resetting the computer again Nextor will boot normally. In this mode the pointer to the emulation data file is set in RAM. -The `NEXT_DSK.DAT` file is created by using the supplied `EMUFILE.COM` tool. Most times it's as easy as doing just `EMUFILE file1.dsk file2.dsk file3.dsk` (or `EMUFILE game\*.dsk`, or just `EMUFILE game\`). There are additional options, run the program without parameters to get more information. +* **Persistent:** Nextor will enter disk emulation mode on every computer reset, until that mode is manually disabled by pressing 0 while booting. In this mode the pointer to the emulation data file is set in the partition table of one of the devices controlled by Nextor (usually the same device that contains the emulation data file and the disk image files, but that's not mandatory). -To disable the disk emulation mode (that is, to boot normally even if a `NEXT_DSK.DAT` file exists), keep the 0 (zero) key pressed while the computer boots. You will have to manually delete or rename the `NEXT_DSK.DAT` file to prevent the disk emulation mode to be entered again in the next system boot. +Both variants of disk emulation mode can be entered by using the `EMUFILE.COM` tool with the `set` parameter, being the one-time variant the default one. #### 3.9.2. Changing the image file @@ -945,7 +1035,7 @@ Up to 32 disk image files can be specified for an emulation session, but only on For example, assume that you are playing a two disks game. You boot with disk 1 and at some point the game asks you to insert disk 2 and press space key. Just press 2 (they key assigned to the second image file) and the space key at the same time and you're good to go. -Alternatively, you can also press the GRAPH key when the computer is trying to read the file. The caps led will lit and the computer will freeze until you release GRAPH and press the appropriate file key. This is useful when having to directly press an alphanumeric key while disk access is performed is a problem (for example, you are in the BASIC prompt and you want to trigger a file change when executing a FILES command: the pressed key would be added to "FILES" causing a Syntax Error). +Alternatively, you can also press the GRAPH key when the computer is trying to read the file. The CAPS led will lit and the computer will freeze until you release GRAPH and press the appropriate file key (or you can press GRAPH again if you change your mind and want to keep using the same disk). This is useful when having to directly press an alphanumeric key while disk access is performed is a problem (for example, you are in the BASIC prompt and you want to trigger a file change when executing a FILES command: the pressed key would be added to "FILES" causing a Syntax Error). #### 3.9.3. Rules and restrictions @@ -954,9 +1044,9 @@ The following rules and restrictions apply to the disk emulation mode: - The primary controller must be a Nextor kernel with a device-based driver. -- The `NEXT_DSK.DAT` file and all the disk image files must be placed in devices controlled by the primary controller (but they can be in different partitions and even in different devices). +- The emulation data file and all the disk image files must be placed in devices controlled by the primary controller (but they can be in different partitions and even in different devices). -- The `NEXT_DSK.DAT` file stores information about absolute device sectors, therefore it will be unusable if the disk image files are moved and file renames will have no effect. It is recommended to generate the file immediately before using it. +- The emulation data file stores information about absolute device sectors, therefore it will be unusable if the disk image files are moved and file renames will have no effect. It is recommended to either generate the file immediately before using it, or have a partition reserved only for disk image files and their corresponding emulation data files (that is, a partition where you usually don' create or move files around). - The disk image files must have a size of at least 512 bytes and at most 32 MBytes, must not contain partitions (the contained filesystem is expected to start right at the beginning of the file), and must contain a proper FAT12 filesystem (the FORMAT command will not work in disk emulation mode). @@ -966,8 +1056,6 @@ The following rules and restrictions apply to the disk emulation mode: - All Nextor controllers but the primary one will be disabled when disk emulation mode is entered. MSX-DOS kernels (such as the internal floppy disk drive) will not, but you can force them to disable themselves by pressing SHIFT while booting; this is useful to free some memory. -- If you are using a `NEXTOR.DAT` file to alter the device mappings priority, Nextor needs the `NEXT_DSK.DAT` to be found before NEXTOR.DAT in order to start emulation mode. This means that `NEXT_DSK.DAT` must be placed either 1. In the same partition of NEXTOR.DAT (relative position in the root directory is irrelevant); 2. In a primary partition with a smaller number in the same device; or 3. In a device with a smaller device number. - #### 3.9.4 How to free some memory @@ -980,7 +1068,7 @@ Some games will not work "out of the box" because they assume that only the flop #### 3.9.5. Known bugs -* The current version of the EMUFILE.COM tool does not verify that the disk image files are not fragmented. +* The current version of the `EMUFILE.COM` tool does not verify that the disk image files are not fragmented. * If you have more than one device in the primary Nextor controller (for example, for the MegaFlashROM SCC+ SD this means two SD cards, or one or two cards plus the ROM disk), Nextor will allocate one dummy drive letter for each extra device. MSX-DOS devices (if any) will then have drive letters assigned after these. For example, if you have three devices, A: is where the emulated disk image file is mounted, B: and C: are dummy, and D: is the internal floppy disk drive. These dummy drives will NOT have memory allocated for FAT buffers. @@ -1011,7 +1099,56 @@ This section contains the change history for the different versions of Nextor. C This list contains the changes for the 2.1 branch only. For the change history of the 2.0 branch see the _[Nextor 2.0 User Manual](../../../blob/v2.0/docs/Nextor%202.0%20User%20Manual.md#5-change-history)_ document. -### 5.1. v2.1.0 beta 1 +### 5.1. v2.1.0 beta 2 + +- Nextor will now try to load `MSXDOS2.SYS` if `NEXTOR.SYS` is not found in the boot drive. + +- The method for selecting partitions for automatic mapping has changed from requiring a `NEXTOR.DAT` file in the root directory to having the "active" flag set in the partition table. + +- Now the first 9 partitions of a device will be scanned during the automatic mapping procedure, this includes extended partitions. + +- FDISK allows to change the "active" flag of new and existing partitions. + +- FDISK now always creates extended partitions, even if 4 or less partitions are defined. + +- FDISK now creates FAT16 partitions with a partition type code of 14 (FAT16 LBA) instead of 6 (FAT16 CHS). + +- The numeric keyboard can now be used both when booting and when changing disks in disk emulation mode. + +- Russian keyboard is now properly recognized (numeric keys only). + +- Introduced the [boot key inverters](#291-boot-key-inverters). + +- Introduced the [one-time boot keys](#292-one-time-boot-keys). + +- Introduced the [NEXBOOT.COM tool](#3411-nexboot-the-one-time-boot-keys-configuration-tool) to set the RAM based one-time boot keys. + +- Introduced the RAM based one-time [disk emulation mode](#39-disk-emulation-mode). + +- The method to enter the old disk emulation mode (now named "persistent") has changed from requiring a `NEXT_DSK.DAT` file in the root directory to storing a pointer to the emulation data file in the partition table of the device. + +- Pressing the 0 key at boot time will delete the pointer to the emulation data file in the partition table, thus permanently disabling the emulation mode - no need to manually do anything else. + +- When Nextor is waiting for a disk key press after having pressed GRAPH in disk emulation mode, now you can press GRAPH again to cancel the disk change. + +- The first Nextor kernel to boot now clears the screen before invoking the driver initialization. + +- ARG is no longer used as temporary work area by the Nextor kernel, this should improve the compatibility of games in disk emulation mode. + +- Fix: drive was remapped in case of error (even if it was retried successfully). + +- Fix: boot sector checksum calculation had a bug that caused "Wrong disk" errors. + +- Fix: [#1 pressing CTRL+STOP while Nextor was trying to load NEXTOR.SYS hanged the computer](https://github.com/Konamiman/Nextor/issues/1). + +- Fix: [#23 computer hanged when booting with one single drive letter (e.g. when using single-device controller in a computer without internal disk drive)](https://github.com/Konamiman/Nextor/issues/23). + +- Fix: [#29 wrong stack management hangedd the computer when a file handle was read or written to a number of times](https://github.com/Konamiman/Nextor/issues/29). + +- Fix: computer crashing when more than one Nextor kernel was present as soon as the extended BIOS hook was called (for example, when loading COMMAND2.COM). + + +### 5.2. v2.1.0 beta 1 - All the changes and fixes of [Nextor 2.0.5](../../../blob/v2.0/docs/Nextor%202.0%20User%20Manual.md#51-v205-beta-1). diff --git a/docs/img/gsg/DirAAndDirB.png b/docs/img/gsg/DirAAndDirB.png index 582128e2..836363a6 100644 Binary files a/docs/img/gsg/DirAAndDirB.png and b/docs/img/gsg/DirAAndDirB.png differ diff --git a/docs/img/gsg/DirAAndDirBDos1Mode.png b/docs/img/gsg/DirAAndDirBDos1Mode.png index 41f4d5b5..acc89d40 100644 Binary files a/docs/img/gsg/DirAAndDirBDos1Mode.png and b/docs/img/gsg/DirAAndDirBDos1Mode.png differ diff --git a/docs/img/gsg/DirAAndDirBDos1ModeWithNextorDat.png b/docs/img/gsg/DirAAndDirBDos1ModeWithNextorDat.png index 7696461b..91db0161 100644 Binary files a/docs/img/gsg/DirAAndDirBDos1ModeWithNextorDat.png and b/docs/img/gsg/DirAAndDirBDos1ModeWithNextorDat.png differ diff --git a/docs/img/gsg/DirAAndDirBWithFiles.png b/docs/img/gsg/DirAAndDirBWithFiles.png index 8d0c2044..639ccbfb 100644 Binary files a/docs/img/gsg/DirAAndDirBWithFiles.png and b/docs/img/gsg/DirAAndDirBWithFiles.png differ diff --git a/docs/img/gsg/DirInDos1Mode.png b/docs/img/gsg/DirInDos1Mode.png index 0daf23b8..3aedc761 100644 Binary files a/docs/img/gsg/DirInDos1Mode.png and b/docs/img/gsg/DirInDos1Mode.png differ diff --git a/docs/img/gsg/DirInDos1ModeWithNextorDat.png b/docs/img/gsg/DirInDos1ModeWithNextorDat.png index 5f55d8a3..6f3b2d7d 100644 Binary files a/docs/img/gsg/DirInDos1ModeWithNextorDat.png and b/docs/img/gsg/DirInDos1ModeWithNextorDat.png differ diff --git a/docs/img/gsg/DirTwoSystemFiles.png b/docs/img/gsg/DirTwoSystemFiles.png index dca92333..f9f056bd 100644 Binary files a/docs/img/gsg/DirTwoSystemFiles.png and b/docs/img/gsg/DirTwoSystemFiles.png differ diff --git a/docs/img/gsg/DirWithNextorDat.png b/docs/img/gsg/DirWithNextorDat.png index 14bf31a7..c536e95a 100644 Binary files a/docs/img/gsg/DirWithNextorDat.png and b/docs/img/gsg/DirWithNextorDat.png differ diff --git a/docs/img/gsg/DriversOneController.png b/docs/img/gsg/DriversOneController.png index 951e5050..d2f08c66 100644 Binary files a/docs/img/gsg/DriversOneController.png and b/docs/img/gsg/DriversOneController.png differ diff --git a/docs/img/gsg/DriversOneDrive.png b/docs/img/gsg/DriversOneDrive.png index f3ccd230..736c0615 100644 Binary files a/docs/img/gsg/DriversOneDrive.png and b/docs/img/gsg/DriversOneDrive.png differ diff --git a/docs/img/gsg/DriversTwoDrives.png b/docs/img/gsg/DriversTwoDrives.png index 922fe222..a88c0893 100644 Binary files a/docs/img/gsg/DriversTwoDrives.png and b/docs/img/gsg/DriversTwoDrives.png differ diff --git a/docs/img/gsg/DrvinfoInBasic.png b/docs/img/gsg/DrvinfoInBasic.png index 6a270735..acebe30c 100644 Binary files a/docs/img/gsg/DrvinfoInBasic.png and b/docs/img/gsg/DrvinfoInBasic.png differ diff --git a/docs/img/gsg/FourPartitionsList.png b/docs/img/gsg/FourPartitionsList.png index 090b0cc2..4790076c 100644 Binary files a/docs/img/gsg/FourPartitionsList.png and b/docs/img/gsg/FourPartitionsList.png differ diff --git a/docs/img/gsg/NextorPrompt.png b/docs/img/gsg/NextorPrompt.png index dd609e24..cd1501a4 100644 Binary files a/docs/img/gsg/NextorPrompt.png and b/docs/img/gsg/NextorPrompt.png differ diff --git a/docs/img/gsg/Partitions2And4Active.PNG b/docs/img/gsg/Partitions2And4Active.PNG new file mode 100644 index 00000000..7d0cb2ff Binary files /dev/null and b/docs/img/gsg/Partitions2And4Active.PNG differ diff --git a/docs/img/gsg/Partitions2And4Active.png b/docs/img/gsg/Partitions2And4Active.png new file mode 100644 index 00000000..7d0cb2ff Binary files /dev/null and b/docs/img/gsg/Partitions2And4Active.png differ diff --git a/source/kernel/bank0/betainfo.mac b/source/kernel/bank0/betainfo.mac index 82bea578..785caad2 100644 --- a/source/kernel/bank0/betainfo.mac +++ b/source/kernel/bank0/betainfo.mac @@ -9,3 +9,7 @@ endif if RC gt 0 defb " RC ",RC+"0"," " endif + +if RR gt 0 + defb "r",RR+"0"," " +endif diff --git a/source/kernel/bank0/dosboot.mac b/source/kernel/bank0/dosboot.mac index 37c7354a..eb2f74b8 100644 --- a/source/kernel/bank0/dosboot.mac +++ b/source/kernel/bank0/dosboot.mac @@ -142,11 +142,8 @@ READ_BOOT_SEC:: ; Corrupts: AF,BC,DE,HL ; ; - ld hl,BOOT_DISKVECT ;Setup disk error and break - ld (DISKVECT##),hl ; vector for trapping - ld hl,BOOT_BREAKVECT ; errors while booting. - ld (BREAKVECT##),hl -; + call SET_BOOT_VECTORS + ld de,($SECBUF##) ;Set the DTA address ready ld c,_SETDTA## ; for reading the boot call BOOT_BDOS ; sector in. @@ -283,24 +280,8 @@ TRY_MSX_DOS:: ; ld (CUR_DRV##),a ;Setup default drive. - ;push af - ;ld a,(NOTFIRST##) - ;or a - ;jr nz,NOBOOT - ;ld e,a - ;ld a,1 - ;ld bc,0FF00h + _LOCK## - ;call BOOT_BDOS - ;ld hl,MFLAGS## - ;set 1,(hl) - NOBOOT: - ;pop af - - ld hl,BOOT_DISKVECT ;Setup disk error and break - ld (DISKVECT##),hl ; vector for trapping - ld hl,BOOT_BREAKVECT ; errors while booting. - ld (BREAKVECT##),hl + call SET_BOOT_VECTORS ; ld b,0 ;Unassign all drives (does ld d,b ; not waste very much time) @@ -313,13 +294,19 @@ NOBOOT: jr z,msxdos_fail ; retry_dos: - ld de,BOOT_NAME ;Try to open the "MSXDOS.SYS" - xor a ; file on the default drive. + ld de,BOOT_NAME ;Try to open the "NEXTOR.SYS" + xor a ;file on the default drive. + ld c,_OPEN## + call BOOT_BDOS + jr z,msxdos_bootok + + ld de,OLD_BOOT_NAME ;Fallback to try "MSXDOS.SYS" + xor a ld c,_OPEN## call BOOT_BDOS jr nz,msxdos_fail ;Jump if file not found ; - +msxdos_bootok: ld de,100h ld hl,3F00h ;Try to read the file in at ld c,_READ## ; 100h up to the top of @@ -352,10 +339,33 @@ msxdos_fail: ; ; BOOT_NAME: db "\NEXTOR.SYS",0 -; +OLD_BOOT_NAME: db "\MSXDOS2.SYS",0 ; ;----------------------------------------------------------------------------- ; + +; Originally, the abort vector was set pointing to BOOT_BREAKVECT whenever +; NEXTOR.SYS was about to be loaded. If the user pressed CTRL+STOP at this time, +; the abort routine kicked in and it tried to read the address at BOOT_BREAK +; and execute it - but since the user paging had been restored before that, +; a random value was being read instead, and thus random code was executed +; and the computer crashed. +; +; Solution: since this default abort routine is just one byte (a RET), +; just store it at an unused place in page 3 and point to it instead. + +SBDAVEC:: +SET_BOOT_VECTORS: + ld hl,BOOT_DISKVECT + ld (DISKVECT##),hl + ld a,0C9h + ld (RAM_ABORT##),a + ld hl,RAM_ABORT## + ld (RAM_ABORT##+1),hl + ld hl,RAM_ABORT##+1 + ld (BREAKVECT##),hl + ret + BOOT_BDOS: call BDOS## ;Routine for calling BDOS. cp .ABORT## jr nz,not_abort_err ;If we have an aborted disk diff --git a/source/kernel/bank0/init.mac b/source/kernel/bank0/init.mac index fcda19ac..d49b4833 100644 --- a/source/kernel/bank0/init.mac +++ b/source/kernel/bank0/init.mac @@ -115,6 +115,8 @@ FATSIZ equ 16 ;size of FAT in sectors FAT equ 19 ;pointer to FAT DPBSIZE equ 21 ;number of bytes per one DPB +SCANKEYS_RAM_BASE equ 0A100h + ; ; MACROs ; @@ -229,8 +231,8 @@ _GO_BIOS: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; -;This routine will return NZ if the "4" key and the appropriate slot key -;are pressed. The slot keys are: +;This routine will return NZ if the appropriate slot key is pressed. +;The slot keys are: ;UIOP for slots 0-0 to 0-3 ;QWER for slots 1-0 to 1-3 ;ASDF for slots 2-0 to 2-3 @@ -238,12 +240,6 @@ _GO_BIOS: ;For unexpanded slots, the key for subslot 0 applies (U, Q, A, Z) DISABLE_KEY: - ;xor a - ;call SNSMAT ;Scan "4" key first - ;cpl - ;and 00010000b - ;ret z - call GSLOT1## and 00001111b add a,a @@ -251,39 +247,419 @@ DISABLE_KEY: ld d,0 ld hl,DISABLE_TBL add hl,de - ld a,(hl) - call SNSMAT - cpl - ld c,a - inc hl - ld a,(hl) - and c + ld c,(hl) ;Offset of byte in boot keys area + inc hl + ld b,(hl) ;Mask in the boot keys byte + + ld hl,BOOTKEYS## + ld e,c + ld d,0 + add hl,de + ld a,(hl) + and b + ret +; 0: 76543210 +; 1: FEDCBA98 +; 2: NMLKJIHG +; 3: VUTSRQPO +; 4: ....ZYXW + DISABLE_TBL: - db 5, 00000100b ;0-0: U - db 4, 01000000b ;1-0: Q - db 2, 01000000b ;2-0: A - db 5, 10000000b ;3-0: Z - - db 3, 01000000b ;0-1: I - db 5, 00010000b ;1-1: W - db 5, 00000001b ;2-1: S - db 5, 00100000b ;3-1: X - - db 4, 00010000b ;0-2: O - db 3, 00000100b ;1-2: E - db 3, 00000010b ;2-2: D - db 3, 00000001b ;3-2: C - - db 4, 00100000b ;0-3: P - db 4, 10000000b ;1-3: R - db 3, 00001000b ;2-3: F - db 5, 00001000b ;3-3: V - - ALIGN 41EFh + db 3, 01000000b ;0-0: U + db 3, 00000100b ;1-0: Q + db 1, 00000100b ;2-0: A + db 4, 00001000b ;3-0: Z + + db 2, 00000100b ;0-1: I + db 4, 00000001b ;1-1: W + db 3, 00010000b ;2-1: S + db 4, 00000010b ;3-1: X + + db 3, 00000001b ;0-2: O + db 1, 01000000b ;1-2: E + db 1, 00100000b ;2-2: D + db 1, 00010000b ;3-2: C + + db 3, 00000010b ;0-3: P + db 3, 00001000b ;1-3: R + db 1, 10000000b ;2-3: F + db 3, 10000000b ;3-3: V + + ALIGN 41EFh-3 + jp SCANKEYS CPMVER: CALLDOS 0Ch ;Return CP/M version number + + ALIGN 4200h + + ;--- BOOT KEY INVERTERS --- + ; + ; These two bytes have one bit assigned for each key that has meaning at boot time. + ; If the bit for one key is set, then the meaning of the key is inverted. + ; + ; E.g. if the bit for the SHIFT key is set, then all MSX-DOS kernels will be + ; disabled by default, but will be enabled if the SHIFT key is pressed + ; during boot (the opposite of the normal behavior). + ; + ; This does NOT have effect when setting the boot keys in RAM + ; (if boot keys are set in RAM, the keyboard is completely ignored). + ; + ; These bytes are fixed at offset 200h (starting at 0) in ROM. + ; They should be changed in the ROM file before flashing in the hardware. + ; + ; Bits are assigned to keys as follows: + ; + ; 0: ..54321. + ; 1: ..CS.... (C = CTRL, S = SHIFT) + ; + ; "." bits are currently unused and should always be 0 to ensure compatibility + ; with possible future extensions. + +KEYS_INV_0: db 00h +KEYS_INV_1: db 20h ;Invert CTRL by default (so internal FDDs get only one drive) + +; +;======================================================================= +; +; This routine scans all the numeric and alphabetic keys, +; including the numeric keyboard. +; +; Input: A=0 for international keyboard, 1 for Russian keyboard +; Output: Keys in HLDEB (1 bit each, set if pressed): ; +; B: 76543210 +; E: FEDCBA98 +; D: NMLKJIHG +; L: VUTSRQPO +; H: ....ZYXW +; +; H holds also the status of CAPS, GRAPH, CTRL and SHIFT on bits 7,6,5,4 +; respectively. +; +; (routine placed here to use a big hole in ROM - may need to be moved +; if the routine grows) + +SK_ROW_0 equ 0 +SK_ROW_1 equ 1 +SK_ROW_2 equ 2 +SK_ROW_3 equ 3 +SK_ROW_4 equ 4 +SK_ROW_5 equ 5 +SK_ROW_6 equ 6 +SK_ROW_9 equ 7 +SK_ROW_10 equ 8 +SK_B equ 9 +SK_E equ 10 +SK_D equ 11 +SK_L equ 12 +SK_H equ 13 + +SK_SIZE equ 14 + +SCANKEYS:: + ld ix,-SK_SIZE + add ix,sp + ld sp,ix + + push af + ld bc,0700h + push ix + pop hl + call SK_GET_ROWS + + ld bc,0209h + call SK_GET_ROWS + + pop af + or a + jr nz,SCANK_RUSSIAN + call SK_INTERNATIONAL + jr SCANK_DONE +SCANK_RUSSIAN: + call SK_RUSSIAN +SCANK_DONE: + + ld b,(ix+SK_B) + ld e,(ix+SK_E) + ld d,(ix+SK_D) + ld l,(ix+SK_L) + ld h,(ix+SK_H) + + ld ix,SK_SIZE + add ix,sp + ld sp,ix + ret + + + ;* International keyboard layout version + +;0: 76543210 +;1: ......98 +;2: BA...... +;3: JIHGFEDC +;4: RQPONMLK +;5: ZYXWVUTS +;6: .... CAPS GRAPH CTRL SHIFT +;Numeric: +;9: 43210... +;10: ...98765 + +SK_INTERNATIONAL: + + ;* 0-7 + + ld a,(ix+SK_ROW_0) ;76543210 + ld (ix+SK_B),a + + ;* 8-F + + ld a,(ix+SK_ROW_1) + and 00000011b + ld b,a ;......89 + + ld a,(ix+SK_ROW_2) ;BA...... + rrca + rrca + rrca + rrca + and 00001100b ;....BA.. + or b + ld b,a ;....BA89 + + ld a,(ix+SK_ROW_3) + rlca + rlca + rlca + rlca + ld c,a ;FEDCJIHG + and 11110000b ;FEDC.... + or b ;FEDCBA89 + + ld (ix+SK_E),a + + ;* G-N + + ld a,c + and 00001111b ;....JIHG + ld b,a + + ld a,(ix+SK_ROW_4) + rlca + rlca + rlca + rlca + ld c,a ;NMLKRQPO + and 11110000b ;NMLK.... + or b ;NMLKJIHG + + ld (ix+SK_D),a + + ;* O-V + + ld a,c + and 00001111b ;....RQPO + ld b,a + + ld a,(ix+SK_ROW_5) + rlca + rlca + rlca + rlca + ld c,a ;VUTSZYXW + and 11110000b ;VUTS.... + or b ;VUTSRQPO + + ld (ix+SK_L),a + + ;* W-Z + + ld a,c + and 00001111b ;....ZYXW + ld (ix+SK_H),a + ld h,a + +SK_COMMON: + ;Input: H = (SK_H) + + ;* CAPS-GRAPH-CTRL-SHIFT + + ld a,(ix+SK_ROW_6) + rlca + rlca + rlca + rlca + and 11110000b ;CAPS-GRAPH-CTRL-SHIFT-ZYXW + or h + + ld (ix+SK_H),a + + ;* Numeric keyboard + + ld a,(ix+SK_ROW_9) ;43210... from numeric keyboard + rrca + rrca + rrca + and 00011111b + ld b,a ;...43210 from numeric keyboard + + ld a,(ix+SK_ROW_10) ;...98765 from numeric keyboard + rlca + rlca + rlca + rlca + rlca + ld c,a ;C = 765...98, we'll use it later + and 11100000b ;765..... from numeric keyboard + or b ;76543210 from numeric keyboard + + or (ix+SK_B) ;76543210 from either the regular or the numeric keyboard + ld (ix+SK_B),a + + ld a,c + and 00000011b ;......98 from numeric keyboard + or (ix+SK_E) + ld (ix+SK_E),a ;FEDCBA98, with 98 from either the regular or the numeric keyboard + + ret + + + ;* Russian keyboard layout version + +;0: 654321.9 +;1: V.H..087 +;2: IF...B.. +;3: O.RPAUWS +;4: KJZ.TXDL +;5: QN.CMGEY +;6: .... CAPS GRAPH CTRL SHIFT +;Numeric: +;9: 43210... +;10: ...98765 + +SK_RUSSIAN: + ld a,(ix+SK_ROW_0) + ld c,a + ld b,(ix+SK_ROW_1) + ld e,0 + + and 11111100b ;654321.. + + srl b ;Cy = 7 + rra ;7654321. + srl a ;.7654321 + + srl c ;Cy = 9 + rl e ;E = .......9 + + srl b ;Cy = 8 + rl e ;E = ......98 + + srl b ;Cy = 0 + rl a ;76543210 + + ld (ix+SK_B),a + ld (ix+SK_E),e + + ;I'm sorry but that's it, only 9 disk image files supported in Russian keyboards. + ;Pull request implementing the (hellish) conversion of the rest of the keys will be welcome. + + xor a + ld (ix+SK_D),a + ld (ix+SK_L),a + ld (ix+SK_H),a + + ld h,a + jp SK_COMMON + + + ;Input: HL = First work area address, B=Rows count, C=First row + ;Output: HL = Last work area address used + 1 +SK_GET_ROWS: + ld a,c + call SNSKEY + cpl + ld (hl),a + inc hl + inc c + djnz SK_GET_ROWS + ret + + ;A clone of the SNSMAT routine in main BIOS +SNSKEY: + push bc + ld c,a + di + in a,(0AAh) + and 0F0h + add a,c + out (0AAh),a + ei + in a,(0A9h) + pop bc + ret +SCEND:: + +NEWKEY EQU 0FBE5H +CAPST EQU 0FCABH +KANAST EQU 0FCACH +CLIKSW EQU 0F3DBH +KILBUF EQU 0156H +CHGET EQU 09FH + + ;Returns A=1 if we have a Russian keyboard, A=0 otherwise +CHECK_IS_RUSSIAN: ; in case of ZF + DI + CALL KILBUF + LD HL,(CAPST) + LD A,(CLIKSW) + PUSH AF + PUSH HL + XOR A + LD (KANAST),A ; KANA OFF + LD (CLIKSW),A ; Shut up! + DEC A + LD (CAPST),A ; CAPS ON + LD (NEWKEY+6),A ; No SHIFT, CTRL etc. + LD A,64 + LD B,7 + CALL 0D89H + POP HL + POP AF + LD (CLIKSW),A + LD (CAPST),HL + CALL CHGET + CP "J" + ld a,1 + RET z + dec a + ret + + + ;Read key status from RAM. + ;Out: Z if status read ok, NZ if not + ; BEDLH = same as SCANKEYS (if Z) + +SCANKEYS_RAM: + ld b,a + ld hl,SCANKEYS_RAM_BASE + ld de,RAMKEYSIG + call STRCOMP + ld a,b + ret nz + + push af + xor a + ld (SCANKEYS_RAM_BASE),a + ld a,(SCANKEYS_RAM_BASE+17) ;After signature, which is 17 bytes long including terminator + ld b,a + ld de,(SCANKEYS_RAM_BASE+18) + ld hl,(SCANKEYS_RAM_BASE+20) + pop af + ret + +RAMKEYSIG: db "NEXTOR_BOOT_KEYS",0 + ALIGN 436Ch FDEL: CALLDOS 13h ;;Delete file (FCB) ; @@ -459,9 +835,10 @@ INIT2: call CHK_DUP ;Will just POP and RET if slot already processed + call DO_KEYS_INIT + call DISABLE_KEY ret nz - ; if 0 ;; If 0, will boot on MSX1 machine (with calendar clock problem). ld a,(VERSION) @@ -495,6 +872,9 @@ endif ; I am the first disk cartridge. ; call INITVARS + + ld a,CLS + call CHPUT ; ; I can be the master. Check if disk system can start up. ; @@ -509,11 +889,11 @@ endif COMPAR ; kill the disk system. jr nz,KILL_DISK ; ; - ld a,6 ;Scan 6th row - call SNSMAT + ld a,(BOOTKEYS##+4) + and 00010000b di - rrca ;If SHIFT key is pressed - jr c,NOTKILL ; kill the disk system + rrca + jr z,NOTKILL ;If SHIFT key is pressed, kill the disk system ; KILL_DISK: ld a,(DISKID) @@ -521,17 +901,6 @@ KILL_DISK: jr nz,NOFFKILL ;Needed if the first kernel was MSX-DOS xor a NOFFKILL: - ;ld d,a - - ;xor a - ;call SNSMAT ;Scan "4" key - ;and 00010000b ;Z if pressed - ;ld a,d - ;jr z,KILL_DISK2 - ;ld a,BELL ;Tell user scanning is over - ;OUTCHR - ;ld a,-1 -KILL_DISK2: ld (PROCNM+8),a ld b,a ld a,-1 ;Kill the entire disk system. @@ -544,11 +913,11 @@ if STURBO ld a,(VERSION) cp 3 ;MSXturboR? ret c ;no - xor a ;Scan "1" key - call SNSMAT - bit 1,a + + ld a,(BOOTKEYS##) + and 00000010b ;Scan "1" key ld a,82h ;If "1" key is NOT being pressed - call nz,CHGCPU ; switch to Super-Turbo mode. + call z,CHGCPU ; switch to Super-Turbo mode. endif ;;if HYBRID ;; xor a @@ -607,11 +976,13 @@ INIHOOK: inc hl ld (hl),0C9h ;instruction code for "RET" ; - ld a,6 ;scan 6th row - call SNSMAT - di - and 00000010b ;extract CTRL key status; Z := pressed - xor 00000010b + ld a,(BOOTKEYS##+4) ;Check CTRL key + and 00100000b + rrca + rrca + rrca + rrca + xor 2 ld (TARGET##),a ; ld a,BELL ;tell user scanning is over @@ -622,7 +993,7 @@ VER_CHK: ; ; I am not the first. check to see if I can be the new master. ; - ld a,(PROCNM+9) ;If in disk emulation mode, disable myself + ld a,(IN_EMU##) ;If in disk emulation mode, disable myself or a ret nz @@ -704,7 +1075,7 @@ SLAVE: ;PROCNM+6: Number of drives actually assigned ;PROCNM+7: 1 to boot in DOS 1 mode ;PROCNM+8: 1 if device-based driver - ;PROCNM+9: 1 if in disk emulation mode (set by AUTODRV in partit.mac) + ;IN_EMU: 1 if in disk emulation mode (set by AUTODRV in partit.mac) ;PROCNM+10: <>0 if the driver provides configuration ;Calculate how many work area space can be allocated, it will be: @@ -1315,8 +1686,18 @@ endif ; REBOOT:: ld a,(BOOT_DRV##) + push af + xor a + jr DO_BOOT ; FIRST_BOOT: + push af + ld a,0FFh + +DO_BOOT: + ld (IS_FIRST_BOOT##),a + pop af + ld sp,BOOTAD+512 ;Must have stack in safe place. push hl ld hl,BASIC ;Set jump address when MSXDOS cannot @@ -1352,17 +1733,12 @@ endif call SET_XFER ; then call the boot sector with scf ; carry flag set to boot up MSXDOS. ; -JP_BOOT_SEC: - ld hl,DISKVECT## ;Jump into the MSX-DOS boot code - ld de,$DOSON## ; with necessary parameters in hand. - ld a,(NOTFIRST##) - jp BOOTAD+1Eh -; + jp JP_BOOT_SEC subttl Set up for disk BASIC IPLSTR: - defb 'RUN"\AUTOEXEC.BAS' + defb 'RUN',34,'\AUTOEXEC.BAS' NULL_CMD: defb 0 NEW_CMD: @@ -2119,6 +2495,42 @@ GSLT_SLTTBL: PRINTL INIT,%($-$$INIT) + + ;Scan and store boot keys and check if keyboard is Russian if that hasn't been done yet + +DO_KEYS_INIT: + ld a,(HAVE_KEYS##) + or a + ret nz + + call CHECK_IS_RUSSIAN + ld (I_AM_RUSSIAN##),a + + call SCANKEYS_RAM + jr z,DO_KEYS_INIT2 + call SCANKEYS + + ld a,(KEYS_INV_0) + and 00111110b + xor b + ld b,a + + ld a,(KEYS_INV_1) + and 00110000b + xor h + ld h,a + +DO_KEYS_INIT2: + ld a,b + ld (BOOTKEYS##),a + ld (BOOTKEYS##+1),de + ld (BOOTKEYS##+3),hl + + ld a,0FFh + ld (HAVE_KEYS##),a + ret + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; End of hole. @@ -2176,6 +2588,21 @@ SETDEFDPB: ALIGN 5006h SNEXT: CALLDOS 12h ;;Search for next (FCB) ; + +; Compare zero terminated strings pointed by HL and DE +; Return Z if they are equal, NZ if not +; Modifies AF, HL, DE + +STRCOMP: + ld a,(de) + cp (hl) + ret nz + or a + ret z + inc hl + inc de + jr STRCOMP + ALIGN 501Eh FSIZE: CALLDOS 23h ;;Get file size (FCB) ; @@ -2190,6 +2617,14 @@ COUNTDRV: call ?C4PBK## ret +JP_BOOT_SEC: + call SBDAVEC## + + ld hl,DISKVECT## ;Jump into the MSX-DOS boot code + ld de,$DOSON## ; with necessary parameters in hand. + ld a,(NOTFIRST##) + jp BOOTAD+1Eh + ALIGN 504Eh LOGIN: CALLDOS 18h ;Get login vector ; @@ -2270,14 +2705,12 @@ CRLF: ld e,CR if HYBRID ; CHECK_1KEY: - xor a ;If "1" or "2" key is pressed at THIS (oops) moment - call SNSMAT ; force MSX-DOS1 - and 00000110b - cp 00000110b ; + ld a,(BOOTKEYS##) ;If "1" or "2" key is pressed at THIS (oops) moment, force MSX-DOS1 + and 00000110b ;===== start mod DOS2.50 (build type) jr nz,OLDDOS ;OLDDOS will do the rest of work. - ld a,(PROCNM+9) ;If in disk emulation mode (set by AUTODRV from DOSINIT), + ld a,(IN_EMU##) ;If in disk emulation mode (set by AUTODRV from DOSINIT), or a ;switch to DOS 1 mode jr nz,OLDDOS @@ -2285,7 +2718,7 @@ if STURBO ld a,(VERSION) cp 3 ;MSXturboR? ret c ;no - ld a,(NUMKEYS) ;4 key pressed? + ld a,(BOOTKEYS##) ;4 key pressed? and 00010000b ld a,81h jp nz,CHGCPU @@ -2325,7 +2758,7 @@ if STURBO cp 3 ;MSXturboR? jr c,NOCHCPU - ld a,(NUMKEYS) + ld a,(BOOTKEYS##) ;2 key pressed? and 00000100b ld a,81h jr nz,DOCHCPU @@ -2371,7 +2804,7 @@ endif ;the work area is already created in BUF_1, ;so just jump to area relocation procedure. - ld a,(PROCNM+9) + ld a,(IN_EMU##) or a jr nz,MK_EMU_TBL @@ -2395,9 +2828,7 @@ MK_EMU_TBL: ;then just copy from BUF_1 to it. ;Otherwise allocate space in page 3. - ld ix,0F980h ;BUF_1## - ld l,(ix+16) - ld h,(ix+17) + ld hl,(EMU_WK_AREA##) ld a,h or l jr nz,OK_EMU_WK @@ -2408,7 +2839,7 @@ MK_EMU_TBL: OK_EMU_WK: push hl ex de,hl - ld hl,0F980h ;BUF_1## + ld hl,EMU_TMP## ld bc,16 call MEMCPY @@ -2416,17 +2847,6 @@ OK_EMU_WK: set 7,(hl) ;Disk emulation mode flag ld (DVB_TABLE##),hl - - ld hl,NXT7## - ld de,NXT7##+1 - ld bc,6 - ld (hl),0 - ldir - ld hl,TMP_FROOT## - ld de,TMP_FROOT##+1 - ld bc,11 - ld (hl),0 - ldir jr END_DVB_TBL @@ -2574,10 +2994,8 @@ else if STURBO ; CHECK_1KEY: - xor a ;If "1" key is pressed at THIS (oops) moment - call SNSMAT ; no change mode. - bit 1,a - ret z + ld a,(BOOTKEYS##) ;If "1" key is pressed at THIS (oops) moment, no change mode. + ret nz ld a,(VERSION) cp 3 ;MSXturboR? ret c ;no @@ -2749,13 +3167,6 @@ GTIME: CALLDOS 2Ch ;Get time STIME: CALLDOS 2Dh ;Set time ; -SCAN_5_KEY: - xor a - call SNSMAT - and 00100000b - xor 00100000b ;A=00100000b if "5" key pressed, 0 if not - ret - ALIGN 55FFh VERIFY: CALLDOS 2Eh ;Set/reset verify flag ; @@ -3190,17 +3601,13 @@ GO_DOS2: ;(so don't run NEXTOR.SYS, AUTOEXEC.BAS or the boot sector code) TO_BASIC_REQUIRED:: - push bc - push ix - push iy - ld ix,SNSMAT - ld iy,(0FCC1h-1) - ld a,0 ;Do not try to boot from disk if "3" key is pressed - call CALSLT - and 8 - pop iy - pop ix - pop bc + ld a,(IS_FIRST_BOOT##) + inc a + ret nz + + ld a,(BOOTKEYS##) + and 00001000b + xor 00001000b ret GET_DISKID_HL: @@ -3246,7 +3653,8 @@ DO_LDIR: CALL_DV_INIT: push af push bc - call SCAN_5_KEY + ld a,(BOOTKEYS##) + and 00100000b pop bc ld c,a pop af diff --git a/source/kernel/bank1/dosinit.mac b/source/kernel/bank1/dosinit.mac index fdc2d834..de6730e8 100644 --- a/source/kernel/bank1/dosinit.mac +++ b/source/kernel/bank1/dosinit.mac @@ -449,7 +449,16 @@ map_jump_loop: ld e,(hl) ;Get next offset from table inc bc jr map_jump_loop ;Loop for next one. ; -map_jumps_done: pop de ;Get RAM code address back +map_jumps_done: + ld hl,_IRQ + pop de ;Get RAM code address back + add hl,de + ld a,0C3h + ld ($IRQ##),a + ld a,l + ld ($IRQ##+1),a + ld a,h + ld ($IRQ##+2),a ; ; +++++ ADJUST ALL ABSOLUTE REFERENCES +++++ ; @@ -2022,7 +2031,7 @@ P3_OFFSET_TAB: defw _GO_DRV defw _JP_VECT ; - defw _IRQ + ;defw _IRQ ;We set this one manually ; defw _RDSLT defw _WRSLT diff --git a/source/kernel/bank1/mapinit.mac b/source/kernel/bank1/mapinit.mac index 253fe858..d4a03d42 100644 --- a/source/kernel/bank1/mapinit.mac +++ b/source/kernel/bank1/mapinit.mac @@ -13,7 +13,6 @@ P2_REG equ 0FEh P3_REG equ 0FFh MSXVER equ 002Dh -SNSMAT equ 0141h ; ; ;----------------------------------------------------------------------------- @@ -147,8 +146,8 @@ if (BUILTIN AND STURBO) ld a,b jr nz,NOTR2 ld b,a - ld a,(NUMKEYS) - and 00010000b + ld a,(BOOTKEYS##) + and 00010000b ;4 key pressed? ld a,b jr nz,NOTR2 sub 4 @@ -183,7 +182,7 @@ if (BUILTIN AND STURBO) ;;if 1 ;;HYBRID ;===== end mod DOS2.50 - ld a,(NUMKEYS) + ld a,(BOOTKEYS##) and 00010000b ld a,6 jr nz,SYSSEGSCOUNT @@ -251,13 +250,13 @@ if (BUILTIN AND STURBO) jr nz,NOTURBOR ;ld d,a - ld a,(NUMKEYS) + ld a,(BOOTKEYS##) and 00010000b - ;ld a,d ;On Turbo-R, the "6" key causes - jr nz,NOTURBOR ;the bigger mapper to be used as primary + ;ld a,d ;On Turbo-R, the "4" key causes + jr nz,NOTURBOR ;the bigger mapper to be used as primary dec hl ;Always mark last 4 - dec (hl) ; segments as allocated + dec (hl) ; segments as allocated dec hl ; to system. dec (hl) dec hl @@ -312,13 +311,6 @@ MAP_SCAN:: ; ; ***** LOOP TO FIND MAPPERS AND BUILD UP TEMPORARY MAPPER RECORDS ***** ; - ld d,a - xor a - call SNSMAT - cpl - ld (NUMKEYS),a - ld a,d - di ;Remember current page-2 slot push af ; for fail safe. ; @@ -353,9 +345,9 @@ sec_slot_loop: push hl jr nz,NO_PRIM_INTERNAL ld d,a - ld a,(NUMKEYS) + ld a,(BOOTKEYS##) and 00010000b - ld a,d ;On Turbo-R, the "5" key causes + ld a,d ;On Turbo-R, the "4" key causes jr nz,NO_PRIM_INTERNAL ;the bigger mapper to be used as primary ;===== start mod DOS2.50 (build type) @@ -745,7 +737,8 @@ MAPBIO3: EXB_NEX: ;WIP... ; -; Call the EXTBIO routine of Nextor kernels other than the master one +; Call the EXTBIO routine of Nextor kernels other than the master one +; Out: D'=1 if system hook must be called, 0 otherwise ; exx ex af,af' @@ -774,8 +767,6 @@ EXB_LOOP: cp c jr z,EXB_DJNZ ;Skip master kernel as we have processed it already - ld a,c - ld h,40h push ix push iy ex af,af' @@ -784,11 +775,14 @@ EXB_LOOP: push bc push de push hl + ld a,(ix) + and 10001111b + ld h,40h call ENASLT ld hl,DV_EXTBIO## ld (BK4_ADD##),hl exx - ld de,0100h + ld de,0100h ;Pass D'=1 by default exx pop hl pop de @@ -816,6 +810,7 @@ EXB_DJNZ: jr EXB_LOOP EXB_RAM_FIN: + set 0,d ;System hook must be called ex af,af' exx push af diff --git a/source/kernel/bank2/err.mac b/source/kernel/bank2/err.mac index abf1449b..cf493a3d 100644 --- a/source/kernel/bank2/err.mac +++ b/source/kernel/bank2/err.mac @@ -86,18 +86,18 @@ read_error: ;===== end add DOS2.50 set 3,c sector_invalid: - push hl - push bc - ld bc,UD_PHYS## ;Get physical unit number from - add hl,bc ; the unit descriptor into - pop bc ; register B. - ld b,(hl) - inc hl - ld a,(hl) ;If UD_TIME is non-zero (UPB - or a ; is defined) then set it to - jr z,err_no_upb ; one to force a BUILD UPB - ld (hl),1 ; before next access. -err_no_upb: pop hl + push ix + push hl + pop ix + ld b,(ix+UD_PHYS##) + bit UF_DBD,(ix+UD_DFLAGS##) + jr nz,err_no_upb + ld a,(ix+UD_TIME##) ;If UD_TIME is non-zero (UPB is defined) then set it to + or a ; one to force a BUILD UPB before next access. + jr z,err_no_upb + ld (ix+UD_TIME##),1 +err_no_upb: + pop ix ; pop af cp .STOP## ;If STOP key pressed then abort diff --git a/source/kernel/bank2/files.mac b/source/kernel/bank2/files.mac index 91277283..8191cd3c 100644 --- a/source/kernel/bank2/files.mac +++ b/source/kernel/bank2/files.mac @@ -59,6 +59,8 @@ ; PROC RDWR_FAB ; + if 1 + ex af,af' ld a,(RW_LEVEL##) cp 1 @@ -84,14 +86,14 @@ push hl ld hl,(RW_OVER##+18) push hl - ;ld hl,(PHYS_UNIT##) - ;push hl OKLEVEL: inc a ld (RW_LEVEL##),a ex af,af' + endif + bit MD_DEV,(ix+FAB_MODE##) ;Jump to handle device reads jp nz,rdwr_device ; and writes separately. ; @@ -139,15 +141,13 @@ rdwr_error: or a rdwr_ret_ok: xor a ; of file error. RDWR_END: + if 1 + ex af,af' ld a,(RW_LEVEL##) cp 2 jr nz,OKLEVEL2 - ;ex af,af' - ;pop hl - ;ld a,l - ;ld (PHYS_UNIT##),a pop hl ld (RW_OVER##+18),hl pop hl @@ -168,30 +168,27 @@ RDWR_END: ld (RW_OVER##+2),hl pop hl ld (RW_OVER##),hl - ;ex af,af' OKLEVEL2: dec a ld (RW_LEVEL##),a ex af,af' + endif + RDWR_END2: ret ; ; ---------------------------------------- ; rdwr_device: - call rdwrdev2 - jp RDWR_END - -rdwrdev2: ld h,a ;Store the paging mode and RFM_PG ; flag in the FAB ready for ld (ix+FAB_PG##),a ; passing to GET_SEGMENT ; ld a,b ;Do nothing if zero bytes or c ; requested - ret z + jr z,RDWR_END ; bit RF_READ,h jr nz,read_device ;Skip if read. diff --git a/source/kernel/bank2/rw.mac b/source/kernel/bank2/rw.mac index 9e43ee65..ee46c20d 100644 --- a/source/kernel/bank2/rw.mac +++ b/source/kernel/bank2/rw.mac @@ -140,11 +140,17 @@ abs_rw_dorw: pcall INV_UD ; buffers for this drive ;If the disk has actually a FAT12 or FAT16 filesystem, - ;set unit descriptor as having UPB but needing validation; - ;otherwise, set unit descriptor as not having UPB. + ;and it's NOT a device-based driver, + ;set unit descriptor as having UPB + ;but needing validation; otherwise (no FAT filesystem), + ;set unit descriptor as not having UPB. - ld de,UD_FLAGS## + ld de,UD_DFLAGS## add hl,de + bit UF_DBD,(hl) + jr nz,abs_common_end + + dec hl ;UD_FLAGS ld a,(hl) and UFM_F2+UFM_F6 ld a,0 diff --git a/source/kernel/bank2/val.mac b/source/kernel/bank2/val.mac index 65b55968..3b22b0e1 100644 --- a/source/kernel/bank2/val.mac +++ b/source/kernel/bank2/val.mac @@ -619,20 +619,26 @@ NEW_BOOT_SZ equ $-NEW_BOOT ; --------------------------------- ; pop hl - call CHECK_LOCK ;Skip all if disk is locked + push hl + push hl + ld bc,UD_TIME## ; unit descriptor and skip if + add hl,bc ; it is zero since this means + ld a,(hl) ; that there is no current + pop hl + or a ; UPB for this unit. + jr z,valfib2 + call IS_FIXED_OR_LOCKED ;Skip all if disk is fixed or locked ld a,0 - ret nz - push hl + pop hl + ret c + push hl +valfib2: dec b ;Skip if B<>1 jr nz,not_opened ; pop hl - - ;ld a,(MFLAGS##) - ;and 2 - ;ld a,0 - ;ret nz ;Skip if "no check media change" flag is set + push hl wfile_loop: push ix @@ -755,9 +761,9 @@ if 1 dec a ;If timeout >2 then assume jr nz,got_old_volid ; same UPB. Otherwise 2. endif - call CHECK_LOCK ;Assume disk unchanged - jr nz,got_old_volid ;if drive is locked - call CHECK_MNT ;or mounted + call IS_FIXED_OR_LOCKED ;Assume disk unchanged + jr c,got_old_volid ;if drive is locked + call CHECK_MNT ;or has a file mounted jr nz,got_old_volid call MEDIA_CHECK ;Do a media check call. @@ -805,22 +811,37 @@ no_dos_disk: pop ix ;Restore FIB pointer ret -; This subroutine will check if a disk is locked. -; If so, and if there is no UPB for the drive, it will generate a new UPB. -; Otherwise (drive not locked, or UPB already exists), it will do nothing. +; This subroutine will check if a device is either fixed, or removable but locked. ; ; Entry: HL = Unit descriptor -; Returns: NZ set it drive is locked, Z otherwise +; Returns: C it drive is fixed or locked, NC otherwise ; Corrupts: none -CHECK_LOCK: +IS_FIXED_OR_LOCKED: push hl ex (sp),ix - bit UF_LCK,(ix+UD_FLAGS##) + push bc + ld b,a + + ld a,(ix+UD_DFLAGS##) + and UFM_DB+UFM_RM + cp UFM_DB ;Device-based + not removable? + scf + jr z,CHKLCK2 + + bit UF_LCK,(ix+UD_FLAGS##) + scf + jr nz,CHKLCK2 + or a + +CHKLCK2: + ld a,b + pop bc ex (sp),ix pop hl ret + CHECK_MNT: push hl ex (sp),ix @@ -890,26 +911,34 @@ VAL_SAME: ; push af - call CHECK_LOCK - jr nz,pop_af_ret -if 1 - call UD_TICK ;Make UD_TIME up to date. -endif push de push hl ld de,UD_TIME## ;HL -> UD_TIME byte of unit add hl,de ; descriptor. - ld a,2 - cp (hl) ;If UD_TIME>2 then the timeout - pop hl ; has not expired so return - jr c,pop_deaf_ret ; without further checking. -; - push bc ;If UD_TIME=2 then do a media + ld a,(hl) + cp 2 + pop hl + push bc + jr c,chk_same_do ;If UD_TIME=0 or 1 there's no UPB so build one + + call IS_FIXED_OR_LOCKED ;If fixed or locked media do nothing more + jr c,not_changed + + call UD_TICK ;Make UD_TIME up to date. + cp 3 ;If UD_TIME>2 then the timeout + jr nc,not_changed ; has not expired so return without further checking. + + cp 2 ;If UD_TIME=2 then do a media call z,MEDIA_CHECK ; check call, otherwise assume jr z,not_changed ; that disk has changed. ; +chk_same_do: push ix ;Get a new UPB for this unit chk_same_loop: call DO_MEDIA_CHANGE ; from the unit handler. + + ld ix,UPB_BUF## + call NEW_UPB + call TEST_SAME_DISK ;Test whether volume-id's are jr z,same_disk ; the same and jump if so. ; @@ -996,7 +1025,7 @@ MCHK2: pop hl bit UF_DBD,a jr nz,MCHECK2 - ld a,1 ;Return C & NZ + ld a,1 ;Return C & NZ (not sure, assume changed) if not a device-based driver or a scf ret @@ -1030,7 +1059,12 @@ MCHECK2: xor a jr MCHECKEND ;are reported as "changed" MCHECK_NOERR: + ld a,(ix+26h) + and 28h + cp 28h + jr z,MCHK_NODIRTYFLAG ld (ix+26h),0 ;Clear dirty disk flag for the checksum +MCHK_NODIRTYFLAG: ld b,0 ld hl,0 ld ix,UPB_BUF## @@ -1256,23 +1290,14 @@ DO_MEDIA_CHANGE: push de push hl push iy - ex af,af' - push af - ex af,af' ld b,(ix+UD_SLOT##) ld c,(ix+UD_SEG##) ld d,(ix+UD_DI##) ld e,(ix+UD_LI##) ld ix,UNMAPALL## - ld (BK4_ADD##),ix - ld ix,?CALL4## - ld iy,(MASTER_SLOT##-1) - call CALSLT## + call CALL4_PRESERVE_ALT - ex af,af' - pop af - ex af,af' pop iy pop hl pop de @@ -1395,22 +1420,22 @@ build_upb_do_findpart: push ix push iy + ld d,0 ld ix,AUTO_ASPART## - ld (BK4_ADD##),ix - ld ix,?CALL4## - ld iy,(MASTER_SLOT##-1) - call CALSLT## + call CALL4_PRESERVE_ALT pop iy pop ix + pop hl ;Restore unit desciptor or a jp nz,build_upb_notfind + push hl ex (sp),ix set UF_FOK,(ix+UD_DFLAGS##) ex (sp),ix - pop hl ;Restore unit desciptor + pop hl ;Read boot sector in UPB_BUF, it will be needed later @@ -1427,8 +1452,8 @@ build_upb_do_findpart: pop hl jr nz,build_upb_err - jp found_upb - + push hl + build_upb_dof2: ex (sp),ix set UF_FOK,(ix+UD_DFLAGS##) @@ -1605,8 +1630,6 @@ MKDPB_DEVBASED: push iy ex af,af' push af - ld de,MKDPB## - ld (BK4_ADD##),de push ix ex (sp),hl pop ix @@ -1614,9 +1637,8 @@ MKDPB_DEVBASED: ld d,(ix+UD_DPB##+1) inc de - ld iy,(MASTER_SLOT##-1) - ld ix,?C4PBK## - call CALSLT## ;Since we don't know state of page 1 when KBDOS is called. + ld ix,MKDPB## + call CALL4_PRESERVE_ALT ;Since we don't know state of page 1 when KBDOS is called. pop af ex af,af' @@ -1867,6 +1889,10 @@ endif push hl ld hl,0 + ld a,(ix+26h) + and 28h + cp 28h + jr z,NUPBL ld (ix+26h),0 ;Clear dirty disk flag for the checksum NUPBL: ld e,(ix) ld d,(ix+1) @@ -3365,6 +3391,35 @@ COMP16: sub e ret + ;Call a routine in bank 4 of master slot, preserving alternate registers. + ;Input: IX=Routine to call +CALL4_PRESERVE_ALT: + exx + ex af,af' + push af + push bc + push de + push hl + ex af,af' + exx + + ld (BK4_ADD##),ix + ld ix,?C4PBK## + ld iy,(MASTER_SLOT##-1) + call CALSLT## + + exx + ex af,af' + pop hl + pop de + pop bc + pop af + ex af,af' + exx + + ret + + FAT16_S: db "FAT16" finish diff --git a/source/kernel/bank3/dos1ker.mac b/source/kernel/bank3/dos1ker.mac index 257636ee..7b406314 100644 --- a/source/kernel/bank3/dos1ker.mac +++ b/source/kernel/bank3/dos1ker.mac @@ -4191,8 +4191,7 @@ T5696: defb 080H,09AH,"E" ,"A" ,08EH,"A" ,08FH,080H ; Inputs ; Outputs ________________________ -A56D0: - jp NODOS1F +A56D0: ;xor a ;ld b,a ;ret @@ -4202,20 +4201,21 @@ A56D0: ; Outputs ________________________ A56D3: - call DO_BDOS - ;ei - ;ld a,1 - ld (YF306),a ; assume CP/M compatible call + ei + ld (YF306),a ; save A (required for extra functions) ld a,c cp 031H ; valid BDOS function ? - jr nc,A56D0 ; nope, unsupported BDOS call + jp nc,NODOS1F ; nope, unsupported BDOS call sub 011H ; Search First BDOS function ? jr nz,A56E6 ld (YF307),de ; yep, save address FCB for Search Next A56E6: dec a ; Search Next BDOS function ? jr nz,A56ED ld de,(YF307) ; yep, get saved address FCB Search First -A56ED: push hl +A56ED: + ld a,1 + ld (YF306),a ; assume CP/M compatible call + push hl ld hl,T5700 ex (sp),hl ; after BDOS routine, fill HL in a CP/M compatible manner push hl @@ -4947,7 +4947,7 @@ I5B0F: DEFB LOW RDSLT,C63F4-C63F4 T5B1A: defb 0,"AUTOEXECBAS",0 -T5B27: defb 'RUN"AUTOEXEC.BAS',0 +T5B27: defb 'RUN',34,'AUTOEXEC.BAS',0 T5B38: defw A5B92 ; start DiskBASIC in direct mode @@ -8719,7 +8719,13 @@ A738E: add hl,sp ; Outputs ________________________ ; Remark is copied to 0F1C9H -A7397: call XF36B ; enable ram on page 1 +A7397: + call XF368 ; enable system diskrom + jp KSTROUT + ds 16-6 + + if 0 + call XF36B ; enable ram on page 1 ld a,(de) call XF368 ; enable system diskrom inc de @@ -8727,6 +8733,7 @@ A7397: call XF36B ; enable ram on page 1 ret z ; end of string, quit call A53A8 ; console output jr A7397 ; next + endif ; Subroutine XFER (transfer) ; Inputs HL = source address, DE = destition address, BC = size @@ -8789,29 +8796,18 @@ A7397: call XF36B ; enable ram on page 1 defb 31,28,31,30,31,30,31,31,30,31,30,31 +BOOTKEYS equ 0F992h ;Defined in kvar.mac + TO_BASIC_REQUIRED: LD A,0FFH LD (YF246),A ; dirsector buffer is invalid - push bc - push ix - push iy - ld ix,SNSMAT - ld iy,(0FCC1h-1) - ld a,0 ;Do not try to boot from disk if "3" key is pressed - call CALSLT - and 8 - pop iy - pop ix - pop bc + ld a,(BOOTKEYS) + and 00001000b ;Do not try to boot from disk if "3" key is pressed LD A,(DEFDPB##+1) LD C,A - jr nz,TBR2 - - scf - ret - -TBR2: - or a + scf + ret nz + or a ret TOBASREQ2: @@ -8824,6 +8820,7 @@ TOBASREQ2: NEWCMD: db 'NEW',0 ; Entry point for non DOS 1 function call +; The value of A is in (YF306) NODOS1F: push hl @@ -8841,7 +8838,7 @@ NODOS1F_LOOP: ld h,(hl) ld l,a ld (BK4_ADD##),hl - ld a,(BUF9##) + ld a,(YF306) ld c,a pop hl jp ?C4PBK## @@ -8857,15 +8854,6 @@ NODOS1F_ERR: ld b,a ret -; Save register A on BDOS call (it is normally corrupted), -; this is needed for the additional function calls. - -DO_BDOS: - ld (BUF9##),a - ei - ld a,1 - ret - ; Entries for additional function calls, ; they are all in bank 4 @@ -9090,6 +9078,7 @@ NEW_ERRS: defb 'Partition already in use', 0 defb 'Illegal in emulation', 0 + ;Allocate page 3 memory for the FAT buffer of a drive. ;Input: IX = pointer to DPB ; HL = Amount of memory to allocate @@ -9102,7 +9091,7 @@ NEW_ERRS: ;many games to not work) ALLFBUF: - ld a,(PROCNM+9) + ld a,(IN_EMU##) or a jp z,A5EC8 ;Jump to actual allocation if not in emulation mode... @@ -9134,6 +9123,34 @@ TRRAMEND: ld a,(H.STKE+0) ret + + ;STROUT routine residing in kernel ROM, borrowed from the DOS 2 kernel. + ;Replacing the original 16 bytes code with a simple call to this routine + ;gives us 10 precious bytes in page 3 that we can use for Nextor specific + ;functionality. + +KSTROUT: + ld hl,1Ah+0C9h*256 ;"LD A,(DE)" then "RET" + push hl + call RD_MEM + pop hl + cp "$" + ret z + push de + ld e,a + call A53A8 ; console output + pop de + inc de + jr KSTROUT +; +RD_MEM: + ld hl,XF368 ; enable system diskrom + push hl + ld hl,4 + add hl,sp + push hl + jp XF36B ; enable system diskrom + ; DRV.MAC is to be placed here. KER1_END:: diff --git a/source/kernel/bank4/partit.mac b/source/kernel/bank4/partit.mac index 202a7dd9..4e39e744 100644 --- a/source/kernel/bank4/partit.mac +++ b/source/kernel/bank4/partit.mac @@ -8,12 +8,16 @@ INCLUDE b0labels.inc ; +EMU_RAM_ADDRESS equ 0A000h + DISKID equ 0FD99h -SNSMAT equ 0141h ;sense key matrix MBR_PSTART equ 01BEh ;Start of partition table in MBR MBR_PSIZE equ 16 ;Size of partition table entry +POFF_STATUS equ 0 ;Offset of status byte in p. table entry +POFF_CHS_START equ 1 POFF_TYPE equ 4 ;Offset of partition type in p. table entry +POFF_CHS_END equ 5 POFF_PSTART equ 8 ;Offset of partition start in p. table entry POFF_PSIZE equ 12 ;Offset of partition size in p. table entry PT_FAT12 equ 1 ;Partition type code for FAT12 @@ -72,11 +76,18 @@ CHPUT: ; D = Device index, 1 to 7 ; E = LUN index, 1 to 7 ; H = Primary partition number (1 to 4) +; bit 7: 0 = Get partition information +; 1 = Get partition table absolute sector ; L = Extended partition number (0 for primary entry in MBR) ; Returns: A = Error from DEV_RW or F_GDRVR, or .IPART; 0 if no error -; B = Partition type, 0 for non existing partition -; HLDE = Starting sector of partition -; IXIY = Partition size +; If "Get partition information": +; B = Partition type, 0 for non existing partition +; C = 80h if bootable partition +; HLDE = Starting sector of partition +; IXIY = Partition size +; If "Get partition table absolute sector": +; HLDE = Absolute sector that holds the partition table entry +; (0 for primary partitions) ; ; In case of disk error when reading the device, an error code will ; be returned. We cannot invoke the standard disk error handling routine, @@ -122,8 +133,9 @@ CHPUT: jp nc,UNEX_DEVL ld a,h - or a - ret z + and 01111111b + ;or a + jp z,UNEX_PART cp 5 jp nc,UNEX_PART @@ -146,6 +158,7 @@ CHPUT: ld bc,MBR_PSIZE ld a,h + and 01111111b PTENTRY_LOOP: dec a jr z,OK_PENTRY @@ -160,22 +173,30 @@ OK_PENTRY: or a jr nz,DO_EXTPAR + ld a,(ix+POFF_TYPE) + or a + jp z,UNEX_PART + ld b,a + + bit 7,h ;Partition table entry sector requested: it's always 0 for primary partitions + ld hl,0 + ld de,0 + ld a,0 + ret nz + ld e,(ix+POFF_PSIZE) ld d,(ix+POFF_PSIZE+1) ld l,(ix+POFF_PSIZE+2) ld h,(ix+POFF_PSIZE+3) push de push hl - ld b,(ix+POFF_TYPE) + ld c,(ix+POFF_STATUS) ld e,(ix+POFF_PSTART) ld d,(ix+POFF_PSTART+1) ld l,(ix+POFF_PSTART+2) ld h,(ix+POFF_PSTART+3) pop ix pop iy - ld a,b - or a - jp z,UNEX_PART xor a ret DO_EXTPAR: @@ -217,6 +238,9 @@ EXTP_LOOP: ; Get the base sector number for the primary entry ; and return + bit 7,h ;Partition table entry sector requested: return its sector + jr nz,EXTP_ENTRYADD + ld ix,($SECBUF##) ld bc,MBR_PSTART add ix,bc @@ -224,10 +248,12 @@ EXTP_LOOP: call UPDATE_SEC ld b,(ix+POFF_TYPE) + ld c,(ix+POFF_STATUS) ld e,(ix+POFF_PSIZE) ld d,(ix+POFF_PSIZE+1) ld l,(ix+POFF_PSIZE+2) ld h,(ix+POFF_PSIZE+3) +EXTP_ENTRYADD: push de push hl ld ix,TMP_SEC## @@ -449,11 +475,11 @@ GDRV_OK_ROM: PROC AUTODRV ; This routine automatically assigns devices and partitions to drives for -; device-based DOS 2.50 drivers. There are two versions, one for DOS 1 and +; device-based Nextor drivers. There are two versions, one for DOS 1 and ; another one for DOS 2, since the processing done in both cases is ; quite different. ; -; In both DOS 1 and DOS 2 modes AUTOASSIGN is called with A=1. +; In both DOS 1 and DOS 2 modes AUTO_ASSIGN (or AUTO_ASPART) is called with A=1. ; This causes the root directory of primary partitions to be scanned ; for a file named NEXT_DSK.DAT (only if the current controller is the ; primary controller); if found and its contents are valid, the whole @@ -461,7 +487,7 @@ GDRV_OK_ROM: ld hl,0 add hl,sp - ld (NXT7##),hl + ld (SPSAVE##),hl ld a,(DOS_VER##) or a jp nz,AUTODRV_DOS2 @@ -563,6 +589,7 @@ AUTODRV_DRVLOOP: push ix push iy ld b,1 + ld a,b call ASK_DRIVE_CONFIG pop iy pop ix @@ -570,7 +597,10 @@ AUTODRV_DRVLOOP: jr z,AUTODRV_DRVL3 dec a jr z,AUTODRV_DRVL2 ;Driver does not provide config for that drive + dec a + jp nz,AUTOD_EMU ;We entered disk emulation mode +AUTODRV_DRVL1: pop ix push ix ld a,-1 @@ -586,17 +616,13 @@ AUTODRV_DRVL2: push ix pop hl - ld a,1 ;????? + ld d,1 call AUTO_ASSIGN AUTODRV_DRVL3: cp 2 ;Did we enter disk emulation mode? - jr nz,NOEMU1 ;Yes: discard everything else and return - ld hl,(NXT7##) - ld sp,hl - ret + jp z,AUTOD_EMU ;Yes: discard everything else and return -NOEMU1: ld hl,(DVB_TABLE##) inc (hl) ;Increment size of table pop ix @@ -705,8 +731,9 @@ AUTOD_UDFND2: ld b,0 ld c,(ix+UD_REL##) + ld a,1 call ASK_DRIVE_CONFIG - dec a + cp 1 jr z,AUTOD_UDFND3 ;Driver did not provide config pop hl or a @@ -721,15 +748,12 @@ AUTOD_UDFND3: push ix pop hl - ld a,1 + ld d,1 call AUTO_ASSIGN cp 2 ;Did we enter disk emulation mode? - jr nz,NOEMU2 ;Yes: discard everything else and return - ld hl,(NXT7##) ;(note that we'll enter DOS 1 mode after returning) - ld sp,hl - ret -NOEMU2: + jp z,AUTOD_EMU ;Yes: discard everything else and return + ;(note that we'll enter DOS 1 mode after returning) pop hl ;Pointer in UNIT_TAB or a @@ -757,6 +781,13 @@ AUTOD_OK: djpnz AUTOD_LOOP jp SETNUMDRV + ;--- We entered disk emulation mode, so return immediately + +AUTOD_EMU: + ld hl,(SPSAVE##) ;(note that we'll enter DOS 1 mode after returning) + ld sp,hl + ret + ;----------------------------------------------------------------------------- ; ; This routine sets the NUMDRV variable according to the number @@ -824,108 +855,109 @@ SETNUMD_NOUD: ; Address of entry in device-based drives table, must have UD_SLOT set ; B = Device index (AUTO_ASPART only) ; C = LUN index (AUTO_ASPART only) -; A = 0: Do NOT try to enter disk emulation mode +; D = 0: Do NOT try to enter disk emulation mode ; 1: Enter disk emulation mode if possible ; ; Output: A = Error code ; 0: Ok ; 1: No suitable device/partition found -; 2: Disk emulation mode entered +; 2: Disk emulation mode was entered -;Temporary area BUF9 (9 bytes) is used as follows: -;+0: Candidate device (a device which has a suitable partition, -; but has no NEXTOR.SYS file), device + 8*LUN (0 if no candidates found), -; bit 7 is the removable device flag, bit 6 is the hot-plug device flag -;+1: Sector number of first partition found on disk -;+5: Sector number of partition being examined -; -;Also, NXTEMP is used to store a pre-candidate device -;(a device that exists but has not been checked yet for partitions), -;NXT7+2 is used to store the value of A at input, and -;NXT7+3 is used to store the stack pointer at input so that we can easily -;discard the stack contents when entering disk emulation mode. +;CURR = current deivce/partition being examined +;CAND = candidate device/partition, will be assigned if no one has the active flag set in status byte + +AAD_UNIT_DESCRIPTOR equ 0 +AAD_LOOP_DEV_INDEX equ 2 +AAD_LOOP_LUN_INDEX equ 3 +AAD_DRIVER_SLOT equ 4 +AAD_CURR_PART_DEVLUN equ 5 +AAD_CURR_PART_INDEX equ 6 ;Bit 7 set when examining extended partitions, FFh when examining the MBR +AAD_CURR_PART_SECTOR equ 7 +AAD_CURR_PART_STATUS_BYTE equ 11 +AAD_CAND_PART_DEVLUN equ 12 +AAD_CAND_PART_SECTOR equ 13 +AAD_FLAGS equ 17 + +AAD_SIZE equ 18 + +AAFLAG_ENTER_EMU_MODE equ 0 +AAFLAG_IS_AUTOASPART equ 7 PROC AUTO_ASPART - scf - jr AUTO_COMMON + set AAFLAG_IS_AUTOASPART,d AUTO_ASSIGN: - or a + ld ix,-AAD_SIZE + add ix,sp + ld sp,ix -AUTO_COMMON: - ld (NXT7##+2),a + ld (ix+AAD_FLAGS),d + + ld (ix+AAD_UNIT_DESCRIPTOR),l + ld (ix+AAD_UNIT_DESCRIPTOR+1),h + push hl + pop iy + ld a,(iy+UD_SLOT##) + ld (ix+AAD_DRIVER_SLOT),a - ld de,(NXTEMP##) ;Save lots of page 3 variables. - push de ;This is necessary because AUTO_ASSIGN uses them - ld de,(TMPDEV##) ;as temporary work area, which is OK in DOS 2 mode - push de ;but in in DOS 1 mode these are actually used for anything else. - ld de,(NXT4##) - push de - ld de,(NXT4##+2) - push de call AUTO_COMMON2 - pop de - ld (NXT4##+2),de - pop de - ld (NXT4##),de - pop de - ld (TMPDEV##),de - pop de - ld (NXTEMP##),de + + ld ix,AAD_SIZE + add ix,sp + ld sp,ix + ret AUTO_COMMON2: - jr nc,AUTO_COMMON3 + bit 0,d + jr z,AUTO_NOEMU + push bc + push de + push hl + xor a + call TRY_RAM_EMU + pop hl + pop de + pop bc + or a + ld a,2 + ret nz +AUTO_NOEMU: + + bit 7,d + jr z,AUTO_COMMON3 ;AUTO_ASPART: - push hl - pop ix - ld a,b ;(ix+UD_DI##) - ld (TMPDEV##),a - ld a,c ;(ix+UD_LI##) - ld (TMPLUN##),a + ld (ix+AAD_LOOP_DEV_INDEX),b + ld (ix+AAD_LOOP_LUN_INDEX),c xor a - ld (BUF9##),a - ld (NXTEMP##),a - inc a - ld (NXT3##),a + ld (ix+AAD_CAND_PART_DEVLUN),a + ld (ix+AAD_CURR_PART_DEVLUN),a jp AA_CHKDUP_OK ;AUTO_ASSIGN: AUTO_COMMON3: xor a - ld (BUF9##),a - ld (NXT3##),a - - xor a - ld (NXT7##+5),a + ld (ix+AAD_CAND_PART_DEVLUN),a + ld (ix+AAD_CURR_PART_STATUS_BYTE),a - push hl - pop ix - - ld hl,0 - add hl,sp - ld (NXT7##+3),hl - - ld a,1 ;Device index + inc a ;Device index = 1 AA_DLOOP: - ld (TMPDEV##),a ;push af + ld (ix+AAD_LOOP_DEV_INDEX),a ld a,1 ;LUN index AA_LLOOP: - ld (TMPLUN##),a ;push af + ld (ix+AAD_LOOP_LUN_INDEX),a xor a - ld (NXTEMP##),a + ld (ix+AAD_CURR_PART_DEVLUN),a ;--- Check if the same slot+device+LUN has been assigned ; to other drive already - ld a,(TMPDEV##) - ld d,a - ld a,(TMPLUN##) - ld e,a + ld d,(ix+AAD_LOOP_DEV_INDEX) + ld e,(ix+AAD_LOOP_LUN_INDEX) ld a,(DOS_VER##) ;Skip in DOS 1 or a @@ -943,7 +975,7 @@ AA_CHKDUP_DOS1: AA_CHKDUP_LOOP1: ld a,(iy+UD_SLOT##) - cp (ix+UD_SLOT##) + cp (ix+AAD_DRIVER_SLOT) jr nz,AA_CHKDUP_NEXT1 ld a,(iy+UD1_DI##) @@ -987,7 +1019,7 @@ AA_CHKDUP_LOOP: jr z,AA_CHKDUP_NEXT ;Unit descriptor in use? ld a,(iy+UD_SLOT##) - cp (ix+UD_SLOT##) + cp (ix+AAD_DRIVER_SLOT) jr nz,AA_CHKDUP_NEXT ld a,(iy+UD_DI##) @@ -1010,18 +1042,13 @@ AA_CHKDUP_OK: ;--- Obtain device information - ld a,(ix+UD_SLOT##) + ld a,(ix+AAD_DRIVER_SLOT) ld_iyh_a ld hl,LUN_INFO## ld (BK4_ADD##),hl ld hl,($SECBUF##) - ;pop bc ;Retrieve LUN index - ;pop af ;Retrieve device index - ;push af - ;push bc - ld a,(TMPLUN##) - ld b,a - ld a,(TMPDEV##) + ld b,(ix+AAD_LOOP_LUN_INDEX) + ld a,(ix+AAD_LOOP_DEV_INDEX) push ix ld ix,CALDRV## call CALSLT ;Call LUN_INFO @@ -1056,105 +1083,184 @@ AA_CHKDUP_OK: ;* Mark the device as candidate for autoassign, ; unless this was done before - ld a,(TMPLUN##) - ld b,a - ld a,(TMPDEV##) + ld b,(ix+AAD_LOOP_LUN_INDEX) + ld a,(ix+AAD_LOOP_DEV_INDEX) sla b sla b sla b or b or d ;Include removable flag - ld (NXTEMP##),a ;Device + 8*LUN, bit 7 is removable flag + ld (ix+AAD_CURR_PART_DEVLUN),a ;Device + 8*LUN, bit 7 is removable flag AA_OK_CANDIDATE: - ;--- Device parameters OK. - ; Now read MBR and look for a suitable partition. + ;--- Device parameters OK. Now scan partitions. + + ld a,1 +AA_PXLOOP: + ld (ix+AAD_CURR_PART_INDEX),a + ld h,a + ld l,0 + bit 7,a ;We are examining extended partitions? + jr z,AA_PX_1ST + ld h,2 ;Yes: primary = 2, extended = partition # - 1 + and 7Fh + dec a + ld l,a +AA_PX_1ST: + ld e,(ix+AAD_LOOP_LUN_INDEX) + ld d,(ix+AAD_LOOP_DEV_INDEX) + ld c,(ix+AAD_DRIVER_SLOT) + ld b,0FFh + + push ix + call F_GPART + pop ix + cp .IPART + jp z,AA_PLOOP_END + or a + jp nz,AA_LLOOP_NEXT ;Not ready or partition not available +AA_PX_POK: - ;* Read device MBR + ;--- If we are scanning the first partition and bit 0 of status byte is set, try to enter disk emulation mode - ld hl,0 - ld (TMP_SEC##),hl - ld (TMP_SEC##+2),hl - ld a,(TMPLUN##) - ld b,a - ld a,(TMPDEV##) - call AA_RSEC - or a - jp nz,AA_LLOOP_NEXT ;Not ready + ld (ix+AAD_CURR_PART_STATUS_BYTE),c - ;* Check partition table + bit 0,c + jp z,AA_PX_NOEMU ;Bit 0 of status byte must be set + bit AAFLAG_ENTER_EMU_MODE,(ix+AAD_FLAGS) + jp z,AA_PX_NOEMU ;Enter emulation mode must have been requested + ld a,(0F348h) + cp (ix+AAD_DRIVER_SLOT) ;Must be the primary slot + jp nz,AA_PX_NOEMU + ld a,(ix+AAD_CURR_PART_INDEX) ;Must be the first partition + dec a + jp nz,AA_PX_NOEMU - xor a - ld (NXT4##+2),a + push hl + push de + push bc + push ix - ld hl,($SECBUF##) - ld bc,MBR_PSTART+POFF_TYPE - add hl,bc - ld b,4 -AA_PLOOP:: - ld a,(hl) ;A=Partition type + ld hl,($SECBUF##) ;We still have sector 0 of the device here from F_GPART + ld bc,MBR_PSTART + add hl,bc + push hl + pop iy ;IY = First entry of partition table + + ld a,(BOOTKEYS##) + and 00000001b ;"0" key pressed? + jr z,AA_PX_DOEMU + + ;* Reset emulation mode flag from status byte in partition table, then boot normally + +AA_PX_KILLEMU: + ld a,(ix+AAD_CURR_PART_STATUS_BYTE) + and 0FEh + ld (iy+POFF_STATUS),a + xor a + ld (iy+POFF_CHS_START),a + ld (iy+POFF_CHS_START+1),a + ld (iy+POFF_CHS_START+2),a + ld (iy+POFF_CHS_END),a + ld (iy+POFF_CHS_END+1),a + ld (iy+POFF_CHS_END+2),a + + ld b,(ix+AAD_LOOP_LUN_INDEX) + ld a,(ix+AAD_LOOP_DEV_INDEX) + ld c,(ix+AAD_DRIVER_SLOT) + ld de,0 + ld (TMP_SEC##),de + ld (TMP_SEC##+2),de + call AA_WSEC + + pop ix + pop bc + pop de + pop hl + jr AA_PX_NOEMU + +AA_PX_DOEMU: + ld hl,($SECBUF##) ;We still have sector 0 of the device here from F_GPART + ld bc,MBR_PSTART + add hl,bc + push hl + pop iy + ld c,(ix+AAD_DRIVER_SLOT) + ld a,(iy+POFF_CHS_START) + ld b,(iy+POFF_CHS_START+1) + ld h,(iy+POFF_CHS_START+2) + ld l,(iy+POFF_CHS_END) + ld d,(iy+POFF_CHS_END+1) + ld e,(iy+POFF_CHS_END+2) + call GO_EMU + pop ix + pop bc + pop de + pop hl + inc a + cp 2 + ret z + +AA_PX_NOEMU: + ld a,b ;Partition type + cp PT_EXT + jr nz,AA_PX_NOEX + ld a,(ix+AAD_CURR_PART_INDEX) + or 80h + jp AA_PXLOOP +AA_PX_NOEX: cp PT_FAT12 jr z,AA_PLOOP_OKTYPE - - ld d,a ld a,(DOS_VER##) or a jr z,AA_PLOOP_NEXT ;In DOS1 only FAT12 is valid - ld a,d + ld a,b cp PT_FAT16 jr z,AA_PLOOP_OKTYPE cp PT_FAT16_S - jr z,AA_PLOOP_OKTYPE + jr z,AA_PLOOP_OKTYPE cp PT_FAT16_L jr z,AA_PLOOP_OKTYPE - AA_PLOOP_NEXT: - ld de,MBR_PSIZE - add hl,de - djnz AA_PLOOP - ld hl,0 - ld (BUF9##+5),hl - ld (BUF9##+7),hl - jr AA_CHECK_BOOT_MBR ;No suitable partitions found: try the MBR itself -AA_PLOOP_OKTYPE: - - ld (NXT4##),hl - ld a,b - ld (NXT4##+2),a + ld a,(ix+AAD_CURR_PART_INDEX) + inc a ;FFh if no more partitions left (we were examining the MBR itself) + jp z,AA_LLOOP_NEXT + cp 5 ;We examine the first 4 primary partitions only... + jp c,AA_PXLOOP + bit 7,a + jr z,AA_PLOOP_END + cp 80h+10 ;...or up to 9 extended partitions + jp c,AA_PXLOOP + +AA_PLOOP_END: + ld hl,0 ;No suitable partitions found: try the MBR itself as last resort + ld de,0 + xor a + ld (ix+AAD_CURR_PART_STATUS_BYTE),a ;Clear any stale active partition flag + dec a + ld (ix+AAD_CURR_PART_INDEX),a ;Partition # = 0FFh -> no more partitions - ;* Read first sector of partition + ;* Read first sector of partition - ld a,(TMPLUN##) - ld b,a - ld a,(TMPDEV##) - ld de,POFF_PSTART-POFF_TYPE - add hl,de - ld e,(hl) - inc hl - ld d,(hl) - inc hl +AA_PLOOP_OKTYPE: + ld b,(ix+AAD_LOOP_LUN_INDEX) + ld a,(ix+AAD_LOOP_DEV_INDEX) ld (TMP_SEC##),de - ld (BUF9##+5),de - ld e,(hl) - inc hl - ld d,(hl) - ld (TMP_SEC##+2),de - ld (BUF9##+7),de + ld (ix+AAD_CURR_PART_SECTOR),e + ld (ix+AAD_CURR_PART_SECTOR+1),d + ld (TMP_SEC##+2),hl + ld (ix+AAD_CURR_PART_SECTOR+2),l + ld (ix+AAD_CURR_PART_SECTOR+3),h + ld c,(ix+AAD_DRIVER_SLOT) -DO_RSEC: call AA_RSEC jr nz,AA_PLOOP_NEXT - ;* Check FAT boot sector + ;* Check FAT boot sector AA_CHECK_BOOT: call CHECK_FAT_BOOT - jp nz,AA_NEXTPAR ;AA_LLOOP_NEXT - jr AA_CHECK_BOOT2 - -AA_CHECK_BOOT_MBR: - call CHECK_FAT_BOOT - jp nz,AA_LLOOP_NEXT + jp nz,AA_PLOOP_NEXT ;AA_LLOOP_NEXT AA_CHECK_BOOT2: @@ -1166,263 +1272,86 @@ AA_CHECK_BOOT2: jr nz,AA_SPC_OK ld a,(iy+UPB_SFAT##+1) or a - jp nz,AA_NEXTPAR ;AA_LLOOP_NEXT + jp nz,AA_PLOOP_NEXT ;AA_LLOOP_NEXT ld a,(iy+UPB_SFAT##) cp 4 - jp nc,AA_NEXTPAR ;AA_LLOOP_NEXT + jp nc,AA_PLOOP_NEXT ;AA_LLOOP_NEXT AA_SPC_OK: ;* Check if the partition is already mapped to another drive push ix push iy - ld h,(ix+UD_SLOT##) - ld l,(ix+UD_SEG##) - ld a,(TMPDEV##) - ld d,a - ld a,(TMPLUN##) - ld e,a + ld h,(ix+AAD_DRIVER_SLOT) + ld l,0FFh ;(ix+UD_SEG##) + ld e,(ix+AAD_UNIT_DESCRIPTOR) + ld d,(ix+AAD_UNIT_DESCRIPTOR+1) + push de + ld d,(ix+AAD_LOOP_DEV_INDEX) + ld e,(ix+AAD_LOOP_LUN_INDEX) exx - ld de,(BUF9##+5) - ld hl,(BUF9##+7) + ld e,(ix+AAD_CURR_PART_SECTOR) + ld d,(ix+AAD_CURR_PART_SECTOR+1) + ld l,(ix+AAD_CURR_PART_SECTOR+2) + ld h,(ix+AAD_CURR_PART_SECTOR+3) exx + pop ix call CHECK_MAP_IN_USE pop iy pop ix - jp nz,AA_NEXTPAR - - ;* All checks ok, partition is good - - ld a,(BUF9##) - or a - jr nz,AA_OK_CANDIDATE2 - - ld a,(NXTEMP##) - ld (BUF9##),a ;Valid partition: mark as candidate device - - ld hl,(TMP_SEC##) ;If this is the first partition being examined, - ld (BUF9##+1),hl ;save its number - ld hl,(TMP_SEC##+2) - ld (BUF9##+3),hl -DO_RSEC2: - -AA_OK_CANDIDATE2: - - ;* Check that there is a file named NEXTOR.DAT in the root directory - ; (if A=1 at input and we are the primary controller, check NEXT_DSK.DAT first) - - ;jp AA_NEXTPAR ;!!! - - ld e,(iy+UPB_SFAT##) - ld d,(iy+UPB_SFAT##+1) ;DE=Sectors per fat - ld b,(iy+UPB_NFAT##) ;B=Number of FATs - ld hl,0 -AA_SUM_FATS: - add hl,de - djnz AA_SUM_FATS ;Make HL=Total FAT sectors count - ld c,(iy+UPB_RES##) - ld b,(iy+UPB_RES##+1) - add hl,bc ;Now HL=First root directory sector ;WIP - - ld de,(TMP_SEC##) ;Set the absolute sector number - add hl,de ;for the start of root directory - ld (TMP_SEC##),hl - ld (TMP_FROOT##),hl - ld hl,0 - ld de,(TMP_SEC##+2) - adc hl,de - ld (TMP_SEC##+2),hl - ld (TMP_FROOT##+2),hl - - ld e,(iy+UPB_NDIR##) ;Same some extra data that we'll need - ld d,(iy+UPB_NDIR##+1) ;if we enter in disk emulation mode - ld (TMP_NDIR##),de - ld a,(iy+UPB_CS##) - ld (TMP_CS##),a - - ld b,e ;(iy+UPB_NDIR##) ;Number of root directory entries - ld a,d ;(iy+UPB_NDIR##+1) ;Number of root directory entries - or a - jr z,AA_OK_ROOTNUM - ld b,254 -AA_OK_ROOTNUM: - - ;Outer loop: check all root directory sectors - -AA_MSXDOS2_SLOOP: - ld a,(TMPLUN##) - ld d,a - ld a,(TMPDEV##) - - push bc - ld b,d - call AA_RSEC - jp nz,AA_MSXDOS2_ERR - - ld b,16 ;Directory entries per sector - ld hl,($SECBUF##) - - ;Inner loop: check all entries in one sector - -AA_MSXDOS2_ELOOP: - pop af ;Total number of root dir entries - dec a - jp z,AA_NOMOREENT ;AA_NEXTPAR ;AA_LLOOP_NEXT - push af - - ld a,(NXT7##+2) - or a - jr z,SRCHNX2 ;Don't search NEXT_DSK.DAT if A=0 at input - - push hl - call GET_DISKID_HL - ld a,(hl) - pop hl - or a - jr nz,SRCHNX2 ;I'm not the primary controller - - di - in a,(0AAh) - and 0F0h - ;add 0 - out (0AAh),a - ei - in a,(0A9h) - and 1 - jp z,SRCHNX2 ;Don't search NEXT_DSK.DAT if key 0 is pressed - - push bc - push hl - ld de,EMUDAT - ld b,11 - dec hl -AA_EMU_CHKE: - inc hl - ld a,(de) - cp (hl) - inc de - jr nz,SRCHNXDAT - djnz AA_EMU_CHKE - - pop hl - push hl - push ix - push iy - call GO_EMU - pop iy - pop ix - or a - jr z,SRCHNXDAT - - ;There's a NEXT_DSK.DAT file and it had valid contents: - ;Stop the presses! We cancel everything since we've entered emulation mode. - - ld hl,(NXT7##+3) - ld sp,hl - ld a,2 - ret - -SRCHNXDAT: - pop hl - pop bc - -SRCHNX2: - push bc - ld de,MSXDOS2DAT - ld b,11 - dec hl -AA_MSXDOS2_CHKE: - inc hl - ld a,(de) - cp (hl) - inc de - jr nz,AA_MSXDOS2_NXTE - djnz AA_MSXDOS2_CHKE - - ld a,(NXT7##+2) - or a - jr z,AA_DO_FOUND - ld a,1 - ld (NXT7##+5),a - inc hl - jr AA_NXTE2 - -AA_DO_FOUND: - pop bc - pop bc -AA_DO_FOUND2: - ld hl,(BUF9##+5) - ld (BUF9##+1),hl - ld hl,(BUF9##+7) - ld (BUF9##+3),hl + jp nz,AA_PLOOP_NEXT + + ;* All checks ok, partition is good. + ; If it has the active flag set, go ahead and assign it. + ; Otherwise mark it as candidate. + + ld a,(ix+AAD_CURR_PART_STATUS_BYTE) + and 80h + jr z,AA_NOT_ACTIVE + + ld l,(ix+AAD_CURR_PART_SECTOR) + ld h,(ix+AAD_CURR_PART_SECTOR+1) + ld (ix+AAD_CAND_PART_SECTOR),l + ld (ix+AAD_CAND_PART_SECTOR+1),h + ld l,(ix+AAD_CURR_PART_SECTOR+2) + ld h,(ix+AAD_CURR_PART_SECTOR+3) + ld (ix+AAD_CAND_PART_SECTOR+2),l + ld (ix+AAD_CAND_PART_SECTOR+3),h + ld a,(ix+AAD_CURR_PART_DEVLUN) + ld (ix+AAD_CAND_PART_DEVLUN),a jp AA_DO_ASSIGN -AA_MSXDOS2_NXTE: - inc hl - djnz AA_MSXDOS2_NXTE -AA_NXTE2: - ld bc,32-11 - add hl,bc ;Make HL point to the next dir entry - - pop bc - dec b - jp nz,AA_MSXDOS2_ELOOP - - ld hl,1 - ld de,(TMP_SEC##) ;Increase root dir sector number - add hl,de - ld (TMP_SEC##),hl - ld hl,0 - ld de,(TMP_SEC##+2) - adc hl,de - ld (TMP_SEC##+2),hl - - pop bc - dec b - jp nz,AA_MSXDOS2_SLOOP - -AA_NOMOREENT: - ld a,(NXT7##+5) +AA_NOT_ACTIVE: + ld a,(ix+AAD_CAND_PART_DEVLUN) or a - jr nz,AA_DO_FOUND2 + jp nz,AA_PLOOP_NEXT -AA_NEXTPAR:: - ld a,(NXT4##+2) - or a - jr z,AA_LLOOP_NEXT + ld a,(ix+AAD_CURR_PART_DEVLUN) + ld (ix+AAD_CAND_PART_DEVLUN),a ;Valid partition: mark as candidate device - ld hl,0 - ld (TMP_SEC##),hl - ld (TMP_SEC##+2),hl - ld a,(TMPLUN##) - ld b,a - ld a,(TMPDEV##) - call AA_RSEC - jp nz,AA_LLOOP_NEXT ;Not ready + ld hl,(TMP_SEC##) ;If this is the first partition being examined, save its number + ld (ix+AAD_CAND_PART_SECTOR),l + ld (ix+AAD_CAND_PART_SECTOR+1),h + ld hl,(TMP_SEC##+2) + ld (ix+AAD_CAND_PART_SECTOR+2),l + ld (ix+AAD_CAND_PART_SECTOR+3),h - ld hl,(NXT4##) - ld a,(NXT4##+2) - ld b,a - jp AA_PLOOP_NEXT - -AA_MSXDOS2_ERR: - pop bc + jp AA_PLOOP_NEXT ;--- No suitable partitions in the current LUN, ; so jump to the next device or LUN AA_LLOOP_NEXT: - ld a,(NXT3##) - or a + bit AAFLAG_IS_AUTOASPART,(ix+AAD_FLAGS) jr nz,AA_LLOOP_END - ld a,(TMPLUN##) + ld a,(ix+AAD_LOOP_LUN_INDEX) inc a cp 8 jp nz,AA_LLOOP - ld a,(TMPDEV##) + ld a,(ix+AAD_LOOP_DEV_INDEX) inc a cp 8 jp nz,AA_DLOOP @@ -1432,7 +1361,7 @@ AA_LLOOP_END: ; If a candidate device was identified, use it, ; otherwise return an error - ld a,(BUF9##) + ld a,(ix+AAD_CAND_PART_DEVLUN) or a jr z,AA_END_NOFOUND @@ -1444,30 +1373,34 @@ AA_LLOOP_END: ld b,a ;B=LUN ld a,c and 111b ;A=Device - ld (TMPDEV##),a - ld a,b - ld (TMPLUN##),a + ld (ix+AAD_LOOP_DEV_INDEX),a + ld (ix+AAD_LOOP_LUN_INDEX),b jp AA_DO_ASSIGN AA_END_NOFOUND: ld a,1 ret ;Error, no suitable device/partition found - ;--- A suitable device has been found. + ;--- A suitable device has been found (the candidate device). ; Assign it to the drive. AA_DO_ASSIGN: + ld l,(ix+AAD_UNIT_DESCRIPTOR) + ld h,(ix+AAD_UNIT_DESCRIPTOR+1) + push hl + pop iy + ld a,(DOS_VER##) or a jr z,AA_DO_ASSDOS1 - set UF_FOK,(ix+UD_DFLAGS##) ;Tell that the partition information is valid - ld b,(ix+UD_SLOT##) - ld c,(ix+UD_PHYS##) + set UF_FOK,(iy+UD_DFLAGS##) ;Tell that the partition information is valid + ld b,(iy+UD_SLOT##) + ld c,(iy+UD_PHYS##) push bc - ld a,(ix+UD_DFLAGS##) - push ix ;First clear the current unit descriptor + ld a,(iy+UD_DFLAGS##) + push iy ;First clear the current unit descriptor pop hl push hl pop de @@ -1475,92 +1408,142 @@ AA_DO_ASSIGN: ld (hl),0 ld bc,UD_SZ##-1 ldir - ld (ix+UD_DFLAGS##),a + ld (iy+UD_DFLAGS##),a pop bc - ld (ix+UD_SLOT##),b - ld (ix+UD_PHYS##),c - ld a,(TMPLUN##) - ld b,a - ld a,(TMPDEV##) - ld (ix+UD_LI##),b - ld (ix+UD_DI##),a - ld (ix+UD_SEG##),0FFh - - ld hl,(BUF9##+1) - ld (ix+UD_FSEC##),l - ld (ix+UD_FSEC##+1),h - ld hl,(BUF9##+3) - ld (ix+UD_FSEC##+2),l - ld (ix+UD_FSEC##+3),h - - ld (ix+UD_CDIR##+1),0FFh ;set current dir -ve => root - ld (ix+UD_CDIR##),0FFh - - ld a,(BUF9##) ;Retrieve removable unit flag + ld (iy+UD_SLOT##),b + ld (iy+UD_PHYS##),c + ld b,(ix+AAD_LOOP_LUN_INDEX) + ld a,(ix+AAD_LOOP_DEV_INDEX) + ld (iy+UD_LI##),b + ld (iy+UD_DI##),a + ld (iy+UD_SEG##),0FFh + + ld l,(ix+AAD_CAND_PART_SECTOR) + ld h,(ix+AAD_CAND_PART_SECTOR+1) + ld (iy+UD_FSEC##),l + ld (iy+UD_FSEC##+1),h + ld l,(ix+AAD_CAND_PART_SECTOR+2) + ld h,(ix+AAD_CAND_PART_SECTOR+3) + ld (iy+UD_FSEC##+2),l + ld (iy+UD_FSEC##+3),h + + ld (iy+UD_CDIR##+1),0FFh ;set current dir -ve => root + ld (iy+UD_CDIR##),0FFh + + ld a,(ix+AAD_CAND_PART_DEVLUN) ;Retrieve removable unit flag rlca rlca rlca and 4 or UFM_DB ;Set "device based driver" - or (ix+UD_DFLAGS##) ;Because the "FSEC OK" flag has already its value - ld (ix+UD_DFLAGS##),a + or (iy+UD_DFLAGS##) ;Because the "FSEC OK" flag has already its value + ld (iy+UD_DFLAGS##),a ld hl,$DPBLIST## - ld c,(ix+UD_PHYS##) + ld c,(iy+UD_PHYS##) dec c sla c ld b,0 add hl,bc ld a,(hl) - ld (ix+UD_DPB##),a + ld (iy+UD_DPB##),a inc hl ld a,(hl) - ld (ix+UD_DPB##+1),a + ld (iy+UD_DPB##+1),a xor a ret AA_DO_ASSDOS1: - ld a,(TMPDEV##) - ld (ix+UD1_DI##),a - ld a,(TMPLUN##) - ld (ix+UD1_LI##),a - ld hl,(BUF9##+1) - ld (ix+UD1_FSEC##),l - ld (ix+UD1_FSEC##+1),h - ld hl,(BUF9##+3) - ld (ix+UD1_FSEC##+2),l - ld (ix+UD1_FSEC##+3),h + ld a,(ix+AAD_LOOP_DEV_INDEX) + ld (iy+UD1_DI##),a + ld a,(ix+AAD_LOOP_LUN_INDEX) + ld (iy+UD1_LI##),a + ld l,(ix+AAD_CAND_PART_SECTOR) + ld h,(ix+AAD_CAND_PART_SECTOR+1) + ld (iy+UD1_FSEC##),l + ld (iy+UD1_FSEC##+1),h + ld l,(ix+AAD_CAND_PART_SECTOR+2) + ld h,(ix+AAD_CAND_PART_SECTOR+3) + ld (iy+UD1_FSEC##+2),l + ld (iy+UD1_FSEC##+3),h xor a ret -MSXDOS2DAT: - db "NEXTOR DAT" -EMUDAT: - db "NEXT_DSKDAT" -;This subroutine reads a sector from the device to SECBUF. + ;Try to enter emulation mode from data in RAM + ;Returns A=1 on success, 0 on failure + +TRY_RAM_EMU: + call GET_P2## + ld b,a + ld a,(P2_TPA##) + call PUT_P2## + + ld hl,EMU_RAM_ADDRESS + ld de,EMUDATASIG + call STRCOMP + jr nz,TRY_RAM_EMU_NO_SIG + + xor a ;Disable emulation for next boot + ld (EMU_RAM_ADDRESS),a ;(in case the code of the emulated disk doesn't do it itself) + + push bc ;Save original page 2 segment + + ld bc,(0F348h) + push ix + ld ix,EMU_RAM_ADDRESS+10h + ld a,(ix) + ld b,(ix+1) + ld e,(ix+2) + ld d,(ix+3) + ld l,(ix+4) + ld h,(ix+5) + + pop ix + + ex (sp),hl + push af + ld a,h ;Restore original page 2 segment + call PUT_P2## + pop af + ex (sp),hl + inc sp ;Discard saved segment number without affecting any register + inc sp + + jp GO_EMU + +TRY_RAM_EMU_NO_SIG: + ld a,b ;Previous segment + call PUT_P2## + xor a + ret + + +;This subroutine reads (AA_RSEC) or writes (AA_WSEC) a sector from the device to SECBUF. ;Input: A = Device index ; B = LUN -; IX = Address of unit descriptor +; C = Driver slot ; (TMP_SEC) = sector number ;Output: NZ on error ;Preserves IX +AA_WSEC: + scf + jr AA_DOSEC + AA_RSEC: - push af - ld a,(ix+UD_SLOT##) - ld_iyh_a - pop af + or a +AA_DOSEC: + ld_iyh_c ld hl,DEV_RW## ld (BK4_ADD##),hl ld c,b ld b,1 ld hl,($SECBUF##) ld de,TMP_SEC## - or a push ix ld ix,CALDRV## call CALSLT ;Call DEV_RW @@ -1698,99 +1681,54 @@ upb_not_found: ;If anything was wrong with ret ; Z-flag clear. -; This routine accepts in HL a pointer to the directory entry of the -; NEXT_DSK.DAT file and does all the job of entering in disk emulation mode. +; This routine does all the job of entering in disk emulation mode +; given the pointer to the emulation data file that is passed as follows: +; +; A = Device index +; B = LUN index +; C = Driver slot number +; HLDE = Absolute device sector where the file starts ; ; It first reads the contents of the file (only the first sector) ; and check that it has the expected structure. If this is not true, ; or if there is an error when reading the file, it does nothing ; and returns with A=0. ; -; Otherwise, it builds the work area in the same temporary buffer where -; the device-drivers table is generated when booting normally in DOS 1 mode, -; then returns with A=1. The format of the table is as follows, note that -; it is mostly compatible with a DOS 1 device-drivers table with just one entry: -; -; +0: Device index of current disk image file -; Bit 7 is kept set to 1 to indicate that we are in disk emulation mode -; +1: Controller slot (always the primary controller) -; +2: Device + 16 * logical unit number for NEXT_DSK.DAT -; Bit 7 is set after the current image file is changed -; and reset again when disk change is checked -; +3: Device index of disk image file -; +4: Logical unit number of disk image file -; +5-8: First sector of disk image file -; +9-10: Disk image file size in sectors -; +11: Number of entries in the disk images table in NEXT_DSK.DAT -; +12-15: Device sector number of NEXT_DSK.DAT contents -; -; The definitve address of the work area as read from NEXT_DSK.DAT is temporarily -; appended at the end of this table, so that either it will be moved to this place +; Otherwise, it builds the work area in EMU_TMP (the same temporary buffer where +; the device-drivers table is generated when booting normally in DOS 1 mode), +; then returns with A=1. The format of the table is defined in kvar.mac (DSK_*). +; +; The definitve address of the work area as read from the emulation data file is temporarily +; stored in EMU_WK_AREA, so that either the table it will be moved to this place ; or, if it is zero, the work area will be properly allocated. -GO_EMU:: - - ;--- Calculate data sector of NEXT_DSK.DAT +GO_EMU: - push ix - push hl - pop ix - ld e,(ix+DR_CLU##) - ld d,(ix+DR_CLU##+1) ;DE = First cluster number of file - pop ix - dec de - dec de ;DE = Zero-based cluster index - - ld hl,0 - ld a,(TMP_CS##) ;Sectors per cluster -GOEMU2: - rra - jp c,GOEMU3 - sla e - rl d - rl l - rl h - jr GOEMU2 -GOEMU3: - push hl ;HLDE = File sector, relative to first data sector - - ld hl,(TMP_NDIR##) ;HL = Number of root directory entries - SRL H ;Divide by 16 -> HL = Number of root directory sectors - RR L - SRL H - RR L - SRL H - RR L - SRL H - RR L - - push hl - pop bc ;BC = Number of root directory sectors - - ex de,hl ;HL = Relative file sector, low - ld de,(TMP_FROOT##) ;DE = Absolute first root dir sector, low - add hl,de - ld (TMP_SEC##),hl - pop de ;DE = Relative file sector, high - ld hl,(TMP_FROOT##+2) - adc hl,de - ld (TMP_SEC##+2),hl + ;--- Store device and LUN of the emulation data file - ld hl,(TMP_SEC##) - add hl,bc - ld (TMP_SEC##),hl - ld (0F980h+12),hl - ld hl,(TMP_SEC##+2) - ld de,0 - adc hl,de - ld (TMP_SEC##+2),hl - ld (0F980h+14),hl + push af + push bc + ld c,a ;Dev + ld a,b ;LUN + rlca + rlca + rlca + rlca + and 0F0h + ld b,a + ld a,c ;Dev + and 0Fh + or b + ld (EMU_TMP##+EMU_DEVLUN##),a ;dev+lun of emulation data file + pop bc + pop af ;--- Read file contents - ld a,(TMPLUN##) - ld b,a - ld a,(TMPDEV##) + ld (EMU_TMP##+EMU_FSEC##),de + ld (EMU_TMP##+EMU_FSEC##+2),hl + ld (TMP_SEC##),de + ld (TMP_SEC##+2),hl call AA_RSEC ld a,0 ret nz @@ -1803,18 +1741,10 @@ GOEMU3: push ix pop hl - ld de,NDATSIG -GOEMU_SIG1: - ld a,(de) - cp (hl) - ld a,0 + ld de,EMUDATASIG + call STRCOMP + ld a,0 ret nz - or a - jr z,GOEMU_SIG2 - inc hl - inc de - jr GOEMU_SIG1 -GOEMU_SIG2: ;> Number of entries must be between 1 and 32 @@ -1852,36 +1782,31 @@ GOEMU_WAOK: ;--- Process file contents - ld iy,0F980h + ld iy,EMU_TMP## ;> Basic data - ld a,(0F348h) ;Controller slot - ld (iy+1),a ld a,(ix+18) ;Work area address, low - ld (iy+16),a + ld (EMU_WK_AREA##),a ld a,(ix+19) ;Work area address, high - ld (iy+17),a + ld (EMU_WK_AREA##+1),a ld a,(ix+16) - ld (iy+11),a ;Number of entries in table - - ld a,(TMPLUN##) - rlca - rlca - rlca - rlca - and 0F0h - ld b,a - ld a,(TMPDEV##) - and 0Fh - or b - ld (iy+2),a ;dev+lun of NEXT_DSK.DAT + ld (iy+DSK_COUNT##),a ;Number of entries in table ;> Current file data ld a,(ix+17) ;Boot file index - ld (iy),a + ld (iy+DSK_IDX##),a set 7,(iy) + + ld c,a + ld a,(I_AM_RUSSIAN##) + or a + jr z,GOEMU_NORUS + set 6,(iy) +GOEMU_NORUS: + ld a,c + dec a add a,a ;Each entry is 8 bytes add a,a @@ -1893,17 +1818,33 @@ GOEMU_WAOK: push ix pop bc add hl,bc ;HL = Pointer to boot file data - ld de,0F980h+3 + ld de,EMU_TMP##+DSK_DEV## ld bc,8 ldir -ekix:: + + ld a,(iy+DSK_DEV##) ;set DSK_DEV and DSK_LUN as same of data file if 0 + or a + jr nz,GOEMU_END + ld a,(iy+EMU_DEVLUN##) + ld b,a + and 00000111b + ld (iy+DSK_DEV##),a + ld a,b + rrca + rrca + rrca + rrca + and 00000111b + ld (iy+DSK_LUN##),a + ;--- All done +GOEMU_END: ld a,1 - ld (PROCNM+9),a + ld (IN_EMU##),a ret -NDATSIG: db "Nextor DSK file",0 +EMUDATASIG: db "NEXTOR_EMU_DATA",0 ;----------------------------------------------------------------------------- ; @@ -1923,43 +1864,43 @@ NDATSIG: db "Nextor DSK file",0 ld (iy+0),a ;Media ID ld hl,512 - ld (iy+1),l ;Tamanyo sector + ld (iy+1),l ;Sector size ld (iy+2),h ld a,15 - ld (iy+3),a ;(Tamanyo sector/32)-1 + ld (iy+3),a ;(Sector size/32)-1 ld a,4 - ld (iy+4),a ;Num unos en el anterior + ld (iy+4),a ;Bits set to 1 in previous value ld a,(ix+13) dec a - ld (iy+5),a ;(Sectores por cluster)-1 + ld (iy+5),a ;(Sectors per cluster)-1 ld b,0 MKDPB_CNT1S: inc b rrca jr c,MKDPB_CNT1S - ld (iy+6),b ;Num unos en el anterior+1 + ld (iy+6),b ;Bits set to 1 in previous value+1 - ld a,(ix+14) ;Sector inicio FAT=Sectores reservados + ld a,(ix+14) ;FAT first sector=reserved sectors ld (iy+7),a ld a,(ix+15) ld (iy+8),a - ld a,(ix+16) ;Numero FATs + ld a,(ix+16) ;Number of FATs ld (iy+9),a ld a,(ix+18) or a ld a,254 jr nz,DIRENT - ld a,(ix+17) ;Num entradas directorio + ld a,(ix+17) ;Number of directory entries DIRENT: ld (iy+10),a - ld e,(ix+22) ;Sectores por FAT - ld (iy+15),e ;(2 bytes en sector 0, 1 byte en DPB) + ld e,(ix+22) ;Sectors per FAT + ld (iy+15),e ;(2 bytes in sector 0, 1 byte in DPB) - ;1er sector directorio=(Sectores reservados+Num FATs*Sectores por FAT) + ;1st sector directory=(Reserved sectors+Number of FATs*Sectors per FAT) ld d,0 ld b,(ix+16) @@ -1976,10 +1917,10 @@ CALC_1SECDIR: ld (iy+17),h ex de,hl - ;1er sector datos=(Sectores reservados+Num FATs*Sectores por FAT)+ - ; (32*Entradas dir/512) + ;1er data sector =(Reserved sectors+Num FATs*Sectors per FAT)+ + ; (32*Directory entries/512) - ld l,(ix+17) ;Calcula Entradas dir/16 + ld l,(ix+17) ;Calculate directory entries/16 ld h,(ix+18) ld b,4 CALC_1SECDAT: @@ -1991,7 +1932,7 @@ CALC_1SECDAT: ld (iy+11),l ld (iy+12),h - ;Num clusters+1=((Sectores totales-1er sector datos)/Sectores por cluster)+1 + ;Num clusters+1=((Total sectors-1st data sector)/Sectors per cluster)+1 push hl pop bc ;DE=1st data sector @@ -2013,9 +1954,9 @@ OK_SMALLSEC: sbc hl,bc ex de,hl ;DEHL=total sectors - 1st data sector - ld a,(ix+13) ;Divide teniendo en cuenta que + ld a,(ix+13) ;Divide taking in account that CALC_NUMCLUS: - rrca ;sectores por cluster es potencia de 2 + rrca ;sectors por cluster is a power of 2 jr c,CALC_NUMCLUS1 sra d rr e @@ -2995,10 +2936,11 @@ MAP_DEF_DEVB: ld b,0 ld c,(ix+UD_REL##) + xor a push hl call ASK_DRIVE_CONFIG pop hl - dec a + cp 1 jr z,MAP_DEF_DEVB_NOCFG ;Driver did not provide config or a ld a,0 @@ -3010,7 +2952,7 @@ MAP_DEF_DEVB_NOCFG: push hl push ix pop hl - xor a + ld d,0 call AUTO_ASSIGN pop hl or a @@ -3746,6 +3688,7 @@ MAPDOS1_DEF: ld c,(ix+UD1_REL##) res 7,c ;Ignore "media changed" flag ld b,1 + xor a call ASK_DRIVE_CONFIG pop ix pop hl @@ -3767,6 +3710,7 @@ MAPDOS1_DEF_NOCFG: ;No config provided by driver, use AUTO_ASSIGN push ix pop hl push hl + ld d,0 call AUTO_ASSIGN pop ix pop hl @@ -3788,7 +3732,7 @@ if 0 pop hl push ix push hl - xor a + ld d,0 call AUTO_ASSIGN pop hl ld (hl),0FFh ;Mark FAT buffer as invalid again @@ -5953,7 +5897,8 @@ GET_DISKID_HL: ; Output: A = number of drives. push bc - call SCAN_5_KEY + ld a,(BOOTKEYS##) ;5 key pressed? + and 00100000b pop bc ld c,a @@ -6050,7 +5995,8 @@ DRVS1LOOP: cp 100b ;Provides config? jr nz,DRVS1NX3 ;No: skip but check "5" key - call SCAN_5_KEY + ld a,(BOOTKEYS##) ;5 key pressed? + and 00100000b ld c,a ld hl,DV_CONFIG## ld (BK4_ADD##),hl @@ -6078,7 +6024,7 @@ DRVS1NX2: ret DRVS1NX3: - call SCAN_5_KEY + ld a,(BOOTKEYS##) ;5 key pressed? and 00100000b ld b,1 jr nz,DRVS1CHG @@ -6200,7 +6146,7 @@ CMIU_END: ;--- DOS 1 version CMIU_DOS1: - ld iy,(DVB_TABLE##) + ld iy,(DVB_TABLE) ld b,(iy) ld a,b or a @@ -6264,14 +6210,19 @@ CMIU1_NEXT: ; Must have UD_SLOT set ; C = Relative unit for the drive ; B = 0 for DOS 2 mode, 1 for DOS 1 mode +; A = 1 to enter disk emulation mode ; Output: A = 0 ok ; 1 driver did not provide info for that drive ; 2 driver provided info, but can't assign partition to drive +; 3 if disk emulation mode has been entered ; If A=0 or 2, sets UD_DI, UD_LI and UD_SEG in the unit descriptor ; If A=0, sets UF_FOK in UD_DFLAGS in the unit descriptor +; If A=3, returns B, C, HLDE from AUTO_ASPART ; Modifies: AF, BC, DE, HL, IY ASK_DRIVE_CONFIG: + ld d,a + push de push bc ;BC=DOS mode and relative unit ld a,(ix+UD_SLOT##) ld_iyh_a @@ -6283,6 +6234,7 @@ ASK_DRIVE_CONFIG: call CALSLT pop ix pop hl ;H=DOS mode and relative unit + pop de ;D=A at input or a ret nz @@ -6306,8 +6258,11 @@ ASKDRVCFG_NEXT: push ix pop hl push hl + ;ld a,d call AUTO_ASPART pop ix + cp 2 + jr z,ASKDRVCFG_GOEMU pop bc ;B=DOS mode dec a @@ -6320,6 +6275,12 @@ ASKDRVCFG_NEXT: xor a ret +ASKDRVCFG_GOEMU: + pop af + ld a,3 + ret + + ;---------------------------- ; ; Read the DV_TYPE byte from a driver @@ -6335,12 +6296,20 @@ GET_DV_TYPE: call CALSLT## ret -SCAN_5_KEY: - xor a - call SNSMAT - and 00100000b - xor 00100000b ;A=00100000b if "5" key pressed, 0 if not - ret + +; Compare zero terminated strings pointed by HL and DE +; Return Z if they are equal, NZ if not +; Modifies AF, HL, DE + +STRCOMP: + ld a,(de) + cp (hl) + ret nz + or a + ret z + inc hl + inc de + jr STRCOMP finish end diff --git a/source/kernel/bank5/AsmCall.h b/source/kernel/bank5/AsmCall.h deleted file mode 100644 index 53b3bcc6..00000000 --- a/source/kernel/bank5/AsmCall.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __ASMCALL_H -#define __ASMCALL_H - -#define AsmCall(dir, regs, in, out) AsmCallAlt(dir, regs, in, out, 0) - -void DriverCall(byte slot, uint routineAddress); -void DosCall(byte function, register_usage outRegistersDetail); -void SwitchSystemBankThenCall(int routineAddress, register_usage outRegistersDetail); -void AsmCallAlt(uint address, Z80_registers* regs, register_usage inRegistersDetail, register_usage outRegistersDetail, int alternateAf); - -#endif //__ASMCALL_H \ No newline at end of file diff --git a/source/kernel/bank5/compfdsk.bat b/source/kernel/bank5/compfdsk.bat index ac1917fb..0df28b76 100644 --- a/source/kernel/bank5/compfdsk.bat +++ b/source/kernel/bank5/compfdsk.bat @@ -3,11 +3,11 @@ echo Compiling, please be patient... sdasz80 -o fdisk_crt0.rel fdisk_crt0.s if errorlevel 1 goto :error -sdcc --code-loc 0x4120 --data-loc 0x8020 -mz80 --disable-warning 196 --disable-warning 84 --disable-warning 85 --max-allocs-per-node 10000 --allow-unsafe-read --opt-code-size --no-std-crt0 fdisk_crt0.rel fdisk.c +sdcc --code-loc 0x4120 --data-loc 0x8020 -mz80 --disable-warning 196 --disable-warning 84 --disable-warning 85 --max-allocs-per-node 1000 --allow-unsafe-read --opt-code-size --no-std-crt0 fdisk_crt0.rel fdisk.c if errorlevel 1 goto :error hex2bin -e dat fdisk.ihx -sdcc --code-loc 0x4120 --data-loc 0xA000 -mz80 --disable-warning 196 --disable-warning 84 --disable-warning 85 --max-allocs-per-node 10000 --allow-unsafe-read --opt-code-size --no-std-crt0 fdisk_crt0.rel fdisk2.c +sdcc --code-loc 0x4120 --data-loc 0xA000 -mz80 --disable-warning 196 --disable-warning 84 --disable-warning 85 --max-allocs-per-node 1000 --allow-unsafe-read --opt-code-size --no-std-crt0 fdisk_crt0.rel fdisk2.c if errorlevel 1 goto :error hex2bin -e dat fdisk2.ihx diff --git a/source/kernel/bank5/drivercall.c b/source/kernel/bank5/drivercall.c new file mode 100644 index 00000000..c7a07ac0 --- /dev/null +++ b/source/kernel/bank5/drivercall.c @@ -0,0 +1,40 @@ +#include "drivercall.h" +#include "../../tools/C/AsmCall.h" +#include "../../tools/C/dos.h" + +//The following is required in the main program: +//byte ASMRUT[4]; +//byte OUT_FLAGS; +//Z80_registers regs; + +void DriverCall(byte slot, uint routineAddress) +{ + byte registerData[8]; + int i; + + memcpy(registerData, ®s, 8); + + regs.Bytes.A = slot; + regs.Bytes.B = 0xFF; + regs.UWords.DE = routineAddress; + regs.Words.HL = (int)registerData; + + DosCallFromRom(_CDRVR, REGS_ALL); + + if(regs.Bytes.A == 0) { + regs.Words.AF = regs.Words.IX; + } +} + +void DosCallFromRom(byte function, register_usage outRegistersDetail) +{ + regs.Bytes.C = function; + SwitchSystemBankThenCall((int)0xF37D, outRegistersDetail); +} + + +void SwitchSystemBankThenCall(int routineAddress, register_usage outRegistersDetail) +{ + *((int*)BK4_ADD) = routineAddress; + AsmCall(CALLB0, ®s, REGS_ALL, outRegistersDetail); +} diff --git a/source/kernel/bank5/drivercall.h b/source/kernel/bank5/drivercall.h new file mode 100644 index 00000000..7f0e33a3 --- /dev/null +++ b/source/kernel/bank5/drivercall.h @@ -0,0 +1,11 @@ +#ifndef __DRIVERCALL_H +#define __DRIVERCALL_H + +#include "../../tools/C/types.h" + +void DriverCall(byte slot, uint routineAddress); +void DosCall(byte function, Z80_registers* regs, register_usage inRegistersDetail, register_usage outRegistersDetail); +void DosCallFromRom(byte function, register_usage outRegistersDetail); +void SwitchSystemBankThenCall(int routineAddress, register_usage outRegistersDetail); + +#endif diff --git a/source/kernel/bank5/fdisk.c b/source/kernel/bank5/fdisk.c index 4665e66e..bc91d452 100644 --- a/source/kernel/bank5/fdisk.c +++ b/source/kernel/bank5/fdisk.c @@ -15,13 +15,13 @@ #include #include #include -#include "asm.h" -#include "system.h" -#include "dos.h" -#include "types.h" -#include "partit.h" +#include "../../tools/C/system.h" +#include "../../tools/C/dos.h" +#include "../../tools/C/types.h" +#include "../../tools/C/asmcall.h" +#include "drivercall.h" +#include "../../tools/C/partit.h" #include "fdisk.h" -#include "asmcall.h" //#define FAKE_DEVICE_INFO //#define FAKE_DRIVER_INFO @@ -87,9 +87,9 @@ ulong fakeDeviceSizeInK; #define HideCursor() print("\x1Bx5") #define DisplayCursor() print("\x1By5") -#define CursorDown() putchar('\x1F') -#define CursorUp() putchar('\x1E') -#define ClearScreen() putchar('\x0C') +#define CursorDown() chput('\x1F') +#define CursorUp() chput('\x1E') +#define ClearScreen() chput('\x0C') #define HomeCursor() print("\x0D\x1BK") #define DeleteToEndOfLine() print("\x1BK") #define DeleteToEndOfLineAndCursorDown() print("\x1BK\x1F"); @@ -105,16 +105,17 @@ void ShowDeviceSelectionScreen(); void GetDevicesInformation(); void EnsureMaximumStringLength(char* string, int maxLength); void GoLunSelectionScreen(byte deviceIndex); -void InitializePartitionningVariables(byte lunIndex); +void InitializePartitioningVariables(byte lunIndex); void ShowLunSelectionScreen(); void PrintSize(ulong sizeInK); byte GetRemainingBy1024String(ulong value, char* destination); void GetLunsInformation(); void PrintDeviceInfoWithIndex(); -void GoPartitionningMainMenuScreen(); +void GoPartitioningMainMenuScreen(); bool GetYesOrNo(); byte GetDiskPartitionsInfo(); void ShowPartitions(); +void TogglePartitionActive(byte partitionIndex); void PrintOnePartitionInfo(partitionInfo* info); void DeleteAllPartitions(); void RecalculateAutoPartitionSize(bool setToAllSpaceAvailable); @@ -130,8 +131,9 @@ byte CreateFatFileSystem(ulong firstDeviceSector, ulong fileSystemSizeInK); void CalculateFatFileSystemParameters(ulong fileSystemSizeInK, dosFilesystemParameters* parameters); #endif bool WritePartitionTable(); -void PreparePartitionningProcess(); +void PreparePartitioningProcess(); byte CreatePartition(int index); +byte ToggleStatusBit(byte partitionTableEntryIndex, ulong partitionTablesector); bool ConfirmDataDestroy(char* action); void ClearInformationArea(); void GetDriversInformation(); @@ -147,7 +149,7 @@ void Locate(byte x, byte y); void LocateX(byte x); void PrintCentered(char* string); void PrintStateMessage(char* string); -void putchar(char ch); +void chput(char ch); void print(char* string); int CallFunctionInExtraBank(int functionNumber, void* parametersBuffer); @@ -206,7 +208,7 @@ void DoFdisk() SaveOriginalScreenConfiguration(); ComposeWorkScreenConfiguration(); SetScreenConfiguration(¤tScreenConfig); - InitializeWorkingScreen("Nextor disk partitionning tool"); + InitializeWorkingScreen("Nextor disk partitioning tool"); GoDriverSelectionScreen(); @@ -502,9 +504,9 @@ void GoLunSelectionScreen(byte deviceIndex) return; } else { key -= '0'; - if(key >= 1 && key <= MAX_LUNS_PER_DEVICE && luns[key - 1].suitableForPartitionning) { - InitializePartitionningVariables(key); - GoPartitionningMainMenuScreen(); + if(key >= 1 && key <= MAX_LUNS_PER_DEVICE && luns[key - 1].suitableForPartitioning) { + InitializePartitioningVariables(key); + GoPartitioningMainMenuScreen(); break; } } @@ -513,7 +515,7 @@ void GoLunSelectionScreen(byte deviceIndex) } -void InitializePartitionningVariables(byte lunIndex) +void InitializePartitioningVariables(byte lunIndex) { selectedLunIndex = lunIndex - 1; selectedLun = &luns[selectedLunIndex]; @@ -556,7 +558,7 @@ void ShowLunSelectionScreen() currentLun = &luns[0]; for(i = 0; i < MAX_LUNS_PER_DEVICE; i++) { - if(currentLun->suitableForPartitionning) { + if(currentLun->suitableForPartitioning) { printf("\x1BK%i. Size: ", i + 1); PrintSize(currentLun->sectorCount / 2); NewLine(); @@ -644,13 +646,13 @@ void GetLunsInformation() currentLun->sectorCount = fakeDeviceSizeInK * 2; } #endif - currentLun->suitableForPartitionning = + currentLun->suitableForPartitioning = (regs.Bytes.A == 0) && (currentLun->mediumType == BLOCK_DEVICE) && (currentLun->sectorSize == 512) && (currentLun->sectorCount >= MIN_DEVICE_SIZE_IN_K * 2) && ((currentLun->flags & (READ_ONLY_LUN | FLOPPY_DISK_LUN)) == 0); - if(currentLun->suitableForPartitionning) { + if(currentLun->suitableForPartitioning) { availableLunsCount++; } @@ -683,7 +685,7 @@ void PrintTargetInfo() } -void GoPartitionningMainMenuScreen() +void GoPartitioningMainMenuScreen() { char key; byte error; @@ -836,7 +838,7 @@ byte GetDiskPartitionsInfo() regs.Bytes.E = selectedLunIndex + 1; regs.Bytes.H = primaryIndex; regs.Bytes.L = extendedIndex; - DosCall(_GPART, REGS_ALL); + DosCallFromRom(_GPART, REGS_ALL); error = regs.Bytes.A; if(error == 0) { if(regs.Bytes.B == PARTYPE_EXTENDED) { @@ -845,6 +847,7 @@ byte GetDiskPartitionsInfo() currentPartition->primaryIndex = primaryIndex; currentPartition->extendedIndex = extendedIndex; currentPartition->partitionType = regs.Bytes.B; + currentPartition->status = regs.Bytes.C; ((uint*)&(currentPartition->sizeInK))[0] = regs.UWords.IY; ((uint*)&(currentPartition->sizeInK))[1] = regs.UWords.IX; currentPartition->sizeInK /= 2; @@ -872,30 +875,60 @@ void ShowPartitions() int lastPartitionIndexToShow; bool isLastPage; bool isFirstPage; + bool allPartitionsArePrimary; byte key; partitionInfo* currentPartition; - Locate(0, screenLinesCount-1); - DeleteToEndOfLine(); - PrintCentered("Press ESC to return"); + if(partitionsExistInDisk) { + allPartitionsArePrimary = true; + for(i=0; iextendedIndex != 0) { + allPartitionsArePrimary = false; + break; + } + } + } else { + allPartitionsArePrimary = false; + } while(true) { isFirstPage = (firstShownPartitionIndex == 1); isLastPage = (firstShownPartitionIndex + PARTITIONS_PER_PAGE) > partitionsCount; lastPartitionIndexToShow = isLastPage ? partitionsCount : firstShownPartitionIndex + PARTITIONS_PER_PAGE - 1; - Locate(0, screenLinesCount-1); - print(isFirstPage ? " " : "<--"); + Locate(0, screenLinesCount-1); + DeleteToEndOfLine(); + if(isFirstPage) { + sprintf(buffer, partitionsCount == 1 ? "1" : partitionsCount > 9 ? "1-9" : "1-%i", partitionsCount); + if(isLastPage) { + sprintf(buffer+4, "ESC = return, %s = toggle active (*)", buffer); + } else { + sprintf(buffer+4, "ESC=back, %s=toggle active (*)", buffer); + } + PrintCentered(buffer+4); + } else { + PrintCentered("Press ESC to return"); + } - Locate(currentScreenConfig.screenWidth - 4, screenLinesCount-1); - print(isLastPage ? " " : "-->"); + if(!(isFirstPage && isLastPage)) { + Locate(0, screenLinesCount-1); + print(isFirstPage ? " " : "<--"); + + Locate(currentScreenConfig.screenWidth - 4, screenLinesCount-1); + print(isLastPage ? " " : "-->"); + } ClearInformationArea(); Locate(0, 3); if(partitionsCount == 1) { PrintCentered(partitionsExistInDisk ? "One partition found on device" : "One new partition defined"); } else { - sprintf(buffer, partitionsExistInDisk ? "%i partitions found on device" : "%i new partitions defined", partitionsCount); + if(allPartitionsArePrimary) { + sprintf(buffer, partitionsExistInDisk ? "%i primary partitions found on device" : "%i new primary partitions defined", partitionsCount); + } else { + sprintf(buffer, partitionsExistInDisk ? "%i partitions found on device" : "%i new partitions defined", partitionsCount); + } PrintCentered(buffer); } NewLine(); @@ -925,23 +958,72 @@ void ShowPartitions() } else if(key == CURSOR_RIGHT && !isLastPage) { firstShownPartitionIndex += PARTITIONS_PER_PAGE; break; - } + } else if(isFirstPage && key>=KEY_1 && keystatus ^= 0x80; + return; + } + + status = partition->status; + primaryIndex = partition->primaryIndex; + extendedIndex = partition->extendedIndex; + + sprintf(buffer, "%set active bit of partition %i? (y/n) ", status & 0x80 ? "Res" : "S", partitionIndex + 1); + PrintStateMessage(buffer); + if(!GetYesOrNo()) { + return; + } + + regs.Bytes.A = selectedDriver->slot; + regs.Bytes.B = 0xFF; + regs.Bytes.D = selectedDeviceIndex; + regs.Bytes.E = selectedLunIndex + 1; + regs.Bytes.H = partition->primaryIndex | 0x80; + regs.Bytes.L = partition->extendedIndex; + DosCallFromRom(_GPART, REGS_ALL); + if(regs.Bytes.A != 0) { + return; + } + + ((uint*)&(partitionTableEntrySector))[0] = regs.UWords.DE; + ((uint*)&(partitionTableEntrySector))[1] = regs.UWords.HL; + + PreparePartitioningProcess(); //Needed to set up driver slot, device index, etc + error = ToggleStatusBit(extendedIndex == 0 ? primaryIndex-1 : 0, partitionTableEntrySector); + if(error == 0) { + partition->status ^= 0x80; + } else { + sprintf(buffer, "Error when accessing device: %i", error); + ClearInformationArea(); + Locate(0,7); + PrintCentered(buffer); + PrintStateMessage("Press any key..."); + WaitKey(); + } + + return; +} void PrintOnePartitionInfo(partitionInfo* info) { - if(!partitionsExistInDisk && partitionsCount <= 4) { - putchar(info->primaryIndex == 1 ? '1' : info->extendedIndex + 1 + '0'); - } else { - putchar(info->primaryIndex + '0'); - if(info->extendedIndex != 0) { - printf("-%i", info->extendedIndex); - } - } - print(": "); + printf("%c %i: ", info->status & 0x80 ? '*' : ' ', info->extendedIndex == 0 ? info->primaryIndex : info->extendedIndex + 1); + if(info->partitionType == PARTYPE_FAT12) { print("FAT12"); } else if(info->partitionType == PARTYPE_FAT16 || info->partitionType == PARTYPE_FAT16_SMALL || info->partitionType == PARTYPE_FAT16_LBA) { @@ -1050,7 +1132,7 @@ void AddPartition() buffer[0] = 6; regs.Words.DE = (int)buffer; - DosCall(_BUFIN, REGS_NONE); + DosCallFromRom(_BUFIN, REGS_NONE); lineLength = buffer[1]; if(lineLength == 0) { return; @@ -1106,9 +1188,10 @@ void AddAutoPartition() { partitionInfo* partition = &partitions[partitionsCount]; + partition->status = partitionsCount == 0 ? 0x80 : 0; partition->sizeInK = autoPartitionSizeInK; partition->partitionType = - partition->sizeInK > MAX_FAT12_PARTITION_SIZE_IN_K ? PARTYPE_FAT16 : PARTYPE_FAT12; + partition->sizeInK > MAX_FAT12_PARTITION_SIZE_IN_K ? PARTYPE_FAT16_LBA : PARTYPE_FAT12; if(partitionsCount == 0) { partition->primaryIndex = 1; partition->extendedIndex = 0; @@ -1198,7 +1281,7 @@ void PrintDosErrorMessage(byte code, char* header) regs.Bytes.B = code; regs.Words.DE = (int)buffer; - DosCall(_EXPLAIN, REGS_NONE); + DosCallFromRom(_EXPLAIN, REGS_NONE); if(strlen(buffer) > currentScreenConfig.screenWidth) { print(buffer); } else { @@ -1285,11 +1368,8 @@ bool WritePartitionTable() //masterBootRecord* mbr = (masterBootRecord*)buffer + 80; byte error; - if(partitionsCount <= 4) { - sprintf(buffer, "Create %i primary partitions on device", partitionsCount); - } else { - sprintf(buffer, "Create %i partitions on device", partitionsCount); - } + sprintf(buffer, "Create %i partitions on device", partitionsCount); + if(!ConfirmDataDestroy(buffer)) { return false; } @@ -1299,8 +1379,8 @@ bool WritePartitionTable() PrintStateMessage("Please wait..."); Locate(0, MESSAGE_ROW); - PrintCentered("Preparing partitionning process..."); - PreparePartitionningProcess(); + PrintCentered("Preparing partitioning process..."); + PreparePartitioningProcess(); for(i = 0; i < partitionsCount; i++) { Locate(0, MESSAGE_ROW); @@ -1326,7 +1406,7 @@ bool WritePartitionTable() } -void PreparePartitionningProcess() +void PreparePartitioningProcess() { byte* remoteCallParams = buffer; @@ -1337,7 +1417,7 @@ void PreparePartitionningProcess() *((partitionInfo**)&remoteCallParams[5]) = &partitions[0]; *((uint*)&remoteCallParams[7]) = luns[selectedLunIndex].sectorsPerTrack; - CallFunctionInExtraBank(f_PreparePartitionningProcess, remoteCallParams); + CallFunctionInExtraBank(f_PreparePartitioningProcess, remoteCallParams); } @@ -1350,6 +1430,15 @@ byte CreatePartition(int index) return (byte)CallFunctionInExtraBank(f_CreatePartition, remoteCallParams); } +byte ToggleStatusBit(byte partitionTableEntryIndex, ulong partitionTablesector) +{ + byte* remoteCallParams = buffer; + + remoteCallParams[0] = partitionTableEntryIndex; + *((ulong*)&remoteCallParams[1]) = partitionTablesector; + + return (byte)CallFunctionInExtraBank(f_ToggleStatusBit, remoteCallParams); +} bool ConfirmDataDestroy(char* action) { @@ -1416,7 +1505,7 @@ void GetDriversInformation() while(error == 0 && driverIndex <= MAX_INSTALLED_DRIVERS) { regs.Bytes.A = driverIndex; regs.Words.HL = (int)currentDriver; - DosCall(_GDRVR, REGS_AF); + DosCallFromRom(_GDRVR, REGS_AF); if((error = regs.Bytes.A) == 0 && (currentDriver->flags & (DRIVER_IS_DOS250 | DRIVER_IS_DEVICE_BASED) == (DRIVER_IS_DOS250 | DRIVER_IS_DEVICE_BASED))) { installedDriversCount++; TerminateRightPaddedStringWithZero(currentDriver->driverName, DRIVER_NAME_LENGTH); @@ -1451,7 +1540,7 @@ byte WaitKey() byte GetKey() { regs.Bytes.E = 0xFF; - DosCall(_DIRIO, REGS_AF); + DosCallFromRom(_DIRIO, REGS_AF); return regs.Bytes.A; } @@ -1505,7 +1594,7 @@ void PrintRuler() HomeCursor(); for(i = 0; i < currentScreenConfig.screenWidth; i++) { - putchar('-'); + chput('-'); } } @@ -1543,7 +1632,7 @@ void PrintStateMessage(char* string) } -void putchar(char ch) __naked +void chput(char ch) __naked { __asm push ix @@ -1591,5 +1680,6 @@ int CallFunctionInExtraBank(int functionNumber, void* parametersBuffer) } -#include "asmcall.c" -#include "printf.c" +#include "../../tools/C/printf.c" +#include "../../tools/C/asmcall.c" +#include "drivercall.c" \ No newline at end of file diff --git a/source/kernel/bank5/fdisk.h b/source/kernel/bank5/fdisk.h index 8799305c..ae4fe26e 100644 --- a/source/kernel/bank5/fdisk.h +++ b/source/kernel/bank5/fdisk.h @@ -3,7 +3,8 @@ #define f_CalculateFatFileSystemParameters 1 #define f_CreateFatFileSystem 2 -#define f_PreparePartitionningProcess 3 +#define f_PreparePartitioningProcess 3 #define f_CreatePartition 4 +#define f_ToggleStatusBit 5 #endif //__FDISK_H \ No newline at end of file diff --git a/source/kernel/bank5/fdisk2.c b/source/kernel/bank5/fdisk2.c index 0905f77e..757432eb 100644 --- a/source/kernel/bank5/fdisk2.c +++ b/source/kernel/bank5/fdisk2.c @@ -15,13 +15,13 @@ #include #include #include -#include "asm.h" -#include "system.h" -#include "dos.h" -#include "types.h" -#include "partit.h" +#include "../../tools/C/types.h" +#include "../../tools/C/system.h" +#include "../../tools/C/dos.h" +#include "../../tools/C/asmcall.h" +#include "drivercall.h" +#include "../../tools/C/partit.h" #include "fdisk.h" -#include "asmcall.h" byte sectorBuffer[512]; byte sectorBufferBackup[512]; @@ -39,6 +39,8 @@ ulong mainExtendedPartitionFirstSector; uint sectorsPerTrack; #define Clear(address, len) memset(address, 0, len) +#define ReadSectorFromDevice(driverSlot, deviceIndex, lunIndex, firstDeviceSector) DeviceSectorRW(driverSlot, deviceIndex, lunIndex, firstDeviceSector, 0) +#define WriteSectorToDevice(driverSlot, deviceIndex, lunIndex, firstDeviceSector) DeviceSectorRW(driverSlot, deviceIndex, lunIndex, firstDeviceSector, 1) int remote_CreateFatFileSystem(byte* callerParameters); byte CreateFatFileSystem(byte driverSlot, byte deviceIndex, byte lunIndex, ulong firstDeviceSector, ulong fileSystemSizeInK); @@ -50,11 +52,12 @@ int remote_CalculateFatFileSystemParameters(byte* callerParameters); void CalculateFatFileSystemParameters(ulong fileSystemSizeInK, dosFilesystemParameters* parameters); int CalculateFatFileSystemParametersFat12(ulong fileSystemSizeInK, dosFilesystemParameters* parameters); int CalculateFatFileSystemParametersFat16(ulong fileSystemSizeInK, dosFilesystemParameters* parameters); -byte WriteSectorToDevice(byte driverSlot, byte deviceIndex, byte lunIndex, ulong firstDeviceSector); -int remote_PreparePartitionningProcess(byte* callerParameters); +byte DeviceSectorRW(byte driverSlot, byte deviceIndex, byte lunIndex, ulong firstDeviceSector, byte write); +int remote_PreparePartitioningProcess(byte* callerParameters); int remote_CreatePartition(byte* callerParameters); int CreatePartition(int index); -void putchar(char ch); +int remote_ToggleStatusBit(byte* callerParameters); +int ToggleStatusBit(byte partitionTableEntryIndex, ulong partitonTablesector); void Locate(byte x, byte y); //BC = function number (defined in fdisk.h), HL = address of parameters block @@ -68,12 +71,15 @@ int main(int bc, int hl) case f_CreateFatFileSystem: return remote_CreateFatFileSystem((byte*)hl); break; - case f_PreparePartitionningProcess: - return remote_PreparePartitionningProcess((byte*)hl); + case f_PreparePartitioningProcess: + return remote_PreparePartitioningProcess((byte*)hl); break; case f_CreatePartition: return remote_CreatePartition((byte*)hl); break; + case f_ToggleStatusBit: + return remote_ToggleStatusBit((byte*)hl); + break; default: return 0; } @@ -439,9 +445,9 @@ int CalculateFatFileSystemParametersFat16(ulong fileSystemSizeInK, dosFilesystem } -byte WriteSectorToDevice(byte driverSlot, byte deviceIndex, byte lunIndex, ulong firstDeviceSector) +byte DeviceSectorRW(byte driverSlot, byte deviceIndex, byte lunIndex, ulong firstDeviceSector, byte write) { - regs.Flags.C = 1; + regs.Flags.C = write; regs.Bytes.A = deviceIndex; regs.Bytes.B = 1; regs.Bytes.C = lunIndex; @@ -453,7 +459,7 @@ byte WriteSectorToDevice(byte driverSlot, byte deviceIndex, byte lunIndex, ulong } -int remote_PreparePartitionningProcess(byte* callerParameters) +int remote_PreparePartitioningProcess(byte* callerParameters) { int i; int sectorsRemaining; @@ -495,38 +501,22 @@ int CreatePartition(int index) ulong firstFileSystemSector; ulong extendedPartitionFirstAbsoluteSector; partitionTableEntry* tableEntry; - bool onlyPrimaryPartitions = (partitionsCount <= 4); ulong x; - if(onlyPrimaryPartitions) { - mbrSector = 0; - tableEntry = &(mbr->primaryPartitions[index]); - if(index == 0) { - ClearSectorBuffer(); - nextDeviceSector = 1; - } else { - memcpy(sectorBuffer, sectorBufferBackup, 512); - } - tableEntry->firstAbsoluteSector = nextDeviceSector; - } else { - mbrSector = nextDeviceSector; - tableEntry = &(mbr->primaryPartitions[0]); - ClearSectorBuffer(); - tableEntry->firstAbsoluteSector = 1; - } + mbrSector = nextDeviceSector; + tableEntry = &(mbr->primaryPartitions[0]); + ClearSectorBuffer(); + tableEntry->firstAbsoluteSector = 1; + tableEntry->status = partition->status; tableEntry->partitionType = partition->partitionType; tableEntry->sectorCount = partition->sizeInK * 2; firstFileSystemSector = mbrSector + tableEntry->firstAbsoluteSector; - if(onlyPrimaryPartitions){ - nextDeviceSector = tableEntry->firstAbsoluteSector + tableEntry->sectorCount; - } else { - nextDeviceSector += tableEntry->firstAbsoluteSector + tableEntry->sectorCount; - } + nextDeviceSector += tableEntry->firstAbsoluteSector + tableEntry->sectorCount; - if(!onlyPrimaryPartitions && index != (partitionsCount - 1)) { + if(index != (partitionsCount - 1)) { tableEntry++; tableEntry->partitionType = PARTYPE_EXTENDED; tableEntry->firstAbsoluteSector = nextDeviceSector; @@ -560,20 +550,29 @@ int CreatePartition(int index) return CreateFatFileSystem(driverSlot, deviceIndex, selectedLunIndex, firstFileSystemSector, partition->sizeInK); } - -void putchar(char ch) __naked +int remote_ToggleStatusBit(byte* callerParameters) { - __asm - push ix - ld ix,#4 - add ix,sp - ld a,(ix) - call CHPUT - pop ix - ret - __endasm; + return (int)ToggleStatusBit( + callerParameters[0], + *((ulong*)&callerParameters[1])); } +int ToggleStatusBit(byte partitionTableEntryIndex, ulong partitonTablesector) +{ + int error; + masterBootRecord* mbr = (masterBootRecord*)sectorBuffer; + partitionTableEntry* entry; + + error = ReadSectorFromDevice(driverSlot, deviceIndex, selectedLunIndex, partitonTablesector); + if(error != 0) + return error; + + entry =&mbr->primaryPartitions[partitionTableEntryIndex]; + + entry->status ^= 0x80; + + return WriteSectorToDevice(driverSlot, deviceIndex, selectedLunIndex, partitonTablesector); +} void Locate(byte x, byte y) { @@ -583,4 +582,5 @@ void Locate(byte x, byte y) } -#include "asmcall.c" +#include "../../tools/C/asmcall.c" +#include "drivercall.c" \ No newline at end of file diff --git a/source/kernel/bank6/dos.h b/source/kernel/bank6/dos.h index 9b8c15b8..c3fff8bd 100644 --- a/source/kernel/bank6/dos.h +++ b/source/kernel/bank6/dos.h @@ -47,7 +47,7 @@ typedef struct { uint cylinders; byte heads; byte sectorsPertrack; - bool suitableForPartitionning; + bool suitableForPartitioning; } lunInfo; @@ -75,7 +75,7 @@ typedef struct { #define LUN_INFO 0x4169 -#define BK4_ADD 0xF84C +#define BK4_ADD 0xF1CF #endif //__DOS_H \ No newline at end of file diff --git a/source/kernel/compile.bat b/source/kernel/compile.bat index c9b68218..e68e6fd6 100644 --- a/source/kernel/compile.bat +++ b/source/kernel/compile.bat @@ -1,6 +1,8 @@ @echo off cls +if .%1==.drivers goto :drivers + echo . echo **************** echo *** COMMON *** @@ -34,7 +36,7 @@ copy ..\rel.rel copy ..\chgbnk.rel copy ..\drv.rel for %%A in (DOSHEAD,40FF,B0,INIT,ALLOC,DSKBASIC,DOSBOOT,BDOS,RAMDRV) do cpm32 M80 =%%A -cpm32 l80 /p:4000,CODES,KVAR,DATA,REL,DOSHEAD,40FF,B0,INIT,ALLOC,DSKBASIC,DOSBOOT,BDOS,RAMDRV,/p:781F,drv,/p:7fd0,chgbnk,b0/n/x/y/e +cpm32 l80 /p:4000,CODES,KVAR,DATA,REL,DOSHEAD,40FF,B0,INIT,ALLOC,DSKBASIC,DOSBOOT,BDOS,RAMDRV,/p:7700,drv,/p:7fd0,chgbnk,b0/n/x/y/e hex2bin b0.hex ..\SymToEqus b0.sym b0labels.inc "\?[^ \t]+|DOSV0|GETERR|BDOSE" ..\SymToEqus b0.sym b0lab_b3.inc "INIT|TIMINT|MAPBIO|GWRK|R_[^ \t]+" @@ -96,7 +98,7 @@ copy ..\bank0\doshead.rel copy ..\bank0\40FF.rel copy ..\bank0\b0lab_b3.inc b0labels.inc for %%A in (DOS1KER,B3) do cpm32 M80 =%%A -cpm32 l80 /p:4000,CODES,KVAR,DATA,DOSHEAD,40FF,B3,DOS1KER,/p:781F,drv,/p:7fd0,chgbnk,b3/N/X/Y/E +cpm32 l80 /p:4000,CODES,KVAR,DATA,DOSHEAD,40FF,B3,DOS1KER,/p:7700,drv,/p:7fd0,chgbnk,b3/N/X/Y/E rem cpm32 l80 /p:4000,CODES,KVAR,DATA,DOSHEAD,40FF,B3,DOS1KER,drv,/p:7fd0,chgbnk,b3/N/X/Y/E hex2bin -s 4000 b3.hex @@ -177,8 +179,10 @@ dd if=bank5\fdisk.dat of=dos250ba.dat bs=1 count=16000 seek=82176 dd if=bank5\fdisk2.dat of=dos250ba.dat bs=1 count=8000 seek=98560 copy bank4\b4rd.bin dd if=b4rd.bin of=dos250ba.dat bs=1 count=15 seek=65664 -copy dos250ba.dat Nextor-2.1.0-beta1.base.dat -copy dos250ba.dat ..\..\bin\kernels\Nextor-2.1.0-beta1.base.dat +copy dos250ba.dat Nextor-2.1.0-beta2.base.dat +copy dos250ba.dat ..\..\bin\kernels\Nextor-2.1.0-beta2.base.dat + +:drivers echo . echo ***************** @@ -212,8 +216,8 @@ cpm32 L80 /P:7fd0,CHGBNK,CHGBNK/N/X/Y/E hex2bin -s 4000 driver.hex hex2bin -s 7FD0 CHGBNK.hex -..\..\..\..\wintools\mknexrom ..\..\Nextor-2.1.0-beta1.base.dat Nextor-2.1.0-beta1.%%~nc.ROM /d:driver.bin /m:chgbnk.bin -copy Nextor-2.1.0-beta1.%%~nc.ROM ..\..\..\..\bin\kernels +..\..\..\..\wintools\mknexrom ..\..\Nextor-2.1.0-beta2.base.dat Nextor-2.1.0-beta2.%%~nc.ROM /d:driver.bin /m:chgbnk.bin +copy Nextor-2.1.0-beta2.%%~nc.ROM ..\..\..\..\bin\kernels del b6.mac del *.rom cd .. @@ -227,10 +231,43 @@ echo *** echo . cd MegaFlashRomSD -..\..\..\..\wintools\mknexrom ..\..\Nextor-2.1.0-beta1.base.dat nextor2.rom /d:driver.bin /m:Mapper.ASCII8.bin -copy nextor2.rom ..\..\..\..\bin\kernels\Nextor-2.1.0-beta1.MegaFlashSDSCC.ROM +..\..\..\..\wintools\mknexrom ..\..\Nextor-2.1.0-beta2.base.dat nextor2.rom /d:driver-1slot.dat /m:Mapper.ASCII8.bin +copy nextor2.rom ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.MegaFlashSDSCC.1-slot.ROM +sjasm makerecoverykernel.asm kernel.dat +copy kernel.dat ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.MegaFlashSDSCC.1-slot.Recovery.ROM +del nextor2.rom +..\..\..\..\wintools\mknexrom ..\..\Nextor-2.1.0-beta2.base.dat nextor2.rom /d:driver-2slots.dat /m:Mapper.ASCII8.bin +copy nextor2.rom ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.MegaFlashSDSCC.2-slots.ROM sjasm makerecoverykernel.asm kernel.dat -copy kernel.dat ..\..\..\..\bin\kernels\Nextor-2.1.0-beta1.MegaFlashSDSCC.Recovery.ROM +copy kernel.dat ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.MegaFlashSDSCC.2-slots.Recovery.ROM +cd .. + +echo . +echo *** +echo *** Driver: Sunrise IDE +echo *** +echo . + +cd SunriseIDE + +del ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.SunriseIDE.emulators.ROM +ren ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.SunriseIDE.ROM Nextor-2.1.0-beta2.SunriseIDE.emulators.ROM +sjasm -c sunride.asm driver.bin +..\..\..\..\wintools\mknexrom ..\..\Nextor-2.1.0-beta2.base.dat nextor2.rom /d:driver.bin /m:chgbnk.bin +copy nextor2.rom ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.SunriseIDE.ROM +:okide +cd .. + +echo . +echo *** +echo *** Driver: Flashjacks +echo *** +echo . + +cd Flashjacks +sjasm flashjacks.asm driver.bin +..\..\..\..\wintools\mknexrom ..\..\Nextor-2.1.0-beta2.base.dat nextor2.rom /d:driver.bin /m:chgbnk.dat +copy nextor2.rom ..\..\..\..\bin\kernels\Nextor-2.1.0-beta2.Flashjacks.ROM cd .. echo . diff --git a/source/kernel/condasm.inc b/source/kernel/condasm.inc index f1ef44ee..e735232a 100644 --- a/source/kernel/condasm.inc +++ b/source/kernel/condasm.inc @@ -10,8 +10,9 @@ BUILTIN equ -1 ;built-in system ALPHA equ 0 ;Level of Alpha release (0: no alpha) ALPHAL equ "" ;Letter after the Alpha release number, or empty -BETA equ 1 ;Level of Beta release (0: no beta) +BETA equ 2 ;Level of Beta release (0: no beta) RC equ 0 ;Level of RC (0: no RC) +RR equ 0 ;Level of release (0: no release level) ; ;----------------------------------------------------------------------------- ; diff --git a/source/kernel/data.mac b/source/kernel/data.mac index 0c7a45c5..41474d9d 100644 --- a/source/kernel/data.mac +++ b/source/kernel/data.mac @@ -50,11 +50,21 @@ ram_ad defl DATABASE ; ------------------------ ; var PRTBUF,6,F1C9 ;MSX-DOS1 compatible string output routine - spare 4 + +; ------------------------ + +; These are available in MSX-DOS 1 mode too thanks to the modification +; of the STROUT routine, see dos1ker.mac + + spare 1 + ;NOTE! BK4_ADD is manually defined in bank5/dos.h, and must be updated if it changes + var0 IS_FIRST_BOOT + var2 BK4_ADD,F1D0 ;Address of routine to be called in bank 4 + var TMP_SEC,4 ;Used for temporary storage of a 32 bit sector number ; ; ------------------------ ; - var0 JUMPBASE,F1D3 ;Start of jump table. + var0 JUMPBASE,F1D6 ;Start of jump table. ; var3 RD_LDIR ;inter-slot LDIR routine for RAMdisk var3 P0_LDIR ;Data transfer routine used by read/write code @@ -63,7 +73,8 @@ ram_ad defl DATABASE var3 GO_DRV ;Call driver routine var3 JP_VECT ;DOS1 compatible error jump ; - var3 $IRQ ;Interrupt entry point + ;var3 $IRQ ;Moved below DTA_ADDR to make room right before JUMPBASE + ;(which was F1D3 originally) ; var3 $RDSLT ;Inter-slot read var3 $WRSLT ;Inter-slot write @@ -99,16 +110,14 @@ ram_ad defl DATABASE ;var3 FR_BK ;spare 6 ; - var TMP_FROOT,4 ;Temporary area used when activating disk emulation mode - var1 TMP_CS - var2 TMP_NDIR - spare 5 ;For future expansion + spare 12 ;For future expansion ; var1 CUR_DRV ;Current logical drive (1=A:) var2 DTA_ADDR,F23D ;DMAADD used by MSXDOS1.SYS - can not move. ; - var0 NXT7 - spare 7 + var3 $IRQ ;Interrupt entry point + var3 RAM_ABORT ;Stores a RET and a pointer to it (see SET_BOOT_VECTORS in dosboot.mac) + spare 1 ; var1 DIRBFD, F246 ;** May be corrupted sometimes. ; @@ -252,16 +261,18 @@ ram_ad defl DATABASE ; var1 DOS_VER ;DOS version number 2.x ; - var0 DVB_TABLE ;Pointer to table of device-based drives for DOS1 var1 P0_64K ;\ These are the basic 64k RAM segment var1 P1_64K ; \ numbers which should never be changed var1 P2_64K ; / by anyone (including the system). var1 P3_64K ;/ + + const DVB_TABLE,P0_64K ;Pointer to table of device-based drives for DOS1 + const KSLOT,P2_64K ;Slot of disk controller being called (used in DOS 1 mode) ; ;===== start mod DOS2.50 (support MegaSCSI) var1 NXT_VER ;Nextor version numbr var1 MAIN_BANK - var KER250,4 ;MSX-DOS 2.50 kernel slots, + var KER250,4 ;Nextor kernel slots, ;bit 6 is set if timer interrupt routine is to be called ;bit 5 is set if the driver provides configuration var _TIME_IRQ,5,F31E @@ -273,24 +284,8 @@ ram_ad defl DATABASE var2 DISKVECT,F323 ;BDOS_GO disk error vector var2 BREAKVECT,F325 ;BDOS_GO ctrl-stop vector ; - var AUXBODY,3,F327 ;Actually 10 - var1 NXTEMP ;For temporary usage by AUTO_ASSIGN - var0 NXT2 ;(values are saved in the stack and later restored) - var1 TMPLUN - var1 TMPDEV - var1 NXT3 - var3 NXT4 + var AUXBODY,10,F327 - ;These variables are declared inside ARG, a 16 byte area used by math-pack. - ;There should be no conflict since DOS kernel and math-pack - ;are not intended to use this area at the same time. - -ARG equ 0F847h - const KSLOT,ARG ;Slot of disk controller being called (used in DOS 1 mode) - const TMP_SEC,ARG+1 ;Used to temporary storage of a 32 bit sector number - const BK4_ADD,ARG+5 ;Address of routine to be called in bank 4 - const BUF9,ARG+7 ;Use by auto-assign routine in bank 4 -; spare 2 var2 $DOS1 ;MSX-DOS1 compatible page-1 BDOS entry spare 1 @@ -596,6 +591,11 @@ ram_ad defl 04115h-6 var3 SET1INT var3 PRV1INT +;----------------------------------------------------------------------------- +; +; Fields in the disk amulation mode table + + ;----------------------------------------------------------------------------- ; diff --git a/source/kernel/drivers/.gitignore b/source/kernel/drivers/.gitignore index 24a9e0df..9b45e266 100644 --- a/source/kernel/drivers/.gitignore +++ b/source/kernel/drivers/.gitignore @@ -3,3 +3,4 @@ bank.inc condasm.inc const.inc macros.inc +**/*.out diff --git a/source/kernel/drivers/Flashjacks/chgbnk.dat b/source/kernel/drivers/Flashjacks/chgbnk.dat new file mode 100644 index 00000000..fe5cb289 --- /dev/null +++ b/source/kernel/drivers/Flashjacks/chgbnk.dat @@ -0,0 +1 @@ +ÅË?ËË?ËË?ËË?ËË?ËxÁæø2AÉÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ \ No newline at end of file diff --git a/source/kernel/drivers/SunriseIDE/DRIVER.02.MAC b/source/kernel/drivers/Flashjacks/flashjacks.asm similarity index 59% rename from source/kernel/drivers/SunriseIDE/DRIVER.02.MAC rename to source/kernel/drivers/Flashjacks/flashjacks.asm index 1b17453e..208fea1e 100644 --- a/source/kernel/drivers/SunriseIDE/DRIVER.02.MAC +++ b/source/kernel/drivers/Flashjacks/flashjacks.asm @@ -1,43 +1,37 @@ - ; Device-based driver for the sunrise IDE interface for MSX-DOS 2.50 + ; Device-based driver for the FLASHJACKS IDE interface for Nextor ; - ; Version 0.1 - ; By Konamiman + ; By Aquijacks v1.4 + ; Based on version 0.1 by Konamiman and 0.15 by Piter Punk + + ;output "sunride_aquijacks.bin" + + org $4000 + + ds 256, $FF ; 256 dummy bytes - ;org 4100h DRV_START: TESTADD equ 0F3F5h -TIMEVAR equ 0FC9Eh ;----------------------------------------------------------------------------- ; ; Driver configuration constants ; -;Driver type: -; 0 for drive-based -; 1 for device-based - -DRV_TYPE equ 1 ;Hot-plug devices support (device-based drivers only): ; 0 for no hot-plug support ; 1 for hot-plug support -DRV_HOTPLUG equ 0 +DRV_HOTPLUG equ 1 -DEBUG equ 0 ;Set to 1 for debugging, 0 to normal operation ;Driver version -VER_MAIN equ 0 -VER_SEC equ 2 -VER_REV equ 0 - - if DEBUG eq 1 - include B0LABELS.INC - endif +VER_MAIN equ 1 +VER_SEC equ 4 +VER_REV equ 1 ;This is a very barebones driver. It has important limitations: ;- CHS mode not supported, disks must support LBA mode. @@ -50,9 +44,8 @@ VER_REV equ 0 ; ; IDE registers and bit definitions -IDE_BANK equ 4104h - ;bit 0: enable (1) or disable (0) IDE registers - ;bits 5-7: select 16K ROM bank +IDE_BANK equ 4104h ;bit 0: enable (1) or disable (0) IDE registers + ;bits 5-7: select 16K ROM bank IDE_DATA equ 7C00h ;Data registers, this is a 512 byte area IDE_ERROR equ 7E01h ;Error register IDE_FEAT equ 7E01h ;Feature register @@ -63,10 +56,10 @@ IDE_CYLOW equ 7E04h ;Cylinder low (CHS mode) IDE_LBAMID equ 7E04h ;Logical sector mid (LBA mode) IDE_CYHIGH equ 7E05h ;Cylinder high (CHS mode) IDE_LBAHIGH equ 7E05h ;Logical sector high (LBA mode) -IDE_HEAD equ 7E06h - ;bits 0-3: Head (CHS mode), logical sector higher (LBA mode) +IDE_HEAD equ 7E06h ;bits 0-3: Head (CHS mode), logical sector higher (LBA mode) IDE_STATUS equ 7E07h ;Status register -IDE_CMD equ 7E07h ;Command register +IDE_CMD equ 7E07h ;Command register +IDE_FLASHJACKS equ 7E09h ;Registro FlashJacks IDE_DEVCTRL equ 7E0Eh ;Device control register ; Bits in the error register @@ -116,6 +109,8 @@ M_SRST equ (1 SHL SRST) CHPUT equ 00A2h ;Character output CHGET equ 009Fh +CLS equ 00C3h +MSXVER equ 002Dh ;----------------------------------------------------------------------------- @@ -156,22 +151,18 @@ CHGET equ 009Fh ; Error codes for DEV_RW and DEV_FORMAT ; -if DRV_TYPE eq 1 - -.NCOMP equ 0FFh -.WRERR equ 0FEh -.DISK equ 0FDh -.NRDY equ 0FCh -.DATA equ 0FAh -.RNF equ 0F9h -.WPROT equ 0F8h -.UFORM equ 0F7h -.SEEK equ 0F3h -.IFORM equ 0F0h -.IDEVL equ 0B5h -.IPARM equ 08Bh - -endif +NCOMP equ 0FFh +WRERR equ 0FEh +DISK equ 0FDh +NRDY equ 0FCh +DATA equ 0FAh +RNF equ 0F9h +WPROT equ 0F8h +UFORM equ 0F7h +SEEK equ 0F3h +IFORM equ 0F0h +IDEVL equ 0B5h +IPARM equ 08Bh ;----------------------------------------------------------------------------- ; @@ -266,13 +257,7 @@ SING_DBL equ 7420h ;"1-Single side / 2-Double side" ; bit 0: 0 for drive-based, 1 for device-based ; bit 1: 1 for hot-plug devices supported (device-based drivers only) -if DRV_TYPE eq 0 - db 0 -endif - -if DRV_TYPE eq 1 db 1+(2*DRV_HOTPLUG) -endif ;Reserved byte db 0 @@ -297,25 +282,16 @@ DRV_NAME: jp DRV_DIRECT3 jp DRV_DIRECT4 - ds 15 -if DRV_TYPE eq 0 - jp DRV_DSKIO - jp DRV_DSKCHG - jp DRV_GETDPB - jp DRV_CHOICE - jp DRV_DSKFMT - jp DRV_MTOFF -endif + ds 15 -if DRV_TYPE eq 1 jp DEV_RW jp DEV_INFO jp DEV_STATUS jp LUN_INFO jp DEV_FORMAT jp DEV_CMD -endif + ;----------------------------------------------------------------------------- @@ -345,7 +321,7 @@ DRV_TIMI: ; Input: ; A = 1 ; B = number of allocated drives for this controller -; (255 if device-based driver, unless 4 i pressed at boot) +; (255 if device-based driver, unless 4 is pressed at boot) ; ; The work area address can be obtained by using GWORK. ; @@ -368,235 +344,369 @@ DRV_INIT: or a ld hl,0 ld a,2 - ret z ;Note that Cy is 0 (no interrupt hooking needed) + ret z ;Note that Cy is 0 (no interrupt hooking needed) ;xor a ;ld (TESTADD),a - ld de,INFO_S - call PRINT - -if DEBUG eq 1 - call DO - - ld hl,8101h - ld (DRVTBL##),hl - ld hl,8301h - ld (DRVTBL##+2),hl - ld hl,8501h - ld (DRVTBL##+4),hl - ld hl,0 - ld (DRVTBL##+6),hl - - ld a,87h - ld (KER250##),a - ld a,85h - ld (KER250##+1),a - ld a,89h - ld (KER250##+2),a + ;--- Borra la pantalla. En los MSX1 hay que decirselo ya que no lo tiene implementado de serie. + + push af ; Guarda las variables de inicio. + push bc + push hl + ;bit 0,a ; Pone a cero el flag Z + ;xor a ; Pone a cero a + ;call CLS + ;--- Este m�todo de borrado es mejor. Aportado por Victor. + ld a,40 ; 40 columnas + ld (0F3AEh),a xor a - ld (KER250##+3),a - - ld a,1 - ld ix,GDRIVER## - ex af,af' - ld a,4 - call CALBNK - jp DRV_INIT_END - - -;Input: Cy=0 to read, 1 to write -; A = Device number, 1 to 7 -; B = Logical unit number, 1 to 7 -; C = Number of sectors to read or write -; HL = Source or destination memory address for the transfer -; DE = Address where the 4 byte sector number is stored. - - ld hl,0C000h - ld ($SECBUF##),hl - - ;ld hl,GPART## - ;ld (BK4_ADD##),hl + call 005Fh ; Screen 0 - ld b,1 - ld c,0FFh - ld d,1 - ld e,1 - ld h,4 - ld l,0 - - ld ix,GPART## - ex af,af' - ld a,4 - call CALBNK - jp DRV_INIT_END - - or a - ld a,1 - ld b,1 - ld c,3 - ld hl,0 - ld (0C000h),hl - ld (0C002h),hl - ld hl,0C000h - ld de,0C000h - call DEV_RW - - ld a,1 - ld (0C000h),a - ld a,2 - ld (0C200h),a - ld a,34h - ld (0C000h+512*3-1),a - - scf - ld a,1 - ld b,1 - ld c,3 - ld hl,0 - ld (0C000h),hl - ld (0C002h),hl - ld hl,0C000h - ld de,0C000h - call DEV_RW - - jp DRV_INIT_END - -luninfo: - - ld a,1 - ld b,1 - ld hl,0C000h - call LUN_INFO - ld a,2 - ld b,1 - ld hl,0C000h - call LUN_INFO - ld a,3 - ld b,1 - ld hl,0C000h - call LUN_INFO - ld a,2 - ld b,2 - ld hl,0C000h - call LUN_INFO + ;--- Comprueba el bit de doble reset y lo ejecuta en caso de estar en on. + call IDE_ON + ld a,(IDE_FLASHJACKS) ; Trae el registro de Flashjacks. + and 11110100b ; Anula los bits de freq y deja solo la marca de comprobaci�n y el bit de reset. + cp 0A4h ; Comprueba marca de comprobaci�n y bit de reset + jr nz,CONTPRG ; No ha detectado una marca correcta del registro flashjacks por lo que no ejecuta nada del reset. + call IDE_OFF + pop hl ; Retorno de las variables de inicio. + pop bc + pop af + rst 0 ; Fuerza un reset. A partir de aqu� hace un soft reset y no continua con el programa. +CONTPRG: + call IDE_OFF + + ;---------------------------------------------- + ;Compruba las teclas F4 y F5 (VDP FREQ y fuerza TURBOCPU) + push af + push hl + push de + push bc - jp DRV_INIT_END + ; Compara tecla pulsada + ld b,7 ;row 7 RET SELECT BS STOP TAB ESC F5 F4 + in a,(0AAh) + and 11110000b + or b + out (0AAh),a + in a,(0A9h) + bit 0,a ;F4 -- Si es tecla pulsada turbo va a la rutina de activaci�n del turbo. + jr nz,Fin_ini ; Salta si no se pulsa tecla de turbo. + push af + call putTURBO_CPU ; Ejecuta el turbo CPU. + pop af +Fin_ini:pop bc + pop de + pop hl + pop af + + ;--- Comienza la escritura en pantalla del driver. + ld de,INFO_S + call PRINT + + ;--- Saca por pantalla el modelo de ordenador. + ld de,MODELO ; Escribre Modelo: + call PRINT + ld a,(MSXVER) ; Trae el registro de version de MSX de la BIOS + cp 00h ; Si es un MSX1 realiza un salto a la escritura de MSX1. + jr z,IMP_MSX1 + cp 01h ; Si es un MSX2 realiza un salto a la escritura de MSX2. + jr z,IMP_MSX2 + cp 02h ; Si es un MSX2+ realiza un salto a la escritura de MSX2+. + jr z,IMP_MSX2M + cp 03h ; Si es un MSX TurboR realiza un salto a la escritura de MSX TurboR. + jr z,IMP_MSXR + cp 04h ; Si es un OCM realiza un salto a la escritura de OCM. + jr z,IMP_OCM + jp NO_DETEC ; Si no es ninguna de las versiones mencionadas, imprime un no detectado. +IMP_MSX1: + ld de,M_MSX1 + call PRINT + jp FIN_IMP; +IMP_MSX2: + ld de,M_MSX2 + call PRINT + jp FIN_IMP; +IMP_MSX2M: + ld de,M_MSX2M + call PRINT + jp FIN_IMP; +IMP_MSXR: + ld de,M_MSXR + call PRINT + jp FIN_IMP; +IMP_OCM: + ld de,M_OCM + call PRINT + jp FIN_IMP; +NO_DETEC: + ld de,M_NDTC + call PRINT +FIN_IMP: + pop hl ; Retorno de las variables de inicio. + pop bc + pop af - ld a,1 - ld b,0 - ld hl,0C000h - call DEV_INFO - ld a,1 - ld b,1 - ld hl,0C000h - call DEV_INFO - ld a,1 - ld b,2 - ld hl,0C000h - call DEV_INFO - ld a,1 - ld b,3 - ld hl,0C000h - call DEV_INFO - jp DRV_INIT_END -DO: -endif + ;-- B�squeda de la unidad por pantalla. + ld de,SEARCH_S + call PRINT ld a,1 call MY_GWORK call IDE_ON - ld (ix),0 - ld (ix+4),0 ;Assume no devices initially + ld (ix),0 ;Assume both devices empty + ld (ix+4),0 - ;--- Perform a software reset on both devices - - ld a,M_SRST - ld (IDE_DEVCTRL),a - nop ;Wait 5 us - xor a - ld (IDE_DEVCTRL),a + ld a,M_SRST ;Do a software reset + ld (IDE_DEVCTRL),a + nop ;Wait 5 us + xor a + ld (IDE_DEVCTRL),a WAIT_RESET: - ld a,(IDE_STATUS) - and M_BSY+M_DRDY - cp M_DRDY - jr nz,WAIT_RESET ;Wait for BSY to clear and DRDY to set - - ;--- Determine whether there is any device connected - ; by looking at the diagnostic code in the error register + ld de,7640 ;Timeout after 30 s +WAIT_RESET1: + ld a,0 + cp e + jr nz,WAIT_DOT ;Print dots while waiting + ld a,46 + call CHPUT +WAIT_DOT: + call CHECK_ESC + jp c,INIT_NO_DEV + ld b,255 +WAIT_RESET2: + ld a,(IDE_STATUS) + and M_BSY+M_DRDY + cp M_DRDY + jr z,WAIT_RESET_END ;Wait for BSY to clear and DRDY to set + djnz WAIT_RESET2 + dec de + ld a,d + or e + jr nz,WAIT_RESET1 + jp INIT_NO_DEV +WAIT_RESET_END: + + ;--- Do a quick pre-check on MASTER device - ld a,(IDE_ERROR) - ld b,a - and 1 - cp 1 - jr nz,INIT_NO_DEV ;Master failed: give up - - ld (ix+4),b ;We'll check later if there is a slave - - ;--- Get info and show the name for the master - - xor a - call WRHEAD ;Select device 1 - ld e,a - ld a,0ECh - call DO_IDE2 - jr c,OK_MASTER - - call INIT_CHECK_DEV - jr c,OK_MASTER + ld a,0 + ld (IDE_HEAD),a ;Select device 0 + nop + + call INIT_PRECHECK_DEV + ld a,(IDE_SECCNT) + cp 85 + jr nz,MASTER_CHECK1_END + ld a,(IDE_SECNUM) + cp 170 + jr nz,MASTER_CHECK1_END + + ld a,1 ;Flag the device + ld (ix),a +MASTER_CHECK1_END: + ld a,46 ;Print dot + call CHPUT + + ld a,M_SRST ; Do ANOTHER software reset + ld (IDE_DEVCTRL),a + nop ;Wait 5 us + xor a + ld (IDE_DEVCTRL),a + nop ;Wait 5 us + ld a,46 ;Print dot + call CHPUT + + ld de,CRLF_S + call PRINT + + ;--- Get info and show the name for the MASTER ld de,MASTER_S call PRINT - call INIT_PRINT_NAME - ld (ix),2 ;ATA device with LBA -OK_MASTER: - - ;--- If the presence of slave musy be checked, - ; issue a test command and check for error - - ld a,(ix+4) ;1 if slave OK or not present, 81h if failed - ld (ix+4),0 +WSKIPMAS: ; If ESC is pressed, ignore this device + ld de,624 ; Wait 1s to read the keyboard +WSKIPMAS1: + call CHECK_ESC + jr c,NODEV_MASTER + ld b,64 +WSKIPMAS2: + ex (sp),hl + ex (sp),hl + djnz WSKIPMAS2 + dec de + ld a,d + or e + jr nz,WSKIPMAS1 + + ld a,(ix) ;If the device isn't flagged it doesn't exists cp 1 - jr nz,OK_SLAVE + jr nz,NODEV_MASTER + ld a,46 ;Print FIRST dot + call CHPUT - ld a,M_DEV - call WRHEAD ;Select device 1 - ld e,a - ld a,0ECh - call DO_IDE2 - jr c,OK_SLAVE ;If error, no device, or ATAPI device + call WAIT_CMD_RDY + jr c,NODEV_MASTER + ld a,0 + ld (IDE_HEAD),a ;Select device 0 + ld a,46 ;Print SECOND dot + call CHPUT + + ld a,0ECh ;Send IDENTIFY commad + call DO_IDE + jr c,NODEV_MASTER + ld a,46 ;Print THIRD dot + call CHPUT + + call INIT_CHECK_DEV ;Check if the device is ATA or ATAPI + jr c,NODEV_MASTER + ld a,46 ;Print FOURTH dot + call CHPUT + + call WAIT_CMD_RDY ;Try to select the device + jr c,NODEV_MASTER ;this is our last chance to *NOT* detect it + ld a,0 + ld (IDE_HEAD),a ;Select device 0 + ld a,46 ;Print FIFTH dot + call CHPUT + + call INIT_PRINT_NAME - ;--- Get info and show the name for the slave + ld (ix),2 ;ATA device with LBA + jr OK_MASTER - call INIT_CHECK_DEV - jr c,OK_SLAVE +NODEV_MASTER: + call CHECK_ESC + jr c,NODEV_MASTER - ld de,SLAVE_S + ld (ix),0 + ld de,NODEVS_S call PRINT - call INIT_PRINT_NAME - - ld (ix+4),2 ;ATA device with LBA -OK_SLAVE: - ;--- End of the initialization procedure +OK_MASTER: + ld a,M_SRST ;Last software reset before we go + ld (IDE_DEVCTRL),a ;some times a faulty slave leaves + ;BSY set forever (30s) + nop ;Wait 5 us + xor a + ld (IDE_DEVCTRL),a jr DRV_INIT_END INIT_NO_DEV: + call CHECK_ESC + jr c,INIT_NO_DEV + + ld de,CRLF_S + call PRINT + ld de,MASTER_S + call PRINT ld de,NODEVS_S call PRINT + + ;--- Fin del procedimiento de inicializaci�n. DRV_INIT_END: + ld (ix+4),0 ; Marca que no hay unidad esclava. call IDE_OFF -if DEBUG eq 1 - ;call CHGET ;For debugging -endif - ret + ;--- Retardo de espera de 2 Segundos para que se vea el texto de carga del driver en pantalla. + ;--- Si es un MSXTurboR no lo hace. Este ya tiene retardo de por si en el arranque. + push de + push bc + ld a,(MSXVER) ; Trae el registro de version de MSX de la BIOS + cp 03h ; Si es un MSX TurboR realiza un salto ya que este equipo es lento de por si al arranque. + jr z,ESPERA_FIN ; Omite la espera de 2s para el TurboR + ld de,1861 ;Contador cargado para 2s +ESPERA_RDY1: + ld b,255 +ESPERA_RDY2: + djnz ESPERA_RDY2 ;Bucle ESPERA_RDY2 + dec de + ld a,d + or e + jr nz,ESPERA_RDY1 ;Bucle ESPERA_RDY1 +ESPERA_FIN: + pop bc + pop de + + ;--- Codigo asistencia a la unidad FLASHJACKS. Se ejecuta despues del inicio de NEXTOR. + call IDE_ON + ld a,(MSXVER) ; Trae el registro de version de MSX de la BIOS + cp 00h ; Si es un MSX1 salta la operaci�n de forzado del VDP por incompatibilidad del mismo. + jr z,DEV_FLASH_FIN + + ; Compara tecla pulsada + ld b,7 ;row 7 RET SELECT BS STOP TAB ESC F5 F4 + in a,(0AAh) + and 11110000b + or b + out (0AAh),a + in a,(0A9h) + bit 1,a ;F5 -- Si es tecla pulsada VDP va a la rutina de permutaci�n de frecuencia. + jp z,DEV_VDP_FIN ; Salta la gesti�n del VDP para la permutaci�n del VDP por tecla pulsada. + ld a,(IDE_FLASHJACKS) ; Trae el registro de Flashjacks. + and 11111011b ; Anula el bit de doble reset para comparar el resto. + cp 0A3h ; Forzado a 60Hz. 101000 + Bit de Forzado a 1 + Bit de 60 Hz a 1 + jr z,DEV_FLASH60 ; Salta al forzado a 60 Hz. + cp 0A2h ; Forzado a 50Hz. 101000 + Bit de Forzado a 1 + Bit de 50 Hz a 0 + jr z,DEV_FLASH50 ; Salta al forzado a 50 Hz. + jp DEV_FLASH_FIN ; Otras opciones son ignoradas y no hace cambio alguno. + +DEV_FLASH50: + ld a,02h ; 02h a 50hz y 00h a 60hz + jp DEV_FLASHVDP; + +DEV_FLASH60: + ld a,00h ; 02h a 50hz y 00h a 60hz + +DEV_FLASHVDP: + out (099h),a ;Salida directa del VPD + ld (0ffe8h), a ;Salida por BIOS del VDP registro 9 + ld a,89h + out (099h),a + +DEV_FLASH_FIN: + call IDE_OFF + ret ; Devuelve el control. + +DEV_VDP_FIN: + ; Ejecuta la permutaci�n del VDP existente + ld hl,0ffe8h;VDP register value + ld a,(hl) + xor 2 + ld (hl),a + di + out (99h),a ;Set VDP Frequency + ld a,9+128 + ei + out (099h),a + call IDE_OFF + ret ; Devuelve el control. + +;--- Subroutines for the INIT procedure + +;Check if there is any device listening in the bus +;Input: device already selected +;Output: If something is there, IDE_SECCNT=85, IDE_SECNUM=170 +; Both variables have random values if nothing is there -;--- Subruotines for the INIT procedure +INIT_PRECHECK_DEV: + ld a,85 + ld (IDE_SECCNT),a + ld a,170 + ld (IDE_SECNUM),a + ld a,170 + ld (IDE_SECCNT),a + ld a,85 + ld (IDE_SECNUM),a + ld a,85 + ld (IDE_SECCNT),a + ld a,170 + ld (IDE_SECNUM),a + ret ;Check that a device is present and usable. ;Input: IDENTIFY DEVICE issued successfully. @@ -606,20 +716,72 @@ endif INIT_CHECK_DEV: ld hl,IDE_DATA ld de,TEMP_WORK - ld bc,50*2 ;Get the first 50 data words + ld bc,50*2 ;Get the first 50 data words ldir - ;ld a,(TEMP_WORK+1) - ;and 80h ;ATAPI device? - ;scf - ;ret nz + ld a,(IDE_STATUS) ;Check status + cp 01111111b ;Usually this means "no device" + jr z,INIT_CHECK_NODEV - ld a,(TEMP_WORK+49*2+1) - and 2 ;LBA supported? - scf - ret z + ; "At power-up or after reset, the Command Block Registers are initialized + ; to the following values: + ; + ; REGISTER VALUE + ; 1F1 Error : 01 + ; 1F2 Sector Count : 01 + ; 1F3 Sector Number : 01 + ; 1F4 Cylinder Low : 00 + ; 1F5 Cylinder High : 00 + ; 1F6 Drive / Head : 00" + ; + ; Not all devices respect this. One of my CompactFlash cards never have + ; Sector Count = 01 and Sector Number = 01 after reset. + ; + ; ld a,(IDE_SECNUM) ;Test if the device is REALLY here + ; cp 1 + ; jr nz,INIT_CHECK_NODEV + ; ld a,(IDE_SECCNT) + ; cp 1 + ; jr nz,INIT_CHECK_NODEV + + ld a,(IDE_CYLOW) ;Test for PATAPI devices + cp 20 + jr nz,TEST2_FOR_ATAPI + ld a,(IDE_CYHIGH) + cp 235 + jr z,INIT_CHECK_NODEV +TEST2_FOR_ATAPI: + ld a,(IDE_CYLOW) ;Test for SATAPI devices + cp 105 + jr nz,TEST_FOR_ATA + ld a,(IDE_CYHIGH) + cp 150 + jr z,INIT_CHECK_NODEV + +TEST_FOR_ATA: + ld a,(IDE_CYLOW) ;Test for PATA devices + cp 0 + jr nz,TEST2_FOR_ATA + ld a,(IDE_CYHIGH) + cp 0 + jr z,TEST_FOR_LBA +TEST2_FOR_ATA: + ld a,(IDE_CYLOW) ;Test for SATA devices + cp 60 + jr nz,INIT_CHECK_NODEV + ld a,(IDE_CYHIGH) + cp 195 + jr nz,INIT_CHECK_NODEV + +TEST_FOR_LBA: + ld a,(TEMP_WORK+49*2+1) + and 2 ;LBA supported? + jr z,INIT_CHECK_NODEV + xor a + ret - or a +INIT_CHECK_NODEV: + scf ret @@ -709,135 +871,10 @@ DRV_DIRECT4: ret -;===== -;===== BEGIN of DRIVE-BASED specific routines -;===== - -if DRV_TYPE eq 0 - -;----------------------------------------------------------------------------- -; -; Read/write disk sectors -; -;Input: A = Drive number, starting at 0 -; Cy = 0 for reading sectors, 1 for writing sectors -; B = Number of sectors to read/write -; DE = First sector number to read/write -; HL = source/destination address for the transfer -;Output: Cy = 0 on success, 1 on error -; A = Error code (on error only): -; 0 Write protected -; 2 Not ready -; 4 Data (CRC) error -; 6 Seek error -; 8 Record not found -; 10 Write fault -; 12 Other errors - -DRV_DSKIO: - ld a,12 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Get disk change status -; -;Input: A = Drive number, starting at 0 -; B = C = Media descriptor -; HL = Base address for DPB -1 -;Output: Cy = 0 on success, 1 on error -; A = Error code (on error only) -; Same codes as DRV_DSKIO -; B = Disk status (on success only) -; 1 Disk not changed -; 0 Unknown -; -1 Disk changed - -DRV_DSKCHG: - ld a,12 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Get DPB for disk -; -;Input: A = Drive number, starting at 0 -; B = C = Media descriptor -; HL = Base address for DPB -1 -;Output: - - -DRV_GETDPB: - ld a,12 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Return format choice string -; -;Input: - -;Output: HL = Address of the choice string in the kernel slot - -DRV_CHOICE: - ld hl,NULL_MSG - ret - - -;----------------------------------------------------------------------------- -; -; Format a disk -; -;Input: A = Formatting choice, from 1 to 9 (see DRV_CHOICE). -; D = Drive number, starting at 0 -; HL = Address of work area in memory -; DE = Size of work area -;Output: Cy = 0 on success, 1 on error -; A = Error code (on error only): -; 0 Write protected -; 2 Not ready -; 4 Data (CRC) error -; 6 Seek error -; 8 Record not found -; 10 Write fault -; 12 Bad parameter -; 14 Insufficient memory -; 16 Other errors - -DRV_DSKFMT: - ld a,16 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Turn off the floppy disk drive motor -; -;Input: - -;Output: - - -DRV_MTOFF: - ret - -endif - - -;===== -;===== END of DRIVE-BASED specific routines -;===== - - ;===== ;===== BEGIN of DEVICE-BASED specific routines ;===== -if DRV_TYPE eq 1 - ;----------------------------------------------------------------------------- ; ; Read or write logical sectors from/to a logical unit @@ -863,6 +900,7 @@ if DRV_TYPE eq 1 ; B = Number of sectors actually read/written DEV_RW: + push af ld a,b ;Swap B and C @@ -901,14 +939,20 @@ DEV_RW_NO0SEC: ld a,(ix+3) or M_LBA or b - call WRHEAD ;IDE_HEAD must be written first, + di ; Se desactivan peticiones de interrupciones para evitar intromisiones. + ld (IDE_HEAD),a ;IDE_HEAD must be written first, + ld (IDE_HEAD),a ; Se duplica env�o de comando para refrescar sin error la FLASHJACKS. ld a,(ix) ;or the other IDE_LBAxxx and IDE_SECCNT ld (IDE_LBALOW),a ;registers will not get a correct value + ld (IDE_LBALOW),a ; Se duplica env�o de comando para refrescar sin error la FLASHJACKS. ld a,(ix+1) ;(blueMSX issue?) + ld (IDE_LBAMID),a ; Se duplica env�o de comando para refrescar sin error la FLASHJACKS. ld (IDE_LBAMID),a ld a,(ix+2) + ld (IDE_LBAHIGH),a ; Se duplica env�o de comando para refrescar sin error la FLASHJACKS. ld (IDE_LBAHIGH),a ld a,c + ld (IDE_SECCNT),a ; Se duplica env�o de comando para refrescar sin error la FLASHJACKS. ld (IDE_SECCNT),a pop af @@ -917,7 +961,9 @@ DEV_RW_NO0SEC: ;--- ;--- READ ;--- - + + call WAIT_CMD_RDY + jr c,DEV_RW_ERR ld a,20h push bc ;Save sector count call DO_IDE @@ -933,10 +979,53 @@ DEV_R_GDATA: push bc ld hl,IDE_DATA ld bc,512 - ldir - pop bc - djnz DEV_R_GDATA +BUCLE_R_GDATA: + di ; Se desactivan peticiones de interrupciones para evitar intromisiones. + ld a,(IDE_STATUS) + bit BSY,a + jr nz,BUCLE_R_GDATA ; Hace una comprobaci�n al inicio y deja paso cuando la FLASHJACKS informa que puede continuar. + ;ld a,(hl) ; Esto est� anulado ya que se trata del mismo proceso que hace ldir pero en muchos mas ciclos de reloj. Proceso muy lento. + ;ld (de),a + ;inc hl + ;inc de + ;dec bc + ;ld a,b + ;or c + ;jr nz,BUCLE_R_GDATA ; Esto est� anulado ya que se trata del mismo proceso que hace ldir pero en muchos mas ciclos de reloj. + + ;ldir ; Volcado ultrar�pido. Usar el del LDI(mas abajo) si se reportan anomal�as (Psycho world en DSK es bueno para probarlo). + ;CALL VOLCADO ; Es un ldir un 21% m�s r�pido. + + +BUCLE_R2_GDATA: + ldi ; 8x LDI + 8x nop Hacemos una espera en cada byte de volcado para dejar a la Flashjacks que se refresque a tiempo.(En un manual de asm es un modo r�pido de copia) + nop ; Esto solo es para sistemas ultra r�pidos como el TurboR. Esto hace lectura y ciclo refresco, bucle hasta fin. + ldi ; Es el m�todo m�s estable. (pero no el m�s r�pido. Mas r�pido ldir y a�n m�s call VOLCADO) + nop ; Los otros funcionan pero cuando hay algo en el otro slot, provoca fallos. (Ejemplo Music module slot 1 y FlashJacks slot 2) + ldi + nop + ldi + nop + ldi + nop + ldi + nop + ldi + nop + ldi + nop + jp pe,BUCLE_R2_GDATA + +BUCLE_R_FIN: + ld a,(IDE_STATUS) + bit BSY,a + jr nz,BUCLE_R_FIN ; Hace una comprobaci�n al final y deja paso cuando la FLASHJACKS informa que puede continuar. + pop bc + call WAIT_IDE + + dec b + jp nz,DEV_R_GDATA call IDE_OFF xor a ret @@ -946,6 +1035,8 @@ DEV_R_GDATA: ;--- DEV_DO_WR: + call WAIT_CMD_RDY + jr c,DEV_RW_ERR ld a,30h push bc ;Save sector count call DO_IDE @@ -957,7 +1048,8 @@ DEV_W_LOOP: push bc ld de,IDE_DATA ld bc,512 - ldir + ldir ; Se deja ldir por mayor estabilidad. + ;CALL VOLCADO ; Es un ldir un 21% m�s r�pido.(Por estabilidad se quita) pop bc call WAIT_IDE @@ -965,8 +1057,9 @@ DEV_W_LOOP: call DEV_RW_FAULT ret nz - - djnz DEV_W_LOOP + + dec b + jp nz,DEV_W_LOOP call IDE_OFF xor a @@ -984,26 +1077,26 @@ DEV_RW_ERR: bit NM,a ;Not ready jr nz,DEV_R_ERR1 - ld a,.NRDY + ld a,NRDY ld b,0 ret DEV_R_ERR1: bit IDNF,a ;Sector not found jr nz,DEV_R_ERR2 - ld a,.RNF + ld a,RNF ld b,0 ret DEV_R_ERR2: bit WP,a ;Write protected jr nz,DEV_R_ERR3 - ld a,.WPROT + ld a,WPROT ld b,0 ret DEV_R_ERR3: - ld a,.DISK ;Other error + ld a,DISK ;Other error ld b,0 ret @@ -1016,7 +1109,7 @@ DEV_RW_FAULT: ret z call IDE_OFF - ld a,.DISK + ld a,DISK ld b,0 or a ret @@ -1026,18 +1119,17 @@ DEV_RW_FAULT: DEV_RW_NOSEC: call IDE_OFF pop af - ld a,.RNF + ld a,RNF ld b,0 ret DEV_RW_NODEV: call IDE_OFF pop af - ld a,.IDEVL + ld a,IDEVL ld b,0 ret - ;----------------------------------------------------------------------------- ; ; Device information gathering @@ -1142,6 +1234,8 @@ DEV_STRING_LOOP: ld a,d cp 33 jr nc,DEVSTRLOOP_1 + cp 126 + jr c,DEVSTRLOOP_1 ld a," " DEVSTRLOOP_1: ld (hl),a @@ -1149,6 +1243,8 @@ DEVSTRLOOP_1: ld a,e cp 33 jr nc,DEVSTRLOOP_2 + cp 126 + jr c,DEVSTRLOOP_2 ld a," " DEVSTRLOOP_2: ld (hl),a @@ -1196,8 +1292,9 @@ DEV_INFO_ERR2: ;Corrupts AF, DE DEV_STING_PREPARE: + call WAIT_CMD_RDY ld a,c ;Issue IDENTIFY DEVICE command - call WRHEAD + ld (IDE_HEAD),a ld a,0ECh call DO_IDE ret c @@ -1265,15 +1362,6 @@ DEV_STATUS: ld a,1 ret nz - ;ld a,(TESTADD) - ;or a - ;ld a,2 - ;ld (TESTADD),a - ;ret z - - ;ld a,1 ;Device is non-removable - ;ret - ld a,e dec a ;FOR TESTING: ld a,2 ;Return "Unchanged" for device 1, "Unknown" for device 2 @@ -1328,7 +1416,12 @@ LUN_INFO: jr z,LUN_INFO2 ld a,M_DEV LUN_INFO2: - call WRHEAD + ld e,a + call WAIT_CMD_RDY + jr c,LUN_INFO_ERROR + ld a,e + + ld (IDE_HEAD),a ld a,0ECh call DO_IDE @@ -1342,7 +1435,7 @@ LUN_INFO2: ld (ix+9),h ld hl,(IDE_DATA) ;Skip word 2 ld hl,(IDE_DATA) - ld (ix+10),l ;Word 3: Heades + ld (ix+10),l ;Word 3: Heads ld hl,(IDE_DATA) ld hl,(IDE_DATA) ;Skip words 4,5 ld hl,(IDE_DATA) @@ -1438,7 +1531,7 @@ LUN_INFO_ERROR: ; FFh: 5.25" Double sided, 40 tracks per side, 8 sectors per track (320K) DEV_FORMAT: - ld a,.IFORM + ld a,IFORM ret @@ -1469,9 +1562,6 @@ DEV_CMD: ld a,2 ret -endif - - ;===== ;===== END of DEVICE-BASED specific routines ;===== @@ -1497,128 +1587,81 @@ IDE_OFF: ld (IDE_BANK),a ret +;----------------------------------------------------------------------------- +; +; Wait the BSY flag to clear and RDY flag to be set +; if we wait for more than 30s, send a soft reset to IDE BUS +; if the soft reset didn't work after 30s return with error +; +; Input: Nothing +; Output: Cy=1 if timeout after soft reset +; Preserves: DE and BC +WAIT_CMD_RDY: + push de + push bc + ld de,8142 ;Limit the wait to 30s +WAIT_RDY1: + ld b,255 +WAIT_RDY2: + ld a,(IDE_STATUS) + and M_BSY+M_DRDY + cp M_DRDY + jr z,WAIT_RDY_END ;Wait for BSY to clear and DRDY to set + djnz WAIT_RDY2 ;End of WAIT_RDY2 loop + dec de + ld a,d + or e + jr nz,WAIT_RDY1 ;End of WAIT_RDY1 loop + scf +WAIT_RDY_END: + pop bc + pop de + ret + ;----------------------------------------------------------------------------- ; ; Execute a command ; ; Input: A = Command code ; Other command registers appropriately set -; Output: Cy=1 if timeout on BSY clear or if ERR bit in status register set +; Output: Cy=1 if ERR bit in status register set -DO_IDE: - ld (IDE_CMD),a - ;ex (sp),hl ;Not necessary - WAIT_BUSY introduces delay already - ;ex (sp),hl +DO_IDE: di + ld (IDE_CMD),a ; Se duplica env�o de comando para refrescar sin error la FLASHJACKS. + ld (IDE_CMD),a WAIT_IDE: - call WAIT_BUSY - jr c,DO_IDE_TOUT - bit DRQ,a - jr z,WAIT_IDE - - rrca - ret - -DO_IDE_TOUT: - pop af - scf - ret - - -;Wait for the BUSY flag to clear. -;If we spend 30 seconds waiting, return Cy set. -;Returns A=last value of IDE_STATUS read (except if timeout occurs). - -WAIT_BUSY: - push bc - push de - ld bc,1500 - ld a,(TIMEVAR) - ld d,a - -WBUSY_LOOP: + nop ; Wait 50us + nop ; Wait 50us ld a,(IDE_STATUS) - bit BSY,a - jr z,WBUSY_END - - ld a,(TIMEVAR) - cp d - jr z,WBUSY_LOOP - ld d,a - - dec bc - ld a,b - or c - jr nz,WBUSY_LOOP - scf - -WBUSY_END: - pop de - pop bc - ret - - ;--- This is the same as DO_IDE - ; but writes E to IDE_HEAD while waiting - -DO_IDE2: - ld (IDE_CMD),a - ;ex (sp),hl ;Not necessary - WAIT_BUSY introduces delay already - ;ex (sp),hl - -WAIT_IDE2: - call WAIT_BUSY2 - jr c,DO_IDE_TOUT2 bit DRQ,a - jr z,WAIT_IDE2 + jr nz,IDE_END + bit BSY,a + jr nz,WAIT_IDE +IDE_END: rrca ret -DO_IDE_TOUT2: - pop af - scf - ret - -WAIT_BUSY2: - push bc - push de - ld bc,1500 - ld a,(TIMEVAR) - ld d,a - -WBUSY_LOOP2: - ld a,e - ld (IDE_HEAD),a - ld a,(IDE_STATUS) - bit BSY,a - jr z,WBUSY_END2 - - ld a,(TIMEVAR) - cp d - jr z,WBUSY_LOOP2 - ld d,a +;----------------------------------------------------------------------------- +; +; Read the keyboard matrix to see if ESC is pressed +; Output: Cy = 1 if pressed, 0 otherwise - dec bc - ld a,b - or c - jr nz,WBUSY_LOOP2 +CHECK_ESC: + ld b,7 + in a,(0AAh) + and 11110000b + or b + out (0AAh),a + in a,(0A9h) + bit 2,a + jr nz,CHECK_ESC_END scf - -WBUSY_END2: - pop de - pop bc - ret - - -;Write A to the HEAD register - -WRHEAD: - ;call WAIT_BUSY - ld (IDE_HEAD),a +CHECK_ESC_END: ret - ;----------------------------------------------------------------------------- ; ; Print a zero-terminated string on screen @@ -1694,23 +1737,112 @@ CHECK_DEV_LUN: or a ret +;----------------------------------------------------------------------------- +; +; Hace un volcado de 512 bytes. +VOLCADO: + REPT 512 ; esto es un 21% m�s r�pido que el ldi + ldi + ENDM + ret + +;---------------------------------------------------------------------------------- +;Turn On Turbo CPU: MSX CIEL, Panasonic 2+,Panasonic Turbo R, special TurboCPU kits +; +;Input: Nothing +;Output: Nothing + +putTURBO_CPU: + +CHGTURCIEL equ 01387h ; CIEL Expert3 bizarre turbo routine + +_TURBO3: +; ; Expert 3 CIEL +; ; Test if the CIEL change-turbo routine signature is in ROM + ld hl,CHGTURCIEL + ld de,CIELSIGN + ld c,2 + +_CIEL1: ld b,3 +_CIEL2: ld a,(hl) + ld ixh,a + ld a,(de) + cp ixh + jr nz,NOTCIEL + inc hl + inc de + djnz _CIEL2 + ld hl,CHGTURCIEL+0Ch + dec c + ld a,c + or a + jr nz,_CIEL2 + call CHGTURCIEL + db 1 ; Padding to make the CIELSIGN inert +CIELSIGN: DEFB 0A7h,0FAh,093h,013h,0DBh,0B6h + +NOTCIEL: + +;------------------------------------------------------------------------------ + ;Check for Panasonic 2+ + LD A,8 + OUT (040H),A ;out the manufacturer code 8 (Panasonic) to I/O port 40h + IN A,(040H) ;read the value you have just written + CPL ;complement all bits of the value + CP 8 ;if it does not match the value you originally wrote, + JR NZ,Not_WX ;it is not a WX/WSX/FX. + XOR A ;write 0 to I/O port 41h + OUT (041H),A ;and the mode changes to high-speed clock + + + jr end_turbo + +Not_WX: ld a,(0180h) ;Turbo R or Turbo CPU kits with JUMP in 0180h + cp 0c3h + ;no_turbo + jr nz,end_turbo + ld a,081h ;ROM Mode... for DRAM Mode-> 82h + call 0180h + +end_turbo: + + ret +;--------------------------------------------------------------- + ;======================= ; Strings ;======================= INFO_S: - db "Sunrise IDE device-based driver",13,10 - db "(c) Konamiman 2009",13,10,13,10,0 + db "FLASHJACKS IDE driver v" + db VER_MAIN+"0",".",VER_SEC+"0",".",VER_REV+"0",13,10 + db "(c) Konamiman 2009",13,10 + db "(c) Aquijacks 2018",13,10,13,10,0 + +SEARCH_S: + db "Buscando: ",0 NODEVS_S: - db "No IDE devices found.",13,10,0 + db "No encontrada",13,10,0 MASTER_S: - db "Master device: ",0 -SLAVE_S: - db "Slave device: ",0 + db "Unidad: ",0 CRLF_S: db 13,10,0 +MODELO: + db "Modelo: ",0 +M_MSX1: + db "MSX1",13,10,13,10,0 +M_MSX2: + db "MSX2",13,10,13,10,0 +M_MSX2M: + db "MSX2+",13,10,13,10,0 +M_MSXR: + db "MSX TurboR",13,10,13,10,0 +M_OCM: + db "OCM",13,10,13,10,0 +M_NDTC: + db "No detectado",13,10,13,10,0 ;----------------------------------------------------------------------------- @@ -1719,6 +1851,8 @@ CRLF_S: DRV_END: - ;ds 3FD0h-(DRV_END-DRV_START) + ds 3ED0h-(DRV_END - DRV_START) end + + diff --git a/source/kernel/drivers/MegaFlashRomSD/driver-1slot.dat b/source/kernel/drivers/MegaFlashRomSD/driver-1slot.dat new file mode 100644 index 00000000..cf812a68 Binary files /dev/null and b/source/kernel/drivers/MegaFlashRomSD/driver-1slot.dat differ diff --git a/source/kernel/drivers/MegaFlashRomSD/driver-2slots.dat b/source/kernel/drivers/MegaFlashRomSD/driver-2slots.dat new file mode 100644 index 00000000..68e00b59 Binary files /dev/null and b/source/kernel/drivers/MegaFlashRomSD/driver-2slots.dat differ diff --git a/source/kernel/drivers/SunriseIDE/DRIVER.01.MAC b/source/kernel/drivers/SunriseIDE/DRIVER.01.MAC deleted file mode 100644 index 8a1d783e..00000000 --- a/source/kernel/drivers/SunriseIDE/DRIVER.01.MAC +++ /dev/null @@ -1,1623 +0,0 @@ - ; Device-based driver for the sunrise IDE interface for MSX-DOS 2.50 - ; - ; Version 0.1 - ; By Konamiman - - ;org 4100h - -DRV_START: - -TESTADD equ 0F3F5h - -;----------------------------------------------------------------------------- -; -; Driver configuration constants -; - -;Driver type: -; 0 for drive-based -; 1 for device-based - -DRV_TYPE equ 1 - -;Hot-plug devices support (device-based drivers only): -; 0 for no hot-plug support -; 1 for hot-plug support - -DRV_HOTPLUG equ 0 - -DEBUG equ 0 ;Set to 1 for debugging, 0 to normal operation - -;Driver version - -VER_MAIN equ 0 -VER_SEC equ 1 -VER_REV equ 0 - - if DEBUG eq 1 - include B0LABELS.INC - endif - -;This is a very barebones driver. It has important limitations: -;- CHS mode not supported, disks must support LBA mode. -;- 48 bit addresses are not supported -; (do the Sunrise IDE hardware support them anyway?) -;- ATAPI devices not supported, only ATA disks. - - -;----------------------------------------------------------------------------- -; -; IDE registers and bit definitions - -IDE_BANK equ 4104h - ;bit 0: enable (1) or disable (0) IDE registers - ;bits 5-7: select 16K ROM bank -IDE_DATA equ 7C00h ;Data registers, this is a 512 byte area -IDE_ERROR equ 7E01h ;Error register -IDE_FEAT equ 7E01h ;Feature register -IDE_SECCNT equ 7E02h ;Sector count -IDE_SECNUM equ 7E03h ;Sector number (CHS mode) -IDE_LBALOW equ 7E03h ;Logical sector low (LBA mode) -IDE_CYLOW equ 7E04h ;Cylinder low (CHS mode) -IDE_LBAMID equ 7E04h ;Logical sector mid (LBA mode) -IDE_CYHIGH equ 7E05h ;Cylinder high (CHS mode) -IDE_LBAHIGH equ 7E05h ;Logical sector high (LBA mode) -IDE_HEAD equ 7E06h - ;bits 0-3: Head (CHS mode), logical sector higher (LBA mode) -IDE_STATUS equ 7E07h ;Status register -IDE_CMD equ 7E07h ;Command register -IDE_DEVCTRL equ 7E0Eh ;Device control register - -; Bits in the error register - -UNC equ 6 ;Uncorrectable Data Error -WP equ 6 ;Write protected -MC equ 5 ;Media Changed -IDNF equ 4 ;ID Not Found -MCR equ 3 ;Media Change Requested -ABRT equ 2 ;Aborted Command -NM equ 1 ;No media - -M_ABRT equ (1 SHL ABRT) - -; Bits in the head register - -DEV equ 4 ;Device select: 0=master, 1=slave -LBA equ 6 ;0=use CHS mode, 1=use LBA mode - -M_DEV equ (1 SHL DEV) -M_LBA equ (1 SHL LBA) - -; Bits in the status register - -BSY equ 7 ;Busy -DRDY equ 6 ;Device ready -DF equ 5 ;Device fault -DRQ equ 3 ;Data request -ERR equ 0 ;Error - -M_BSY equ (1 SHL BSY) -M_DRDY equ (1 SHL DRDY) -M_DF equ (1 SHL DF) -M_DRQ equ (1 SHL DRQ) -M_ERR equ (1 SHL ERR) - -; Bits in the device control register register - -SRST equ 2 ;Software reset - -M_SRST equ (1 SHL SRST) - - -;----------------------------------------------------------------------------- -; -; Standard BIOS and work area entries - -CHPUT equ 00A2h ;Character output -CHGET equ 009Fh - - -;----------------------------------------------------------------------------- -; -; Work area definition -; -;+0: Device and logical units types for master device -; bits 0,1: Device type -; 00: No device connected -; 01: ATA hard disk, CHS only -; 10: ATA hard disk, LBA supported -; 11: ATAPI device -; bits 2,3: Device type for LUN 1 on master device -; 00: Block device -; 01: Other, non removable -; 10: CD-ROM -; 11: Other, removable -; bits 4,5: Device type for LUN 2 on master device -; bits 6,7: Device type for LUN 3 on master device -; -;+1: Logical unit types for master device -; bits 0,1: Device type for LUN 4 on master device -; bits 2,3: Device type for LUN 5 on master device -; bits 4,5: Device type for LUN 6 on master device -; bits 6,7: Device type for LUN 7 on master device -; -;+2,3: Reserved for CHS data for the master device (to be implemented) -; -;+4..+7: Same as +0..+3, for the slave device -; -; Note: Actually, due to driver limitations, currently only the -; "device type" bits are used, and with possible values 00 and 10 only. -; LUN type bits are always 00. - - -;----------------------------------------------------------------------------- -; -; Error codes for DEV_RW and DEV_FORMAT -; - -if DRV_TYPE eq 1 - -.NCOMP equ 0FFh -.WRERR equ 0FEh -.DISK equ 0FDh -.NRDY equ 0FCh -.DATA equ 0FAh -.RNF equ 0F9h -.WPROT equ 0F8h -.UFORM equ 0F7h -.SEEK equ 0F3h -.IFORM equ 0F0h -.IDEVL equ 0B5h -.IPARM equ 08Bh - -endif - -;----------------------------------------------------------------------------- -; -; Routines available on kernel page 0 -; - -;* Get in A the current slot for page 1. Corrupts F. -; Must be called by using CALBNK to bank 0: -; xor a -; ld ix,GSLOT1 -; call CALBNK - -GSLOT1 equ 402Dh - - -;* This routine reads a byte from another bank. -; Must be called by using CALBNK to the desired bank, -; passing the address to be read in HL: -; ld a,bank -; ld hl,address -; ld ix,RDBANK -; call CALBNK - -RDBANK equ 403Ch - - -;* This routine temporarily switches kernel bank 0/3, -; then jumps to CALBAS in MSX BIOS. -; This is necessary so that kernel bank is correct in case of BASIC error. - -CALBAS equ 403Fh - - -;* Call a routine in another bank. -; Must be used if the driver spawns across more than one bank. -; Input: A = bank -; IX = routine address -; AF' = AF for the routine -; BC, DE, HL, IY = input for the routine - -CALBNK equ 4042h - - -;* Get in IX the address of the SLTWRK entry for the slot passed in A, -; which will in turn contain a pointer to the allocated page 3 -; work area for that slot (0 if no work area was allocated). -; If A=0, then it uses the slot currently switched in page 1. -; Returns A=current slot for page 1, if A=0 was passed. -; Corrupts F. -; Must be called by using CALBNK to bank 0: -; ld a,slot -; ex af,af' -; xor a -; ld ix,GWORK -; call CALBNK - -GWORK equ 4045h - - -;* Call a routine in the driver bank. -; Input: (BK4_ADD) = routine address -; AF, BC, DE, HL, IY = input for the routine -; -; Calls a routine in the driver bank. This routine is the same as CALBNK, -; except that the routine address is passed in address BK4_ADD (#F2ED) -; instead of IX, and the bank number is always 5. This is useful when used -; in combination with CALSLT to call a driver routine from outside -; the driver itself. -; -; Note that register IX can't be used as input parameter, it is -; corrupted before reaching the invoked code. - -CALDRV equ 4048h - - -;----------------------------------------------------------------------------- -; -; Built-in format choice strings -; - -NULL_MSG equ 741Fh ;Null string (disk can't be formatted) -SING_DBL equ 7420h ;"1-Single side / 2-Double side" - - -;----------------------------------------------------------------------------- -; -; Driver signature -; - db "NEXTOR_DRIVER",0 - -; Driver flags: -; bit 0: 0 for drive-based, 1 for device-based -; bit 1: 1 for hot-plug devices supported (device-based drivers only) - -if DRV_TYPE eq 0 - db 0 -endif - -if DRV_TYPE eq 1 - db 1+(2*DRV_HOTPLUG) -endif - -;Reserved byte - db 0 - -;Driver name - -DRV_NAME: - db "Sunrise IDE" - ds 32-($-DRV_NAME)," " - -;Jump table - - jp DRV_TIMI - jp DRV_VERSION - jp DRV_INIT - jp DRV_BASSTAT - jp DRV_BASDEV - jp DRV_EXTBIO - jp DRV_DIRECT0 - jp DRV_DIRECT1 - jp DRV_DIRECT2 - jp DRV_DIRECT3 - jp DRV_DIRECT4 - - ds 15 - -if DRV_TYPE eq 0 - jp DRV_DSKIO - jp DRV_DSKCHG - jp DRV_GETDPB - jp DRV_CHOICE - jp DRV_DSKFMT - jp DRV_MTOFF -endif - -if DRV_TYPE eq 1 - jp DEV_RW - jp DEV_INFO - jp DEV_STATUS - jp LUN_INFO - jp DEV_FORMAT - jp DEV_CMD -endif - - -;----------------------------------------------------------------------------- -; -; Timer interrupt routine, it will be called on each timer interrupt -; (at 50 or 60Hz), but only if DRV_INIT returns Cy=1 on its first execution. - -DRV_TIMI: - ret - - -;----------------------------------------------------------------------------- -; -; Driver initialization, it is called twice: -; -; 1) First execution, for information gathering. -; Input: -; A = 0 -; B = number of available drives (drive-based drivers only) -; HL = maximum size of allocatable work area in page 3 -; Output: -; A = number of required drives (for drive-based driver only) -; HL = size of required work area in page 3 -; Cy = 1 if DRV_TIMI must be hooked to the timer interrupt, 0 otherwise -; -; 2) Second execution, for work area and hardware initialization. -; Input: -; A = 1 -; B = number of allocated drives for this controller -; (255 if device-based driver, unless 4 i pressed at boot) -; -; The work area address can be obtained by using GWORK. -; -; If first execution requests more work area than available, -; second execution will not be done and DRV_TIMI will not be hooked -; to the timer interrupt. -; -; If first execution requests more drives than available, -; as many drives as possible will be allocated, and the initialization -; procedure will continue the normal way -; (for drive-based drivers only. Device-based drivers always -; get two allocated drives.) - -TEMP_WORK equ 0C000h - -DRV_INIT: - ;--- If first execution, just inform that no work area is needed - ; (the 8 bytes in SLTWRK are enough) - - or a - ld hl,0 - ld a,2 - ret z ;Note that Cy is 0 (no interrupt hooking needed) - - ;xor a - ;ld (TESTADD),a - - ld de,INFO_S - call PRINT - -if DEBUG eq 1 - call DO - - ld hl,8101h - ld (DRVTBL##),hl - ld hl,8301h - ld (DRVTBL##+2),hl - ld hl,8501h - ld (DRVTBL##+4),hl - ld hl,0 - ld (DRVTBL##+6),hl - - ld a,87h - ld (KER250##),a - ld a,85h - ld (KER250##+1),a - ld a,89h - ld (KER250##+2),a - xor a - ld (KER250##+3),a - - ld a,1 - ld ix,GDRIVER## - ex af,af' - ld a,4 - call CALBNK - jp DRV_INIT_END - - -;Input: Cy=0 to read, 1 to write -; A = Device number, 1 to 7 -; B = Logical unit number, 1 to 7 -; C = Number of sectors to read or write -; HL = Source or destination memory address for the transfer -; DE = Address where the 4 byte sector number is stored. - - ld hl,0C000h - ld ($SECBUF##),hl - - ;ld hl,GPART## - ;ld (BK4_ADD##),hl - - ld b,1 - ld c,0FFh - ld d,1 - ld e,1 - ld h,4 - ld l,0 - - ld ix,GPART## - ex af,af' - ld a,4 - call CALBNK - jp DRV_INIT_END - - or a - ld a,1 - ld b,1 - ld c,3 - ld hl,0 - ld (0C000h),hl - ld (0C002h),hl - ld hl,0C000h - ld de,0C000h - call DEV_RW - - ld a,1 - ld (0C000h),a - ld a,2 - ld (0C200h),a - ld a,34h - ld (0C000h+512*3-1),a - - scf - ld a,1 - ld b,1 - ld c,3 - ld hl,0 - ld (0C000h),hl - ld (0C002h),hl - ld hl,0C000h - ld de,0C000h - call DEV_RW - - jp DRV_INIT_END - -luninfo: - - ld a,1 - ld b,1 - ld hl,0C000h - call LUN_INFO - ld a,2 - ld b,1 - ld hl,0C000h - call LUN_INFO - ld a,3 - ld b,1 - ld hl,0C000h - call LUN_INFO - ld a,2 - ld b,2 - ld hl,0C000h - call LUN_INFO - - jp DRV_INIT_END - - ld a,1 - ld b,0 - ld hl,0C000h - call DEV_INFO - ld a,1 - ld b,1 - ld hl,0C000h - call DEV_INFO - ld a,1 - ld b,2 - ld hl,0C000h - call DEV_INFO - ld a,1 - ld b,3 - ld hl,0C000h - call DEV_INFO - jp DRV_INIT_END -DO: -endif - - ld a,1 - call MY_GWORK - call IDE_ON - ld (ix),0 - ld (ix+4),0 ;Assume no devices initially - - ;--- Perform a software reset on both devices - - ld a,M_SRST - ld (IDE_DEVCTRL),a - nop ;Wait 5 us - xor a - ld (IDE_DEVCTRL),a - -WAIT_RESET: - ld a,(IDE_STATUS) - and M_BSY+M_DRDY - cp M_DRDY - jr nz,WAIT_RESET ;Wait for BSY to clear and DRDY to set - - ;--- Determine whether there is any device connected - ; by looking at the diagnostic code in the error register - - ld a,(IDE_ERROR) - ld b,a - and 1 - cp 1 - jr nz,INIT_NO_DEV ;Master failed: give up - - ld (ix+4),b ;We'll check later if there is a slave - - ;--- Get info and show the name for the master - - xor a - ld (IDE_HEAD),a ;Select device 1 - ld a,0ECh - call DO_IDE - jr c,OK_MASTER - - call INIT_CHECK_DEV - jr c,OK_MASTER - - ld de,MASTER_S - call PRINT - call INIT_PRINT_NAME - - ld (ix),2 ;ATA device with LBA -OK_MASTER: - - ;--- If the presence of slave musy be checked, - ; issue a test command and check for error - - ld a,(ix+4) ;1 if slave OK or not present, 81h if failed - ld (ix+4),0 - cp 1 - jr nz,OK_SLAVE - - ld a,M_DEV - ld (IDE_HEAD),a ;Select device 1 - ld a,0ECh - call DO_IDE - jr c,OK_SLAVE ;If error, no device, or ATAPI device - - ;--- Get info and show the name for the slave - - call INIT_CHECK_DEV - jr c,OK_SLAVE - - ld de,SLAVE_S - call PRINT - call INIT_PRINT_NAME - - ld (ix+4),2 ;ATA device with LBA -OK_SLAVE: - - ;--- End of the initialization procedure - - jr DRV_INIT_END - -INIT_NO_DEV: - ld de,NODEVS_S - call PRINT - -DRV_INIT_END: - call IDE_OFF -if DEBUG eq 1 - ;call CHGET ;For debugging -endif - - ret - -;--- Subruotines for the INIT procedure - -;Check that a device is present and usable. -;Input: IDENTIFY DEVICE issued successfully. -;Output: Cy=0 for device ok, 1 for no device or not usable. -; If device ok, 50 first bytes of IDENTIFY device copied to TEMP_WORK. - -INIT_CHECK_DEV: - ld hl,IDE_DATA - ld de,TEMP_WORK - ld bc,50*2 ;Get the first 50 data words - ldir - - ;ld a,(TEMP_WORK+1) - ;and 80h ;ATAPI device? - ;scf - ;ret nz - - ld a,(TEMP_WORK+49*2+1) - and 2 ;LBA supported? - scf - ret z - - or a - ret - - -;Print a device name. -;Input: 50 first bytes of IDENTIFY device on TEMP_WORK. - -INIT_PRINT_NAME: - ld hl,TEMP_WORK+27*2 - ld b,20 -DEVNAME_LOOP: - ld c,(hl) - inc hl - ld a,(hl) - inc hl - call CHPUT - ld a,c - call CHPUT - djnz DEVNAME_LOOP - - ld de,CRLF_S - call PRINT - ret - - -;----------------------------------------------------------------------------- -; -; Obtain driver version -; -; Input: - -; Output: A = Main version number -; B = Secondary version number -; C = Revision number - -DRV_VERSION: - ld a,VER_MAIN - ld b,VER_SEC - ld c,VER_REV - ret - - -;----------------------------------------------------------------------------- -; -; BASIC expanded statement ("CALL") handler. -; Works the expected way, except that CALBAS in kernel page 0 -; must be called instead of CALBAS in MSX BIOS. - -DRV_BASSTAT: - scf - ret - - -;----------------------------------------------------------------------------- -; -; BASIC expanded device handler. -; Works the expected way, except that CALBAS in kernel page 0 -; must be called instead of CALBAS in MSX BIOS. - -DRV_BASDEV: - scf - ret - - -;----------------------------------------------------------------------------- -; -; Extended BIOS hook. -; Works the expected way, except that it must return -; D'=1 if the old hook must be called, D'=0 otherwise. -; It is entered with D'=1. - -DRV_EXTBIO: - ret - - -;----------------------------------------------------------------------------- -; -; Direct calls entry points. -; Calls to addresses 7450h, 7453h, 7456h, 7459h and 745Ch -; in kernel banks 0 and 3 will be redirected -; to DIRECT0/1/2/3/4 respectively. -; Receives all register data from the caller except IX and AF'. - -DRV_DIRECT0: -DRV_DIRECT1: -DRV_DIRECT2: -DRV_DIRECT3: -DRV_DIRECT4: - ret - - -;===== -;===== BEGIN of DRIVE-BASED specific routines -;===== - -if DRV_TYPE eq 0 - -;----------------------------------------------------------------------------- -; -; Read/write disk sectors -; -;Input: A = Drive number, starting at 0 -; Cy = 0 for reading sectors, 1 for writing sectors -; B = Number of sectors to read/write -; DE = First sector number to read/write -; HL = source/destination address for the transfer -;Output: Cy = 0 on success, 1 on error -; A = Error code (on error only): -; 0 Write protected -; 2 Not ready -; 4 Data (CRC) error -; 6 Seek error -; 8 Record not found -; 10 Write fault -; 12 Other errors - -DRV_DSKIO: - ld a,12 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Get disk change status -; -;Input: A = Drive number, starting at 0 -; B = C = Media descriptor -; HL = Base address for DPB -1 -;Output: Cy = 0 on success, 1 on error -; A = Error code (on error only) -; Same codes as DRV_DSKIO -; B = Disk status (on success only) -; 1 Disk not changed -; 0 Unknown -; -1 Disk changed - -DRV_DSKCHG: - ld a,12 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Get DPB for disk -; -;Input: A = Drive number, starting at 0 -; B = C = Media descriptor -; HL = Base address for DPB -1 -;Output: - - -DRV_GETDPB: - ld a,12 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Return format choice string -; -;Input: - -;Output: HL = Address of the choice string in the kernel slot - -DRV_CHOICE: - ld hl,NULL_MSG - ret - - -;----------------------------------------------------------------------------- -; -; Format a disk -; -;Input: A = Formatting choice, from 1 to 9 (see DRV_CHOICE). -; D = Drive number, starting at 0 -; HL = Address of work area in memory -; DE = Size of work area -;Output: Cy = 0 on success, 1 on error -; A = Error code (on error only): -; 0 Write protected -; 2 Not ready -; 4 Data (CRC) error -; 6 Seek error -; 8 Record not found -; 10 Write fault -; 12 Bad parameter -; 14 Insufficient memory -; 16 Other errors - -DRV_DSKFMT: - ld a,16 - scf - ret - - -;----------------------------------------------------------------------------- -; -; Turn off the floppy disk drive motor -; -;Input: - -;Output: - - -DRV_MTOFF: - ret - -endif - - -;===== -;===== END of DRIVE-BASED specific routines -;===== - - -;===== -;===== BEGIN of DEVICE-BASED specific routines -;===== - -if DRV_TYPE eq 1 - -;----------------------------------------------------------------------------- -; -; Read or write logical sectors from/to a logical unit -; -;Input: Cy=0 to read, 1 to write -; A = Device number, 1 to 7 -; B = Number of sectors to read or write -; C = Logical unit number, 1 to 7 -; HL = Source or destination memory address for the transfer -; DE = Address where the 4 byte sector number is stored -;Output: A = Error code (the same codes of MSX-DOS are used): -; 0: Ok -; .IDEVL: Invalid device or LUN -; .NRDY: Not ready -; .DISK: General unknown disk error -; .DATA: CRC error when reading -; .RNF: Sector not found -; .UFORM: Unformatted disk -; .WPROT: Write protected media, or read-only logical unit -; .WRERR: Write error -; .NCOMP: Incompatible disk -; .SEEK: Seek error -; B = Number of sectors actually read/written - -DEV_RW: - push af - - ld a,b ;Swap B and C - ld b,c - ld c,a - pop af - push af - push bc - call CHECK_DEV_LUN - pop bc - jp c,DEV_RW_NODEV - - dec a - jr z,DEV_RW2 - ld a,M_DEV -DEV_RW2: - ld b,a - - ld a,c - or a - jr nz,DEV_RW_NO0SEC - pop af - xor a - ld b,0 - ret -DEV_RW_NO0SEC: - - push de - pop ix - ld a,(ix+3) - and 11110000b - jp nz,DEV_RW_NOSEC ;Only 28 bit sector numbers supported - - call IDE_ON - - ld a,(ix+3) - or M_LBA - or b - ld (IDE_HEAD),a ;IDE_HEAD must be written first, - ld a,(ix) ;or the other IDE_LBAxxx and IDE_SECCNT - ld (IDE_LBALOW),a ;registers will not get a correct value - ld a,(ix+1) ;(blueMSX issue?) - ld (IDE_LBAMID),a - ld a,(ix+2) - ld (IDE_LBAHIGH),a - ld a,c - ld (IDE_SECCNT),a - - pop af - jr c,DEV_DO_WR - - ;--- - ;--- READ - ;--- - - ld a,20h - push bc ;Save sector count - call DO_IDE - pop bc - jr c,DEV_RW_ERR - - call DEV_RW_FAULT - ret nz - - ld b,c ;Retrieve sector count - ex de,hl -DEV_R_GDATA: - push bc - ld hl,IDE_DATA - ld bc,512 - ldir - pop bc - djnz DEV_R_GDATA - - call IDE_OFF - xor a - ret - - ;--- - ;--- WRITE - ;--- - -DEV_DO_WR: - ld a,30h - push bc ;Save sector count - call DO_IDE - pop bc - jr c,DEV_RW_ERR - - ld b,c ;Retrieve sector count -DEV_W_LOOP: - push bc - ld de,IDE_DATA - ld bc,512 - ldir - pop bc - - call WAIT_IDE - jr c,DEV_RW_ERR - - call DEV_RW_FAULT - ret nz - - djnz DEV_W_LOOP - - call IDE_OFF - xor a - ret - - ;--- - ;--- ERROR ON READ/WRITE - ;--- - -DEV_RW_ERR: - ld a,(IDE_ERROR) - ld b,a - call IDE_OFF - ld a,b - - bit NM,a ;Not ready - jr nz,DEV_R_ERR1 - ld a,.NRDY - ld b,0 - ret -DEV_R_ERR1: - - bit IDNF,a ;Sector not found - jr nz,DEV_R_ERR2 - ld a,.RNF - ld b,0 - ret -DEV_R_ERR2: - - bit WP,a ;Write protected - jr nz,DEV_R_ERR3 - ld a,.WPROT - ld b,0 - ret -DEV_R_ERR3: - - ld a,.DISK ;Other error - ld b,0 - ret - - ;--- Check for device fault - ; Output: NZ and A=.DISK on fault - -DEV_RW_FAULT: - ld a,(IDE_STATUS) - and M_DF ;Device fault - ret z - - call IDE_OFF - ld a,.DISK - ld b,0 - or a - ret - - ;--- Termination points - -DEV_RW_NOSEC: - call IDE_OFF - pop af - ld a,.RNF - ld b,0 - ret - -DEV_RW_NODEV: - call IDE_OFF - pop af - ld a,.IDEVL - ld b,0 - ret - - -;----------------------------------------------------------------------------- -; -; Device information gathering -; -;Input: A = Device index, 1 to 7 -; B = Information to return: -; 0: Basic information -; 1: Manufacturer name string -; 2: Device name string -; 3: Serial number string -; HL = Pointer to a buffer in RAM -;Output: A = Error code: -; 0: Ok -; 1: Device not available or invalid device index -; 2: Information not available, or invalid information index -; When basic information is requested, -; buffer filled with the following information: -; -;+0 (1): Numer of logical units, from 1 to 8. 1 if the device has no logical -; drives (which is functionally equivalent to having only one). -;+1 (1): Flags, always zero -; -; The strings must be printable ASCII string (ASCII codes 32 to 126), -; left justified and padded with spaces. All the strings are optional, -; if not available, an error must be returned. -; If a string is provided by the device in binary format, it must be reported -; as an hexadecimal, upper-cased string, preceded by the prefix "0x". -; The maximum length for a string is 64 characters; -; if the string is actually longer, the leftmost 64 characters -; should be provided. -; -; In the case of the serial number string, the same rules for the strings -; apply, except that it must be provided right-justified, -; and if it is too long, the rightmost characters must be -; provided, not the leftmost. - -DEV_INFO: - or a ;Check device index - jr z,DEV_INFO_ERR1 - cp 3 - jr nc,DEV_INFO_ERR1 - - call MY_GWORK - - ld c,a - ld a,b - or a - jr nz,DEV_INFO_STRING - - ;--- Obtain basic information - - ld a,(ix) - or a ;Device available? - jr z,DEV_INFO_ERR1 - - ld (hl),1 ;One single LUN - inc hl - ld (hl),0 ;Always zero - xor a - ret - - ;--- Obtain string information - -DEV_INFO_STRING: - push hl - push bc - push hl - pop de - inc de - ld (hl)," " - ld bc,64-1 - ldir - pop bc - pop hl - - call IDE_ON - - ld a,c - dec a - jr z,DEV_INFO_STRING2 - ld a,M_DEV - -DEV_INFO_STRING2: - ld c,a ;C=Device flag for the HEAD register - ld a,b - - dec a - jr z,DEV_INFO_ERR2 ;Manufacturer name - - ;--- Device name - - dec a - jr nz,DEV_STRING_NO1 - - ld b,27 - call DEV_STING_PREPARE - jr c,DEV_INFO_ERR1 - - ld b,20 -DEV_STRING_LOOP: - ld de,(IDE_DATA) - ld a,d - cp 33 - jr nc,DEVSTRLOOP_1 - ld a," " -DEVSTRLOOP_1: - ld (hl),a - inc hl - ld a,e - cp 33 - jr nc,DEVSTRLOOP_2 - ld a," " -DEVSTRLOOP_2: - ld (hl),a - inc hl - djnz DEV_STRING_LOOP - - call IDE_OFF - xor a - ret - -DEV_STRING_NO1: - - ;--- Serial number - - dec a - jr nz,DEV_INFO_ERR2 ;Unknown string - - ld b,10 - call DEV_STING_PREPARE - jr c,DEV_INFO_ERR1 - - ld bc,44 - add hl,bc ;Since the string is 20 chars long - ld b,10 - jr DEV_STRING_LOOP - - ;--- Termination with error - -DEV_INFO_ERR1: - call IDE_OFF - ld a,1 - ret - -DEV_INFO_ERR2: - call IDE_OFF - ld a,2 - ret - - - -;Common processing for obtaining a device information string -;Input: B = Offset of the string in the device information (words) -; HL = Destination address for the string -; C = Device flag for the HEAD register -;Corrupts AF, DE - -DEV_STING_PREPARE: - ld a,c ;Issue IDENTIFY DEVICE command - ld (IDE_HEAD),a - ld a,0ECh - call DO_IDE - ret c - - push hl ;Fill destination with spaces - push bc - push hl - pop de - inc de - ld (hl)," " - ld bc,64-1 - ldir - pop bc - pop hl - -DEV_STRING_SKIP: - ld de,(IDE_DATA) ;Skip device data until the desired string - djnz DEV_STRING_SKIP - - ret - - -;----------------------------------------------------------------------------- -; -; Obtain device status -; -;Input: A = Device index, 1 to 7 -; B = Logical unit number, 1 to 7. -; 0 to return the status of the device itself. -;Output: A = Status for the specified logical unit, -; or for the whole device if 0 was specified: -; 0: The device or logical unit is not available, or the -; device or logical unit number supplied is invalid. -; 1: The device or logical unit is available and has not -; changed since the last status request. -; 2: The device or logical unit is available and has changed -; since the last status request -; (for devices, the device has been unplugged and a -; different device has been plugged which has been -; assigned the same device index; for logical units, -; the media has been changed). -; 3: The device or logical unit is available, but it is not -; possible to determine whether it has been changed -; or not since the last status request. -; -; Devices not supporting hot-plugging must always return status value 1. -; Non removable logical units may return values 0 and 1. - -DEV_STATUS: - set 0,b ;So that CHECK_DEV_LUN admits B=0 - - call CHECK_DEV_LUN - ld e,a - ld a,0 - ret c - - ld a,1 ;Never changed - ret - - ;ld a,1 - ;ret - - ld a,e - cp 2 - ld a,1 - ret nz - - ;ld a,(TESTADD) - ;or a - ;ld a,2 - ;ld (TESTADD),a - ;ret z - - ;ld a,1 ;Device is non-removable - ;ret - - ld a,e - dec a ;FOR TESTING: - ld a,2 ;Return "Unchanged" for device 1, "Unknown" for device 2 - ret z - ld a,3 - ret - - -;----------------------------------------------------------------------------- -; -; Obtain logical unit information -; -;Input: A = Device index, 1 to 7. -; B = Logical unit number, 1 to 7. -; HL = Pointer to buffer in RAM. -;Output: A = 0: Ok, buffer filled with information. -; 1: Error, device or logical unit not available, -; or device index or logical unit number invalid. -; On success, buffer filled with the following information: -; -;+0 (1): Medium type: -; 0: Block device -; 1: CD or DVD reader or recorder -; 2-254: Unused. Additional codes may be defined in the future. -; 255: Other -;+1 (2): Sector size, 0 if this information does not apply or is -; not available. -;+3 (4): Total number of available sectors. -; 0 if this information does not apply or is not available. -;+7 (1): Flags: -; bit 0: 1 if the medium is removable. -; bit 1: 1 if the medium is read only. A medium that can dinamically -; be write protected or write enabled is not considered -; to be read-only. -; bit 2: 1 if the LUN is a floppy disk drive. -;+8 (2): Number of cylinders (0, if not a hard disk) -;+10 (1): Number of heads (0, if not a hard disk) -;+11 (1): Number of sectors per track (0, if not a hard disk) - -LUN_INFO: - call CHECK_DEV_LUN - jp c,LUN_INFO_ERROR - - ld b,a - call IDE_ON - ld a,b - - push hl - pop ix - - dec a - jr z,LUN_INFO2 - ld a,M_DEV -LUN_INFO2: - ld (IDE_HEAD),a - - ld a,0ECh - call DO_IDE - jr c,LUN_INFO_ERROR - - ;Set cylinders, heads, and sectors/track - - ld hl,(IDE_DATA) ;Skip word 0 - ld hl,(IDE_DATA) - ld (ix+8),l ;Word 1: Cylinders - ld (ix+9),h - ld hl,(IDE_DATA) ;Skip word 2 - ld hl,(IDE_DATA) - ld (ix+10),l ;Word 3: Heades - ld hl,(IDE_DATA) - ld hl,(IDE_DATA) ;Skip words 4,5 - ld hl,(IDE_DATA) - ld (ix+11),l ;Word 6: Sectors/track - - ;Set maximum sector number - - ld b,60-7 ;Skip until word 60 -LUN_INFO_SKIP1: - ld de,(IDE_DATA) - djnz LUN_INFO_SKIP1 - - ld de,(IDE_DATA) ;DE = Low word - ld hl,(IDE_DATA) ;HL = High word - - ld (ix+3),e - ld (ix+4),d - ld (ix+5),l - ld (ix+6),h - - ;Set sector size - - ld b,117-62 ;Skip until word 117 -LUN_INFO_SKIP2: - ld de,(IDE_DATA) - djnz LUN_INFO_SKIP2 - - ld de,(IDE_DATA) ;DE = Low word - ld hl,(IDE_DATA) ;HL = High word - - ld a,h ;If high word not zero, set zero (info not available) - or l - ld hl,0 - jr nz,LUN_INFO_SSIZE - - ld a,d - or e - jr nz,LUN_INFO_SSIZE - ld de,512 ;If low word is zero, assume 512 bytes -LUN_INFO_SSIZE: - ld (ix+1),e - ld (ix+2),d - - ;Set other parameters - - ld (ix),0 ;Block device - ld (ix+7),0 ;Non removable device nor LUN - - call IDE_OFF - xor a - ret - -LUN_INFO_ERROR: - call IDE_OFF - ld a,1 - ret - - -;----------------------------------------------------------------------------- -; -; Physical format a device -; -;Input: A = Device index, 1 to 7 -; B = Logical unit number, 1 to 7 -; C = Format choice, 0 to return choice string -;Output: -; When C=0 at input: -; A = 0: Ok, address of choice string returned -; .IFORM: Invalid device or logical unit number, -; or device not formattable -; HL = Address of format choice string (in bank 0 or 3), -; only if A=0 returned. -; Zero, if only one choice is available. -; -; When C<>0 at input: -; A = 0: Ok, device formatted -; Other: error code, same as DEV_RW plus: -; .IPARM: Invalid format choice -; .IFORM: Invalid device or logical unit number, -; or device not formattable -; B = Media ID if the device is a floppy disk, zero otherwise -; (only if A=0 is returned) -; -; Media IDs are: -; F0h: 3.5" Double Sided, 80 tracks per side, 18 sectors per track (1.44MB) -; F8h: 3.5" Single sided, 80 tracks per side, 9 sectors per track (360K) -; F9h: 3.5" Double sided, 80 tracks per side, 9 sectors per track (720K) -; FAh: 5.25" Single sided, 80 tracks per side, 8 sectors per track (320K) -; FBh: 3.5" Double sided, 80 tracks per side, 8 sectors per track (640K) -; FCh: 5.25" Single sided, 40 tracks per side, 9 sectors per track (180K) -; FDh: 5.25" Double sided, 40 tracks per side, 9 sectors per track (360K) -; FEh: 5.25" Single sided, 40 tracks per side, 8 sectors per track (160K) -; FFh: 5.25" Double sided, 40 tracks per side, 8 sectors per track (320K) - -DEV_FORMAT: - ld a,.IFORM - ret - - -;----------------------------------------------------------------------------- -; -; Execute direct command on a device -; -;Input: A = Device number, 1 to 7 -; B = Logical unit number, 1 to 7 (if applicable) -; HL = Address of input buffer -; DE = Address of output buffer, 0 if not necessary -;Output: Output buffer appropriately filled (if applicable) -; A = Error code: -; 0: Ok -; 1: Invalid device number or logical unit number, -; or device not ready -; 2: Invalid or unknown command -; 3: Insufficient output buffer space -; 4-15: Reserved -; 16-255: Device specific error codes -; -; The first two bytes of the input and output buffers must contain the size -; of the buffer, not incuding the size bytes themselves. -; For example, if 16 bytes are needed for a buffer, then 18 bytes must -; be allocated, and the first two bytes of the buffer must be 16, 0. - -DEV_CMD: - ld a,2 - ret - -endif - - -;===== -;===== END of DEVICE-BASED specific routines -;===== - - -;======================= -; Subroutines -;======================= - -;----------------------------------------------------------------------------- -; -; Enable or disable the IDE registers - -;Note that bank 7 (the driver code bank) must be kept switched - -IDE_ON: - ld a,1+7*32 - ld (IDE_BANK),a - ret - -IDE_OFF: - ld a,7*32 - ld (IDE_BANK),a - ret - - -;----------------------------------------------------------------------------- -; -; Execute a command -; -; Input: A = Command code -; Other command registers appropriately set -; Output: Cy=1 if ERR bit in status register set - -DO_IDE: - ld (IDE_CMD),a - -WAIT_IDE: - ld a,(IDE_STATUS) - bit DRQ,a - jr nz,IDE_END - bit BSY,a - jr nz,WAIT_IDE - -IDE_END: - rrca - ret - - -;----------------------------------------------------------------------------- -; -; Print a zero-terminated string on screen -; Input: DE = String address - -PRINT: - ld a,(de) - or a - ret z - call CHPUT - inc de - jr PRINT - - -;----------------------------------------------------------------------------- -; -; Obtain the work area address for the driver -; Input: A=1 to obtain the work area for the master, 2 for the slave -; Preserves A - -MY_GWORK: - push af - xor a - EX AF,AF' - XOR A - LD IX,GWORK - call CALBNK - pop af - cp 1 - ret z - inc ix - inc ix - inc ix - inc ix - ret - - -;----------------------------------------------------------------------------- -; -; Check the device index and LUN -; Input: A = device index, B = lun -; Output: Cy=0 if OK, 1 if device or LUN invalid -; IX = Work area for the device -; Modifies F, C - -CHECK_DEV_LUN: - or a ;Check device index - scf - ret z - cp 3 - ccf - ret c - - ld c,a - ld a,b ;Check LUN number - cp 1 - ld a,c - scf - ret nz - - push hl - push de - call MY_GWORK - pop de - pop hl - ld c,a - ld a,(ix) - or a - ld a,c - scf - ret z - - or a - ret - - -;======================= -; Strings -;======================= - -INFO_S: - db "Sunrise IDE device-based driver",13,10 - db "(c) Konamiman 2009",13,10,13,10,0 - -NODEVS_S: - db "No IDE devices found.",13,10,0 -MASTER_S: - db "Master device: ",0 -SLAVE_S: - db "Slave device: ",0 -CRLF_S: - db 13,10,0 - - -;----------------------------------------------------------------------------- -; -; Padding up to the required driver size - -DRV_END: - - ;ds 3FD0h-(DRV_END-DRV_START) - - end diff --git a/source/kernel/drivers/SunriseIDE/DRIVER.MAC b/source/kernel/drivers/SunriseIDE/driver.mac similarity index 95% rename from source/kernel/drivers/SunriseIDE/DRIVER.MAC rename to source/kernel/drivers/SunriseIDE/driver.mac index 80139bd8..4bb0845a 100644 --- a/source/kernel/drivers/SunriseIDE/DRIVER.MAC +++ b/source/kernel/drivers/SunriseIDE/driver.mac @@ -818,6 +818,9 @@ DRV_DIRECT4: ; C = LUN index DRV_CONFIG: + ld a,1 + ret + dec a jr z,DRV_CONFIG_1 dec a @@ -835,7 +838,10 @@ DRV_CONFIG_1: ret DRV_CONFIG_2: - ld a,1 + ld b,c + inc b + ld c,1 + xor a ret @@ -868,6 +874,11 @@ DRV_CONFIG_2: ; B = Number of sectors actually read/written DEV_RW: + ;jr nc,kk + ;ld a,0F8h ;.WPROT + ;ld b,0 + ;ret +kk: push af ld a,b ;Swap B and C diff --git a/source/kernel/drivers/SunriseIDE/sunride.asm b/source/kernel/drivers/SunriseIDE/sunride.asm new file mode 100644 index 00000000..bb683d02 --- /dev/null +++ b/source/kernel/drivers/SunriseIDE/sunride.asm @@ -0,0 +1,3315 @@ + ; Device-based driver for the sunrise IDE interface for Nextor + ; + ; Version 0.1.7 + ; By Konamiman + ; By Piter Punk + ; By FRS + + org 4000h + ds 4100h-$,0 ; DRV_START must be at 4100h +DRV_START: + +TESTADD equ 0F3F5h + +;----------------------------------------------------------------------------- +; +; Driver configuration constants +; + +;Driver type: +; 0 for drive-based +; 1 for device-based + +DRV_TYPE equ 1 + +;Hot-plug devices support (device-based drivers only): +; 0 for no hot-plug support +; 1 for hot-plug support + +DRV_HOTPLUG equ 0 + +DEBUG equ 0 ;Set to 1 for debugging, 0 to normal operation + +;Driver version + +VER_MAIN equ 0 +VER_SEC equ 1 +VER_REV equ 7 + + +;Miscellaneous configuration + DEFINE PIOMODE3 ; Configure devices to work on PIO MODE 3 + + +;This is a very barebones driver. It has important limitations: +;- CHS mode not supported, disks must support LBA mode. +;- 48 bit addresses are not supported +; (do the Sunrise IDE hardware support them anyway?) +;- ATAPI devices not supported, only ATA disks. + + +;----------------------------------------------------------------------------- +; +; IDE registers and bit definitions + +IDE_BANK equ 4104h ;bit 0: enable (1) or disable (0) IDE registers + ;bits 5-7: select 16K ROM bank +IDE_DATA equ 7C00h ;Data registers, this is a 512 byte area +IDE_ERROR equ 7E01h ;Error register +IDE_FEAT equ 7E01h ;Feature register +IDE_SECCNT equ 7E02h ;Sector count +IDE_SECNUM equ 7E03h ;Sector number (CHS mode) +IDE_LBALOW equ 7E03h ;Logical sector low (LBA mode) +IDE_CYLOW equ 7E04h ;Cylinder low (CHS mode) +IDE_LBAMID equ 7E04h ;Logical sector mid (LBA mode) +IDE_CYHIGH equ 7E05h ;Cylinder high (CHS mode) +IDE_LBAHIGH equ 7E05h ;Logical sector high (LBA mode) +IDE_HEAD equ 7E06h ;bits 0-3: Head (CHS mode), logical sector higher (LBA mode) +IDE_STATUS equ 7E07h ;Status register +IDE_CMD equ 7E07h ;Command register +IDE_DEVCTRL equ 7E0Eh ;Device control register + +; Bits in the error register + +UNC equ 6 ;Uncorrectable Data Error +WP equ 6 ;Write protected +MC equ 5 ;Media Changed +IDNF equ 4 ;ID Not Found +MCR equ 3 ;Media Change Requested +ABRT equ 2 ;Aborted Command +NM equ 1 ;No media + +M_ABRT equ 100b ;(1 SHL ABRT) + +; Bits in the head register + +DEV equ 4 ;Device select: 0=master, 1=slave +LBA equ 6 ;0=use CHS mode, 1=use LBA mode + +M_DEV equ 10000b ;(1 SHL DEV) +M_LBA equ 1000000b ;(1 SHL LBA) + +; Bits in the status register + +BSY equ 7 ;Busy +DRDY equ 6 ;Device ready +DF equ 5 ;Device fault +DRQ equ 3 ;Data request +ERR equ 0 ;Error + +M_BSY equ 10000000b ;(1 SHL BSY) +M_DRDY equ 1000000b ;(1 SHL DRDY) +M_DF equ 100000b ;(1 SHL DF) +M_DRQ equ 1000b ;(1 SHL DRQ) +M_ERR equ 1b ;(1 SHL ERR) + +; Bits in the device control register register + +nIEN equ 1 ;Disable interrupts +SRST equ 2 ;Software reset + +M_nIEN equ 10b ;(1 SHL nIEN) +M_SRST equ 100b ;(1 SHL SRST) + +; IDE commands + +ATACMD: +.PRDSECTRT equ #20 +.PWRSECTRT equ #30 +.DEVDIAG equ #90 +.IDENTIFY equ #EC +.SETFEATURES equ #EF + +ATAPICMD: +.RESET equ #08 +.PACKET equ #A0 +.IDENTPACKET equ #A1 + +PACKETCMD: +.RQSENSE equ #03 ; +.RDCAPACITY equ #25 ; Read the media capacity +.READ10 equ #28 ; Read sectors (16bit) +.READ12 equ #A8 ; Read sectors (32bit) +.WRITE10 equ #2A ; Write sectors (16bit) +.WRITE12 equ #AA ; Write sectors (32bit) +.GTMEDIASTAT equ #DA ; Get media status + + +;----------------------------------------------------------------------------- +; +; Standard BIOS entries +CALSLT equ #001C +DCOMPR equ #0020 ; Compare register pairs HL and DE +INITXT equ #006C +CHSNS equ #009C ; Sense keyboard buffer for character +CHGET equ #009F ; Get character from keyboard buffer +CHPUT equ #00A2 ; A=char +BREAKX equ #00B7 ; Check CTRL-STOP key directly +CLS equ #00C3 ; Chamar com A=0 +ERAFNK equ #00CC ; Erase function key display +SNSMAT equ #0141 ; Read row of keyboard matrix +KILBUF equ #0156 ; Clear keyboard buffer +EXTROM equ #015F +CHGCPU equ #0180 +GETCPU equ #0183 + +; subROM functions +SDFSCR equ #0185 +REDCLK equ #01F5 + +; System variables +MSXVER equ #002D +LINL40 equ #F3AE ; Width +LINLEN equ #F3B0 +BDRCLR equ #F3EB +BASROM equ #FBB1 +INTFLG equ #FC9B +JIFFY equ #FC9E +SCRMOD equ #FCAF +EXPTBL equ #FCC1 + + +;----------------------------------------------------------------------------- +; +; Work area definition +; +;+0: Device and logical units types for master device +; bits 0,1: Device type +; 00: No device connected +; 01: ATA hard disk, CHS only +; 10: ATA hard disk, LBA supported +; 11: ATAPI device +; bits 2,3: Device type for LUN 1 on master device +; 00: Block device, non-removable +; 01: Block device, removable +; 10: Other, non removable +; 11: CD-ROM +; bits 4,5: Device type for LUN 2 on master device +; bits 6,7: Device type for LUN 3 on master device +; Inside DRV_INIT only: b7=1 error detected on diagnostics +; b6~b0: reported error code +; +;+1: Logical unit types for master device +; bits 0,1: Device type for LUN 4 on master device +; bits 2,3: Device type for LUN 5 on master device +; bits 4,5: Device type for LUN 6 on master device +; bits 6,7: Device type for LUN 7 on master device +; +;+2,3: Reserved for CHS data for the master device (to be implemented) +; +;+4..+7: Same as +0..+3, for the slave device +; +; Note: Actually, due to driver limitations, currently only the +; "device type" bits are used, and with possible values 00 and 10 only. +; LUN type bits are always 00. + + + STRUCT DEVINFO ; Contains information about a specific device +BASE ; Offset to the base of the data structure +t321D db +t7654 db +;CHSRESERVED ds 2 ; Disabled to save space. 2 bytes won't be enough anyway +SECTSIZE dw ; Sector size for this device +pBASEWRK dw ; Cache pointer to go back to the base of the work area + ENDS + + STRUCT WRKAREA +BASE ; Offset to the base of the data structure +BLKLEN dw ; Size of the block to be copied. ***Must be + ; \the first element of the WRKAREA +PCTBUFF ds 16 ; Buffer to send ATAPI PACKET commands +LDIRHLPR ds 8 ; LDIR data transter helper routine. This is + ; in RAM to speed up the R800 copy a lot. +MASTER DEVINFO ; Offset to the MASTER data structure +SLAVE DEVINFO ; Offset to the SLAVE data structure + ; \*** It must follow the MASTER DEVINFO + ENDS + + STRUCT WRKTEMP +pDEVMSG dw ; Pointer to the text "Master:" or "Slave:" +BUFFER ds 512 ; Buffer for the IDENTIFY info + ENDS + +; ATAPI/SCSI packet structures + STRUCT PCTRW10 ; PACKET READ10/WRITE10 structure +OPCODE db +OPTIONS db +LBA dd +GROUP db +LENGHT dw +CONTROL db + ENDS + + STRUCT PCTRW12 ; PACKET READ12/WRITE12 structure +OPCODE db +OPTIONS db +LBA dd +LENGHT dd +GROUP db +CONTROL db + ENDS + + + + +;----------------------------------------------------------------------------- +; +; Error codes for DEV_RW and DEV_FORMAT +; + +_NCOMP equ 0FFh +_WRERR equ 0FEh +_DISK equ 0FDh +_NRDY equ 0FCh +_DATA equ 0FAh +_RNF equ 0F9h +_WPROT equ 0F8h +_UFORM equ 0F7h +_SEEK equ 0F3h +_IFORM equ 0F0h +_IDEVL equ 0B5h +_IPARM equ 08Bh + +;----------------------------------------------------------------------------- +; +; Routines available on kernel page 0 +; + +;* Get in A the current slot for page 1. Corrupts F. +; Must be called by using CALBNK to bank 0: +; xor a +; ld ix,GSLOT1 +; call CALBNK + +GSLOT1 equ 402Dh + + +;* This routine reads a byte from another bank. +; Must be called by using CALBNK to the desired bank, +; passing the address to be read in HL: +; ld a,bank +; ld hl,address +; ld ix,RDBANK +; call CALBNK + +RDBANK equ 403Ch + + +;* This routine temporarily switches kernel bank 0/3, +; then jumps to CALBAS in MSX BIOS. +; This is necessary so that kernel bank is correct in case of BASIC error. + +CALBAS equ 403Fh + + +;* Call a routine in another bank. +; Must be used if the driver spawns across more than one bank. +; Input: A = bank +; IX = routine address +; AF' = AF for the routine +; BC, DE, HL, IY = input for the routine + +CALBNK equ 4042h + + +;* Get in IX the address of the SLTWRK entry for the slot passed in A, +; which will in turn contain a pointer to the allocated page 3 +; work area for that slot (0 if no work area was allocated). +; If A=0, then it uses the slot currently switched in page 1. +; Returns A=current slot for page 1, if A=0 was passed. +; Corrupts F. +; Must be called by using CALBNK to bank 0: +; ld a,slot +; ex af,af' +; xor a +; ld ix,GWORK +; call CALBNK + +GWORK equ 4045h + + +;* Call a routine in the driver bank. +; Input: (BK4_ADD) = routine address +; AF, BC, DE, HL, IY = input for the routine +; +; Calls a routine in the driver bank. This routine is the same as CALBNK, +; except that the routine address is passed in address BK4_ADD (#F2ED) +; instead of IX, and the bank number is always 5. This is useful when used +; in combination with CALSLT to call a driver routine from outside +; the driver itself. +; +; Note that register IX can't be used as input parameter, it is +; corrupted before reaching the invoked code. + +CALDRV equ 4048h + + +;* Set the current bank +; Must be used exclusively by the MSXBOOT routine +SETBNK equ 7FD0h + + +;----------------------------------------------------------------------------- +; +; Built-in format choice strings +; + +NULL_MSG equ 741Fh ;Null string (disk can't be formatted) +SING_DBL equ 7420h ;"1-Single side / 2-Double side" + + +;----------------------------------------------------------------------------- +; +; Driver signature +; + db "NEXTOR_DRIVER",0 + +; Driver flags: +; bit 0: 0 for drive-based, 1 for device-based +; bit 1: 1 for hot-plug devices supported (device-based drivers only) + + db 1+(2*DRV_HOTPLUG) + +;Reserved byte + db 0 + +;Driver name + +DRV_NAME: + db "Sunrise IDE" + ds 32-($-DRV_NAME)," " + +;Jump table + + jp DRV_TIMI + jp DRV_VERSION + jp DRV_INIT + jp DRV_BASSTAT + jp DRV_BASDEV + jp DRV_EXTBIO + jp DRV_DIRECT0 + jp DRV_DIRECT1 + jp DRV_DIRECT2 + jp DRV_DIRECT3 + jp DRV_DIRECT4 + + ds 15 + + jp DEV_RW + jp DEV_INFO + jp DEV_STATUS + jp LUN_INFO + jp DEV_FORMAT + jp DEV_CMD + + +;----------------------------------------------------------------------------- +; +; Timer interrupt routine, it will be called on each timer interrupt +; (at 50 or 60Hz), but only if DRV_INIT returns Cy=1 on its first execution. + +DRV_TIMI: + ret + + +;----------------------------------------------------------------------------- +; +; Driver initialization, it is called twice: +; +; 1) First execution, for information gathering. +; Input: +; A = 0 +; B = number of available drives (drive-based drivers only) +; HL = maximum size of allocatable work area in page 3 +; Output: +; A = number of required drives (for drive-based driver only) +; HL = size of required work area in page 3 +; Cy = 1 if DRV_TIMI must be hooked to the timer interrupt, 0 otherwise +; +; 2) Second execution, for work area and hardware initialization. +; Input: +; A = 1 +; B = number of allocated drives for this controller +; (255 if device-based driver, unless 4 is pressed at boot) +; +; The work area address can be obtained by using GWORK. +; +; If first execution requests more work area than available, +; second execution will not be done and DRV_TIMI will not be hooked +; to the timer interrupt. +; +; If first execution requests more drives than available, +; as many drives as possible will be allocated, and the initialization +; procedure will continue the normal way +; (for drive-based drivers only. Device-based drivers always +; get two allocated drives.) + +DRV_INIT: + ld hl,WRKAREA ; size of work area + or a ; Clear Cy + ret z + +; 2nd call: + ld a,(CHGCPU) + cp #C3 ; IS CHGCPU present? + jr nz,.call2ini + call GETCPU + push af ; Save the current CPU + ld a,#82 + call CHGCPU ; Enable the turbo +.call2ini: + call MYSETSCR + + ld de,INFO_S + call PRINT + + xor a ; Request the WorkArea base pointer + call MY_GWORK + call INIWORK ; Initialize the work-area + call IDE_ON + +.init: ld (ix+WRKAREA.MASTER.t321D),#FE ; error: No master detected yet + ld de,INIT_S ; Print "Initializing: " + call PRINT + ld a,M_DEV ; Select SLAVE + call WAIT_BSY ; Is the it alive? + jr c,.reset ; No, reset everyone + xor a ; select MASTER + call SELDEV + call WAIT_BSY ; Is the it alive? + jr nc,.diag ; Yes, skip +.reset: + call RESET_ALL +.diag: + ld a,(INTFLG) + cp 3 ; CTRL+STOP pressed? + jp z,INIT_ABORTED + ld a,ATACMD.DEVDIAG ; Both drives will execute diagnostics + ld (IDE_CMD),a + call WAIT_RST ; Wait for the diagnostics to end + ld a,(INTFLG) + cp 3 ; CTRL+STOP pressed? + jp z,INIT_ABORTED + ld a,(IDE_STATUS) + and M_ERR ; Error bit set? + jr nz,.diagchk ; on error, skip to diagnostics + ld (ix+WRKAREA.MASTER.t321D),0 ; Clear undetected master error + +.diagchk: + ; Check the diagnostics and print the results + call CHKDIAG + push af + ld de,INIT_S ; Print "Initializing: " + call PRINT + pop af + ld de,OK_S + call nc,PRINT + ld de,ERROR_S + call c,PRINT + +.chkmaster: + ld de,MASTER_S + ld (TEMP_WORK.pDEVMSG),de + call PRINT + + ; Check for DIAGNOSTICS errors + ld a,(ix+WRKAREA.MASTER.t321D) + ld c,a + bit 7,a ; Any error detected by DIAGNOSE? + jr z,.detinit ; No, skip + call DIAGERRPRT ; Print the diagnostic error + ld (ix+WRKAREA.MASTER.t321D),0 ; This device isn't available + ; Errors 0 and 5 are critical and cannot proceed + ld a,c + and #7F ; Crop erro code + jr z,.critical + cp 5 ; Microcontroller error on master? + jp nz,.chkslave ; No: slave can still be used safely +.critical: + ld (ix+WRKAREA.SLAVE.t321D),0 ; No master = no slave + jp DRV_INIT_END ; Finish DEV_INIT + +.detinit: + ld a,M_DEV ; Select SLAVE + call SELDEV + call WAIT_RST ; wait until ready + jr nc,.detmaster + ld (ix+WRKAREA.SLAVE.t321D),#80 ; Slave has an error + +.detmaster: + call RESET_ALL.ataonly + push ix + ld de,WRKAREA.MASTER + add ix,de ; Point ix to the MASTER work area + xor a ; Select MASTER + call DETDEV + pop ix + ld a,(ix+WRKAREA.MASTER.t321D) + and 3 ; There can't be a slave without a master + jr z,INIT_MASTERFAIL ; Finish DEV_INIT + +.chkslave: + ld de,SLAVE_S + ld (TEMP_WORK.pDEVMSG),de + call PRINT + + ; Check for DIAGNOSTICS errors + ld a,(ix+WRKAREA.SLAVE.t321D) + bit 7,a ; Any error detected by DIAGNOSE? + jr z,.detslave ; No, skip to detection + + call DIAGERRPRT ; Print the diagnostic error + ld (ix+WRKAREA.SLAVE.t321D),0 ; This device isn't available + jp DRV_INIT_END + +.detslave: + push ix + ld de,WRKAREA.SLAVE.BASE + add ix,de ; Point ix to the SLAVE work area + ld a,M_DEV ; Select SLAVE + call DETDEV + pop ix + + ; Reset all devices to finish +END_DETECT: + call RESET_ALL + + ;--- End of the initialization procedure +DRV_INIT_END: + call IDE_OFF + call INICHKSTOP + ld de,CRLF_S ; Skip a line for the next driver + call PRINT + + ; ***Workaround for a bug in Nextor that causes it to freeze if + ; CTRL+STOP was pressed on boot + ld a,(INTFLG) + cp 3 ; Is CTRL+STOP still signaled? + jr nz,.restCPU ; no, skip + xor a + ld (INTFLG),a ; Clear CTRL+STOP otherwise Nextor will freeze + +.restCPU: ; Restore the CPU if necessary + ld a,(CHGCPU) + cp #C3 ; IS CHGCPU present? + ret nz + pop af + or #80 + jp CHGCPU + + +INIT_ABORTED: + ld de,ABORTED_S ; Print "" + jr INIT_MASTERFAIL.end + +INIT_MASTERFAIL: + ld de,DIAGS_S.nomaster ; Print "failed"> + call PRINT +.end: ld (ix+WRKAREA.MASTER.t321D),0 + ld (ix+WRKAREA.SLAVE.t321D),0 + jr DRV_INIT_END + + + + +;--- Subroutines for the INIT procedure + +; Input: A=target device +; (TEMP_WORK.pDEVMSG): Pointer to the "Master" or "Slave" text +DETDEV: + ld c,a ; c=target device + ld de,DETECT_S ; Print "detecting" + call PRINT + + ld a,(INTFLG) + cp 3 ; Was CTRL+STOP signaled? + jp z,.aborted ; Yes, skip + + ld a,c ; Select device + call SELDEV + call WAIT_BSY ; wait until ready + jp c,.nodev + call DISDEVINT ; Disable interrupts + jp c,.nodev + + ld a,'.' ; Print the FIRST dot + call CHPUT + ;--- Get the device type + call GETDEVTYPE ; Get the device type + ei + ld (ix+DEVINFO.t321D),a + jp c,.nodev + cp #FF + jp z,.unknown + + ;---Configure the PIO transfer mode + IFDEF PIOMODE3 + ld a,3 ; Set transfer mode + ld (IDE_FEAT),a + + ld a,#8+#3 ; PIO flow control, mode 3, so + ; IORDY becomes functional + ld (IDE_SECCNT),a + + ld a,ATACMD.SETFEATURES + ld (IDE_CMD),a + call WAIT_BSY + jr c,.unsupported ; No PIO3? This device is too old + ENDIF + + ;--- Get the name of the device + ;(IDENTIFY device data on TEMP_WORK.BUFFER) +.getinfo: + ld de,(TEMP_WORK.pDEVMSG) + call PRINT + + ;Print the device name. + ld hl,TEMP_WORK.BUFFER+27*2 + ld b,20 + call .prtword + + ; Print the firmware version + ld hl,TEMP_WORK.BUFFER+23*2 + ld b,4 + call .prtword + + ; Print the device characteristics + ld de,DETECT_S.oparenthesis + call PRINT + ld a,(ix+DEVINFO.t321D) + and 3 ; Crop devtype + ld de,DETECT_S.chs + dec a + jr z,.printdevtype + ld de,DETECT_S.lba + dec a + jr z,.printdevtype + ld de,DETECT_S.atapi +.printdevtype: + call PRINT + + ld a,')' + call CHPUT + ld de,CRLF_S + jp PRINT + + + + + + ; --- Print an word string + ; input: HL=string ponter + ; B=Number of words to print +.prtword: + ld c,(hl) + inc hl + ld a,(hl) + inc hl + call CHPUT + ld a,c + call CHPUT + djnz .prtword + ret + + ;--- Unknown device +.unknown: + ld (ix+DEVINFO.t321D),a + ld de,DETECT_S.unknown + call PRINT + ld a,h + call PRINTHEXBYTE + ld a,l + call PRINTHEXBYTE + ld a,'h' + call CHPUT + ld de,CRLF_S + jp PRINT + + ;--- Unsupported device (either too old or too new) +.unsupported: + ld de,DETECT_S.unsupported + jr .nodevreason + + ;--- No device was found +.nodev: + ld de,NODEVS_S + + ;--- Prints the reason why there will be no device reported here +.nodevreason: + ld (ix+DEVINFO.t321D),0 + push de + ld de,(TEMP_WORK.pDEVMSG) + call PRINT ; Clear previous label message + pop de + jp PRINT + + ;--- Dectection aborted by the user +.aborted: + ld de,ABORTED_S + jr .nodevreason + +;----------------------------------------------------------- +WAIT_RST: +; Wait for the BSY flat to be reset for the selected device +; Output: Cy set= timeout +; (INTFLG)=3 if the user pressed CTRL+STOP +; Note: This routine is intended to wait BSY for long periods, as required +; by soft-reset and DIAGNOSTICS. + +; Step-1: Fast reset +; Will catch devices that reset quicly, like CFs and HDDs that are already spinning + + ld de,5*60 ; Wait for up to 5s +.wait1: + ld a,e + and 127 ; Is it the time to print a dot? + ld a,'.' + call z,CHPUT ;Yes, print dots while waiting + call BREAKX + ret c + ld bc,#0505 ;5 fast retries for 5 short pauses +.wait2: + ld a,(INTFLG) + cp 3 ; was CTRL+STOP still signaled? + ret z + ld a,(IDE_STATUS) + and M_BSY + ret z ; This ATA device has finished its reset + djnz .wait2 + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + dec c + jr nz,.wait2 + dec de + ld a,e + or d + halt ;Give the device some time to breath + jr nz,.wait1 + scf + ret + +;Check that a device is present and usable. +;Input: DIAGNOSTICS issued successfully. +;Output: A=devtype. 0=nodev, 1=CHS, 2=LBA, 3=ATAPI +; Cy=0 for device ok, 1 for no device or not usable. +; If device ok, 50 first bytes of IDENTIFY device copied to TEMP_WORK. + +GETDEVTYPE: +; Input: none +; Output: A=devtype. 0=none, 1=CHS, 2=LBA, 3=ATAPI +; Cy on if the device is undetected or unknown +; When Cy=on, HL will contain the signature of the unknown device + +; Notes: + ; Device Signatures are checked according to the ATA/ATAPI Command Set-3 + ; (ACS-3) revision-5 document, page-347. + + ; PATA PATAPI SATA SATAPI + ; COUNT : 01h 01h 01h 01h + ; LBA 23-16: 00h EBh C3h 96h + ; LBA 8-15: 00h 14h 3Ch 69h + ; LBA 0-7: 01h 01h 01h 01h + + ; This signatures are output by the following commands: + ; - DEVICE RESET (08h) + ; - DEVICE DIAGNOSTIC (90h) + ; - IDENTIFY DEVICE (ECh) + ; - READ SECTOR(S) (20h) + + ; Note by Piter: Not all devices respect this. One of my CompactFlash + ; cards never have Sector Count = 01 after reset. + ;ld a,(IDE_SECCNT) + ;cp 1 + ;jr nz,INIT_CHECK_NODEV + + ld hl,(IDE_LBAMID) + ld de,#EB14 ; PATAPI signature? + rst DCOMPR + ld a,3 ; devtype=ATAPI + jr z,.identify + + ld de,#9669 ; SATAPI signature? + rst DCOMPR + ld a,3 ; devtype=ATAPI + jr z,.identify + + ld de,#0000 ; PATA signature? + rst DCOMPR + ld a,1 ; devtype=CHS + jr z,.identify + + ld de,#C33C ; SATA signature? + rst DCOMPR + ld a,2 ; devtype=LBA + jr z,.identify + + ld de,#7F7F ; Unconnected signature? + rst DCOMPR + scf + ret z ; Yes, quit with Cy + + ld de,#FFFF ; Unconnected signature? + rst DCOMPR + scf + ret z ; Yes, quit with Cy + +.unkdev: ; Unknown device + ld a,#FF + or a + ret + +.identify: + ld b,a ; b=devtype + cp 3 ; ATAPI? + ld a,ATACMD.IDENTIFY ;Send IDENTIFY commad + jr c,.identify2 + ld a,ATAPICMD.IDENTPACKET ;Send IDENTIFY PACKET commad +.identify2: + di + call PIO_CMD + ld a,0 ; Return 0 on error + ret c + ld a,b ; a=devtype + ld hl,IDE_DATA + ld de,TEMP_WORK.BUFFER + ld bc,512 ;Read the IDENTIFY packet + ldir + ei + cp 2 ; SATA or ATAPI? + ret nc ; Yes, return + +.chkLBA: + ld a,(TEMP_WORK.BUFFER+49*2+1) + and 2 ; LBA supported? + ld a,1 ; devtype=CHS + ret z ; No, return + inc a ; devtype=LBA + ret + + + + +;----------------------------------------------------------------------------- +; +; Obtain driver version +; +; Input: - +; Output: A = Main version number +; B = Secondary version number +; C = Revision number + +DRV_VERSION: + ld a,VER_MAIN + ld b,VER_SEC + ld c,VER_REV + ret + + +;----------------------------------------------------------------------------- +; +; BASIC expanded statement ("CALL") handler. +; Works the expected way, except that CALBAS in kernel page 0 +; must be called instead of CALBAS in MSX BIOS. + +DRV_BASSTAT: + scf + ret + + +;----------------------------------------------------------------------------- +; +; BASIC expanded device handler. +; Works the expected way, except that CALBAS in kernel page 0 +; must be called instead of CALBAS in MSX BIOS. + +DRV_BASDEV: + scf + ret + + +;----------------------------------------------------------------------------- +; +; Extended BIOS hook. +; Works the expected way, except that it must return +; D'=1 if the old hook must be called, D'=0 otherwise. +; It is entered with D'=1. + +DRV_EXTBIO: + ret + + +;----------------------------------------------------------------------------- +; +; Direct calls entry points. +; Calls to addresses 7450h, 7453h, 7456h, 7459h and 745Ch +; in kernel banks 0 and 3 will be redirected +; to DIRECT0/1/2/3/4 respectively. +; Receives all register data from the caller except IX and AF'. + +DRV_DIRECT0: +DRV_DIRECT1: +DRV_DIRECT2: +DRV_DIRECT3: +DRV_DIRECT4: + ret + + +;===== +;===== BEGIN of DEVICE-BASED specific routines +;===== + +;----------------------------------------------------------------------------- +; +; Read or write logical sectors from/to a logical unit +; +;Input: Cy=0 to read, 1 to write +; A = Device number, 1 to 7 +; B = Number of sectors to read or write +; C = Logical unit number, 1 to 7 +; HL = Source or destination memory address for the transfer +; DE = Address where the 4 byte sector number is stored +;Output: A = Error code (the same codes of MSX-DOS are used): +; 0: Ok +; _IDEVL: Invalid device or LUN +; _NRDY: Not ready +; _DISK: General unknown disk error +; _DATA: CRC error when reading +; _RNF: Sector not found +; _UFORM: Unformatted disk +; _WPROT: Write protected media, or read-only logical unit +; _WRERR: Write error +; _NCOMP: Incompatible disk +; _SEEK: Seek error +; B = Number of sectors actually read/written + +DEV_RW: + push af + call MY_GWORK ; ix=Work area pointer for this device + + push bc + ld b,c ;b=LUN + call CHECK_DEV_LUN + pop bc + jp c,DEV_RW_NODEV + + dec a + jr z,DEV_RW2 + ld a,M_DEV +DEV_RW2: + ld c,a ;c=dev# in IDE format + + ld a,b + or a + jr nz,DEV_RW_NO0SEC + pop af ;Discard the device number that was on stack + xor a + ld b,0 + ret +DEV_RW_NO0SEC: + ld iy,de + ld a,(iy+3) + and 11110000b + jp nz,DEV_RW_NOSEC ;Only 28 bit sector numbers supported + + call IDE_ON + + ld a,(ix+DEVINFO.t321D) + and 3 ; Crop devtype + cp 3 ; ATAPI? + jp z,DEV_ATAPI_RW + +DEV_ATA_RW: + ld a,(iy+3) + or M_LBA + or c ; Mix with dev# in IDE format + call SELDEV ; IDE_HEAD must be written first, + ld a,(iy) ; or the other IDE_LBAxxx and IDE_SECCNT + ld (IDE_LBALOW),a ; registers will not get a correct value + ld e,(iy+1) ; (blueMSX issue?) + ld d,(iy+2) + ld (IDE_LBAMID),de + ld a,b + ld (IDE_SECCNT),a + + pop af ; a=device number in Nextor format + jp c,DEV_ATA_WR + + ;--- + ;--- ATA READ + ;--- +DEV_ATA_RD: + ld a,ATACMD.PRDSECTRT ; PIO read sector with retry + call PIO_CMD + jp c,DEV_RW_ERR + + call CHK_RW_FAULT + ret c + ld iyl,b ; iyl=number of blocks + ex de,hl ; de=destination address + + ld bc,512 ; block size ***Hardcoded. Ignores (BLKLEN) + call READ_DATA + jp c,DEV_RW_ERR + call IDE_OFF + xor a ; A=0: No error. + ret + + ;--- + ;--- ATA WRITE + ;--- +DEV_ATA_WR: + ld a,ATACMD.PWRSECTRT ; PIO write sector with retry + call PIO_CMD + jp c,DEV_RW_ERR + ld iyl,b ; iyl=number of blocks + + ld bc,512 ; block size ***Hardcoded. Ignores (BLKLEN) + call WRITE_DATA + jp c,DEV_RW_ERR + call IDE_OFF + xor a ; A=0: No error. + ret + + +DEV_ATAPI_RW: + ld a,c ;Get devnum in IDE format + call SELDEV + + ; Fill the READ10/WRITE10 packet structure + push de + ld e,(ix+DEVINFO.pBASEWRK) ; hl=pointer to WorkArea + ld d,(ix+DEVINFO.pBASEWRK+1) + ld iy,de ; iy=WRKAREA pointer + pop de + + ; Set the block size + ld a,(ix+DEVINFO.SECTSIZE) + ld (iy+WRKAREA.BLKLEN),a + ld a,(ix+DEVINFO.SECTSIZE+1) + ld (iy+WRKAREA.BLKLEN+1),a + + ld (iy+WRKAREA.PCTBUFF+PCTRW10.LENGHT),0 + ld (iy+WRKAREA.PCTBUFF+PCTRW10.LENGHT+1),b + ld a,(de) + ld (iy+WRKAREA.PCTBUFF+PCTRW10.LBA+3),a + inc de + ld a,(de) + ld (iy+WRKAREA.PCTBUFF+PCTRW10.LBA+2),a + inc de + ld a,(de) + ld (iy+WRKAREA.PCTBUFF+PCTRW10.LBA+1),a + inc de + ld a,(de) + ld (iy+WRKAREA.PCTBUFF+PCTRW10.LBA+0),a + ; Set the fields that we don't need to 0 + xor a + ld (iy+WRKAREA.PCTBUFF+PCTRW10.OPTIONS),a + ld (iy+WRKAREA.PCTBUFF+PCTRW10.GROUP),a + ld (iy+WRKAREA.PCTBUFF+PCTRW10.CONTROL),a + ld (iy+WRKAREA.PCTBUFF+PCTRW12.GROUP),a + ld (iy+WRKAREA.PCTBUFF+PCTRW12.CONTROL),a + + ld de,512 ;Set the buffer size to the 512 bytes + ld (IDE_LBAMID),de + + ; + pop af ; a=device number in Nextor format, f=r/w flag + jp c,DEV_ATAPI_WR + ; + +DEV_ATAPI_RD: + ld a,PACKETCMD.READ12 + ld (iy+WRKAREA.PCTBUFF+PCTRW10.OPCODE),a + ld a,ATAPICMD.PACKET ; PIO send PACKET command + call PIO_CMD + jp c,DEV_RW_ERR + push bc,hl,iy + ld iyl,1 ; 1 block + ld hl,WRKAREA.PCTBUFF + ld bc,PCTRW10 ; block size=10 bytes + call WRITE_DATA ; Send the packet to the device + pop iy,hl,bc + jp c,DEV_RW_ERR + +.init1: ; Set the sector size and number of blocks + ; sizes bigger than 512 must be a multiple of 512 + ld a,(ix+DEVINFO.SECTSIZE+1) + srl a ; SECTSIZE=SECTSIZE/512 (the IDE buffer can + ; transfer only 512 bytes per time) + ld de,512 ; block size=512 + jr nz,.init2 ; Skip if the boundary check is ok + inc a ; Keep the block count to at least 1 + ld e,(ix+DEVINFO.SECTSIZE) + ld d,(ix+DEVINFO.SECTSIZE+1) + +.init2: + ld c,a ; c=number of 512-byte blocks per sector + + push bc + ld bc,de ; bc=block size + call SETLDIRHLPR ; hl'=Pointer to LDIR helper in RAM + pop bc + ex de,hl ; de=destination address +.loopsector: + push bc + ld iyl,c ; get the number of blocks per sector +.loopblock: + call WAIT_DRQ + jr c,.rderr + ld hl,IDE_DATA + call RUN_HLPR + dec iyl + jr nz,.loopblock + pop bc + djnz .loopsector + + call IDE_OFF + xor a + ret + +.rderr: ; Allows the read loop to run faster with a jr + jp DEV_RW_ERR + + +DEV_ATAPI_WR: + ld a,PACKETCMD.WRITE10 + ld (iy+WRKAREA.PCTBUFF+PCTRW10.OPCODE),a + ld a,ATAPICMD.PACKET ; PIO send PACKET command + call PIO_CMD + jp c,DEV_RW_ERR + push bc,hl,iy + ld iyl,1 ; 1 block + ld hl,WRKAREA.PCTBUFF + ld bc,PCTRW10 ; block size=10 bytes + call WRITE_DATA ; Send the packet to the device + pop iy,hl,bc + jp c,DEV_RW_ERR + +.init1: ; Set the sector size and number of blocks + ; sizes bigger than 512 must be a multiple of 512 + ld a,(ix+DEVINFO.SECTSIZE+1) + srl a ; SECTSIZE=SECTSIZE/512 (the IDE buffer can + ; transfer only 512 bytes per time) + ld de,512 ; block size=512 + jr nz,.init2 ; Skip if the boundary check is ok + inc a ; Keep the block count to at least 1 + ld e,(ix+DEVINFO.SECTSIZE) + ld d,(ix+DEVINFO.SECTSIZE+1) + +.init2: + ld c,a ; c=number of 512-byte blocks per sector + + push bc + ld bc,de ; bc=block size + call SETLDIRHLPR ; hl'=Pointer to LDIR helper in RAM + pop bc +.loopsector: + push bc + ld iyl,c ; get the number of blocks per sector +.loopblock: + call WAIT_DRQ + jr c,.rderr + ld de,IDE_DATA + call RUN_HLPR + call CHK_RW_FAULT + jr c,.rderr + dec iyl + jp nz,.loopblock + pop bc + djnz .loopsector + + call IDE_OFF + xor a + ret + +.rderr: ; Allows the read loop to run faster with a jr +; jp DEV_RW_ERR + + + ;--- + ;--- ERROR ON READ/WRITE + ;--- + +DEV_RW_ERR: + ld a,(IDE_ERROR) + ld b,a ; b=IDE_ERROR + call IDE_OFF + bit NM,b ;Not ready + jr nz,DEV_R_ERR1 + ld a,_NRDY + ld b,0 + ret +DEV_R_ERR1: + bit IDNF,b ;Sector not found + jr nz,DEV_R_ERR2 + ld a,_RNF + ld b,0 + ret +DEV_R_ERR2: + bit WP,b ;Write protected + jr nz,DEV_R_ERR3 + ld a,_WPROT + ld b,0 + ret +DEV_R_ERR3: + ld a,_DISK ;Other error + ld b,0 + ret + + ;--- Termination points + +DEV_RW_NOSEC: + call IDE_OFF + pop af + ld a,_RNF + ld b,0 + ret + +DEV_RW_NODEV: + call IDE_OFF + pop af + ld a,_IDEVL + ld b,0 + ret + + +;----------------------------------------------------------------------------- +; +; Device information gathering +; +;Input: A = Device index, 1 to 7 +; B = Information to return: +; 0: Basic information +; 1: Manufacturer name string +; 2: Device name string +; 3: Serial number string +; HL = Pointer to a buffer in RAM +;Output: A = Error code: +; 0: Ok +; 1: Device not available or invalid device index +; 2: Information not available, or invalid information index +; When basic information is requested, +; buffer filled with the following information: +; +;+0 (1): Numer of logical units, from 1 to 8. 1 if the device has no logical +; drives (which is functionally equivalent to having only one). +;+1 (1): Flags, always zero +; +; The strings must be printable ASCII string (ASCII codes 32 to 126), +; left justified and padded with spaces. All the strings are optional, +; if not available, an error must be returned. +; If a string is provided by the device in binary format, it must be reported +; as an hexadecimal, upper-cased string, preceded by the prefix "0x". +; The maximum length for a string is 64 characters; +; if the string is actually longer, the leftmost 64 characters +; should be provided. +; +; In the case of the serial number string, the same rules for the strings +; apply, except that it must be provided right-justified, +; and if it is too long, the rightmost characters must be +; provided, not the leftmost. + +DEV_INFO: + ;Check device index boundaries + or a + jp z,.error1 + cp 3 + jp nc,.error1 + + call MY_GWORK + + ld c,a + ld a,b + or a + jr nz,.strings + + ;--- Obtain basic information + + ld a,(ix+DEVINFO.t321D) ; Get current device type + and 3 ;Device available? + jr z,.error1 + + ld (hl),1 ;One single LUN + inc hl + ld (hl),0 ;Always zero + xor a + ret + + ;--- Obtain string information +.strings: + call IDE_ON + + ld a,c + dec a + jr z,.swcase + ld a,M_DEV + +.swcase: + call SELDEV + + ld a,b + dec a ; A=1? (Manufacturer name) + jr z,.error2 ; Yes, quit. IDE doesn't have it. + + dec a ; A=2? (Device name) + jr z,.devname + + dec a ; A=3? (Serial number) + jr nz,.error2 ; No, quit with error + jr .devserial ; Skip to serial number routine + + ;--- Device name +.devname: +; push hl + call DEV_STRING_CLR + ld bc,#1B14 ; Device name word on IDENTIFY + call DEV_STRING_DIGEST +; pop hl + jr c,.error1 +; ld bc,#1708 +; ld de,21 +; add hl,de +; call DEV_STRING_DIGEST ; Get the device version +; jr c,.error1 + + call IDE_OFF + xor a + ret + + + ;--- Serial number +.devserial: + call DEV_STRING_CLR + ld bc,#0A0A + ld de,44 + add hl,de ;Since the string is 20 chars long + call DEV_STRING_DIGEST + jr c,.error1 + call IDE_OFF + xor a + ret + + + ;--- Termination with error +.error1: + call IDE_OFF + ld a,1 + scf + ret + +.error2: + call IDE_OFF + ld a,2 + ret + + +;--- Clear the destination buffer +; Input : HL = 64 bytes string buffer +; Modifies: AF, BC +DEV_STRING_CLR: + push hl + ld a,' ' + ld b,64 +.loopclr: + ld (hl),a + inc hl + djnz .loopclr + pop hl + ret + + + + + +;Common processing for obtaining a device information string +;Input : B = Offset of the string in the device information (words) +; C = Size of the string to be copied to the buffer (bytes) +; HL = Destination address for the string +;Modifies: AF, BC, DE, HL +DEV_STRING_GET: + push hl + ; Calculate the number of bytes that will remain + ld a,c + srl a ; a=number of words in the string + add b ; a=number of words to be consumed + ld e,a + ld d,0 + ld hl,256 + or a + sbc hl,de + ld h,l ; h=number of remaining words + ex (sp),hl ; (sp)=number of remaining words + + ld a,(ix+DEVINFO.t321D) + and 3 + cp 3 ; ATAPI? + ld a,ATACMD.IDENTIFY ; Send IDENTIFY commad + jr c,.identify + ld a,ATAPICMD.IDENTPACKET ;Send IDENTIFY PACKET commad +.identify: + call PIO_CMD + jr c,.errorpop + + ex de,hl ; de=string buffer +.skip: + ld hl,(IDE_DATA) ;Skip device data until the desired string + djnz .skip + + ; Transfer all bytes to the buffer. String processing must be done + ; later because some devices don't like when the transfer is too slow +; ld b,0 + ld hl,IDE_DATA + ldir + + pop bc ; b=number of remaining words +.flushloop: ; Flush the rest of the data + ld hl,(IDE_DATA) + djnz .flushloop + + or a ; Clear Cy + ret + +.errorpop: + pop de ; Discard stack data + ret + + +; Digest a string from the device and place it on the buffer +; Input : IY=Pointer to the text buffer +; B=Size of the string +; Modifies: AF, BC +DEV_STRING_DIGEST: + push bc,hl + call DEV_STRING_GET + pop iy,bc + ret c + ld b,c + + ; --- Digest an ATA string into a text string +.stringloop: + ld a,(iy+1) + ld c,(iy) + call .validatechar + ld (iy),a + ld a,c + call .validatechar + ld (iy+1),a + inc iy + inc iy + djnz .stringloop + or a ; Clear Cy + ret + +.validatechar: + cp 32 + jr c,.invalidchar + cp 127 + ret c +.invalidchar: + ld a,'_' + ret + + + + +;----------------------------------------------------------------------------- +; +; Obtain device status +; +;Input: A = Device index, 1 to 7 +; B = Logical unit number, 1 to 7. +; 0 to return the status of the device itself. +;Output: A = Status for the specified logical unit, +; or for the whole device if 0 was specified: +; 0: The device or logical unit is not available, or the +; device or logical unit number supplied is invalid. +; 1: The device or logical unit is available and has not +; changed since the last status request. +; 2: The device or logical unit is available and has changed +; since the last status request +; (for devices, the device has been unplugged and a +; different device has been plugged which has been +; assigned the same device index; for logical units, +; the media has been changed). +; 3: The device or logical unit is available, but it is not +; possible to determine whether it has been changed +; or not since the last status request. +; +; Devices not supporting hot-plugging must always return status value 1. +; Non removable logical units may return values 0 and 1. + +DEV_STATUS: + set 0,b ;So that CHECK_DEV_LUN admits B=0 + + call CHECK_DEV_LUN + ld e,a + ld a,0 + ret c + + ld a,1 ;Never changed + ret + + ;ld a,1 + ;ret + + ld a,e + cp 2 + ld a,1 + ret nz + + ld a,e + dec a ;FOR TESTING: + ld a,2 ;Return "Unchanged" for device 1, "Unknown" for device 2 + ret z + ld a,3 + ret + + +;----------------------------------------------------------------------------- +; +; Obtain logical unit information +; +;Input: A = Device index, 1 to 7. +; B = Logical unit number, 1 to 7. +; HL = Pointer to buffer in RAM. +;Output: A = 0: Ok, buffer filled with information. +; 1: Error, device or logical unit not available, +; or device index or logical unit number invalid. +; On success, buffer filled with the following information: +; +;+0 (1): Medium type: +; 0: Block device +; 1: CD or DVD reader or recorder +; 2-254: Unused. Additional codes may be defined in the future. +; 255: Other +;+1 (2): Sector size, 0 if this information does not apply or is +; not available. +;+3 (4): Total number of available sectors. +; 0 if this information does not apply or is not available. +;+7 (1): Flags: +; bit 0: 1 if the medium is removable. +; bit 1: 1 if the medium is read only. A medium that can dinamically +; be write protected or write enabled is not considered +; to be read-only. +; bit 2: 1 if the LUN is a floppy disk drive. +;+8 (2): Number of cylinders (0, if not a hard disk) +;+10 (1): Number of heads (0, if not a hard disk) +;+11 (1): Number of sectors per track (0, if not a hard disk) + +LUN_INFO: + call CHECK_DEV_LUN + jp c,LUN_INFO_ERROR + + call MY_GWORK ; ix=workarea for this device + + ld b,a + call IDE_ON + ld a,b + + push hl + pop iy + dec a + jr z,LUN_INFO2 + ld a,M_DEV +LUN_INFO2: + + ld e,a + call WAIT_DRDY + jp c,LUN_INFO_ERROR + ld a,e + + call SELDEV + + ld a,(ix+DEVINFO.t321D) + and 3 + cp 3 ; ATAPI? + jp z,LUN_NFO_ATAPI ; Yes, skip + + ld a,ATACMD.IDENTIFY ; Send IDENTIFY commad + call PIO_CMD + jp c,LUN_INFO_ERROR + + ;========== Device properties ========== + + ;---Set the device type + ld (iy),0 ;set device type + ld (iy+7),0 ;Not removable, nor floppy + + ld hl,(IDE_DATA) ;Skip word 0 + ;Set cylinders, heads, and sectors/track + ld hl,(IDE_DATA) + ld (iy+8),l ;Word 1: Cylinders + ld (iy+9),h + ld hl,(IDE_DATA) ;Skip word 2 + ld hl,(IDE_DATA) + ld (iy+10),l ;Word 3: Heads + ld hl,(IDE_DATA) + ld hl,(IDE_DATA) ;Skip words 4,5 + ld hl,(IDE_DATA) + ld (iy+11),l ;Word 6: Sectors/track + + ;Set maximum sector number + ld b,60-7 ;Skip until word 60 +.skip1: + ld de,(IDE_DATA) + djnz .skip1 + + ld de,(IDE_DATA) ;DE = Low word + ld hl,(IDE_DATA) ;HL = High word + + ld (iy+3),e + ld (iy+4),d + ld (iy+5),l + ld (iy+6),h + + ;Set sector size + ld b,117-62 ;Skip until word 117 +.skip2: + ld de,(IDE_DATA) + djnz .skip2 + + ld de,(IDE_DATA) ;DE = Low word + ld hl,(IDE_DATA) ;HL = High word + + ld a,h ;If high word not zero, set zero (info not available) + or l + ld hl,0 + ex de,hl + jr nz,.info_ssize + + ex de,hl + ld a,d + or e + jr nz,.info_ssize + ld de,512 ;If low word is zero, assume 512 bytes +.info_ssize: + ld (iy+1),e + ld (iy+2),d + ld (ix+DEVINFO.SECTSIZE),e + ld (ix+DEVINFO.SECTSIZE+1),d + + ;Flush the rest of the data + ld b,256-118 +.skip3: + ld de,(IDE_DATA) + djnz .skip3 + + ; Finish + call IDE_OFF + xor a + ret + +LUN_NFO_ATAPI: + ld a,ATAPICMD.IDENTPACKET ;Send IDENTIFY PACKET commad + call PIO_CMD + jp c,LUN_INFO_ERROR + + ld hl,(IDE_DATA) ;Read word 0 + ; Get the ATAPI device type + xor a + sla l ;Get the removable-device flag + adc a,a ;Inject it in A + ld (iy+7),a + ld a,h + and #1F ;Crop command packet set + ld d,a ;d=0: block device + jr z,.setdevtype ;Direct-access device + dec d ;d=255: other + cp 5 ;CD-ROM? + jr nz,.setdevtype ;Yes, skip + ld d,1 ;d=1: CD-ROM + ld a,2 ;read-only media + or (iy+7) +.setdevtype: + ld (iy+7),a + ld (iy),d ;set device type + + ld b,255 ;Flush the rest of the data +.skip1: + ld hl,(IDE_DATA) + djnz .skip1 + + + ld hl,512 ;Set the buffer size to 512 bytes + ld (IDE_LBAMID),hl + ld l,(ix+DEVINFO.pBASEWRK) ; hl=WorkArea + ld h,(ix+DEVINFO.pBASEWRK+1) + ld de,WRKAREA.PCTBUFF + add hl,de + push hl + ld (hl),PACKETCMD.RDCAPACITY + inc hl + ld b,11 +.zloop: ld (hl),0 ; Clear the rest of the package + inc hl + djnz .zloop + + ld a,ATAPICMD.PACKET ; PIO send PACKET command + call PIO_CMD + jr c,.errorpop + + pop hl + push hl ; Source=PCTBUF + ld bc,12 ; 12 byte packet + push iy + ld iyl,1 + call WRITE_DATA ; Send the packet to the device + pop iy + jr nc,.rdmediapropr ; No error? Then read media proprieties + + ; Guess the sector size based on the device type + pop de ; Discard the destination buffer address + ld a,(iy) ; Get device type + ld de,2048 ; CD-ROM sector size + cp 1 ; CD-ROM? + jr z,.info_ssizeatapi + ld de,512 ; Otherwise assume a 512 byte sector + jr .info_ssizeatapi + +.rdmediapropr: + pop de ; Destination=PCTBUFF + ld bc,8 ; 8 byte response + push iy + ld iyl,1 + call READ_DATA + pop iy + jr c,LUN_INFO_ERROR + + ld h,(ix+WRKAREA.PCTBUFF+0) ; Get the number of sectors + ld l,(ix+WRKAREA.PCTBUFF+1) + ld d,(ix+WRKAREA.PCTBUFF+2) + ld e,(ix+WRKAREA.PCTBUFF+3) + ld (iy+3),e ; Set the number of sectors + ld (iy+4),d + ld (iy+5),l + ld (iy+6),h + + ld h,(ix+WRKAREA.PCTBUFF+4) ; Get the sector size + ld l,(ix+WRKAREA.PCTBUFF+5) + ld d,(ix+WRKAREA.PCTBUFF+6) + ld e,(ix+WRKAREA.PCTBUFF+7) + + ld a,h ;If high word not zero, set zero (info not available) + or l + ld hl,0 + ex de,hl + jr nz,.info_ssizeatapi + + ex de,hl + ld a,d + or e + jr nz,.info_ssizeatapi + ld de,512 ;If low word is zero, assume 512 bytes +.info_ssizeatapi: + ld (iy+1),e ; Set the sector size + ld (iy+2),d + ld (ix+DEVINFO.SECTSIZE),e + ld (ix+DEVINFO.SECTSIZE+1),d + + call IDE_OFF + xor a + ret + +.errorpop: + pop hl + +LUN_INFO_ERROR: + call IDE_OFF + ld a,1 + ret + + +;----------------------------------------------------------------------------- +; +; Physical format a device +; +;Input: A = Device index, 1 to 7 +; B = Logical unit number, 1 to 7 +; C = Format choice, 0 to return choice string +;Output: +; When C=0 at input: +; A = 0: Ok, address of choice string returned +; _IFORM: Invalid device or logical unit number, +; or device not formattable +; HL = Address of format choice string (in bank 0 or 3), +; only if A=0 returned. +; Zero, if only one choice is available. +; +; When C<>0 at input: +; A = 0: Ok, device formatted +; Other: error code, same as DEV_RW plus: +; _IPARM: Invalid format choice +; _IFORM: Invalid device or logical unit number, +; or device not formattable +; B = Media ID if the device is a floppy disk, zero otherwise +; (only if A=0 is returned) +; +; Media IDs are: +; F0h: 3.5" Double Sided, 80 tracks per side, 18 sectors per track (1.44MB) +; F8h: 3.5" Single sided, 80 tracks per side, 9 sectors per track (360K) +; F9h: 3.5" Double sided, 80 tracks per side, 9 sectors per track (720K) +; FAh: 5.25" Single sided, 80 tracks per side, 8 sectors per track (320K) +; FBh: 3.5" Double sided, 80 tracks per side, 8 sectors per track (640K) +; FCh: 5.25" Single sided, 40 tracks per side, 9 sectors per track (180K) +; FDh: 5.25" Double sided, 40 tracks per side, 9 sectors per track (360K) +; FEh: 5.25" Single sided, 40 tracks per side, 8 sectors per track (160K) +; FFh: 5.25" Double sided, 40 tracks per side, 8 sectors per track (320K) + +DEV_FORMAT: + ld a,_IFORM + ret + + +;----------------------------------------------------------------------------- +; +; Execute direct command on a device +; +;Input: A = Device number, 1 to 7 +; B = Logical unit number, 1 to 7 (if applicable) +; HL = Address of input buffer +; DE = Address of output buffer, 0 if not necessary +;Output: Output buffer appropriately filled (if applicable) +; A = Error code: +; 0: Ok +; 1: Invalid device number or logical unit number, +; or device not ready +; 2: Invalid or unknown command +; 3: Insufficient output buffer space +; 4-15: Reserved +; 16-255: Device specific error codes +; +; The first two bytes of the input and output buffers must contain the size +; of the buffer, not incuding the size bytes themselves. +; For example, if 16 bytes are needed for a buffer, then 18 bytes must +; be allocated, and the first two bytes of the buffer must be 16, 0. + +DEV_CMD: + ld a,2 + ret + +;===== +;===== END of DEVICE-BASED specific routines +;===== + + +;======================= +; Subroutines +;======================= + +;----------------------------------------------------------------------------- +; +; Enable or disable the IDE registers + +;Note that bank 7 (the driver code bank) must be kept switched + +IDE_ON: + ld a,1+7*32 + ld (IDE_BANK),a + ret + +IDE_OFF: + ld a,7*32 + ld (IDE_BANK),a + ret + +;----------------------------------------------------------------------------- +; Wait the BSY flag to clear +; Note: This version has a short timeout and is intended for the normal r/w +; operations. It's not adequate to be used for slower commands like soft-reset +; or DIAGNOSTICS. +; +; Input: Nothing +; Output: Cy=1 if timeout +; A = Contents of the status register + +WAIT_BSY: + out (#E6),a ; Reset System-timer + in a,(#E7) + or a ; Is the timer present? + jr z,.hasTimer + + push bc + ld bc,#0090 ; 256 fast retries, 48 slow retries +.wait1: + ld a,(IDE_STATUS) + and M_BSY ; Still busy? + jr z,.end ; No, skip + ex (sp),hl + ex (sp),hl + djnz .wait1 ; fast retry + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + dec c + jr nz,.wait1 ; slow retry + scf ; Timeout: quit with Cy=on +.end: pop bc + ret + +.hasTimer: + push bc + ld b,1*4 ; 1s +.twait1: + ld a,(IDE_STATUS) + and M_BSY + jr z,.tend ; Yes, quit + in a,(#E7) + cp 250 ; 250ms + jr c,.twait1 + out (#E6),a ; Reset the timer again + djnz .twait1 + scf ; Timeout: quit with Cy=on +.tend: + ld a,(IDE_STATUS) ; Clear the INTRQ + pop bc + ret + + + + + +;----------------------------------------------------------------------------- +; Wait the BSY flag to clear and RDY flag to be set +; if we wait for more than 30s, send a soft reset to IDE BUS +; if the soft reset didn't work after 30s return with error +; +; Input: Nothing +; Output: Cy=1 if timeout after soft reset +; A = Contents of the status register + +WAIT_DRDY: + out (#E6),a ; Reset System-timer + in a,(#E7) + or a ; Is the timer present? + jr z,.hasTimer + + push bc + ld bc,#0000 ; 256 fast retries, 256 slow retries +.wait1: ld a,(IDE_STATUS) + and M_BSY+M_DRDY + cp M_DRDY ; BSY=0 and DRDY=1? + jr z,.end ; Yes, quit + ex (sp),hl + ex (sp),hl + djnz .wait1 ; fast retry + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + dec c + jr nz,.wait1 ; slow retry + scf +.end: pop bc + ld a,(IDE_STATUS) ; Clear the INTRQ + ret + +.hasTimer: + push bc + ld b,10*4 ; 10s +.twait1: + ld a,(IDE_STATUS) + and M_BSY+M_DRDY + cp M_DRDY ; BSY=0 and DRDY=1? + jr z,.tend ; Yes, quit + in a,(#E7) + cp 250 ; 250ms + jr c,.twait1 + out (#E6),a ; Reset the timer again + djnz .twait1 + scf ; Timeout: quit with Cy=on +.tend: ld a,(IDE_STATUS) + pop bc + ret + +;----------------------------------------------------------------------------- +;--- Check for device fault or error +; Output: Cy=on and A=_DISK on fault + +CHK_RW_FAULT: + call WAIT_BSY ; wait until the flags are valid +; jr c,.error ; quit on timeout + ret c ; quit on timeout + + ld a,(IDE_STATUS) + and M_DF+M_ERR ; Device fault or error? + ret z ; No, quit wit Cy off +;.error: +; call IDE_OFF +; ld a,_DISK +; ld b,0 + scf + ret + +;----------------------------------------------------------------------------- +; Check for ERROR +; +CHK_ERR: + call WAIT_BSY ; wait until the flags are valid + ret c + bit ERR,a ; error? + ret z ; No, quit + scf + ret + + +;----------------------------------------------------------------------------- +; Execute a PIO command +; +; Input: A = Command code +; Other command registers appropriately set +; Output: Cy=1 if ERR bit in status register set +; A = Contents of the status register + +PIO_CMD: + push bc + ld c,a + call WAIT_BSY ; wait until the flags are valid + ld a,c + pop bc + ret c + ld (IDE_CMD),a + ; Must wait 400ns + nop ; 1400ns@3.57MHz + +;----------------------------------------------------------------------------- +; +WAIT_DRQ: + call WAIT_BSY ; wait until the flags are valid + ret c ; quit on timeout + + out (#E6),a ; Reset System-timer + in a,(#E7) + or a ; Is the timer present? + jr z,.hasTimer + + push bc + ld bc,#0090 ; 256 fast retries, 144 slow retries +.wait1: ld a,(IDE_STATUS) + rrca ; ERR=1? + jr c,.end2 ; Yes, abort with error + and (M_DRQ>>1) ; DRQ=1? + jr nz,.end ; Yes, quit + ex (sp),hl + ex (sp),hl + djnz .wait1 ; fast retry + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + ex (sp),hl + dec c + jr nz,.wait1 ; slow retry + scf ; Cy = timeout +.end: +; ex (sp),hl ; Blind wait for the INTRQ, since +; ex (sp),hl ; this IDE interface doesn't allow +; ex (sp),hl ; us to know when the interrupt would +; ex (sp),hl ; be triggered. +.end2: pop bc + ld a,(IDE_STATUS) + ret + +.hasTimer: + push bc + ld b,5*4 ; 5s +.twait1: + ld a,(IDE_STATUS) + rrca ; error? + jr c,.tend2 ; Yes, abort with Cy=on + and (M_DRQ>>1) ; DRQ=1? + jr nz,.tend ; Yes, quit + in a,(#E7) + cp 250 ; 250ms + jr c,.twait1 + out (#E6),a ; Reset the timer again + djnz .twait1 + scf ; Timeout: quit with Cy=on + jr .tend2 +.tend: + out (#E6),a ; Reset the timer +.tblindwait: ; Blind wait for the INTRQ, since + in a,(#E6) ; this IDE interface doesn't allow + ; us to know when the interrupt would + ; be triggered. Duh! + cp 3 ; 3*4us + jr c,.tblindwait +.tend2: pop bc + ld a,(IDE_STATUS) ; Clear the INTRQ + ret + + + + + +;----------------------------------------------------------------------------- +; Select a device +; +; This operation seems to require a delay, otherwise the devices may behave +; erratically +SELDEV: + ex af,af' + call WAIT_BSY + ret c + ex af,af' + ld (IDE_HEAD),a + ; Detect the system timer + out (#E6),a + in a,(#E7) + or a + jr z,.twait1 + ex (sp),hl + ex (sp),hl + ret +.twait1: + in a,(#E6) + cp 3 ; 3*4us + jr c,.twait1 + ret + +;----------------------------------------------------------------------------- +; Disable the interrupts for the current device +; +; This operation seems to require a delay, otherwise the devices may behave +; erratically +DISDEVINT: + ld a,M_nIEN ; Disable interrupts + ld (IDE_DEVCTRL),a + ; Detect the system timer + out (#E6),a + in a,(#E7) + or a + jr z,.twait1 + ex (sp),hl + ex (sp),hl + ret +.twait1: + in a,(#E6) + cp 3 ; 3*4us + jr c,.twait1 + ret + + ld a,(IDE_STATUS) + rrca ; ERR=1? + ccf + ret nc ; Yes, quit + jp WAIT_BSY + + +;----------------------------------------------------------------------------- +; +; Do a soft reset on the IDE devices +; +; Input : none +; Output : Cy if timed out +; (INTFLG)=3 if the user pressed CTRL+STOP + +RESET_ALL: + ld a,M_DEV ; Select SLAVE + call SELDEV + call WAIT_BSY + xor a ; Select MASTER + call SELDEV + call WAIT_BSY + + call .atapirst + +.ataonly: + xor a ; Select MASTER + call SELDEV + call WAIT_BSY + + out (#E6),a + in a,(#E7) + or a ; Is the system-timer present? + jr z,.hasSystimer ; Yes, use it + +.noSystimer: + ld a,M_SRST+M_nIEN ; Do a software reset + ld (IDE_DEVCTRL),a + halt + halt ; 16.6ms (spec: 5us) + ld a,M_nIEN ; stop reset + ld (IDE_DEVCTRL),a + halt ; 16.6ms (spec: 2ms) + call WAIT_RST ; Wait for the resets to finish + ret c + halt + halt + ret + +.hasSystimer: +.twait1: + in a,(#E6) + cp 2 ; 2*4us (spec: > 5us) + jr c,.twait1 + + ld a,M_nIEN ; stop reset + ld (IDE_DEVCTRL),a + out (#E6),a +.twait2: + in a,(#E7) + cp 3 ; 3ms (spec: > 2ms) + jr c,.twait2 + call WAIT_RST ; Wait for the resets to finish + ret c + halt + halt + ret + +.atapirst: + ; Reset a slave ATAPI + ld a,M_DEV ; Select SLAVE + call SELDEV + ld a,ATAPICMD.RESET + ld (IDE_CMD),a + ; Reset a master ATAPI + xor a ; Select MASTER + call SELDEV + ld a,ATAPICMD.RESET + ld (IDE_CMD),a + ret + + +;----------------------------------------------------------------------------- +; Checks for a diagnostic error and set a warning flag accordingly +; Input : none +; Output: WRKAREA.MASTER.t321D and WRKAREA.SLAVE.t321D: +; 0=no error +; bit7=1: error. b6~b0: reported error code +; Modifies: B + + +CHKDIAG: + ld a,(ix+WRKAREA.MASTER.t321D) + inc a ; Undetected master? + scf + ret z ; Yes, quit with error + ld a,(IDE_ERROR) + ld b,a ; b=DIAG status + and #7F ; Crop the master error code + cp 1 ; Any error? + jr z,.chkslave ; No, skip +.saveerrms: ; Save the error code from the master + or #80 + ld (ix+WRKAREA.MASTER.t321D),a + bit 7,b ; Error on slave? + scf + ret z ; No, quit +.chkslave: + bit 7,b ; Error on slave? + ret z ; No, quit + ld a,M_DEV ; Select the slave + call SELDEV + ld a,(IDE_ERROR) + and #7F ; Crop the slave error code + cp 1 ; Any error? + ret z ; No, quit +.saveerrsl: ; Save the error code from the slave + or #80 + ld (ix+WRKAREA.SLAVE.t321D),a + ld a,b + cp 1 ; Any error reported? + ret z ; No, quit with Cy=off + scf ; Cy=on if there was any error + ret + +;----------------------------------------------------------------------------- +; Prints an explanation message for a diagnostic error +; Input: A=Diagnostic error + +DIAGERRPRT: + cp #FE ; Undetected master? + ld de,DIAGS_S.nomaster + jr z,.print ; Yes, print + and #7F ; Crop the error code + jr z,.print ; 0=Undetected master: print + ld b,a + dec b ; adjust for the switch case + djnz .buff + ld de,DIAGS_S.formatter ; ERR=2 + jr .print +.buff: djnz .ecc + ld de,DIAGS_S.buffer ; ERR=3 + jr .print +.ecc: djnz .mcu + ld de,DIAGS_S.ECC ; ERR=4 + jr .print +.mcu: djnz .unkn + ld de,DIAGS_S.microcontroller ; ERR=5 +.print: jp PRINT +.unkn: ld de,DIAGS_S.unknown + push af + call PRINT + pop af + call PRINTHEXBYTE + ld a,'>' + call CHPUT + ld de,CRLF_S + jr .print + +;----------------------------------------------------------------------------- +; Subroutine to read blocks of arbitrary size on the IDE +; Input: DE =Data destination +; BC =block size +; IYL=Number of blocks +READ_DATA: + call SETLDIRHLPR ; hl'=Pointer to data transfer helper +.loop: + call WAIT_DRQ + ret c + ld hl,IDE_DATA + call RUN_HLPR + dec iyl + jp nz,.loop + ret + + +;----------------------------------------------------------------------------- +; Subroutine to write blocks of arbitrary size on the IDE +; Input: HL =Data source +; BC =block size +; IYL=Number of blocks +WRITE_DATA: + call SETLDIRHLPR ; hl'=Pointer to LDIR helper in RAM +.loop: + call WAIT_DRQ + ret c + ld de,IDE_DATA + call RUN_HLPR + call CHK_RW_FAULT + ret c + dec iyl + jp nz,.loop + ret + +LDI512: ; Z80 optimized 512 byte transfer + exx + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ldi + ret + + + +;----------------------------------------------------------------------------- +; +; Print a zero-terminated string on screen +; Input: DE = String address + +PRINT: + ld a,(de) + or a + ret z + call CHPUT + inc de + jr PRINT + + +;----------------------------------------------------------------------------- +; +; Obtain the work area address for the driver or the device +; Input: A=Selects where to point inside the work area +; 0: base work area +; 1: work area for the master +; 2: work area for the slave +; Output: IX=Pointer to the selected work area +; Modifies: disables the IDE registers + +MY_GWORK: + push af + xor a + EX AF,AF' + XOR A + LD IX,GWORK + call CALBNK + pop af + push de + ld e,(ix) ; de=Pointer to the WorkAREA in RAM + ld d,(ix+1) + ld ix,0 + or a + jr z,.end + cp 1 + ld ix,WRKAREA.MASTER.BASE + jr z,.end + ld ix,WRKAREA.SLAVE.BASE +.end: add ix,de ; Point ix to the device work area + pop de + ret + +;----------------------------------------------------------------------------- +; +; Check the device index and LUN +; Input: A = device index, B = lun +; Output: Cy=0 if OK, 1 if device or LUN invalid +; IX = Work area for the device +; Modifies F, C + +CHECK_DEV_LUN: + or a ;Check device index + scf + ret z ;Return with error if devindex=0 + cp 3 + ccf + ret c ;Return with error if devindex>2 + + ld c,a ; c=device index + + + + ld a,b ; Check LUN number + cp 1 + ld a,c + scf + ret nz + + push hl + push de + call MY_GWORK + pop de + pop hl + ld c,a + ld a,(ix+DEVINFO.t321D) + and 3 + jr z,.nodev + cp 1 ; TODO: Implement CHS support + jr z,.nodev ; For now, CHS devices are unsupported + ld a,c + or a + ret + +.nodev: + ld a,c + scf + ret + + + +; ------------------------------------------------ +; Jumps to a helper routine, usually in RAM +; Input: HL': Address of the target routine +; ------------------------------------------------ +RUN_HLPR: + exx + jp (hl) + +; ------------------------------------------------ +; Setup the arbitrary block size LDIR helper to be used +; Input : BC : block size (must be >2 bytes) +; Output : HL': Address of the LDIR helper in RAM +; Modifies: AF, DE', HL' +; ------------------------------------------------ +SETLDIRHLPR: + ld a,b + or c ; Shortcut comparison. Takes advantage that + ; only 512 and 2 will have this OR bitmask + ; to save time + cp HIGH 512 ; bc=512? + exx + jr nz,.useLDIR ; No, must use LDIR then + + ; Check for a Z80 or R800 + xor a ; Clear Cy + dec a ; A=#FF + db #ED,#F9 ; mulub a,a + jr c,.useLDIR ; Always use LDIR in RAM for the R800 + + ld hl,LDI512 + exx + ret + +.useLDIR: + exx + push bc + exx + pop de ; de=block size + ld l,(ix+DEVINFO.pBASEWRK) + ld h,(ix+DEVINFO.pBASEWRK+1) + ; Set the the block size + ; *** BLKLEN must be the first data in the workArea + ld (hl),e + inc hl + ld (hl),d + ; Point to the data transfer routine + ld de,WRKAREA.LDIRHLPR-1 + add hl,de + exx ; hl'=Pointer to LDIR helper routine + ret + + + +; ------------------------------------------------ +; Initialize the Work-area +; ------------------------------------------------ +INIWORK: + ; Clear the WorkArea + push ix + pop hl + push hl + ld b,WRKAREA + xor a +.clrwork2: + ld (hl),a + inc hl + djnz .clrwork2 + + pop hl + ; Set the pointers to go back to the base of the WorkArea + ld (ix+WRKAREA.MASTER.pBASEWRK),l + ld (ix+WRKAREA.MASTER.pBASEWRK+1),h + ld (ix+WRKAREA.SLAVE.pBASEWRK),l + ld (ix+WRKAREA.SLAVE.pBASEWRK+1),h + + ; Install the data transfer helper routine in the WorkArea + ; This speeds up the LDIR speed a lot for the R800 + ld de,WRKAREA.LDIRHLPR + add hl,de + ex de,hl + ld hl,R800DATHLP + ld bc,R800DATHLP.end-R800DATHLP + ldir + + ; Point the LD BC (addr) from LDIRHLPR to BLKLEN + push ix + pop hl + ld de,WRKAREA.BLKLEN + add hl,de ; hl=pointer to BLKLEN + ld (ix+WRKAREA.LDIRHLPR+3),l + ld (ix+WRKAREA.LDIRHLPR+4),h + ret + +; ------------------------------------------------ +; R800 data transfer routine, copied to the WorkArea +; ------------------------------------------------ +R800DATHLP: + exx + ld bc,(0) ; The address will be set by INIWORK + ldir + ret +.end: + +;----------------------------------------------------------------------------- +; +; Restore screen parameters on MSX>=2 if they're not set yet +; Input : none +; Output : none +; Modifies: all +MYSETSCR: + ld a,(MSXVER) + or a ; MSX1? + jr nz,.notMSX1 ; No, skip +.MSX1: + ld a,(SCRMOD) + or a ; SCREEN0 already? + ret z ; Yes, quit + jp INITXT ; set screen0 + +.notMSX1: + ld c,$23 ; Block-2, R#3 + ld ix,REDCLK + call EXTROM + and 1 + ld b,a + ld a,(SCRMOD) + cp b + jr nz,.restore + inc c + ld ix,REDCLK + call EXTROM + ld b,a + inc c + ld ix,REDCLK + call EXTROM + add a,a + add a,a + add a,a + add a,a + or b + ld b,a + ld a,(LINLEN) + cp b + ret z +.restore: + xor a ; Don't displat the function keys + ld ix,SDFSCR + jp EXTROM + +;----------------------------------------------------------------------------- +; Prints a byte in hex +; Input : A=byte to be printed +; Modifies: C +PRINTHEXBYTE: + ld c,a + rrca + rrca + rrca + rrca + and #F + call printnibble + ld a,c + and #F + call printnibble + ret + +printnibble: + cp 10 ; <=9? + jr c,.print09 ; Yes, skip +; ld a,9 ; Limit to 1 digit + cp 15 + jr c,.printAF + ld a,#F ; Limit to 15 +.printAF: + add "A"-10 + jp CHPUT +.print09: + add "0" + jp CHPUT + +;----------------------------------------------------------------------------- +; +; Check if the STOP key was signaled on DRV_INIT +; Input : none +; Output : none +; Modifies: all + +INICHKSTOP: + ld a,(INTFLG) + cp 4 ; Was STOP pressed? + ret nz ; No, quit as fast as possible + + ; Handle STOP to pause and read messages, and ask for the copyright info + ld de,BOOTPAUSE_S + call PRINT +.wait1: ld a,7 + call SNSMAT + and $10 ; Is STOP still pressed? + jr z,.wait1 ; Wait for STOP to be released + xor a + ld (INTFLG),a ; Clear STOP flag + ld b,0 ; b=inhibit 'i' key flag +.wait2: call CHSNS + call nz,.chkikey ; Wait until a key is pressed + ld a,(INTFLG) + cp 4 ; Was STOP pressed? + jr nz,.wait2 ; No, return + xor a + ld (INTFLG),a ; Clear STOP flag + call KILBUF + ld b,30 ; Since the user is trying pause the +.wait3: halt ; boot messages, this gives him enough + ; time to react and pause the next + ; driver + ld a,(INTFLG) + cp 4 ; Was STOP pressed? + ret z ; quit so the next driver can process it + djnz .wait3 ; The user will have the impression + ; that he has a perfect timing. ;) + ret + +.chkikey: + bit 0,b ; Was the copyright message shown? + ret nz ; Yes, return + call CHGET + cp 'i' + jr z,.showcopyright + cp 'I' + ret nz +.showcopyright: + inc b ; Inhibit further presses of the i key + ld de,COPYRIGHT_S + jp PRINT + + + + + +;======================= +; Strings +;======================= + +INFO_S: + db 13,"Sunrise compatible IDE driver v",27,'J' + db VER_MAIN+$30,'.',VER_SEC+$30,'.',VER_REV+$30 +CRLF_S: db 13,10,0 +COPYRIGHT_S: + db "(c) 2009 Konamiman",13,10 + db "(c) 2014 Piter Punk",13,10 + db "(c) 2017 FRS",13,10,13,10,0 + +BOOTPAUSE_S: + db "Paused. Press to show the copyright info.",13,10,0 + +SEARCH_S: + db "Searching: ",0 + +NODEVS_S: + db "not found",13,10,0 +ABORTED_S: + db "",13,10,0 +INIT_S: + db 13,"Initializing : ",27,'J',0 +MASTER_S: + db 13,"Master device: ",27,'J',0 +SLAVE_S: + db 13,"Slave device : ",27,'J',0 + +OK_S: db "Ok",13,10,0 +ERROR_S: + db "Error!",13,10,0 + +DETECT_S: + db "detecting",0 +.unknown: db "Unknown device ",0 +.unsupported: db "Unsuppored device",0 +.oparenthesis: db " (",0 +.chs: db "CHS",0 +.lba: db "LBA",0 +.atapi: db "ATP",0 + + +DIAGS_S: +.nomaster: db "",7,13,10,0 +.formatter: db "",7,13,10,0 +.buffer: db "",7,13,10,0 +.ECC: db "",7,13,10,0 +.microcontroller: db "",7,13,10,0 +.unknown: db " + PRINTL ,%($-START)-(ADDR-ORIGIN) + org ADDR-ORIGIN + else + PRINTL ,%(ADDR-ORIGIN)-($-START) + defs (ADDR-ORIGIN)-($-START),0 + endif +endm + +ORIGIN equ 7700h + + ALIGN 7700h ; ; External Routines. ; @@ -27,10 +48,219 @@ $$DRIVE:: public DEFDPB ; - ;*** This should be compiled at 781Fh -SNSMAT equ 0141h +;----------------------------------------------------------------------------- + +;This routine is invoked in disk emulation mode prior to any disk access. +;If checks if a valid file change key is being pressed, and if so, +;reloads the emulation data file and updates the information in DVB_TABLE. +;If no suitable key is being pressed, or if change is performed ok, returns Z. +;If there is an error reading the emulation data file, returns NZ and A=Error code. + +CHGFILE: + push hl + push de + push bc + push ix + push iy + call CHGF2 + pop iy + pop ix + pop bc + pop de + pop hl + ret + +CHGF2: + ld ix,(DVB_TABLE##) + + call GETCURKEY + or a + ret z + cp 0FFh + jr nz,CHGF3 + + call CAPSON + call WAIT_KEY_RELEASE ;GRAPH pressed: wait for other keys to release... + +CHGWA2: + call GETCURKEY ;...then to be pressed again. + or a + jr z,CHGWA2 + + cp 0FFh ;User changed his mind and pressed GRAPH + jr nz,CHGF3 + + call WAIT_KEY_RELEASE + ret + +CHGF3: + ld c,a + call CAPSON + + ;--- The key with index C is pressed + + ;> Do nothing if chosen file is the same currently in use + + ld a,(ix+DSK_IDX##) + and 3Fh + cp c + call z,CAPSOFF + ret z + + ;> Read emulation data file + push bc + + ld a,(ix+EMU_DEVLUN##) ;data file dev index + 16 * LUN index + ld d,a + rrca + rrca + rrca + rrca + and 111b + ld b,a ;LUN + ld a,d + and 111b ;Device + + ld l,(ix+EMU_FSEC##) + ld h,(ix+EMU_FSEC##+1) + ld (TMP_SEC##),hl + ld l,(ix+EMU_FSEC##+2) + ld h,(ix+EMU_FSEC##+3) + ld (TMP_SEC##+2),hl + + ld iy,(0F348h-1) ;Master controller slot + ld hl,DEV_RW## + ld (BK4_ADD##),hl + ld c,b + ld b,1 + ld hl,($SECBUF##) + ld de,TMP_SEC## + or a + + push ix + ld ix,CALDRV## + call CALSLT## ;Call DEV_RW + pop ix + pop bc + call CAPSOFF + or a + ret nz + + ;> Set the new file data in work area + + ld a,(ix+DSK_IDX##) + and 11000000b ;In emulation mode flag + Russian keyboard flag + ld b,a + ld a,c + or b + ld (ix+DSK_IDX##),a + set 7,(ix+EMU_DEVLUN##) ;File changed flag + + dec a + add a,a ;Each entry is 8 bytes + add a,a + add a,a + ld l,a + ld h,0 + ld bc,24 + add hl,bc + ld de,($SECBUF##) + add hl,de ;HL = Pointer to boot file data + push ix + pop de + inc de + inc de ;DE must point to DSK_DEV in work area + ld bc,8 + ldir + + ld a,(ix+DSK_DEV##) ;set DSK_DEV and DSK_LUN as same of data file if 0 + or a + jr nz,CHGF4 + ld a,(ix+EMU_DEVLUN##) + ld b,a + and 00000111b + ld (ix+DSK_DEV##),a + ld a,b + rrca + rrca + rrca + rrca + and 00000111b + ld (ix+DSK_LUN##),a + +CHGF4: + xor a + ret + + +WAIT_KEY_RELEASE: + call GETCURKEY + or a + jr nz,WAIT_KEY_RELEASE + ret + + + ;Return in A the index of currently pressed key, 0 if none, FFh is GRAPH + ;Input: IX = Pointer to emulation data area +GETCURKEY: + ex af,af' + ld a,(ix+DSK_IDX##) + rlca + rlca + rlca + and 1 ;Russian keyboard? + ex af,af' + push ix + ld ix,SCANKEYS + xor a + call CALBNK## + pop ix + bit 6,h + ld a,0FFh + ret nz + ld c,b + ld b,(ix+DSK_COUNT##) + ld a,1 + + ;HLDEC = key statuses + ;B = Keys left to check + ;A = Current key index + ;We do an initial rotation because we want to start at key 1. +CHGLOOP: + sra c + rr e + rr d + rr l + rr h + bit 0,c + ret nz + + inc a + djnz CHGLOOP + + xor a + ret + +CAPSON: + in a,(0AAh) + and 10111111b + out (0AAh),a + ret + +CAPSOFF: + push af + in a,(0AAh) + or 01000000b + out (0AAh),a + pop af + ret + + + + + ALIGN 781Fh ;----------------------------------------------------------------------------- ; ; Null message. The address of this message can be returned by @@ -52,9 +282,9 @@ null_message: ; Calls to these addresses will be translated to calls to the DV_DIRECTx ; entry points in the driver bank. - ds 7850h-7843h ;Can't do "ds 7850h-$", the compiler complaints + ALIGN 7850h -DIRCALL:: +DIRCALL: call DO_DIRCALL call DO_DIRCALL call DO_DIRCALL @@ -82,22 +312,31 @@ DIO_ENTRY:: call IS_DVB jp nc,DIO_ENTRY_DO - ld a,(iy+2) + ld a,(iy+UD1_DI##) or a jp z,DISKERR call IS_EMU - jr nc,DIOEN_NOEMU + jp c,DIOEN_ISEMU + + ;>>> NOT in disk emulation mode + +DIOEN_NOEMU: + call HAS_PARTITION + call nz,ASSIGN_PARTITION + jp nz,POP_CONV_ERR + jr DIOEN3 ;>>> In disk emulation mode +DIOEN_ISEMU: pop af push af or a jp nz,DISKERR ;Drive number must be 0 - call CHGFILE + call CHGFILE jr z,DIOCHGFOK pop bc ld b,0 @@ -109,8 +348,8 @@ DIOCHGFOK: push hl push de ld ix,(DVB_TABLE##) - ld e,(ix+9) - ld d,(ix+10) ;DE = dsk size in sectors + ld e,(ix+DSK_SIZE##) + ld d,(ix+DSK_SIZE##+1) ;DE = dsk size in sectors pop hl push hl @@ -150,29 +389,36 @@ WVDP: call CAPSOFF ret - ;>>> NOT in disk emulation mode - -DIOEN_NOEMU: - call HAS_PARTITION - call nz,ASSIGN_PARTITION - jp nz,POP_CONV_ERR - jr DIOEN3 - DIOEN2: push af + ld iy,(DVB_TABLE) DIOEN3: + + ; In this point one of these is true: + ; + ; - We are in disk emulation mode, and IY points to the beginning + ; of the work area for emulation mode. + ; + ; - We are in normal DOS 1 mode, and IY points to the entry + ; for the drive in DVB_TABLE. + ; + ; The following code is common to both cases, that's why + ; device index, LUN index and first sector number must be stored + ; at the same offset in both the DVB_TABLE entries (UD1_*) + ; and the disk emulation work area (DSK_*). + ld a,1 ld (KSLOT##),a ;KSLOT=1 -> device-based push hl - ld l,(iy+4) - ld h,(iy+5) + ld l,(iy+UD1_FSEC##) + ld h,(iy+UD1_FSEC##+1) add hl,de ld ix,TMP_SEC## ld (ix),l ;Calculate absolute sector number ld (ix+1),h - ld l,(iy+6) - ld h,(iy+7) + ld l,(iy+UD1_FSEC##+2) + ld h,(iy+UD1_FSEC##+3) ld de,0 adc hl,de ld (ix+2),l @@ -180,9 +426,9 @@ DIOEN3: pop hl ;Restore transfer address ld de,TMP_SEC## - ld c,(iy+3) ;Set LUN index - pop af ;From here Cy must be kept untouched - ld a,(iy+2) ;Set device index + ld c,(iy+UD1_LI##) ;Set LUN index + pop af ;From here Cy must be kept untouched + ld a,(iy+UD1_DI##) ;Set device index jr DIO_ENTRY_DO_2 @@ -365,233 +611,6 @@ DIO_INC_DE_DVB_END: pop hl ret -;----------------------------------------------------------------------------- - -;This routine is invoked in disk emulation mode prior to any disk access. -;If checks if a valid file change key is being pressed, and if so, -;reloads the NEXT_DSK.DAT file and updates the information in DVB_TABLE. -;If no suitable key is being pressed, or if change is performed ok, returns Z. -;If there is an error reading NEXT_DSK.DAT, returns NZ and A=Error code. - -CHGFILE: - push hl - push de - push bc - push ix - push iy - call CHGF2 - pop iy - pop ix - pop bc - pop de - pop hl - ret - -CHGF2: - ld ix,(DVB_TABLE##) - - ld a,6 ;Check GRAPH key - call SNSKEY - and 100b - jr nz,NOGRAPH - -CHGWAIT: - call CAPSON - call GETCURKEY ;GRAPH pressed: wait for other keys to release... - or a - jr nz,CHGWAIT - -CHGWA2: - call GETCURKEY ;...then to be pressed again. - or a - jr z,CHGWA2 - - jr CHGF3 - -NOGRAPH: - call GETCURKEY - or a - ret z - -CHGF3: - ld c,a - call CAPSON - - ;--- The key with index C is pressed - - ;> Do nothing if chosen file is the same currently in use - - ld a,(ix) - and 7Fh - cp c - call z,CAPSOFF - ret z - - ;> Read .DAT file - - push bc - - ld a,(ix+2) ;.DAT file dev index + 16 * LUN index - ld d,a - rrca - rrca - rrca - rrca - and 111b - ld b,a ;LUN - ld a,d - and 111b ;Device - - ld l,(ix+12) - ld h,(ix+13) - ld (TMP_SEC##),hl - ld l,(ix+14) - ld h,(ix+15) - ld (TMP_SEC##+2),hl - - ld iy,(0F348h-1) ;Master controller slot - ld hl,DEV_RW## - ld (BK4_ADD##),hl - ld c,b - ld b,1 - ld hl,($SECBUF##) - ld de,TMP_SEC## - or a - - push ix - ld ix,CALDRV## - call CALSLT## ;Call DEV_RW - pop ix - pop bc - call CAPSOFF - or a - ret nz - - ;> Set the new file data in work area - - ld a,c - ld (ix),a - set 7,(ix) - set 7,(ix+2) ;File changed flag - - dec a - add a,a ;Each entry is 8 bytes - add a,a - add a,a - ld l,a - ld h,0 - ld bc,24 - add hl,bc - ld de,($SECBUF##) - add hl,de ;HL = Pointer to boot file data - push ix - pop de - inc de - inc de - inc de - ld bc,8 - ldir - - xor a - ret - - - ;Return in A the index of currently pressed key, 0 if none - ;Input: IX = Pointer to entry in DVB_TABLE - -GETCURKEY: - ld b,(ix+11) - ld hl,CHGTBL - ld d,-1 - ld c,1 - - ;B=Number of keys left to test - ;HL=Pointer to current key in table - ;D=Last keyboard row checked - ;E=Last keyboard row value obtained - ;C=Current key number -CHGLOOP: - ld a,(hl) - inc hl - cp d - jr z,IHAVEROW - ld d,a - call SNSKEY - ld e,a -IHAVEROW: - ld a,(hl) - inc hl - and e - ld a,c - ret z - inc c - djnz CHGLOOP - - xor a ;No suitable key pressed - ret - -SNSKEY:: - push bc - ld c,a - di - in a,(0AAh) - and 0F0h - add a,c - out (0AAh),a - ei - in a,(0A9h) - pop bc - ret - -CHGTBL: - db 0,2 ;1 - db 0,4 ;2 - db 0,8 ;3 - db 0,16 ;4 - db 0,32 ;5 - db 0,64 ;6 - db 0,128 ;7 - db 1,1 ;8 - db 1,2 ;9 - db 2,64 ;A - db 2,128 ;B - db 3,1 ;C - db 3,2 ;D - db 3,4 ;E - db 3,8 ;F - db 3,16 ;G - db 3,32 ;H - db 3,64 ;I - db 3,128 ;J - db 4,1 ;K - db 4,2 ;L - db 4,4 ;M - db 4,8 ;N - db 4,16 ;O - db 4,32 ;P - db 4,64 ;Q - db 4,128 ;R - db 5,1 ;S - db 5,2 ;T - db 5,4 ;U - db 5,8 ;V - db 5,16 ;W - -CAPSON: - in a,(0AAh) - and 10111111b - out (0AAh),a - ret - -CAPSOFF: - push af - in a,(0AAh) - or 01000000b - out (0AAh),a - pop af - ret - - ;----------------------------------------------------------------------------- ; ; General disk routines entry @@ -604,7 +623,7 @@ CHG_ENTRY:: jp nc,DO_CALBNK ld d,a - ld a,(iy+2) + ld a,(iy+UD1_DI##) or a jp z,DISKERR @@ -622,8 +641,8 @@ CHG_ENTRY:: xor a ld ix,(DVB_TABLE##) - bit 7,(ix+2) - res 7,(ix+2) + bit 7,(ix+EMU_DEVLUN##) + res 7,(ix+EMU_DEVLUN##) ld b,1 ret z ld a,d @@ -636,9 +655,9 @@ CHGEN_NOEMU: ;Drive-based mapping: ;Return "changed" if partition has changed, "unchanged" otherwise - ld a,(iy+1) + ld a,(iy+UD1_REL##) ld c,a - res 7,(iy+1) + res 7,(iy+UD1_REL##) and 10000000b ;Check partition changed flag ld b,-1 ld a,c @@ -676,17 +695,17 @@ DO_MKDPB: DPBEN2: push hl - ld a,(iy+4) + ld a,(iy+UD1_FSEC##) ld (TMP_SEC##),a - ld a,(iy+5) + ld a,(iy+UD1_FSEC##+1) ld (TMP_SEC##+1),a - ld a,(iy+6) + ld a,(iy+UD1_FSEC##+2) ld (TMP_SEC##+2),a - ld a,(iy+7) + ld a,(iy+UD1_FSEC##+3) ld (TMP_SEC##+3),a - ld a,(iy+2) + ld a,(iy+UD1_DI##) ld b,1 - ld c,(iy+3) + ld c,(iy+UD1_LI##) ld de,TMP_SEC## ld hl,($SECBUF##) or a @@ -815,13 +834,13 @@ IS_DVB_NOEMU: IS_DVB_LOOP: push bc ld a,(KSLOT##) - ld b,(iy) + ld b,(iy+UD1_SLOT##) res 6,b cp b pop bc jr nz,DIO_NEXT - ld a,(iy+1) + ld a,(iy+UD1_REL##) and 01111111b ;Ignore partition changed flag cp c jr nz,DIO_NEXT @@ -870,10 +889,10 @@ IS_EMU: ; Return A=0, Z if partition assigned; A<>0, NZ if NO partition assigned. HAS_PARTITION: - ld a,(iy+4) ;No partition assigned - and (iy+5) ;if sector number is -1 - and (iy+6) - and (iy+7) + ld a,(iy+UD1_FSEC##) ;No partition assigned + and (iy+UD1_FSEC##+1) ;if sector number is -1 + and (iy+UD1_FSEC##+2) + and (iy+UD1_FSEC##+3) inc a jr z,RET_NZ xor a @@ -908,7 +927,8 @@ ASSIGN_PARTITION: ld b,(iy+UD1_DI##) ld c,(iy+UD1_LI##) - ld a,4 + ld a,4 + ld d,0 ld ix,AUTO_ASPART## call CALBNK## @@ -933,9 +953,9 @@ READ_BOOT: ld de,0 ld (TMP_SEC##),de ld (TMP_SEC##+2),de - ld a,(iy+2) + ld a,(iy+UD1_DI##) ld b,1 - ld c,(iy+3) + ld c,(iy+UD1_LI##) ld de,TMP_SEC## ld hl,($SECBUF##) or a @@ -1016,6 +1036,10 @@ DEFDPB: DB 3 DW 7 ; + + ALIGN 7BD0h + ;Here goes the 1K free area at the end of banks 0 and 3 + finish ; end diff --git a/source/kernel/kvar.mac b/source/kernel/kvar.mac index 7d6f10c8..18f37282 100644 --- a/source/kernel/kvar.mac +++ b/source/kernel/kvar.mac @@ -225,6 +225,10 @@ size macro name ;***************************************************************************** ; Entry in the device-based drives table (pointed by DVB_TABLE) in MSX-DOS 1 mode +; +; The table consists of one byte with the number of entries, followed by +; the entries themselves. +; ; WARNING: UD1_SLOT needs to be at the same position as UD_SLOT ifield 0 ;Start at offset zero @@ -238,6 +242,50 @@ size macro name size UD1_SZ ;Total size of unit descriptor +;----------------------------------------------------------------------------- +; +; Work area for the disk emulation mode (pointed by DVB_TABLE) +; +; Bit 7 of DSK_IDX is kept set to indicate that we are in disk emulation mode +; (if reset, it's the count of entries for the device-based drives table +; in normal DOS 1 mode, see UD1_*) +; +; Bit 6 of DSK_IDX is set if we have a Russian keyboard +; +; Bit 7 of EMU_DEVLUN is set after the current image file is changed +; and reset again when disk change is checked. +; +; WARNING: DSK_DEV, DSK_LUN and DSK_FSEC must have the same offset +; as the DI_* equivalents; this is required by DIO_ENTRY in drv.mac. + + ifield 0 ;Start at offset zero + + field 1,DSK_IDX ;Index of current disk image file + field 1,EMU_DEVLUN ;Device + 16 * LUN of emulation data mode + field 1,DSK_DEV ;Device index of current disk image file + field 1,DSK_LUN ;LUN index of current disk image file + field 4,DSK_FSEC ;First sector of current disk image file + field 2,DSK_SIZE ;Size of current disk image file in sectors + field 1,DSK_COUNT ;Number of emulated disk images + field 4,EMU_FSEC ;Sector number of the emulation data file + + size EMU_SZ ;Total size of unit descriptor + +;----------------------------------------------------------------------------- + + ;Temporary work area used at boot time + + const BOOT_TMP,0F980h + + ifield BOOT_TMP + + field EMU_SZ,EMU_TMP ;Temporary location of work area used when setting up disk emulation mode + field 1,IN_EMU ;Set to 1 when disk emulation mode has been entered + field 2,EMU_WK_AREA ;Address of work area as read from the emulation data file + ;NOTE! BOOTKEYS is used in dos1ker.mac, it must be manually updated if it changes + field 5,BOOTKEYS ;To store the state of boot keys + field 1,I_AM_RUSSIAN + field 1,HAVE_KEYS ; ;----------------------------------------------------------------------------- ; diff --git a/source/tools/.gitignore b/source/tools/.gitignore new file mode 100644 index 00000000..ec0e4206 --- /dev/null +++ b/source/tools/.gitignore @@ -0,0 +1,3 @@ +*.com +*.inc +*.COM \ No newline at end of file diff --git a/source/tools/C/.gitignore b/source/tools/C/.gitignore new file mode 100644 index 00000000..a26982a0 --- /dev/null +++ b/source/tools/C/.gitignore @@ -0,0 +1,3 @@ +*.asm +!crt0*.asm +*.com diff --git a/source/kernel/bank5/AsmCall.c b/source/tools/C/AsmCall.c similarity index 69% rename from source/kernel/bank5/AsmCall.c rename to source/tools/C/AsmCall.c index 423c8bc7..49c296bd 100644 --- a/source/kernel/bank5/AsmCall.c +++ b/source/tools/C/AsmCall.c @@ -1,43 +1,18 @@ -#include "asm.h" #include "asmcall.h" //The following is required in the main program: //byte ASMRUT[4]; //byte OUT_FLAGS; //Z80_registers regs; +// +//Also the following initialization is required: +//ASMRUT[0] = 0xC3; -void DriverCall(byte slot, uint routineAddress) +void DosCall(byte function, Z80_registers* regs, register_usage inRegistersDetail, register_usage outRegistersDetail) { - byte registerData[8]; - int i; - - memcpy(registerData, ®s, 8); - - regs.Bytes.A = slot; - regs.Bytes.B = 0xFF; - regs.UWords.DE = routineAddress; - regs.Words.HL = (int)registerData; - - DosCall(_CDRVR, REGS_ALL); - - if(regs.Bytes.A == 0) { - regs.Words.AF = regs.Words.IX; - } -} - - -void DosCall(byte function, register_usage outRegistersDetail) -{ - regs.Bytes.C = function; - SwitchSystemBankThenCall((int)0xF37D, outRegistersDetail); -} - - -void SwitchSystemBankThenCall(int routineAddress, register_usage outRegistersDetail) -{ - *((int*)BK4_ADD) = routineAddress; - AsmCall(CALLB0, ®s, REGS_ALL, outRegistersDetail); + regs->Bytes.C = function; + AsmCall(0x0005,regs,inRegistersDetail < REGS_MAIN ? REGS_MAIN : inRegistersDetail, outRegistersDetail); } diff --git a/source/kernel/bank5/asm.h b/source/tools/C/AsmCall.h similarity index 57% rename from source/kernel/bank5/asm.h rename to source/tools/C/AsmCall.h index fe57a4c7..29c82852 100644 --- a/source/kernel/bank5/asm.h +++ b/source/tools/C/AsmCall.h @@ -1,19 +1,8 @@ -#ifndef __ASM_H -#define __ASM_H +#ifndef __ASMCALL_H +#define __ASMCALL_H #include "types.h" -#ifndef NULL -#define NULL 0 -#endif - - -/* --- Register detail levels --- */ - -// This value tells which registers to pass in/out -// to the routine invoked by AsmCall, DosCall, BiosCall -// and UnapiCall. - typedef enum { REGS_NONE = 0, //No registers at all REGS_AF = 1, //AF only @@ -21,14 +10,6 @@ typedef enum { REGS_ALL = 3 //AF, BC, DE, HL, IX, IY } register_usage; - -/* --- Structure representing the Z80 registers --- - Registers can be accesses as: - Signed or unsigned words (ex: regs.Words.HL, regs.UWords.HL) - Bytes (ex: regs.Bytes.A) - Flags (ex: regs.Flags.Z) - */ - typedef union { struct { byte F; @@ -72,4 +53,10 @@ typedef union { } Flags; } Z80_registers; -#endif + +#define AsmCall(dir, regs, in, out) AsmCallAlt(dir, regs, in, out, 0) + +void DosCall(byte function, Z80_registers* regs, register_usage inRegistersDetail, register_usage outRegistersDetail); +void AsmCallAlt(uint address, Z80_registers* regs, register_usage inRegistersDetail, register_usage outRegistersDetail, int alternateAf); + +#endif //__ASMCALL_H \ No newline at end of file diff --git a/source/tools/C/asm.h b/source/tools/C/asm.h index daed18db..58965ae7 100644 --- a/source/tools/C/asm.h +++ b/source/tools/C/asm.h @@ -1,13 +1,7 @@ #ifndef __ASM_H #define __ASM_H -#ifndef uint -typedef unsigned int uint; -#endif - -#ifndef byte -typedef unsigned char byte; -#endif +#include "types.h" #ifndef NULL #define NULL 0 diff --git a/source/tools/C/compemu.bat b/source/tools/C/compemu.bat index e932865d..4a78c809 100644 --- a/source/tools/C/compemu.bat +++ b/source/tools/C/compemu.bat @@ -1,6 +1,6 @@ @echo off cls -sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --no-std-crt0 crt0msx_msxdos_advanced.rel msxchar.lib asm.lib emufile.c +sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --disable-warning 85 --no-std-crt0 crt0msx_msxdos_advanced.rel emufile.c if errorlevel 1 goto :end hex2bin -e com emufile.ihx copy emufile.com ..\..\..\bin\tools\ diff --git a/source/tools/C/compnexboot.bat b/source/tools/C/compnexboot.bat new file mode 100644 index 00000000..782e03e1 --- /dev/null +++ b/source/tools/C/compnexboot.bat @@ -0,0 +1,7 @@ +@echo off +cls +sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --disable-warning 85 --no-std-crt0 crt0msx_msxdos_advanced.rel nexboot.c +if errorlevel 1 goto :end +hex2bin -e com nexboot.ihx +copy nexboot.com ..\..\..\bin\tools\ +:end diff --git a/source/kernel/bank5/dos.h b/source/tools/C/dos.h similarity index 53% rename from source/kernel/bank5/dos.h rename to source/tools/C/dos.h index c6e50405..6e1c27b0 100644 --- a/source/kernel/bank5/dos.h +++ b/source/tools/C/dos.h @@ -10,7 +10,20 @@ #define MAX_INFO_LENGTH 64 -/* MSX-DOS data structures */ +/* MSX-DOS/Nextor data structures */ + +typedef struct { + byte alwaysFF; + char filename[13]; + byte attributes; + byte timeOfModification[2]; + byte dateOfModification[2]; + unsigned int startCluster; + unsigned long fileSize; + byte logicalDrive; + byte internal[38]; +} fileInfoBlock; + #define DRIVER_IS_DOS250 (1 << 7) #define DRIVER_IS_DEVICE_BASED 1 @@ -34,6 +47,19 @@ typedef struct { char deviceName[MAX_INFO_LENGTH]; } deviceInfo; +#define DRIVE_STATUS_ASSIGNED_TO_DEVICE 1 + + +typedef struct { + byte driveStatus; + byte driverSlotNumber; + byte driverSegmentNumber; + byte relativeDriveNumber; + byte deviceIndex; + byte logicalUnitNumber; + ulong firstSectorNumber; + byte reserved[64 - 10]; +} driveLetterInfo; #define BLOCK_DEVICE 0 #define READ_ONLY_LUN (1 << 1) @@ -47,23 +73,36 @@ typedef struct { uint cylinders; byte heads; byte sectorsPerTrack; - bool suitableForPartitionning; + bool suitableForPartitioning; } lunInfo; /* MSX-DOS functions */ +#define _TERM0 0 #define _DIRIO 0x06 #define _BUFIN 0x0A +#define _DPARM 0x31 +#define _FFIRST 0x40 +#define _FNEXT 0x41 +#define _OPEN 0x43 +#define _CREATE 0x44 +#define _CLOSE 0x45 +#define _READ 0x48 +#define _WRITE 0x49 +#define _PARSE 0x5B +#define _TERM 0x62 #define _EXPLAIN 0x66 +#define _DOSVER 0x6F #define _GDRVR 0x78 #define _GPART 0x7A #define _CDRVR 0x7B - +#define _GDLI 0x79 /* MSX-DOS error codes */ #define _IPART 0xB4 +#define _NOFIL 0xD7 /* Disk driver routines */ @@ -75,7 +114,7 @@ typedef struct { #define LUN_INFO 0x4169 -#define BK4_ADD 0xF84C +#define BK4_ADD 0xF1D0 #endif //__DOS_H \ No newline at end of file diff --git a/source/tools/C/emufile.c b/source/tools/C/emufile.c index 0d80eb39..5004ae2c 100644 --- a/source/tools/C/emufile.c +++ b/source/tools/C/emufile.c @@ -1,21 +1,12 @@ -/* DSK emulation configuration file creation tool for Nextor v1.0 - By Konamiman 2/2015 +/* DSK emulation configuration file creation tool for Nextor v1.1 + By Konamiman 3/2019 Compilation command line: sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel - asm.lib emufile.c + emufile.c hex2bin -e com emufile.ihx - - ASM.LIB, MSXCHAR.LIB and crt0msx_msxdos_advanced.rel - are available at www.konamiman.com - - (You don't need MSXCHAR.LIB if you manage to put proper PUTCHAR.REL, - GETCHAR.REL and PRINTF.REL in the standard Z80.LIB... I couldn't manage to - do it, I get a "Library not created with SDCCLIB" error) - - Comments are welcome: konamiman@konamiman.com */ /* Includes */ @@ -24,28 +15,15 @@ #include #include #include -#include - -//These are available at www.konamiman.com -#include "asm.h" +#include "types.h" +#include "system.h" +#include "dos.h" +#include "partit.h" +#include "asmcall.h" +#include "strcmpi.h" /* Typedefs */ -typedef unsigned char bool; -typedef unsigned long ulong; - -typedef struct { - byte alwaysFF; - char filename[13]; - byte attributes; - byte timeOfModification[2]; - byte dateOfModification[2]; - unsigned int startCluster; - unsigned long fileSize; - byte logicalDrive; - byte internal[38]; -} FileInfoBlock; - typedef struct { char signature[16]; byte numberOfEntriesInImagesTable; @@ -70,74 +48,90 @@ typedef struct { #define IS_NEXTOR (1 << 7) #define IS_DEVICE_BASED (1) +#define PARSE_FLAG_HAS_FILENAME (1 << 3) +#define PARSE_FLAG_HAS_EXTENSION (1 << 4) +#define PARSE_FLAG_IS_AMBIGUOUS (1 << 5) + #define MallocBase 0x8000 #define MaxFilesToProcess 32 -#define CALSLT 0x001C -#define EXPTBL 0xFCC1 +#define SetupRAMAddress ((byte*)0xA000) -#define _TERM0 0 -#define _DPARM 0x31 -#define _FFIRST 0x40 -#define _FNEXT 0x41 -#define _OPEN 0x43 -#define _CREATE 0x44 -#define _CLOSE 0x45 -#define _WRITE 0x49 -#define _TERM 0x62 -#define _DOSVER 0x6F -#define _GDRVR 0x78 -#define _GDLI 0x79 - -#define _NOFIL 0xD7 /* Strings */ const char* strTitle= - "DSK Emulation Configuration File Creation Tool for Nextor v1.0\r\n" - "By Konamiman, 2/2015\r\n" + "Disk image emulation tool for Nextor v1.1\r\n" + "By Konamiman, 3/2019\r\n" "\r\n"; const char* strUsage= - "Usage: emufile [] [ ...]\r\n" + "Usage: emufile [] [ ...]\r\n" + " emufile set [o|p[[]]]\r\n" + " emufile ?\r\n"; + +const char* strHelp= + "* To create an emulation data file:\r\n" "\r\n" - ": Disk image files to emulate. Can contain wildcards.\r\n" + "emufile [] [ ...]\r\n" + "\r\n" + ": Path and name of emulation data file to create.\r\n" + " Default extension is .EMU\r\n" "\r\n" ":\r\n" "\r\n" - "- o : Path and name of the generated configuration file.\r\n" - " Default is \"\\NEXT_DSK.DAT\"\r\n" - " If it ends with \"\\\" or \":\", file name will be \"NEXT_DSK.DAT\".\r\n" - "- b : The index of the image file to mount at boot time.\r\n" - " Must be 1-9 or A-W. Default is 1.\r\n" - "- a
: Page 3 address for the 16 byte work area.\r\n" - " Must be a hexadecimal number between C000 and FFEF.\r\n" - " If missing or 0, the work area is allocated at boot time.\r\n" - "- r : Reset the computer after generating the file.\r\n" - "- p : Print filenames and associated keys.\r\n" + "-b : The index of the image file to mount at boot time.\r\n" + " Must be 1-9 or A-W. Default is 1.\r\n" + "-a
: Page 3 address for the 16 byte work area.\r\n" + " Must be a hexadecimal number between C000 and FFEF.\r\n" + " If missing or 0, the work area is allocated at boot time.\r\n" + "-p : Print filenames and associated keys after creating the data file.\r\n" + "\r\n" + "TYPE /B the generated file to see the names of the registered files.\r\n" + "\r\n" + "\r\n" + "* To setup an existing emulation data file for booting:\r\n" + "\r\n" + "emufile set [o|p[[]]]\r\n" "\r\n" - "TYPE /B the generated file to see the names of the registered files.\r\n"; + "o: one-time emulation (store emulation data file pointer in RAM).\r\n" + "This is the default if only is specified.\r\n" + "\r\n" + "p: persistent emulation (store emulation data file pointer in partition table).\r\n" + "Use and to specify the device whose\r\n" + "partition table will be written. Default device (if only 'p' is specified)\r\n" + "is the device where the emulation data file is located.\r\n" + "Default (if only 'p' is specified) is 1.\r\n" + "\r\n" + "The computer will reset after successfully finishing the setup.\r\n"; const char* strInvParam = "Invalid parameter"; const char* strCRLF = "\r\n"; +const char* emuDataSignature = "NEXTOR_EMU_DATA"; + /* Global variables */ Z80_registers regs; +byte ASMRUT[4]; +byte OUT_FLAGS; void* mallocPointer; char* outputFileName; int bootFileIndex; -bool autoReset; bool printFilenames; uint workAreaAddress; -FileInfoBlock* fib; +fileInfoBlock* fib; int totalFilesProcessed; -byte* driveInfo; +driveLetterInfo* driveInfo; byte* driveParameters; byte* fileContentsBase; byte* fileNamesBase; byte* fileNamesAppendAddress; +byte fileHandle; +int setupPartitionDeviceIndex; +int setupPartitionLunIndex; +bool setupAsPersistent; /* Some handy code defines */ @@ -150,7 +144,9 @@ byte* fileNamesAppendAddress; void CheckPreconditions(); void CheckPrimaryControllerIsNextor(); void Initialize(); -void ProcessArguments(char** argv, int argc); +bool ProcessArguments(char** argv, int argc); +void ProcessCreateFileArguments(char** argv, int argc); +void ProcessSetupFileArguments(char** argv, int argc); int ProcessOption(char optionLetter, char* optionValue); void ProcessFilename(char* fileName); void TooManyFiles(); @@ -158,17 +154,15 @@ void StartSearchingFiles(char* fileName); void ProcessFileFound(); void GetDriveInfoForFileInFib(); void CheckControllerForFileInFib(); -ulong GetFirstDriveSectorForFileInFib(); ulong GetFirstFileSectorForFileInFib(); void AddFileInFibToFilesTable(ulong sector); +void SetDeviceIndexesOfFilesTableToZeroIfAllInSameDeviceAsDataFile(); void AddFileInFibToFilenamesInfo(); void GenerateFile(); -void ProcessOutputFileOption(char* optionValue); +void AddFileExtension(char* fileName); void ProcessBootIndexOption(char* optionValue); void ProcessWorkAreaAddressOption(char* optionValue); -void ProcessResetOption(); void ProcessPrintFilenamesOption(); - void Terminate(const char* errorMessage); void TerminateWithDosError(byte errorCode); void print(char* s); @@ -176,26 +170,39 @@ void CheckDosVersion(); void* malloc(int size); uint ParseHex(char* hexString); void DoDosCall(byte functionCode); +void SetupFile(); +void DriverCall(byte slot, uint routineAddress); +byte DeviceSectorRW(byte driverSlot, byte deviceIndex, byte lunIndex, ulong sectorNumber, byte* buffer, bool write); +void VerifyDataFileSignature(byte* sectorBuffer); void ResetComputer(); +#define ReadDeviceSector(driverSlot, deviceIndex, lunIndex, sectorNumber, buffer) DeviceSectorRW(driverSlot, deviceIndex, lunIndex, sectorNumber, buffer, false) +#define WriteDeviceSector(driverSlot, deviceIndex, lunIndex, sectorNumber, buffer) DeviceSectorRW(driverSlot, deviceIndex, lunIndex, sectorNumber, buffer, true) + /* MAIN */ int main(char** argv, int argc) { + bool isSetupFile; + + ASMRUT[0] = 0xC3; print(strTitle); - + CheckPreconditions(); Initialize(); - ProcessArguments(argv, argc); + isSetupFile = ProcessArguments(argv, argc); + + if(isSetupFile) { + SetupFile(); + printf("Done. Resetting computer..."); + ResetComputer(); + } if(totalFilesProcessed > 0) { + SetDeviceIndexesOfFilesTableToZeroIfAllInSameDeviceAsDataFile(); GenerateFile(); printf( "%s%s successfully generated!\r\n%i disk image file(s) registered\r\n", printFilenames ? "\r\n" : "", outputFileName, totalFilesProcessed); - if(autoReset) { - print("Resetting computer..."); - ResetComputer(); - } } else { print(strUsage); } @@ -234,10 +241,10 @@ void Initialize() mallocPointer = (void*)MallocBase; outputFileName = malloc(128); - strcpy(outputFileName, "\\NEXT_DSK.DAT"); + *outputFileName = (char)0; - fib = malloc(sizeof(FileInfoBlock)); - driveInfo = malloc(64); + fib = malloc(sizeof(fileInfoBlock)); + driveInfo = malloc(sizeof(driveLetterInfo)); driveParameters = malloc(32); fileContentsBase = malloc( sizeof(GeneratedFileHeader) + @@ -245,44 +252,122 @@ void Initialize() fileNamesBase = malloc(19 * MaxFilesToProcess); fileNamesAppendAddress = fileNamesBase; + fileHandle = 0; bootFileIndex = 1; - autoReset = false; printFilenames = false; workAreaAddress = 0; totalFilesProcessed = 0; } -void ProcessArguments(char** argv, int argc) +bool ProcessArguments(char** argv, int argc) { - int i; - char* currentArg; + if(argc > 0 && argv[0][0] == '?') { + print(strHelp); + Terminate(null); + } - if(argc == 0) { + if(argc < 2) { print(strUsage); Terminate(null); } - + + if(strcmpi(argv[0], "set") == 0) { + ProcessSetupFileArguments(argv, argc); + return true; + } + + ProcessCreateFileArguments(argv, argc); + return false; +} + +void ProcessCreateFileArguments(char** argv, int argc) +{ + int i; + char* currentArg; + bool processingOptions; + + processingOptions = true; + for(i=0; i 9) { + Terminate("Invalid device index"); + } + + if(argv[2][2] == '\0') { + setupPartitionLunIndex = 1; + return; + } + + setupPartitionLunIndex = argv[2][2] - '0'; + if(setupPartitionLunIndex < 1 || setupPartitionLunIndex > 9) { + Terminate("Invalid LUN index"); + } + + if(argv[2][3] != '\0') { + InvalidParameter(); + } } int ProcessOption(char optionLetter, char* optionValue) { optionLetter |= 32; - if(optionLetter == 'o') { - ProcessOutputFileOption(optionValue); - return 1; - } - if(optionLetter == 'b') { ProcessBootIndexOption(optionValue); return 1; @@ -293,11 +378,6 @@ int ProcessOption(char optionLetter, char* optionValue) return 1; } - if(optionLetter == 'r') { - ProcessResetOption(); - return 0; - } - if(optionLetter == 'p') { ProcessPrintFilenamesOption(); return 0; @@ -307,15 +387,17 @@ int ProcessOption(char optionLetter, char* optionValue) return 0; } -void ProcessOutputFileOption(char* optionValue) +void AddFileExtension(char* fileName) { - char* lastCharPointer; - - strcpy(outputFileName, optionValue); - lastCharPointer = outputFileName + strlen(outputFileName) - 1; - if(*lastCharPointer == '\\' || *lastCharPointer == ':') { - strcpy(lastCharPointer + 1, "NEXT_DSK.DAT"); - } + strcpy(outputFileName, fileName); + + regs.Bytes.B = 0; + regs.Words.DE = (int)outputFileName; + DoDosCall(_PARSE); + + if(!(regs.Bytes.B & PARSE_FLAG_HAS_EXTENSION)) { + strcpy((char*)regs.Words.DE, ".EMU"); + } } void ProcessBootIndexOption(char* optionValue) @@ -346,11 +428,6 @@ void ProcessWorkAreaAddressOption(char* optionValue) } } -void ProcessResetOption() -{ - autoReset = true; -} - void ProcessPrintFilenamesOption() { printFilenames = true; @@ -403,8 +480,7 @@ void ProcessFileFound() return; } - sector = GetFirstDriveSectorForFileInFib(); - sector += GetFirstFileSectorForFileInFib(); + sector = driveInfo->firstSectorNumber + GetFirstFileSectorForFileInFib(); AddFileInFibToFilesTable(sector); AddFileInFibToFilenamesInfo(); @@ -425,17 +501,12 @@ void GetDriveInfoForFileInFib() void CheckControllerForFileInFib() { - if(driveInfo[0] != 1 || driveInfo[1] != PrimaryControllerSlot()) { + if(driveInfo->driveStatus != DRIVE_STATUS_ASSIGNED_TO_DEVICE || driveInfo->driverSlotNumber != PrimaryControllerSlot()) { printf("*** Drive %c: is not controlled by the primary Nextor kernel\r\n", fib->logicalDrive - 1 + 'A'); Terminate(null); } } -ulong GetFirstDriveSectorForFileInFib() -{ - return *((ulong*)(driveInfo + 6)); -} - ulong GetFirstFileSectorForFileInFib() { ulong firstDataSector; @@ -462,8 +533,8 @@ void AddFileInFibToFilesTable(ulong sector) sizeof(GeneratedFileHeader) + (sizeof(GeneratedFileTableEntry) * totalFilesProcessed)); - tableEntry->deviceIndex = *(driveInfo + 4); - tableEntry->logicalUnitNumber = *(driveInfo + 5); + tableEntry->deviceIndex = driveInfo->deviceIndex; + tableEntry->logicalUnitNumber = driveInfo->logicalUnitNumber; tableEntry->firstFileSector = sector; tableEntry->fileSizeInSector = (uint)(fib->fileSize >> 9); } @@ -480,11 +551,44 @@ void AddFileInFibToFilenamesInfo() *fileNamesAppendAddress++ = '\n'; } +void SetDeviceIndexesOfFilesTableToZeroIfAllInSameDeviceAsDataFile() +{ + GeneratedFileTableEntry* tableEntry; + int i; + + regs.Bytes.B = 0; + regs.Words.DE = (int)outputFileName; + DoDosCall(_PARSE); + regs.Bytes.A = regs.Bytes.C - 1; //drive number of the data file + regs.Words.HL = (int)driveInfo; + DoDosCall(_GDLI); + + tableEntry = (GeneratedFileTableEntry*)(fileContentsBase + sizeof(GeneratedFileHeader)); + + for(i=0; ideviceIndex != driveInfo->deviceIndex || tableEntry->logicalUnitNumber != driveInfo->logicalUnitNumber) { + return; + } + tableEntry++; + } + + tableEntry = (GeneratedFileTableEntry*)(fileContentsBase + sizeof(GeneratedFileHeader)); + + for(i=0; ideviceIndex = 0; + tableEntry->logicalUnitNumber = 0; + tableEntry++; + } +} + void GenerateFile() { GeneratedFileHeader* header; byte fileHandle; char* fileNamesHeader; + char* bootFileIndexString; if(bootFileIndex > totalFilesProcessed) { bootFileIndex = totalFilesProcessed; @@ -493,7 +597,7 @@ void GenerateFile() } header = (GeneratedFileHeader*)fileContentsBase; - strcpy(header->signature, "Nextor DSK file"); + strcpy(header->signature, emuDataSignature); header->numberOfEntriesInImagesTable = totalFilesProcessed; header->indexOfImageToMountAtBoot = bootFileIndex; header->workAreaAddress = workAreaAddress; @@ -511,7 +615,7 @@ void GenerateFile() (sizeof(GeneratedFileHeader) + (sizeof(GeneratedFileTableEntry) * totalFilesProcessed)); DoDosCall(_WRITE); - + fileNamesHeader = "\fDisk image files registered:\r\n\r\n"; regs.Bytes.B = fileHandle; regs.Words.DE = (int)fileNamesHeader; @@ -522,28 +626,155 @@ void GenerateFile() regs.Words.DE = (int)fileNamesBase; regs.Words.HL = (int)(fileNamesAppendAddress - fileNamesBase); DoDosCall(_WRITE); + + bootFileIndexString = malloc(32); + sprintf(bootFileIndexString, "\r\nBoot file index: %i\r\n", bootFileIndex); + regs.Bytes.B = fileHandle; + regs.Words.DE = (int)bootFileIndexString; + regs.Words.HL = strlen(bootFileIndexString); + DoDosCall(_WRITE); regs.Bytes.B = fileHandle; DoDosCall(_CLOSE); +} + +void SetupFile() +{ + ulong sector; + masterBootRecord* sectorBuffer; + partitionTableEntry* partition; + byte error; + + AddFileExtension(outputFileName); + StartSearchingFiles(outputFileName); + GetDriveInfoForFileInFib(); + CheckControllerForFileInFib(); + + if(fib->fileSize == 0) { + Terminate("*** The emulation data file is empty"); + } + + sectorBuffer = malloc(sizeof(masterBootRecord)); + + VerifyDataFileSignature((byte*)sectorBuffer); + + sector = driveInfo->firstSectorNumber + GetFirstFileSectorForFileInFib(); + + if(setupPartitionDeviceIndex == 0) { + setupPartitionDeviceIndex = driveInfo->deviceIndex; + setupPartitionLunIndex = driveInfo->logicalUnitNumber; + } + + sectorBuffer = malloc(sizeof(masterBootRecord)); + error = ReadDeviceSector(driveInfo->driverSlotNumber, setupPartitionDeviceIndex, setupPartitionLunIndex, 0, (byte*)sectorBuffer); + if(error != 0) { + print("*** Error when reading MBR of device:"); + TerminateWithDosError(error); + } + if(setupAsPersistent) { + partition = &(sectorBuffer->primaryPartitions[0]); + partition->status |= 1; + partition->chsOfFirstSector[0] = driveInfo->deviceIndex; + partition->chsOfFirstSector[1] = driveInfo->logicalUnitNumber; + partition->chsOfFirstSector[2] = ((byte*)§or)[3]; //MSB + partition->chsOfLastSector[0] = ((byte*)§or)[2]; + partition->chsOfLastSector[1] = ((byte*)§or)[1]; + partition->chsOfLastSector[2] = ((byte*)§or)[0]; //LSB + + error = WriteDeviceSector(driveInfo->driverSlotNumber, setupPartitionDeviceIndex, setupPartitionLunIndex, 0, (byte*)sectorBuffer); + if(error != 0) { + print("*** Error when writing MBR of device:"); + TerminateWithDosError(error); + } + } else { + strcpy(SetupRAMAddress, emuDataSignature); + SetupRAMAddress[0x10] = driveInfo->deviceIndex; + SetupRAMAddress[0x11] = driveInfo->logicalUnitNumber; + SetupRAMAddress[0x12] = ((byte*)§or)[0]; //LSB + SetupRAMAddress[0x13] = ((byte*)§or)[1]; + SetupRAMAddress[0x14] = ((byte*)§or)[2]; + SetupRAMAddress[0x15] = ((byte*)§or)[3]; //MSB + } +} + +void VerifyDataFileSignature(byte* sectorBuffer) +{ + regs.Words.DE = (int)outputFileName; + regs.Bytes.A = 1; //read-only + DoDosCall(_OPEN); + fileHandle = regs.Bytes.B; + + regs.Words.DE = (int)sectorBuffer; + regs.Words.HL = 16; + DoDosCall(_READ); + + if(regs.Words.HL < 16 || strcmpi((char*)sectorBuffer, emuDataSignature) != 0) { + Terminate("Invalid emulation data file"); + } +} + +byte DeviceSectorRW(byte driverSlot, byte deviceIndex, byte lunIndex, ulong sectorNumber, byte* buffer, bool write) +{ + regs.Flags.C = write; + regs.Bytes.A = deviceIndex; + regs.Bytes.B = 1; + regs.Bytes.C = lunIndex; + regs.Words.HL = (int)buffer; + regs.Words.DE = (int)§orNumber; + + DriverCall(driverSlot, DEV_RW); + return regs.Bytes.A; +} + +void DriverCall(byte slot, uint routineAddress) +{ + byte registerData[8]; + int i; + + memcpy(registerData, ®s, 8); + + regs.Bytes.A = slot; + regs.Bytes.B = 0xFF; + regs.UWords.DE = routineAddress; + regs.Words.HL = (int)registerData; + + DoDosCall(_CDRVR); + + regs.Words.AF = regs.Words.IX; +} + +void ResetComputer() +{ + regs.Bytes.IYh = *(byte*)EXPTBL; + regs.Words.IX = 0; + AsmCall(CALSLT, ®s, REGS_ALL, REGS_NONE); + + //Just in case, but we should never reach here + Terminate(null); } void Terminate(const char* errorMessage) { + if(fileHandle != 0) { + regs.Bytes.B = fileHandle; + DoDosCall(_CLOSE); + } + if(errorMessage != NULL) { printf("\r\x1BK*** %s\r\n", errorMessage); } regs.Bytes.B = (errorMessage == NULL ? 0 : 1); - DosCall(_TERM, ®s, REGS_MAIN, REGS_NONE); - DosCall(_TERM0, ®s, REGS_MAIN, REGS_NONE); + DoDosCall(_TERM); + DoDosCall(_TERM0); } void TerminateWithDosError(byte errorCode) { regs.Bytes.B = errorCode; - DosCall(_TERM, ®s, REGS_MAIN, REGS_NONE); + DoDosCall(_TERM); } @@ -577,7 +808,7 @@ void CheckDosVersion() { regs.Bytes.B = 0x5A; regs.Words.HL = 0x1234; - regs.Words.DE = 0xABCD; + regs.Words.DE = (int)0xABCD; regs.Words.IX = 0; DosCall(_DOSVER, ®s, REGS_ALL, REGS_ALL); @@ -625,9 +856,7 @@ void DoDosCall(byte functionCode) } } -void ResetComputer() -{ - regs.Bytes.IYh = *(byte*)EXPTBL; - regs.Words.IX = 0; - AsmCall(CALSLT, ®s, REGS_ALL, REGS_NONE); -} \ No newline at end of file +#define COM_FILE +#include "printf.c" +#include "asmcall.c" +#include "strcmpi.c" diff --git a/source/tools/C/nexboot.c b/source/tools/C/nexboot.c new file mode 100644 index 00000000..69adf1ef --- /dev/null +++ b/source/tools/C/nexboot.c @@ -0,0 +1,206 @@ +/* Nextor temporary boot keys configuration tool + By Konamiman 3/2019 + + Compilation command line: + + sdcc --code-loc 0x180 --data-loc 0 -mz80 --disable-warning 196 + --no-std-crt0 crt0_msxdos_advanced.rel msxchar.rel + nexboot.c + hex2bin -e com emufile.ihx +*/ + +#include +#include +#include +#include +#include "types.h" +#include "system.h" +#include "dos.h" +#include "asmcall.h" +#include "strcmpi.h" + +/* Defines */ + +#define false (0) +#define true (!(false)) +#define null ((void*)0) + +#define RamKeysAddress ((byte*)0xA100) + +/* Strings */ + +const char* strTitle= + "One-time boot keys configuration tool for Nextor v1.0\r\n" + "By Konamiman, 3/2019\r\n" + "\r\n"; + +const char* strUsage= + "Usage: nexboot |. [ [ ...]]\r\n" + "\r\n" + ": keys that will be considered as pressed in next boot.\r\n" + " can include the numbers 1 to 9, C (for CTRL) and S (for SHIFT)\r\n," + "or be '.' to not specify any key (if you only want to disable kernels).\r\n" + "\r\n" + "s: slot numbers of the Nextor kernels to disable in the next boot.\r\n" + "They can be followed by a subslot number, e.g. 13 for slot 1, subslot 3.\r\n" + "\r\n" + "The computer will reset after successfully setting the keys.\r\n"; + +const char* strInvParam = "Invalid parameter"; +const char* strInvSlot = "Invalid slot specification"; +const char* strCRLF = "\r\n"; + +/* Global variables */ + +Z80_registers regs; +byte ASMRUT[4]; +byte OUT_FLAGS; +byte keyFlags[5]; + +//First value: byte offset in keyFlags +//Second value: mask to set in the byte in keyFlags +byte keysBySlot[16*2] = { + 3, 0b01000000, //0-0: U + 3, 0b00000100, //1-0: Q + 1, 0b00000100, //2-0: A + 4, 0b00001000, //3-0: Z + + 2, 0b00000100, //0-1: I + 4, 0b00000001, //1-1: W + 3, 0b00010000, //2-1: S + 4, 0b00000010, //3-1: X + + 3, 0b00000001, //0-2: O + 1, 0b01000000, //1-2: E + 1, 0b00100000, //2-2: D + 1, 0b00010000, //3-2: C + + 3, 0b00000010, //0-3: P + 3, 0b00001000, //1-3: R + 1, 0b10000000, //2-3: F + 3, 0b10000000, //3-3: V +}; + +/* Function prototypes */ + +void GetSlotDisableKeys(int count, char** slots); +void GetNumericBits(char* keys); +void SetKeysInRam(); +void Terminate(const char* errorMessage); +void InvalidParameter(); +void ResetComputer(); + +/* MAIN */ + +int main(char** argv, int argc) +{ + ASMRUT[0] = 0xC3; + memset(keyFlags, 0, 5); + + printf(strTitle); + + if(argc == 0) { + printf(strUsage); + Terminate(null); + } + + if(argv[0][0] != '.') { + GetNumericBits(argv[0]); + } + + if(argc > 1) { + GetSlotDisableKeys(argc-1, argv+1); + } + + SetKeysInRam(); + + printf("Done. Resetting computer..."); + ResetComputer(); + + return 0; +} + +void GetNumericBits(char* keys) +{ + byte keysCount; + byte currentKey; + byte i; + + keysCount = strlen(keys); + for(i=0; i= '1' && currentKey <= '7') { + keyFlags[0] |= (1 << currentKey-'0'); + } + else if(currentKey == '8' || currentKey == '9') { + keyFlags[1] |= (1 << currentKey-'8'); + } + else if(currentKey == 's') { + keyFlags[4] |= 0x10; + } + else if(currentKey == 'c') { + keyFlags[4] |= 0x20; + } + else { + Terminate("Invalid key specification"); + } + } +} + +void GetSlotDisableKeys(int count, char** slots) +{ + int i; + char* slot; + byte slotNumber; + + for(i=0; i '3') { + Terminate(strInvSlot); + } + + slotNumber = slot[0] - '0'; + + if(slot[1] != '\0') { + if(slot[1] < '0' || slot[1] > '3') { + Terminate(strInvSlot); + } + + slotNumber |= (slot[1] - '0') << 2; + } + + keyFlags[keysBySlot[slotNumber*2]] |= keysBySlot[(slotNumber*2)+1]; + } +} + +void SetKeysInRam() +{ + strcpy(RamKeysAddress, "NEXTOR_BOOT_KEYS"); + memcpy(RamKeysAddress+0x11, keyFlags, 5); +} + +void Terminate(const char* errorMessage) +{ + if(errorMessage != NULL) { + printf("\r\x1BK*** %s\r\n", errorMessage); + } + + regs.Bytes.B = (errorMessage == NULL ? 0 : 1); + DosCall(_TERM, ®s, REGS_MAIN, REGS_NONE); + DosCall(_TERM0, ®s, REGS_MAIN, REGS_NONE); +} + +void ResetComputer() +{ + regs.Bytes.IYh = *(byte*)EXPTBL; + regs.Words.IX = 0; + AsmCall(CALSLT, ®s, REGS_ALL, REGS_NONE); + + //Just in case, but we should never reach here + Terminate(null); +} + +#define COM_FILE +#include "printf.c" +#include "asmcall.c" diff --git a/source/kernel/bank5/partit.h b/source/tools/C/partit.h similarity index 93% rename from source/kernel/bank5/partit.h rename to source/tools/C/partit.h index ca8019f0..774cdf54 100644 --- a/source/kernel/bank5/partit.h +++ b/source/tools/C/partit.h @@ -1,7 +1,7 @@ #ifndef __PARTIT_H #define __PARTIT_H -#include "types.h" +#include "../../tools/C/types.h" #define MAX_PARTITIONS_TO_HANDLE 256 #define MIN_DEVICE_SIZE_IN_K 10 @@ -40,6 +40,7 @@ typedef struct { byte primaryIndex; byte extendedIndex; byte partitionType; + byte status; ulong sizeInK; uint alignmentPaddingInSectors; } partitionInfo; diff --git a/source/kernel/bank5/printf.c b/source/tools/C/printf.c similarity index 92% rename from source/kernel/bank5/printf.c rename to source/tools/C/printf.c index d788d184..31c38094 100644 --- a/source/kernel/bank5/printf.c +++ b/source/tools/C/printf.c @@ -29,6 +29,8 @@ #include #include "system.h" +#define CONOUT 2 + #ifdef SUPPORT_LONG extern void _ultoa(long val, char* buffer, char base); extern void _ltoa(long val, char* buffer, char base); @@ -67,10 +69,15 @@ static void do_char(const char* buf, char c) __naked ld h,a or l +#ifdef COM_FILE + ld c,#CONOUT + jp z,5 +#else ld a,e jp z,CHPUT +#endif - ld(hl),e + ld (hl),e ret __endasm; diff --git a/source/tools/C/strcmpi.c b/source/tools/C/strcmpi.c new file mode 100644 index 00000000..26c0e8b0 --- /dev/null +++ b/source/tools/C/strcmpi.c @@ -0,0 +1,12 @@ +int strcmpi(const char *a1, const char *a2) { + char c1, c2; + /* Want both assignments to happen but a 0 in both to quit, so it's | not || */ + while((c1=*a1) | (c2=*a2)) { + if (!c1 || !c2 || /* Unneccesary? */ + (islower(c1) ? toupper(c1) : c1) != (islower(c2) ? toupper(c2) : c2)) + return (c1 - c2); + a1++; + a2++; + } + return 0; +} diff --git a/source/tools/C/strcmpi.h b/source/tools/C/strcmpi.h new file mode 100644 index 00000000..d94139c1 --- /dev/null +++ b/source/tools/C/strcmpi.h @@ -0,0 +1,6 @@ +#ifndef __STRCMPI_H +#define __STRCMPI_H + +int strcmpi(const char *a1, const char *a2); + +#endif diff --git a/source/kernel/bank5/system.h b/source/tools/C/system.h similarity index 84% rename from source/kernel/bank5/system.h rename to source/tools/C/system.h index a0aef783..4ab4a7ec 100644 --- a/source/kernel/bank5/system.h +++ b/source/tools/C/system.h @@ -8,11 +8,13 @@ #define ESC 27 #define CURSOR_RIGHT 28 #define CURSOR_LEFT 29 +#define KEY_1 49 /* MSX BIOS routines */ #define SYNCHR 0x0008 +#define CALSLT 0x001C #define INITXT 0x006C #define INIT32 0x006F #define CHPUT 0x00A2 @@ -40,7 +42,6 @@ #define VALTYP 0xF663 #define DAC 0xF7F6 #define SCRMOD 0xFCAF - - +#define EXPTBL 0xFCC1 #endif //__SYSTEM_H \ No newline at end of file diff --git a/source/kernel/bank5/types.h b/source/tools/C/types.h similarity index 100% rename from source/kernel/bank5/types.h rename to source/tools/C/types.h diff --git a/source/tools/C/vsft.c b/source/tools/C/vsft.c index 8976c813..40d9936b 100644 --- a/source/tools/C/vsft.c +++ b/source/tools/C/vsft.c @@ -26,6 +26,7 @@ #include #include #include +#include "strcmpi.h" //These are available at www.konamiman.com #include "asm.h" @@ -147,7 +148,6 @@ void TerminateWithDosError(byte errorCode); void print(char* s); void CheckDosVersion(); void ExtractParameters(char** argv, int argc); -int strcmpi(const char *a1, const char *a2); void GetDriveInfo(); void PrintDriveInfo(); void PrintSizeInK(unsigned long size); @@ -278,21 +278,6 @@ void ExtractParameters(char** argv, int argc) } } - -int strcmpi(const char *a1, const char *a2) { - char c1, c2; - /* Want both assignments to happen but a 0 in both to quit, so it's | not || */ - while((c1=*a1) | (c2=*a2)) { - if (!c1 || !c2 || /* Unneccesary? */ - (islower(c1) ? toupper(c1) : c1) != (islower(c2) ? toupper(c2) : c2)) - return (c1 - c2); - a1++; - a2++; - } - return 0; -} - - void GetDriveInfo() { regs.Words.DE = (int)Buffer; @@ -469,3 +454,5 @@ void WritebootSector() TerminateWithDosError(regs.Bytes.A); } } + +#include "strcmpi.c" diff --git a/source/tools/compile.bat b/source/tools/compile.bat index bea4f0ab..ec9240fd 100644 --- a/source/tools/compile.bat +++ b/source/tools/compile.bat @@ -1,10 +1,10 @@ @echo off cls -copy ..\msxdos25\macros.inc -copy ..\msxdos25\const.inc -copy ..\msxdos25\codes.mac -copy ..\msxdos25\data.mac +copy ..\kernel\macros.inc +copy ..\kernel\const.inc +copy ..\kernel\codes.mac +copy ..\kernel\data.mac for %%A in (CODES,DATA,SHARED) do cpm32 M80 =%%A del codes.mac del data.mac diff --git a/wintools/.gitignore b/wintools/.gitignore new file mode 100644 index 00000000..1b2081ac --- /dev/null +++ b/wintools/.gitignore @@ -0,0 +1 @@ +*.obj diff --git a/wintools/mknexrom.c b/wintools/mknexrom.c index eeed4fe3..72a202c3 100644 --- a/wintools/mknexrom.c +++ b/wintools/mknexrom.c @@ -1,8 +1,8 @@ /* MKNEXROM - Make a Nextor kernel ROM - By Konamiman, 4/2014 + By Konamiman, 3/2019 Usage: - mknexrom [/d:] [/m:] [/e:] [/8:<8K bank select address>] + mknexrom [] [/d:] [/m:] [/e:] [/8:<8K bank select address>] [/k:] This program creates a Nextor kernel ROM from a base file and a driver file, as per the recipe specified in the driver development guide. It also allows modifying @@ -71,6 +71,10 @@ inc a ld (6800h),a ret + + + is a hexadecimal number that contains the value of the boot key invert bytes, + LSB is byte 0 and MSX is byte 1. For example 1002 to invert keys SHIFT and 1. */ /* v1.01 (4/2011): @@ -90,7 +94,10 @@ v1.05 (4/2014): Added the <8K bank select address> parameter. - + + v1.06 (3/2019): + Added the parameter. + Existing full ROM files can now be updated, is optional for these. */ @@ -114,6 +121,7 @@ #define _8K_INIT_PATCH_ADDRESS 0x00F7 //File position where the patch for 8K bank mapper must be written #define LD_XXXX_A_OPCODE 0x32 #define MAPPER_CODE_HEADER_SIZE 3 +#define BOOT_KEYS_INVERTER_OFFSET 0x200 #define safeClose(file) {if(file!=NULL) {fclose(file); file=NULL;}} @@ -140,6 +148,11 @@ int main(int argc, char* argv[]) int i; unsigned short position; int First8KMappingAddress=0; + int hasBootKeys=0; + int bootKeys=0; + char byteBuffer; + int modifyOriginalFile; + int firstModifierArgumentIndex; char* baseFilename=NULL; char* newFilename=NULL; @@ -160,14 +173,23 @@ int main(int argc, char* argv[]) //* Get command line parameters printf("\r\n"); - if(argc<4) { + if(argc<3) { DisplayInfo(); DoExit(0); } baseFilename=argv[1]; - newFilename=argv[2]; - for(i=3; i> 8); + writeCount+=fwrite(&byteBuffer, 1, 1, newFile); + + if(writeCount!=2) { + printf("*** Can't write boot keys inverter bytes to the ROM file: %s\r\n", newFilename); + DoExit(1); + } + } //* Done - printf("ROM file %s created successfully.", newFilename); + if(modifyOriginalFile) { + printf("ROM file %s updated successfully.", baseFilename); + } else { + printf("ROM file %s created successfully.", newFilename); + } + DoExit(0); } @@ -467,12 +526,12 @@ int main(int argc, char* argv[]) void DisplayInfo() { - printf("MKNEXROM v1.05 - Make a Nextor kernel ROM\r\n" - "By Konamiman, 4/2014\r\n" + printf("MKNEXROM v1.06 - Make a Nextor kernel ROM\r\n" + "By Konamiman, 3/2019\r\n" "\r\n" "Usage:\r\n" - "mknexrom [/d:] [/m:]\r\n" - " [/e:] [/8:<8K bank select address>]\r\n" + "mknexrom [] [/d:] [/m:]\r\n" + " [/e:] [/8:<8K bank select address>] [/k:]\r\n" ); } diff --git a/wintools/mknexrom.exe b/wintools/mknexrom.exe index ef011668..63e24354 100644 Binary files a/wintools/mknexrom.exe and b/wintools/mknexrom.exe differ diff --git a/wintools/mknexrom.obj b/wintools/mknexrom.obj deleted file mode 100644 index 16cbeb4d..00000000 Binary files a/wintools/mknexrom.obj and /dev/null differ