libcd.pas 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. {
  2. * (C) Copyright 1993/1994 Sony Computer Entertainment ,Tokyo,Japan.
  3. * All Rights Reserved
  4. *
  5. * libcd.h: CD-ROM sub system hendler
  6. *
  7. * CD-ROM Primitive Command list:
  8. *
  9. * Symbol type Contents
  10. * ------------------------------------------------------
  11. * CdlNop B NOP
  12. * CdlSetloc B Set position
  13. * CdlPlay B CD-DA Play
  14. * CdlForward B Forward
  15. * CdlBackward B Backward
  16. * CdlReadN B Read with retry
  17. * CdlStanby N Standby
  18. * CdlStop N Stop
  19. * CdlPause N Pause
  20. * CdlMute B Mute on
  21. * CdlDemute B Mute off
  22. * CdlSetfilter B Set SubHeader filter
  23. * CdlSetmode B Set mode
  24. * CdlGetlocL B Get logical position
  25. * CdlGetlocP B Get phisycal position
  26. * CdlSeekL N Logical Seek
  27. * CdlSeekP N Phisical Seek
  28. * CdlReadS B Read without retry
  29. * ------------------------------------------------------
  30. * B: Blocking, N: Non-Blocking operation
  31. *
  32. *
  33. * Symbol arg result
  34. * --------------------------------------------------------------
  35. * CdlNop - status
  36. * CdlSetloc min,sec,sector status
  37. * CdlPlay - status
  38. * CdlForward - status
  39. * CdlBackward - status
  40. * CdlReadN - status
  41. * CdlStanby - status
  42. * CdlStop - status
  43. * CdlPause - status
  44. * CdlMute - status
  45. * CdlDemute - status
  46. * CdlSetfilter file,chan status
  47. * CdlSetmode mode status
  48. * CdlGetlocL - min,sec,sector,mode,file, chan
  49. * CdlGetlocP - track,index,min,sec,frame,
  50. * amin,asec,aframe
  51. * CdlSeekL - status
  52. * CdlSeekP - status
  53. * CdlReadS - status
  54. * --------------------------------------------------------------
  55. }
  56. unit libcd;
  57. interface
  58. uses libstd;
  59. const
  60. // CD-ROM Mode (used int CdlSetmode)
  61. CdlModeStream = $100; // Normal Streaming
  62. CdlModeStream2 = $120; // SUB HEADER information includes
  63. CdlModeSpeed = $80; // 0: normal speed 1: double speed
  64. CdlModeRT = $40; // 0: ADPCM off 1: ADPCM on
  65. CdlModeSize1 = $20; // 0: 2048 byte 1: 2340byte
  66. CdlModeSize0 = $10; // 0: - 1: 2328byte
  67. CdlModeSF = $08; // 0: Channel off 1: Channel on
  68. CdlModeRept = $04; // 0: Report off 1: Report on
  69. CdlModeAP = $02; // 0: AutoPause off 1: AutoPause on
  70. CdlModeDA = $01; // 0: CD-DA off 1: CD-DA on
  71. // Status Contents
  72. CdlStatPlay = $80; // playing CD-DA
  73. CdlStatSeek = $40; // seeking
  74. CdlStatRead = $20; // reading data sectors
  75. CdlStatShellOpen= $10; // once shell open
  76. CdlStatSeekError= $04; // seek error detected
  77. CdlStatStandby = $02; // spindle motor rotating
  78. CdlStatError = $01; // command error detected
  79. // Macros for CdGetDiskType()
  80. CdlStatNoDisk = 0;
  81. CdlOtherFormat = 1;
  82. CdlCdromFormat = 2;
  83. // CD-ROM Primitive Commands
  84. CdlNop = $01;
  85. CdlSetloc = $02;
  86. CdlPlay = $03;
  87. CdlForward = $04;
  88. CdlBackward = $05;
  89. CdlReadN = $06;
  90. CdlStandby = $07;
  91. CdlStop = $08;
  92. CdlPause = $09;
  93. CdlMute = $0b;
  94. CdlDemute = $0c;
  95. CdlSetfilter = $0d;
  96. CdlSetmode = $0e;
  97. CdlGetparam = $0f;
  98. CdlGetlocL = $10;
  99. CdlGetlocP = $11;
  100. CdlGetTN = $13;
  101. CdlGetTD = $14;
  102. CdlSeekL = $15;
  103. CdlSeekP = $16;
  104. CdlReadS = $1B;
  105. // Interrupts
  106. CdlNoIntr = $00; // No interrupt
  107. CdlDataReady = $01; // Data Ready
  108. CdlComplete = $02; // Command Complete
  109. CdlAcknowledge = $03; // Acknowledge (reserved)
  110. CdlDataEnd = $04; // End of Data Detected
  111. CdlDiskError = $05; // Error Detected
  112. // Library Macros
  113. function btoi(b: longint): byte; // BCD to u_char
  114. function itob(i: byte): longint; // u_char to BCD
  115. procedure CdSeekL(p: dword);
  116. procedure CdSeekP(p: dword);
  117. procedure CdStandby;
  118. procedure CdPause;
  119. procedure CdStop;
  120. procedure CdMute;
  121. procedure CdDeMute;
  122. procedure CdForward;
  123. procedure CdBackward;
  124. // Position
  125. const
  126. CdlMAXTOC = 100;
  127. // Callback
  128. type
  129. CdlCB = procedure (b: byte; p: pchar);
  130. // Location
  131. type
  132. CdlLOC = packed record
  133. minute : byte; // minute (BCD)
  134. second : byte; // second (BCD)
  135. sector : byte; // sector (BCD)
  136. track : byte; // track (void)
  137. end;
  138. PCdlLOC = ^CdlLOC;
  139. // ADPCM Filter
  140. CdlFILTER = packed record
  141. _file : byte; // file ID (always 1)
  142. chan : byte; // channel ID
  143. pad : u_short;
  144. end;
  145. // Attenuator
  146. CdlATV = packed record
  147. val0 : byte; // volume for CD(L) -> SPU (L)
  148. val1 : byte; // volume for CD(L) -> SPU (R)
  149. val2 : byte; // volume for CD(R) -> SPU (L)
  150. val3 : byte; // volume for CD(R) -> SPU (R)
  151. end;
  152. PCdlATV = ^CdlATV;
  153. // Low Level File System for CdSearchFile()
  154. const
  155. CdlMAXFILE = 64; // max number of files in a directory
  156. CdlMAXDIR = 128; // max number of total directories
  157. CdlMAXLEVEL = 8; // max levels of directories
  158. type
  159. CdlFILE = packed record
  160. pos : CdlLOC; // file location
  161. size : u_long; // file size
  162. name : array [0..15] of char; // file name (body) */
  163. end;
  164. PCdlFILE = ^CdlFILE;
  165. // Streaming Structures
  166. type
  167. StHEADER = packed record // CD-ROM STR structure
  168. id : u_short;
  169. _type : u_short;
  170. secCount : u_short;
  171. nSectors : u_short;
  172. frameCount : u_long;
  173. frameSize : u_long;
  174. width : u_short;
  175. height : u_short;
  176. dummy1 : u_long;
  177. dummy2 : u_long;
  178. loc : CdlLOC;
  179. end;
  180. const
  181. StFREE = $0000;
  182. StREWIND = $0001;
  183. StCOMPLETE = $0002;
  184. StBUSY = $0003;
  185. StLOCK = $0004;
  186. EDC = 0;
  187. SECTOR_SIZE = 512; // Sector Size (word)
  188. HEADER_SIZE = 8; // Header Size (word)
  189. StSTATUS = $00;
  190. StVER = $00;
  191. StTYPE = $01;
  192. StSECTOR_OFFSET = $02;
  193. StSECTOR_SIZE = $03;
  194. StFRAME_NO = $04;
  195. StFRAME_SIZE = $06;
  196. StMOVIE_WIDTH = $08;
  197. StMOVIE_HEIGHT = $09;
  198. // Prototypes for Streaming
  199. procedure StSetRing(ring_addr: Pdword; ring_size:Pdword); stdcall external;
  200. procedure StClearRing; stdcall external;
  201. procedure StUnSetRing; stdcall external;
  202. procedure StSetStream(mode: u_long; start_frame, end_frame: u_long; func1, func2: pointer); stdcall external;
  203. procedure StSetEmulate(addr: Pdword; mode: u_long; start_frame, end_frame: u_long; func1, func2: pointer); stdcall external;
  204. function StFreeRing(base: Pdword): u_long; stdcall external;
  205. function StGetNext(addr: pointer; header: pointer): u_long; stdcall external;
  206. function StGetNextS(addr: pointer; header: pointer): u_long; stdcall external;
  207. function StNextStatus(addr: pointer; header: pointer): u_short; stdcall external;
  208. procedure StRingStatus(free_sectors: Pshort; over_sectors: Pshort); stdcall external;
  209. procedure StSetMask(mask: u_long; start, _end: u_long); stdcall external;
  210. procedure StCdInterrupt; stdcall external;
  211. function StGetBackloc(loc: PCdlLOC): longint; stdcall external;
  212. function StSetChannel(channel: u_long): longint; stdcall external;
  213. // Prototypes
  214. procedure CdFlush; stdcall external;
  215. function CdSearchFile(fp: PCdlFILE; name: pchar): PCdlFILE; stdcall external;
  216. function CdIntToPos(i: longint; p: PCdlLOC): PCdlLOC; stdcall external;
  217. function CdComstr(com: byte): pchar; stdcall external;
  218. function CdIntstr(intr: byte): pchar; stdcall external;
  219. function CdControl(com: byte; param: Pbyte; result: Pbyte): longint; stdcall external;
  220. function CdControlB(com: byte; param: Pbyte; result: Pbyte): longint; stdcall external;
  221. function CdControlF(com: byte; param: Pbyte): longint; stdcall external;
  222. function CdGetSector(madr: pointer; size: longint): longint; stdcall external;
  223. function CdGetSector2(madr: pointer; size: longint): longint; stdcall external;
  224. function CdDataSync(mode: longint): longint; stdcall external;
  225. function CdGetToc(loc: PCdlLOC): longint; stdcall external;
  226. function CdPlay(mode: longint; track: Plongint; offset: longint): longint; stdcall external;
  227. function CdMix(vol: PCdlATV): longint; stdcall external;
  228. function CdPosToInt(p: PCdlLOC): longint; stdcall external;
  229. function CdRead(sectors: longint; buf: pointer; mode: longint): longint; stdcall external;
  230. function CdRead2(mode: longint): longint; stdcall external;
  231. function CdReadFile(_file: pchar; addr: pointer; nbyte: longint): longint; stdcall external;
  232. function CdReadSync(mode: longint; res: pointer): longint; stdcall external;
  233. function CdReady(mode: longint; res: pointer): longint; stdcall external;
  234. function CdSetDebug(level: longint): longint; stdcall external;
  235. procedure CdSync(mode: longint; res: pointer); stdcall external;
  236. function CdDataCallback(func: pointer): pointer; stdcall external;
  237. function CdReadCallback(func: CdlCB): CdlCB; stdcall external;
  238. function CdReadyCallback(func: CdlCB): CdlCB; stdcall external;
  239. function CdSyncCallback(func: CdlCB): CdlCB; stdcall external;
  240. function CdInit: longint; stdcall external;
  241. function CdReset(mode: longint): longint; stdcall external;
  242. function CdStatus: longint; stdcall external;
  243. function CdLastCom: longint; stdcall external;
  244. function CdLastPos: PCdlLOC; stdcall external;
  245. function CdMode: longint; stdcall external;
  246. function CdDiskReady(mode: longint): longint; stdcall external;
  247. function CdGetDiskType: longint; stdcall external;
  248. // CdReadExec(char *file): EXEC;
  249. procedure CdReadBreak; stdcall external;
  250. implementation
  251. function btoi(b: longint): byte;
  252. begin
  253. btoi:= b div 16 * 10 + b mod 16;
  254. end;
  255. function itob(i: byte): longint;
  256. begin
  257. itob:= i div 10 * 16 + i mod 10;
  258. end;
  259. procedure CdSeekL(p: dword);
  260. begin
  261. CdControl(CdlSeekL, @p, nil);
  262. end;
  263. procedure CdSeekP(p: dword);
  264. begin
  265. CdControl(CdlSeekP, @p, nil);
  266. end;
  267. procedure CdStandby;
  268. begin
  269. CdControl(CdlStandby, nil, nil);
  270. end;
  271. procedure CdPause;
  272. begin
  273. CdControl(CdlPause, nil, nil);
  274. end;
  275. procedure CdStop;
  276. begin
  277. CdControl(CdlStop, nil, nil);
  278. end;
  279. procedure CdMute;
  280. begin
  281. CdControl(CdlMute, nil, nil);
  282. end;
  283. procedure CdDeMute;
  284. begin
  285. CdControl(CdlDemute, nil, nil);
  286. end;
  287. procedure CdForward;
  288. begin
  289. CdControl(CdlForward, nil, nil);
  290. end;
  291. procedure CdBackward;
  292. begin
  293. CdControl(CdlBackward, nil, nil);
  294. end;
  295. begin
  296. end.