Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //---------------------------------------------------------------------------//
- // DOS Dmp I&O Acess //
- // //
- // 2016 Modification for 6101's PyV //
- // //
- // First 11 Will be LCD Bus //
- // 4 Will be IOS //
- // 2 Will be Leds //
- // //
- // 0-7 D0-D8: P00-P07 //
- // //
- // 8 DI1 : P27 //
- // 9 DI2 : P20 //
- // 10 DO1 : P21 //
- // 11 DO2 : P22 //
- // //
- // 12 DE : P34 //
- // 13 DRW : P35 //
- // 14 DRS : P36 //
- // //
- // 15 LED1 : P26 //
- // 16 LED2 : P25 //
- //---------------------------------------------------------------------------//
- #include <conio.h>
- #include <string.h>
- #include <stdio.h>
- #include <conio.h>
- #include "Terminal.h"
- #include "MThread.h"
- #include "ioacess.h"
- #define INDEX_BYTE1 0x98 // Port 0
- #define INDEX_BYTE3 0x9B // Port 3
- #define INDEX_BYTE2 0x9A // port 2
- #define DATA_BYTE1 0x78 // read Bytes from Port
- #define DATA_BYTE3 0x7B
- #define DATA_BYTE2 0x7A
- void SetIoPins(UCHAR * Definition);
- //--------------------------------- Overal Unique resource ------------------//
- static UCHAR PortA ; // Port One Actual Out value
- static UCHAR PortB ; // Port Two Actual Out value
- static UCHAR PortC ; // Port three Actual Out value
- static UCHAR IODef1 ; // Overall Port Actual I/O Definition (1: Out, 0:In) (24 IOS)
- static UCHAR IODef2 ; // Overall Port Actual I/O Definition
- static UCHAR IODef3 ; // Overall Port Actual I/O Definition
- static AlreadyStart = FALSE; // System On Line
- //---------------------------------------------------------------------------//
- // Overal HW Start //
- // All Start as Inputs //
- //---------------------------------------------------------------------------//
- BOOL StartIolayer( void )
- {
- if (AlreadyStart) return TRUE;
- AlreadyStart = TRUE ;
- printf("Start IO Layer\r\n") ;
- //- Port will be Input -------------//
- //- But Out will be set as 1 //
- PortA = 0 ;
- PortB = 0 ;
- PortC = 0 ;
- IODef1 = 0 ;
- IODef2 = 0 ;
- IODef3 = 0 ;
- SetIoPins("IIIIIIIIIIIIIIIIIIIIIIII");
- MtWait(10ul) ;
- return TRUE ;
- }
- void EndIoLayer( void )
- {
- if (!AlreadyStart) return;
- AlreadyStart = FALSE ;
- SetIoPins("IIIIIIIIIIIIIIIIIIIIIIII");
- MtWait(10ul) ;
- }
- //---------------------------------------------------------------------------//
- // HW I/O Start Definition Of Pins //
- // IODEF = 1, Output, 0 = Input //
- //---------------------------------------------------------------------------//
- void SetIoPins( UCHAR * Definition ) // Set IO Bidireccional Pins 'I' , 'O' , 'X' Don't Care About Bits)
- { UCHAR c,c1,c2 ;
- UCHAR Shiffer ;
- //-------------------------------------------------------------------//
- // Definition of Port 1 : Consecutive IOS //
- //-------------------------------------------------------------------//
- c2 = strlen(Definition) ;
- c1=(c2>8)?8:c2 ;
- for(Shiffer=0x80,c=0;c<c1;c++, Shiffer=Shiffer>>1)
- {
- //----- Now calculate IO mask -------------------------------------
- if (Definition[c]=='O') {IODef1|= Shiffer;PortA|=Shiffer;continue;} // 1 is Output
- if (Definition[c]=='I') {IODef1&=~Shiffer ;continue;} // 0 is Input (make a "Hole")
- }
- //-------------------------------------------------------------------//
- // Definition of Port 2 : Mixed IOS //
- //-------------------------------------------------------------------//
- if (c2<8 ) return ;
- if (c2>17) c2=17 ;
- for(c=8;c<c2;c++)
- {
- //----- Now calculate IO mask -------------------------------------
- if (Definition[c]=='O')
- { switch(c)
- { case 8:IODef2|=0x02;PortB|=0x02; break ; // P21 Set 1 as Output: avlue 1 As Start
- case 9:IODef2|=0x04;PortB|=0x04; break ; // P22
- case 10:IODef2|=0x80;PortB|=0x80; break ; // P27
- case 11:IODef2|=0x01;PortB|=0x01; break ; // P20
- case 12:IODef3|=0x10;PortC|=0x10; break ; // P34
- case 13:IODef3|=0x20;PortC|=0x20; break ; // P35
- case 14:IODef3|=0x40;PortC|=0x40; break ; // P36
- case 15:IODef2|=0x20;PortB|=0x20; break ; // P25
- case 16:IODef2|=0x40;PortB|=0x40; break ; // P26
- }
- continue;
- }
- if (Definition[c]=='I')
- { switch(c)
- { case 8:IODef2&=~0x02; break ; // P21 Set 0 as input
- case 9:IODef2&=~0x04; break ; // P22
- case 10:IODef2&=~0x80; break ; // P27
- case 11:IODef2&=~0x01; break ; // P20
- case 12:IODef3&=~0x10; break ; // P34
- case 13:IODef3&=~0x20; break ; // P35
- case 14:IODef3&=~0x40; break ; // P36
- case 15:IODef2&=~0x20; break ; // P25
- case 16:IODef2&=~0x40; break ; // P26
- }
- continue;
- }
- //--- Other (X, Dont change values --------------------------------
- }
- //-- Now Set Directions & Data at Outputs -----------------------------
- outp(INDEX_BYTE1,IODef1) ;
- outp(DATA_BYTE1 ,PortA ) ;
- MtWait(10ul) ;
- outp(INDEX_BYTE2,IODef2) ;
- outp(DATA_BYTE2 ,PortB ) ;
- MtWait(10ul) ;
- outp(INDEX_BYTE3,IODef3) ;
- outp(DATA_BYTE3 ,PortC ) ;
- MtWait(10ul) ;
- //printf("%s\r\n",Definition) ;
- //printf("Port1_DIR[%02x],OUT[%02x]\r\n",IODef1,PortA) ;
- //printf("Port2_DIR[%02x],OUT[%02x]\r\n",IODef2,PortB) ;
- //printf("Port3_DIR[%02x],OUT[%02x]\r\n",IODef3,PortC) ;
- }
- //---------------------------------------------------------------------------//
- // Access To Bits //
- //---------------------------------------------------------------------------//
- void GetIoData ( UCHAR * Data,BOOL * IoData) // Pins To read "1 read, 0 Non read"
- // Return An Array Of Bools Properlly Filled
- { WORD c,c1,c2 ;
- BOOL B ;
- UCHAR Port1,Port2,Port3 ;
- UCHAR Shiffer ;
- // First Read Data From POrts------------------------------------------------
- Port1 = inp(DATA_BYTE1) ;
- Port2 = inp(DATA_BYTE2) ;
- Port3 = inp(DATA_BYTE3) ;
- c2 = strlen(Data) ;
- for(c=0;c<c2;c++) IoData[c]=FALSE ;
- // Definition of Port 1 -----------------------------------------------------
- c1=(c2>8)?8:c2 ;
- for(Shiffer=0x80,c=0;c<c1;c++, Shiffer=Shiffer>>1)
- { if ( IODef1&Shiffer || Data[c]=='0') IoData[c]=((PortA&Shiffer)!=0); // If defined as Output Or value is 0 (input) get Stored value
- else IoData[c]=((Port1&Shiffer)!=0);
- }
- // Definition of Port 2 (second's 16) ---------------------------------------
- if (c2<8 ) return;
- if (c2>17) c2=17 ;
- for(Shiffer=0x80,c=8;c<c2;c++,Shiffer=Shiffer>>1)
- { switch(c)
- { case 8:B=(IODef2&0x02 || Data[c]=='0')?PortB&0x02:Port2&0x02 ;break; // P21
- case 9:B=(IODef2&0x04 || Data[c]=='0')?PortB&0x04:Port2&0x04 ;break; // P22
- case 10:B=(IODef2&0x80 || Data[c]=='0')?PortB&0x80:Port2&0x80 ;break; // P27
- case 11:B=(IODef2&0x01 || Data[c]=='0')?PortB&0x01:Port2&0x01 ;break; // P20
- case 12:B=(IODef3&0x10 || Data[c]=='0')?PortC&0x10:Port3&0x10 ;break; // P34
- case 13:B=(IODef3&0x20 || Data[c]=='0')?PortC&0x20:Port3&0x20 ;break; // P35
- case 14:B=(IODef3&0x40 || Data[c]=='0')?PortC&0x40:Port3&0x40 ;break; // P36
- case 15:B=(IODef2&0x20 || Data[c]=='0')?PortB&0x20:Port2&0x20 ;break; // P25
- case 16:B=(IODef2&0x40 || Data[c]=='0')?PortB&0x40:Port2&0x40 ;break; // P26
- }
- IoData[c]=(B!=0) ;
- }
- }
- void SetIoData(UCHAR * Data) // Set Io Data 'X' Dont Care '0' or '1'
- { UCHAR c,c1,c2 ;
- UCHAR Shiffer ;
- UCHAR Port1,Port2,Port3;
- c2 = strlen(Data) ;
- Port1 = PortA ;
- Port2 = PortB ;
- Port3 = PortC ;
- // Definition of Port 1 ------------------------------------------------------------
- c1=(c2>8)?8:c2 ;
- for(Shiffer=0x80,c=0;c<c1;c++,Shiffer=Shiffer>>1)
- { if (Data[c]=='0') {PortA&=~Shiffer; continue;} // programming 0 to port
- if (Data[c]=='1') {PortA|= Shiffer; continue;} // programming 1 to port
- }
- // Now for Second Outputs ---------------------------------------------------------
- if (c2<8 ) return; // Not do anything
- if (c2>17) c2=17 ;
- for(c=8;c<c2;c++)
- { switch(c)
- { case 8:if (Data[c]=='0') PortB&=~0x02;else if (Data[c]=='1') PortB|=0x02;break; // P21
- case 9:if (Data[c]=='0') PortB&=~0x04;else if (Data[c]=='1') PortB|=0x04;break; // P22
- case 10:if (Data[c]=='0') PortB&=~0x80;else if (Data[c]=='1') PortB|=0x80;break; // P27
- case 11:if (Data[c]=='0') PortB&=~0x01;else if (Data[c]=='1') PortB|=0x01;break; // P20
- case 12:if (Data[c]=='0') PortC&=~0x10;else if (Data[c]=='1') PortC|=0x10;break; // P34
- case 13:if (Data[c]=='0') PortC&=~0x20;else if (Data[c]=='1') PortC|=0x20;break; // P35
- case 14:if (Data[c]=='0') PortC&=~0x40;else if (Data[c]=='1') PortC|=0x40;break; // P36
- case 15:if (Data[c]=='0') PortB&=~0x20;else if (Data[c]=='1') PortB|=0x20;break; // P25
- case 16:if (Data[c]=='0') PortB&=~0x40;else if (Data[c]=='1') PortB|=0x40;break; // P26
- }
- }
- //- Set Values ---------------------------------------------------------------------
- //printf("Output[%s]\r\n",Data) ;
- if (Port1!=PortA)
- { //printf("P1[%02x]\r\n",PortA) ;
- outp(DATA_BYTE1 ,PortA) ;
- }
- if (Port2!=PortB)
- { //printf("P2[%02x]\r\n",PortB) ;
- outp(DATA_BYTE2 ,PortB) ;
- }
- if (Port3!=PortC)
- { //printf("P3[%02x]\r\n",PortC) ;
- outp(DATA_BYTE3 ,PortC) ;
- }
- }
- //---------------------------------------------------------------------------//
- // Access To Bytes //
- //---------------------------------------------------------------------------//
- //-- This Function Group 8 Bites to 1 Byte To accelerate Process
- //-- at This Moment is a Dummy Function
- WORD GroupIoData(UCHAR * Data) // "Start Bit" -> Assign Virtual Number
- { UCHAR Data1=Data[0] ;
- Data1+= 0 ;
- return 1 ;
- }
- //-- Previos Dummy Function (Continuation) ------------------------
- void SetGroupIoData(WORD Id,UCHAR Data) // Previos Group Number
- { WORD Id1=Id ;
- Id1 += 0 ;
- outp(DATA_BYTE1,Data) ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement