Modified stdlib to use stack rotations to timeshare heap registers.
[vvhitespace] / stdlib / debug.pvvs
index db61a96..4cc8a73 100644 (file)
@@ -2,14 +2,24 @@
 #define VVS_STDLIB_DEBUG
 
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 #define VVS_STDLIB_DEBUG
 
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+@ Name:
+@   dumpheap (111000)
 @ Description:
 @ Description:
-@   This function dumps the heap from startaddr to endaddr.
+@   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.
 @ Call Stack:
 @   endaddr
 @   startaddr  <-- TOS
 @ Return Stack:
 @   <empty>
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 @ Call Stack:
 @   endaddr
 @   startaddr  <-- TOS
 @ Return Stack:
 @   <empty>
 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+#include <stdio.pvvs>
 NSSVTTTSSSN              | Mark: 111000 (dump heap)
 
 @ Prepare a numeric address and value on the stack
 NSSVTTTSSSN              | Mark: 111000 (dump heap)
 
 @ Prepare a numeric address and value on the stack
@@ -19,25 +29,25 @@ TTT                      | LOAD
 SNT                      | SWAP
 
 @ Print output line for this memory location
 SNT                      | SWAP
 
 @ Print output line for this memory location
-NSTTSSSSSTN              | JSR>1000001 (print absolute value of number)
+NSTTSSSSTTN              | JSR>1000011 (print absolute value of number)
 SSSTTTSTSN               | PUSH ASCII ':'
 SSSTSSTN                 | PUSH ASCII '\t'
 TNSS                     | PUTC
 TNSS                     | PUTC
 SSSTTTSTSN               | PUSH ASCII ':'
 SSSTSSTN                 | PUSH ASCII '\t'
 TNSS                     | PUTC
 TNSS                     | PUTC
-NSTTSTSN                 | JSR>1010 (print number from stack)
+NSTTSSTN                 | JSR>1001 (print number from stack)
 SSSTSTSN                 | PUSH ASCII '\n'
 TNSS                     | PUTC
 
 @ Figure out if the loop is complete.
 SSSTSTSN                 | PUSH ASCII '\n'
 TNSS                     | PUTC
 
 @ Figure out if the loop is complete.
-SSSSN                    | PUSH 0 (ptr)
+SSSTN                    | PUSH 1 (ptr)
 SNT                      | SWAP
 TTS                      | STORE
 SNS                      | DUP
 SNT                      | SWAP
 TTS                      | STORE
 SNS                      | DUP
-SSSSN                    | PUSH 0 (ptr)
+SSSTN                    | PUSH 1 (ptr)
 TTT                      | LOAD
 TSST                     | SUBTRACT
 NTSSSTTTSSSSSSSSSSSN     | BRZ > 00111000 00000000
 TTT                      | LOAD
 TSST                     | SUBTRACT
 NTSSSTTTSSSSSSSSSSSN     | BRZ > 00111000 00000000
-SSSSN                    | PUSH 0 (ptr)
+SSSTN                    | PUSH 1 (ptr)
 TTT                      | LOAD
 SSSTN                    | PUSH 1
 TSSS                     | ADD
 TTT                      | LOAD
 SSSTN                    | PUSH 1
 TSSS                     | ADD
@@ -48,6 +58,41 @@ NSSVSSTTTSSSSSSSSSSSN    | Mark: 00111000 00000000
 SNN                      | DROP
 NTN                      | RTS
 
 SNN                      | DROP
 NTN                      | RTS
 
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+@ Name:
+@   dumpstack (111001)
+@ Description:
+@   Dumps 'count' entries from the stack.
+@ Call Stack:
+@   count <-- TOS
+@ Return Stack:
+@   <empty>
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 #include <stdio.pvvs>
 #include <stdio.pvvs>
+NSSVTTTSSTN              | Mark: 111001 (dump stack)
+
+@ Print output line for the current TOS.
+SNS                      | DUP
+NSTTSSSSTTN              | JSR>1000011 (print absolute value of number)
+SSSTTTSTSN               | PUSH ASCII ':'
+SSSTSSTN                 | PUSH ASCII '\t'
+TNSS                     | PUTC
+TNSS                     | PUTC
+SNT                      | SWAP
+NSTTSSTN                 | JSR>1001 (print number from stack)
+SSSTSTSN                 | PUSH ASCII '\n'
+TNSS                     | PUTC
+
+@ Figure out if the loop is complete.
+SNS                      | DUP
+NTSSSTTTSSTSSSSSSSSN     | BRZ > 00111001 00000000
+SSSTN                    | PUSH 1
+TSST                     | SUBTRACT
+NSNTTTSSTN               | JMP>111001 (dump stack)
+
+@ Clean up and return
+NSSVSSTTTSSTSSSSSSSSN    | Mark: 00111001 00000000
+SNN                      | DROP
+NTN                      | RTS
 
 #endif
 
 #endif