Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.24 KB | None | 0 0
  1. //---------------------------------------------------------------------------//
  2. // DOS Dmp I&O Acess //
  3. // //
  4. // 2016 Modification for 6101's PyV //
  5. // //
  6. // First 11 Will be LCD Bus //
  7. // 4 Will be IOS //
  8. // 2 Will be Leds //
  9. // //
  10. // 0-7 D0-D8: P00-P07 //
  11. // //
  12. // 8 DI1 : P27 //
  13. // 9 DI2 : P20 //
  14. // 10 DO1 : P21 //
  15. // 11 DO2 : P22 //
  16. // //
  17. // 12 DE : P34 //
  18. // 13 DRW : P35 //
  19. // 14 DRS : P36 //
  20. // //
  21. // 15 LED1 : P26 //
  22. // 16 LED2 : P25 //
  23. //---------------------------------------------------------------------------//
  24. #include <conio.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include <conio.h>
  28.  
  29. #include "Terminal.h"
  30. #include "MThread.h"
  31. #include "ioacess.h"
  32.  
  33.  
  34. #define INDEX_BYTE1 0x98 // Port 0
  35. #define INDEX_BYTE3 0x9B // Port 3
  36. #define INDEX_BYTE2 0x9A // port 2
  37.  
  38. #define DATA_BYTE1 0x78 // read Bytes from Port
  39. #define DATA_BYTE3 0x7B
  40. #define DATA_BYTE2 0x7A
  41.  
  42. void SetIoPins(UCHAR * Definition);
  43.  
  44. //--------------------------------- Overal Unique resource ------------------//
  45. static UCHAR PortA ; // Port One Actual Out value
  46. static UCHAR PortB ; // Port Two Actual Out value
  47. static UCHAR PortC ; // Port three Actual Out value
  48.  
  49. static UCHAR IODef1 ; // Overall Port Actual I/O Definition (1: Out, 0:In) (24 IOS)
  50. static UCHAR IODef2 ; // Overall Port Actual I/O Definition
  51. static UCHAR IODef3 ; // Overall Port Actual I/O Definition
  52.  
  53. static AlreadyStart = FALSE; // System On Line
  54.  
  55. //---------------------------------------------------------------------------//
  56. // Overal HW Start //
  57. // All Start as Inputs //
  58. //---------------------------------------------------------------------------//
  59. BOOL StartIolayer( void )
  60. {
  61. if (AlreadyStart) return TRUE;
  62.  
  63. AlreadyStart = TRUE ;
  64. printf("Start IO Layer\r\n") ;
  65.  
  66. //- Port will be Input -------------//
  67. //- But Out will be set as 1 //
  68. PortA = 0 ;
  69. PortB = 0 ;
  70. PortC = 0 ;
  71. IODef1 = 0 ;
  72. IODef2 = 0 ;
  73. IODef3 = 0 ;
  74. SetIoPins("IIIIIIIIIIIIIIIIIIIIIIII");
  75. MtWait(10ul) ;
  76. return TRUE ;
  77. }
  78.  
  79. void EndIoLayer( void )
  80. {
  81. if (!AlreadyStart) return;
  82. AlreadyStart = FALSE ;
  83. SetIoPins("IIIIIIIIIIIIIIIIIIIIIIII");
  84. MtWait(10ul) ;
  85. }
  86.  
  87. //---------------------------------------------------------------------------//
  88. // HW I/O Start Definition Of Pins //
  89. // IODEF = 1, Output, 0 = Input //
  90. //---------------------------------------------------------------------------//
  91. void SetIoPins( UCHAR * Definition ) // Set IO Bidireccional Pins 'I' , 'O' , 'X' Don't Care About Bits)
  92. { UCHAR c,c1,c2 ;
  93. UCHAR Shiffer ;
  94.  
  95. //-------------------------------------------------------------------//
  96. // Definition of Port 1 : Consecutive IOS //
  97. //-------------------------------------------------------------------//
  98. c2 = strlen(Definition) ;
  99. c1=(c2>8)?8:c2 ;
  100. for(Shiffer=0x80,c=0;c<c1;c++, Shiffer=Shiffer>>1)
  101. {
  102. //----- Now calculate IO mask -------------------------------------
  103. if (Definition[c]=='O') {IODef1|= Shiffer;PortA|=Shiffer;continue;} // 1 is Output
  104. if (Definition[c]=='I') {IODef1&=~Shiffer ;continue;} // 0 is Input (make a "Hole")
  105. }
  106.  
  107. //-------------------------------------------------------------------//
  108. // Definition of Port 2 : Mixed IOS //
  109. //-------------------------------------------------------------------//
  110. if (c2<8 ) return ;
  111. if (c2>17) c2=17 ;
  112. for(c=8;c<c2;c++)
  113. {
  114. //----- Now calculate IO mask -------------------------------------
  115. if (Definition[c]=='O')
  116. { switch(c)
  117. { case 8:IODef2|=0x02;PortB|=0x02; break ; // P21 Set 1 as Output: avlue 1 As Start
  118. case 9:IODef2|=0x04;PortB|=0x04; break ; // P22
  119. case 10:IODef2|=0x80;PortB|=0x80; break ; // P27
  120. case 11:IODef2|=0x01;PortB|=0x01; break ; // P20
  121. case 12:IODef3|=0x10;PortC|=0x10; break ; // P34
  122. case 13:IODef3|=0x20;PortC|=0x20; break ; // P35
  123. case 14:IODef3|=0x40;PortC|=0x40; break ; // P36
  124. case 15:IODef2|=0x20;PortB|=0x20; break ; // P25
  125. case 16:IODef2|=0x40;PortB|=0x40; break ; // P26
  126. }
  127. continue;
  128. }
  129.  
  130. if (Definition[c]=='I')
  131. { switch(c)
  132. { case 8:IODef2&=~0x02; break ; // P21 Set 0 as input
  133. case 9:IODef2&=~0x04; break ; // P22
  134. case 10:IODef2&=~0x80; break ; // P27
  135. case 11:IODef2&=~0x01; break ; // P20
  136. case 12:IODef3&=~0x10; break ; // P34
  137. case 13:IODef3&=~0x20; break ; // P35
  138. case 14:IODef3&=~0x40; break ; // P36
  139. case 15:IODef2&=~0x20; break ; // P25
  140. case 16:IODef2&=~0x40; break ; // P26
  141. }
  142. continue;
  143. }
  144.  
  145. //--- Other (X, Dont change values --------------------------------
  146. }
  147.  
  148. //-- Now Set Directions & Data at Outputs -----------------------------
  149. outp(INDEX_BYTE1,IODef1) ;
  150. outp(DATA_BYTE1 ,PortA ) ;
  151. MtWait(10ul) ;
  152.  
  153. outp(INDEX_BYTE2,IODef2) ;
  154. outp(DATA_BYTE2 ,PortB ) ;
  155. MtWait(10ul) ;
  156.  
  157. outp(INDEX_BYTE3,IODef3) ;
  158. outp(DATA_BYTE3 ,PortC ) ;
  159. MtWait(10ul) ;
  160.  
  161. //printf("%s\r\n",Definition) ;
  162. //printf("Port1_DIR[%02x],OUT[%02x]\r\n",IODef1,PortA) ;
  163. //printf("Port2_DIR[%02x],OUT[%02x]\r\n",IODef2,PortB) ;
  164. //printf("Port3_DIR[%02x],OUT[%02x]\r\n",IODef3,PortC) ;
  165. }
  166.  
  167. //---------------------------------------------------------------------------//
  168. // Access To Bits //
  169. //---------------------------------------------------------------------------//
  170. void GetIoData ( UCHAR * Data,BOOL * IoData) // Pins To read "1 read, 0 Non read"
  171. // Return An Array Of Bools Properlly Filled
  172. { WORD c,c1,c2 ;
  173. BOOL B ;
  174. UCHAR Port1,Port2,Port3 ;
  175. UCHAR Shiffer ;
  176.  
  177. // First Read Data From POrts------------------------------------------------
  178. Port1 = inp(DATA_BYTE1) ;
  179. Port2 = inp(DATA_BYTE2) ;
  180. Port3 = inp(DATA_BYTE3) ;
  181.  
  182. c2 = strlen(Data) ;
  183. for(c=0;c<c2;c++) IoData[c]=FALSE ;
  184.  
  185. // Definition of Port 1 -----------------------------------------------------
  186. c1=(c2>8)?8:c2 ;
  187. for(Shiffer=0x80,c=0;c<c1;c++, Shiffer=Shiffer>>1)
  188. { if ( IODef1&Shiffer || Data[c]=='0') IoData[c]=((PortA&Shiffer)!=0); // If defined as Output Or value is 0 (input) get Stored value
  189. else IoData[c]=((Port1&Shiffer)!=0);
  190.  
  191. }
  192.  
  193. // Definition of Port 2 (second's 16) ---------------------------------------
  194. if (c2<8 ) return;
  195. if (c2>17) c2=17 ;
  196. for(Shiffer=0x80,c=8;c<c2;c++,Shiffer=Shiffer>>1)
  197. { switch(c)
  198. { case 8:B=(IODef2&0x02 || Data[c]=='0')?PortB&0x02:Port2&0x02 ;break; // P21
  199. case 9:B=(IODef2&0x04 || Data[c]=='0')?PortB&0x04:Port2&0x04 ;break; // P22
  200. case 10:B=(IODef2&0x80 || Data[c]=='0')?PortB&0x80:Port2&0x80 ;break; // P27
  201. case 11:B=(IODef2&0x01 || Data[c]=='0')?PortB&0x01:Port2&0x01 ;break; // P20
  202. case 12:B=(IODef3&0x10 || Data[c]=='0')?PortC&0x10:Port3&0x10 ;break; // P34
  203. case 13:B=(IODef3&0x20 || Data[c]=='0')?PortC&0x20:Port3&0x20 ;break; // P35
  204. case 14:B=(IODef3&0x40 || Data[c]=='0')?PortC&0x40:Port3&0x40 ;break; // P36
  205. case 15:B=(IODef2&0x20 || Data[c]=='0')?PortB&0x20:Port2&0x20 ;break; // P25
  206. case 16:B=(IODef2&0x40 || Data[c]=='0')?PortB&0x40:Port2&0x40 ;break; // P26
  207. }
  208. IoData[c]=(B!=0) ;
  209. }
  210. }
  211.  
  212. void SetIoData(UCHAR * Data) // Set Io Data 'X' Dont Care '0' or '1'
  213. { UCHAR c,c1,c2 ;
  214. UCHAR Shiffer ;
  215. UCHAR Port1,Port2,Port3;
  216.  
  217. c2 = strlen(Data) ;
  218. Port1 = PortA ;
  219. Port2 = PortB ;
  220. Port3 = PortC ;
  221.  
  222. // Definition of Port 1 ------------------------------------------------------------
  223. c1=(c2>8)?8:c2 ;
  224. for(Shiffer=0x80,c=0;c<c1;c++,Shiffer=Shiffer>>1)
  225. { if (Data[c]=='0') {PortA&=~Shiffer; continue;} // programming 0 to port
  226. if (Data[c]=='1') {PortA|= Shiffer; continue;} // programming 1 to port
  227. }
  228.  
  229. // Now for Second Outputs ---------------------------------------------------------
  230. if (c2<8 ) return; // Not do anything
  231. if (c2>17) c2=17 ;
  232. for(c=8;c<c2;c++)
  233. { switch(c)
  234. { case 8:if (Data[c]=='0') PortB&=~0x02;else if (Data[c]=='1') PortB|=0x02;break; // P21
  235. case 9:if (Data[c]=='0') PortB&=~0x04;else if (Data[c]=='1') PortB|=0x04;break; // P22
  236. case 10:if (Data[c]=='0') PortB&=~0x80;else if (Data[c]=='1') PortB|=0x80;break; // P27
  237. case 11:if (Data[c]=='0') PortB&=~0x01;else if (Data[c]=='1') PortB|=0x01;break; // P20
  238. case 12:if (Data[c]=='0') PortC&=~0x10;else if (Data[c]=='1') PortC|=0x10;break; // P34
  239. case 13:if (Data[c]=='0') PortC&=~0x20;else if (Data[c]=='1') PortC|=0x20;break; // P35
  240. case 14:if (Data[c]=='0') PortC&=~0x40;else if (Data[c]=='1') PortC|=0x40;break; // P36
  241. case 15:if (Data[c]=='0') PortB&=~0x20;else if (Data[c]=='1') PortB|=0x20;break; // P25
  242. case 16:if (Data[c]=='0') PortB&=~0x40;else if (Data[c]=='1') PortB|=0x40;break; // P26
  243. }
  244. }
  245.  
  246. //- Set Values ---------------------------------------------------------------------
  247. //printf("Output[%s]\r\n",Data) ;
  248.  
  249. if (Port1!=PortA)
  250. { //printf("P1[%02x]\r\n",PortA) ;
  251. outp(DATA_BYTE1 ,PortA) ;
  252. }
  253.  
  254. if (Port2!=PortB)
  255. { //printf("P2[%02x]\r\n",PortB) ;
  256. outp(DATA_BYTE2 ,PortB) ;
  257. }
  258.  
  259. if (Port3!=PortC)
  260. { //printf("P3[%02x]\r\n",PortC) ;
  261. outp(DATA_BYTE3 ,PortC) ;
  262. }
  263. }
  264.  
  265.  
  266. //---------------------------------------------------------------------------//
  267. // Access To Bytes //
  268. //---------------------------------------------------------------------------//
  269.  
  270. //-- This Function Group 8 Bites to 1 Byte To accelerate Process
  271. //-- at This Moment is a Dummy Function
  272. WORD GroupIoData(UCHAR * Data) // "Start Bit" -> Assign Virtual Number
  273. { UCHAR Data1=Data[0] ;
  274. Data1+= 0 ;
  275.  
  276. return 1 ;
  277. }
  278.  
  279. //-- Previos Dummy Function (Continuation) ------------------------
  280. void SetGroupIoData(WORD Id,UCHAR Data) // Previos Group Number
  281. { WORD Id1=Id ;
  282. Id1 += 0 ;
  283.  
  284. outp(DATA_BYTE1,Data) ;
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement