-/* xscreensaver, Copyright (c) 1998-2012 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1998-2014 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
#include "screenhack.h"
#include "apple2.h"
#include "textclient.h"
+#include "utf8wc.h"
#undef countof
#define countof(x) (sizeof((x))/sizeof((*x)))
#define SCREEN_COLS 40
#define SCREEN_ROWS 24
-#define DEBUG
-
/* Given a bitmask, returns the position and width of the field.
*/
*stepno=10;
break;
+ case 80:
+ /* Do nothing, just wait */
+ *next_actiontime += 2.0;
+ *stepno = A2CONTROLLER_FREE;
+ break;
+
case A2CONTROLLER_FREE:
+ /* It is possible that still image is being loaded,
+ in that case mine cannot be freed, because
+ callback function tries to use it, so wait.
+ */
+ if (mine->image_loading_p) {
+ *stepno = 80;
+ break;
+ }
free(mine->render_img);
free(mine->img_filename);
free(mine);
int curparam;
int cursor_x, cursor_y;
int saved_x, saved_y;
+ int unicruds; char unicrud[7];
union {
struct {
unsigned int bold : 1;
int i;
int start, end;
+ /* Mostly duplicated in phosphor.c */
+
switch (state->escstate)
{
case 0:
}
break;
case 10: /* LF */
+# ifndef HAVE_FORKPTY
+ state->cursor_x = 0; /* No ptys on iPhone; assume CRLF. */
+# endif
case 11: /* VT */
case 12: /* FF */
if (state->cursor_y < rows - 1)
state->curparam = 0;
break;
default:
+
+ /* states 102-106 are for UTF-8 decoding */
+
+ if ((c & 0xE0) == 0xC0) { /* 110xxxxx - 11 bits, 2 bytes */
+ state->unicruds = 1;
+ state->unicrud[0] = c;
+ state->escstate = 102;
+ break;
+ } else if ((c & 0xF0) == 0xE0) { /* 1110xxxx - 16 bits, 3 bytes */
+ state->unicruds = 1;
+ state->unicrud[0] = c;
+ state->escstate = 103;
+ break;
+ } else if ((c & 0xF8) == 0xF0) { /* 11110xxx - 21 bits, 4 bytes */
+ state->unicruds = 1;
+ state->unicrud[0] = c;
+ state->escstate = 104;
+ break;
+ } else if ((c & 0xFC) == 0xF8) { /* 111110xx - 26 bits, 5 bytes */
+ state->unicruds = 1;
+ state->unicrud[0] = c;
+ state->escstate = 105;
+ break;
+ } else if ((c & 0xFE) == 0xFC) { /* 1111110x - 31 bits, 6 bytes */
+ state->unicruds = 1;
+ state->unicrud[0] = c;
+ state->escstate = 106;
+ break;
+ }
+
+ PRINT:
+
/* If the cursor is in column 39 and we print a character, then
that character shows up in column 39, and the cursor is no longer
visible on the screen (it's in "column 40".) If another character
state->curparam = 0;
break;
case '%': /* Select charset */
- /* No, I don't support UTF-8, since the apple2 font
- isn't even Unicode anyway. We must still catch the
- last byte, though. */
+ /* @: Select default (ISO 646 / ISO 8859-1)
+ G: Select UTF-8
+ 8: Select UTF-8 (obsolete)
+
+ We can just ignore this and always process UTF-8, I think?
+ We must still catch the last byte, though.
+ */
case '(':
case ')':
/* I don't support different fonts either - see above
case 3:
state->escstate = 0;
break;
+
+ case 102:
+ case 103:
+ case 104:
+ case 105:
+ case 106:
+ {
+ int total = state->escstate - 100; /* see what I did there */
+ if (state->unicruds < total) {
+ /* Buffer more bytes of the UTF-8 sequence */
+ state->unicrud[state->unicruds++] = c;
+ }
+
+ if (state->unicruds >= total) {
+ /* Done! Convert it to ASCII and print that. */
+ char *s;
+ state->unicrud[state->unicruds] = 0;
+ s = utf8_to_latin1 ((const char *) state->unicrud, True);
+ state->unicruds = 0;
+ state->escstate = 0;
+ if (s) {
+ c = s[0];
+ free (s);
+ goto PRINT;
+ } else {
+ /* c = 0; */
+ }
+ }
+ }
+ break;
+
+ default:
+ abort();
}
a2_goto(st, state->cursor_y, state->cursor_x);
}
mine->tc = textclient_open (mine->dpy);
textclient_reshape (mine->tc,
SCREEN_COLS, SCREEN_ROWS,
- SCREEN_COLS, SCREEN_ROWS);
+ SCREEN_COLS, SCREEN_ROWS,
+ 0);
}
if (! mine->fast_p)
*next_actiontime += 4.0;
*stepno = 10;
+
+ mine->last_emit_time = sim->curtime;
break;
case 10:
+ case 11:
{
+ Bool first_line_p = (*stepno == 10);
unsigned char buf[1024];
int nr,nwant;
double elapsed;
elapsed=sim->curtime - mine->last_emit_time;
- mine->last_emit_time=sim->curtime;
- nwant=elapsed*25.0;
- if (elapsed>1.0) nwant=1;
- if (nwant<1) nwant=1;
- if (nwant>4) nwant=4;
+
+ nwant = elapsed * 25.0; /* characters per second */
+
+ if (first_line_p) {
+ *stepno = 11;
+ nwant = 1;
+ }
+
+ if (nwant > 40) nwant = 40;
if (mine->fast_p)
nwant = sizeof(buf)-1;
+ if (nwant <= 0) break;
+
+ mine->last_emit_time = sim->curtime;
+
nr=terminal_read(mine, buf, nwant);
for (i=0; i<nr; i++) {
c=buf[i];
st->sim = 0;
}
- return 10000;
+#ifdef HAVE_MOBILE
+ return 0;
+#else
+ return 5000;
+#endif
}
static void
unsigned int w, unsigned int h)
{
struct state *st = (struct state *) closure;
- analogtv_reconfigure (st->sim->dec);
+ if (st->sim)
+ analogtv_reconfigure (st->sim->dec);
}
static Bool
{
struct state *st = (struct state *) closure;
- if (st->controller == terminal_controller &&
+ if (st->sim &&
+ st->controller == terminal_controller &&
event->xany.type == KeyPress) {
terminal_keypress_handler (dpy, event, st->sim->controller_data);
return True;