- disk.cpp looks for HFS partition info in the disk image; this makes it

possible to, for example, use MacOS-partitioned hard disks and removable
  media under B2/Unix even if the OS doesn't understand Mac partition maps
  by specifying the appropriate block device name as a Mac volume
- fixed typo in audio_dummy.cpp
- added minimally required UDP tunneling code to ether_dummy.cpp
- main_unix.cpp: if pthreads are not supported, we trigger the Ethernet
  interrupt in the 60Hz ticker; this makes UDP tunneling work under
  NetBSD/m68k (as the only form of networking)
This commit is contained in:
cebix 2001-07-14 20:01:20 +00:00
parent 55df210d27
commit 54bfc83cfe
5 changed files with 104 additions and 8 deletions

View File

@ -835,8 +835,9 @@ static void one_tick(...)
}
#ifndef HAVE_PTHREADS
// No threads available, perform video refresh from here
// No threads available, perform video refresh and networking from here
VideoRefresh();
SetInterruptFlag(INTFLAG_ETHER);
#endif
// Trigger 60Hz interrupt

View File

@ -132,7 +132,7 @@ struct cdrom_drive_info {
void *fh; // File handle
int block_size; // CD-ROM block size
int twok_offset; // Offset of beginning of 2K block to last Prime position
uint32 start_byte; // Start of HFS partition on disk
loff_t start_byte; // Start of HFS partition on disk
bool to_be_mounted; // Flag: drive must be mounted in accRun
bool mount_non_hfs; // Flag: Issue disk-inserted events for non-HFS disks

View File

@ -71,13 +71,14 @@ const uint8 DiskIcon[258] = {
// Struct for each drive
struct disk_drive_info {
disk_drive_info() : num(0), fh(NULL), read_only(false), status(0) {}
disk_drive_info() : num(0), fh(NULL), start_byte(0), read_only(false), status(0) {}
disk_drive_info(void *fh_, bool ro) : num(0), fh(fh_), read_only(ro), status(0) {}
void close_fh(void) { Sys_close(fh); }
int num; // Drive number
void *fh; // File handle
loff_t start_byte; // Start of HFS partition on disk
uint32 num_blocks; // Size in 512-byte blocks
bool to_be_mounted; // Flag: drive must be mounted in accRun
bool read_only; // Flag: force write protection
@ -110,6 +111,39 @@ static drive_vec::iterator get_drive_info(int num)
}
/*
* Find HFS partition, set info->start_byte and info->num_blocks
* (0 = no partition map or HFS partition found, assume flat disk image)
*/
static void find_hfs_partition(disk_drive_info &info)
{
info.start_byte = 0;
info.num_blocks = 0;
uint8 *map = new uint8[512];
// Search first 64 blocks for HFS partition
for (int i=0; i<64; i++) {
if (Sys_read(info.fh, map, i * 512, 512) != 512)
break;
// Not a partition map block? Then look at next block
uint16 sig = (map[0] << 8) | map[1];
if (sig != 0x504d)
continue;
// Partition map block found, Apple HFS partition?
if (strcmp((char *)(map + 48), "Apple_HFS") == 0) {
info.start_byte = ntohl(((uint32 *)map)[2]) << 9;
info.num_blocks = ntohl(((uint32 *)map)[3]);
D(bug(" HFS partition found at %d, %d blocks\n", info.start_byte, info.num_blocks));
break;
}
}
delete[] map;
}
/*
* Initialization
*/
@ -163,7 +197,9 @@ bool DiskMountVolume(void *fh)
info->read_only = SysIsReadOnly(info->fh);
WriteMacInt8(info->status + dsDiskInPlace, 1); // Inserted removable disk
WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0xff : 0);
info->num_blocks = SysGetFileSize(info->fh) / 512;
find_hfs_partition(*info);
if (info->start_byte == 0)
info->num_blocks = SysGetFileSize(info->fh) / 512;
WriteMacInt16(info->status + dsDriveSize, info->num_blocks & 0xffff);
WriteMacInt16(info->status + dsDriveS1, info->num_blocks >> 16);
info->to_be_mounted = true;
@ -249,7 +285,9 @@ int16 DiskOpen(uint32 pb, uint32 dce)
if (disk_in_place) {
D(bug(" disk inserted\n"));
WriteMacInt8(info->status + dsWriteProt, info->read_only ? 0x80 : 0);
info->num_blocks = SysGetFileSize(info->fh) / 512;
find_hfs_partition(*info);
if (info->start_byte == 0)
info->num_blocks = SysGetFileSize(info->fh) / 512;
info->to_be_mounted = true;
}
D(bug(" %d blocks\n", info->num_blocks));
@ -295,7 +333,7 @@ int16 DiskPrime(uint32 pb, uint32 dce)
if ((ReadMacInt16(pb + ioTrap) & 0xff) == aRdCmd) {
// Read
actual = Sys_read(info->fh, buffer, position, length);
actual = Sys_read(info->fh, buffer, position + info->start_byte, length);
if (actual != length)
return readErr;
@ -304,7 +342,7 @@ int16 DiskPrime(uint32 pb, uint32 dce)
// Write
if (info->read_only)
return wPrErr;
actual = Sys_write(info->fh, buffer, position, length);
actual = Sys_write(info->fh, buffer, position + info->start_byte, length);
if (actual != length)
return writErr;
}

View File

@ -43,7 +43,7 @@ void AudioInit(void)
// Only one sample format is supported
audio_sample_rates.push_back(44100 << 16);
audio_sample_sized.push_back(16);
audio_sample_sizes.push_back(16);
audio_channel_counts.push_back(2);
// Sound disabled in prefs? Then do nothing

View File

@ -19,6 +19,12 @@
*/
#include "sysdeps.h"
#if SUPPORTS_UDP_TUNNEL
#include <netinet/in.h>
#include <sys/socket.h>
#endif
#include "cpu_emulation.h"
#include "main.h"
#include "macos_util.h"
@ -33,6 +39,13 @@
#define MONITOR 0
// Global variables
#if SUPPORTS_UDP_TUNNEL
static int fd = -1; // UDP tunnel socket fd
static bool udp_tunnel_active = false;
#endif
/*
* Initialization
*/
@ -113,10 +126,54 @@ int16 ether_write(uint32 wds)
}
/*
* Start UDP packet reception thread
*/
bool ether_start_udp_thread(int socket_fd)
{
#if SUPPORTS_UDP_TUNNEL
fd = socket_fd;
udp_tunnel_active = true;
return true;
#else
return false;
#endif
}
/*
* Stop UDP packet reception thread
*/
void ether_stop_udp_thread(void)
{
#if SUPPORTS_UDP_TUNNEL
udp_tunnel_active = false;
#endif
}
/*
* Ethernet interrupt - activate deferred tasks to call IODone or protocol handlers
*/
void EtherInterrupt(void)
{
#if SUPPORTS_UDP_TUNNEL
if (udp_tunnel_active) {
uint8 packet[1514];
ssize_t length;
// Read packets from socket and hand to ether_udp_read() for processing
while (true) {
struct sockaddr_in from;
socklen_t from_len = sizeof(from);
length = recvfrom(fd, packet, 1514, 0, (struct sockaddr *)&from, &from_len);
if (length < 14)
break;
ether_udp_read(packet, length, &from);
}
}
#endif
}