mirror of https://github.com/wwarthen/RomWBW.git
6 changed files with 1 additions and 155 deletions
Binary file not shown.
@ -1,21 +0,0 @@ |
|||||
MIT License |
|
||||
|
|
||||
Copyright (c) 2016 ipatix |
|
||||
|
|
||||
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. |
|
||||
@ -1,20 +0,0 @@ |
|||||
CC = gcc |
|
||||
STRIP = strip |
|
||||
CFLAGS = -Werror -Wall -Wextra -Wconversion -O2 -D NDEBUG |
|
||||
BINARY = bin2asm |
|
||||
|
|
||||
SRC_FILES = $(wildcard *.c) |
|
||||
OBJ_FILES = $(SRC_FILES:.c=.o) |
|
||||
|
|
||||
all: $(BINARY) |
|
||||
|
|
||||
.PHONY: clean |
|
||||
clean: |
|
||||
rm -f $(OBJ_FILES) |
|
||||
|
|
||||
$(BINARY): $(OBJ_FILES) |
|
||||
$(CC) -o $@ $^ $(LIBS) |
|
||||
$(STRIP) -s $@ |
|
||||
|
|
||||
%.o: %.c |
|
||||
$(CC) -c -o $@ $< $(CFLAGS) $(IMPORT) |
|
||||
@ -1,5 +0,0 @@ |
|||||
# bin2asm |
|
||||
Converts binary files to ASM compatible assembly files |
|
||||
|
|
||||
Usage: |
|
||||
$ bin2asm hello.bin > hello.asm |
|
||||
@ -1,100 +0,0 @@ |
|||||
//bin2asm from Michael Panzlaff https://github.com/ipatix/bin2asm Thanks Mike.
|
|
||||
//Modified by Phil Summers difficultylevelhigh@gmail.com for ROMWBW
|
|
||||
|
|
||||
#include <stdio.h> |
|
||||
#include <stdlib.h> |
|
||||
#include <string.h> |
|
||||
#include <libgen.h> |
|
||||
|
|
||||
void die(const char msg[]) { |
|
||||
perror(msg); |
|
||||
exit(EXIT_FAILURE); |
|
||||
} |
|
||||
|
|
||||
int main(int argc, char *argv[]) { |
|
||||
for (int i = 1; i < argc; i++) { |
|
||||
// determine file size
|
|
||||
FILE *input_file = fopen(argv[i], "rb"); |
|
||||
if (!input_file) { |
|
||||
fprintf(stderr, "fail %s\n", argv[i]); |
|
||||
die("Couldn't open input file"); |
|
||||
} |
|
||||
if (fseek(input_file, 0, SEEK_END) == -1) { |
|
||||
die("Error determining file size"); |
|
||||
} |
|
||||
long file_size = ftell(input_file); |
|
||||
if (file_size == -1) { |
|
||||
die("Error determining file size (2)"); |
|
||||
} |
|
||||
if (fseek(input_file, 0, SEEK_SET) == -1) { |
|
||||
die("Error determining file size (3)"); |
|
||||
} |
|
||||
// get file name
|
|
||||
char *name = basename(argv[i]); |
|
||||
char *dot = strrchr(name, '.'); |
|
||||
if (dot) { |
|
||||
*dot = '\0'; |
|
||||
} |
|
||||
|
|
||||
// write lines
|
|
||||
while (file_size > 0) { |
|
||||
size_t bytes_read = (file_size > 8) ? 8 : (size_t)file_size; |
|
||||
unsigned char data_buf[8]; |
|
||||
size_t actual_read = fread(data_buf, 1, bytes_read, input_file); |
|
||||
if (actual_read != bytes_read) { |
|
||||
fprintf(stderr, "Error while reading file, only %d read instead of %d\n", (int)actual_read, (int)bytes_read); |
|
||||
if (feof(input_file)) |
|
||||
fprintf(stderr, "Reached end of file\n"); |
|
||||
if (ferror(input_file)) |
|
||||
fprintf(stderr, "An unknown error occured while reading the file\n"); |
|
||||
perror("ERROR"); |
|
||||
exit(EXIT_FAILURE); |
|
||||
} |
|
||||
switch (bytes_read) { |
|
||||
case 1: |
|
||||
printf(" .db $%02X\r\n", |
|
||||
data_buf[0]); |
|
||||
break; |
|
||||
case 2: |
|
||||
printf(" .db $%02X, $%02X\r\n", |
|
||||
data_buf[0], data_buf[1]); |
|
||||
break; |
|
||||
case 3: |
|
||||
printf(" .db $%02X, $%02X, $%02X\r\n", |
|
||||
data_buf[0], data_buf[1], data_buf[2]); |
|
||||
break; |
|
||||
case 4: |
|
||||
printf(" .db $%02X, $%02X, $%02X, $%02X\r\n", |
|
||||
data_buf[0], data_buf[1], data_buf[2], data_buf[3]); |
|
||||
break; |
|
||||
case 5: |
|
||||
printf(" .db $%02X, $%02X, $%02X, $%02X, $%02X\r\n", |
|
||||
data_buf[0], data_buf[1], data_buf[2], data_buf[3], data_buf[4]); |
|
||||
break; |
|
||||
case 6: |
|
||||
printf(" .db $%02X, $%02X, $%02X, $%02X, $%02X, $%02X\r\n", |
|
||||
data_buf[0], data_buf[1], data_buf[2], data_buf[3], data_buf[4], data_buf[5]); |
|
||||
break; |
|
||||
case 7: |
|
||||
printf(" .db $%02X, $%02X, $%02X, $%02X, $%02X, $%02X, $%02X\r\n", |
|
||||
data_buf[0], data_buf[1], data_buf[2], data_buf[3], data_buf[4], data_buf[5], data_buf[6]); |
|
||||
break; |
|
||||
case 8: |
|
||||
printf(" .db $%02X, $%02X, $%02X, $%02X, $%02X, $%02X, $%02X, $%02X\r\n", |
|
||||
data_buf[0], data_buf[1], data_buf[2], data_buf[3], data_buf[4], data_buf[5], data_buf[6], data_buf[7]); |
|
||||
break; |
|
||||
default: |
|
||||
fprintf(stderr, "Invalid program state\n"); |
|
||||
exit(EXIT_FAILURE); |
|
||||
} |
|
||||
file_size -= (long)bytes_read; |
|
||||
} |
|
||||
|
|
||||
printf("\r\n"); |
|
||||
|
|
||||
if (fclose(input_file)) { |
|
||||
die("Error while closing file"); |
|
||||
} |
|
||||
} |
|
||||
return 0; |
|
||||
} |
|
||||
Loading…
Reference in new issue