Source file: /~heha/hs/glpntdrv.zip/glpwow/glpwow.cpp

#include <windows.h>
#include "glpntdrv.h"
#include "../inpout32/inpout32.h"

#define elemof(x) (sizeof(x)/sizeof(*(x)))
#include <stdio.h>

#define queue ((HQUEUE*)BAADFOOD)[0]

class CMDBUF2:CMDBUF {
 void Out(BYTE o, BYTE b);
 BYTE In(BYTE o);
 BYTE Busy() {return ~In(1)&0x80;}
 void DataOut(BYTE b) {Out(0,In(0)&0x80|b); Out(0,In(0)^0x80);}
 bool WaitForNotBusy();
 void SwitchInterfaceMode(bool mode);
 void SetL1_Q11();
 void ResetL1_Q00();
 void SetReadbackChannel(BYTE chn);
 DWORD InDatenReg(int bits, BYTE rbc=2);
 void Delay(DWORD us) {LptDelay(queue,us);};
 BOOL _cdecl ExecKernelDriver();
};

void CMDBUF2::Out(BYTE o, BYTE b) {
 unused[o]=b;		// retten
 LptOut(queue,o,b);
}

BYTE CMDBUF2::In(BYTE o) {
 switch (o) {
  case 0:
  case 2: return unused[o];
  default: return LptIn(queue,o);
 }
}

bool CMDBUF2::WaitForNotBusy() {
 for (int i=0; i<=busyloopcount; i++) {
  if (!Busy()) return true;
 }
 return false;
}

void CMDBUF2::SwitchInterfaceMode(bool mode) {
 if (interfacemode!=mode) {
  interfacemode=mode;
  DataOut(0x70|(BYTE)mode);
 }
}

void CMDBUF2::SetL1_Q11() {
 if (!flag_9C7F) {
  flag_9C7F=0x10;
  SwitchInterfaceMode(true);
  DataOut(0x11|flag_9C7E);
 }
}

void CMDBUF2::ResetL1_Q00() {
 if (flag_9C7C) {
  flag_9C7C=false;
  SwitchInterfaceMode(true);
  DataOut(flag_9C7D);
 }
}

void CMDBUF2::SetReadbackChannel(UCHAR chn) {
 SwitchInterfaceMode(false);
 DataOut(0x50|chn);
}

DWORD CMDBUF2::InDatenReg(int bits, BYTE rbc) {
 SetL1_Q11();
 if (rbc==2) ResetL1_Q00();
 SetReadbackChannel(rbc);
 ULONG ret=0;			// weiter wie ReadDatenRegByte() 
 for (int i=0; i<bits; i++) {
  ret<<=1;
  if (Busy()) ret++;
  DataOut(0);
 }
 return ret;
}

#define dbg(x) DebugOut x

void _cdecl DebugOut(const char*t,...) {
 char s[256];
 va_list va;
 va_start(va,t);
 _vsnprintf(s,elemof(s),t,va);
 OutputDebugString(s);
}

BOOL CMDBUF2::ExecKernelDriver() {
 errorcode=0;
 int tp=GetThreadPriority(GetCurrentThread());
 SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_HIGHEST);
 for (BYTE pass=1; pass<=2; pass++) {
  LptPass(queue,pass);
  for (int i=0; i<5000; i++) {
   dbg(("Index %d Funktion %d\n",i,n[i].func));
   switch (n[i].func) {
    case 0: break;		// NOP
    case 1: Out(0,(BYTE)n[i].arg); break;
    case 2: Out(0,In(0)&0x80|(BYTE)n[i].arg); break;
    case 3: retval=In(0); break;
    case 4: Out(0,In(0)^0x80); break;
    case 5: Out(0,~In(0)&0x80|(BYTE)n[i].arg); break;
    case 6: Out(2,In(2)&0xDE|(BYTE)n[i].arg); break;
    case 7: Busy(); break;
    case 8: Out(2,In(2)|0xE4); break;	// RESET (INIT) = HIGH
    case 9: retval=Busy(); break;
    case 10: DataOut((BYTE)n[i].arg); break;
    case 11: retval=InDatenReg(8); break;
    case 12: retval=InDatenReg(16); break;
    case 13:
    case 14: Delay(n[i].arg); break;
    case 15: break;		// Enable()
    case 16: break;		// Disable()
    case 17: retval=InDatenReg(20,10); break;
    case 18: retval=InDatenReg(20,12); break;
    case 19: queue=LptOpen(address,0); break;
    case 20: BusySpeed=1; retval=TRUE; break;
    case 21: retval=WaitForNotBusy(); break;
    case 22: retval=2; break;
    case 23: LptClose(queue); queue=0; break;
    case 24: goto breakout;
    default: errorcode=1001; goto breakout;
   }
  }
breakout:;
 }
 SetThreadPriority(GetCurrentThread(),tp);
 return errorcode==0;
}

/*
EXTERN_C BOOL _DllMainCRTStartup(HINSTANCE hInst, ULONG reason, LPVOID) {
 return TRUE;
}
*/
Detected encoding: ASCII (7 bit)2