home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol165 / genbim.asm < prev    next >
Encoding:
Assembly Source File  |  1984-07-08  |  4.9 KB  |  295 lines

  1.  
  2. ;    ------------------------------------------------------------
  3. ;    Some programs, such as DDT.COM, can be executed together
  4. ;    with another program, but both of them cannot be situated
  5. ;    at the standard CP/M origin 0100H. To move one of them to
  6. ;    high memory without knowing in advance how much memory is
  7. ;    available needs a relocation scheme which can be carried
  8. ;    out at run time. Page relocation utilizes a bitmap which
  9. ;    shows the location of the high byte of all addresses that
  10. ;    the program contains. If the program has been assembled
  11. ;    with respect to origin zero, it can be moved to its final
  12. ;    location, following which its actual origin can be added
  13. ;    to all the bytes which have been marked. This is actually
  14. ;    the way that CP/M's DDT.COM has been written. GENBIM.ASM
  15. ;    is a program which will generate the necessary bitmap; it
  16. ;    requires two .COM files containing the same program, but
  17. ;    assembled at two different origins each corresponding to
  18. ;    a page boundary. Assuming that the only discrepancies be-
  19. ;    tween the two programs are the relocatable addresses, the
  20. ;    .BIM file is generated using the first disk and the first
  21. ;    filename as its own.
  22. ;
  23. ;            GENBIM .ASM Copyright (C) 1983
  24. ;            Universidad Autonoma de Puebla
  25. ;              September 12, 1983
  26. ;
  27. ;    [Harold V. McIntosh, 12 Spetember 1983]
  28. ;    ------------------------------------------------------------
  29.  
  30.  
  31. LF    equ    0AH    ;line feed
  32. CR    equ    0DH    ;carriage return
  33.  
  34. BDOS    equ    0005H    ;jump to BDOS
  35. TFCB    equ    005CH    ;DDT's file control block
  36. TBUF    equ    0080H    ;DDT's sector buffer
  37.  
  38. ;    -------------
  39.     org    0100H
  40. ;    -------------
  41.  
  42. begn:    lxi    h,0000
  43.     dad    sp
  44.     shld    stak
  45.     lxi    sp,stak
  46.     lxi    h,logo        ;"GENBIM/UAP"
  47.     call    mssg
  48.     lda    TFCB+1        ;file name
  49.     cpi    ' '
  50.     jz    tuto
  51.     call    setup
  52.     lxi    h,TFCB+9
  53.     mvi    m,'B'
  54.     inx    h
  55.     mvi    m,'I'
  56.     inx    h
  57.     mvi    m,'M'
  58.  
  59.     mvi    c,15    ;(0F) open file
  60.     lxi    d,fcb1
  61.     call    BDOS
  62.     inr    a
  63.     jz    err1
  64.     mvi    c,15    ;(0F) open file
  65.     lxi    d,fcb2
  66.     call    BDOS
  67.     inr    a
  68.     jz    err2
  69.     mvi    c,19    ;(13) delete file
  70.     lxi    d,TFCB
  71.     call    BDOS
  72.     mvi    c,22    ;(16) create file
  73.     lxi    d,TFCB
  74.     call    BDOS
  75.     mvi    c,15    ;(0F) open file
  76.     lxi    d,TFCB
  77.     call    BDOS
  78.  
  79.     xra    a
  80.     sta    TFCB+32
  81.     sta    fcb1+32
  82.     sta    fcb2+32
  83.     sta    byct
  84.     inr    a
  85.     lxi    b,TBUF
  86.     stax    b
  87.  
  88. loop:    lda    byct
  89.     ani    07FH
  90.     jnz    rnb    ;bytes in the buffer
  91.     push    b
  92.     mvi    c,26    ;(1A) set DMA address
  93.     lxi    d,buf1
  94.     call    BDOS
  95.     mvi    c,20    ;(14) read one record
  96.     lxi    d,fcb1
  97.     call    BDOS
  98.     mvi    c,26    ;(1A) set DMA address
  99.     lxi    d,buf2
  100.     call    BDOS
  101.     mvi    c,20    ;(14) read one record
  102.     lxi    d,fcb2
  103.     call    BDOS
  104.     ora    a
  105.     pop    b
  106.     jnz    reen    ;end of record
  107.     lxi    d,buf1
  108.     lxi    h,buf2
  109.     mvi    a,80H
  110. rnb:    dcr    a
  111.     sta    byct
  112.     ldax    d
  113.     sub    m
  114.     sui    1
  115.     cmc
  116.     ldax    b
  117.     ral
  118.     stax    b
  119.     jnc    inb
  120.     inx    b
  121.     mov    a,b
  122.     ora    a
  123.     jz    wri
  124.     push    d
  125.     push    h
  126.     mvi    c,26    ;(1A) set DMA address
  127.     lxi    d,TBUF
  128.     call    BDOS
  129.     mvi    c,21    ;(15) write one record
  130.     lxi    d,TFCB
  131.     call    BDOS
  132.     lxi    b,TBUF
  133.     pop    h
  134.     pop    d
  135. wri:    mvi    a,1
  136.     stax    b
  137. inb:    inx    d
  138.     inx    h
  139.     jmp    loop
  140.  
  141. reen:    ldax    b
  142.     cpi    1
  143.     jnz    last
  144.     mov    a,b
  145.     cpi    1
  146.     jz    clos
  147. last:    sub    a
  148.     ldax    b
  149. ree:    ral
  150.     jnc    ree
  151.     stax    b
  152. rii:    inx    b
  153.     mov    a,b
  154.     ora    a
  155.     jnz    finl
  156.     xra    a
  157.     stax    b
  158.     jmp    rii
  159. finl:    mvi    c,26    ;(1A) set DMA address
  160.     lxi    d,TBUF
  161.     call    BDOS
  162.     mvi    c,21    ;(15) write one record
  163.     lxi    d,TFCB
  164.     call    BDOS
  165. clos:    mvi    c,16    ;(10) close file
  166.     lxi    d,TFCB
  167.     call    BDOS
  168. gbye:    lhld    stak
  169.     sphl
  170.     ret
  171.  
  172. setup:    mvi    b,16
  173.     lxi    d,TFCB
  174.     lxi    h,fcb1
  175.     call    moov
  176.     mvi    b,16
  177.     lxi    d,TFCB+16
  178.     lxi    h,fcb2
  179. moov:    ldax    d
  180.     mov    m,a
  181.     inx    d
  182.     inx    h
  183.     dcr    b
  184.     jnz    moov
  185.     lxi    d,-7
  186.     dad    d
  187.     mov    a,m
  188.     cpi    ' '
  189.     rnz
  190.     mvi    m,'C'
  191.     inx    h
  192.     mvi    m,'O'
  193.     inx    h
  194.     mvi    m,'M'
  195.     ret
  196.  
  197. ;    Type CR,LF.
  198.  
  199. crlf:    mvi    a,CR
  200.     call    aout    ;A to console
  201.     mvi    a,LF
  202.     jmp    aout    ;A to console
  203.  
  204. ;    Type one or two spaces.
  205.  
  206. dubl:    call    sngl
  207. sngl:    mvi    a,' '
  208.  
  209. ;    A to console
  210.  
  211. aout:    push    h
  212.     push    d
  213.     push    b
  214.     mov    e,a
  215.     mvi    c,02
  216.     call    BDOS
  217.     pop    b
  218.     pop    d
  219.     pop    h
  220.     ret    
  221.  
  222. ;    Type A as two nibbles
  223.  
  224. word:    mov    a,d
  225.     call    byte
  226.     mov    a,e
  227. byte:    push    psw    
  228.     rar    
  229.     rar    
  230.     rar    
  231.     rar    
  232.     call    nybl
  233.     pop    psw
  234. nybl:    ani    0FH
  235.     adi    90H
  236.     daa
  237.     aci    40H
  238.     daa
  239.     jmp    aout    ;A to console
  240.  
  241. ;    Message terminated by zero to console
  242.  
  243. mssg:    mov    a,m
  244.     ora    a
  245.     rz
  246.     call    aout    ;A to console
  247.     inx    h
  248.     jmp    mssg
  249.  
  250. err1:    lxi    h,er1
  251.     call    mssg
  252.     jmp    gbye
  253.  
  254. err2:    lxi    h,er2
  255.     call    mssg
  256.     jmp    gbye
  257.  
  258. tuto:    lxi    h,scrp
  259.     call    mssg
  260.     jmp    gbye
  261.  
  262. ;    ---------------------------------------------------------
  263.  
  264. logo:    db    '         GENBIM/ICUAP',CR,LF
  265.     db    'Universidad Autonoma de Puebla',CR,LF
  266.     db    '      September 12, 1983',CR,LF,00
  267.  
  268. er1:    db    'Cannot open .COM file',00
  269. er2:    db    'Cannot open comparison file',00
  270. scrp:    db    CR,LF,CR,LF
  271.     db    'GENBIM.COM is a program which will generate a bitmap',CR,LF
  272.     db    'which can be used for the pagewise relocation of a',CR,LF
  273.     db    'binary file. It requires two copies of the same .COM',CR,LF
  274.     db    'file, whose origins differ by an integral number of',CR,LF
  275.     db    'pages. The command line:',CR,LF,CR,LF
  276.     db    '      GENBIM [X:]FILE1[.AAA],[Y:]FILE2[.BBB]',CR,LF,CR,LF
  277.     db    'will produce the bitmap in [X:]FILE1.BIM. The last',CR,LF
  278.     db    'record will be completed with trailing zeroes. The',CR,LF
  279.     db    'default extension is .COM, but some other explicit',CR,LF
  280.     db    'extension may be used as desired.',CR,LF
  281.     db    CR,LF
  282.     db    00
  283.  
  284.     ds    20
  285. stak:    ds    2
  286. fcb1:    ds    33
  287. fcb2:    ds    33
  288. byct:    ds    1
  289. bipt:    ds    2
  290. borg:    ds    2
  291. buf1:    ds    80H
  292. buf2:    ds    80H
  293.  
  294.  
  295.