revert BasiliskII, change only SheepShaver

This commit is contained in:
kanjitalk755 2017-11-18 13:08:30 +09:00
parent e7c041c0d5
commit 056dc36070
9 changed files with 3731 additions and 8 deletions

View File

@ -198,12 +198,12 @@ static void *vm_acquire_framebuffer(uint32 size)
// always try to reallocate framebuffer at the same address
static void *fb = VM_MAP_FAILED;
if (fb != VM_MAP_FAILED) {
// if (vm_acquire_fixed(fb, size) < 0) {
if (vm_acquire_fixed(fb, size) < 0) {
#ifndef SHEEPSHAVER
printf("FATAL: Could not reallocate framebuffer at previous address\n");
#endif
fb = VM_MAP_FAILED;
// }
}
}
if (fb == VM_MAP_FAILED)
fb = vm_acquire(size, VM_MAP_DEFAULT | VM_MAP_32BIT);

View File

@ -107,8 +107,8 @@ void pagezero_64(struct mach_header_64 *machhead)
exit(1);
}
/* change the permissions */
// sc_cmd->maxprot = target_uint32(VM_PROT_ALL);
// sc_cmd->initprot = target_uint32(VM_PROT_ALL);
sc_cmd->maxprot = target_uint32(VM_PROT_ALL);
sc_cmd->initprot = target_uint32(VM_PROT_ALL);
}
#endif

View File

