home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / v9t9_module.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  10.8 KB  |  416 lines

  1.  
  2. /*
  3.  *    This is the public interface to a v9t9 module.
  4.  *
  5.  */
  6.  
  7. #ifndef __v9t9_module_h__
  8. #define __v9t9_module_h__
  9.  
  10. #include "centry.h"
  11.  
  12. #include "16bit.h"
  13.  
  14. /*
  15.     History:
  16.  
  17.     20000703:    -- added vmSoundModule.flush() as a means to
  18.                    turn off sound without messing around with
  19.                    cached sound info.
  20.     20000625:    -- removed vmVideoModule.update().  No reason to
  21.                     have this, since it's always a call into vdp.c.
  22.                     Also removed updatetextlist.  Our bitmap has
  23.                     enough info to safely update 8x6 blocks
  24.                     by drawing 8x8 blocks instead.
  25.     20000409:    -- changed keyboard getkeynames into getextendedkeys,
  26.                     keeping enums and names constant for keys and
  27.                     making modules only define which they support
  28.     19990725:    -- bumped vmModule version to 3 and changed
  29.                     'install' to 'enable' and added 'disable' and
  30.                     a tag field
  31.     19990601:    -- bumped all version numbers to 2.
  32.                 -- removed vmContext parameter from all callbacks 
  33.                     (the idea of a loadable plugin module is currently 
  34.                     absurd)
  35.  
  36. */
  37.  
  38. /*    These enums are accepted error returns from module functions. */
  39. typedef enum
  40. {
  41.     vmOk             = 0,
  42.     vmNotAvailable,
  43.     vmConfigError,
  44.     vmDisabled,
  45.     vmInternalError
  46. }    vmResult;
  47.  
  48. /*    module types */
  49. typedef enum
  50. {
  51.     vmTypeCPU, 
  52.     vmTypeVideo,
  53.     vmTypeSound,
  54.     vmTypeKeyboard,
  55.     vmTypeDSR
  56. }    vmType;
  57.  
  58. /*    module flags */
  59. typedef enum
  60. {
  61.     vmFlagsNone = 0,
  62.     vmFlagsExclusive = 1,        /*     module must be only one of its type;
  63.                                     usually used when it consumes all the
  64.                                     information; module may be used exclusively
  65.                                     nonetheless, due to emulator restrictions */
  66.     vmFlagsOneShotEnable = 2,    /*    module can only be enabled once */
  67.     vmFlagsOneShotDisable = 4,    /*    module can only be disabled once */
  68.     vmFlagsUnused
  69. }    vmFlags;
  70.  
  71. /*    runtime flags */
  72. enum
  73. {
  74.     /* these flags correspond to the vmFlags for switching to a module  */
  75.     vmRTEnabledOnce = 0x1,        /*    we installed the module (once) */
  76.     vmRTDisabledOnce = 0x2,        /*    we installed the module (once) */
  77.  
  78.     /* these flags correspond to the startup/shutdown process */
  79.     vmRTUndoInit = 0x10,        /*     we inited the module (and must term) */
  80.     vmRTUndoEnable = 0x20,        /*     we enabled the module (and must disable) */
  81.     vmRTUndoRestart = 0x40,        /*     we restarted the module (and must restop) */
  82.  
  83.     vmRTInUse = 0x100,            /*    currently using this module */
  84.     vmRTUnselected = 0x200,        /*    intentionally unselected this one */
  85.     vmRTUnavailable = 0x400,    /*    ->detect() failed */
  86.  
  87.     vmRTUserModified = 0x800,    /*    status modified by user (i.e., save it) */
  88.     vmRTUnused
  89. };
  90.  
  91. /************************/
  92.  
  93. /*    This struct is passed from a module to v9t9 and
  94.     serves to define its capabilities and callbacks. */
  95.  
  96. typedef struct
  97. {
  98.     int            version;
  99. }    vmGenericModule;
  100.  
  101. /**********************************************/
  102.  
  103. #define VMCPU_CURRENT_VERSION 2
  104.  
  105. typedef struct
  106. {
  107.     u16        pc, wp, st;
  108. }    cpuContext;
  109.  
  110. enum
  111. {
  112.     em_KeepGoing = 0,    // nothing big
  113.     em_Interrupted = 1,    // return to system
  114.     em_TooFast = 2,        // idle
  115.     em_Quitting = 3,    // normal termination
  116.     em_Dying = 4        // fatal termination
  117. };
  118.  
  119. /*    A CPU module, currently, means nothing special */
  120. typedef struct
  121. {    
  122.     int            version;
  123.             
  124.     /* execute until interrupted, return an em_XXXX value */
  125.     int            (*execute)(void);
  126.             
  127.     /* interrupt execution (results in vmCPUModule->execute() returning) */
  128.     void        (*stop)(void);
  129.  
  130. }    vmCPUModule;    /* vmTypeCPU */
  131.  
  132.         
  133. /**********************************************/
  134.  
  135. #define VMSOUND_CURRENT_VERSION    3
  136.  
  137. typedef enum
  138. {
  139.     vms_Tv0        = 0x01,
  140.     vms_Tv1        = 0x02,
  141.     vms_Tv2        = 0x04,
  142.     vms_Tn        = 0x08,
  143.     vms_Vv0        = 0x10,
  144.     vms_Vv1        = 0x20,
  145.     vms_Vv2        = 0x40,
  146.     vms_Vn        = 0x80,
  147.  
  148. }    vmsUpdateMask;
  149.  
  150. typedef enum
  151. {
  152.     vms_Speech    = 0x01,        // speech synthesizer
  153.     vms_AGw        = 0x02        // audio gate
  154. }    vmsPlayMask;
  155.  
  156. typedef enum
  157. {
  158.     vms_AGr        = 0x02        // audio gate [cassette]
  159. }    vmsReadMask;
  160.  
  161.  
  162.  
  163. /*    A sound module expresses the current state of sound, including
  164.     the three-voice-plus-noise sound chip, and all digital sounds
  165.     produced from other sources (speech, cassette, etc).
  166.     
  167.     Currently, the state of the sound chip is in the voices[]
  168.     array (defined in sound.h).  Read from that array to determine
  169.     what the 'updated' bitmask is referring to.  
  170.     
  171.     As for digital sounds, they are presented directly to the 'play'
  172.     function.  The mix_server.c file is intended to be a somewhat portable
  173.     mixer for digital data.  Feel free to use it.
  174. */
  175. typedef struct
  176. {
  177.     int            version;
  178.  
  179.       /* update sound according to bitmask */
  180.     void        (*update)(vmsUpdateMask updated);
  181.  
  182.       /* flush tone/noise sound */
  183.     void        (*flush)(void);
  184.  
  185.       /* schedule digital data for playing (immediately if possible,
  186.           else after all other sound of this type);
  187.           kind is *one* element of vmsPlayMask;
  188.           data/size/hz describe the sample */
  189.     void        (*play)(vmsPlayMask kind, s8 *data, int size, int hz);
  190.  
  191.     /* read digital data from input; smooth input data if hardware
  192.          is not capable of reading at a low 'hz' rate (for cassette). */
  193.     void        (*read)(vmsReadMask kind, u8 *data, int size, int hz);     
  194. }    vmSoundModule;        /* vmTypeSound */
  195.  
  196. /**********************************************/
  197.  
  198. #define VMVIDEO_CURRENT_VERSION 3
  199.  
  200. /* 
  201.  
  202.     A video module is expected to work by copying from an offscreen
  203.     bitmap of the 99/4A screen (maintained in vdp.c), the changed
  204.     parts of which are announced through callbacks to updatelist.
  205.     This routine is sent lists of updateblocks, which contain pointers
  206.     to the upper-left corners of 8x8 blocks in the bitmap.
  207.     UPDATE_ROW_STRIDE is the width of a row. The extent of the bitmap
  208.     is greater than that of the 99/4A video screen for use in clipping
  209.     sprites.
  210.     
  211.     Never touch the bitmap!  It is expected to maintain history between
  212.     updates.
  213.     
  214.     The bitmap is arranged using one byte per color, range 0 to 16.  Bytes
  215.     with values 1 through 15 correspond to ordinary TI colors.  Entry 0 is
  216.     used for "clear", the background.  The video mode you use should allow
  217.     palette flipping for best performance, since entry 0 represents a color
  218.     that changes often (the setfgbg callback).  Entry 16 is used for the
  219.     foreground color in text mode.  
  220. */
  221.     
  222. struct updateblock;
  223.  
  224. typedef struct
  225. {
  226.     int            version;
  227.  
  228.     /* update screen (or offscreen page) from blocks in list */
  229.     vmResult    (*updatelist)(struct updateblock *first, int num);
  230.     
  231.     /* resize the screen to this size in pixels
  232.         (usually 256x192 or 240x192 for text mode) */
  233.     vmResult    (*resize)(u32 x, u32 y);
  234.  
  235.     /* update color 0 and color 16 (as appearing in the main
  236.         bitmap) to these TI colors (which may be 0, interpret as black) */
  237.     vmResult    (*setfgbg)(u8 bg, u8 fg);
  238.  
  239.     /* blank the screen; background color is 'bg' 
  240.         (maybe set all palette entries to color bg) */
  241.     vmResult    (*setblank)(u8 bg);
  242.     
  243.     /* unblank the screen */
  244.     vmResult    (*resetfromblank)(void);
  245. }    vmVideoModule;        /* vmTypeVideo */
  246.  
  247. /**********************************************/
  248.  
  249. #define VMKEYBOARD_CURRENT_VERSION 3
  250.  
  251. typedef enum {
  252.     SK_FIRST = 128,
  253.     SK_PAUSE = SK_FIRST,
  254.     SK_F1, SK_F2, SK_F3, SK_F4,
  255.     SK_F5, SK_F6, SK_F7, SK_F8,
  256.     SK_F9, SK_F10, SK_F11, SK_F12,
  257.     SK_ESC, SK_TAB,
  258.     SK_WIN_LEFT, SK_WIN_RIGHT, SK_MENU,
  259.     SK_LAST
  260. }    SpecialKey;
  261.  
  262. typedef struct
  263. {
  264.     int            version;
  265.             
  266.     /*    scan keyboard and update crukeyboardmap[] */
  267.     vmResult    (*scan)(void);
  268.     
  269.     /*    return list of supported extended keys from
  270.         the SK_xxx enum list; terminate with 0. */
  271.     vmResult    (*getspecialkeys)(SpecialKey **list);
  272. }    vmKeyboardModule;    /* vmTypeKeyboard */
  273.  
  274. /**********************************************/
  275.  
  276. /*    DSR module. 
  277.     "install" routine should load ROM and set up CRU handlers.
  278.     The >0 bit handler should call dsr_set_active(). */
  279. #define VMDSR_CURRENT_VERSION 1
  280.         
  281. typedef struct
  282. {
  283.     int            version;
  284.     
  285.     /*    Return CRU base module is currently active on. 
  286.         It will only be called if a program jumps into the DSR
  287.         memory area (>4000...>5FFF) and the DSR is active.
  288.         This allows one module to emulate a series of
  289.         devices, if necessary.  */
  290.     vmResult    (*getcrubase)(u32 *base);
  291.     
  292.     /*    Handle file-level DSR callbacks;
  293.         code is either a device number or a subroutine number,
  294.         as enumerated in the DSR's device name list.
  295.         This routine is only called if the DSR ROM for the
  296.         active device uses the OP_DSR opcode (0xC00..0xC1F). */
  297.     vmResult    (*filehandler)(u32 code);
  298. }    vmDSRModule;    /* vmTypeDSR */
  299.  
  300. /**********************************************/
  301.  
  302. /*    current version of module struct */
  303. #define VM_CURRENT_VERSION    3
  304.  
  305. typedef struct vmModule
  306. {
  307.     /* ------ common to all modules ------ */
  308.     
  309.     int            version;
  310.     
  311.     const char    *name;        /* screen name */
  312.     const char    *tag;        /* tag for id */
  313.     
  314.     vmType        type;
  315.     vmFlags        flags;
  316.     
  317.     /* detect whether module is usable; called before
  318.         any configuration variables are known */
  319.     vmResult    (*detect)(void);
  320.     
  321.     /* [one-time] initialization; called before any
  322.         configuration variables are known; insert your
  323.         own variables here and initialize them */
  324.     vmResult    (*init)(void);
  325.  
  326.     /* [one-time] termination at program start */
  327.     vmResult    (*term)(void);
  328.     
  329.     /*  multi-time installation; configuration
  330.         variables are known; called when module is
  331.         selected */
  332.     vmResult    (*enable)(void);
  333.  
  334.     /*  multi-time uninstallation; called when module is
  335.         unselected */
  336.     vmResult    (*disable)(void);
  337.  
  338.     /* multi-time restart; done in context switches
  339.         into 9900 mode from non-9900 mode (or when
  340.         pausing) */
  341.     vmResult    (*restart)(void);
  342.     
  343.     /* multi-time restop; done in context switches
  344.         from non-9900 mode to 9900 mode. */
  345.     vmResult    (*restop)(void);
  346.  
  347.     union 
  348.     {
  349.         vmGenericModule    *generic;
  350.         vmCPUModule        *cpu;
  351.         vmVideoModule    *video;
  352.         vmSoundModule    *sound;
  353.         vmKeyboardModule *kbd;
  354.         vmDSRModule        *dsr;
  355.     }    m;
  356.  
  357.     /* set to zero; used during runtime */
  358.     u32                runtimeflags;
  359.     struct vmModule *next;        /* of this type */
  360.     
  361. }    vmModule;
  362.  
  363. /***********************************/
  364.  
  365. int            vmModulesInit(void);
  366. int            vmModulesTerm(void);
  367. void        vmAddModuleCommands(void);
  368.  
  369. int            vmRegisterModules(vmModule **module);
  370.  
  371. vmResult    vmDetectModule(vmModule *module);
  372. vmResult    vmEnableModule(vmModule *module);
  373. vmResult    vmDisableModule(vmModule *module);
  374. vmResult    vmInitModule(vmModule *module);
  375. vmResult    vmTermModule(vmModule *module);
  376. vmResult    vmInstallModule(vmModule *module);
  377. vmResult    vmRestartModule(vmModule *module);
  378. vmResult    vmRestopModule(vmModule *module);
  379.  
  380. vmModule *vmLookupModule(char *tag);
  381.  
  382. int    vmDetectModules(void);
  383. int    vmSelectStartupModules(void);
  384. int    vmValidateModuleSelection(bool startup, bool incremental);
  385. int    vmInitModules(void);
  386. int    vmTermModules(void);
  387. int    vmEnableModules(void);
  388. int    vmDisableModules(void);
  389. int    vmRestartModules(void);
  390. int    vmRestopModules(void);
  391. int vmClearUserFlagsOnModules(void);
  392.  
  393. extern vmModule *vmCPU, *vmVideo, *vmSound,
  394.                 *vmKeyboard, *vmDSR;
  395. extern vmModule *vmCPUMain, *vmVideoMain, *vmSoundMain,
  396.                 *vmKeyboardMain;
  397. extern int vmCPUCount, vmVideoCount, vmSoundCount,
  398.             vmKeyboardCount, vmDSRCount;
  399.  
  400. INLINE vmResult MODULE_ITERATE(vmModule *start, vmResult (*routine)(vmModule *))
  401. {
  402.     vmModule *ptr = start; 
  403.     vmResult res, ret = vmOk;
  404.     while (ptr) {
  405.         res = routine(ptr);
  406.         if (res != vmOk)
  407.             ret = res;
  408.         ptr = ptr->next;
  409.     }
  410.     return ret;
  411. }
  412.  
  413. #include "cexit.h"
  414.  
  415. #endif
  416.