Welcome to the Apple II Simulator!

This file describes a way, how to download rom and disk images from an AppleII.

Needed equipment:
	A Unix machine (or a MS-DOSe or an Atari ST or ...)
	An AppleII
	A Disk Drive
	A serial card (i used a Super Serial Card from Apple Inc.)
	A null modem cable

Getting the ROMs:
	Connect the Apple to a serial line of your Unix machine
	(or your MS-DOSe or your Atari ST) via null modem cable.
	Adjust baud rate, stop bits etc. etc. etc.
	Make sure, you can recieve text from your Apple.
	
	On Unix, type 'cat /dev/ttya'. On MS-DOSe or Atari ST,
	run your favourite terminal program (like kermit, uniterm etc.)

	On the Apple, type PR#2 (if you have the serial card in slot 2)
	and all following keystrokes should go to the other side.

	Unix only: interrupt the cat-command.

	Type PR#0

	On Unix, type now 'cat -u /dev/ttya >download'.
	On MS-DOSe or Atari ST, tell your favourite terminal program
	to begin download.

	On the Apple, type the following:
		PR#2:CALL-151
		D000.FFFF
		C600.C6FF
		3D0G
		PR#0

	On Unix, send a 'kill -HUP' to the cat process.
	On MS-DOSe or Atari ST, tell your favourite terminal program
	to stop download.

	Now you should have a file (name it 'download') containing the
	apple rom image in hex.

	It should look like this:
		*D000.FFFF

		D000- 6F D8 65 D7 F8 DC 94 D9
		D008- B1 DB 30 F3 D8 DF E1 DB
		:	:	:	:
		:	:	:	:
		FFF8- F5 03 FB 03 62 FA 40 FA
		*C600.C6FF

		C600- A2 20 A0 00 A2 03 86 3C
		:	:	:	:
		:	:	:	:
		C6F8- 4C 01 08 00 00 00 00 00
		*3D0G

		]PR#0

	Now, please type in (or cut and paste) this little program:

-------------------8<------------------8<-----------------8<------------
#include <stdio.h>

main()
{
        FILE *f;
        char buf[256];
        unsigned char mem[65536];
        int adr,i;
        char hi,lo;
        int ret;

        f=fopen("download","r");

        fgets(buf,256,f);
        while (!feof(f))
        {
                ret=sscanf(buf,"%4x-",&adr);
                if (ret==1)
                        for (i=0;i<8;i++)
                        {
                                hi=buf[6+3*i];
                                if (hi<='9') hi=hi-'0'; else hi=10+hi-'A';
                                lo=buf[7+3*i];
                                if (lo<='9') lo=lo-'0'; else lo=10+lo-'A';
                                mem[adr+i]=16*hi+lo;
                        }
                fgets(buf,256,f);
        }
        fclose(f);

        f=fopen("d000.rom","w");
        fwrite(mem+0xd000,1,0x0800,f);
        fclose(f);

        f=fopen("d800.rom","w");
        fwrite(mem+0xd800,1,0x0800,f);
        fclose(f);

        f=fopen("e000.rom","w");
        fwrite(mem+0xe000,1,0x0800,f);
        fclose(f);

        f=fopen("e800.rom","w");
        fwrite(mem+0xe800,1,0x0800,f);
        fclose(f);

        f=fopen("f000.rom","w");
        fwrite(mem+0xf000,1,0x0800,f);
        fclose(f);

        f=fopen("f800.rom","w");
        fwrite(mem+0xf800,1,0x0800,f);
        fclose(f);

        f=fopen("controller.rom","w");
        fwrite(mem+0xc600,1,0x0100,f);
        fclose(f);
}
-------------------8<------------------8<-----------------8<------------

	Run it and you get the rom images.

Getting disk images:
	For disk images, a better comressed format is needed.
	The monitor output is quite easy to produce, but it's
	nearly four times the size of the raw data. This is ok for
	some (twelve) kbytes of data, but not for 140 kbytes.
	Much better is the uuencode format, which has much less overhead.
	On Unix, uudecode is standard and for MS-DOSe or Atari ST,
	get the source of uudecode from 386BSD and compile it.
	
	Let's advance: get a DOS 3.3 disk, boot your apple and type
	in the following basic program:

