1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554 |
- #define BUILDING_OPENDOORS
- #include <stdarg.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <time.h>
- #include "OpenDoor.h"
- #include "ODCore.h"
- #include "ODGen.h"
- #include "ODPlat.h"
- #include "ODScrn.h"
- #include "ODUtil.h"
- #include "ODFrame.h"
- #include "ODInEx.h"
- #ifdef ODPLAT_WIN32
- #include "ODKrnl.h"
- #include "ODRes.h"
- #endif
- #define SCREEN_BUFFER_SIZE (OD_SCREEN_WIDTH * OD_SCREEN_HEIGHT * 2)
- #define SCREEN_BUFFER_SEGMENT_SIZE (SCREEN_BUFFER_SIZE / 16)
- #define BYTES_PER_CHAR 2
- #define BUFFER_LINE_BYTES (OD_SCREEN_WIDTH * BYTES_PER_CHAR)
- #define LINE_BUFFER_SIZE (OD_SCREEN_WIDTH + 1)
- #if defined(ODPLAT_DOS) || defined(ODPLAT_NIX)
- static void *pAllocatedBufferMemory;
- #endif
- static void ODFAR *pScrnBuffer;
- static BYTE btCursorColumn;
- static BYTE btCursorRow;
- static BYTE btLeftBoundary;
- static BYTE btTopBoundary;
- static BYTE btRightBoundary;
- static BYTE btBottomBoundary;
- static BYTE btCurrentAttribute;
- static BOOL bScrollEnabled;
- #ifdef ODPLAT_DOS
- static WORD wBufferSegment;
- static BYTE btDisplayPage;
- #endif
- static BYTE bCaretOn;
- static char szBuffer[LINE_BUFFER_SIZE];
- static void ODScrnGetCursorPos(void);
- static void ODScrnUpdateCaretPos(void);
- static void ODScrnScrollUpOneLine(void);
- static void ODScrnScrollUpAndInvalidate(void);
- #ifdef ODPLAT_WIN32
- typedef struct
- {
- HWND hwndFrame;
- HANDLE hInstance;
- } tODScrnThreadInfo;
- static HWND hwndScreenWindow;
- BOOL bScreenHasFocus;
- static HFONT hCurrentFont;
- static INT nFontCellWidth;
- static INT nFontCellHeight;
- COLORREF acrPCTextColors[] =
- {
- RGB(0x00, 0x00, 0x00),
- RGB(0x00, 0x00, 0xc0),
- RGB(0x00, 0xc0, 0x00),
- RGB(0x00, 0xc0, 0xc0),
- RGB(0xc0, 0x00, 0x00),
- RGB(0xc0, 0x00, 0xc0),
- RGB(0xc0, 0xc0, 0x00),
- RGB(0xc0, 0xc0, 0xc0),
- RGB(0x7f, 0x7f, 0x7f),
- RGB(0x00, 0x00, 0xff),
- RGB(0x00, 0xff, 0x00),
- RGB(0x00, 0xff, 0xff),
- RGB(0xff, 0x00, 0x00),
- RGB(0xff, 0x00, 0xff),
- RGB(0xff, 0xff, 0x00),
- RGB(0xff, 0xff, 0xff),
- };
- typedef struct
- {
- int nVirtKey;
- BYTE btODKey;
- } tWinKeyToODKey;
- tWinKeyToODKey aWinKeyToODKey[] =
- {
- {VK_UP, OD_KEY_UP},
- {VK_DOWN, OD_KEY_DOWN},
- {VK_LEFT, OD_KEY_LEFT},
- {VK_RIGHT, OD_KEY_RIGHT},
- {VK_INSERT, OD_KEY_INSERT},
- {VK_DELETE, OD_KEY_DELETE},
- {VK_END, OD_KEY_END},
- {VK_HOME, OD_KEY_HOME},
- {VK_PRIOR, OD_KEY_PGUP},
- {VK_NEXT, OD_KEY_PGDN},
- {VK_F1, OD_KEY_F1},
- {VK_F2, OD_KEY_F2},
- {VK_F3, OD_KEY_F3},
- {VK_F4, OD_KEY_F4},
- {VK_F5, OD_KEY_F5},
- {VK_F6, OD_KEY_F6},
- {VK_F7, OD_KEY_F7},
- {VK_F8, OD_KEY_F8},
- {VK_F9, OD_KEY_F9},
- {VK_F10, OD_KEY_F10},
- };
- #define COLUMN_AS_XPIXEL(nColumn) (((INT)(nColumn)) * nFontCellWidth)
- #define ROW_AS_YPIXEL(nRow) (((INT)(nRow)) * nFontCellHeight)
- #define XPIXEL_AS_COLUMN(nX) (((INT)(nX)) / nFontCellWidth)
- #define YPIXEL_AS_ROW(nY) (((INT)(nY)) / nFontCellHeight)
- #define WM_MOVE_YOUR_CARET (WM_USER + 1)
- #define WM_KEYDOWN_RELAY (WM_USER + 2)
- #define CARET_HEIGHT 3
- LRESULT CALLBACK ODScrnWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
- LPARAM lParam);
- static HWND ODScrnCreateWin(HWND hwndFrame, HANDLE hInstance);
- static void ODScrnMessageLoop(HANDLE hInstance, HWND hwndScreen);
- DWORD OD_THREAD_FUNC ODScrnThreadProc(void *pParam);
- static void ODScrnPaint(HDC hdc, INT nLeft, INT nTop, INT nRight, INT nBottom);
- static void ODScrnInvalidate(BYTE btLeft, BYTE btTop, BYTE btRight,
- BYTE btBottom);
- static void ODScrnSetCurrentFont(HWND hwndScreen, HFONT hNewFont);
- static void ODScrnSetWinCaretPos(void);
- static HWND ODScrnCreateWin(HWND hwndFrame, HANDLE hInstance)
- {
- HWND hwndScreen = NULL;
- WNDCLASS wcScreenWindow;
- ASSERT(hwndFrame != NULL);
- ASSERT(hInstance != NULL);
-
- memset(&wcScreenWindow, 0, sizeof(wcScreenWindow));
- wcScreenWindow.style = CS_HREDRAW | CS_VREDRAW;
- wcScreenWindow.lpfnWndProc = ODScrnWindowProc;
- wcScreenWindow.cbClsExtra = 0;
- wcScreenWindow.cbWndExtra = 0;
- wcScreenWindow.hInstance = hInstance;
- wcScreenWindow.hIcon = NULL;
- wcScreenWindow.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcScreenWindow.hbrBackground = NULL;
- wcScreenWindow.lpszMenuName = NULL;
- wcScreenWindow.lpszClassName = "ODScreen";
- RegisterClass(&wcScreenWindow);
-
- if((hwndScreen = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- wcScreenWindow.lpszClassName,
- "",
- WS_CHILD | WS_BORDER,
- 0,
- 0,
- 500,
- 300,
- hwndFrame,
- NULL,
- hInstance,
- (LPVOID)hInstance)) == NULL)
- {
-
- return(NULL);
- }
-
- hwndScreenWindow = hwndScreen;
- return(hwndScreen);
- }
- LRESULT CALLBACK ODScrnWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
- LPARAM lParam)
- {
- HINSTANCE hInstance;
- ASSERT(hwnd != NULL);
- hInstance = (HINSTANCE)GetWindowLong(hwnd, GWL_USERDATA);
- switch(uMsg)
- {
- case WM_SYSCOMMAND:
-
-
-
-
-
-
- if(wParam == SC_KEYMENU)
- {
- PostMessage(GetParent(hwnd), uMsg, wParam, lParam);
- }
- else
- {
- return(DefWindowProc(hwnd, uMsg, wParam, lParam));
- }
- break;
- case WM_CREATE:
- {
- CREATESTRUCT *pCreateStruct = (CREATESTRUCT *)lParam;
- hInstance = (HINSTANCE)pCreateStruct->lpCreateParams;
- SetWindowLong(hwnd, GWL_USERDATA, (LONG)hInstance);
- break;
- }
- case WM_PAINT:
- {
- PAINTSTRUCT PaintStruct;
- HDC hdc;
-
- hdc = BeginPaint(hwnd, &PaintStruct);
- if(hdc != NULL)
- {
-
- ODScrnPaint(hdc,
- XPIXEL_AS_COLUMN(PaintStruct.rcPaint.left),
- YPIXEL_AS_ROW(PaintStruct.rcPaint.top),
- XPIXEL_AS_COLUMN(PaintStruct.rcPaint.right),
- YPIXEL_AS_ROW(PaintStruct.rcPaint.bottom));
-
- EndPaint(hwnd, &PaintStruct);
- }
- break;
- }
- case WM_MOVE_YOUR_CARET:
- ODScrnSetWinCaretPos();
- break;
- case WM_LBUTTONDOWN:
- SetFocus(hwnd);
- break;
- case WM_SETFOCUS:
-
-
- CreateCaret(hwnd, NULL, nFontCellWidth, CARET_HEIGHT);
-
- bScreenHasFocus = TRUE;
-
- ODScrnSetWinCaretPos();
-
- ShowCaret(hwnd);
- break;
- case WM_KILLFOCUS:
-
- bScreenHasFocus = FALSE;
-
- DestroyCaret();
- break;
- case WM_KEYDOWN_RELAY:
- {
- int nVirtKeyPressed = (int)wParam;
- WORD wRepeatCount = LOWORD(lParam);
- int nKeyTableIndex;
- WORD wKey = 0;
-
- for(nKeyTableIndex = 0; nKeyTableIndex < DIM(aWinKeyToODKey);
- ++nKeyTableIndex)
- {
- if(aWinKeyToODKey[nKeyTableIndex].nVirtKey == nVirtKeyPressed)
- {
- wKey = MAKEWORD(0, aWinKeyToODKey[nKeyTableIndex].btODKey);
- break;
- }
- }
-
- if(wKey != 0)
- {
- while(wRepeatCount--)
- {
- ODKrnlHandleLocalKey(wKey);
- }
- }
- break;
- }
- case WM_CHAR:
- {
- WORD wRepeatCount = LOWORD(lParam);
- BYTE btScanCode = LOBYTE(HIWORD(lParam));
- TCHAR chCharCode = (TCHAR)wParam;
- WORD wKey;
-
- wKey = MAKEWORD(chCharCode, btScanCode);
-
- while(wRepeatCount--)
- {
- ODKrnlHandleLocalKey(wKey);
- }
- break;
- }
- default:
-
-
- return(DefWindowProc(hwnd, uMsg, wParam, lParam));
- }
- return(0);
- }
- static void ODScrnPaint(HDC hdc, INT nLeft, INT nTop, INT nRight, INT nBottom)
- {
- INT nIDSavedState;
- INT nCurrentLine;
- INT nStartColumn;
- INT nEndColumn;
- BYTE *pbtBufferContents;
- char achStringToOutput[OD_SCREEN_WIDTH];
- char *pchNextChar;
- BYTE btCurrentAttribute;
- ASSERT(hdc != NULL);
- ASSERT(nLeft >= 0);
- ASSERT(nTop >= 0);
- ASSERT(nRight >= nLeft);
- ASSERT(nBottom >= nTop);
-
- if(nRight >= OD_SCREEN_WIDTH) nRight = OD_SCREEN_WIDTH - 1;
- if(nBottom >= OD_SCREEN_HEIGHT) nBottom = OD_SCREEN_HEIGHT - 1;
-
-
- nIDSavedState = SaveDC(hdc);
-
- SetBkMode(hdc, OPAQUE);
- SelectObject(hdc, hCurrentFont);
-
- for(nCurrentLine = nTop; nCurrentLine <= nBottom; ++nCurrentLine)
- {
-
-
- pbtBufferContents = (BYTE *)(pScrnBuffer) +
- ((nCurrentLine * OD_SCREEN_WIDTH) + nLeft) * 2;
-
-
- for(nStartColumn = nLeft; nStartColumn <= nRight;
- nStartColumn = nEndColumn)
- {
-
-
- pchNextChar = achStringToOutput;
-
- btCurrentAttribute = pbtBufferContents[1];
-
- for(nEndColumn = nStartColumn; nEndColumn <= nRight; ++nEndColumn)
- {
-
-
- if(btCurrentAttribute != pbtBufferContents[1])
- {
- break;
- }
-
- *pchNextChar++ = *pbtBufferContents;
-
- pbtBufferContents += 2;
- }
-
-
- SetTextColor(hdc, acrPCTextColors[btCurrentAttribute & 0x0f]);
- SetBkColor(hdc, acrPCTextColors[(btCurrentAttribute & 0xf0) >> 4]);
-
- TextOut(hdc,
- COLUMN_AS_XPIXEL(nStartColumn),
- ROW_AS_YPIXEL(nCurrentLine),
- achStringToOutput,
- (nEndColumn - nStartColumn));
- }
- }
-
-
- RestoreDC(hdc, nIDSavedState);
- }
- static void ODScrnInvalidate(BYTE btLeft, BYTE btTop, BYTE btRight,
- BYTE btBottom)
- {
- RECT rcToInvalidate;
-
-
- if(hwndScreenWindow == NULL) return;
-
- rcToInvalidate.left = COLUMN_AS_XPIXEL(btLeft);
- rcToInvalidate.top = ROW_AS_YPIXEL(btTop);
- rcToInvalidate.right = COLUMN_AS_XPIXEL(btRight + 1);
- rcToInvalidate.bottom = ROW_AS_YPIXEL(btBottom + 1);
-
- InvalidateRect(hwndScreenWindow, &rcToInvalidate, FALSE);
- }
- static void ODScrnSetCurrentFont(HWND hwndScreen, HFONT hNewFont)
- {
- HDC hdc;
- INT nIDSavedState;
- TEXTMETRIC TextMetrics;
-
- hdc = GetDC(hwndScreen);
-
-
- if(hdc == NULL)
- {
- return;
- }
-
- hCurrentFont = hNewFont;
-
-
- nIDSavedState = SaveDC(hdc);
- SelectObject(hdc, hCurrentFont);
- GetTextMetrics(hdc, &TextMetrics);
- RestoreDC(hdc, nIDSavedState);
- ReleaseDC(hwndScreen, hdc);
-
- nFontCellWidth = TextMetrics.tmMaxCharWidth;
- nFontCellHeight = TextMetrics.tmHeight;
-
- ODScrnAdjustWindows();
- ODScrnAdjustWindows();
- }
- void ODScrnAdjustWindows(void)
- {
- INT nNewClientWidth;
- INT nNewClientHeight;
- RECT rcClient;
- RECT rcWindow;
- INT nNonClientWidth;
- INT nNonClientHeight;
- INT nScreenWindowWidth;
- INT nScreenWindowHeight;
- HWND hwndFrame;
- INT nTopFrameUsed;
- INT nBottomFrameUsed;
- HWND hwndScreen;
- hwndScreen = hwndScreenWindow;
- ASSERT(hwndScreen != NULL);
- hwndFrame = GetParent(hwndScreen);
- ASSERT(hwndFrame != NULL);
-
-
- nTopFrameUsed = ODFrameGetUsedClientAtTop(hwndFrame);
- nBottomFrameUsed = ODFrameGetUsedClientAtBottom(hwndFrame);
-
- nNewClientWidth = nFontCellWidth * OD_SCREEN_WIDTH;
- nNewClientHeight = nFontCellHeight * OD_SCREEN_HEIGHT;
-
- GetClientRect(hwndScreen, &rcClient);
- GetWindowRect(hwndScreen, &rcWindow);
- nNonClientWidth = (rcWindow.right - rcWindow.left)
- - (rcClient.right - rcClient.left);
- nNonClientHeight = (rcWindow.bottom - rcWindow.top)
- - (rcClient.bottom - rcClient.top);
-
- nScreenWindowWidth = nNewClientWidth + nNonClientWidth;
- nScreenWindowHeight = nNewClientHeight + nNonClientHeight;
-
- SetWindowPos(hwndScreen, NULL, 0, nTopFrameUsed, nScreenWindowWidth,
- nScreenWindowHeight, SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOZORDER);
-
-
-
- GetClientRect(hwndFrame, &rcClient);
- GetWindowRect(hwndFrame, &rcWindow);
- nNonClientWidth = (rcWindow.right - rcWindow.left)
- - (rcClient.right - rcClient.left);
- nNonClientHeight = (rcWindow.bottom - rcWindow.top)
- - (rcClient.bottom - rcClient.top);
- SetWindowPos(hwndFrame, NULL, 0, 0, nScreenWindowWidth + nNonClientWidth,
- nScreenWindowHeight + nNonClientHeight + nTopFrameUsed
- + nBottomFrameUsed,
- SWP_NOACTIVATE | SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
- }
- static void ODScrnMessageLoop(HANDLE hInstance, HWND hwndScreen)
- {
- MSG msg;
- HWND hwndFrame;
- ASSERT(hInstance != NULL);
- ASSERT(hwndScreen != NULL);
-
- hwndFrame = GetParent(hwndScreen);
-
-
-
- while(GetMessage(&msg, NULL, 0, 0))
- {
- if(!ODFrameTranslateAccelerator(hwndFrame, &msg))
- {
- TranslateMessage(&msg);
- if(msg.message == WM_KEYDOWN)
- {
- PostMessage(hwndScreen, WM_KEYDOWN_RELAY, msg.wParam, msg.lParam);
- }
- DispatchMessage(&msg);
- }
- }
- }
- DWORD OD_THREAD_FUNC ODScrnThreadProc(void *pParam)
- {
- tODScrnThreadInfo *pScrnThreadInfo = (tODScrnThreadInfo *)pParam;
- HWND hwndScreen;
- HANDLE hInstance = pScrnThreadInfo->hInstance;
- HWND hwndFrame = pScrnThreadInfo->hwndFrame;
-
-
- free(pScrnThreadInfo);
-
- hwndScreen = ODScrnCreateWin(hwndFrame, hInstance);
- if(hwndScreen == NULL)
- {
- return(FALSE);
- }
-
-
-
- ODScrnSetCurrentFont(hwndScreen, GetStockObject(OEM_FIXED_FONT));
-
- #ifdef ODPLAT_WIN32
- if(bPromptForUserName)
- {
- if(DialogBox(hInstance, MAKEINTRESOURCE(IDD_LOGIN), hwndFrame,
- ODInitLoginDlgProc) == IDCANCEL)
- {
- exit(od_control.od_errorlevel[1]);
- }
- PostMessage(hwndScreen, WM_SETFOCUS, 0, 0L);
- }
- #endif
-
- if(od_control.od_cmd_show == SW_MINIMIZE ||
- od_control.od_cmd_show == SW_SHOWMINIMIZED ||
- od_control.od_cmd_show == SW_SHOWMINNOACTIVE)
- {
- ShowWindow(hwndFrame, SW_SHOWMINNOACTIVE);
- }
- else
- {
- ShowWindow(hwndFrame, SW_RESTORE);
- }
-
- ShowWindow(hwndScreen, SW_SHOW);
-
- ODScrnMessageLoop(hInstance, hwndScreen);
-
- DestroyWindow(hwndScreen);
- return(TRUE);
- }
- tODResult ODScrnStartWindow(HANDLE hInstance, tODThreadHandle *phScreenThread,
- HWND hwndFrame)
- {
- tODScrnThreadInfo *pScrnThreadInfo;
- ASSERT(hInstance != NULL);
- ASSERT(phScreenThread != NULL);
- ASSERT(hwndFrame != NULL);
-
- if((pScrnThreadInfo = malloc(sizeof(tODScrnThreadInfo))) == NULL)
- {
- return(kODRCNoMemory);
- }
- pScrnThreadInfo->hInstance = hInstance;
- pScrnThreadInfo->hwndFrame = hwndFrame;
-
- return(ODThreadCreate(phScreenThread, ODScrnThreadProc,
- pScrnThreadInfo));
- }
- void ODScrnSetFocusToWindow(void)
- {
- if(hwndScreenWindow != NULL)
- {
- SetFocus(hwndScreenWindow);
- }
- }
- static void ODScrnSetWinCaretPos(void)
- {
-
-
- if(bScreenHasFocus)
- {
- SetCaretPos(COLUMN_AS_XPIXEL(btCursorColumn + btLeftBoundary),
- ROW_AS_YPIXEL(btCursorRow + btTopBoundary + 1) - CARET_HEIGHT);
- }
- }
- #endif
- tODResult ODScrnInitialize(void)
- {
- BOOL bClear = TRUE;
- #if defined(ODPLAT_DOS) || defined(ODPLAT_NIX)
-
-
-
- #ifndef ODPLAT_NIX
- if(od_control.od_silent_mode)
- {
- #endif
-
-
- pAllocatedBufferMemory = malloc(SCREEN_BUFFER_SIZE);
- if(pAllocatedBufferMemory == NULL)
- {
- return(kODRCNoMemory);
- }
-
-
- pScrnBuffer = pAllocatedBufferMemory;
- #ifndef ODPLAT_NIX
- }
- else
- {
- BYTE btDisplayMode;
-
- ASM push si
- ASM push di
- ASM mov ah, 0x0f
- ASM int 0x10
- ASM mov btDisplayMode, al
- ASM pop di
- ASM pop si
- switch(btDisplayMode & 0x7f)
- {
-
- case 0x02:
- case 0x03:
- wBufferSegment = 0xb800;
- pScrnBuffer = (void ODFAR *)0xb8000000L;
- bClear = TRUE;
- break;
-
- case 0x07:
- wBufferSegment = 0xb000;
- pScrnBuffer = (void ODFAR *)0xb0000000L;
- bClear = TRUE;
- break;
-
- case 0x21:
- wBufferSegment = 0xb000;
- pScrnBuffer = (void ODFAR *)0xb0000000L;
- bClear = FALSE;
-
- ASM push si
- ASM push di
- ASM mov ax, 0x0007
- ASM int 0x10
- ASM pop di
- ASM pop si
- break;
-
- default:
- wBufferSegment = 0xb800;
- pScrnBuffer = (void ODFAR *)0xb8000000L;
- bClear = FALSE;
-
- ASM push si
- ASM push di
- ASM mov ax, 0x0003
- ASM int 0x10
- ASM pop di
- ASM pop si
- }
-
- ASM push si
- ASM push di
- ASM mov ah, 0x0f
- ASM int 0x10
- ASM mov btDisplayPage, bh
- ASM pop di
- ASM pop si
- if(btDisplayPage!=0)
- {
- wBufferSegment += (SCREEN_BUFFER_SEGMENT_SIZE * btDisplayPage);
- ((char ODFAR *)pScrnBuffer) += (SCREEN_BUFFER_SIZE * btDisplayPage);
- }
- if(ODMultitasker == kMultitaskerDV)
- {
-
-
- ASM mov ax, 0x2b02
- ASM mov cx, 0x4445
- ASM mov dx, 0x5351
- ASM int 0x21
- ASM cmp bx, 0x1950
- ASM jne no_change
- ASM mov wBufferSegment, dx
- (long)pScrnBuffer = ODDWordShiftLeft((long)wBufferSegment, 16);
- no_change: ;
- }
- }
- #endif
- #endif
- #ifdef ODPLAT_WIN32
-
- pScrnBuffer = malloc(SCREEN_BUFFER_SIZE);
- if(pScrnBuffer == NULL)
- {
- return(kODRCNoMemory);
- }
- #endif
-
- btLeftBoundary = 0;
- btRightBoundary = 79;
- btTopBoundary = 0;
- btBottomBoundary = 24;
- btCurrentAttribute = 0x07;
- bScrollEnabled = 1;
-
- if(bClear)
- {
- ODScrnClear();
- }
-
- bCaretOn = FALSE;
- ODScrnEnableCaret(TRUE);
-
- return(kODRCSuccess);
- }
- void ODScrnShutdown(void)
- {
- #ifdef ODPLAT_WIN32
-
- if(pScrnBuffer != NULL)
- {
- free(pScrnBuffer);
- pScrnBuffer = NULL;
- }
- #else
-
-
- #ifndef ODPLAT_NIX
- if(od_control.od_silent_mode && pAllocatedBufferMemory != NULL)
- {
- #endif
- free(pAllocatedBufferMemory);
- pAllocatedBufferMemory = NULL;
- pScrnBuffer = NULL;
- #ifndef ODPLAT_NIX
- }
- #endif
- #endif
- }
- void ODScrnSetBoundary(BYTE btLeft, BYTE btTop, BYTE btRight, BYTE btBottom)
- {
-
- btLeftBoundary = btLeft - 1;
- btRightBoundary = btRight - 1;
- btTopBoundary = btTop - 1;
- btBottomBoundary = btBottom - 1;
-
- if(btCursorColumn > btRightBoundary - btLeftBoundary)
- {
- btCursorColumn = btRightBoundary - btLeftBoundary;
- }
- else if(btCursorColumn < btLeftBoundary)
- {
- btCursorColumn = btLeftBoundary;
- }
- if(btCursorRow > btBottomBoundary - btTopBoundary)
- {
- btCursorRow = btBottomBoundary - btTopBoundary;
- }
- else if(btCursorRow < btTopBoundary)
- {
- btCursorRow = btTopBoundary;
- }
-
- ODScrnUpdateCaretPos();
- }
- void ODScrnSetCursorPos(BYTE btColumn, BYTE btRow)
- {
-
- btCursorColumn = btColumn - 1;
- btCursorRow = btRow - 1;
-
- if(btCursorColumn > btRightBoundary - btLeftBoundary)
- btCursorColumn = btRightBoundary - btLeftBoundary;
- if(btCursorRow > btBottomBoundary - btTopBoundary)
- btCursorRow = btBottomBoundary - btTopBoundary;
-
- ODScrnUpdateCaretPos();
- }
- void ODScrnSetAttribute(BYTE btAttribute)
- {
-
- btCurrentAttribute = btAttribute;
- }
- void ODScrnEnableScrolling(BOOL bEnable)
- {
-
- bScrollEnabled = bEnable;
- }
- void ODScrnEnableCaret(BOOL bEnable)
- {
- #ifdef ODPLAT_DOS
- if(bCaretOn == bEnable) return;
- bCaretOn = bEnable;
-
- ASM push si
- ASM push di
- ASM mov ah, 0x03
- ASM mov bh, btDisplayPage
- ASM int 0x10
-
- ASM push cx
- ASM mov ah, 0x0f
- ASM int 0x10
- ASM pop cx
-
- ASM push ax
- ASM and ch, 0x1f
- ASM mov al, bCaretOn
- ASM and al, al
- ASM jnz set_cursor
-
-
-
- ASM or ch, 0x20
- set_cursor:
- ASM pop ax
- ASM mov bh, btDisplayPage
- ASM mov ah, 0x01
- ASM int 0x10
- ASM pop di
- ASM pop si
- if(bCaretOn)
- {
-
- ODScrnUpdateCaretPos();
- }
- else
- {
-
- ASM mov ah, 0x02
- ASM mov bh, btDisplayPage
- ASM mov dh, OD_SCREEN_HEIGHT
- ASM mov dl, OD_SCREEN_WIDTH
- ASM push si
- ASM push di
- ASM int 0x10
- ASM pop di
- ASM pop si
- }
- #endif
- }
- void ODScrnGetTextInfo(tODScrnTextInfo *pTextInfo)
- {
- pTextInfo->wintop = btTopBoundary + 1;
- pTextInfo->winleft = btLeftBoundary + 1;
- pTextInfo->winright = btRightBoundary + 1;
- pTextInfo->winbottom = btBottomBoundary + 1;
- pTextInfo->attribute = btCurrentAttribute;
- pTextInfo->curx = btCursorColumn + 1;
- pTextInfo->cury = btCursorRow + 1;
- }
- INT ODScrnPrintf(char *pszFormat, ...)
- {
- va_list pArgumentList;
- INT nToReturn;
-
- va_start(pArgumentList, pszFormat);
- nToReturn = vsprintf(szBuffer, pszFormat, pArgumentList);
- va_end(pArgumentList);
-
- ASSERT(strlen(szBuffer) <= sizeof(szBuffer) - 1);
-
- ODScrnDisplayString(szBuffer);
-
- return (nToReturn);
- }
- void ODScrnDisplayChar(unsigned char chToOutput)
- {
- BYTE ODFAR *pbtDest;
-
- ODScrnGetCursorPos();
- if(btCursorColumn > btRightBoundary - btLeftBoundary)
- {
- btCursorColumn = btRightBoundary - btLeftBoundary;
- }
- if(btCursorRow > btBottomBoundary - btTopBoundary)
- {
- btCursorRow = btBottomBoundary - btTopBoundary;
- }
- switch(chToOutput)
- {
-
- case '\r':
- btCursorColumn = 0;
- break;
-
- case '\n':
-
- if(btCursorRow == btBottomBoundary - btTopBoundary)
- {
-
- ODScrnScrollUpAndInvalidate();
- }
-
- else
- {
-
- ++btCursorRow;
- }
- break;
- case '\b':
-
- if(btCursorColumn != 0) --btCursorColumn;
- break;
- case '\t':
-
- btCursorColumn = ((btCursorColumn / 8) + 1) * 8;
- if(btCursorColumn > btRightBoundary - btLeftBoundary)
- {
- btCursorColumn = 0;
-
- if(++btCursorRow > btBottomBoundary - btTopBoundary)
- {
-
- btCursorRow = btBottomBoundary - btTopBoundary;
-
- ODScrnScrollUpAndInvalidate();
- }
- }
- break;
- case '\a':
-
- if(!od_control.od_silent_mode)
- {
- #ifdef ODPLAT_DOS
- ASM mov ah, 0x02
- ASM mov dl, 7
- ASM int 0x21
- #endif
- #ifdef ODPLAT_WIN32
- MessageBeep(0xffffffff);
- #endif
- }
- break;
-
- default:
-
- pbtDest = (BYTE ODFAR *)pScrnBuffer
- + ((btTopBoundary + btCursorRow) * BUFFER_LINE_BYTES
- + (btLeftBoundary + btCursorColumn) * BYTES_PER_CHAR);
- *pbtDest++ = chToOutput;
- *pbtDest = btCurrentAttribute;
- ASSERT(pbtDest >= (BYTE ODFAR *)pScrnBuffer);
- ASSERT(pbtDest < (BYTE ODFAR *)pScrnBuffer + SCREEN_BUFFER_SIZE);
- #ifdef ODPLAT_WIN32
-
- ODScrnInvalidate((BYTE)(btCursorColumn + btLeftBoundary),
- (BYTE)(btCursorRow + btTopBoundary),
- (BYTE)(btCursorColumn + btLeftBoundary),
- (BYTE)(btCursorRow + btTopBoundary));
- #endif
-
- if(++btCursorColumn > btRightBoundary - btLeftBoundary)
- {
-
- btCursorColumn = 0;
-
- if(++btCursorRow > btBottomBoundary - btTopBoundary)
- {
-
- btCursorRow = btBottomBoundary - btTopBoundary;
-
- ODScrnScrollUpAndInvalidate();
- }
- }
- }
-
- ODScrnUpdateCaretPos();
- }
- static void ODScrnGetCursorPos(void)
- {
- #ifdef ODPLAT_DOS
- if(!bCaretOn) return;
- ASM mov ah, 0x03
- ASM mov bh, btDisplayPage
- ASM push si
- ASM push di
- ASM int 0x10
- ASM pop di
- ASM pop si
- ASM sub dh, btTopBoundary
- ASM mov btCursorRow, dh
- ASM sub dl, btLeftBoundary
- ASM mov btCursorColumn, dl
- #endif
- }
- static void ODScrnUpdateCaretPos(void)
- {
- #ifdef ODPLAT_DOS
- if(!bCaretOn) return;
-
- ASM mov ah, 0x02
- ASM mov bh, btDisplayPage
- ASM mov dh, btCursorRow
- ASM add dh, btTopBoundary
- ASM mov dl, btCursorColumn
- ASM add dl, btLeftBoundary
- ASM push si
- ASM push di
- ASM int 0x10
- ASM pop di
- ASM pop si
- #endif
- #ifdef ODPLAT_WIN32
- if(hwndScreenWindow != NULL)
- {
- PostMessage(hwndScreenWindow, WM_MOVE_YOUR_CARET, 0, 0);
- }
- #endif
- }
- void ODScrnClear(void)
- {
- WORD ODFAR *pDest = (WORD ODFAR *)pScrnBuffer +
- ((btTopBoundary * OD_SCREEN_WIDTH) + btLeftBoundary);
- WORD wBlank = (((WORD)btCurrentAttribute) << 8) | 32;
- BYTE btCurColumn;
- BYTE btCurLine = (btBottomBoundary - btTopBoundary) + 1;
- BYTE btColumnStart = (btRightBoundary - btLeftBoundary) + 1;
- BYTE btSkip = OD_SCREEN_WIDTH - btColumnStart;
-
- do
- {
- btCurColumn = btColumnStart;
- do
- {
- ASSERT(pDest >= (WORD ODFAR *)pScrnBuffer);
- ASSERT(pDest <= (WORD ODFAR *)pScrnBuffer + 2000);
- *(pDest++) = wBlank;
- } while ((--btCurColumn) != 0);
- pDest += btSkip;
- } while((--btCurLine) != 0);
-
- btCursorColumn = btCursorRow = 0;
-
- ODScrnUpdateCaretPos();
- #ifdef ODPLAT_WIN32
-
- ODScrnInvalidate(btLeftBoundary, btTopBoundary, btRightBoundary,
- btBottomBoundary);
- #endif
- }
- static void ODScrnScrollUpAndInvalidate(void)
- {
-
- if(bScrollEnabled)
- {
-
- ODScrnScrollUpOneLine();
- #ifdef ODPLAT_WIN32
-
- ODScrnInvalidate(btLeftBoundary, btTopBoundary, btRightBoundary,
- btBottomBoundary);
- #endif
- }
- }
- static void ODScrnScrollUpOneLine(void)
- {
- WORD ODFAR *pwDest = (WORD ODFAR *)pScrnBuffer
- + (btTopBoundary * OD_SCREEN_WIDTH + btLeftBoundary);
- WORD ODFAR *pwSource;
- BYTE btCurColumn;
- BYTE btCurLine = btBottomBoundary - btTopBoundary;
- BYTE btColumnStart = btRightBoundary - btLeftBoundary + 1;
- BYTE btSkip = OD_SCREEN_WIDTH - btColumnStart;
- WORD wBlank = (((WORD)btCurrentAttribute) << 8) | 32;
- pwSource = pwDest + OD_SCREEN_WIDTH;
- ASSERT(btSkip >= 0 && btSkip <= OD_SCREEN_WIDTH);
-
- do
- {
- btCurColumn = btColumnStart;
- do
- {
- ASSERT(pwDest >= (WORD ODFAR *)pScrnBuffer);
- ASSERT(pwDest <= (WORD ODFAR *)pScrnBuffer + 2000);
- ASSERT(pwSource >= (WORD ODFAR *)pScrnBuffer);
- ASSERT(pwSource <= (WORD ODFAR *)pScrnBuffer+2000);
- *(pwDest++) = *(pwSource++);
- } while((--btCurColumn) != 0);
- pwDest += btSkip;
- pwSource += btSkip;
- } while ((--btCurLine) != 0);
-
- btCurColumn = btColumnStart;
- do
- {
- ASSERT(pwDest >= (WORD ODFAR *)pScrnBuffer);
- ASSERT(pwDest <= (WORD ODFAR *)pScrnBuffer + 2000);
- *(pwDest++) = wBlank;
- } while((--btCurColumn) != 0);
- }
- BOOL ODScrnGetText(BYTE btLeft, BYTE btTop, BYTE btRight, BYTE btBottom,
- void *pbtBuffer)
- {
- WORD *pwBuffer = (WORD *)pbtBuffer;
- WORD ODFAR *pSource = (WORD ODFAR *)pScrnBuffer
- + ((((--btTop) + btTopBoundary)
- * OD_SCREEN_WIDTH) + btLeftBoundary + (--btLeft));
- BYTE btCurColumn;
- BYTE btCurLine = (--btBottom) - btTop + 1;
- BYTE btColumnStart = (--btRight) - btLeft + 1;
- BYTE btSkip = OD_SCREEN_WIDTH - btColumnStart;
- ASSERT(btLeft >= 0);
- ASSERT(btTop >= 0);
- ASSERT(btRight <= btRightBoundary - btLeftBoundary);
- ASSERT(btBottom <= btBottomBoundary - btTopBoundary);
- ASSERT(pbtBuffer);
-
- do
- {
- btCurColumn = btColumnStart;
- do
- {
- ASSERT(pSource >= (WORD ODFAR *)pScrnBuffer);
- ASSERT(pSource <= (WORD ODFAR *)pScrnBuffer + 2000);
- ASSERT(pwBuffer >= (WORD *)pbtBuffer);
- ASSERT(pwBuffer <= (WORD *)pbtBuffer + 2000);
- *(pwBuffer++) = *(pSource++);
- } while ((--btCurColumn) != 0);
- pSource += btSkip;
- } while((--btCurLine) != 0);
- return(TRUE);
- }
- BOOL ODScrnPutText(BYTE btLeft, BYTE btTop, BYTE btRight, BYTE btBottom,
- void *pbtBuffer)
- {
- WORD *pwBuffer = (WORD *)pbtBuffer;
- WORD ODFAR *pDest = (WORD ODFAR *)pScrnBuffer
- + ((((--btTop) + btTopBoundary)
- * OD_SCREEN_WIDTH) + btLeftBoundary + (--btLeft));
- BYTE btCurColumn;
- BYTE btCurLine = (--btBottom) - btTop + 1;
- BYTE btColumnStart = (--btRight) - btLeft + 1;
- BYTE btSkip = OD_SCREEN_WIDTH - btColumnStart;
- ASSERT(btLeft >= 0 && btTop >= 0);
- ASSERT(btLeft <= btRightBoundary - btLeftBoundary);
- ASSERT(btTop <= btBottomBoundary - btTopBoundary);
- ASSERT(btRight >= 0 && btBottom >= 0);
- ASSERT(btRight <= btRightBoundary - btLeftBoundary);
- ASSERT(btBottom <= btBottomBoundary - btTopBoundary);
- ASSERT(pbtBuffer != NULL);
-
- do
- {
- btCurColumn = btColumnStart;
- do
- {
- ASSERT(pDest >= (WORD ODFAR *)pScrnBuffer);
- ASSERT(pDest <= (WORD ODFAR *)pScrnBuffer + 2000);
- ASSERT(pwBuffer >= (WORD *)pbtBuffer);
- ASSERT(pwBuffer <= (WORD *)pbtBuffer + 2000);
- *(pDest++) = *(pwBuffer++);
- } while ((--btCurColumn) != 0);
- pDest += btSkip;
- } while((--btCurLine) != 0);
- #ifdef ODPLAT_WIN32
-
- ODScrnInvalidate((BYTE)(btLeftBoundary + btLeft),
- (BYTE)(btTopBoundary + btTop),
- (BYTE)(btRightBoundary + btRight),
- (BYTE)(btBottomBoundary + btBottom));
- #endif
- return(TRUE);
- }
- void ODScrnDisplayString(const char *pszString)
- {
- ODScrnDisplayBuffer(pszString, strlen(pszString));
- }
- void ODScrnDisplayBuffer(const char *pBuffer, INT nCharsToDisplay)
- {
- const char *pchCurrentChar = pBuffer;
- INT nCharsLeft = nCharsToDisplay;
- BYTE ODFAR *pDest;
- BYTE btLeftColumn;
- BYTE btAttribute = btCurrentAttribute;
- BYTE btCurrentColumn;
- BYTE btBottom = btBottomBoundary - btTopBoundary;
- #ifdef ODPLAT_WIN32
- BOOL bAnythingInvalid = FALSE;
- BYTE btLeftMost;
- BYTE btRightMost;
- BYTE btTopMost;
- BYTE btBottomMost;
- #endif
- ASSERT(pBuffer != NULL);
- ASSERT(nCharsToDisplay >= 0);
- ODScrnGetCursorPos();
- if(btCursorColumn > btRightBoundary - btLeftBoundary)
- {
- btCursorColumn = btRightBoundary - btLeftBoundary;
- }
- if(btCursorRow > btBottomBoundary - btTopBoundary)
- {
- btCursorRow = btBottomBoundary - btTopBoundary;
- }
- btCurrentColumn = btCursorColumn;
- btLeftColumn = btRightBoundary - (btCurrentColumn + btLeftBoundary);
- pDest = (BYTE ODFAR *) pScrnBuffer + (((btTopBoundary + btCursorRow)
- * BUFFER_LINE_BYTES)
- + (btLeftBoundary + btCursorColumn) * BYTES_PER_CHAR);
- while(nCharsLeft--)
- {
- ASSERT(pDest >= (BYTE ODFAR *)pScrnBuffer);
- ASSERT(pDest <= (BYTE ODFAR *)pScrnBuffer + SCREEN_BUFFER_SIZE);
- switch(*pchCurrentChar)
- {
- case '\r':
- btCurrentColumn = 0;
- btLeftColumn = btRightBoundary - btLeftBoundary;
- pDest = (BYTE ODFAR *)pScrnBuffer + ((btTopBoundary + btCursorRow)
- * BUFFER_LINE_BYTES + btLeftBoundary * BYTES_PER_CHAR);
- pchCurrentChar++;
- break;
- case '\n':
- if (btCursorRow < btBottom)
- {
- ++btCursorRow;
- pDest += BUFFER_LINE_BYTES;
- }
- else if(bScrollEnabled)
- {
- ODScrnScrollUpOneLine();
- #ifdef ODPLAT_WIN32
-
- bAnythingInvalid = TRUE;
- btLeftMost = btLeftBoundary;
- btRightMost = btRightBoundary;
- btTopMost = btTopBoundary;
- btBottomMost = btBottomBoundary;
- #endif
- }
- pchCurrentChar++;
- break;
- case '\a':
-
- if(!od_control.od_silent_mode)
- {
- #ifdef ODPLAT_DOS
- ASM mov ah, 0x02
- ASM mov dl, 7
- ASM int 0x21
- #endif
- #ifdef ODPLAT_WIN32
- MessageBeep(0xffffffff);
- #endif
- pchCurrentChar++;
- }
- break;
- case '\t':
-
- btCurrentColumn = ((btCurrentColumn / 8) + 1) * 8;
- if(btCurrentColumn > btRightBoundary - btLeftBoundary)
- {
- btCurrentColumn = 0;
-
- if(++btCursorRow > btBottomBoundary - btTopBoundary)
- {
-
- btCursorRow = btBottomBoundary - btTopBoundary;
-
- if(bScrollEnabled)
- {
-
- ODScrnScrollUpOneLine();
- #ifdef ODPLAT_WIN32
-
- bAnythingInvalid = TRUE;
- btLeftMost = btLeftBoundary;
- btRightMost = btRightBoundary;
- btTopMost = btTopBoundary;
- btBottomMost = btBottomBoundary;
- #endif
- }
- }
- }
-
- pDest = (BYTE ODFAR *) pScrnBuffer
- + (((btTopBoundary + btCursorRow) * BUFFER_LINE_BYTES)
- + (btLeftBoundary + btCursorColumn) * BYTES_PER_CHAR);
- break;
- case '\b':
- if(btCurrentColumn > 0)
- {
- --btCurrentColumn;
- pDest-=2;
- btLeftColumn++;
- }
- pchCurrentChar++;
- break;
- default:
- *(pDest++) = *(pchCurrentChar++);
- *(pDest++) = btAttribute;
- #ifdef ODPLAT_WIN32
-
- if(!bAnythingInvalid)
- {
- bAnythingInvalid = TRUE;
- btLeftMost = btLeftBoundary + btCurrentColumn;
- btRightMost = btLeftBoundary + btCurrentColumn;
- btTopMost = btTopBoundary + btCursorRow;
- btBottomMost = btTopBoundary + btCursorRow;
- }
- else
- {
- BYTE btColumn = btLeftBoundary + btCurrentColumn;
- BYTE btRow = btTopBoundary + btCursorRow;
- if(btColumn < btLeftMost) btLeftMost = btColumn;
- if(btColumn > btRightMost) btRightMost = btColumn;
- if(btRow < btTopMost) btTopMost = btRow;
- if(btRow > btBottomMost) btBottomMost = btRow;
- }
- #endif
- if(btLeftColumn--)
- {
- ++btCurrentColumn;
- }
- else
- {
- btCurrentColumn = 0;
- btLeftColumn = btRightBoundary - btLeftBoundary;
- if(btCursorRow < btBottom)
- {
- ++btCursorRow;
- }
- else if(bScrollEnabled)
- {
- ODScrnScrollUpOneLine();
- #ifdef ODPLAT_WIN32
-
- bAnythingInvalid = TRUE;
- btLeftMost = btLeftBoundary;
- btRightMost = btRightBoundary;
- btTopMost = btTopBoundary;
- btBottomMost = btBottomBoundary;
- #endif
- }
- pDest = (BYTE ODFAR *)pScrnBuffer
- + ((btTopBoundary + btCursorRow)
- * BUFFER_LINE_BYTES + btLeftBoundary * BYTES_PER_CHAR);
- }
- }
- }
- btCursorColumn = btCurrentColumn;
- ODScrnUpdateCaretPos();
- #ifdef ODPLAT_WIN32
- if(bAnythingInvalid)
- {
-
- ODScrnInvalidate(btLeftMost, btTopMost, btRightMost,
- btBottomMost);
- }
- #endif
- }
- BOOL ODScrnCopyText(BYTE btLeft, BYTE btTop, BYTE btRight, BYTE btBottom,
- BYTE btDestColumn, BYTE btDestRow)
- {
- void *pScrnBuffer;
- ASSERT(btLeft >= 0 && btTop >= 0);
- ASSERT(btLeft <= btRightBoundary - btLeftBoundary);
- ASSERT(btTop <= btBottomBoundary - btTopBoundary);
- ASSERT(btRight >= 0 && btBottom >= 0);
- ASSERT(btRight <= btRightBoundary - btLeftBoundary);
- ASSERT(btBottom <= btBottomBoundary - btTopBoundary);
- ASSERT(btDestColumn >= 0 && btDestRow >= 0);
- ASSERT(btDestColumn <= btRightBoundary - btLeftBoundary);
- ASSERT(btDestRow <= btBottomBoundary - btTopBoundary);
- if( !(btLeft <= btRightBoundary - btLeftBoundary
- && btTop <= btBottomBoundary - btTopBoundary)
- || !(btRight <= btRightBoundary - btLeftBoundary
- && btBottom <= btBottomBoundary - btTopBoundary)
- || !(btDestColumn <= btRightBoundary - btLeftBoundary
- && btDestRow <= btBottomBoundary - btTopBoundary))
- {
- return(FALSE);
- }
- if((pScrnBuffer = malloc((btRight - btLeft + 1) * (btBottom - btTop + 1)
- * BYTES_PER_CHAR)) == NULL)
- {
-
- return (FALSE);
- }
- ODScrnGetText(btLeft, btTop, btRight, btBottom, pScrnBuffer);
- ODScrnPutText(btDestColumn, btDestRow,
- (BYTE)(btRight + (btDestColumn - btLeft)),
- (BYTE)(btBottom + (btDestRow - btTop)), pScrnBuffer);
- free(pScrnBuffer);
- return(TRUE);
- }
- void ODScrnClearToEndOfLine(void)
- {
- unsigned char btCharsToDelete = btRightBoundary
- - (btLeftBoundary + btCursorColumn);
- BYTE ODFAR *pDest = (BYTE ODFAR *) pScrnBuffer
- + (((btTopBoundary + btCursorRow) * BUFFER_LINE_BYTES)
- + (btLeftBoundary + btCursorColumn) * BYTES_PER_CHAR);
- BYTE btAttribute = btCurrentAttribute;
- while(btCharsToDelete--)
- {
- *(pDest++) = ' ';
- *(pDest++) = btAttribute;
- }
- #ifdef ODPLAT_WIN32
-
- ODScrnInvalidate((BYTE)(btLeftBoundary + btCursorColumn),
- (BYTE)(btTopBoundary + btCursorRow), btRightBoundary,
- (BYTE)(btTopBoundary + btCursorRow));
- #endif
- }
- #ifdef OD_TEXTMODE
- void *ODScrnCreateWindow(BYTE btLeft, BYTE btTop, BYTE btRight,
- BYTE btBottom, BYTE btAttribute, char *pszTitle, BYTE btTitleAttribute)
- {
- void *pUnder;
- INT nBetween;
- INT nCount;
- INT nFirst;
- char *pszString;
- int nTitleWidth;
- ASSERT(pszTitle != NULL);
-
- if((pUnder = malloc((btRight - btLeft + 1) * (btBottom - btTop + 1)
- * BYTES_PER_CHAR + 4 * sizeof(BYTE))) == NULL)
- {
- return(NULL);
- }
-
- ((BYTE *)pUnder)[0] = btLeft;
- ((BYTE *)pUnder)[1] = btTop;
- ((BYTE *)pUnder)[2] = btRight;
- ((BYTE *)pUnder)[3] = btBottom;
-
- ODScrnGetText(btLeft, btTop, btRight, btBottom, ((BYTE *)pUnder) + 4);
-
-
- if(strlen(pszTitle) == 0)
- {
- nTitleWidth = 0;
- }
- else
- {
- nTitleWidth = strlen(pszTitle) + 2;
- }
- nCount = (nBetween = btRight - btLeft - 1) - nTitleWidth;
- nCount -= (nFirst = nCount / 2);
-
- ODScrnSetCursorPos(btLeft, btTop);
- ODScrnSetAttribute(btAttribute);
-
- ODScrnDisplayChar((unsigned char)214);
- while(nFirst--) ODScrnDisplayChar((unsigned char)196);
- if(strlen(pszTitle) != 0)
- {
- ODScrnSetAttribute(btTitleAttribute);
- ODScrnDisplayChar(' ');
- ODScrnDisplayString(pszTitle);
- ODScrnDisplayChar(' ');
- ODScrnSetAttribute(btAttribute);
- }
- while(nCount--) ODScrnDisplayChar((unsigned char)196);
- ODScrnDisplayChar((unsigned char)183);
-
- pszString = szBuffer;
- *pszString++ = (unsigned char)186;
- nCount = nBetween;
- while(nCount--) *pszString++ = ' ';
- *pszString++ = (unsigned char)186;
- *pszString++ = '\0';
-
- for(nCount = btTop + 1; nCount < btBottom; ++nCount)
- {
- ODScrnSetCursorPos(btLeft, (BYTE)nCount);
- ODScrnDisplayString(szBuffer);
- }
-
- ODScrnSetCursorPos(btLeft, btBottom);
- ODScrnDisplayChar((unsigned char)211);
- while(nBetween--) ODScrnDisplayChar((unsigned char)196);
- ODScrnDisplayChar((unsigned char)189);
-
- return(pUnder);
- }
- #endif
- #ifdef OD_TEXTMODE
- void ODScrnDestroyWindow(void *pWindow)
- {
- BYTE btLeft;
- BYTE btTop;
- BYTE btRight;
- BYTE btBottom;
- BYTE *pabtWindow = (BYTE *)pWindow;
- ASSERT(pWindow != NULL);
-
- btLeft = pabtWindow[0];
- btTop = pabtWindow[1];
- btRight = pabtWindow[2];
- btBottom = pabtWindow[3];
-
- ODScrnPutText(btLeft, btTop, btRight, btBottom, ((BYTE *)pWindow) + 4);
-
- free(pWindow);
- }
- #endif
- #ifdef OD_TEXTMODE
- void ODScrnLocalInput(BYTE btLeft, BYTE btRow, char *pszString,
- BYTE btMaxChars)
- {
- BYTE btCount;
- BYTE btCurrentPos;
- BOOL bAnyKeysPressed = FALSE;
- tODInputEvent InputEvent;
-
- ODScrnSetCursorPos(btLeft, btRow);
- ODScrnDisplayString(pszString);
- for(btCount = strlen(pszString); btCount <= btMaxChars; ++btCount)
- {
- ODScrnDisplayChar(177);
- }
-
- btCurrentPos = strlen(pszString);
-
- for(;;)
- {
-
- ODScrnSetCursorPos((BYTE)(btLeft + btCurrentPos), btRow);
-
- ODInQueueGetNextEvent(hODInputQueue, &InputEvent, OD_NO_TIMEOUT);
- switch(InputEvent.chKeyPress)
- {
- case '\b':
-
-
- if(btCurrentPos > 0)
- {
-
- btCurrentPos--;
- ODScrnSetCursorPos((BYTE)(btLeft + btCurrentPos), btRow);
- ODScrnDisplayChar(177);
- pszString[btCurrentPos] = '\0';
- }
- break;
- case '\n':
- case '\r':
-
- return;
- case '\0':
-
-
- ODInQueueGetNextEvent(hODInputQueue, &InputEvent, OD_NO_TIMEOUT);
- break;
- default:
-
- if(InputEvent.chKeyPress >= ' ')
- {
-
-
- if(!bAnyKeysPressed)
- {
- btCurrentPos = 0;
- ODScrnSetCursorPos(btLeft, btRow);
- for(btCount = 0; btCount <= btMaxChars; ++btCount)
- {
- ODScrnDisplayChar(177);
- }
- ODScrnSetCursorPos(btLeft, btRow);
- }
-
-
- if(btCurrentPos < btMaxChars)
- {
-
- ODScrnDisplayChar(InputEvent.chKeyPress);
-
- pszString[btCurrentPos] = InputEvent.chKeyPress;
-
- ++btCurrentPos;
-
- pszString[btCurrentPos] = '\0';
- }
- }
- }
-
- bAnyKeysPressed = TRUE;
- }
- }
- #endif
- void *ODScrnShowMessage(char *pszText, int nFlags)
- {
- ASSERT(pszText != NULL);
- ASSERT(nFlags == 0);
-
- if(od_control.od_silent_mode) return(NULL);
- #ifdef ODPLAT_WIN32
-
-
- PostMessage(GetParent(hwndScreenWindow), WM_SHOW_MESSAGE, (WPARAM)nFlags,
- (LPARAM)pszText);
- return(NULL);
- #else
- {
- int nWindowWidth;
- int nLeftColumn;
- char szMessage[74];
- void *pWindow;
- UNUSED(nFlags);
- ODStringCopy(szMessage, pszText, sizeof(szMessage));
- ODStoreTextInfo();
- nWindowWidth = strlen(szMessage) + 4;
- nLeftColumn = 40 - (nWindowWidth / 2);
- if((pWindow = ODScrnCreateWindow((BYTE)nLeftColumn, 10,
- (BYTE)(nLeftColumn + (nWindowWidth - 1)), 14,
- od_control.od_local_win_col, "", od_control.od_local_win_col))
- == NULL)
- {
- return(NULL);
- }
- ODScrnSetCursorPos((BYTE)(42 - (nWindowWidth / 2)), 12);
- ODScrnDisplayString(szMessage);
- ODRestoreTextInfo();
- ODScrnEnableCaret(FALSE);
- return(pWindow);
- }
- #endif
- }
- void ODScrnRemoveMessage(void *pMessageInfo)
- {
-
- if(od_control.od_silent_mode) return;
- #ifdef ODPLAT_WIN32
-
-
- SendMessage(GetParent(hwndScreenWindow), WM_REMOVE_MESSAGE, 0, 0L);
- #else
-
- if(pMessageInfo == NULL) return;
- ODStoreTextInfo();
- ODScrnDestroyWindow(pMessageInfo);
- ODRestoreTextInfo();
- ODScrnEnableCaret(TRUE);
- #endif
- }
|