Bit16 value;
} Pointer;
-/* eprintf - Taken from "Practice of Programming" by Kernighan and Pike */
-static void eprintf(char *fmt, ...){
- va_list args;
-
- char *progname = "Assembler";
-
- fflush(stdout);
- if (progname != NULL)
- fprintf(stderr, "%s: ", progname);
-
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- va_end(args);
-
- if (fmt[0] != '\0' && fmt[strlen(fmt) -1] == ':')
- fprintf(stderr, " %s", strerror(errno));
- fprintf(stderr, "\n");
- exit(2); /* conventional value for failed execution */
-}
-/* emalloc - Taken from "Practice of Programming" by Kernighan and
- Pike. If memory allocatiion fails the program will print a message
- an exit. */
static void *emalloc(size_t n) {
- void *p;
-
- p = malloc(n);
- if (p == NULL)
- eprintf("malloc of %u bytes failed:", n);
+ void *p = malloc(n);
+ if (! p) abort();
return p;
}
-/* ecalloc - Dose the same thing as emalloc just calls calloc instead. */
static void *ecalloc(uint32_t nelm, size_t nsize){
- void *p;
-
- p = calloc(nelm, nsize);
- if (p == NULL)
- eprintf("calloc of %u bytes failed:", nelm * nsize);
+ void *p = calloc(nelm, nsize);
+ if (!p) abort();
return p;
}
Bit16 n;
switch(adm){
case SINGLE:
- output = "";
+ *output = 0;
break;
case IMMEDIATE_LESS:
case IMMEDIATE_GREAT:
sprintf(output,"$%x,x",n);
break;
case DCB_PARAM:
- output = "";
+ *output = 0;
break;
}
}
static void jmpSBC(machine_6502 *machine, AddrMode adm){
Pointer ptr;
- Bit8 vflag;
+ /*Bit8 vflag;*/
Bit8 c = bitOn(machine->regP, CARRY_FL);
Bit16 tmp, w;
BOOL isValue = getValue(machine, adm, &ptr);
warnValue(isValue);
- vflag = (bitOn(machine->regA,NEGATIVE_FL) &&
- bitOn(ptr.value, NEGATIVE_FL));
+ /*vflag = (bitOn(machine->regA,NEGATIVE_FL) &&
+ bitOn(ptr.value, NEGATIVE_FL));*/
if (bitOn(machine->regP, DECIMAL_FL)) {
Bit8 ar = nibble(machine->regA, RIGHT);
int i = 0;
char *buffer = ecalloc(defaultSize,sizeof(char));
- if (buffer == NULL)
- eprintf("Could not allocate memory for buffer.");
+ if (!buffer) abort();
ifp = fopen(filename, "rb");
- if (ifp == NULL)
- eprintf("Could not open file.");
+ if (!ifp) return 0;
while((c = getc(ifp)) != EOF){
buffer[i++] = c;
size += defaultSize;
buffer = realloc(buffer, size);
if (buffer == NULL) {
- fclose(ifp);
- eprintf("Could not resize buffer.");
+ abort();
}
}
}
fclose(ifp);
buffer = realloc(buffer, i+2);
- if (buffer == NULL)
- eprintf("Could not resize buffer.");
+ if (!buffer) abort();
/* Make sure we have a line feed at the end */
buffer[i] = '\n';
buffer[i+1] = '\0';
/* Bit16 end = pc + machine->codeLen; */
/* Bit16 n; */
/* ofp = fopen(filename, "w"); */
-/* if (ofp == NULL) */
-/* eprintf("Could not open file."); */
+/* if (!ofp) abort(); */
/* fprintf(ofp,"Bit8 prog[%d] =\n{",machine->codeLen); */
/* n = 1; */
}
else {
machine->regPC = machine->defaultCodePC;
- oldDefault = machine->defaultCodePC;
+ /*oldDefault = machine->defaultCodePC;*/
}
if (asmline->labelDecl) {
code = fileToBuffer(filename);
- if (! compileCode(machine, code) ){
- eprintf("Could not compile code.\n");
- }
+ if (! compileCode(machine, code) ) abort();
free(code);
code = fileToBuffer(filename);
- if (! compileCode(machine, code) ){
- eprintf("Could not compile code.\n");
- }
+ if (! compileCode(machine, code) ) abort();
free(code);