PB... functions implementation

About SheepShaver, a PPC Mac emulator for Windows, MacOS X, and Linux that can run System 7.5.3 to MacOS 9.0.4.

Moderators: Cat_7, Ronald P. Regensburg, ClockWise

Post Reply
dadreamer
Inquisitive Elf
Posts: 34
Joined: Sun Jan 08, 2017 4:31 pm

PB... functions implementation

Post by dadreamer »

Hi!

I'm using System 7.5.3 w/ SheepShaver 2.3 on Windows 10 x64. Just out of my curiosity I've been playing with some old IDE, calling low-level PB... functions (PBOpen, PBControl / PBStatus, RBRead / PBWrite, PBClose) from there. As I can see, the rest of calls works OK. But something does not.

For example, I'm trying to work with Disk Driver in such way:
1. open the Driver by calling PBOpenSync with .Disk name and internal drive number (= 2) as parameters;
2. read some bytes from the disk by calling PBReadSync (bytes count = 512, position mode = 1 (fsFromStart), position offset = 0);
3. get the drive status by calling PBStatusSync w/ status code = 8 (drvStsCode);
4. close the Driver by calling PBCloseSync.

So, everything goes fine besides receiving the drive status.

Image

I'm always getting -56 error from the Driver that reads
error -56 nsDrvErr: no such drive (tried to mount a bad drive num)
(according to Mac Error Codes list)

But why I cannot get the status when I'm able to successfully open the disk and read from it? I wonder how accurately SS emulates Drivers and Managers... Is it my own mistake or Driver functionality is implemented just partially?

I've double-checked my code and it seems to be correct. Also tried to run this test app in another emulator but have not succeed with anything (I need PowerPC processor for that, but unfortunately PearPC is unable to run Classic environment). It would be nice to have a real Mac here but I don't have one.
User avatar
adespoton
Forum All-Star
Posts: 4208
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: PB... functions implementation

Post by adespoton »

I haven't dug into how SheepShaver handles closing virtual hardware devices; you might want to try in qemu with Mac OS 9.0.4, as you can both run the qemu debugger and MacsBug there, which should give you more information, plus give you a comparison point.

Figuring out the problem could also result in a fix for SheepShaver, although it hasn't been actively developed now for years, so it might not.
dadreamer
Inquisitive Elf
Posts: 34
Joined: Sun Jan 08, 2017 4:31 pm

Re: PB... functions implementation

Post by dadreamer »

I checked it out and it appears that I'm getting the same error in QEMU also. Still haven't tried MacsBug or any other debugger there due to strange graphical issues... But I tried to debug this issue on SheepShaver. There's the source code for SS/BasiliskII Disk Driver. According to that I can conclude that most of the functions are implemented completely (except, maybe, Disk Status w/ codes 44, 45, 46 and 70). My app is trying to get Drive Status with code = 8, that calls this piece of code:

Code: Select all

int16 DiskStatus(uint32 pb, uint32 dce)
{
	drive_vec::iterator info = get_drive_info(ReadMacInt16(pb + ioVRefNum));
	uint16 code = ReadMacInt16(pb + csCode);
	D(bug("DiskStatus %d\n", code));

	// I skip General codes here 'cause my code equals to 8

	// Drive valid?
	if (info == drives.end())
		return nsDrvErr;

	// Drive-specific codes
	switch (code) {
		case 8:		// Get drive status
			Mac2Mac_memcpy(pb + csParam, info->status, 22);
			return noErr;

	// Unimplemented codes are skipped also
	}
}
Using the debug mechanisme of SS I have found out that (info == drives.end()) is always true whatever input params were used for the Driver Open -> Read/Write or Control/Status -> Close session. It's kinda strange but I admit that ParamBlock might be formed incorrectly by IDE. I'm gonna check it out with some debugger later.

So, here are the questions.
- Is out there some system API logger/sniffer for SS or QEMU like Windows well-known sniffers WinAPIOverride, API Logger, API Monitor, Auto Debug Professional etc? I need to catch a few PB... functions like PBOpenSync and others.
- May I use MacsBug or QEMU debugger as step-by-step app tracer as I could do with ollydbg in Windows? I'd like to check func's parameters, asm and memory dump.
- Where's QEMU Disk Driver code? I may be inattentive, but I haven't found it here.
Post Reply