2015-04-01 12:43:50 +00:00
|
|
|
/*
|
2016-04-03 09:56:10 +00:00
|
|
|
* Copyright (c) 2015-2016 Carsten Sonne Larsen
|
2015-04-01 12:43:50 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mem.h"
|
|
|
|
#include "clib.h"
|
|
|
|
#include "localize/start.h"
|
|
|
|
#include "system/program.h"
|
|
|
|
#include "system/program_stdc.h"
|
|
|
|
#include "system/program_amiga.h"
|
|
|
|
#include "system/program_test.h"
|
|
|
|
#include "system/console.h"
|
|
|
|
#include "system/console_stdc.h"
|
|
|
|
#include "system/console_amiga.h"
|
|
|
|
#include "system/language.h"
|
|
|
|
#include "system/language_stdc.h"
|
|
|
|
#include "system/language_amiga.h"
|
2015-04-15 12:41:33 +00:00
|
|
|
#include "system/language_posix.h"
|
2015-04-01 12:43:50 +00:00
|
|
|
#include "system/filesystem.h"
|
|
|
|
#include "system/filesystem_stdc.h"
|
|
|
|
#include "system/filesystem_amiga.h"
|
|
|
|
#include "system/preferences.h"
|
|
|
|
#include "system/preferences_stdc.h"
|
|
|
|
#include "system/preferences_amiga.h"
|
|
|
|
#include "system/window_amiga.h"
|
|
|
|
#include "system/graph_amiga.h"
|
2015-04-13 21:44:17 +00:00
|
|
|
#include "system/base/io.h"
|
|
|
|
|
|
|
|
#ifdef AMIGA
|
|
|
|
#include <exec/types.h>
|
|
|
|
#include <exec/io.h>
|
|
|
|
#include <exec/memory.h>
|
|
|
|
#include <libraries/dos.h>
|
|
|
|
#include <graphics/gfxbase.h>
|
|
|
|
#include <intuition/intuition.h>
|
|
|
|
#include <intuition/intuitionbase.h>
|
|
|
|
#include <devices/conunit.h>
|
|
|
|
#include <devices/console.h>
|
|
|
|
#include <clib/exec_protos.h>
|
|
|
|
#include <clib/alib_protos.h>
|
|
|
|
#include <clib/dos_protos.h>
|
|
|
|
#include <clib/intuition_protos.h>
|
|
|
|
#include <clib/locale_protos.h>
|
|
|
|
#endif
|
2015-04-01 12:43:50 +00:00
|
|
|
|
2015-04-07 19:18:39 +00:00
|
|
|
const char *vers = TXTDOSVERSION;
|
2015-04-13 21:44:17 +00:00
|
|
|
class Program *Program = NULL;
|
|
|
|
#ifdef AMIGA
|
|
|
|
static struct DosBase *DosBase = NULL;
|
|
|
|
static struct GfxBase *GfxBase = NULL;
|
|
|
|
static struct LocaleBase *LocaleBase = NULL;
|
|
|
|
static struct IntuitionBase *IntuitionBase = NULL;
|
|
|
|
#endif
|
2015-04-01 12:43:50 +00:00
|
|
|
|
|
|
|
class Program* CreateProgram(int argc, char **argv) {
|
|
|
|
#ifdef WITHTEST
|
|
|
|
if (argc == 2 && StrIsEqual(argv[1], "test")) {
|
2015-04-13 21:44:17 +00:00
|
|
|
return new TestProgram();
|
2015-04-01 12:43:50 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
#ifdef AMIGA
|
2015-04-13 21:44:17 +00:00
|
|
|
IntuitionBase = (struct IntuitionBase*)OpenLibrary(INTUITION_NAME, INTUITION_REV);
|
|
|
|
GfxBase = (struct GfxBase*)OpenLibrary(GRAPHICS_NAME, GRAPHICS_REV);
|
|
|
|
|
|
|
|
if (IntuitionBase != NULL && GfxBase != NULL) {
|
|
|
|
return new AmigaProgram();
|
|
|
|
} else {
|
|
|
|
return new StandardProgram();
|
|
|
|
}
|
2015-04-01 12:43:50 +00:00
|
|
|
#else
|
2015-04-13 21:44:17 +00:00
|
|
|
return new StandardProgram();
|
2015-04-01 12:43:50 +00:00
|
|
|
#endif
|
|
|
|
}
|
2015-04-13 21:44:17 +00:00
|
|
|
return NULL;
|
2015-04-01 12:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class Language* CreateLanguage()
|
|
|
|
{
|
2015-04-15 12:41:33 +00:00
|
|
|
#ifdef UNIX
|
|
|
|
return new PosixLanguage();
|
|
|
|
#endif
|
2015-04-01 12:43:50 +00:00
|
|
|
#ifdef AMIGA
|
2015-04-13 21:44:17 +00:00
|
|
|
LocaleBase = (struct LocaleBase*)OpenLibrary(LOCALE_NAME, LOCALE_REV);
|
|
|
|
if (LocaleBase != NULL) {
|
|
|
|
return new AmigaLanguage();
|
|
|
|
} else
|
2015-04-01 12:43:50 +00:00
|
|
|
#endif
|
2015-04-13 21:44:17 +00:00
|
|
|
{
|
|
|
|
return new StandardLanguage();
|
|
|
|
}
|
2015-04-01 12:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class PreferencesBase* CreatePreferences()
|
|
|
|
{
|
|
|
|
#ifdef AMIGA
|
|
|
|
return new AmigaPreferences();
|
|
|
|
#else
|
|
|
|
return new StandardPreferences();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
class FilesystemBase* CreateFilesystem()
|
|
|
|
{
|
|
|
|
#ifdef AMIGA
|
2015-04-13 21:44:17 +00:00
|
|
|
DosBase = (struct DosBase*)OpenLibrary(AMIGADOS_NAME, AMIGADOS_REV);
|
|
|
|
if (DosBase == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-04-01 12:43:50 +00:00
|
|
|
return new AmigaFilesystem();
|
|
|
|
#else
|
|
|
|
return new StandardFilesystem();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphWindow* CreateGraphWindow() {
|
|
|
|
#ifdef AMIGA
|
|
|
|
return new AmigaGraphWindow();
|
|
|
|
#else
|
|
|
|
return NOMEM;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteToShell(const char *out) {
|
|
|
|
#ifdef AMIGA
|
|
|
|
Write(Output(), (APTR)out, StrLen(out));
|
|
|
|
Write(Output(), (APTR)NORMALTEXT, StrLen(NORMALTEXT));
|
|
|
|
#else
|
|
|
|
printf("%s%s", out, NORMALTEXT);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-04-13 21:44:17 +00:00
|
|
|
void Cleanup()
|
|
|
|
{
|
|
|
|
#ifdef AMIGA
|
|
|
|
if (DosBase != NULL) {
|
|
|
|
CloseLibrary((struct Library*)DosBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LocaleBase != NULL) {
|
|
|
|
CloseLibrary((struct Library*)LocaleBase);
|
|
|
|
}
|
2015-04-01 12:43:50 +00:00
|
|
|
|
2015-04-13 21:44:17 +00:00
|
|
|
if (GfxBase != NULL) {
|
|
|
|
CloseLibrary((struct Library*)GfxBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IntuitionBase != NULL) {
|
|
|
|
CloseLibrary((struct Library*)IntuitionBase);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
delete Program;
|
|
|
|
FreeAllSafe();
|
|
|
|
}
|