Skip to content

Commit

Permalink
Merge pull request #5 from MP2E/macos_port
Browse files Browse the repository at this point in the history
initial port to macOS
  • Loading branch information
vampirefrog authored Nov 7, 2024
2 parents c8e3f65 + 6c00357 commit 14b9f70
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
6 changes: 3 additions & 3 deletions v68doscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ int v68_dos_call(uint16_t instr) {
}
break;
case DOS_CALL_GETDATE: {
#if __linux__
#if __linux__ || __APPLE__
time_t t = time(NULL);
struct tm result;
localtime_r(&t, &result);
Expand All @@ -497,7 +497,7 @@ int v68_dos_call(uint16_t instr) {
}
break;
case DOS_CALL_GETTIME: {
#if __linux__
#if __linux__ || __APPLE__
time_t t = time(NULL);
struct tm result;
localtime_r(&t, &result);
Expand All @@ -507,7 +507,7 @@ int v68_dos_call(uint16_t instr) {
}
break;
case DOS_CALL_GETTIM2: {
#if __linux__
#if __linux__ || __APPLE__
time_t t = time(NULL);
struct tm result;
localtime_r(&t, &result);
Expand Down
18 changes: 16 additions & 2 deletions v68io.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <limits.h>
#if __linux__
#include <mntent.h>
#elif __APPLE__
#include <sys/mount.h>
#endif
#include <string.h>
#include <sys/types.h>
Expand Down Expand Up @@ -38,7 +40,7 @@ struct dosfile dosfiles[96];
int v68_io_init() {
memset(drives, 0, sizeof(drives));

#if __linux__
#if __linux__ || __APPLE__
// Init Z: as unix /
char buf[PATH_MAX];
buf[0] = 0;
Expand Down Expand Up @@ -105,6 +107,18 @@ int v68_io_autodetect_drives() {
}
}
fclose(f);
#elif __APPLE__
char *home = getenv("HOME");
if(home && *home) {
strncpy(drives['H' - 'A'].vpath, home, PATH_MAX);
drives['H' - 'A'].cwd[0] = 0;
}

struct statfs *mounts;
int num_mounts = getmntinfo(&mounts, MNT_WAIT);
for (int i = 0; i < num_mounts; i++) {
v68_io_add_drive(v68_io_unused_drive(), mounts[i].f_mntonname);
}
#else
DWORD dw = GetLogicalDrives();
for(int i = 'A', j = 1; i <= 'Z'; i++, j <<= 1) {
Expand Down Expand Up @@ -458,7 +472,7 @@ static int find_ci(char *from, char *to, int to_len) {
}

#else
strncpy(to, to_len, from);
strncpy(to, from, to_len);
#endif

return 0;
Expand Down
16 changes: 14 additions & 2 deletions v68iocscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <string.h>
#if __linux__
#include <sys/sysinfo.h>
#elif __APPLE__
#include <sys/sysctl.h>
#endif
#include "v68.h"
#include "v68iocscall.h"
Expand Down Expand Up @@ -507,8 +509,18 @@ int v68_iocs_call(uint16_t instr) {
sysinfo(&si);
m68k_set_reg(M68K_REG_D0, (si.uptime % (24 * 60 * 60)) * 100);
m68k_set_reg(M68K_REG_D1, si.uptime / (24 * 60 * 60));
#endif
#ifdef WIN32
#elif __APPLE__
struct timeval boottime;
size_t len = sizeof(boottime);
int mib[2] = { CTL_KERN, KERN_BOOTTIME };
if ( sysctl(mib, 2, &boottime, &len, NULL, 0) < 0 ) {
break;
}
time_t bsec = boottime.tv_sec, csec = time(NULL);
long uptime = difftime(csec, bsec);
m68k_set_reg(M68K_REG_D0, (uptime % (24 * 60 * 60)) * 100);
m68k_set_reg(M68K_REG_D1, uptime / (24 * 60 * 60));
#elif WIN32
DWORD u = GetTickCount();
u /= 1000;
m68k_set_reg(M68K_REG_D0, (u % (24 * 60 * 60)) * 100);
Expand Down

0 comments on commit 14b9f70

Please sign in to comment.