10 REM ** ANDorEOR6 ** 20 REM (C) DP-J 31Mar1994 Ver 1.11 30 : 40 MODE7 50 PROCtitle 60 PRINTTAB(0,23)"Information ? "; 70 REPEAT:g%=INSTR(" YyNn",GET$) DIV2:IFg%=1MODE3:VDU19,1,3,0,0,0:PROCinfo ELSE UNTILg% 80 IFg%=1 PROCend:END 90 *FX4,2 100 *FX229,1 110 MODE7:PROCtitle 120 PROCin:PROCdo 130 VDU23,1,0,0;0;0;0 140 PRINTTAB(0,30)"R to Re-RUN: Q to Quit: M to alter mask" 150 REPEAT:g%=INSTR(" RrQqMm",GET$) DIV2:IFg%=3 PROCalter ELSE UNTILg% 160 IFg%=1RUN 170 PROCend:END 180 : 190 DEF PROCend 200 VDU23,1,1,0;0;0;0 210 *FX4,0 220 *FX229,0 230 IFg%=1PRINTTAB(40,24)"2 REPEAT:PRINTTAB(0,2)CHR$(130)"Operand = ";:INPUT""x%;:x$=STR$(x%):PROCvalid(x$,2):UNTILj%=0:PRINTTAB(20,2)"(denary)":s%=2 320 PRINTTAB(0,3)CHR$(133)"Mask = &";:PRINTTAB(12,3)STRING$(25," "):REPEAT:INPUTTAB(12,3)y$:PROCvalid(y$,3):UNTILj%=0:y%=EVAL("&"+y$) 330 PRINTSTRING$(34," ");TAB(0,4)CHR$(134)"Result" 340 PRINT'TAB(7)CHR$(130)"MSB"TAB(25)"LSB" 350 ENDPROC 360 : 370 DEF PROCdo 380 PROCbin(x%,130):PROCbin(y%,133) 390 xand%=x%ANDy%:PROCbin(xand%,134):PRINT" AND" 400 PRINTCHR$(129)"Masked bits unchanged"'CHR$(129)"Un-Masked bits are unset" 410 : 420 PROCbin(x%,130):PROCbin(y%,133) 430 xor%=x%ORy%:PROCbin(xor%,134):PRINT" OR" 440 PRINTCHR$(129)"Masked bits are set"'CHR$(129)"Un-Masked bits unchanged" 450 : 460 PROCbin(x%,130):PROCbin(y%,133) 470 xeor%=x%EORy%:PROCbin(xeor%,134):PRINT" EOR" 480 PRINTCHR$(129)"Masked bits reversed"'CHR$(129)"Un-Masked bits unchanged" 490 ENDPROC 500 : 510 DEF PROCbin(N%,c) 520 LOCALn%:PRINT 530 FORn%=15TO0STEP-1 540 IFn% MOD8=7 PRINT" "; 550 IFN% AND2^n% PRINTCHR$(c)"1"; ELSE PRINTCHR$(c)"0"; 560 NEXT 570 ENDPROC 580 : 590 DEF PROCalter 600 LOCALr%,tab%,b% 610 PRINTTAB(0,23)"Cursors:Spacebar to set/unset mask bits" 620 PRINTTAB(0,24)" (B)eep: (C)lear Mask: (R)UN: (Q)uit";:VDU11 630 *FX4,1 640 c%=0:r%=7:bp%=7 650 PRINTTAB(32,r%)CHR$136 660 REPEAT 670 PRINTTAB(34-c%,r%)"<":tabc%=34-c%:tabr%=r% 680 REPEAT:g%=(GETAND95)-7:UNTILg%>0ANDg%<5ORg%=-7ORg%=74ORg%=59ORg%=60ORg%=75 690 c%=c%+(-(g%=1)+(g%=2))*2 700 IFg%=1 c%=c%-(c%=16) ELSE IFg%=2 c%=c%+(c%=15) 710 IFc%<0 c%=0 ELSE IFc%>31 c%=31 720 r%=r%-(g%=3)*6+(g%=4)*6 730 IFr%<7 r%=7 ELSE IFr%>19 r%=19 740 b%=(c%+(c%>16)) DIV2 750 IFg%=59 bp%=bp%+1:bp%=bp% MOD2*7 760 IFg%=-7 THEN IF(y%AND(2^b%))=0 VDUbp%:y%=y%+2^b% ELSE IF g%=-7 VDUbp%:y%=y%-2^b% 770 PRINTTAB(tabc%,tabr%)" " 780 IFg%=60 y%=0 790 IFg%=-7ORg%=60 PRINTTAB(19,1)CHR$131"& "TAB(21,1);~y%;TAB(26,1)"=current Mask"TAB(0,4)" ":PROCdo 800 UNTILg%=74ORg%=75 810 IFg%=75 g%=1 820 ENDPROC 830 : 840 DEF PROCvalid(x$,row%) 850 LOCALg%,i% 860 IFx$=""PROCerr(19,20):PRINT"No input! Try again":ENDPROC 870 j%=0:FORi%=1TOLENx$:z$=MID$(x$,i%,1):g%=INSTR("0123456789ABCDEF",z$):j%=j%+(g%=0):NEXT 880 IF j%<>0 PROCerr(15,24):PRINT"(&"x$")? Invalid hex":ENDPROC 890 IFs%<3ANDLENx$>4 PROCerr(34,5):PRINT"Too big: 16 bits only. &FFFF max":ENDPROC 900 IFs%>2 IFx%>65535 PROCerr(34,5):PRINT"Too big: 16 bits only. 65535 max":ENDPROC 910 ENDPROC 920 : 930 DEF PROCerr(a%,b%) 940 PRINTTAB(a%,row%+1)STRING$(b%," ")TAB(12,row%)STRING$(10," "):j%=1 950 ENDPROC 960 : 970 DEF PROCtitle 980 PRINTTAB(35,6)CHR$(130)"dp-j" 990 PRINTTAB(10,8)CHR$(141)CHR$(130)"ANDandORandEOR" 1000 PRINTTAB(10)CHR$(141)CHR$(133)"ANDandORandEOR" 1010 PRINT'TAB(7)CHR$(133)"16 bit integer numbers" 1020 PRINT''CHR$(130)"LSB is least significant byte (lo-byte)" 1030 PRINTCHR$(130)"MSB is most significant byte (hi-byte)" 1040 ENDPROC 1050 : 1060 DEF PROCinfo 1070 PRINTTAB(0,2)"INTRODUCTION" 1080 PRINT"When it is required to manipulate selected bits of a binary number a procedure referred to as 'masking' is used." 1090 PRINT"The mask is simply a number which is ANDed, ORed or EORed with the original"'"number (the operand) to isolate or convert selected bits of the operand." 1100 PRINT"For example it may be required to test if the operand has certain bits 'set'."'"(ie. having the value 1 as opposed to 0)" 1110 PRINT"The mask is expressed in hexadecimal which has a more direct relationship to thehalf-byte (nybble) and consequently less cumbersome than denary to interpret." 1120 PRINT'"OPERATION" 1130 PRINT"This utility performs the (operand)AND(mask) etc. logic operations and displays the resulting bits." 1140 PRINT"A particular mask can be selected for bit manipulation but note that ALL the"'"masks and results are then correspondingly updated." 1150 PRINT"The original mask value is retained for reference and the current value is"'"displayed alongside." 1160 PRINT"Protection is provided against invalid inputs." 1170 PRINT'"FEEDBACK" 1180 PRINT"Program comment to:- 8-Bit Software"'TAB(28)"East Yorkshire. HU12 8HF." 1190 PRINTTAB(0,24)"End of Text. (C)ontinue or (F)inish? "; 1200 REPEAT:g%=INSTR(" FfCc",GET$) DIV2:IFg%=1PROCend ELSEUNTILg%=2 1210 ENDPROC