public static String getTokenTextInternal(char[] buffer, int start, int end, int size, boolean upcaseP) {
    if (start >= size) {
      start = start - size;
    }
    else if (start < 0) {
      start = size + start;
    }
    if (end > size) {
      end = end - size;
    }
    else if (end < 0) {
      end = size + end;
    }
    { int length = end - start;
      StringBuffer result = null;
      int cursor = 0;
      int auxend = end;

      if (length < 0) {
        length = length + size;
        auxend = size;
      }
      result = Stella.makeRawMutableString(length);
      if (upcaseP) {
        loop000 : for (;;) {
          while (start < auxend) {
            edu.isi.stella.javalib.Native.mutableString_nthSetter(result, (Stella.$CHARACTER_UPCASE_TABLE$.charAt(((int) (((char) (0x00ff & buffer[start])))))), cursor);
            cursor = cursor + 1;
            start = start + 1;
          }
          if (auxend == end) {
            break loop000;
          }
          start = 0;
          auxend = end;
        }
      }
      else {
        loop002 : for (;;) {
          while (start < auxend) {
            edu.isi.stella.javalib.Native.mutableString_nthSetter(result, (((char) (0x00ff & buffer[start]))), cursor);
            cursor = cursor + 1;
            start = start + 1;
          }
          if (auxend == end) {
            break loop002;
          }
          start = 0;
          auxend = end;
        }
      }
      return (result.toString());
    }
  }