home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / X00API.C < prev    next >
C/C++ Source or Header  |  1994-04-03  |  11KB  |  412 lines

  1. /*
  2.  *   X00API.C: X00 FOSSIL driver
  3.  *   
  4.  *   Created by R.F. Pels.
  5.  *   modified by Bob Stout
  6.  *   Placed in the public domain by R.F. Pels.
  7.  */
  8.  
  9. #include "x00api.h"
  10. #include <dos.h>
  11.  
  12. static union  REGS  x00regs;
  13. static struct SREGS x00sregs;
  14. int                 x00error = 0;
  15.  
  16. #if __cplusplus
  17.  extern "C" {
  18. #endif
  19.  
  20. #ifdef __TURBOC__
  21.  #define PEEK(s,o) peek(s,o)
  22. #else /* MSC or ZTC */
  23.  #define PEEK(s,o) *((unsigned _far *)(MK_FP((s),(o))))
  24. #endif
  25.  
  26. #ifndef MK_FP
  27.  #define MK_FP(seg,offset) \
  28.         ((void _far *)(((unsigned long)(seg)<<16) | (unsigned)(offset)))
  29. #endif
  30.  
  31. unsigned int  x00_detect(void)
  32. {
  33.         unsigned int segofx00;
  34.         unsigned int ofsofx00;
  35.         
  36.         /* Peek in interrupt vector table for start of FOSSIL */
  37.  
  38.         ofsofx00 = PEEK(0, X00_VECTOR * 4);
  39.         segofx00 = PEEK(0, (X00_VECTOR * 4) + 2);
  40.         
  41.         /* Peek in start of FOSSIL + X00_IDOFFSET */
  42.  
  43.         return (PEEK(segofx00, ofsofx00 + X00_IDOFFSET));
  44. }
  45.  
  46. FOSSILSTATUS  x00_set(unsigned char set, PORT port)
  47. {
  48.         FOSSILSTATUS retval;
  49.         
  50.         x00regs.x.ax = SET_BAUDRATE | set;
  51.         x00regs.x.dx = port;
  52.         int86(X00_VECTOR, &x00regs, &x00regs);
  53.         retval.statusword = x00regs.x.ax;
  54.         return retval;
  55. }
  56.  
  57. FOSSILSTATUS  x00_tx_char(unsigned char c, PORT port)
  58. {
  59.         FOSSILSTATUS retval;
  60.         
  61.         x00regs.x.ax = TX_CHAR | c;
  62.         x00regs.x.dx = port;
  63.         int86(X00_VECTOR, &x00regs, &x00regs);
  64.         retval.statusword = x00regs.x.ax;
  65.         return retval;
  66. }
  67.  
  68. unsigned char  x00_rx_char(PORT port)
  69. {
  70.         x00regs.x.ax = RX_CHAR;
  71.         x00regs.x.dx = port;
  72.         int86(X00_VECTOR, &x00regs, &x00regs);
  73.         return (unsigned char)(x00regs.x.ax & 0xff);
  74. }
  75.  
  76. FOSSILSTATUS  x00_status(PORT port)
  77. {
  78.         FOSSILSTATUS retval;
  79.         
  80.         x00regs.x.ax = STATUS;
  81.         x00regs.x.dx = port;
  82.         int86(X00_VECTOR, &x00regs, &x00regs);
  83.         retval.statusword = x00regs.x.ax;
  84.         return retval;
  85. }
  86.  
  87. FOSSILINIT    x00_init(PORT port, unsigned char far *ctlc_flagbyte)
  88. {
  89.         FOSSILINIT retval;
  90.         
  91.         x00regs.x.ax = INITIALIZE;
  92.         if (ctlc_flagbyte != (unsigned char far *)0)
  93.         {
  94.                 x00regs.x.dx = 0x00ff;
  95.                 x00regs.x.bx = 0x4F50;
  96.                 segread(&x00sregs);
  97.                 x00sregs.es  = FP_SEG(ctlc_flagbyte);
  98.                 x00regs.x.cx = FP_OFF(ctlc_flagbyte);
  99.         }
  100.         else
  101.         {
  102.                 x00regs.x.bx = 0x0000; /* in any case _NOT_ 0x4f50 */
  103.                 x00regs.x.dx = port;
  104.         }
  105.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  106.         retval.result       = x00regs.x.ax;
  107.         retval.max_function = (unsigned char)(x00regs.x.bx & 0xff);
  108.         retval.revision     = (unsigned char)(x00regs.x.bx >> 8);
  109.         return retval;
  110. }
  111.  
  112. void          x00_deinit(PORT port)
  113. {
  114.         x00regs.x.ax = DEINITIALIZE;
  115.         x00regs.x.dx = port;
  116.         int86(X00_VECTOR, &x00regs, &x00regs);
  117. }
  118.  
  119. unsigned int  x00_raise_dtr(PORT port)
  120. {
  121.         unsigned int retval;
  122.         
  123.         x00regs.x.ax = RAISE_DTR;
  124.         x00regs.x.dx = port;
  125.         int86(X00_VECTOR, &x00regs, &x00regs);
  126.         if ((x00regs.x.ax & 0x0001) == 1)
  127.         {
  128.                 retval = X00_DTR_HIGH;
  129.         }
  130.         else    retval = X00_DTR_LOW;
  131.         return retval;
  132. }
  133.  
  134. unsigned int  x00_lower_dtr(PORT port)
  135. {
  136.         unsigned int retval;
  137.         
  138.         x00regs.x.ax = LOWER_DTR;
  139.         x00regs.x.dx = port;
  140.         int86(X00_VECTOR, &x00regs, &x00regs);
  141.         if ((x00regs.x.ax & 0x0001) == 1)
  142.         {
  143.                 retval = X00_DTR_HIGH;
  144.         }
  145.         else    retval = X00_DTR_LOW;
  146.         return retval;
  147. }
  148.  
  149. FOSSILSYSINFO x00_sysinfo(void)
  150. {
  151.         FOSSILSYSINFO retval;
  152.         
  153.         x00regs.x.ax = GET_SYS_INFO;
  154.         int86(X00_VECTOR, &x00regs, &x00regs);
  155.         retval.tick_number        = (unsigned char)(x00regs.x.ax & 0xff);
  156.         retval.ticks_per_second   = (unsigned char)(x00regs.x.ax >> 8);
  157.         retval.approx_ms_per_tick = x00regs.x.dx;
  158.         return retval;
  159. }
  160.  
  161. void          x00_flush_output(PORT port)
  162. {
  163.         x00regs.x.ax = FLUSH_OUTPUT;
  164.         x00regs.x.dx = port;
  165.         int86(X00_VECTOR, &x00regs, &x00regs);
  166. }
  167.  
  168. void          x00_purge_output(PORT port)
  169. {
  170.         x00regs.x.ax = PURGE_OUTPUT;
  171.         x00regs.x.dx = port;
  172.         int86(X00_VECTOR, &x00regs, &x00regs);
  173. }
  174.  
  175. void          x00_purge_input(PORT port)
  176. {
  177.         x00regs.x.ax = PURGE_INPUT;
  178.         x00regs.x.dx = port;
  179.         int86(X00_VECTOR, &x00regs, &x00regs);
  180. }
  181.  
  182. unsigned int  x00_tx_char_nowait(unsigned char c, PORT port)
  183. {
  184.         unsigned int retval;
  185.         
  186.         x00regs.x.ax = TX_CHAR_NOWAIT | c;
  187.         x00regs.x.dx = port;
  188.         int86(X00_VECTOR, &x00regs, &x00regs);
  189.         if ((x00regs.x.ax & 0x0001) == 1)
  190.         {
  191.                 retval = X00_OK;
  192.         }
  193.         else    retval = X00_CHAR_NOT_SENT;
  194.         return retval;
  195. }
  196.  
  197. unsigned int  x00_peek_ahead_input(PORT port)
  198. {
  199.         x00regs.x.ax = PEEK_AHEAD_INPUT;
  200.         x00regs.x.dx = port;
  201.         int86(X00_VECTOR, &x00regs, &x00regs);
  202.         return x00regs.x.ax;
  203. }
  204.  
  205. unsigned int   x00_peek_ahead_kbd(void)
  206. {
  207.         x00regs.x.ax = PEEK_AHEAD_KBD;
  208.         int86(X00_VECTOR, &x00regs, &x00regs);
  209.         return x00regs.x.ax;
  210. }
  211.  
  212. unsigned int  x00_read_kbd(void)
  213. {
  214.         x00regs.x.ax = READ_KBD;
  215.         int86(X00_VECTOR, &x00regs, &x00regs);
  216.         return x00regs.x.ax;
  217. }
  218.  
  219. void          x00_flow_control(FOSSILFLOWCTRL f, PORT port)
  220. {
  221.         x00regs.x.ax = FLOW_CONTROL | 0xf0 | f.flowword;
  222.         x00regs.x.dx = port;
  223.         int86(X00_VECTOR, &x00regs, &x00regs);
  224. }
  225.  
  226. unsigned int  x00_ctlc_ctlk_check(FOSSILCTLCCTLK c, PORT port)
  227. {
  228.         x00regs.x.ax = CTLC_CTLK_CHECK | c.checkword;
  229.         x00regs.x.dx = port;
  230.         int86(X00_VECTOR, &x00regs, &x00regs);
  231.         return x00regs.x.ax;
  232. }
  233.  
  234. void          x00_set_cup(unsigned char row, unsigned char col)
  235. {
  236.         x00regs.x.ax = SET_CUP;
  237.         x00regs.x.dx = (row << 8) | col;
  238.         int86(X00_VECTOR, &x00regs, &x00regs);
  239. }
  240.  
  241. void          x00_get_cup(unsigned char *row, unsigned char *col)
  242. {
  243.         x00regs.x.ax = GET_CUP;
  244.         int86(X00_VECTOR, &x00regs, &x00regs);
  245.         *col = (unsigned char)(x00regs.x.dx & 0xff);
  246.         *row = (unsigned char)(x00regs.x.dx >> 8);
  247. }
  248.  
  249. void          x00_write_ANSI_char(unsigned char c)
  250. {
  251.         x00regs.x.ax = WRITE_ANSI_CHAR | c;
  252.         int86(X00_VECTOR, &x00regs, &x00regs);
  253. }
  254.  
  255. void          x00_enable_watchdog(PORT port)
  256. {
  257.         x00regs.x.ax = ENABLE_WATCHDOG;
  258.         x00regs.x.dx = port;
  259.         int86(X00_VECTOR, &x00regs, &x00regs);
  260. }
  261.  
  262. void          x00_disable_watchdog(PORT port)
  263. {
  264.         x00regs.x.ax = DISABLE_WATCHDOG;
  265.         x00regs.x.dx = port;
  266.         int86(X00_VECTOR, &x00regs, &x00regs);
  267. }
  268.  
  269. void          x00_write_BIOS_char(unsigned char c)
  270. {
  271.         x00regs.x.ax = WRITE_BIOS_CHAR | c;
  272.         int86(X00_VECTOR, &x00regs, &x00regs);
  273. }
  274.  
  275. unsigned int  x00_insert_tick_func(void (far *tickfunc)())
  276. {
  277.         unsigned int retval;
  278.         
  279.         x00regs.x.ax = INSERT_TICK_FUNC;
  280.         x00regs.x.dx = FP_OFF(tickfunc);
  281.         segread(&x00sregs);
  282.         x00sregs.es  = FP_SEG(tickfunc);
  283.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  284.         if (x00regs.x.ax == 0x0000)
  285.         {
  286.                 retval = X00_OK;
  287.         }
  288.         else    retval = X00_INS_TICK;
  289.         return retval;
  290. }
  291.  
  292. unsigned int  x00_delete_tick_func(void (far *tickfunc)())
  293. {
  294.         unsigned int retval;
  295.         
  296.         x00regs.x.ax = DELETE_TICK_FUNC;
  297.         x00regs.x.dx = FP_OFF(tickfunc);
  298.         segread(&x00sregs);
  299.         x00sregs.es  = FP_SEG(tickfunc);
  300.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  301.         if (x00regs.x.ax == 0x0000)
  302.         {
  303.                 retval = X00_OK;
  304.         }
  305.         else    retval = X00_DEL_TICK;
  306.         return retval;
  307. }
  308.  
  309. void          x00_boot_machine(unsigned int boottype)
  310. {
  311.         x00regs.x.ax = BOOT_MACHINE | (boottype & 0x0001);
  312.         int86(X00_VECTOR, &x00regs, &x00regs);
  313. }
  314.  
  315. unsigned int  x00_read_block(unsigned int count, void far *buf, PORT port)
  316. {
  317.         x00regs.x.ax = READ_BLOCK;
  318.         x00regs.x.cx = count;
  319.         x00regs.x.dx = port;
  320.         segread(&x00sregs);
  321.         x00sregs.es  = FP_SEG(buf);
  322.         x00regs.x.di = FP_OFF(buf);
  323.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  324.         return x00regs.x.ax;
  325. }
  326.  
  327. unsigned int  x00_write_block(unsigned int count, void far *buf, PORT port)
  328. {
  329.         x00regs.x.ax = WRITE_BLOCK;
  330.         x00regs.x.cx = count;
  331.         x00regs.x.dx = port;
  332.         segread(&x00sregs);
  333.         x00sregs.es  = FP_SEG(buf);
  334.         x00regs.x.di = FP_OFF(buf);
  335.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  336.         return x00regs.x.ax;
  337. }
  338.  
  339. void          x00_start_break_signal(PORT port)
  340. {
  341.         x00regs.x.ax = START_BREAK_SIGNAL;
  342.         x00regs.x.dx = port;
  343.         int86(X00_VECTOR, &x00regs, &x00regs);
  344. }
  345.  
  346. void          x00_stop_break_signal(PORT port)
  347. {
  348.         x00regs.x.ax = STOP_BREAK_SIGNAL;
  349.         x00regs.x.dx = port;
  350.         int86(X00_VECTOR, &x00regs, &x00regs);
  351. }
  352.  
  353. unsigned int  x00_get_driverinfo(void far *buf, PORT port)
  354. {
  355.         x00regs.x.ax = GET_DRIVER_INFO;
  356.         x00regs.x.cx = sizeof(FOSSILINFO);
  357.         segread(&x00sregs);
  358.         x00sregs.es  = FP_SEG(buf);
  359.         x00regs.x.di = FP_OFF(buf);
  360.         x00regs.x.dx = port;
  361.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  362.         return x00regs.x.ax;
  363. }
  364.  
  365. unsigned int  x00_install_appendage(unsigned char appcode,
  366.                                               void (far *appfunc)())
  367. {
  368.         unsigned int retval;
  369.         
  370.         x00regs.x.ax = INSTALL_APPENDAGE | appcode;
  371.         segread(&x00sregs);
  372.         x00sregs.es  = FP_SEG(appfunc);
  373.         x00regs.x.dx = FP_OFF(appfunc);
  374.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  375.         if (x00regs.x.ax == X00_PRESENT)
  376.         {
  377.                 if ((x00regs.x.bx & 0xff00) == 1)
  378.                 {
  379.                         retval = X00_OK;
  380.                 }
  381.                 else    retval = X00_INS_APP;
  382.         }
  383.         else    retval = X00_NOT_HERE;
  384.         return retval;
  385. }
  386.  
  387. unsigned int  x00_remove_appendage(unsigned char appcode,
  388.                                              void (far *appfunc)())
  389. {
  390.         unsigned int retval;
  391.         
  392.         x00regs.x.ax = REMOVE_APPENDAGE | appcode;
  393.         segread(&x00sregs);
  394.         x00sregs.es  = FP_SEG(appfunc);
  395.         x00regs.x.dx = FP_OFF(appfunc);
  396.         int86x(X00_VECTOR, &x00regs, &x00regs, &x00sregs);
  397.         if (x00regs.x.ax == X00_PRESENT)
  398.         {
  399.                 if ((x00regs.x.bx & 0xff00) == 1)
  400.                 {
  401.                         retval = X00_OK;
  402.                 }
  403.                 else    retval = X00_REM_APP;
  404.         }
  405.         else    retval = X00_NOT_HERE;
  406.         return retval;
  407. }
  408.  
  409. #if __cplusplus
  410.  }
  411. #endif
  412.