home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / KAYPRO / KPNUROM.LBR / KDEBLOCK.ZQ0 / KDEBLOCK.Z80
Text File  |  2000-06-30  |  7KB  |  253 lines

  1. title    Kaypro 4-83 Resident Software Package
  2. subttl    Deblocking
  3. ;
  4.     extrn    denflag, sekdsk, seksec, sektrk
  5.     extrn    move
  6.     extrn    rd, readhst
  7.     extrn    wrt, writehst
  8. ;
  9.     entry    read, write, setdma
  10. ;
  11.     entry    hstdsk, hsttrk, hstsec, hstbuf
  12.     entry    hstwrt, hstact, unacnt, erflag
  13. ;
  14.     dseg
  15. ;
  16. ; Disk deblocking etc.
  17. hstdsk:    ds    1;    host disk number
  18. hsttrk:    ds    2;    host track number
  19. hstsec:    ds    1;    host sector number
  20. sekhst:    ds    1;    seek shr secshf
  21. hstact:    ds    1;    host active flag
  22. hstwrt:    ds    1;    host written flag
  23. unacnt:    ds    1;    unallocted record count
  24. unadsk:    ds    1;    last unallocated disk
  25. unatrk:    ds    2;    last unallocated track
  26. unasec:    ds    1;    last unallocated sector
  27. erflag:    ds    1;    error reporting
  28. rsflag:    ds    1;    read sector flag
  29. readop:    ds    1;    1 if read operation
  30. wrtype:    ds    1;    write operation type
  31. dmaadr:    ds    2;    current DMA address
  32. hstbuf:    ds    512;    deblocking buffer
  33. ;
  34. ;
  35.     cseg
  36. ;
  37. ;*****************************************************
  38. ;*      Logical BIOS entry points                    *
  39. ;*      Sector Deblocking Algorithms                 *
  40. ;*****************************************************
  41. blksiz    equ    1024        ;CP/M allocation size
  42. hstsiz    equ    512        ;host disk sector size
  43. hstspt    equ    10        ;host disk sectors/trk
  44. hstblk    equ    hstsiz/128    ;CP/M sects/host buff
  45. cpmspt    equ    hstblk * hstspt    ;CP/M sectors/track
  46. secmsk    equ    hstblk-1    ;sector mask
  47. secshf    equ    2        ;log2(hstblk) sector mask
  48. wrall    equ    0        ;write to allocated
  49. wrdir    equ    1        ;write to directory
  50. wrual    equ    2        ;write to unallocated
  51. ;
  52. ; --------------------------------------------------------
  53. ;
  54. ; set current dma address
  55. setdma:    ld    (dmaadr),bc;    set dma address given by BC
  56.     ret
  57. ;
  58. ; read selected logical sector
  59. read:    ld    a,(denflag);    read the selected CP/M sector
  60.     or     a
  61.     ld    hl,(dmaadr)
  62.     ex    de,hl
  63.     ld    b,1;        sector record
  64.     jp    nz,rd;        single density read into dmaadr
  65.     xor    a;         a patch by DRI
  66.     ld    (unacnt),a
  67.     ld    a,1
  68.     ld    (readop),a;    read operation
  69.     ld    (rsflag),a;    must read data
  70.     ld    a,wrual
  71.     ld    (wrtype),a;    treat as unalloc
  72.     jp    rwoper;        to perform the read
  73. ;
  74. ; write selected logical sector
  75. write:    ld    a,(denflag);    write the selected CP/M sector
  76.     or     a
  77.     ld    hl,(dmaadr)
  78.     ex    de,hl
  79.     ld    b,1;        sector record
  80.     jp    nz,wrt;        single density write from dmaadr
  81.     xor    a;        0 to accumulator
  82.     ld    (readop),a;    not a read operation
  83.     ld    a,c;        write type in c
  84.     ld    (wrtype),a
  85.     cp    wrual;        write unallocated?
  86.     jp    nz,chkuna;    check for unalloc
  87. ;     "     "
  88. ; write to unallocated, set parameters
  89.     ld    a,blksiz/128;    next unalloc recs
  90.     ld    (unacnt),a
  91.     ld    a,(sekdsk);    disk to seek
  92.     ld    (unadsk),a;    unadsk = sekdsk
  93.     ld    hl,(sektrk)
  94.     ld    (unatrk),hl;    unatrk = sectrk
  95.     ld    a,(seksec)
  96.     ld    (unasec),a;    unasec = seksec
  97. ;     "     "
  98. ; check for write to unallocated sector
  99. chkuna:    ld    a,(unacnt);    any unalloc remain?
  100.     or    a
  101.     jp    z,alloc;    skip if not
  102. ;     "     "
  103. ; more unallocated records remain
  104.     dec    a;        unacnt = unacnt-1
  105.     ld    (unacnt),a
  106.     ld    a,(sekdsk);    same disk?
  107.     ld    hl,unadsk
  108.     cp    (hl);        sekdsk = unadsk?
  109.     jp    nz,alloc;    skip if not
  110. ;    "    "
  111. ; disks are the same
  112.     ld    hl,unatrk
  113.     call    cpsktrk;    sektrk = unatrk?
  114.     jp    nz,alloc;    skip if not
  115. ;     "     "
  116. ; tracks are the same
  117.     ld    a,(seksec);    same sector?
  118.     ld    hl,unasec
  119.     cp    (hl);        seksec = unasec?
  120.     jp    nz,alloc;    skip if not
  121. ;     "     "
  122. ; match, move to next sector for future ref
  123.     inc    (hl);        unasec = unasec+1
  124.     ld    a,(hl);        end of track?
  125.     cp    cpmspt;        count CP/M sectors
  126.     jp    c,noovf;    skip if no overflow
  127. ;     "     "
  128. ; overflow to next track
  129.     ld    (hl),0;        unasec = 0
  130.     ld    hl,(unatrk)
  131.     inc    hl
  132.     ld    (unatrk),hl;    unatrk = unatrk+1
  133. ;     "     "
  134. ; match found, mark as unnecessary read
  135. noovf:    xor    a;        0 to accumulator
  136.     ld    (rsflag),a;    rsflag = 0
  137.     jp    rwoper;        to perform the write
  138. ;
  139. ; not an unallocated record, requires pre-read
  140. alloc:    xor    a;        0 to accum
  141.     ld    (unacnt),a;    unacnt = 0
  142.     inc    a;        1 to accum
  143.     ld    (rsflag),a;    rsflag = 1
  144. ;     "     "
  145. ; *    Common code for READ and WRITE follows       *;
  146. ; enter here to perform the read/write
  147. rwoper:    xor    a;        zero to accum
  148.     ld    (erflag),a;    no errors (yet)
  149.     ld    a,(seksec);    compute host sector
  150.     or    a;        carry = 0
  151.     rra;            shift right
  152.     or    a;        carry = 0
  153.     rra;            shift right
  154.     ld    (sekhst),a;    host sector to seek
  155. ;    "    "        active host sector?
  156.     ld    hl,hstact;    host active flag
  157.     ld    a,(hl)
  158.     ld    (hl),1;        always becomes 1
  159.     or    a;        was it already?
  160.     jp    z,filhst;    fill host if not
  161. ;    "    "
  162. ; host buffer active, same as seek buffer?
  163.     ld    a,(sekdsk)
  164.     ld    hl,hstdsk;    same disk?
  165.     cp    (hl);        sekdsk = hstdsk?
  166.     jp    nz,nomatch
  167.     ld    hl,hsttrk;    same disk, is it same track?
  168.     call    cpsktrk;    sektrk = hsttrk?
  169.     jp    nz,nomatch
  170. ;    "    "        same disk, same track, same buffer?
  171.     ld    a,(sekhst)
  172.     ld    hl,hstsec;    sekhst = hstsec?
  173.     cp    (hl)
  174.     jp    z,match;    skip if match
  175. ;    "    "
  176. ; proper disk but not correct sector
  177. nomatch:
  178.     ld    a,(hstwrt);    host written?
  179.     or    a
  180.     call    nz,writehst;    clear host buff
  181. ;     "     "
  182. ; may have to fill the host buffer
  183. filhst:    ld    a,(sekdsk)
  184.     ld    (hstdsk),a
  185.     ld    hl,(sektrk)
  186.     ld    (hsttrk),hl
  187.     ld    a,(sekhst)
  188.     ld    (hstsec),a
  189.     ld    a,(rsflag);    need to read?
  190.     or    a
  191.     call    nz,readhst;    yes, if 1
  192.     xor    a;        0 to accum
  193.     ld    (hstwrt),a;    no pending write
  194. ;     "     "
  195. ; copy data to or from buffer
  196. match:    ld    a,(seksec);    mask buffer number
  197.     and    secmsk;        least signif bits
  198.     ld    l,a;        ready to shift
  199.     ld    h,0;        double count
  200.     add    hl,hl;        shift left 7
  201.     add    hl,hl
  202.     add    hl,hl
  203.     add    hl,hl
  204.     add    hl,hl
  205.     add    hl,hl
  206.     add    hl,hl
  207. ;    "    "        hl has relative host buffer address
  208.     ld    de,hstbuf
  209.     add    hl,de;        hl = host address
  210.     ld    de,(dmaadr);    de = dma address
  211.     ld    bc,128;        length
  212.     ld    a,(readop);    which way?
  213.     or    a
  214.     jp    nz,rwmove;    skip if read
  215. ;    "    "
  216. ; write operation, mark and switch direction
  217.     ld    a,1
  218.     ld    (hstwrt),a;    hstwrt = 1
  219.     ex    de,hl;        source/dest swap
  220. ;     "     "
  221. rwmove:    call    move;        move a logical sector to/from buffer
  222. ;     "     "
  223. ; data has been moved to/from host buffer
  224.     ld    a,(wrtype);    write type
  225.     cp    wrdir;        to directory?
  226.     ld    a,(erflag);    in case of errors
  227.     ret    nz;        no further processing
  228. ;     "     "
  229. ; clear host buffer for directory write
  230.     or    a;        errors?
  231.     ret    nz;        skip if so
  232.     xor    a;        0 to accum
  233.     ld    (hstwrt),a;    buffer written
  234.     call    writehst
  235.     ld    a,(erflag)
  236.     ret
  237. ;
  238. ;*    Utility subroutine for 16-bit compare        *;
  239. ;    HL = .unatrk or .hsttrk, compare with sektrk
  240. cpsktrk:
  241.     ex    de,hl
  242.     ld    hl,sektrk
  243.     ld    a,(de);        low byte compare
  244.     cp    (hl);        same?
  245.     ret    nz;        return if not
  246.     inc    de;        low bytes equal, test hi byte
  247.     inc    hl
  248.     ld    a,(de)
  249.     cp    (hl);    sets flags
  250.     ret
  251. ;
  252.     end
  253.