TO KEEP A LONG STORY SHORT This month, we are going to discuss the direct page. This will prove very useful in the future. We are going to modify our CLPSCN routine to get its data from the direct page. First of all, what is the direct page? The direct page is a page (256 bytes) or RAM which can be accessed by a single byte address. This block of RAM is pointed to by the DP register which holds the most significant byte (MSB) or the address (the first byte). The address in your instruction then will be the least significant byte (LSB) of the address (the last byte). For example, if the value in DP was $1A and your address was $AC, the actual address being accessed would be $1AAC. Unfortunately, there is no LDDP instruction so we must use a different method of changing its contents. The method generally used is to load one of the accumulators (A or B) with the new DP value and transfering it to DP via a TFR A,DP or TFR B,DP instruction. More on TFR later. The direct page can significantly shorten a long program with a large number of variables. Since only one byte is required to access an address in the direct page, each time it is addressed, it is one byte shorter than extended addressing. It is also faster since one less byte must be processed before the instructon can be executed. The uses of the Direct page are unlimited; in fact, Microsoft made extensive use of it when they programmed the BASIC interpreter. BASIC uses the page of RAM from $0000 to $00FF as its direct page (DP=$00). There are some unused bytes at the top end which we will use to simplify the programming procedure (it saves changing the DP and then restoring it after!). The thirteen bytes from $F3 to $FF are unused; we will use $FB to $FF as our parameter block; then all we have to do is drop the $7F off our extended addressing in CLPSCN. You will recall the program was something as follows: 00010 ORG $7F00 00020 CLPSCN LDX >$7FFC 00030 LDA >$7FFB 00040 LOOP STA ,X+ 00050 CMPX >$7FFE 00060 BLS LOOP 00070 RTS NOTE: direct page addressing is usually preceded by a < as opposed to a > for extended addressing. Our program would read as follows if we make the changes suggested above: 00010 ORG $7F00 00020 CLPSCN LDX <$FC 00030 LDA <$FB 00040 LOOP STA ,X+ 00050 CMPX <$FE 00060 BLS LOOP 00070 RTS Now we must assemble the program. The tables from the first article will provide the opcodes for direct page addressing. Direct page addressing are assembled as for extended addressing except the address is only one byte. The assembly appears something as follows: 7F00 00010 ORG $7F00 7F00 9E FC 00020 CLPSCN LDX <$FC 7F02 96 FB 00030 LDA <$FB 7F04 A7 80 00040 LOOP STA ,X+ 7F06 9C FE 00050 CMPX <$FE 7F08 23 FA 00060 BLS LOOP 7F0A 39 00070 RTS Note that this program is 11 bytes long while the program last month was 14 bytes long. In a longer program the memory savings could add up to thousands of bytes! You have seen the BASIC programs in past articles which load the machine code into RAM. I will now explain how to produce them. First use CLEAR to set aside the memory where your program will reside. The syntax is as follows: CLEAR #string space,(1st address of program)-1 Then in a FOR statement, use the first and last addresses of the program in the loop. READ in values from DATA statements into a string variable. Then use the statement: POKE X,VAL("&H"+A$) where X is the variable from the FOR statement and A$ is the string variable. Then you must close the loop with a NEXT statement. Afterward, include in DATA statements all values, in order, as hexadecimal values (no prefixes or suffixes). These will be READ in by the first part of the program. Try to write your own program for this month's venture. Remember to use it you must poke the values required into $FB through $FF. I will include the program I used in next month's article. Now, as promises, a note on TFR. There are two instructions which involve moving one or two bytes directly from one register to another of equal size. These are TFR (transfer) and EXG (exchange). The following is a table of registers and their 4-bit codes as used by EXG and TFR in the operand: !==================!==================! ! 8-BIT REGISTERS ! 16-BIT REGISTERS ! !==========!=======!==========!=======! ! REGISTER ! CODE ! REGISTER ! CODE ! !==========!=======!==========!=======! ! A ! 8 ! D ! 0 ! ! B ! 9 ! X ! 1 ! ! CC ! A ! Y ! 2 ! ! DP ! B ! U ! 3 ! !==========!=======! S ! 4 ! ! PC ! 5 ! !==========!=======! The first registers is contained in the first 4 bits of the operand and the second register is contained in the last 4 bits of the operand. Note in the table the hexadecimal digits are given--these will plug right into the assembly. Examples: TFR A,DP --- 1F 8B EXG Y,D --- 1E 20 There is one other odd type of instruction which will be dealt with next month: PSHS, PSHU, PULS, PULU. We will also begin dealing with indexed addressing and briefly look at 16 bit relative addressing. Good luck with the BASIC program. Until next month!