void RiscComm::onConsoleInput(QString input) { m_sp->readAll(); // flush any residual crap out (from FPGA reset for example) if (input.compare("s") == 0) { sendStep(); doScan(); } else if (input.compare("sc") == 0) doScan(); else if (input.compare("q") == 0) QCoreApplication::exit(); else if (input.compare("r") == 0) sendRun(); else if (input.compare("rs") == 0) sendReset(); else if (input.compare("st") == 0) { sendStop(); doScan(); } else if (input.startsWith("wp")) { QStringList args = input.split(" "); if (args.length() == 2) { // upload a file sendProgram(args.at(1)); } } else if (input.compare("clrmem") == 0) { QByteArray zeros; zeros.fill(0, 256); writeMem(zeros, 0, true); } else if (input.compare("dm") == 0) { dumpMem(); } else qDebug() << "Unknown command:" << input; }
int main(void) { dumpMem(&b, sizeof(struct Bla)); printf("Sizeof %d\n", sizeof(struct Bla)); printf("Vals: %d %d %d\n", b.a, b.b, b.c); return 0; }
int main() { double d1=0.01; double d2=0.05; double ret=d1+d2; printf("0.01: "); dumpMem((char *)&d1, sizeof(double)); printf("80 out: %.80f\n", d1); printf("0.05: "); dumpMem((char *)&d2, sizeof(double)); printf("80 out: %.80f\n", d2); printf("result of 0.01+0.05: "); dumpMem((char *)&ret, sizeof(double)); printf("80 out: %.80f\n", ret); printf("18 out: %.18f\n", ret); printf("19 out: %.19f\n", ret); }
// Returns 1 if passed, 0 if failed. // int memTest (CYG_ADDRWORD startAddr, CYG_ADDRWORD endAddr) { CYG_ADDRWORD badAddr; // Addr test failed at diag_printf("\nWalking 1's test: "); if (onesTest((CYG_ADDRWORD *)startAddr) == FAILED) goto failed; diag_printf("passed"); diag_printf("\n32-bit address test: "); if (Addr32((cyg_uint32 *)startAddr, (cyg_uint32 *)endAddr, &badAddr) == FAILED) goto failed; diag_printf("passed"); diag_printf("\n32-bit address bar test: "); if (Bar32((cyg_uint32 *)startAddr, (cyg_uint32 *)endAddr, &badAddr) == FAILED) goto failed; diag_printf("passed"); diag_printf("\n8-bit address test: "); if (Addr8((cyg_uint8 *)startAddr, (cyg_uint8 *)endAddr, &badAddr) == FAILED) goto failed; diag_printf("passed"); diag_printf("\nByte address bar test: "); if (Bar8((cyg_uint8 *)startAddr, (cyg_uint8 *)endAddr, &badAddr) == FAILED) goto failed; diag_printf("passed"); return 1; failed: diag_printf("failed"); dumpMem(badAddr); return 0; }
int main(int argc, char **argv) { int cycles_to_run; char *machine_code; // This will hold our "ASCII Object File" char debug_command[180]="init"; char *cmdptr; unsigned int dbg_addr; printf("6502 simulator front end for CS 2208a.\n\n"); // Did the user specify an object file on the command line? // If not... help them. if(argc < 3) { printf("Usage: %s [ASCII Object File name] [# cycles to simulate] {-d}\n",argv[0]); printf(" e.g.: %s test.obj 3000 -d\n\n",argv[0]); exit(-1); } // Read the object file into a string. machine_code = read_obj_file(argv[1]); // Fire up the system RAM initMem(); // Load the object file from the string into our simulated RAM, // starting at memory location 'code_location'. loadMem(machine_code,code_location); // We did something horribly underhanded in read_obj_file()... // we allocated memory with 'malloc' and then passed back a pointer. // But note that the onus is on us, the C programmer, to _remember_ // that we did that and free up the memory when it's no longer needed. // Not a big deal here, but imagine a bigger program where you're keeping // track of hundreds of mallocs and frees. Now you know why C programs // leak memory like the titanic. free(machine_code); // Initialize the 6502 init6502(); reset6502(); PC = code_location; // Make sure the program counter points to our code! // All set to run the simulator now! // Everything below is just fanciness to give you a rudimentry 6502 debugger // to help with your assignment. Without the fancyness, all we're really doing // is one call: // // exec6502(num_cycles); // Run in debug mode, if requested if( (argc > 3) && (!strcmp(argv[3],"-d"))) { printf("Running in DEBUG MODE.\n\nType '?' for help.\n"); // Debug loop while(strcmp(debug_command,"quit")) { //dumpMem(0x0021); // Check the value we stored to the zero page //dumpMem(0x01FF); // Peek at the top of the stack. Remember, the stack // is hard-coded to addresses $0100–$01FF. //dump6502reg(); // print registers to the screen printf("debug> "); if( (gets(debug_command))[0] != '\0'){ cmdptr = strtok(debug_command," "); switch(cmdptr[0]) { case 'p': if(cmdptr = strtok(NULL," ")) { sscanf(cmdptr, "%x", &dbg_addr); dumpMem((WORD)dbg_addr); } break; case 'r': dump6502reg(); break; case 's': exec6502(1); // Execute 1 command break; case '?': printf("\n\np [0xAddress] - print value at memory location\n"); printf("r - print register values\n"); printf("s - step through program\n"); printf("quit - exit\n\n"); break; default: (cmdptr[0] % 2) ? printf("Herp.\n") : printf("Derp.\n"); } } } } else { // Otherwise, run in regular mode. exec6502(atoi(argv[2])); } }