home *** CD-ROM | disk | FTP | other *** search
/ hackzapple.com / www.hackzapple.com.tar / www.hackzapple.com / ORG1 / M4 / GUILLARD / MAIN.HTM.orig < prev   
Text File  |  2010-10-06  |  17KB  |  201 lines

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML><HEAD><TITLE>Apple II IDE / ATA interface</TITLE>
  3. <META http-equiv=Content-Type content="text/html; charset=windows-1252">
  4. <META content="MSHTML 6.00.2900.2873" name=GENERATOR>
  5. <META content="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot" 
  6. name=Template></HEAD>
  7. <BODY vLink="#800080" link="#0000ff" 
  8. background="../../../THEMAS/M4/GUILLARD/Image2.jpg"><B><I><FONT
  9. face=Arial color="#ff0000" size="4">
  10. <P align=center>Apple II IDE/ATA interface</P></FONT></I></B><FONT face=Arial 
  11. size=2>
  12. <P align=center>StΘphane Guillard - </FONT><A 
  13. href="mailto:stephane.guillard@steria.com"><FONT face=Arial 
  14. size=2>stephane.guillard@steria.com</FONT></A></P>
  15. <P align=center><IMG height=65 
  16. src="../../../THEMAS/M4/GUILLARD/Image1.gif" width=81></P>
  17. <FONT face=Arial size=2>
  18. <P align=center> </P>
  19. </FONT>
  20. <B><FONT face=Arial size=4>
  21. <P>1 - Introduction</FONT></P></B>
  22. <FONT face=Arial size=2>
  23. <P>The Apple II is one of the finest personal computers ever made, if not the finest. I love it, and even if one of mine is something like 15 years old, I still make hardware and software projects for it (I have a basic IIe, an enhanced IIe, a IIc w/384k, a ROM1 IIgs and a ROM3 IIgs).</P>
  24. <P>I felt it lacked a hard disk, and that it would be fun to make my own hardware adapter and software, thus I designed an easy to build hardware interface. At present time, I have :</P>
  25. <UL>
  26.   <LI>Fully functional hardware adapter for 2 IDE peripherals (e.g. a HDD and a   CD-Rom reader), PIO Mode 1, running in any Apple 2 slot (tested on my IIe and   on my IIgs). 
  27.   <LI>low level software enabling initialization of devices, reading and writing   sectors from the harddrive, analysis of Master Boot Record (find partition   table), and Boot Partition Block (find a FAT16 FS in a partition).   <LI>Small and fast user commands on top of low level software, to save / load   / execute something from memory to disk, navigate in directory tree and more 
  28.   <LI>POSIX-like API (creat(), open(), read(), write() etc.) which eases creating standard unix-like utilities (like cp, rm, mv, cat, mkdir, etc.) 
  29.   <LI>Some of the utilities above.</LI></UL>
  30. <P>These routines are currently under development, at various stages of completion.</P>
  31. <P>This project is (to my knowledge) unique and different from other existing Apple II HDD interfaces by the following aspects :</P>
  32. <UL>
  33.   <LI>It is freely available : you can do it and change it on your own (as opposed to commercial products). I would love to be notified of enhancements, 
  34.   <LI>It is really cheap to build (my prototype cost under US$15 or FRF100 or EUR15), 
  35.   <LI>It enables full 16 bit transfers to/from the IDE peripherals, by use of a 2-way MSB buffer (technique inspired by a 8051 IDE interface project published in Elektor March 2001), 
  36.   <LI>On a software basis, it conforms to Microsoft FAT16 filesystem structures, so that you can mix and match files w/ PC files. Plus, user level services from my software are (will be or can easily be ported to) usable under current 
  37.   Apple II operating systems (DOS3.3, ProDOS, UCSD and CP/M). This is an original and arbitrary choice, as opposed to supporting the classical 2 x 32 MB native ProDOS volumes, because it is much more open and flexible, even if 
  38.   it will not be compatible with all ProDOS applications.</LI></UL></FONT><B><FONT 
  39. face=Arial size=4>
  40. <P>2 - Theory</P></FONT></B>
  41. <FONT face=Arial size=2>
  42. <P>The basics are :</P>
  43. <UL>
  44.   <LI>IDE / ATA is a 16 bit interface designed in the PC world. Use of it in a 8 bit environment like the Apple II requires some asynchronous dual way buffering of the MSB (upper 8 bits of the 16 bit word). I recently found in an Elektor application note (March 2001, Stefan Schwark) the idea of using 2 8 bit latches to add IDE/ATA to a 8051 microcontroller, and recycled this idea into this project (Elektor is an European electronics monthly newspaper). 
  45.   <LI>Apart from this, IDE can be very simple to implement, since PIO modes only require a processor able to tell if it is reading or writing, 4 address bits, and a few device selection and R/W bits. 
  46.   <LI>IDE / ATA standard is completely defined in an on line available document "  Working Draft 1410D - T13 - Revision 1b - 14 March 2001 Information Technology - AT Attachment with Packet Interface - 6 (ATA/ATAPI-6) ", available 
  47.  
  48. <A href="http://www.cs.ucla.edu/~kohler/class/04f-aos/ref/hardware/ATA-d1410r3a.pdf">
  49. </A>
  50.  (Nota JPL : j'ai changΘ le lien d'origine qui Θtait mort)
  51.   <LI>FAT filesystem structures are completely defined in various web documents, among which " Hardware White Paper - Designing Hardware for Microsoft« Operating Systems - Microsoft Extensible Firmware Initiative FAT32 File System   Specification - FAT: General Overview of On-Disk Format - Version 1.03, December 6, 2000 - Microsoft Corporation ", available  <A 
  52.   href="http://www.o3one.org/hwdocs/fat_fs/fatgen103.doc"><FONT face=Arial size=2>here</FONT></A> (Nota JPL : j'ai changΘ le lien d'origine qui Θtait mort) 
  53.   <LI>From the above, I have made a hardware schematics, built a prototype, developed a few 65C02 assembly code lines and voilα ! My Apple IIe has a 170 MB hard drive and a 6x CD-ROM reader !</LI>
  54. </UL></FONT>
  55. <P>Here are the interface (in slot 7) and HDD (on top of power supply, w/insulating plastic shield), in my enhanced IIe :</P>
  56. <P align=center><IMG 
  57. src="../../../THEMAS/M4/GUILLARD/proto-full.jpg"></P><FONT face=Arial 
  58. size=2>
  59. <P>Here are detailed pictures of interface and HDD, from both above and below 
  60. :</P></FONT>
  61. <P align=center><IMG src="../../../THEMAS/M4/GUILLARD/proto-top.jpg">
  62. <FONT face=Arial> <IMG src="../../../THEMAS/M4/GUILLARD/proto-bot.jpg"></FONT></P><B><FONT 
  63. face=Arial size=4>
  64. <P>3 - Hardware</P></FONT></B>
  65. <FONT face=Arial size=2><I>
  66. <P align=center>
  67. Note : all pictures below may not be very readable on your setup, but if you save them and view them separately it should be OK.
  68. </P>
  69. </I>
  70. <P>The idea behind the 2 latches is to operate them asynchronously :</P>
  71. <UL>
  72.   <LI>When I read a 16 bit word from the device, I indeed read the D0..D7 bits into the processor, and by latching logics, the other 8 D8..D15 bits get latched into a MSB "read" latch. Then, in a second read cycle at another address, I read these bits from the latch without activating the IDE device. 
  73.   <LI>When I write a 16 bit word to the device, in a first step I write the D8..D15 bits into the MSB "write" latch without activating the IDE device, then in a second write cycle at another address, I write the D0..D7 bits to the device, and by another latching logics, the MSB "write" contents gets sent to the device at the same time as the D0..D7.</LI></UL>
  74. <P>The following picture illustrates this :</P></FONT>
  75. <P><IMG alt="" src="../../../THEMAS/M4/GUILLARD/bus-principle.jpg" 
  76. align=middle></P><FONT face=Arial size=2>
  77. <P>The hardware schematics lie in two parts :</P>
  78. <UL>
  79.   <LI>Bus logic, which mainly includes the 2 8 bit latches (the LED is the IDE activity LED, common to master and slave devices) :</LI></UL>
  80. </FONT>
  81. <P align=center><IMG src="../../../THEMAS/M4/GUILLARD/schm-bus.jpg"></P>
  82. <UL>
  83. <FONT face=Arial size=2>
  84.   <LI>Glue logic, which include all selection and decoding circuits 
  85. :</LI></FONT>
  86. </UL>
  87. <P align=center><IMG 
  88. src="../../../THEMAS/M4/GUILLARD/schm-glue.jpg"></P><FONT face=Arial 
  89. size=2>
  90. <P>Please note that since the decoding logic is activated by the Device Select line from the Apple II slot, the interface is mapped as 16 bytes into the Apple address space.</P>
  91. <P>In my setup, I put the interface in slot 7, thus addresses are in the C0F0 ..C0FF range.</P>
  92. <P>The +5V and +12V DC power supply voltages for the IDE peripherals can be taken from the Apple II bus, but it is not really recommended, due to current limitations of the Apple II power supply. This is especially true if your Apple 
  93. II is loaded with boards, like mine </P></FONT><FONT face=Wingdings 
  94. size=2>J</FONT><FONT face=Arial size=2> 
  95. <P>Don't make wiring too long. Add decoupling capacitors (100 nF) between +5VDC and GND on each chip.</P>
  96. <P>All recommended pull-ups and pull-downs in the ATA specs are included in this design. It can handle 2 devices (master & slave), and supports cable select (then use a cable select-compatible IDE cable).</P>
  97. <P>Schematics mention HCT class logic chips, but any (reasonably fast) kind will suit. My prototype is based on recycled chips coming from old boards.</P><P>On the photo of my prototype, there is a 20 pin DIL empty chip holder, it was intended for spare use but not used. Total chip count is 7.</P></FONT>
  98. <B><FONT face=Arial size=4>
  99. <P>4 - Software, basics</P></FONT></B>
  100. <FONT face=Arial size=2>
  101. <P>From a low level software point of view, the IDE registers map into the board address space this way :</P></FONT>
  102. <P align=center><IMG 
  103. src="../../../THEMAS/M4/GUILLARD/sw-regs.jpg"></P><FONT face=Arial 
  104. size=2>
  105. <P>Then I have written (Procode 65C02 assembly) a low level set of </FONT><A href="../../../THEMAS/M4/GUILLARD/lwlv-src.txt">routines</A><FONT face=Arial size=2> which are able to initialize the master IDE device, inquiry it and print info, analyze its MBR and find the partitions, and tell the 4 partition information. The code is commented, thus I won't go in explanations 
  106. within this document. Here is its output with my drive (actual Apple II screen capture) :</FONT></P>
  107. <P align=center><IMG 
  108. src="../../../THEMAS/M4/GUILLARD/sw-init.jpg"></P><FONT face=Arial size=2>
  109. <P>From this base, and with the Master Boot Record and FAT structure definition, I have made an </FONT><A href="../../../THEMAS/M4/GUILLARD/LBA-CHS.xls">Excel file</A><FONT face=Arial size=2> which helps calculating the position of various important sectors (MBR, FAT, 2<SUP>nd</SUP> FAT, First Root Dir Block, First Data Block) on the disk from its geometry, and gives cylinder / head / sector numbers, like the following for my hard drive and its only 1 FAT16 partition :</FONT></P>
  110. <P align=center><IMG src="../../../THEMAS/M4/GUILLARD/sw-excel.jpg"></P><FONT face=Arial size=2>
  111. <P>In the Excel file, all values in WHITE cells can be changed according to your hard drive. MBR should ALWAYS be at CHS 0 0 1.</P>
  112. <P>The small BASIC listing included is a simple sector browser based on the assembly routines mentioned above, which will ask for a C H S location, read the 512 byte sector from the drive and display it in ASCII and HEX form. This simple program, which prompts for CHS, stores them in RAM, calls read sector routine and dump sector routine, gives the following output from my drive (3 actual Apple II screen captures) :</P></FONT>
  113. <P align=center><IMG 
  114. src="../../../THEMAS/M4/GUILLARD/sw-blocks.jpg"></P><FONT face=Arial size=2>
  115. <P>If you look at the third dumped sector (first block of the root directory of the first partition), you will recognize well-known files </FONT><FONT face=Wingdings size=2>J</FONT></P><FONT face=Arial size=2> 
  116. <P>All screen captures made through a serial cable using an Apple II super serial card and HyperTerminal on the PC.</P></FONT><B><FONT face=Arial size=4>
  117. <P>5 - Operating system software (OSS)</P></FONT><U><FONT face=Arial>
  118. <P>Introduction</P></FONT></U></B><FONT face=Arial size=2>
  119. <P>From the experience collected with the above prototype software, I went on with the idea of writing a multi layer operating environment (OSS) for the HDD :</P>
  120. <UL>
  121.   <LI>1st layer : low level routines - init device, read / write sectors 
  122.   <LI>2nd layer : disk structure analysis - master boot record -> find the partition table, boot parameter block -> find the FAT16 FS and its main structures 
  123.   <LI>3rd layer : FAT16 structure navigation - File Allocation Table itself, cluster chain alloc / free, directories, etc. 
  124.   <LI>4th layer : small and efficient user services - save / load / execute, navigate in directory tree 
  125.   <LI>5th layer : POSIX API (in a separate library) - standard unix like calls  (creat(), open(), read(), write(), lseek() etc.) 
  126.   <LI>6th layer : standard unix like utilities (rm, mv, cat, cp, mkdir etc.)</LI></UL>
  127. <P>Each layer runs on top of the previous, except 5th runs directly on top of 3rd.</P>
  128. <P>The idea is to distribute the OSS code as :</P>
  129. <UL>
  130.   <LI>a resident, ROMed module including 1st to 4th layers, 
  131.   <LI>a developer library including 5th layer, 
  132.   <LI>a set of executables including 6th layer 
  133.   <LI>a patch for DOS3.3 and ProDOS to redirect their most used commands to the  HDD OS</LI></UL></FONT><B><U><FONT face=Arial>
  134. <P>Development environment</P></FONT></U></B><FONT face=Arial size=2>
  135. <P>Experiencing assembly coding with the prototype software has proved to be very inefficient (even if it is the best path to small and fast code), so in order to develop all this quickly, I decided to code all in C, then when 
  136. everything is running, convert at least layers 1 to 4 back to assembly.</P>
  137. </FONT>
  138. <P>Thus I downloaded the CC65 6502 C compiler package from 
  139.  
  140. <A href="http://www.cc65.org/">http://www.cc65.org/</A>
  141. <FONT face=Arial size=2> (thanks Ullrich Von Bassewitz), and integrated it into Microsoft Visual C++ 6. Thus I can edit code in MSVC, compile it using CC65 (configured as an external make tool), edit errors directly in MSVC thanks to CC65 printing its errors in an MSVC style, and when all is OK, wrap the binary into an Apple II bin file (which consists in adding 2 address bytes and 2 size bytes at the beginning) using a small too lI made for this purpose.
  142. <BR><BR>
  143. Then the code is downloaded to floppy (DOS3.3, but works as well under ProDOS) on the Apple II using HyperTerminal on the PC and Kermit385 on the Apple II (Apple Super Serial Card set to 19.200 bauds and hardware handshaking).
  144. </FONT></P><B><U>
  145. <FONT face=Arial>
  146. <P>Downloads</FONT></P></U></B>
  147. <P><A href="http://s.guillard.free.fr/Apple2IDE/csrc">Here</A><FONT face=Arial size=2> you can find the source and binaries for the current snapshot of the OSS.</FONT></P><B><FONT face=Arial size=4>
  148. <P>6 - Limitations and future</P>
  149. </FONT></B><UL><FONT face=Arial size=2>
  150.   <LI>The interface won't work with modern fast IDE peripherals, for reasons which probably lie in slow bus timings on the Apple II, which almost but not completely match IDE/ATA PIO mode 1 timings. Try with the oldest drives you may find. Mine works well with a Quantum LPS170AT (170 MB) drive, and a 6x CD-ROM drive, which are the only "old" IDE peripherals I have on hand. This may get fixed if I find enough time to work on bus timings. This may be different in a II GS context (had not enough time to extensively try yet). By the way, the system works as well in the II GS as it does in the IIe. 
  151.   <LI>To get detailed operation info, please read the assembly source provided, it is not long but self documented. </LI></FONT></UL><B><FONT face=Arial 
  152. size=4>
  153. <P>7 - Version history</P></FONT></B>
  154. <TABLE cellSpacing=3 cellPadding=4 width=720 border=1>
  155.   <TBODY>
  156.   <TR>
  157.     <TD vAlign=top width="17%">
  158.       <P align=center><B><FONT face=Arial size=2>Version</FONT></B></P></TD>
  159.     <TD vAlign=top width="83%"><B><FONT face=Arial size=2>
  160.       <P align=center>Updates</FONT></B></P></TD></TR>
  161.   <TR>
  162.     <TD vAlign=top width="17%"><FONT face=Arial size=1>
  163.       <P>0.0.1 - May-02-2001</FONT></P></TD>
  164.     <TD vAlign=top width="83%"><FONT face=Arial size=1>
  165.       <P>First public delivery.</FONT></P></TD></TR>
  166.   <TR>
  167.     <TD vAlign=top width="17%"><FONT face=Arial size=1>
  168.       <P>0.0.2 - May-03-2001</FONT></P></TD>
  169.     <TD vAlign=top width="83%"><FONT face=Arial size=1>
  170.       <P>Only small adjustments over prev. Version.</FONT></P></TD></TR>
  171.   <TR>
  172.     <TD vAlign=top width="17%"><FONT face=Arial size=1>
  173.       <P>0.0.3 - May 25-2001</FONT></P></TD>
  174.     <TD vAlign=top width="83%"><FONT face=Arial size=1>
  175.       <P>Removed bug in ASM source : print A as 2 hex digits is $FDDA, not 
  176.       $FDE3.</P>
  177.       <P>Added first run of C source.</FONT></P></TD></TR>
  178.   <TR>
  179.     <TD vAlign=top width="17%"><FONT face=Arial size=1>
  180.       <P>0.0.4 - June 17-2001</FONT></P></TD>
  181.     <TD vAlign=top width="83%"><FONT face=Arial size=1>
  182.       <P>Fixed calculation in Excel file.</P>
  183.       <P>Completed POSIX API</P>
  184.       <P>Full working interactive sampler</FONT></P></TD></TR></TBODY></TABLE><B><FONT 
  185. face=Arial size=4>
  186. <P>7 - Thanks to</P>
  187. </FONT></B><UL><FONT face=Arial size=2>
  188.   <LI>My wife for her supporting many computers at home, their fans whirling late at night, my children for the love they give everyday, 
  189.   <LI>Elektor and its application note (March 2001, Stefan Schwark) for the idea of 2 way asynchronous latches, 
  190.   <LI>The ones who made the Amiga and Apple II what they are now and which I really LOVE : the perfect nerd platform ! 
  191.   <LI>Users who come up with support and enhancement ideas ! (a list will be set up here some day :-)</LI></FONT></UL><B><FONT face=Arial size=4>
  192. <P>Legalese</P></FONT></B><FONT face=Arial size=2>
  193. <P>I hope no one will find a legal issue in all this stuff, as its only purpose is have fun with open source hardware and software, experiment and share, and bring life back into an ancient but lovely computer.</P>
  194. <P>" The author of this project can not be pursued in any case à"</P>
  195. <P>" Use at your own risk à"</P>
  196. <P>" Make backups à "</P>
  197. <P>" Please if you propagate this project, do so using the original archives 
  198. à"</P>
  199. <P>" Send me back your enhancement ideas and source code à"</P>
  200. <P>" Have fun à"</P></FONT></BODY></HTML>
  201.