} else { sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22," IC/IM position invalid "); error = true; }  break;  case 20: int imcX = bk.getNextByte(); int imcY = bk.getNextByte() & 0xff; if (imcX >= 0 && imcX <= saRows && imcY >= 0 && imcY <= saCols) {   screen52.setPendingInsert(false,imcX,imcY); }
   private boolean writeToDisplay(boolean controlsExist) {      int pos = 0;      boolean error=false;      boolean done=false;      int attr;      byte nextOne;      byte control0 = 0;      byte control1 = 0;      int saRows = screen52.getRows();      int saCols = screen52.getCols();      try {         if (controlsExist) {            control0 = bk.getNextByte();            control1 = bk.getNextByte();            processCC0(control0);         }         while (bk.hasNext() && !done) {//            pos = bk.getCurrentPos();//            int rowc = screen52.getCurrentRow();//            int colc = screen52.getCurrentCol();            switch (bk.getNextByte()) {               case 1:     // SOH - Start of Header Order                  error = processSOH();                  break;               case 02:    // RA - Repeat to address                  int row = screen52.getCurrentRow();                  int col = screen52.getCurrentCol();                  int toRow = bk.getNextByte();                  int toCol = bk.getNextByte() & 0xff;                  if (toRow >= row) {                     int repeat = bk.getNextByte();                     // a little intelligence here I hope                     if (row == 1 &&                        col == 2 &&                        toRow == screen52.getRows() &&                        toCol == screen52.getCols())                        screen52.clearScreen();                     else {                        if (repeat != 0)                           repeat = getASCIIChar(repeat);                        int times = ((toRow * screen52.getCols()) + toCol) -                                 ((row * screen52.getCols()) + col);                        while (times-- >= 0) {                           screen52.setChar(repeat);                        }                     }                  }                  else {                     sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x23," RA invalid");                     error =true;                  }                  break;               case 03:    // EA - Erase to address                  int EArow = screen52.getCurrentRow();                  int EAcol = screen52.getCurrentCol();                  int toEARow = bk.getNextByte();                  int toEACol = bk.getNextByte() & 0xff;                  int EALength = bk.getNextByte()  & 0xff;                  while (--EALength > 0) {                     bk.getNextByte();                  }                  char EAAttr = (char)0;                  // a little intelligence here I hope                  if (EArow == 1 &&                     EAcol == 2 &&                     toEARow == screen52.getRows() &&                     toEACol == screen52.getCols())                     screen52.clearScreen();                  else {                     int times = ((toEARow * screen52.getCols()) + toEACol) -                              ((EArow * screen52.getCols()) + EAcol);                     while (times-- >= 0) {                        screen52.setChar(EAAttr);                     }                  }                  break;               case 04:    // Command - Escape                  done = true;                  break;               case 16:    // TD - Transparent Data                  bk.getNextByte();                  int j = bk.getNextByte();  // length                  while (j-- > 0)                     bk.getNextByte();                  break;               case 17:    // SBA - set buffer address order (row column)                  int saRow = bk.getNextByte();                  int saCol = bk.getNextByte() & 0xff;                  // make sure it is in bounds                  if (saRow >= 0 &&                        saRow <= screen52.getRows() &&                        saCol >= 0 &&                        saCol <= screen52.getCols()) {                     screen52.goto_XY(saRow,saCol); // now set screen position for output                  }                  else {                     sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22,"invalid row/col order" +                                                                     " saRow = " +                                                                     saRow +                                                                     " saRows = " +                                                                     screen52.getRows() +                                                                     " saCol = " + saCol);                     error = true;                  }                  break;               case 18:    // WEA - Extended Attribute                  bk.getNextByte();                  bk.getNextByte();                  break;               case 19:    // IC - Insert Cursor               case 20:    // MC - Move Cursor                  int icX = bk.getNextByte();                  int icY = bk.getNextByte() & 0xff;                  if (icX >= 0 &&                        icX <= saRows &&                        icY >= 0 &&                        icY <= saCols)//                     System.out.println(" IC " + icX + " " + icY);                     screen52.setPendingInsert(true,icX,icY);                  else {                     sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x22," IC/IM position invalid ");                     error = true;                  }                  break;               case 21:    // WTDSF - Write To Display Structured Field order                  error = writeToDisplayStructuredField();                  break;               case 29:    // SF - Start of Field                  int fcw1 = 0;                  int fcw2 = 0;                  int ffw1 = 0;                  int ffw0 = bk.getNextByte() & 0xff;   // FFW                  if ((ffw0 & 0x40) == 0x40) {                     ffw1 = bk.getNextByte() & 0xff;   // FFW 1                     fcw1 = bk.getNextByte() & 0xff;   // check for field control word                     if (!isAttribute(fcw1)) {                        fcw2 = bk.getNextByte() & 0xff;   // FCW 2                        attr = bk.getNextByte() & 0xff;   // attribute field                     }                     else {                        attr = fcw1;      // attribute of field                        fcw1 = 0;                     }                  }                  else {                     attr = ffw0;                  }                  int fLength = (bk.getNextByte() & 0xff) << 8 | bk.getNextByte() & 0xff;                  screen52.addField(attr,fLength, ffw0,ffw1,fcw1,fcw2);                  break;               default:    // all others must be output to screen                  byte byte0 = bk.getByteOffset(-1);                  if (isAttribute(byte0)) {                     screen52.setAttr(byte0);                  }                  else {                     if (!screen52.isStatusErrorCode()) {                        if (!isData(byte0)) {//                           if (byte0 == 255) {//                              sendNegResponse(NR_REQUEST_ERROR,0x05,0x01,0x42,//                              " Attempt to send FF to screen");//                           }//                           else                           screen52.setChar(byte0);                        }                        else//                           screen52.setChar(getASCIIChar(byte0));                           screen52.setChar(codePage.ebcdic2uni(byte0));                     }                     else {                        if (byte0 == 0)                           screen52.setChar(byte0);                        else                           screen52.setChar(getASCIIChar(byte0));                     }                  }                  break;            }            if (error)               done = true;         }      }      catch (Exception e) {         System.out.println("write to display " + e.getMessage());      };      processCC1(control1);      return error;   }