home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / pktsend.zip / 8086.H next >
C/C++ Source or Header  |  1995-02-24  |  7KB  |  257 lines

  1. /*  8086.H
  2.  
  3.     Author:      Patrick Whittle
  4.     Date:        July, 1994
  5.  
  6.     Revisions:   October 3, 1994
  7.                  February 24, 1995
  8.  
  9.     Various 8086 CPU assembler calls, including mouse calls (int 33h),
  10.     DOS int 21h calls, and direct video functions are included in this
  11.     file.  Borland's inline assembly is used in some functions.
  12.  
  13. */
  14.  
  15. #if !defined( __DOS_H )
  16. #include <dos.h>                   /* int86 uses this file */
  17. #endif
  18. #if !defined( __STDARG_H )
  19. #include <stdarg.h>
  20. #endif
  21. #if !defined(__CONIO_H)
  22. #include <conio.h>
  23. #endif
  24. #if !defined(__STRING_H)
  25. #include <string.h>
  26. #endif
  27.  
  28. #define VIDEO          0x10
  29. #define DOSCALL        0x21
  30. #define GETVEC         0x35  /* Get interrupt vector function of int 21h */
  31. #define PRINTCHR       0x2
  32. #define MOUSE          0x33
  33. #define RESET          0x21
  34. #define SHOW           0x1
  35. #define HIDE           0x2
  36. #define MOUSEPOS       0x4
  37. #define PRESS          0x5
  38. #define RELEASE        0x6
  39. #define MONO           0xB000
  40. #define COLOUR         0xB800
  41. #if !defined(TRUE)
  42. #define TRUE           -1
  43. #endif
  44. #if !defined(FALSE)
  45. #define FALSE          0
  46. #endif
  47.  
  48. /* Function prototypes are next */
  49. int videoAddress(void);
  50. int scanvector(char *str, int segval, int offval);
  51.  
  52. /***************************************************************************
  53. Function  : sendpkt
  54. Parameters: Input is a pointer to the string to be sent on the ethernet
  55. Returns   : A TRUE or FALSE condition for success or failure is returned
  56.  
  57. ***************************************************************************/
  58. int sendpkt(char *packet, int len, int intno) {
  59.  
  60.     int stat = TRUE;
  61.     union REGS regs;
  62.  
  63.     regs.h.ah = 4;
  64.     regs.x.cx = len;
  65.     regs.x.si = (int)packet;
  66.  
  67.     int86(intno, ®s, ®s);
  68.  
  69.     if(regs.x.cflag)    /* If there's an error sending, return FALSE.  */
  70.     stat = FALSE;
  71.  
  72.     return(stat);
  73. }
  74. /***************************************************************************
  75. Function  : drvrchk
  76. Parameters: No input required
  77. Returns   : A TRUE or FALSE condition
  78.  
  79.       This function will search for the first available interrupt between
  80.       between 0x60 and 0x80 and stop after first is found.  If no packet
  81.       driver is found in memory, drvrchk returns a FALSE condition.  If
  82.       a driver is found, drvrchk returns the interrupt it is using.
  83.  
  84. ***************************************************************************/
  85. int drvrchk(void) {
  86.  
  87.     int flag = FALSE, segment, offptr, intnum;
  88.     char *pktstr = "PKT DRVR";
  89.  
  90.     asm    push   es      /* current interrupt handler returned in es:bx */
  91.     asm    push   bx
  92.  
  93.     for(intnum = 0x60; intnum <= 0x80; intnum++) {
  94.     asm {
  95.         mov    ah, GETVEC
  96.         mov    al, BYTE PTR intnum      /* get interupt vector */
  97.         int    DOSCALL
  98.         mov    WORD PTR segment, es
  99.         mov    WORD PTR offptr, bx
  100.     }
  101.     offptr += 3;                        /* move 3 bytes into segment */
  102.  
  103.     flag = scanvector(pktstr, segment, offptr);
  104.  
  105.     if(flag) {          /* If TRUE condition resulted - driver found. */
  106.         flag = intnum;  /* flag is returned to be used as int number */
  107.         intnum = 0x81;  /* We want to exit loop now */
  108.     }
  109.     }
  110.     asm pop    bx
  111.     asm pop    es
  112.  
  113.     return(flag);
  114. }
  115. /***************************************************************************
  116. Function  : scanvector
  117. Parameters: assumes ES segment as the destination for compare
  118. Returns   : TRUE or FALSE condition
  119.  
  120. ***************************************************************************/
  121. int scanvector(char *str, int destseg, int offval) {
  122.  
  123.     int f = TRUE, strl;
  124.     strl = strlen(str);
  125.  
  126.     asm push   es
  127.     asm mov    es, WORD PTR destseg
  128.     asm mov    si, WORD PTR str
  129.     asm    mov    di, WORD PTR offval
  130.     asm mov    cx, WORD PTR strl
  131.     asm cld
  132.     asm    repe   cmpsb
  133.     asm    je     scandone  // IF result of compare was true, then do not
  134.     f = FALSE;           // change f and exit routine (i.e. match found).
  135.  
  136.   scandone:
  137.     asm pop    es
  138.     return(f);
  139. }
  140. /***************************************************************************
  141. Function  : writetovideo
  142. Parameters: ASCII code for character to display
  143. Returns   :
  144.  
  145. ***************************************************************************/
  146. void writetovideo(int len, int code, int color) {
  147.  
  148.     int address = ((wherex() - 1) * 2) + ((wherey() -1) * 160);
  149.     int videoSeg = videoAddress();   /* Is a colour card on system? */
  150.  
  151.     asm {
  152.     mov   ah, BYTE PTR color
  153.     mov   al, BYTE PTR code      /* The character to display      */
  154.     mov   cx, WORD PTR len       /* cx determines number of loops */
  155.     mov   dx, WORD PTR videoSeg
  156.     push  es
  157.     mov   es, dx
  158.     mov   di, WORD PTR address
  159.     rep   stosw
  160.     pop   es
  161.     }
  162. }
  163. /***************************************************************************
  164. Function  : videoAddress
  165. Parameters: None
  166. Returns   : Segment address for video RAM on a given system
  167.  
  168. ***************************************************************************/
  169. int videoAddress(void) {
  170.  
  171.     int returnReg;
  172.  
  173.     asm {
  174.     mov   ax, 0x0F00
  175.     int   VIDEO
  176.     mov   BYTE PTR returnReg, al
  177.     }
  178.     if (returnReg == 7)
  179.     returnReg = MONO;
  180.     else
  181.     returnReg = COLOUR;
  182.  
  183.     return(returnReg);
  184. }
  185. /***************************************************************************
  186. Function  : initmouse
  187. Parameters: None
  188. Returns   :
  189.  
  190. ***************************************************************************/
  191. int initmouse(void) {
  192.  
  193.     union REGS regs;
  194.  
  195.     regs.x.ax = 0;
  196.  
  197.     int86(MOUSE, ®s, ®s);
  198.     return(regs.x.ax);
  199. }
  200. /***************************************************************************
  201. Function  : showmouse
  202. Parameters: None
  203. Returns   :
  204.  
  205. ***************************************************************************/
  206. void showmouse(void) {
  207.  
  208.     union REGS regs;
  209.  
  210.     regs.h.ah = 0;
  211.     regs.h.al = SHOW;
  212.     int86(MOUSE, ®s, ®s);
  213. }
  214. /***************************************************************************
  215. Function  : hidemouse
  216. Parameters: None
  217. Returns   :
  218.  
  219. ***************************************************************************/
  220. void hidemouse(void) {
  221.  
  222.     union REGS regs;
  223.  
  224.     regs.h.ah = 0;
  225.     regs.h.al = HIDE;
  226.     int86(MOUSE, ®s, ®s);
  227. }
  228. /***************************************************************************
  229. Function  : movemouse
  230. Parameters: column and row to position to
  231. Returns   : nothing
  232.  
  233. **************************************************************************/
  234. void movemouse(int col, int row) {
  235.  
  236.     union REGS regs;
  237.  
  238.     regs.x.ax = 4;
  239.     regs.x.cx = (col*8)-1;
  240.     regs.x.dx = (row*8)-1;      /* rows are from 1 to 25 */
  241.  
  242.     int86(MOUSE, ®s, ®s);
  243. }
  244. /***************************************************************************
  245. Function  : mouseoff
  246. Parameters: None
  247. Returns   :
  248.  
  249. **************************************************************************/
  250. void mouseoff(void) {
  251.  
  252.     union REGS regs;
  253.  
  254.     regs.h.ah = 0;
  255.     regs.h.al = RESET;                  /* Software reset */
  256.     int86(MOUSE, ®s, ®s);
  257. }