Home » Personal collection » Acorn ADFS disks » Electron_User_Group » EUG_55.ADF » V/+BRR1

V/+BRR1

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 » Personal collection » Acorn ADFS disks » Electron_User_Group » EUG_55.ADF
Filename: V/+BRR1
Read OK:
File size: 147F bytes
Load address: 56204556
Exec address: 52422B2E
Duplicates

There are 3 duplicate copies of this file in the archive:

File contents
                          BASIC ROM ROUTINES
                         Christopher Dewhurst

THE Basic Rom is that dark and mysterious area of memory that lies 
beyond the screen, starting at &8000 and stretching up to &BFFF. It's
the backstage department containing the machine code needed to interpret
your Basic commands. But have you ever wondered if we can use some of 
that machine code in our own programs? Have you, for instance, struggled
to write an assembler routine to print a number on the screen, when one
must surely exist somewhere in the Basic Rom? Well, wonder no more, 
because there is indeed such a routine, and in this article we'll be 
exploring that and a lot more besides.
   Before we go any further, however, a word of caution. The best 
machine code is specific machine code written for a specific job; Basic
Rom routines are general-purpose routines, and are not the answer to
everything. Having said that, if speed is not your main priority, then
the Rom routines are ideal. They make your programs smaller and smarter,
provided you use them properly - and this usually involves some fairly
tricky setting up - so listen carefully.
   I learnt a lot about the Basic Rom by exploring around it and experi-
menting with it myself. I also picked up a few tips from THE ADVANCED
BASIC ROM USER GUIDE by Colin Pharo (Cambridge Micro Centre, 1984). 
Roland Waddilove also presented a series of excellent articles on the 
subject in ELECTRON USER; if you still have these paper beauties, dig 
out the November 1988 issue for a rundown on mathematical Rom routines. 
However, I will be concentrating on routines which print numbers in hex 
or decimal, the random number generator, and printing strings of text.
   In case you're wondering, BBC Master owners won't be left out of the
discussion this time. I have done quite a bit of disassembling of the
Basic 4 Rom to find out where equivalent routines to Basic 2 reside. 
Basic 2 is the Rom fitted in the BBC B and Electron, and Basic 4 is the 
one fitted in the Master (Like the Plus 2, for some reason Basic 3
never was). When I talk about a Rom routine, I will specify both the
Basic 2 and Basic 4 addresses - together with examples and commentaries
on how to use them - so it is up to you to use the correct one depending
on which computer you have. If you experience any difficulties - or if 
you have additional hints and tips - just write in.
   Right, down to business. We must first get to know what is called the
Integer Work Area, or IWA for short. This is just a sequence of four
bytes in zero page, located at &2A-&2D. Before Basic can work on an
integer variable, be it adding a number to it or printing it out, it 
must be put into the IWA. Fortunately, life is made easier with the help
of a couple of routines which copy an integer variable, either from zero
page or from the main memory, to the IWA:

1.      Routine: Copy 4-byte integer from zero page to the IWA
        Basic 2 address: &AF56
        Basic 4 address: &AA80

        Entry: X = zero page offset at which the integer to be copied is
        located.
        Exit: IWA contains the integer.
        Ex.:    LDX #&70  \integer at &70-3
                JSR &AF56  \copy to IWA

2.      Routine: Copy 4-byte integer from memory to the IWA
        Basic 2: &B336
        Basic 4: &B1AA

        Entry: &2A/&2B contain address of the integer.
        Exit: IWA contains the integer.
        Ex.:    LDA #integer MOD 256
                STA &2A
                LDA #integer DIV 256
                STA &2B	
                JSR &B336
                ...
                .integer EQUD &12345678

There are also two routines which do the opposite of above. The one at 
&BE44 (Basic 2)/&BDC6 (Basic 4) copies the IWA to a zero-page location, 
X being set to the zero page location on entry. The routine at &B4C6 
(Basic 2)/&B347 (Basic 4) copies the IWA to a location in main memory 
whose address is held in &37/&38.

3.      Routine: Print a string
        Basic 2: &BFCF
        Basic 4: &BECF

        Entry: The string must follow the JSR &BFCF instruction, and be
        terminated by a byte of value &80 or greater.
        Ex.:    JSR &BFCF
                EQUS "Hello there.":NOP
                ...

Notice how I've used the NOP instruction to terminate the string. The
NOP opcode has a value of &EA, which satisfies the condition of being
&80 or greater. The important point to remember is that program
execution continues AFTER that NOP instruction. In machine code, every
time a JSR instruction is executed the current address is pushed onto
the stack. Basic pulls this address from the stack, stores it in zero
page locations &37/&38 and uses indirect addressing to get the bytes of
the string. By the time the string has been printed, &37/&38 contains
the address of the next instruction after the string in the program
that called the routine. The disadvantage of this routine, however, is
that while you can include control codes (to turn off the cursor for
instance) you can't print out a string of graphics characters because
they have an ASCII value of &80 or above, which, as we said, is used to
terminate the string.

