Use of the Disk II Interface Card Through Your Own Software by John Uhley
Total Page:16
File Type:pdf, Size:1020Kb
Use of the Disk II Interface Card Through Your Own Software by John Uhley This is the first of a series of three articles which will discuss In the table below 'S' represents one of the 16 softswitches of several techniques used in accessing the Disk II Interface Card. the specified slot The routines discussed in these articles will enable a pro· grammer to access the Disk II without the use of Apple DOS or SLOT SOFTSWITCH X·REG COMMAND Apple RWTS. This article will introduce the programmer to one method of accessing the Disk II Interface card and develop 0 s $00 LDA $C08S,X several routines to position the disk drive's magnetic head 1 s $10 LDA $C08S,X across the surface of the diskette. 2 s $20 LDA $C08S,X 3 s $30 LDA $C08S,X Each of the eight slots in back of the Apple computer is 4 s $40 LDA $C08S,X allocated 16 memory locations for 1/0 control. Some of these 5 s $50 LDA $C08S,X memory locations act as softswitches (software switches) and 6 s $60 LDA $C08S,X perform a predefined hardware task when addressed by a 7 s $70 LDA $C08S,X software routine. Other 1/0 memory locations are used as wormholes through which data can enter or exit the computer. Depending on the actual card placed in a given slot the 16 Most of the Apple's I/ 0 is done on page $CO of memory. The softswitches will perform a different function. This article will following table illustrates the range of memory reserved for only discuss the effect of these 16 softswitches on the Disk II each slot's softswitches. Interface Card. The table below illustrates the functions of each of the softswitches. SLOT LOCATIONS MEMORY LOCATION FUNCTION 0 $COBO· $C08F $COBO+ SLOT Phase 0 off (positioning) 1 $C090 · $C09F $C081 +SLOT Phase 0 on (positioning) 2 $COAO · $COAF $C082 +SLOT Phase 1 off (positioning) $C083 +SLOT Phase 1 on (positioning) $COBO · $COBF 3 $C084 +SLOT Phase 2 off (positioning) 4 $COCO · $COCF $C085 +SLOT Phase 2 on (positioning) 5 $CODO · $CODF $C086 +SLOT Phase 3 off (positioning) 6 $COEO · $COEF $C087 - SLOT Phase 3 on (positioning) 7 $COFO · $COFF $C088 +SLOT Power Down (drive off) $C089 ·SLOT Power Up (drive on) One common method of accessing softswitches through software is to use the Apple's indexed addressing mode. By $C08A +SLOT Select 1 (select drive 1) adding various values to the address of a slot zero softswitch it $COBB+ SLOT Select 2 (select drive 2) is possible to change the addressed slot by altering the index register alone. For example, if a program wanted to access the $C08C +SLOT Readswitch softswitches of the card in Slot3 the following method could be (1/0 wormhole) used: $C08D +SLOT Writeswitch (1/0 wormhole) LDX #$30 ; (select slot 3) $COSE+ SLOT Clearswitch (1/0 wormhole) TURN ON LDA $C089,X turn on disk drive in slot3 $C08F +SLOT Shiftswitch RTS and return (1/0 wormhole) (SLOT refers to the index value needed to access the Using this technique the same routine can access any slot's softswitches of a given slot As shown earlier, this value is equal softswitches by changing the value in the X·register: to that slot number times 16.) LDX #$60 ; (select slot 6) JMP TURNON ; turn on disk drive in slot 6 The following routines demonstrate some of the techniques ; using the same routine used to activate or deactivate a disk drive. Each time a new disk 12 Apple Orchard drive is activated it is necessary to wait for the drive' s motor to lower numbered tracks. Figures A and B illustrate the concepts reach operational speed. One suitable delay loop is illustrated discussed in these paragraphs using simplified models. by the "MWAIT' subroutine. Figure C shows a magnetized needle surrounded by four electromagnetic poles. By magnetizing one of the four poles The first eight softswitches are used to position the disk the needle is forced to 'point' towards that pole. By magnetizing drive' s magnetic head above the physical tracks of a diskette. and demagnetizing the poles in a given order the needle can be These softswitches are used to rotate a motor which moves the made to spin in a clockwise or counterclockwise direction (see magnetic head back and forth along the surface of a diskette. figure D). By replacing the needle with a motor and the poles with By rotating the motor in a clockwise direction the magnetic software controlled electromagnets (numbered 0, 1,2,and 3) a head is moved towards higher numbered tracks. Conversely, model of the disk drive's positioning motor can be visualized counterclockwise rotation forces the magnetic head towards (see figure E). **'**'**'**'**'****'**'**'**** 10 ''*'***'*'*''******'***'****** .-, 11 ~ • * • • • ROUTINE TO TURN ON DRIVE 1 * 12 * SET SLOT EQUAL TO SLOT 6 * • 13 ' 5 '*********************'**'**'* 14 *'*****''**'*'*'* ~ ········**'* 6 SLOT EOU S0001 /000: A9 60 15 LDA lH60 7 UAlT EQU $0002 /002: 85 01 16 ST,; 'oLOT 8 DISKON EQU lC089 17 '**********'*'***************' 9 DRIVEA EGU $COBA 18 * 10 **'**'***'********'**'******** 19 * TURN ON THE DISK DRIVE AND * 11 * * 20 * SELECT DRIVE B 12 * SET SLOT EOUAL TO SLOT 6 * 21 • 13 • 22 **'*'***''**''*'*********''*'* 14 ********************'********* /004: A6 01 23 LDX SLOT /000: A9 60 15 LDA U60 /006: Bii 89 CO 24 LflA fllSl<ON,X /002: B5 01 16 STA SLOT / 009: (![1 BB CO 25 L.O;; DIUVEB,X 17 ****************************** 26 **'''''*****''************'*** 1B * * 27 . ' 19 * TURN ON THE DISK DRIVE AND * 2B * UAIT FOR DRIVE TO POWER UP * 20 * SELECT DRIVE A * 29 21 • 30 •••••••••••••••••••••••••••••• 22 ***'''''''''******'*****'***** /OOC: A9 EF 31 MWAIT LDA illEF / 004: Ao 01 23 LDX SLOT ? OOE: B5 02 32 STA UAIT 7006: BD B9 CO 24 LDA DISKON,X / 010: A9 BB 33 LOA #$[18 /009: BD BA CO 25 LIIA DRIVE;~,X /012: 85 03 34 STA WAIT+l 26 *'****''********************** ?014: AO 12 35 HWAITA LDY #$12 27 ' 7016: BB 36 MWAIYP. DEY . /017: [10 FD 37 2B • UAIT FOR DRIVE TO POWER UP * BNE til.JAITB 29 • /019: E6 02 3B INC I.MIT 30 ****************************** ?01B: DO F7 39 BNE tlWAIT ;; ?OOC: A9 EF 31 HWAIT LDA #SEF / ()1 [I: E6 03 40 INC WtHT+1 /OOE: BS 02 32 STA UAIT /OlF: DO F3 41 :BNE HWAITA /010: A9 DB 33 LDA UD8 /021: 60 42 RTS 7012: B5 03 34 STA WAIT+1 ?014: AO 12 35 HWAITA LDY #$12 /016: BB 36 HUAITF DEY 1 ···················· ~ ········· ?017: DO FD 37 BNE 11WAIT8 2 * * /019: E6 02 3B INC l.JAIT 3 * ROUTINE TO TURN OFF A DISK * /01B: [10 F7 39 BNE Hl.JrHrn 4 /OHi: E6 03 40 INC WAIT+1 *'*'''''********'**'********** /01F: DO· F3 41 BNE MWAITA SLOT EGLI $0001 /021: 60 42 RTS 7 DISKOFF EQU SCOB8 B ,,,, .......................... 9 * * 10 * SET SLOT EQUAL TO SLOT 6 * 11 • •t• 12 **'**''*********************** /000: A9 60 13 L[IA H60 / (102: 85 01 14 STA SLOT ********'**'**'**********''''* 15 ****'******'*'**************** 2 • • 16 • * 3 • ROUTINE TO TURN ON DRIVE 2 * 17 • TURN OFF THE DISK DRIVE * 4 * 1B * Al[I OUIT * 5 **'****'*''''**'***'*****'***' 19 * * 6 SLOT EGU $0001 20 •••••••••••••••••••••••••••••• 7 UAIT EQU $0002 /004: A6 01 21 LBX SLOT B DISKON EOU lC089 ?006: Bii 88 CO 22 U1,, :OISl<flFF,X 9 DRIVEB EQU $COBB ?009: 60 23 RTS April 1983 13 0 0 3 Figure A 2 0 3 0 2 Figure C Figure B 14 A pp Ie Orchard magnetic element of motor I I Phase 0 I I I 0 I I I I 0 ) 2 Phase 3 Phase 1 c:=i c:::i 0 2 Phase 2 1 0 3 Figure E 0 ( 2 Each of the eight softswitches used in positioning the magnetic head actually activates or deactivates a specific phase of the positioning motor. By addressing these soft 3 switches in a specific order the motor can be rotC}ted and the magnetic head positioned bad" and forth along the surface of a diskette. The following taple illustrates the function of each of the eight 'positioning' softswitches. Note that SLOT refers to the index value needed to access the softswitches of a given slot 0 2 r MEMORY LOCATION PHASE FUNCTION $C080 +SLOT 0 Turn phase 0 off $C081 +SLOT 0 Turn phase 0 on $C082 + SLOT 1 Turn phase l off $C083 +SLOT 1 Turn phase 1 on 3 $C084 +SLOT 2 Turn phase 2 off $C085 +SLOT 2 Turn phase 2 on Figure D $C086 +SLOT 3 Turn phase 3 off $C087 +SLOT 3 Turn phase 3 on April 1983 15 When positioning the magnetiC head via software, it is in the ratio of 1 :2. All even numbered tracks are positioned necessary to wait for the positioning motor to physically move "under" phase 0 and all odd numbered tracks are positioned . to an activated phase before that phase is deactivated. For "under" phase 2. When positioned on phases 1 or 3 the disk example, in order to 'pulse' phase 0 of the positioning motor drive' s magnetic head is position~d over a half·track (much like the following routine mig ht be executed. a car driving in two lanes). Half-tracks are not used py Apple DOS although some protected software makes use of them. #$60 ; (select slot 6) LSX The phase to which a DOS track corresponds can be calculated by multiplying the DOS track number by two (using LDA the ASL opcode). This value represents the number of phases LDA $C081 ,X turn on phase 0 that must be pulsed from phase 0 (of track zero) in order to LDA #$56 wait for motor to move reach the specified DOS track JSR $FCA8 to the phase LDA $C080,X before deactivating phase 0 The following routine can be used to position the disk drive's magnetic head over any physical track of a diskette.