static void do_strategy(CONTEXT*ctx, int id, int extra) { REQUEST_HEADER *hdr = CTX_SEG_OFF_TO_LIN(ctx, ctx->SegEs, ctx->Ebx); void **hdr_ptr = strategy_data[id]; if (!hdr_ptr) { hdr_ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(void *)+extra); strategy_data[id] = hdr_ptr; } *hdr_ptr = hdr; do_lret(ctx); }
static void do_strategy(CONTEXT86*ctx, int id, int extra) { REQUEST_HEADER *hdr = CTX_SEG_OFF_TO_LIN(ctx, ctx->SegEs, ctx->Ebx); void **hdr_ptr = strategy_data[id]; if (!hdr_ptr) { hdr_ptr = calloc(1,sizeof(void *)+extra); strategy_data[id] = hdr_ptr; } *hdr_ptr = hdr; do_lret(ctx); }
static void WINAPI nul_interrupt(CONTEXT*ctx) { REQUEST_HEADER *hdr = get_hdr(SYSTEM_STRATEGY_NUL, NULL); /* eat everything and recycle nothing */ switch (hdr->command) { case CMD_INPUT: ((REQ_IO*)hdr)->count = 0; hdr->status = STAT_DONE; break; case CMD_SAFEINPUT: hdr->status = STAT_DONE|STAT_BUSY; break; default: hdr->status = STAT_DONE; } do_lret(ctx); }
static void WINAPI con_interrupt(CONTEXT*ctx) { int *scan; REQUEST_HEADER *hdr = get_hdr(SYSTEM_STRATEGY_CON,(void **)&scan); BIOSDATA *bios = DOSVM_BiosData(); WORD CurOfs = bios->NextKbdCharPtr; DOS_LISTOFLISTS *lol = DOSMEM_LOL(); DOS_DATASEG *dataseg = (DOS_DATASEG *)lol; BYTE *linebuffer = dataseg->buffer; BYTE *curbuffer = (lol->offs_unread_CON) ? (((BYTE*)dataseg) + lol->offs_unread_CON) : NULL; DOS_DEVICE_HEADER *con = dataseg->dev; DWORD w; switch (hdr->command) { case CMD_INPUT: { REQ_IO *io = (REQ_IO *)hdr; WORD count = io->count, len = 0; BYTE *buffer = CTX_SEG_OFF_TO_LIN(ctx, SELECTOROF(io->buffer), (DWORD)OFFSETOF(io->buffer)); hdr->status = STAT_BUSY; /* first, check whether we already have data in line buffer */ if (curbuffer) { /* yep, copy as much as we can */ BYTE data = 0; while ((len<count) && (data != '\r')) { data = *curbuffer++; buffer[len++] = data; } if (data == '\r') { /* line buffer emptied */ lol->offs_unread_CON = 0; curbuffer = NULL; /* if we're not in raw mode, call it a day */ if (!(con->attr & ATTR_RAW)) { hdr->status = STAT_DONE; io->count = len; break; } } else { /* still some data left */ lol->offs_unread_CON = curbuffer - (BYTE*)lol; /* but buffer was filled, we're done */ hdr->status = STAT_DONE; io->count = len; break; } } /* if we're in raw mode, we just need to fill the buffer */ if (con->attr & ATTR_RAW) { while (len<count) { WORD data; /* do we have a waiting scancode? */ if (*scan) { /* yes, store scancode in buffer */ buffer[len++] = *scan; *scan = 0; if (len==count) break; } /* check for new keyboard input */ while (CurOfs == bios->FirstKbdCharPtr) { /* no input available yet, so wait... */ DOSVM_Wait( ctx ); } /* read from keyboard queue (call int16?) */ data = ((WORD*)bios)[CurOfs]; CurOfs += 2; if (CurOfs >= bios->KbdBufferEnd) CurOfs = bios->KbdBufferStart; bios->NextKbdCharPtr = CurOfs; /* if it's an extended key, save scancode */ if (LOBYTE(data) == 0) *scan = HIBYTE(data); /* store ASCII char in buffer */ buffer[len++] = LOBYTE(data); } } else { /* we're not in raw mode, so we need to do line input... */ while (TRUE) { WORD data; /* check for new keyboard input */ while (CurOfs == bios->FirstKbdCharPtr) { /* no input available yet, so wait... */ DOSVM_Wait( ctx ); } /* read from keyboard queue (call int16?) */ data = ((WORD*)bios)[CurOfs]; CurOfs += 2; if (CurOfs >= bios->KbdBufferEnd) CurOfs = bios->KbdBufferStart; bios->NextKbdCharPtr = CurOfs; if (LOBYTE(data) == '\r') { /* it's the return key, we're done */ linebuffer[len++] = LOBYTE(data); break; } else if (LOBYTE(data) >= ' ') { /* a character */ if ((len+1)<CON_BUFFER) { linebuffer[len] = LOBYTE(data); WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), &linebuffer[len++], 1, &w, NULL); } /* else beep, but I don't like noise */ } else switch (LOBYTE(data)) { case '\b': if (len>0) { len--; WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "\b \b", 3, &w, NULL); } break; } } if (len > count) { /* save rest of line for later */ lol->offs_unread_CON = linebuffer - (BYTE*)lol + count; len = count; } memcpy(buffer, linebuffer, len); } hdr->status = STAT_DONE; io->count = len; } break; case CMD_SAFEINPUT: if (curbuffer) { /* some line input waiting */ hdr->status = STAT_DONE; ((REQ_SAFEINPUT*)hdr)->data = *curbuffer; } else if (con->attr & ATTR_RAW) { if (CurOfs == bios->FirstKbdCharPtr) { /* no input */ hdr->status = STAT_DONE|STAT_BUSY; } else { /* some keyboard input waiting */ hdr->status = STAT_DONE; ((REQ_SAFEINPUT*)hdr)->data = ((BYTE*)bios)[CurOfs]; } } else { /* no line input */ hdr->status = STAT_DONE|STAT_BUSY; } break; case CMD_INSTATUS: if (curbuffer) { /* we have data */ hdr->status = STAT_DONE; } else if (con->attr & ATTR_RAW) { if (CurOfs == bios->FirstKbdCharPtr) { /* no input */ hdr->status = STAT_DONE|STAT_BUSY; } else { /* some keyboard input waiting */ hdr->status = STAT_DONE; } } else { /* no line input */ hdr->status = STAT_DONE|STAT_BUSY; } break; case CMD_INFLUSH: /* flush line and keyboard queue */ lol->offs_unread_CON = 0; bios->NextKbdCharPtr = bios->FirstKbdCharPtr; break; case CMD_OUTPUT: case CMD_SAFEOUTPUT: { REQ_IO *io = (REQ_IO *)hdr; BYTE *buffer = CTX_SEG_OFF_TO_LIN(ctx, SELECTOROF(io->buffer), (DWORD)OFFSETOF(io->buffer)); DWORD result = 0; WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buffer, io->count, &result, NULL); io->count = result; hdr->status = STAT_DONE; } break; default: hdr->status = STAT_DONE; } do_lret(ctx); }