Home » CEEFAX disks » telesoftware3.adl » 11_12_87/T\OSB08

11_12_87/T\OSB08

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » CEEFAX disks » telesoftware3.adl
Filename: 11_12_87/T\OSB08
Read OK:
File size: 123A bytes
Load address: 0000
Exec address: 0000
File contents
OSBITS - An Exploration of the BBC Micro at Machine Level

By Programmer

...........................................................


Part 8: Logical Operators

We're back to comparisons in this module.  Already you have
come across branching operations carried out conditionally
on the setting of certain flags in the processor status
register; mnemonics like BNE BEQ BMI.  Logical operators
enable us to compare the bits of one byte with the bits of
another, and essentially there are three types of
comparison.

AND is the first.  This means that when you take byte1 AND
byte 2 the result has bits set only where they are set in
both bytes.  This can be illustrated by using a thing called
a truth table (ancient form of torture no doubt):

                    0  1          0 AND 0 = 0
                                  1 AND 0 = 0
               0    0  0          0 AND 1 = 0
               1    0  1          1 AND 1 = 1

AND is used to mask out certain bits of a byte so that we
are only left with the ones we want.  Say we wanted to set
the top bit of a byte held in the Accumulator to zero, then
we would do it like this.

        LDA number
        AND #&7F         \ &7F is 01111111 in binary

This does not mean that all seven lower bits of the number
are set but that the top bit is cleared and the lower seven
are left unchanged.

In the program for the last module I used AND #&F to mask
out the top four bits of a byte so I could work with the
just the bottom nybble.

There is a variant on AND with the mnemonic BIT which
performs an AND without changing the byte in the
Accumulator.  It does affect the flags though so branching
can be done on the result of a BIT operation.  It is used to
test specific bits (hence the mnemonic) and to use it you
load the mask into the accumulator and BIT a memory location
like this:

        LDA #1
        BIT number       \ If bit 0 is 1 then the zero
                         \ flag will be cleared
        BNE elsewhere    \ So branch if bit 0 is set

OR is the next, with the mnemonic ORA.  Here if a particular
bit of either byte is set then that bit of the result will
be set.

                   0  1           0 0R 0 = 0
                                  1 OR 0 = 1
               0   0  1           0 OR 1 = 1
               1   1  1           1 OR 1 = 1

This is used to make sure that bits of a byte are set (i.e.
the reverse of AND) such that to set the top bit of a number
we do this:

         LDA number
         ORA &80         \ &80 is 10000000 in binary

and the top bit will be set and the rest will remain
unchanged.

The final operator is the Exclusive OR, and EOR is the
mnemonic.  Here a bit in the result is set if that bit is
set in either, but not both, of the other bytes.

                   0  1           0 EOR 0 = 0
                                  1 EOR 0 = 1
               0   0  1           0 EOR 1 = 1
               1   1  0           1 EOR 1 = 0

With this you can reverse the status of a flag without
knowing that status beforehand.  I call it flag waving with
EOR (apologies to A A Milne).  Let's say you have bit 0 of a
number as a flag and you want to reverse it, then you do
this.

         LDA number
         EOR 1           \ 1 is, of course, 00000001


EORing a number with itself always produces zero and EORing
with &FF reverses the settings of all bits, producing a ones
complement negative.  A neat way to produce the negative of
a byte is to EOR it with &FF (255) and then add one.  Check
back to module 2 to see why it works.

It's a simple little piece of code in this module.  The
ASCII codes are arranged such that the code for a letter AND
&DF will always produce the code for upper case, and B/osb08
does simply that.  However, being simple it does not produce
a satisfactory result for all the other keys on the
keyboard.  This approach is one of the ways to legislate
against people who turn off (or on) the CAPS LOCK on their
micro when you expect it the other way around.  The other
way is to use OSBYTE 202 which simulates pressing of the
relevant keys.  The only trap in this code is to prevent a
control code sneaking through without you expecting it.

In the next module I'll give you some information about the
other operating system routines in the BBC Micro to do with
file handling and the like, and we'll use one of them to
print out a list of the ROMS in your machine.

............................................................

PS:  Thank you for your feedback.  I'm particularly grateful
to Peter Vince for his constructive criticism and spelling
checker and I hope that my odd typo and (rare!) brain clog
have not confused you.
00000000  4f 53 42 49 54 53 20 2d  20 41 6e 20 45 78 70 6c  |OSBITS - An Expl|
00000010  6f 72 61 74 69 6f 6e 20  6f 66 20 74 68 65 20 42  |oration of the B|
00000020  42 43 20 4d 69 63 72 6f  20 61 74 20 4d 61 63 68  |BC Micro at Mach|
00000030  69 6e 65 20 4c 65 76 65  6c 0d 0d 42 79 20 50 72  |ine Level..By Pr|
00000040  6f 67 72 61 6d 6d 65 72  0d 0d 2e 2e 2e 2e 2e 2e  |ogrammer........|
00000050  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 2e  |................|
*
00000080  2e 2e 2e 2e 2e 0d 0d 0d  50 61 72 74 20 38 3a 20  |........Part 8: |
00000090  4c 6f 67 69 63 61 6c 20  4f 70 65 72 61 74 6f 72  |Logical Operator|
000000a0  73 0d 0d 57 65 27 72 65  20 62 61 63 6b 20 74 6f  |s..We're back to|
000000b0  20 63 6f 6d 70 61 72 69  73 6f 6e 73 20 69 6e 20  | comparisons in |
000000c0  74 68 69 73 20 6d 6f 64  75 6c 65 2e 20 20 41 6c  |this module.  Al|
000000d0  72 65 61 64 79 20 79 6f  75 20 68 61 76 65 0d 63  |ready you have.c|
000000e0  6f 6d 65 20 61 63 72 6f  73 73 20 62 72 61 6e 63  |ome across branc|
000000f0  68 69 6e 67 20 6f 70 65  72 61 74 69 6f 6e 73 20  |hing operations |
00000100  63 61 72 72 69 65 64 20  6f 75 74 20 63 6f 6e 64  |carried out cond|
00000110  69 74 69 6f 6e 61 6c 6c  79 0d 6f 6e 20 74 68 65  |itionally.on the|
00000120  20 73 65 74 74 69 6e 67  20 6f 66 20 63 65 72 74  | setting of cert|
00000130  61 69 6e 20 66 6c 61 67  73 20 69 6e 20 74 68 65  |ain flags in the|
00000140  20 70 72 6f 63 65 73 73  6f 72 20 73 74 61 74 75  | processor statu|
00000150  73 0d 72 65 67 69 73 74  65 72 3b 20 6d 6e 65 6d  |s.register; mnem|
00000160  6f 6e 69 63 73 20 6c 69  6b 65 20 42 4e 45 20 42  |onics like BNE B|
00000170  45 51 20 42 4d 49 2e 20  20 4c 6f 67 69 63 61 6c  |EQ BMI.  Logical|
00000180  20 6f 70 65 72 61 74 6f  72 73 0d 65 6e 61 62 6c  | operators.enabl|
00000190  65 20 75 73 20 74 6f 20  63 6f 6d 70 61 72 65 20  |e us to compare |
000001a0  74 68 65 20 62 69 74 73  20 6f 66 20 6f 6e 65 20  |the bits of one |
000001b0  62 79 74 65 20 77 69 74  68 20 74 68 65 20 62 69  |byte with the bi|
000001c0  74 73 20 6f 66 0d 61 6e  6f 74 68 65 72 2c 20 61  |ts of.another, a|
000001d0  6e 64 20 65 73 73 65 6e  74 69 61 6c 6c 79 20 74  |nd essentially t|
000001e0  68 65 72 65 20 61 72 65  20 74 68 72 65 65 20 74  |here are three t|
000001f0  79 70 65 73 20 6f 66 0d  63 6f 6d 70 61 72 69 73  |ypes of.comparis|
00000200  6f 6e 2e 0d 0d 41 4e 44  20 69 73 20 74 68 65 20  |on...AND is the |
00000210  66 69 72 73 74 2e 20 20  54 68 69 73 20 6d 65 61  |first.  This mea|
00000220  6e 73 20 74 68 61 74 20  77 68 65 6e 20 79 6f 75  |ns that when you|
00000230  20 74 61 6b 65 20 62 79  74 65 31 20 41 4e 44 0d  | take byte1 AND.|
00000240  62 79 74 65 20 32 20 74  68 65 20 72 65 73 75 6c  |byte 2 the resul|
00000250  74 20 68 61 73 20 62 69  74 73 20 73 65 74 20 6f  |t has bits set o|
00000260  6e 6c 79 20 77 68 65 72  65 20 74 68 65 79 20 61  |nly where they a|
00000270  72 65 20 73 65 74 20 69  6e 0d 62 6f 74 68 20 62  |re set in.both b|
00000280  79 74 65 73 2e 20 20 54  68 69 73 20 63 61 6e 20  |ytes.  This can |
00000290  62 65 20 69 6c 6c 75 73  74 72 61 74 65 64 20 62  |be illustrated b|
000002a0  79 20 75 73 69 6e 67 20  61 20 74 68 69 6e 67 20  |y using a thing |
000002b0  63 61 6c 6c 65 64 0d 61  20 74 72 75 74 68 20 74  |called.a truth t|
000002c0  61 62 6c 65 20 28 61 6e  63 69 65 6e 74 20 66 6f  |able (ancient fo|
000002d0  72 6d 20 6f 66 20 74 6f  72 74 75 72 65 20 6e 6f  |rm of torture no|
000002e0  20 64 6f 75 62 74 29 3a  0d 0d 20 20 20 20 20 20  | doubt):..      |
000002f0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 30 20  |              0 |
00000300  20 31 20 20 20 20 20 20  20 20 20 20 30 20 41 4e  | 1          0 AN|
00000310  44 20 30 20 3d 20 30 0d  20 20 20 20 20 20 20 20  |D 0 = 0.        |
00000320  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000330  20 20 20 20 20 20 20 20  20 20 31 20 41 4e 44 20  |          1 AND |
00000340  30 20 3d 20 30 0d 20 20  20 20 20 20 20 20 20 20  |0 = 0.          |
00000350  20 20 20 20 20 30 20 20  20 20 30 20 20 30 20 20  |     0    0  0  |
00000360  20 20 20 20 20 20 20 20  30 20 41 4e 44 20 31 20  |        0 AND 1 |
00000370  3d 20 30 0d 20 20 20 20  20 20 20 20 20 20 20 20  |= 0.            |
00000380  20 20 20 31 20 20 20 20  30 20 20 31 20 20 20 20  |   1    0  1    |
00000390  20 20 20 20 20 20 31 20  41 4e 44 20 31 20 3d 20  |      1 AND 1 = |
000003a0  31 0d 0d 41 4e 44 20 69  73 20 75 73 65 64 20 74  |1..AND is used t|
000003b0  6f 20 6d 61 73 6b 20 6f  75 74 20 63 65 72 74 61  |o mask out certa|
000003c0  69 6e 20 62 69 74 73 20  6f 66 20 61 20 62 79 74  |in bits of a byt|
000003d0  65 20 73 6f 20 74 68 61  74 20 77 65 0d 61 72 65  |e so that we.are|
000003e0  20 6f 6e 6c 79 20 6c 65  66 74 20 77 69 74 68 20  | only left with |
000003f0  74 68 65 20 6f 6e 65 73  20 77 65 20 77 61 6e 74  |the ones we want|
00000400  2e 20 20 53 61 79 20 77  65 20 77 61 6e 74 65 64  |.  Say we wanted|
00000410  20 74 6f 20 73 65 74 0d  74 68 65 20 74 6f 70 20  | to set.the top |
00000420  62 69 74 20 6f 66 20 61  20 62 79 74 65 20 68 65  |bit of a byte he|
00000430  6c 64 20 69 6e 20 74 68  65 20 41 63 63 75 6d 75  |ld in the Accumu|
00000440  6c 61 74 6f 72 20 74 6f  20 7a 65 72 6f 2c 20 74  |lator to zero, t|
00000450  68 65 6e 0d 77 65 20 77  6f 75 6c 64 20 64 6f 20  |hen.we would do |
00000460  69 74 20 6c 69 6b 65 20  74 68 69 73 2e 0d 0d 20  |it like this... |
00000470  20 20 20 20 20 20 20 4c  44 41 20 6e 75 6d 62 65  |       LDA numbe|
00000480  72 0d 20 20 20 20 20 20  20 20 41 4e 44 20 23 26  |r.        AND #&|
00000490  37 46 20 20 20 20 20 20  20 20 20 5c 20 26 37 46  |7F         \ &7F|
000004a0  20 69 73 20 30 31 31 31  31 31 31 31 20 69 6e 20  | is 01111111 in |
000004b0  62 69 6e 61 72 79 0d 0d  54 68 69 73 20 64 6f 65  |binary..This doe|
000004c0  73 20 6e 6f 74 20 6d 65  61 6e 20 74 68 61 74 20  |s not mean that |
000004d0  61 6c 6c 20 73 65 76 65  6e 20 6c 6f 77 65 72 20  |all seven lower |
000004e0  62 69 74 73 20 6f 66 20  74 68 65 20 6e 75 6d 62  |bits of the numb|
000004f0  65 72 0d 61 72 65 20 73  65 74 20 62 75 74 20 74  |er.are set but t|
00000500  68 61 74 20 74 68 65 20  74 6f 70 20 62 69 74 20  |hat the top bit |
00000510  69 73 20 63 6c 65 61 72  65 64 20 61 6e 64 20 74  |is cleared and t|
00000520  68 65 20 6c 6f 77 65 72  20 73 65 76 65 6e 0d 61  |he lower seven.a|
00000530  72 65 20 6c 65 66 74 20  75 6e 63 68 61 6e 67 65  |re left unchange|
00000540  64 2e 0d 0d 49 6e 20 74  68 65 20 70 72 6f 67 72  |d...In the progr|
00000550  61 6d 20 66 6f 72 20 74  68 65 20 6c 61 73 74 20  |am for the last |
00000560  6d 6f 64 75 6c 65 20 49  20 75 73 65 64 20 41 4e  |module I used AN|
00000570  44 20 23 26 46 20 74 6f  20 6d 61 73 6b 0d 6f 75  |D #&F to mask.ou|
00000580  74 20 74 68 65 20 74 6f  70 20 66 6f 75 72 20 62  |t the top four b|
00000590  69 74 73 20 6f 66 20 61  20 62 79 74 65 20 73 6f  |its of a byte so|
000005a0  20 49 20 63 6f 75 6c 64  20 77 6f 72 6b 20 77 69  | I could work wi|
000005b0  74 68 20 74 68 65 0d 6a  75 73 74 20 74 68 65 20  |th the.just the |
000005c0  62 6f 74 74 6f 6d 20 6e  79 62 62 6c 65 2e 0d 0d  |bottom nybble...|
000005d0  54 68 65 72 65 20 69 73  20 61 20 76 61 72 69 61  |There is a varia|
000005e0  6e 74 20 6f 6e 20 41 4e  44 20 77 69 74 68 20 74  |nt on AND with t|
000005f0  68 65 20 6d 6e 65 6d 6f  6e 69 63 20 42 49 54 20  |he mnemonic BIT |
00000600  77 68 69 63 68 0d 70 65  72 66 6f 72 6d 73 20 61  |which.performs a|
00000610  6e 20 41 4e 44 20 77 69  74 68 6f 75 74 20 63 68  |n AND without ch|
00000620  61 6e 67 69 6e 67 20 74  68 65 20 62 79 74 65 20  |anging the byte |
00000630  69 6e 20 74 68 65 0d 41  63 63 75 6d 75 6c 61 74  |in the.Accumulat|
00000640  6f 72 2e 20 20 49 74 20  64 6f 65 73 20 61 66 66  |or.  It does aff|
00000650  65 63 74 20 74 68 65 20  66 6c 61 67 73 20 74 68  |ect the flags th|
00000660  6f 75 67 68 20 73 6f 20  62 72 61 6e 63 68 69 6e  |ough so branchin|
00000670  67 0d 63 61 6e 20 62 65  20 64 6f 6e 65 20 6f 6e  |g.can be done on|
00000680  20 74 68 65 20 72 65 73  75 6c 74 20 6f 66 20 61  | the result of a|
00000690  20 42 49 54 20 6f 70 65  72 61 74 69 6f 6e 2e 20  | BIT operation. |
000006a0  20 49 74 20 69 73 20 75  73 65 64 20 74 6f 0d 74  | It is used to.t|
000006b0  65 73 74 20 73 70 65 63  69 66 69 63 20 62 69 74  |est specific bit|
000006c0  73 20 28 68 65 6e 63 65  20 74 68 65 20 6d 6e 65  |s (hence the mne|
000006d0  6d 6f 6e 69 63 29 20 61  6e 64 20 74 6f 20 75 73  |monic) and to us|
000006e0  65 20 69 74 20 79 6f 75  0d 6c 6f 61 64 20 74 68  |e it you.load th|
000006f0  65 20 6d 61 73 6b 20 69  6e 74 6f 20 74 68 65 20  |e mask into the |
00000700  61 63 63 75 6d 75 6c 61  74 6f 72 20 61 6e 64 20  |accumulator and |
00000710  42 49 54 20 61 20 6d 65  6d 6f 72 79 20 6c 6f 63  |BIT a memory loc|
00000720  61 74 69 6f 6e 0d 6c 69  6b 65 20 74 68 69 73 3a  |ation.like this:|
00000730  0d 0d 20 20 20 20 20 20  20 20 4c 44 41 20 23 31  |..        LDA #1|
00000740  0d 20 20 20 20 20 20 20  20 42 49 54 20 6e 75 6d  |.        BIT num|
00000750  62 65 72 20 20 20 20 20  20 20 5c 20 49 66 20 62  |ber       \ If b|
00000760  69 74 20 30 20 69 73 20  31 20 74 68 65 6e 20 74  |it 0 is 1 then t|
00000770  68 65 20 7a 65 72 6f 0d  20 20 20 20 20 20 20 20  |he zero.        |
00000780  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000790  20 5c 20 66 6c 61 67 20  77 69 6c 6c 20 62 65 20  | \ flag will be |
000007a0  63 6c 65 61 72 65 64 0d  20 20 20 20 20 20 20 20  |cleared.        |
000007b0  42 4e 45 20 65 6c 73 65  77 68 65 72 65 20 20 20  |BNE elsewhere   |
000007c0  20 5c 20 53 6f 20 62 72  61 6e 63 68 20 69 66 20  | \ So branch if |
000007d0  62 69 74 20 30 20 69 73  20 73 65 74 0d 0d 4f 52  |bit 0 is set..OR|
000007e0  20 69 73 20 74 68 65 20  6e 65 78 74 2c 20 77 69  | is the next, wi|
000007f0  74 68 20 74 68 65 20 6d  6e 65 6d 6f 6e 69 63 20  |th the mnemonic |
00000800  4f 52 41 2e 20 20 48 65  72 65 20 69 66 20 61 20  |ORA.  Here if a |
00000810  70 61 72 74 69 63 75 6c  61 72 0d 62 69 74 20 6f  |particular.bit o|
00000820  66 20 65 69 74 68 65 72  20 62 79 74 65 20 69 73  |f either byte is|
00000830  20 73 65 74 20 74 68 65  6e 20 74 68 61 74 20 62  | set then that b|
00000840  69 74 20 6f 66 20 74 68  65 20 72 65 73 75 6c 74  |it of the result|
00000850  20 77 69 6c 6c 0d 62 65  20 73 65 74 2e 0d 0d 20  | will.be set... |
00000860  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000870  20 20 30 20 20 31 20 20  20 20 20 20 20 20 20 20  |  0  1          |
00000880  20 30 20 30 52 20 30 20  3d 20 30 0d 20 20 20 20  | 0 0R 0 = 0.    |
00000890  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000008a0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 31 20  |              1 |
000008b0  4f 52 20 30 20 3d 20 31  0d 20 20 20 20 20 20 20  |OR 0 = 1.       |
000008c0  20 20 20 20 20 20 20 20  30 20 20 20 30 20 20 31  |        0   0  1|
000008d0  20 20 20 20 20 20 20 20  20 20 20 30 20 4f 52 20  |           0 OR |
000008e0  31 20 3d 20 31 0d 20 20  20 20 20 20 20 20 20 20  |1 = 1.          |
000008f0  20 20 20 20 20 31 20 20  20 31 20 20 31 20 20 20  |     1   1  1   |
00000900  20 20 20 20 20 20 20 20  31 20 4f 52 20 31 20 3d  |        1 OR 1 =|
00000910  20 31 0d 0d 54 68 69 73  20 69 73 20 75 73 65 64  | 1..This is used|
00000920  20 74 6f 20 6d 61 6b 65  20 73 75 72 65 20 74 68  | to make sure th|
00000930  61 74 20 62 69 74 73 20  6f 66 20 61 20 62 79 74  |at bits of a byt|
00000940  65 20 61 72 65 20 73 65  74 20 28 69 2e 65 2e 0d  |e are set (i.e..|
00000950  74 68 65 20 72 65 76 65  72 73 65 20 6f 66 20 41  |the reverse of A|
00000960  4e 44 29 20 73 75 63 68  20 74 68 61 74 20 74 6f  |ND) such that to|
00000970  20 73 65 74 20 74 68 65  20 74 6f 70 20 62 69 74  | set the top bit|
00000980  20 6f 66 20 61 20 6e 75  6d 62 65 72 0d 77 65 20  | of a number.we |
00000990  64 6f 20 74 68 69 73 3a  0d 0d 20 20 20 20 20 20  |do this:..      |
000009a0  20 20 20 4c 44 41 20 6e  75 6d 62 65 72 0d 20 20  |   LDA number.  |
000009b0  20 20 20 20 20 20 20 4f  52 41 20 26 38 30 20 20  |       ORA &80  |
000009c0  20 20 20 20 20 20 20 5c  20 26 38 30 20 69 73 20  |       \ &80 is |
000009d0  31 30 30 30 30 30 30 30  20 69 6e 20 62 69 6e 61  |10000000 in bina|
000009e0  72 79 0d 0d 61 6e 64 20  74 68 65 20 74 6f 70 20  |ry..and the top |
000009f0  62 69 74 20 77 69 6c 6c  20 62 65 20 73 65 74 20  |bit will be set |
00000a00  61 6e 64 20 74 68 65 20  72 65 73 74 20 77 69 6c  |and the rest wil|
00000a10  6c 20 72 65 6d 61 69 6e  0d 75 6e 63 68 61 6e 67  |l remain.unchang|
00000a20  65 64 2e 0d 0d 54 68 65  20 66 69 6e 61 6c 20 6f  |ed...The final o|
00000a30  70 65 72 61 74 6f 72 20  69 73 20 74 68 65 20 45  |perator is the E|
00000a40  78 63 6c 75 73 69 76 65  20 4f 52 2c 20 61 6e 64  |xclusive OR, and|
00000a50  20 45 4f 52 20 69 73 20  74 68 65 0d 6d 6e 65 6d  | EOR is the.mnem|
00000a60  6f 6e 69 63 2e 20 20 48  65 72 65 20 61 20 62 69  |onic.  Here a bi|
00000a70  74 20 69 6e 20 74 68 65  20 72 65 73 75 6c 74 20  |t in the result |
00000a80  69 73 20 73 65 74 20 69  66 20 74 68 61 74 20 62  |is set if that b|
00000a90  69 74 20 69 73 0d 73 65  74 20 69 6e 20 65 69 74  |it is.set in eit|
00000aa0  68 65 72 2c 20 62 75 74  20 6e 6f 74 20 62 6f 74  |her, but not bot|
00000ab0  68 2c 20 6f 66 20 74 68  65 20 6f 74 68 65 72 20  |h, of the other |
00000ac0  62 79 74 65 73 2e 0d 0d  20 20 20 20 20 20 20 20  |bytes...        |
00000ad0  20 20 20 20 20 20 20 20  20 20 20 30 20 20 31 20  |           0  1 |
00000ae0  20 20 20 20 20 20 20 20  20 20 30 20 45 4f 52 20  |          0 EOR |
00000af0  30 20 3d 20 30 0d 20 20  20 20 20 20 20 20 20 20  |0 = 0.          |
00000b00  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000b10  20 20 20 20 20 20 20 20  31 20 45 4f 52 20 30 20  |        1 EOR 0 |
00000b20  3d 20 31 0d 20 20 20 20  20 20 20 20 20 20 20 20  |= 1.            |
00000b30  20 20 20 30 20 20 20 30  20 20 31 20 20 20 20 20  |   0   0  1     |
00000b40  20 20 20 20 20 20 30 20  45 4f 52 20 31 20 3d 20  |      0 EOR 1 = |
00000b50  31 0d 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |1.              |
00000b60  20 31 20 20 20 31 20 20  30 20 20 20 20 20 20 20  | 1   1  0       |
00000b70  20 20 20 20 31 20 45 4f  52 20 31 20 3d 20 30 0d  |    1 EOR 1 = 0.|
00000b80  0d 57 69 74 68 20 74 68  69 73 20 79 6f 75 20 63  |.With this you c|
00000b90  61 6e 20 72 65 76 65 72  73 65 20 74 68 65 20 73  |an reverse the s|
00000ba0  74 61 74 75 73 20 6f 66  20 61 20 66 6c 61 67 20  |tatus of a flag |
00000bb0  77 69 74 68 6f 75 74 0d  6b 6e 6f 77 69 6e 67 20  |without.knowing |
00000bc0  74 68 61 74 20 73 74 61  74 75 73 20 62 65 66 6f  |that status befo|
00000bd0  72 65 68 61 6e 64 2e 20  20 49 20 63 61 6c 6c 20  |rehand.  I call |
00000be0  69 74 20 66 6c 61 67 20  77 61 76 69 6e 67 20 77  |it flag waving w|
00000bf0  69 74 68 0d 45 4f 52 20  28 61 70 6f 6c 6f 67 69  |ith.EOR (apologi|
00000c00  65 73 20 74 6f 20 41 20  41 20 4d 69 6c 6e 65 29  |es to A A Milne)|
00000c10  2e 20 20 4c 65 74 27 73  20 73 61 79 20 79 6f 75  |.  Let's say you|
00000c20  20 68 61 76 65 20 62 69  74 20 30 20 6f 66 20 61  | have bit 0 of a|
00000c30  0d 6e 75 6d 62 65 72 20  61 73 20 61 20 66 6c 61  |.number as a fla|
00000c40  67 20 61 6e 64 20 79 6f  75 20 77 61 6e 74 20 74  |g and you want t|
00000c50  6f 20 72 65 76 65 72 73  65 20 69 74 2c 20 74 68  |o reverse it, th|
00000c60  65 6e 20 79 6f 75 20 64  6f 0d 74 68 69 73 2e 0d  |en you do.this..|
00000c70  0d 20 20 20 20 20 20 20  20 20 4c 44 41 20 6e 75  |.         LDA nu|
00000c80  6d 62 65 72 0d 20 20 20  20 20 20 20 20 20 45 4f  |mber.         EO|
00000c90  52 20 31 20 20 20 20 20  20 20 20 20 20 20 5c 20  |R 1           \ |
00000ca0  31 20 69 73 2c 20 6f 66  20 63 6f 75 72 73 65 2c  |1 is, of course,|
00000cb0  20 30 30 30 30 30 30 30  31 0d 0d 0d 45 4f 52 69  | 00000001...EORi|
00000cc0  6e 67 20 61 20 6e 75 6d  62 65 72 20 77 69 74 68  |ng a number with|
00000cd0  20 69 74 73 65 6c 66 20  61 6c 77 61 79 73 20 70  | itself always p|
00000ce0  72 6f 64 75 63 65 73 20  7a 65 72 6f 20 61 6e 64  |roduces zero and|
00000cf0  20 45 4f 52 69 6e 67 0d  77 69 74 68 20 26 46 46  | EORing.with &FF|
00000d00  20 72 65 76 65 72 73 65  73 20 74 68 65 20 73 65  | reverses the se|
00000d10  74 74 69 6e 67 73 20 6f  66 20 61 6c 6c 20 62 69  |ttings of all bi|
00000d20  74 73 2c 20 70 72 6f 64  75 63 69 6e 67 20 61 20  |ts, producing a |
00000d30  6f 6e 65 73 0d 63 6f 6d  70 6c 65 6d 65 6e 74 20  |ones.complement |
00000d40  6e 65 67 61 74 69 76 65  2e 20 20 41 20 6e 65 61  |negative.  A nea|
00000d50  74 20 77 61 79 20 74 6f  20 70 72 6f 64 75 63 65  |t way to produce|
00000d60  20 74 68 65 20 6e 65 67  61 74 69 76 65 20 6f 66  | the negative of|
00000d70  0d 61 20 62 79 74 65 20  69 73 20 74 6f 20 45 4f  |.a byte is to EO|
00000d80  52 20 69 74 20 77 69 74  68 20 26 46 46 20 28 32  |R it with &FF (2|
00000d90  35 35 29 20 61 6e 64 20  74 68 65 6e 20 61 64 64  |55) and then add|
00000da0  20 6f 6e 65 2e 20 20 43  68 65 63 6b 0d 62 61 63  | one.  Check.bac|
00000db0  6b 20 74 6f 20 6d 6f 64  75 6c 65 20 32 20 74 6f  |k to module 2 to|
00000dc0  20 73 65 65 20 77 68 79  20 69 74 20 77 6f 72 6b  | see why it work|
00000dd0  73 2e 0d 0d 49 74 27 73  20 61 20 73 69 6d 70 6c  |s...It's a simpl|
00000de0  65 20 6c 69 74 74 6c 65  20 70 69 65 63 65 20 6f  |e little piece o|
00000df0  66 20 63 6f 64 65 20 69  6e 20 74 68 69 73 20 6d  |f code in this m|
00000e00  6f 64 75 6c 65 2e 20 20  54 68 65 0d 41 53 43 49  |odule.  The.ASCI|
00000e10  49 20 63 6f 64 65 73 20  61 72 65 20 61 72 72 61  |I codes are arra|
00000e20  6e 67 65 64 20 73 75 63  68 20 74 68 61 74 20 74  |nged such that t|
00000e30  68 65 20 63 6f 64 65 20  66 6f 72 20 61 20 6c 65  |he code for a le|
00000e40  74 74 65 72 20 41 4e 44  0d 26 44 46 20 77 69 6c  |tter AND.&DF wil|
00000e50  6c 20 61 6c 77 61 79 73  20 70 72 6f 64 75 63 65  |l always produce|
00000e60  20 74 68 65 20 63 6f 64  65 20 66 6f 72 20 75 70  | the code for up|
00000e70  70 65 72 20 63 61 73 65  2c 20 61 6e 64 20 42 2f  |per case, and B/|
00000e80  6f 73 62 30 38 0d 64 6f  65 73 20 73 69 6d 70 6c  |osb08.does simpl|
00000e90  79 20 74 68 61 74 2e 20  20 48 6f 77 65 76 65 72  |y that.  However|
00000ea0  2c 20 62 65 69 6e 67 20  73 69 6d 70 6c 65 20 69  |, being simple i|
00000eb0  74 20 64 6f 65 73 20 6e  6f 74 20 70 72 6f 64 75  |t does not produ|
00000ec0  63 65 0d 61 20 73 61 74  69 73 66 61 63 74 6f 72  |ce.a satisfactor|
00000ed0  79 20 72 65 73 75 6c 74  20 66 6f 72 20 61 6c 6c  |y result for all|
00000ee0  20 74 68 65 20 6f 74 68  65 72 20 6b 65 79 73 20  | the other keys |
00000ef0  6f 6e 20 74 68 65 0d 6b  65 79 62 6f 61 72 64 2e  |on the.keyboard.|
00000f00  20 20 54 68 69 73 20 61  70 70 72 6f 61 63 68 20  |  This approach |
00000f10  69 73 20 6f 6e 65 20 6f  66 20 74 68 65 20 77 61  |is one of the wa|
00000f20  79 73 20 74 6f 20 6c 65  67 69 73 6c 61 74 65 0d  |ys to legislate.|
00000f30  61 67 61 69 6e 73 74 20  70 65 6f 70 6c 65 20 77  |against people w|
00000f40  68 6f 20 74 75 72 6e 20  6f 66 66 20 28 6f 72 20  |ho turn off (or |
00000f50  6f 6e 29 20 74 68 65 20  43 41 50 53 20 4c 4f 43  |on) the CAPS LOC|
00000f60  4b 20 6f 6e 20 74 68 65  69 72 0d 6d 69 63 72 6f  |K on their.micro|
00000f70  20 77 68 65 6e 20 79 6f  75 20 65 78 70 65 63 74  | when you expect|
00000f80  20 69 74 20 74 68 65 20  6f 74 68 65 72 20 77 61  | it the other wa|
00000f90  79 20 61 72 6f 75 6e 64  2e 20 20 54 68 65 20 6f  |y around.  The o|
00000fa0  74 68 65 72 0d 77 61 79  20 69 73 20 74 6f 20 75  |ther.way is to u|
00000fb0  73 65 20 4f 53 42 59 54  45 20 32 30 32 20 77 68  |se OSBYTE 202 wh|
00000fc0  69 63 68 20 73 69 6d 75  6c 61 74 65 73 20 70 72  |ich simulates pr|
00000fd0  65 73 73 69 6e 67 20 6f  66 20 74 68 65 0d 72 65  |essing of the.re|
00000fe0  6c 65 76 61 6e 74 20 6b  65 79 73 2e 20 20 54 68  |levant keys.  Th|
00000ff0  65 20 6f 6e 6c 79 20 74  72 61 70 20 69 6e 20 74  |e only trap in t|
00001000  68 69 73 20 63 6f 64 65  20 69 73 20 74 6f 20 70  |his code is to p|
00001010  72 65 76 65 6e 74 20 61  0d 63 6f 6e 74 72 6f 6c  |revent a.control|
00001020  20 63 6f 64 65 20 73 6e  65 61 6b 69 6e 67 20 74  | code sneaking t|
00001030  68 72 6f 75 67 68 20 77  69 74 68 6f 75 74 20 79  |hrough without y|
00001040  6f 75 20 65 78 70 65 63  74 69 6e 67 20 69 74 2e  |ou expecting it.|
00001050  0d 0d 49 6e 20 74 68 65  20 6e 65 78 74 20 6d 6f  |..In the next mo|
00001060  64 75 6c 65 20 49 27 6c  6c 20 67 69 76 65 20 79  |dule I'll give y|
00001070  6f 75 20 73 6f 6d 65 20  69 6e 66 6f 72 6d 61 74  |ou some informat|
00001080  69 6f 6e 20 61 62 6f 75  74 20 74 68 65 0d 6f 74  |ion about the.ot|
00001090  68 65 72 20 6f 70 65 72  61 74 69 6e 67 20 73 79  |her operating sy|
000010a0  73 74 65 6d 20 72 6f 75  74 69 6e 65 73 20 69 6e  |stem routines in|
000010b0  20 74 68 65 20 42 42 43  20 4d 69 63 72 6f 20 74  | the BBC Micro t|
000010c0  6f 20 64 6f 20 77 69 74  68 0d 66 69 6c 65 20 68  |o do with.file h|
000010d0  61 6e 64 6c 69 6e 67 20  61 6e 64 20 74 68 65 20  |andling and the |
000010e0  6c 69 6b 65 2c 20 61 6e  64 20 77 65 27 6c 6c 20  |like, and we'll |
000010f0  75 73 65 20 6f 6e 65 20  6f 66 20 74 68 65 6d 20  |use one of them |
00001100  74 6f 0d 70 72 69 6e 74  20 6f 75 74 20 61 20 6c  |to.print out a l|
00001110  69 73 74 20 6f 66 20 74  68 65 20 52 4f 4d 53 20  |ist of the ROMS |
00001120  69 6e 20 79 6f 75 72 20  6d 61 63 68 69 6e 65 2e  |in your machine.|
00001130  0d 0d 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 2e  |................|
00001140  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 2e 2e  |................|
*
00001160  2e 2e 2e 2e 2e 2e 2e 2e  2e 2e 2e 2e 2e 2e 0d 0d  |................|
00001170  50 53 3a 20 20 54 68 61  6e 6b 20 79 6f 75 20 66  |PS:  Thank you f|
00001180  6f 72 20 79 6f 75 72 20  66 65 65 64 62 61 63 6b  |or your feedback|
00001190  2e 20 20 49 27 6d 20 70  61 72 74 69 63 75 6c 61  |.  I'm particula|
000011a0  72 6c 79 20 67 72 61 74  65 66 75 6c 0d 74 6f 20  |rly grateful.to |
000011b0  50 65 74 65 72 20 56 69  6e 63 65 20 66 6f 72 20  |Peter Vince for |
000011c0  68 69 73 20 63 6f 6e 73  74 72 75 63 74 69 76 65  |his constructive|
000011d0  20 63 72 69 74 69 63 69  73 6d 20 61 6e 64 20 73  | criticism and s|
000011e0  70 65 6c 6c 69 6e 67 0d  63 68 65 63 6b 65 72 20  |pelling.checker |
000011f0  61 6e 64 20 49 20 68 6f  70 65 20 74 68 61 74 20  |and I hope that |
00001200  6d 79 20 6f 64 64 20 74  79 70 6f 20 61 6e 64 20  |my odd typo and |
00001210  28 72 61 72 65 21 29 20  62 72 61 69 6e 20 63 6c  |(rare!) brain cl|
00001220  6f 67 0d 68 61 76 65 20  6e 6f 74 20 63 6f 6e 66  |og.have not conf|
00001230  75 73 65 64 20 79 6f 75  2e 0d                    |used you..|
0000123a
11_12_87/T\OSB08.m0
11_12_87/T\OSB08.m1
11_12_87/T\OSB08.m2
11_12_87/T\OSB08.m4
11_12_87/T\OSB08.m5