
INSIDE COMMODORE DOS I INSIDE COMMODORE DOS by Richard lmmers, Ph.D. Adrian Public Schools Adrian, Michigan and Gerald C. Neufeld, Ph.D. Brandon university Brandon, Manitoba Canada Technical Illustrations by Diane M. corralejo fflDATAMOST 19821 Nordhoff Street, Northridge, CA 91324 (818) 709-1202 [ First Printing, July 1984 Second Printing, February 1985 RESTON PUBLISHING COMPANY, INC. A Prentice-Hall Company Reston, Virginia ISBN 0-8359-3091-2 Copyright © 1984 by DATAMOST, Inc. All Rights Reserved This manual is published and copyrighted by DATAMOST, Inc. All rights are reserved by DATAMOST, Inc. Copying, duplicating, selling or otherwise distributing this pro- duct is hereby expressly forbidden except by prior written consent of DATAMOST, Inc. The words COMMODORE, CBM, COMMODORE 64, VIC-20, VIC-1541 and the Com- modore logo are registered trademarks of Commodore Business Machines, Inc. Commodore Business Machines was not in any way involved in the writing or other preparation of this manual, nor were the facts presented here reviewed for accuracy by them. The information presented in this manual is the result of intensive study of the disassembly of the 1541 DOS. Every effort has been made to provide error-free infor- mation. However, neither the authors nor DATAMOST, Inc. can accept responsibility for any loss or damage, tangible or intangible, resulting from use or improper or un- intended use of this information. Printed in U.S.A. ACKNOWLEDGEMENTS A manual like this one would not be possible without a great deal of technical assistance. Mike Todd's Disk File column in the ICPUG Newsletter proved to be an invaluable source of insight into the inner workings of Commodore's DOS. Raeto West's book, Program- ming the PET/CBM, was a constant companion. Jim Butterfield's numerous articles also provided valuable bits and pieces of information. Brad Templeton's POWER™ system and PAL™ assembler made the development of the programs in this manual a real joy. These packages are commercially available from Professional Software Inc. In addition, both the PAL disassembler and MICROMON were used as tools for disassembling the 1541 DOS. We would also like to acknowledge the patience and forebearance of our families and friends. Without their support, producing this manual would have been considerably more difficult. Mike Louder of DATAMOST, Inc. also provided tremendous support for its production. Finally, we would like to extend a special note of thanks to Dr. Tom MacNeil and Nancy Neufeld for their diligent work in proofreading this manual. This manual was written on a Commodore computer system using the WordPro 4 Plus word processing system. The WordPro Plus™ Series is commercially available from Professional Software Inc. This sophisticated word processing system made editing and last minute revisions much easier. I TABLE OF CONTENTS Chapter 1 - INTRODUCTION 11 A Brief Word About the Programs 11 How to Type in the Programs 12 Chapter 2 - USING THE 1541'S DOS 15 The Purpose of DOS 15 Communicating with the 1541 15 The Command Channel 16 Using the Command Channel 17 Diskette Housekeeping 20 Chapter 3 - DISKETTE FORMATTING 29 Layout of Tracks and Sectors 29 Layout of a Sector 31 The Header Block 32 The Data Block 33 Chapter 4 - DISKETTE ORGANIZATION 35 Information Management 35 The Directory You See 35 The Block Availablity Map 36 The Directory Entries 40 Program File Storage 48 Sequential File Storage 53 Relative File Storage 56 User File Storage 69 Deleted File Storage 69 Locked Files 70 Chapter 5 - DIRECT-ACCESS PROGRAMMING 71 Introduction to Direct-Access Programming 71 Beginning Direct-Access Programming 71 Block-Read Command 73 Buffer-Pointer Command 75 Block-Write Command 77 Memory-Read Command 81 Memory-Write Command 85 Block-Allocate Command 89 Block-Free Command 94 Memory-Execute Command 96 Block Execute Command 97 Direct-Access Entomology 98 7 Chapter 6 - INTERMEDIATE DIRECT-ACCESS PROGRAMMING 103 Chapter 7 - DOS PROTECTION 113 Commodore's Data Encoding Scheme 113 Checksums 118 Description of DOS Error Messages 119 Analyzing a Protected Diskette 122 Duplicating a Protection Scheme 123 How to Create 21 Errors on a Full Track 124 How to Create a 21 Error on a Single Sector 126 How to Create a 23 Error on a Single Sector 129 How to Duplicate a 23 Error on a Single Sector 133 How to Create 23 Errors on a Full Track 137 How to Create 20 Errors on a Full Track 144 How to Create 27 Errors on a Full Track 150 How to Create a 22 Error on a Single Sector 155 How to Duplicate a 22 Error on a Single Sector 156 How to Format a Diskette with Multiple IDs 158 How to Backup a DOS Protected Diskette 162 How to Copy a File 168 Chapter 8 - GETTING OUT OF TROUBLE 173 Unscratching a File 173 Recovering a Soft Sector 175 Recovering a Hard Sector 175 Recovering a Relative File 176 Recovering an Entire Diskette 177 Recovering a Physically Damaged Diskette 177 Recovering an Unclosed File 177 Recovering from a Short New 178 Recovering from a Full New 179 Chapter 9 - OVERVIEW OF THE 1541 DOS 181 Introduction to 1541 DOS 181 The Hard Working 6502 181 Major IP Routines 182 Using the IP Routines 185 Major FDC Routines 188 Using the FDC Routines 193 The Recording Process 199 Block Diagram of the 1541 201 Writing Data to a Diskette 202 Reading Data From a Diskette 204 Summary Bugs in DOS 2.6 206 Write Incompatability with 4040 208 Late News 215 8 Appendix A - 1541 RAM VARIABLE DEFINITIONS 217 Appendix B - ANALYSIS OF THE 1541's ROM 229 Appendix C - PROGRAM LISTINGS 437 Appendix D - MATHEMATICAL CONVERSION ROUTINES 485 Index 499 9 Ignorance is a precious thing. Once lost, it can never be regained. CHAPTER 1 INTRODUCTION This manual is intended to supplement the documentation provided in the 15^1 User's Manual. Although this manual is primarily designed to meet the needs of the in- termediate to advanced programmer, it will also be ofinterest to the novice Commodore user who wants to know more about how his 1541 disk drive works. This manual is not intended to replace the documentation provided by Commodore Business Machines, Inc. and the reader is assumed to be relatively familiar with the contents of the 15J+1 User's Manual. For the sake of continuity and clarity, some of the information covered in the 15U1 User's Manual is also presented here. However, the majority of the information presented in this manual is original and is the result of intensive disassembly and an- notation of the 1541's DOS by the authors. Some information is based on articles and notes published in a variety of publications as well as discussions with other knowledgeable disk experts. This manual was not prepared with the assistance of Commodore Business Machines, Inc. Although we cannot guarantee the accuracy of all the information presented in this manual, the material has been thoroughly researched and tested. There were several reasons for writing Inside Commodore DOS: 1. To correct errors and omissions in the 15J>1 User's Manual. 2. To help you make more effective use of your disk drive. 3. To provide complete information on diskette formatting. 4. To provide complete information on the storage of files. 5. To allow you to read and write data in non-standard ways. 6. To help you make a backup copy of your "protected" diskettes. 7. To help you recover damaged diskettes. 8. To help you understand the operation of your disk drive. Although this manual focuses primarily on the 1541 disk drive, much of the information also applies to other Commodore disk drives. 1 -1 A Brief Word About the Programs This book contains listings for 46 ready-to-use programs written in BASIC. These pro- grams are copyrighted. They may NOT be used commercially, in whole or in part, period. Since many of the programs are long, typing them all in would be a time consuming, tedious task. Feel free to share your typing efforts with a friend who has also purchased a copy of this book. In return, we simply ask that you do not share a program with some- one who does not own a legitimate copy of this book. 11 The programs in this book are disk utilities. They do not use flashy graphics or sound. Rather, they are extremely powerful tools. Remember, any tool can be dangerous if it is used improperly. Be sure that you know what you are doing before you use a given program. Always experiment with a program on a test diskette before you actually use it on one that contains valuable programs or data. Practice makes perfect. Each program was individually tested on a variety of 1541 disk drives having a wide range of serial numbers. Moreover, each program always worked perfectly. Unfortunately, it is impossible to guarantee that a particular program will work with your model. If a given program does not seem to work properly, check your typing carefully. Any er- rors, especially in the DATA statements which contain a machine language program, will produce problems. As a courtesy to the more advanced programmer, we have also included the source listings for each machine language routine. A source listing immediately follows a related BASIC program listing and has a file name ending in "PAL". It is for use with the PAL assembler. Note: Ifyou are using a different assembler, you may have to make some minor changes. The programs in this book were designed to be not only useful and beneficial, but in- structive as well. Many of them illustrate the "state of the art" in the use of Commodore's direct-access disk commands.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages512 Page
-
File Size-