@ -16,7 +16,6 @@
08163339158C121000C449F9 /* dis-asm.h in Headers */ = {isa = PBXBuildFile; fileRef = 08163337158C121000C449F9 /* dis-asm.h */; };
08163340158C125800C449F9 /* ppc-dis.c in Sources */ = {isa = PBXBuildFile; fileRef = 08163338158C121000C449F9 /* ppc-dis.c */; };
082AC22D14AA52E900071F5E /* prefs_editor_dummy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 082AC22C14AA52E900071F5E /* prefs_editor_dummy.cpp */; };
082AC26214AA59F000071F5E /* lowmem.c in Sources */ = {isa = PBXBuildFile; fileRef = 082AC26114AA59F000071F5E /* lowmem.c */; };
083E370C16EFE85000CCCA59 /* disk_sparsebundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 083E370A16EFE85000CCCA59 /* disk_sparsebundle.cpp */; };
083E372216EFE87200CCCA59 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 083E372016EFE87200CCCA59 /* tinyxml2.cpp */; };
0846E4B114B1264700574779 /* ieeefp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0856CDF714A99EEF000B1711 /* ieeefp.cpp */; };
@ -106,6 +105,7 @@
08CD42E814B7B8AA009CA2A2 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08CD42E714B7B8AA009CA2A2 /* Carbon.framework */; };
08E877521E0640E800A90A2C /* clip_macosx.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0856CE2C14A99EF0000B1711 /* clip_macosx.cpp */; };
A7B1921418C35D4700791D8D /* DiskType.m in Sources */ = {isa = PBXBuildFile; fileRef = A7B1921318C35D4700791D8D /* DiskType.m */; };
E4302EE31FBFE7FA00A5B500 /* lowmem.c in Sources */ = {isa = PBXBuildFile; fileRef = E4302EE21FBFE7FA00A5B500 /* lowmem.c */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -151,7 +151,6 @@
08163338158C121000C449F9 /* ppc-dis.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "ppc-dis.c"; sourceTree = "<group>"; };
082AC22C14AA52E900071F5E /* prefs_editor_dummy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = prefs_editor_dummy.cpp; sourceTree = "<group>"; };
082AC25214AA59B600071F5E /* lowmem */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = lowmem; sourceTree = BUILT_PRODUCTS_DIR; };
082AC26114AA59F000071F5E /* lowmem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = lowmem.c; path = ../../../BasiliskII/src/Unix/Darwin/lowmem.c; sourceTree = SOURCE_ROOT; };
083E370A16EFE85000CCCA59 /* disk_sparsebundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = disk_sparsebundle.cpp; path = ../Unix/disk_sparsebundle.cpp; sourceTree = SOURCE_ROOT; };
083E370B16EFE85000CCCA59 /* disk_unix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = disk_unix.h; path = ../Unix/disk_unix.h; sourceTree = SOURCE_ROOT; };
083E372016EFE87200CCCA59 /* tinyxml2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = tinyxml2.cpp; path = ../Unix/tinyxml2.cpp; sourceTree = SOURCE_ROOT; };
@ -379,6 +378,7 @@
08D93A15159FE174003B04EC /* clip_macosx64.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = clip_macosx64.mm; sourceTree = "<group>"; };
A7B1921218C35D4700791D8D /* DiskType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiskType.h; sourceTree = "<group>"; };
A7B1921318C35D4700791D8D /* DiskType.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DiskType.m; sourceTree = "<group>"; };
E4302EE21FBFE7FA00A5B500 /* lowmem.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = lowmem.c; path = Darwin/lowmem.c; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -427,7 +427,7 @@
082AC25614AA59DA00071F5E /* Darwin */ = {
isa = PBXGroup;
children = (
082AC26114AA59F000071F5E /* lowmem.c */,
E4302EE21FBFE7FA00A5B500 /* lowmem.c */,
);
name = Darwin;
sourceTree = "<group>";
@ -1046,7 +1046,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
082AC26214AA59F000071F5E /* lowmem.c in Sources */,
E4302EE31FBFE7FA00A5B500 /* lowmem.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -0,0 +1,16 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
*/
#ifndef _SDLMain_h_
#define _SDLMain_h_
#import <Cocoa/Cocoa.h>
@interface SDLMain : NSObject
@end
#endif /* _SDLMain_h_ */

View File

@ -0,0 +1,381 @@
/* SDLMain.m - main entry point for our Cocoa-ized SDL app
Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
Non-NIB-Code & other changes: Max Horn <max@quendi.de>
Feel free to customize this file to suit your needs
*/
#include "SDL.h"
#include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h>
/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
it ourselves here. */
@interface NSApplication(SDL_Missing_Methods)
- (void)setAppleMenu:(NSMenu *)menu;
@end
/* Use this flag to determine whether we use SDLMain.nib or not */
#define SDL_USE_NIB_FILE 0
/* Use this flag to determine whether we use CPS (docking) or not */
#define SDL_USE_CPS 1
#ifdef SDL_USE_CPS
/* Portions of CPS.h */
typedef struct CPSProcessSerNum
{
UInt32 lo;
UInt32 hi;
} CPSProcessSerNum;
extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
#endif /* SDL_USE_CPS */
static int gArgc;
static char **gArgv;
static BOOL gFinderLaunch;
static BOOL gCalledAppMainline = FALSE;
static NSString *getApplicationName(void)
{
const NSDictionary *dict;
NSString *appName = 0;
/* Determine the application name */
dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];
if (![appName length])
appName = [[NSProcessInfo processInfo] processName];
return appName;
}
#if SDL_USE_NIB_FILE
/* A helper category for NSString */
@interface NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
@end
#endif
@interface NSApplication (SDLApplication)
@end
@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
/* The main class of the application, the application's delegate */
@implementation SDLMain
/* Set the working directory to the .app's parent directory */
- (void) setupWorkingDirectory:(BOOL)shouldChdir
{
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
chdir(parentdir); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}
#if SDL_USE_NIB_FILE
/* Fix menu to contain the real app name instead of "SDL App" */
- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
{
NSRange aRange;
NSEnumerator *enumerator;
NSMenuItem *menuItem;
aRange = [[aMenu title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
enumerator = [[aMenu itemArray] objectEnumerator];
while ((menuItem = [enumerator nextObject]))
{
aRange = [[menuItem title] rangeOfString:@"SDL App"];
if (aRange.length != 0)
[menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
if ([menuItem hasSubmenu])
[self fixMenu:[menuItem submenu] withAppName:appName];
}
}
#else
static void setApplicationMenu(void)
{
/* warning: this code is very odd */
NSMenu *appleMenu;
NSMenuItem *menuItem;
NSString *title;
NSString *appName;
appName = getApplicationName();
appleMenu = [[NSMenu alloc] initWithTitle:@""];
/* Add menu items */
title = [@"About " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Hide " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
[menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
[appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
[appleMenu addItem:[NSMenuItem separatorItem]];
title = [@"Quit " stringByAppendingString:appName];
[appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
/* Put menu into the menubar */
menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
[menuItem setSubmenu:appleMenu];
[[NSApp mainMenu] addItem:menuItem];
/* Tell the application object that this is now the application menu */
[NSApp setAppleMenu:appleMenu];
/* Finally give up our references to the objects */
[appleMenu release];
[menuItem release];
}
/* Create a window menu */
static void setupWindowMenu(void)
{
NSMenu *windowMenu;
NSMenuItem *windowMenuItem;
NSMenuItem *menuItem;
windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
/* "Minimize" item */
menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
[windowMenu addItem:menuItem];
[menuItem release];
/* Put menu into the menubar */
windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
[windowMenuItem setSubmenu:windowMenu];
[[NSApp mainMenu] addItem:windowMenuItem];
/* Tell the application object that this is now the window menu */
[NSApp setWindowsMenu:windowMenu];
/* Finally give up our references to the objects */
[windowMenu release];
[windowMenuItem release];
}
/* Replacement for NSApplicationMain */
static void CustomApplicationMain (int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
SDLMain *sdlMain;
/* Ensure the application object is initialised */
[NSApplication sharedApplication];
#ifdef SDL_USE_CPS
{
CPSProcessSerNum PSN;
/* Tell the dock about us */
if (!CPSGetCurrentProcess(&PSN))
if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
if (!CPSSetFrontProcess(&PSN))
[NSApplication sharedApplication];
}
#endif /* SDL_USE_CPS */
/* Set up the menubar */
[NSApp setMainMenu:[[[NSMenu alloc] init] autorelease]];
setApplicationMenu();
setupWindowMenu();
/* Create SDLMain and make it the app delegate */
sdlMain = [[SDLMain alloc] init];
[NSApp setDelegate:sdlMain];
/* Start the main event loop */
[NSApp run];
[sdlMain release];
[pool release];
}
#endif
/*
* Catch document open requests...this lets us notice files when the app
* was launched by double-clicking a document, or when a document was
* dragged/dropped on the app's icon. You need to have a
* CFBundleDocumentsType section in your Info.plist to get this message,
* apparently.
*
* Files are added to gArgv, so to the app, they'll look like command line
* arguments. Previously, apps launched from the finder had nothing but
* an argv[0].
*
* This message may be received multiple times to open several docs on launch.
*
* This message is ignored once the app's mainline has been called.
*/
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
const char *temparg;
size_t arglen;
char *arg;
char **newargv;
if (!gFinderLaunch) /* MacOS is passing command line args. */
return FALSE;
if (gCalledAppMainline) /* app has started, ignore this document. */
return FALSE;
temparg = [filename UTF8String];
arglen = SDL_strlen(temparg) + 1;
arg = (char *) SDL_malloc(arglen);
if (arg == NULL)
return FALSE;
newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 2));
if (newargv == NULL)
{
SDL_free(arg);
return FALSE;
}
gArgv = newargv;
SDL_strlcpy(arg, temparg, arglen);
gArgv[gArgc++] = arg;
gArgv[gArgc] = NULL;
return TRUE;
}
/* Called when the internal event loop has just started running */
- (void) applicationDidFinishLaunching: (NSNotification *) note
{
int status;
/* Set the working directory to the .app's parent directory */
[self setupWorkingDirectory:gFinderLaunch];
#if SDL_USE_NIB_FILE
/* Set the main menu to contain the real app name instead of "SDL App" */
[self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
#endif
/* Hand off to main application code */
gCalledAppMainline = TRUE;
status = SDL_main (gArgc, gArgv);
/* We're done, thank you for playing */
exit(status);
}
@end
@implementation NSString (ReplaceSubString)
- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
{
unsigned int bufferSize;
unsigned int selfLen = [self length];
unsigned int aStringLen = [aString length];
unichar *buffer;
NSRange localRange;
NSString *result;
bufferSize = selfLen + aStringLen - aRange.length;
buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
/* Get first part into buffer */
localRange.location = 0;
localRange.length = aRange.location;
[self getCharacters:buffer range:localRange];
/* Get middle part into buffer */
localRange.location = 0;
localRange.length = aStringLen;
[aString getCharacters:(buffer+aRange.location) range:localRange];
/* Get last part into buffer */
localRange.location = aRange.location + aRange.length;
localRange.length = selfLen - localRange.location;
[self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
/* Build output string */
result = [NSString stringWithCharacters:buffer length:bufferSize];
NSDeallocateMemoryPages(buffer, bufferSize);
return result;
}
@end
#ifdef main
# undef main
#endif
/* Main entry point to executable - should *not* be SDL_main! */
int main (int argc, char **argv)
{
/* Copy the arguments into a global variable */
/* This is passed if we are launched by double-clicking */
if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
gArgv[0] = argv[0];
gArgv[1] = NULL;
gArgc = 1;
gFinderLaunch = YES;
} else {
int i;
gArgc = argc;
gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
for (i = 0; i <= argc; i++)
gArgv[i] = argv[i];
gFinderLaunch = NO;
}
#if SDL_USE_NIB_FILE
NSApplicationMain (argc, argv);
#else
CustomApplicationMain (argc, argv);
#endif
return 0;
}

View File

@ -0,0 +1,344 @@
/*
* audio_sdl.cpp - Audio support, SDL implementation
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "sysdeps.h"
#include "cpu_emulation.h"
#include "main.h"
#include "prefs.h"
#include "user_strings.h"
#include "audio.h"
#include "audio_defs.h"
#include <SDL_mutex.h>
#include <SDL_audio.h>
#define DEBUG 0
#include "debug.h"
#if defined(BINCUE)
#include "bincue_unix.h"
#endif
#define MAC_MAX_VOLUME 0x0100
// The currently selected audio parameters (indices in audio_sample_rates[] etc. vectors)
static int audio_sample_rate_index = 0;
static int audio_sample_size_index = 0;
static int audio_channel_count_index = 0;
// Global variables
static SDL_sem *audio_irq_done_sem = NULL; // Signal from interrupt to streaming thread: data block read
static uint8 silence_byte; // Byte value to use to fill sound buffers with silence
static uint8 *audio_mix_buf = NULL;
static int audio_volume = SDL_MIX_MAXVOLUME;
static bool audio_mute = false;
// Prototypes
static void stream_func(void *arg, uint8 *stream, int stream_len);
/*
* Initialization
*/
// Set AudioStatus to reflect current audio stream format
static void set_audio_status_format(void)
{
AudioStatus.sample_rate = audio_sample_rates[audio_sample_rate_index];
AudioStatus.sample_size = audio_sample_sizes[audio_sample_size_index];
AudioStatus.channels = audio_channel_counts[audio_channel_count_index];
}
// Init SDL audio system
static bool open_sdl_audio(void)
{
// SDL supports a variety of twisted little audio formats, all different
if (audio_sample_sizes.empty()) {
audio_sample_rates.push_back(11025 << 16);
audio_sample_rates.push_back(22050 << 16);
audio_sample_rates.push_back(44100 << 16);
audio_sample_sizes.push_back(8);
audio_sample_sizes.push_back(16);
audio_channel_counts.push_back(1);
audio_channel_counts.push_back(2);
// Default to highest supported values
audio_sample_rate_index = audio_sample_rates.size() - 1;
audio_sample_size_index = audio_sample_sizes.size() - 1;
audio_channel_count_index = audio_channel_counts.size() - 1;
}
SDL_AudioSpec audio_spec;
audio_spec.freq = audio_sample_rates[audio_sample_rate_index] >> 16;
audio_spec.format = (audio_sample_sizes[audio_sample_size_index] == 8) ? AUDIO_U8 : AUDIO_S16MSB;
audio_spec.channels = audio_channel_counts[audio_channel_count_index];
audio_spec.samples = 4096;
audio_spec.callback = stream_func;
audio_spec.userdata = NULL;
// Open the audio device, forcing the desired format
if (SDL_OpenAudio(&audio_spec, NULL) < 0) {
fprintf(stderr, "WARNING: Cannot open audio: %s\n", SDL_GetError());
return false;
}
#if defined(BINCUE)
OpenAudio_bincue(audio_spec.freq, audio_spec.format, audio_spec.channels,
audio_spec.silence);
#endif
char driver_name[32];
printf("Using SDL/%s audio output\n", SDL_AudioDriverName(driver_name, sizeof(driver_name) - 1));
silence_byte = audio_spec.silence;
SDL_PauseAudio(0);
// Sound buffer size = 4096 frames
audio_frames_per_block = audio_spec.samples;
audio_mix_buf = (uint8*)malloc(audio_spec.size);
return true;
}
static bool open_audio(void)
{
// Try to open SDL audio
if (!open_sdl_audio()) {
WarningAlert(GetString(STR_NO_AUDIO_WARN));
return false;
}
// Device opened, set AudioStatus
set_audio_status_format();
// Everything went fine
audio_open = true;
return true;
}
void AudioInit(void)
{
// Init audio status and feature flags
AudioStatus.sample_rate = 44100 << 16;
AudioStatus.sample_size = 16;
AudioStatus.channels = 2;
AudioStatus.mixer = 0;
AudioStatus.num_sources = 0;
audio_component_flags = cmpWantsRegisterMessage | kStereoOut | k16BitOut;
// Sound disabled in prefs? Then do nothing
if (PrefsFindBool("nosound"))
return;
// Init semaphore
audio_irq_done_sem = SDL_CreateSemaphore(0);
// Open and initialize audio device
open_audio();
}
/*
* Deinitialization
*/
static void close_audio(void)
{
// Close audio device
SDL_CloseAudio();
free(audio_mix_buf);
audio_mix_buf = NULL;
audio_open = false;
}
void AudioExit(void)
{
// Close audio device
close_audio();
// Delete semaphore
if (audio_irq_done_sem)
SDL_DestroySemaphore(audio_irq_done_sem);
}
/*
* First source added, start audio stream
*/
void audio_enter_stream()
{
}
/*
* Last source removed, stop audio stream
*/
void audio_exit_stream()
{
}
/*
* Streaming function
*/
static void stream_func(void *arg, uint8 *stream, int stream_len)
{
if (AudioStatus.num_sources) {
// Trigger audio interrupt to get new buffer
D(bug("stream: triggering irq\n"));
SetInterruptFlag(INTFLAG_AUDIO);
TriggerInterrupt();
D(bug("stream: waiting for ack\n"));
SDL_SemWait(audio_irq_done_sem);
D(bug("stream: ack received\n"));
// Get size of audio data
uint32 apple_stream_info = ReadMacInt32(audio_data + adatStreamInfo);
if (apple_stream_info && !audio_mute) {
int work_size = ReadMacInt32(apple_stream_info + scd_sampleCount) * (AudioStatus.sample_size >> 3) * AudioStatus.channels;
D(bug("stream: work_size %d\n", work_size));
if (work_size > stream_len)
work_size = stream_len;
if (work_size == 0)
goto silence;
// Send data to audio device
Mac2Host_memcpy(audio_mix_buf, ReadMacInt32(apple_stream_info + scd_buffer), work_size);
memset((uint8 *)stream, silence_byte, stream_len);
SDL_MixAudio(stream, audio_mix_buf, work_size, audio_volume);
D(bug("stream: data written\n"));
} else
goto silence;
} else {
// Audio not active, play silence
silence: memset(stream, silence_byte, stream_len);
}
#if defined(BINCUE)
MixAudio_bincue(stream, stream_len);
#endif
}
/*
* MacOS audio interrupt, read next data block
*/
void AudioInterrupt(void)
{
D(bug("AudioInterrupt\n"));
// Get data from apple mixer
if (AudioStatus.mixer) {
M68kRegisters r;
r.a[0] = audio_data + adatStreamInfo;
r.a[1] = AudioStatus.mixer;
Execute68k(audio_data + adatGetSourceData, &r);
D(bug(" GetSourceData() returns %08lx\n", r.d[0]));
} else
WriteMacInt32(audio_data + adatStreamInfo, 0);
// Signal stream function
SDL_SemPost(audio_irq_done_sem);
D(bug("AudioInterrupt done\n"));
}
/*
* Set sampling parameters
* "index" is an index into the audio_sample_rates[] etc. vectors
* It is guaranteed that AudioStatus.num_sources == 0
*/
bool audio_set_sample_rate(int index)
{
close_audio();
audio_sample_rate_index = index;
return open_audio();
}
bool audio_set_sample_size(int index)
{
close_audio();
audio_sample_size_index = index;
return open_audio();
}
bool audio_set_channels(int index)
{
close_audio();
audio_channel_count_index = index;
return open_audio();
}
/*
* Get/set volume controls (volume values received/returned have the left channel
* volume in the upper 16 bits and the right channel volume in the lower 16 bits;
* both volumes are 8.8 fixed point values with 0x0100 meaning "maximum volume"))
*/
bool audio_get_main_mute(void)
{
return audio_mute;
}
uint32 audio_get_main_volume(void)
{
uint32 chan = (audio_volume * MAC_MAX_VOLUME / SDL_MIX_MAXVOLUME);
return (chan << 16) + chan;
}
bool audio_get_speaker_mute(void)
{
return audio_mute;
}
uint32 audio_get_speaker_volume(void)
{
return audio_get_main_volume();
}
void audio_set_main_mute(bool mute)
{
audio_mute = mute;
}
void audio_set_main_volume(uint32 vol)
{
// We only have one-channel volume right now.
uint32 avg = ((vol >> 16) + (vol & 0xffff)) / 2;
if (avg > MAC_MAX_VOLUME)
avg = MAC_MAX_VOLUME;
audio_volume = avg * SDL_MIX_MAXVOLUME / MAC_MAX_VOLUME;
}
void audio_set_speaker_mute(bool mute)
{
}
void audio_set_speaker_volume(uint32 vol)
{
}

View File

@ -0,0 +1,464 @@
# /usr/share/BasiliskII/keycodes
#
# Basilisk II (C) 1997-2005 Christian Bauer
#
# This file is used to translate the (server-specific) scancodes to
# Mac keycodes depending on the window server being used.
#
# The format of this file is as follows:
#
# sdl <driver string>
# <SDL scancode> <Mac keycode>
# <SDL scancode> <Mac keycode>
# <SDL scancode> <Mac keycode>
# ...
# sdl <driver string>
# <SDL scancode> <Mac keycode>
# <SDL scancode> <Mac keycode>
# ...
#
# The "driver string" must match the first part of the SDL driver vendor
# description as reported by SDL_VideoDriverName(). If a match is found,
# the keycode translation table is constructed from the following
# lines. Each line contains an SDL scancode followed by its associated
# Mac keycode. Both keycodes have to be given in decimal. Lines
# beginning with "#" or ";" are treated as comments and ignored.
#
#
# X11 server
#
sdl x11
sdl dga
9 53 # Esc
67 122 # F1
68 120 # F2
69 99 # F3
70 118 # F4
71 96 # F5
72 97 # F6
73 98 # F7
74 100 # F8
75 101 # F9
76 109 # F10
95 103 # F11
96 111 # F12
111 105 # PrintScrn
78 107 # Scroll Lock
110 113 # Pause
49 50 # `
10 18 # 1
11 19 # 2
12 20 # 3
13 21 # 4
14 23 # 5
15 22 # 6
16 26 # 7
17 28 # 8
18 25 # 9
19 29 # 0
20 27 # -
21 24 # =
22 51 # Backspace
106 114 # Insert
97 115 # Home
99 116 # Page Up
77 71 # Num Lock
112 75 # KP /
63 67 # KP *
82 78 # KP -
23 48 # Tab
24 12 # Q
25 13 # W
26 14 # E
27 15 # R
28 17 # T
29 16 # Y
30 32 # U
31 34 # I
32 31 # O
33 35 # P
34 33 # [
35 30 # ]
36 36 # Return
107 117 # Delete
103 119 # End
105 121 # Page Down
79 89 # KP 7
80 91 # KP 8
81 92 # KP 9
86 69 # KP +
66 57 # Caps Lock
38 0 # A
39 1 # S
40 2 # D
41 3 # F
42 5 # G
43 4 # H
44 38 # J
45 40 # K
46 37 # L
47 41 # ;
48 39 # '
83 86 # KP 4
84 87 # KP 5
85 88 # KP 6
50 56 # Shift Left
94 50 # International
52 6 # Z
53 7 # X
54 8 # C
55 9 # V
56 11 # B
57 45 # N
58 46 # M
59 43 # ,
60 47 # .
61 44 # /
62 56 # Shift Right
51 42 # \
98 62 # Cursor Up
87 83 # KP 1
88 84 # KP 2
89 85 # KP 3
108 76 # KP Enter
37 54 # Ctrl Left
115 58 # Logo Left (-> Option)
64 55 # Alt Left (-> Command)
65 49 # Space
113 55 # Alt Right (-> Command)
116 58 # Logo Right (-> Option)
117 50 # Menu (-> International)
109 54 # Ctrl Right
100 59 # Cursor Left
104 61 # Cursor Down
102 60 # Cursor Right
90 82 # KP 0
91 65 # KP .
#
# Linux Framebuffer Console
#
sdl fbcon
1 53 # Esc
59 122 # F1
60 120 # F2
61 99 # F3
62 118 # F4
63 96 # F5
64 97 # F6
65 98 # F7
66 100 # F8
67 101 # F9
68 109 # F10
87 103 # F11
88 111 # F12
99 105 # PrintScrn
70 107 # Scroll Lock
119 113 # Pause
41 50 # `
2 18 # 1
3 19 # 2
4 20 # 3
5 21 # 4
6 23 # 5
7 22 # 6
8 26 # 7
9 28 # 8
10 25 # 9
11 29 # 0
12 27 # -
13 24 # =
14 51 # Backspace
110 114 # Insert
102 115 # Home
104 116 # Page Up
69 71 # Num Lock
98 75 # KP /
55 67 # KP *
74 78 # KP -
15 48 # Tab
16 12 # Q
17 13 # W
18 14 # E
19 15 # R
20 17 # T
21 16 # Y
22 32 # U
23 34 # I
24 31 # O
25 35 # P
26 33 # [
27 30 # ]
28 36 # Return
111 117 # Delete
107 119 # End
109 121 # Page Down
71 89 # KP 7
72 91 # KP 8
73 92 # KP 9
78 69 # KP +
58 57 # Caps Lock
30 0 # A
31 1 # S
32 2 # D
33 3 # F
34 5 # G
35 4 # H
36 38 # J
37 40 # K
38 37 # L
39 41 # ;
40 39 # '
75 86 # KP 4
76 87 # KP 5
77 88 # KP 6
42 56 # Shift Left
86 50 # International
44 6 # Z
45 7 # X
46 8 # C
47 9 # V
48 11 # B
49 45 # N
50 46 # M
51 43 # ,
52 47 # .
53 44 # /
54 56 # Shift Right
43 42 # \
103 62 # Cursor Up
79 83 # KP 1
80 84 # KP 2
81 85 # KP 3
96 76 # KP Enter
29 54 # Ctrl Left
125 58 # Logo Left (-> Option)
56 55 # Alt Left (-> Command)
57 49 # Space
100 55 # Alt Right (-> Command)
126 58 # Logo Right (-> Option)
97 54 # Ctrl Right
105 59 # Cursor Left
108 61 # Cursor Down
106 60 # Cursor Right
82 82 # KP 0
83 65 # KP .
#
# Quartz (1:1 translation actually)
#
sdl Quartz
53 53 # Esc
122 122 # F1
120 120 # F2
99 99 # F3
118 118 # F4
96 96 # F5
97 97 # F6
98 98 # F7
100 100 # F8
101 101 # F9
109 109 # F10
103 103 # F11
111 111 # F12
105 105 # F13/PrintScrn
107 107 # F14/Scroll Lock
113 113 # F15/Pause
10 10 # `
18 18 # 1
19 19 # 2
20 20 # 3
21 21 # 4
23 23 # 5
22 22 # 6
26 26 # 7
28 28 # 8
25 25 # 9
29 29 # 0
27 27 # -
24 24 # =
51 51 # Backspace
114 114 # Help/Insert
115 115 # Home
116 116 # Page Up
71 71 # Num Lock
81 81 # KP =
75 75 # KP /
67 67 # KP *
48 48 # Tab
12 12 # Q
13 13 # W
14 14 # E
15 15 # R
17 17 # T
16 16 # Y
32 32 # U
34 34 # I
31 31 # O
35 35 # P
33 33 # [
30 30 # ]
36 36 # Return
117 117 # Delete
119 119 # End
121 121 # Page Down
89 89 # KP 7
91 91 # KP 8
92 92 # KP 9
78 78 # KP -
57 57 # Caps Lock
0 0 # A
1 1 # S
2 2 # D
3 3 # F
5 5 # G
4 4 # H
38 38 # J
40 40 # K
37 37 # L
41 41 # ;
39 39 # '
42 42 # \
86 86 # KP 4
87 87 # KP 5
88 88 # KP 6
69 69 # KP +
56 56 # Shift
50 50 # International
6 6 # Z
7 7 # X
8 8 # C
9 9 # V
11 11 # B
45 45 # N
46 46 # M
43 43 # ,
47 47 # .
44 44 # /
126 62 # Cursor Up
123 59 # Cursor Left
125 61 # Cursor Down
124 60 # Cursor Right
83 83 # KP 1
84 84 # KP 2
85 85 # KP 3
76 76 # KP Enter
54 54 # Ctrl
58 58 # Option
55 55 # Command
54 54 # Ctrl Left
49 49 # Space
82 82 # KP 0
65 65 # KP .
#
# Windows
#
sdl windib
sdl directx
1 53 # Esc
59 122 # F1
60 120 # F2
61 99 # F3
62 118 # F4
63 96 # F5
64 97 # F6
65 98 # F7
66 100 # F8
67 101 # F9
68 109 # F10
87 103 # F11
88 111 # F12
183 105 # PrintScrn
70 107 # Scroll Lock
197 113 # Pause
41 50 # `
2 18 # 1
3 19 # 2
4 20 # 3
5 21 # 4
6 23 # 5
7 22 # 6
8 26 # 7
9 28 # 8
10 25 # 9
11 29 # 0
12 27 # -
13 24 # =
14 51 # Backspace
210 114 # Insert
199 115 # Home
201 116 # Page Up
69 71 # Num Lock
181 75 # KP /
55 67 # KP *
74 78 # KP -
15 48 # Tab
16 12 # Q
17 13 # W
18 14 # E
19 15 # R
20 17 # T
21 16 # Y
22 32 # U
23 34 # I
24 31 # O
25 35 # P
26 33 # [
27 30 # ]
28 36 # Return
211 117 # Delete
207 119 # End
209 121 # Page Down
71 89 # KP 7
72 91 # KP 8
73 92 # KP 9
78 69 # KP +
58 57 # Caps Lock
30 0 # A
31 1 # S
32 2 # D
33 3 # F
34 5 # G
35 4 # H
36 38 # J
37 40 # K
38 37 # L
39 41 # ;
40 39 # '
75 86 # KP 4
76 87 # KP 5
77 88 # KP 6
42 56 # Shift Left
86 50 # International
44 6 # Z
45 7 # X
46 8 # C
47 9 # V
48 11 # B
49 45 # N
50 46 # M
51 43 # ,
52 47 # .
53 44 # /
54 56 # Shift Right
43 42 # \
200 62 # Cursor Up
79 83 # KP 1
80 84 # KP 2
81 85 # KP 3
156 76 # KP Enter
29 54 # Ctrl Left
219 58 # Logo Left (-> Option)
56 55 # Alt Left (-> Command)
57 49 # Space
184 55 # Alt Right (-> Command)
220 58 # Logo Right (-> Option)
221 50 # Menu (-> International)
157 54 # Ctrl Right
203 59 # Cursor Left
208 61 # Cursor Down
205 60 # Cursor Right
82 82 # KP 0
83 65 # KP .

2264
SheepShaver/src/SDL/video_sdl.cpp Executable file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,254 @@
/*
* lowmem.c - enable access to low memory globals on Darwin
*
* Copyright (c) 2003 Michael Z. Sliczniak
*
* Basilisk II (C) 1997-2005 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <mach/vm_prot.h>
#include <mach-o/loader.h>
#include <mach-o/fat.h>
static const char progname[] = "lowmem";
static const char *filename;
static int do_swap = 0;
static uint32_t target_uint32(uint32_t value)
{
if (do_swap)
value = OSSwapInt32(value);
return value;
}
void pagezero_32(struct mach_header *machhead)
{
struct segment_command *sc_cmd;
if (target_uint32(machhead->filetype) != MH_EXECUTE) {
(void)fprintf(stderr, "%s: %s does not appear to be an executable file\n",
progname, filename);
exit(1);
}
if (machhead->ncmds == 0) {
(void)fprintf(stderr, "%s: %s does not contain any load commands\n",
progname, filename);
exit(1);
}
sc_cmd = (void *)&machhead[1];
if (target_uint32(sc_cmd->cmd) != LC_SEGMENT){
(void)fprintf(stderr, "%s: load segment not first command in %s\n",
progname, filename);
exit(1);
}
if (strncmp(sc_cmd->segname, "__PAGEZERO", sizeof (*sc_cmd->segname))) {
(void)fprintf(stderr, "%s: zero page not first segment in %s\n",
progname, filename);
exit(1);
}
/* change the permissions */
sc_cmd->maxprot = target_uint32(VM_PROT_ALL);
sc_cmd->initprot = target_uint32(VM_PROT_ALL);
#ifdef MH_PIE
/* disable pie in header */
machhead->flags = target_uint32(target_uint32(machhead->flags) & ~MH_PIE);
#endif
}
#if defined(MH_MAGIC_64)
void pagezero_64(struct mach_header_64 *machhead)
{
struct segment_command_64 *sc_cmd;
if (target_uint32(machhead->filetype) != MH_EXECUTE) {
(void)fprintf(stderr, "%s: %s does not appear to be an executable file\n",
progname, filename);
exit(1);
}
if (machhead->ncmds == 0) {
(void)fprintf(stderr, "%s: %s does not contain any load commands\n",
progname, filename);
exit(1);
}
sc_cmd = (void *)&machhead[1];
if (target_uint32(sc_cmd->cmd) != LC_SEGMENT_64) {
(void)fprintf(stderr, "%s: load segment not first command in %s\n",
progname, filename);
exit(1);
}
if (strncmp(sc_cmd->segname, "__PAGEZERO", sizeof(*sc_cmd->segname))) {
(void)fprintf(stderr, "%s: zero page not first segment in %s\n",
progname, filename);
exit(1);
}
/* change the permissions */
// sc_cmd->maxprot = target_uint32(VM_PROT_ALL);
// sc_cmd->initprot = target_uint32(VM_PROT_ALL);
}
#endif
/*
* Under Mach there is very little assumed about the memory map of object
* files. It is the job of the loader to create the initial memory map of an
* executable. In a Mach-O executable there will be numerous loader commands
* that the loader must process. Some of these will create the initial memory
* map used by the executable. Under Darwin the static object file linker,
* ld, automatically adds the __PAGEZERO segment to all executables. The
* default size of this segment is the page size of the target system and
* the initial and maximum permissions are set to allow no access. This is so
* that all programs fault on a NULL pointer dereference. Arguably this is
* incorrect and the maximum permissions shoould be rwx so that programs can
* change this default behavior. Then programs could be written that assume
* a null string at the null address, which was the convention on some
* systems. In our case we need to have 8K mapped at zero for the low memory
* globals and this program modifies the segment load command in the
* basiliskII executable so that it can be used for data.
*/
int
main(int argc, const char *argv[])
{
int fd;
char *addr;
size_t file_size;
struct mach_header *machhead;
#if defined(MH_MAGIC_64)
struct mach_header_64 *machhead64;
#endif
struct fat_header *fathead;
struct stat f;
if (argc != 2) {
(void)fprintf(stderr, "Usage: %s executable\n", progname);
exit(1);
}
filename = argv[1];
if (stat(filename, &f)) {
(void)fprintf(stderr, "%s: could not stat %s: %s\n",
progname, filename, strerror(errno));
exit(1);
}
file_size = (size_t) f.st_size;
fd = open(filename, O_RDWR, 0);
if (fd == -1) {
(void)fprintf(stderr, "%s: could not open %s: %s\n",
progname, filename, strerror(errno));
exit(1);
}
/*
* Size does not really matter, it will be rounded-up to a multiple
* of the page size automatically.
*/
addr = mmap(NULL, file_size, PROT_READ | PROT_WRITE,
MAP_FILE | MAP_SHARED, fd, 0);
if (addr == NULL || addr == MAP_FAILED) {
(void)fprintf(stderr, "%s: could not mmap %s: %s\n",
progname, filename, strerror(errno));
exit(1);
}
/*
* Check to see if the Mach-O magic bytes are in the header.
*/
machhead = (void *)addr;
#if defined(MH_MAGIC_64)
machhead64 = (void *)addr;
#endif
fathead = (void *)addr;
#if defined(MH_MAGIC_64)
do_swap = machhead->magic == MH_CIGAM || fathead->magic == FAT_CIGAM || machhead64->magic == MH_CIGAM_64;
#else
do_swap = machhead->magic == MH_CIGAM || fathead->magic == FAT_CIGAM;
#endif
if (target_uint32(machhead->magic) == MH_MAGIC) {
pagezero_32(machhead);
#if defined(MH_MAGIC_64)
} else if (target_uint32(machhead64->magic) == MH_MAGIC_64) {
pagezero_64(machhead64);
#endif
} else if (target_uint32(fathead->magic) == FAT_MAGIC) {
struct fat_arch *arch = (void *)&fathead[1];
int saved_swap = do_swap;
int i;
for (i = 0; i < target_uint32(fathead->nfat_arch); ++i, ++arch) {
machhead = (void *)(addr + target_uint32(arch->offset));
#if defined(MH_MAGIC_64)
machhead64 = (void *)(addr + target_uint32(arch->offset));
#endif
#if defined(MH_MAGIC_64)
do_swap = machhead->magic == MH_CIGAM || machhead64->magic == MH_CIGAM_64;
#else
do_swap = machhead->magic == MH_CIGAM;
#endif
if (target_uint32(machhead->magic) == MH_MAGIC) {
pagezero_32(machhead);
#if defined(MH_MAGIC_64)
} else if (target_uint32(machhead64->magic) == MH_MAGIC_64) {
pagezero_64(machhead64);
#endif
} else {
(void)fprintf(stderr, "%s: %s does not appear to be a Mach-O object file\n",
progname, filename);
exit(1);
}
do_swap = saved_swap;
}
} else {
(void)fprintf(stderr, "%s: %s does not appear to be a Mach-O object file\n",
progname, filename);
exit(1);
}
/*
* We do not make __PAGEZERO 8K in this program because then
* all of the offsets would be wrong in the object file after
* this segment. Instead we use the -pagezero_size option
* to link the executable.
*/
if (msync(addr, file_size, MS_SYNC) == -1) {
(void)fprintf(stderr, "%s: could not sync %s: %s\n",
progname, filename, strerror(errno));
exit(1);
}
if (munmap(addr, file_size) == -1) {
(void)fprintf(stderr, "%s: could not unmap %s: %s\n",
progname, filename, strerror(errno));
exit(1);
}
(void)close(fd);
exit(0);
}