Example #1
0
  protected short op_sread() {
    byte ch;
    int tsize;
    int tbuf;
    int bufloc;

    tbuf = operands[0] & 0xFFFF;
    zm.update_status_line();
    zm.current_window.flush();
    zm.current_window.reset_line_count();
    // System.err.println("textbuf = " + Integer.toString(tbuf, 16));
    tsize = zm.memory_image[tbuf] & 0xFF;
    if (tsize < 2) zm.fatal("Text Buffer < 3 bytes");
    tsize--; /* reserve a byte for the terminator */
    bufloc = 1;
    while ((tsize != 0) && ((ch = zm.get_input_byte(true)) != 13) && (ch != 10)) {
      // System.err.println("sr_ch @ " + Integer.toString(tbuf+bufloc, 16) +
      // " : " + ch);
      if ((ch >= (byte) 'A') && (ch <= (byte) 'Z')) {
        ch = (byte) (ch - (byte) 'A' + (byte) 'a');
      }
      zm.memory_image[tbuf + bufloc] = ch;
      bufloc++;
      tsize--;
    }
    zm.memory_image[tbuf + bufloc] = 0;
    zm.zd.tokenise(tbuf + 1, bufloc - 1, operands[1] & 0xFFFF);
    return ZFALSE;
  }
Example #2
0
 protected short op_dec() {
   short vval;
   vval = zm.get_variable(operands[0]);
   vval--;
   zm.set_variable(operands[0], vval);
   return ZFALSE;
 }
Example #3
0
  protected short op_inc_chk() {
    short vval;

    vval = zm.get_variable(operands[0]);
    vval++;
    zm.set_variable(operands[0], vval);
    if (vval > operands[1]) return ZTRUE;
    return ZFALSE;
  }
Example #4
0
  protected void z_ret() {
    Object tos;

    do tos = zm.zstack.pop();
    while (!(tos instanceof short[]));
    zm.locals = (short[]) tos;
    // System.err.print("From ");
    // System.err.print(Integer.toString(zm.pc, 16));
    zm.pc = ((Integer) zm.zstack.pop()).intValue();
    // System.err.print(" returning to ");
    // System.err.println(Integer.toString(zm.pc, 16));
    storevar = (short) (((Integer) zm.zstack.pop()).intValue());
    zm.zstack.pop(); /* stack frame boundary */
  }
Example #5
0
 protected void decode_second_half() {
   if (isstore()) storevar = zm.get_code_byte();
   if (isbranch()) {
     branchoffset = zm.get_code_byte();
     branchtype = (branchoffset & 0x80) != 0;
     if ((branchoffset & 0x40) != 0) /* positive 6-bit number */ branchoffset &= 0x3F;
     else if ((branchoffset & 0x20) != 0) /* negative 14-bit number */
       branchoffset =
           (short) (0xC000 | ((branchoffset << 8) | (((short) zm.get_code_byte()) & 0xFF)));
     else
       /* positive 14-bit number */
       branchoffset =
           (short) (((branchoffset & 0x3F) << 8) | (((short) zm.get_code_byte()) & 0xFF));
   }
 }
Example #6
0
  public void set_header_flags() {
    /* at start, restart, restore */
    ZHeader5 header = (ZHeader5) this.header;

    super.set_header_flags();
    header.set_revision(0, 0);

    /* screen model flags */
    header.set_colors_available(false);
    header.set_bold_available(true);
    header.set_italic_available(true);
    header.set_fixed_font_available(true);
    header.set_timed_input_available(false);
    header.set_graphics_font_available(false);

    /* other flags (is mouse part of screen model?) */
    header.set_undo_available(true);
    header.set_mouse_available(false);
    header.set_sound_available(false);
    header.set_interpreter_number(ZHeader5.INTERP_MSDOS);
    header.set_interpreter_version((int) 'J');
    header.set_screen_height_lines(screen.getlines());
    header.set_screen_width_characters(screen.getchars());

    /* TODO -- units */
    header.set_screen_height_units(screen.getlines());
    header.set_screen_width_units(screen.getchars());
    header.set_font_height_units(1);
    header.set_font_width_units(1);

    header.set_default_background_color(screen.getZBackground());
    header.set_default_foreground_color(screen.getZForeground());
  }
