You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.7 KiB
86 lines
1.7 KiB
#include "constants.h"
|
|
#include "file.h"
|
|
|
|
#define _GNU_SOURCE
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <getopt.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <sys/stat.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "emu.c"
|
|
|
|
uint16_t* fileRead(char* name) {
|
|
FILE* fp = fopen(name, "rb");
|
|
if (!(access(name, F_OK) == 0)) {
|
|
errno = -1;
|
|
printf("Hi?\n");
|
|
return 0;
|
|
}
|
|
|
|
struct stat st;
|
|
stat(name, &st);
|
|
int length = st.st_size;
|
|
|
|
uint16_t rbuf[length+1];
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
fread(&rbuf[i], 2, 1, fp);
|
|
}
|
|
fclose(fp);
|
|
|
|
uint16_t* tmp = rbuf;
|
|
return tmp;
|
|
}
|
|
|
|
//blanks out memory and initializes various things
|
|
int init() {
|
|
for (int i = 0; i <= 0xFFFF; i++) { //blank memory
|
|
memory[i] = 0x00;
|
|
}
|
|
|
|
cpuStatus.brk = 0;
|
|
cpuStatus.carry = 0;
|
|
cpuStatus.dec = 0;
|
|
cpuStatus.ird = 0;
|
|
cpuStatus.neg = 0;
|
|
cpuStatus.overflow = 0;
|
|
cpuStatus.zero = 0;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void help(char* exe) {
|
|
printf("%s - a 6502 emulator.\n"
|
|
" Usage: %s [prg]", exe, exe);
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
char* filename = *++argv; //TODO: jankiest thing ever
|
|
|
|
/*uint16_t* binary = (uint16_t*)fileRead(filename);
|
|
|
|
//uint16_t binary[] = {0xe7e6, 0xeaea, 0x01e6, 0xe8ea, 0xc8ea, 0x00ea};
|
|
int size = sizeof(binary)/sizeof(binary[0])+1;
|
|
uint8_t exec[size*2];
|
|
for (int i,i2 = 0; i < size-1; i++) {
|
|
printf("%04X\n", binary[i]);
|
|
uint8_t lsb = (binary[i] & 0xFF);
|
|
uint8_t hsb = (binary[i] & 0xFF00) >> 8;
|
|
exec[i2] = lsb;
|
|
exec[++i2] = hsb;
|
|
i2++;
|
|
}*/
|
|
uint8_t* exec = (uint8_t*)bin;
|
|
int size = __6502_functional_test_bin_len;
|
|
printf("Program ROM:\n");
|
|
for (int i = 0; i < size; i++) {
|
|
printf("0x%02X\n", exec[i]);
|
|
}
|
|
emulate(exec, size, 0x0400); //hacky lol
|
|
return 0;
|
|
}
|