#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

typedef unsigned short us;
typedef unsigned int   ui;
typedef unsigned char  uc;
typedef unsigned long  ul;

typedef struct SVBE_InfoBlock {
  uc VbeSignature[4];           // VBE Signature
  us VbeVersion;                // VBE Version
  ul OemStringPtr;              // Pointer to OEM String
  ul Capabilities;              // Capabilities of graphics cont.
  ul VideoModePtr;              // Pointer to Video Mode List
                                // Added for VBE 1.2+
  us TotalMemory;               // Number of 64kb memory blocks
                                // Added for VBE 2.0+
  us OemSoftwareRev;            // VBE implementation Software revision
  ul OemVendorNamePtr;          // Pointer to Vendor Name String
  ul OemProductNamePtr;         // Pointer to Product Name String
  ul OemProductRevPtr;          // Pointer to Product Revision String
  us AccelVbeVersion;           // VBE/AF Version
  ul AccelVideoModePtr;         // Pointer to Acclelerated Mode List
  uc Reserved20[216];           // Reserved for VBE implementation
                                // scratch area
  uc OemData[256];              // Data Area for OEM Strings
  uc NaVsyakiySloochay[100];    // 2e
} VBE_InfoBlock;

typedef struct SVBE_ModeInfoBlock {
  us ModeAttributes;            // mode attributes
  uc WinAAttributes;            // window A attributes
  uc WinBAttributes;            // window B attributes
  us WinGranularity;            // window granularity
  us WinSize;                   // window size
  us WinASegment;               // window A start segment
  us WinBSegment;               // window B start segment
  ul WinFuncPtr;                // pointer to window function
  us BytesPerScanLine;          // bytes per scan line
                                // Mandatory information for VBE 1.2 and above
  us XResolution;               // horizontal resolution in pixels or chars
  us YResolution;               // vertical resolution in pixels or chars
  uc XCharSize;                 // character cell width in pixels
  uc YCharSize;                 // character cell height in pixels
  uc NumberOfPlanes;            // number of memory planes
  uc BitsPerPixel;              // bits per pixel
  uc NumberOfBanks;             // number of banks
  uc MemoryModel;               // memory model type
  uc BankSize;                  // bank size in KB
  uc NumberOfImagePages;        // number of images
  uc Reserved12;                // reserved for page function
                                // Direct Color fields (required
                                // for direct/6 and YUV/7 memory models)
  uc RedMaskSize;               // size of direct color red mask in bits
  uc RedFieldPosition;          // bit position of lsb of red mask
  uc GreenMaskSize;             // size of direct color green mask in bits
  uc GreenFieldPosition;        // bit position of lsb of green mask
  uc BlueMaskSize;              // size of direct color blue mask in bits
  uc BlueFieldPosition;         // bit position of lsb of blue mask
  uc RsvdMaskSize;              // size of direct color reserved mask in bits
  uc RsvdFieldPosition;         // bit position of lsb of reserved mask
  uc DirectColorModeInfo;       // direct color mode attributes
                                // Mandatory information for VBE 2.0 and above
  ul PhysBasePtr;               // physical address for flat frame buffer
  ul OffScreenMemOffset;        // pointer to start of off screen memory
  us OffScreenMemSize;          // amount of off screen memory in 1k units
  uc Reserved20[206];           // remainder of ModeInfoBlock
  uc NaVsyakiySloochay[100];    // 2e
} VBE_ModeInfoBlock;

typedef struct SVBE_RMI {       // Rreal Mode Interrupt (RMI) structure
  ul EDI, ESI, EBP, ReservedByRMI,
     EBX, EDX, ECX, EAX;
  us flags,
     ES, DS,
     FS, GS,
     IP, CS,
     SP, SS;
} VBE_RMI;

typedef struct SMode {       // Тип описывающий видео-режим.
    ul  bpl;        // Байт на строку растра.
    ul  w;          // Ширина
    ul  h;          // Высота
    ul  bpp;        // Бит на точку
    ul  bytespp;    // Байт на точку
    ul  banked;     // (1)LFB or (0)Banked
    ul  error;      // Ошибка (обязательно надо проверять)
    uc* LFB;        // Указатель на LFB
    uc* VLFB;        // Указатель на Виртуальный экран
} TMode;

TMode           cm;            // Текущий видеорежим.

int GetVBEVersion(void);
void PutVBEVersion(void);
TMode SetVESAMode(int xmax, int ymax, int bpp);
void SetVGAMode(int mode);
void InitGraph(void);
void blt(TMode m);
void PutPixel(int x,int y,int color);
void Line(int x1,int y1,int x2,int y2,int color);

