Advertisement
Cthutu

Memory page allocation

Feb 11th, 2020
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. M_P3DOS         equ     $94             ; +3 DOS function call
  2. IDE_BANK        equ     $01bd           ; NextZXOS function to manage memory
  3.  
  4. ;;----------------------------------------------------------------------------------------------------------------------
  5. ;; Internal routine to allocate a single page from the OS.
  6. ;;
  7. ;; Output:
  8. ;;      A = page # (or 0 if failed)
  9. ;;
  10. ;;----------------------------------------------------------------------------------------------------------------------
  11.  
  12. allocPage:      push    ix
  13.                 push    bc
  14.                 push    de
  15.                 push    hl
  16.  
  17.                 ; Allocate a page by using the OS function IDE_BANK.
  18.                 ld      hl,$0001        ; Select allocate function and allocate from normal memory.
  19.                 exx                     ; Function parameters are switched to alternative registers.
  20.                 ld      de,IDE_BANK     ; Choose the function.
  21.                 ld      c,7             ; We want RAM 7 swapped in when we run this function (so that the OS can run).
  22.                 rst     8
  23.                 db      M_P3DOS         ; Call the function, new page # is in E
  24.                 jr      c,.success
  25.  
  26.                 ; We failed here
  27.                 xor     a
  28.                 ld      e,a             ; Page # is 0 (i.e. error)
  29.  
  30. .success        ld      a,e
  31.                 pop     hl
  32.                 pop     de
  33.                 pop     bc
  34.                 pop     ix
  35.                 ret
  36.  
  37. ;;----------------------------------------------------------------------------------------------------------------------
  38. ;; Internal routine to return a previously allocated page back to the OS.
  39. ;;
  40. ;; Input:
  41. ;;      A = page #
  42. ;;
  43. ;;----------------------------------------------------------------------------------------------------------------------
  44.  
  45. freePage:       push    af
  46.                 push    ix
  47.                 push    bc
  48.                 push    de
  49.                 push    hl
  50.  
  51.                 ld      e,a             ; E = page #
  52.                 ld      hl,$0003        ; Deallocate function from normal memory
  53.                 exx                     ; Function parameters are switched to alternative registers.
  54.                 ld      de,IDE_BANK     ; Choose the function.
  55.                 ld      c,7
  56.                 rst     8
  57.                 db      M_P3DOS
  58.  
  59.                 pop     hl
  60.                 pop     de
  61.                 pop     bc
  62.                 pop     ix
  63.                 pop     af
  64.                 ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement