diff --git a/forth/dictionary.txt b/forth/dictionary.txt index 2d8f454..978e873 100644 --- a/forth/dictionary.txt +++ b/forth/dictionary.txt @@ -199,6 +199,9 @@ core. ." xxx" -- *I* Compiles string literal xxx followed by a call to (print) C< -- c Read one char from buffered input. +DUMP n a -- Prints n bytes at addr a in a hexdump format. + Prints in chunks of 8 bytes. Doesn't do partial + lines. Output is designed to fit in 32 columns. EMIT c -- Spit char c to output stream IN> -- a Address of variable containing current pos in input buffer. diff --git a/forth/fmt.fs b/forth/fmt.fs index bf994e3..4055ce9 100644 --- a/forth/fmt.fs +++ b/forth/fmt.fs @@ -42,3 +42,34 @@ 256 /MOD ( l h ) .x .x ; + +( a -- a+8 ) +: _ + DUP ( save for 2nd loop ) + ':' EMIT DUP .x SPC + 4 0 DO + DUP @ + 256 /MOD SWAP + .x .x + SPC + 2 + + LOOP + DROP + 8 0 DO + DUP C@ + DUP 0x20 < IF DROP '.' THEN + DUP 0x7e > IF DROP '.' THEN + EMIT + 1 + + LOOP + LF +; +( n a -- ) +: DUMP + LF + BEGIN + OVER 1 < IF DROP EXIT THEN + _ + SWAP 8 - SWAP + AGAIN +;