diff --git a/startup.4th b/startup.4th index 3b6e438..b4eb7e1 100644 --- a/startup.4th +++ b/startup.4th @@ -973,15 +973,20 @@ CREATE PNO-BUFFER PNO-BUFFER-BYTES ALLOT PNO-BUFFER PNO-BUFFER-BYTES + CONSTANT PNO-BUFFER-END CREATE PNO-POINTER PNO-BUFFER-END , +\ Return the number of characters consumed/remaining in the PNO buffer +: PNO-USED ( -- u ) PNO-BUFFER-END PNO-POINTER @ - ; +: PNO-REMAINING ( -- u ) PNO-POINTER @ PNO-BUFFER - ; + \ THROW if there are less than u bytes remaining in the PNO buffer -: PNO-CHECK ( u -- ) - PNO-POINTER @ PNO-BUFFER - U> IF EXCP-PNO-OVERFLOW THROW THEN ; +: PNO-CHECK ( u -- ) PNO-REMAINING U> IF EXCP-PNO-OVERFLOW THROW THEN ; >>FORTH : <# PNO-BUFFER-END PNO-POINTER ! ; : HOLD ( char -- ) PNO-POINTER 1 DUP PNO-CHECK OVER -! @ C! ; : HOLDS ( c-addr u -- ) PNO-POINTER OVER DUP PNO-CHECK OVER -! @ SWAP CMOVE ; +: #PAD ( c n -- ) + 0 MAX DUP PNO-USED UMIN - DUP PNO-CHECK PNO-POINTER 2DUP -! @ SWAP ROT FILL ; : #> ( xd -- c-addr u ) 2DROP PNO-BUFFER-END PNO-POINTER @ TUCK - ; : SIGN ( n -- ) 0< IF [[ CHAR - ]] HOLD THEN ; @@ -1000,13 +1005,24 @@ CREATE PNO-POINTER PNO-BUFFER-END , \ Example: 12345 0 <# 3 #DFP #> ≡ "12.345" : #DFP ( ud1 u -- ud2 ) BEGIN ?DUP WHILE 1- >R # R> REPEAT [[ CHAR . ]] HOLD #S ; -\ Display the unsigned number at the top of the stack -: DU. ( ud -- "" ) <# #S #> TYPE ; -: U. ( u -- "" ) 0 DU. ; +>>FORTH -\ Display the signed number at the top of the stack -: D. ( d -- "" ) DUP -ROT DABS <# #S ROT SIGN #> TYPE ; -: . ( n -- "" ) S>D D. ; +\ Display the unsigned double-cell number at the top of the stack, right-aligned +: DU.R ( ud n -- "" ) >R <# #S BL R> #PAD #> TYPE ; + +\ Display the signed double-cell number at the top of the stack, right-aligned +: D.R ( d n -- "" ) + >R DUP -ROT DABS <# #S ROT SIGN BL R> #PAD #> TYPE ; + +\ Single-cell versions of DU.R and D.R +: U.R ( u n -- "" ) 0 SWAP DU.R ; +: .R ( n1 n2 -- "" ) >R S>D R> D.R ; + +\ Versions of DU.R, D.R, U.R, and .R without right-alignment +: DU. ( ud -- "" ) 0 DU.R ; +: U. ( u -- "" ) 0 0 DU.R ; +: D. ( d -- "" ) 0 D.R ; +: . ( n -- "" ) S>D 0 D.R ; \ Return the number of words on the data and return stacks, respectively : DEPTH ( -- n ) SP@ S0 SWAP - CELL / ;