NO

Author Topic: Games programming troubles  (Read 4497 times)

wd40

  • Guest
Games programming troubles
« on: July 29, 2010, 07:52:38 PM »
Hello,

Im trying to learn how to dos games programming in C to learn from the bottom up. I am getting lots of errors currently, from sample code i have used from the website:

http://www3.telus.net/alexander_russell/course/introduction.htm

I would be very grateful for any help you could give to fix the program.

I am getting the following error messages:

C:\Users\Ford\Documents\Pelles C Projects\new\main.c(15): error #2149: Undefined size for 'in' with type '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(15): error #2149: Undefined size for 'out' with type '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(18): error #2152: Unknown field 'h' of '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(18): error #2113: Left operand of '.' has incompatible type 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(19): warning #2027: Missing prototype for 'int86'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(20): error #2152: Unknown field 'h' of '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(20): error #2113: Left operand of '.' has incompatible type 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(23): error #2152: Unknown field 'h' of '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(23): error #2113: Left operand of '.' has incompatible type 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(24): error #2152: Unknown field 'h' of '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(24): error #2113: Left operand of '.' has incompatible type 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(30): error #2149: Undefined size for 'in' with type '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(30): error #2149: Undefined size for 'out' with type '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(33): error #2152: Unknown field 'h' of '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(33): error #2113: Left operand of '.' has incompatible type 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(34): error #2152: Unknown field 'h' of '(incomplete) union REGS'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(34): error #2113: Left operand of '.' has incompatible type 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(35): warning #2027: Missing prototype for 'int86'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(39): error #2001: Syntax error: expected ';' but found '*'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(39): warning #2099: Missing type specifier; assuming 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(40): error #2001: Syntax error: expected ';' but found '*'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(40): warning #2099: Missing type specifier; assuming 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(46): warning #2027: Missing prototype for 'farmalloc'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(46): error #2168: Operands of '=' have incompatible types 'int *' and 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(50): warning #2027: Missing prototype for 'MK_FP'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(50): error #2168: Operands of '=' have incompatible types 'int *' and 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(55): warning #2027: Missing prototype for '_fmemset'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(55): error #2048: Undeclared identifier 'offscreen'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(55): error #2048: Undeclared identifier 'screensize'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(73): warning #2027: Missing prototype for 'inportb'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(75): warning #2027: Missing prototype for 'inportb'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(79): warning #2027: Missing prototype for '_fmemcpy'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(82): warning #2099: Missing type specifier; assuming 'int'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(82): error #2048: Undeclared identifier 'y'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(82): error #2048: Undeclared identifier 'x'.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(82): error #2069: Initializer must be constant.
C:\Users\Ford\Documents\Pelles C Projects\new\main.c(93): error #2048: Undeclared identifier 'screen_with'.

Code is below:

Code: [Select]
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main()
{

}

int old_mode;

void enter_mode13h(void)
{
union REGS in, out;

// get old video mode
in.h.ah=0xf;
int86(0x10, &in, &out);
old_mode=out.h.al;

// enter mode 13h
in.h.ah=0;
in.h.al=0x13;
int86(0x10, &in, &out);
}

void leave_mode13h(void)
{
union REGS in, out;

// change to the video mode we were in before we switched to mode 13h
in.h.ah=0;
in.h.al=old_mode;
int86(0x10, &in, &out);
}


unsigned char far *screen; // pointer to the VGA video memory
unsigned char far *off_screen; // pointer to our off screen buffer
int screen_width, screen_height;
unsigned int screen_size;

int init_video_mode(void)
{
off_screen=farmalloc(64000u);

if ( off_screen )
{
screen=MK_FP(0xa000, 0);
screen_width=320;
screen_height=200;
screen_size=64000u;
enter_mode13h();
_fmemset(offscreen, 0, screensize);
return 0;
}
else
{
// no mem! Return error code!
leave_mode13h();
printf("Out of mem!\n");
return 1;
}
}

#define INPUT_STATUS_0 0x3da

// copy the off screen buffer to video memory
void update_buffer(void)
{
// wait for vertical re-trace
while ( inportb(INPUT_STATUS_0) & 8 )
;
while ( !(inportb(INPUT_STATUS_0) & 8) )
;

// copy everything to video memory
_fmemcpy(screen, off_screen, screen_size);
}

