home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / CHIPHEFT102001.ISO / pda / Palm / dateien / emulator_app_21d29.sit / HostControl.h next >
Encoding:
C/C++ Source or Header  |  1999-07-07  |  9.0 KB  |  265 lines  |  [TEXT/CWIE]

  1. /* ================================================================================== */
  2. /* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
  3. /* ================================================================================== */
  4.  
  5. #ifndef _HOSTCONTROL_H_
  6. #define _HOSTCONTROL_H_
  7.  
  8. #include <SysTraps.h>
  9.  
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13.  
  14.  
  15. /*
  16.     Set the base value for selectors. Note that this value MUST be
  17.     two bytes long and have the high byte be non-zero. The reason
  18.     for this has to do with the way SysGremlins was originally
  19.     declared. It took a GremlinsSelector enumerated value. Originally,
  20.     there was only one value, and it was zero. The way the 68K compiler
  21.     works, it decides that GremlinsSelectors are only one byte long,
  22.     so a call to SysGremlins would push one byte onto the stack. Because
  23.     all values on the stack need to be word-aligned, the processor
  24.     subtracts 1 from the stack before pushing on the byte. Therefore,
  25.     the stack looks like:
  26.  
  27.             previous contents
  28.             garbage byte
  29.             selector
  30.             return address
  31.  
  32.     With this setup, we have two choices: leave the selector size at
  33.     one byte and limit ourselves to 256 functions, or define the selector
  34.     to be a two byte value, with the first 256 values (all those with 0x00
  35.     in the upper byte) to be GremlinIsOn. The latter sounds preferable, so
  36.     we start the new selectors at 0x0100.
  37. */
  38.  
  39. #define hostSelectorBase    0x0100
  40. #define hostSelectorChunk    0x0100
  41. #define hostSection(x)        (hostSelectorBase + (hostSelectorChunk * (x)))
  42.  
  43. typedef enum
  44. {
  45.     // Host information selectors
  46.  
  47.     hostSelectorGetHostVersion = hostSection(0),
  48.     hostSelectorGetHostID,
  49.     hostSelectorGetHostPlatform,
  50.     hostSelectorIsSelectorImplemented,
  51.     hostSelectorGestalt,
  52.     hostSelectorIsCallingTrap,
  53.  
  54.     // Profiler selectors
  55.  
  56.     hostSelectorProfileInit = hostSection(1),
  57.     hostSelectorProfileStart,
  58.     hostSelectorProfileStop,
  59.     hostSelectorProfileDump,
  60.     hostSelectorProfileCleanup,
  61.  
  62.     // Std C Library wrapper selectors
  63.  
  64.     hostSelectorErrNo = hostSection(2),
  65.  
  66.     hostSelectorFClose,
  67.     hostSelectorFEOF,
  68.     hostSelectorFError,
  69.     hostSelectorFFlush,
  70.     hostSelectorFGetC,
  71.     hostSelectorFGetPos,
  72.     hostSelectorFGetS,
  73.     hostSelectorFOpen,
  74.     hostSelectorFPrintF,        // Floating point not yet supported in Poser
  75.     hostSelectorFPutC,
  76.     hostSelectorFPutS,
  77.     hostSelectorFRead,
  78.     hostSelectorRemove,            // Not yet implemented in Poser
  79.     hostSelectorRename,            // Not yet implemented in Poser
  80.     hostSelectorFReopen,        // Not yet implemented in Poser
  81.     hostSelectorFScanF,            // Not yet implemented
  82.     hostSelectorFSeek,
  83.     hostSelectorFSetPos,
  84.     hostSelectorFTell,
  85.     hostSelectorFWrite,
  86.     hostSelectorTmpFile,
  87.     hostSelectorTmpNam,            // Not yet implemented in Poser
  88.     hostSelectorGetEnv,
  89.  
  90.     hostSelectorMalloc,            // Not yet implemented in Poser
  91.     hostSelectorRealloc,        // Not yet implemented in Poser
  92.     hostSelectorFree,            // Not yet implemented in Poser
  93.     
  94.     // Gremlin selectors
  95.  
  96.     hostSelectorGremlinIsRunning = hostSection(3),
  97.     hostSelectorGremlinNumber,
  98.     hostSelectorGremlinCounter,
  99.     hostSelectorGremlinLimit,
  100. //    hostSelectorGremlinApp,
  101.  
  102.     // Database selectors
  103.  
  104.     hostSelectorImportFile = hostSection(4),
  105.     hostSelectorExportFile,
  106.  
  107.     // Preferences selectors
  108.  
  109.     hostSelectorSetDebugOption = hostSection(5),        // Not yet implemented
  110.     hostSelectorSetWindowScale,                            // Not yet implemented
  111.     hostSelectorSetWindowBackground,                    // Not yet implemented
  112.  
  113.     // Logging selectors
  114.  
  115.     hostSelectorLogFile = hostSection(6),
  116.     hostSelectorSetLogFileSize,
  117.  
  118.     hostSelectorLastTrapNumber
  119. } HostControlTrapNumber;
  120.  
  121.  
  122. typedef struct HostFILE
  123. {
  124.     long    _field;
  125. } HostFILE;
  126.  
  127.  
  128.  
  129. typedef long    HostBool;
  130. typedef long    HostErr;
  131. typedef long    HostID;
  132. typedef long    HostPlatform;
  133. typedef long    HostBG;
  134.  
  135. #ifndef hostErrorClass
  136.     #define    hostErrorClass                0x1C00    // Host Control Manager
  137. #else
  138.     #if hostErrorClass != 0x1C00
  139.         #error "You cannot change hostErrorClass without telling us."
  140.     #endif
  141. #endif
  142.  
  143. enum    // HostErr values
  144. {
  145.     hostErrNone = 0,
  146.  
  147.     hostErrBase = hostErrorClass,
  148.  
  149.     hostErrUnknownGestaltSelector,
  150.  
  151.     hostErrDiskError,
  152.  
  153.     hostErrOutOfMemory,
  154.     hostErrMemReadOutOfRange,
  155.     hostErrMemWriteOutOfRange,
  156.     hostErrMemInvalidPtr,
  157.  
  158.     hostErrInvalidParameter
  159. };
  160.  
  161.  
  162. enum    // HostID values
  163. {
  164.     hostIDPalmOS,
  165.     hostIDPalmOSEmulator,    // The Copilot thingy
  166.     hostIDPalmOSSimulator    // The Mac libraries you link with thingy
  167. };
  168.  
  169.  
  170. enum    // HostPlatform values
  171. {
  172.     hostPlatformPalmOS,
  173.     hostPlatformWindows,
  174.     hostPlatformMacintosh,
  175.     hostPlatformUnix
  176. };
  177.  
  178.  
  179. enum    // HostBG values
  180. {
  181.     hostBGGray,
  182.     hostBGWhite
  183. };
  184.  
  185.  
  186. // Define this in case SysTraps.h doesn't have it.
  187.  
  188. #define sysTrapHostControl (sysTrapBase + 836)
  189.  
  190. #define HOST_TRAP(selector)                                                    \
  191.     FIVEWORD_INLINE(                                                        \
  192.         0x3F3C, selector,                    /* MOVE.W #selector, -(A7)    */    \
  193.         m68kTrapInstr + sysDispatchTrapNum,    /* TRAP $F                    */    \
  194.         sysTrapHostControl,                    /* sysTrapHostControl        */    \
  195.         0x544F)                                /* ADD.Q #2, A7                */ 
  196.  
  197.  
  198. long            HostGetHostVersion            (void)                                        HOST_TRAP (hostSelectorGetHostVersion);
  199. HostID            HostGetHostID                (void)                                        HOST_TRAP (hostSelectorGetHostID);
  200. HostPlatform    HostGetHostPlatform            (void)                                        HOST_TRAP (hostSelectorGetHostPlatform);
  201. HostBool        HostIsSelectorImplemented    (long selector)                                HOST_TRAP (hostSelectorIsSelectorImplemented);
  202. HostErr            HostGestalt                    (long gestSel, long* response)                HOST_TRAP (hostSelectorGestalt);
  203. HostBool        HostIsCallingTrap            (void)                                        HOST_TRAP (hostSelectorIsCallingTrap);
  204.  
  205. HostErr            HostProfileInit                (long maxCalls, long maxDepth)                HOST_TRAP (hostSelectorProfileInit);
  206. HostErr            HostProfileStart            (void)                                        HOST_TRAP (hostSelectorProfileStart);
  207. HostErr            HostProfileStop                (void)                                        HOST_TRAP (hostSelectorProfileStop);
  208. HostErr            HostProfileDump                (const char* filename)                        HOST_TRAP (hostSelectorProfileDump);
  209. HostErr            HostProfileCleanup            (void)                                        HOST_TRAP (hostSelectorProfileCleanup);
  210.  
  211. long            HostErrNo                    (void)                                        HOST_TRAP (hostSelectorErrNo);
  212.  
  213. long            HostFClose                    (HostFILE* f)                                HOST_TRAP (hostSelectorFClose);
  214. long            HostFEOF                    (HostFILE* f)                                HOST_TRAP (hostSelectorFEOF);
  215. long            HostFError                    (HostFILE* f)                                HOST_TRAP (hostSelectorFError);
  216. long            HostFFlush                    (HostFILE* f)                                HOST_TRAP (hostSelectorFFlush);
  217. long            HostFGetC                    (HostFILE* f)                                HOST_TRAP (hostSelectorFGetC);
  218. long            HostFGetPos                    (HostFILE* f, long* posP)                    HOST_TRAP (hostSelectorFGetPos);
  219. char*            HostFGetS                    (char* s, long n, HostFILE* f)                HOST_TRAP (hostSelectorFGetS);
  220. HostFILE*        HostFOpen                    (const char* name, const char* mode)        HOST_TRAP (hostSelectorFOpen);
  221. long            HostFPrintF                    (HostFILE* f, const char* fmt, ...)            HOST_TRAP (hostSelectorFPrintF);
  222. long            HostFPutC                    (long c, HostFILE* f)                        HOST_TRAP (hostSelectorFPutC);
  223. long            HostFPutS                    (const char* s, HostFILE* f)                HOST_TRAP (hostSelectorFPutS);
  224. long            HostFRead                    (void* buffer, long size, long count, HostFILE* f)
  225.                                                                                         HOST_TRAP (hostSelectorFRead);
  226. long            HostRemove                    (const char* name)                            HOST_TRAP (hostSelectorRemove);
  227. long            HostRename                    (const char* oldName, const char* newName)    HOST_TRAP (hostSelectorRename);
  228. HostFILE*        HostFReopen                    (const char* name, const char* mode, HostFILE *f)
  229.                                                                                         HOST_TRAP (hostSelectorFReopen);
  230. long            HostFScanF                    (HostFILE* f, const char *fmt, ...)            HOST_TRAP(hostSelectorFScanF);
  231. long            HostFSeek                    (HostFILE* f, long offset, long origin)        HOST_TRAP (hostSelectorFSeek);
  232. long            HostFSetPos                    (HostFILE* f, long* pos)                    HOST_TRAP (hostSelectorFSetPos);
  233. long            HostFTell                    (HostFILE* f)                                HOST_TRAP (hostSelectorFTell);
  234. long            HostFWrite                    (const void* buffer, long size, long count, HostFILE* f)
  235.                                                                                         HOST_TRAP (hostSelectorFWrite);
  236. HostFILE*        HostTmpFile                    (void)                                        HOST_TRAP (hostSelectorTmpFile);
  237. char*            HostTmpNam                    (char *name)                                HOST_TRAP (hostSelectorTmpNam);
  238. char*            HostGetEnv                    (const char*)                                HOST_TRAP (hostSelectorGetEnv);
  239.  
  240. void*            HostMalloc                    (long size)                                    HOST_TRAP (hostSelectorMalloc);
  241. void*            HostRealloc                    (void* p, long size)                        HOST_TRAP (hostSelectorRealloc);
  242. void            HostFree                    (void* p)                                    HOST_TRAP (hostSelectorFree);
  243.  
  244. HostBool        HostGremlinIsRunning        (void)                                        HOST_TRAP (hostSelectorGremlinIsRunning);
  245. long            HostGremlinNumber            (void)                                        HOST_TRAP (hostSelectorGremlinNumber);
  246. long            HostGremlinCounter            (void)                                        HOST_TRAP (hostSelectorGremlinCounter);
  247. long            HostGremlinLimit            (void)                                        HOST_TRAP (hostSelectorGremlinLimit);
  248.  
  249. HostErr            HostImportFile                (const char* fileName, long cardNum)        HOST_TRAP (hostSelectorImportFile);
  250. HostErr            HostExportFile                (const char* fileName, long cardNum, const char* dbName)
  251.                                                                                         HOST_TRAP (hostSelectorExportFile);
  252.  
  253. HostBool        HostSetDebugOption            (HostBool newSetting)                        HOST_TRAP (hostSelectorSetDebugOption);
  254. long            HostSetWindowScale            (long newScale)                                HOST_TRAP (hostSelectorSetWindowScale);
  255. HostBG            HostSetWindowBackground        (HostBG newBackground)                        HOST_TRAP (hostSelectorSetWindowBackground);
  256.  
  257. HostFILE*        HostLogFile                    (void)                                        HOST_TRAP (hostSelectorLogFile);
  258. void            HostSetLogFileSize            (long)                                        HOST_TRAP (hostSelectorSetLogFileSize);
  259.  
  260. #ifdef __cplusplus 
  261. }
  262. #endif
  263.  
  264. #endif /* _HOSTCONTROL_H_ */
  265.