Skip to content

Commit

Permalink
Fixed cursor positioning. Cursor was not moved correctly after some s…
Browse files Browse the repository at this point in the history
…pacing characters and was left in the

wrong position after flash and concealed attr processing.
  • Loading branch information
simonlaszcz committed Jun 14, 2024
1 parent 4dd850b commit 1fe93b7
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 51 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ Several variations are available but the following is recommended:

## Installation
wget "https://github.com/simonlaszcz/vidtex/blob/master/releases/vidtex-1.3.0.tar.gz?raw=true" -O "vidtex-1.3.0.tar.gz"
tar xvf vidtex-1.3.0.tar.gz
cd vidtex-1.3.0
# Substitute n.n.n with the release number
wget "https://github.com/simonlaszcz/vidtex/blob/master/releases/vidtex-n.n.n.tar.gz?raw=true" -O "vidtex-n.n.n.tar.gz"
tar xvf vidtex-n.n.n.tar.gz
cd vidtex-n.n.n
./configure
sudo make install

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([vidtex], [1.3.0])
AC_INIT([vidtex], [1.4.0])
AX_WITH_CURSES
AC_ARG_WITH([ncursesw], AC_MSG_ERROR([ncursesw not installed]))
AC_CONFIG_SRCDIR([src/main.c])
Expand Down
Binary file added releases/vidtex-1.4.0.tar.gz
Binary file not shown.
93 changes: 65 additions & 28 deletions src/decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ static void vt_put_char(struct vt_decoder_state *state,
int row, int col, wchar_t ch, struct vt_decoder_attr *attr);
static void vt_init_colors(void);
static void vt_trace(struct vt_decoder_state *state, char *format, ...);
static void vt_cursor(struct vt_decoder_state *state);
static void vt_dump(struct vt_decoder_state *state, uint8_t *buffer, int count);
void vt_move_cursor(struct vt_decoder_state *state);

void
vt_decoder_init(struct vt_decoder_state *state)
Expand All @@ -34,10 +34,11 @@ vt_decoder_init(struct vt_decoder_state *state)
}
}

curs_set(0);
state->flags.is_cursor_on = false;
curs_set(state->force_cursor);
vt_new_frame(state);
vt_get_char_code(state, true, false, 0, 2, &state->space);
wrefresh(state->win);
}

void
Expand Down Expand Up @@ -87,8 +88,8 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
}
}

vt_move_cursor(state);
vt_trace(state, "BS");
vt_cursor(state);
continue;
case 9: // h-tab
++state->col;
Expand All @@ -102,13 +103,20 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
}
}

vt_move_cursor(state);
vt_trace(state, "H-TAB");
vt_cursor(state);
continue;
case 10: // LF (end of row)
vt_next_row(state);
case 10: // LF
++state->row;

if (state->row >= MAX_ROWS) {
state->row = 0;
}

vt_reset_flags(state);
vt_reset_after_flags(state);
vt_move_cursor(state);
vt_trace(state, "LF (new row)");
vt_cursor(state);
continue;
case 11: // v-tab
--state->row;
Expand All @@ -117,36 +125,39 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
state->row = MAX_ROWS - 1;
}

vt_move_cursor(state);
vt_trace(state, "V-TAB");
vt_cursor(state);
continue;
case 12:
// FF (new frame/clear screen)
vt_new_frame(state);
vt_move_cursor(state);
vt_trace(state, "FF (new frame)");
vt_cursor(state);
continue;
case 13: // CR
vt_fill_end(state);
state->col = 0;
vt_move_cursor(state);
vt_trace(state, "CR (fill to end)");
vt_cursor(state);
continue;
case 17: // DC1 - cursor on
curs_set(1);
state->flags.is_cursor_on = true;
vt_move_cursor(state);
vt_trace(state, "DC1 (cursor on)");
continue;
case 20: // DC4 - cursor off
curs_set(0);
state->flags.is_cursor_on = false;
curs_set(state->force_cursor);
vt_move_cursor(state);
vt_trace(state, "DC4 (cursor off)");
continue;
case 30: // RS - back to origin
vt_fill_end(state);
state->col = 0;
state->row = 0;
vt_move_cursor(state);
vt_trace(state, "RS (fill to end, back to origin)");
vt_cursor(state);
continue;
}

Expand Down Expand Up @@ -314,47 +325,78 @@ vt_decoder_decode(struct vt_decoder_state *state, uint8_t *buffer, int count)
wmove(state->win, state->row, state->col);
wrefresh(state->win);
}
}

// Move the cursor to the last character displayed
curs_set(state->force_cursor || state->flags.is_cursor_on);
void
vt_move_cursor(struct vt_decoder_state *state)
{
wmove(state->win, state->row, state->col);
wrefresh(state->win);

if (state->flags.is_cursor_on) {
wrefresh(state->win);
}
}

void
vt_decoder_toggle_flash(struct vt_decoder_state *state)
{
bool needs_refresh = false;
int curs = curs_set(0);
state->screen_flash_state = !state->screen_flash_state;

if (curs) {
wrefresh(state->win);
}

for (int r = 0; r < MAX_ROWS; ++r) {
for (int c = 0; c < MAX_COLS; ++c) {
struct vt_decoder_cell *cell = &state->cells[r][c];

if (cell->attr.has_flash) {
vt_put_char(state, r, c, cell->character, &cell->attr);
needs_refresh = true;
}
}
}

wrefresh(state->win);
curs_set(curs);

if (needs_refresh || curs) {
// restore cursor position
wmove(state->win, state->row, state->col);
wrefresh(state->win);
}
}

