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