@@ -73,7 +73,7 @@ typedef struct statistic_data
7373
7474int gbl$memory [MEMORY_SIZE ], gbl$registers [REGMEM_SIZE ], gbl$debug = FALSE, gbl$verbose = FALSE,
7575 gbl$normal_operands [] = {2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 2 }, gbl$gather_statistics = FALSE, gbl$enable_uart = TRUE,
76- gbl$ctrl_c = FALSE;
76+ gbl$ctrl_c = FALSE, gbl$breakpoint = -1 ;
7777char * gbl$normal_mnemonics [] = {"MOVE" , "ADD" , "ADDC" , "SUB" , "SUBC" , "SHL" , "SHR" , "SWAP" ,
7878 "NOT" , "AND" , "OR" , "XOR" , "CMP" , "" , "HALT" },
7979 * gbl$branch_mnemonics [] = {"ABRA" , "ASUB" , "RBRA" , "RSUB" },
@@ -550,28 +550,28 @@ int execute()
550550 source_1 = read_source_operand (source_mode , source_regaddr , FALSE);
551551 destination = source_0 + source_1 ;
552552 update_status_bits (destination , source_0 , source_1 , MODIFY_ALL );
553- write_destination (destination_mode , destination_regaddr , destination , FALSE );
553+ write_destination (destination_mode , destination_regaddr , destination , TRUE );
554554 break ;
555555 case 2 : /* ADDC */
556556 source_0 = read_source_operand (destination_mode , destination_regaddr , TRUE);
557557 source_1 = read_source_operand (source_mode , source_regaddr , FALSE);
558558 destination = source_0 + source_1 + ((read_register (14 ) >> 2 ) & 1 ); /* Take carry into account */
559559 update_status_bits (destination , source_0 , source_1 , MODIFY_ALL );
560- write_destination (destination_mode , destination_regaddr , destination , FALSE );
560+ write_destination (destination_mode , destination_regaddr , destination , TRUE );
561561 break ;
562562 case 3 : /* SUB */
563563 source_0 = read_source_operand (destination_mode , destination_regaddr , TRUE);
564564 source_1 = read_source_operand (source_mode , source_regaddr , FALSE);
565565 destination = source_0 - source_1 ;
566566 update_status_bits (destination , source_0 , source_1 , MODIFY_ALL );
567- write_destination (destination_mode , destination_regaddr , destination , FALSE );
567+ write_destination (destination_mode , destination_regaddr , destination , TRUE );
568568 break ;
569569 case 4 : /* SUBC */
570570 source_0 = read_source_operand (destination_mode , destination_regaddr , TRUE);
571571 source_1 = read_source_operand (source_mode , source_regaddr , FALSE);
572572 destination = source_0 - source_1 - ((read_register (14 ) >> 2 ) & 1 ); /* Take carry into account */
573573 update_status_bits (destination , source_0 , source_1 , MODIFY_ALL );
574- write_destination (destination_mode , destination_regaddr , destination , FALSE );
574+ write_destination (destination_mode , destination_regaddr , destination , TRUE );
575575 break ;
576576 case 5 : /* SHL */
577577 source_0 = read_source_operand (source_mode , source_regaddr , FALSE);
@@ -612,21 +612,21 @@ int execute()
612612 source_1 = read_source_operand (source_mode , source_regaddr , FALSE);
613613 destination = source_0 & source_1 ;
614614 update_status_bits (destination , source_0 , source_1 , DO_NOT_MODIFY_CARRY | DO_NOT_MODIFY_OVERFLOW );
615- write_destination (destination_mode , destination_regaddr , destination , FALSE );
615+ write_destination (destination_mode , destination_regaddr , destination , TRUE );
616616 break ;
617617 case 10 : /* OR */
618618 source_0 = read_source_operand (destination_mode , destination_regaddr , TRUE);
619619 source_1 = read_source_operand (source_mode , source_regaddr , FALSE);
620620 destination = source_0 | source_1 ;
621621 update_status_bits (destination , source_0 , source_1 , DO_NOT_MODIFY_CARRY | DO_NOT_MODIFY_OVERFLOW );
622- write_destination (destination_mode , destination_regaddr , destination , FALSE );
622+ write_destination (destination_mode , destination_regaddr , destination , TRUE );
623623 break ;
624624 case 11 : /* XOR */
625625 source_0 = read_source_operand (destination_mode , destination_regaddr , TRUE);
626626 source_1 = read_source_operand (source_mode , source_regaddr , FALSE);
627627 destination = source_0 ^ source_1 ;
628628 update_status_bits (destination , source_0 , source_1 , DO_NOT_MODIFY_CARRY | DO_NOT_MODIFY_OVERFLOW );
629- write_destination (destination_mode , destination_regaddr , destination , FALSE );
629+ write_destination (destination_mode , destination_regaddr , destination , TRUE );
630630 break ;
631631 case 12 : /* CMP */
632632 source_0 = read_source_operand (destination_mode , destination_regaddr , FALSE);
@@ -682,6 +682,13 @@ int execute()
682682 return TRUE;
683683 }
684684
685+ if (read_register (15 ) == gbl$breakpoint )
686+ {
687+ printf ("Breakpoint reached: %04X\n" , address );
688+ return TRUE;
689+ }
690+
691+
685692/* write_register(15, read_register(15) + 1); */ /* Update program counter */
686693 return FALSE; /* No HALT instruction executed */
687694}
@@ -858,6 +865,10 @@ int main(int argc, char **argv)
858865 {
859866 if (!strcmp (token , "QUIT" ) || !strcmp (token , "EXIT" ))
860867 return 0 ;
868+ else if (!strcmp (token , "CB" ))
869+ gbl$breakpoint = -1 ;
870+ else if (!strcmp (token , "SB" ))
871+ printf ("Breakpoint set to %04X\n" , gbl$breakpoint = str2int (tokenize (NULL , delimiters )));
861872 else if (!strcmp (token , "DUMP" ))
862873 {
863874 start = str2int (tokenize (NULL , delimiters ));
@@ -949,6 +960,7 @@ int main(int argc, char **argv)
949960 }
950961 else if (!strcmp (token , "HELP" ))
951962 printf ("\n\
963+ CB Clear Breakpoint\n\
952964DEBUG Toggle debug mode (for development only)\n\
953965DIS <START>, <STOP> Disassemble a memory region\n\
954966DUMP <START>, <STOP> Dump a memory area, START and STOP can be\n\
@@ -958,8 +970,9 @@ QUIT/EXIT Stop the emulator and return to the shell\n\
958970RESET Reset the whole machine\n\
959971RDUMP Print a register dump\n\
960972RUN [<ADDR>] Run a program beginning at ADDR\n\
961- SET <REG|ADDR> <VALUE> Either set a register of a memory cell\n\
973+ SET <REG|ADDR> <VALUE> Either set a register or a memory cell\n\
962974SAVE <FILENAME> <START> <STOP> Create a loadable binary file\n\
975+ SB <ADDR> Set breakpoint to an address\n\
963976STAT Displays some execution statistics\n\
964977STEP [<ADDR>] Executes a single instruction at address\n\
965978 ADDR. If not address is specified the current\n\
0 commit comments