mirror of
https://github.com/cc65/cc65.git
synced 2025-03-22 11:29:40 +00:00
Added the main conversion module. New option --convert-to. New short options
for --read and --write. git-svn-id: svn://svn.cc65.org/cc65/trunk@5586 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
b55c290823
commit
1aaff0ce2f
src/sp65
59
src/sp65/convert.c
Normal file
59
src/sp65/convert.c
Normal file
@ -0,0 +1,59 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* convert.c */
|
||||
/* */
|
||||
/* Main target conversion module for the sp65 file and bitmap utility */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
/* warranty. In no event will the authors be held liable for any damages */
|
||||
/* arising from the use of this software. */
|
||||
/* */
|
||||
/* Permission is granted to anyone to use this software for any purpose, */
|
||||
/* including commercial applications, and to alter it and redistribute it */
|
||||
/* freely, subject to the following restrictions: */
|
||||
/* */
|
||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||
/* claim that you wrote the original software. If you use this software */
|
||||
/* in a product, an acknowledgment in the product documentation would be */
|
||||
/* appreciated but is not required. */
|
||||
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||
/* be misrepresented as being the original software. */
|
||||
/* 3. This notice may not be removed or altered from any source */
|
||||
/* distribution. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* sp65 */
|
||||
#include "convert.h"
|
||||
#include "koala.h"
|
||||
#include "vic2sprite.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
StrBuf* ConvertTo (const Bitmap* B, const Collection* A)
|
||||
/* Convert the bitmap B into some sort of other binary format. The output is
|
||||
* stored in a string buffer (which is actually a dynamic char array) and
|
||||
* returned. The actual output format is taken from the "format" attribute
|
||||
* in the attribute collection A.
|
||||
*/
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
70
src/sp65/convert.h
Normal file
70
src/sp65/convert.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*****************************************************************************/
|
||||
/* */
|
||||
/* convert.h */
|
||||
/* */
|
||||
/* Main target conversion module for the sp65 file and bitmap utility */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
/* */
|
||||
/* */
|
||||
/* This software is provided 'as-is', without any expressed or implied */
|
||||
/* warranty. In no event will the authors be held liable for any damages */
|
||||
/* arising from the use of this software. */
|
||||
/* */
|
||||
/* Permission is granted to anyone to use this software for any purpose, */
|
||||
/* including commercial applications, and to alter it and redistribute it */
|
||||
/* freely, subject to the following restrictions: */
|
||||
/* */
|
||||
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||
/* claim that you wrote the original software. If you use this software */
|
||||
/* in a product, an acknowledgment in the product documentation would be */
|
||||
/* appreciated but is not required. */
|
||||
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||
/* be misrepresented as being the original software. */
|
||||
/* 3. This notice may not be removed or altered from any source */
|
||||
/* distribution. */
|
||||
/* */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifndef CONVERT_H
|
||||
#define CONVERT_H
|
||||
|
||||
|
||||
|
||||
/* common */
|
||||
#include "coll.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
/* sp65 */
|
||||
#include "bitmap.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
StrBuf* ConvertTo (const Bitmap* B, const Collection* A);
|
||||
/* Convert the bitmap B into some sort of other binary format. The output is
|
||||
* stored in a string buffer (which is actually a dynamic char array) and
|
||||
* returned. The actual output format is taken from the "format" attribute
|
||||
* in the attribute collection A.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* End of convert.h */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
|
||||
/* sp65 */
|
||||
#include "attr.h"
|
||||
#include "convert.h"
|
||||
#include "error.h"
|
||||
#include "input.h"
|
||||
#include "output.h"
|
||||
@ -61,9 +62,12 @@
|
||||
/* Bitmap first read */
|
||||
static Bitmap* B;
|
||||
|
||||
/* Bitmap last processed */
|
||||
/* Bitmap working copy */
|
||||
static Bitmap* C;
|
||||
|
||||
/* Output data from convertion */
|
||||
static StrBuf* D;
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
@ -79,17 +83,21 @@ static void Usage (void)
|
||||
"Usage: %s [options] file [options] [file]\n"
|
||||
"Short options:\n"
|
||||
" -V\t\t\t\tPrint the version number and exit\n"
|
||||
" -c fmt[,attrlist]\t\tConvert into target format\n"
|
||||
" -h\t\t\t\tHelp (this text)\n"
|
||||
" -r file[,attrlist]\t\tRead an input file\n"
|
||||
" -v\t\t\t\tIncrease verbosity\n"
|
||||
" -w file[,attrlist]\t\tWrite the output to a file\n"
|
||||
"\n"
|
||||
"Long options:\n"
|
||||
" --convert-to fmt[,attrlist]\tConvert into target format\n"
|
||||
" --help\t\t\tHelp (this text)\n"
|
||||
" --pop\t\t\t\tRestore the original loaded image\n"
|
||||
" --read file[,attrlist]\tRead an input file\n"
|
||||
" --slice x,y,w,h\t\tGenerate a slice from the loaded bitmap\n"
|
||||
" --verbose\t\t\tIncrease verbosity\n"
|
||||
" --version\t\t\tPrint the version number and exit\n"
|
||||
" --write file[,attrlist]\tWrite an output file\n",
|
||||
" --write file[,attrlist]\tWrite the output to a file\n",
|
||||
ProgName);
|
||||
}
|
||||
|
||||
@ -111,6 +119,46 @@ static void SetWorkBitmap (Bitmap* N)
|
||||
|
||||
|
||||
|
||||
static void SetOutputData (StrBuf* N)
|
||||
/* Delete the old output data and replace it by the given one. The new one
|
||||
* may be NULL to clear it.
|
||||
*/
|
||||
{
|
||||
/* Delete the old output data */
|
||||
if (D != 0) {
|
||||
FreeStrBuf (D);
|
||||
}
|
||||
|
||||
/* Set the new one */
|
||||
D = N;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptConvertTo (const char* Opt attribute ((unused)), const char* Arg)
|
||||
/* Convert the bitmap into a target format */
|
||||
{
|
||||
static const char* NameList[] = {
|
||||
"format"
|
||||
};
|
||||
|
||||
/* Parse the argument */
|
||||
Collection* A = ParseAttrList (Arg, NameList, 2);
|
||||
|
||||
/* We must have a bitmap */
|
||||
if (C == 0) {
|
||||
Error ("No bitmap to convert");
|
||||
}
|
||||
|
||||
/* Convert the bitmap */
|
||||
SetOutputData (ConvertTo (C, A));
|
||||
|
||||
/* Delete the attribute list */
|
||||
FreeCollection (A);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptHelp (const char* Opt attribute ((unused)),
|
||||
const char* Arg attribute ((unused)))
|
||||
/* Print usage information and exit */
|
||||
@ -250,6 +298,9 @@ static void OptWrite (const char* Opt, const char* Arg)
|
||||
|
||||
/* Write the file */
|
||||
WriteOutputFile (FileName, 0, OF);
|
||||
|
||||
/* Delete the attribute list */
|
||||
FreeCollection (A);
|
||||
}
|
||||
|
||||
|
||||
@ -259,6 +310,7 @@ int main (int argc, char* argv [])
|
||||
{
|
||||
/* Program long options */
|
||||
static const LongOpt OptTab[] = {
|
||||
{ "--convert-to", 1, OptConvertTo },
|
||||
{ "--help", 0, OptHelp },
|
||||
{ "--pop", 0, OptPop },
|
||||
{ "--read", 1, OptRead },
|
||||
@ -292,6 +344,10 @@ int main (int argc, char* argv [])
|
||||
OptVersion (Arg, 0);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
OptConvertTo (Arg, GetArg (&I, 2));
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
OptHelp (Arg, 0);
|
||||
break;
|
||||
@ -304,6 +360,10 @@ int main (int argc, char* argv [])
|
||||
OptVerbose (Arg, 0);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
OptWrite (Arg, GetArg (&I, 2));
|
||||
break;
|
||||
|
||||
default:
|
||||
UnknownOption (Arg);
|
||||
break;
|
||||
|
@ -27,7 +27,8 @@ OBJS = asm.o \
|
||||
bin.o \
|
||||
bitmap.o \
|
||||
color.o \
|
||||
error.o \
|
||||
convert.o \
|
||||
error.o \
|
||||
fileio.o \
|
||||
input.o \
|
||||
koala.o \
|
||||
|
@ -65,7 +65,8 @@ OBJS = asm.obj \
|
||||
bin.obj \
|
||||
bitmap.obj \
|
||||
color.obj \
|
||||
error.obj \
|
||||
convert.obj \
|
||||
error.obj \
|
||||
fileio.obj \
|
||||
input.obj \
|
||||
koala.obj \
|
||||
|
Loading…
x
Reference in New Issue
Block a user