#include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <stdint.h> #include "fake6502.h" #define ROM "./build/kernel" uint8_t *ram; char charset[256] = { '@', 'P', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '1', 'A', 'Q', '"', '#', '$', '%', '&', '7', '(', ')', '*', '+', ',', '-', '.', '2', 'B', 'R', '"', '#', '$', '%', '&', 'g', '(', ')', '*', '+', ',', '-', '.', '3', 'C', 'S', '"', '#', '$', '%', '&', 'w', '(', ')', '*', '+', ',', '-', '.', '4', 'D', 'T', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '5', 'E', 'U', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '\0', 'F', 'V', '"', '#', '$', '%', '&', 'G', '(', ')', '*', '+', ',', '-', '.', '7', 'G', 'W', '"', '#', '$', '%', '&', 'W', '(', ')', '*', '+', ',', '-', '.', '8', 'H', 'X', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '9', 'I', 'Y', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', 'A', 'J', 'Z', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', 'B', 'K', '[', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', 'C', 'L', '\\', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', 'D', 'M', ']', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', 'E', 'N', '^', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', 'F', 'O', '_', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '0' }; int main( int argc, char **argv ) { int fd = 0; struct stat sb; int x = 0; printf( "6502 Emulation\n" ); ram = malloc( 65536 ); fd = open( ROM, O_RDONLY ); if( fd != -1 ) { stat( ROM, &sb ); read( fd, ram + (0x10000 - sb.st_size), sb.st_size); close( fd ); } reset6502(); //for( x = 0; x < 10000; x++ ) { while( 1 ) { step6502(); } return( 0x0 ); } uint8_t read6502(uint16_t address) { printf("read6502: 0x%X[0x%04X]\n", address, ram[address] ); /* if( address >= 0xC000 && address <= 0xCFFF) printf("read6502: 0x%X\n", address ); else if( address <= 0x00FF ) printf("read6502: 0x%X[0x%04X]\n", address, ram[address] ); */ return( ram[address] ); } void write6502(uint16_t address, uint8_t value) { printf("write6502: 0x%X[0x%X]\n", address, value ); if( address <= 0x1FF ) { //printf("PWS"); } else if( address >= 0x03D0 && address <= 0x03FF ) { //printf("V"); } else if( address >= 0x0400 && address <= 0x07FF ) { //printf("TP1: [0x%04X]", value); //printf("TP1: [0x%04X]", value); if( charset[value] != '\0' ) printf("%c\n", charset[value]); //else //printf("<%i>", value); } else if( address >= 0x0800 && address <= 0x0BFF ) { //printf("TP2: [0x%04X]", value); //printf("TP1: [0x%04X]", value); //printf("TP1: [0x%04X]", value); //if( charset[value] != '\0' ) // printf("%c", charset[value]); //else //printf("<%i>", value); } else if( address >= 0x2000 ) { // printf("OH: 0x%X", address); } ram[address] = value; }