USHORT, BOOL, GDT, TSS, and ISRs

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
K.J.

USHORT, BOOL, GDT, TSS, and ISRs

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

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

Post 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
-- Stu --
K.J.

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

Post by K.J. »

USHORT == unsigned short

Integer?

K.J.
Whatever5k

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

Post by Whatever5k »

Yes... .
Just use the term "unsigned short" or make a typedef
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

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

Post 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.
-- Stu --
K.J.

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

Post by K.J. »

Well I used this and it worked fine:

#define USHORT unsigned short int

Thanks,
K.J.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

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

Post 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
-- Stu --
ark

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

Post 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.
ark

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

Post by ark »

Oops...I meant that the #define code was equivalent to:

char *pszString1, pszString2;
ark

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

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