Blame src/debug/ptyc_dbg_raw.c

1bab02
/*********************************************************/
1bab02
/*  ptycon: a pty-console bridge                         */
f25e99
/*  Copyright (C) 2016--2017  SysDeer Technologies, LLC  */
1bab02
/*  Released under GPLv2 and GPLv3; see COPYING.PTYCON.  */
1bab02
/*********************************************************/
1bab02
1bab02
#include <psxtypes/psxtypes.h>
1bab02
#include <ntcon/ntcon.h>
1bab02
#include <ntapi/ntapi.h>
1bab02
#include <gdi/gdi.h>
1bab02
1bab02
#include <ptycon/ptycon.h>
1bab02
#include "ptycon_driver_impl.h"
1bab02
5399d4
int __stdcall ptyc_dbg_raw(struct ptyc_driver_ctx_impl * ictx)
1bab02
{
11483c
	int32_t		status;
11483c
	void *		hwait;
11483c
	char *		ch;
11483c
	nt_iosb		iosb;
11483c
	size_t		nbytes;
11483c
	unsigned char	uch;
11483c
	unsigned int	keyval;
11483c
	char		xch[6] = {0,0,0,0,0,0};
11483c
11483c
	if ((status = ntapi->tt_create_private_event(
11483c
			&hwait,
11483c
			NT_NOTIFICATION_EVENT,
11483c
			NT_EVENT_NOT_SIGNALED)))
11483c
		return status;
11483c
11483c
	do {
11483c
		status = ntapi->pty_read(
11483c
			ictx->cctx.hpts,
11483c
			hwait,0,0,
11483c
			&iosb,
11483c
			&uch,1,
11483c
			0,0);
11483c
11483c
		if (status == NT_STATUS_PENDING)
11483c
			status = ntapi->zw_wait_for_single_object(
11483c
				hwait,NT_SYNC_ALERTABLE,0);
11483c
11483c
		if (status || iosb.status) {
11483c
			ntapi->zw_close(hwait);
11483c
			return status ? status : iosb.status;
11483c
		}
11483c
11483c
		ntapi->sprintf(xch,"0x%02x ",(keyval = uch));
11483c
		nbytes = sizeof(xch) - 1;
11483c
11483c
		for (ch=xch; nbytes; ) {
11483c
			status = ntapi->pty_write(
11483c
				ictx->cctx.hpts,
72aece
				hwait,0,0,&iosb,
72aece
				ch,(uint32_t)nbytes,
11483c
				0,0);
11483c
11483c
			if (status == NT_STATUS_PENDING)
11483c
				status = ntapi->zw_wait_for_single_object(
11483c
					hwait,NT_SYNC_ALERTABLE,0);
11483c
11483c
			if (status || iosb.status) {
11483c
				ntapi->zw_close(hwait);
11483c
				return status ? status : iosb.status;
11483c
			}
11483c
11483c
			ch     += iosb.info;
11483c
			nbytes -= iosb.info;
11483c
		}
11483c
	} while (1);
1bab02
}