Inferno #08
30 ноября 2005
  Железо  

Iron - CD-ROM - a device and Tricks connection.

<b>Iron</b> - CD-ROM - a device and Tricks connection.
        Talks on CD

   CD-ROM - a very moody ustroystvo.Ma
locally that it is not completely documented
(Incidentally, that details how you can
drowning) - Various models are quite different
software from one druga.Naibolshy experience
This issue has become Budder (Constantine
Hares), which tested a bunch of drives and
wrote a decent copier. SMT, author
Emulator Unreal Speccy, rely more
 for documentation.

   In the brainstorming part, of course,
Not only me (Alone Coder), Budder and SMT,
and Vega, Kury, ZET-9, AmoNik, etc. While
Many questions still decide not to
managed, but I think some of the intermediate
main results published useful. Prev
assumed that the reader is already familiar with
Article Vega in Paragraph # 25. There is wrong races
write commands READ TOC (read table
sessions). Judging by the standard INF-8020 (it
the same original document defining
schy behavior of CD-ROMs, but there's a lot
shamefully hushed up - there is even
Reference "ATA-ATAPI errata"), FUNC - then
the same number as FORMAT, but shifted by 6
bit to the left. FUNC>> 6 and FORMAT must coincide
give t.k.novye drives may not support
vat FUNC (ptsshnye devices are often spread
propagate with the drivers, and each company
can understand the "standard" as he wants).
To read the data from all sessions
need to specify BEGTRK = 0 FORMAT = 0. If
only the latter - that FORMAT = 1. LENGTN Well
zhno bet the maximum (2048, senior
byte forward), and drive himself to determine
how many bytes to transfer (the number of bytes before
exchange is placed in the registers of the cylinder ATA).
The command does not work on the first try!
That she worked before her execution
 should be considered, such as sector 0.

   But I run ahead. So go on:


                   SMT:

