Updated license in file and added FIXME markers

This commit is contained in:
Tennessee Carmel-Veilleux 2014-07-23 15:36:35 -04:00
parent 11eb27cced
commit 18114bf7df

200
dcc6502.c
View File

@ -1,15 +1,29 @@
/**************************************************************/ /**********************************************************************************
/* DCC6502.c -> Main module of: */ * dcc6502.c -> Main module of: *
/* Disassembler and Cycle Counter for the 6502 microprocessor */ * Disassembler and Cycle Counter for the 6502 microprocessor *
/* */ * *
/* (C) 1998-2014 Tennessee Carmel-Veilleux(veilleux@ameth.org)*/ * This code is offered under the MIT License (MIT) *
/* This code is offered as FREEware. You cannot modify nor */ * *
/* distribute modified versions of this software without */ * Copyright (c) 2014 Tennessee Carmel-Veilleux <veilleux@tentech.ca *
/* prior written consent of the author(s). The author shall */ * *
/* NOT be responsible for ANY damage purely physical, */ * Permission is hereby granted, free of charge, to any person obtaining a copy *
/* emotional, material and magical to either you or anyone. */ * 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. *
**********************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -42,6 +56,7 @@ typedef struct OPcode {
unsigned char cross_page; /* 1 if cross-page boundaries affect cycles */ unsigned char cross_page; /* 1 if cross-page boundaries affect cycles */
} OPcode; } OPcode;
// FIXME: Stop using the needless union and become native-endianness-agnostic
typedef union typedef union
{ {
#ifdef LSB_FIRST #ifdef LSB_FIRST
@ -58,7 +73,8 @@ char name_table[56][4]={
"DEC", "DEX", "DEY", "EOR", "INC", "INX", "INY", "JMP", "JSR", "LDA", "DEC", "DEX", "DEY", "EOR", "INC", "INX", "INY", "JMP", "JSR", "LDA",
"LDX", "LDY", "LSR", "NOP", "ORA", "PHA", "PHP", "PLA", "PLP", "ROL", "LDX", "LDY", "LSR", "NOP", "ORA", "PHA", "PHP", "PLA", "PLP", "ROL",
"ROR", "RTI", "RTS", "SBC", "SEC", "SED", "SEI", "STA", "STX", "STY", "ROR", "RTI", "RTS", "SBC", "SEC", "SED", "SEI", "STA", "STX", "STY",
"TAX", "TAY", "TSX", "TXA", "TXS", "TYA"}; "TAX", "TAY", "TSX", "TXA", "TXS", "TYA"
};
/* Opcode table */ /* Opcode table */
OPcode opcode_table[NUMBER_OPCODES] = { OPcode opcode_table[NUMBER_OPCODES] = {
@ -270,6 +286,8 @@ OPcode opcode_table[NUMBER_OPCODES] = {
{0x98, 55, IMPLI, 2, 0} /* TYA */ {0x98, 55, IMPLI, 2, 0} /* TYA */
}; };
// FIXME: use stdint types
// FIXME: use g_ nomenclature for globals
unsigned short org; /* Origin of addresses */ unsigned short org; /* Origin of addresses */
char hex_output = 0; /* 1 if hex output is desired at beginning of line */ char hex_output = 0; /* 1 if hex output is desired at beginning of line */
char cycle_counting = 0; /* 1 if we want cycle counting */ char cycle_counting = 0; /* 1 if we want cycle counting */
@ -285,7 +303,7 @@ char line[512];
void emit_header(char *filename, int fsize, unsigned short org) { void emit_header(char *filename, int fsize, unsigned short org) {
fprintf(stdout, "; Source generated by DCC6502 version %s\n", VERSION_INFO); fprintf(stdout, "; Source generated by DCC6502 version %s\n", VERSION_INFO);
fprintf(stdout, "; For more info about DCC6502, e-mail veilleux@ameth.org\n;\n"); fprintf(stdout, "; For more info about DCC6502, see https://github.com/tcarmelveilleux/dcc6502\n");
fprintf(stdout, "; FILENAME: %s, File Size: %d, ORG: $%04X\n", filename, fsize, org); fprintf(stdout, "; FILENAME: %s, File Size: %d, ORG: $%04X\n", filename, fsize, org);
if (hex_output) fprintf(stdout, "; -> Hex output enabled\n"); if (hex_output) fprintf(stdout, "; -> Hex output enabled\n");
if (cycle_counting) fprintf(stdout, "; -> Cycle counting enabled\n"); if (cycle_counting) fprintf(stdout, "; -> Cycle counting enabled\n");
@ -301,7 +319,9 @@ void append_cycle(char *input, unsigned char entry, unsigned short arg, unsigned
cycles = opcode_table[entry].cycles; cycles = opcode_table[entry].cycles;
sprintf(tmpstr, " Cycles: %d ", cycles); sprintf(tmpstr, " Cycles: %d ", cycles);
if (opcode_table[entry].cross_page) strcat(tmpstr, "*!* "); if (opcode_table[entry].cross_page) {
strcat(tmpstr, "*!* ");
}
strcat(input, tmpstr); strcat(input, tmpstr);
} }
@ -347,6 +367,7 @@ void append_nes(char *input, unsigned short arg) {
} }
} }
// FIXME: Refactor code to reduce line duplication and make more readable
/* This function disassembles the opcode at the PC and outputs it in *output */ /* This function disassembles the opcode at the PC and outputs it in *output */
void disassemble(char *output) { void disassemble(char *output) {
unsigned char tmp_byte1, tmp_byte2, opcode; unsigned char tmp_byte1, tmp_byte2, opcode;
@ -379,13 +400,16 @@ void disassemble(char *output) {
case IMMED: case IMMED:
PC++; PC++;
tmp_byte1 = buffer[PC]; /* Get immediate value */ tmp_byte1 = buffer[PC]; /* Get immediate value */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X:\t%s #$%02x\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X> %02X %02X:\t%s #$%02x\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1);
else } else {
sprintf(tmpstr, "$%04X\t%s #$%02x\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X\t%s #$%02x\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC-1, org+PC-1); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC-1, org+PC-1);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -401,10 +425,14 @@ void disassemble(char *output) {
sprintf(tmpstr, "$%04X\t%s $%02X%02X\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l); sprintf(tmpstr, "$%04X\t%s $%02X%02X\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l);
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, tmp_word.W, org+PC-2); if (cycle_counting) {
append_cycle(tmpstr, entry, tmp_word.W, org+PC-2);
}
/* Add NES port info if necessary */ /* Add NES port info if necessary */
if (nes_mode) append_nes(tmpstr, tmp_word.W); if (nes_mode) {
append_nes(tmpstr, tmp_word.W);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -412,25 +440,31 @@ void disassemble(char *output) {
PC++; PC++;
tmp_byte1 = buffer[PC]; /* Get low byte of address */ tmp_byte1 = buffer[PC]; /* Get low byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%02X\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%02X\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1);
else } else {
sprintf(tmpstr, "$%04X\t%s $%02X\t\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X\t%s $%02X\t\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC-1, org+PC-1); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC-1, org+PC-1);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
case IMPLI: case IMPLI:
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X:\t%s\t\t;", org+PC, opcode, name_table[opcode_table[entry].name]); sprintf(tmpstr, "$%04X> %02X:\t%s\t\t;", org+PC, opcode, name_table[opcode_table[entry].name]);
else } else {
sprintf(tmpstr, "$%04X\t%s\t\t;", org+PC, name_table[opcode_table[entry].name]); sprintf(tmpstr, "$%04X\t%s\t\t;", org+PC, name_table[opcode_table[entry].name]);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC, org+PC); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC, org+PC);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -441,13 +475,16 @@ void disassemble(char *output) {
PC++; PC++;
tmp_word.B.h = buffer[PC]; /* Get high byte of address */ tmp_word.B.h = buffer[PC]; /* Get high byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X%02X:\t%s ($%02X%02X)\t;", org+PC-2, opcode, tmp_word.B.l, tmp_word.B.h, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l); sprintf(tmpstr, "$%04X> %02X %02X%02X:\t%s ($%02X%02X)\t;", org+PC-2, opcode, tmp_word.B.l, tmp_word.B.h, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l);
else } else {
sprintf(tmpstr, "$%04X\t%s ($%02X%02X)\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l); sprintf(tmpstr, "$%04X\t%s ($%02X%02X)\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, tmp_word.W, org+PC-2); if (cycle_counting) {
append_cycle(tmpstr, entry, tmp_word.W, org+PC-2);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -458,16 +495,22 @@ void disassemble(char *output) {
PC++; PC++;
tmp_word.B.h = buffer[PC]; /* Get high byte of address */ tmp_word.B.h = buffer[PC]; /* Get high byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X%02X:\t%s $%02X%02X,X\t;", org+PC-2, opcode, tmp_word.B.l, tmp_word.B.h, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l); sprintf(tmpstr, "$%04X> %02X %02X%02X:\t%s $%02X%02X,X\t;", org+PC-2, opcode, tmp_word.B.l, tmp_word.B.h, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l);
else } else {
sprintf(tmpstr, "$%04X\t%s $%02X%02X,X\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l); sprintf(tmpstr, "$%04X\t%s $%02X%02X,X\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, tmp_word.W, org+PC-2); if (cycle_counting) {
append_cycle(tmpstr, entry, tmp_word.W, org+PC-2);
}
/* Add NES port info if necessary */ /* Add NES port info if necessary */
if (nes_mode) append_nes(tmpstr, tmp_word.W); if (nes_mode) {
append_nes(tmpstr, tmp_word.W);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -477,16 +520,22 @@ void disassemble(char *output) {
PC++; PC++;
tmp_word.B.h = buffer[PC]; /* Get high byte of address */ tmp_word.B.h = buffer[PC]; /* Get high byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X%02X:\t%s $%02X%02X,Y\t;", org+PC-2, opcode, tmp_word.B.l, tmp_word.B.h, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l); sprintf(tmpstr, "$%04X> %02X %02X%02X:\t%s $%02X%02X,Y\t;", org+PC-2, opcode, tmp_word.B.l, tmp_word.B.h, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l);
else } else {
sprintf(tmpstr, "$%04X\t%s $%02X%02X,Y\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l); sprintf(tmpstr, "$%04X\t%s $%02X%02X,Y\t;", org+PC-2, name_table[opcode_table[entry].name], tmp_word.B.h, tmp_word.B.l);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, tmp_word.W, org+PC-2); if (cycle_counting) {
append_cycle(tmpstr, entry, tmp_word.W, org+PC-2);
}
/* Add NES port info if necessary */ /* Add NES port info if necessary */
if (nes_mode) append_nes(tmpstr, tmp_word.W); if (nes_mode) {
append_nes(tmpstr, tmp_word.W);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -494,13 +543,16 @@ void disassemble(char *output) {
PC++; PC++;
tmp_byte1 = buffer[PC]; /* Get low byte of address */ tmp_byte1 = buffer[PC]; /* Get low byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%02X,X\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%02X,X\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1);
else } else {
sprintf(tmpstr, "$%04X\t%s $%02X,X\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X\t%s $%02X,X\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC-1, org+PC-1); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC-1, org+PC-1);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -509,13 +561,16 @@ void disassemble(char *output) {
PC++; PC++;
tmp_byte1 = buffer[PC]; /* Get low byte of address */ tmp_byte1 = buffer[PC]; /* Get low byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%02X,Y\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%02X,Y\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1);
else } else {
sprintf(tmpstr, "$%04X\t%s $%02X,Y\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X\t%s $%02X,Y\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC-1, org+PC-1); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC-1, org+PC-1);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -524,13 +579,16 @@ void disassemble(char *output) {
PC++; PC++;
tmp_byte1 = buffer[PC]; /* Get low byte of address */ tmp_byte1 = buffer[PC]; /* Get low byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X:\t%s ($%02X,X)\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X> %02X %02X:\t%s ($%02X,X)\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1);
else } else {
sprintf(tmpstr, "$%04X\t%s ($%02X,X)\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X\t%s ($%02X,X)\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC-1, org+PC-1); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC-1, org+PC-1);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -539,13 +597,16 @@ void disassemble(char *output) {
PC++; PC++;
tmp_byte1 = buffer[PC]; /* Get low byte of address */ tmp_byte1 = buffer[PC]; /* Get low byte of address */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X:\t%s ($%02X),Y\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X> %02X %02X:\t%s ($%02X),Y\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], tmp_byte1);
else } else {
sprintf(tmpstr, "$%04X\t%s ($%02X),Y\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1); sprintf(tmpstr, "$%04X\t%s ($%02X),Y\t;", org+PC-1, name_table[opcode_table[entry].name], tmp_byte1);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC-1, org+PC-1); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC-1, org+PC-1);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -554,25 +615,31 @@ void disassemble(char *output) {
PC++; PC++;
tmp_byte1 = buffer[PC]; /* Get relative modifier */ tmp_byte1 = buffer[PC]; /* Get relative modifier */
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%04X\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], (org+PC)+(signed char)(tmp_byte1)+1); sprintf(tmpstr, "$%04X> %02X %02X:\t%s $%04X\t\t;", org+PC-1, opcode, tmp_byte1, name_table[opcode_table[entry].name], (org+PC)+(signed char)(tmp_byte1)+1);
else } else {
sprintf(tmpstr, "$%04X\t%s $%04X\t;", org+PC-1, name_table[opcode_table[entry].name], (org+PC)+(signed char)(tmp_byte1)+1); sprintf(tmpstr, "$%04X\t%s $%04X\t;", org+PC-1, name_table[opcode_table[entry].name], (org+PC)+(signed char)(tmp_byte1)+1);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC, org+PC); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC, org+PC);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
case ACCUM: case ACCUM:
if (hex_output) if (hex_output) {
sprintf(tmpstr, "$%04X> %02X:\t%s A\t\t;", org+PC, opcode, name_table[opcode_table[entry].name]); sprintf(tmpstr, "$%04X> %02X:\t%s A\t\t;", org+PC, opcode, name_table[opcode_table[entry].name]);
else } else {
sprintf(tmpstr, "$%04X\t%s A\t\t;", org+PC, name_table[opcode_table[entry].name]); sprintf(tmpstr, "$%04X\t%s A\t\t;", org+PC, name_table[opcode_table[entry].name]);
}
/* Add cycle count if necessary */ /* Add cycle count if necessary */
if (cycle_counting) append_cycle(tmpstr, entry, org+PC, org+PC); if (cycle_counting) {
append_cycle(tmpstr, entry, org+PC, org+PC);
}
strncpy(output, tmpstr, 254); strncpy(output, tmpstr, 254);
break; break;
@ -584,8 +651,9 @@ void disassemble(char *output) {
} }
void version(void) { void version(void) {
fprintf(stderr, "DCC6502 %s (C)1998-2014 Tennessee Carmel-Veilleux\n", VERSION_INFO); fprintf(stderr, "DCC6502 %s (C)1998-2014 Tennessee Carmel-Veilleux <veilleux@tentech.ca>\n", VERSION_INFO);
fprintf(stderr, "This is free software. To see the LICENSE, use the -v parameter\n"); fprintf(stderr, "This software is licensed under the MIT license. See the LICENSE file.\n");
fprintf(stderr, "See source on github: https://github.com/tcarmelveilleux/dcc6502.\n");
} }
void usage_helper(char *str) { void usage_helper(char *str) {
@ -603,15 +671,7 @@ void usage(void) {
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
void license(void) { // FIXME: DE-KLUDGIFY THIS :D
fprintf(stderr, "(C) 1998-2014 Tennessee Carmel-Veilleux(veilleux@ameth.org)\n");
fprintf(stderr, "This code is offered as FREEware. You cannot modify nor\n");
fprintf(stderr, "distribute modified versions of this software without\n");
fprintf(stderr, "prior written consent of the author(s). The author shall\n");
fprintf(stderr, "NOT be responsible for ANY damage purely physical,\n");
fprintf(stderr, "emotional, material and magical to either you or anyone.\n");
}
unsigned short hex2int (char *str, unsigned short dfl) { unsigned short hex2int (char *str, unsigned short dfl) {
char HEX_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; char HEX_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
int i, j; int i, j;
@ -626,7 +686,9 @@ unsigned short hex2int (char *str, unsigned short dfl) {
} }
c = toupper(str[i]); c = toupper(str[i]);
for (j = 0; j < 16; j++) { for (j = 0; j < 16; j++) {
if (c == HEX_digits[j]) k = j; if (c == HEX_digits[j]) {
k = j;
}
} }
tmp |= ((k & 0xf) << shift); tmp |= ((k & 0xf) << shift);
shift += 4; shift += 4;
@ -682,7 +744,6 @@ int main(int argc, char *argv[]) {
case '?': case '?':
version(); version();
usage(); usage();
license();
exit(0); exit(0);
break; break;
case 'n': case 'n':
@ -696,7 +757,6 @@ int main(int argc, char *argv[]) {
break; break;
case 'v': case 'v':
version(); version();
license();
exit(0); exit(0);
break; break;
case 'o': case 'o':
@ -720,12 +780,10 @@ int main(int argc, char *argv[]) {
case '?': case '?':
version(); version();
usage(); usage();
license();
exit(0); exit(0);
break; break;
case 'v': case 'v':
version(); version();
license();
exit(0); exit(0);
break; break;
default: default: