分类: C/C++
2009-06-16 00:06:11
#include int main() { char *msg = "hello world!$"; asm mov ax,cs; asm mov dx,ax; asm mov es,ax; asm mov dx,msg; asm mov ah,9h; asm int 21h; getchar(); return 0; } |
#include #include #include #define IOY3 0xC480 //0xE8C0 #define P8255_A IOY3+0x00*4 #define P8255_B IOY3+0x01*4 #define P8255_C IOY3+0x02*4 #define P8255_MODE IOY3+0x03*4 #define SPEED 0x10 #define S0 SPEED*1 #define S1 SPEED*2 #define S2 SPEED*3 #define S3 SPEED*4 #define S4 SPEED*5 #define S5 SPEED*6 #define S6 SPEED*7 typedef enum { RIGHT, /*0*/ LEFT /*1*/ }FLAG; //gobal var int buffer = 0x33; FLAG flag = RIGHT; //declare func void outb(int addr,int mode); int inb(int addr); void display(char *msg); int is_key(void); void dly_speed(int speed); void set_speed(int speed,FLAG flag); void do_key(int key); void outb(int addr,int mode) { asm mov dx,addr; asm mov ax,mode; asm out dx,ax; } int inb(int addr) { asm mov dx,addr; asm in al,dx; asm xor ah,ah; return (_AX); } void display(char *msg) { asm mov dx,msg; asm mov ah,09h; asm int 21h; } int is_key(void) { asm mov ah,06h; asm mov dl,0ffh; asm int 21h; asm je nokey; asm mov ax,1; return (_AX); nokey: asm mov ax,0; return (_AX); } void dly_speed(int speed) { asm mov dx,speed; dly: asm mov cx,0ffffh; lp: asm loop lp; asm dec dx; asm jnz dly; } void set_speed(int speed,FLAG flag) { outb(P8255_A,buffer); if (flag == RIGHT) { asm { mov ax,buffer; ror al,1; mov buffer,ax; } } else { asm { mov ax,buffer; rol al,1; mov buffer,ax; } } printf("buffer = %x\n",buffer); dly_speed(speed); } void do_key(int key) { int time = 0; if (key == 0) { buffer = 0x33; outb(P8255_A,buffer); return; } else { printf("key = %d\t",key); flag = ((key & 0x0080) == 0? RIGHT: LEFT); printf("flag = %d\t",flag); time = (key & 0x007f); printf("time = %d\t",time); if (time&0x01) { printf("time&0x01=%d S0\t",time&0x01); set_speed(S0,flag); } else if (time&0x02) { printf("time=%d S1\t",time); set_speed(S1,flag); } else if(time&0x04) { printf("time=%d S2\t",time); set_speed(S2,flag); } else if (time&0x08) { set_speed(S3,flag); printf("S3\t"); } else if (time&0x10) { set_speed(S4,flag); printf("S4\t"); } else if(time&0x20) { set_speed(S5,flag); printf("S5\t"); } else if (time&0x40) { set_speed(S6,flag); printf("S6\t"); } else { printf("time&0x02=%d\tstop\t",time&0x80); } } } int main() { int c; outb(P8255_MODE,0x90); //init 8255 outb(P8255_A,buffer); //init buffer = 33h while (!is_key()) { c = inb(P8255_C); do_key(0xc0); } return 0; } |
TARGET= bujinji CC= tcc CFLAGS= -B TCDIR= D:\tc3 INCLUDE= $(TCDIR)\INCLUDE LIB= $(TCDIR)\LIB $(TARGET).exe: $(TARGET).obj $(CC) $(CFLAGS) -I$(INCLUDE) -L$(LIB) $(TARGET).obj $(TARGET).obj: $(TARGET).c $(CC) $(CFLAGS) -I$(INCLUDE) -L$(LIB) -c $(TARGET).c clean: @del bujinji.obj |