Files
nethack/outdated/sys/amiga/amidos.c
nhmall cb223271cb add cross-compile recipe for amiga
Disclaimer: This is a minimal recipe, just to get someone else
started if they have a desire to get a full cross-compile of
NetHack-3.7 going for the Amiga. Some NetHack code bitrot was
corrected, and it does seem able to compile the game itself
to a point. See caveats below.

- If you want to obtain the cross-compiler and tools/libs for Amiga
         https://github.com/bebbo/amiga-gcc

  To our knowledge, a pre-built copy isn't available, so you have to
  obtain the source via git and build it on your system.

  The build prerequisite packages for Ubuntu are easily obtained:

    sudo apt install make wget git gcc g++ lhasa libgmp-dev \
        libmpfr-dev libmpc-dev flex bison gettext texinfo ncurses-dev \
        autoconf rsync

  The build prerequisite packages for macOS are apparently easily
  obtained via homebrew, but that was not tested:

    brew install bash wget make lhasa gmp mpfr libmpc flex gettext \
    texinfo gcc make autoconf

  After installing the prerequite packages and the cross-compiler
  it was a straightforward build:

        git clone https://github.com/bebbo/amiga-gcc.git
        cd amiga-gcc
        make update
    [Note that you may have to take ownership of the files in the
     bebbo repo via chown before succesfully carrying out the next
     steps]
        make clean
        make clean-prefix
        date; make all -j3 >&b.log; date
  The compiler pieces are installed in /opt/amiga by default which
  was satisfactory for our initial attempt, but if you want you can
  alter the prefix before you build if you want. That is all
  spelled out on the page at: https://github.com/bebbo/amiga-gcc

  The Amiga cross-compile can then be carried out by specifying
  CROSS_TO_AMIGA=1 on the make command line.

  For example:
       make CROSS_TO_AMIGA=1 all
       make CROSS_TO_AMIGA=1 package

You can explicitly include tty and curses support if desired, otherwise
you'll end up with a tty-only cross-compile build. The SDL1 pdcurses
support has not been tested.

       make WANT_WIN_TTY=1 WANT_WIN_CURSES=1 CROSS_TO_AMIGA=1 all

Also note that building the amiga targets using the make command
above, does not preclude you from building local linux or macOS
targets as well. Just drop the CROSS_TO_AMIGA=1 from the make
command line.

The cross-compiler hints additions are enclosed inside ifdef sections
and won't interfere with the non-cross-compile build in that case.

CAVEATS: The original NetHack Amiga build steps included the source for
some utilities that were built and executed on the amiga: txt2iff and
xpm2iff as part of the NetHack build procedure on amiga. Those did not
compile out-of-the-box on the linux host. They will either have to be:
    - ported to build and run on the linux or macOS cross-compile host

   or

    - their functionality will have to be rolled into amiga NetHack
      itself and executed on the target Amiga the first time the game
      is run, perhaps.

Good luck amiga aficionados, perhaps you'll be able to take this
initial effort forward and get NetHack-3.7 available on the amiga or
amiga-emulator. Let us know if you do, and we can roll changes in
if you provide them.
2020-09-28 17:30:22 -04:00

516 lines
12 KiB
C

