Better hex/oct width handling.
[AROS.git] / rom / dos / loadseg_overlay.c
bloba9a813af3cdb923e3228a0174a9b7b86a06ebcaa
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #define DEBUG 0
9 #include <exec/execbase.h>
10 #include <exec/memory.h>
11 #include <dos/dosasl.h>
12 #include <dos/doshunks.h>
13 #include <dos/dosextens.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <proto/arossupport.h>
17 #include <aros/asmcall.h>
18 #include <aros/debug.h>
19 #include <aros/macros.h>
21 #include <loadseg/loadseg.h>
23 #include "dos_intern.h"
25 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT) && defined(__mc68000)
26 static AROS_UFH4(LONG, ReadFunc,
27 AROS_UFHA(BPTR, file, D1),
28 AROS_UFHA(APTR, buffer, D2),
29 AROS_UFHA(LONG, length, D3),
30 AROS_UFHA(struct DosLibrary *, DOSBase, A6)
33 AROS_USERFUNC_INIT
35 return FRead(file, buffer, 1, length);
37 AROS_USERFUNC_EXIT
40 static AROS_UFH3(APTR, AllocFunc,
41 AROS_UFHA(ULONG, length, D0),
42 AROS_UFHA(ULONG, flags, D1),
43 AROS_UFHA(struct ExecBase *, SysBase, A6)
46 AROS_USERFUNC_INIT
48 return AllocMem(length, flags);
50 AROS_USERFUNC_EXIT
53 static AROS_UFH3(void, FreeFunc,
54 AROS_UFHA(APTR, buffer, A1),
55 AROS_UFHA(ULONG, length, D0),
56 AROS_UFHA(struct ExecBase *, SysBase, A6)
59 AROS_USERFUNC_INIT
61 FreeMem(buffer, length);
63 AROS_USERFUNC_EXIT
66 AROS_UFH4(BPTR, LoadSeg_Overlay,
67 AROS_UFHA(UBYTE*, name, D1),
68 AROS_UFHA(BPTR, hunktable, D2),
69 AROS_UFHA(BPTR, fh, D3),
70 AROS_UFHA(struct DosLibrary *, DOSBase, A6))
72 AROS_USERFUNC_INIT
74 void (*FunctionArray[3])();
75 ULONG hunktype;
76 BPTR seg;
77 SIPTR error = RETURN_OK;
79 FunctionArray[0] = (APTR)ReadFunc;
80 FunctionArray[1] = (APTR)AllocFunc;
81 FunctionArray[2] = (APTR)FreeFunc;
83 D(bug("LoadSeg_Overlay. table=%x fh=%x\n", hunktable, fh));
84 if (AROS_UFC4(LONG, ReadFunc,
85 AROS_UFCA(BPTR, fh, D1),
86 AROS_UFCA(void *, &hunktype, D2),
87 AROS_UFCA(LONG, sizeof(hunktype), D3),
88 AROS_UFCA(struct Library *, DOSBase,A6)) != sizeof(hunktype))
89 return BNULL;
90 hunktype = AROS_BE2LONG(hunktype);
91 if (hunktype != HUNK_HEADER)
92 return BNULL;
93 seg = LoadSegment(fh, hunktable, (SIPTR*)FunctionArray, NULL, &error, (struct Library *)DOSBase);
94 if (seg == BNULL)
95 SetIoErr(error);
97 return seg;
99 AROS_USERFUNC_EXIT
102 #endif