?login_element?

Subversion Repositories NedoOS

Rev

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