-------------------8<------------------8<-----------------8<------------
100  REM  UUENCODE DISK
110  HIMEM: 16384
120 AD = 16384:A0 = AD + 256
130  IF  PEEK (1013) = 76 AND  PEEK (1014) = 32 AND  PEEK (1015) = 3 THEN 160
140  PRINT  CHR$ (4)"BRUN RWTS2"
150  PRINT  CHR$ (4)"BRUN UUENCODE.BIN"
160  & A(A0,1)
170 A1 = A0
180  PR# 2
190  PRINT "BEGIN 666 DISK"
200  FOR T = 0 TO 34
210  FOR S = 0 TO 15
300  & R(T,S)
310 A2 = A0 + 256
400  IF A2 - A1 < 45 THEN 500
410  POKE 237,45
420  POKE 239,A1 / 256
430  POKE 238,A1 - 256 *  PEEK (239)
440  CALL 784
450 A1 = A1 + 45
460  GOTO 400
500  POKE 237,A2 - A1
510  POKE 239,A1 / 256
520  POKE 238,A1 - 256 *  PEEK (239)
530  CALL 787
540 A1 = A1 - 256
600  NEXT S
610  NEXT T
700  POKE 237,A2 - A1 - 256
710  POKE 239,A1 / 256
720  POKE 238,A1 - 256 *  PEEK (239)
730  CALL 784
800  PRINT " "
900  PRINT "END"
910  PR# 0
-------------------8<------------------8<-----------------8<------------

	Save it on disk with
		SAVE UUENCODE.DISK

	Enter the apple monitor (CALL -151) and type in the
	following hexdump:

-------------------8<------------------8<-----------------8<------------
0270: A9 4C 8D 13 03 8D 10 03
0278: A9 02 8D 15 03 A9 8D 8D
0280: 14 03 A9 02 8D 12 03 A9
0288: A1 8D 11 03 60 A4 ED A5
0290: EE 85 EC A5 EF 85 ED C6
0298: ED B1 EE 91 EC 88 10 F9
02A0: 60 A5 ED 20 E7 02 A0 00
02A8: C4 ED 10 36 A9 00 85 EC
02B0: B1 EE 4A 66 EC 4A 66 EC
02B8: 20 E7 02 C8 B1 EE 4A 4A
02C0: 05 EC 4A 4A 20 E7 02 B1
02C8: EE 85 EC C8 B1 EE 0A 26
02D0: EC 0A 26 EC A5 EC 20 E7
02D8: 02 B1 EE 20 E7 02 C8 4C
02E0: A8 02 A9 8D 4C ED FD 29
02E8: 3F D0 02 A9 40 18 69 A0
02F0: 4C ED FD 00 00 00 00 00
02F8: 00 00 00 00 00 00 00 00
0300: A9 4C 8D F5 03 A9 20 8D
0308: F6 03 A9 03 8D F7 03 60
0310: 04 C6 51 F0 08 CA D0 F6
0318: A6 50 4C 0B 03 60 00 4A
0320: C9 52 F0 0F C9 57 F0 0F
0328: EA EA EA EA C9 41 F0 1D
0330: 4C 7C D9 A9 01 D0 02 A9
0338: 02 85 FA 20 B5 03 20 46
0340: E7 86 FC A5 50 85 FB 20
0348: B8 DE 4C 65 03 20 B5 03
0350: 20 46 E7 8A EA EA EA EA
0358: 85 FF A5 50 85 FD A5 51
0360: 85 FE 4C B8 DE 20 E3 03
0368: 84 06 85 07 A0 01 A9 60
0370: 91 06 C8 A5 FF 91 06 C8
0378: A9 00 91 06 C8 A5 FB 91
0380: 06 C8 A5 FC 91 06 A0 08
0388: A5 FD 91 06 C8 A5 FE 91
0390: 06 A0 0C A5 FA 91 06 A0
0398: 0E A9 00 91 06 C8 A9 60
03A0: 91 06 A4 06 A5 07 20 D9
03A8: 03 A9 00 85 48 A0 0D B1
03B0: 06 85 1D 60 00 20 B1 00
03B8: 4C BB DE 29 2A 2B 00 2C
-------------------8<------------------8<-----------------8<------------

	Save it on disk with the following commands:
		BSAVE RWTS2,A$300,L$C0
		BSAVE UUENCODE.BIN,A$270,L$90

	On Unix, type cat -u /dev/ttya >disk.uue
	On MS-DOSe or Atari, you should tell your favourite terminal
	program to start download.

	On the Apple, insert a COPYAble disk and type RUN.

	After the disk stops spinning, the transfer is done.
	Interrupt the 'cat' command with 'kill -HUP' or tell
	your terminal program to stop downloading.

	Try to 'uudecode' the file. 

	Now you should have a working disk image.

Some Hints:
	This is the way, i have done it.
	I hope, you can succeed also.
	I have tested the programs. 
	If you find bugs, please send a e-mail.
	
	If your images aren't complete, check the handshake.
	I had (luckily) no problems with the Super Serial Card.

	If your uudecode says 'no begin line', edit the uuencoded
	file and change the first and the last line to lowercase.

	Because the character rom isn't accessible directly,
	i have included it.

Peter Koch (e-mail: koch@informatik.uni-kl.de)
