2020-04-11 15:11:36 -04:00
|
|
|
( requires core, parse, cmp )
|
2020-03-17 21:44:32 -04:00
|
|
|
|
2020-04-05 12:11:59 -04:00
|
|
|
: _
|
2020-03-17 21:44:32 -04:00
|
|
|
999 SWAP ( stop indicator )
|
|
|
|
DUP 0 = IF '0' EXIT THEN ( 0 is a special case )
|
|
|
|
BEGIN
|
|
|
|
DUP 0 = IF DROP EXIT THEN
|
|
|
|
10 /MOD ( r q )
|
|
|
|
SWAP '0' + SWAP ( d q )
|
|
|
|
AGAIN
|
|
|
|
;
|
|
|
|
|
|
|
|
: . ( n -- )
|
|
|
|
( handle negative )
|
|
|
|
( that "0 1 -" thing is because we don't parse negative
|
|
|
|
number correctly yet. )
|
|
|
|
DUP 0 < IF '-' EMIT 0 1 - * THEN
|
2020-04-05 12:11:59 -04:00
|
|
|
_
|
2020-03-17 21:44:32 -04:00
|
|
|
BEGIN
|
|
|
|
DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done )
|
|
|
|
EMIT
|
|
|
|
AGAIN
|
|
|
|
;
|
|
|
|
|
2020-03-21 16:17:51 -04:00
|
|
|
: ? @ . ;
|
|
|
|
|
2020-04-05 12:11:59 -04:00
|
|
|
: _
|
2020-03-17 21:44:32 -04:00
|
|
|
DUP 9 > IF 10 - 'a' +
|
2020-04-05 12:11:59 -04:00
|
|
|
ELSE '0' + THEN
|
2020-03-17 21:44:32 -04:00
|
|
|
;
|
|
|
|
|
2020-04-05 12:11:59 -04:00
|
|
|
( For hex display, there are no negatives )
|
|
|
|
|
|
|
|
: .x
|
|
|
|
256 MOD ( ensure < 0x100 )
|
|
|
|
16 /MOD ( l h )
|
|
|
|
_ EMIT ( l )
|
|
|
|
_ EMIT
|
|
|
|
;
|
|
|
|
|
|
|
|
: .X
|
|
|
|
256 /MOD ( l h )
|
|
|
|
.x .x
|
2020-03-17 21:44:32 -04:00
|
|
|
;
|
2020-04-05 13:53:03 -04:00
|
|
|
|
|
|
|
( 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@
|
2020-04-05 16:11:17 -04:00
|
|
|
DUP <>{ 0x20 &< 0x7e |> <>}
|
|
|
|
IF DROP '.' THEN
|
2020-04-05 13:53:03 -04:00
|
|
|
EMIT
|
|
|
|
1 +
|
|
|
|
LOOP
|
2020-04-14 09:05:43 -04:00
|
|
|
CRLF
|
2020-04-05 13:53:03 -04:00
|
|
|
;
|
2020-04-05 16:11:17 -04:00
|
|
|
|
2020-04-05 13:53:03 -04:00
|
|
|
( n a -- )
|
|
|
|
: DUMP
|
|
|
|
LF
|
|
|
|
BEGIN
|
2020-04-05 20:19:58 -04:00
|
|
|
OVER 1 < IF 2DROP EXIT THEN
|
2020-04-05 13:53:03 -04:00
|
|
|
_
|
|
|
|
SWAP 8 - SWAP
|
|
|
|
AGAIN
|
|
|
|
;
|