Ticket #8415: patch3.diff

File patch3.diff, 17.5 KB (added by SF/capehill, 20 years ago)

AmigaOS 4 changes, 3rd attempt

  • scummvm/backends/fs/amigaos4/amigaos4-fs.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/backends/fs/amigaos4/amigaos4-fs.cpp scummvm_cvs/scummvm/backends/fs/amigaos4/amigaos4-fs.cpp
    old new  
     1/* ScummVM - Scumm Interpreter
     2 * Copyright (C) 2002-2005 The ScummVM project
     3 *
     4 * This program is free software; you can redistribute it and/or
     5 * modify it under the terms of the GNU General Public License
     6 * as published by the Free Software Foundation; either version 2
     7 * of the License, or (at your option) any later version.
     8 *
     9 * This program is distributed in the hope that it will be useful,
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12 * GNU General Public License for more details.
     13 *
     14 * You should have received a copy of the GNU General Public License
     15 * along with this program; if not, write to the Free Software
     16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     17 *
     18 * $Header$
     19 */
     20
     21#if defined(__amigaos4__)
     22#ifdef __USE_INLINE__
     23#undef __USE_INLINE__
     24#endif
     25
     26#include <proto/exec.h>
     27#include <proto/dos.h>
     28#include <stdio.h>
     29
     30#ifndef USE_NEWLIB
     31#include <strings.h>
     32#endif
     33
     34#include <stdafx.h>
     35
     36#include "util.h"
     37
     38#include "base/engine.h"
     39#include "../fs.h"
     40
     41#define ENTER() /* debug(6, "Enter\n") */
     42#define LEAVE() /* debug(6, "Leave\n") */
     43
     44
     45const uint32 ExAllBufferSize = 40960;
     46
     47class AmigaOSFilesystemNode : public AbstractFilesystemNode {
     48        protected:
     49                BPTR _pFileLock;
     50                String _sDisplayName;
     51                bool _bIsDirectory;
     52                bool _bIsValid;
     53                String _sPath;
     54
     55        public:
     56                AmigaOSFilesystemNode();
     57                AmigaOSFilesystemNode(const AmigaOSFilesystemNode *pNode);
     58                AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0);
     59                AmigaOSFilesystemNode(const String &p);
     60
     61                ~AmigaOSFilesystemNode();
     62
     63                virtual String displayName() const { return _sDisplayName; };
     64                virtual bool isValid() const { return _bIsValid; };
     65                virtual bool isDirectory() const { return _bIsDirectory; };
     66                virtual String path() const { return _sPath; };
     67
     68                virtual FSList listDir(ListMode mode = kListDirectoriesOnly) const;
     69                virtual FSList listVolumes(void) const;
     70                virtual AbstractFilesystemNode *parent() const;
     71                virtual AbstractFilesystemNode *clone() const { return new AmigaOSFilesystemNode(this); };
     72};
     73
     74AbstractFilesystemNode *FilesystemNode::getRoot() {
     75        return new AmigaOSFilesystemNode();
     76}
     77
     78AbstractFilesystemNode *FilesystemNode::getNodeForPath(const String     &path) {
     79        return new AmigaOSFilesystemNode(path);
     80}
     81
     82AmigaOSFilesystemNode::AmigaOSFilesystemNode() {
     83        ENTER();
     84        _sDisplayName = "Available Disks";
     85        _bIsValid = true;
     86        _bIsDirectory = true;
     87        _sPath = "";
     88        _pFileLock = 0;
     89        LEAVE();
     90}
     91
     92
     93AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) {
     94        ENTER();
     95
     96        int len = 0, offset = p.size();
     97       
     98        assert(offset > 0);
     99
     100        _sPath = p;
     101
     102        // Extract last component from path
     103        const char *str = p.c_str();
     104       
     105        while (offset > 0 && (str[offset-1] == '/' || str[offset-1] == ':'))
     106                offset--;
     107
     108        while (offset > 0 && (str[offset-1] != '/' && str[offset-1] != ':')) {
     109                len++;
     110                offset--;
     111        }
     112       
     113        _sDisplayName = String(str + offset, len);
     114
     115        // Check whether it is a directory, and whether the file actually exists
     116
     117        struct FileInfoBlock *fib = (struct FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
     118        if (!fib) {
     119                debug(6, "fib == 0\n");
     120                LEAVE();
     121                return;
     122        }
     123
     124        BPTR pLock = IDOS->Lock( (char *)_sPath.c_str(), SHARED_LOCK);
     125        if (pLock) {
     126                if (IDOS->Examine(pLock, fib) != DOSFALSE) {
     127                        if (fib->fib_EntryType > 0)
     128                                _bIsDirectory = true;
     129                        else
     130                                _bIsDirectory = false;
     131
     132                        if (_bIsDirectory) {
     133                                if (fib->fib_EntryType != ST_ROOT)
     134                                        _sPath += "/";
     135                               
     136                                _pFileLock = IDOS->DupLock(pLock);
     137                                _bIsValid = (_pFileLock != 0);
     138                        }
     139                        else _bIsValid = true;
     140                }
     141        }
     142
     143        IDOS->FreeDosObject(DOS_FIB, fib);
     144        LEAVE();
     145}
     146
     147AmigaOSFilesystemNode::AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName) {
     148        ENTER();
     149        int bufsize = 256;
     150        _pFileLock = 0;
     151
     152        while (1) {
     153                char *name = new char[bufsize];
     154                if (IDOS->NameFromLock(pLock, name, bufsize) != DOSFALSE) {
     155                        _sPath = name;
     156                        _sDisplayName = pDisplayName ? pDisplayName : IDOS->FilePart(name);
     157                        delete name;
     158                        break;
     159                }
     160
     161                if (IDOS->IoErr() != ERROR_LINE_TOO_LONG) {
     162                        _bIsValid = false;
     163                        debug(6, "Error\n");
     164                        LEAVE();
     165                        delete name;
     166                        return;
     167                }
     168                bufsize *= 2;
     169                delete name;
     170        }
     171
     172        _bIsValid =     false;
     173
     174        struct FileInfoBlock *fib = (struct     FileInfoBlock *)IDOS->AllocDosObject(DOS_FIB, NULL);
     175        if (!fib) {
     176                debug(6, "fib == 0\n");
     177                LEAVE();
     178                return;
     179        }
     180
     181        if (IDOS->Examine(pLock, fib) != DOSFALSE) {
     182                if (fib->fib_EntryType > 0)
     183                        _bIsDirectory = true;
     184                else
     185                        _bIsDirectory = false;
     186
     187                if (_bIsDirectory) {
     188                        if (fib->fib_EntryType != ST_ROOT)
     189                                _sPath += "/";
     190
     191                        _pFileLock = IDOS->DupLock(pLock);
     192                        _bIsValid = (_pFileLock != 0);
     193                }
     194                else _bIsValid = true;
     195        }
     196
     197        IDOS->FreeDosObject(DOS_FIB, fib);
     198        LEAVE();
     199}
     200
     201AmigaOSFilesystemNode::AmigaOSFilesystemNode(const AmigaOSFilesystemNode *node) {
     202        ENTER();
     203        _sDisplayName = node->_sDisplayName;
     204        _bIsValid = node->_bIsValid;
     205        _bIsDirectory = node->_bIsDirectory;
     206        _sPath = node->_sPath;
     207        _pFileLock = IDOS->DupLock(node->_pFileLock);
     208        LEAVE();
     209}
     210
     211AmigaOSFilesystemNode::~AmigaOSFilesystemNode() {
     212        ENTER();
     213        if (_pFileLock)
     214                IDOS->UnLock(_pFileLock);
     215        LEAVE();
     216}
     217
     218FSList AmigaOSFilesystemNode::listDir(ListMode mode) const {
     219        ENTER();
     220
     221        if (!_bIsValid) {
     222                debug(6, "Invalid node\n");
     223                LEAVE();
     224                //return 0;
     225        }
     226
     227        if (!_bIsDirectory) {
     228                debug(6, "Not a directory\n");
     229                LEAVE();
     230                //return 0;
     231        }
     232
     233        if (_pFileLock == 0) {
     234                debug(6, "Root node\n");
     235                LEAVE();
     236                return listVolumes();
     237        }
     238
     239        //FSList *myList = new FSList();
     240        FSList myList;
     241
     242        struct ExAllControl *eac;
     243        struct ExAllData *data, *ead;
     244        BOOL bExMore;
     245
     246        eac = (struct ExAllControl *)IDOS->AllocDosObject(DOS_EXALLCONTROL, 0);
     247        if (eac) {
     248                data = (struct ExAllData *)IExec->AllocVec(ExAllBufferSize, MEMF_ANY);
     249                if (data) {
     250                        eac->eac_LastKey = 0;
     251                        do {
     252                                bExMore = IDOS->ExAll(_pFileLock, data, ExAllBufferSize,
     253                                        ED_TYPE, eac);
     254
     255                                LONG error = IDOS->IoErr();
     256                                if (!bExMore && error != ERROR_NO_MORE_ENTRIES)
     257                                        break;
     258
     259                                if (eac->eac_Entries == 0)
     260                                        continue;
     261
     262                                ead     = data;
     263                                do {
     264                                        AmigaOSFilesystemNode *entry;
     265                                        String full_path;
     266                                        BPTR lock;
     267
     268                                        if ((ead->ed_Type > 0 && (mode & kListDirectoriesOnly)) ||
     269                                                (ead->ed_Type < 0 && (mode & kListFilesOnly))) {
     270                                                full_path = _sPath;
     271                                                full_path += (char*)ead->ed_Name;
     272                                                lock = IDOS->Lock((char *)full_path.c_str(), SHARED_LOCK);
     273                                                if (lock) {
     274                                                        entry = new AmigaOSFilesystemNode(lock, (char *)ead->ed_Name);
     275                                                        if (entry) {
     276                                                                if (entry->isValid())
     277                                                                        myList.push_back(wrap(entry));
     278                                                                else
     279                                                                        delete entry;
     280                                                        }
     281                                                        IDOS->UnLock(lock);
     282                                                }
     283                                        }
     284                                        ead = ead->ed_Next;
     285                                } while (ead);
     286                        } while (bExMore);
     287
     288                        IExec->FreeVec(data);
     289                }
     290
     291                IDOS->FreeDosObject(DOS_EXALLCONTROL, eac);
     292        }
     293        LEAVE();
     294        return myList;
     295}
     296
     297AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const {
     298        ENTER();
     299        AmigaOSFilesystemNode *node;
     300
     301        if (!_bIsDirectory) {
     302                debug(6, "No directory\n");
     303                LEAVE();
     304                return 0;
     305        }
     306
     307        if (_pFileLock == 0) {
     308                debug(6, "Root node\n");
     309                LEAVE();
     310                return clone();
     311        }
     312
     313        BPTR parent = IDOS->ParentDir(_pFileLock);
     314        if (parent) {
     315                node = new AmigaOSFilesystemNode(parent);
     316                IDOS->UnLock(parent);
     317        }
     318        else
     319                node = new AmigaOSFilesystemNode();
     320
     321        LEAVE();
     322        return node;
     323}
     324
     325FSList AmigaOSFilesystemNode::listVolumes(void) const {
     326        ENTER();
     327        //FSList *myList = new FSList();
     328        FSList myList;
     329
     330        struct DosList *dosList;
     331
     332        const uint32 lockFlags = LDF_READ | LDF_VOLUMES;
     333        char name[256];
     334
     335        dosList = IDOS->LockDosList(lockFlags);
     336        if (!dosList) {
     337                debug(6, "Cannot lock dos list\n");
     338                LEAVE();
     339                return myList;
     340        }
     341
     342
     343        dosList = IDOS->NextDosEntry(dosList, LDF_VOLUMES);
     344        while (dosList) {
     345                if (dosList->dol_Type == DLT_VOLUME &&
     346                        dosList->dol_Name &&
     347                        dosList->dol_Task) {
     348                        AmigaOSFilesystemNode *entry;
     349                        const char *volname = (const char *)BADDR(dosList->dol_Name)+1;
     350                        const char *devname = (const char *)((struct Task *)dosList->dol_Task->mp_SigTask)->tc_Node.ln_Name;
     351
     352                        strcpy(name, volname);
     353                        strcat(name, ":");
     354
     355                        BPTR volume_lock = IDOS->Lock(name,     SHARED_LOCK);
     356                        if (volume_lock) {
     357                                sprintf(name, "%s (%s)", volname, devname);
     358                                entry = new AmigaOSFilesystemNode(volume_lock, name);
     359                                if (entry) {
     360                                        if (entry->isValid())
     361                                                myList.push_back(wrap(entry));
     362                                        else
     363                                                delete entry;
     364                                }
     365                                IDOS->UnLock(volume_lock);
     366                        }
     367                }
     368                dosList = IDOS->NextDosEntry(dosList, LDF_VOLUMES);
     369        }
     370
     371        IDOS->UnLockDosList(lockFlags);
     372
     373        LEAVE();
     374        return myList;
     375}
     376
     377#endif
  • scummvm/backends/module.mk

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/backends/module.mk scummvm_cvs/scummvm/backends/module.mk
    old new  
    55        backends/fs/posix/posix-fs.o \
    66        backends/fs/morphos/abox-fs.o \
    77        backends/fs/windows/windows-fs.o \
     8        backends/fs/amigaos4/amigaos4-fs.o \
    89        backends/midi/alsa.o \
    910        backends/midi/coreaudio.o \
    1011        backends/midi/morphos.o \
     
    1920        backends/fs/posix \
    2021        backends/fs/morphos \
    2122        backends/fs/windows \
     23        backends/fs/amigaos4 \
    2224        backends/midi
    2325
    2426# Include common rules
  • scummvm/base/gameDetector.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/base/gameDetector.cpp scummvm_cvs/scummvm/base/gameDetector.cpp
    old new  
    594594                warning("No path was provided. Assuming the data files are in the current directory");
    595595                gameDataPath = "./";
    596596        } else if (gameDataPath.lastChar() != '/'
    597 #ifdef __MORPHOS__
     597#if defined(__MORPHOS__) || defined(__amigaos4__)
    598598                                        && gameDataPath.lastChar() != ':'
    599599#endif
    600600                                        && gameDataPath.lastChar() != '\\') {
  • scummvm/base/main.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/base/main.cpp scummvm_cvs/scummvm/base/main.cpp
    old new  
    122122#endif
    123123        ;
    124124
     125#if defined(__amigaos4__)
     126// Set the stack cookie, 640 KB should be enough for everyone ;)
     127const char* stackCookie = "$STACK: 655360\0";
     128#endif
     129
    125130#if defined(WIN32) && defined(NO_CONSOLE)
    126131#include <cstdio>
    127132#define STDOUT_FILE     TEXT("stdout.txt")
  • scummvm/common/file.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/common/file.cpp scummvm_cvs/scummvm/common/file.cpp
    old new  
    9292                file = fopen(buf, mode);
    9393        }
    9494
     95#ifdef __amigaos4__
     96        //
     97        // Work around for possibility that someone uses AmigaOS newlib build with SmartFileSystem (blocksize 512 bytes), leading
     98        // to buffer size being only 512 bytes. Clib2 sets the buffer size to 8KB, resulting smooth movie playback. This forces the buffer
     99        // to be "enough" also when using newlib compile on SFS.
     100        //
     101        if (file) {
     102                setvbuf(file, NULL, _IOFBF, 8192);
     103        }
     104#endif
     105
    95106        return file;
    96107}
    97108
  • scummvm/common/savefile.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/common/savefile.cpp scummvm_cvs/scummvm/common/savefile.cpp
    old new  
    143143        const int dirLen = strlen(buf);
    144144
    145145        if (dirLen > 0) {
    146 #ifdef __MORPHOS__
     146#if defined(__MORPHOS__) || defined(__amigaos4__)
    147147                if (buf[dirLen-1] != ':' && buf[dirLen-1] != '/')
    148148#endif
    149149
  • scummvm/common/scaler/hq2x.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/common/scaler/hq2x.cpp scummvm_cvs/scummvm/common/scaler/hq2x.cpp
    old new  
    4242#else
    4343
    4444#ifdef HAS_ALTIVEC
     45#ifdef __amigaos4__
     46#include <proto/exec.h>
     47#include <altivec.h>
     48static bool isAltiVecAvailable() {
     49        uint32 vec_unit;
     50        IExec->GetCPUInfo(GCIT_VectorUnit, &vec_unit, TAG_DONE);
     51        if (vec_unit == VECTORTYPE_NONE)
     52                return false;
     53        else
     54                return true;
     55}
     56#else
    4557#include <sys/sysctl.h>
    4658
    4759static bool isAltiVecAvailable()  {
     
    5466        return false;
    5567}
    5668#endif
     69#endif
    5770
    5871#define PIXEL00_0       *(q) = w5;
    5972#define PIXEL00_10      *(q) = interpolate16_2<bitFormat,3,1>(w5, w1);
  • scummvm/common/scaler/hq3x.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/common/scaler/hq3x.cpp scummvm_cvs/scummvm/common/scaler/hq3x.cpp
    old new  
    4242#else
    4343
    4444#ifdef HAS_ALTIVEC
     45#ifdef __amigaos4__
     46#include <proto/exec.h>
     47static bool isAltiVecAvailable()  {
     48        uint32 vec_unit;
     49        IExec->GetCPUInfo(GCIT_VectorUnit, &vec_unit, TAG_DONE);
     50        if (vec_unit == VECTORTYPE_NONE)
     51                return false;
     52        else
     53                return true;
     54}
     55#else
    4556#include <sys/sysctl.h>
    4657
    4758static bool isAltiVecAvailable()  {
     
    5465        return false;
    5566}
    5667#endif
     68#endif
    5769
    5870#define PIXEL00_1M  *(q) = interpolate16_2<bitFormat,3,1>(w5, w1);
    5971#define PIXEL00_1U  *(q) = interpolate16_2<bitFormat,3,1>(w5, w2);
  • scummvm/common/scummsys.h

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/common/scummsys.h scummvm_cvs/scummvm/common/scummsys.h
    old new  
    323323        #define fsize(a)                        ps2_fsize(a)
    324324
    325325        extern void ps2_disableHandleCaching(void);
     326#elif defined (__amigaos4__)
     327        #include <exec/types.h>
     328
     329        #define scumm_stricmp strcasecmp
     330        #define scumm_strnicmp strncasecmp
     331
     332        #define CHECK_HEAP
     333
     334        #define SCUMM_BIG_ENDIAN
     335
     336        // You need to set this manually if necessary
     337        #define SCUMM_NEED_ALIGNMENT
     338
     339        #define FORCEINLINE inline
     340        #define CDECL
     341
     342        #ifndef HAVE_CONFIG_H
     343        typedef unsigned char byte;
     344        typedef unsigned int uint;
     345        #endif
     346
     347        #define START_PACK_STRUCTS
     348        #define END_PACK_STRUCTS
     349        #define GCC_PACK __attribute__((packed))
     350        #define NORETURN __attribute__((__noreturn__))
    326351#else
    327352        #error No system type defined
    328353#endif
  • scummvm/common/stdafx.h

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/common/stdafx.h scummvm_cvs/scummvm/common/stdafx.h
    old new  
    111111#endif
    112112#if !defined(macintosh)
    113113#include <sys/types.h>
    114 #if !defined(__PLAYSTATION2__)
     114#if !defined(__PLAYSTATION2__) && !defined(__amigaos4__)
    115115#include <sys/uio.h>
    116116#endif
     117#if !defined(__amigaos4__)
    117118#include <sys/param.h>
    118119#endif
     120#endif
    119121#if !defined (__BEOS__)
    120122#include <unistd.h>
    121123#endif
  • scummvm/configure

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/configure scummvm_cvs/scummvm/configure
    old new  
    434434        _host_os=riscos
    435435        _host_cpu=arm
    436436        ;;
     437ppc-amigaos)
     438        _host_os=amigaos
     439        _host_cpu=ppc
     440        ;;
    437441*)
    438442        guessed_host=`$_srcdir/config.guess`
    439443        _host_cpu=`echo $guessed_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
     
    613617                        type_2_byte='short'
    614618                        type_4_byte='int'
    615619                        ;;
     620                ppc-amigaos)
     621                        echo "Cross-compiling to $_host, forcing endianness, alignment and type sizes"
     622                        _def_endianness='#define SCUMM_BIG_ENDIAN'
     623                        _def_align='#define     SCUMM_NEED_ALIGNMENT'
     624                        type_1_byte='char'
     625                        type_2_byte='short'
     626                        type_4_byte='long'
     627                        CXXFLAGS="$CFLAGS -newlib -mstrict-align -mcpu=750 -mtune=7400"
     628                        LDFLAGS="$LDFLAGS -newlib"
     629                        ;;
    616630                *)
    617631                        echo "Cross-compiling to unknown target, please add your target to configure."
    618632                        exit 1
     
    11751189# -------- Generated by configure -----------
    11761190
    11771191CXX := $CXX
    1178 CXXFLAGS := $CXXFLAGS
     1192CXXFLAGS += $CXXFLAGS
    11791193LIBS += $LIBS
    11801194RANLIB := $_ranlib
    11811195INSTALL := $_install
  • scummvm/gui/options.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/gui/options.cpp scummvm_cvs/scummvm/gui/options.cpp
    old new  
    3434#include "sound/mididrv.h"
    3535#include "sound/mixer.h"
    3636
    37 #if (!( defined(__PALM_OS__) || defined(__DC__) || defined(__GP32__)) && !defined(_MSC_VER))
     37#if (!( defined(__PALM_OS__) || defined(__DC__) || defined(__GP32__) || defined(__amigaos4__)) && !defined(_MSC_VER))
    3838#include <sys/param.h>
    3939#include <unistd.h>
    4040#endif
  • scummvm/sound/softsynth/mt32/partialManager.cpp

    diff -urwN -x CVS -x .deps scummvm_cvs_pure/scummvm/sound/softsynth/mt32/partialManager.cpp scummvm_cvs/scummvm/sound/softsynth/mt32/partialManager.cpp
    old new  
    1919 * IN THE SOFTWARE.
    2020 */
    2121
     22#ifdef __amigaos4__
     23#include <string.h>
     24#else
    2225#include <memory.h>
     26#endif
    2327
    2428#include "mt32emu.h"
    2529