home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol027 / testsave.asm < prev    next >
Encoding:
Assembly Source File  |  1985-02-10  |  7.0 KB  |  331 lines

  1.  
  2. Title 'DISAVE - Cpm Utility to save gcp image to disk     12/30/80'
  3. ;---------------------------------------------------------
  4. ; ISAVE.HEX is a selective save program that loads into
  5. ;    low core and prompts the user for the address
  6. ;    range and start address of the image to be stored 
  7. ;    on disk.  
  8. ;
  9. ;    The first block on the disk is the program download
  10. ;    command that will be sent to the GCP to download this
  11. ;    image.  Its image is as follows:
  12. ;
  13. ;    length byte of command (6)
  14. ;    download opcode (either 7 or 7*4)
  15. ;    download program id (1). This is not used but added for
  16. ;       compatibility with downloaded code.
  17. ;    download program address (2 bytes) Specifies load address
  18. ;       in the GCP.
  19. ;    Download program length (2 bytes) Specifies length of
  20. ;        program to be downloaded.
  21. ;
  22. ;    Length count for execution command (usually 3)
  23. ;    Execute command opcode (16 or 16*4)
  24. ;    execute program id (1)
  25. ;    Execution address (2 bytes)
  26. ;
  27. ;
  28. ;
  29. ;    The second and subsequent blocks
  30. ;    are the memory image.
  31. ;
  32. ;    The file will always be saved as GCPMON .COM
  33. ;
  34. ;       This version of iload is altered to omit the request
  35. ;       for the start execution command.  This command
  36. ;       will be given from the iload program at the time
  37. ;       the diagnostic subroutine is called.
  38. ;
  39. ;---------------------------------------------------------
  40.     cr    equ    0dh
  41.     lf    equ    0ah
  42.     @bdos    equ    0005h
  43.     pgmcmd    equ    7*4        ;opcode specifing download
  44.     execcmd    equ    16*4        ;opcode specifing program execute
  45.  
  46. page
  47. ;aseg
  48.     ORG    100H
  49. START:
  50.     LXI    SP,STK        ;SET STACKPOINTER
  51.     LXI    D,FCB
  52.     MVI    C,0FH        ;OPEN CODE
  53.     call    @bdos
  54.     ANI    0FCH        ;XXXX XX..
  55.     JZ    OPENOKè    ;----------------------------------
  56.     ; OPENFAILED  TRY A MAKE
  57.     ;----------------------------------
  58.     LXI    D,FCB
  59.     MVI    C,16H        ;MAKEA FILE
  60.     call    @bdos
  61.     ANI    0FCH        ;XXX XX..
  62.     JZ    OPENOK
  63.     ;----------------------------------
  64.     ; CAN'T OPEN OR MAKE TTHE FILE
  65.     ; TELL SOMEONE
  66.     ;----------------------------------
  67.     lxi    d,msg1
  68.     mvi    c,9
  69.     call    @bdos
  70.     ;--------------------------------------
  71.     ; reboot
  72.     ;--------------------------------------
  73.     mvi    c,0
  74.     call    @bdos
  75.     jmp    0
  76. ;----------------------------------------------
  77. ; openok.... transfer alllto disk
  78. ;----------------------------------------------
  79. openok:
  80.     ;------------------------------------
  81.     ; Get start address
  82.     ;------------------------------------
  83.     lxi    d,starmsg
  84.     mvi    c,9
  85.     call    @bdos
  86.     call    getaddr
  87.     shld    addr1
  88.     ;-------------------------------------
  89.     ; Get end address
  90.     ;-------------------------------------
  91.     lxi    d,endmsg
  92.     mvi    c,9
  93.     call    @bdos
  94.     call    getaddr
  95.     shld    addr2
  96.  
  97.     jmp    wrtb0        ;go write block 0
  98. starmsg:    
  99.     db    cr,lf,'Start address....$'
  100. endmsg:
  101.     db    cr,lf,'End address.....$'
  102. ;---------------------------------------------------
  103. ;
  104. ;   Write out the first block to disk. it contains 
  105. ;    the three data addresses.
  106. ;---------------------------------------------------
  107. wrtb0:
  108.     ;-----------------------------------
  109.     ; Calculate lengthè    ;----------------------------------
  110.     lhld    addr1        ;get start address in de
  111.     xchg
  112.     lhld    addr2        ;get stop address
  113.     call    sub16
  114.     jc    ouch        ;overflow
  115.     inx    h        ;add one for last byte
  116.     shld    addr4
  117.     jmp    wrthdr        ;go write header
  118.  
  119. ouch:    lxi    d,oflow
  120.     mvi    c,9
  121.     call    @bdos
  122.     mvi    c,0
  123.     call    @bdos
  124.     jmp    0
  125. oflow:
  126.     db    cr,lf,'End address less than start$'
  127.     ;-----------------------------------
  128.     ; Write out header block
  129.     ;----------------------------------
  130. wrthdr:
  131.     lxi    d,header
  132.     mvi    c,1ah        ;set dma address
  133.     call    @bdos
  134.  
  135.     lxi    d,fcb
  136.     mvi    c,15h        ;write???
  137.     call    @bdos
  138.     ora    a
  139.     jnz    wrterr
  140.  
  141.     lhld    addr1        ;get start address
  142.     shld    wrtaddr        ;save original write add
  143. wrtloop:
  144.     lhld    wrtaddr
  145.     xchg
  146.     mvi    c,1ah        ;set DMA address
  147.     call    @bdos
  148.  
  149.     lhld    wrtaddr
  150.     lxi    d,128
  151.     dad    d
  152.     shld    wrtaddr        ;set up for next one
  153.  
  154.     lxi    d,fcb
  155.     lxi    b,15h        ;do a write
  156.     call    @bdos
  157.  
  158.     ora    a
  159.     jnz    wrterr        ;go to write error msg
  160.     ;-----------------------------------------------
  161.     ; Drop the count by the length, if less than zero 
  162.     ; we are done.
  163.     ;-----------------------------------------------è    lhld    addr4
  164.     lxi    d,128
  165.     call    sub16
  166.     jc    endit
  167.  
  168.     shld    addr4
  169.     jmp    wrtloop
  170.     ;--------------------------------------
  171.     ; error condition
  172.     ; on write
  173.     ;---------------------------------------
  174. wrterr:    lxi    d,msg2
  175.     mvi    c,9
  176.     call    @bdos
  177.     mvi    c,0
  178.     call    @bdos
  179. ;------------------------------------------------
  180. ; close the file
  181. ;-------------------------------------------------
  182. endit:
  183.     lxi    d,fcb
  184.     mvi    c,10h        ;close
  185.     call    @bdos
  186.     ani    0fch
  187.     jz    endok
  188.     ;-----------------------------------------
  189.     ; didn't close successfully
  190.     ;------------------------------------------
  191.     lxi    d,msg3
  192.     mvi    c,9
  193.     call    @bdos
  194.     mvi    c,0
  195.     call    @bdos
  196.     jmp    0
  197. ;------------------------------------------------
  198. ; all done successfully
  199. ;
  200. ;------------------------------------------------
  201. endok:
  202.     lxi    d,msg4
  203.     mvi    c,9
  204.     call    @bdos
  205.     
  206.     mvi    c,0
  207.     call    @bdos
  208.     jmp    0
  209. ;------------------------------------------------------------
  210. ; The following is used to get a four byte hex address.
  211. ; when successfully asseembled, it is returned in the
  212. ; HL register pair.
  213. ;-------------------------------------------------------------
  214. getaddr:
  215.     lxi    d,gomsg
  216.     mvi    c,9
  217.     call    @bdosè
  218.     lxi    h,0
  219.     push    h
  220.  
  221.     mvi    c,1
  222.     call    @bdos
  223.  
  224.     call    nibble
  225.     jc    badchar
  226.  
  227.     rlc
  228.     rlc
  229.     rlc
  230.     rlc
  231.     pop    h
  232.     mov    h,a
  233.     push    h
  234.  
  235.     mvi    c,1
  236.     call    @bdos
  237.     call    nibble
  238.     jc    badchar
  239.     pop    h
  240.     ora    h
  241.     mov    h,a
  242.     push    h
  243.  
  244.     mvi    c,1
  245.     call    @bdos
  246.     call    nibble
  247.     jc    badchar
  248.  
  249.     pop    h
  250.     rlc
  251.     rlc
  252.     rlc
  253.     rlc
  254.     mov    l,a
  255.     push    h
  256.  
  257.     mvi    c,1
  258.     call    @bdos
  259.     call    nibble
  260.     jc    badchar
  261.     pop    h
  262.     ora    l
  263.     mov    l,a
  264.     ret
  265. badchar:
  266.     pop    h
  267.     jmp    getaddr
  268. gomsg:    db    cr,lf,'       enter 4 digit hex address:$'
  269.  
  270. nibble:
  271.     sui    '0'è    rc
  272.     adi    0e9h
  273.     rc
  274.     adi    6
  275.     jp    nio
  276.     adi    7
  277.     rc
  278. nio:    adi    10
  279.     ora    a
  280.     ret
  281. ;---------------------------------------------
  282. ; Subtract 16 bit DE from 16 bit HL leaving
  283. ; result in HL
  284. ;---------------------------------------------
  285. sub16:
  286.     mov    a,l
  287.     sub    e
  288.     mov    l,a
  289.     mov    a,h
  290.     sbb    d
  291.     mov    h,a
  292.     ret
  293.  
  294. ;------------------------------------------------------------
  295. ; The following is the header block.  It is an image of the
  296. ; download and the execute command that will be sent to
  297. ; cause the rest of the code in the file to download
  298. ;------------------------------------------------------------
  299. header:
  300.     db    6        ;length of download command
  301.     db    pgmcmd        ;download opcode
  302.     db    1        ;dummy program id
  303. addr1:    dw    0        ;start of image location
  304. addr4:    dw    0        ;calculated length of image
  305.  
  306.     
  307.     db    0        ;length of execute command
  308.     db    0              ;command opcode
  309.     db    1        ;dummy program id
  310. addr3:    dw    0        ;execution start address
  311.  
  312.     db    0,0,0
  313. addr2:    dw    0        ;hold area for stop address
  314.  
  315. wrtaddr: dw    0        ;write address hold
  316.  
  317. msg1:    db    'Open file failed',cr,lf,'$'
  318. msg2:    db    'Write file failed',cr,lf,'$'
  319. msg3:    db    'Close failed',cr,lf,'$'
  320. msg4:    db    cr,lf,'GCPMON .COM file created',cr,lf,'$'
  321.  
  322. fcb:    db    0,'GCPMON  COM'
  323.     db    0,0,0,0,0,0,0,0
  324.     db    0,0,0,0,0,0,0,0
  325.     db    0,0,0,0,0,0,0,0è    db    0,0,0,0,0,0,0,0
  326. stak:    ds    40h
  327. stk:    db    0
  328.  
  329.     end    start
  330.  
  331.