Classic Computer Magazine Archive COMPUTE! ISSUE 74 / JULY 1986 / PAGE 10

Readers Feedback

The Editors and Readers of COMPUTE!

If you have any questions, comments, or suggestions you would like to see addressed in this column, write to "Readers' Feedback," COMPUTE!, P.O. Box 5406, Greensboro, NC 27403. Due to the volume of mail we receive, we regret that we cannot provide personal answers to technical questions.

Apple RESET Vectoring

Is there any way to make the Apple II jump to a specific machine language subroutine after the RESET key has been hit?

Jose A. Colon Olivo

This can done by changing the two-byte RESET vector at location 1010 ($03F2). The most direct way to alter the vector is to POKE the starting address of your machine language program into locations 101 01011 in low byte/high byte format, then update these pointers with CALL 1169 When you hit RESET, the Apple checks the vector, goes to the indicated location, and runs your program. As an example, suppose you wish to execute the following routine which prints an A on the screen upon RESET:

0300 LDA #$C1
0302 JSR $FDFO
0305 JMP $03D0

The first step is to determine the high and low bytes of the starting address in decimal. The hexadecimal number $0300 is expressed as decimal 768. So, the high and low bytes of the starting address are:

HI=INT(768/256)= 3

Next, POKE the address values in 1010 and 1011, and execute the CALL to update the pointers:

POKE 1010,10
POKE 1011,HI
CALL -1169

When you hit RESET, the routine executes. Notice that the ML routine ends with JMP $03D0. Because the routine is jumped to directly, it leaves no return address on the microprocessor's stack. If it had ended with an RTS, you'd wind up back in the machine language monitor after it's done. To avoid this unwanted result, you must exit with a JMP to the BASIC soft reentry point at $03D0.

The same technique can be used to make the computer run a BASIC program when RESET is hit. Simply POKE the location of the Applesoft RUN routine into the RESET vector and call the ML from the first line of a BASIC program (for instance, with CALL -768). This could be done with the following program line:

10 POKE 1010,102: POKE 1011,213: CALL -1169

In this case, you'd want to return to BASIC by ending the ML routine with RTS rather than JMP $03D0.