home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mega CD-ROM 1
/
megacd_rom_1.zip
/
megacd_rom_1
/
MAGAZINE
/
DDJMAG
/
DDJ8704.ZIP
/
HAMLST.LST
< prev
next >
Wrap
File List
|
1987-03-12
|
10KB
|
285 lines
( Elemental tools Ham 10:31 12/13/86 )
: -CUR 14 0 SET-CURSOR ; ( no cursor )
: +CUR 6 7 SET-CURSOR ; ( normal cursor )
: BACK ( n - ) 0 ?DO 8 EMIT LOOP ; ( backspace word )
0 CONSTANT NEW ( to collect new digits )
-1 CONSTANT OLD ( to provide existing number to routine )
: INCR ( a - ) 1 SWAP +! ; ( increments variable )
: DECR ( a - ) -1 SWAP +! ; ( decrements variable )
: Bs? ( n - f ) 8 = ; ( T if backspace pressed )
: Cr? ( n - f ) 13 = ; ( T if carriage return pressed )
VARIABLE OK-NEG ( T allows for entry of - ; F rejects - )
VARIABLE SOUND ( T if using sound )
: BELL ( - ) SOUND @ IF 440 8 BEEP ( short beep ) THEN ;
CREATE #PAD 15 ALLOT ( work area )
: #P! ( c n - ) #PAD + C! ; ( stores character c at offset n )
CREATE #VAR 14 ALLOT ( holds various values )
#VAR CONSTANT #DEC ( no. of fractional digits ALLOWED )
#VAR 2+ CONSTANT #dec ( no. of fractional digits ENTERED )
#VAR 4 + CONSTANT #WHOLE ( no. of whole digits entered )
#VAR 6 + CONSTANT #HIT ( no. of keystrokes )
#VAR 8 + CONSTANT NEG~ ( T if number is negative )
#VAR 10 + CONSTANT dec~ ( T if decimal point entered )
#VAR 12 + CONSTANT DIGCNT ( counts no. of digits for old nos.)
: PLACES ( n - ) #DEC ! ; ( sets # of decimal places allowed )
: #init #dec 12 ERASE ( don't erase #DEC ) #PAD 15 ERASE ;
: *HIT/NEG #HIT 4 ERASE ; ( resets no. hit and negative flag )
: NEG? ( - f ) NEG~ @ ; ( T if number is negative )
: dec? ( - f ) dec~ @ ; ( T if dec point entered )
( Get and edit keystroke Ham 10:33 12/13/86 )
: CAPITALIZE ( c - C ) DUP 96 > OVER 123 < AND IF BL - THEN ;
: FIXUP ( c-c) DUP ASCII B = OVER BL = OR IF DROP ASCII C THEN
( convert B and space bar to C := clear number entry )
( L := 1 ) DUP ASCII L = IF DROP ASCII 1 THEN
( O := 0 ) DUP ASCII O = IF DROP ASCII 0 THEN ;
: #? ( n - f ) DUP ASCII / > SWAP ASCII : < AND ; ( T if digit)
: BAD? ( n - f ) DUP #? OK-NEG @ IF OVER ASCII - = OR THEN
#DEC @ IF OVER ASCII . = OR THEN
OVER ASCII C = OR OVER Bs? OR SWAP Cr? OR NOT ;
: GET# ( - n) BEGIN KEY CAPITALIZE FIXUP DUP BAD?
WHILE DROP BELL REPEAT ;
( Collection box Ham 10:34 12/13/86 )
: #,S ( #w - #, ) 3 /MOD SWAP 0= + 0 MAX ;
( takes # of whole-number digits, leaves # of commas required)
( Warning: Assumes 83-Std flag = -1; negate flag if 79 Std )
: FULLCNT ( n - n' ) #DEC @ IF 1+ THEN OK-NEG @ IF 1+ THEN ;
( adds to char cnt the decimal point and minus sign if any )
: BOXSIZE ( n - m ) DUP ( # of digits ) #DEC @ - ( #whole digts)
DUP 1 < ( T if no whole digits ) NEGATE ( 83-Std flag ) >R
#,S ( # of commas ) R> + + 2+ ( space at either end )
FULLCNT ; ( leaves number of character in box )
: BOX ( n - ) BOXSIZE SPACES ;
( prints inverse spaces to define field for number entry)
( Sign/decimal Ham 10:34 12/13/86 )
: -. ( displays - or . or both when no digits yet entered )
NEG? dec? AND IF 3 BACK ." -. "
ELSE NEG? IF 2 BACK ." - "
ELSE dec? IF 2 BACK ." . "
THEN THEN THEN ;
( Count digits; show number Ham 10:35 12/13/86 )
: 2, ( d - ) , , ; ( store double into dictionary )
CREATE NINES 9. 2, 99. 2, 999. 2, 9999. 2, 99999. 2,
999999. 2, 9999999. 2, 99999999. 2, 999999999. 2,
: #OFDIGITS ( d - # ) DABS 1 DIGCNT !
BEGIN 2DUP DIGCNT @ 1- 4 * NINES + 2@ D>
WHILE DIGCNT INCR REPEAT 2DROP DIGCNT @ ;
: PUT# ( - adr cnt ) ( prepares number for display )
0. #PAD 1- CONVERT DROP 2DUP #OFDIGITS >R
<# dec? IF #dec @ 0 ?DO # LOOP ASCII . HOLD THEN
R> #dec @ - #,S 0 ?DO # # # ASCII , HOLD LOOP
#S NEG? SIGN #> ;
( Display the number nicely Ham 19:39 12/04/86 )
: DISPLAY# ( n - n ) DUP ( get another copy of max # of digits )
BOXSIZE DUP BACK
( back up to beginning of entry field; top of stack is )
( size of box, which is greater than # of digits )
#HIT @
IF 1- ( space at end ) PUT# ROT OVER - SPACES TYPE SPACE
ELSE SPACES ( new box ) -. THEN ;
( n is max no. of digits to be entered, which stays on stk )
( Wrap-up routine Ham 21:15 11/27/86 )
: 10D* ( d - 10*d ) 2DUP 2DUP D+ 2DUP D+ D+ 2DUP D+ ;
: SCALE# #DEC @ ?DUP IF #dec @ - 0 ?DO 10D* LOOP THEN ;
( scale up to integer from decimal fraction )
: #DONE ( - d # )
( leaves double number entered and no. of digits entered )
( no. of digits = zero means no digits entered )
0. #PAD 1- CONVERT ( leaves addr of 1st nonconverting char )
#PAD - ( number of digits ) >R
NEG? IF DNEGATE THEN SCALE# R> DUP 0=
IF ( number is 0, see whether key pressed or no entry )
DROP #HIT @ 0> NEGATE ( Note: 83-Std flag ) THEN ;
( Adjust counts Ham 18:51 11/06/86 )
: #dec-ADJ #dec @ IF #dec DECR THEN ; ( down one decimal )
: #WHOLE-ADJ dec? NOT IF #WHOLE DECR THEN ; ( down 1 whole no.)
: NO-.? ( - f ) #HIT @ 0= NEG? 0= dec? 0= AND AND ;
( When decimal point is hit Ham 18:53 11/06/86 )
: .ROUTINE dec? IF BELL ( decimal point already entered )
ELSE dec~ ON ( mark entry of decimal point )
THEN ;
( Check if need to adjust digits Ham 18:23 11/06/86 )
( WHOLE-CK & DEC-CK have this stack diagram: ( n f - n f' )
( where n is the no. of digits entered so far )
: WHOLE-CK dec? 0= IF OVER #DEC @ - #WHOLE @ = OR THEN ;
( makes flag T if dec pt not entered AND we have all the )
( whole number digits that we can accept )
: DEC-CK #DEC @ ?DUP IF #dec @ = OR THEN ;
( makes flag T if we have all the digits to the right )
( of the decimal that we can accept )
( The true flag will cause the latest digit entered to be )
( dropped and the bell to sound (if SOUND is on)
( Count each digit entered Ham 18:24 11/06/86 )
VARIABLE 0START ( T if starting with whole number zero )
( A starting whole number value of zero is in effect a )
( leading zero and should not be counted in the total of )
( digits entered, or else the final numeric digit will not )
( be accepted. )
: CNT-DIGIT dec? IF #dec INCR
ELSE 0START @ IF 0START OFF ( 1-time switch )
ELSE #WHOLE INCR THEN THEN ;
( Initialization for "old" numbers Ham 18:26 11/06/86 )
( If old number is decimal, all places are present. )
: SET-dec #DEC @ ?DUP IF #dec ! dec~ ON THEN ;
: SET-NEG ( d n - n d ) ROT ROT ( move dbl to top ) 2DUP 0. D<
IF ( neg: convert and note sign ) DNEGATE NEG~ ON THEN ;
( Put number into #PAD as an string of ASCII values: )
: SET-#P ( d - ) <# dec? IF #dec @ 0 DO # LOOP THEN
DIGCNT @ #DEC @ > IF #S THEN #> #PAD SWAP CMOVE ;
( Initializes for loop Ham 18:34 11/06/86 )
: DSET ( d # T|# F -- m n p )
( m = # of digits to collect, n p = limits for loop )
0START OFF #init OVER BOX
IF ( old number present ) SET-dec SET-NEG 2DUP
2DUP OR 0= #DEC @ 0= AND ( double is both zero and whole )
IF 0START ON THEN ( so mark it as a zero start )
#OFDIGITS #DEC @ MAX DUP #HIT ! ( set # of digits entered )
DUP #DEC @ - 0 MAX #WHOLE ! ( set # of whole digits ent)
ROT ROT SET-#P ( make & save ASCII string )
SWAP DUP 1+ ROT 0START @ + ( using 83-Std flag to decr)
ELSE ( no old number present ) DUP 1+ 0 THEN ;
( Backspace routine Ham 10:35 12/13/86 )
VARIABLE INDX ( holds index from loop )
: "I" ( - index ) INDX @ ; ( lets me get I from outside loop )
: NO#? ( - f) #HIT @ 0= ; ( T = no digits entered )
: BSP-ROU ( -- loop-incr ) dec? #dec @ 0= AND
IF dec~ OFF 0 ( just backed over the decimal point )
ELSE "I" IF 0 "I" 1- #P! ( zap previous entry in string )
#HIT DECR #dec-ADJ #WHOLE-ADJ ( adjust counts )
NO-.? ( no minus sign or decimal point? )
IF BELL "I" NEGATE ( back up all the way )
ELSE NO#? IF "I" NEGATE
ELSE -1 THEN THEN
ELSE *HIT/NEG BELL 0 THEN THEN ;
( The above above takes care of the details of the backspace in
numeric entry & leaves the proper loop increment on the stk )
( Final input word Ham 18:51 11/06/86 )
: DIGITS ( d # T | # F -- d #) REVERSE DSET DO DISPLAY# GET#
DUP Bs? IF DROP I INDX ! BSP-ROU
ELSE DUP ASCII - = IF DROP NEG~ @ NOT NEG~ ! 0
ELSE DUP ASCII . = IF DROP .ROUTINE 0
ELSE DUP ASCII C = IF DROP #PAD C@ ASCII 0 <>
IF #HIT @ NEGATE ELSE 0 THEN #init
ELSE DUP I #P! ( store char ) Cr? IF LEAVE THEN
I 1+ #HIT ! ( count of net keystrokes )
DUP ( # of digits to enter ) I = WHOLE-CK DEC-CK
IF ( at end: reject digit ) 0 I #P! I #HIT ! BELL 0
ELSE #PAD I + C@ ASCII 0 <> I 0<> OR dec? OR
NEGATE ( 83 Std flag ) DUP IF CNT-DIGIT THEN
THEN THEN THEN THEN THEN +LOOP
DROP ( count ) #DONE REVERSE ;
( Test Ham 18:51 11/06/86 )
0 PLACES
OK-NEG OFF
SOUND ON
-CUR
5 NEW DIGITS
CR CR
2 PLACES
OK-NEG ON
7 NEW DIGITS
+CUR