Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dos.h>
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "MoreTypes.h"
- const SCREEN_WIDTH = 80, SCREEN_HEIGHT = 25;
- const ushort SCREEN_SEG = 0xB800;
- const SCREEN_SIZE = 80*25;
- // Text image structs
- const ulong FILE_MAGIC = 0x58464754; // TGFX
- struct TxtGFXHeader {
- ulong magic;
- ushort Width;
- ushort Height;
- };
- struct TxtGFX {
- int Size;
- int Width;
- int Height;
- ushort* Image;
- };
- ushort *ScreenBuff;
- extern struct TxtGFX LoadGFX(char* filename) {
- FILE *filePtr;
- struct TxtGFXHeader Header;
- struct TxtGFX Img;
- filePtr = fopen(filename, "rb");
- if (!filePtr) {
- printf("Error opening file: ");
- printf(filename);
- printf("!\r\n");
- return Img;
- }
- // Read header to check it's a valid file
- fread(&Header, sizeof(struct TxtGFXHeader), 1, filePtr);
- if (Header.magic != FILE_MAGIC) {
- printf("Error: corrupt or invalid TGF file!\r\n");
- return Img;
- }
- Img.Size = Header.Width * Header.Height * sizeof(ushort);
- Img.Width = Header.Width;
- Img.Height = Header.Height;
- Img.Image = malloc(Img.Size); // Create buffer for image
- if (Img.Image == 0) {
- printf("Error allocating memory for new image!\r\n");
- return Img;
- }
- fread(Img.Image, Img.Size, 1, filePtr); // Read actual image into buffer
- fclose(filePtr);
- return Img;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement