Functions to Read, Test, and Change bits:
DEF FNReadBit (Address,Bit) = INT(PEEK(Address)/2^Bit)-2 * INT(PEEK(Address)/2^(Bit+1))
DEF FNResetBit (Address,Bit) = PEEK(Address) - FNReadBit(Address,Bit) * 2^Bit
DEF FNSetBit (Address,Bit) = PEEK(Address) + (1-FNReadBit(Address,Bit)) * 2^Bit
DEF FNToggleBit (Address,Bit) = FNResetBit(Address,Bit) + FNSetBit(Address,Bit) - peek(Address)
109 -- Bit 1==> Type-Ahead
Set = Enabled
Reset = Disabled
116 -- Bit 5==> Caps
Set = Upper Only
Reset = Upper/Lower
121 -- Bit 7==> Spooler
Set = Despooling
Reset = Paused
124 -- Bit 4==> Break Key
Set = Disabled
Reset = Enabled
127 -- Bit 4==> Clock Display
Set = Display On
Reset = Display Off
127 -- Bit 6==> Cursor Control
Set = Non-Blinking
Reset = Blinking
For example to turn the clock display on from BASIC use the statement:
POKE 127,FNSetBit(127,4).
Print string of number without a leading space:
Call with A set to the number.
DEF FNST$(A)=RIGHT$(STR$(A),LEN(STR$(A))-1)
Function to display the current DOS version:
DEF FNVersion$="TRSDOS Version " + LEFT$(HEX$(PEEK(133)),1)+"." + RIGHT$(HEX$(PEEK(133)),1) + "."+HEX$(PEEK(59))
Function to display the current date in 'Day, Mon ##, 19##' format:
DEF FNDay$=MID$("SunMonTueWedThuFriSat",(((PEEK(55)AND 14)/2)-1)*3+1,3)+", "+MID$("JanFebMarAprMayJunJulAugSepOctNovDec",(PEEK(53)-1)*3+1,3)+" "+RIGHT$(" "+FNST$(PEEK(52))+", 19"+FNST$(PEEK(51))
Print appropriate article in front of a word:
Call with A$ = to the word that you want the article in front of.
DEF FNARTICLE$(A$)="A"+LEFT$("n",INSTR("AEIOUaeiou",LEFT$(A$,1)))+" "+A$
Display a menu number in reverse video:
Call with A = to menu number to display.
DEF FNNUM$(A)="{"+CHR$(16)+FNST$(A)+CHR$(17)"} "
Condense the TIME or DATE strings to 4 bytes:
Call with A$ = to TIME$ or DATE$.
DEF FNTIMEDATE$(A$)=MKS$(VAL(LEFT$(A$,2)+MID$(A$,4,2)+RIGHT$(A$,2)))
Expand time or date string as condense above:
Call with A$ = Condensed string -- B$ = seperator, '/' or ':'.
DEF FNEXPAND$(A$,B$)=STRING$(6-LEN(FNST$(CVS(A$))),48) +
LEFT$(FNST$(CVS(A$)),(LEN(FNST$(CVS(A$)))-4))+B$ +
LEFT$(RIGHT$(FNST$(CVS(A$)),4),2)+B$ +
RIGHT$(FNST$(CVS(A$)),2)
Pad string on right or left to a specific length:
Call with A$ = String -- A = maximum length to output
DEF FNRSPC$(A$,A)=LEFT$(A$+SPACE$(A),A)
DEF FNLSPC$(A$,A)=RIGHT$(SPACE$(A)+A$,A)