Os dejo un programa en MESCC, que viene a ser el complemento de la RSX que he publicado en la sección de ensamblador.
Su cometido es leer un fichero de imagen BMP en blanco y negro, cuyas dimensiones sean múltiplo de 8, y convertirlo a un fichero de imagen SCR.
Dicho SCR podemos después convertirlo a un listado en ensamblador con el otro programa que acabo de dejar también en esta sección del foro, y utilizarlo en nuestros programas para PCW.
Es un indispensable en mis proyectos para PCW, como Quijote, Samaruc GUI, DeskJoy, The Same Game, etc.
Supongo que se puede adaptar para generar ficheros compatibles con otros sistemas.
Saludos.
Código: Seleccionar todo
/* bmptoscr.c
Converts a BMP bitmap file into a SCR image file as
used in Quijote for the Amstrad PCW.
(C) 2007 Floppy Software, Valencia, Spain.
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Compiled with MESCC.
Revisions:
28 Apr 2007 : v1.00
Notes:
Width and height must be multiply of 8.
Only black and white images are supported.
*/
#include <mescc.h>
#include <fileio.h>
#include <printf.h>
#define VERSION "1.0 / 28 Apr 2007"
FILE *ifp, *ofp;
unsigned char *bufbmp, *ptr;
int x, y, row, col, rows, cols;
int wide, high, sizeline;
putbyte(byte)
int byte;
{
if(fputc(byte, ofp)==EOF)
error("can't write");
return byte;
}
putword(word)
int word;
{
putbyte(word & 0xFF);
putbyte((word >> 8) & 0xFF);
return word;
}
getbyte()
{
int byte;
if((byte=fgetc(ifp))==EOF)
error("can't read");
return byte;
}
getword()
{
return (getbyte() & 0xFF) + ((getbyte() << 8) & 0xFF00);
}
getnull(num)
int num;
{
int i;
for(i=0; i!=num; ++i)
getbyte();
}
error(txt)
char *txt;
{
printf("ERROR: %s\n", txt);
exit(1);
}
main(argc, argv)
int argc, argv[];
{
printf("bmptoscr v%s\n\n", VERSION);
if(argc!=3)
{
printf("Usage - bmptoscr file.bmp file.scr");
exit(1);
}
/* Read header of bmp file */
if((ifp=fopen(argv[1],"rb"))==NULL)
error("can't open input file");
getnull(18);
if((wide=getword()) % 8)
error("Width must be 8 multiply");
getnull(2);
if((high=getword()) % 8)
error("Height must be 8 multiply");
getnull(38);
/* Write header of scr file */
if((ofp=fopen(argv[2],"wb"))==NULL)
error("can't open output file");
putword((cols=(wide+7)/8)); /* Width in columns (bytes) */
putword((rows=(high+7)/8)); /* height in rows (bytes) */
sizeline=((wide+31)/32)*4; /* bmp line size in bytes (multiplo de 4)*/
if((bufbmp=malloc(rows*8*cols))==NULL)
error("no memory for buffer");
/* Read bmp data and store it in reverse order */
for(y=high; y; --y)
{
ptr=bufbmp+(y-1)*cols;
for(x=cols; x; --x)
*ptr++=getbyte();
getnull(sizeline-cols);
}
/* Write scr data */
for(y=0; y!=high; y+=8)
for(col=0; col!=cols; ++col)
for(row=0; row!=8; ++row)
putbyte(bufbmp[y*cols+col+row*cols]);
/* Close files and bye */
fclose(ifp);
fclose(ofp);
}