/* Author: Jose Romeo Vela Date: March 24, 2002 email: jrvela@aristasol.com http://www.aristasol.com/ This software is licensed under GNU's GPL. For details see http://www.gnu.org/ Copyright (c) 2002, Jose Romeo Vela ============================================================================== Modifications: 4/13/2002 jrv1 Changed the copyright symbol to use (c) instead the extended ascii 4/15/2002 jrv2 Added code to do one last dump after a 9xx instruction. Previous version just stoped the loop and never showed the execution of the 9xx instruction. */ #include "config.h" #include "cpu_micro_code.h" void cardiac_logo() { printf("************************************************************\n"); printf("******************** C I N C ******************************\n"); printf("************************************************************\n"); printf("**************** C R D I A C *************************\n"); printf("************************************************************\n"); printf("****************** Version %s *************************\n", VERSION); printf("****** GNU License Copyright (c) 2002 Jose Romeo Vela ******\n"); /*jrv1*/ printf("************************************************************\n"); } void cinc_dump(struct cardiac_s * cardiac) { /* dump cardiac registers and memory */ int i; char ladybug[MAXRAM]; for (i=0;ipc] = '@'; /* print the register */ printf("\n\n\n"); printf("================ C I N C C A R D I A C ==============================\n\n"); printf(" ACCUMULATOR: %+05d\n",cardiac->ac*cardiac->ac_sign); printf(" PROGRAM COUNTER: %02d\n",cardiac->pc); printf(" INSTRUCTION REGISTER: %1d%02d\n\n",cardiac->opcode,cardiac->address); printf("=================M e m o r e y C e l l s===========================\n\n"); /* Print the memory cells with the ladybug marking the location of the pc. */ /* The memory cells are printed in the same layout as the original CARDIAC */ /* memory. */ for (i=0;i<15;i=i++) { printf("%c%02d[% 04d] | %c%02d[% 04d] | %c%02d[% 04d] | %c%02d[% 04d] | %c%02d[% 04d] | %c%02d[% 04d]\n",ladybug[i],i,cardiac->ram[i],ladybug[i+17],i+17,cardiac->ram[i+17],ladybug[i+34],i+34,cardiac->ram[i+34],ladybug[i+51],i+51,cardiac->ram[i+51],ladybug[i+68],i+68,cardiac->ram[i+68],ladybug[i+85],i+85,cardiac->ram[i+85]); } for (i=15;i<17;i=i++) { printf("%c%02d[% 04d] | %c%02d[% 04d] | %c%02d[% 04d] | %c%02d[% 04d]\n",ladybug[i],i,cardiac->ram[i],ladybug[i+17],i+17,cardiac->ram[i+17],ladybug[i+34],i+34,cardiac->ram[i+34],ladybug[i+51],i+51,cardiac->ram[i+51]); } printf("========================================================================\n\n"); } int cinc_cpu(struct cardiac_s * cardiac) { /* cinc_cpu is the control unit for Cardiac. Each cycle performs the following three opetions: fetch instruction from memory to instruction register increment program counter execute the instruction in the instruction register */ int rc = 0; int exit_code; if (cardiac->dump) cardiac_logo(); exit_code = 0; while (cardiac->running){ if (cardiac->dump) cinc_dump(cardiac); /* fetch and increment pc */ exit_code = cinc_fetch(cardiac); if ( ! exit_code ) { /* execute the instruction stored in the instruction register */ exit_code = cinc_exec(cardiac); if (exit_code) { cardiac->running=FALSE; rc = 1000+exit_code; return(rc); } } else { cardiac->running = FALSE; rc = 2001; return(rc); } } if ( cardiac->dump ) { cinc_dump(cardiac); } return(rc); }