@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ Some of the subroutines in this file duplicate other stdlib subroutines.
@ This is to avoid outside dependencies and allow debugging of stdlib code.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ Dumps the heap from 'startaddr' to 'endaddr'.
@ This subroutine stomps on heap[1] after printing the first heap location.
@ If you dump starting from heap[0], then heap[1] will print inaccurately.
@ Starting the dump from any other location will work without error.
@ TODO: Should I use heap[0] and DIE rather than RTS?
@ At the moment, the ability to continue is too useful to me.
@ If it's useful to me, it's probably useful to other people.
@ For now, leave dumpheap as-is.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NSSVTTTSSSN | Mark: 111000 (dump heap)
@ Prepare a numeric address and value on the stack
@ Print output line for this memory location
NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
SSSTSSTN | PUSH ASCII '\t'
SSSTTTSTSN | PUSH ASCII ':'
NSTTTTSTSN | JSR > 111010 (debug:printsign)
NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
SSSTSTSN | PUSH ASCII '\n'
@ Figure out if the loop is complete.
NTSSSTTTSSSSSSSSSSSN | BRZ > 00111000 00000000
NSNTTTSSSN | JMP > 111000 (dump heap)
NSSVSSTTTSSSSSSSSSSSN | Mark: 00111000 00000000
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ Dumps 'count' entries from the stack.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NSSVTTTSSTN | Mark: 111001 (dump stack)
SSSSSSSSSN | PUSH ASCII '\0'
SSSSSSTSTSN | PUSH ASCII '\n'
SSSSTTTSTSN | PUSH ASCII ':'
SSSTSTSSTTN | PUSH ASCII 'S'
SSSTSSTTTTN | PUSH ASCII 'O'
SSSTSTSTSSN | PUSH ASCII 'T'
NSTTTTTSSN | JSR > 111100 (debug:printstring)
@ Print output line for the current TOS.
NSSVSSTTTSSTSSSSSSSTN | Mark: 00111001 00000001
NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
SSSTSSTN | PUSH ASCII '\t'
SSSTTTSTSN | PUSH ASCII ':'
NSTTTTSTSN | JSR > 111010 (debug:printsign)
NSTTTTSTTN | JSR > 111011 (debug:printmagnitude)
SSSTSTSN | PUSH ASCII '\n'
@ Figure out if the loop is complete.
NTSSSTTTSSTSSSSSSSSN | BRZ > 00111001 00000000
NSNSSTTTSSTSSSSSSSTN | JMP > 00111001 00000001
NSSVSSTTTSSTSSSSSSSSN | Mark: 00111001 00000000
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ Prints the sign of 'number'.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NSSVTTTSTSN | Mark: 111010 (debug:printsign)
NTTSSTTTSTSSSSSSSSTN | BMI > 00111010 00000001
SSSTSTSTTN | PUSH ASCII '+'
NSNSSTTTSTSSSSSSSTSN | JMP > 00111010 00000010
NSSVSSTTTSTSSSSSSSSTN | Mark: 00111010 00000001
SSSTSTTSTN | PUSH ASCII '-'
NSSVSSTTTSTSSSSSSSTSN | Mark: 00111010 00000010
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ printmagnitude (111011)
@ Prints the magnitude of 'number'.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NSSVTTTSTTN | Mark: 111011 (debug:printmagnitude)
@ Extract the magnitude of the number.
NTTSSTTTSTTSSSSSSSSN | BMI > 00111011 00000000
NSNSSTTTSTTSSSSSSSTN | JMP > 00111011 00000001
NSSVSSTTTSTTSSSSSSSSN | Mark: 00111011 00000000
NSSVSSTTTSTTSSSSSSSTN | Mark: 00111011 00000001
@ Prepare for building a string on the stack.
@ Pick off one digit on each pass through this loop.
NSSVSSTTTSTTSSSSSSTSN | Mark: 00111011 00000010
@ Mod-off a digit, convert to ASCII, store on stack as part of the string.
SSSTTSSSSN | PUSH ASCII '0'
@ Divide down to next digit and keep looping if number != 0 yet.
NTSSSTTTSTTSSSSSSTTN | BRZ > 00111011 00000011
NSNSSTTTSTTSSSSSSTSN | JMP > 00111011 00000010
@ Print the string we have built on the stack.
NSSVSSTTTSTTSSSSSSTTN | Mark: 00111011 00000011
NSTTTTTSSN | JSR > 111100 (debug:printstring)
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ Prints a null-terminated string from the stack.
@ null-terminator (ASCII '\0')
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NSSVTTTTSSN | Mark: 111100 (debug:printstring)
NTSSSTTTTSSSSSSSSSTN | BRZ > 00111100 00000001
NSNTTTTSSN | JMP > 111100
NSSVSSTTTTSSSSSSSSSTN | Mark: 00111100 00000001