/* NetHack 3.6 amidos.c $NHDT-Date: 1432512796 2015/05/25 00:13:16 $ $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
/* Copyright (c) Olaf Seibert, Nijmegen, The Netherlands, 1988,1990. */
/* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1991,1992,1993,1996. */
/* NetHack may be freely redistributed. See license for details. */
/*
* An assortment of imitations of cheap plastic MSDOS and Unix functions.
*/
#include "hack.h"
#include "winami.h"
/* Defined in config.h, let's undefine it here (static function below) */
#undef strcmpi
#include <libraries/dos.h>
#include <exec/execbase.h>
#include <intuition/intuition.h>
#undef COUNT
#if defined(__SASC_60) || defined(__GNUC__)
#include <proto/exec.h>
#include <proto/dos.h>
#endif
#ifdef AZTEC_50
#include <functions.h>
#undef strcmpi
#endif
/* Prototypes */
#ifndef AMIGA_CROSS
#include "NH:sys/amiga/amiwind.p"
#include "NH:sys/amiga/winami.p"
#include "NH:sys/amiga/amidos.p"
#else
#include "winami.p"
#include "winami.p"
#include "amidos.p"
#endif
extern char Initialized;
extern struct window_procs amii_procs;
struct ami_sysflags sysflags = {0};
#ifndef __SASC_60
int Enable_Abort = 0; /* for stdio package */
#endif
/* Initial path, so we can find NetHack.cnf */
char PATH[PATHLEN] = "NetHack:";
static boolean record_exists(void);
void
flushout()
{
(void) fflush(stdout);
}
#ifndef getuid
getuid()
{
return 1;
}
#endif
#ifndef getlogin
char *
getlogin()
{
return ((char *) NULL);
}
#endif
#ifndef AZTEC_50
int
abs(x)
int x;
{
return x < 0 ? -x : x;
}
#endif
#ifdef SHELL
int
dosh()
{
int i;
char buf[BUFSZ];
extern struct ExecBase *SysBase;
/* Only under 2.0 and later ROMs do we have System() */
if (SysBase->LibNode.lib_Version >= 37 && !amibbs) {
getlin("Enter CLI Command...", buf);
if (buf[0] != '\033')
i = System(buf, NULL);
} else {
i = 0;
pline("No mysterious force prevented you from using multitasking.");
}
return i;
}
#endif /* SHELL */
#ifdef MFLOPPY
#include <ctype.h>
#define Sprintf (void) sprintf
#define EXTENSION 72
/*
* This routine uses an approximation of the free bytes on a disk.
* How large a file you can actually write depends on the number of
* extension blocks you need for it.
* In each extenstion block there are maximum 72 pointers to blocks,
* so every 73 disk blocks have only 72 available for data.
* The (necessary) file header is also good for 72 data block pointers.
*/
/* TODO: update this for FFS */
long
freediskspace(path)
char *path;
{
#ifdef UNTESTED
/* these changes from Patric Mueller <bhaak@gmx.net> for AROS to
* handle larger disks. Also needs limits.h and aros/oldprograms.h
* for AROS. (keni)
*/
unsigned long long freeBytes = 0;
#else
register long freeBytes = 0;
#endif
register struct InfoData *infoData; /* Remember... longword aligned */
char fileName[32];
/*
* Find a valid path on the device of which we want the free space.
* If there is a colon in the name, it is an absolute path
* and all up to the colon is everything we need.
* Remember slashes in a volume name are allowed!
* If there is no colon, it is relative to the current directory,
* so must be on the current device, so "" is enough...
*/
{
register char *colon;
strncpy(fileName, path, sizeof(fileName) - 1);
fileName[31] = 0;
if (colon = index(fileName, ':'))
colon[1] = '\0';
else
fileName[0] = '\0';
}
{
BPTR fileLock;
infoData = (struct InfoData *) alloc(sizeof(struct InfoData));
if (fileLock = Lock(fileName, SHARED_LOCK)) {
if (Info(fileLock, infoData)) {
/* We got a kind of DOS volume, since we can Lock it. */
/* Calculate number of blocks available for new file */
/* Kludge for the ever-full VOID: (oops RAM:) device */
if (infoData->id_UnitNumber == -1
&& infoData->id_NumBlocks == infoData->id_NumBlocksUsed) {
freeBytes = AvailMem(0L) - 64 * 1024L;
/* Just a stupid guess at the */
/* Ram-Handler overhead per block: */
freeBytes -= freeBytes / 16;
} else {
/* Normal kind of DOS file system device/volume */
freeBytes =
infoData->id_NumBlocks - infoData->id_NumBlocksUsed;
freeBytes -= (freeBytes + EXTENSION) / (EXTENSION + 1);
freeBytes *= infoData->id_BytesPerBlock;
#ifdef UNTESTED
if (freeBytes > LONG_MAX) {
freeBytes = LONG_MAX;
}
#endif
}
if (freeBytes < 0)
freeBytes = 0;
}
UnLock(fileLock);
}
free(infoData);
return freeBytes;
}
}
long
filesize(file)
char *file;
{
register BPTR fileLock;
register struct FileInfoBlock *fileInfoBlock;
register long size = 0;
fileInfoBlock =
(struct FileInfoBlock *) alloc(sizeof(struct FileInfoBlock));
if (fileLock = Lock(file, SHARED_LOCK)) {
if (Examine(fileLock, fileInfoBlock)) {
size = fileInfoBlock->fib_Size;
}
UnLock(fileLock);
}
free(fileInfoBlock);
return size;
}
#if 0
void
eraseall(path, files)
const char *path, *files;
{
BPTR dirLock, dirLock2;
struct FileInfoBlock *fibp;
int chklen;
#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
if(files != g.alllevels)panic("eraseall");
#endif
chklen=(int)index(files,'*')-(int)files;
if (dirLock = Lock( (char *)path ,SHARED_LOCK)) {
dirLock2=DupLock(dirLock);
dirLock2= CurrentDir(dirLock2);
fibp=AllocMem(sizeof(struct FileInfoBlock),0);
if(fibp){
if(Examine(dirLock,fibp)){
while(ExNext(dirLock,fibp)){
if(!strncmp(fibp->fib_FileName,files,chklen)){
DeleteFile(fibp->fib_FileName);
}
}
}
FreeMem(fibp,sizeof(struct FileInfoBlock));
}
UnLock(dirLock);
UnLock(CurrentDir(dirLock2));
}
}
#endif
/* This size makes that most files can be copied with two Read()/Write()s */
#if 0 /* Unused */
#define COPYSIZE 4096
char *CopyFile(from, to)
const char *from, *to;
{
register BPTR fromFile, toFile;
register char *buffer;
register long size;
char *error = NULL;
buffer = (char *) alloc(COPYSIZE);
if (fromFile = Open( (char *)from, MODE_OLDFILE)) {
if (toFile = Open( (char *)to, MODE_NEWFILE)) {
while (size = Read(fromFile, buffer, (long)COPYSIZE)) {
if (size == -1){
error = "Read error";
break;
}
if (size != Write(toFile, buffer, size)) {
error = "Write error";
break;
}
}
Close(toFile);
} else
error = "Cannot open destination";
Close(fromFile);
} else
error = "Cannot open source (this should not occur)";
free(buffer);
return error;
}
#endif
#ifdef MFLOPPY
/* this should be replaced */
saveDiskPrompt(start)
{
char buf[BUFSIZ], *bp;
BPTR fileLock;
if (sysflags.asksavedisk) {
/* Don't prompt if you can find the save file */
if (fileLock = Lock(g.SAVEF, SHARED_LOCK)) {
UnLock(fileLock);
#if defined(TTY_GRAPHICS)
if (windowprocs.win_init_nhwindows
!= amii_procs.win_init_nhwindows)
clear_nhwindow(WIN_MAP);
#endif
#if defined(AMII_GRAPHICS)
if (windowprocs.win_init_nhwindows
== amii_procs.win_init_nhwindows)
clear_nhwindow(WIN_BASE);
#endif
return 1;
}
pline("If save file is on a SAVE disk, put that disk in now.");
if (strlen(g.SAVEF) > QBUFSZ - 25 - 22)
panic("not enough buffer space for prompt");
/* THIS IS A HACK */
#if defined(TTY_GRAPHICS)
if (windowprocs.win_init_nhwindows != amii_procs.win_init_nhwindows) {
getlin("File name ?", buf);
clear_nhwindow(WIN_MAP);
}
#endif
#if defined(AMII_GRAPHICS)
if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows) {
getlind("File name ?", buf, g.SAVEF);
clear_nhwindow(WIN_BASE);
}
#endif
clear_nhwindow(WIN_MESSAGE);
if (!start && *buf == '\033')
return 0;
/* Strip any whitespace. Also, if nothing was entered except
* whitespace, do not change the value of g.SAVEF.
*/
for (bp = buf; *bp; bp++) {
if (!isspace(*bp)) {
strncpy(g.SAVEF, bp, PATHLEN);
break;
}
}
}
return 1;
}
#endif /* MFLOPPY */
/* Return 1 if the record file was found */
static boolean
record_exists()
{
FILE *file;
if (file = fopenp(RECORD, "r")) {
fclose(file);
return TRUE;
}
return FALSE;
}
#ifdef MFLOPPY
/*
* Under MSDOS: Prompt for game disk, then check for record file.
* For Amiga: do nothing, but called from restore.c
*/
void
gameDiskPrompt()
{
}
#endif
/*
* Add a slash to any name not ending in / or :. There must
* be room for the /.
*/
void
append_slash(name)
char *name;
{
char *ptr;
if (!*name)
return;
ptr = eos(name) - 1;
if (*ptr != '/' && *ptr != ':') {
*++ptr = '/';
*++ptr = '\0';
}
}
void
getreturn(str)
const char *str;
{
int ch;
raw_printf("Hit <RETURN> %s.", str);
while ((ch = nhgetch()) != '\n' && ch != '\r')
continue;
}
/* Follow the PATH, trying to fopen the file.
*/
#define PATHSEP ';'
FILE *
fopenp(name, mode)
register const char *name, *mode;
{
register char *bp, *pp, lastch;
register FILE *fp;
register BPTR theLock;
char buf[BUFSIZ];
/* Try the default directory first. Then look along PATH.
*/
if (strlen(name) >= BUFSIZ)
return (NULL);
strcpy(buf, name);
if (theLock = Lock(buf, SHARED_LOCK)) {
UnLock(theLock);
if (fp = fopen(buf, mode))
return fp;
}
pp = PATH;
while (pp && *pp) {
bp = buf;
while (*pp && *pp != PATHSEP) {
if (bp > buf + BUFSIZ - 1)
return (NULL);
lastch = *bp++ = *pp++;
}
if (lastch != ':' && lastch != '/' && bp != buf)
*bp++ = '/';
if (bp + strlen(name) > buf + BUFSIZ - 1)
return (NULL);
strcpy(bp, name);
if (theLock = Lock(buf, SHARED_LOCK)) {
UnLock(theLock);
if (fp = fopen(buf, mode))
return fp;
}
if (*pp)
pp++;
}
return NULL;
}
#endif /* MFLOPPY */
#ifdef CHDIR
/*
* A not general-purpose directory changing routine.
* Assumes you want to return to the original directory eventually,
* by chdir()ing to orgdir (which is defined in pcmain.c).
* Assumes -1 is not a valid lock, since 0 is valid.
*/
#define NO_LOCK ((BPTR) -1)
static BPTR OrgDirLock = NO_LOCK;
chdir(dir) char *dir;
{
extern char orgdir[];
if (dir == orgdir) {
/* We want to go back to where we came from. */
if (OrgDirLock != NO_LOCK) {
UnLock(CurrentDir(OrgDirLock));
OrgDirLock = NO_LOCK;
}
} else {
/*
* Go to some new place. If still at the original
* directory, save the FileLock.
*/
BPTR newDir;
if (newDir = Lock((char *) dir, SHARED_LOCK)) {
if (OrgDirLock == NO_LOCK) {
OrgDirLock = CurrentDir(newDir);
} else {
UnLock(CurrentDir(newDir));
}
} else {
return -1; /* Failed */
}
}
/* CurrentDir always succeeds if you have a lock */
return 0;
}
#endif /* CHDIR */
/* Chdir back to original directory
*/
#undef exit
void
nethack_exit(code)
{
#ifdef CHDIR
extern char orgdir[];
#endif
#ifdef CHDIR
chdir(orgdir); /* chdir, not chdirx */
#endif
#ifdef AMII_GRAPHICS
if (windowprocs.win_init_nhwindows == amii_procs.win_init_nhwindows)
CleanUp();
#endif
exit(code);
}
void regularize(s) /* normalize file name - we don't like :'s or /'s */
register char *s;
{
register char *lp;
while ((lp = index(s, ':')) || (lp = index(s, '/')))
*lp = '_';
}