Example #7
0
  protected short op_ret_popped() {
    short returnvalue;

    returnvalue = zm.get_variable((short) 0);
    z_ret();
    return returnvalue;
  }
Example #8
0
 protected short op_set_window() {
   zm.current_window.flush();
   // System.err.println("set_window " + operands[0]);
   zm.current_window = zm.window[operands[0]];
   if (operands[0] == UPPER_WINDOW) zm.current_window.movecursor(0, 0);
   return ZFALSE;
 }
Example #9
0
  protected short op_call() {
    int nlocals;
    int i;
    short thislocal;

    if (operands[0] == 0) {
      /* calls to zero return false */
      /*
       * Can't just return false because call is not treated as a store in
       * execute_instruction
       */
      zm.set_variable(storevar, ZFALSE);
    } else {
      zm.zstack.push(new ZFrameBound(isstore()));
      zm.zstack.push(new Integer(storevar));
      zm.zstack.push(new Integer(zm.pc));
      zm.zstack.push(zm.locals);
      // System.err.print("From ");
      // System.err.print(Integer.toString(zm.pc, 16));
      zm.pc = zm.routine_address(operands[0]);
      // System.err.print(" calling routine at ");
      // System.err.println(Integer.toString(zm.pc, 16));
      nlocals = zm.get_code_byte();
      zm.locals = new short[nlocals];
      for (i = 0; i < nlocals; i++) {
        thislocal = (short) (((zm.get_code_byte() << 8) & 0xFF00) | (zm.get_code_byte() & 0xFF));
        if (i < (count - 1)) {
          zm.locals[i] = operands[i + 1];
        } else {
          zm.locals[i] = thislocal;
        }
      }
    }
    return ZFALSE;
  }
Example #10
0
  protected short op_mod() {
    int dividend = operands[0];
    int divisor = operands[1];

    if (divisor == 0) {
      zm.fatal("Remainder from division by zero");
    }
    return (short) (dividend % divisor);
  }
Example #11
0
  protected short op_print_num() {
    char[] mychars;
    int i;

    mychars = Integer.toString((int) operands[0], 10).toCharArray();
    for (i = 0; i < mychars.length; i++) {
      zm.print_ascii_char((short) mychars[i]);
    }
    return ZFALSE;
  }
Example #12
0
  public void restart() {

    super.restart();

    window[0].moveto(0, 0);
    window[1].moveto(0, 0);
    window[0].resize(screen.getchars(), screen.getlines());
    window[1].resize(0, 0);
    window[0].movecursor(0, window[0].getHeight() - 1);
  }
Example #13
0
  protected short op_output_stream() {
    zm.current_window.flush();
    if (operands[0] == 3) {
      zm.printmemory = operands[1] & 0xFFFF;
      zm.memory_image[zm.printmemory] = (byte) 0;
      zm.memory_image[zm.printmemory + 1] = (byte) 0;
    } else if (operands[0] == 2) zm.header.set_transcripting(true);
    else if (operands[0] == -2) zm.header.set_transcripting(false);

    if (operands[0] > 0) zm.outputs[operands[0]] = true;
    else zm.outputs[-operands[0]] = false;
    return ZFALSE;
  }
Example #14
0
  void detach_obj(short object) {
    /* note: does not leave object tree well-formed */
    short parent;
    short cursor;

    // System.err.println("detach_obj " + object);
    parent = zm.objects.parent(object);
    if (parent != 0) {
      cursor = zm.objects.child(parent);
      if (cursor == object) {
        zm.objects.set_child(parent, zm.objects.sibling(object));
      } else {
        while (zm.objects.sibling(cursor) != object) {
          cursor = zm.objects.sibling(cursor);
          if (cursor == 0) zm.fatal("Malformed object tree");
        }
        zm.objects.set_sibling(cursor, zm.objects.sibling(object));
      }
    }
  }
