Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge input-rewrite #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,49 +300,9 @@ int8_t input()
'v'
};

int ch = screen.input();

// FIXME: this looks awful
if(ch == NOINP_KEYCODE)
return NOINP_KEYCODE;
else if(ch == 'h')
return HALT_KEYCODE;
else if(ch == 'm')
return MEMDUMP_KEYCODE;
else if(ch == 'p')
return REFRESH_KEYCODE;

for(int8_t i = 0; i < 16; i++)
{
if(ch == mapping[i])
return i;
}

return NOINP_KEYCODE;
}

int8_t blockinginput()
{
int inp;
timing_t start = now();

do
{
inp = input();
sleepuntil(start, hztotiming(TARGET_HZ));
} while(inp == NOINP_KEYCODE);

return inp;
}

//void showinp(int inp)
//{
// if(inp != NOINP_KEYCODE)
// mvprintw(50, 0, "%c", inp+'0');
// else
// mvprintw(50, 0, " ");
//}

void loadfont(vm_t *vm)
{
// lores
Expand Down
24 changes: 1 addition & 23 deletions screen_ncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,8 @@ void nc_drawtext(int y, int x, const char *format, ...)
va_end(args);
}

int getch_bf = ERR;
timing_t getch_buf_cl = 0;
int getch_buf()
{
const timing_t getch_buf_cl_target = hztotiming(GETCH_HZ);
timing_t cl = now();

// FIXME: why is getch_bf == ERR needed here?
if(getch_bf == ERR || cl - getch_buf_cl >= getch_buf_cl_target)
{
getch_buf_cl = cl;
getch_bf = getch();
}
return getch_bf;
}

int nc_input()
{
int ch = getch_buf();
flushinp();

if(ch == ERR)
return NOINP_KEYCODE;

return ch;
return -1;
}

28 changes: 1 addition & 27 deletions screen_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,34 +114,8 @@ void sdl_drawtext(int y, int x, const char *format, ...)
//va_end(vargs);
}

int pollevent_bf = NOINP_KEYCODE;
timing_t pollevent_buf_cl = 0;
int sdl_input()
{
const timing_t pollevent_buf_cl_target = hztotiming(GETCH_HZ);
timing_t cl = now();

if(cl - pollevent_buf_cl >= pollevent_buf_cl_target)
{
SDL_Event event;

while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
pollevent_bf = 'h';
break;
case SDL_TEXTINPUT:
pollevent_bf = event.text.text[0];
break;
default:
pollevent_bf = NOINP_KEYCODE;
break;
}
}
}

return pollevent_bf;
return -1;
}

32 changes: 5 additions & 27 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,11 @@ status_t step(vm_t *vm)
uint8_t x = (op & 0x0f00) >> 8;
uint8_t y = (op & 0x00f0) >> 4;

int8_t inp = input();

uint8_t shift;
uint8_t flag = 0;

vm->op = op;

if(inp == HALT_KEYCODE)
{
vm->halt = 1;
return ST_OK;
}
else if(inp == MEMDUMP_KEYCODE)
{
memdump(vm);
return ST_OK;
}
else if(inp == REFRESH_KEYCODE)
{
vm->redrawscreen = 1;
return ST_OK;
}

#ifdef FLOOD_WITH_OPS
fprintf(stderr, "========================\n");
fprintf(stderr, "op: 0x%04x\n", op);
Expand Down Expand Up @@ -297,14 +279,10 @@ status_t step(vm_t *vm)
draw(vm, vm->V[x], vm->V[y], n);
break;
case 0xe0:
if(ln == 0x9e)
{
if(inp == vm->V[x]) vm->PC+=2;
}
else if(ln == 0xa1)
{
if(inp != vm->V[x]) vm->PC+=2;
}
if(ln == 0x9e);
// TODO: non-blocking input
else if(ln == 0xa1);
// TODO: non-blocking input
else
return ST_OP_UNDEFINED;
break;
Expand All @@ -315,7 +293,7 @@ status_t step(vm_t *vm)
vm->V[x] = vm->delay;
break;
case 0x0a:
vm->V[x] = blockinginput();
// TODO: blocking input
break;
case 0x15:
vm->delay = vm->V[x];
Expand Down