*/
@Override
public void draw() {
-
int width = getDisplayWidth();
boolean syncEmulator = false;
- if ((System.currentTimeMillis() - lastUpdateTime > 125)
+ if ((System.currentTimeMillis() - lastUpdateTime >= 25)
&& (dirty == true)
) {
// Too much time has passed, draw it all.
continue;
}
- Cell newCell = new Cell();
- newCell.setTo(ch);
+ Cell newCell = new Cell(ch);
boolean reverse = line.isReverseColor() ^ ch.isReverse();
newCell.setReverse(false);
if (reverse) {
BufferedImage image;
if (line.getDoubleHeight() == 1) {
// Double-height top half: don't draw the underline.
- Cell newCell = new Cell();
- newCell.setTo(cell);
+ Cell newCell = new Cell(cell);
newCell.setUnderline(false);
image = doubleFont.getImage(newCell, textWidth * 2, textHeight * 2,
cursorBlinkVisible);
// Now that we have the double-wide glyph drawn, copy the right
// pieces of it to the cells.
- Cell left = new Cell();
- Cell right = new Cell();
- left.setTo(cell);
- right.setTo(cell);
+ Cell left = new Cell(cell);
+ Cell right = new Cell(cell);
right.setChar(' ');
BufferedImage leftImage = null;
BufferedImage rightImage = null;
Graphics2D gr2 = image.createGraphics();
gr2.setFont(font);
- Cell cellColor = new Cell();
- cellColor.setTo(cell);
+ Cell cellColor = new Cell(cell);
// Check for reverse
if (cell.isReverse()) {
gr2.dispose();
// We need a new key that will not be mutated by invertCell().
- Cell key = new Cell();
- key.setTo(cell);
+ Cell key = new Cell(cell);
if (cell.isBlink() && !blinkVisible) {
glyphCacheBlink.put(key, image);
} else {
BufferedImage rightImage = image.getSubimage(getTextWidth(), 0,
getTextWidth(), getTextHeight());
- Cell left = new Cell();
- left.setTo(cell);
+ Cell left = new Cell(cell);
left.setImage(leftImage);
left.setWidth(Cell.Width.LEFT);
// Blank out the char itself, so that shadows do not leave artifacts.
left.setChar(' ');
putCharXY(x, y, left);
- Cell right = new Cell();
- right.setTo(cell);
+ Cell right = new Cell(cell);
right.setImage(rightImage);
right.setWidth(Cell.Width.RIGHT);
// Blank out the char itself, so that shadows do not leave artifacts.
public final void putFullwidthCharXY(final int x, final int y,
final char ch, final CellAttributes attr) {
- Cell cell = new Cell(ch);
- cell.setAttr(attr);
+ Cell cell = new Cell(ch, attr);
putFullwidthCharXY(x, y, cell);
}
&& (swing.getBufferStrategy() != null)
) {
do {
- clearPhysical();
do {
drawToSwing();
} while (swing.getBufferStrategy().contentsRestored());
gr2 = (Graphics2D) gr;
}
- Cell cellColor = new Cell();
- cellColor.setTo(cell);
+ Cell cellColor = new Cell(cell);
// Check for reverse
if (cell.isReverse()) {
// We need a new key that will not be mutated by
// invertCell().
- Cell key = new Cell();
- key.setTo(cell);
+ Cell key = new Cell(cell);
if (cell.isBlink() && !cursorBlinkVisible) {
glyphCacheBlink.put(key, image);
} else {
/**
* The character at this cell.
*/
- private char ch;
+ private char ch = ' ';
/**
* The display width of this cell.
* The background color used for the area the image portion might not
* cover.
*/
- private Color background = null;
+ private Color background = Color.BLACK;
/**
* hashCode() needs to call image.hashCode(), which can get quite
* @see #reset()
*/
public Cell() {
- reset();
+ // NOP
}
/**
* @see #reset()
*/
public Cell(final char ch) {
- reset();
+ this.ch = ch;
+ }
+
+ /**
+ * Public constructor sets the character and attributes.
+ *
+ * @param ch character to set to
+ * @param attr attributes to use
+ */
+ public Cell(final char ch, final CellAttributes attr) {
+ super(attr);
this.ch = ch;
}
public class CellAttributes {
// ------------------------------------------------------------------------
- // Variables --------------------------------------------------------------
+ // Constants --------------------------------------------------------------
// ------------------------------------------------------------------------
/**
* Bold attribute.
*/
- private boolean bold;
+ private static final int BOLD = 0x01;
/**
* Blink attribute.
*/
- private boolean blink;
+ private static final int BLINK = 0x02;
/**
* Reverse attribute.
*/
- private boolean reverse;
+ private static final int REVERSE = 0x04;
/**
* Underline attribute.
*/
- private boolean underline;
+ private static final int UNDERLINE = 0x08;
/**
* Protected attribute.
*/
- private boolean protect;
+ private static final int PROTECT = 0x10;
+
+
+ // ------------------------------------------------------------------------
+ // Variables --------------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Boolean flags.
+ */
+ private int flags = 0;
/**
* Foreground color. Color.WHITE, Color.RED, etc.
*/
- private Color foreColor;
+ private Color foreColor = Color.WHITE;
/**
* Background color. Color.WHITE, Color.RED, etc.
*/
- private Color backColor;
+ private Color backColor = Color.BLACK;
/**
* Foreground color as 24-bit RGB value. Negative value means not set.
* @see #reset()
*/
public CellAttributes() {
- reset();
+ // NOP
}
/**
* @return bold value
*/
public final boolean isBold() {
- return bold;
+ return ((flags & BOLD) == 0 ? false : true);
}
/**
* @param bold new bold value
*/
public final void setBold(final boolean bold) {
- this.bold = bold;
+ if (bold) {
+ flags |= BOLD;
+ } else {
+ flags &= ~BOLD;
+ }
}
/**
* @return blink value
*/
public final boolean isBlink() {
- return blink;
+ return ((flags & BLINK) == 0 ? false : true);
}
/**
* @param blink new blink value
*/
public final void setBlink(final boolean blink) {
- this.blink = blink;
+ if (blink) {
+ flags |= BLINK;
+ } else {
+ flags &= ~BLINK;
+ }
}
/**
* @return reverse value
*/
public final boolean isReverse() {
- return reverse;
+ return ((flags & REVERSE) == 0 ? false : true);
}
/**
* @param reverse new reverse value
*/
public final void setReverse(final boolean reverse) {
- this.reverse = reverse;
+ if (reverse) {
+ flags |= REVERSE;
+ } else {
+ flags &= ~REVERSE;
+ }
}
/**
* @return underline value
*/
public final boolean isUnderline() {
- return underline;
+ return ((flags & UNDERLINE) == 0 ? false : true);
}
/**
* @param underline new underline value
*/
public final void setUnderline(final boolean underline) {
- this.underline = underline;
+ if (underline) {
+ flags |= UNDERLINE;
+ } else {
+ flags &= ~UNDERLINE;
+ }
}
/**
* @return protect value
*/
public final boolean isProtect() {
- return protect;
+ return ((flags & PROTECT) == 0 ? false : true);
}
/**
* @param protect new protect value
*/
public final void setProtect(final boolean protect) {
- this.protect = protect;
+ if (protect) {
+ flags |= PROTECT;
+ } else {
+ flags &= ~PROTECT;
+ }
}
/**
* bold/underline/blink/rever/protect.
*/
public void reset() {
- bold = false;
- blink = false;
- reverse = false;
- underline = false;
- protect = false;
+ flags = 0;
foreColor = Color.WHITE;
backColor = Color.BLACK;
foreColorRGB = -1;
}
CellAttributes that = (CellAttributes) rhs;
- return ((foreColor == that.foreColor)
+ return ((flags == that.flags)
+ && (foreColor == that.foreColor)
&& (backColor == that.backColor)
&& (foreColorRGB == that.foreColorRGB)
- && (backColorRGB == that.backColorRGB)
- && (bold == that.bold)
- && (reverse == that.reverse)
- && (underline == that.underline)
- && (blink == that.blink)
- && (protect == that.protect));
+ && (backColorRGB == that.backColorRGB));
}
/**
int A = 13;
int B = 23;
int hash = A;
- hash = (B * hash) + (bold ? 1 : 0);
- hash = (B * hash) + (blink ? 1 : 0);
- hash = (B * hash) + (underline ? 1 : 0);
- hash = (B * hash) + (reverse ? 1 : 0);
- hash = (B * hash) + (protect ? 1 : 0);
+ hash = (B * hash) + flags;
hash = (B * hash) + foreColor.hashCode();
hash = (B * hash) + backColor.hashCode();
hash = (B * hash) + foreColorRGB;
public void setTo(final Object rhs) {
CellAttributes that = (CellAttributes) rhs;
- this.bold = that.bold;
- this.blink = that.blink;
- this.reverse = that.reverse;
- this.underline = that.underline;
- this.protect = that.protect;
+ this.flags = that.flags;
this.foreColor = that.foreColor;
this.backColor = that.backColor;
this.foreColorRGB = that.foreColorRGB;
(foreColorRGB & 0xFFFFFF),
(backColorRGB & 0xFFFFFF));
}
- return String.format("%s%s%s on %s", (bold == true ? "bold " : ""),
- (blink == true ? "blink " : ""), foreColor, backColor);
+ return String.format("%s%s%s on %s", (isBold() ? "bold " : ""),
+ (isBlink() ? "blink " : ""), foreColor, backColor);
}
}
public DisplayLine(final CellAttributes attr) {
chars = new Cell[MAX_LINE_LENGTH];
for (int i = 0; i < chars.length; i++) {
- chars[i] = new Cell();
- chars[i].setTo(attr);
+ chars[i] = new Cell(attr);
}
}
*/
public void insert(final int idx, final Cell newCell) {
System.arraycopy(chars, idx, chars, idx + 1, chars.length - idx - 1);
- chars[idx] = new Cell();
- chars[idx].setTo(newCell);
+ chars[idx] = new Cell(newCell);
}
/**
*/
public void delete(final int idx, final Cell newCell) {
System.arraycopy(chars, idx + 1, chars, idx, chars.length - idx - 1);
- chars[chars.length - 1] = new Cell();
- chars[chars.length - 1].setTo(newCell);
+ chars[chars.length - 1] = new Cell(newCell);
}
}
char [] readBufferUTF8 = null;
byte [] readBuffer = null;
if (utf8) {
- readBufferUTF8 = new char[128];
+ readBufferUTF8 = new char[2048];
} else {
- readBuffer = new byte[128];
+ readBuffer = new byte[2048];
}
while (!done && !stopReaderThread) {
* DECALN - Screen alignment display.
*/
private void decaln() {
- Cell newCell = new Cell();
- newCell.setChar('E');
+ Cell newCell = new Cell('E');
for (DisplayLine line: display) {
for (int i = 0; i < line.length(); i++) {
line.replace(i, newCell);
lastTextHeight = textHeight;
}
- Cell cell = new Cell(ch);
- cell.setAttr(currentState.attr);
+ Cell cell = new Cell(ch, currentState.attr);
BufferedImage image = glyphMaker.getImage(cell, textWidth * 2,
textHeight);
BufferedImage leftImage = image.getSubimage(0, 0, textWidth,
BufferedImage rightImage = image.getSubimage(textWidth, 0, textWidth,
textHeight);
- Cell left = new Cell();
- left.setTo(cell);
+ Cell left = new Cell(cell);
left.setImage(leftImage);
left.setWidth(Cell.Width.LEFT);
display.get(leftY).replace(leftX, left);
- Cell right = new Cell();
- right.setTo(cell);
+ Cell right = new Cell(cell);
right.setImage(rightImage);
right.setWidth(Cell.Width.RIGHT);
display.get(rightY).replace(rightX, right);