Page 1 of 1

What am I doing wrong here? (C)

Posted: Fri Jun 02, 2006 10:57 am
by REV
I'm using Watcom C/C++ 11.0c and no value is returned. What am I doing wrong here?

unsigned char indata;

unsigned char in(unsigned short port) {
__asm {
mov dx, port
in al, dx
mov indata, al
}
return indata;
}

Re:What am I doing wrong here? (C)

Posted: Sat Jun 03, 2006 1:27 am
by earlz
maybe the port isn't returning anything(or 0) and I'm suprised you didn't have to put _indata in the asm

Re:What am I doing wrong here? (C)

Posted: Sat Jun 03, 2006 1:53 pm
by REV
I know something is going wrong here.

out(0x70, 0x14);
printf("Detecting floppy disks");
det = in(0x71);

That should return a value. Port 0x70 tells the CMOS to return the floppys. I found this document on osdever.net and I wrote the out and in code fine.

void out(unsigned short port, unsigned short portdata) {
__asm {
mov dx, port //unsigned short
mov ax, portdata //unsigned short
out dx, ax
}
}

Theres the out() code. This is driving me nuts!

Re:What am I doing wrong here? (C)

Posted: Sun Jun 18, 2006 1:11 pm
by Ryu
I/O port 70h & 71h are byte wide ports. Correct this in out()function. Its better to name that outw() and make one for outb() and outd() if you want to wrap these calls in C.

Re:What am I doing wrong here? (C)

Posted: Tue Jun 20, 2006 8:31 am
by df
shouldnt you use a pragma aux with watcom?
(plus upgrade from 11.0c to openwatcom 1.4/1.5)

(off top of my head)

Code: Select all

unsigned char in(unsigned short port);
#pragma aux in=      \
    "in al,dx"            \
    parm caller [dx]     \
    value [al]             \
    modify [eax edx];
found this after searching

Code: Select all

void koutpw(long i1, long i);
#pragma aux koutpw =\ 
"out dx, ax",\ 
parm [edx][eax]\ 
modify exact;

int kinp(long i); 
#pragma aux kinp =\ 
"in al, dx",\ 
parm nomemory [edx]\ 
modify exact [eax];
not sure about the trailing ';' after the modify's.