home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / DRI-archive / roche / GENGRAF.ASM < prev    next >
Assembly Source File  |  2009-12-11  |  16KB  |  695 lines

  1. ; GENGRAF.ASM
  2. ; -----------
  3. ;
  4. ; GSX-80 - GENGRAF.COM
  5. ;
  6. ; Disassembled by:
  7. ;
  8. ; ROCHE Emmanuel
  9. ; 8 rue HERLUISON
  10. ; 10000 TROYES
  11. ; FRANCE
  12. ; ------
  13. ;
  14. ;--------------------------------
  15. ;
  16.     PAGE    0        ; Listing without page breaks
  17. ;
  18.     ORG    0100H        ; Standard CP/M-80 COMmand file
  19. ;
  20. ;--------------------------------
  21. ; List of ASCII characters used
  22. ;
  23. lf    equ    0AH        ; Line Feed
  24. cr    equ    0DH        ; Carriage Return
  25. ctrlZ    equ    1AH        ; = End Of File
  26. ;
  27. ;--------------------------------
  28. ; List of BDOS functions used
  29. ;
  30. BDOS    equ    0005H        ; Basic Disk Operating System
  31. ;
  32. sysres    equ     0        ; System reset
  33. conout    equ     2        ; Console output
  34. pstring    equ     9        ; Print string
  35. openf    equ    15        ; Open file
  36. closef    equ    16        ; Close file
  37. deletef    equ    19        ; Delete file
  38. readf    equ    20        ; Read sequential
  39. writef    equ    21        ; Write sequential
  40. makef    equ    22        ; Make file
  41. renamef    equ    23        ; Rename file
  42. setDMA    equ    26        ; Set DMA address
  43. filsiz    equ    35        ; Compute file size
  44. ;
  45. ;--------------------------------
  46. ; List of page zero locations used
  47. ;
  48. reboot    EQU    0000H        ; Warm start
  49. dskuse    EQU    0004H        ; Current disk and user number
  50. topTPA    EQU    0006H        ; Address of top TPA
  51. I$0010    EQU    0010H        ; ----I
  52. I$0020    EQU    0020H        ; ----I
  53. FCB1    EQU    005CH        ; Default File Control Block 1
  54. ZERtyp    EQU    0065H        ; First char of filetype in page zero
  55. ZERcr    EQU    007CH        ; Current record position in page zero
  56. ZERrrn    EQU    007DH        ; Random record number in page zero
  57. DBUF    EQU    0080H        ; Default 128-byte disk buffer
  58. ;
  59. C$CD02    EQU    0CD02H        ; -C---
  60. I$CDF9    EQU    0CDF9H        ; ----I
  61. I$FFF3    EQU    0FFF3H        ; ----I
  62. ;
  63. ;--------------------------------
  64. ; List of offset inside Default FCB 1
  65. ;
  66. FCBtyp    equ    0009H        ; First char of filetype in FCB
  67. FCBex    equ    000CH        ; Current extent number  in FCB
  68. ;
  69. ;======================================================================
  70. ; Start of first program
  71. ;
  72. start1:    DB    0C3H        ; Jump opcode
  73. ;
  74. word1:    DW    start2        ; Point to start of program
  75. ;
  76. retone:    DB    0C9H        ; Return opcode
  77. ;
  78. word2:    DW    0000H        ; ?
  79. ;
  80. start3:    LXI    H,0001H        ; HL = 1 (point to BIOS entry?)
  81.     SPHL            ; Stack = above
  82.     CALL    chkASG        ; Check is ASSIGN.SYS is on disk
  83.     CALL    readA        ; Read ASSIGN.SYS file
  84.     MVI    A,05H        ; Number of drivers to try to load
  85.     PUSH    PSW        ; 
  86.     LXI    H,DMAbuf    ; DMA buffer (source)
  87.     LXI    D,DDnumb    ; DD number  (destination)
  88. getbyt:    MOV    A,M        ; Get a byte from ASSIGN.SYS
  89.     CPI    ctrlZ        ; = EOF?
  90.     JZ    close3        ; Then Close ASSIGN.SYS
  91.     CPI    31H        ; Is it a number?
  92.     JNC    dozen        ; 
  93.     XRA    A        ; If < 1 then set to 0
  94.     JMP    digit        ; 
  95. ;
  96. ;--------------------------------
  97. ;
  98. dozen:    SUI    30H        ; Convert to binary number
  99.     ADD    A        ; (Multiplied by 10?)
  100.     MOV    B,A        ; 
  101.     ADD    A        ; 
  102.     ADD    A        ; 
  103.     ADD    B        ; 
  104. digit:    MOV    B,A        ; 
  105.     INX    H        ; 
  106.     MOV    A,M        ; Get a byte from ASSIGN.SYS
  107.     SUI    30H        ; Convert to binary number
  108.     ADD    B        ; 
  109.     STAX    D        ; Store it in DD number
  110.     XRA    A        ; Reset Reg-A to zero
  111.     INX    D        ; 
  112.     STAX    D        ; 2nd byte of DD number = zero
  113.     INX    D        ; 
  114.     INX    H        ; (Space separator in ASSIGN.SYS)
  115.     INX    H        ; (Point to drive letter)
  116.     CALL    upper        ; Convert to upper case
  117.     SUI    40H        ; Convert to binary number
  118.     STAX    D        ; Store in DD list
  119.     INX    D        ; Point to next char in destination
  120.     INX    H        ; Point to next char in source
  121.     MVI    C,08H        ; 8 chars of device driver
  122. DDname:    CALL    upper        ; Convert to upper case
  123.     CPI    ';'        ; Start of comments? (end of DD name)
  124.     JZ    fill1        ; 
  125.     CPI    cr        ; End of line?
  126.     JNZ    fill2        ; 
  127. fill1:    MVI    A,' '        ; Space for filling DD filename
  128.     DCX    H        ; Decrement counter
  129. fill2:    STAX    D        ; Put space in DD table
  130.     INX    D        ; 
  131.     DCR    C        ; = 0?
  132.     JNZ    DDname        ; No: loop
  133.     MVI    A,lf        ; Yes: we must have reached the Line Feed
  134. fill3:    CMP    M        ; Isn't it?
  135.     INX    H        ; 
  136.     JNZ    fill3        ; 
  137.     POP    PSW        ; 
  138.     DCR    A        ; Loop 5 times
  139.     PUSH    PSW        ; 
  140.     JNZ    getbyt        ; Get another byte from ASSIGN.SYS
  141. close3:    POP    PSW        ; 
  142.     CALL    closeA        ; Close ASSIGN.SYS
  143.     LHLD    topTPA        ; Load address of top of TPA from page zero
  144.     SHLD    savtop        ; Save address of top of TPA
  145.     LXI    D,DDlist    ; Source: List of 5 DD filenames
  146.     LXI    H,ASSIGN    ; Destin: ASSIGN.SYS file spec
  147.     MVI    C,09H        ; 9 bytes (drive code + DD filename)
  148.     CALL    copyDH        ; Copy one file specification
  149.     MVI    M,50H        ; "P" (add PRL filetype)
  150.     INX    H        ; 
  151.     MVI    M,52H        ; "R"
  152.     INX    H        ; 
  153.     MVI    M,4CH        ; "L"
  154.     CALL    C0278        ; 
  155.     LHLD    LOMEM        ; New top of TPA after DD is loaded
  156.     SHLD    savtop        ; Save address of top of TPA
  157.     LXI    D,GSXSYS    ; Source: GDOS file specification
  158.     LXI    H,ASSIGN    ; Destin: ASSIGN.SYS file spec
  159.     MVI    C,0CH        ; 12 bytes (drive code + FILENAME.TYP)
  160.     CALL    copyDH        ; Copy one file specification
  161.     CALL    C0278        ; 
  162.     LHLD    LOMEM        ; Destin: New top of TPA after DD is loaded
  163.     PUSH    H        ; 
  164.     LXI    B,dskuse    ; Current disk and user number
  165.     DAD    B        ; 
  166.     LXI    D,topTPA    ; Source: Load address of top TPA
  167.     MVI    C,02H        ; 2 bytes
  168.     CALL    copyDH        ; Copy it in LOMEM
  169.     LXI    D,DDnumb    ; Source: 
  170.     MVI    C,02H        ; 2 bytes
  171.     CALL    copyDH        ; Copy it in DDnumb
  172.     DCX    D        ; 
  173.     DCX    D        ; Source: 
  174.     MVI    C,37H        ; 55 bytes (5 times 11 bytes)
  175.     CALL    copyDH        ; Copy 5 file specifications
  176.     XCHG            ; 
  177.     INX    D        ; 
  178.     INX    D        ; 
  179.     MVI    C,pstring    ; Print string
  180.     CALL    BDOS        ; 
  181.     LHLD    word2        ; Load what?
  182.     POP    D        ; 
  183.     DAD    D        ; 
  184.     JNC    ninofm        ; 'not enough memory$'
  185.     XCHG            ; 
  186.     SHLD    topTPA        ; Store address of top TPA
  187.     MVI    C,setDMA    ; Set DMA address
  188.     LXI    D,DBUF        ; Default 128-bytes disk buffer
  189.     CALL    BDOS        ; 
  190.     LXI    D,reloc        ; Source: Put RELOC address in Reg-DE
  191.     LHLD    LOMEM        ; Destin: New top of TPA after DD is loaded
  192.     LXI    B,I$FFF3    ; Length of GSX.SYS (GDOS) ?
  193.     DAD    B        ; 
  194.     PUSH    H        ; 
  195.     SHLD    GDOSb        ; GDOS base
  196.     MVI    C,0DH        ; 13 bytes
  197.     CALL    copyDH        ; Copy a string in TPA
  198.     LXI    H,border    ; Limit between 1st and 2nd program
  199.     POP    D        ; 
  200.     PUSH    D        ; 
  201.     MOV    A,E        ; 
  202.     SUB    L        ; 
  203.     MOV    C,A        ; 
  204.     MOV    A,D        ; 
  205.     SBB    H        ; 
  206.     MOV    B,A        ; 
  207.     LXI    D,start1    ; Start of first program
  208.     JMP    retone        ; Return opcode
  209. ;
  210. ;--------------------------------
  211. ; HL source
  212. ; DE destination
  213. ; BC count
  214. ;
  215. reloc:    MOV    A,M        ; Get a byte
  216.     STAX    D        ; Put it in destination
  217.     INX    H        ; 
  218.     INX    D        ; 
  219.     DCX    B        ; Decrement 16 bit counter
  220.     MOV    A,B        ; 
  221.     ORA    C        ; If finished, then jump to GDOS
  222.     DB    0C2H        ; JNZ opcode
  223. GDOSb:    DW    0000H        ; GDOS base
  224.     JMP    start1        ; Else: Start of first program
  225. ;
  226. ;--------------------------------
  227. ; Test if lower cases.
  228. ; If so, convert to upper cases.
  229. ;
  230. upper:    MOV    A,M        ; Get a byte
  231.     INX    H        ; 
  232.     CPI    'a'        ; Beginning of lower cases?
  233.     RC            ; 
  234.     CPI    'z'+1        ; End of lower cases?
  235.     RNC            ; 
  236.     SUI    20H        ; Convert to upper cases
  237.     RET            ; 
  238. ;
  239. ;--------------------------------
  240. ; Copy a string in TPA from DE (source) to HL (destination)
  241. ;
  242. ; DE = source
  243. ; HL = destination
  244. ;  C = number of bytes
  245. ;
  246. copyDH:    LDAX    D        ; Get a byte from source
  247.     MOV    M,A        ; Put it in TPA at destination HL
  248.     INX    D        ; 
  249.     INX    H        ; 
  250.     DCR    C        ; Decrement counter
  251.     JNZ    copyDH        ; 
  252.     RET            ; 
  253. ;
  254. ;--------------------------------
  255. ;
  256. ninofm:    LXI    D,notmem    ; 'Not enough memory$'
  257.     JMP    bak2CPM        ; 
  258. ;
  259. ;--------------------------------
  260. ;
  261. notmem:    DB    'Not enough memory$'
  262. ;
  263. GSXSYS:    DB    00H        ; Default drive
  264.     DB    'GSX     SYS'    ; GDOS file specification
  265. ;
  266. ;--------------------------------
  267. ; Table of DDs
  268. ;
  269. ; Format:
  270. ; DW 0FFFFH is replaced by DD number (HI = DD number, LO = 00H)
  271. ; DB 00H    is replaced by the drive number
  272. ; DS 8      is replaced by the DD filename
  273. ;
  274. DDnumb:    DW    0FFFFH
  275. DDlist:    DB    00H
  276.     DB    '        '    ; First DD filename
  277. ;
  278.     DW    0FFFFH
  279.     DB    00H
  280.     DB    '        '    ; Second DD filename
  281. ;
  282.     DW    0FFFFH
  283.     DB    00H
  284.     DB    '        '    ; Third DD filename
  285. ;
  286.     DW    0FFFFH
  287.     DB    00H
  288.     DB    '        '    ; Fourth DD filename
  289. ;
  290.     DW    0FFFFH
  291.     DB    00H
  292.     DB    '        '    ; Fifth DD filename
  293. ;
  294. ;--------------------------------
  295. ;
  296. C0278:    CALL    chkASG        ; Check if ASSIGN.SYS is on disk
  297.     CALL    readA        ; Read ASSIGN.SYS file
  298.     LHLD    DMA2nd        ; DMA buffer 2nd byte (PRL program size)
  299.     PUSH    H        ; 
  300.     XCHG            ; 
  301.     LHLD    savtop        ; Load address of top of TPA
  302.     MOV    A,L        ; 
  303.     SUB    E        ; 
  304.     MOV    A,H        ; Compute HIMEM - PRL program size
  305.     SBB    D        ; 
  306.     MOV    H,A        ; 
  307.     MVI    L,00H        ; Page boundary
  308.     SHLD    LOMEM        ; Store address of new top of TPA
  309.     PUSH    H        ; 
  310.     PUSH    H        ; 
  311.     PUSH    D        ; 
  312.     CALL    readA        ; Read ASSIGN.SYS file
  313.     POP    B        ; 
  314.     POP    H        ; 
  315. J$0298:    CALL    C02C8        ; 
  316.     MOV    M,A        ; 
  317.     INX    H        ; 
  318.     DCX    B        ; 
  319.     MOV    A,C        ; 
  320.     ORA    B        ; 
  321.     JNZ    J$0298        ; 
  322.     POP    H        ; 
  323.     MOV    B,H        ; 
  324.     DCR    B        ; 
  325.     POP    D        ; 
  326. J$02A7:    MVI    C,08H        ; 8 
  327.     CALL    C02C8        ; 
  328. J$02AC:    RLC            ; 
  329.     PUSH    PSW        ; 
  330.     JNC    J$02B4        ; 
  331.     MOV    A,B        ; 
  332.     ADD    M        ; 
  333.     MOV    M,A        ; 
  334. J$02B4:    INX    H        ; 
  335.     DCX    D        ; 
  336.     MOV    A,D        ; 
  337.     ORA    E        ; 
  338.     JZ    close2        ; Close ASSIGN.SYS
  339.     POP    PSW        ; 
  340.     DCR    C        ; 
  341.     JNZ    J$02AC        ; 
  342.     JMP    J$02A7        ; 
  343. ;
  344. ;--------------------------------
  345. ;
  346. close2:    POP    PSW        ; 
  347.     CALL    closeA        ; Close ASSIGN.SYS
  348.     RET            ; 
  349. ;
  350. ;--------------------------------
  351. ;
  352. C02C8:    PUSH    H        ; 
  353.     PUSH    D        ; 
  354.     LHLD    D03B6        ; 
  355.     INR    L        ; 
  356.     JP    J$02D9        ; 
  357.     PUSH    B        ; 
  358.     CALL    readA        ; Read ASSIGN.SYS file
  359.     POP    B        ; 
  360.     LXI    H,0000H        ; 
  361. J$02D9:    SHLD    D03B6        ; 
  362.     LXI    D,DMAbuf    ; DMA buffer
  363.     DAD    D        ; 
  364.     MOV    A,M        ; 
  365.     POP    D        ; 
  366.     POP    H        ; 
  367.     RET            ; 
  368. ;
  369. ;--------------------------------
  370. ; Check if file is on disk
  371. ;
  372. chkASG:    LXI    D,ASSIGN    ; ASSIGN.SYS file spec
  373. chkfil:    PUSH    D        ; 
  374.     LXI    H,FCBex        ; Point to current extent number
  375.     DAD    D        ; 
  376.     MVI    M,00H        ; 
  377.     INX    H        ; 
  378.     INX    H        ; 
  379.     MVI    M,00H        ; 
  380.     MVI    A,80H        ; 
  381.     STA    D03B6        ; 
  382.     MVI    C,openf        ; Open file
  383.     CALL    BDOS        ; 
  384.     POP    D        ; 
  385.     LXI    H,I$0020    ; 
  386.     DAD    D        ; 
  387.     MVI    M,00H        ; 
  388. badchk:    ORA    A        ; Successful open/close?
  389.     RP            ; Yes: return
  390.     CALL    showFN        ; No: Display filename on console
  391.     LXI    D,notfnd    ; ' not found$'
  392.     JMP    bak2CPM        ; 
  393. ;
  394. ;--------------------------------
  395. ;
  396. closeA:    LXI    D,ASSIGN    ; ASSIGN.SYS file spec
  397.     MVI    C,closef    ; Close file
  398.     CALL    BDOS        ; 
  399.     JMP    badchk        ; Cf. above
  400. ;
  401. ;--------------------------------
  402. ; Display filename on console
  403. ;
  404. showFN:    XCHG            ; 
  405.     MOV    A,M        ; Get drive code
  406.     ORA    A        ; 
  407.     JZ    nodriv        ; 
  408.     ADI    40H        ; Convert drive code in letter
  409.     MOV    E,A        ; 
  410.     CALL    showit        ; 
  411.     MVI    E,':'        ; Drive separator
  412.     CALL    showit        ; 
  413. nodriv:    INX    H        ; 
  414.     MVI    A,8+1        ; Filename
  415.     CALL    loopri        ; 
  416.     MVI    E,'.'        ; Filename separator
  417.     CALL    showit        ; 
  418.     MVI    A,3+1        ; Filetype
  419.     CALL    loopri        ; 
  420.     RET            ; 
  421. ;
  422. ;--------------------------------
  423. ; Display a char on console
  424. ;
  425. showit:    PUSH    H        ; 
  426.     MVI    C,conout    ; Console output
  427.     CALL    BDOS        ; 
  428.     POP    H        ; 
  429.     RET            ; 
  430. ;
  431. ;--------------------------------
  432. ; Display n-1 chars on console
  433. ;
  434. loopri:    DCR    A        ; Done?
  435.     RZ            ; 
  436.     MOV    E,M        ; Get char
  437.     INX    H        ; Ready next char
  438.     PUSH    PSW        ; 
  439.     CALL    showit        ; Display the char on console
  440.     POP    PSW        ; 
  441.     JMP    loopri        ; Loop until done
  442. ;
  443. ;--------------------------------
  444. ; Read ASSIGN.SYS file
  445. ;
  446. readA:    LXI    D,DMAbuf    ; DMA buffer
  447.     MVI    C,setDMA    ; Set DMA address
  448.     CALL    BDOS        ; 
  449.     LXI    D,ASSIGN    ; ASSIGN.SYS file spec
  450.     PUSH    D        ; 
  451.     MVI    C,readf        ; Read sequential
  452.     CALL    BDOS        ; 
  453.     POP    D        ; 
  454.     ORA    A        ; Successful read?
  455.     RZ            ; Yes: return
  456.     CALL    showFN        ; No: Display filename on console
  457.     LXI    D,whyEOF    ; ':  unexpected EOF$'
  458. bak2CPM:MVI    C,pstring    ; Print string
  459.     CALL    BDOS        ; 
  460.     JMP    reboot        ; Warm start
  461. ;
  462. ;--------------------------------
  463. ;
  464. whyEOF:    DB    ':  unexpected EOF$'
  465. ;
  466. notfnd:    DB    ' not found$'
  467. ;
  468. ASSIGN:    DB    00H        ; Default drive
  469.     DB    'ASSIGN  SYS'    ; File specification
  470.     DS    24        ; Rest of FCB definition
  471. ;
  472. savtop:    DW    0000H        ; Save area for top of TPA
  473. ;
  474. LOMEM:    DW    0000H        ; Save area for new top of TPA,
  475.                 ;   after a DD is loaded in TPA
  476. ;
  477. D03B6:    DW    0000H        ; ?
  478. ;
  479. DMAbuf:    DB    00H        ; DMA buffer first byte
  480. ;
  481. DMA2nd:    DB    00H        ; DMA buffer second byte (PRL program size)
  482. ;
  483.     DS    126        ; Rest of 128-bytes buffer
  484. ;
  485. ;
  486. ;======================================================================
  487. ; Start of second program
  488. ;
  489. start2:    LXI    D,copyr        ; Copyright message
  490.     MVI    C,pstring    ; Print string
  491.     CALL    BDOS        ; 
  492.     LXI    H,ZERtyp    ; First char of filetype in page zero
  493.     MVI    M,43H        ; "C"  (add COM filetype)
  494.     INX    H        ; 
  495.     MVI    M,4FH        ; "O"
  496.     INX    H        ; 
  497.     MVI    M,4DH        ; "M"
  498.     LXI    D,FCB1        ; Default FCB in page zero
  499.     MVI    C,filsiz    ; Compute file size
  500.     CALL    BDOS        ; 
  501.     LHLD    ZERrrn        ; Random record number in page zero
  502.     DAD    H        ; 
  503.     DAD    H        ; 
  504.     DAD    H        ; 
  505.     DAD    H        ; 
  506.     DAD    H        ; 
  507.     DAD    H        ; 
  508.     DAD    H        ; 
  509.     LXI    D,I$048D    ; 
  510.     DAD    D        ; 
  511.     MOV    A,L        ; 
  512.     CMA            ; 
  513.     MOV    L,A        ; 
  514.     MOV    A,H        ; 
  515.     CMA            ; 
  516.     MOV    H,A        ; 
  517.     INX    H        ; 
  518.     SHLD    word2        ; Save what?
  519.     XRA    A        ; 
  520.     STA    ZERcr        ; Current record position set to zero
  521.     LXI    H,FCB1        ; Source: Default FCB in page zero
  522.     LXI    D,FCBseq    ; Destin: FCB for read/write seq
  523.     PUSH    D        ; 
  524.     MVI    C,24H        ; 36 bytes
  525.     CALL    copyHD        ; 
  526.     POP    D        ; 
  527.     PUSH    D        ; 
  528.     LXI    H,FCBtyp    ; Point to first char of filetype
  529. ;
  530. border:        ; +++ Limit between 1st and 2nd program +++
  531. ;
  532.     DAD    D        ; 
  533.     MVI    M,24H        ; "$" (temporary file)
  534.     INX    H        ; 
  535.     MVI    M,24H        ; "$"
  536.     INX    H        ; 
  537.     MVI    M,24H        ; "$"
  538.     MVI    C,deletef    ; Delete file
  539.     CALL    BDOS        ; 
  540.  
  541. I$048D    EQU    $-1        ; ???
  542.  
  543.     POP    D        ; 
  544.     MVI    C,makef        ; Make file
  545.     CALL    BDOS        ; 
  546.     INR    A        ; 
  547.     JZ    nodspc        ; Display 'no dir space' on console
  548.     LXI    H,start3    ; Relocate start of program
  549.     SHLD    word1        ; Point to start of program
  550.     LXI    D,start1    ; Start of first program
  551. J$04A1:    PUSH    D        ; 
  552.     MVI    C,setDMA    ; Set DMA address
  553.     CALL    BDOS        ; 
  554.     LXI    D,FCBseq    ; FCB for read/write seq
  555.     MVI    C,writef    ; Write sequential
  556.     CALL    BDOS        ; 
  557.     POP    D        ; 
  558.     LXI    H,DBUF        ; Default 128-bytes disk buffer
  559.     DAD    D        ; 
  560.     XCHG            ; 
  561.     LXI    H,start2    ; Start of second program
  562.     MOV    A,E        ; 
  563.     SUB    L        ; 
  564.     MOV    A,D        ; 
  565.     SBB    H        ; 
  566.     JC    J$04A1        ; 
  567.     LXI    D,FCB1        ; Default FCB in page zero
  568.     CALL    chkfil        ; Check if file is on disk
  569. J$04C5:    MVI    C,80H        ; 
  570.     LXI    D,copyr        ; 
  571. J$04CA:    PUSH    D        ; 
  572.     PUSH    B        ; 
  573.     MVI    C,setDMA    ; Set DMA address
  574.     CALL    BDOS        ; 
  575.     LXI    D,FCB1        ; Default FCB in page zero
  576.     MVI    C,readf        ; Read sequential
  577.     CALL    BDOS        ; 
  578.     STA    errcod        ; Error code (Read sequential)
  579.     ORA    A        ; 
  580.     POP    B        ; 
  581.     POP    D        ; 
  582.     JNZ    J04EE        ; 
  583.     DCR    C        ; 
  584.     JZ    J04EE        ; 
  585.     LXI    H,DBUF        ; Default 128-bytes disk buffer
  586.     DAD    D        ; 
  587.     XCHG            ; 
  588.     JMP    J$04CA        ; 
  589. ;
  590. ;--------------------------------
  591. ;
  592. J04EE:    MVI    A,80H        ; 
  593.     SUB    C        ; 
  594.     MOV    C,A        ; 
  595.     LXI    D,copyr        ; 
  596. J$04F5:    PUSH    B        ; 
  597.     PUSH    D        ; 
  598.     MVI    C,setDMA    ; Set DMA address
  599.     CALL    BDOS        ; 
  600.     LXI    D,FCBseq    ; FCB for read/write seq
  601.     MVI    C,writef    ; Write sequential
  602.     CALL    BDOS        ; 
  603.     ORA    A        ; 
  604.     POP    D        ; 
  605.     POP    B        ; 
  606.     JNZ    werror        ; Display 'write error$' on console
  607.     DCR    C        ; 
  608.     JZ    J$0516        ; 
  609.     LXI    H,DBUF        ; Default 128-bytes disk buffer
  610.     DAD    D        ; 
  611.     XCHG            ; 
  612.     JMP    J$04F5        ; 
  613. ;
  614. ;--------------------------------
  615. ;
  616. J$0516:    LDA    errcod        ; Error code (Read sequential)
  617.     ORA    A        ; 
  618.     JZ    J$04C5        ; 
  619.     LXI    D,FCBseq    ; FCB for read/write seq
  620.     MVI    C,closef    ; Close file
  621.     CALL    BDOS        ; 
  622.     LXI    D,FCB1        ; 
  623.     MVI    C,deletef    ; Delete file
  624.     CALL    BDOS        ; 
  625.     LXI    D,FCBseq    ; FCB for read/write seq
  626.     LXI    H,I$0010    ; 
  627.     DAD    D        ; 
  628.     MVI    C,10H        ; 16 bytes
  629.     XCHG            ; 
  630.     CALL    copyHD        ; 
  631.     LXI    H,rentyp    ; 
  632.     MVI    M,43H        ; "C" (add COM filetype)
  633.     INX    H        ; 
  634.     MVI    M,4FH        ; "O"
  635.     INX    H        ; 
  636.     MVI    M,4DH        ; "M"
  637.     MVI    C,renamef    ; Rename file
  638.     LXI    D,FCBseq    ; FCB for read/write seq
  639.     CALL    BDOS        ; 
  640.     MVI    C,sysres    ; System reset
  641.     JMP    BDOS        ; 
  642. ;
  643. ;--------------------------------
  644. ; HL = source
  645. ; DE = destination
  646. ;  C = count
  647. ;
  648. copyHD:    MOV    A,M        ; Get a byte
  649.     STAX    D        ; Put it in destination DE
  650.     INX    H        ; 
  651.     INX    D        ; 
  652.     DCR    C        ; Decrement count
  653.     JNZ    copyHD        ; 
  654.     RET            ; 
  655. ;
  656. ;--------------------------------
  657. ;
  658. werror:    LXI    D,wrierr    ; 'Write Error.$'
  659.     JMP    bak2CPM        ; 
  660. ;
  661. ;--------------------------------
  662. ;
  663. nodspc:    LXI    D,nodirs    ; 'No Directory Space.$'
  664.     JMP    bak2CPM        ; 
  665. ;
  666. ;--------------------------------
  667. ;
  668. errcod:    DB    00H        ; Error code (Read sequential)
  669. ;
  670.     DB    00H        ; (Byte added by linker?)
  671. ;
  672. FCBseq:    DB    00H        ; FCB for read/write seq
  673.     DB    00H,00H,00H,00H,00H,00H,00H,00H
  674.     DB    00H,00H,00H,00H,00H,00H,00H,00H
  675.     DB    00H,00H,00H,00H,00H,00H,00H,00H
  676. ;
  677. rentyp:    DB    00H,00H,00H    ; Filetype for renaming filename.COM
  678.     DB    00H,00H,00H,00H,00H,00H,00H,00H
  679. ;
  680. ;--------------------------------
  681. ;
  682. wrierr:    DB    'Write Error.$'
  683. ;
  684. nodirs:    DB    'No Directory Space.$'
  685. ;
  686. copyr:    DB    '---------------------------------------------------', cr, lf
  687.     DB    'GENGRAF 1.0  15 Nov 82   Serial No 5000-1232-654321', cr, lf
  688.     DB    'Copyright (C) 1982                                 ', cr, lf
  689.     DB    'Digital Research, Inc.          All Rights Reserved', cr, lf
  690.     DB    '---------------------------------------------------', cr, lf, '$'
  691. ;
  692. ;--------------------------------
  693. ;
  694.     END    100H        ; Standard CP/M-80 COMmand file
  695.