Offset=y*320 + x;

void draw_pixel(int x, int y, int colour)
{

*(off_screen + y*screen_width + x)=colour;
}

 int get_pixel(int x, int y)
{

return *(off_screen + y*screen_with + x);
}


Thankyou for your time
« Last Edit: July 29, 2010, 07:55:59 PM by wd40 »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Games programming troubles
« Reply #1 on: July 29, 2010, 09:59:06 PM »
PellesC is 32-bit compiler and yours example code is for 16-bit.
May the source be with you

wd40

  • Guest
Re: Games programming troubles
« Reply #2 on: July 30, 2010, 12:31:40 AM »
Oh right didn't realise that, do you know any good 16-bit c compilers?

Thanks for your time
« Last Edit: July 30, 2010, 12:37:45 AM by wd40 »

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: Games programming troubles
« Reply #3 on: July 30, 2010, 07:45:09 AM »
You  can try Open Watcom C compiler. It's big multitarget compiler
(32/16 bit ~50 Mb on disk and  install package 82 Mb)
http://www.openwatcom.org
http://www.openwatcom.org/index.php/Download
Your example code can't compile with that.

Digital Mars C/C++ compiler
http://www.digitalmars.com/
http://www.digitalmars.com/download/freecompiler.html

MSDOS:
From net you can find Turbo C version 2.01 or Turbo C++ version 1.01.
But you must register to there first
http://edn.embarcadero.com/article/20841
http://edn.embarcadero.com/article/21751

This modified version compiles with Open Watcom 1.9:
Code: [Select]
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#ifdef __WATCOMC__
#include <malloc.h>
#else
#include <alloc.h>
#endif
#include <dos.h>
#include <string.h>

int main(void)
{
    return 0;
}

int old_mode;

void enter_mode13h(void)
{
        union REGS in, out;

        // get old video mode
        in.h.ah=0xf;
        int86(0x10, &in, &out);
        old_mode=out.h.al;

        // enter mode 13h
        in.h.ah=0;
        in.h.al=0x13;
        int86(0x10, &in, &out);
}

void leave_mode13h(void)
{
        union REGS in, out;

        // change to the video mode we were in before we switched to mode 13h
        in.h.ah=0;
        in.h.al=old_mode;
        int86(0x10, &in, &out);
}


unsigned char far *screen;       // pointer to the VGA video memory
unsigned char far *off_screen;  // pointer to our off screen buffer
int screen_width, screen_height;
unsigned int screen_size;

int init_video_mode(void)
{
#ifdef __WATCOMC__
        off_screen=_fmalloc(64000u);
#else    
        off_screen=farmalloc(64000u);
#endif
        if ( off_screen )
                {
                screen=MK_FP(0xa000, 0);
                screen_width=320;
                screen_height=200;
                screen_size=64000u;
                enter_mode13h();
                _fmemset(off_screen, 0, screen_size);
                return 0;
                }
        else
                {
                // no mem! Return error code!
                leave_mode13h();
                printf("Out of mem!\n");
                return 1;
                }
}

#define INPUT_STATUS_0 0x3da

// copy the off screen buffer to video memory
void update_buffer(void)
{
#ifdef __WATCOMC__
        // wait for vertical re-trace
        while ( inp(INPUT_STATUS_0) & 8 )
                ;
        while ( !(inp(INPUT_STATUS_0) & 8) )
                ;
#else    
        // wait for vertical re-trace
        while ( inportb(INPUT_STATUS_0) & 8 )
                ;
        while ( !(inportb(INPUT_STATUS_0) & 8) )
                ;
#endif
        // copy everything to video memory
        _fmemcpy(screen, off_screen, screen_size);
}

//Offset=y*320 + x;

void draw_pixel(int x, int y, int colour)
{

        *(off_screen + y*screen_width + x)=colour;
}

 int get_pixel(int x, int y)
{

        return *(off_screen + y*screen_width + x);
}
« Last Edit: July 30, 2010, 09:44:06 AM by timovjl »
May the source be with you