怎樣在BCB下使用inport與outport?
1998-09-13 00:00:00



在標準的Win32平台上inport與outport是不允許的,應該由撰寫驅動程式來達成,但我們可以在Windows 95/98 平台上使用組合語言做到 由於在BCB1時並沒有內建 TASM 而到了BCB3裡若非購買Pro版也沒有提供TASM,但幸好 BCB1 與 BCB3 接保留了 __emit__ 這個函示來讓我們能夠達到不須 TASM 就可以使用組合語言的目的。 若須使用inport與outport則只需加入這個宣告檔案即可

檔案列表 bcbio.h

 
void outportb(unsigned short int port,unsigned char value)
{
__emit__(0x8b,0x95,&port);
//mov edx,*(&port);
__emit__(0x8a,0x85,&value);
//mov al,*(&value);
__emit__(0x66,0xee);
//out dx,al;
}

void outportw(unsigned short int port,unsigned short int value)
{
__emit__(0x8b,0x95,&port);
//mov edx,*(&port);
__emit__(0x66,0x8b,0x85,&value);
//mov ax,*(&value);
__emit__(0xef);
//out dx,ax;
}

char inportb(unsigned short int port)
{
char value;
__emit__(0x8b,0x95,&port);
//mov edx,*(&port);
__emit__(0x66,0xec);
//in al,dx;
__emit__(0x88,0x85,&value);
//mov *(&value),al;
return value;
}

short int inportw(unsigned short int port)
{
short int value;
__emit__(0x8b,0x95,&port);
//mov edx,*(&port);
__emit__(0xed);
//in ax,dx;
__emit__(0x66,0x89,0x85,&value);
//mov *(&value),ax;
return value;
}