From 16fca6c4f109bf443cbbf09daa31aee5bf764611 Mon Sep 17 00:00:00 2001 From: RT Date: Sun, 19 Jul 2026 18:43:24 -0500 Subject: [PATCH] CRIOMAIN.CPP: translate Korean comments to English, clean UTF-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Translated all EUC-KR/CP949 Korean developer comments (~35 lines) to English. File re-saved as UTF-8 (was CP949/EUC-KR on disk). Also included: g_dwRIOPollTimeout formula that scales WaitForMultipleObjects timeout by baud rate: clamp(ceil(480000/baud), 5, 50) ms. Key translations: - Developer markers (sanghoon/hyun) - Packet receive loop comments - ACK/NAK handling comments - Thread/COM init comments - Button table comments - Joystick pedal/throttle diagram comments Decorative diamond markers (◆) stripped from case labels and section dividers. Unicode arrows (← →) in diagram comments replaced with ASCII. --- Gameleap/code/mw4/Code/MW4/CRIOMAIN.CPP | 95 ++++++++++++++----------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/Gameleap/code/mw4/Code/MW4/CRIOMAIN.CPP b/Gameleap/code/mw4/Code/MW4/CRIOMAIN.CPP index 8d0fe02d..d2d2bc96 100644 --- a/Gameleap/code/mw4/Code/MW4/CRIOMAIN.CPP +++ b/Gameleap/code/mw4/Code/MW4/CRIOMAIN.CPP @@ -43,7 +43,7 @@ LONG g_LeftPedalLast = 0; LONG g_RightPedalLast = 0; BOOL g_StartGame = FALSE; -static int g_nOpenComState = 0; // +static int g_nOpenComState = 0; // hyun DWORD g_dwLastAnalogUpdate = 0; @@ -54,7 +54,7 @@ DWORD g_dwLastAnalogUpdate = 0; #define RESTART_CHAR 0xFE #define IDLE_CHAR 0xFF -//member ó ȰҰ. +//Use it like a member variable. static HANDLE g_hCom = INVALID_HANDLE_VALUE; static OVERLAPPED wos; static OVERLAPPED ros; @@ -108,6 +108,7 @@ int g_nRIOPacketCountB = (sizeof(g_baRIOLengthsB) / sizeof(g_baRIOLengthsB[0])); int g_nRIOType = 0; // 0: old(original) type, 1: new type DWORD g_dwRIOBaud = 0; // [tbaud] 0: default by RIO type; else COM1 baud forced by -tbaud (high-speed replica of the original RIO board, protocol unchanged) +DWORD g_dwRIOPollTimeout = 50; // [tbaud] WaitForMultipleObjects timeout (ms); computed from baud rate before the receive loop starts int g_nEjectButton = 61; // 61: original, 31: new type BYTE* g_pbRIOLengths = NULL; int g_nRIOPacketCount = 0; @@ -318,7 +319,7 @@ void RequestVersion(); void RequestAnalogUpdate(BYTE bFreq = 3); // start - for new RIO Board only... -//received packet ٸ 忡 óϹǷ.. ciritical section ʿϴ.. +//Received packets are handled in different threads.. a critical section is needed.. BYTE received_buffer[128][16]; int received_packet=0;//packets count in the received_buffer. DWORD received_serial=0; @@ -569,7 +570,7 @@ BOOL SetupConnection(HANDLE hCom) return TRUE; /* - ó ƾ.. + Original processing routine.. NPTTYINFO npTTYInfo=0 ; BYTE bset1 = (BYTE) ((FLOWCTRL( npTTYInfo ) & FC_DTRDSR) != 0) ; BYTE bset2 = (BYTE) ((FLOWCTRL( npTTYInfo ) & FC_RTSCTS) != 0) ; @@ -603,7 +604,7 @@ BOOL SetupConnection(HANDLE hCom) -//ó ʴ ׸.. GetCommState ⺻ óѴ. +//Unhandled items.. handled using GetCommState default values. DWORD fDsrSensitivity:1; // DSR sensitivity DWORD fTXContinueOnXoff:1; // XOFF continues Tx DWORD fErrorChar: 1; // enable error replacement @@ -647,7 +648,7 @@ HANDLE OpenConnection(int port) g_hLampEvent = CreateEvent(0,FALSE,0,0); g_hCommWatchThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL, 0, (LPTHREAD_START_ROUTINE)CommWatchProc, NULL, CREATE_SUSPENDED, &g_dwThreadID); if (g_hCommWatchThread) { - //Thread Ǿ. + //Thread was created successfully. ////////////////////////////////////////////// //All OK //Exit Point <====== @@ -744,11 +745,11 @@ retry: for(int i=0;i<(int)dwLength;i++){ int ch=(BYTE)lpszBlock[i]; - // ڸŭ . - //.. ް ִ packet ..  controlڶ ִ ̴. + //Loop for the number of received characters. + //Currently.. no packet is being received.. can receive any control character. if(packetbyteremain!=0){ - //Ŷ شϴ ڰ ߴ.. ڵ ޴´. + //Character corresponding to a packet has arrived.. receive the remaining characters. if (ch & 0x80) { packetbyteremain=0; chinpacket=0; @@ -758,7 +759,7 @@ retry: packetbytes[chinpacket] = ch; chinpacket++; if (packetbyteremain == 0) { - //ϳ Ŷ ϼǾ. ߴ.. Ѵ. + //A packet has been completed and arrived.. respond immediately. chinpacket--; // exclude check byte int packettype=packetbytes[0]; BYTE bCheckByte = 0; @@ -837,21 +838,21 @@ retry: packettype++; packettype--; #endif // _DEBUG - case rio_Ack2://ߡߡߡߡߡߡߡߡߡ + case rio_Ack2: if (g_nRIOType != 0) { BYTE id=packetbytes[1]; int popped_index=PopPacket(id); ack_timeout=GetTickCount()+30; if(popped_index==0){ - //ó... ̴. + //This is the very first one... Normal case. }else if(popped_index>0){ - //ó ƴѰ. - //͵ ʾǷ ٽ ... - ReSendPackets(popped_index);//߸ ŭ.. + //Not the very first one. + //Previous ones were not sent successfully, resend... + ReSendPackets(popped_index);//By the number of incorrect ones.. }else{ - // ߴٴ°.. id Դٴ ε.. - // .. ׷ Ư ó . - //׳ Ѵ. + //Failure means an id that does not exist arrived.. + //An obvious error.. but there is no particular way to handle it. + //Simply ignore it. } } break; @@ -870,9 +871,9 @@ retry: // WriteTTYBlock(hWnd,"|",1); chinpacket=0; - //packetbytes۸ . + //Clear the packetbytes buffer. } else { - // Ŷ ڵ ʾҴ.. ƹ͵ ʴ´. + //Packet characters have not all arrived yet.. do nothing. ; } }else{ @@ -889,7 +890,7 @@ retry: }//for(int i=0;i<(int)dwLength;i++) - // + //sanghoon end if (!fReadStat){ if (GetLastError() == ERROR_IO_PENDING){ while(!GetOverlappedResult( g_hCom,&ros, &dwLength, TRUE )){ @@ -1000,12 +1001,22 @@ DWORD FAR PASCAL CommWatchProc( LPSTR lpData ) } g_dwLastAnalogUpdate = GetTickCount() + 2800; + // [tbaud] Scale the poll timeout proportionally to baud rate so faster links + // poll more frequently. Formula: clamp(ceil(480000/baud), 5, 50) + // preserves the existing 50ms at 9600 baud, floors at 5ms for high speeds. + // effectiveBaud: use -tbaud override if set, else the RIO type's default. + { + DWORD effectiveBaud = (g_dwRIOBaud != 0) ? g_dwRIOBaud + : ((g_nRIOType == 0) ? 9600UL : 115200UL); + g_dwRIOPollTimeout = min(50UL, max(5UL, + (480000UL + effectiveBaud - 1) / effectiveBaud)); + } while(1) { DWORD dwEvtMask = 0; WaitCommEvent( g_hCom, &dwEvtMask,&wcos ); - DWORD ret=WaitForMultipleObjects(3,events,FALSE,50/*INFINITE*/); + DWORD ret=WaitForMultipleObjects(3,events,FALSE,g_dwRIOPollTimeout); if(ret==WAIT_OBJECT_0){ //An Comm Event has arrived. DWORD bytesread; @@ -1022,10 +1033,10 @@ DWORD FAR PASCAL CommWatchProc( LPSTR lpData ) } } else {*/ if (g_nRIOType != 0) { - ///ߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡ ReadCommBlock ack ޾ duetime updateŲ. - ///ߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡCheckSentBuffer... + ///When ack is received from ReadCommBlock above, update duetime. + ///CheckSentBuffer... if(GetTickCount()>ack_timeout) - ReSendPackets(sent_packet);//sent_buffer ִ ͵ ٽ . + ReSendPackets(sent_packet);//Resend everything in sent_buffer. } /*}*/ }else if(ret==WAIT_OBJECT_0+1){ @@ -1039,9 +1050,9 @@ DWORD FAR PASCAL CommWatchProc( LPSTR lpData ) //break; }else if (ret==WAIT_TIMEOUT) { if (g_nRIOType != 0) { - ///ߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡߡCheckSentBuffer... + ///CheckSentBuffer... if(GetTickCount()>ack_timeout) - ReSendPackets(sent_packet);//sent_buffer ִ ͵ ٽ . + ReSendPackets(sent_packet);//Resend everything in sent_buffer. } if (packetbyteremain == 0) { RequestAnalogUpdate(); @@ -1236,8 +1247,8 @@ bool SaveReceivedPacket(const BYTE*ba,int length) bool GetSerialFromReceivedBuffer(char * ba) { -//ButtonPressed/Released ´.. - // serial packet ű. +//Store only ButtonPressed/Released.. + //Transfer all serial packets. if(received_packet>0){ if(received_buffer[0][2]==received_serial){ CopyMemory(ba,received_buffer[0],16); @@ -1264,7 +1275,7 @@ bool QueuePacket(const BYTE *ba,int length) int PopPacket(BYTE id) { -//lamp.. id.. +//lamp.. check by id.. //search the packet.. for(int i=0;i ====================== - + /^ g_LeftPedalStart: INT_MAX (+) lP = (LONG)g_LeftPedalStart - g_LeftPedal; - lP + lP result value is always negative */ LONG lP = 0; @@ -2362,9 +2373,9 @@ void CRIOMAIN::UpdateThrottle (DIJOYSTATE &js) Up Down ====================== - (-) (+) + <-- (-) (+) --> ====================== - + /^ g_ThrottleStart: INT_MIN (-) */ @@ -2447,11 +2458,11 @@ void CRIOMAIN::UpdateJoystick (DIJOYSTATE &js) */ ////////////////////////////////////////////////////////////////////////////////// /* - 80 ǹ + Meaning of 80 - RIO (LEFT :120 ~ RIGHT :-80) شٰ ϰ - (LEFTǰ) RIGHT ִ밪 80 ̻ ߶ - LEFT RIGHT ӵ ϼ ִ + Assuming RIO returns values in range (LEFT:120 ~ RIGHT:-80) + (In the LEFT case) clip values above the RIGHT maximum of 80, and the rest + if discarded, LEFT and RIGHT can move at the same speed */ ////////////////////////////////////////////////////////////////////////////////// LONG lJ;