#include "glpntdrv.h"
/*************
** BasicIO **
*************/
// Zustand von Busy abfragen, dabei <busywaitcount> Zyklen (etwa µs) warten
// Liefert 0x80 wenn BUSY = HIGH
UCHAR BasicIO::Busy() {
for (int i=0; i<pCmdBuf->busywaitcount; i++) READ(1);
return ~READ(1)&0x80;
}
/* Datenbyte (7 Bit) mit Taktung (= Toggeln von Bit 7) ausgeben
0x20 - StartPgmImpuls
0x00 - ReadDatenRegByte, ReadDatenRegWord, ReadDatenRegPin1_20, ReadDatenRegPin21_40
argn - DataOut
0x71 - SwitchInterfaceMode(true) bei SetL1, ResetL1
0x70 - SwitchInterfaceMode(false) sonst
0x1? - SetL1
flag_0c7d - ResetL1
0x5? - SetReadbackChannel
0x3? - LoadTimerSerReg, Bit 0 = serielle Daten, Bit 15 zuerst
Tatsächlich wird nur _eine_Flanke ausgegeben! Das GALEP benutzt offenbar beide Flanken. */
void BasicIO::DataOut(UCHAR b) {
if (pCmdBuf->loopcount) {
WRITE(0,READ(0)&0x80|b);
for (int i=0; i<pCmdBuf->loopcount; i++) {
WRITE(0,READ(0)&0x80|b);
}
WRITE(0,READ(0)^0x80);
}else{
WRITE(0,~READ(0)&0x80|b);
}
}
/**********************
** KrnlInterfaceHdw **
**********************/
BOOL KrnlInterfaceHdw::WaitForNotBusy() {
for (int i=0; i<=pCmdBuf->busyloopcount; i++) {
if (!Busy()) return TRUE;
}
return FALSE;
}
void KrnlInterfaceHdw::SwitchInterfaceMode(bool mode) {
if (pCmdBuf->interfacemode!=mode) {
pCmdBuf->interfacemode=mode;
DataOut(0x70|(UCHAR)mode);
}
}
void KrnlInterfaceHdw::SetL1_Q11() {
if (!pCmdBuf->flag_9C7F) {
pCmdBuf->flag_9C7F=0x10;
SwitchInterfaceMode(true);
DataOut(0x11|pCmdBuf->flag_9C7E);
}
}
void KrnlInterfaceHdw::ResetL1_Q00() {
if (pCmdBuf->flag_9C7C) {
pCmdBuf->flag_9C7C=false;
SwitchInterfaceMode(true);
DataOut(pCmdBuf->flag_9C7D);
}
}
void KrnlInterfaceHdw::SetReadbackChannel(UCHAR chn) {
SwitchInterfaceMode(false);
DataOut(0x50|chn);
}
USHORT KrnlInterfaceHdw::ReadDatenRegByte() {
SetL1_Q11();
ResetL1_Q00();
SetReadbackChannel(2);
ULONG ret=0;
for (int i=0; i<8; i++) { // 8 Bits lesen
ret<<=1;
if (Busy()) ret++;
DataOut(0);
}
return USHORT(ret);
}
USHORT KrnlInterfaceHdw::ReadDatenRegWord() {
SetL1_Q11();
ResetL1_Q00();
SetReadbackChannel(0x02);
ULONG ret=0; // weiter wie ReadDatenRegByte()
for (int i=0; i<16; i++) {
ret<<=1;
if (Busy()) ret++;
DataOut(0);
}
return USHORT(ret);
}
// Pinreihe 1..20 lesen (20 Bit)
ULONG KrnlInterfaceHdw::ReadDatenRegPin1_20() {
SetL1_Q11();
SetReadbackChannel(0x0A);
ULONG ret=0; // weiter wie ReadDatenRegByte()
for (int i=0; i<20; i++) {
ret<<=1;
if (Busy()) ret++;
DataOut(0);
}
return ret;
}
// Pinreihe 21..40 lesen (20 Bit)
ULONG KrnlInterfaceHdw::ReadDatenRegPin21_40() {
SetL1_Q11();
SetReadbackChannel(0x0C);
ULONG ret=0; // weiter wie ReadDatenRegByte()
for (int i=0; i<20; i++) {
ret<<=1;
if (Busy()) ret++;
DataOut(0);
}
return ret;
}
USHORT KrnlInterfaceHdw::CalcTimerWert(ULONG val) {
return USHORT(0x10000-(val>>1));
}
void KrnlInterfaceHdw::LoadTimerSerReg(USHORT val) {
SwitchInterfaceMode(false);
for (int i=0; i<16; i++) {
DataOut(0x30|val>>15);
val<<=1;
}
}
void KrnlInterfaceHdw::StartPgmImpuls() {
SwitchInterfaceMode(false);
DataOut(0x20); // 0x20 == StartPgmImpuls
}
BOOL KrnlInterfaceHdw::MeasureBusySpeed() {
LoadTimerSerReg(CalcTimerWert(100));
DisableCallCount++;
if (!IsIrplHigh) {
IsIrplHigh=true;
SetIrqlHigh();
}
StartPgmImpuls();
SetReadbackChannel(6);
ULONG i;
for (i=0;Busy();i++);
Enable();
if (i>=1) {
pCmdBuf->BusySpeed=i;
return TRUE;
}
return FALSE;
}
Detected encoding: ANSI (CP1252) | 4
|
|