Created
April 16, 2014 17:45
-
-
Save mnemnion/10912594 to your computer and use it in GitHub Desktop.
A simple hex dump for Retro (11)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( Simple Hex Dump ) | |
needs bad' | |
needs console' | |
8 constant (dump-width) | |
: putxt xt->d d->name puts ; | |
: hexabyte ( "hexes a byte" ) | |
dup 10 < | |
[ 48 + ] | |
[ 87 + ] if ; | |
: byte>cha ( byte -> < := cha true | byte false > -- := ?cha ) | |
( "filters out non-printable ascii" ) | |
dup 32 126 within ; | |
: putbyte dup 4 >> hexabyte putc | |
16 mod hexabyte putc | |
; | |
: putcell ( cell -> nil ) | |
^bad'unpack 4 [ putbyte ] times ; | |
: normalText ( - ) ^console'console? [ "\[0m" puts ] ifFalse ; | |
: (highlight) ( cell -> cell ) | |
( "highlight cells " ) | |
dup xt->d 0 <> | |
[ ^console'RED ^console'foreground ] | |
[ ^console'normalText ] if | |
; | |
"" variable: dump-str | |
: dot-or-cha | |
dump-str @ swap | |
byte>cha | |
[ ^strings'appendChar ] | |
[ drop '. ^strings'appendChar ] if | |
dump-str ! | |
; | |
: (stringulate) ( cell -> cell ) | |
dup ^bad'unpack 4 [ dot-or-cha ] times | |
; | |
: dotpr | |
dump-str @ | |
puts | |
"" dump-str ! | |
; | |
: smart-dump ( adr range -> nil "hexdump") | |
[ | |
(dump-width) mod 0 = | |
[ ^console'normalText | |
10 [ space ] times | |
dotpr | |
cr dup putcell ': putc space space ] ifTrue | |
dup @ (highlight) (stringulate) putcell space 1+ ] iter | |
^console'normalText 10 [ space ] times dotpr | |
; | |
: dump | |
[ | |
(dump-width) mod 0 = | |
[ 10 [ space ] times | |
dotpr | |
cr dup putcell ': putc space space ] ifTrue | |
dup @ (stringulate) putcell space 1+ ] iter | |
10 [ space ] times | |
dotpr | |
; | |
: dump-me 12 23 putcell ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment