Advertisement
Ham62

DOS pCon.c

Aug 9th, 2017
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <dos.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "MoreTypes.h"
  6.  
  7. const SCREEN_WIDTH = 80, SCREEN_HEIGHT = 25;
  8. const ushort SCREEN_SEG = 0xB800;
  9. const SCREEN_SIZE = 80*25;
  10.  
  11. // Text image structs
  12. const ulong FILE_MAGIC = 0x58464754; // TGFX
  13. struct TxtGFXHeader {
  14.     ulong magic;
  15.     ushort Width;
  16.     ushort Height;
  17. };
  18. struct TxtGFX {
  19.     int Size;
  20.     int Width;
  21.     int Height;
  22.     ushort* Image;
  23. };
  24.  
  25. ushort *ScreenBuff;
  26.  
  27. extern struct TxtGFX LoadGFX(char* filename) {
  28.     FILE *filePtr;
  29.     struct TxtGFXHeader Header;
  30.     struct TxtGFX Img;
  31.  
  32.     filePtr = fopen(filename, "rb");
  33.     if (!filePtr) {
  34.         printf("Error opening file: ");
  35.         printf(filename);
  36.         printf("!\r\n");
  37.         return Img;
  38.     }
  39.  
  40.     // Read header to check it's a valid file
  41.     fread(&Header, sizeof(struct TxtGFXHeader), 1, filePtr);
  42.     if (Header.magic != FILE_MAGIC) {
  43.         printf("Error: corrupt or invalid TGF file!\r\n");
  44.         return Img;
  45.     }
  46.     Img.Size = Header.Width * Header.Height * sizeof(ushort);
  47.     Img.Width = Header.Width;
  48.     Img.Height = Header.Height;
  49.     Img.Image = malloc(Img.Size);           // Create buffer for image
  50.     if (Img.Image == 0) {
  51.         printf("Error allocating memory for new image!\r\n");
  52.         return Img;
  53.     }
  54.     fread(Img.Image, Img.Size, 1, filePtr); // Read actual image into buffer
  55.    
  56.     fclose(filePtr);
  57.     return Img;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement