home *** CD-ROM | disk | FTP | other *** search
/ CBM Funet Archive / cbm-funet-archive-2003.iso / cbm / documents / projects / drives / 64hdproj.sfx / c64sat.src < prev    next >
Encoding:
Text File  |  1990-02-12  |  3.9 KB  |  172 lines

  1. ;bput"sat.src
  2. ;rput"sat.src
  3. ;
  4. ;+++++++++++++++++++++++++++++++++
  5. ;+  allocate and de-allocate     +
  6. ;+  a sector in the sector       +
  7. ;+  allocation table.            +
  8. ;+                               +
  9. ;+ input for de-allocate:        +
  10. ;+    sector number to free.     +
  11. ;+                               +
  12. ;+ output for de-allocate:       +
  13. ;+    satbit is set on.          +
  14. ;+                               +
  15. ;+ input for allocate: none      +
  16. ;+                               +
  17. ;+ output for allocate:          +
  18. ;+    satbit turned off, and     +
  19. ;+    sector number of the       +
  20. ;+    newly allocated sector.    +
  21. ;+++++++++++++++++++++++++++++++++
  22. ;
  23. satsecptr = $fb ;and fc
  24. ;
  25. allocatesat lda freesatsector
  26.  cmp currentsat ;is it same as sat in buffer?
  27.  beq allocatesat1
  28. allocateread jsr readsatsector ;go get the sector
  29.  bcc allocatesat1
  30.  rts ;return with error
  31. allocatesat1 jsr setsatptrs
  32.  ldx #0 ;set counter
  33.  ldy #0 ;index pointer
  34. allocatesat2 lda (satsecptr),y ;any free?
  35.  bne allocatesat3 ;go if so
  36.  iny
  37.  bne allocatesat2
  38.  inx
  39.  cpx #2 ;got em all?
  40.  beq allocatesat2a
  41.  inc satsecptr+1 ;bump page
  42.  bne allocatesat2
  43. allocatesat2a = *
  44.  inc freesatsector ;bump
  45.  jsr defset ;get x ptr to table
  46.  lda freesatsector ;get number
  47.  cmp ptfdir,x ;was there no room?
  48.  bne allocateread
  49.  sec ;return with carry for no room
  50.  rts
  51. allocatesat3 sty satbyt ;save offset
  52.  stx satbyt+1
  53.  ldx #$80 ;set bit pointer
  54.  stx satbit
  55. allocatesat4 asl a ;shift a bit
  56.  bcs allocatesat5
  57.  lsr satbit
  58.  bne allocatesat4
  59. allocatesat5 jsr defset ;get drive ptr
  60.  lda currentsat
  61.  sta satsec ;save the sector number
  62.  lda (satsecptr),y ;turn off bit
  63.  eor satbit
  64.  sta (satsecptr),y ;to allocate
  65.  lda #1 ;set satbuffer needs to be
  66.  sta satbufferflag ;written
  67.  clc
  68.  rts ;return to caller with success
  69. ;
  70. ;++ de-allocate a sector by turning
  71. ;++ on the bit in the sat sector.
  72. ;
  73. deallocatesats tay ;setup for conversion
  74.  lda #0
  75.  tax
  76.  jsr sector2sat ;to sat format
  77.  jmp deallocatesat
  78. ;++ the following requires that
  79. ;++ satsec, satbyt, and satbit be
  80. ;++ primed.
  81. allocabsolutes tay ;set up for conversion
  82.  lda #0
  83.  tax
  84.  jsr sector2sat
  85. allocabsolute lda satbit ;invert
  86.  eor #$ff ;the bits
  87.  sta satbit
  88.  lda #255 ;set absolute alloc flag
  89.  .byt $2c ;bit
  90. deallocatesat lda #0
  91.  sta allocdeallocfl
  92.  lda satsec ;see if in memory
  93.  cmp currentsat
  94.  beq deallocatesat1
  95.  jsr readsatsector
  96.  bcc deallocatesat1
  97.  rts ;return if error
  98. deallocatesat1 jsr setsatptrs ;addrress buffer
  99.  lda #>satbuffer
  100.  clc
  101.  adc satbyt
  102.  sta satsecptr+1
  103.  ldy satbyt+1 ;get rest of offset
  104.  lda (satsecptr),y
  105.  ldx allocdeallocfl ;check type
  106.  bmi allocabsol
  107.  ora satbit
  108.  jmp allocdeallocsv
  109. allocabsol and satbit
  110. allocdeallocsv = *
  111.  sta (satsecptr),y
  112.  lda #1 ;set need write flag
  113.  sta satbufferflag
  114.  clc ;indicate success
  115.  rts ;return to caller
  116. ;
  117. readsatsector = * ;read sat sector
  118.  pha
  119.  ldx satbufferflag ;buffer need to be written?
  120.  beq readsatsector1 ;on if not
  121.  lda currentsat ;get sector to save
  122.  jsr writesatsector ;write it out
  123.  bcc readsatsector1
  124.  pla
  125.  rts ;return with carry for error
  126. readsatsector1 pla ;get saved sector
  127.  sta currentsat ;make it current
  128.  jsr satsetupdcb
  129.  jsr read
  130.  rts
  131. satsetupdcb pha ;save for a jiffy
  132.  jsr defset ;get table offset
  133.  pla
  134.  clc ;add offset
  135.  adc ptfsat,x ;sector number
  136.  sta secnum+2
  137.  lda #0
  138.  sta secnum
  139.  sta secnum+1
  140.  jsr sec2cyldcb ;convert to dcb format
  141.  jsr defset
  142.  txa
  143.  ora head ;get drive and head
  144.  sta hdnum
  145.  lda cylmsb
  146.  sta secadr
  147.  lda cyllsb
  148.  sta cylnum
  149.  lda #1 ;ensure only one sector
  150.  sta blkcnt
  151.  lda #<satbuffer
  152.  sta bufadr
  153.  lda #>satbuffer
  154.  sta bufadr+1
  155.  rts
  156. writesatsector jsr satsetupdcb
  157.  jsr write
  158.  bcc writesatsectox
  159.  lda #0
  160.  sta satbufferflag
  161.  sec
  162. writesatsectox rts ;return
  163. freesatsector .byt 0 ;first sat with room
  164. setsatptrs lda #<satbuffer
  165.  sta satsecptr
  166.  lda #>satbuffer
  167.  sta satsecptr+1
  168.  rts
  169. satbufferflag .byt 0 ;sector changed flag
  170. currentsat .byt 0 ;sat in buffer
  171. allocdeallocfl .byt 0 ;flag
  172. .end sat.src
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.