gbaconv

A set of tools aimed at GameBoy Advance developers
Log | Files | Refs | README | LICENSE

commit cf0e28e5cedb0feeb89db5b9f81a96775df17312
parent 1c0c29c287649e53f61c93804cb6501a094253a9
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 21 Feb 2019 19:49:32 +0100

Reformat Makefile and both source files.

Diffstat:
MMakefile | 23++++++++++-------------
Mpcx2gba.c | 247++++++++++++++++++++++++++++++++++---------------------------------------------
Mwav2gba.c | 185++++++++++++++++++++++++++++++++++---------------------------------------------
3 files changed, 196 insertions(+), 259 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,16 +1,13 @@ -############################################################################### -# # -# GBAconv 1.00 # -# Copyright (c) 2002-2017, Frederic Cambus # -# https://github.com/fcambus/gbaconv # -# # -# Last Updated: 2017-02-07 # -# # -# GBAconv is released under the BSD 2-Clause license. # -# See LICENSE file for details. # -# # -############################################################################### - +# +# GBAconv 1.00 +# Copyright (c) 2002-2019, Frederic Cambus +# https://github.com/fcambus/gbaconv +# +# Last Updated: 2019-02-21 +# +# GBAconv is released under the BSD 2-Clause license. +# See LICENSE file for details. +# CC = gcc TARGET = all diff --git a/pcx2gba.c b/pcx2gba.c @@ -1,23 +1,21 @@ -/*****************************************************************************/ -/* */ -/* GBAconv 1.00 */ -/* Copyright (c) 2002-2017, Frederic Cambus */ -/* https://github.com/fcambus/gbaconv */ -/* */ -/* PCX to GBA Converter */ -/* */ -/* Created: 2002-12-09 */ -/* Last Updated: 2017-02-07 */ -/* */ -/* GBAconv is released under the BSD 2-Clause license. */ -/* See LICENSE file for details. */ -/* */ -/*****************************************************************************/ +/* + * GBAconv 1.00 + * Copyright (c) 2002-2017, Frederic Cambus + * https://github.com/fcambus/gbaconv + * + * PCX to GBA Converter + * + * Created: 2002-12-09 + * Last Updated: 2019-02-21 + * + * GBAconv is released under the BSD 2-Clause license. + * See LICENSE file for details. + */ -#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> FILE *input_file; unsigned char *input_file_buffer; @@ -27,24 +25,24 @@ struct stat input_file_stat; FILE *output_file; struct pcx_header { - char ID; - char version; - char encoding; - char bits_per_pixel; - short int x_min; - short int y_min; - short int x_max; - short int y_max; - short x_resolution; - short y_resolution; - char palette[48]; - char reserved; - char number_of_bit_planes; - short bytes_per_line; - short palette_type; - short x_screen_size; - short y_screen_size; - char filler[54]; + char ID; + char version; + char encoding; + char bits_per_pixel; + short int x_min; + short int y_min; + short int x_max; + short int y_max; + short x_resolution; + short y_resolution; + char palette[48]; + char reserved; + char number_of_bit_planes; + short bytes_per_line; + short palette_type; + short x_screen_size; + short y_screen_size; + char filler[54]; } pcx_header; unsigned char pcx_image_palette[768]; @@ -58,134 +56,103 @@ int offset; int run_count; int run_position; +int main(int argc, char *argv[]) { + printf("-------------------------------------------------------------------------------\n"); + printf(" PCX to GBA Converter - GBAconv 1.00 (c) by Frederic Cambus 2002-2017\n"); + printf("-------------------------------------------------------------------------------\n\n"); + if (argc != 4) { + printf("USAGE: pcx2gba input.pcx output.inc array_name (Input File must be 8-bpp PCX)\n\n"); + exit(0); + } -/*****************************************************************************/ -/* Main */ -/*****************************************************************************/ - -int main (int argc, char *argv[]) { - printf("-------------------------------------------------------------------------------\n"); - printf(" PCX to GBA Converter - GBAconv 1.00 (c) by Frederic Cambus 2002-2017\n"); - printf("-------------------------------------------------------------------------------\n\n"); - - if (argc!=4) { - printf("USAGE: pcx2gba input.pcx output.inc array_name (Input File must be 8-bpp PCX)\n\n"); - exit(0); - } - - - -/*****************************************************************************/ -/* Load Input File */ -/*****************************************************************************/ - - stat (argv[1], &input_file_stat); - input_file_size=input_file_stat.st_size; - - input_file_buffer=malloc(input_file_size); - - if (input_file_buffer==NULL) { - printf("ERROR: Cannot allocate memory\n\n"); - exit(-1); - } - - input_file=fopen(argv[1],"rb"); - if (input_file==NULL) { - printf("ERROR: Cannot open file %s\n\n",argv[1]); - exit(-1); - } - - fread(input_file_buffer,input_file_size,1,input_file); - fclose(input_file); - - - -/*****************************************************************************/ -/* Check that the file is a valid 8-bpp PCX */ -/*****************************************************************************/ - - memcpy(&pcx_header,input_file_buffer,128); - - if (pcx_header.bits_per_pixel!=8) { - printf("ERROR: Input File is not 8-bpp\n\n"); - exit(-1); - } - - - -/*****************************************************************************/ -/* Uncompress RLE encoded PCX Input File */ -/*****************************************************************************/ + /* Load Input File */ + stat(argv[1], &input_file_stat); + input_file_size = input_file_stat.st_size; - pcx_buffer_size=(pcx_header.x_max+1)*(pcx_header.y_max+1); - pcx_buffer=malloc(pcx_buffer_size); + input_file_buffer = malloc(input_file_size); - while (loop<input_file_size-768-128) { - current_byte=input_file_buffer[loop+128]; + if (input_file_buffer == NULL) { + printf("ERROR: Cannot allocate memory\n\n"); + exit(-1); + } - if (current_byte>192) { - run_count=current_byte-192; + input_file = fopen(argv[1], "rb"); + if (input_file == NULL) { + printf("ERROR: Cannot open file %s\n\n", argv[1]); + exit(-1); + } - for (run_position=0;run_position<run_count;run_position++) { - pcx_buffer[offset+run_position]=input_file_buffer[loop+128+1]; - } - offset+=run_count; - loop+=2; - } else { - pcx_buffer[offset]=current_byte; - offset++; - loop++; - } - } + fread(input_file_buffer, input_file_size, 1, input_file); + fclose(input_file); - for (loop=0;loop<768;loop++) { - pcx_image_palette[loop]=(input_file_buffer[input_file_size-768+loop]/8); - } + /* Check that the file is a valid 8-bpp PCX */ + memcpy(&pcx_header, input_file_buffer, 128); + if (pcx_header.bits_per_pixel != 8) { + printf("ERROR: Input File is not 8-bpp\n\n"); + exit(-1); + } + /* Uncompress RLE encoded PCX Input File */ + pcx_buffer_size = (pcx_header.x_max+1)*(pcx_header.y_max+1); + pcx_buffer = malloc(pcx_buffer_size); -/*****************************************************************************/ -/* Create Output File */ -/*****************************************************************************/ + while (loop < input_file_size-768-128) { + current_byte = input_file_buffer[loop+128]; - output_file=fopen(argv[2],"w"); - if (output_file==NULL) { - printf("ERROR: Cannot create file %s\n\n",argv[2]); - exit(-1); - } + if (current_byte > 192) { + run_count = current_byte-192; - printf("INPUT FILE: %s (%ix%ix%i-bpp)\n",argv[1],pcx_header.x_max+1,pcx_header.y_max+1,pcx_header.bits_per_pixel); - printf("OUTPUT FILE: %s\n\n",argv[2]); + for (run_position = 0; run_position < run_count; run_position++) { + pcx_buffer[offset+run_position] = input_file_buffer[loop+128+1]; + } + offset += run_count; + loop += 2; + } else { + pcx_buffer[offset] = current_byte; + offset++; + loop++; + } + } - fprintf(output_file,"const u16 %s_palette[] = {\n", argv[3]); + for (loop = 0; loop < 768; loop++) { + pcx_image_palette[loop] = (input_file_buffer[input_file_size-768+loop]/8); + } - for (loop=0;loop<256;loop++) { - fprintf(output_file,"0x%x,",(pcx_image_palette[loop*3] | pcx_image_palette[(loop*3)+1]<<5 | pcx_image_palette[(loop*3)+2]<<10)); - } + /* Create Output File */ + output_file = fopen(argv[2], "w"); + if (output_file == NULL) { + printf("ERROR: Cannot create file %s\n\n", argv[2]); + exit(-1); + } - fseek(output_file,ftell(output_file)-1,0); - fprintf(output_file,"};\n\n"); + printf("INPUT FILE: %s (%ix%ix%i-bpp)\n", argv[1], pcx_header.x_max+1, pcx_header.y_max+1, pcx_header.bits_per_pixel); + printf("OUTPUT FILE: %s\n\n", argv[2]); - fprintf(output_file,"const u16 %s[] = {\n", argv[3]); + fprintf(output_file, "const u16 %s_palette[] = {\n", argv[3]); - for (loop=0;loop<pcx_buffer_size/2;loop++) { - fprintf(output_file,"0x%x,",(pcx_buffer[loop*2] | pcx_buffer[(loop*2)+1]<<8)); - } + for (loop = 0; loop < 256; loop++) { + fprintf(output_file, "0x%x,", (pcx_image_palette[loop*3] | pcx_image_palette[(loop*3)+1]<<5 | pcx_image_palette[(loop*3)+2]<<10)); + } - fseek(output_file,ftell(output_file)-1,0); - fprintf(output_file,"};\n"); + fseek(output_file, ftell(output_file)-1, 0); + fprintf(output_file, "};\n\n"); + fprintf(output_file, "const u16 %s[] = {\n", argv[3]); + for (loop = 0; loop < pcx_buffer_size/2; loop++) { + fprintf(output_file, "0x%x,", (pcx_buffer[loop*2] | pcx_buffer[(loop*2)+1]<<8)); + } -/*****************************************************************************/ -/* Terminate Program */ -/*****************************************************************************/ + fseek(output_file, ftell(output_file)-1, 0); + fprintf(output_file, "};\n"); - fclose(output_file); - free(input_file_buffer); + /* Terminate Program */ + fclose(output_file); + free(input_file_buffer); - printf("Successfully created file %s\n\n",argv[2]); + printf("Successfully created file %s\n\n", argv[2]); - return (0); + return (0); } diff --git a/wav2gba.c b/wav2gba.c @@ -1,23 +1,21 @@ -/*****************************************************************************/ -/* */ -/* GBAconv 1.00 */ -/* Copyright (c) 2002-2017, Frederic Cambus */ -/* https://github.com/fcambus/gbaconv */ -/* */ -/* WAV to GBA Converter */ -/* */ -/* Created: 2002-12-10 */ -/* Last Updated: 2017-02-07 */ -/* */ -/* GBAconv is released under the BSD 2-Clause license. */ -/* See LICENSE file for details. */ -/* */ -/*****************************************************************************/ +/* + * GBAconv 1.00 + * Copyright (c) 2002-2017, Frederic Cambus + * https://github.com/fcambus/gbaconv + * + * WAV to GBA Converter + * + * Created: 2002-12-10 + * Last Updated: 2019-02-21 + * + * GBAconv is released under the BSD 2-Clause license. + * See LICENSE file for details. + */ -#include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> FILE *input_file; char *input_file_buffer; @@ -27,115 +25,90 @@ struct stat input_file_stat; FILE *output_file; struct wave_header { - char chunk_ID[4]; - unsigned int chunk_size; - char format[4]; - char fmt_chunk[4]; - unsigned int fmt_chunk_size; - unsigned short int audio_format; - unsigned short int channels; - unsigned int sample_rate; - unsigned int byte_rate; - unsigned short int block_align; - unsigned short int bits_per_sample; - char data_chunk[4]; - unsigned int data_chunk_size; + char chunk_ID[4]; + unsigned int chunk_size; + char format[4]; + char fmt_chunk[4]; + unsigned int fmt_chunk_size; + unsigned short int audio_format; + unsigned short int channels; + unsigned int sample_rate; + unsigned int byte_rate; + unsigned short int block_align; + unsigned short int bits_per_sample; + char data_chunk[4]; + unsigned int data_chunk_size; } wave_header; int loop; +int main(int argc, char *argv[]) { + printf("-------------------------------------------------------------------------------\n"); + printf(" WAV to GBA Converter - GBAconv 1.00 (c) by Frederic Cambus 2002-2017\n"); + printf("-------------------------------------------------------------------------------\n\n"); + if (argc != 4) { + printf("USAGE: wav2gba input.wav output.inc array_name (Input File must be 8-bit, MONO)\n\n"); + exit(0); + } -/*****************************************************************************/ -/* Main */ -/*****************************************************************************/ - -int main (int argc, char *argv[]) { - printf("-------------------------------------------------------------------------------\n"); - printf(" WAV to GBA Converter - GBAconv 1.00 (c) by Frederic Cambus 2002-2017\n"); - printf("-------------------------------------------------------------------------------\n\n"); - - if (argc!=4) { - printf("USAGE: wav2gba input.wav output.inc array_name (Input File must be 8-bit, MONO)\n\n"); - exit(0); - } - - - -/*****************************************************************************/ -/* load input file */ -/*****************************************************************************/ - - stat (argv[1], &input_file_stat); - input_file_size=input_file_stat.st_size; - - input_file_buffer=malloc(input_file_size); - - if (input_file_buffer==NULL) { - printf("ERROR: Cannot allocate memory\n\n"); - exit(-1); - } - - input_file=fopen(argv[1],"rb"); - if (input_file==NULL) { - printf("ERROR: Cannot open file %s\n\n",argv[1]); - exit(-1); - } - - fread(input_file_buffer,input_file_size,1,input_file); - fclose(input_file); - - - -/*****************************************************************************/ -/* Check that the file is a valid 8-bit MONO WAV */ -/*****************************************************************************/ - - memcpy(&wave_header,input_file_buffer,44); + /* load input file */ + stat(argv[1], &input_file_stat); + input_file_size = input_file_stat.st_size; - if (wave_header.channels!=1) { - printf("ERROR: Input File is not MONO\n\n"); - exit(-1); - } + input_file_buffer = malloc(input_file_size); - if (wave_header.bits_per_sample!=8) { - printf("ERROR: Input File is not 8-bit\n\n"); - exit(-1); - } + if (input_file_buffer == NULL) { + printf("ERROR: Cannot allocate memory\n\n"); + exit(-1); + } + input_file = fopen(argv[1], "rb"); + if (input_file == NULL) { + printf("ERROR: Cannot open file %s\n\n", argv[1]); + exit(-1); + } + fread(input_file_buffer, input_file_size, 1, input_file); + fclose(input_file); -/*****************************************************************************/ -/* Create Output File */ -/*****************************************************************************/ + /* Check that the file is a valid 8-bit MONO WAV */ + memcpy(&wave_header, input_file_buffer, 44); - output_file=fopen(argv[2],"w"); - if (output_file==NULL) { - printf("ERROR: Cannot create file %s\n\n",argv[2]); - exit(-1); - } + if (wave_header.channels != 1) { + printf("ERROR: Input File is not MONO\n\n"); + exit(-1); + } - printf("INPUT FILE: %s (8-bit, MONO, %i Hz)\n",argv[1],wave_header.sample_rate); - printf("OUTPUT FILE: %s\n\n",argv[2]); + if (wave_header.bits_per_sample != 8) { + printf("ERROR: Input File is not 8-bit\n\n"); + exit(-1); + } - fprintf(output_file,"const s8 %s[] = {\n", argv[3]); + /* Create Output File */ + output_file = fopen(argv[2], "w"); + if (output_file == NULL) { + printf("ERROR: Cannot create file %s\n\n", argv[2]); + exit(-1); + } - for (loop=0;loop<input_file_size;loop++) { - fprintf(output_file,"0x%x,",input_file_buffer[44+loop]+128); - } - fseek(output_file,ftell(output_file)-1,0); - fprintf(output_file,"};\n"); + printf("INPUT FILE: %s (8-bit, MONO, %i Hz)\n", argv[1], wave_header.sample_rate); + printf("OUTPUT FILE: %s\n\n", argv[2]); + fprintf(output_file, "const s8 %s[] = {\n", argv[3]); + for (loop = 0; loop < input_file_size; loop++) { + fprintf(output_file, "0x%x,", input_file_buffer[44+loop]+128); + } -/*****************************************************************************/ -/* Terminate Program */ -/*****************************************************************************/ + fseek(output_file, ftell(output_file)-1, 0); + fprintf(output_file, "};\n"); - fclose(output_file); - free(input_file_buffer); + /* Terminate Program */ + fclose(output_file); + free(input_file_buffer); - printf("Successfully created file %s\n\n",argv[2]); + printf("Successfully created file %s\n\n", argv[2]); - return (0); + return (0); }