home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu 2008 / 2008-06-02_hobbes.nmsu.edu.zip / new / scummc-0.2.0-os2.zip / ScummC / src / scvm_thread.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-04-07  |  3.5 KB  |  127 lines

  1. /* ScummC
  2.  * Copyright (C) 2006  Alban Bedel
  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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17.  *
  18.  */
  19.  
  20. /**
  21.  * @file scvm_thread.h
  22.  * @ingroup scvm
  23.  * @brief SCVM thread implementation.
  24.  */
  25.  
  26. typedef struct scvm_script {
  27.   unsigned id;
  28.   unsigned size;
  29.   unsigned char code[0];
  30. } scvm_script_t;
  31.  
  32. /// @name Thread states
  33. //@{
  34. #define SCVM_THREAD_STOPPED 0
  35. #define SCVM_THREAD_RUNNING 1
  36. #define SCVM_THREAD_PENDED  2
  37. #define SCVM_THREAD_DELAYED 3
  38. #define SCVM_THREAD_FROZEN  4
  39. //@}
  40.  
  41. /// @name Thread flags
  42. //@{
  43. #define SCVM_THREAD_NO_FREEZE 1
  44. #define SCVM_THREAD_RECURSIVE 2
  45.  
  46. #define SCVM_THREAD_DELAY (1<<16)
  47. #define SCVM_THREAD_AT_BREAKPOINT (2<<16)
  48. //@}
  49.  
  50. #define SCVM_MAX_OVERRIDE 8
  51.  
  52. typedef struct scvm_thread scvm_thread_t;
  53.  
  54. struct scvm_thread {
  55.   unsigned id;
  56.   /// unused, running, pended, delayed, frozen
  57.   unsigned state;
  58.   /// Used for script runned by the VM itself
  59.   unsigned next_state;
  60.   /// Parent thread for recursive calls
  61.   scvm_thread_t* parent;
  62.   unsigned flags;
  63.   unsigned cycle;
  64.   /// Delay left in ms
  65.   unsigned delay;
  66.   /// Script beeing run
  67.   scvm_script_t* script;
  68.   /// Position in the code
  69.   unsigned code_ptr;
  70.   /// Code_ptr is saved here when a new op is started
  71.   unsigned op_start;
  72.   /// Thread variables
  73.   unsigned num_var;
  74.   int *var;
  75.   /// Override stack
  76.   unsigned override_ptr;
  77.   unsigned override[SCVM_MAX_OVERRIDE];
  78. };
  79.  
  80. typedef int (*scvm_op_f)(struct scvm* vm, scvm_thread_t* thread);
  81.  
  82. typedef struct scvm_op {
  83.   scvm_op_f op;
  84.   char* name;
  85. } scvm_op_t;
  86.  
  87. char* scvm_thread_state_name(unsigned state);
  88.  
  89. void scvm_thread_flags_name(unsigned flags, char* out, int size);
  90.  
  91. int scvm_thread_r8(scvm_thread_t* thread, uint8_t* ret);
  92.  
  93. int scvm_thread_r16(scvm_thread_t* thread, uint16_t* ret);
  94.  
  95. int scvm_thread_r32(scvm_thread_t* thread, uint32_t* ret);
  96.  
  97. int scvm_thread_strlen(scvm_thread_t* thread, unsigned* len);
  98.  
  99. int scvm_thread_begin_override(scvm_t* vm, scvm_thread_t* thread);
  100.  
  101. int scvm_thread_end_override(scvm_t* vm, scvm_thread_t* thread);
  102.  
  103. int scvm_start_thread(scvm_t* vm, scvm_script_t* scr, unsigned code_ptr,
  104.                       unsigned flags, unsigned* args);
  105.  
  106. int scvm_stop_thread(scvm_t* vm, scvm_thread_t* thread);
  107.  
  108. int scvm_thread_do_op(scvm_t* vm, scvm_thread_t* thread, scvm_op_t* optable);
  109.  
  110. int scvm_thread_run(scvm_t* vm, scvm_thread_t* thread);
  111.  
  112. int scvm_start_script(scvm_t* vm, unsigned flags, unsigned num, unsigned* args);
  113.  
  114. int scvm_stop_script(scvm_t* vm, unsigned id);
  115.  
  116. int scvm_is_script_running(scvm_t* vm, unsigned id);
  117.  
  118. int scvm_thread_read_var(scvm_t* vm, scvm_thread_t* thread,
  119.                          uint16_t addr, int* val);
  120.  
  121. int scvm_thread_write_var(scvm_t* vm, scvm_thread_t* thread,
  122.                           uint16_t addr, int val);
  123.  
  124. int scvm_read_array(scvm_t* vm, unsigned addr, unsigned x, unsigned y, int* val);
  125.  
  126. int scvm_write_array(scvm_t* vm, unsigned addr, unsigned x, unsigned y, int val);
  127.