Compare commits

..

No commits in common. "cd55adae4f962564ff2f775741419ad9c5ee7747" and "c3ae983a734c9f783ef684ade077c2e14ac5a8b9" have entirely different histories.

5 changed files with 144 additions and 726 deletions

File diff suppressed because it is too large Load diff

View file

@ -351,6 +351,7 @@ end;
function TKPComm.GetInput: string;
var
Stat: TComStat;
BytesToRead: Integer;
BytesRead: Integer;
Buf: array[0..255] of Char;
@ -359,12 +360,15 @@ begin
if not FPortOpen or (FCommId < 0) then
Exit;
{ Read directly without querying GetCommError first. ReadComm }
{ returns the number of bytes actually available (up to BytesToRead) }
{ so the extra GetCommError round-trip is unnecessary overhead. }
BytesToRead := 255;
GetCommError(FCommId, Stat);
BytesToRead := Stat.cbInQue;
if (FInputLen > 0) and (BytesToRead > FInputLen) then
BytesToRead := FInputLen;
if BytesToRead > 255 then
BytesToRead := 255;
if BytesToRead <= 0 then
Exit;
BytesRead := ReadComm(FCommId, @Buf, BytesToRead);
if BytesRead <= 0 then
@ -554,12 +558,14 @@ end;
procedure TKPComm.ProcessReceiveNotify;
var
Stat: TComStat;
begin
if FRThreshold <= 0 then
Exit;
{ WM_COMMNOTIFY with CN_RECEIVE means data is available -- the driver }
{ already checked the threshold. No need to call GetCommError here. }
DoCommEvent(comEvReceive);
GetCommError(FCommId, Stat);
if Integer(Stat.cbInQue) >= FRThreshold then
DoCommEvent(comEvReceive);
end;

View file

@ -116,9 +116,6 @@ CSI (ESC\[) sequences:
| ESC\[*params*m | SGR | Set graphic rendition (see below) |
| ESC\[s | SCP | Save cursor position |
| ESC\[u | RCP | Restore cursor position |
| ESC\[c | DA | Device Attributes — responds ESC\[?1;0c (VT100) |
| ESC\[5n | DSR | Device Status Report — responds ESC\[0n (OK) |
| ESC\[6n | CPR | Cursor Position Report — responds ESC\[*row*;*col*R |
SGR codes:
@ -151,7 +148,6 @@ Control characters:
| LF (#10) | Line feed (scrolls at bottom) |
| BS (#8) | Backspace (no erase) |
| TAB (#9) | Tab to next 8-column stop |
| ENQ (#5) | Answerback — responds ESC\[?1;0c (VT100) |
| BEL (#7) | System beep |
**ANSI Music:**

View file

@ -85,19 +85,9 @@ begin
case FComm.CommEvent of
comEvReceive:
begin
{ Drain all available data in a single update batch. This }
{ suppresses per-Write rendering so we get one paint at the }
{ end instead of one per 255-byte chunk. }
FAnsi.BeginUpdate;
try
repeat
S := FComm.Input;
if Length(S) > 0 then
FAnsi.Write(S);
until Length(S) = 0;
finally
FAnsi.EndUpdate;
end;
S := FComm.Input;
if Length(S) > 0 then
FAnsi.Write(S);
end;
end;
end;
@ -141,7 +131,7 @@ begin
FEditSettings.Left := 148;
FEditSettings.Top := 8;
FEditSettings.Width := 140;
FEditSettings.Text := '115200,N,8,1';
FEditSettings.Text := '9600,N,8,1';
FBtnOpen := TButton.Create(Self);
FBtnOpen.Parent := Self;
@ -174,15 +164,6 @@ begin
FAnsi.Left := 0;
FAnsi.Top := 38;
FAnsi.OnKeyData := AnsiKeyData;
{ Font diagnostic: write known CP437 box-drawing characters. }
{ If the OEM font is working, you should see: }
{ Line 1: single-line box top ┌───┐ }
{ Line 2: shade + full block ░▒▓█ }
{ Line 3: single-line box bottom └───┘ }
{ If you see accented letters (Ú Ä ¿ ° ± ² Û À Ù), the font is }
{ ANSI_CHARSET instead of OEM_CHARSET. }
FAnsi.Write(#$DA#$C4#$C4#$C4#$BF' '#$B0#$B1#$B2#$DB' '#$C0#$C4#$C4#$C4#$D9#13#10);
end;

View file

@ -259,13 +259,6 @@ void applyBaudRate(PortStateT *port, uint16_t baud)
base = port->baseAddr;
divisor = (uint16_t)(BAUD_DIVISOR_BASE / actualBaud);
// Guard: divisor 0 means the UART treats it as 65536, giving ~1.76 baud.
// This can happen when BuildCommDCB stores a raw truncated value for
// 115200 (e.g. 0xE101 = 57601) and a future rate exceeds 115200.
if (divisor == 0) {
divisor = 1;
}
// Set DLAB to access divisor latch
lcr = (uint8_t)_inp(base + UART_LCR);
_outp(base + UART_LCR, lcr | LCR_DLAB);
@ -322,11 +315,6 @@ void applyLineParams(PortStateT *port, uint8_t byteSize, uint8_t parity, uint8_t
break;
}
dbgHex16("KPCOMM: applyLine byteSize", (uint16_t)byteSize);
dbgHex16("KPCOMM: applyLine parity", (uint16_t)parity);
dbgHex16("KPCOMM: applyLine stopBits", (uint16_t)stopBits);
dbgHex16("KPCOMM: applyLine LCR", (uint16_t)lcr);
_outp(base + UART_LCR, lcr);
port->byteSize = byteSize;
@ -960,12 +948,10 @@ int16_t FAR PASCAL _export inicom(DCB FAR *dcb)
_inp(port->baseAddr + UART_RBR);
// Populate ComDEB for third-party compatibility
port->comDeb.port = port->baseAddr;
port->comDeb.port = port->baseAddr;
port->comDeb.baudRate = port->baudRate;
port->comDeb.qInSize = port->rxSize;
port->comDeb.qOutSize = port->txSize;
port->comDeb.lcrShadow = (uint8_t)_inp(port->baseAddr + UART_LCR);
port->comDeb.mcrShadow = (uint8_t)_inp(port->baseAddr + UART_MCR);
// Enable receive and line status interrupts
_outp(port->baseAddr + UART_IER, IER_RDA | IER_LSI | IER_MSI);
@ -1115,9 +1101,7 @@ void primeTx(PortStateT *port)
// reactivateOpenCommPorts - Reactivate all ports after task switch (ordinal 18)
//
// Called by Windows when switching back to this VM.
// Restores full UART state: baud rate, line params (LCR), MCR, FIFOs,
// and re-enables interrupts. A DOS fullscreen app or VM switch may
// have reprogrammed the UART, so we must restore everything.
// Re-enables interrupts and restores MCR state.
// -----------------------------------------------------------------------
void FAR PASCAL _export reactivateOpenCommPorts(void)
{
@ -1133,12 +1117,6 @@ void FAR PASCAL _export reactivateOpenCommPorts(void)
continue;
}
// Restore baud rate (sets DLAB, writes divisor, clears DLAB)
applyBaudRate(port, port->baudRate);
// Restore line parameters (word length, parity, stop bits)
applyLineParams(port, port->byteSize, port->parity, port->stopBits);
// Restore MCR (DTR, RTS, OUT2)
mcr = MCR_OUT2;
if (port->dtrState) {