2020-04-12 05:11:36 +10:00
|
|
|
( requires core, parse, cmp )
|
2020-03-18 12:44:32 +11:00
|
|
|
|
2020-04-06 02:11:59 +10:00
|
|
|
: _
|
2020-03-18 12:44:32 +11: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 )
|
2020-04-16 02:29:47 +10:00
|
|
|
DUP <0 IF '-' EMIT -1 * THEN
|
2020-04-06 02:11:59 +10:00
|
|
|
_
|
2020-03-18 12:44:32 +11:00
|
|
|
BEGIN
|
2020-04-18 11:10:48 +10:00
|
|
|
DUP '9' > IF DROP EXIT THEN ( stop indicator, we're done )
|
2020-03-18 12:44:32 +11:00
|
|
|
EMIT
|
|
|
|
AGAIN
|
|
|
|
;
|
|
|
|
|
2020-03-22 07:17:51 +11:00
|
|
|
: ? @ . ;
|
|
|
|
|
2020-04-06 02:11:59 +10:00
|
|
|
: _
|
2020-03-18 12:44:32 +11:00
|
|
|
DUP 9 > IF 10 - 'a' +
|
2020-04-06 02:11:59 +10:00
|
|
|
ELSE '0' + THEN
|
2020-03-18 12:44:32 +11:00
|
|
|
;
|
|
|
|
|
2020-04-06 02:11:59 +10:00
|
|
|
( For hex display, there are no negatives )
|
|
|
|
|
|
|
|
: .x
|
|
|
|
256 MOD ( ensure < 0x100 )
|
|
|
|
16 /MOD ( l h )
|
2020-04-18 11:10:48 +10:00
|
|
|
_ EMIT ( l )
|
2020-04-06 02:11:59 +10:00
|
|
|
_ EMIT
|
|
|
|
;
|
|
|
|
|
|
|
|
: .X
|
|
|
|
256 /MOD ( l h )
|
|
|
|
.x .x
|
2020-03-18 12:44:32 +11:00
|
|
|
;
|
2020-04-06 03:53:03 +10:00
|
|
|
|
|
|
|
( a -- a+8 )
|
|
|
|
: _
|
|
|
|
DUP ( save for 2nd loop )
|
|
|
|
':' EMIT DUP .x SPC
|
|
|
|
4 0 DO
|
|
|
|
DUP @
|
|
|
|
256 /MOD SWAP
|
|
|
|
.x .x
|
|
|
|
SPC
|
2020-04-16 11:29:39 +10:00
|
|
|
2+
|
2020-04-06 03:53:03 +10:00
|
|
|
LOOP
|
|
|
|
DROP
|
|
|
|
8 0 DO
|
2020-04-17 08:58:11 +10:00
|
|
|
C@+
|
2020-04-06 06:11:17 +10:00
|
|
|
DUP <>{ 0x20 &< 0x7e |> <>}
|
|
|
|
IF DROP '.' THEN
|
2020-04-06 03:53:03 +10:00
|
|
|
EMIT
|
|
|
|
LOOP
|
2020-04-14 23:05:43 +10:00
|
|
|
CRLF
|
2020-04-06 03:53:03 +10:00
|
|
|
;
|
2020-04-06 06:11:17 +10:00
|
|
|
|
2020-04-06 03:53:03 +10:00
|
|
|
( n a -- )
|
|
|
|
: DUMP
|
|
|
|
LF
|
|
|
|
BEGIN
|
2020-04-06 10:19:58 +10:00
|
|
|
OVER 1 < IF 2DROP EXIT THEN
|
2020-04-06 03:53:03 +10:00
|
|
|
_
|
|
|
|
SWAP 8 - SWAP
|
|
|
|
AGAIN
|
|
|
|
;
|