Example #15
0
  public void execute() {
    short result;

    // System.err.println("Executing instruction " + opnum);
    switch (opnum) {
      case OP_JE:
        result = op_je();
        break;
      case OP_JL:
        result = op_jl();
        break;
      case OP_JG:
        result = op_jg();
        break;
      case OP_DEC_CHK:
        result = op_dec_chk();
        break;
      case OP_INC_CHK:
        result = op_inc_chk();
        break;
      case OP_JIN:
        result = op_jin();
        break;
      case OP_TEST:
        result = op_test();
        break;
      case OP_OR:
        result = op_or();
        break;
      case OP_AND:
        result = op_and();
        break;
      case OP_TEST_ATTR:
        result = op_test_attr();
        break;
      case OP_SET_ATTR:
        result = op_set_attr();
        break;
      case OP_CLEAR_ATTR:
        result = op_clear_attr();
        break;
      case OP_STORE:
        result = op_store();
        break;
      case OP_INSERT_OBJ:
        result = op_insert_obj();
        break;
      case OP_LOADW:
        result = op_loadw();
        break;
      case OP_LOADB:
        result = op_loadb();
        break;
      case OP_GET_PROP:
        result = op_get_prop();
        break;
      case OP_GET_PROP_ADDR:
        result = op_get_prop_addr();
        break;
      case OP_GET_NEXT_PROP:
        result = op_get_next_prop();
        break;
      case OP_ADD:
        result = op_add();
        break;
      case OP_SUB:
        result = op_sub();
        break;
      case OP_MUL:
        result = op_mul();
        break;
      case OP_DIV:
        result = op_div();
        break;
      case OP_MOD:
        result = op_mod();
        break;
      case OP_JZ:
        result = op_jz();
        break;
      case OP_GET_SIBLING:
        result = op_get_sibling();
        break;
      case OP_GET_CHILD:
        result = op_get_child();
        break;
      case OP_GET_PARENT:
        result = op_get_parent();
        break;
      case OP_GET_PROP_LEN:
        result = op_get_prop_len();
        break;
      case OP_INC:
        result = op_inc();
        break;
      case OP_DEC:
        result = op_dec();
        break;
      case OP_PRINT_ADDR:
        result = op_print_addr();
        break;
      case OP_CALL_1S:
        result = op_call_1s();
        break;
      case OP_REMOVE_OBJ:
        result = op_remove_obj();
        break;
      case OP_PRINT_OBJ:
        result = op_print_obj();
        break;
      case OP_RET:
        result = op_ret();
        break;
      case OP_JUMP:
        result = op_jump();
        break;
      case OP_PRINT_PADDR:
        result = op_print_paddr();
        break;
      case OP_LOAD:
        result = op_load();
        break;
      case OP_NOT:
        result = op_not();
        break;
      case OP_RTRUE:
        result = op_rtrue();
        break;
      case OP_RFALSE:
        result = op_rfalse();
        break;
      case OP_PRINT:
        result = op_print();
        break;
      case OP_PRINT_RET:
        result = op_print_ret();
        break;
      case OP_NOP:
        result = op_nop();
        break;
      case OP_SAVE:
        result = op_save();
        break;
      case OP_RESTORE:
        result = op_restore();
        break;
      case OP_RESTART:
        result = op_restart();
        break;
      case OP_RET_POPPED:
        result = op_ret_popped();
        break;
      case OP_POP:
        result = op_pop();
        break;
      case OP_QUIT:
        result = op_quit();
        break;
      case OP_NEW_LINE:
        result = op_new_line();
        break;
      case OP_SHOW_STATUS:
        result = op_show_status();
        break;
      case OP_VERIFY:
        result = op_verify();
        break;
      case OP_EXTENDED:
        result = op_extended();
        break;
      case OP_PIRACY:
        result = op_piracy();
        break;
      case OP_CALL:
        result = op_call();
        break;
      case OP_STOREW:
        result = op_storew();
        break;
      case OP_STOREB:
        result = op_storeb();
        break;
      case OP_PUT_PROP:
        result = op_put_prop();
        break;
      case OP_SREAD:
        result = op_sread();
        break;
      case OP_PRINT_CHAR:
        result = op_print_char();
        break;
      case OP_PRINT_NUM:
        result = op_print_num();
        break;
      case OP_RANDOM:
        result = op_random();
        break;
      case OP_PUSH:
        result = op_push();
        break;
      case OP_PULL:
        result = op_pull();
        break;
      case OP_SPLIT_WINDOW:
        result = op_split_window();
        break;
      case OP_SET_WINDOW:
        result = op_set_window();
        break;
      case OP_OUTPUT_STREAM:
        result = op_output_stream();
        break;
      case OP_INPUT_STREAM:
        result = op_input_stream();
        break;
      case OP_SOUND_EFFECT:
        result = op_sound_effect();
        break;
      default:
        result = op_illegal();
    }

    if (((opnum != OP_CALL) && isstore()) || isret()) {
      zm.set_variable(storevar, result);
    }

    if (isbranch()) {
      if ((result == 0) != branchtype) {
        /*
         * that is, if result is 0 and branchtype is false, or result is nonzero
         * and branchtype is true
         */
        switch (branchoffset) {
          case 0:
            z_ret();
            zm.set_variable(storevar, ZFALSE);
            break;
          case 1:
            z_ret();
            zm.set_variable(storevar, ZTRUE);
            break;
          default:
            zm.pc += branchoffset - 2;
        }
      }
    }
  }
Example #16
0
 protected short op_show_status() {
   zm.update_status_line();
   return ZFALSE;
 }
Example #17
0
 protected short op_new_line() {
   zm.print_ascii_char((short) 13);
   return ZFALSE;
 }
Example #18
0
 protected short op_quit() {
   zm.print_ascii_char((short) '*');
   zm.print_ascii_char((short) '*');
   zm.print_ascii_char((short) '*');
   zm.print_ascii_char((short) 'E');
   zm.print_ascii_char((short) 'N');
   zm.print_ascii_char((short) 'D');
   zm.print_ascii_char((short) ' ');
   zm.print_ascii_char((short) 'O');
   zm.print_ascii_char((short) 'F');
   zm.print_ascii_char((short) ' ');
   zm.print_ascii_char((short) 'S');
   zm.print_ascii_char((short) 'E');
   zm.print_ascii_char((short) 'S');
   zm.print_ascii_char((short) 'S');
   zm.print_ascii_char((short) 'I');
   zm.print_ascii_char((short) 'O');
   zm.print_ascii_char((short) 'N');
   zm.print_ascii_char((short) '*');
   zm.print_ascii_char((short) '*');
   zm.print_ascii_char((short) '*');
   zm.print_ascii_char((short) 13);
   // zm.stop();
   return ZFALSE;
 }
Example #19
0
 protected short op_pop() {
   zm.get_variable((short) 0); /* pop the stack and toss the result */
   return ZFALSE;
 }
Example #20
0
 protected short op_illegal() {
   zm.fatal("Unknown opcode");
   return ZFALSE;
 }
Example #21
0
 protected short op_print_ret() {
   zm.print_string(zm.pc);
   zm.print_ascii_char((short) 13);
   z_ret();
   return ZTRUE;
 }
Example #22
0
 protected short op_print() {
   int nchars;
   nchars = zm.print_string(zm.pc);
   zm.pc += nchars;
   return ZFALSE;
 }
Example #23
0
 protected short op_load() {
   return zm.get_variable(operands[0]);
 }
Example #24
0
 protected short op_print_paddr() {
   zm.print_string(zm.string_address(operands[0]));
   return ZFALSE;
 }
Example #25
0
 protected short op_jump() {
   zm.pc += operands[0] - 2;
   return ZFALSE;
 }
Example #26
0
 protected short op_store() {
   zm.set_variable(operands[0], operands[1]);
   return ZFALSE;
 }
Example #27
0
 protected short op_print_obj() {
   zm.print_string(zm.objects.short_name_addr(operands[0]));
   return ZTRUE;
 }
Example #28
0
 protected short op_restart() {
   zm.restart();
   return ZFALSE;
 }
Example #29
0
 protected short op_print_char() {
   zm.print_ascii_char(operands[0]);
   return ZFALSE;
 }
Example #30
0
 protected short op_print_addr() {
   zm.print_string((int) operands[0] & 0xFFFF);
   return ZFALSE;
 }