10REM ** ANDorEOR6 **
20REM (C) DP-J 31Mar1994 Ver 1.11
30:
40MODE7
50PROCtitle
60PRINTTAB(0,23)"Information ? ";
70REPEAT:g%=INSTR(" YyNn",GET$) DIV2:
IFg%=1MODE3:VDU19,1,3,0,0,0:PROCinfo ELS
E UNTILg%
80IFg%=1 PROCend:END
90*FX4,2
100*FX229,1
110MODE7:PROCtitle
120PROCin:PROCdo
130VDU23,1,0,0;0;0;0
140PRINTTAB(0,30)"R to Re-RUN: Q to Qu
it: M to alter mask"
150REPEAT:g%=INSTR(" RrQqMm",GET$) DIV
2:IFg%=3 PROCalter ELSE UNTILg%
160IFg%=1RUN
170PROCend:END
180:
190DEF PROCend
200VDU23,1,1,0;0;0;0
210*FX4,0
220*FX229,0
230IFg%=1PRINTTAB(40,24)"<FINISHED"; E
LSEPRINTTAB(13,3)"<FINISHED";
240ENDPROC
250:
260DEF PROCin
270PRINTTAB(0,23)"(H)exadecimal or (D)
ecimal operand?";
280REPEAT:s%=INSTR("HhDd",GET$):UNTILs
%:CLS
290y%=0
300IFs%<3 REPEAT:PRINTTAB(0,2)CHR$(130
)"Operand = &";:INPUT""x$:PROCvalid(x$,2
):UNTILj%=0:x%=EVAL("&"+x$)
310IFs%>2 REPEAT:PRINTTAB(0,2)CHR$(130
)"Operand = ";:INPUT""x%;:x$=STR$(x%):P
ROCvalid(x$,2):UNTILj%=0:PRINTTAB(20,2)"
(denary)":s%=2
320PRINTTAB(0,3)CHR$(133)"Mask = &"
;:PRINTTAB(12,3)STRING$(25," "):REPEAT:I
NPUTTAB(12,3)y$:PROCvalid(y$,3):UNTILj%=
0:y%=EVAL("&"+y$)
330PRINTSTRING$(34," ");TAB(0,4)CHR$(1
34)"Result"
340PRINT'TAB(7)CHR$(130)"MSB"TAB(25)"L
SB"
350ENDPROC
360:
370DEF PROCdo
380PROCbin(x%,130):PROCbin(y%,133)
390xand%=x%ANDy%:PROCbin(xand%,134):PR
INT" AND"
400PRINTCHR$(129)"Masked bits unchange
d"'CHR$(129)"Un-Masked bits are unset"
410:
420PROCbin(x%,130):PROCbin(y%,133)
430xor%=x%ORy%:PROCbin(xor%,134):PRINT
" OR"
440PRINTCHR$(129)"Masked bits are set"
'CHR$(129)"Un-Masked bits unchanged"
450:
460PROCbin(x%,130):PROCbin(y%,133)
470xeor%=x%EORy%:PROCbin(xeor%,134):PR
INT" EOR"
480PRINTCHR$(129)"Masked bits reversed
"'CHR$(129)"Un-Masked bits unchanged"
490ENDPROC
500:
510DEF PROCbin(N%,c)
520LOCALn%:PRINT
530FORn%=15TO0STEP-1
540IFn% MOD8=7 PRINT" ";
550IFN% AND2^n% PRINTCHR$(c)"1"; ELSE
PRINTCHR$(c)"0";
560NEXT
570ENDPROC
580:
590DEF PROCalter
600LOCALr%,tab%,b%
610PRINTTAB(0,23)"Cursors:Spacebar to
set/unset mask bits"
620PRINTTAB(0,24)" (B)eep: (C)lear Ma
sk: (R)UN: (Q)uit";:VDU11
630*FX4,1
640c%=0:r%=7:bp%=7
650PRINTTAB(32,r%)CHR$136
660REPEAT
670PRINTTAB(34-c%,r%)"<":tabc%=34-c%:t
abr%=r%
680REPEAT:g%=(GETAND95)-7:UNTILg%>0AND
g%<5ORg%=-7ORg%=74ORg%=59ORg%=60ORg%=75
690c%=c%+(-(g%=1)+(g%=2))*2
700IFg%=1 c%=c%-(c%=16) ELSE IFg%=2 c%
=c%+(c%=15)
710IFc%<0 c%=0 ELSE IFc%>31 c%=31
720r%=r%-(g%=3)*6+(g%=4)*6
730IFr%<7 r%=7 ELSE IFr%>19 r%=19
740b%=(c%+(c%>16)) DIV2
750IFg%=59 bp%=bp%+1:bp%=bp% MOD2*7
760IFg%=-7 THEN IF(y%AND(2^b%))=0 VDUb
p%:y%=y%+2^b% ELSE IF g%=-7 VDUbp%:y%=y%
-2^b%
770PRINTTAB(tabc%,tabr%)" "
780IFg%=60 y%=0
790IFg%=-7ORg%=60 PRINTTAB(19,1)CHR$13
1"& "TAB(21,1);÷y%;TAB(26,1)"=current
Mask"TAB(0,4)" ":PROCdo
800UNTILg%=74ORg%=75
810IFg%=75 g%=1
820ENDPROC
830:
840DEF PROCvalid(x$,row%)
850LOCALg%,i%
860IFx$=""PROCerr(19,20):PRINT"No inpu
t! Try again":ENDPROC
870j%=0:FORi%=1TOLENx$:z$=MID$(x$,i%,1
):g%=INSTR("0123456789ABCDEF",z$):j%=j%+
(g%=0):NEXT
880IF j%<>0 PROCerr(15,24):PRINT"(&"x$
")? Invalid hex":ENDPROC
890IFs%<3ANDLENx$>4 PROCerr(34,5):PRIN
T"Too big: 16 bits only. &FFFF max":ENDP
ROC
900IFs%>2 IFx%>65535 PROCerr(34,5):PRI
NT"Too big: 16 bits only. 65535 max":END
PROC
910ENDPROC
920:
930DEF PROCerr(a%,b%)
940PRINTTAB(a%,row%+1)STRING$(b%," ")T
AB(12,row%)STRING$(10," "):j%=1
950ENDPROC
960:
970DEF PROCtitle
980PRINTTAB(35,6)CHR$(130)"dp-j"
990PRINTTAB(10,8)CHR$(141)CHR$(130)"AN
DandORandEOR"
1000PRINTTAB(10)CHR$(141)CHR$(133)"ANDa
ndORandEOR"
1010PRINT'TAB(7)CHR$(133)"16 bit intege
r numbers"
1020PRINT''CHR$(130)"LSB is least signi
ficant byte (lo-byte)"
1030PRINTCHR$(130)"MSB is most signific
ant byte (hi-byte)"
1040ENDPROC
1050:
1060DEF PROCinfo
1070PRINTTAB(0,2)"INTRODUCTION"
1080PRINT"When it is required to manipu
late selected bits of a binary number a
procedure referred to as 'masking' is u
sed."
1090PRINT"The mask is simply a number w
hich is ANDed, ORed or EORed with the or
iginal"'"number (the operand) to isolate
or convert selected bits of the operand
."
1100PRINT"For example it may be require
d to test if the operand has certain bit
s 'set'."'"(ie. having the value 1 as op
posed to 0)"
1110PRINT"The mask is expressed in hexa
decimal which has a more direct relation
ship to thehalf-byte (nybble) and conseq
uently less cumbersome than denary to in
terpret."
1120PRINT'"OPERATION"
1130PRINT"This utility performs the (op
erand)AND(mask) etc. logic operations an
d displays the resulting bits."
1140PRINT"A particular mask can be sele
cted for bit manipulation but note that
ALL the"'"masks and results are then cor
respondingly updated."
1150PRINT"The original mask value is re
tained for reference and the current val
ue is"'"displayed alongside."
1160PRINT"Protection is provided agains
t invalid inputs."
1170PRINT'"FEEDBACK"
1180PRINT"Program comment to:- 8
-Bit Software, 17 Lambert Park Road, Hed
on, Hull"'TAB(28)"East Yorkshire. HU12 8
HF."
1190PRINTTAB(0,24)"End of Text. (C)onti
nue or (F)inish? ";
1200REPEAT:g%=INSTR(" FfCc",GET$) DIV2:
IFg%=1PROCend ELSEUNTILg%=2
1210ENDPROC