spp20.c
来自「串口模块源代码,实用,简单,稳定,有一定的参考价值.」· C语言 代码 · 共 236 行
C
236 行
/****************************************************************************
* *
* Standard Parallel Port (SPP) Debug Tool *
* http://www.senet.com.au/~cpeacock/pdebug.htm *
* *
* Source Code originally written by Craig Peacock <cpeacock@senet.com.au> *
* *
* Modified by Flavio Poletti <poletti@writeme.com> on July 21, 1998: *
* indentation ;-) *
* extension to DJGPP *
* parallel port addresses retrieval *
* user cannot insert addresses any more *
* mouse is not turned off on redraws *
* some code re-adjusting *
* wait for button release after action *
* *
* THIS PROGRAM COMES WITH NO WARRANTY: IF YOU DECIDE TO USE IT, YOU DO IT *
* AT YOUR OWN RISK. *
* *
* This source code can be freely distributed provided that no modifications *
* are made. Should you have any modifications which you believe would be *
* useful, send them to Craig Peacock <cpeacock@senet.com.au> for inclusion. *
* *
* The source code cannot be sold either in source form or pre-programmed *
* into a device, without the written permission of the Author. *
* *
****************************************************************************/
#include <dos.h>
#include <conio.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/* If compiling with DJGPP, include also... */
#ifdef DJGPP
#include <sys/farptr.h>
#include <go32.h>
#endif
/* Global variables */
int port; /* Currently scanned port */
int port_positions[4]; /* List of all ports */
int port_number; /* Number of present ports */
/* Some useful defines... */
#define setpos(x,y) gotoxy((y)+1,(x)+1)
#define BACKGROUNDCOLOR BLUE
#define FOREGROUNDCOLOR WHITE
#define DISABLEDCOLOR LIGHTGRAY
/* Something dependent on the compiler... */
#ifdef DJGPP
#define outport outportw
#define MY_SHORT short
void getports (void)
{
unsigned int address; /* Address of Port */
int j;
unsigned long ptraddr = 0x0408; /* Base Address: segment is zero*/
port_number = 0;
for (j = 0; j < 3; j++)
{
port_positions[j] = _farpeekw(_dos_ds,ptraddr);
ptraddr += 2;
if (port_positions[j])
port_number++;
}
}
#else /* my else clauses always refer to BORLAND C */
#define MY_SHORT
void getports (void)
{
unsigned int address; /* Address of Port */
int j;
unsigned MY_SHORT int far *ptraddr;
ptraddr= (unsigned MY_SHORT int far *)0x00000408;
port_number = 0;
for (j = 0; j < 3; j++)
{
port_positions[j] = *(ptraddr++);
if (port_positions[j])
port_number++;
}
}
#endif
/* Start of common section */
/* Mouse routines */
/* Mouse initialization */
void mouse(void)
{
union REGS inregs;
union REGS outregs;
/* Mouse reset, initialization */
inregs.x.ax = 0;
int86(0x33, &inregs, & outregs);
/* Show mouse */
inregs.x.ax = 1;
int86(0x33, &inregs, & outregs);
/* Set mouse initial position */
inregs.x.ax = 4;
inregs.x.cx = 0;
inregs.x.dx = 8;
int86(0x33, &inregs, & outregs);
}
void mouseon(void)
{
union REGS inregs;
union REGS outregs;
inregs.x.ax = 1;
int86(0x33,&inregs,&outregs);
}
void mouseoff(void)
{
union REGS inregs;
union REGS outregs;
inregs.x.ax = 2;
int86(0x33,&inregs,&outregs);
}
void updatemouse(void)
{
union REGS inregs;
union REGS outregs;
/* Hide mouse... */
inregs.x.ax = 2;
int86(0x33,&inregs,&outregs);
/* ... and show it again! */
inregs.x.ax = 1;
int86(0x33,&inregs,&outregs);
}
void mousestatus
(MY_SHORT int *row,
MY_SHORT int *column,
MY_SHORT int *buttonstatus)
{
union REGS inregs;
union REGS outregs;
inregs.x.ax = 3;
int86(0x33, &inregs, &outregs);
*column = ((outregs.x.cx)/8)*8;
*row = ((outregs.x.dx)/8)*8;
*buttonstatus = outregs.x.bx;
}
/* Other stuff... */
void data(int bit, int port, int base)
{
if (base & bit)
base &= ~bit;
else
base |= bit;
outport(port,base);
}
/* Show inactive ports as disabled */
void disable_port(int j)
{
setpos(6,35+11*j);
textbackground(BACKGROUNDCOLOR);
textcolor(DISABLEDCOLOR);
cprintf("LPT %d [ ]",j+1);
textcolor(FOREGROUNDCOLOR);
}
/* Actions performed on exit */
void exit_jobs(void)
{
/* Turn off the mouse */
mouseoff();
/* Clear text screen */
textbackground(0);
textcolor(7);
clrscr();
/* Restore cursor */
_setcursortype(_NORMALCURSOR);
/* Send message */
printf("Parallel Port Debug Tool V2.0 - August 1998\n");
printf("Source Code Available from http://www.senet.com.au/~cpeacock/pdebug.htm\n\n");
}
/* Initialization */
int init(void)
{
int j;
/* See whether there are ports to debug! */
getports();
if (!port_number)
{
printf("Parallel Port Debug Tool V2.0 - August 1998\n");
printf("Source Code Available from http://www.senet.com.au/~cpeacock/pdebug.htm\n");
printf("Sorry, No detectable Parallel Port found on your PC\n\n");
return(0);
}
/* Set default port to LPT1 */
port = port_positions[0];
/* Screen initialization */
textbackground(0);
textcolor(FOREGROUNDCOLOR);
clrscr();
textbackground(BACKGROUNDCOLOR);
cprintf("赏屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯屯突");
cprintf("
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?