This article continued in V.+BRR2. First published EUG #55.
00000000  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000010  20 20 20 20 20 20 20 20  20 20 42 41 53 49 43 20  |          BASIC |
00000020  52 4f 4d 20 52 4f 55 54  49 4e 45 53 0d 20 20 20  |ROM ROUTINES.   |
00000030  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000040  20 20 20 20 20 20 43 68  72 69 73 74 6f 70 68 65  |      Christophe|
00000050  72 20 44 65 77 68 75 72  73 74 0d 0d 54 48 45 20  |r Dewhurst..THE |
00000060  42 61 73 69 63 20 52 6f  6d 20 69 73 20 74 68 61  |Basic Rom is tha|
00000070  74 20 64 61 72 6b 20 61  6e 64 20 6d 79 73 74 65  |t dark and myste|
00000080  72 69 6f 75 73 20 61 72  65 61 20 6f 66 20 6d 65  |rious area of me|
00000090  6d 6f 72 79 20 74 68 61  74 20 6c 69 65 73 20 0d  |mory that lies .|
000000a0  62 65 79 6f 6e 64 20 74  68 65 20 73 63 72 65 65  |beyond the scree|
000000b0  6e 2c 20 73 74 61 72 74  69 6e 67 20 61 74 20 26  |n, starting at &|
000000c0  38 30 30 30 20 61 6e 64  20 73 74 72 65 74 63 68  |8000 and stretch|
000000d0  69 6e 67 20 75 70 20 74  6f 20 26 42 46 46 46 2e  |ing up to &BFFF.|
000000e0  20 49 74 27 73 0d 74 68  65 20 62 61 63 6b 73 74  | It's.the backst|
000000f0  61 67 65 20 64 65 70 61  72 74 6d 65 6e 74 20 63  |age department c|
00000100  6f 6e 74 61 69 6e 69 6e  67 20 74 68 65 20 6d 61  |ontaining the ma|
00000110  63 68 69 6e 65 20 63 6f  64 65 20 6e 65 65 64 65  |chine code neede|
00000120  64 20 74 6f 20 69 6e 74  65 72 70 72 65 74 0d 79  |d to interpret.y|
00000130  6f 75 72 20 42 61 73 69  63 20 63 6f 6d 6d 61 6e  |our Basic comman|
00000140  64 73 2e 20 42 75 74 20  68 61 76 65 20 79 6f 75  |ds. But have you|
00000150  20 65 76 65 72 20 77 6f  6e 64 65 72 65 64 20 69  | ever wondered i|
00000160  66 20 77 65 20 63 61 6e  20 75 73 65 20 73 6f 6d  |f we can use som|
00000170  65 20 6f 66 20 0d 74 68  61 74 20 6d 61 63 68 69  |e of .that machi|
00000180  6e 65 20 63 6f 64 65 20  69 6e 20 6f 75 72 20 6f  |ne code in our o|
00000190  77 6e 20 70 72 6f 67 72  61 6d 73 3f 20 48 61 76  |wn programs? Hav|
000001a0  65 20 79 6f 75 2c 20 66  6f 72 20 69 6e 73 74 61  |e you, for insta|
000001b0  6e 63 65 2c 20 73 74 72  75 67 67 6c 65 64 0d 74  |nce, struggled.t|
000001c0  6f 20 77 72 69 74 65 20  61 6e 20 61 73 73 65 6d  |o write an assem|
000001d0  62 6c 65 72 20 72 6f 75  74 69 6e 65 20 74 6f 20  |bler routine to |
000001e0  70 72 69 6e 74 20 61 20  6e 75 6d 62 65 72 20 6f  |print a number o|
000001f0  6e 20 74 68 65 20 73 63  72 65 65 6e 2c 20 77 68  |n the screen, wh|
00000200  65 6e 20 6f 6e 65 0d 6d  75 73 74 20 73 75 72 65  |en one.must sure|
00000210  6c 79 20 65 78 69 73 74  20 73 6f 6d 65 77 68 65  |ly exist somewhe|
00000220  72 65 20 69 6e 20 74 68  65 20 42 61 73 69 63 20  |re in the Basic |
00000230  52 6f 6d 3f 20 57 65 6c  6c 2c 20 77 6f 6e 64 65  |Rom? Well, wonde|
00000240  72 20 6e 6f 20 6d 6f 72  65 2c 20 0d 62 65 63 61  |r no more, .beca|
00000250  75 73 65 20 74 68 65 72  65 20 69 73 20 69 6e 64  |use there is ind|
00000260  65 65 64 20 73 75 63 68  20 61 20 72 6f 75 74 69  |eed such a routi|
00000270  6e 65 2c 20 61 6e 64 20  69 6e 20 74 68 69 73 20  |ne, and in this |
00000280  61 72 74 69 63 6c 65 20  77 65 27 6c 6c 20 62 65  |article we'll be|
00000290  20 0d 65 78 70 6c 6f 72  69 6e 67 20 74 68 61 74  | .exploring that|
000002a0  20 61 6e 64 20 61 20 6c  6f 74 20 6d 6f 72 65 20  | and a lot more |
000002b0  62 65 73 69 64 65 73 2e  0d 20 20 20 42 65 66 6f  |besides..   Befo|
000002c0  72 65 20 77 65 20 67 6f  20 61 6e 79 20 66 75 72  |re we go any fur|
000002d0  74 68 65 72 2c 20 68 6f  77 65 76 65 72 2c 20 61  |ther, however, a|
000002e0  20 77 6f 72 64 20 6f 66  20 63 61 75 74 69 6f 6e  | word of caution|
000002f0  2e 20 54 68 65 20 62 65  73 74 20 0d 6d 61 63 68  |. The best .mach|
00000300  69 6e 65 20 63 6f 64 65  20 69 73 20 73 70 65 63  |ine code is spec|
00000310  69 66 69 63 20 6d 61 63  68 69 6e 65 20 63 6f 64  |ific machine cod|
00000320  65 20 77 72 69 74 74 65  6e 20 66 6f 72 20 61 20  |e written for a |
00000330  73 70 65 63 69 66 69 63  20 6a 6f 62 3b 20 42 61  |specific job; Ba|
00000340  73 69 63 0d 52 6f 6d 20  72 6f 75 74 69 6e 65 73  |sic.Rom routines|
00000350  20 61 72 65 20 67 65 6e  65 72 61 6c 2d 70 75 72  | are general-pur|
00000360  70 6f 73 65 20 72 6f 75  74 69 6e 65 73 2c 20 61  |pose routines, a|
00000370  6e 64 20 61 72 65 20 6e  6f 74 20 74 68 65 20 61  |nd are not the a|
00000380  6e 73 77 65 72 20 74 6f  0d 65 76 65 72 79 74 68  |nswer to.everyth|
00000390  69 6e 67 2e 20 48 61 76  69 6e 67 20 73 61 69 64  |ing. Having said|
000003a0  20 74 68 61 74 2c 20 69  66 20 73 70 65 65 64 20  | that, if speed |
000003b0  69 73 20 6e 6f 74 20 79  6f 75 72 20 6d 61 69 6e  |is not your main|
000003c0  20 70 72 69 6f 72 69 74  79 2c 20 74 68 65 6e 0d  | priority, then.|
000003d0  74 68 65 20 52 6f 6d 20  72 6f 75 74 69 6e 65 73  |the Rom routines|
000003e0  20 61 72 65 20 69 64 65  61 6c 2e 20 54 68 65 79  | are ideal. They|
000003f0  20 6d 61 6b 65 20 79 6f  75 72 20 70 72 6f 67 72  | make your progr|
00000400  61 6d 73 20 73 6d 61 6c  6c 65 72 20 61 6e 64 20  |ams smaller and |
00000410  73 6d 61 72 74 65 72 2c  0d 70 72 6f 76 69 64 65  |smarter,.provide|
00000420  64 20 79 6f 75 20 75 73  65 20 74 68 65 6d 20 70  |d you use them p|
00000430  72 6f 70 65 72 6c 79 20  2d 20 61 6e 64 20 74 68  |roperly - and th|
00000440  69 73 20 75 73 75 61 6c  6c 79 20 69 6e 76 6f 6c  |is usually invol|
00000450  76 65 73 20 73 6f 6d 65  20 66 61 69 72 6c 79 0d  |ves some fairly.|
00000460  74 72 69 63 6b 79 20 73  65 74 74 69 6e 67 20 75  |tricky setting u|
00000470  70 20 2d 20 73 6f 20 6c  69 73 74 65 6e 20 63 61  |p - so listen ca|
00000480  72 65 66 75 6c 6c 79 2e  0d 20 20 20 49 20 6c 65  |refully..   I le|
00000490  61 72 6e 74 20 61 20 6c  6f 74 20 61 62 6f 75 74  |arnt a lot about|
000004a0  20 74 68 65 20 42 61 73  69 63 20 52 6f 6d 20 62  | the Basic Rom b|
000004b0  79 20 65 78 70 6c 6f 72  69 6e 67 20 61 72 6f 75  |y exploring arou|
000004c0  6e 64 20 69 74 20 61 6e  64 20 65 78 70 65 72 69  |nd it and experi|
000004d0  2d 0d 6d 65 6e 74 69 6e  67 20 77 69 74 68 20 69  |-.menting with i|
000004e0  74 20 6d 79 73 65 6c 66  2e 20 49 20 61 6c 73 6f  |t myself. I also|
000004f0  20 70 69 63 6b 65 64 20  75 70 20 61 20 66 65 77  | picked up a few|
00000500  20 74 69 70 73 20 66 72  6f 6d 20 54 48 45 20 41  | tips from THE A|
00000510  44 56 41 4e 43 45 44 0d  42 41 53 49 43 20 52 4f  |DVANCED.BASIC RO|
00000520  4d 20 55 53 45 52 20 47  55 49 44 45 20 62 79 20  |M USER GUIDE by |
00000530  43 6f 6c 69 6e 20 50 68  61 72 6f 20 28 43 61 6d  |Colin Pharo (Cam|
00000540  62 72 69 64 67 65 20 4d  69 63 72 6f 20 43 65 6e  |bridge Micro Cen|
00000550  74 72 65 2c 20 31 39 38  34 29 2e 20 0d 52 6f 6c  |tre, 1984). .Rol|
00000560  61 6e 64 20 57 61 64 64  69 6c 6f 76 65 20 61 6c  |and Waddilove al|
00000570  73 6f 20 70 72 65 73 65  6e 74 65 64 20 61 20 73  |so presented a s|
00000580  65 72 69 65 73 20 6f 66  20 65 78 63 65 6c 6c 65  |eries of excelle|
00000590  6e 74 20 61 72 74 69 63  6c 65 73 20 6f 6e 20 74  |nt articles on t|
000005a0  68 65 20 0d 73 75 62 6a  65 63 74 20 69 6e 20 45  |he .subject in E|
000005b0  4c 45 43 54 52 4f 4e 20  55 53 45 52 3b 20 69 66  |LECTRON USER; if|
000005c0  20 79 6f 75 20 73 74 69  6c 6c 20 68 61 76 65 20  | you still have |
000005d0  74 68 65 73 65 20 70 61  70 65 72 20 62 65 61 75  |these paper beau|
000005e0  74 69 65 73 2c 20 64 69  67 20 0d 6f 75 74 20 74  |ties, dig .out t|
000005f0  68 65 20 4e 6f 76 65 6d  62 65 72 20 31 39 38 38  |he November 1988|
00000600  20 69 73 73 75 65 20 66  6f 72 20 61 20 72 75 6e  | issue for a run|
00000610  64 6f 77 6e 20 6f 6e 20  6d 61 74 68 65 6d 61 74  |down on mathemat|
00000620  69 63 61 6c 20 52 6f 6d  20 72 6f 75 74 69 6e 65  |ical Rom routine|
00000630  73 2e 20 0d 48 6f 77 65  76 65 72 2c 20 49 20 77  |s. .However, I w|
00000640  69 6c 6c 20 62 65 20 63  6f 6e 63 65 6e 74 72 61  |ill be concentra|
00000650  74 69 6e 67 20 6f 6e 20  72 6f 75 74 69 6e 65 73  |ting on routines|
00000660  20 77 68 69 63 68 20 70  72 69 6e 74 20 6e 75 6d  | which print num|
00000670  62 65 72 73 20 69 6e 20  68 65 78 20 0d 6f 72 20  |bers in hex .or |
00000680  64 65 63 69 6d 61 6c 2c  20 74 68 65 20 72 61 6e  |decimal, the ran|
00000690  64 6f 6d 20 6e 75 6d 62  65 72 20 67 65 6e 65 72  |dom number gener|
000006a0  61 74 6f 72 2c 20 61 6e  64 20 70 72 69 6e 74 69  |ator, and printi|
000006b0  6e 67 20 73 74 72 69 6e  67 73 20 6f 66 20 74 65  |ng strings of te|
000006c0  78 74 2e 0d 20 20 20 49  6e 20 63 61 73 65 20 79  |xt..   In case y|
000006d0  6f 75 27 72 65 20 77 6f  6e 64 65 72 69 6e 67 2c  |ou're wondering,|
000006e0  20 42 42 43 20 4d 61 73  74 65 72 20 6f 77 6e 65  | BBC Master owne|
000006f0  72 73 20 77 6f 6e 27 74  20 62 65 20 6c 65 66 74  |rs won't be left|
00000700  20 6f 75 74 20 6f 66 20  74 68 65 0d 64 69 73 63  | out of the.disc|
00000710  75 73 73 69 6f 6e 20 74  68 69 73 20 74 69 6d 65  |ussion this time|
00000720  2e 20 49 20 68 61 76 65  20 64 6f 6e 65 20 71 75  |. I have done qu|
00000730  69 74 65 20 61 20 62 69  74 20 6f 66 20 64 69 73  |ite a bit of dis|
00000740  61 73 73 65 6d 62 6c 69  6e 67 20 6f 66 20 74 68  |assembling of th|
00000750  65 0d 42 61 73 69 63 20  34 20 52 6f 6d 20 74 6f  |e.Basic 4 Rom to|
00000760  20 66 69 6e 64 20 6f 75  74 20 77 68 65 72 65 20  | find out where |
00000770  65 71 75 69 76 61 6c 65  6e 74 20 72 6f 75 74 69  |equivalent routi|
00000780  6e 65 73 20 74 6f 20 42  61 73 69 63 20 32 20 72  |nes to Basic 2 r|
00000790  65 73 69 64 65 2e 20 0d  42 61 73 69 63 20 32 20  |eside. .Basic 2 |
000007a0  69 73 20 74 68 65 20 52  6f 6d 20 66 69 74 74 65  |is the Rom fitte|
000007b0  64 20 69 6e 20 74 68 65  20 42 42 43 20 42 20 61  |d in the BBC B a|
000007c0  6e 64 20 45 6c 65 63 74  72 6f 6e 2c 20 61 6e 64  |nd Electron, and|
000007d0  20 42 61 73 69 63 20 34  20 69 73 20 74 68 65 20  | Basic 4 is the |
000007e0  0d 6f 6e 65 20 66 69 74  74 65 64 20 69 6e 20 74  |.one fitted in t|
000007f0  68 65 20 4d 61 73 74 65  72 20 28 4c 69 6b 65 20  |he Master (Like |
00000800  74 68 65 20 50 6c 75 73  20 32 2c 20 66 6f 72 20  |the Plus 2, for |
00000810  73 6f 6d 65 20 72 65 61  73 6f 6e 20 42 61 73 69  |some reason Basi|
00000820  63 20 33 0d 6e 65 76 65  72 20 77 61 73 29 2e 20  |c 3.never was). |
00000830  57 68 65 6e 20 49 20 74  61 6c 6b 20 61 62 6f 75  |When I talk abou|
00000840  74 20 61 20 52 6f 6d 20  72 6f 75 74 69 6e 65 2c  |t a Rom routine,|
00000850  20 49 20 77 69 6c 6c 20  73 70 65 63 69 66 79 20  | I will specify |
00000860  62 6f 74 68 20 74 68 65  0d 42 61 73 69 63 20 32  |both the.Basic 2|
00000870  20 61 6e 64 20 42 61 73  69 63 20 34 20 61 64 64  | and Basic 4 add|
00000880  72 65 73 73 65 73 20 2d  20 74 6f 67 65 74 68 65  |resses - togethe|
00000890  72 20 77 69 74 68 20 65  78 61 6d 70 6c 65 73 20  |r with examples |
000008a0  61 6e 64 20 63 6f 6d 6d  65 6e 74 61 72 69 65 73  |and commentaries|
000008b0  0d 6f 6e 20 68 6f 77 20  74 6f 20 75 73 65 20 74  |.on how to use t|
000008c0  68 65 6d 20 2d 20 73 6f  20 69 74 20 69 73 20 75  |hem - so it is u|
000008d0  70 20 74 6f 20 79 6f 75  20 74 6f 20 75 73 65 20  |p to you to use |
000008e0  74 68 65 20 63 6f 72 72  65 63 74 20 6f 6e 65 20  |the correct one |
000008f0  64 65 70 65 6e 64 69 6e  67 0d 6f 6e 20 77 68 69  |depending.on whi|
00000900  63 68 20 63 6f 6d 70 75  74 65 72 20 79 6f 75 20  |ch computer you |
00000910  68 61 76 65 2e 20 49 66  20 79 6f 75 20 65 78 70  |have. If you exp|
00000920  65 72 69 65 6e 63 65 20  61 6e 79 20 64 69 66 66  |erience any diff|
00000930  69 63 75 6c 74 69 65 73  20 2d 20 6f 72 20 69 66  |iculties - or if|
00000940  20 0d 79 6f 75 20 68 61  76 65 20 61 64 64 69 74  | .you have addit|
00000950  69 6f 6e 61 6c 20 68 69  6e 74 73 20 61 6e 64 20  |ional hints and |
00000960  74 69 70 73 20 2d 20 6a  75 73 74 20 77 72 69 74  |tips - just writ|
00000970  65 20 69 6e 2e 0d 20 20  20 52 69 67 68 74 2c 20  |e in..   Right, |
00000980  64 6f 77 6e 20 74 6f 20  62 75 73 69 6e 65 73 73  |down to business|
00000990  2e 20 57 65 20 6d 75 73  74 20 66 69 72 73 74 20  |. We must first |
000009a0  67 65 74 20 74 6f 20 6b  6e 6f 77 20 77 68 61 74  |get to know what|
000009b0  20 69 73 20 63 61 6c 6c  65 64 20 74 68 65 0d 49  | is called the.I|
000009c0  6e 74 65 67 65 72 20 57  6f 72 6b 20 41 72 65 61  |nteger Work Area|
000009d0  2c 20 6f 72 20 49 57 41  20 66 6f 72 20 73 68 6f  |, or IWA for sho|
000009e0  72 74 2e 20 54 68 69 73  20 69 73 20 6a 75 73 74  |rt. This is just|
000009f0  20 61 20 73 65 71 75 65  6e 63 65 20 6f 66 20 66  | a sequence of f|
00000a00  6f 75 72 0d 62 79 74 65  73 20 69 6e 20 7a 65 72  |our.bytes in zer|
00000a10  6f 20 70 61 67 65 2c 20  6c 6f 63 61 74 65 64 20  |o page, located |
00000a20  61 74 20 26 32 41 2d 26  32 44 2e 20 42 65 66 6f  |at &2A-&2D. Befo|
00000a30  72 65 20 42 61 73 69 63  20 63 61 6e 20 77 6f 72  |re Basic can wor|
00000a40  6b 20 6f 6e 20 61 6e 0d  69 6e 74 65 67 65 72 20  |k on an.integer |
00000a50  76 61 72 69 61 62 6c 65  2c 20 62 65 20 69 74 20  |variable, be it |
00000a60  61 64 64 69 6e 67 20 61  20 6e 75 6d 62 65 72 20  |adding a number |
00000a70  74 6f 20 69 74 20 6f 72  20 70 72 69 6e 74 69 6e  |to it or printin|
00000a80  67 20 69 74 20 6f 75 74  2c 20 69 74 20 0d 6d 75  |g it out, it .mu|
00000a90  73 74 20 62 65 20 70 75  74 20 69 6e 74 6f 20 74  |st be put into t|
00000aa0  68 65 20 49 57 41 2e 20  46 6f 72 74 75 6e 61 74  |he IWA. Fortunat|
00000ab0  65 6c 79 2c 20 6c 69 66  65 20 69 73 20 6d 61 64  |ely, life is mad|
00000ac0  65 20 65 61 73 69 65 72  20 77 69 74 68 20 74 68  |e easier with th|
00000ad0  65 20 68 65 6c 70 0d 6f  66 20 61 20 63 6f 75 70  |e help.of a coup|
00000ae0  6c 65 20 6f 66 20 72 6f  75 74 69 6e 65 73 20 77  |le of routines w|
00000af0  68 69 63 68 20 63 6f 70  79 20 61 6e 20 69 6e 74  |hich copy an int|
00000b00  65 67 65 72 20 76 61 72  69 61 62 6c 65 2c 20 65  |eger variable, e|
00000b10  69 74 68 65 72 20 66 72  6f 6d 20 7a 65 72 6f 0d  |ither from zero.|
00000b20  70 61 67 65 20 6f 72 20  66 72 6f 6d 20 74 68 65  |page or from the|
00000b30  20 6d 61 69 6e 20 6d 65  6d 6f 72 79 2c 20 74 6f  | main memory, to|
00000b40  20 74 68 65 20 49 57 41  3a 0d 0d 31 2e 20 20 20  | the IWA:..1.   |
00000b50  20 20 20 52 6f 75 74 69  6e 65 3a 20 43 6f 70 79  |   Routine: Copy|
00000b60  20 34 2d 62 79 74 65 20  69 6e 74 65 67 65 72 20  | 4-byte integer |
00000b70  66 72 6f 6d 20 7a 65 72  6f 20 70 61 67 65 20 74  |from zero page t|
00000b80  6f 20 74 68 65 20 49 57  41 0d 20 20 20 20 20 20  |o the IWA.      |
00000b90  20 20 42 61 73 69 63 20  32 20 61 64 64 72 65 73  |  Basic 2 addres|
00000ba0  73 3a 20 26 41 46 35 36  0d 20 20 20 20 20 20 20  |s: &AF56.       |
00000bb0  20 42 61 73 69 63 20 34  20 61 64 64 72 65 73 73  | Basic 4 address|
00000bc0  3a 20 26 41 41 38 30 0d  0d 20 20 20 20 20 20 20  |: &AA80..       |
00000bd0  20 45 6e 74 72 79 3a 20  58 20 3d 20 7a 65 72 6f  | Entry: X = zero|
00000be0  20 70 61 67 65 20 6f 66  66 73 65 74 20 61 74 20  | page offset at |
00000bf0  77 68 69 63 68 20 74 68  65 20 69 6e 74 65 67 65  |which the intege|
00000c00  72 20 74 6f 20 62 65 20  63 6f 70 69 65 64 20 69  |r to be copied i|
00000c10  73 0d 20 20 20 20 20 20  20 20 6c 6f 63 61 74 65  |s.        locate|
00000c20  64 2e 0d 20 20 20 20 20  20 20 20 45 78 69 74 3a  |d..        Exit:|
00000c30  20 49 57 41 20 63 6f 6e  74 61 69 6e 73 20 74 68  | IWA contains th|
00000c40  65 20 69 6e 74 65 67 65  72 2e 0d 20 20 20 20 20  |e integer..     |
00000c50  20 20 20 45 78 2e 3a 20  20 20 20 4c 44 58 20 23  |   Ex.:    LDX #|
00000c60  26 37 30 20 20 5c 69 6e  74 65 67 65 72 20 61 74  |&70  \integer at|
00000c70  20 26 37 30 2d 33 0d 20  20 20 20 20 20 20 20 20  | &70-3.         |
00000c80  20 20 20 20 20 20 20 4a  53 52 20 26 41 46 35 36  |       JSR &AF56|
00000c90  20 20 5c 63 6f 70 79 20  74 6f 20 49 57 41 0d 0d  |  \copy to IWA..|
00000ca0  32 2e 20 20 20 20 20 20  52 6f 75 74 69 6e 65 3a  |2.      Routine:|
00000cb0  20 43 6f 70 79 20 34 2d  62 79 74 65 20 69 6e 74  | Copy 4-byte int|
00000cc0  65 67 65 72 20 66 72 6f  6d 20 6d 65 6d 6f 72 79  |eger from memory|
00000cd0  20 74 6f 20 74 68 65 20  49 57 41 0d 20 20 20 20  | to the IWA.    |
00000ce0  20 20 20 20 42 61 73 69  63 20 32 3a 20 26 42 33  |    Basic 2: &B3|
00000cf0  33 36 0d 20 20 20 20 20  20 20 20 42 61 73 69 63  |36.        Basic|
00000d00  20 34 3a 20 26 42 31 41  41 0d 0d 20 20 20 20 20  | 4: &B1AA..     |
00000d10  20 20 20 45 6e 74 72 79  3a 20 26 32 41 2f 26 32  |   Entry: &2A/&2|
00000d20  42 20 63 6f 6e 74 61 69  6e 20 61 64 64 72 65 73  |B contain addres|
00000d30  73 20 6f 66 20 74 68 65  20 69 6e 74 65 67 65 72  |s of the integer|
00000d40  2e 0d 20 20 20 20 20 20  20 20 45 78 69 74 3a 20  |..        Exit: |
00000d50  49 57 41 20 63 6f 6e 74  61 69 6e 73 20 74 68 65  |IWA contains the|
00000d60  20 69 6e 74 65 67 65 72  2e 0d 20 20 20 20 20 20  | integer..      |
00000d70  20 20 45 78 2e 3a 20 20  20 20 4c 44 41 20 23 69  |  Ex.:    LDA #i|
00000d80  6e 74 65 67 65 72 20 4d  4f 44 20 32 35 36 0d 20  |nteger MOD 256. |
00000d90  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 53  |               S|
00000da0  54 41 20 26 32 41 0d 20  20 20 20 20 20 20 20 20  |TA &2A.         |
00000db0  20 20 20 20 20 20 20 4c  44 41 20 23 69 6e 74 65  |       LDA #inte|
00000dc0  67 65 72 20 44 49 56 20  32 35 36 0d 20 20 20 20  |ger DIV 256.    |
00000dd0  20 20 20 20 20 20 20 20  20 20 20 20 53 54 41 20  |            STA |
00000de0  26 32 42 09 0d 20 20 20  20 20 20 20 20 20 20 20  |&2B..           |
00000df0  20 20 20 20 20 4a 53 52  20 26 42 33 33 36 0d 20  |     JSR &B336. |
00000e00  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 2e  |               .|
00000e10  2e 2e 0d 20 20 20 20 20  20 20 20 20 20 20 20 20  |...             |
00000e20  20 20 20 2e 69 6e 74 65  67 65 72 20 45 51 55 44  |   .integer EQUD|
00000e30  20 26 31 32 33 34 35 36  37 38 0d 0d 54 68 65 72  | &12345678..Ther|
00000e40  65 20 61 72 65 20 61 6c  73 6f 20 74 77 6f 20 72  |e are also two r|
00000e50  6f 75 74 69 6e 65 73 20  77 68 69 63 68 20 64 6f  |outines which do|
00000e60  20 74 68 65 20 6f 70 70  6f 73 69 74 65 20 6f 66  | the opposite of|
00000e70  20 61 62 6f 76 65 2e 20  54 68 65 20 6f 6e 65 20  | above. The one |
00000e80  61 74 20 0d 26 42 45 34  34 20 28 42 61 73 69 63  |at .&BE44 (Basic|
00000e90  20 32 29 2f 26 42 44 43  36 20 28 42 61 73 69 63  | 2)/&BDC6 (Basic|
00000ea0  20 34 29 20 63 6f 70 69  65 73 20 74 68 65 20 49  | 4) copies the I|
00000eb0  57 41 20 74 6f 20 61 20  7a 65 72 6f 2d 70 61 67  |WA to a zero-pag|
00000ec0  65 20 6c 6f 63 61 74 69  6f 6e 2c 20 0d 58 20 62  |e location, .X b|
00000ed0  65 69 6e 67 20 73 65 74  20 74 6f 20 74 68 65 20  |eing set to the |
00000ee0  7a 65 72 6f 20 70 61 67  65 20 6c 6f 63 61 74 69  |zero page locati|
00000ef0  6f 6e 20 6f 6e 20 65 6e  74 72 79 2e 20 54 68 65  |on on entry. The|
00000f00  20 72 6f 75 74 69 6e 65  20 61 74 20 26 42 34 43  | routine at &B4C|
00000f10  36 20 0d 28 42 61 73 69  63 20 32 29 2f 26 42 33  |6 .(Basic 2)/&B3|
00000f20  34 37 20 28 42 61 73 69  63 20 34 29 20 63 6f 70  |47 (Basic 4) cop|
00000f30  69 65 73 20 74 68 65 20  49 57 41 20 74 6f 20 61  |ies the IWA to a|
00000f40  20 6c 6f 63 61 74 69 6f  6e 20 69 6e 20 6d 61 69  | location in mai|
00000f50  6e 20 6d 65 6d 6f 72 79  20 0d 77 68 6f 73 65 20  |n memory .whose |
00000f60  61 64 64 72 65 73 73 20  69 73 20 68 65 6c 64 20  |address is held |
00000f70  69 6e 20 26 33 37 2f 26  33 38 2e 0d 0d 33 2e 20  |in &37/&38...3. |
00000f80  20 20 20 20 20 52 6f 75  74 69 6e 65 3a 20 50 72  |     Routine: Pr|
00000f90  69 6e 74 20 61 20 73 74  72 69 6e 67 0d 20 20 20  |int a string.   |
00000fa0  20 20 20 20 20 42 61 73  69 63 20 32 3a 20 26 42  |     Basic 2: &B|
00000fb0  46 43 46 0d 20 20 20 20  20 20 20 20 42 61 73 69  |FCF.        Basi|
00000fc0  63 20 34 3a 20 26 42 45  43 46 0d 0d 20 20 20 20  |c 4: &BECF..    |
00000fd0  20 20 20 20 45 6e 74 72  79 3a 20 54 68 65 20 73  |    Entry: The s|
00000fe0  74 72 69 6e 67 20 6d 75  73 74 20 66 6f 6c 6c 6f  |tring must follo|
00000ff0  77 20 74 68 65 20 4a 53  52 20 26 42 46 43 46 20  |w the JSR &BFCF |
00001000  69 6e 73 74 72 75 63 74  69 6f 6e 2c 20 61 6e 64  |instruction, and|
00001010  20 62 65 0d 20 20 20 20  20 20 20 20 74 65 72 6d  | be.        term|
00001020  69 6e 61 74 65 64 20 62  79 20 61 20 62 79 74 65  |inated by a byte|
00001030  20 6f 66 20 76 61 6c 75  65 20 26 38 30 20 6f 72  | of value &80 or|
00001040  20 67 72 65 61 74 65 72  2e 0d 20 20 20 20 20 20  | greater..      |
00001050  20 20 45 78 2e 3a 20 20  20 20 4a 53 52 20 26 42  |  Ex.:    JSR &B|
00001060  46 43 46 0d 20 20 20 20  20 20 20 20 20 20 20 20  |FCF.            |
00001070  20 20 20 20 45 51 55 53  20 22 48 65 6c 6c 6f 20  |    EQUS "Hello |
00001080  74 68 65 72 65 2e 22 3a  4e 4f 50 0d 20 20 20 20  |there.":NOP.    |
00001090  20 20 20 20 20 20 20 20  20 20 20 20 2e 2e 2e 0d  |            ....|
000010a0  0d 4e 6f 74 69 63 65 20  68 6f 77 20 49 27 76 65  |.Notice how I've|
000010b0  20 75 73 65 64 20 74 68  65 20 4e 4f 50 20 69 6e  | used the NOP in|
000010c0  73 74 72 75 63 74 69 6f  6e 20 74 6f 20 74 65 72  |struction to ter|
000010d0  6d 69 6e 61 74 65 20 74  68 65 20 73 74 72 69 6e  |minate the strin|
000010e0  67 2e 20 54 68 65 0d 4e  4f 50 20 6f 70 63 6f 64  |g. The.NOP opcod|
000010f0  65 20 68 61 73 20 61 20  76 61 6c 75 65 20 6f 66  |e has a value of|
00001100  20 26 45 41 2c 20 77 68  69 63 68 20 73 61 74 69  | &EA, which sati|
00001110  73 66 69 65 73 20 74 68  65 20 63 6f 6e 64 69 74  |sfies the condit|
00001120  69 6f 6e 20 6f 66 20 62  65 69 6e 67 0d 26 38 30  |ion of being.&80|
00001130  20 6f 72 20 67 72 65 61  74 65 72 2e 20 54 68 65  | or greater. The|
00001140  20 69 6d 70 6f 72 74 61  6e 74 20 70 6f 69 6e 74  | important point|
00001150  20 74 6f 20 72 65 6d 65  6d 62 65 72 20 69 73 20  | to remember is |
00001160  74 68 61 74 20 70 72 6f  67 72 61 6d 0d 65 78 65  |that program.exe|
00001170  63 75 74 69 6f 6e 20 63  6f 6e 74 69 6e 75 65 73  |cution continues|
00001180  20 41 46 54 45 52 20 74  68 61 74 20 4e 4f 50 20  | AFTER that NOP |
00001190  69 6e 73 74 72 75 63 74  69 6f 6e 2e 20 49 6e 20  |instruction. In |
000011a0  6d 61 63 68 69 6e 65 20  63 6f 64 65 2c 20 65 76  |machine code, ev|
000011b0  65 72 79 0d 74 69 6d 65  20 61 20 4a 53 52 20 69  |ery.time a JSR i|
000011c0  6e 73 74 72 75 63 74 69  6f 6e 20 69 73 20 65 78  |nstruction is ex|
000011d0  65 63 75 74 65 64 20 74  68 65 20 63 75 72 72 65  |ecuted the curre|
000011e0  6e 74 20 61 64 64 72 65  73 73 20 69 73 20 70 75  |nt address is pu|
000011f0  73 68 65 64 20 6f 6e 74  6f 0d 74 68 65 20 73 74  |shed onto.the st|
00001200  61 63 6b 2e 20 42 61 73  69 63 20 70 75 6c 6c 73  |ack. Basic pulls|
00001210  20 74 68 69 73 20 61 64  64 72 65 73 73 20 66 72  | this address fr|
00001220  6f 6d 20 74 68 65 20 73  74 61 63 6b 2c 20 73 74  |om the stack, st|
00001230  6f 72 65 73 20 69 74 20  69 6e 20 7a 65 72 6f 0d  |ores it in zero.|
00001240  70 61 67 65 20 6c 6f 63  61 74 69 6f 6e 73 20 26  |page locations &|
00001250  33 37 2f 26 33 38 20 61  6e 64 20 75 73 65 73 20  |37/&38 and uses |
00001260  69 6e 64 69 72 65 63 74  20 61 64 64 72 65 73 73  |indirect address|
00001270  69 6e 67 20 74 6f 20 67  65 74 20 74 68 65 20 62  |ing to get the b|
00001280  79 74 65 73 20 6f 66 0d  74 68 65 20 73 74 72 69  |ytes of.the stri|
00001290  6e 67 2e 20 42 79 20 74  68 65 20 74 69 6d 65 20  |ng. By the time |
000012a0  74 68 65 20 73 74 72 69  6e 67 20 68 61 73 20 62  |the string has b|
000012b0  65 65 6e 20 70 72 69 6e  74 65 64 2c 20 26 33 37  |een printed, &37|
000012c0  2f 26 33 38 20 63 6f 6e  74 61 69 6e 73 0d 74 68  |/&38 contains.th|
000012d0  65 20 61 64 64 72 65 73  73 20 6f 66 20 74 68 65  |e address of the|
000012e0  20 6e 65 78 74 20 69 6e  73 74 72 75 63 74 69 6f  | next instructio|
000012f0  6e 20 61 66 74 65 72 20  74 68 65 20 73 74 72 69  |n after the stri|
00001300  6e 67 20 69 6e 20 74 68  65 20 70 72 6f 67 72 61  |ng in the progra|
00001310  6d 0d 74 68 61 74 20 63  61 6c 6c 65 64 20 74 68  |m.that called th|
00001320  65 20 72 6f 75 74 69 6e  65 2e 20 54 68 65 20 64  |e routine. The d|
00001330  69 73 61 64 76 61 6e 74  61 67 65 20 6f 66 20 74  |isadvantage of t|
00001340  68 69 73 20 72 6f 75 74  69 6e 65 2c 20 68 6f 77  |his routine, how|
00001350  65 76 65 72 2c 20 69 73  0d 74 68 61 74 20 77 68  |ever, is.that wh|
00001360  69 6c 65 20 79 6f 75 20  63 61 6e 20 69 6e 63 6c  |ile you can incl|
00001370  75 64 65 20 63 6f 6e 74  72 6f 6c 20 63 6f 64 65  |ude control code|
00001380  73 20 28 74 6f 20 74 75  72 6e 20 6f 66 66 20 74  |s (to turn off t|
00001390  68 65 20 63 75 72 73 6f  72 20 66 6f 72 0d 69 6e  |he cursor for.in|
000013a0  73 74 61 6e 63 65 29 20  79 6f 75 20 63 61 6e 27  |stance) you can'|
000013b0  74 20 70 72 69 6e 74 20  6f 75 74 20 61 20 73 74  |t print out a st|
000013c0  72 69 6e 67 20 6f 66 20  67 72 61 70 68 69 63 73  |ring of graphics|
000013d0  20 63 68 61 72 61 63 74  65 72 73 20 62 65 63 61  | characters beca|
000013e0  75 73 65 0d 74 68 65 79  20 68 61 76 65 20 61 6e  |use.they have an|
000013f0  20 41 53 43 49 49 20 76  61 6c 75 65 20 6f 66 20  | ASCII value of |
00001400  26 38 30 20 6f 72 20 61  62 6f 76 65 2c 20 77 68  |&80 or above, wh|
00001410  69 63 68 2c 20 61 73 20  77 65 20 73 61 69 64 2c  |ich, as we said,|
00001420  20 69 73 20 75 73 65 64  20 74 6f 0d 74 65 72 6d  | is used to.term|
00001430  69 6e 61 74 65 20 74 68  65 20 73 74 72 69 6e 67  |inate the string|
00001440  2e 0d 0d 54 68 69 73 20  61 72 74 69 63 6c 65 20  |...This article |
00001450  63 6f 6e 74 69 6e 75 65  64 20 69 6e 20 56 2e 2b  |continued in V.+|
00001460  42 52 52 32 2e 20 46 69  72 73 74 20 70 75 62 6c  |BRR2. First publ|
00001470  69 73 68 65 64 20 45 55  47 20 23 35 35 2e 0d     |ished EUG #55..|
0000147f
V/+BRR1.m0
V/+BRR1.m1
V/+BRR1.m2
V/+BRR1.m4
V/+BRR1.m5