11.07.2015 Views

Untitled - TRS-80 Color Computer Archive

Untitled - TRS-80 Color Computer Archive

Untitled - TRS-80 Color Computer Archive

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

language USR calls for use in theirBASIC programs. But this is beyondthe ken of most BASIC users.Fortunately, bitwise operatorscan be implemented in Atari BASIC.And that's exactly the purpose of thesubroutines of lines 9000 through9090 (bitwise AND) and lines 9100through 9190 (bitwise OR) in Program 2. I don't have space in thiscolumn to explain the theory andoperation of bitwise operators, butwe can quickly look at one exampleof their use.Suppose you want to performsome subroutine only when theuser of your program hits the SELECT key. Further, suppose that inyour program it is legitimate andpossible that the user may be pushing down either {or both) theSTART and OPTION keys at thatsame time as SELECT. If you lookin most any good reference book(COMPUTED Mapping the Atari,for example), you will find a littletable something like this:Push PEEK(53279) shows thisthis key decimal binarynoneSTARTSELECTOPTION111110101011Here we have listed the binaryvalues (even though you couldhave run Program 1 to convert thedecimal values yourself) to showclearly what the console keys aredoing: Each of those three keyschanges a single bit of the specifiedaddress from 1 to 0 when it ispushed. So, we would like a way toisolate the state of the middle bit (ofthe three) to test for SELECT beingpressed. No sooner said than done.In most languages, you woulduse something equivalent to this:SELECTPUSHED = NOT { PEEK(53279)AND 2)In Atari BASIC, you can do it theway I did it in Program 2. Enoughsaid?Finally, there is Program 3. Youcan not use this program by itself.You must first add all four of thesubroutines (on lines numbered 9000or greater) from Programs 1 and 2. Besure to keep those subroutines handyso they can be used by Program 3 or,I hope, by some of your own programs. (Remember, if you LIST arange of lines to disk or cassette, youcan use ENTER to merge them witha program in memory.)Program 3 is a catchall. It allows you to enter two numbersusing two (optionally) differentnumber bases. It then allows you tochoose a number base for displaypurposes and shows you the conversions of the two numbers alongwith the results of bitwise ANDingthem and bitwise ORing them. Fora thorough understanding ofbitwise operations, you mightchoose base 2 (binary) for all inputand output. Happy hacking. @Program 1: Base ConverterEI 100 REM ***** PROGRAM TODEMONSTRATEK110 REM ***** NUMBER BASECONVERSIONHH 120 REMEH130 DIM N*(40):REM (MUSTBE AT LEAST 32)HJ 140 REMJO 200 ? : ? i PRINT "BASE FORINPUT";:INPUT BASEINKE 210 PRINT "NUMBER ";HNPUT N*HJ 220 BASE-BASEIN: QOSUB 9400:DECIMAL-NCE 230 IF N

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!