[Soft] ETA (Encoded Text Animation) format and decoder

English forum for http://www.nedopc.org/nedopc

Moderator: Shaos

User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

[Soft] ETA (Encoded Text Animation) format and decoder

Post by Shaos »

This is source code for 16-bit DOS text mode 80x25:

Code: Select all

/* ETA_PLAY.C - A.A.Shabarshin (April 2015) - for Turbo-C 2.01
==============================================================

Copyright (c) 2015 A.A.Shabarshin <me@shaos.net>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

*/

#include <stdio.h>
#include <conio.h>

/*

 Encoded Text Animation (ETA):
 =============================
 Header: '@',Cols,Rows,Number
 User: Number*8 - user characters (up to 32)
 Data: Sequence of bytes that ends with 0xF0:
 0xxxxxxx - ASCII character itself (including user space <0x20)
 100xxxxx - Repeat space 2...33 times (x+2)
 1010xxxx - Skip 1...16 characters (0 means 16)
 1011xxxx - GFX character itself (0xB0...0xBF)
 110xxxxx - GFX character itself (0xC0...0xDF)
 1110xxxx - Repeat next character 1...16 times (0 means 16) + 1 byte after that
 1111xxxx - Extended GFX character itself, but
 11110000 - End of the image/movie (0xF0)
 11110001 - End of the frame that should stay for N/30 sec and start from row M
            (0xF1 + 2 bytes N and M after that)

 Shaos, April 2015

*/

int main(int argc, char** argv)
{
 int i,c,n,m,w,h,x,y;
 FILE *f;
 if(argc<2)
 {
   printf("Usage: ETA_PLAY FILE.ETA\n");
   return -1;
 }
 f = fopen(argv[1],"rb");
 if(f==NULL)
 {
   printf("Can't open file '%s'!\n",argv[1]);
   return -2;
 }
 c = fgetc(f);
 if(c!='@')
 {
   printf("Invalid ETA file!\n");
   return -3;
 }
 w = fgetc(f);
 h = fgetc(f);
 c = fgetc(f);
 if(c!=0)
 {
   printf("This player doesn't support user defined characters!\n");
   return -3;
 }
 x = (80-w)/2;
 y = (25-h)/2;
 clrscr();
 window(x,y,x+w-1,y+h);
#if 0
 /* this is for later borlands */
 _setcursortype(_NOCURSOR);
#endif
 m = 0;
 while(c!=0xF0)
 {
   c = fgetc(f);
   switch(c>>4)
   {
     case 0:
     case 1:
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
     case 7:
       putch(c);
       break;
     case 8:
     case 9:
       n = (c & 0x1F) + 2;
       for(i=0;i<n;i++) putch(' ');
       break;
     case 10:
       n = c & 0x0F;
       if(n==0) n = 16;
       i = wherex() + n;
       if(i > w)
          gotoxy(i-w,wherey()+1);
       else
          gotoxy(i,wherey());
       break;
     case 11:
     case 12:
     case 13:
       putch(c);
       break;
     case 14:
       n = c & 0x0F;
       if(n==0) n = 16;
       c = fgetc(f);
       for(i=0;i<n;i++) putch(c);
       break;
     case 15:
       if(c==0xF0) break;
       if(c==0xF1)
       {
          m++;
          delay(33*fgetc(f));
          gotoxy(1,fgetc(f)+1);
          if(kbhit() && getch()==27) c=0xF0;
       }
       else putch(c);
       break;
   }
 }
 fclose(f);
 return 0;
}
Я тут за главного - если что шлите мыло на me собака shaos точка net
User avatar
Shaos
Admin
Posts: 24008
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: [Soft] ETA (Encoded Text Animation) format and decoder

Post by Shaos »

Possible extensions to represent colored text:
F2 - clear screen (fill with spaces)
F3 x - set attribute as
| bit 7 - Intensity of background (use carefully)
| bits 6...4 - Background color RGB
| bit 3 - Intensity of foreground
| bits 2...0 - Foreground color RGB (text)
F4 - inverse attributes
F5 - change text color to gray over black (and set high intensity)
F6 - change text color to white over black (and set low intensity)
F7 - change text color to bright white over black (and set high intensity)
F8 - change text color to black (gray if high intensity set) and print character 0xDB
F9 - change text color to blue and print character 0xDB
FA - change text color to green and print character 0xDB
FB - change text color to cyan and print character 0xDB
FC - change text color to red and print character 0xDB
FD - change text color to magenta and print character 0xDB
FE - change text color to brown (yellow if high intensity set) and print character 0xDB
FF - change text color to white and print character 0xDB
Я тут за главного - если что шлите мыло на me собака shaos точка net