S>> According to the standard ATAPI device after reset
S>> proof required to keep the status of the origin,
S>> to the old pre-atapishnye BIOSes do not
S>> identified him for the screw. And most importantly, no one
S>> does not require CD-ROM set DRDY after
S>> command, it is at the discretion of razrabotchi
S>> Cove device.
DB> And when it is on the status of a unit?
After completion of the first ATAPI-command
(# A0). But after a reset necessarily 0;
This differs from the ATA.

DB> And what does the situation, when a reg.
DB> able to read # D0 (I mean the employment
DB> then) and no prog do not want to see
DB> CD-ROM? As his soft reset to
DB> this situation? Helps to just chill
DB> LIMITED reset: (
Bit SRST (Soft Reset - # 0C, then # 08 in
Device Control Register (at Nemo port # C8))
Then it is necessary to give the command # 08, wait
removal of BSY.

The ATA software reset mechanism, SRST,
(Bit 2 in the Device Control Register)
cannot be used for ATAPI Devices, because
resets issued by the ATAPI driver would
also reset any attached hard disk and vice
versa. To solve this ATAPI defines an
ATAPI Soft Reset command using a reserved
ATA opcode which could be decoded by the
interface controller hardware.
To maintain Master / Slave compatibility
with ATA disk drives and prevent detection
of ATAPI Devices by non ATAPI-aware BIOS,
ATAPI Devices shall implement the
following upon receipt of an ATA SRST:
1. Perform SRST PDIAG sequence see "5.18.2
SRST Initialization Sequence "on page 46.
2. Initialize the task file with Status =
00h or 10h, Error = According to SRST
Sequence, Sector Count = 01h, Sector
Number = 01h, Cylinder Low = 14h, Cylinder
High = EBh and Drive / Head = 00h. Note that
Device 0 will be seleted after the
completion of the SRST sequence.
3. The functionality of the DRDY and DSC
bits shall be restored on the first
command following an SRST.
4. Continue executing commands or play
operations.
5. Leave Mode settings or Set Feature
settings unchanged.
6. If a selected ATAPI Device detects SRST
while its own DRQ or BSY is set (one), then
the command in progress shall be stopped.

DB> And you are not lying around instructions on how to
DB> adjust the speed of rotation
DB> CD-ROM'е?
10.8.23 SET CD SPEED Command
The SET CD SPEED command provides a means
for the Nost to set the spindle speed to
be used while reading and writing CD data.
Note that the Play commands may not use
the speed set by this command.
0 Operation code (BBh)
1 Reserved
2 MSB Read Drive Speed ​​in Kbytes / Second
3 LSB
4 MSB Reserved for Write Drive Speed ​​in
Kbytes / Second
5 LSB
6 Reserved
7 Reserved
8 Reserved
9 Reserved
10 Reserved
11 Reserved
The Drive Speed ​​parameter contains the
requested Data Rate the drive should use.
The drive may choose to select the speed
specified or any slower rate. A value of
FFFFh will set the Drive Speed ​​to the
Maximum supported. Requesting a speed
faster than the drive supports will not
generate an error. The actual maximum
speed supported is returned in the
Capabilities Mode Sense page (See
"10.8.6.4 CD-ROM Capabilities and
Mechanical Status Page "on page 115.)


   Comments on the speed of the site
insidePro.com:
-----------------------------------------
            Hacker secrets

                   or

    Recipes brake fluid for CD


   The emergence of high-speed CDROM drives led to a huge 
number of problems and, reputedly users, plus

here is much smaller than minusov.Eto reaction
tive hum, vibration, torn to shreds
Wheels - tell me what the hell it all to you
need? In addition, many of the algorithms for
binding to the CD at high speeds feel
itself is extremely unstable, and secure disk
runs are not the first time, if
general zapuskaetsya.Kakoy same from all of this
exit? Of course - slow! Fortunately, to
Mandu SET CD SEED (opcode 0BBh), most
drives still support them. Seemed
would set the options you want and go! But no
- Everything is not so simple ...

   Trouble first (small, but
annoying). Speed ​​is not specified in the "iksah"
in kilobytes per second (just a kilo
bytes, not bytes!). And once
rate corresponds to the bandwidth
capacity of 176 kilobytes per second. A
twice? Think, 176 * 2 = 352? And here
No - 353! But three times the rate calculated
slyaetsya in full accordance with the usual
our math: 176 * 3 = 528, but 4-fold
radial velocity again deviates from the "x's":
176 * 4 = 704, against 706 for the standard. Non
correctly specified speed leads to mouth
suggesting the speed at level less than expected
my, and the correspondence between actions and
Steps away from unique. Assume
drive supports the following series of velocity
Tei: 16x, 24x, 32x and 40x. If the specified rate
growth (in kilobytes per second) is not dotyagi
increases to the normative rate of 32 "xXx", then
drive moves in the near bottom "under
he supported the speed t.e.v our case
16x. The moral: to translate "'X' in
kilobytes per second, they should not multiply
at 176 and 177!

   Trouble the second (larger and annoyance
it). Command, issuing a full list at
supported the velocities in the standard special
fication is not, and get this information when
hoditsya only brute force.
Correctly running program before beginning
Scrap this enumeration must be satisfied by
presence of media in the drive, and if he is there
is - to force open the tray. The point
that the unwinding of defective CDROM drive to a high velocity 
may at lead to its rupture and consequent

deterioration of the drive. The user must
be absolutely sure that the established
lenny in the drive will rotate names
but with the speed with which it is asked, and
your program will not spontaneously
increase speed without any visible
reasons.

   Trouble third (or quiet horror).
Some drives (in particular, TEAC 522E)
successfully swallow the SET CD SPEED command and
confirm the change of speed, WHO
rotating in the MODE SENSE its new value, one
However, the physical velocity of the disk remains
betrayal until as long as it has not
happen or that treatment. Poe
Besides following the SET CD SPEED thumbs up to give
read command sector from the disk, if the horse
chno, the disc is present at all. Change the same
speed drive with no disc in the tray - Board
rshenno senseless operation, suitable
except for the construction of a number of supports
Mykh velocity t.k.posle insertion of a new di
ska to drive past fast-track
fail, and most
optimal (in terms of driving!) rate
rate for each disk is determined by indie
vidual. Also, the drive may change
speed drive on your own pony
Multiplying it, if reading is not important, and accordingly
respectively, increasing the speed, if all
going well.
-----------------------------------------
   Last paragraph - pure truth itself with
it hurts.


                 Budder:


   Definition HDD (Master) and CDD (Slave):
----------------------------------------- DETECT CALL SEL_MAS

         CALL DRDET

         LD A, D: OR E: LD A, 0: JR NZ, ENDC

        INC A
 ENDC LD (HDEN), A

         CALL SEL_SLA

         LD A, # 08: CALL COMM

         LD A, 1, (CDEN), A

        CALL CDDET: RET Z
 NoCD LD A, 201, (PTCD), A

         XOR A: LD (CDEN), A

        RET
CDEN NOP; 1-have device,
HDEN NOP; 0-device is not
-----------------------------------------
   The output of the result will be a CDEN and
HDEN!

----------------------------------------- COMM LD BC, # F0: OUT 
A : RET 

 XPOZI LD (LTHL), HL, (LTDE), DE; LBA on!

        LD A, H, H, D, D, E, E, A
; DE, cyl H, head L, sec
 POZI LD A, H: AND% 00001111: LD H, A

         LD A, (DRVRE)

         OR H

         LD BC, # D0: OUT A

         LD A, L, C, # 70: OUT A

         LD A, D, C, # B0: OUT A

         LD A, E, C, # 90: OUT A

        RET

 RPOZ LD BC, # D0: IN A: AND # 0F

         LD H, A, C, # 70: IN A

         LD L, A, C, # B0: IN A

         LD D, A, C, # 90: IN A

         LD E, A

        RET
;---------------------------------------- CDDET CALL SEL_SLA
 DRDET LD DE, 0

         LD H, D, L, E

         CALL XPOZI

         LD A, # EC

        CALL COMM
.3 HALT; delay in 3 / 50 sec

                     , Giving the IDE device

         CALL RPOZ; time to think and

         LD HL, # EB14; whether it? ;)

         OR A: SBC HL, DE

        RET Z
 NFOC LD A, 1: OR A

        RET
;---------------------------------------- SEL_SLA LD A, # B0

         LD (DRVRE), A

         LD BC, # D0: OUT A: LD C, # F0: IN A

         RLCA

        RET
 SEL_MAS LD A, # E0

        JR SEL_SLA +2
;---------------------------------------- DRVRE NOP
LTHL DS 2
LTDE DS 2
-----------------------------------------

   Procedure of waiting BSY:
----------------------------------------- RDY LD BC, # F0: IN A 
; infinite 

         RLCA: RET NC; waiting for BSY

        JR RDY

 READY LD E, 0, D, 0; waiting for BSY

         LD BC, # F0: IN A; with timeout

         RLCA: JR C, RY

        XOR A: OUT (254), A: RET
 RY LD BC, # F0, BC, # F0; idle

         DEC D: JR NZ, READY +4

         DEC E: JR NZ, READY +2

         LD A, 1: OUT (254), A

         CALL ECCOM

         EI: HALT

        JR READY
ECCOM NOP: LD BC, # F0, A, # EC: OUT A: RET
; Working with the HDD in ECCOM to Record
; Value 201 (RET), and working with CDD
; Record 0 (NOP)


   The current engine WDC instead READY one hundred
um READY2:
----------------------------------------- READY2 XOR A: LD 
(TMR), A; waiting for BSY  REA LD BC, # F0: IN A; with timeout


         RLCA: JR NC, RY2; in 1 / 2 seconds

         LD A, (TMR): CP 25: JR C, REA

         LD A, 1: OUT (254), A

         CALL ECCOM

         EI: HALT

        JR READY2
 RY2 XOR A: OUT (254), A

        RET
TMR NOP

 I_N_T PUSH HL; should hang

         LD HL, TMR: INC (HL); interrupt

         POP HL

         EI

        RET
-----------------------------------------
   But such demands the presence of the counter
interrupt ...


   In fact READY need to call
ONLY before performing a new team, and
In some cases, where such principles
exponentially, causing the team after the regular RDY
(Or does not cause neither one nor the other).

    Example:

        CALL READY; waiting /

                    ; Job readiness

        CALL EJECT; Packet

                    ; By pushing the tray

        CALL RDY; awaiting execution


   Another important place - the waiting
DRQ before taking the data in the process of reading
of the sector:
-----------------------------------------; Procedure read sector
; HL = Kuzia else in the package seated
READSE LD (HLAD), HL
 RETRYL XOR A: OUT (254), A

         CALL READY

         LD HL, READP: CALL SNDPAK

                           , Instructs
 LOADSE1 LD A, 5: OUT (254), A; read sector

         CALL READY

         CALL ERROR_7: JR C, RETRYL

        LD D, 0
; In some extra buggy CD-drive
; Here may hang, if you make just
; Call WAITDRQ
 WDQ LD BC, # F0: IN A

         BIT 3, A: JR NZ, WQR

         DEC D: JR Z, RETRYL

        JR WDQ
WQR LD HL, (HLAD)
GSLOD
 .4 CALL READS

         XOR A: OUT (254), A

        RET
HLAD DS 2

READS LD C, # 10, D, # 80
 RE1 INI: INC C

         INI: DEC C

         INI: INC C

         INI: DEC C

         DEC D: JR NZ, RE1

        RET
;---------------------------------------- SNDPAK PUSH HL; IN HL 
ADDR OF PAK 

         CALL READY

        CALL SEL_SLA



         LD HL, # 0800

        CALL OUTRCIL; expose values

                        ; Byte count

         LD A, # A0; give Komad of

         LD BC, # F0: OUT A; Packet

         POP HL

        LD BC, 12

 TRANSOU PUSH BC

         CALL RDY

         CALL WAITDRQ

         POP BC

         OR A

         RR B, C

         JR NC, $ +3

        INC BC

 TOUT1 PUSH BC

         INC HL

         LD A, (HL), BC, # 11

         OUT A

         DEC HL

         LD A, (HL): DEC C

         OUT A

         INC HL, HL

         POP BC

         DEC BC

         LD A, B

         OR C

         JR NZ, TOUT1

        RET

 OUTRCIL LD A, L, BC, # 90: OUT A

         LD A, H, C, # B0: OUT A

        RET
;------------- Reading packet -------------- ERRT POP BC

        RET
 TRANSIN; HL = BC = Kuzia lope

         PUSH BC

         CALL SEL_SLA

         CALL RDY, ERROR_7: JR C, ERRT

         CALL WAITDRQ

         POP BC

         OR A

         RR B, C

         JR NC, $ +3

        INC BC
 T_I1 IN A, (# 10): LD (HL), A: INC HL

         IN A, (# 11): LD (HL), A: INC HL

         DEC BC

         LD A, B: OR C

         JR NZ, T_I1

        RET

 HLTOLEN LD BC, # 90, A, L: OUT A

         LD BC, # B0, A, H: OUT A

        RET
 LENTOHL LD BC, # 90: IN A: LD L, A

         LD BC, # B0: IN A: LD H, A

        RET

 WAITDRQ LD BC, # F0: IN A

         BIT 3, A: RET NZ

        JR WAITDRQ
 ERROR_7 LD BC, # F0: IN A

         RRCA

        RET
-----------------------------------------
   In all other procedures can you
be called simply WAITDRQ! (Where required
is.)


   Waiting for a CD drive at any time
Meaney: I can not describe in detail, t.k.mnogie
stuff I can not remember. I can only say that in those
most times when the drive is not ready, CD at
Waters sees any team as a bug
(Excl.. Some of them). BSY signal indicates
employment, at least after the spacecraft
Coy or team (for example, the transmission packet
ma), but if there was no error!

   After packet transmission regardless of the fact
On whether he was handed over, put procedure
READY (look procedure read Sector)
her inspection of the error signal in the register
state. If an error, then repeat starting
package, and thus is expected to ready
sequence the CD drive at any time vreneni ...

   In my engine has another feature:
Control of timeouts, a cat. must
be in the process of waiting BSY (all
drivers on the PC so done), I chose 1 / 2
seconds. On a PC, the restriction on waiting time
Denmark is not only the BSY, but also to remain
lnye signaly.Pri timeout in my engine
command is # EC, cat. is necessarily
Indeed for all ATAPI devices, and which
Weigh BSY! (If you do not like # EC, then
You can use # 00, but for any necessary
another point in the subcommand code FR (register
properties), in our case it is 0.)


                   SMT:


   Still play a bit with direct access
the CD-ROM, and realized how to grow legs
give the package with the code # 00. Often the first on
this on CD-ROM command is executed with
error. But we need to watch that for an error, and
do not try to repeat or give to another
Mandu. Most likely, in the error register conditions
stalled the MC [???] or MCR [Media Change
Requested in ATAPI - D3 Registry errors]
ie user pressed the eject or insert a new
disc. In this case, the drive informs the host
discarding the following command with acc.
oshibkoy.A instead send the packet
# 00, which "swallow" this alert
need to repeat the operation if an error of
level MC / MCR. After all, it is quite possible (although
very unlikely) that the change of media or
pressing eject will just between coma
ndami # 00 and the working team, then working
team broken off, despite the pre-
passed # 00.

10.8.26 TEST UNIT READY Command
The TEST UNIT READY command provides a
means to check if the Device is ready.
This is not a request for a self-test. If
the Device would accept an appropriate
medium-access command without returning
CHECK CONDITION sta-tus, this command
shall return a GOOD status. If the Device
cannot become operational or is in a state
such that an Host Computer action (e.g.
START / STOP UNIT command with LoEj = 0 '
Start = 1) is required to make the unit
ready, the ATAPI CD-ROM Drive shall return
CHECK CONDITION status with a sense key of
NOT READY. 10.8.26.1 Using the TEST UNIT
READY Command The TEST UNIT READY command
is useful in that it allows a Host
Computer to poll a Device until it is
ready without the need to allocate space
for returned data. It is especially useful
to check cartridge status. ATAPI CD-ROM
Drives are expected to respond promptly to
indicate the current status of the device.
0 Operation code (00h)
1 Reserved
2 Reserved
3 Reserved
4 Reserved
5 Reserved
6 Reserved
7 Reserved
8 Reserved
9 Reserved
10 Reserved
11 Reserved


   P.S. And then it becomes clear why
in your case the package # 00 was required only
once - you simply drive is not changed.

DB> 1. When I form a reset control
DB> that returns the register (# 0C, then through some
DB> certain time # 08), how to determine
DB> when I give the # 08? IMHO should be
DB> some light on this?
Removal of BSY. He immediately set
after the # 08.

   Reset via ATA SRST does not interrupt the coma
NDU ATAPI, but puts a signature as a result
Giustra cylinder. However, it does not interfere.

DB> 2. If you run the initialization until it
DB> of how sidyuk after hard reset
DB> (RES on the loop) has time to unwind,
DB> a CD-ROM ignores the command. No matter how I
DB> read status registers and error, but
DB> difference between the two states (time to
DB> / did not have time to unwind) did not notice.
Error reads commands REQUEST SENSE
(# 03).

DB> 3. Some drives make a mistake on
DB> command set the speed, after which
DB> does not respond to commands. As
DB> get them to work after this?
Do not give the command. Ask about support
 through the MODE SENSE / CAPABILITIES.

   Ed.: There's no sign that the drive can
change the speed!

DB> 4. How do I know that the time has come again
DB> file command speed setting
DB> (ie how do you know that the drive its self
DB> randomly changed)?
Yes. Assume that the current speed through the
MODE SENSE / CAPABILITIES
(# 5A with a parameter # 2A).
b. Usually the rate is reset when you change
media. Put option after treatment
MCR; If checked, before the team
ask again the speed (for simplicity
precede the reading of the catalog SET CD SPEED.
Once the disc was replaced, the user is forced
read, at the same time the rate is established).




Other articles:

Inferno - The authors of the magazine.

Inferno - Entered from the editor.

Inferno - Errors in the previous numbers.

Inferno - On the shell.

Iron - CD-ROM - a device and Tricks connection.

For Coderz - CD video on the ZX. How to write a video player with CD-ROM.

Softinka - Technical Reference disk system DISCiPLE / + D.

For Coderz - Small programmers' tricks.

Mathematics - The history of the solution of Fermat's theorem.

Gameland - Game Shestnashki.

Softinka - a description and history of the program to work with hard disk HDDoctor v0.9.

Secrets - The X button in different applications: Wolfenstein'2004, IG # 5, ACEdit, DNA OS, Wild Disk Copier.

Softinka - Improved graphics converter Gigascreen.

Sound - tube amplifier. Stereo lampochnik 2x5 Tues of old TVs.

Iron - Overview of cassette players.

Inferno - Letters to the Editor.

Gamedev - The history of the game Pang.

Gamedev - Tips for writing an arcade game.

Advertising - Ads by Roman Chuunin.

Advertising - Ads by Alexei Zhabina.

Advertising - Ads by V. Bogdanovich.

Interview - Interview with Nikolay Rodionov, author of popular books for the ZX Spectrum

For Coderz - The calculation of trigonometric and algebraic functions in a high-level languages.

DIY - scheme of 16-color video mode v1.1 for the Pentagon.

Iron - Description of Products K555TL2.

For Coderz - Programming device sound generation Turbo Sound.

Softinka - 384x304 viewer. program allows you to view color pictures, is larger than the screen.

Softinka - ZX Spectrum emulator for ZX Spectrum.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
Ator magazine - ZX-Format No.7
BBS List - Schedule Minsk BBS.
Spekovskaya demoscene - SaiR00S: on the code in the demos - "Chunky rulez?".

В этот день...   21 November