|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 4448 (0x1160)
Types: TextFile
Notes: UNIX file
Names: »clk.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦2d53db1df⟧ UNIX Filesystem
└─⟦this⟧ »frankh/src/junk/clk.c«
/*
* Centronics parallel printer interface driver for Commodore Z8000M
* (uses the Z8036 chip).
*
*
*
*
*/
#include <coherent.h>
#include <con.h>
#include <errno.h>
#include <io.h>
#include <proc.h>
#include <uproc.h>
#include <stat.h>
int ckload();
int ckuload();
int ckwrite();
int ckopen();
int ckclose();
int ckintr();
int nulldev();
int nonedev();
CON ckcon = {
DFCHR, /* Flags */
12, /* Major index */
ckopen, /* Open */
ckclose, /* Close */
nulldev, /* Block */
nonedev, /* Read */
ckwrite, /* Write */
nonedev, /* Ioctl */
nulldev, /* Powerfail */
nulldev, /* Timeout */
ckload, /* Load */
ckuload /* Unload */
};
/*
* Various ports and masks. All initialization of the Z8036
* is done in the mach since there are other devices that
* use the chip. If you want to change LPIRQ you must also
* modify its definition in the mach.
*/
#define LPPORT 0x1D /* Printer port */
#define BUSYPORT 0x1F /* BUSY port */
#define ACKPORT 0x9D /* Acknowledge port */
#define STROBEPORT 0x9F /* Strobe port */
#define SETSTROBE 0x70 /* Sets strobe line */
#define CLEARSTROBE 0x78 /* Clears strobe line */
#define ACKMASK 0x02 /* Mask for acknowledge bit */
#define BUSYMASK 0x01 /* Mask for busy bit */
#define PBCS 0x93 /* Z8036 #2 port B cmd & stat reg */
#define PCDD 0x0D
#define PCDATA 0x1F
#define PBDATA 0x1B
#define CLRIPIUS 0x20 /* Mask to clear IP and IUS */
#define LPIRQ 0x70 /* Printer interrupt */
#define MAXBUF 256 /* # of bytes in buffer */
#define LOLIM 30 /* Low buffer limit for wakeup */
/* lpflag bits */
#define LPOPEN 0x01 /* Printer is open */
#define LPSLEEP 0x02 /* Sleeping on buffer event */
#define LPRAW 0x04 /* Raw mode */
#define LPWFI 0x08 /* Waiting for Interrupt */
/*
*
*
*
* The data lines are initialised, as follows in md.s:
* 8036 #1, port b, non-inverting: output data lines
* 8036 #1, port c, bit 0, non-inverting: input busy line
* 8036 #2, port b, bit 1, inverting: inpupt acknowledge
* 8036 #2, port c, bit 3, non-inverting: output strobe
*
*/
ckload()
{
unsigned int tmp;
printf("Begin . . .\n");
outb( PCDD, 0x05); /* set up STOP line */
outb( PCDATA, inb(PCDATA) | 0x50);
outb( PBDATA, 0);
printf("ckload: start\n");
outb( PCDATA, inb(PCDATA) & ~0x01); /* set select = 0 */
outb( PBDATA, inb(PBDATA) | 0x80); /* set stop = 1 */
outb( PBDATA, inb(PBDATA) & 0xF0); /* set d0-d3 = 0 */
outb( PBDATA, inb(PBDATA) | 0x40); /* set adw = 1 */
tmp = 0; /* delay */
outb( PBDATA, inb(PBDATA) & ~0x40); /* set adw = 0 */
outb( PBDATA, inb(PBDATA) | 0x10); /* set rd = 1 */
tmp = 5 * 5; /* delay */
tmp = inb(PBDATA) & 0x0F; /* read and mask */
printf("ckload: tmp = %u\n", tmp);
outb( PBDATA, inb(PBDATA) & ~0x80); /* set stop = 0 */
outb( PBDATA, inb(PBDATA) | 0x01); /* set select = 1 */
}
/*
* Unload the driver and close up shop
*/
ckuload()
{
int i;
i = 0;
}
/*
* The open routine makes sure
* that only one process can have the
* printer open at once, and copies the
* RAW bit of the minor into the local
* printer flags.
*/
ckopen(dev, mode)
dev_t dev;
{
}
/*
* The close routine drains the
* circular buffer in the per printer
* database, and then marks the device
* as no longer open.
*/
ckclose(dev)
dev_t dev;
{
}
/*
* The write routine copies the
* characters from the user buffer to
* the printer buffer, expanding tabs and
* keeping track of the current horizontal
* position of the print head.
*/
ckwrite(dev, iop)
dev_t dev;
IO *iop;
{
}
/*
* Put a character into the
* printer buffer. Make sure that there is
* room to do so, and wait for the interrupt
* driven part to make more room if this is
* indeed necessary.
*/
lpchar(c)
{
/* register int s;
s = sphi();
while (lp.lpnbuf >= MAXBUF) {
lpstart();
lp.lpflag |= LPSLEEP;
sleep((char *)&lp, 0, 0, 0);
}
++lp.lpnbuf;
if (lp.lpin == &lp.lpbuf[MAXBUF])
lp.lpin = &lp.lpbuf[0];
*lp.lpin++ = c;
spl(s); */
}
/*
* Interrupt routine. Poke the printer
* to get it going. Wake up the process level
* half of the driver, if necessary.
*/
lpintr()
{
/* register int s;
s = sphi();
outb(PBCS, CLRIPIUS);
outb(ACKPORT, inb(ACKPORT) & ~ACKMASK);
if ((lp.lpflag & LPWFI) != 0) {
lp.lpflag &= ~LPWFI;
lpstart();
if ((lp.lpflag&LPSLEEP)!=0 && lp.lpnbuf<LOLIM) {
lp.lpflag &= ~LPSLEEP;
wakeup((char *)&lp);
}
}
spl(s); */
}