home *** CD-ROM | disk | FTP | other *** search
- ;bput"c2sec.src
- ;rput"c2sec.src
- ;
- ;+++++++++++++++++++++++++++++++++
- ;+ sector, sat, and disk address +
- ;+ routines. +
- ;+ entry points: +
- ;+* sec2cyldcb - convert secnum to +
- ;+ msbsec, lsb, head format. +
- ;+* sec2cyldcb1 - convert cylmsb and +
- ;+ sector number to msbsec +
- ;+ format with output in +
- ;+ cylmsb. +
- ;+* sectr2cylindr - convert secnum to +
- ;+ cylmsb, cyllsb, head, +
- ;+ sector. +
- ;+* sat2sector - convert satsec, +
- ;+ satbyt, and satbit to a +
- ;+ sector number. +
- ;+* sector2sat - convert secnum to +
- ;+ sat entry. input is x - +
- ;+ hi byte of secnum, a - mid +
- ;+ byte of secnum, and y - low+
- ;+ byte of secnum. +
- ;+* cyl2sectordcb - convert dcb format +
- ;+ disk address to secnum. +
- ;+ input: a - drive-head +
- ;+ x - msb cylinder +
- ;+ y - lsb cylinder +
- ;+* cylinder2sectr - convert head, cyllsb+
- ;+ cylmsb, & sector to secnum.+
- ;+++++++++++++++++++++++++++++++++
- ;
- ;+++++++++++++++++++++++++++++++++
- ;+the following areas are used by+
- ;+ these subroutines. +
- ;+-------------------------------+
- ;+ shifts 1 byte work +
- ;+ worka 3 byte work area +
- ;+ workb 2 byte work area +
- ;+ workc 2 byte work area +
- ;+ secnum 3 byte sector number in+
- ;+ hi, med, lo format +
- ;+ satsec 1 byte sat sector +
- ;+ satbyt 2 byte byte offset in +
- ;+ sat sector. hi, lo +
- ;+ satbit 1 byte bit mask of sat +
- ;+ sector byte +
- ;+ cylmsb 1 byte msb of cylinder +
- ;+ cyllsb 1 byte lsb of cylinder +
- ;+ head 1 byte head number +
- ;+ sector 1 byte sector number +
- ;+ sectrk 1 byte number of +
- ;+ sectors per track +
- ;+ seccyl 1 byte number of +
- ;+ sectors per cylinder +
- ;+++++++++++++++++++++++++++++++++
- ;
- ;
- ;+++++++++++++++++++++++++++++++++
- ;+ convert relative sector number+
- ;+ to cylinder, head and sector. +
- ;+ +
- ;+ input - field secnum which +
- ;+ contains the relative sector.+
- ;+ +
- ;+ output - fields head, cyllsb, +
- ;+ cylmsb, and sector filled and+
- ;+ a - head number +
- ;+ y - cylinder lsb +
- ;+ x - sector and cyl msb +
- ;+++++++++++++++++++++++++++++++++
- ;
- ;
- sec2cyldcb jsr sectr2cylindr ;go convert
- sec2cyldcb1 ldx #6 ;put chr in dcb form
- lda cylmsb
- shiftmsbleft asl a
- dex
- bne shiftmsbleft
- ora sector
- sta cylmsb
- rts ;tis done
- ;
- sectr2cylindr lda #0 ;zero work, etc.
- sta workb
- sta workb+1
- sta workc+1
- sta head
- sta cylmsb
- sta cyllsb
- ldx #2 ;move secnum to work a
- movesecnum2a lda secnum,x
- sta worka,x
- dex
- bpl movesecnum2a
- jsr defset ;get ptr to parmtab
- lda ptscyl,x ;get sector per cyl
- sta workc ;times hex 100
- inc workb ;make counter 256
- ldx #9 ;prime count down
- calccylinder jsr dividesector ;go subtract
- bcc updateoperands
- lda workb+1
- clc
- adc cyllsb
- sta cyllsb
- lda workb
- adc cylmsb
- sta cylmsb
- jmp calccylinder ;go see if more
- ;
- updateoperands lsr workb ;adjust adder
- ror workb+1
- lsr workc ;shift divisor
- ror workc+1
- dex
- bne calccylinder ;try some more
- lda #17 ;get num sec per trk
- sta workc+1 ;in subtractor
- calculatehead jsr dividesector ;go subtract
- bcc savesectornum ;go if done
- inc head
- bne calculatehead
- savesectornum lda worka+2 ;get sector num
- sta sector
- rts
- ;
- ;
- ;+++++++++++++++++++++++++++++++++
- ;+ subtract workc from work a if +
- ;+ worka >= workc +
- ;+ return carry set for didit. +
- ;+ return carry clear for small. +
- ;+++++++++++++++++++++++++++++++++
- ;
- dividesector lda worka ;check hi sec byt
- bne subtractem
- lda worka+1 ;check second byte
- cmp workc ;for <=
- bcc dividereturn ;go if too small
- bne subtractem ;go not equal
- lda worka+2 ;check low byte
- cmp workc+1
- bcc dividereturn ;too small go on
- subtractem lda worka+2 ;subtract
- sec
- sbc workc+1
- sta worka+2
- lda worka+1
- sbc workc
- sta worka+1
- lda worka
- sbc #0
- sta worka
- sec
- dividereturn rts
- ;
- ;+++++++++++++++++++++++++++++++++
- ;+ convert satsec, satbyt, and +
- ;+ satbit to relative sector #. +
- ;+ +
- ;+ input - fields satsec, satbyt +
- ;+ and satbit. +
- ;+ +
- ;+ output- relative sector in +
- ;+ secnum. +
- ;+++++++++++++++++++++++++++++++++
- ;
- sat2sector lda #0 ;init sector num
- sta secnum
- ldx #4 ;number to shift
- lda satsec ;get field
- shiftsatseclf asl a
- rol secnum
- dex
- bne shiftsatseclf
- sta secnum+1
- lda satbyt ;get hi
- sta worka
- ldx #3 ;multiply by 8
- lda satbyt+1 ;now lo byte offset
- shiftsatbytlf asl a
- rol worka
- dex
- bne shiftsatbytlf
- sta secnum+2
- clc
- lda worka ;add hi byte
- adc secnum+1
- sta secnum+1
- lda satbit ;get the bit number
- ldx #0
- shiftsatbitlf asl a ;shift till it goes
- bcs addtosecnum ;out
- inx
- bne shiftsatbitlf
- addtosecnum txa ;set up for add
- jmp addbyte2secnum
- ;clc
- ;adc secnum+2 ;add to total
- ;sta secnum+2
- ;bcc sat2secreturn
- ;inc secnum+1 ;else add overflow
- ;bne sat2secreturn
- ;inc secnum
- ;sat2secreturn rts ;return
- ;
- ;+++++++++++++++++++++++++++++++++
- ;+ convert sector number to sat +
- ;+ entry. +
- ;+ +
- ;+ input: a-middle byte of secnum+
- ;+ x-hi byte of secnum +
- ;+ y-lo byte of secnum +
- ;+ +
- ;+ +
- ;+ output: sat sector, byte, and +
- ;+ bit in byte. +
- ;+ satsec - sector number of sate+
- ;+ satbyt - byte of sate +
- ;+ satbit - bit of byte +
- ;+++++++++++++++++++++++++++++++++
- ;
- sector2sat sta satsec ;a has middle byte
- and #$0f ;isolate low 12 bits for
- sta satbyt ;for satbyt
- txa ;get hi byte of secnum
- ldx #4 ;need to shift for satsec
- divideby4096 lsr a ;satsec = int(secnum/4096)
- ror satsec
- dex
- bne divideby4096 ;do all 4 shifts
- tya ;get low byte of secnum
- sta satbyt+1 ;put in offset
- and #$07 ;isolate the bit number
- tax ;now put bit in its place
- lda #$80 ;prime bit
- shiftsec dex ;check if thru
- bmi savesatbit
- lsr a
- bne shiftsec
- savesatbit sta satbit ;now have bit
- ldx #3 ;now divide byte offset by 8
- dividsatbytby8 lsr satbyt
- ror satbyt+1
- dex
- bne dividsatbytby8
- rts
- ;
- ;+++++++++++++++++++++++++++++++++
- ;+ convert cylinder, head, sector+
- ;+ to sector number. +
- ;+ +
- ;+ there are 2 entries to this +
- ;+ subroutine. +
- ;+ cyl2sectordcb - input is as follows +
- ;+ a - drive-head byte +
- ;+ x - msb-sector +
- ;+ y - lsb cylinder +
- ;+ +
- ;+ cylinder2sectr - the following fields +
- ;+ must be initialized before+
- ;+ calling this entry. +
- ;+ head, sector, cyllsb, cylmsb +
- ;+ +
- ;+++++++++++++++++++++++++++++++++
- ;
- cyl2sectordcb sty cyllsb ;put in lsb of cylinder
- and #$0f ;isolate just the head
- sta head
- txa ;get msb and sector
- and #$1f ;isolate sector number
- sta sector
- txa ;now handle msb of cylinder
- ldx #6 ;number of shifts
- shiftdownmsb lsr a
- dex
- bne shiftdownmsb
- sta cylmsb ;put it away
- ;
- cylinder2sectr lda #0 ;clear the result field
- sta secnum
- sta secnum+1
- sta secnum+2
- ldy #8 ;prime shifts
- jsr defset ;get parm tab offset
- lda ptscyl,x ;and sector per cyl
- sta workb
- muliplycylindr = * ;clear carry
- lda cyllsb ;get low cyl number
- sta worka+2
- lda cylmsb ;get high cyl number
- sta worka+1
- lda #0 ;clear next work
- sta worka
- dey
- asl workb ;shift sec/cyl
- bcc anymoreshifts
- tya ;move to x
- tax
- beq addtosecnum2
- clc
- shiftworkal asl worka+2
- rol worka+1
- rol worka
- dex
- bne shiftworkal
- addtosecnum2 ldx #2
- clc
- addtosecnumlp lda secnum,x
- adc worka,x
- sta secnum,x
- dex
- bpl addtosecnumlp
- anymoreshifts cpy #0 ;any more?
- bne muliplycylindr
- ;+ add in head x sector per trk
- ldx head ;get counter
- beq addsect2secnum ;go if head 0
- addheadxsectrk lda #17 ;get sectors per track
- jsr addbyte2secnum ;go add to total
- dex
- bne addheadxsectrk
- ;+ add the sector
- addsect2secnum lda sector
- jsr addbyte2secnum
- lda secnum
- ldx secnum+1
- ldy secnum+2
- rts
- addbyte2secnum clc
- adc secnum+2
- sta secnum+2
- bcc addalldone
- inc secnum+1
- bne addalldone
- inc secnum
- addalldone = *
- rts
- ;
- .end c2sec
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-