home *** CD-ROM | disk | FTP | other *** search
/ Games 1995 to 2000 / Games.iso / SexTetris / IBMPC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-16  |  18.5 KB  |  465 lines

  1. #include "microlib.h" // for pre-compiled headers only
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5. #include "ibmpc.h"
  6.  
  7. extern VIDEOSTATUS vs;
  8.  
  9. void _movmem(PSTR t, PSTR s, int len)
  10. {
  11.     int i;
  12.  
  13.     for (i = 0; i < len; i++)
  14.         t[i] = s[i];
  15. }
  16.  
  17. /* ────────┬────────────────────────────────────────────────────────────────┐
  18. │ FUNCTION │ _kbdhit()                                                      │
  19. │          │    This function reads a character from the keyboard--if one   │
  20. │          │    is ready--using interrupt 0x21. If a character is not ready,│
  21. │          │    the function returns zero. Characters are not echoed to the │
  22. │          │    screen. ASCII and extended characters are returned.         │
  23. │          │    NOTE: This version is used if intdos() does not return the  │
  24. │          │          flag register.                                        │
  25. ├──────────┼────────────────────────────────────────────────────────────────┤
  26. │ ENTRY    │ void                                                           │
  27. ├──────────┼────────────────────────────────────────────────────────────────┤
  28. │ EXIT     │ int    key code                                                │
  29. ├──────────┼────────────────────────────────────────────────────────────────┤
  30. │ DLU      │ 05-10-92                                                       │
  31. └──────────┴────────────────────────────────────────────────────────────── */
  32. int _kbdhit(void)
  33. {
  34.     unsigned c,
  35.              flag;
  36.  
  37.     _asm    mov     c,00h
  38.     _asm    mov     flag,00h
  39. loop1:
  40.     _asm    mov     dl,0FFh                     /* input requested      */
  41.     _asm    mov     ah,06h                      /* direct console I/O   */
  42.     _asm    int     21h
  43.     _asm    jz      clear                       /* no character ready   */
  44.     _asm    or      al,al
  45.     _asm    jne     good                        /* a character is ready */
  46. // read an extended code key
  47.     _asm    mov     dl,0FFh
  48.     _asm    mov     ah,06h
  49.     _asm    int     21h
  50.     _asm    mov     ah,al
  51.     _asm    xor     al,al
  52.     _asm    mov     flag,ax
  53.     return  (flag);
  54.  
  55. clear:
  56.     _asm    mov     al,00h
  57. good:
  58.     _asm    mov     BYTE PTR c, al
  59.  
  60. okkbd:
  61.     return (int) (c + flag);
  62. }
  63.  
  64. void at_say(int col, int row, unsigned char *string, unsigned char attr)
  65. {
  66.     int  offset = (row*80 + col) * 2;
  67.     int  x1, y1;
  68.  
  69.     //mouHideCur();
  70.     switch (vs.crtmode) {
  71.         case VMODE_3 :
  72.         case VMODE_7 :
  73.             while (*string) {
  74.                 *(vs.segment+offset) = *string++;
  75.                 *(vs.segment+offset+1) = attr;
  76.                 offset += 2;
  77.             }
  78.             break;
  79.         //case VMODE_16 :
  80.         //case VMODE_18 :
  81.         //    #ifdef _TXT_COORDS_
  82.         //        x1 = col << 3;
  83.         //        y1 = row << 4;
  84.         //    #else
  85.         //        x1 = col;
  86.         //        y1 = row;
  87.         //    #endif
  88.         //    rectfill(x1, y1, x1 + (strlen(string) << 3), y1+14, BG(attr));
  89.         //    while (*string) {
  90.         //        llettr(x1, y1, *string, FG(attr));
  91.         //        x1 += 8;
  92.         //        string++;
  93.         //    }
  94.         //  //_drawString(x1, y1, *string, FG(attr), _CURRENT_FONT_);
  95.         //  break;
  96.         default :
  97.             break;
  98.     }
  99.     //mouShowCur();
  100. }
  101.  
  102. PSTR LJ(PSTR LStr, PSTR Buffer, int FWdth)
  103. {
  104.     int T, LS;
  105.  
  106.     for (LS = 0; LStr[LS]; LS++);
  107.  
  108.     if (LS <= FWdth) {
  109.         FWdth--;
  110.         for (T = 0; LStr[T]; T++)
  111.             Buffer[T] = LStr[T];
  112.         for (; T <= FWdth; T++)
  113.             Buffer[T] = ' ';
  114.         Buffer[T] = 0;
  115.     }
  116.     else {
  117.         FWdth--;
  118.         for (T = 0; T <= FWdth; T++)
  119.         Buffer[T] = LStr[T];
  120.         Buffer[T] = 0;
  121.     }
  122.     return (Buffer);
  123. }
  124.  
  125. PSTR RJ(PSTR RStr, PSTR Buffer, int FieldWidth)
  126. {
  127.     int T, T1, LR;
  128.  
  129.     for (LR = 0; RStr[LR]; LR++);
  130.  
  131.     if (LR <= FieldWidth) {
  132.         T1 = FieldWidth - LR - 1;
  133.         for (T = 0; T <= T1; T++)
  134.             Buffer[T] = ' ';
  135.         for (T1 = 0, FieldWidth--; T <= FieldWidth; T++, T1++)
  136.             Buffer[T] = RStr[T1];
  137.         Buffer[T] = '\0';
  138.     }/* if LR */
  139.     else {
  140.         Buffer[FieldWidth] = '\0';
  141.         for(FieldWidth--, LR-- ; FieldWidth >= 0; FieldWidth--, LR--)
  142.             Buffer[FieldWidth] = RStr[LR];
  143.     }/* if LR else */
  144.     return (Buffer);
  145. }
  146.  
  147. PSTR Replace(PSTR Src, PSTR Target, int Position)
  148. {
  149.     int T, LT;
  150.     for (LT = 0; Target[LT]; LT++);
  151.     if (Position <= LT) {
  152.         Position--;
  153.         for (T = 0; Src[T]; T++, Position++)
  154.             Target[Position] = Src[T];
  155.         LT--;
  156.         if(Position>LT)
  157.         Target[Position] = '\0';
  158.     }
  159.     else {
  160.         Position--;
  161.         for (; LT < Position; LT++)
  162.         Target[LT] = ' ';
  163.         for (T = 0; Src[T]; Position++, T++)
  164.             Target[Position] = Src[T];
  165.         Target[Position] = '\0';
  166.     }
  167.     return(Target);
  168. }
  169.  
  170. void vioInit(void)
  171. {
  172.     char far *vptr = (char far *) 0x00400049;
  173.     int  vmode = *vptr;
  174.  
  175.     switch (vmode) {
  176.  
  177.         case VMODE_3 :
  178.             vs.screenwide = 80;
  179.             vs.screendeep = 24;
  180.             vs.txtcols = 80;
  181.             vs.txtrows = 24;
  182.             vs.crtmode = 0x03;
  183.             vs.crtpage = 0x00;
  184.             vs.segment = (char *) 0xb8000000;
  185.             break;
  186.  
  187.         case VMODE_7 :
  188.             vs.screenwide = 80;
  189.             vs.screendeep = 24;
  190.             vs.txtcols = 80;
  191.             vs.txtrows = 24;
  192.             vs.crtmode = 0x07;
  193.             vs.crtpage = 0x00;
  194.             vs.segment = (char *) 0xb0000000;
  195.             break;
  196.  
  197.         case VMODE_16 :
  198.             vs.screenwide = 640;
  199.             vs.screendeep = 350;
  200.             vs.txtcols = 80;
  201.             vs.txtrows = 24;
  202.             vs.crtmode = 0x10;
  203.             vs.crtpage = 0x00;
  204.             vs.segment = (char *) 0xA0000000;
  205.             break;
  206.  
  207.         case VMODE_18 :
  208.             vs.screenwide = 640;
  209.             vs.screendeep = 480;
  210.             vs.txtcols = 80;
  211.             vs.txtrows = 30;
  212.             vs.crtmode = 0x12;
  213.             vs.crtpage = 0x00;
  214.             vs.segment = (char *) 0xA0000000;
  215.             break;
  216.  
  217.         default :
  218.             puts("video mode not supported !!!");
  219.             exit(0);
  220.             break;
  221.     }
  222.  
  223.     vioSetBlinkBit(0);
  224. }
  225.  
  226. /* ────────┬────────────────────────────────────────────────────────────────┐
  227. │ FUNCTION │ vioSetCurType()                                                │
  228. │          │    This function sets the cursor characteristics               │
  229. ├──────────┼────────────────────────────────────────────────────────────────┤
  230. │ ENTRY    │ int start     the starting scan line for the cursor            │
  231. │          │ int end       the ending scan line for the cursor              │
  232. │          │    NOTE :                                                      │
  233. │          │           CH bits 0-4 = start line                             │
  234. │          │           CH bits 5-6 = blink attribute                        │
  235. │          │                         ( 00=normal, 01=invisible              │
  236. │          │                           10=slow,   11=fast )                 │
  237. │          │           CL bits 0-4 = end line                               │
  238. ├──────────┼────────────────────────────────────────────────────────────────┤
  239. │ EXIT     │ void                                                           │
  240. ├──────────┼────────────────────────────────────────────────────────────────┤
  241. │ DLU      │ 30-08-93                                                       │
  242. └──────────┴────────────────────────────────────────────────────────────── */
  243. void vioSetCurType(int start, int end, int attr)
  244. {
  245.     union REGS regs;
  246.  
  247.     regs.h.ah = 0x01;
  248.     regs.h.ch = attr << 4;
  249.     regs.h.ch += start;
  250.     regs.h.cl = end;
  251.     int86(0x10, ®s, ®s);
  252. }
  253. /* ────────┬────────────────────────────────────────────────────────────────┐
  254. │ FUNCTION │ vioSetCurPos()                                                 │
  255. │          │    This function places the cursor at row-col as given by the  │
  256. │          │    function arguments.                                         │
  257. │          │    NOTE: For speed reasons, valid row and column numbers are   │
  258. │          │          NOT checked. getvcols() could be used to check valid  │
  259. │          │          columns; rows should not exceed 25. The value 1 is    │
  260. │          │          subtracted from row and column so that the upper left │
  261. │          │          corner.                                               │
  262. ├──────────┼────────────────────────────────────────────────────────────────┤
  263. │ ENTRY    │ int row        the row position for the cursor                 │
  264. │          │ int col        the column position for the cursor              │
  265. ├──────────┼────────────────────────────────────────────────────────────────┤
  266. │ EXIT     │ void                                                           │
  267. ├──────────┼────────────────────────────────────────────────────────────────┤
  268. │ DLU       │ 10-05-92                                                       │
  269. └──────────┴────────────────────────────────────────────────────────────── */
  270. void vioSetCurPos(int row, int col)
  271. {
  272.     union REGS regs;
  273.  
  274.     regs.h.ah = 0x02;
  275.     regs.h.bh = vioGetPage();
  276.     regs.h.dh = row - 1;
  277.     regs.h.dl = col - 1;
  278.     int86(0x10, ®s, ®s);
  279.  
  280. }
  281. /* ────────┬────────────────────────────────────────────────────────────────┐
  282. │ FUNCTION │ vioGetCurPos()                                                 │
  283. │          │    This function finds the current row and column position of  │
  284. │          │    the cursor, and fills in the two pointers with the approp   │         │    values. The value of 1 is added to agree with a home        │
  285. │          │    position of 1,1 rather than 0,0.                            │
  286. ├──────────┼────────────────────────────────────────────────────────────────┤
  287. │ ENTRY    │ int *row       the row position for the cursor                 │
  288. │          │ int *col       the column position for the cursor              │
  289. ├──────────┼────────────────────────────────────────────────────────────────┤
  290. │ EXIT     │ void                                                           │
  291. ├──────────┼────────────────────────────────────────────────────────────────┤
  292. │ DLU       │ 10-05-92                                                       │
  293. └──────────┴────────────────────────────────────────────────────────────── */
  294. void vioGetCurPos(int *row, int *col)
  295. {
  296.     union REGS regs;
  297.  
  298.     regs.h.ah = 0x03;
  299.     regs.h.bh = vioGetPage();
  300.     int86(0x10, ®s, ®s);
  301.  
  302.     *row   = (int) regs.h.dh + 1;
  303.     *col   = (int) regs.h.dl + 1;
  304. }
  305. /* ────────┬────────────────────────────────────────────────────────────────┐
  306. │ FUNCTION │ vioGetCurType()                                                │
  307. │          │    This function retrieves the cursor type                     │
  308. ├──────────┼────────────────────────────────────────────────────────────────┤
  309. │ ENTRY    │ int *start     the starting scan line for the cursor           │
  310. │          │ int *end       the ending scan line for the cursor             │
  311. ├──────────┼────────────────────────────────────────────────────────────────┤
  312. │ EXIT     │ void                                                           │
  313. ├──────────┼────────────────────────────────────────────────────────────────┤
  314. │ DLU       │ 10-05-92                                                       │
  315. └──────────┴────────────────────────────────────────────────────────────── */
  316. void vioGetCurType(int *start, int *end)
  317. {
  318.     union REGS regs;
  319.  
  320.     regs.h.ah = 0x03;
  321.     regs.h.bh = vioGetPage();
  322.     int86(0x10, ®s, ®s);
  323.  
  324.     *start = (int) regs.h.ch;
  325.     *end   = (int) regs.h.cl;
  326. }
  327. /* ────────┬────────────────────────────────────────────────────────────────┐
  328. │ FUNCTION │ vioSetPage()                                                   │
  329. │          │    This function set the active page for the video display     │
  330. ├──────────┼────────────────────────────────────────────────────────────────┤
  331. │ ENTRY    │ int page       the page number                                 │
  332. ├──────────┼────────────────────────────────────────────────────────────────┤
  333. │ EXIT     │ void                                                           │
  334. ├──────────┼────────────────────────────────────────────────────────────────┤
  335. │ DLU      │ 18-08-92                                                       │
  336. └──────────┴────────────────────────────────────────────────────────────── */
  337. void vioSetPage(int page)
  338. {
  339.     union REGS regs;
  340.  
  341.     regs.h.ah = 0x05;
  342.     regs.h.al = page;
  343.     int86(0x10, ®s, ®s);
  344. }
  345. /* ────────┬────────────────────────────────────────────────────────────────┐
  346. │ FUNCTION │ vioScroll()                                                    │
  347. │          │    This function scrolls the screen via BIOS.                  │
  348. │          │    The value of the variable-named function may be either      │
  349. │          │    0x06 for an upward scroll or 0x07 for a downward scroll.    │
  350. │          │    The arguments determine how many columns currently are in   │
  351. │          │    use on the screen.                                          │
  352. ├──────────┼────────────────────────────────────────────────────────────────┤
  353. │ ENTRY    │  int row       the row position for the window                 │
  354. │          │  int col       the column position for the window              │
  355. │          │  int wide      the width of the window                         │
  356. │          │  int deep      the depth of the window                         │
  357. │          │  int lines     the number of lines to scroll within            │
  358. │          │                       the window (all are scrolled if 0)       │
  359. │          │  int function  0x07 for up scroll, 0x06 for down               │
  360. │          │  int attr      attribute to be used                            │
  361. ├──────────┼────────────────────────────────────────────────────────────────┤
  362. │ EXIT     │ void                                                           │
  363. ├──────────┼────────────────────────────────────────────────────────────────┤
  364. │ DLU       │ 10-05-92                                                       │
  365. └──────────┴────────────────────────────────────────────────────────────── */
  366. void vioScroll(int row, int col, int wide, int deep, int lines, int function, int attr)
  367. {
  368.     union REGS regs;
  369.  
  370.     //row--;
  371.     //col--;
  372.     regs.h.ah = function;
  373.     regs.h.al = lines;
  374.     regs.h.ch = row;
  375.     regs.h.cl = col;
  376.     regs.h.dh = row + deep - 1;
  377.     regs.h.dl = col + wide;
  378.     regs.h.bh = attr;
  379.     int86(0x10, ®s, ®s);
  380. }
  381. /* ────────┬────────────────────────────────────────────────────────────────┐
  382. │ FUNCTION │ vioGetPage()                                                   │
  383. │          │    This function gets the active video page.                   │
  384. ├──────────┼────────────────────────────────────────────────────────────────┤
  385. │ ENTRY    │ void                                                           │
  386. ├──────────┼────────────────────────────────────────────────────────────────┤
  387. │ EXIT     │ int        the currently active page                           │
  388. ├──────────┼────────────────────────────────────────────────────────────────┤
  389. │ DLU       │ 10-05-92                                                       │
  390. └──────────┴────────────────────────────────────────────────────────────── */
  391. int vioGetPage(void)
  392. {
  393.     union REGS regs;
  394.  
  395.     regs.h.ah = 0x0F;
  396.     int86(0x10, ®s, ®s);
  397.  
  398.     return (regs.h.bh);
  399. }
  400. /* ────────┬────────────────────────────────────────────────────────────────┐
  401. │ FUNCTION │ vioGetMode()                                                   │
  402. │          │    This function gets the active video mode.                   │
  403. ├──────────┼────────────────────────────────────────────────────────────────┤
  404. │ ENTRY    │ void                                                           │
  405. ├──────────┼────────────────────────────────────────────────────────────────┤
  406. │ EXIT     │ int        the active video mode                               │
  407. ├──────────┼────────────────────────────────────────────────────────────────┤
  408. │ DLU      │ 07-06-92                                                       │
  409. └──────────┴────────────────────────────────────────────────────────────── */
  410. int vioGetMode(void)
  411. {
  412.     union REGS regs;
  413.  
  414.     regs.h.ah = 0x0F;          /* Function 0x0f gets video mode */
  415.     int86(0x10, ®s, ®s);
  416.  
  417.     return (regs.h.al);
  418. }
  419. /* ────────┬────────────────────────────────────────────────────────────────┐
  420. │ FUNCTION │ vioGetCols()                                                   │
  421. │          │    This function returns the columns used by the active display│
  422. ├──────────┼────────────────────────────────────────────────────────────────┤
  423. │ ENTRY    │ void                                                           │
  424. ├──────────┼────────────────────────────────────────────────────────────────┤
  425. │ EXIT     │ int        the number of columns                               │
  426. ├──────────┼────────────────────────────────────────────────────────────────┤
  427. │ DLU      │ 07-06-92                                                       │
  428. └──────────┴────────────────────────────────────────────────────────────── */
  429. int vioGetCols(void)
  430. {
  431.     union REGS regs;
  432.  
  433.     regs.h.ah = 0x0F;
  434.  
  435.     int86(0x10, ®s, ®s);
  436.     if (regs.h.al < 2)
  437.         return 40;              /* 40-column mode */
  438.  
  439.     if (regs.h.al > 3 && regs.h.al != 7)
  440.         return 0;               /* Return 0 for any graphics mode */
  441.     else
  442.         return 80;              /* 80-column mode */
  443. }
  444.  
  445. /* ────────┬────────────────────────────────────────────────────────────────┐
  446. │ FUNCTION │ vioSetBlinkBit()                                               │
  447. │          │    This function enables/disables the blink/intensity bit      │
  448. │          │    1 : enable Blink bit                                        │
  449. │          │    0 : enable Intensity bit                                    │
  450. ├──────────┼────────────────────────────────────────────────────────────────┤
  451. │ ENTRY    │ int        the intensity flag (ON/OFF)                         │
  452. ├──────────┼────────────────────────────────────────────────────────────────┤
  453. │ EXIT     │ void                                                           │
  454. ├──────────┼────────────────────────────────────────────────────────────────┤
  455. │ DLU      │ 11-11-92                                                       │
  456. └──────────┴────────────────────────────────────────────────────────────── */
  457. void vioSetBlinkBit(char flag)
  458. {
  459.     union REGS regs;
  460.  
  461.     regs.x.ax = 0x1003;
  462.     regs.h.bl = flag;
  463.     int86(0x10, ®s, ®s);
  464. }
  465.