Page 1 of 1

USHORT, BOOL, GDT, TSS, and ISRs

Posted: Fri Feb 08, 2002 11:06 pm
by K.J.
I was trying out a part of code from df's OS Dev FAQ and couldn't get this to work:

     /* void update_cursor(int row, int col)
      * by Dark Fiber
      */
     void update_cursor(int row, int col)
     {
           USHORT      position=(row*80) + col;

           // cursor LOW port to vga INDEX register
           outb(0x3D4, 0x0F);
           outb(0x3D5, (UCHAR)(position&0xFF));
           // cursor HIGH port to vga INDEX register
           outb(0x3D4, 0x0E);
           outb(0x3D5, (UCHAR)((position>>8)&0xFF));
     };


The problem is that DJGPP doesn't know what USHORT is and I don't either(though I think that it's short something). I also can't seem to be able to have a function in DJGPP return a BOOL:

BOOL test_it();

DJGPP says that it doesn't know what BOOL is.

My last question is, does anyone know where I can find a good tutorial or doc that explains GDT, TSS, and how to setup ISRs?

Thanks in advance,
K.J.

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Fri Feb 08, 2002 11:13 pm
by df
UCHAR == unsigned char
USHORT == unsigned short
ULONG == unsigned long
UINT32 == unsigned long
UINT16 == unsigned short
UINT8 == unsigend char

SCHAR == signed char
SSHORT == signed short
SLONG == signed long
SINT32 == signed long
SINT16 == signed short
SINT8 == sigend char

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Fri Feb 08, 2002 11:16 pm
by K.J.
USHORT == unsigned short

Integer?

K.J.

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Sat Feb 09, 2002 12:29 am
by Whatever5k
Yes... .
Just use the term "unsigned short" or make a typedef

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Sat Feb 09, 2002 3:14 am
by df
USHORT == unsigned short

Integer?
no. on 32bit architecture, a short is 16bits, an integer is 32bits.
in real mode, integer is 16bits.

short is always 16bits on x86, long is always 32bits. char is always 8.

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Sat Feb 09, 2002 9:30 pm
by K.J.
Well I used this and it worked fine:

#define USHORT unsigned short int

Thanks,
K.J.

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Sat Feb 09, 2002 11:18 pm
by df

Code: Select all

#ifndef __typedef_int
#define __typedef_int
typedef signed char SCHAR;
typedef unsigned char UCHAR;
typedef signed long SLONG;
typedef unsigned long ULONG;
typedef signed short SSHORT;
typedef unsigned short USHORT;
#endif

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Mon Feb 11, 2002 7:46 am
by ark
#define's are ok, but for defining a new type, it's generally better to use typedef, and here's why: take the following code

#define PSTR char*

PSTR pszString1, pszString2;

this creates ONE char* variable called pszString1 and one CHAR (not char*) variable called pszString2 -- this is because #define essentially does a text replacement, making the above code equivalent to:

char *pszString1, *pszString2;

However, if you use a typedef:

typedef char* PSTR;

PSTR pszString1, pszString2;

this creates TWO char* variables, because PSTR becomes a full data type.

For something like unsigned short it's fine to #define, but if you do something like that with pointers it can come back and get you.

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Mon Feb 11, 2002 7:48 am
by ark
Oops...I meant that the #define code was equivalent to:

char *pszString1, pszString2;

Re: USHORT, BOOL, GDT, TSS, and ISRs

Posted: Mon Feb 11, 2002 7:54 am
by ark
by the way, BOOL is another thing that you'll have to typedef (or you can change it to bool if DJGPP supports ANSI C++).

BOOL can be defined as pretty much any integer type. When I define it, I usually just make it an int, though a shorter type like char would probably work fine.

typedef int BOOL;
#define TRUE 1
#define FALSE 0