THE EXTENDED FAMILY Last month, we wrote a short routine to clear the lowres text screen. We learned about immediate addressing, load instructions, store instructions, the RTS instruction, and auto-incrementing by 1. We also learned about 8-bit (1 byte) relative addressing which all Bxx instructions use. This month, we are going to study extended direct addressing and its merits. We are also going to look at position independant code versus position dependant code. Extended direct addressing uses a two byte address as the operrand. This address never changes unless we physically change the program. Most instructions have an extended direct addressing mode. I will refer to extended direct addressing as 'extended' addressing from now on. Position independant code is code which, after it is assembled, can be loaded anywhere in RAM and it will execute properly. Such a program uses all relative addressing to reference itself and extended addressing to reference external routines or I/O loactions. Position dependant code, on the other hand, must be loaded into a specific location in the RAM and uses extended addressing to reference parts of itself. Our CLRSCN routine last month was actually position independant. You can observe this by changing &H7F00 to &H7F80 and &H7F0C to &H7F8C in line 10 and running the program. Then execute at &H7F80. We could put it at any location (except in the BASIC interpreter (&8000 on), for example, $3F11 or $1234 or $7A1E. We are going to write a more useful routine this month: we are going to modify our porgram to clear only part of the screen. You will recall the code for our CLRSCN routine looked something as follows: 00010 ORG $7F00 00020 CLRSCN LDX #$400 00030 LDA #$60 00040 LOOP STA ,X+ 00050 CMPX #$5FF 00060 BLS LOOP 00070 RTS Since we will want to get parameters from BASIC, we must find some method of passing them to our routine. One method is to use a parameter block at $7FFB organized as follows: $7FFB fill character (the character you want the screen cleared to) $7FFC beginning address (2 bytes) $7FFE ending address (2 bytes) We will use extended addressing to access these parameters from our routine which we'll call CLPSCN (CLear Part SCreeN). We'll use POKE to get parameters to this memory block from the BASIC program. The assembly routine would then look as follows, if we use last month's flow chart: 00010 ORG $7F00 00020 CLPSCN LDX >$7FFC 00030 LDA >$7FFB 00040 LOOP STA ,X+ 00050 CMPX >$7FFE 00060 BLS LOOP 00070 RTS Extended addressing can be preceeded by a > to force the mode. It is generally useful to use the > anyway, since it relieves confusion when looking at a listing at a later date. Our program is still relocatable; you'll notice that the program itself uses relative addressing while using extended addressing to reach the parameter block (IO). To assemble extended addressing, you look up to code in the charts from the first article and follow it by the address after the > expanded to two bytes (add 0s to the beginning until it is four hexadecimal digits long). The assembly would look as follows if we use the procedure from before for the rest of the program: 7F00 00010 ORG $7F00 7F00 BE 7FFC 00020 CLPSCN LDX >$7FFC 7F03 B6 7FFB 00030 LDA >$7FFB 7F06 A7 80 00040 LOOP STA ,X+ 7F08 BC 7FFC 00050 CMPX >$7FFE 7F0B 23 F8 00060 BLS LOOP 7F0D 39 00070 RTS This program is 1 byte longer than CLRSCN but is far more versatile. The following can be used at the beginning of a BASIC program to use it on the 32 column screen: 10 CLEAR200,&H7EFF:FORX=&H7F00 TO&H7F0D:READA$:POKEX,VAL("& H"+A$):NEXTX:DATABE,7F,FC,B7,7F,FB,A7,80,BC,7F,FE,23,F8,39 Just poke the code for the character (some experimentation may be necessary) into $7FFB. For the beginning and ending addresses, add 1024 to the PRINT@ address. Use INT(X/256) for the first byte and X-256*INT(X/256) for the second byte where X is the address. Have fun experimenting with this routine. Next month we will examine direct page addressing and its applications.