home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / SB386 / KABOOM2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-11  |  1.9 KB  |  100 lines

  1. /* Video services for kaboom */
  2.  
  3. #include "stdio.h"
  4. #include "stdarg.h"
  5. #include "stdlib.h"
  6. #include "dos.h"
  7. #include "conio.h"
  8. #include "string.h"
  9. #include "kaboom2.h"
  10.  
  11. #define SCREEN_X 80
  12. #define SCREEN_Y 25
  13. #define GRID_X 15
  14. #define GRID_Y  9
  15. #define TRUE 1
  16. #define FALSE 0
  17.  
  18. void Pause(void)
  19. {
  20.     if (_getch() == 0) _getch();
  21. }
  22.  
  23. void GetXY_(int *pX, int *pY)
  24. {
  25.     union REGS regs;
  26.     regs.h.ah = 3;
  27.     regs.h.bh = 0;                          /* display page 0 */
  28.     _int86(0x10, ®s, ®s);
  29.     if (pY != NULL) {
  30.         (*pY) = regs.h.dh;
  31.     }
  32.     if (pX != NULL) {
  33.         (*pX) = regs.h.dl;
  34.     }
  35. }
  36. void GotoXY_(int x, int y)
  37. {
  38.     union REGS regs;
  39.     regs.h.ah = 2;
  40.     regs.h.dh = (unsigned char)y;
  41.     regs.h.dl = (unsigned char)x;
  42.     regs.h.bh = 0;                           /* display page 0 */
  43.     _int86(0x10, ®s, ®s);
  44. }
  45. int nRandom(int nMax)
  46. {
  47.     static int maxint = 0x7FFFFFFF;
  48.  
  49.     return (int)(((double)rand() / (double)maxint) * (double)nMax);
  50. }
  51.  
  52.  
  53. /* Build a far pointer from components */
  54. char _far *build_farptr(sel, off)
  55.  int sel, off;
  56. {
  57.     union {
  58.         char _far *fp;
  59.         struct {
  60.             long off;
  61.             short sel;
  62.         } s;
  63.     } u;
  64.  
  65.     u.s.sel = sel;
  66.     u.s.off = off;
  67.     return u.fp;
  68. }
  69.  
  70. void DisplayChar(int x, int y, char cChar, int nColor)
  71. {
  72.     char _far *cPos;
  73.     static unsigned short scr_sel = 0x001C;
  74.  
  75.     if ((x>=0 && x<SCREEN_X) &&
  76.         (y>=0 && y<SCREEN_Y)) {
  77.         cPos = build_farptr(scr_sel, (x+y*80)<<1);
  78.         *cPos = cChar;
  79.         *(cPos+1) = (char)nColor;
  80.     }
  81. }
  82.  
  83. void Initialize(void)
  84. {
  85.         extern initrand;
  86.     unsigned int     nRand;     /* seed for random number generator */
  87.     struct dostime_t sDosTime;    /* time structure; used for above seed     */
  88.  
  89.     if(initrand) {
  90.         srand(initrand);
  91.         return;
  92.     }
  93.  
  94.     _dos_gettime(&sDosTime);
  95.     nRand = (unsigned int)((sDosTime.hsecond * 600) +
  96.         (sDosTime.second * 10) +
  97.         (sDosTime.minute / 6));
  98.     srand(nRand);
  99. }
  100.