home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / OEMLAYER.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.9 KB  |  79 lines

  1. /*
  2.     OEMLAYER.C -- Character mode Windows using the OEM Layer?
  3.  
  4.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  5.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  6.  
  7.     Build using: WINIOBC OEMLAYER (for Borland C++ v3.00)
  8.                  WINIOMS OEMLAYER (for Microsoft C/SDK)
  9. */
  10.  
  11. #include <windows.h> 
  12. #include <dos.h>
  13. #include "winio.h" 
  14.  
  15. /* undocumented functions */ 
  16. extern void FAR PASCAL EnableOEMLayer(void);
  17. extern void FAR PASCAL DisableOEMLayer(void);
  18.  
  19. #include "checkord.c"
  20.  
  21. #ifndef __BORLANDC__
  22. #define MK_FP(a,b)  ((void far *)(((unsigned long)(a) << 16) | (b)))
  23. #endif
  24.  
  25. void b800display(char *szDisplay)
  26.     {
  27.     unsigned lineofs = 0, charofs = 0, scrsel;
  28.  
  29.     printf("Screen Selector is %04x\n", 
  30.     scrsel = LOWORD((DWORD)
  31.             GetProcAddress(GetModuleHandle("KERNEL"), "__B800h")));
  32.     
  33.     for (; *szDisplay; szDisplay++)
  34.         switch (*szDisplay) {
  35.             case '\r' : charofs = 0; break;
  36.             case '\n' : lineofs += 160; break;
  37.             default :
  38.                 *(WORD FAR *) MK_FP(scrsel, lineofs+charofs) =
  39.                             0xe00 | *szDisplay;
  40.                 charofs += 2;
  41.             }
  42.     }
  43.  
  44.  
  45. int main() 
  46.     {
  47.     // Ord/name check
  48.     if (! (CheckOrdName("EnableOEMLayer", "USER", 3)) &&
  49.             (CheckOrdName("DisableOEMLayer", "USER", 4)))
  50.         return 0;
  51.  
  52.     winio_about("OEMLAYER"
  53.         "\nUses DisableOEMLayer/EnableOEMLayer to temporarily"
  54.         "\nenter text mode while still in Windows"
  55.         "\n\nFrom Chapter 6 of"
  56.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  57.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  58.         );
  59.     
  60.     DisableOEMLayer();
  61.     b800display("\n"
  62.         "The OEM layer has been disabled, and normal Windows\r\n"
  63.         "keyboard and display handling have been suspended.\r\n"
  64.         "Direct writes to b800:0 are being used to display this,\r\n"
  65.         "and a call to Int 16h will be used to get your keystroke.\r\n"
  66.         "\r\n"
  67.         "Press a key to return");
  68.     
  69.     _asm {
  70.         mov ah, 0
  71.         int 16h
  72.         }
  73.     
  74.     EnableOEMLayer();
  75.     
  76.     printf("\n\nProgram terminated");
  77.     return 0;
  78.     }
  79.