Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

565 lines
14 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "StdAfx.h"
  2. #include "ISA.h"
  3. #include "Timer.h"
  4. #include "A2D.h"
  5. #include "SysClock.h"
  6. //#define ENCODER_6000_PULSES
  7. #define LGS_PULSE_COUNT 6000
  8. #ifdef ENCODER_6000_PULSES
  9. #define TEMPERATURE_ENABLE
  10. #else
  11. #define TEMPERATURE_ENABLE
  12. // #define MOTOR_GEAR_RATIO 61 /*150*/ // 61
  13. // #define ENCODER_PULSE_COUNT 6 /*10*/ // 6
  14. #define MOTOR_GEAR_RATIO 150
  15. #define ENCODER_PULSE_COUNT 1
  16. #define ENCODER_PULSE_HIRES_COUNT (LGS_PULSE_COUNT / MOTOR_GEAR_RATIO)
  17. #define ENCODER_PULSE_HIRES_REMAIN (LGS_PULSE_COUNT % MOTOR_GEAR_RATIO)
  18. #define HIRES_MEASUREMENT_START_TIME 100
  19. #endif
  20. //#define ISA_DEFAULT_MODE_READ_BUS
  21. sbit ISA_IOW = P3^7;
  22. sbit ISA_IOR = P3^6;
  23. sbit ISA_IOCHRDY = P3^5;
  24. sbit ISA_AEN = P3^4;
  25. sbit ISA_IRQ5 = P1^0;
  26. sbit ISA_BUFFER_OE = P4^6;
  27. sbit ISA_BUFFER_DIR = P4^7; // if low then A = B (ISA = MCU)
  28. sbit ENCODER_PhA = P2^4;
  29. sbit ENCODER_PhB = P2^5;
  30. sbit ENCODER_ZERO = P2^6;
  31. sbit DRY_CONTACT_1 = P1^6;
  32. sbit DRY_CONTACT_2 = P1^7;
  33. sbit LRF_ENABLE = P0^7;
  34. sbit LRF_READY = P2^2;
  35. sbit LRF_SUN_1 = P2^1;
  36. sbit LRF_SUN_2 = P2^0;
  37. sbit HEATER_ENABLE = P0^6;
  38. #define ISA_DIR_IOCHRDY P3MDOUT
  39. #define ISA_DIR_IRQ5 P1MDOUT
  40. #define DRY_CONTACT_DIR P1MDOUT
  41. #define ISA_REGISTER_COUNT 16
  42. // fast variables
  43. static BYTE ISA_bRegEnable = 0;
  44. static BYTE ISA_bRegIndex = 0;
  45. static BYTE ISA_pRegValue[ISA_REGISTER_COUNT];
  46. static BYTE ISA_bTxAddress;
  47. static BYTE ISA_bTxData4[2] = {0};
  48. static BYTE ISA_bTxData5[2] = {0};
  49. static BYTE ISA_bTxIndex = 0;
  50. static BYTE ISA_bAccessCount= 0;
  51. CBYTE ISA_BitReverseTable256[] =
  52. {
  53. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  54. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  55. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  56. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  57. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  58. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  59. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  60. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  61. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  62. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  63. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  64. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  65. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  66. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  67. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  68. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  69. };
  70. // slow variables
  71. static BOOL bZero = TRUE;
  72. static BOOL bZeroCheck = TRUE;
  73. #ifdef ENCODER_6000_PULSES
  74. static BYTE bPhaseStateAB = 0;
  75. #else
  76. static BOOL bReadyZero = FALSE;
  77. static INT nAngle = 0;
  78. static WORD nPulseTime = MICRO_SEC_TO_HIRES(160L);
  79. static BOOL bPhaseCheck = TRUE;
  80. static INT nAngle6 = 0;
  81. static BOOL bReady6 = FALSE;
  82. static INT nPulseCount = 0;
  83. static WORD nHiResolutionCount = 0;
  84. static WORD nHiResolutionTemp = 0;
  85. static DWORD nHiResolutionTimer = 0;
  86. static BYTE nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  87. #endif
  88. static BOOL bReset = TRUE;
  89. static UNION_WORD wRange1 = {0};
  90. static UNION_WORD wRange2 = {0};
  91. static WORD wTemperature = 0;
  92. static BOOL bSun1 = FALSE;
  93. static BOOL bSun2 = FALSE;
  94. static INT nZeroShift = 0;
  95. #ifdef TEMPERATURE_ENABLE
  96. static WORD wTemperatureON = 0;
  97. static WORD wTemperatureOFF = 0;
  98. #endif
  99. static BYTE bTemp;
  100. static XBYTE pRelayBuffer[32];
  101. static INT nRelayBuffer = 0;
  102. void ISA_Init()
  103. {
  104. // init fast variables
  105. ISA_bRegEnable = 0;
  106. ISA_bTxIndex = 0;
  107. ISA_bAccessCount = 0;
  108. // init slow variables
  109. bZero = FALSE;
  110. bZeroCheck = TRUE;
  111. #ifdef ENCODER_6000_PULSES
  112. bPhaseStateAB = 0;
  113. #else
  114. bReadyZero = FALSE;
  115. nPulseTime = MICRO_SEC_TO_HIRES(160L);
  116. nAngle = 0;
  117. bPhaseCheck = TRUE;
  118. nAngle6 = 0;
  119. bReady6 = FALSE;
  120. nPulseCount = 0;
  121. nHiResolutionCount = 0;
  122. nHiResolutionTemp = 0;
  123. nHiResolutionTimer = 0;
  124. nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  125. #endif
  126. wRange1.wValue = 0;
  127. wRange2.wValue = 0;
  128. wTemperature = 0;
  129. bSun1 = FALSE;
  130. bSun2 = FALSE;
  131. bReset = TRUE;
  132. }
  133. void ISA_Serve()
  134. {
  135. // init DAC0
  136. SFRPAGE = DAC0_PAGE;
  137. DAC0L = 0xFF;
  138. DAC0H = 0xFF;
  139. DAC0CN = 0x80;
  140. SFRPAGE = CONFIG_PAGE;
  141. #ifdef TEMPERATURE_ENABLE
  142. // heater control
  143. P0MDOUT |= (1<<6);
  144. HEATER_ENABLE = TRUE;
  145. #endif
  146. // clear LRF
  147. P0MDOUT |= (1<<7);
  148. LRF_ENABLE = FALSE;
  149. // clear dry contacts
  150. DRY_CONTACT_DIR |= (1<<6);
  151. DRY_CONTACT_DIR |= (1<<7);
  152. DRY_CONTACT_1 = TRUE;
  153. DRY_CONTACT_2 = TRUE;
  154. // clear IRQ5
  155. ISA_DIR_IRQ5 |= (1<<0);
  156. ISA_IRQ5 = 0;
  157. // set ISA data as output
  158. #ifdef ISA_DEFAULT_MODE_READ_BUS
  159. P7MDOUT = 0x00; // set P7 as input
  160. P7 = 0xFF;
  161. #else
  162. P7MDOUT = 0xFF; // set P7 as output
  163. P7 = 0x00;
  164. #endif
  165. #ifndef ENCODER_6000_PULSES
  166. // init HI resolution timer
  167. nHiResolutionCount = HiResTimer0_Get();
  168. nHiResolutionTimer = 0;
  169. nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  170. // restart IRQ timer
  171. HiResTimer1_Restart( -nPulseTime );
  172. #endif
  173. while( TRUE )
  174. {
  175. // process ISA requests
  176. if( ISA_AEN == 0 && P5 == 0x03 )
  177. {
  178. ISA_DIR_IOCHRDY |= (1<<5);
  179. ISA_IOCHRDY = 0; // hold bus circle
  180. if( ISA_IOR == 0 )
  181. {
  182. if( P6 == 0x04 || P6 == 0x05 || P6 == 0x09 )
  183. {
  184. ISA_IRQ5 = 0; // clear interrupt
  185. #ifdef ISA_DEFAULT_MODE_READ_BUS
  186. P7MDOUT = 0xFF; // set P7 as output
  187. #endif
  188. ISA_BUFFER_DIR = 0; // set DIR to write to bus
  189. ISA_BUFFER_OE = 0; // set OE low to enable buffer
  190. switch( P6 )
  191. {
  192. case 0x04: P7 = ISA_bTxData4[ISA_bTxIndex]; break;
  193. case 0x05: P7 = ISA_bTxData5[ISA_bTxIndex++]; break;
  194. case 0x09: P7 = 0x5A; break;
  195. }
  196. ISA_IOCHRDY = 1; // ready to end of bus circle
  197. ISA_DIR_IOCHRDY &= ~(1<<5);
  198. if( ISA_bAccessCount ) // decrease access count
  199. ISA_bAccessCount--;
  200. while( ISA_IOR == 0 ); // wait end of bus circle
  201. ISA_BUFFER_OE = 1; // set OE high to Z-state the buffer
  202. #ifdef ISA_DEFAULT_MODE_READ_BUS
  203. P7MDOUT = 0x00; // set P7 as input
  204. P7 = 0xFF;
  205. #endif
  206. }
  207. }
  208. else
  209. if( ISA_IOW == 0 )
  210. {
  211. if( P6 == 0x06 || P6 == 0x07 || P6 == 0x08 )
  212. {
  213. ISA_IRQ5 = 0; // clear interrupt
  214. #ifndef ISA_DEFAULT_MODE_READ_BUS
  215. P7MDOUT = 0x00; // set P7 as input
  216. P7 = 0xFF;
  217. #endif
  218. ISA_BUFFER_DIR = 1; // set DIR to read from bus
  219. ISA_BUFFER_OE = 0; // set OE low to enable buffer
  220. switch( P6 )
  221. {
  222. case 0x06: bTemp = P7; bReset = (bTemp ^ ISA_bRegEnable) & 0xC0; ISA_bRegEnable = bTemp; break;
  223. case 0x07: ISA_bRegIndex = ISA_BitReverseTable256[P7] & (ISA_REGISTER_COUNT-1); bReset = TRUE; break;
  224. case 0x08: ISA_pRegValue[ISA_bRegIndex] = ISA_BitReverseTable256[P7]; bReset = TRUE; break;
  225. }
  226. #ifndef ISA_DEFAULT_MODE_READ_BUS
  227. P7MDOUT = 0xFF; // set P7 as output
  228. #endif
  229. ISA_BUFFER_OE = 1; // set OE high to Z-state the buffer
  230. }
  231. }
  232. ISA_IOCHRDY = 1; // ready to end of bus circle
  233. ISA_DIR_IOCHRDY &= ~(1<<5);
  234. }
  235. #ifdef ENCODER_6000_PULSES
  236. #define PHASE_STATE_AB_MASK ((1<<4)|(1<<5))
  237. // wait for phase change
  238. if( (P2 & PHASE_STATE_AB_MASK) == bPhaseStateAB )
  239. continue;
  240. bPhaseStateAB = P2 & PHASE_STATE_AB_MASK;
  241. #else
  242. // wait for end of ISA serving circle
  243. SFRPAGE = TIMER01_PAGE;
  244. if( !TF1 )
  245. {
  246. SFRPAGE = CONFIG_PAGE;
  247. continue;
  248. }
  249. TF1 = 0;
  250. SFRPAGE = CONFIG_PAGE;
  251. #endif
  252. // if interrupt no LRF is enabled
  253. if( (ISA_bRegEnable & 0xC0) == 0 )
  254. continue;
  255. // reset encoder and timeouts
  256. if( bReset )
  257. {
  258. bReset = FALSE;
  259. ISA_bAccessCount = 0;
  260. ISA_IRQ5 = 0;
  261. bZero = FALSE;
  262. bZeroCheck = TRUE;
  263. #ifndef ENCODER_6000_PULSES
  264. bReadyZero = FALSE;
  265. nAngle = 0;
  266. nPulseTime = MICRO_SEC_TO_HIRES(160L);
  267. bPhaseCheck = TRUE;
  268. nAngle6 = 0;
  269. bReady6 = FALSE;
  270. nPulseCount = 0;
  271. nHiResolutionCount = 0;
  272. nHiResolutionTemp = 0;
  273. nHiResolutionTimer = 0;
  274. nHiResolutionStart = HIRES_MEASUREMENT_START_TIME;
  275. #endif
  276. nZeroShift = ((WORD)ISA_pRegValue[5] << 8) | ISA_pRegValue[6];
  277. #ifdef TEMPERATURE_ENABLE
  278. wTemperatureON = ADC0_Temperature2Adc( (((LONG)(CHAR)ISA_pRegValue[4]) ) * 10L );
  279. wTemperatureOFF = ADC0_Temperature2Adc( (((LONG)(CHAR)ISA_pRegValue[4]) + 1L) * 10L );
  280. #endif
  281. wRange1.wValue = 0;
  282. wRange2.wValue = 0;
  283. bSun1 = 0;
  284. bSun2 = 0;
  285. }
  286. #ifndef ENCODER_6000_PULSES
  287. // reset IRQ timer
  288. HiResTimer1_Restart( -nPulseTime );
  289. // calculate hi resolution time
  290. nHiResolutionTemp = HiResTimer0_Get();
  291. nHiResolutionTimer += (DWORD)(nHiResolutionTemp - nHiResolutionCount);
  292. nHiResolutionCount = nHiResolutionTemp;
  293. #endif
  294. // produce zero mark (very importent to syncronize zero mark with encoder positions)
  295. if( ENCODER_ZERO )
  296. {
  297. if( bZeroCheck )
  298. {
  299. bZeroCheck = FALSE;
  300. bZero = TRUE;
  301. #ifndef ENCODER_6000_PULSES
  302. bReadyZero = TRUE;
  303. nAngle = 0;
  304. #endif
  305. }
  306. }
  307. else
  308. bZeroCheck = TRUE;
  309. #ifndef ENCODER_6000_PULSES
  310. // move motor angle
  311. if( ENCODER_PhA )
  312. {
  313. if( bPhaseCheck )
  314. {
  315. bPhaseCheck = FALSE;
  316. // find synch point
  317. if( ++nAngle6 == ENCODER_PULSE_COUNT )
  318. {
  319. nAngle6 = 0;
  320. bReady6 = TRUE;
  321. // calculate amount of angles until next sync point
  322. nPulseCount += ENCODER_PULSE_HIRES_REMAIN;
  323. if( nPulseCount >= MOTOR_GEAR_RATIO )
  324. {
  325. nPulseCount -= MOTOR_GEAR_RATIO;
  326. nPulseTime = nHiResolutionTimer / ( ENCODER_PULSE_HIRES_COUNT - 1 );
  327. }
  328. else
  329. nPulseTime = nHiResolutionTimer / ( ENCODER_PULSE_HIRES_COUNT + 1 ); // changed to +1 from 0 for 6000, in 362 should be 0!!!
  330. // validate time measurement
  331. if( nHiResolutionStart )
  332. {
  333. nHiResolutionStart--;
  334. if( nPulseTime > MICRO_SEC_TO_HIRES(200L) ) // 3 kHz
  335. nPulseTime = MICRO_SEC_TO_HIRES(200L);
  336. }
  337. else
  338. {
  339. if( nPulseTime > MICRO_SEC_TO_HIRES(400L) ) // 2.5 kHz
  340. nPulseTime = MICRO_SEC_TO_HIRES(400L);
  341. }
  342. nHiResolutionTimer = 0;
  343. // update DAC according to speed
  344. SFRPAGE = DAC0_PAGE;
  345. // DAC0L = nPulseTime << 2;
  346. // DAC0H = nPulseTime >> 6;
  347. DAC0L = nPulseTime << 3;
  348. DAC0H = nPulseTime >> 7;
  349. SFRPAGE = CONFIG_PAGE;
  350. }
  351. }
  352. }
  353. else
  354. bPhaseCheck = TRUE;
  355. #endif
  356. // set dry contacts
  357. DRY_CONTACT_1 = (ISA_bRegEnable & 0x10) != 0x10;
  358. DRY_CONTACT_2 = (ISA_bRegEnable & 0x20) != 0x20;
  359. // continue to search for zero mark and 6 angles
  360. #ifndef ENCODER_6000_PULSES
  361. if( !bReadyZero || !bReady6 )
  362. continue;
  363. // check zero mark
  364. bZero = (nZeroShift == nAngle);
  365. // move angle
  366. nAngle++;
  367. if( nAngle > LGS_PULSE_COUNT )
  368. continue;
  369. #endif
  370. // if not all data were processed than stop interrupt generation
  371. if( ISA_bAccessCount )
  372. {
  373. ISA_IRQ5 = 0;
  374. ISA_bAccessCount = 0;
  375. ISA_bRegEnable &= ~0xC0;
  376. continue;
  377. }
  378. // start LRF (and temperature measurenment)
  379. LRF_ENABLE = TRUE;
  380. wTemperature = ADC0_Convert( 0x0F );
  381. LRF_ENABLE = FALSE;
  382. // wait for LRF ready (around 15 uS)
  383. // HiResTimer0_Wait( MICRO_SEC_TO_HIRES(15) ); // 20 - ok, but 25 probably better
  384. #ifdef ENCODER_6000_PULSES
  385. HiResTimer1_Wait( 28+5+15+10 ); // +10 added 2006/11/08
  386. #else
  387. HiResTimer1_Wait( 28+5+10 ); // +10 added 2006/11/08
  388. #endif
  389. // convert ranges
  390. if( (ISA_bRegEnable & 0x80) == 0x80 )
  391. {
  392. wRange1.wValue = ADC0_Convert( 0x00 );
  393. bSun1 = !LRF_SUN_1;
  394. }
  395. if( (ISA_bRegEnable & 0x40) == 0x40 )
  396. {
  397. wRange2.wValue = ADC0_Convert( 0x01 );
  398. bSun2 = !LRF_SUN_2;
  399. }
  400. #ifdef TEMPERATURE_ENABLE
  401. // heater control
  402. if( HEATER_ENABLE )
  403. {
  404. if( wTemperature < wTemperatureON )
  405. HEATER_ENABLE = FALSE;
  406. }
  407. else
  408. {
  409. // histeresis - one degree of Celsius
  410. if( wTemperature > wTemperatureOFF )
  411. HEATER_ENABLE = TRUE;
  412. }
  413. #endif
  414. #ifdef SPIKES_TEST
  415. if( nAngle & 0x100 )
  416. {
  417. wRange1.wValue = 0x0FFF / 2;
  418. wRange2.wValue = 0x0FFF / 4;
  419. }
  420. else
  421. {
  422. wRange1.wValue = 0x0FFF / 4;
  423. wRange2.wValue = 0x0FFF / 2;
  424. }
  425. #endif
  426. // ranges will be negatived on PC side
  427. wRange1.wValue = 0x0FFF - wRange1.wValue;
  428. wRange2.wValue = 0x0FFF - wRange2.wValue;
  429. // prepare data for sending to other side
  430. ISA_bTxData4[0] = (ISA_BitReverseTable256[ wRange1.bValue.bLo ] );
  431. ISA_bTxData5[0] = (ISA_BitReverseTable256[ wRange1.bValue.bHi ] & ~0x0F);
  432. ISA_bTxData4[1] = (ISA_BitReverseTable256[ wRange2.bValue.bLo ] );
  433. ISA_bTxData5[1] = (ISA_BitReverseTable256[ wRange2.bValue.bHi ] & ~0x0F);
  434. if( bZero )
  435. {
  436. ISA_bTxData5[0] |= 0x08;
  437. ISA_bTxData5[1] |= 0x08;
  438. bZero = FALSE;
  439. }
  440. if( bSun1 )
  441. {
  442. ISA_bTxData5[0] |= 0x04;
  443. ISA_bTxData5[1] |= 0x04;
  444. }
  445. if( bSun2 )
  446. {
  447. ISA_bTxData5[0] |= 0x02;
  448. ISA_bTxData5[1] |= 0x02;
  449. }
  450. // power OK
  451. ISA_bTxData5[0] |= 0x01;
  452. ISA_bTxData5[1] |= 0x01;
  453. // expected 4 inport reads via ISA bus
  454. ISA_bAccessCount = 4;
  455. ISA_bTxIndex = 0;
  456. // restart ISA bus serve time
  457. ISA_IRQ5 = 1;
  458. }
  459. }