// // DCCTEST.C - Test program for the DCC-MB interface and driver // #include #include short DCCSetMode(short); short DCCQueryDriver(short *, short *); short DCCReset(void); short DCCActivateLoco(short, short); short DCCSetSpeed(short, short); short DCCSetExtraBit(short, short); short DCCSetDirection(short, short); short DCCSetNReps(short); short DCCSetGroup1Acc(short, short, short); short DCCWritePagedRegister(short, short); short DCCSetPPortLine(short, short); short nDCCAddr, nSpeed=0, nDir=1, nExtraBit=0; char szDir[2][8] = {"Reverse", "Forward"}; char szSpeed[16][15] = {"Emergency Stop", "Stop", "Run 1", "Run 2", "Run 3", "Run 4", "Run 5", "Run 6", "Run 7", "Run 8", "Run 9", "Run 10", "Run 11", "Run 12", "Run 13", "Run 14"}; short nAccValue[5] = {0, 0, 0, 0, 0}; main() { char c; short nAcc, nDriverMode, nLocos, nReg, nValue; if (DCCQueryDriver(&nDriverMode, &nLocos) != 0xFACE) { printf("\007Error: DCC-MB Driver is not installed."); return 1; } printf ("Enter your decoder's DCC address : "); scanf("%d", &nDCCAddr); DCCActivateLoco(nDCCAddr, 1); printf ("\n [Esc] - Quit\n"); printf (" [Up and Down Arrows] - Change Speed\n"); printf (" [Enter] - Change Direction\n"); printf (" [F1-F5] - Aux Functions 1 to 5\n"); printf (" [R] - DCC Reset\n"); printf (" [E] - Set/Clear Extra Bit\n"); printf (" [P] - Program a Register\n\n"); DCCSetMode(1); do { printf ("\r Speed: %-15s | Dir: %s | Extra Bit: %1d | Aux: %1d %1d %1d %1d %1d ", szSpeed[nSpeed], szDir[nDir], nExtraBit, nAccValue[0], nAccValue[1], nAccValue[2], nAccValue[3], nAccValue[4]); c = getch(); if (c == 0) { c = getch(); switch (c) { case 59: // F1 case 60: // F2 case 61: // F3 case 62: // F4 case 63: // F5 nAcc = (short)c - 59; if (nAccValue[nAcc] == 0) nAccValue[nAcc] = 1; else nAccValue[nAcc] = 0; DCCSetGroup1Acc(nDCCAddr, nAcc, nAccValue[nAcc]); break; case 72: // Up arrow - increment speed if (nSpeed < 15) DCCSetSpeed(nDCCAddr, ++nSpeed); break; case 80: // Down arrow - decrement speed if (nSpeed > 0) DCCSetSpeed(nDCCAddr, --nSpeed); break; } } else if (c == 13) { DCCSetSpeed(nDCCAddr, (nSpeed = 0)); nDir = 1 - nDir; DCCSetDirection(nDCCAddr, nDir); } else if ((c == 'r') || (c == 'R')) { DCCReset(); nSpeed = 0; } else if ((c == 'e') || (c == 'E')) { nExtraBit = 1 - nExtraBit; DCCSetExtraBit(nDCCAddr, nExtraBit); } else if ((c == 'p') || (c == 'P')) { DCCSetSpeed(nDCCAddr, 0); DCCSetMode(2); printf ("\r "); printf ("\rRegister Number (0-8) : "); scanf ("%d", &nReg); printf ("\r "); printf ("\rValue (0-255) : "); scanf ("%d", &nValue); DCCWritePagedRegister(nValue, nReg); DCCSetMode(1); } } while (c != 27); DCCSetSpeed(nDCCAddr, 0); printf ("\n\n"); //DCCSetMode(0); } //--------------------------------------------------------------------------- // DCC-MB Driver Calls //--------------------------------------------------------------------------- union _REGS regs; // structure that holds values of all registers //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCSetMode(short nMode) { regs.h.ah = 0; regs.h.al = (unsigned char)nMode; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCQueryDriver(short *nDriverMode, short *nActiveLocos) { regs.x.ax = 0x00FF; _int86(0x70, ®s, ®s); *nDriverMode = regs.x.bx; *nActiveLocos = regs.x.cx; return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCReset() { regs.h.ah = 1; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCActivateLoco(short nDCCAddr, short nSpeedMode) { regs.h.ah = 10; regs.h.al = (unsigned char)nSpeedMode; regs.x.bx = (unsigned char)nDCCAddr; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCDeactivateLoco(short nDCCAddr) { regs.h.ah = 11; regs.x.bx = (unsigned char)nDCCAddr; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCSetSpeed(short nDCCAddr, short nSpeed) { regs.h.ah = 12; regs.h.al = (unsigned char)nSpeed; regs.h.bl = (unsigned char)nDCCAddr; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCSetDirection(short nDCCAddr, short nDir) { regs.h.ah = 13; regs.h.al = (unsigned char)nDir; regs.h.bl = (unsigned char)nDCCAddr; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCSetExtraBit(short nDCCAddr, short nValue) { regs.h.ah = 14; regs.h.al = (unsigned char)nValue; regs.h.bl = (unsigned char)nDCCAddr; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCSetNReps(short nReps) { regs.h.ah = 30; regs.h.al = (unsigned char)nReps; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCSetGroup1Acc(short nDCCAddr, short nAccNum, short nValue) { regs.h.ah = 31; regs.h.al = (unsigned char)nValue; regs.h.bl = (unsigned char)nDCCAddr; regs.h.cl = (unsigned char)nAccNum; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCWritePagedRegister(short nValue, short nRegNum) { regs.h.ah = 50; regs.h.al = (unsigned char)nValue; regs.h.bl = (unsigned char)nRegNum; _int86(0x70, ®s, ®s); return regs.x.ax; } //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: short DCCSetPPortLine(short nValue, short nLineNum) { regs.h.ah = 200; regs.h.al = (unsigned char)nValue; regs.h.bl = (unsigned char)nLineNum; _int86(0x70, ®s, ®s); return regs.x.ax; } //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::