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

  1. title 'GOCRCGEN - Cpm utility to download code to GCP        02/12/81'
  2. ;---------------------------------------------------------
  3. ;GOCRCGEN.COM is a special load program used to get a 
  4. ;    copy of the GCP code that resides on disk, 
  5. ;    Download it to the GCP boot for storage in RAM
  6. ;    and then give it control.  The first block
  7. ;    on disk is a header block that contains the
  8. ;    download commands to download, and then execute
  9. ;    downloaded code. Format of this block is as follows:
  10. ;
  11. ;    Modiified by D.C.Barrick 810206
  12. ;                 by D.A.STEELE  12 FEB 81
  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 is always  saved as CRCGEN.COM 
  33. ;    and is assumed to be on the A: drive.
  34. ;
  35. ;---------------------------------------------------------
  36.     cr    equ    0dh
  37.     lf    equ    0ah
  38.     @bdos    equ    0005h
  39.  
  40. page
  41. ;--------------------------------------------------------
  42. ; The following equates establish the linkage between
  43. ; the program in the TPA and the special GCP routines
  44. ; hidden in the BIOS
  45. ;--------------------------------------------------------
  46.  
  47. msize    equ    62        ; This should be set to system RAM size
  48.                 ; Note: This BIOS requires 2k more than the
  49.                 ; standard CP/M BIOS. Therefore the CCP/BDOS
  50.                 ; routines must be located 2k lower than normal.
  51.                 ; This is automactically accomplished by the 
  52.                 ; MOVCPM.COM supplied with InterSystems
  53.                 ; CP/M package. For example:
  54.                 ; MOVCPM 64 *    will create a CCP/BDOS
  55.                 ; which starts at DC00h instead of E400h.èbias    equ    (msize-22)*1024
  56. ccp    equ    3400h+bias    ; base of CCP
  57. bdos    equ    ccp+806h    ; base address of BDOS (about 7k below the BIOS)
  58. bios    equ    ccp+1600h    ; base address of BIOS (basic input/output system)
  59.  
  60. gxo    equ    bios+51        ; routine for transparent send to the GCP (char in <C>).
  61. dmawrt    equ    bios+69        ; routine to do DMA write to GCP
  62.                 ; <BC> has length, <DE> has data address
  63.  
  64. page
  65.     aseg
  66.     ORG    100H
  67. START:
  68.     ; save CP/M's stack
  69.  
  70.     di
  71.     lxi    h,0
  72.     dad    sp
  73.     shld    OLD$STACK
  74.     lxi    sp, USER$STACK
  75.     ei
  76.  
  77.     LXI    D,FCB
  78.     MVI    C,0FH        ;OPEN CODE
  79.     CALL    @bdos
  80.     ANI    0FCH        ;XXXX XX..
  81.     JZ    OPENOK
  82.     ;----------------------------------
  83.     ; The file CRCGEN.COM  doesn't exist, Tell someone and 
  84.     ; then exit.
  85.     ;----------------------------------
  86.     lxi    d,msg1
  87.     mvi    c,9
  88.     call    @bdos
  89.     ;--------------------------------------
  90.     ; return to CP/M
  91.     ;--------------------------------------
  92.     jmp    return
  93. openok:
  94. ;---------------------------------------------------------
  95. ; Read in the header block
  96. ;-----------------------------------------------------------
  97.     lxi    d,header
  98.     mvi    c,1ah        ;set dma address
  99.     call    @bdos
  100.  
  101.     lxi    d,fcb
  102.     mvi    c,20        ;read in header
  103.     call    @bdos
  104.     ani    0FCh        ;ignore low two bits as error
  105.     ora    a
  106.     jnz    rderr
  107.  
  108. ;-----------------------------------------------------------
  109. ; CRCGEN file has been opened and it's header block read intoè; memory.  Send the program download command and then 
  110. ; start the actual reads and DMA transfers.
  111. ;----------------------------------------------------------
  112.  
  113.     lxi    h,header
  114.     call    send        ;send to GCP
  115.     shld    execadd        ;save execute command address
  116.  
  117.     lxi    d,rdbuffer
  118.     mvi    c,1ah        ;set DMA address for data
  119.     call    @bdos
  120. rdloop:
  121.     lxi    d,fcb
  122.     mvi    c,20        ;read a block
  123.     call    @bdos
  124.     ani    0FCh        ;ignore read type bits
  125.     ora    a
  126.     jnz    rderr        ;go to write error msg
  127.     ;-----------------------------------------------
  128.     ; Drop the count by 128, if less than zero 
  129.     ; we must do a residual dma write, if new length is
  130.     ; zero, we must send a full 128 and then stop
  131.     ;-----------------------------------------------
  132.     lhld    addr4
  133.     lxi    d,128
  134.     call    sub16
  135.     jc    partial
  136.  
  137.     ;---------------------------------------------------
  138.     ; Must have been 128 or greater so DMA 128 bytes
  139.     ;---------------------------------------------------
  140.     shld    addr4
  141.     lxi    b,128        ;DMA length
  142.     lxi    d,rdbuffer    ;address
  143.     call    dmawrt
  144.  
  145.     ;----------------------------------
  146.     ; Now see if done. i.e. new length of zero
  147.     ;-----------------------------------
  148.     lhld    addr4
  149.     mov    a,l
  150.     ora    h
  151.     jz    endit
  152.  
  153.     jmp    rdloop        ;more
  154.     ;--------------------------------------
  155.     ; error condition
  156.     ; on write
  157.     ;---------------------------------------
  158. rderr:    lxi    d,msg2
  159.     mvi    c,9
  160.     call    @bdos
  161.     mvi    c,0
  162.     call    @bdos
  163. ;----------------------------------------------è; All done except for the last short block
  164. ;-----------------------------------------------
  165. partial:
  166.     lhld    addr4        ;get the partial buffer count
  167.     mov    b,h
  168.     mov    c,l
  169.     lxi    d,rdbuffer
  170.     call    dmawrt
  171.  
  172. ;------------------------------------------------
  173. ; close the file
  174. ;-------------------------------------------------
  175. endit:
  176.     lxi    d,fcb
  177.     mvi    c,10h        ;close
  178.     call    @bdos
  179.     ani    0fch
  180.     jz    endok
  181.     ;-----------------------------------------
  182.     ; didn't close successfully
  183.     ;------------------------------------------
  184.     lxi    d,msg3
  185.     mvi    c,9
  186.     call    @bdos
  187.     mvi    c,0
  188.     call    @bdos
  189.     jmp    return
  190. ;------------------------------------------------
  191. ; all done successfully
  192. ;
  193. ;    send the start execution code
  194. ;------------------------------------------------
  195. endok:
  196.     lhld    execadd        ;restore execute command address & send
  197.     call    send
  198.  
  199. ;------------------------------------------------
  200. ; wait a while for the GCP to start up
  201. ; then return to CP/M
  202. ;------------------------------------------------
  203.     lxi    h,1000h
  204. delay:
  205.     dcx    h
  206.     mov    a,h
  207.     ora    l
  208.     jnz    delay
  209.     jmp    return
  210. page
  211. ;---------------------------------------------
  212. ; Subtract 16 bit DE from 16 bit HL leaving
  213. ; result in HL
  214. ;---------------------------------------------
  215. sub16:
  216.     mov    a,l
  217.     sub    eè    mov    l,a
  218.     mov    a,h
  219.     sbb    d
  220.     mov    h,a
  221.     ret
  222.  
  223. ;-------------------------------------------------------
  224. ; SEND  This is used to send a command sequence to the
  225. ;    Skeleton GCP. The HL register must point to the
  226. ;    command length byte. NOTE that the length byte
  227. ;    doesn't include itself.   On completeion
  228. ;    <HL> should point to the next commands length byte.
  229. ;---------------------------------------------------------
  230. send:
  231.     mov    a,m        ;get length byte
  232.     inr    a        ;add one to get length that I must send.
  233. send2:
  234.     push    h
  235.     push    psw
  236.     mov    c,m        ;get a byte 
  237.     call    gxo        ;and send
  238.     pop    psw
  239.     pop    h
  240.     inx    h        ;step to next
  241.     dcr    a        ;drop count
  242.     rz            ;return on all sent
  243.     jmp    send2        ;go send more
  244.  
  245. ;-----------------------------------------------------------
  246. ; Restore CP/M's stack and return
  247. ;-----------------------------------------------------------
  248. return:
  249.     di
  250.     lhld    old$stack
  251.     sphl
  252.     ei
  253.     ret 
  254.  
  255. page
  256. ;------------------------------------------------------------
  257. ; The following is the header block.  It is an image of the
  258. ; download and the execute command that will be sent to
  259. ; cause the rest of the code in the file to download
  260.  
  261. ;------------------------------------------------------------
  262. header:
  263.     ds    1        ;length of download command
  264.     ds    1        ;download command opcode
  265.     ds    1        ;dummy program id
  266. addr1:    ds    2        ;start of image location
  267. addr4:    ds    2        ;calculated length of image
  268.  
  269.     
  270.     ds    1        ;length of execute command
  271.     ds    1        ;execute commands opcodeè    ds    1        ;dummy program id
  272. addr3:    ds    2        ;execution start address
  273.  
  274.     ds    3        ;dummy area
  275. addr2:    ds    2        ;hold area for stop address
  276.  
  277. rdaddr: ds    2        ;write address hold
  278. execadd:ds    2        ;hold for executes command address
  279.  
  280. rdbuffer: ds    128        ;download buffer
  281.  
  282. msg1:    db    'No CRCGEN.COM file on drive A.',cr,lf,'$'
  283. msg2:    db    'GCP Read file failed',cr,lf,'$'
  284. msg3:    db    'Close failed',cr,lf,'$'
  285.  
  286. fcb:    db    0,'CRCGEN  COM'
  287.     db    0,0,0,0,0,0,0,0
  288.     db    0,0,0,0,0,0,0,0
  289.     db    0,0,0,0,0,0,0,0
  290.     db    0,0,0,0,0,0,0,0
  291.     ds    80h        ; user stack space
  292. user$stack    equ    $
  293.  
  294. old$stack:
  295.     ds    2        ; save location for CP/M's stack pointer
  296.     end    start
  297.  
  298.