-typedef struct
-{
- int todo;
-} Opcode_dict;
-
-
-struct
-{
- int zversion; /* 0 - 8 */
- int zorkid; /* 0 - 65535 */
- char zserial[7]; /* YYMMDD */
- Opcode_dict *opcode_dict;
-} Config;
-
-
-struct String_Table_Elem
-{
- string value; // value in ASCII format
- int index;
-};
-
-
-class CMain
-{
-public:
- CMain ();
- int assembly ();
- void fill_config (void);
- void get_arguments (int argc, char *argv[], char *envp[]);
-
- char *get_output_file_name ();
-private:
- char *m_output_file;
- list < String_Table_Elem > m_string_table;
- int m_code_size;
-
-
- char *build_output_filename (const char basename[], const char *suffix);
- void fill_zserial (void);
- void new_file_suffix (char *result, size_t maxlen, const char *src,
- const char *newsuffix);
-
- void output_code_section ();
-
- void parse_intarg (int *dest, const char name[], int min, int max,
- int defval);
- void parse_zserial (void);
- void print_usage (int failed);
- void print_version ();
- void wrong_arg (const char *err, ...);
-
-};
-
-
-CMain::CMain ():m_output_file (NULL)
-{
-}
-
-int
-CMain::assembly ()
-{
- FILE *file = fopen (m_output_file, "wb");
- if (file)
- {
- program_header_reset (6);
- int size = sizeof (Program_header);
-
- Program_header.mode = 0;
- Program_header.release = 1; // game version
-
- int code_start_offset = 64;
- Program_header.startPC = code_start_offset >> 2;
-
- m_code_size = 0;
- ZMemblock *zmem_code = zmem_init (65536);
-
- /// write zero number of local variables
- zmem_putbyte (zmem_code, 0); // number of local variables
- ++m_code_size;
-
- // write instructions' codes
- for (int i = 0; i < g_numberOfInstructions; ++i)
- {
- for (int j = 0; j < g_codes[i]->used_size; ++j)
- {
- zmem_putbyte (zmem_code, g_codes[i]->contents[j]);
- ++m_code_size;
- }
- }
-
- if (m_code_size & 7)
- m_code_size += 8 - (m_code_size & 7);
-
- Program_header.dynamic_size = 8;
-
- //Program_header.h_file_size = 33; //sizeof(Program_header) + zmb->used_size;
-
- //m_code_size = 8;