Skip to content

Instantly share code, notes, and snippets.

@PJensen
Created January 19, 2011 16:06
Show Gist options
  • Save PJensen/786367 to your computer and use it in GitHub Desktop.
Save PJensen/786367 to your computer and use it in GitHub Desktop.
Header file for graph.c
/*
** Filename: graph.c
**
** Copyright (C) 2001, Pete J. Jensen All Rights Reserved
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
**
** This module handles all low level video operations, such as initializing a
** graphics mode, ending a graphics mode, puting pixels etc.
**
** CONTENTS:
** initializeGraphicsMode();
** endGraphicsMode();
** putPixel();
** getPixel();
*/
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <dir.h>
#include <alloc.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <io.h>
#include <limits.h>
/* Graphics Header File*/
#include "graph.h"
/**
* Function: initializeGraphicsMode
* Purpose : To initialize the graphics mode into mode 13H; it has the
* properties of 320x200 screensize & 8 bits per pixel.
* Inputs : Void
* Returns : Void
* Modifies: The current graphics mode.
* Sample Call : initializeGraphicsMode();
*/
void initializeGraphicsMode()
{
asm MOV AL, 13H;
asm MOV AH, 00H;
asm INT VIDEO_BIOS;
}
/*
* Function: endGraphicsMode
* Purpose : To take us out of the 13H graphics mode and back into dos text
* mode. This should be run anytime the program hits an error.
* and displays an error message.
* Inputs : Void
* Returns : Void.
* Modifies: The Current Graphics Mode.
* Sample Call : endGraphicsMode();
*/
void endGraphicsMode()
{
asm MOV AL, 3H;
asm MOV AH, 00H;
asm INT VIDEO_BIOS;
}
/*
* Function: putPixel
* Purpose : To put a pixel @ x,y with given colorByte.
* Inputs : word X: The X location of the pixel.
word Y: The Y location of the pixel.
* Returns : Void
* Modifies: Adds one pixel to the graphics screen.
* Sample Call : putPixel(10, 10, 14);
* Remarks: Adapted from "Using PCX Graphics Files", Roger T. Stevens
*/
void putPixel(word X, word Y, byte color)
{
asm mov DI, VIDEO_RAM;
asm mov ES, DI;
asm mov AX, Y;
asm mov BX, Y;
asm shl AX, 8;
asm shl BX, 6;
asm add AX, BX;
asm add AX, X;
asm mov DI, AX;
asm mov AL, color;
asm mov ES:[DI], AL;
}
/*
* Function: getPixel
* Purpose : To get a pixel @ x,y with & return colorByte.
* Inputs : word X: The X location of the pixel.
word Y: The Y location of the pixel.
* Returns : The byteColor @ x,y.
* Sample Call : byteColor = getPixel(10, 10);
*/
byte getPixel(word X, word Y)
{
byte getColor;
asm MOV AH,0DH
asm MOV CX,X
asm MOV DX,Y
asm INT VIDEO_BIOS
asm MOV getColor, AL
return getColor;
}
/*
** Filename: graph.h
**
** Copyright (C) 2001, Pete J. Jensen All Rights Reserved
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __GRAPH_H
#define __GRAPH_H
/* Defines for graphics module */
#define VIDEO_BIOS 10H
#define VIDEO_RAM 0xA000
/* Screen size, width & height defined */
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 200
#define SCREEN_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT)
/* Typedefs for byte & word */
typedef unsigned char byte;
typedef unsigned short word;
/* Prototypes for Graphics Module */
void initializeGraphicsMode(void);
void endGraphicsMode(void);
void putPixel(word X, word Y, byte color);
byte getPixel(word X, word Y);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment