home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDOS / DOSPLSOR.ARK / DOSRELOC.MAC < prev    next >
Text File  |  1986-12-07  |  14KB  |  589 lines

  1. title    'DOSRELOC - make/replace MOVCPM (86/12/07)'
  2. ; ***********************************************
  3. ; * Allows creation of MOVDOS or MOVCPM system    *
  4. ; * where custom bioses, CCPs, BDOS patches,    *
  5. ; * etc. have been installed.            *
  6. ; *                        *
  7. ; * Copyright (C) 1980, 1982, 1984, 1986    *
  8. ; * by    C.B. Falconer    (203) 281-1438        *
  9. ; *    680 Hartford Tpk.,            *
  10. ; *    Hamden, Conn 06517            *
  11. ; *                        *
  12. ; * All rights reserved                *
  13. ; ***********************************************
  14. ; *     86/12/07 No change, altered DOS+ ver.    *
  15. ; ***********************************************
  16. ; * 1.2    86/11/13 - Added OsborneI configuration    *
  17. ; *    Now require 'G' 2nd parameter for any    *
  18. ; *    immediate execution.  Fewer accidents.    *
  19. ; *    Added "save" size customization        *
  20. ; ***********************************************
  21. ; *     85/11/19 - Intel mnemnonics, no change    *
  22. ; ***********************************************
  23. ; * 1.1 10 Mar. 1984. Added Kaypro installation *
  24. ; * constants. Specify aseg for m80.  cbf    *
  25. ; ***********************************************
  26. ;
  27. ;  *** WARNING *** special values installed in "reloc"
  28. ;        for KAYPRO sign-on.  Very klugy
  29. ;
  30. ; ***********************************************
  31. ; Generate a relocation image for CP/M 2.2 & variants
  32. ; Assumes that:
  33. ;   1.    zero based image located at 0980h-22ffh
  34. ;   2.    running system exists @(6)-0806h up
  35. ; Generates a relocation bit map at 05c0 thru 08ffh where each byte
  36. ; specifies relocation for 8 object bytes.  The ms bit of the bit
  37. ; vector corresponds to the lower of the 8 object bytes.  Note that
  38. ; the bootstrap image at 900h thru 97fh will be read in from the
  39. ; system disk.  If the assemble time constant "boot" is false suitable
  40. ; boot images are assumed to exist and any existing relocation bits
  41. ; are preserved.
  42. ;
  43. ; Algorithm: Wherever the two systems differ by exactly the load
  44. ; address hi byte of the running system a relocation bit is generated,
  45. ; else we assume some random data value, and generate 0.
  46. ;
  47. ; As far as possible this code is dependant on the various assembly
  48. ; time constants below.  This should ease adaptation to other DOS+ or
  49. ; CPM versions or other systems. This is organized to simplify the
  50. ; conditional assembly areas to ease adaptation to other assemblers.
  51. ;
  52. ; The zero based image is available, 80h bytes higher, in the standard
  53. ; "MOVCPM" program.  The user will have to add a suitable bios and
  54. ; optional boot image.  For DOS+ the distributed MOVDOS+ program
  55. ; contains all images in the correct locations and is based on this.
  56. ;
  57. ; Since DDT or DDTZ replaces ccp in operation, and modifies the sysfnc
  58. ; entry in addition, the bit vector generator will not run under DDTZ.
  59. ; In addition, since the data is modified when relocating, the program
  60. ; can not be run again without reloading a fresh image.  The system
  61. ; self modifies to become, in turn:
  62. ;    bit vector generator
  63. ;    "movcpm" program
  64. ;    error program
  65. ;
  66. ;
  67. true    equ    -1
  68. false    equ    not true
  69. boot    set    true;        false leaves the boot reloc bits
  70. ver    equ    12;        program version
  71. ;
  72. ; CPM version. Set only one value "true"
  73. cpm14    equ    false
  74. cpm22    equ    false
  75. dos24    equ    true
  76. ;
  77. ; Host machine. Set only one value "true".
  78. ; This suffices for the configured machines.
  79. ; For others various customization equates must be modified.
  80. sssd    equ    false
  81. yale    equ    false
  82. kp83    equ    true;        early Kaypro II/4 only
  83. oz1    equ    false;        Osborne I, dd
  84. ;
  85.     if    NOT (sssd OR yale OR kp83 or oz1)
  86.      +++ Error - set at least one system true +++
  87.     endif
  88. ;
  89. ; DOS+/CPM values
  90. cout    equ    2;        write char.
  91. tstr    equ    9;        write string
  92. reboot    equ    0
  93. sysfnc    equ    reboot+5
  94. defcb    equ    reboot+05ch
  95. parm1    equ    defcb+1
  96. altfcb    equ    reboot+06ch
  97. parm2    equ    altfcb+1
  98. ;
  99. ; define minimum size to run DDTZ and MOVDOS+
  100.     if    yale or sssd or oz1
  101. minsiz     equ    16*4
  102.     endif
  103.     if    kp83;        allow for bank switch, bios above it
  104. minsiz     equ    17*4+2
  105. @sgnon     equ    01dch;        offset for cbf (f4) bios sign-on msg.
  106.     endif;            VERY klugy patch arrangement.
  107. ;
  108. ; cpmsiz cannot exceed 01a00h on SSSD systems.  Others vary.
  109. ; Smaller values can be used where the bios allocation is less
  110. ; than the maximum storable on 51 sectors (tks 0 & 1) (SSSD)
  111. ; For standard systems this means biosiz must not exceed 0380h
  112. ; Note that the system may use further uninitialized memory.
  113. ;
  114. ; Anomalous to avoid nested ifs. Ease portability
  115.     if    kp83
  116. biosiz     equ    200h
  117. btsect     equ    0;        Kaypros native numbering scheme
  118.     endif
  119.     if    yale
  120. biosiz     equ    080h
  121. btsect     equ    1;        Uses standard sector numbering
  122.     endif
  123.     if    sssd
  124. biosiz     equ    0380h;        Standard allocation
  125. btsect     equ    1;
  126.     endif
  127.     if    oz1
  128. biosiz     equ    0880h
  129. btsect     equ    0;        Actually unused
  130. boot     set    false
  131.     endif
  132. ;
  133.     if    cpm22 or dos24;    use the following
  134. syssiz     equ    28;        pages, ver 2.2 bios allowance
  135. ccpsiz     equ    0800h;        size of the ccp segment
  136. bdosiz     equ    0e00h;        size of bdos segment
  137.     endif
  138.     if    cpm22
  139. cpmver     equ    22;        cpmversion no.
  140.     endif
  141.     if    dos24
  142. cpmver     equ    25
  143.     endif
  144.     if    cpm14;        use the following
  145. syssiz     equ    23;        23 pages, ver 1.4 bios allowance
  146. ccpsiz     equ    0800h;        size of the ccp segment
  147. bdosiz     equ    0d00h;        size of bdos segment
  148. cpmver     equ    14;        cpmversion no.
  149.     endif
  150. btsize    equ    080h;        size of any boot image
  151. cpmsiz    equ    btsize+ccpsiz+bdosiz+biosiz;     Total system size
  152. imgloc    equ    0900h;        location of the zero based image
  153. ;
  154.     if    sssd AND (cpmsiz gt 01a00h)
  155.      +++ ERROR - can't handle this size bios +++
  156.     endif
  157. ;
  158. pages    equ    (imgloc+cpmsiz-1)/256
  159. ;
  160. ; offset controls the default /n parameter when the system sets itself
  161. ; to the max. memory available.  This moves DOS+ or CPM up the spec-
  162. ; ified number of 256 byte pages, where less than the normal alloca-
  163. ; tion for bios is required.  0 is equivalent to the original movcpm.
  164. ; Offsets that are non-divisible by 4 will report a /n size parameter.
  165. ; Similarly negative values can be used to reserve space at the top of
  166. ; memory for other uses
  167.     if    kp83 or sssd
  168. offset     equ    0;    in "pages"
  169.     endif
  170.     if    yale
  171. offset     equ    4;    All bios except vector/dskparms in ROM
  172.     endif
  173.     if    oz1
  174. offset     equ    -5;    in "pages", reserve 1.25 k at top.
  175.     endif
  176. ;
  177. ; ******** END customization equates **********
  178. ;
  179. ; control chars
  180. cr    equ    0dh
  181. lf    equ    0ah
  182. ;
  183.     aseg;            Absolute segment
  184.     org    0100h
  185. ;
  186.     nop;            handy for debug
  187. begin:    jmp    start;        to patch for reverse operation
  188. ;
  189. ; *************************************************
  190. ; generate the relocation bit map and construct a revised version of
  191. ; "movdos+" or "movcpm" program.  The new "movdos+" can generate the
  192. ; owners bios, ccp and bootstrap
  193. start:    lxi    sp,stack
  194.     lxi    d,signon
  195.     mvi    c,tstr
  196.     call    sysfnc;        sign-on
  197.     call    ldboot;        in case image needed
  198.     if    not boot;    bypass booter area
  199.      lxi    h,bitv+btsize/16
  200.     endif
  201.     if    boot;        include booter area
  202.      lxi    h,bitv
  203.     endif
  204.     shld    bitvec    
  205.     lhld    sysfnc+1
  206.     lxi    d,-(ccpsiz+6)
  207.     dad    d;        point to start of ccp
  208.     mov    a,h
  209.     sta    delta    
  210.     if    boot;        include booter area
  211.      lxi    d,-btsize
  212.     endif
  213.     if    not boot;    leave patch space
  214.      lxi    d,0
  215.     endif
  216.     dad    d
  217.     xchg    
  218.     if    not boot;    count and zero base ptr for no boot
  219.      lxi    h,cpmbas+btsize;    bypass booter
  220.      lxi    b,(cpmsiz+7-btsize)/8;    ensure full bytes
  221.     endif
  222.     if    boot;        count & zero base to include booter
  223.      lxi    h,cpmbas
  224.      lxi    b,(cpmsiz+7)/8
  225.     endif
  226.     call    vect;        make relocation vector
  227.     lxi    h,mvcpm
  228.     shld    begin+1;    convert entry
  229.     lxi    d,dunmsg
  230.     jmp    exit
  231. ;
  232. ; make bit vector
  233. ; at entry,    (hl)=^current zero based image byte
  234. ;        (de)=^current running system byte
  235. ;        (bc)=(bytes to examine)/8
  236. ;         (delta)=critical difference to signal relocation
  237. ;        (bitvec)=^storage for generated bit vector
  238. ; a,f,b,c,d,e,h,l,bitvec,bitvec^
  239. vect:    push    b
  240.     lxi    b,8;        b:=0;c:=bit ctr.
  241. vect2:    lda    delta
  242.     xchg    
  243.     sub    m
  244.     xchg    
  245.     add    m
  246.     cma
  247.     adi    1;        cy if result was 0
  248.     mov    a,b
  249.     adc    a;        2*a+cy
  250.     mov    b,a
  251.     inx    d
  252.     inx    h
  253.     dcr    c
  254.     jnz    vect2;        same vector byte
  255.     push    h
  256.     lhld    bitvec
  257.     mov    m,b
  258.     inx    h
  259.     shld    bitvec    
  260.     pop    h
  261.     pop    b
  262.     dcx    b;        count generated bytes
  263.     mov    a,b
  264.     ora    c
  265.     jnz    vect;        do next byte
  266.     ret
  267. ;
  268. ; load track 0 sector 1 (the bootstrap) just below ccp
  269. ; this is the booter that works with the current system
  270. ; a,f,b,c,d,e,h,l
  271. ldboot:    if    NOT oz1;    which has no boot sector
  272.      mvi    c,0
  273.      mvi    a,9;        select drive
  274.      call    biosf
  275.      lhld    sysfnc+1
  276.      lxi    d,-(ccpsiz+6)-128
  277.      dad    d;        find base of ccp-128
  278.      mov    b,h
  279.      mov    c,l
  280.      mvi    a,12;        set dma
  281.      call    biosf
  282.      mvi    c,btsect
  283.      mvi    a,11;        set sector
  284.      call    biosf
  285.      mvi    c,0
  286.      mvi    a,10;        set track
  287.      call    biosf
  288.      mvi    a,13;        read sector
  289.      call    biosf
  290.      ora    a
  291.      lxi    d,msg7
  292.      jnz    exit;        bad read
  293.      ret
  294. ;
  295. ; transfer to bios function #(a)
  296. ; a,f+bios
  297. biosf:     push    h
  298.      lhld    reboot+1
  299.      mov    l,a
  300.      add    a
  301.      add    l
  302.      mov    l,a
  303.      xthl;            restore hl, stack xfr adr
  304.     endif;        so plenty of room for bit map on Osborne
  305.     ret
  306. ;
  307. ; *************************************************
  308. ; replacement section for "movdos+" or "movcpm" to use the above
  309. ; generated bit map.  Uses "movcpm" protocol, except that the size
  310. ; specification (e.g. "48") can be qualified by /1,/2, or /3 (e.g.
  311. ; "48/1") to move the final system up by 1, 2, or 3 256 byte
  312. ; increments.  Thus the system can be relocated on any page boundary.
  313. ;
  314. ; interrogate system for top of contiguous (to 0) memory
  315. ; returns (hl)=^last functional location (+256*offset)
  316. ; a,f,h,l
  317. qmem:    lxi    h,0ffh;        assumes 0..100h exists
  318. qmem1:    inr    h
  319.     jz    qmem2;        full memory.
  320.     mov    a,m
  321.     cma
  322.     mov    m,a;    ***  This are must not
  323.     cmp    m;    ***  end up on page location 0ffh
  324.     cma;        ***  else it will self destruct.
  325.     mov    m,a;        restore it
  326.     jz    qmem1
  327. qmem2:    dcr    h;        point to last location functional
  328.     mov    a,h
  329.     adi    offset
  330.     mov    h,a
  331.     ret
  332. ;
  333. ; a replacement "movcpm" program
  334. mvcpm:    lxi    sp,stack
  335.     lxi    h,reboot
  336.     shld    begin+1;    prevent a 2nd call
  337.     lxi    d,signon
  338.     mvi    c,tstr
  339.     call    sysfnc;        sign-on
  340.     lxi    d,parm1
  341.     ldax    d
  342.     cpi    ' '
  343.     jz    mvcpm5;        use max available
  344.     cpi    '?'
  345.     jz    mvcpm5;        use max available
  346.     lxi    h,0;        will hold mem address
  347. mvcpm1:    ldax    d
  348.     inx    d
  349.     call    qnum
  350.     jc    mvcpm2;        not digit
  351.     sui    '0'
  352.     mov    c,l
  353.     mov    b,h
  354.     dad    h;        2*
  355.     dad    h;        4*
  356.     dad    b;        5*
  357.     dad    h;        10*
  358.     mov    c,a
  359.     mvi    b,0
  360.     dad    b;        incorporate value
  361.     jmp    mvcpm1
  362. mvcpm2:    dad    h
  363.     dad    h;        4*, in pages
  364.     cpi    '/';        check for increment
  365.     jnz    mvcpm3;        none
  366.     ldax    d
  367.     inx    d
  368.     call    qnum
  369.     jc    errer;        bad input
  370.     sui    '0'
  371.     cpi    4
  372.     jnc    errer;        bad input
  373.     add    l
  374.     mov    l,a;        result in pages
  375. mvcpm3:    mov    a,h
  376.     dcr    a
  377.     jm    mvcpm4;        less than 64k
  378.     jnz    errer;        more than 64k
  379.     ora    l
  380.     jnz    errer;        64/n k, error
  381. mvcpm4:    mov    h,l
  382.     mvi    l,0;        *256, form top address
  383.     dcx    h;        form top available address
  384.     jmp    mvcpm6
  385. mvcpm5:    call    qmem;        find top available
  386. mvcpm6:    lxi    d,-syssiz*256;
  387.     dad    d;        final loadpoint in (hl)
  388.     inx    h;        to actual loadpoint
  389.     mov    a,h
  390.     sta    delta;        hi byte of relocation point
  391.     cpi    minsiz-syssiz
  392.     jc    errer;        specification too small
  393.     mvi    c,tstr
  394.     lxi    d,msg1
  395.     call    sysfnc;        advise
  396.     call    tdelt
  397.     lxi    d,msg1a
  398.     mvi    c,tstr
  399.     call    sysfnc
  400.     call    reloc;        relocate data in place
  401.     lda    parm2
  402.     cpi    'G'
  403.     jz    exec;        put in place and execute
  404.     mvi    c,tstr
  405.     lxi    d,msg2
  406.     call    sysfnc
  407.     call    tdelt
  408.     lxi    d,msg3
  409.     jmp    exit
  410. ;
  411. ; put the relocated image in place and execute it
  412. exec:    mvi    c,tstr
  413.     lxi    d,msg6
  414.     call    sysfnc
  415.     lxi    d,cpmbas+btsize;    ignore the booter area
  416.     lda    delta
  417.     mov    h,a
  418.     mvi    l,0
  419.     lxi    b,cpmsiz-btsize;    count to transfer
  420.     push    h;            save for control xfr
  421. exec1:    ldax    d
  422.     mov    m,a
  423.     inx    h
  424.     inx    d
  425.     dcx    b
  426.     mov    a,b
  427.     ora    c
  428.     jnz    exec1;        more to move
  429.     pop    h
  430.     lxi    d,ccpsiz+bdosiz
  431.     dad    d;        form entry to bios cold start
  432.     pchl
  433. ;
  434. ; output "delta" as nn[/n] size id
  435. ; a,f
  436. tdelt:    push    b
  437.     push    d
  438.     push    h
  439.     lda    delta
  440.     adi    syssiz;        correct for top of memory
  441.     mov    b,a
  442.     ani    3
  443.     mov    c,a
  444.     mov    a,b
  445.     rar
  446.     rar
  447.     ani    03fh
  448.     mvi    e,'0'-1
  449.     jnz    tdelt1;        not 64k
  450.     mvi    e,'6'
  451.     mvi    a,'4'
  452.     jmp    tdelt2
  453. tdelt1:    inr    e
  454.     sui    10
  455.     jp    tdelt1;        extract ms digit
  456.     adi    '0'+10
  457. tdelt2:    push    b
  458.     push    psw
  459.     mvi    c,cout
  460.     call    sysfnc
  461.     pop    psw
  462.     mov    e,a
  463.     mvi    c,cout
  464.     call    sysfnc
  465.     pop    b
  466.     mov    a,c
  467.     ora    a
  468.     jz    tdelt9;        no extra portion
  469.     adi    '0'
  470.     push    psw
  471.     mvi    c,cout
  472.     mvi    e,'/'
  473.     call    sysfnc
  474.     pop    psw
  475.     mov    e,a
  476.     mvi    c,cout
  477.     call    sysfnc
  478. tdelt9:    pop    h
  479.     pop    d
  480.     pop    b
  481.     ret
  482. ;
  483. ; relocate the data image in place, using the
  484. ; global variable "delta" as the relocation amount
  485. ; a,f,b,c,d,e,h,l
  486. reloc:    lxi    h,bitv
  487.     lxi    d,cpmbas
  488.     lxi    b,(cpmsiz+7)/8
  489. reloc1:    push    b;        save byte counter
  490.     lxi    b,8
  491.     mov    b,m;        get reloc bits
  492.     xchg    
  493. reloc2:    mov    a,b
  494.     add    a
  495.     mov    b,a
  496.     jnc    reloc3;        dont relocate this
  497.     lda    delta
  498.     add    m
  499.     mov    m,a
  500. reloc3:    inx    h;        next object byte
  501.     dcr    c
  502.     jnz    reloc2;        more bits to scan
  503.     xchg    
  504.     inx    h;        next reloc bit vector
  505.     pop    b
  506.     dcx    b
  507.     mov    a,b
  508.     ora    c
  509.     jnz    reloc1;        not done
  510. ;    ********************************************
  511.     if    kp83;        ** special considerations for sign-on
  512.      lda    parm1
  513.      cpi    ' '
  514.      rz;            64k max, leave native sign-on
  515.      lxi    d,parm1
  516.      lxi    h,cpmbas+btsize+ccpsiz+bdosiz+@sgnon;     SPECIAL VALUE
  517.      mov    a,m;        for cbf bios --^ ONLY
  518.      cpi    '6'
  519.      rnz;            This is not the right version
  520.      ldax    d;        Appears to be the right bios,
  521.      mov    m,a;         go ahead and patch the sign-on
  522.      inx    d
  523.      inx    h
  524.      ldax    d
  525.      mov    m,a;        crude 2 digits for now
  526.     endif
  527. ;    ********************************************
  528.     ret
  529. ;
  530. ; check (a) for ascii numeric char, carry if not
  531. ; f
  532. qnum:    cpi    '0'
  533.     rc    
  534.     cpi    '9'+1
  535.     cmc
  536.     ret
  537. ;
  538. ; error exit
  539. errer:    lxi    d,msg5
  540. ;    "    "
  541. exit:    mvi    c,tstr
  542.     call    sysfnc
  543.     jmp    reboot
  544. ;
  545. msg1:    db    'Constructing $'
  546. msg1A:    db    'k DOS+ System V. '
  547.     db    cpmver/10+'0','.',cpmver MOD 10 + '0', ' for '
  548.     if    sssd
  549.      db    'SSSD std. system'
  550.     endif
  551.     if    kp83
  552.      db    'Kaypro 2/4 (83)'
  553.     endif
  554.     if    yale
  555.      db    'Yale'
  556.     endif
  557.     if    oz1
  558.      db    'Osborne I'
  559.     endif
  560.     db    '$'
  561. msg2:    db    cr,lf,'Ready for "SYSGEN" or "SAVE '
  562.     db    pages/10 + '0', pages MOD 10 +'0'
  563.     db    ' DOS$'
  564. msg3:    db    'K.SYS"$'
  565. msg5:    db    'Invalid system size$'
  566. msg6:    db    cr,lf,'Running new system$'
  567. msg7:    db    cr,lf,'Error reading bootstrap image$'
  568. dunmsg:    db    'Now "SAVE '
  569.     db    pages/10 + '0', pages MOD 10 +'0'
  570.     db    ' MOVDOS+.COM"$'
  571. signon:    db    cr,lf,'DOS+ Mover Ver. '
  572.     db    ver/10+'0','.',ver mod 10+'0',cr,lf,'$'
  573. ;
  574. ; storage
  575. bitvec:    ds    2
  576. delta:    ds    1
  577.     ds    64;        run time stack
  578. stack:    ds    0
  579. ;
  580. ; the data base area
  581.     org    imgloc-(cpmsiz+7)/8
  582.     if    $ lt stack
  583.      +++ ERROR bios too large +++
  584.     endif
  585. bitv:    ds    (cpmsiz+7)/8;    resultant bit vector
  586. cpmbas:    ds    cpmsiz;        image of cpm system
  587. ;
  588.     end    
  589. α¬