TITLE Apple II, IIe and II+: Auto-Run Apple w/o DOS Article ID: 9 Created: 9/21/84 Modified: 2/25/98 -------------------------------------------------------------------------------- TOPIC Some applications require that an Apple start running an Applesoft program from power-up without human interaction. This is easy with the disk and Auto-Start ROM. Simply initilaize the diskette with the desired program in memory and the disk will boot and run it when the power comes on. But sometimes a disk drive is undesirable, especially where there is only one program to run and the cost must be kept low. So here is a way to have a card that will load and run an Applesoft program automatically on power-up in any Apple II+. -------------------------------------------------------------------------------- DISCUSSION I will assume the use of a card like the Mountain Computer ROM+ that has a 256 byte "control ROM" and room for some larger ROMs to store the Applesoft program. On the ROM+ this is a bank of up to six 2716 type EPROMs. Using EPROMs has the advantage that you can change your Applesoft program later by erasing the EPROMs and reprogramming and the disadvantages of higher cost and using more power from the Apple's power supply. The power consumption of the EPROMs won't be a problem if the Apple isn't filled with cards. The software in the control ROM is required to do five things: 1. Pretend that it's a disk controller card so that the Auto-Start ROM will execute its code. 2. Initialize Applesoft. 3. Move an image of the Applesoft program down from the ROMs into the proper area of RAM. 4. Set up the required Applesoft pointers for the end of the program. 5. RUN the program. All that's needed to convince the Auto-Start that there's a disk controller card out there is to have a ROM whose first four odd bytes match the Apple P5 or P5A PROM. If the monitor finds a ROM that matches it in slot N, it will do a jump to $CN00. The routine that does this starts at $FAA6 and is listed on page 144 of the Apple II reference manual. The first eight bytes in the control ROM will be: 24 20 24 00 24 03 24 3C Note: By having the even numbered bytes equal to $24, (BIT Page zero) when the code is executed starting at $CN00 nothing will happen until the byte after the $3C. The proper way to initialize Applesoft is to jump to $E000. Unfortunately this entry into Applesoft falls into the normal command level routine. o regain control so that the control ROM can load a program we can use the same trick that DOS uses. As soon as Applesoft reaches its command level it prints a prompt, ("]") and waits for the user to type in a command. Since all input and output in the Apple is handled through two pointers in RAM, we can divert the input routine to point back into the control ROM. This will leave several levels of subroutine on the 6502 stack but Applesoft will re-initialize the stack when we RUN the program so it doesn't matter. Now the question becomes what address to put into the pointer. The control ROM's address will change depending on which peripheral slot it's plugged into. The low byte is just the offset from the start of the ROM since the address always starts on a 256 byte boundary but the high byte could be anything from $C1 to $C7. When the Auto-Start ROM looks for a disk controller card it saves the high order byte in $7F8. So the contents of $38 and $39, the input pointer, becomes the offset which is stored at location $7F8. Then we can jump to $E000 to initialize Applesoft confident that we will regain control when it's done. For the next step a copy of the image of the application program needs to be programmed into the EPROMs. The program starts at the address pointed to by $67 and $68 and ends at the address pointed to by $AF and $B0. The contents of the end address pointer, $AF and $B0, will be inserted in the control ROM at locations $1F and $23. When control comes back through the input routine pointer, Applesoft has already initialized $67 and $68. So the next step is to move the image of the Applesoft program down to where it originally came from. How this is done will depend on the hardware of the ROM card and the length of the Applesoft program. If you use the Apple firmware card you will have to address the soft switch to select the firmware card and then address the switch again to re-select the Applesoft ROMs. With the ROMPLUS it could be as simple as using the monitor move routine, $FE2C, to move a program of less than 2 kilobytes long. There is a little more initialization to be done before the Applesoft program can be RUN. The end of program pointer mentioned earlier must be put into $69 and $6A and one more Applesoft routine must be called. Unfortunately this one also drops into Applesoft's command mode so we have to modify the input pointer again to point to a third part of the control ROM. Once this is done the final initialization can be done with a jump to $D4F2. And now the final part, we need to reset the input pointer so that the program can input normally from the keyboard and actually RUN the program. To make things easier there is a routine set by the Auto-Start ROM that will set the input pointers to the keyboard at location $FE89. Then all that's left to do is jump to $D566 which will run the program. For a bit of finesse, if we put a $80 into location $D6, the user will not be able to list the program. In fact any attempt to do any Applesoft command except LOAD from cassette will cause the program to RUN. Also, by changing the reset vectors in the Auto-Start ROM to point to the RUN routine, the program will become very difficult to stop or modify. (To change the reset vector, load memory starting at $3F2 with 66 D5 70. See page 36 and 37 of the Apple II Reference manual for more details) THE LISTING This listing is all done relative to the start of the ROM so all address are given as one byte. If you use an assembler, simply origin the code in RAM and when it is programmed into the control ROM it will work just fine. The routines are not arranged in order of execution so that the move routine will be at the end since the length of the move routine will vary with the hardware requirements. Just be sure that the three byte jump is inserted behind the move routine. * THE FIRST 4 INSTRUCTIONS LOOK LIKE A DISK BUT DON'T * DO ANYTHING * 00: 24 20 BIT $20 02: 24 00 BIT $00 04: 24 03 BIT $03 06: 24 3C BIT $3C * * THIS PART INITIALIZES APPLESOFT AND GETS CONTROL BACK * AT ENTRY2 * 08: A9 1A ENTRY1 LDA # ENTRY2 0A: 85 38 STA KSWL 0C: A5 F8 07 LDA $07F8 0F: 85 39 STA KSWH 11: 4C 00 E0 JMP COLDSTART * * RESET INPUT TO THE KEYBOARD AND RUN THE PROGRAM * 14: 20 8 1a ENRTY3 JSR SETKBD 17: 4C 66 D5 JMP RUN * * FINISH INITIALIZATION & MOVE THE PROGRAM TEXT DOWN * FROM THE ROMS * 1A: A9 14 ENTRY2 LDA # ENTRY3 1C: 85 38 STA KSWL 1E: A9 LL LDA # LENGTH-L 20: 85 69 STA LOMEML 22: A9 HH LDA # LENGTH-H 24: 85 6A STA LOMEMH INSERT YOUR MOVE ROUTINE HERE FOLLOWED BY : 4C F2 D4 JMP INIT PART 2