Skip to content

Commit

Permalink
support dynamically changing the bit width
Browse files Browse the repository at this point in the history
  • Loading branch information
mellowcandle committed May 2, 2019
1 parent cf873ca commit ed31d82
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ To move around use the arrow keys, or use _vi_ key bindings : <kbd> h </kbd> <kb

You can toggle a bit bit using the <kbd> space </kbd> key.

Reducing or extending the bit width interactivblly is also very easy, just use:

<kbd> ! </kbd> for 8bit, <kbd> @ </kbd> for 16Bit, <kbd> $ </kbd> for 32Bit and <kbd> * </kbd> for 64Bit.

When chaning bit width, the number is *masked* with the new width, so you might lost precision, use with care.

Leave the program by pressing <kbd> q </kbd>.

## Installation
Expand Down
46 changes: 36 additions & 10 deletions interactive.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int dec_pos, hex_pos, oct_pos;
static void set_fields_width(int width)
{
int min_field_distance;

g_width = width;
switch (width) {
case 64:
binary_field_size = DBL_BINARY_WIN_LEN;
Expand Down Expand Up @@ -458,6 +458,8 @@ void unpaint_screen(void)
free_field(field[i]);
delwin(fields_win);
delwin(binary_win);
clear();
refresh();
}

int start_interactive(uint64_t start)
Expand All @@ -479,24 +481,48 @@ int start_interactive(uint64_t start)
ch = wgetch(fields_win);
LOG("ch= %d\n", ch);

if (ch == 'q' || ch == 'Q')
break;
switch (ch) {

if (ch == KEY_RESIZE) {
case 'q':
case 'Q':
goto exit;
break;
case KEY_RESIZE:
LOG("Terminal resize\n");
unpaint_screen();
paint_screen();
continue;
break;
case '!':
unpaint_screen();
set_fields_width(8);
paint_screen();
break;
case '@':
unpaint_screen();
set_fields_width(16);
paint_screen();
break;
case '$':
unpaint_screen();
set_fields_width(32);
paint_screen();
break;
case '*':
unpaint_screen();
set_fields_width(64);
paint_screen();
break;
default:
if (view == BINARY_VIEW)
process_binary(ch);
else
process_fields(ch);
}

if (view == BINARY_VIEW)
process_binary(ch);
else
process_fields(ch);

refresh();
}

exit:
unpaint_screen();
#ifdef TRACE
fclose(fd);
Expand Down

0 comments on commit ed31d82

Please sign in to comment.