Files
nethack/include/dlb.h
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

148 lines
3.9 KiB
C

/* NetHack 3.7 dlb.h $NHDT-Date: 1596498534 2020/08/03 23:48:54 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.12 $ */
/* Copyright (c) Kenneth Lorber, Bethesda, Maryland, 1993. */
/* NetHack may be freely redistributed. See license for details. */
#ifndef DLB_H
#define DLB_H
/* definitions for data library */
#ifdef DLB
/* implementations */
#if defined(MAC) && !defined(MAC_CROSS)
#define DLBRSRC /* use Mac resources */
#else
#define DLBLIB /* use a set of external files */
#endif
#ifdef DLBLIB
/* directory structure in memory */
typedef struct dlb_directory {
char *fname; /* file name as seen from calling code */
long foffset; /* offset in lib file to start of this file */
long fsize; /* file size */
char handling; /* how to handle the file (compression, etc) */
} libdir;
/* information about each open library */
typedef struct dlb_library {
FILE *fdata; /* opened data file */
long fmark; /* current file mark */
libdir *dir; /* directory of library file */
char *sspace; /* pointer to string space */
long nentries; /* # of files in directory */
long rev; /* dlb file revision */
long strsize; /* dlb file string size */
} library;
/* library definitions */
#ifndef DLBFILE
#ifndef VERSION_IN_DLB_FILENAME
#define DLBFILE "nhdat" /* name of library */
#else
#define MAX_DLB_FILENAME 256
#define DLBFILE dlbfilename
#define DLBBASENAME "nhdat"
extern char dlbfilename[MAX_DLB_FILENAME];
extern char *FDECL(build_dlb_filename, (const char *));
#endif
#endif
#ifndef FILENAME_CMP
#define FILENAME_CMP strcmp /* case sensitive */
#endif
#endif /* DLBLIB */
typedef struct dlb_handle {
FILE *fp; /* pointer to an external file, use if non-null */
#ifdef DLBLIB
library *lib; /* pointer to library structure */
long start; /* offset of start of file */
long size; /* size of file */
long mark; /* current file marker */
#endif
#ifdef DLBRSRC
int fd; /* HandleFile file descriptor */
#endif
} dlb;
#if defined(ULTRIX_PROTO) && !defined(__STDC__)
/* buggy old Ultrix compiler wants this for the (*dlb_fread_proc)
and (*dlb_fgets_proc) prototypes in struct dlb_procs (dlb.c);
we'll use it in all the declarations for consistency */
#define DLB_P struct dlb_handle *
#else
#define DLB_P dlb *
#endif
boolean NDECL(dlb_init);
void NDECL(dlb_cleanup);
dlb *FDECL(dlb_fopen, (const char *, const char *));
int FDECL(dlb_fclose, (DLB_P));
int FDECL(dlb_fread, (char *, int, int, DLB_P));
int FDECL(dlb_fseek, (DLB_P, long, int));
char *FDECL(dlb_fgets, (char *, int, DLB_P));
int FDECL(dlb_fgetc, (DLB_P));
long FDECL(dlb_ftell, (DLB_P));
/* Resource DLB entry points */
#ifdef DLBRSRC
boolean rsrc_dlb_init(void);
void rsrc_dlb_cleanup(void);
boolean rsrc_dlb_fopen(dlb *dp, const char *name, const char *mode);
int rsrc_dlb_fclose(dlb *dp);
int rsrc_dlb_fread(char *buf, int size, int quan, dlb *dp);
int rsrc_dlb_fseek(dlb *dp, long pos, int whence);
char *rsrc_dlb_fgets(char *buf, int len, dlb *dp);
int rsrc_dlb_fgetc(dlb *dp);
long rsrc_dlb_ftell(dlb *dp);
#endif
#else /* DLB */
#define dlb FILE
#define dlb_init()
#define dlb_cleanup()
#define dlb_fopen fopen
#define dlb_fclose fclose
#define dlb_fread fread
#define dlb_fseek fseek
#define dlb_fgets fgets
#define dlb_fgetc fgetc
#define dlb_ftell ftell
#endif /* DLB */
/* various other I/O stuff we don't want to replicate everywhere */
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif
#ifndef SEEK_END
#define SEEK_END 2
#endif
#define RDTMODE "r"
#if (defined(MSDOS) || defined(WIN32) || defined(TOS) || defined(OS2)) \
&& defined(DLB)
#define WRTMODE "w+b"
#else
#define WRTMODE "w+"
#endif
#if (defined(MICRO) && !defined(AMIGA)) || defined(THINK_C) \
|| defined(__MWERKS__) || defined(WIN32)
#define RDBMODE "rb"
#define WRBMODE "w+b"
#else
#define RDBMODE "r"
#define WRBMODE "w+"
#endif
#endif /* DLB_H */