home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / util / rsx2.lbr / LOADRSX.MZC / LOADRSX.MAC
Encoding:
Text File  |  1993-06-09  |  3.5 KB  |  154 lines

  1. ;Modified to use the offset passed in A (A=0: real offset is 1 page)
  2. ;Bruce Morgen - June 13, 1987
  3.  
  4. ;This source is copyright 1984 by Jim Lopushinsky to discourage
  5. ;commercial use.
  6. ;
  7. ;This is the relocator subroutine that relocates PRL modules at [HL]
  8. ;to just below the top of TPA, and calls the RSX manager to integrate
  9. ;the relocated module. on entry:
  10. ;
  11. ;    HL    address of PRL module to relocate. It must be on a page 
  12. ;        boundary, and points to the 1 page PRL header.
  13. ;
  14. ;    A    zero -- Relocate just below Top of TPA.
  15. ;        non-zero -- Relocate below the CCP.  Only used by
  16. ;            SETRSX to relocate the RSX manager.
  17. ;
  18. ;March 5/84
  19.  
  20. ;This code is written using Zilog mnemonics, although no Z80-specific
  21. ;instructions are used.  I learned Zilog before Intel, and I find
  22. ;them easier to use and less confusing.
  23. ;
  24.  
  25.     .z80
  26.  
  27.     public    loadrsx
  28.  
  29. bdos    equ    5
  30.  
  31. loadrsx:
  32.     ld    e,a        ;save relocate offset
  33. ;    or    a        ;below the CCP?
  34. ;    jp    z,noccp        ;nope.
  35. ;    ld    e,8        ;8 page offset for CCP
  36. noccp:
  37.     ld    a,l
  38.     or    a        ;test for page boundary
  39.     ld    a,1
  40.     ret    nz        ;return with error if not page boundary
  41.     inc    hl        ;point to PRL code length in PRL header
  42.     ld    c,(hl)        ;get code length in BC
  43.     inc    hl
  44.     ld    b,(hl)
  45.     ld    a,(bdos+2)    ;get top of TPA page
  46.     sub    e        ;adjust for possibility of CCP
  47.     dec    a        ;less 1 page
  48.     dec    bc
  49.     sub    b        ;form target page address
  50.     inc    bc
  51.     cp    15        ;must be greater than 0F00H
  52.     jp    c,nroom
  53.     dec    hl
  54.     dec    hl
  55.     push    hl        ;save source address
  56.     add    hl,bc        ;form address of bit map
  57.     cp    h        ;are we ok?
  58.     pop    hl
  59.     jp    c,nroom        ;out of memory
  60.     ld    d,a        ;destination address in DE
  61.     ld    e,0
  62.     inc    h        ;adjust HL to point to start of code
  63.     push    de
  64.     push    bc
  65.     call    movebc        ;move code into place
  66.     pop    bc        ;length of module in BC
  67.     pop    de
  68.     push    de
  69.     ld    e,d        ;relocation page offset in E
  70.     dec    e        ;adjust relocation offset
  71.     push    hl        ;bit map address on stack
  72.     ld    h,e        ;relocation offset in H
  73.     ld    e,0        ;init to byte boundary
  74. reloclp:
  75.     ld    a,b
  76.     or    c        ;are we done?
  77.     jp    z,reldon    ;yep.
  78.     dec    bc        ;decrement length left
  79.     ld    a,e        ;get low byte of target address
  80.     and    7        ;mod 8
  81.     jp    nz,nobump    ;not at byte boundary in bit map
  82.     ex    (sp),hl        ;get bit map address
  83.     ld    a,(hl)        ;get relocation bits
  84.     inc    hl        ;adjust bit map address
  85.     ex    (sp),hl        ;back to stack
  86.     ld    l,a        ;relocation bits in L
  87. nobump:
  88.     ld    a,l        ;get relocation bits
  89.     rla            ;shift into carry
  90.     ld    l,a
  91.     jp    nc,noadj    ;jump if no need to adjust
  92.     ld    a,(de)        ;get target byte
  93.     add    a,h        ;adjust address
  94.     ld    (de),a        ;put it back
  95. noadj:
  96.     inc    de        ;increment target
  97.     jp    reloclp        ;and loop for more
  98.  
  99. ;.........
  100. ;
  101. ;Relocation complete.  Call RSX manager to complete RSX chains.
  102. ;
  103.  
  104. reldon:
  105.     pop    de
  106.     pop    de        ;restore stack  DE points to RSX just loaded
  107.     ld    e,18h        ;point to loader flag
  108.     ld    a,(de)
  109.     or    a        ;test loader flag
  110.     jp    z,notldr    ;jump if not doing RSX manager
  111. ;
  112. ;If we are setting up the RSX manager, need to call it via JP (HL)
  113. ;
  114.     ld    h,d        ;get address of RSX manager entry in HL
  115.     ld    l,6
  116.     ld    bc,rsxret    ;push return onto stack
  117.     push    bc
  118.     ld    c,59        ;call RSX manager function
  119.     jp    (hl)        ;go to it
  120. notldr:
  121.     ld    c,59        ;call RSX manager function
  122.     call    bdos        ;RSX manager includes RSX just loaded
  123. rsxret:
  124.     xor    a        ;say we have no errors
  125.     ret
  126. ;
  127. ;...........
  128. ;
  129. ;Here if insufficient memory for relocation
  130. ;
  131. ;
  132. nroom:
  133.     ld    a,2        ;return code
  134.     or    a
  135.     ret
  136. ;
  137. ;...........
  138. ;
  139. ;
  140. ;MOVEBC  Move [HL] to [DE] length in [BC]
  141. ;
  142. movebc:
  143.     ld    a,b
  144.     or    c
  145.     ret    z
  146.     ld    a,(hl)
  147.     ld    (de),a
  148.     inc    hl
  149.     inc    de
  150.     dec    bc
  151.     jp    movebc
  152.  
  153.     end
  154.