void
vt_decoder_toggle_reveal(struct vt_decoder_state *state)
{
bool needs_refresh = false;
int curs = curs_set(0);
state->screen_revealed_state = !state->screen_revealed_state;

if (curs) {
wrefresh(state->win);
}

for (int r = 0; r < MAX_ROWS; ++r) {
for (int c = 0; c < MAX_COLS; ++c) {
struct vt_decoder_cell *cell = &state->cells[r][c];

if (cell->attr.has_concealed) {
vt_put_char(state, r, c, cell->character, &cell->attr);
needs_refresh = true;
}
}
}

wrefresh(state->win);
curs_set(curs);

if (needs_refresh || curs) {
// restore cursor position
wmove(state->win, state->row, state->col);
wrefresh(state->win);
}
}

static void
Expand Down Expand Up @@ -472,7 +514,7 @@ vt_reset_flags(struct vt_decoder_state *state)
state->flags.is_mosaic_held = false;
state->flags.held_mosaic = state->space;
state->flags.is_double_height = false;
// Leave cursor ON
// leave cursor as is
}

static void
Expand Down Expand Up @@ -567,8 +609,12 @@ vt_init_colors(void)
static void
vt_trace(struct vt_decoder_state *state, char *format, ...)
{
int cy = 0;
int cx = 0;

if (state->trace_file != NULL) {
fprintf(state->trace_file, "%02d,%02d\t", state->row, state->col);
getyx(state->win, cy, cx);
fprintf(state->trace_file, "%02d,%02d (%02d,%02d)\t", state->row, state->col, cy, cx);
va_list args;
va_start(args, format);
vfprintf(state->trace_file, format, args);
Expand All @@ -577,15 +623,6 @@ vt_trace(struct vt_decoder_state *state, char *format, ...)
}
}

static void
vt_cursor(struct vt_decoder_state *state)
{
if (state->force_cursor) {
wmove(state->win, state->row, state->col);
wrefresh(state->win);
}
}

static void
vt_dump(struct vt_decoder_state *state, uint8_t *buffer, int count)
{
Expand Down
1 change: 0 additions & 1 deletion src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ struct vt_decoder_flags
bool is_mosaic_held;
struct vt_decoder_char held_mosaic;
bool is_double_height;
// DC1 = on, DC4 = off. Set-At
bool is_cursor_on;
};

Expand Down
17 changes: 6 additions & 11 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ vt_parse_options(int argc, char *argv[], struct vt_session_state *session)
{"port", required_argument, 0, 0},
{"dump", required_argument, 0, 0},
{"menu", no_argument, 0, 0},
{"cursor", no_argument, 0, 0},
{"mono", no_argument, 0, 0},
{"trace", required_argument, 0, 0},
{"bold", no_argument, 0, 0},
Expand Down Expand Up @@ -414,12 +413,9 @@ vt_parse_options(int argc, char *argv[], struct vt_session_state *session)
session->show_menu = true;
break;
case 4:
session->decoder_state.force_cursor = true;
break;
case 5:
session->decoder_state.mono_mode = true;
break;
case 6:
case 5:
if (session->decoder_state.trace_file != NULL) {
vt_usage();
goto abend;
Expand All @@ -431,23 +427,23 @@ vt_parse_options(int argc, char *argv[], struct vt_session_state *session)
}
setbuf(session->decoder_state.trace_file, NULL);
break;
case 7:
case 6:
session->decoder_state.bold_mode = true;
break;
case 8:
case 7:
session->decoder_state.map_char = &gal_map_char;
break;
case 9:
case 8:
session->load_file = fopen(optarg, "rb");
if (session->load_file == NULL) {
log_err();
goto abend;
}
break;
case 10:
case 9:
session->show_help = true;
break;
case 11:
case 10:
session->show_version = true;
break;
}
Expand Down Expand Up @@ -645,7 +641,6 @@ vt_usage(void)
printf("Version: %s\n", version);
printf("Usage: vidtex [options]\nOptions:\n");
printf("%-16s\tOutput bold brighter colours\n", "--bold");
printf("%-16s\tAlways show cursor\n", "--cursor");
printf("%-16s\tDump all bytes read from host to file\n", "--dump filename");
printf("%-16s\tLoad and display a saved frame\n", "--file filename");
printf("%-16s\tOutput char codes for Mode7 font\n", "--galax");
Expand Down
3 changes: 0 additions & 3 deletions src/vidtex.1
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ Several variations are available but the following is recommended:
\-\-\fBbold
Output bold text and brighter colours
.TP
\-\-\fBcursor
Always display the cursor
.TP
\-\-\fBdump \fIfile
Dump all bytes received from the host to \fIfile\fR
.TP
Expand Down
5 changes: 1 addition & 4 deletions src/vidtexrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#name,host,port,preamble,postamble
ccl4,fish.ccl4.org,23, ,42 81 81
night-owl,nightowlbbs.ddns.net,6400, ,42 57 48 95 95
nxtel,nx.nxtel.org,23280
teefax,teletext.matrixnetwork.co.uk,6502, ,70 70 70
telstar-fast-1,glasstty.com,6502,255 253 3,42 57 48 95 95
telstar-fast-2,glasstty.com,6503,255 253 3,42 57 48 95 95
telstar-slow-1,glasstty.com,6502, ,42 57 48 95 95
telstar-slow-2,glasstty.com,6503, ,42 57 48 95 95
prestel demo,viewdata.org.uk,6522
linkline demo,viewdata.org.uk,6854
#offline for a long time
ringworld,rw1.m63.co.uk,23

0 comments on commit 1fe93b7

Please sign in to comment.