DMK-Format-Details.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. This text file describes the DMK format as it is being used in openMSX.
  2. Originally openMSX only support simple sector based formats like the
  3. generic dsk format and the xsa format (which in essence is a compressed
  4. dsk format). These formats contained a simple dump of all the data in
  5. the sectors on a 360/720KB Double Density disk.
  6. These formats however could not be used to store track info that was
  7. commonly used for copyprotecting disks. Copy protecting resorted to
  8. tricks like out of order sectors, partially formated tracks and other
  9. trickery that was made possible by customizing the actual track
  10. headers, sector headers and CRC checks that are used by the FDC (floppy
  11. disk controller) chip when reading data from a disk.
  12. When Wouter,one of the openMSX developers, started to look for a
  13. format for openMSX to store more complete (read: copy-protected)
  14. diskimages his eyes fell upon the DMK format.
  15. The DMK format was originaly created to store TRS-80 disk. Not all of
  16. the TRS-80 specifics in the DMK format apply to the MSX standard so
  17. not everything in the DMK format is implemented for the moment, nor
  18. will it probably ever be . For instance Single Density was never
  19. used on MSX, so no support for it is implemented in openMSX.
  20. The original page containing this info can be found at
  21. http://www.trs-80.com/wordpress/dsk-and-dmk-image-utilities/
  22. DMK Format Details
  23. ==================
  24. Files with a .DSK extension could be JV1, JV3, or DMK format. The DMK
  25. format is a format developed by David Keil which allows for the storing
  26. of TRS-80 disks in pure form, which would allow for the representation
  27. of copy protected disks into emulator images. The DMK format gives the
  28. ability to support any FM or MFM encoded format that is reasonably close
  29. to the IBM 3740 or IBM System 34 standards.
  30. DMK format disks are easy to discern because of its 16 byte header.
  31. Emulators made after 2005 should handle the DMK format.
  32. The DMK virtual disk format is as close to the way data on a real disk
  33. is stored as possible. There is very little added overhead and the data
  34. is easily examined and edited using PC based hex editors. The actual
  35. design is really quite simple and enables support of ALL the WD-17xx
  36. controller functions and formats. While the design is simple however the
  37. programming requirements for this format are much more extensive then
  38. for the JV1/JV3 formats.
  39. Disk header:
  40. Virtual disks have a 16 byte disk header which is initialized when the
  41. user creates a new virtual disk. This header may be modified before or
  42. after a virtual disk has been formatted to change some of its
  43. characteristics.
  44. +----------------------------------------------------------------------+
  45. | Byte 0 | If this byte is set to FFH the disk is 'write |
  46. | | protected', 00H allows writing. |
  47. |--------------+-------------------------------------------------------|
  48. | Byte 1 | Number of tracks on virtual disk. Since tracks start |
  49. | | at 0 this value will be one greater than the highest |
  50. | | track written to the disk. So a disk with 40 tracks |
  51. | | will have a value of 40 (28H) in this field after |
  52. | | formatting while the highest track written would be |
  53. | | 39. This field is updated after a track is formatted |
  54. | | if the track formatted is greater than or equal to |
  55. | | the current number of tracks. Re-formatting a disk |
  56. | | with fewer tracks will NOT reduce the number of |
  57. | | tracks on the virtual disk. Once a virtual disk has |
  58. | | allocated space for a track it will NEVER release it. |
  59. | | Formatting a virtual disk with 80 tracks then |
  60. | | re-formatting it with 40 tracks would waste space |
  61. | | just like formatting only 40 tracks on an 80 track |
  62. | | drive. The emulator and TRS-80 operating system don't |
  63. | | care. To re-format a virtual disk with fewer tracks |
  64. | | use the /I option at start-up to delete and re-create |
  65. | | the virtual disk first, then re-format to save space. |
  66. | | |
  67. | | Note: This field should NEVER be modified. Changing |
  68. | | this number will cause TRS-80 operating system disk |
  69. | | errors. (Like reading an 80 track disk in a 40 track |
  70. | | drive) |
  71. | | |
  72. |--------------+-------------------------------------------------------|
  73. | Byte 2 & 3 | This is the track length for the virtual disk. By |
  74. | | default the value is 1900H, 80H bytes more than the |
  75. | | actual track length, this gives a track length of |
  76. | | 6272 bytes. A real double density track length is |
  77. | | aprox. 6250 bytes. This is the default value when a |
  78. | | virtual disk is created. Values for other disk and |
  79. | | format types are 0CC0H for single density 5.25" |
  80. | | floppies, 14E0H for single density 8" floppies and |
  81. | | 2940H for double density 8" floppies. The max value |
  82. | | is 2940H. For normal formatting of disks the values |
  83. | | of 1900H and 2940H for 5.25" and 8" are used. The |
  84. | | emulator will write two bytes and read every second |
  85. | | byte when in single density to maintain proper |
  86. | | sector spacing, allowing mixed density disks. Setting |
  87. | | the track length must be done before a virtual disk |
  88. | | is formatted or the disk will have to be re-formatted |
  89. | | and since the space for the disk has already been |
  90. | | allocated no space will be saved. |
  91. | | |
  92. | | WARNING: Bytes are entered in reverse order (ex. |
  93. | | 2940H would be entered, byte 2=40, byte 3=29). |
  94. | | |
  95. | | Note: No modification of the track length is |
  96. | | necessary, doing so only saves space and is not |
  97. | | necessary to normal operation. The values for all |
  98. | | normal 5.25" and 8" disks are set when the virtual |
  99. | | disk is created. DON'T modify the track length unless |
  100. | | you understand these instructions completely. Nothing |
  101. | | in the PC world can be messed up by improper |
  102. | | modification but any other virtual disk mounted in |
  103. | | the emulator with an improperly modified disk could |
  104. | | have their data scrambled. |
  105. |--------------+-------------------------------------------------------|
  106. | Byte 4 | Virtual disk option flags. |
  107. | | |
  108. | | Bit 4 of this byte, if set, means this is a single |
  109. | | sided ONLY disk. This bit is set if the user selects |
  110. | | single sided during disk creation and should not |
  111. | | require modification. This flag is used only to save |
  112. | | PC hard disk space and is never required. |
  113. | | |
  114. | | Bit 6 of this byte, if set, means this disk is to be |
  115. | | single density size and the emulator will access one |
  116. | | byte instead of two when doing I/O in single density. |
  117. | | Double density can still be written to a single |
  118. | | density disk but with half the track length only 10 |
  119. | | 256 byte sectors can be written in either density. |
  120. | | Mixed density is also possible but sector timing may |
  121. | | be off so protected disks may not work, a maximum of |
  122. | | 10 256 byte sectors of mixed density can be written |
  123. | | to a single density disk. A program like "Spook |
  124. | | House" which has a mixed density track 0 with 1 SD |
  125. | | sector and 1 DD sector and the rest of the disk |
  126. | | consisting of 10 SD sectors/track will work with this |
  127. | | flag set and save half the PC hard disk space. The |
  128. | | protected disk "Super Utility + 3.0" however has 6 SD |
  129. | | and 6 DD sectors/track for a total of 12 256 byte |
  130. | | sectors/track. This disk cannot be single density. |
  131. | | |
  132. | | This bit is set if the user selects single density |
  133. | | during disk creation and should not require |
  134. | | modification. This flag is used only to save PC hard |
  135. | | disk space and is never required. |
  136. | | |
  137. | | Bit 7 of this byte, if set, means density is to be |
  138. | | ignored when accessing this disk. The disk MUST be |
  139. | | formatted in double density but the emulator will |
  140. | | then read and write the sectors in either density. |
  141. | | The emulator will access one byte instead of two when |
  142. | | doing I/O in single density. |
  143. | | |
  144. | | This flag was an early way to support mixed density |
  145. | | disks it is no longer needed for this purpose. It is |
  146. | | now used for compatibility with old virtual disks |
  147. | | created without the double byte now used when in |
  148. | | single density. This bit can be set manually in a hex |
  149. | | editor to access old virtual disks written in single |
  150. | | density. |
  151. |--------------+-------------------------------------------------------|
  152. | Byte 5-B | reserved for future options |
  153. |--------------+-------------------------------------------------------|
  154. | Byte C-F | Must be zero if virtual disk is in emulator's native |
  155. | | format. |
  156. | | |
  157. | | Must be 12345678h if virtual disk is a REAL disk |
  158. | | specification file used to access REAL TRS-80 |
  159. | | floppies in compatible PC drives. |
  160. |--------------+-------------------------------------------------------|
  161. | Track Header | Each track has a 128 (80H) byte header which contains |
  162. | | an offset to each IDAM in the track. This is created |
  163. | | during format and should NEVER require modification. |
  164. | | The actual track data follows this header and can be |
  165. | | viewed with a hex editor showing the raw data on the |
  166. | | track. Modification should not be done as each IDAM |
  167. | | and sector has a CRC, this is just like a real disk, |
  168. | | and modifying the sector data without updating the |
  169. | | CRC value will cause CRC errors when accessing the |
  170. | | virtual disk within the emulator. |
  171. | | |
  172. | | Note: Modification within MSDOS could however be done |
  173. | | to emulate a protected disk in the TRS-80 emulator. |
  174. +----------------------------------------------------------------------+
  175. Track header:
  176. Each side of each track has a 128 (80H) byte header which contains an
  177. offset pointer to each IDAM in the track. This allows a maximum of 64
  178. sector IDAMs/track. This is more than twice what an 8 inch disk would
  179. require and 3.5 times that of a normal TRS-80 5 inch DD disk. This
  180. should more than enough for any protected disk also.
  181. These IDAM pointers MUST adhere to the following rules.
  182. * Each pointer is a 2 byte offset to the FEh byte of the IDAM. In
  183. double byte single density the pointer is to the first FEh.
  184. * The offset includes the 128 byte header. For example, an IDAM 10h
  185. bytes into the track would have a pointer of 90h, 10h+80h=90h.
  186. * The IDAM offsets MUST be in ascending order with no unused or bad
  187. pointers.
  188. * If all the entries are not used the header is terminated with a
  189. 0000h entry. Unused entries must also be zero filled.
  190. * Any IDAMs overwritten during a sector write command should have
  191. their entry removed from the header and all other pointer entries
  192. shifted to fill in.
  193. * The IDAM pointers are created during the track write command
  194. (format). A completed track write MUST remove all previous IDAM
  195. pointers. A partial track write (aborted with the forced interrupt
  196. command) MUST have it's previous pointers that were not
  197. overwritten added to the new IDAM pointers.
  198. * The pointer bytes are stored in reverse order (LSB/MSB).
  199. Each IDAM pointer has two flags. Bit 15 is set if the sector is double
  200. density. Bit 14 is currently undefined. These bits must be masked to get
  201. the actual sector offset. For example, an offset to an IDAM at byte 90h
  202. would be 0090h if single density and 8090h if double density.
  203. Track data:
  204. The actual track data follows the header and can be viewed with a hex
  205. editor showing the raw data on the track. If the virtual disk doesn't
  206. have bits 6 or 7 set of byte 4 of the disk header then each single
  207. density data byte is written twice, this includes IDAMs and CRCs (the
  208. CRCs are calculated as if only 1 byte was written however). The IDAM and
  209. sector data each have CRCs, this is just like on a real disk.
  210. Modification should not be done since doing so without updating the
  211. CRCs would cause data errors. Modification could be done however to
  212. create protected tracks for importing protected disks to virtual disk
  213. format. Examples of disks created using this technique are "Super
  214. Utility+ 3.0" and "Forbidden City".