###################################################### # Standard Macros ###################################################### ###### Subroutine and interrupt routine .MACRO RTS # Return from subroutine POP PC .ENDMACRO .MACRO RTI # Return from interrupt POP PC .ENDMACRO ###### Clearing status flags .MACRO CLRN # Clear the N flag to 0 AND %1110, S0 .ENDMACRO .MACRO CLRZ # Clear the Z flag to 0 AND %1101, S0 .ENDMACRO .MACRO CLRC # Clear the C flag to 0 AND %1011, S0 .ENDMACRO .MACRO CLRO # Clear the O flag to 0 AND %0111, S0 .ENDMACRO .MACRO CLRI # Clear the I flag to 0 AND %1110, S1 .ENDMACRO ###### Setting status flags .MACRO SETN # Set the N flag to 1 OR %0001, S0 .ENDMACRO .MACRO SETZ # Set the Z flag to 1 OR %0010, S0 .ENDMACRO .MACRO SETC # Set the C flag to 1 OR %0100, S0 .ENDMACRO .MACRO SETO # Set the O flag to 1 OR %1000, S0 .ENDMACRO .MACRO SETI # Set the I flag to 1 OR %0001, S1 .ENDMACRO .MACRO SETH # Set the H flag to 1 OR %0010, S1 .ENDMACRO ###### Arithmetic .MACRO ADD @1:1, @2:1 # Add without carry CLRC # Clear C flag to 0 ADDC @1, @2 .ENDMACRO .MACRO SUB @1:1, @2:1 # Subtract without borrow SETC # Set C flag to 1 (itâ€™s SUBB @1, @2 # acting as a borrow) .ENDMACRO ###### Rotates .MACRO ROL @1:1 # Rotate left (but not ROLC @1 # through the C flag) AND @1, %1110 # Clear LS bit to 0 JMPNC DONE # Jump if C flag is 0 ... OR @1, %0001 # ... else set LS bit to 1 DONE: .ENDMACRO .MACRO ROR @1:1 # Rotate right (but not RORC @1 # through the C flag) AND @1, %0111 # Clear MS bit to 0 JMPNC DONE # Jump if C flag is 0 ... OR @1, %1000 # ... else set MS bit to 1 DONE: .ENDMACRO ###### Shifts .MACRO LSHL @1:1 # Logical shift left ROLC @1 AND @1, %1110 # Clear LS bit to 0 .ENDMACRO .MACRO LSHR @1:1 # Logical shift right RORC @1 AND @1, %0111 # Clear MS bit to 0 .ENDMACRO .MACRO ASHL @1:1 # Arithmetic shift left ROLC @1 # (Identical to LSHL) AND @1, %1110 # Clear LS bit to 0 .ENDMACRO .MACRO ASHR @1:1 # Arithmetic shift right ### Get copy of MSB into O flag CLRO # Clear O flag to 0 ROLC @1 # Get MS bit into C flag JMPNC NEXT # Jump if C flag is 0 ... SETO # ... else set O flag to 1 NEXT: RORC @1 # Return to initial state ### Do the shift RORC @1 # Rotate right AND %0111, @1 # Clear the MS bit JMPNO DONE # Jump of O flag is 0 ... OR %1000, @1 # ... else set MS bit to 1 DONE: .ENDMACRO ###### Miscellaneous .MACRO HALT # Halt the HRRG CPU by SETH # setting the H flag to 1 .ENDMACRO