?login_element?

Subversion Repositories NedoOS

Rev

Rev 608 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. insertbyte
  2. ;ahl=insert addr        
  3. ;c=symbol
  4. ;out: ahl=next addr (kills bc,de)
  5.         push af
  6.         push hl
  7.  
  8.          push bc ;c=symbol
  9.         push af
  10.         push hl
  11.         call incfilesize ;before! because we can access new page
  12.          call setchanged
  13.         pop hl
  14.         pop af
  15.          pop de ;e=symbol
  16.  
  17. insertbyte_pg0
  18. ;ahl=addr
  19. ;e=symbol
  20.           push af
  21.           push hl
  22.         call ahl_to_pgaddr_pgsizeafter ;hl=phys addr, bc=block size after hl (may be 0!) (keeps de)
  23.         push bc
  24.         call insertbyte_ldirbc
  25.         pop bc
  26.           pop hl
  27.           pop af
  28.         add hl,bc
  29.         adc a,0
  30. ;ahl=addr for next block
  31. ;e=symbol for next block (out-of-text for eof)
  32.         call iseof
  33.         jr nz,insertbyte_pg0
  34.        
  35.         pop hl
  36.         pop af ;insert addr
  37. nextbyte
  38.         ld bc,1
  39.         add hl,bc
  40.         adc a,b;0
  41.         ret
  42.  
  43. deletebyte
  44. ;ahl=delete addr (kept) (kills bc,de)
  45.         push af
  46.         push hl
  47.  
  48. deletebyte_pg0
  49. ;ahl=addr        
  50.           push af
  51.           push hl
  52.         call ahl_to_pgaddr_pgsizeafter ;hl=phys addr, bc=block size after hl (may be 0!) (keeps de)
  53.          call setchanged
  54. ;hl=byte addr to delete
  55. ;bc=size from hl to end
  56.         push bc
  57.         call deletebyte_ldirbc
  58.         pop bc
  59.           pop hl
  60.           pop af
  61.         add hl,bc
  62.         adc a,0
  63. ;ahl=addr for next block
  64.         call iseof
  65.         jr z,deletebyte_pgq
  66. ;copy first byte of next block to last byte of this block
  67.         push af
  68.         push hl
  69.         call ahl_to_pgaddr;_pgsizeafter ;hl=phys addr, bc=block size after hl (may be 0!) (keeps de)
  70.         ld e,(hl) ;first byte of next block
  71.         pop hl
  72.         pop af
  73.         push af
  74.         push hl
  75.          dec hl ;last byte of this block
  76.         call ahl_to_pgaddr;_pgsizeafter ;hl=phys addr, bc=block size after hl (may be 0!) (keeps de)
  77.         ld (hl),e
  78.         pop hl
  79.         pop af
  80.         jr deletebyte_pg0
  81.        
  82. deletebyte_pgq
  83.         call decfilesize ;after! because we can access deleted last page
  84.         pop hl
  85.         pop af ;delete addr
  86.         ret
  87.  
  88. deletebyte_ldirbc
  89. ;hl=byte addr to delete
  90. ;bc=size from hl to end (may be 0!)
  91.         dec bc ;bc=size from ahl+1 to end
  92.         ld a,b
  93.         or c
  94.         ret z
  95.         ld d,h
  96.         ld e,l
  97.         inc hl
  98.         ld a,b
  99.         or c
  100.         ret z ;jr z,$+4
  101.         ldir
  102.         ret        
  103.  
  104. ;reserves page
  105. incfilesize
  106.         ;ld hl,(fcb+FCB_FSIZE)
  107.         call getsize
  108.        
  109.         push af
  110.         push hl
  111.         ld a,h
  112.         and 0x3f
  113.         or l
  114.         call z,reservepage
  115.         pop hl
  116.         pop af
  117.        
  118.         ld bc,1
  119.         add hl,bc
  120.         adc a,b;0
  121.         ld (filesize),hl
  122.         ld (filesizeHSW),a
  123.         ret
  124.  
  125. ;unreserves page
  126. decfilesize
  127.         ;ld hl,(fcb+FCB_FSIZE)
  128.         call getsize
  129.         or a
  130.         ld bc,1
  131.         sbc hl,bc
  132.         sbc a,b;0
  133.         ld (filesize),hl
  134.         ld (filesizeHSW),a
  135.  
  136.         ld a,h
  137.         and 0x3f
  138.         or l
  139.         call z,unreservepage
  140.         ret
  141.  
  142.  
  143. ahl_to_pgaddr_pgsizeafter
  144. ;ahl=addr
  145. ;out: hl=phys addr, bc=block size after hl (may be 0!) (keeps de)
  146.         push af
  147.         push hl
  148.         ld l,h
  149.         ld h,a
  150.         add hl,hl
  151.         add hl,hl
  152.         push hl ;h=page number
  153.         call getsize
  154.         ld c,h
  155.         rl c
  156.         rla
  157.         rl c
  158.         rla
  159.         ld c,a ;c=end page number
  160.         pop af ;page number
  161.         cp c
  162.         ld bc,0x4000
  163.         jr nz,ahl_to_pgaddr_pgsize_noend
  164.         ;size=hl&0x3fff
  165.         ;add hl,hl
  166.         ;add hl,hl
  167.         ;srl h
  168.         ;srl h
  169.         ld a,h
  170.         and 0x3f
  171.         ld b,a
  172.         ld c,l
  173. ahl_to_pgaddr_pgsize_noend
  174. ;bc=pg size (may be 0!)
  175.         pop hl
  176.         pop af
  177.         call ahl_to_pgaddr ;hl=phys addr (keeps bc)
  178.         push hl
  179.         res 7,h
  180.         ;res 6,h
  181.         ld a,c
  182.         sub l
  183.         ld c,a
  184.         ld a,b
  185.         sbc a,h
  186.         ld b,a ;bc=block size after hl (may be 0!)
  187.         pop hl
  188.         ret
  189.        
  190. insertbyte_ldirbc
  191. ;e=byte to insert
  192. ;hl=byte addr to insert
  193. ;bc=size from hl to end (may be 0!)
  194. ;out: e=deleted last byte, [hl=end addr]
  195.         ld a,b
  196.         or c
  197.         ret z
  198.         ld a,e
  199.         add hl,bc ;end addr
  200.         dec hl
  201.         ld e,(hl)
  202.         push de ;d=deleted last byte
  203.         ld d,h
  204.         ld e,l
  205.         inc de
  206.         ;push de ;end addr
  207.         dec hl
  208.         dec de
  209.         push af
  210.         dec bc
  211.         ld a,b
  212.         or c
  213.         jr z,$+4
  214.         lddr
  215.         pop af
  216.         ;pop hl ;end addr
  217.         ld (de),a
  218.         pop de ;e=deleted last byte
  219.         ret
  220.        
  221. prevbyte
  222.         ld bc,1
  223.         or a
  224.         sbc hl,bc
  225.         sbc a,b;0
  226.         ret
  227.        
  228. getbyte
  229.         push af
  230.         push hl
  231.         call ahl_to_pgaddr
  232.         ld c,(hl)
  233.         pop hl
  234.         pop af
  235.         ret
  236.        
  237. pgaddr_to_ahl
  238. ;de = new addr (bits 13..0), bit 14 = overflow
  239. ;ahl = old addr
  240.         bit 6,d
  241.         ld bc,0x4000
  242.         jr z,$+4
  243.         add hl,bc
  244.         adc a,c;0
  245.         ld c,a
  246.         ld l,e
  247.         ld a,d
  248.         xor h
  249.         and 0x3f
  250.         xor h
  251.         ld h,a ;bits 13..0 copied
  252.         ld a,c ;ahl = new addr
  253.         ret ;nc
  254.  
  255. reservepage
  256. ;new page, set page in textpages, npages++, set page in #c000
  257. ;nz=error
  258.         OS_NEWPAGE
  259.         or a
  260.         ret nz
  261. npages=$+1
  262.         ld hl,textpages
  263.         ld (hl),e
  264.         inc l
  265.         ld (npages),hl
  266.         ld a,e
  267.         SETPG32KHIGH
  268.         xor a
  269.         ret ;z
  270.  
  271. unreservepages
  272. unreservepages0
  273.         call unreservepage
  274.         jr z,unreservepages0
  275.         ret
  276.        
  277. unreservepage
  278. ;del page, npages--
  279. ;nz=error
  280.         ld hl,(npages)
  281.         ld a,l
  282.         or a
  283.         jr z,unreservepage_fail
  284.         dec l
  285.         ld (npages),hl
  286.         ld e,(hl)
  287.         OS_DELPAGE
  288.         xor a
  289.         ret ;z
  290. unreservepage_fail
  291.         xor a
  292.         dec a
  293.         ret ;nz
  294.        
  295. ahl_to_pgaddr
  296. ;keeps bc,de
  297. ;counts physical hl
  298.         rl h
  299.         rla
  300.         rl h
  301.         rla
  302.         srl h
  303.         scf
  304.         rr h
  305.         push bc
  306.         call setpg32k
  307.         pop bc
  308.         ret
  309.  
  310. setpg32k
  311. ;a=page number in table (0..)
  312.         push hl
  313.         ld l,a
  314.         ld h,textpages/256
  315.         ld a,(hl)
  316.         SETPG32KLOW
  317.         inc l
  318.         ld a,(hl)
  319.         SETPG32KHIGH
  320.         pop hl
  321.         ret
  322.        
  323.         align 256
  324. textpages
  325.         ds 256
  326.