Article 10868 of comp.sys.apple2.programmer: Path: news1.icaen!news.uiowa.edu!news.physics.uiowa.edu!hammer.uoregon.edu!logbridge.uoregon.edu!newsfeed.berkeley.edu!cyclone.swbell.net!typhoon01.swbell.net.POSTED!not-for-mail Message-ID: <37D258CF.F8264C02@swbell.net> From: Rubywand Reply-To: rubywand@swbell.net X-Mailer: Mozilla 4.6 [en] (Win95; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.sys.apple2.programmer Subject: Re: Programming on an Apple ][e References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 352 Date: Sun, 05 Sep 1999 06:49:35 -0500 NNTP-Posting-Host: 207.193.9.199 X-Complaints-To: abuse@swbell.net X-Trace: typhoon01.swbell.net 936532216 207.193.9.199 (Sun, 05 Sep 1999 04:50:16 PDT) NNTP-Posting-Date: Sun, 05 Sep 1999 04:50:16 PDT Organization: SBC Internet Services Xref: news1.icaen comp.sys.apple2.programmer:10868 Scott Smith writes ... > > I just acquired an Apple ][e and wanted to find some good resources for > programming machine language instructions with it (I'm primarily an x86 > person and some of the instructions are confusing me). There are several good places on the net to find out about programming and to get programming software: Apple Cabi.net- Florida ftp://24.96.48.134:6502/Cabi_Archives/FAQs.and.INFO/LanguagesAndProgramming/ ftp://24.96.48.134:6502/Cabi_Archives/Languages.Programming/ Apple II Lessons & Software (Applesoft) http://www.iglou.com/qwerty/kb/dlfiles.html Apple II Programmer's Archive http://net-24-42.dhcp.mcw.edu/a2pa.html (relocating;may be down) ACN Florida mirror ftp://24.96.48.134:6502/Cabi_Archives/Languages.Programming/A2.Programmer%27s.Archive/ Apple II Textfiles (good for PEEKs & POKEs and monitor subroutine lists) http://www.textfiles.com/apple/ Ground ftp://ground.ecn.uiowa.edu/2/apple2/MiscInfo/Applesoft/ ftp://ground.ecn.uiowa.edu/apple2/MiscInfo/Programming/ ftp://ground.ecn.uiowa.edu/2/apple2/apple8/Beagle.Oldies/ ftp://ground.ecn.uiowa.edu/apple2/MiscInfo/ Home of the Apple II http://www.educate.net.au/~apple2/ http://www.xs4all.nl/~fjkraan/comp/apple2faq/ Niel Parker's Home Page- Apple IIgs Progamming information http://axis.llx.com/~nparker/a2/ SoWhat Software http://www.sowhatsoftware.com/home.html Texas II- Appleworks products, Y2k patches, and information; home site for the Apple II Mail Group (A2MG) http://members.aol.com/A2MG/ Apple II DOS and ProDOS mini manual http://home.swbell.net/rubywand/Csa2DOSMM.html Apple II game authoring links http://home.swbell.net/rubywand/A2FAQs7GAMESITES.html#004 More Apple II links http://home.swbell.net/rubywand/A2FAQs4MAJORSITES.html "A2Pro" forum- programming information & lessons http://forums.delphi.com/a2pro The comp.sys.apple2.programmer USENET newsgroup The comp.sys.apple2 USENET newsgroup Some machine language stuff to look for ... Assembly Lines: The Book by Wagner Beagle Bros "Peeks, Pokes, and Pointers" (poster) Programming the 65816 Including the 6502, 65C02, and 65802 by David Eyes and Ron Lichty 65816/65802 Assembly Language Programming by Fischer What's Where in the Apple II? by William F. Luebbert > Also, I want to > know a way out of the register view (?) (whatever that's called when you > type '&' after booting the system) once you've entered into it. Any help > is greatly appreciated as there seems to be virtually no support for these > beasts on the net as far as I can tell! A pretty good starting point is he Apple II FAQS. You can find them in various formats on several sites. One website with the current version is http://home.swbell.net/rubywand/A2FAQs1START.html Just typing in & [Return] at the Applesoft BASIC prompt ("]") executes a direct jump to address $3F5. Usually, there is just a JMP instruction there which sends you back to the Applesoft prompt. Some programs use the & vector to jump to machine language routines which then parse stuff following the & to decide what to do. The & vector is a means to create custom commands which can be executed from the Applesoft prompt and in Applesoft programs. All Apple II's include a "monitor" program in ROM. Entering CALL-151 from the BASIC prompt puts you 'in' the monitor. Here you can view and change values in key memory locations and enter machine language routines. If entering & does something special after booting, it is probably because booting loaded some program which installs a set of "ampersand commands"-- for example, some Beagle Bros software uses & commands. How you would exit back to the Applesoft prompt would depend upon the program. (ESC is a fairly common "cancel" key.) Pressing Control-Reset (press Control, then press and release Reset, then release Control) gets you out of most messy places on an Apple II. (Software can change this, though. Many commercial programs set things up so that a Reset will reboot the disk; a few programs just refresh the screen in response to a Reset.) You can enter machine code while in the Apple II monitor. All Apple II's include this program in ROM. Here is description of many monitor commands which was posted by David Empson: >> Every Apple II has a built in "System Monitor", which lets you play around with memory contents. To get into it, start in BASIC and type CALL-151. You then get an * prompt to indicate you are in the monitor. To get back to BASIC at a later point, press Control-C then return (on a line by itself). The monitor has a lot of commands and the syntax is rather cryptic. Everything is entered and displayed in hexadecimal (base 16). The simplest commands are a single letter. For example, the "I" command sets the display to inverse, and "N" sets it to normal. The next level up in complexity are commands which expect a single address parameter. The address must be entered first, followed by the command letter. In some cases, the monitor remembers the last address used, so you can continue where you left off by using the command letter by itself. An example of this is the "L" command (list) which disassembles 20 instructions. The normal usage is to enter the start address followed by an "L". After you've seen one screenful, type "L" by itself and you get another screenful continuing from the next address. e.g. E000L L The first command will list the first page of code for the Applesoft BASIC interpreter, and the second command will list the second page. You can use multiple commands on the same line, as long as you know what you are doing. If you don't mind pausing and resuming the scrolling output (use Ctrl-S to pause, any key to resume), you can do something like: E000LLLLLLL to get several pages of disassembly at once. Moving up another step are commands that accept a range of addresses. The address range is entered, with the start and end address separated by a period (fullstop), and the command letter (if any) goes on the end. The best example of this is a memory dump, which doesn't have a command letter. If you want to display a range of bytes as a hex dump, use something like this: E000.E07F The monitor displays eight bytes per line, with the address at the beginning of each line. If you don't start on a multiple of eight, then the first line will have less than eight bytes and subsequent lines will be aligned on eight byte boundaries. There are variations on the memory dump that can be used for special cases: 1. You can press return on a blank line to display the next eight bytes. 2. If you enter an address and press return, one location is displayed. 3. You can continue from the end of the previous dump to a specified address by entering a dot followed by the end address. You can also display scattered locations by entering them as separate commands. For example: E000 E003 E006 will display the three specified locations, one per line. The third layer of command complexity are the commands which expect a destination address and a source address range. The destination address goes first, then a less-than sign, then the source range (with a dot in the middle), and finally the command letter. The main example of this is a memory move ("M"): 4000<6000.7FFFM This will move 8192 (2000 hex) bytes from locations 6000 through 7FFF down to 4000. If your source and destination ranges overlap, the move will work correctly if you are moving data to a lower memory location, but if moving to a higher location you will get a repeating pattern of the data from the start of the source range. There is one major command that breaks the rules above: the "set memory" command. The general syntax for this is the start address followed by a colon, then a space-separated list of bytes to be entered into memory. If you enter more than two digits for the data bytes, only the low order two digits are used. If you are entering a lot of data, you can continue the command on subsequent lines by starting the command with a colon (no address). The rest of the command line after the colon is regarded as part of the data to be entered, unless the monitor encounters a single letter command first. For example, the following single line command will enter a short machine code program and disassemble it. The "N" command (normal) is used as a dummy command to force the data entry to terminate. 300:20 58 FC A9 C8 20 ED FD A9 E9 20 ED FD 20 8E FD 60 N 300L Having got all that out of the way, here are the major monitor commands, each given in example form. Display next line of hex dump 1000 Hex dump one location 1000.101F Hex dump a range of locations .102F Continue hex dump to specified address 1000:1 2 3 50 Set memory :51 52 53 Continue set memory 300G Go - call subroutine at specified location G Go again - call same address as last time I Inverse 300L List - disassemble 20 lines L List again - continue disassembly 1000<2000.207FM Move - copy range to destination address N Normal 1000<2000.207FV Verify - compare range to destination address There are also several commands that use control characters: Ctrl-B Cold start BASIC (avoid this) Ctrl-C Warm start BASIC Ctrl-E Display the saved CPU registers Ctrl-K Set input to specified slot (preceded by slot number) Ctrl-P Set output to specified slot (preceded by slot number) Ctrl-Y User command The Ctrl-E command also lets you set the saved CPU registers, which will be used on a subsequent G (go) command. Type Ctrl-E then a colon, followed by the data to place into the A, X and Y registers. The Ctrl-K and Ctrl-P commands should be avoided if you are running under DOS 3.3 or ProDOS, because they may cause DOS to be disconnected from the I/O. Use PR#n or IN#n instead. Ctrl-Y is an "escape hatch", which allows third-party code to hook into the monitor for this one command. On the Apple IIgs, IIc (with UniDisk ROM or later), and enhanced IIe there is also a mini-assembler which can be accessed from the monitor by typing an exclamation mark as a monitor command. While in the mini-assembler you enter lines of the form Address:Instruction, or to enter instructions in sequence, type a space then the instruction. (You must specify the address for the first instruction, or you could be writing anywhere.) Press on a blank line to get back to the monitor. e.g. starting in the monitor, type in the following: ! 1000:JSR FC58 LDA #C8 JSR FDED LDA #E9 JSR FDED JSR FD8E RTS 1000L 1000G This is the same program I gave above as an example of the set memory command, loaded at a different location. It is important to keep in mind that you can do all sorts of nasty things to the computer if you play around in the monitor and don't know where things are located in memory. The safest bet if you want to have a play would be to start the computer with no disk in the drive, then get into the monitor. Don't play around with the following memory areas at all (unless you know exactly what you are doing): 0020-004F Zero page memory area used by the monitor 0100-01FF Stack 0200-02FF Input buffer 03D0-03FF System vectors C000-C0FF I/O space. Don't even read memory in this area unless you know what you are doing. C100-C7FF I/O firmware (usually ROM on cards in slots, or emultated slots). Some I/O cards may have I/O ports in this area (but not for the IIc). C800-CFFF Bank-switched area used by I/O cards. It is safe to read this area in the IIc, but it has to be handled carefully in other machines. The following areas must be handled carefully to avoid problems: 0050-00FF Zero page memory area used by Applesoft BASIC 0400-07FF Text screen and "screen holes", which contain system data D000-FFFF ROM and bank-switched RAM ("language card"). Don't write anything into this area, especially if you are running under ProDOS. Other memory areas that you may need to be aware of: 0800-???? Applesoft BASIC programs normally go here, followed by variables 2000-3FFF Hires graphics buffer for page 1 4000-5FFF Hires graphics buffer for page 2 9600-BFFF Normally used by DOS 3.3 or ProDOS ????-95FF Normally used for strings in Applesoft BASIC The hires graphics buffers are only an issue if you need to use them. Under DOS 3.3 or ProDOS, the upper memory limit (9600) may change depending on the use of the MAXFILES command under DOS or the number of open files under ProDOS. This leaves you with the following areas that you can usually play with to your heart's content. There are _some_ exceptions, but I've covered enough for one article. 0000-001F This isn't entirely free, but is usually OK. 0300-03CF Often used for small machine code programs. 1000(ish)-7FFF(ish) The last area varies wildly depending on the size of any BASIC program and its variables. << Rubywand