* Myarc FDC 18 sectors/track DSDD format routine * Original code by Will McGovern * More or less as used in Funnelweb DiskReview * and earlier DM-1000 upgrade * Self-contained but assumes VMBR, VMBW utilities * available in calling program * - otherwise write your own as in-line code * Easily modified for DSQD - just change track count * Self-modifying for drive select SBO instruction at * label MYFMT3 - needs change for use as ROM code *--- Call as --- * BLWP @MYFMT * BYTE drive#(1-4),#sides(1-2) * JMP ERROR *----------- MPAD EQU >8300 PAD fast memory MGPLWS EQU >83E0 Fast WSP for critical code MBUFFR EQU >DF80 Temp track layout buffer TRKLEN EQU >1830 Nominal (min) size of track PADSAV EQU >3600 Temp VDP save area for PAD * Data for track and sectors * Byte/count table * >156 bytes for each sector data block FMTDTA BYTE >4E,>28 Track lead in FMTDTB BYTE >00,>0C Synchronize for address BYTE >F5,>03 MFM filler BYTE >FE,>01 Address mark BYTE >00,>03 Data to be filled in BYTE >01,>01 256 byte sectors BYTE >F7,>01 For CRC generation BYTE >4E,>18 Filler - ID/Data separation BYTE >00,>0C Synchronize for data BYTE >F5,>03 MFM filler BYTE >FB,>01 Data mark BYTE >E5,>80,>E5,>80 Initialized sector data BYTE >F7,>01 For CRC generation BYTE >4E,>18 Filler MBAA BYTE >AA Flag for end of sector data MSCTLN EQU >156 Sector data length * FDC command and misc data T0 BYTE >02 Restore to track #0 command SI BYTE >52 Step head in command WT BYTE >F0 Write track command MFOUR BYTE >04 Max # drives * Sector interlace table INTLCE BYTE 0,11,4,15,8,1,12,5,16 BYTE 9,2,13,6,17,10,3,14,7 EVEN MYFWSP BSS >20 Workspace in RAM * Format code BLWP entry point MYFMT DATA MYFWSP,MYFMT1 BLWP vector MYFMT1 MOVB *R14,*R14 Check drive # JEQ BADDRV Don't use this routine CB *R14,@MFOUR Max 4 drives permitted JLE MYFT1A OK BADDRV RTWP Immediate error return MYFT1A LI R0,PADSAV Save contents of PAD to VDP LI R1,MPAD PAD RAM LI R2,>0100 Do the lot for simplicity BLWP @VMBW Assumed available LI R0,MCODE Code for writing to disk LI R1,MPAD Put in PAD for speed MYFMT2 MOV *R0+,*R1+ Copy it over JNE MYFMT2 Data is null word terminated * Construct track data MYFMT4 LI R2,MBUFFR Point to track buffer LI R3,18 18 sectors/track LI R4,FMTDTA Track data table byte/count JMP MYFMT7 Include track lead in MYFMT6 LI R4,FMTDTB Data table for each sector MYFMT7 MOVB *R4+,R0 Fetch data-byte CB @MBAA,R0 End marker byte ? JNE MYFMT8 No - go write in repeats DEC R3 Count off sectors JNE MYFMT6 More to do JMP MYFM10 Track layout done MYFMT8 MOVB *R4+,R1 Fetch repeat byte-count SRL R1,8 Make word count MYFMT9 MOVB R0,*R2+ Write to buffer DEC R1 Tick off JNE MYFMT9 Next repeat of byte JMP MYFMT7 Go get next data-byte * Set up FDC for track write MYFM10 MOVB *R14+,R0 Fetch drive # AI R0,>300 Massage for CRU drive select MOVB R0,@MYFMT3+1 Write in to CRU instruction MOVB *R14+,R5 Fetch # of sides SRL R5,8 Make word CLR R6 For side 1 - first pass LI R12,>1100 Select FDC DSR CRU base LDCR @MNULL,8 Make sure all reset SBO 0 Turn on DSR SBO 1 Turn on FDC controller MYFMT3 SBO 0 Drive CRU # written to LSB SBZ 2 SBZ 3 RSTORE BL @TRK00 Reset to Track #0 JMP MSKERR Error exit * Write interlace pattern into track data MYFM11 LI R3,40 Tracks/side (80 for 720 Kb) CLR R4 Initialize track # MYFM12 LI R0,MBUFFR+>38 First sector ID pointer LI R1,18 Sectors/track count LI R2,INTLCE Sector interlace pattern MYFM13 MOVB R4,*R0+ Track # MOVB R6,*R0+ Side # MOVB *R2+,*R0 Sector # AI R0,MSCTLN-2 Next sector ID DEC R1 Count off sector JNE MYFM13 More to do BLWP @WRTTRK Write the track to disk JMP WTERR2 Error return DEC R3 Count off a track JEQ MYFM14 Done BL @STEP Step in one track JMP MSKERR Error return AI R4,>100 Next track # JMP MYFM12 Set up next track data MYFM14 AI R6,>100 For disk side 2 SBO 2 Disk side #2 if needed DEC R5 Done ? JNE RSTORE Second side to go INCT R14 Step over error return * Restore PAD and exit WTERR2 EQU $ Error return MSKERR EQU $ LDCR @MNULL,8 Turn it all off LI R0,PADSAV VDP buffer LI R1,MPAD Set up to restore PAD LI R2,>100 Retrieve whole PAD BLWP @VMBR Utility assumed available RTWP Back to main program * Direct track writing code * Timing critical - code and workspace both in PAD * >5F01 is Myarc memory mapped control register address * >5F07 is Myarc memory mapped write register address WRTTRK DATA MGPLWS,WRTTK1 Use GPL Workspace in PAD WRTTK1 LI R4,>5F07 FDC write address in register LI R5,MBUFFR Track data in RAM LI R6,TRKLEN Size of track data LI R7,>4E4E Track run-out byte LI R12,>1100 FDC CRU base SETO R0 Set time-out counter MOVB @WT,@>5F01 Send WRITE command to FDC BL @MPAD BL to MCODE code in PAD INCT R14 Step over error return RTWP Directly here after error * Code block to be moved to PAD for speed MCODE EQU $ Start fast code for PAD TB 1 Want to write JEQ MCODE4 Yeah, go ahead DEC R0 One more time JEQ MCODE2 That's it - return an error TB 1 Ask again to write JEQ MCODE4 Ready now TB 0 Check INTRQ JNE MCODE No, not yet MCODE2 RT MCODE3 TB 1 Want to write again JNE MCODE3 Wait for it MCODE4 MOVB *R5+,*R4 Write a byte to the FDC DEC R6 Count it off JNE MCODE3 More to go MCODE5 MOVB R7,*R4 Run-out track to end TB 0 Check INTRQ JNE MCODE5 Not done yet INCT R11 Step over error return RT MNULL DATA 0 Null flag ends copy to PAD *------- * Head control subroutines with error branch * Call as * BL @TRK00 - Restore head to track #0 * BL @STEP - Step head in one track * JMP ERR <- seek/drive error *---------- TRK00 MOVB @T0,@>5F01 Send RESTORE command to FDC JMP INTRQ STEP MOVB @SI,@>5F01 Send STEP-IN command to FDC INTRQ LI R1,2 Set outside loop counter INTRQ1 SETO R0 Set error counter INTRQ2 TB 0 INTRQ ? JEQ INTRQ3 Yes - exit normally DEC R0 Inner loop run out ? JNE INTRQ2 No - keep waiting DEC R1 Yes - outer loop done ? JNE INTRQ1 No - reset inner loop JMP INTRQ4 Yes - exit with error INTRQ3 INCT R11 Step over error JMP INTRQ4 RT -- ----------------------------------------------------------- arvcm@cc.newcastle.edu.au -----------------------------------------------------------