_PORTING D-FLAT++ TO OS/2_ by Jon Wright Listing One // ------------- cursor.h -- modified for OS/2 operation - jw21sep93 #ifndef CURSOR_H #define CURSOR_H #define INCL_BASE #define INCL_NOPMAPI #include const int MAXSAVES = 50; // depth of cursor save/restore stack class Cursor { VIOCURSORINFO ci; // --- cursor save/restore stack int cursorpos[MAXSAVES]; int cursorshape[MAXSAVES]; int cs; // count of cursor saves in effect void Cursor::GetCursor(); public: Cursor(); ~Cursor(); void SetPosition(int x, int y); void GetPosition(int &x, int &y); void SetType(unsigned t); void NormalCursor() { SetType(0x0607); } void BoxCursor() { SetType(0x0107); } void Hide(); void Show(); void Save(); void Restore(); void SwapStack(); }; inline void swap(int& a, int& b) { int x = a; a = b; b = x; } #endif Listing Two // ------------ cursor.cpp -- modified for OS/2 operation - jw13nov93 #include #include "cursor.h" #include "desktop.h" Cursor::Cursor() { VioGetCurType(&ci, 0); cs = 0; Save(); } Cursor::~Cursor() { Restore(); } // ------ get cursor shape and position void Cursor::GetCursor(){}; // -------- get the current cursor position void Cursor::GetPosition(int &x, int &y) { USHORT sx, sy; VioGetCurPos(&sy, &sx, 0); x = sx; y = sy; } // ------ position the cursor void Cursor::SetPosition(int x, int y) { VioSetCurPos((USHORT)y, (USHORT)x, 0); } // ------ save the current cursor configuration void Cursor::Save() { USHORT x, y; if (cs < MAXSAVES) { VioGetCurPos(&y, &x, 0); cursorpos[cs] = (x<<8) | y; VioGetCurType(&ci, 0); cursorshape[cs] = (ci.yStart << 8) | ci.cEnd; cs++; } } // ---- restore the saved cursor configuration void Cursor::Restore() { USHORT row = (USHORT)(cursorpos[cs] & 0xff); USHORT col = (USHORT)((cursorpos[cs] >> 8) & 0xff); if (cs) { --cs; VioSetCurPos(row, col, 0); SetType(cursorshape[cs]); } } /* ---- set the cursor type ---- */ void Cursor::SetType(unsigned t) { ci.yStart = (USHORT)((t >> 8) & 0xff); ci.cEnd = (USHORT)(t & 0xff); VioSetCurType(&ci, 0); } /* ----- swap the cursor stack ------- */ void Cursor::SwapStack() { if (cs > 1) { swap(cursorpos[cs-2], cursorpos[cs-1]); swap(cursorshape[cs-2], cursorshape[cs-1]); } } /* ------ hide the cursor ------ */ void Cursor::Hide() { USHORT t; t = ci.attr; ci.attr = 0xffff; VioSetCurType(&ci, 0); ci.attr = t; } /* ------ show the cursor ------ */ void Cursor::Show() { VioSetCurType(&ci, 0); } Listing Three // --------- speaker.h #ifndef SPEAKER_H #define SPEAKER_H #define INCL_BASE #include class Speaker { public: void Beep(); }; #endif Listing Four // -------- speaker.cpp -- modified for OS/2 operation - jw21sep93 #include "speaker.h" #include "dflatdef.h" void Speaker::Beep() { DosBeep(1000, 250); } Listing FIve // ----------- dtimer.h -- modified for OS/2 operation - jw21sep93 // uses OS/2 Timer services rather than doing own timer management. // renamed to avoid collision with Borlands Timer.h #ifndef TIMER_H #define TIMER_H #define INCL_BASE #define INCL_DOSDATETIME #define INCL_NOPMAPI #include #include "dflatdef.h" class Timer { HEV sem; HTIMER timer; APIRET rc; Bool disabled; public: Timer(); ~Timer(); Bool TimedOut(); void SetTimer(int ticks); void DisableTimer(); Bool TimerRunning(); void Countdown() { ; } Bool TimerDisabled() { return disabled; } }; #endif Listing Six // -------- dtimer.cpp -- OS/2 Version created to use the OS/2 Timer Services // jw21sep93 -- renamed from 'timer.cpp' to match header #include #include "dtimer.h" Timer::Timer() { // create semaphore ULONG SemAttr = DC_SEM_SHARED; // needs to be shared disabled = True; // start in disabled state timer = 0; rc = DosCreateEventSem(NULL, &sem, SemAttr, 1); if(rc != NO_ERROR) { printf("DosCreateEventSem failed: rc = %d\n",rc); } } Timer::~Timer() { rc = DosStopTimer(timer); rc = DosCloseEventSem(sem); } void Timer::SetTimer(int ticks) { ULONG ct; disabled = False; if (timer) { rc = DosStopTimer(timer); } rc = DosResetEventSem(sem, &ct); if(rc != NO_ERROR && rc != ERROR_ALREADY_RESET) { printf("DosResetEventSem failed: rc = %d\n",rc); } rc = DosAsyncTimer(ticks*18, (HSEM)sem, &timer); if(rc != NO_ERROR) { printf("DosAsyncTimer failed: rc = %d\n",rc); } } void Timer::DisableTimer() { disabled = True; } Bool Timer::TimedOut() { ULONG ct = 0L; if (disabled == False) { rc = DosQueryEventSem(sem, &ct); if(rc != NO_ERROR) { printf("DosQueryEventSem failed: rc = %d\n",rc); } } return (Bool) (ct != 0L); } Bool Timer::TimerRunning() { ULONG ct; if (disabled == False) { rc = DosQueryEventSem(sem, &ct); if(rc != NO_ERROR) { printf("DosQueryEventSem failed: rc = %d\n",rc); } return (Bool) (ct == 0L); } return(False); }