--- BasiliskII/src/macos_util.cpp 1999/10/03 14:16:25 1.1.1.1 +++ BasiliskII/src/macos_util.cpp 2008/01/01 09:40:31 1.12 @@ -1,7 +1,7 @@ /* * macos_util.cpp - MacOS definitions/utility functions * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2008 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +20,7 @@ #include "sysdeps.h" #include "cpu_emulation.h" +#include "adb.h" #include "main.h" #include "sony.h" #include "disk.h" @@ -34,7 +35,7 @@ * Enqueue QElem to list */ -void Enqueue(uint32 elem, uint32 list) +void EnqueueMac(uint32 elem, uint32 list) { WriteMacInt32(elem + qLink, 0); if (!ReadMacInt32(list + qTail)) { @@ -56,7 +57,7 @@ static bool is_drive_number_free(int num uint32 e = ReadMacInt32(0x308 + qHead); while (e) { uint32 d = e - dsQLink; - if (ReadMacInt16(d + dsQDrive) == num) + if ((int)ReadMacInt16(d + dsQDrive) == num) return false; e = ReadMacInt32(e + qLink); } @@ -86,16 +87,6 @@ void MountVolume(void *fh) /* - * Test if basic MacOS initializations (of the ROM) are done - */ - -bool HasMacStarted(void) -{ - return ReadMacInt32(0xcfc) == 'WLSC'; // Mac warm start flag -} - - -/* * Calculate disk image file layout given file size and first 256 data bytes */ @@ -111,3 +102,45 @@ void FileDiskLayout(loff_t size, uint8 * real_size = size - start_byte; } } + + +uint32 DebugUtil(uint32 Selector) +{ + switch (Selector) { + case duDebuggerGetMax: + return 3; + case duDebuggerEnter: + return 0; + case duDebuggerExit: + return 0; + case duDebuggerPoll: + ADBInterrupt(); + return 0; + default: + return (uint32) paramErr; + } +} + + +/* + * Convert time_t value to MacOS time (seconds since 1.1.1904) + */ + +uint32 TimeToMacTime(time_t t) +{ + // This code is taken from glibc 2.2 + + // Convert to number of seconds elapsed since 1-Jan-1904 + struct tm *local = localtime(&t); + const int TM_EPOCH_YEAR = 1900; + const int MAC_EPOCH_YEAR = 1904; + int a4 = ((local->tm_year + TM_EPOCH_YEAR) >> 2) - !(local->tm_year & 3); + int b4 = (MAC_EPOCH_YEAR >> 2) - !(MAC_EPOCH_YEAR & 3); + int a100 = a4 / 25 - (a4 % 25 < 0); + int b100 = b4 / 25 - (b4 % 25 < 0); + int a400 = a100 >> 2; + int b400 = b100 >> 2; + int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); + uint32 days = local->tm_yday + 365 * (local->tm_year - 4) + intervening_leap_days; + return local->tm_sec + 60 * (local->tm_min + 60 * (local->tm_hour + 24 * days)); +}