Subttl -North Star Hard_Sectored Single_Density Format (5_Jul_83) ;================================================================ ; ; Internal DJDMA Routines home equ 0a0h ;DJDMA Home Routine seek equ 0a3h ;DJDMA Seek Routine sdrive equ 0a6h ;DJDMA Select Drive Routine hsync equ 0a9h ;DJDMA Hole Sync. Routine (hard sectored disks only) ; Registers diskd equ 4001h ;Disk Data Port status equ 4003h ;Status Register Location on DJDMA board contrl equ 4007h ;Disk Control Port ; Bit Masks for the disk status port (4003h) INDEX equ 10h ;Index Pulse Mask WRTPRO equ 40h ;Write Protected .z80 nss: ;Define the starting address of the program .phase 1030h nssstr: ;Define the starting address of the code PAGE ;---------------------------------------------------------------------- ; Begin Tables ;------------- ; Parameter Table nsspt: db 4 ;Drive Number db 40 ;Total Number of Tracks db 0 ;Current Track Number db 0 ;Side Number db 0 ;Sector Length Code db 0 ;Starting Sector Number dâ 0 ;Last Sector Number + 1 db 0E5h ;Fill Byte db 0 ;Starting Track of Write Pre-Compensation db 0 ;Pre-Index Gap (Gap_4) db 0 ;Post-Data Field Gap (Gap_3) db 0 ;Flag: Skip Index Mark (0=skip, Not-0=write) db 0 ;Number of Sides (0=1_Side, 1=2_Sides) ds 3,0 ;Spares ; Entry Points nssjt: jp nsse1 ;Fill in parameters jp nsse2 ;Format Initial Entry Point jp nsse3 ;Format Re:Entry Point jp nsse4 ;Format Next Surface (Current Surface Plus One) jp nsse5 ;Format Last Surface (Current Surface Minus One) ; Vectors to Parameters nssvt: dw nsse2+1 ;Drive number (nssform) dw nssnul ;Total Number of Tracks dw nss3 ;Current Track Number dw nssnul ;Current Side Number dw nssnul ;Sector Length Code dw nssnul ;Starting Sector Number dw nssnul ;Last Sector Number + 1 dw nss12+1 ;Fill Byte (data) dw nssnul ;Starting Track of Write Pre-Compensation dw nssnul ;Pre-Index Gap (Gap_4) dw nssnul ;Post-Data Field Gap (Gap_3) dw nssnul ;Flag: Skip Index Mark (0=skip, Not-0=write) dw nssnul ;Number of Sides (0=1_Side, 1=2_Sides) dw nssnul ;Spare dw nssnul ;Spare dw nssnul ;Spare PAGE ;---------------------------------------------------------------------- ; Transfer Parameters Routine ;---------------------------- ; 1) This routine stuffs the values from the parameter table (xxxxpt) ; into the appropriate locations in the code. ; Save the Registers nsse1: push bc ;Save The Primary registers push de push hl ld (nsss1),sp ;save the stack pointer ; Set up the registers for the transfer loop ld sp,nssvt ;SP:= Vector Table ld de,nsspt ;DE:= Parameter Table ld b,16 ;Counter:= max count ; Move the parameters into the code section nsslp: ld a,(de) ;Repeat pop hl ld (hl),a ; Vector_Location:= Parameter inc de djnz nsslp ;Until (all parameters have been transferred) ; Restore the Registers ld sp,(nsss1) ;Restore the stack pointer pop hl pop de pop bc ;Restore the register set ld a,40h ;Flag:= Normal Status ret ;Return PAGE ;---------------------------------------------------------------------- ; Begin The Format Routine ;------------------------- ; ; Initial Entry Point ;-------------------- ; nsse2: ld a,0 ;Select the drive call sdrive ;If (drive is non-Existant) ret nz ; Error Return (81h) Bad Drive Number ld a,(iy+2) ;A:= Drive_Pattern or 0eh ;(Mask out step, side-select & direction bits) ld (4004h),a ;Select the drive ld bc,1000 call nssw ;Wait 1 second for motor to come up to speed ld (ix+0bh),0 ;Reset the index counter (A eq 0) set 2,(ix+0eh) ;set the motor status to on call hsync ;Synchronize with the disk index hole sdexit: ld a,82h ;If (Disk not turning/Not Ready) ret z ; Error Return (82h) Not Ready call home ;Home the disk heads bit 5,(hl) ;If (heads failed to home) jr z,sdexit ; goto Not_Ready error exit ld a,(4003h) ;If (Disk is Write Protected) and WRTPRO ld a,90h ret nz ; Error Return (90h) Write Protect ; Re:Entry Point ;--------------- ; nsse3: ld (ix+0bh),0 ;Reset the index count to zero ld a,(nss3) ;If (Current_Track ne Desired_Track) cp (iy+1) call nz,seek ; Seek Desired_Track ld a,(nss3) ;If (Current_Track eq 0) or a ld a,(nss12+1) ; (initialize to the current fill byte) jr nz,nsskp1 ld a,(nsscnf) ; (Single Density configuration byte) nsskp1: ld (nss13+1),a ; Set the configuration byte PAGE ld (ix+0ah),80h ;Resync with the disk nssws0: call hsync ;If (disk has stopped turning) jr z,sdexit ; goto Not_Ready error exit xor a cp (ix+0ah) jr nz,nssws0 ;(Wait for sector 0) ld a,90h ld (contrl),a ;Set up the controller (82s105) ld hl,diskd ;HL:= Pointer to Disk Data Port ld c,0 ;C:= Current_Sector ld (ix+9),c ;De-sync the disk ;Set number of fill bytes and Control Byte ld b,11h ;B:= Single Density Count of Zero fill ld a,64h ;A:= Single Density Control byte cstart: ld (4006h),a ;Start the controller ;Write Pre-amble nsszro: ld (hl),0 ;Repeat Write a zero to the disk ex (sp),hl ; (kill some time) ex (sp),hl djnz nsszro ;Until Zero fill has been written ;Write Data ID Marks ld (hl),0fbh ;Write Data ID Mark ld b,5ch ;Counter:= Number of byte to the config. byte nss12: ld e,20h ;E:= Fill_Character nss13: ld d,20h ;D:= Configuration_Byte xor a ;A:= Zero ;Write the first 5Ch Fill Bytes sd1lp: ex (sp),hl ;Repeat ex (sp),hl ; (kill some time) ld (hl),e ; Write fill byte xor e rlca djnz sd1lp ;Until (5C Bytes written) PAGE ld b,51h ;Counter:= Remaining Byte count in sector ex (sp),hl ex (sp),hl ld (hl),d ;Write Configuration byte xor d rlca ex Af,Af' ld a,e ld (nss13+1),a ;(Reset the configuration byte to be fill byte) ex Af,Af' ex (sp),hl ex (sp),hl ld (hl),e ;Write another fill byte xor e rlca ;Write the remaining fill bytes sd2lp: ex (sp),hl ;Repeat ex (sp),hl ; (kill some time) ld (hl),e ; Write a Fill Byte xor e rlca ex (sp),hl ex (sp),hl ld (hl),e ; Write another fill byte xor e rlca djnz sd2lp ;Until (remaining fill bytes written) ex (sp),hl ex (sp),hl ;(kill some time) ld (hl),a ;Write a zero fill byte ; Setup the number of pre-amble fill bytes for next sector ld b,11h ;B:= single density post-amble byte count PAGE ;Write the Post_Amble sd4lp: ex (sp),hl ;Repeat ex (sp),hl ; (kill some time) ld (hl),e ; write fill byte ld a,(status) and index jr z,sd4lp ;Until (Next sector/index hole detected) inc c ;If (there's another sector to format) ld a,0ah cp c jr nz,nsszro ; GOTO (write next sector) ld a,0 ld (contrl),a ;Turn off the controller (& write gate) call nss1ms ;Delay 1 Millisecond ld a,40h ;Status:= Normal Return ret PAGE ;---------------------------------------------------------------------- ; Format the Next Surface ;------------------------ ; nsse4: ld a,(nss3) inc a ;Track_Number:= Track_Number + 1 ld (nss3),a call nsse3 ;Format the Track ret ;Return with track value ;---------------------------------------------------------------------- ; Format the Last Surface ;------------------------ ; nsse5: ld a,(nss3) dec a ;Track_Number:= Track_Number - 1 ld (nss3),a call nsse3 ;Format the Track ret ;Return with track value ;---------------------------------------------------------------------- ; Time Delay Routines ;-------------------- ; ; Wait the time Specified in the BC register pair ;------------------------------------------------ ; nssw: call nss1ms ;Repeat dec bc ; Wait a millisecond ld a,b or c jr nz,nssw ;Until (Time_Delay eq 0) ret ; Delay 1 Millisecond ;-------------------- ; nss1ms: push bc ld b,200d ;B:= Tic-Count nss1lp: ld a,a ;Repeat djnz nss1lp ;Until (Tic-count eq 0) pop bc ret ;---------------------------------------------------------------------- ; Data Storage ;------------- ; nss3: db 0 ;Current track number nssnul: db 0 ;Null Parameter Pointer nsss1: dw 0 ;Save location for the stack nsscnf: db 10h ;Single Sided Single Density Configuration Byte nssend: ;Define the ending address of the code .dephase end