C++, I really need help :(

Viper Frag

Golden Member
Nov 22, 1999
1,000
4
81
I am trying to make a clear screen function and another function to home the cursor. So once I wrote out the code I get 25 errors and I don't know why. Here are the errors I get:
--------------------Configuration: Cpp2 - Win32 Debug--------------------
Compiling...
Cpp2.cpp
E:\C-Files\Homework\CLS\Cpp2.cpp(15) : error C2079: 'regs' uses undefined union 'REGS'
E:\C-Files\Homework\CLS\Cpp2.cpp(18) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(18) : error C2228: left of '.ah' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(19) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(19) : error C2228: left of '.al' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(20) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(20) : error C2228: left of '.bh' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(21) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(21) : error C2228: left of '.ch' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(22) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(22) : error C2228: left of '.cl' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(23) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(23) : error C2228: left of '.dh' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(24) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(24) : error C2228: left of '.dl' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(25) : error C2065: 'int86' : undeclared identifier
E:\C-Files\Homework\CLS\Cpp2.cpp(37) : error C2079: 'regs' uses undefined union 'REGS'
E:\C-Files\Homework\CLS\Cpp2.cpp(40) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(40) : error C2228: left of '.ah' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(41) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(41) : error C2228: left of '.bh' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(42) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(42) : error C2228: left of '.dh' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(43) : error C2228: left of '.h' must have class/struct/union type
E:\C-Files\Homework\CLS\Cpp2.cpp(43) : error C2228: left of '.dl' must have class/struct/union type
Error executing cl.exe.

Cpp2.obj - 25 error(s), 0 warning(s)

And this is the C++ code:

#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>

#define VIDEO 0x10 //Video Interrupt
#define COLS 80 //Screen Width
#define ROWS 25 //Screen Rows

void cls(void);
void locate(int col, int row);

void cls(void)
{
union REGS regs;


regs. h . ah=0x06; //func 6, scroll window
regs. h . al=0x00; //clear screen
regs. h . bh=0x07; //make screen &quot;blank&quot;
regs. h . ch=0x00; //Upper left row
regs. h . cl=0x00; //Upper left column
regs. h . dh=ROWS - 1; //Lower right row
regs. h . dl=COLS - 1; //Lower right column
int86(VIDEO,&amp;regs,&amp;regs);

locate(0,0); //&quot;Home&quot; the cursor
}

/* LOCATE Function
Moves the cursor to position col,row, where col ranges from 0 to 79 and row from
0 to 24. Upper left corner = 0,0; lower right corner = 79,24
*/

void locate(int col, int row)
{
union REGS regs;


regs. h . ah=0x02; //Vid func 2, move cursor
regs. h . bh=0x00; //Video screen (always 0)
regs. h . dh=row; //Cursor's row position
regs. h . dl=col; //Cursor's column position
int86(VIDEO,&amp;regs,&amp;regs);
}

I have to hand this in by tommorow :( . I would really appreciate any help you can give me.

Thanks,
Viper-Frag
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
Ahh... classic DOS direct video mode programming.

Your code is essentially assembly, not C++... it looks good from what I can remember.

The first error is the important one.. the others are just a result of that same error.

I'm in Linux, so I don't have the same header files as you and that's not standard (dos.h).. so I'm not sure why it doesn't recognize the type 'REGS'. I recommend looking in the included header files manually and finding out what's up.

Also, your int86() function is undefined. I assume you realize this is nothing more than a macro for the x86 'int <interrupt>' assembly call. Again, I don't know where this function is called, but you could even use direct inline assembly if you wanted to do that, where you'd do something like:

mov ax, <video mode> ; 13h == mode 13 graphics, forgot the others
int 10h

Grep through your header files to find int86 or look in the help file to find where it is defined.
 

Try removing the spaces between the regs. h. ah stuff

regs.h.ah=0x06;
etc...
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
dwell,

I doubt it was that :) I assumed that was a formatting error here
 

jkdude

Banned
Oct 10, 1999
1,204
0
0
Viper-Frag,

if all you wanna do is just clear the screen, and you are using Borland C++ 5.5 for DOS, just do this:

once u already have the #include <conio.h> there, type this whenever you want to clear the screen:

clrscr();

and that should be it!!!

i hope that works and helps you out. Also, i hope that what i said is applicable in your case and that i am not mistaken.

good luck,
Joseph
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
Well, my first guess would be that it should just be:

regs.ah = 0x06;

But you guys are missing the critical issue, this line:

union REGS regs;

This is getting that first error
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
jkdude,

The point of his assignment is to create his own clrscreen function, not use the conio one.

At least this is what I'm guessing.
 

He's just missing some #include

DOS, C++, inline ASM, now that's old school.
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
yeah.. that takes me back... I'm happy to see they're still teaching this stuff in schools.
 

I actually had a copy of Borland C++ zipped up on my HD. REGS is defined in DOS.H and BIOS.H, so he should be ok. Dunno what the problem is.
 

arcain

Senior member
Oct 9, 1999
932
0
0
The newer versions of Visual C++ cannot make DOS programs. I thin the last version that could was 2.x or 4.x. Also : &quot;Configuration: Cpp2 - Win32 Debug&quot; looks like you're compiling a windows executable.. I dunno how that will work with the interrupts.
 

Yeah, you will never get 16-bit DOS stuff to work with VC++. Even though VC++ comes with a DOS.H header, it does not contain the REGS union.