⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io-edit.c

📁 在DOS下进行IO端口查看的小软件
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

extern unsigned long inport32(unsigned int);
extern void outport32(unsigned int,unsigned long int);

command_line(int argc, char *argv[])
{
  unsigned int port,data8,data16,a,qty;
  unsigned long int data32;
  char *endptr;
if(!((argv[2][0]=='1'||argv[2][0]=='2'||argv[2][0]=='4')&&argc==5&&argv[1][0]=='-'&&(argv[1][1]=='r'||argv[1][1]=='w')))
  {
   printf("IO PORT Editor 1.0,  Program by EMDI-RMA-FA of FOXCONN Group, 2008.07.29");
   printf("\n\nusage: ioport -r  [width[1||2||4]] [start port address] [qty]");
   printf("\nexample: ioport -r 4 ed08 a4");
   printf("\nusage: ioport -w  [width[1||2||4]] [port address] [value]");
   printf("\nexample: ioport -w 2 8fd0 f98d");
   exit(1);
  }
port=strtol(argv[3],&endptr,16);

if(argv[1][1]=='r')
{
 qty=strtol(argv[4],&endptr,16);
 if(argv[2][0]=='1')
   {
    for(a=port;port<a+qty;port+=1)
    {
    data8=inportb(port);
    printf("\n%04x:  %02x",port,data8);
    }
    exit(0);
    }

  if(argv[2][0]=='2')
   {
    for(a=port;port<a+qty;port+=2)
    {
    data16=inport(port);
    printf("\n%04x: %04x",port,data16);
    }
    exit(0);
    }
  if(argv[2][0]=='4')
   {
    for(a=port;port<a+qty;port+=4)
    {
    data32=inport32(port);
    printf("\n%04x: %08lx",port,data32);
    }
    exit(0);
    }
}
if(argv[1][1]=='w')
   {
    if(argv[2][0]=='1')
       {
	data8=strtol(argv[4],&endptr,16);
	outportb(port,data8);
	exit(0);
       }
    if(argv[2][0]=='2')
       {
	data16=strtol(argv[4],&endptr,16);
	outport(port,data16);
	exit(0);
       }
    if(argv[2][0]=='4')
       {
	data32=strtol(argv[4],&endptr,16);
	outport32(port,data32);
	exit(0);
       }
   }
return 0;
}

unsigned int start_address,end_address,width,byte_buffer[16*16],word_buffer[16*16];
unsigned long int dword_buffer[4*16];
unsigned int current_port,current_bit,end_port,end_x,end_y;
struct dword_
{
   unsigned int address;
   unsigned long int value;
   unsigned int y;
   unsigned int start_x;
   unsigned int end_x;

} port_bit32_value[4*16];

struct word_
{
   unsigned int address;
   unsigned int value;
   unsigned int y;
   unsigned int start_x;
   unsigned int end_x;

} port_bit16_value[8*16];

struct byte_
{
   unsigned int address;
   unsigned int value;
   unsigned int y;
   unsigned int start_x;
   unsigned int end_x;

} port_bit8_value[16*16];
            
unsigned int get_start_address(void)
{
 window(16,3,20,3);
 textattr(128+(BLUE<<4)+RED);
 clrscr();
 scanf("%x",&start_address);
}

unsigned int get_end_address(void)
{
 window(44,3,48,3);
 textattr(128+(BLUE<<4)+RED);
 clrscr();
 scanf("%x",&end_address);
}

unsigned int get_width(void)
{
 for(width=0;(width!=1) && (width!=2) && (width!=4);)
 {
  window(66,3,67,3);
  textattr(128+(BLUE<<4)+RED);
  clrscr();
  scanf("%x",&width);
 }
}

read_byte_page(void)
{
   unsigned int temp;
   if(end_address-start_address>=256) end_address=start_address+255;
   for(temp=0;start_address+temp<=end_address;temp++)
   {
      port_bit8_value[temp].address=start_address+temp;
      port_bit8_value[temp].value=inportb(start_address+temp);
      port_bit8_value[temp].y=temp/16+1;
      port_bit8_value[temp].start_x= (temp%16)*4+1+(temp%16>=8)*2;
      port_bit8_value[temp].end_x= (temp%16)*4+1+(temp%16>=8)*2+1;
   }
   end_x=port_bit8_value[temp-1].end_x;
   end_y=port_bit8_value[temp-1].y;
   end_port=temp-1;
}

read_word_page(void)
{
   unsigned int temp;
   if(end_address-start_address>=256) end_address=start_address+255;
   for(temp=0;start_address+temp*2<=end_address;temp++)
   {
      port_bit16_value[temp].address=start_address+temp*2;
      port_bit16_value[temp].value=inport(start_address+temp*2);
      port_bit16_value[temp].y=temp/8+1;
      port_bit16_value[temp].start_x= (temp%8)*6+1+(temp%8>=4)*2;
      port_bit16_value[temp].end_x= (temp%8)*6+1+(temp%8>=4)*2+3;
   }
   end_x=port_bit16_value[temp-1].end_x;
   end_y=port_bit16_value[temp-1].y;
   end_port=temp-1; 
}

read_dword_page(void)
{
   unsigned int temp;
   if(end_address-start_address>=256) end_address=start_address+255;
   for(temp=0;start_address+temp*4<=end_address;temp++)
   {
      port_bit32_value[temp].address=start_address+temp*4;
      port_bit32_value[temp].value=inport32(start_address+temp*4);
      port_bit32_value[temp].y=temp/4+1;
      port_bit32_value[temp].start_x= (temp%4)*10+1+(temp%4>=2)*2;
      port_bit32_value[temp].end_x= (temp%4)*10+1+(temp%4>=2)*2+7;
   }
   end_x=port_bit32_value[temp-1].end_x;
   end_y=port_bit32_value[temp-1].y;
   end_port=temp-1; 
}

disp_byte_page(void)
{
 unsigned int temp;
 window(1,5,80,23);
 textbackground(BLUE);
 textcolor(WHITE);
 clrscr();
 cprintf("     X : 0   1   2   3   4   5   6   7     8   9   a   b   c   d   e   f");

 window(1,6,8,23);
 textbackground(BLUE);
 textcolor(WHITE);
 clrscr();
 for(temp=0;start_address+temp<=end_address;temp+=16)
 {
  cprintf(" %4x:\n\r",start_address+temp);   /* printer all address */
 }

 window(9,6,73,21);
 textbackground(WHITE);
 textcolor(BLACK);
 clrscr();
 for(temp=0;start_address+temp<=end_address && temp<16*16;temp++)
   {
      gotoxy(port_bit8_value[temp].start_x,port_bit8_value[temp].y);
      cprintf("%02x",port_bit8_value[temp].value);
   }
}

disp_word_page(void)
{
 unsigned int temp;
 window(1,5,80,23);
 textbackground(BLUE);
 textcolor(WHITE);
 clrscr();
 cprintf("     X :   0     2     4     6       8     a     c     e");

 window(1,6,8,23);
 textbackground(BLUE);
 textcolor(WHITE);
 clrscr();
 for(temp=0;start_address+temp<=end_address;temp+=16)
 {
  cprintf(" %4x:\n\r",start_address+temp);   /* printer all address */
 }

 window(9,6,57,21);
 textbackground(WHITE);
 textcolor(BLACK);
 clrscr();
 for(temp=0;start_address+temp*2<=end_address && temp<8*16;temp++)
   {
      gotoxy(port_bit16_value[temp].start_x,port_bit16_value[temp].y);
      cprintf("%04x",port_bit16_value[temp].value);
   }
}

disp_dword_page(void)
{
 unsigned int temp;
 window(1,5,80,23);
 textbackground(BLUE);
 textcolor(WHITE);
 clrscr();
 cprintf("     X :       0         4           8         c");

 window(1,6,8,23);
 textbackground(BLUE);
 textcolor(WHITE);
 clrscr();
 for(temp=0;start_address+temp<=end_address;temp+=16)
 {
  cprintf(" %4x:\n\r",start_address+temp);   /* printer all address */
 }

 window(9,6,49,21);
 textbackground(WHITE);
 textcolor(BLACK);
 clrscr();
 for(temp=0;start_address+temp*4<=end_address && temp<4*16;temp++)
   {
      gotoxy(port_bit32_value[temp].start_x,port_bit32_value[temp].y);
      cprintf("%08lx",port_bit32_value[temp].value);
   }
}

read_page(void)
{
 if(width==1)
 {
  read_byte_page();
 }
 if(width==2)
 {
  read_word_page();
 }
 if(width==4)
 {
  read_dword_page();
 }
} 

disp_page(void)
{
 if(width==1)
 {
  disp_byte_page();
 }
 if(width==2)
 {
  disp_word_page();
 }
 if(width==4)
 {
  disp_dword_page();
 }
} 

move_up(void)
{                                             
 unsigned int x,y;
 x=wherex();
 y=wherey();
 if(y==1)
    {
     if(start_address>=16)   start_address-=16;
     else start_address=0;
     read_page();
     disp_page();
     gotoxy(x,y);       
    }
 else
    {       
     gotoxy(x,y-1);
     if(width==1) current_port-=16;
     if(width==2) current_port-=8;
     if(width==4) current_port-=4;
    }  
}

move_down(void)
{                                             
   unsigned int x,y;
   x=wherex();
   y=wherey();
   if(y==16)
   {
      if(end_address<0xffff-16)
      {
         end_address+=16;
         start_address+=16;
      }
      else
      {
         end_address=0xffff;
         start_address+=16;
      }
      read_page();
      disp_page();
      gotoxy(x,y);
   }
   else if(y+1<end_y || (y+1==end_y && x<=end_x ))
   {
      gotoxy(x,y+1);
      if(width==1) current_port+=16;
      if(width==2) current_port+=8;
      if(width==4) current_port+=4;  
   }
   else if(y+1==end_y && x>end_x)
   {
      gotoxy(end_x,end_y);
      current_port=end_port;
      current_bit=width*2-1;
   }
   else
   {
      end_address+=16;
      read_page();
      disp_page();
      gotoxy(x,y+1);
      if(width==1) current_port+=16;
      if(width==2) current_port+=8;
      if(width==4) current_port+=4;  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -