What am I doing wrong here? (C)

Programming, for all ages and all languages.
Post Reply
REV

What am I doing wrong here? (C)

Post 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;
}
earlz

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

Post 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
REV

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

Post 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!
Ryu

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

Post 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.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

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

Post 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.
-- Stu --
Post Reply