home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qasm10 / qasm10.txt
Encoding:
Text File  |  1996-08-21  |  29.7 KB  |  769 lines

  1. Quake(tm) Assembler Manual 1.0
  2. ------------------------------
  3. Copyright (C) 1996 by Ferrara Francesco
  4. QUAKE (C) 1996 id software, Inc., All right reserved
  5.  
  6.  
  7.  
  8.  
  9. Table of contents
  10. -----------------
  11.  
  12. 1.      Introduction
  13. 2.      The executable file PROGS.DAT
  14. 2.      Crc calculus
  15. 4.      Statements
  16.         4.1     Descriptions of instructions
  17. 5.      Globaldefs
  18. 6.      Fielddefs
  19. 7.      Functions
  20. 8.      Strings
  21. 9.      Globals
  22. 10.     Comments
  23. 11.     Tables                   
  24.         11.1 Types
  25.         11.2 Standard offset for builtin functions 
  26.         11.3 Builtin function number
  27.  
  28.  
  29.  
  30. ________________________________________________________________________________
  31.  
  32. 1.      Introduction                                           
  33.  
  34.         This is a manual of Quake Assembler that are the instructions that Quake run for the entities in the QuakeWorld.
  35.         It is a not so complex set of instructions. It's different from the sets known to computer world. I have written this manual from the analyzing of qcc compiler. The QuakeC compiler (qcc) can compile a subset of the ANSI C language into Quake Assembler so the game can run these instructions.
  36.         If you want an introduction of the Quake Entities please read the one of the QuakeC specs. 
  37.         This manual is written to help the writing of other compilers maybe C++ or Assemblers for the game Quake. QuakeC is a lot far from the best compiler.
  38.         All sources between bars are taken from the source code of QCC the QuakeC compiler. 
  39.         Please excuse my poor english, think to read this in Italian. If you want to help me with english write to the address below.
  40.         This text is E-mail ware if you found this text useful you must write to me an e-mail letter!!! ;)
  41.         
  42.         E-Mail: frank@aerre.it
  43.         HPage:  http:\\www.aerre.it\~frank\qasm10.txt
  44.         
  45. ________________________________________________________________________________
  46.  
  47. 2.      The executable file PROGS.DAT
  48.  
  49.         Quake run the file progs.dat that is in your game data directory. That is \QUAKE\ID1 or the dir that you have specified with the '-game' option. 
  50.         It contains the instructions, the data, and the names of all your variables. The first thing in the file is the header. A struct that contains the number and the offset of the other struct of the datas.
  51.         Now you can read below the first structure of progs.dat:
  52.     
  53. -------------------------
  54. typedef struct
  55. {
  56.     int        version;        
  57.     // The version nr. is 6 in Q1.01
  58.     int        crc;            
  59.     // check of header file read CRC            
  60.     int        ofs_statements; 
  61.     // This is the offset from the beginning of the file
  62.     int        numstatements;  
  63.     // This is the number of asm istructions 4 short wide (4*2 bytes)
  64.     int        ofs_globaldefs; 
  65.     int        numglobaldefs;  
  66.     // That contains the definition of the names of variables
  67.     int        ofs_fielddefs;
  68.     int        numfielddefs;   
  69.     // That contains the definition of the names of fields of entity
  70.     int        ofs_functions;  
  71.     int        numfunctions;   
  72.     // This is the nr. of info struct for functions
  73.     int        ofs_strings;
  74.     int        numstrings;     
  75.     // This is the nr. of byte that this list contains
  76.     int        ofs_globals;
  77.     int        numglobals;     
  78.     // That is a long list of float values
  79.     int        entityfields;   
  80.     // How many field that are in the entity data struct
  81. } dprograms_t;
  82. -------------------------
  83. ________________________________________________________________________________
  84.         
  85. 3.      CRC Calculus
  86.         
  87.         This is a 16 bit, non-reflected CRC using the polynomial 0x1021 and the initial and final xor values shown below...  in other words, the CCITT standard CRC used by XMODEM.
  88.  
  89. -------------------------
  90. #define CRC_INIT_VALUE    0xffff
  91. #define CRC_XOR_VALUE    0x0000
  92.  
  93. static unsigned short crctable[256] =
  94. {
  95.     0x0000,    0x1021,    0x2042,    0x3063,    0x4084,    0x50a5,    0x60c6,    0x70e7,
  96.     0x8108,    0x9129,    0xa14a,    0xb16b,    0xc18c,    0xd1ad,    0xe1ce,    0xf1ef,
  97.     0x1231,    0x0210,    0x3273,    0x2252,    0x52b5,    0x4294,    0x72f7,    0x62d6,
  98.     0x9339,    0x8318,    0xb37b,    0xa35a,    0xd3bd,    0xc39c,    0xf3ff,    0xe3de,
  99.     0x2462,    0x3443,    0x0420,    0x1401,    0x64e6,    0x74c7,    0x44a4,    0x5485,
  100.     0xa56a,    0xb54b,    0x8528,    0x9509,    0xe5ee,    0xf5cf,    0xc5ac,    0xd58d,
  101.     0x3653,    0x2672,    0x1611,    0x0630,    0x76d7,    0x66f6,    0x5695,    0x46b4,
  102.     0xb75b,    0xa77a,    0x9719,    0x8738,    0xf7df,    0xe7fe,    0xd79d,    0xc7bc,
  103.     0x48c4,    0x58e5,    0x6886,    0x78a7,    0x0840,    0x1861,    0x2802,    0x3823,
  104.     0xc9cc,    0xd9ed,    0xe98e,    0xf9af,    0x8948,    0x9969,    0xa90a,    0xb92b,
  105.     0x5af5,    0x4ad4,    0x7ab7,    0x6a96,    0x1a71,    0x0a50,    0x3a33,    0x2a12,
  106.     0xdbfd,    0xcbdc,    0xfbbf,    0xeb9e,    0x9b79,    0x8b58,    0xbb3b,    0xab1a,
  107.     0x6ca6,    0x7c87,    0x4ce4,    0x5cc5,    0x2c22,    0x3c03,    0x0c60,    0x1c41,
  108.     0xedae,    0xfd8f,    0xcdec,    0xddcd,    0xad2a,    0xbd0b,    0x8d68,    0x9d49,
  109.     0x7e97,    0x6eb6,    0x5ed5,    0x4ef4,    0x3e13,    0x2e32,    0x1e51,    0x0e70,
  110.     0xff9f,    0xefbe,    0xdfdd,    0xcffc,    0xbf1b,    0xaf3a,    0x9f59,    0x8f78,
  111.     0x9188,    0x81a9,    0xb1ca,    0xa1eb,    0xd10c,    0xc12d,    0xf14e,    0xe16f,
  112.     0x1080,    0x00a1,    0x30c2,    0x20e3,    0x5004,    0x4025,    0x7046,    0x6067,
  113.     0x83b9,    0x9398,    0xa3fb,    0xb3da,    0xc33d,    0xd31c,    0xe37f,    0xf35e,
  114.     0x02b1,    0x1290,    0x22f3,    0x32d2,    0x4235,    0x5214,    0x6277,    0x7256,
  115.     0xb5ea,    0xa5cb,    0x95a8,    0x8589,    0xf56e,    0xe54f,    0xd52c,    0xc50d,
  116.     0x34e2,    0x24c3,    0x14a0,    0x0481,    0x7466,    0x6447,    0x5424,    0x4405,
  117.     0xa7db,    0xb7fa,    0x8799,    0x97b8,    0xe75f,    0xf77e,    0xc71d,    0xd73c,
  118.     0x26d3,    0x36f2,    0x0691,    0x16b0,    0x6657,    0x7676,    0x4615,    0x5634,
  119.     0xd94c,    0xc96d,    0xf90e,    0xe92f,    0x99c8,    0x89e9,    0xb98a,    0xa9ab,
  120.     0x5844,    0x4865,    0x7806,    0x6827,    0x18c0,    0x08e1,    0x3882,    0x28a3,
  121.     0xcb7d,    0xdb5c,    0xeb3f,    0xfb1e,    0x8bf9,    0x9bd8,    0xabbb,    0xbb9a,
  122.     0x4a75,    0x5a54,    0x6a37,    0x7a16,    0x0af1,    0x1ad0,    0x2ab3,    0x3a92,
  123.     0xfd2e,    0xed0f,    0xdd6c,    0xcd4d,    0xbdaa,    0xad8b,    0x9de8,    0x8dc9,
  124.     0x7c26,    0x6c07,    0x5c64,    0x4c45,    0x3ca2,    0x2c83,    0x1ce0,    0x0cc1,
  125.     0xef1f,    0xff3e,    0xcf5d,    0xdf7c,    0xaf9b,    0xbfba,    0x8fd9,    0x9ff8,
  126.     0x6e17,    0x7e36,    0x4e55,    0x5e74,    0x2e93,    0x3eb2,    0x0ed1,    0x1ef0
  127. };
  128.  
  129. void CRC_Init(unsigned short *crcvalue)
  130. {
  131.     *crcvalue = CRC_INIT_VALUE;
  132. }
  133.  
  134. void CRC_ProcessByte(unsigned short *crcvalue, byte data)
  135. {
  136.     *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
  137. }
  138.  
  139. unsigned short CRC_Value(unsigned short crcvalue)
  140. {
  141.     return crcvalue ^ CRC_XOR_VALUE;
  142. }                  
  143. -------------------------                            
  144.  
  145.  
  146.  
  147.         You must construct a file progdefs.h like this:
  148.         
  149.         
  150.         
  151.         
  152. -------------------------
  153. /* file generated by qcc, do not modify */
  154.  
  155. typedef struct
  156. {    int    pad[28];
  157.     int    self;
  158.     int    other;
  159.     int    world;
  160.     float    time;
  161.     float    frametime;
  162.     float    force_retouch;
  163.     string_t    mapname;
  164.     float    deathmatch;
  165.     float    coop;
  166.     float    teamplay;
  167.     float    serverflags;
  168.     float    total_secrets;
  169.     float    total_monsters;
  170.     float    found_secrets;
  171.     float    killed_monsters;
  172.     float    parm1;
  173.     float    parm2;
  174.     float    parm3;
  175.     float    parm4;
  176.     float    parm5;
  177.     float    parm6;
  178.     float    parm7;
  179.     float    parm8;
  180.     float    parm9;
  181.     float    parm10;
  182.     float    parm11;
  183.     float    parm12;
  184.     float    parm13;
  185.     float    parm14;
  186.     float    parm15;
  187.     float    parm16;
  188.     vec3_t    v_forward;
  189.     vec3_t    v_up;
  190.     vec3_t    v_right;
  191.     float    trace_allsolid;
  192.     float    trace_startsolid;
  193.     float    trace_fraction;
  194.     vec3_t    trace_endpos;
  195.     vec3_t    trace_plane_normal;
  196.     float    trace_plane_dist;
  197.     int    trace_ent;
  198.     float    trace_inopen;
  199.     float    trace_inwater;
  200.     int    msg_entity;
  201.     func_t    main;
  202.     func_t    StartFrame;
  203.     func_t    PlayerPreThink;
  204.     func_t    PlayerPostThink;
  205.     func_t    ClientKill;
  206.     func_t    ClientConnect;
  207.     func_t    PutClientInServer;
  208.     func_t    ClientDisconnect;
  209.     func_t    SetNewParms;
  210.     func_t    SetChangeParms;
  211. } globalvars_t;
  212.  
  213. typedef struct
  214. {
  215.     float    modelindex;
  216.     vec3_t    absmin;
  217.     vec3_t    absmax;
  218.     float    ltime;
  219.     float    movetype;
  220.     float    solid;
  221.     vec3_t    origin;
  222.     vec3_t    oldorigin;
  223.     vec3_t    velocity;
  224.     vec3_t    angles;
  225.     vec3_t    avelocity;
  226.     vec3_t    punchangle;
  227.     string_t    classname;
  228.     string_t    model;
  229.     float    frame;
  230.     float    skin;
  231.     float    effects;
  232.     vec3_t    mins;
  233.     vec3_t    maxs;
  234.     vec3_t    size;
  235.     func_t    touch;
  236.     func_t    use;
  237.     func_t    think;
  238.     func_t    blocked;
  239.     float    nextthink;
  240.     int    groundentity;
  241.     float    health;
  242.     float    frags;
  243.     float    weapon;
  244.     string_t    weaponmodel;
  245.     float    weaponframe;
  246.     float    currentammo;
  247.     float    ammo_shells;
  248.     float    ammo_nails;
  249.     float    ammo_rockets;
  250.     float    ammo_cells;
  251.     float    items;
  252.     float    takedamage;
  253.     int    chain;
  254.     float    deadflag;
  255.     vec3_t    view_ofs;
  256.     float    button0;
  257.     float    button1;
  258.     float    button2;
  259.     float    impulse;
  260.     float    fixangle;
  261.     vec3_t    v_angle;
  262.     float    idealpitch;
  263.     string_t    netname;
  264.     int    enemy;
  265.     float    flags;
  266.     float    colormap;
  267.     float    team;
  268.     float    max_health;
  269.     float    teleport_time;
  270.     float    armortype;
  271.     float    armorvalue;
  272.     float    waterlevel;
  273.     float    watertype;
  274.     float    ideal_yaw;
  275.     float    yaw_speed;
  276.     int    aiment;
  277.     int    goalentity;
  278.     float    spawnflags;
  279.     string_t    target;
  280.     string_t    targetname;
  281.     float    dmg_take;
  282.     float    dmg_save;
  283.     int    dmg_inflictor;
  284.     int    owner;
  285.     vec3_t    movedir;
  286.     string_t    message;
  287.     float    sounds;
  288.     string_t    noise;
  289.     string_t    noise1;
  290.     string_t    noise2;
  291.     string_t    noise3;
  292. } entvars_t;
  293.  
  294. #define PROGHEADER_CRC 5927
  295. -------------------------
  296.  
  297.  
  298.  
  299.         With the two struct of global vars and entities vars pass this file byte by byte to crc and then write the last line the the decimal code.
  300.         Like this functions, the filename is "progdefs.h":
  301.  
  302.  
  303.  
  304.  
  305.         
  306. -------------------------
  307. int    PR_WriteProgdefs (char *filename)
  308. {
  309.     def_t    *d;
  310.     FILE    *f;
  311.     unsigned short        crc;
  312.     int        c;
  313.     
  314.     printf ("writing %s\n", filename);
  315.     f = fopen (filename, "w");
  316.     
  317. // print global vars until the first field is defined
  318.     fprintf (f,"\n/* file generated by qcc, do not modify */\n\ntypedef struct\n{\tint\tpad[%i];\n", RESERVED_OFS);
  319.     for (d=pr.def_head.next ; d ; d=d->next)
  320.     {
  321.         if (!strcmp (d->name, "end_sys_globals"))
  322.             break;
  323.             
  324.         switch (d->type->type)
  325.         {
  326.         case ev_float:
  327.             fprintf (f, "\tfloat\t%s;\n",d->name);
  328.             break;
  329.         case ev_vector:
  330.             fprintf (f, "\tvec3_t\t%s;\n",d->name);
  331.             d=d->next->next->next;    // skip the elements
  332.             break;
  333.         case ev_string:
  334.             fprintf (f,"\tstring_t\t%s;\n",d->name);
  335.             break;
  336.         case ev_function:
  337.             fprintf (f,"\tfunc_t\t%s;\n",d->name);
  338.             break;
  339.         case ev_entity:
  340.             fprintf (f,"\tint\t%s;\n",d->name);
  341.             break;
  342.         default:
  343.             fprintf (f,"\tint\t%s;\n",d->name);
  344.             break;
  345.         }
  346.     }
  347.     fprintf (f,"} globalvars_t;\n\n");
  348.  
  349. // print all fields
  350.     fprintf (f,"typedef struct\n{\n");
  351.     for (d=pr.def_head.next ; d ; d=d->next)
  352.     {
  353.         if (!strcmp (d->name, "end_sys_fields"))
  354.             break;
  355.             
  356.         if (d->type->type != ev_field)
  357.             continue;
  358.             
  359.         switch (d->type->aux_type->type)
  360.         {
  361.         case ev_float:
  362.             fprintf (f,"\tfloat\t%s;\n",d->name);
  363.             break;
  364.         case ev_vector:
  365.             fprintf (f,"\tvec3_t\t%s;\n",d->name);
  366.             d=d->next->next->next;    // skip the elements
  367.             break;
  368.         case ev_string:
  369.             fprintf (f,"\tstring_t\t%s;\n",d->name);
  370.             break;
  371.         case ev_function:
  372.             fprintf (f,"\tfunc_t\t%s;\n",d->name);
  373.             break;
  374.         case ev_entity:
  375.             fprintf (f,"\tint\t%s;\n",d->name);
  376.             break;
  377.         default:
  378.             fprintf (f,"\tint\t%s;\n",d->name);
  379.             break;
  380.         }
  381.     }
  382.     fprintf (f,"} entvars_t;\n\n");
  383.     
  384.     fclose (f);
  385.     
  386. // do a crc of the file
  387.     CRC_Init (&crc);
  388.     f = fopen (filename, "r+");
  389.     while ((c = fgetc(f)) != EOF)
  390.         CRC_ProcessByte (&crc, c);
  391.         
  392.     fprintf (f,"#define PROGHEADER_CRC %i\n", crc);
  393.     fclose (f);
  394.  
  395.     return crc;
  396. }       
  397. -------------------------
  398.  
  399.  
  400. ________________________________________________________________________________
  401.  
  402. 4.      Statements
  403.  
  404.         The structure of one asm istruction is:
  405.  
  406. -------------------------
  407. typedef struct statement_s
  408. {
  409.     unsigned short    op;
  410.     short    a,b,c;
  411. } dstatement_t;
  412. -------------------------
  413.         The op is the opcode that are:
  414.         Nummber,Name, Priotity, RightAssociative, 1stpar, 2ndpar, respar.
  415.         
  416.         0x00    DONE, -1, false, &def_entity, &def_field, &def_void
  417.         0x01    MUL_F, 2, false, &def_float, &def_float, &def_float
  418.         0x02    MUL_V, 2, false, &def_vector, &def_vector, &def_float
  419.         0x03    MUL_FV, 2, false, &def_float, &def_vector, &def_vector
  420.         0x04    MUL_VF, 2, false, &def_vector, &def_float, &def_vector
  421.         0x05    DIV, 2, false, &def_float, &def_float, &def_float
  422.         0x06    ADD_F, 3, false, &def_float, &def_float, &def_float
  423.         0x07    ADD_V, 3, false, &def_vector, &def_vector, &def_vector
  424.         0x08    SUB_F, 3, false, &def_float, &def_float, &def_float
  425.         0x09    SUB_V, 3, false, &def_vector, &def_vector, &def_vector
  426.         0x0a    EQ_F, 4, false, &def_float, &def_float, &def_float
  427.         0x0b    EQ_V, 4, false, &def_vector, &def_vector, &def_float
  428.         0x0c    EQ_S, 4, false, &def_string, &def_string, &def_float
  429.         0x0d    EQ_E, 4, false, &def_entity, &def_entity, &def_float
  430.         0x0e    EQ_FNC, 4, false, &def_function, &def_function, &def_float
  431.         0x0f    NE_F, 4, false, &def_float, &def_float, &def_float
  432.         0x10    NE_V, 4, false, &def_vector, &def_vector, &def_float
  433.         0x11    NE_S, 4, false, &def_string, &def_string, &def_float
  434.         0x12    NE_E, 4, false, &def_entity, &def_entity, &def_float
  435.         0x13    NE_FNC, 4, false, &def_function, &def_function, &def_float
  436.         0x14    LE, 4, false, &def_float, &def_float, &def_float
  437.         0x15    GE, 4, false, &def_float, &def_float, &def_float
  438.         0x16    LT, 4, false, &def_float, &def_float, &def_float
  439.         0x17    GT, 4, false, &def_float, &def_float, &def_float
  440.         0x18    INDIRECT, 1, false, &def_entity, &def_field, &def_float
  441.         0x19    INDIRECT, 1, false, &def_entity, &def_field, &def_vector
  442.         0x1a    INDIRECT, 1, false, &def_entity, &def_field, &def_string
  443.         0x1b    INDIRECT, 1, false, &def_entity, &def_field, &def_entity
  444.         0x1c    INDIRECT, 1, false, &def_entity, &def_field, &def_field
  445.         0x1d    INDIRECT, 1, false, &def_entity, &def_field, &def_function
  446.         0x1e    ADDRESS, 1, false, &def_entity, &def_field, &def_pointer
  447.         0x1f    STORE_F, 5, true, &def_float, &def_float, &def_float
  448.         0x20    STORE_V, 5, true, &def_vector, &def_vector, &def_vector
  449.         0x21    STORE_S, 5, true, &def_string, &def_string, &def_string
  450.         0x22    STORE_ENT, 5, true, &def_entity, &def_entity, &def_entity
  451.         0x23    STORE_FLD, 5, true, &def_field, &def_field, &def_field
  452.         0x24    STORE_FNC, 5, true, &def_function, &def_function&def_function},
  453.         0x25    STOREP_F, 5, true, &def_pointer, &def_float, &def_float
  454.         0x26    STOREP_V, 5, true, &def_pointer, &def_vector, &def_vector
  455.         0x27    STOREP_S, 5, true, &def_pointer, &def_string, &def_string
  456.         0x28    STOREP_ENT, 5, true, &def_pointer, &def_entity, &def_entity
  457.         0x29    STOREP_FLD, 5, true, &def_pointer, &def_field, &def_field
  458.         0x2a    STOREP_FNC, 5, true, &def_pointer, &def_function&def_function},
  459.         0x2b    RETURN, -1, false, &def_void, &def_void, &def_void
  460.         0x2c    NOT_F, -1, false, &def_float, &def_void, &def_float
  461.         0x2d    NOT_V, -1, false, &def_vector, &def_void, &def_float
  462.         0x2e    NOT_S, -1, false, &def_vector, &def_void, &def_float
  463.         0x2f    NOT_ENT, -1, false, &def_entity, &def_void, &def_float
  464.         0x30    NOT_FNC, -1, false, &def_function, &def_void, &def_float
  465.         0x31    IF, -1, false, &def_float, &def_float, &def_void
  466.         0x32    IFNOT, -1, false, &def_float, &def_float, &def_void
  467.         0x33    CALL0, -1, false, &def_function, &def_void, &def_void
  468.         0x34    CALL1, -1, false, &def_function, &def_void, &def_void
  469.         0x35    CALL2, -1, false, &def_function, &def_void, &def_void}
  470.         0x36    CALL3, -1, false, &def_function, &def_void, &def_void}
  471.         0x37    CALL4, -1, false, &def_function, &def_void, &def_void
  472.         0x38    CALL5, -1, false, &def_function, &def_void, &def_void
  473.         0x39    CALL6, -1, false, &def_function, &def_void, &def_void
  474.         0x3a    CALL7, -1, false, &def_function, &def_void, &def_void
  475.         0x3b    CALL8, -1, false, &def_function, &def_void, &def_void
  476.         0x3c    STATE, -1, false, &def_float, &def_float, &def_void
  477.         0x3d    GOTO, -1, false, &def_float, &def_void, &def_void
  478.         0x3e    AND, 6, false, &def_float, &def_float, &def_float
  479.         0x3f    OR, 6, false, &def_float, &def_float, &def_float
  480.         0x40    BITAND, 2, false, &def_float, &def_float, &def_float
  481.         0x41    BITOR, 2, false, &def_float, &def_float, &def_float
  482.  
  483. 4.1     Descriptions of instructions           
  484.         
  485.         0x00    DONE
  486.                 It is the last istr. of procedure. That end the proc.
  487.         0x01    MUL_F, 2, false, &def_float, &def_float, &def_float  
  488.         0x02    MUL_V, 2, false, &def_vector, &def_vector, &def_float
  489.         0x03    MUL_FV, 2, false, &def_float, &def_vector, &def_vector
  490.         0x04    MUL_VF, 2, false, &def_vector, &def_float, &def_vector
  491.                 These instruction multiply their args
  492.         0x05    DIV, 2, false, &def_float, &def_float, &def_float
  493.                 Only two float can be divided
  494.         0x06    ADD_F, 3, false, &def_float, &def_float, &def_float
  495.         0x07    ADD_V, 3, false, &def_vector, &def_vector, &def_vector
  496.                 Adding. You can't add a float to a vector
  497.         0x08    SUB_F, 3, false, &def_float, &def_float, &def_float
  498.         0x09    SUB_V, 3, false, &def_vector, &def_vector, &def_vector
  499.                 Subtract.
  500.         0x0a    EQ_F, 4, false, &def_float, &def_float, &def_float
  501.         0x0b    EQ_V, 4, false, &def_vector, &def_vector, &def_float
  502.         0x0c    EQ_S, 4, false, &def_string, &def_string, &def_float
  503.         0x0d    EQ_E, 4, false, &def_entity, &def_entity, &def_float
  504.                 These instr. test the the 1st and the 2nd args and then
  505.                 emit in the result 0(false) or 1(true) the answer.
  506.         0x0e    EQ_FNC, 4, false, &def_function, &def_function, &def_float
  507.                 This instruction test if a function is defined.
  508.         0x0f    NE_F, 4, false, &def_float, &def_float, &def_float
  509.         0x10    NE_V, 4, false, &def_vector, &def_vector, &def_float
  510.         0x11    NE_S, 4, false, &def_string, &def_string, &def_float
  511.         0x12    NE_E, 4, false, &def_entity, &def_entity, &def_float
  512.                 Not equal.
  513.         0x13    NE_FNC, 4, false, &def_function, &def_function, &def_float
  514.                 This istruction test if a function is not defined
  515.         0x14    LE, 4, false, &def_float, &def_float, &def_float
  516.                 1st <= 2nd args 0(false) 1(true) in result
  517.         0x15    GE, 4, false, &def_float, &def_float, &def_float
  518.                 1st >= 2nd args 0(false) 1(true) in result
  519.         0x16    LT, 4, false, &def_float, &def_float, &def_float
  520.                 1st < 2nd args 0(false) 1(true) in result
  521.         0x17    GT, 4, false, &def_float, &def_float, &def_float 
  522.                 1st > 2nd args 0(false) 1(true) in result
  523.         0x18    INDIRECT, 1, false, &def_entity, &def_field, &def_float
  524.                 Access a float field in an entity vars.
  525.         0x19    INDIRECT, 1, false, &def_entity, &def_field, &def_vector
  526.                 Access a vector field in an entity vars.
  527.         0x1a    INDIRECT, 1, false, &def_entity, &def_field, &def_string
  528.                 Access a string field in an entity vars.
  529.         0x1b    INDIRECT, 1, false, &def_entity, &def_field, &def_entity
  530.                 Access a entity field in an entity vars.
  531.         0x1c    INDIRECT, 1, false, &def_entity, &def_field, &def_field
  532.                 Access a field field in an entity vars.
  533.         0x1d    INDIRECT, 1, false, &def_entity, &def_field, &def_function
  534.                 Access a function field in an entity vars.
  535.         0x1e    ADDRESS, 1, false, &def_entity, &def_field, &def_pointer
  536.                 write a globals position of a entity.field type
  537.         0x1f    STORE_F, 5, true, &def_float, &def_float, &def_float
  538.                 Movs a 1st vars in the 2nd, 3rd is ignored.
  539.         0x20    STORE_V, 5, true, &def_vector, &def_vector, &def_vector
  540.         0x21    STORE_S, 5, true, &def_string, &def_string, &def_string
  541.         0x22    STORE_ENT, 5, true, &def_entity, &def_entity, &def_entity
  542.         0x23    STORE_FLD, 5, true, &def_field, &def_field, &def_field
  543.         0x24    STORE_FNC, 5, true, &def_function, &def_function, &def_function
  544.         0x25    STOREP_F, 5, true, &def_pointer, &def_float, &def_float        
  545.                 These instruction read the pointer grab the float in and write                  this to the 2nd pars
  546.         0x26    STOREP_V, 5, true, &def_pointer, &def_vector, &def_vector
  547.         0x27    STOREP_S, 5, true, &def_pointer, &def_string, &def_string
  548.         0x28    STOREP_ENT, 5, true, &def_pointer, &def_entity, &def_entity
  549.         0x29    STOREP_FLD, 5, true, &def_pointer, &def_field, &def_field
  550.         0x2a    STOREP_FNC, 5, true, &def_pointer, &def_function, &def_function
  551.         0x2b    RETURN, -1, false, &def_void, &def_void, &def_void
  552.                 This function return from a function. Contrary to DONE it is not                the end of the function.
  553.         0x2c    NOT_F, -1, false, &def_float, &def_void, &def_float
  554.         0x2d    NOT_V, -1, false, &def_vector, &def_void, &def_float
  555.         0x2e    NOT_S, -1, false, &def_vector, &def_void, &def_float
  556.         0x2f    NOT_ENT, -1, false, &def_entity, &def_void, &def_float
  557.         0x30    NOT_FNC, -1, false, &def_function, &def_void, &def_float
  558.                 These istr. are logical not bitwise.
  559.         0x31    IF, -1, false, &def_float, &def_float, &def_void
  560.                 If 1st pars is true next istr is 2nd pars istr. after                   0x32    IFNOT, -1, false, &def_float, &def_float, &def_void
  561.                 If 1st pars is false next istr is 2nd pars istr. after                  0x33    CALL0, -1, false, &def_function, &def_void, &def_void
  562.                 A call with 0 parameter.
  563.         0x34    CALL1, -1, false, &def_function, &def_void, &def_void
  564.                 A call with 1 parameter.
  565.         0x35    CALL2, -1, false, &def_function, &def_void, &def_void
  566.                 A call with 2 parameter.
  567.         0x36    CALL3, -1, false, &def_function, &def_void, &def_void
  568.                 A call with 3 parameter.
  569.         0x37    CALL4, -1, false, &def_function, &def_void, &def_void
  570.                 A call with 4 parameter.
  571.         0x38    CALL5, -1, false, &def_function, &def_void, &def_void
  572.                 A call with 5 parameter.
  573.         0x39    CALL6, -1, false, &def_function, &def_void, &def_void
  574.                 A call with 6 parameter.
  575.         0x3a    CALL7, -1, false, &def_function, &def_void, &def_void
  576.                 A call with 7 parameter.
  577.         0x3b    CALL8, -1, false, &def_function, &def_void, &def_void
  578.                 A call with 8 parameter.
  579.         0x3c    STATE, -1, false, &def_float, &def_float, &def_void
  580.                 the 1st arg is written to self.frame the 2nd is written 
  581.                 to self.think, self.nextthink is automatically time+0.1
  582.         0x3d    GOTO, -1, false, &def_float, &def_void, &def_void  
  583.                 Goto to 1st pars istr. after is neg is before.
  584.         0x3e    AND, 6, false, &def_float, &def_float, &def_float
  585.                 Logical and
  586.         0x3f    OR, 6, false, &def_float, &def_float, &def_float
  587.                 Logical or
  588.         0x40    BITAND, 2, false, &def_float, &def_float, &def_float
  589.                 Bitwise and
  590.         0x41    BITOR, 2, false, &def_float, &def_float, &def_float
  591.                 Bitwise or
  592.            
  593.  
  594. ________________________________________________________________________________
  595.         
  596. 5.      Globaldefs
  597.  
  598.         Are simply a long list of struct that can contain all variables in the game. The type are in the range 0-7 and the ofs is the position in the globals list. s_name is the position in the stings list. if DEF_SAVEGLOBGAL is 1 than that variable must be save in save game.
  599.         
  600. -------------------------
  601. typedef struct
  602. {
  603.     unsigned short    type;
  604.     unsigned short    ofs;
  605.     int            s_name;
  606. } ddef_t;
  607. #define    DEF_SAVEGLOBGAL    (1<<15)
  608. -------------------------
  609. ________________________________________________________________________________
  610.         
  611. 6.      Fielddefs
  612.  
  613.         It's the same of Globaldefs but are the name of the fields of the entity structure.
  614.                 ________________________________________________________________________________        
  615. 7.      Functions
  616.  
  617.         In this list of structures you can find all info that you want for the functions:                   
  618.         
  619. -------------------------
  620. #define    MAX_PARMS    8       // The max number of parameters
  621. typedef struct
  622. {
  623.     int        first_statement;    // negative numbers are builtins
  624.     // This is the number of the first istructions in statements structs.
  625.     int        parm_start;
  626.     // This is the number of the 1st parm in the global heap
  627.     int        locals;        // total ints of parms + locals
  628.     // ex: 7 for 1 entities 1 vector 1 float 1 func 1 local float
  629.     int        profile;        // runtime info set to 0
  630.     
  631.     int        s_name;             // string number of the name    
  632.     int        s_file;        // source file defined in
  633.     
  634.     int        numparms;
  635.     byte           parm_size[MAX_PARMS]; 
  636. } dfunction_t;
  637. -------------------------
  638.         Note: 
  639.         Entity  =       1 float
  640.         float   =       1 float
  641.         vector  =       3 float
  642.         func    =       1 float
  643. ________________________________________________________________________________        
  644. 8.      Strings
  645.  
  646.         The strings data are zero-terminated c-style strings. That can contain the name of the functions or the name of the variables or simply strings to be printed in your code.
  647.         All strings are associated with a number that is the positions in the list of strings. The First string is the number 0. 
  648.         Warning: the s_name field in all other struct is the positions in the list of strings NOT the offset.
  649.         ex:
  650.         "pippo0pluto0paperino0"
  651.         s_name:
  652.         0       pippo
  653.         1       pluto
  654.         2       paperino
  655.  
  656. ________________________________________________________________________________        
  657. 9.      Globals
  658.  
  659.         A long list of floats. All float are 32-bit wide.
  660. ________________________________________________________________________________
  661.         
  662. 10.     Comments
  663.  
  664.         All parameter are not dinamically allocated but are fixed in the globals list. The function use only 28 fixed positions in the global list to pass parameters. Read tables below. Quake engine read the 28 fixed position and write to the parameters of the function explaned 
  665.         Globals for functions are 0.0 fixed. Quake can reading functions list fill the value with the correct position in the list. Builtin function have negative first_statement number.
  666.         Warning all number are position in another structure not offset in the structure. All structure have fixed dim only strings is size-variable, but you can reconstruct a list of pointers to the strings. So reading a s_name field you can regenerate the name of that var.
  667.       
  668. ________________________________________________________________________________
  669.  
  670. 11.     Tables
  671.  
  672. 11.1    Types (number of globals allocated)
  673.         
  674.         0       void    (0)
  675.         1       string  (0)
  676.         2       float   (1)
  677.         3       vector  (3)
  678.         4       entity  (1)
  679.         5       field   (0)
  680.         6       function(1)
  681.         7       pointer (1)
  682.         
  683. 11.2    Standard offset to passing func functions 
  684.         
  685.         All parameters have 3 float of space to have the possibility to pass vectors. 
  686.         
  687.         0       Null 
  688.         1       Return value
  689.         4       1st parameter 
  690.         7       2nd parameter
  691.         10      3rd parameter
  692.         13      4th parameter
  693.         16      5th parameter
  694.         19      6th parameter
  695.         22      7th parameter
  696.         25      8th parameter            
  697.         
  698.         28      First free globals position
  699.         
  700. 11.3    Builtin function number
  701.  
  702.         makevectors:     -1
  703.         setorigin:       -2
  704.         setmodel:        -3
  705.         setsize:         -4
  706.         break:           -6
  707.         random:          -7
  708.         sound:           -8
  709.         normalize:       -9
  710.         error:           -10
  711.         objerror:        -11
  712.         vlen:            -12
  713.         vectoyaw:        -13
  714.         spawn:           -14
  715.         remove:          -15
  716.         traceline:       -16
  717.         checkclient:     -17
  718.         find:            -18
  719.         precache_sound:  -19
  720.         precache_model:  -20
  721.         stuffcmd:        -21
  722.         findradius:      -22
  723.         bprint:          -23
  724.         sprint:          -24
  725.         dprint:          -25
  726.         ftos:            -26
  727.         vtos:            -27
  728.         coredump:        -28
  729.         traceon:         -29
  730.         traceoff:        -30
  731.         eprint:          -31
  732.         walkmove:        -32
  733.         droptofloor:     -34
  734.         lightstyle:      -35
  735.         rint:            -36
  736.         floor:           -37
  737.         ceil:            -38
  738.         checkbottom:     -40
  739.         pointcontents:   -41
  740.         fabs:            -43
  741.         aim:             -44
  742.         cvar:            -45
  743.         localcmd:        -46
  744.         nextent:         -47
  745.         particle:        -48
  746.         ChangeYaw:       -49
  747.         vectoangles:     -51
  748.         WriteByte:       -52
  749.         WriteChar:       -53
  750.         WriteShort:      -54
  751.         WriteLong:       -55
  752.         WriteCoord:      -56
  753.         WriteAngle:      -57
  754.         WriteString:     -58
  755.         WriteEntity:     -59
  756.         movetogoal:      -67
  757.         precache_file:   -68
  758.         makestatic:      -69
  759.         changelevel:     -70
  760.         cvar_set:        -72
  761.         centerprint:     -73
  762.         ambientsound:    -74
  763.         precache_model2: -75
  764.         precache_sound2: -76
  765.         precache_file2:  -77
  766.         setspawnparms:   -78                                    
  767.         
  768. ________________________________________________________________________________
  769. Copyright(C) 1996 by Ferrara Francesco (frank@aerre.it), id Software Inc.