home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / basic / extend.lbr / RELOC.AQM / RELOC.ASM
Encoding:
Assembly Source File  |  1986-10-31  |  2.8 KB  |  106 lines

  1. ; Reprinted from Micro/Systems Journal, Vol. 1, No. 1, March-
  2. ; April 1985, article titled "Assembly Language Extensions for
  3. ; MS-Basic" by Ron Kreymborg.  
  4. ;
  5.  
  6. ;**************************************************************;
  7. ; RELOC:   A program to move a page relocatable assembly       ;
  8. ;     language module with an origin at zero to the top      ;
  9. ;       of available memory.                                   ;
  10. ;                                                              ;
  11. ;                         Ron Kreymborg     ;
  12. ;                                                              ;
  13. ; This code resides at the end of MBASIC                       ;
  14. ;**************************************************************;
  15.  
  16.     org    6000h
  17.  
  18. exit:    jmp    0        ; original address of Basic
  19. èstart:    lxi    sp,stack
  20.  
  21. ; Define code length and start address
  22.  
  23.     lxi    h,buff        ; source for move
  24.     mov    c,m        ; get length of module
  25.     inx    h
  26.     mov    b,m
  27.     mov    a,b        ; anything there?
  28.     ora    c
  29.     jz    exit        ; ..no
  30.  
  31.     lxi    d,0feh
  32.     dad    d        ; start of code
  33.     xchg            ; put in DE
  34.     push    b        ; save count
  35.     push    b
  36.  
  37. ; Compute destination address in HL
  38.  
  39.     lhld    6        ; get bdos address
  40.     shld    buff+100h    ; insert in module
  41.     mvi    l,0        ; ensure we go to a page boundry
  42.     inr    b        ; convert length to pages
  43.     mov    a,h
  44.     sub    b
  45.     mov    h,aè
  46. ; Now move the code to the address in HL
  47.  
  48.     pop    b        ; restore byte count
  49.     push    h        ; save destination address
  50. movlp:    ldax    d        ; get byte of code
  51.     mov    m,a        ; move to new location
  52.     inx    h        ; step pointers
  53.     inx    d
  54.     dcx    b        ; and decrement counter
  55.     mov    a,c
  56.     ora    b        ; done?
  57.     jnz    movlp        ; ..no, loop
  58.  
  59.     pop    h        ; restore destination
  60.     shld    6        ; setup new bdos vector
  61.     xchg
  62.     pop    b        ; restore count
  63.  
  64. ; Now BC has the byte count, HL points to the first byte of the
  65. ; bit map, and DE has the destination address
  66.  
  67.     push    h        ; bit map address to top of stack
  68.     mov    h,d        ; (h) is relocated page offset
  69.  
  70. reclp:    mov    a,b        ; check if done
  71.     ora    cè    jz    exit        ; ..yes, go start up Basic
  72.     dcx    b        ; decrease count
  73.     mov    a,e        ; is DE address modulo 8 bytes?
  74.     ani    7        ;   if so - must get next map byte
  75.     jnz    rec2        ; ..no
  76.  
  77. ; Get next map byte via top of stack
  78.  
  79.     xthl            ; get current map pointer
  80.     mov    a,m        ; get byte into A
  81.     inx    h        ; point to next byte
  82.     xthl
  83.     mov    l,a        ; store in L
  84.  
  85. rec2:    mov    a,l        ; check next bit in byte
  86.     ral
  87.     mov    l,a        ; save for later
  88.     jnc    rec3        ; no relocation required
  89.  
  90. ; Add in the offset for a set bit 
  91.  
  92.     ldax    d        ; get byte
  93.     add    h        ; add offset
  94.     stax    d        ; store relocated byte back
  95. rec3:    inx    d        ; step to next byte in relocated
  96.     jmp    reclp        ;   code and around again
  97. è; <stack> must occur on an 8 bit boundry
  98.  
  99.     org    ($ AND 0fff0h) + 10h
  100.  
  101. stack    equ    $
  102.     db    0
  103. buff:    dw    0    ; zero for no module case
  104.  
  105.     end
  106.