Trying to read a physical disk

168 views
Skip to first unread message

Josef Moellers

unread,
Mar 18, 2022, 6:21:34 AMMar 18
to

Hi,
I'm trying to read a physical disk to get an image of the disk
I have changed the first couple of bytes of the image to identify the
disk, but I still get E5s.
As a test, I'm trying to read just the very first sector off the disk, I do:
LD C,4 ; select drive E:
LD A,9 ; SELDSK
CALL BIOS
LD BC,0 ; Set Track 0
LD A,10 ; SETTRK
CALL BIOS
LD BC,1H ; Set Sector 1
LD A,11 ; SETSEC
CALL BIOS
LD BC,buffer
LD A,12 ; SETDMA
CALL BIOS
LD A.13 ; READ
CALL BIOS
Then I dump the first 16 bytes of the data but it is all E5s
What am I doing wrong here?
Neither the SELDSK nor the READ report an error.
I also tried Sector 11H as ZSystem uses this as the first sector number
of a track.

Thanks,

Josef
NB This is on an SB180FX which has a hard disk occupying drives A..D,
then a GoTek floppy emulator as floppy drive 0/drive E:, a 3½" drive as
drive 1/F: and a 5¼" drive as drive 2/G:.

Udo Munk

unread,
Mar 18, 2022, 8:09:46 AMMar 18
to
You are reading a sector that is empty but formatted with the usual E5. Try reading other sectors that contain data.

Josef Moellers

unread,
Mar 18, 2022, 9:01:01 AMMar 18
to

On 18.03.22 13:09, Udo Munk wrote:
> You are reading a sector that is empty but formatted with the usual E5. Try reading other sectors that contain data.

I'm trying to read the very first sector on the disk.

As I wrote, this is a GoTec USB-to-Floppy adapter with the FlashFloppy
firmware. It uses file(s) on the USB stick to hold the disk image(s).

I have modified the file using this specific image to have a string (the
file name) as the first couple of bytes, so it should not be E5 but
something different.

But I'll try to modify the program so that I can specify disk number,
track number and sector number.

Thanks anyway,

Josef

Josef Moellers

unread,
Mar 18, 2022, 9:25:02 AMMar 18
to

On 18.03.22 13:09, Udo Munk wrote:
> You are reading a sector that is empty but formatted with the usual E5. Try reading other sectors that contain data.

It appears that my reference (DR's CP/M Operating System Manual) is
incorrect in that the sector number is 0-based, not 1-based.
Reading drive=4, track=0, sector=0 reads the correct sector:
5A,5A,5A,5A,5A,30,32,36,2E,69,6D,67,E5,E5,E5,E5,
while reading 4,0,1 reads
E5,E5,E5,E5,E5,E5,E5,E5,E5,E5,E5,E5,E5,E5,E5,E5,

Go figure,

Josef

Martin

unread,
Mar 18, 2022, 2:48:01 PMMar 18
to
You don't call SECTRAN, so the sector number is "physical",
it can be any number the hardware needs to get.

You need to find out this physical sector number first and
pass that to SETSEC.

There is a very good sector editor called "the disk inspector",
which just didn't work on my 0-based system.

This program is *so* useful, I had to look inside and came up
with a quick and dirty patch to fix it.

Here is the relevant part of the code disasssembled.

I hope, you can read it and peruse the modification I made.

Martin


$ cat INFO_inspect_2.x_self_adapting_sector_number_base_fix.diffs
================
INFO: VERSION 2.1: ADDRESS 226a
INFO: VERSION 2.1: ADDRESS 281f
INFO: VERSION 2.2: ADDRESS 2a15
================

================
INFO: SELECT DISK AND FILL SECTOR DESCRIPTOR RECORD
INFO: IY: ADDRESS OF SECTOR DESCRIPTOR FOR
INFO: UPPER SECTOR (015eh)/LOWER SECTOR (0177h)
INFO: +00h: DRIVE
INFO: +01h/02h: TRACK
INFO: +03H/04H: SECTOR
INFO: +05H/06H: BLOCK
INFO: +07H/08H: ALV
INFO: +09H: SELECTED DRIVE
INFO: +0ah/0bH: CKS
INFO: +0ch/0dH: LAST TRACK + 1
INFO: +0eh/0fh: SPT
----
29e6 fd 4e 00 LD C,(IY+00) ;DISK DRIVE
29e9 00 NOP ;UNKNOWN PATCHED OUT
29ea 00 NOP
29eb 00 NOP
29ec 1e 01 LD E,001 ;NOT FIRST SELECT
29ee 21 1b 00 LD HL,001b ;SELECT DISK DRIVE
29f1 cd 54 0d CALL 0d54 ;CALL BIOS

29f4 16 00 LD D,000
29f6 1e 00 LD E,000
29f8 b7 OR A
29f9 ed 5a ADC HL,DE
29fb ca a0 2a JP Z,2aa0 ;SELECT ERROR

29fe e5 PUSH HL
29ff dd e1 POP IX ;DPH PTR IN IX

2a01 dd 5e 00 LD E,(IX+00) ;XLT (OR 0000h)
2a04 dd 56 01 LD D,(IX+01)
2a07 fd 73 12 LD (IY+12),E
2a0a fd 72 13 LD (IY+13),D

2a0d af XOR A ;LOWEST SECTOR NUMBER
2a0e fd 77 17 LD (IY+17),A

2a11 7a LD A,D
2a12 b3 OR E
2a13 28 05 JR Z,2a1a ;NO TRANSLATION
================
INFO: OLD: HARD CODED SECTOR NUMBER BASE 01H
<<< 2a15 3e 01 LD A,001
================
INFO: NEW: ASSUME XLT STARTS WITH THE LOWEST SECTOR NUMBER
INFO: NEW: USE IT AS SELF-ADAPTING SECTOR NUMBER BASE
>>> 2a15 1a LD A,(DE)
>>> 2a16 00 NOP
================
2a17 fd 77 17 LD (IY+17),A

2a1a dd 5e 0e LD E,(IX+0e) ;ALV
2a1d dd 56 0f LD D,(IX+0f)
2a20 fd 73 07 LD (IY+07),E
2a23 fd 72 08 LD (IY+08),D

2a26 dd 5e 0a LD E,(IX+0a) ;DPB
2a29 dd 56 0b LD D,(IX+0b)
2a2c d5 PUSH DE
2a2d dd e1 POP IX ;DPB PTR IN IX

2a2f dd 7e 00 LD A,(IX+00) ;SPT
2a32 fd 77 0e LD (IY+0e),A
2a35 dd 7e 01 LD A,(IX+01)
2a38 fd 77 0f LD (IY+0f),A

2a3b dd 7e 0d LD A,(IX+0d) ;OFF
2a3e fd 77 14 LD (IY+14),A
2a41 dd 7e 0e LD A,(IX+0e)
2a44 fd 77 15 LD (IY+15),A

2a47 dd 7e 02 LD A,(IX+02) ;BSH
2a4a fd 77 16 LD (IY+16),A

2a4d dd 7e 05 LD A,(IX+05) ;DSM
2a50 fd 77 10 LD (IY+10),A
2a53 dd 7e 06 LD A,(IX+06)
2a56 fd 77 11 LD (IY+11),A

2a59 fd 46 16 LD B,(IY+16) ;BSH
2a5c fd 66 11 LD H,(IY+11) ;DSM
2a5f fd 6e 10 LD L,(IY+10)
2a62 23 INC HL ;#BLOCKS
2a63 29 ADD HL,HL
2a64 10 fd DJNZ 2a63
2a66 7c LD A,H
2a67 b5 OR L
2a68 20 03 JR NZ,2a6d
2a6a 21 ff ff LD HL,ffff ;FFFF, IF (1)0000H

2a6d fd 56 0f LD D,(IY+0f) ;SPT
2a70 fd 5e 0e LD E,(IY+0e)
2a73 01 00 00 LD BC,0000
2a76 03 INC BC ;CALC #TRACKS
2a77 ed 52 SBC HL,DE
2a79 28 02 JR Z,2a7d
2a7b 30 f9 JR NC,2a76

2a7d c5 PUSH BC
2a7e e1 POP HL ;#TRACKS

2a7f fd 56 15 LD D,(IY+15) ;OFF
2a82 fd 5e 14 LD E,(IY+14)
2a85 af XOR A
2a86 ba CP D
2a87 20 06 JR NZ,2a8f
2a89 3e 04 LD A,004
2a8b bb CP E
2a8c 38 01 JR C,2a8f
2a8e 19 ADD HL,DE ;IF OFF<=0004H ADD OFF
2a8f fd 75 0c LD (IY+0c),L
2a92 fd 74 0d LD (IY+0d),H

2a95 fd 7e 00 LD A,(IY+00) ;DISK DRIVE
2a98 32 a9 2a LD (2aa9),A
2a9b fd 77 09 LD (IY+09),A ;DRIVE
2a9e af XOR A ;NO ERROR
2a9f c9 RET

2aa0 3e ff LD A,0ff ;INVALID
2aa2 32 a9 2a LD (2aa9),A
2aa5 3e 02 LD A,002 ;ERROR #2
2aa7 b7 OR A
2aa8 c9 RET
================


fridtjof.ma...@gmail.com

unread,
Mar 18, 2022, 4:18:44 PMMar 18
to
4 is not E: 0 is default, 1 is A: and 5: is E:

fridtjof.ma...@gmail.com

unread,
Mar 18, 2022, 4:21:16 PMMar 18
to
On Friday, March 18, 2022 at 6:21:34 AM UTC-4, Josef Moellers wrote:
My bad... these are BIOS calls - 4 *is* E:

Josef Moellers

unread,
Mar 21, 2022, 6:24:48 AMMar 21
to
Hm, here's something I don't understand:
The native floppy format of the SB180FX is 5spt, 1024bps, the first
physical sector on each track being 11H.
If I issue a READ, I get "only" 128 bytes. I have to issue 40 READs with
increasing sector numbers (0..39) until I get an error reported back
from READ, register A being non-0 on return from "CALL BIOS", a function
in syslib.
So the sector number that I pass to SETSEC cannot be a "number the
hardware needs to get". These would be 11H..15H.
Also, I do not specify the head, so I assume that the least significant
bit in the track number is the head number.

> You need to find out this physical sector number first and
> pass that to SETSEC.

As the GoTec adapter has no disk rotating, my disk images are just
logical linear dumps of the disks (*). Therefore, I have not specified
any skew factor.

I think I will need to adapt my code when I read from a physical floppy
disk. My intention of this whole game is to store all physical floppy
disks as images on the USB stick and not need the old drives ever again.

> There is a very good sector editor called "the disk inspector",
> which just didn't work on my 0-based system.

The SB180FX came with DU3, a "Disk Utility".
I have the CP/M CDROM from Walnut Creek which has SRW150.LBR,
"Memory/Disk inspector/modifier", is this what you refer to?

> This program is *so* useful, I had to look inside and came up
> with a quick and dirty patch to fix it.
>
> Here is the relevant part of the code disasssembled.
>
> I hope, you can read it and peruse the modification I made.

I'll have a look, thanks.

Josef

(*) Those I produced using the SB180FX monitor driven by an PERL/EXPECT
script: in a PERL loop: starting with sector 1, read the next sector to
8000H, then dump 8000,83FF.

Udo Munk

unread,
Mar 21, 2022, 11:28:54 AMMar 21
to
CPM 2 only knows about disks with 128 bytes per sector. If the physical size of a sector is something else
the BIOS must do a translation. In your code sniped you are not calling the SECTRAN routine, which would
return the physical sector you need to address on the disk, so you would have to calculate that your self.
Would be easier to call SECTRAN before SETSEC, I assume your BIOS works and knows what it is doing.

Martin

unread,
Mar 21, 2022, 3:45:31 PMMar 21
to
The value passed to SETSEC then is a value which makes it easier
for the BIOS to translate to the final physical value
in the deblocking routine.

>> You need to find out this physical sector number first and
>> pass that to SETSEC.
>
> As the GoTec adapter has no disk rotating, my disk images are just
> logical linear dumps of the disks (*). Therefore, I have not specified
> any skew factor.
>
> I think I will need to adapt my code when I read from a physical floppy
> disk. My intention of this whole game is to store all physical floppy
> disks as images on the USB stick and not need the old drives ever again.
>

If you want to read your floppy disks to convert them into images, it
is important to read the tracks itself in logical ascending order and
within each track the sectors in logical (linear) order by calling
SECTRAN.

You get a linear filesystem image which is more easily adaptable to any
system or emulator you will get.

If you are only interested in the CP/M filesystem itself, then you start
copying with the first data track leaving the system tracks out.

But don't forget to keep several complete sets of your system disks!


>> There is a very good sector editor called "the disk inspector",
>> which just didn't work on my 0-based system.
>
> The SB180FX came with DU3, a "Disk Utility".
> I have the CP/M CDROM from Walnut Creek which has SRW150.LBR,
> "Memory/Disk inspector/modifier", is this what you refer to?
>

Its "inspect.com" inside
<http://cpmarchives.classiccmp.org/trs80/Software/cpm/2006/Unsorted/cpm1.zip>

The Disk Inspector
Written by Graham Campbell

A review is in "Micro Cornucopia #10 2/83"

Martin

unread,
Mar 21, 2022, 9:35:34 PMMar 21
to
Am 03/21/2022 08:44 PM, Martin schrieb:
>>> You don't call SECTRAN, so the sector number is "physical",
>>> it can be any number the hardware needs to get.
>>
>> Hm, here's something I don't understand:
>> The native floppy format of the SB180FX is 5spt, 1024bps, the first
>> physical sector on each track being 11H.
>> If I issue a READ, I get "only" 128 bytes. I have to issue 40 READs with
>> increasing sector numbers (0..39) until I get an error reported back
>> from READ, register A being non-0 on return from "CALL BIOS", a function
>> in syslib.
>> So the sector number that I pass to SETSEC cannot be a "number the
>> hardware needs to get". These would be 11H..15H.
>> Also, I do not specify the head, so I assume that the least significant
>> bit in the track number is the head number.
>>
>
> The value passed to SETSEC then is a value which makes it easier
> for the BIOS to translate to the final physical value
> in the deblocking routine.
>

BTW, my 0-based translation table looks like:

; sector translate vector
TRANS: DB 0,1,4,5
DB 8,9,12,13
DB 16,17,2,3
DB 6,7,10,11
DB 14,15,18,19

The deblocking and the sector skew is clearly visible.


Josef Moellers

unread,
Mar 22, 2022, 3:27:28 AMMar 22
to

Mooi'n,

On 18.03.22 11:21, Josef Moellers wrote:
[...]

Thanks Udo, Martin, Fridtjof for the help you provided and the insight I
got from that.

I have stepped back a few paces and have thought about what exactly I
was trying to achieve: I want to get rid of the mechanical floppy disk
drives and have all the floppies that I still have from way back when I
bought the SB180FX and played around with it on another medium,
especially on the USB stick in the GoTek.

However, it occurred to me that whatever I was trying to actually do
would be way too complicated because once I have an image on my "hard
disk" (a parallel-SCSI connected flash disk), I need to transfer it to
my Linux box to then put it onto the USB stick. The transfer would not
be too complicated if I had a serial line so I could use any of the
transfer protocols [xyz]modem or even kermit, but my connection is
through an XPORT, a LAN-to-serial (or was it serial-to-LAN?) adapter. I
have compiled minicom to work with a network connection, so this setup
works but it cannot do the file transfers because the connection is not
a real serial line and thus cannot be easily shared between the "use"
connection and the "transfer" connection.

A way simpler solution is to create an empty image on the stick, switch
the GoTek to that image and then just use a disk copy program to
transfer the floppy disk's contents to the image or, as an alternative,
create a CP/M filesystem (mkfs.cpm) and just copy all the files over.

So I will leave this project as it is.

Thanks again,

Josef
Reply all
Reply to author
Forward
0 new messages