Added functions to stdlib:
[vvhitespace] / stdlib / stdio.pvvs
CommitLineData
8bed3ccd
AT
1#ifndef VVS_STDLIB_STDIO
2#define VVS_STDLIB_STDIO
3
4@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a
AT
5@ Name:
6@ printstackstring (1000)
8bed3ccd 7@ Description:
bb21580a 8@ Prints a null-terminated string from the stack.
8bed3ccd
AT
9@ Call Stack:
10@ null-terminator (ASCII '\0')
11@ char n
12@ ...
13@ char 2
14@ char 1 <-- TOS
15@ Return Stack:
16@ <empty>
17@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
32c440bf
AT
18NSSVTSSSN | Mark: 1000 (print string from stack)
19SNS | DUP
20NTSSSSSTSSSSSSSSSSTN | BRZ > 00001000 00000001
21TNSS | Print character
22NSNTSSSN | JMP > 1000
23NSSVSSSSTSSSSSSSSSSTN | Mark: 00001000 00000001
24SNN | DROP
25NTN | RTS
26
8bed3ccd 27@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a
AT
28@ Name:
29@ printheapstring (1001)
8bed3ccd 30@ Description:
bb21580a 31@ Prints a null-terminated string from the heap.
8bed3ccd
AT
32@ Call Stack:
33@ pointer to first character <-- TOS
34@ Return Stack:
35@ <empty>
36@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
32c440bf
AT
37NSSVTSSTN | Mark: 1001 (print string from heap)
38SNS | DUP
39TTT | LOAD
40SNS | DUP
41NTSSSSSTSSTSSSSSSSTN | BRZ > 00001001 00000001
42TNSS | Print character
43SSSTN | Push +1
44TSSS | ADD
45NSNTSSTN | JMP > 1001
46NSSVSSSSTSSTSSSSSSSTN | Mark: 00001001 00000001
47SNN | DROP
48SNN | DROP
49NTN | RTS
8bed3ccd 50
3625ff3a 51@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a
AT
52@ Name:
53@ printstacknumber (1010)
3625ff3a 54@ Description:
bb21580a 55@ Prints 'number' from the stack in sign-magnitude format.
3625ff3a
AT
56@ Leading zeros are suppressed.
57@ Call Stack:
bb21580a 58@ number <-- TOS
3625ff3a
AT
59@ Return Stack:
60@ <empty>
61@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
62NSSVTSTSN | Mark: 1010 (print number from stack)
63SNS | DUP
ae1f85a1
AT
64NSTTSSSSTSN | JSR > 1000010
65NSTTSSSSTTN | JSR > 1000011
3625ff3a
AT
66NTN | RTS
67
68@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a 69@ Name:
ae1f85a1 70@ printstacknumbersign (1000010)
3625ff3a 71@ Description:
bb21580a 72@ Prints the sign of 'number' from the stack.
3625ff3a 73@ Call Stack:
bb21580a 74@ number <-- TOS
3625ff3a
AT
75@ Return Stack:
76@ <empty>
77@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ae1f85a1
AT
78NSSVTSSSSTSN | Mark: 1000010 (print sign of number from stack)
79NTTSTSSSSTSSSSSSSSTN | BMI > 01000010 00000001
3625ff3a 80SSSTSTSTTN | PUSH ASCII '+'
ae1f85a1
AT
81NSNSTSSSSTSSSSSSSTSN | JMP > 01000010 00000010
82NSSVSTSSSSTSSSSSSSSTN | Mark: 01000010 00000001
3625ff3a 83SSSTSTTSTN | PUSH ASCII '-'
ae1f85a1 84NSSVSTSSSSTSSSSSSSTSN | Mark: 01000010 00000010
3625ff3a
AT
85TNSS | PUTC
86NTN | RTS
87
88@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a 89@ Name:
ae1f85a1 90@ printstacknumbermagnitude (1000011)
3625ff3a 91@ Description:
bb21580a 92@ Prints the magnitude of 'number' from the stack.
3625ff3a 93@ Call Stack:
bb21580a 94@ number <-- TOS
3625ff3a
AT
95@ Return Stack:
96@ <empty>
97@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a 98#include <math.pvvs>
ae1f85a1 99NSSVTSSSSTTN | Mark: 1000011 (print magnitude of number from stack)
3625ff3a
AT
100NSTTSSSTN | JSR > 10001 (absolute value)
101
102SSSSN | PUSH ASCII '\0'
103SNT | SWAP
104
105@ Pick off one digit on each pass through this loop.
ae1f85a1 106NSSVSTSSSSTTSSSSSSSSN | Mark: 01000011 00000000
3625ff3a
AT
107SNS | DUP
108
109@ Mod-off a digit, convert to ASCII, store on stack as part of the string.
110SSSTSTSN | PUSH +10
111TSTT | MODULO
112SSSTTSSSSN | PUSH ASCII '0'
113TSSS | ADD
114SNT | SWAP
115
116@ Divide down to next digit and keep looping if number != 0 yet.
117SSSTSTSN | PUSH +10
118TSTS | DIVIDE
119SNS | DUP
ae1f85a1
AT
120NTSSTSSSSTTSSSSSSSTN | BRZ > 01000011 00000001
121NSNSTSSSSTTSSSSSSSSN | JMP > 01000011 00000000
3625ff3a
AT
122
123@ Print the string we have built on the stack.
ae1f85a1 124NSSVSTSSSSTTSSSSSSSTN | Mark: 01000011 00000001
3625ff3a
AT
125SNN | DROP
126NSTTSSSN | JSR > 1000 (print string from stack)
127NTN | RTS
128
8bed3ccd 129#endif