view pwplib/dumbterm.c @ 71:a87eb778f225

Improvements to the MinGW crossbuild. Should now build with default tools from Debian mingw packages, though you need Win32 version of libSDL with the necessary headers and so on in addition. 64-bit builds not tested and probably won't work. Tested on Debian 7.0, earlier won't work. binutils-mingw-w64-i686 gcc-mingw-w64-i686 mingw-w64-i686-dev
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 14 Aug 2012 03:08:10 +0300
parents 5d819ba6891c
children
line wrap: on
line source

/*
 *  pwplib tty driver: dumb ascii output
 *
 */

#include "config.h"

#ifdef HAVE_TTYSTUFF

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "pwplib.h"
#include "convert.h"
#include "tty.h"

struct
{
   char*newframe;
   char*newline_;
   int lgt_newline_;

   unsigned char*buf;

   int frame;
}
 pwp_tty_dumb;

void tty_dumb_dump_attr()
{
   u8 *s=pwplib.videobuf.d;
   unsigned char *d=pwp_tty_dumb.buf;
   int i=pwplib.videobuf.height,j;

#ifndef FUCK1
   d+=sprintf((char*)d,(char*)pwp_tty_dumb.newframe,pwp_tty_dumb.frame++);
#else
   sprintf((char*)d,(char*)pwp_tty_dumb.newframe,pwp_tty_dumb.frame++);
   d+=strlen(d);
#endif

   for(;i;i--)
   {
      for(j=pwplib.videobuf.width;j;j--)
      {
         *d++=*s;
         s+=2;
      }
      memcpy(d,pwp_tty_dumb.newline_,pwp_tty_dumb.lgt_newline_*sizeof(char));
      d+=pwp_tty_dumb.lgt_newline_;
   }

   fwrite(pwp_tty_dumb.buf,(d-pwp_tty_dumb.buf),sizeof(char),stdout);

   if(pwplib.set.framedelay)
   usleep(pwplib.set.framedelay*1000);
}

void tty_dumb_prep_attr()
{
   if(pwp_tty_dumb.buf!=NULL)
      free(pwp_tty_dumb.buf);

   pwp_tty_dumb.buf=malloc((
      (pwp_tty_dumb.lgt_newline_+pwplib.videobuf.width)*pwplib.videobuf.height
      )+strlen(pwp_tty_dumb.newframe));
}

int tty_dumb_init() /*int argc,char**argv) */
{
   pwplib.prep_attr=tty_dumb_prep_attr;
   pwplib.dump_attr=tty_dumb_dump_attr;

   pwp_tty_dumb.newframe="\22";
   pwp_tty_dumb.newline_="\n";

   /* ... get options */

   pwp_tty_dumb.lgt_newline_=strlen(pwp_tty_dumb.newline_);
   pwp_tty_dumb.frame=0;

   conv_init(8,3,2);

   return 1;
}


/*
   options to be included:

   newline_ "string"	set newline_ string
   newframe "string"	set newframe string
   optimize none	no optimization
   optimize blank	skip spaces at end of line  (default)
   optimize video	skip unchanged lines && non-changed areas at eol

*/

#endif