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 / LANGUAGS / FORTRAN / CPMLIB.ARK / CPMFN.MAC < prev    next >
Text File  |  1982-01-12  |  12KB  |  624 lines

  1. ;
  2. ;    CPMFN
  3. ;
  4. ;    CP/M BDOS Functions - interface routines
  5. ;
  6. ;
  7. ;    Originally written:  November, 1981
  8. ;
  9. ;    Pre-release modifications:
  10. ;    Dec. 10, 1981 - Added EXIST routine (FN17)
  11. ;
  12. ;    Released to CP/M User's Group as:
  13. ;    Version 1.0
  14. ;    January 12, 1982
  15. ;
  16. ;    Author: William R. Brandoni
  17. ;
  18. ;    Language: Microsoft M80 (MACRO-80 assembler) Version 3.4 (26-Nov-80)
  19. ;
  20. ;
  21. ;    See the "User-Defined Equates" section for modifications
  22. ;    you may have to make to reassemble this file.
  23. ;
  24. ;    Note that function classes that are not active at this
  25. ;    time are untested.
  26. ;
  27. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  28. ;
  29. ;    This file is a general purpose interface for
  30. ;    BDOS calls to CP/M version 2.x.
  31. ;
  32. ;    The main reason for its existance is to provide
  33. ;    an interface between Microsoft FORTRAN-80 and
  34. ;    several I/O operations not supported in that
  35. ;    language.
  36. ;
  37. ;    This file is intended as support to Microsoft FORTRAN
  38. ;    subroutines which in turn provide all of the
  39. ;    interfacing and setup functions prior to calling
  40. ;    one of these entry points.
  41. ;    As a result, this file is NOT a complete BDOS interface.
  42. ;    It provides only the basic machine-level system calls.
  43. ;    Arguments are assumed to be passed into these routines
  44. ;    in Microsoft format (ie. all arguments passed as addresses).
  45. ;
  46. ;    The structure of this file is such that a maximum of
  47. ;    two arguments can be passed from FORTRAN.  This is because
  48. ;    the third would be passed in the BC register pair, and
  49. ;    register B is overwritten immediately upon entry.
  50. ;    If more than two arguments should be required at a future
  51. ;    time, then the entry point would need to be restructured.
  52. ;
  53. ;    For the time being, only a few BDOS functions are supported.
  54. ;    However, the structure is such that more can be added
  55. ;    at a future time.
  56. ;    (Note that many BDOS I/O functions are already contained
  57. ;    within FORTRAN, so they do not need to be supported here.)
  58. ;
  59. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  60. ;
  61. ;    For an explanation of the various BDOS functions, see
  62. ;    the "CP/M 2.0 INTERFACE GUIDE" (c) 1979 by Digital
  63. ;    Research -- including the addendum for CP/M 2.2
  64. ;
  65. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  66. ;
  67. ;    For programming expediency, the BDOS functions
  68. ;    were assigned to arbitrary "classes".
  69. ;
  70. ;    The "classes" are defined as:
  71. ;
  72. ;    CLASS A:    Function value:        C
  73. ;
  74. ;    CLASS B:    Function value:        C
  75. ;            Returned value:        A
  76. ;
  77. ;    CLASS C:    Function value:        C
  78. ;            Input value:        E
  79. ;
  80. ;    CLASS D:    Function value:        C
  81. ;            Input value:        E
  82. ;            Returned value:        A
  83. ;
  84. ;    CLASS E:    Function value:        C
  85. ;            Input address:        <DE>
  86. ;
  87. ;    CLASS F:    Function value:        C
  88. ;            Input address:        <DE>
  89. ;            Returned value:        A
  90. ;
  91. ;    CLASS G:    Function value:        C
  92. ;            Input value:        DE
  93. ;            Returned value:        A
  94. ;
  95. ;    CLASS H:    Function value:        C
  96. ;            Returned value:        HL
  97. ;
  98. ;    CLASS I:    Function value:        C
  99. ;            Returned address:    <HL>
  100. ;
  101. ;
  102. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  103. ;
  104. ;    Using this classification, the functions (0 - 40) 
  105. ;    provided by CP/M version 2.2 are assigned 
  106. ;    as follows:
  107. ;
  108. ;    CLASS        FUNCTION
  109. ;
  110. ;    A         0, 13, 28
  111. ;    B         1,  3,  7, 11, 18, 25
  112. ;    C         2,  4,  5,  8, 14
  113. ;    D         6, 32
  114. ;    E         9, 10, 26, 35, 36
  115. ;    F        15, 16, 17, 19, 20, 21, 22, 23,
  116. ;            30, 33, 34, 40
  117. ;    G        37
  118. ;    H        12, 24, 29
  119. ;    I        27, 31
  120. ;    (undefined)    38, 39
  121. ;
  122. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  123.     PAGE
  124. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  125. ;
  126. ;    User-Defined Equates
  127. ;
  128. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  129. ;
  130. ;    Define base of CP/M (std version is 0000H)
  131. ;
  132. ;
  133.     BASE    EQU    0000H    ;<--- set to base of your CP/M
  134. ;
  135. ;
  136. ;
  137. ;    Define which functions to support: 0 = no / 1 = yes
  138. ;
  139. ;
  140. ;                Function        FORTRAN 
  141. ;                Description        Interface
  142. ;                            Routine
  143. ;
  144.     FN0    EQU    0    ;system reset
  145.     FN1    EQU    1    ;console input        INCHR
  146.     FN2    EQU    0    ;console output
  147.     FN3    EQU    0    ;reader input
  148.     FN4    EQU    0    ;punch output
  149.     FN5    EQU    0    ;list output
  150.     FN6    EQU    1    ;direct console I/O    INKEY
  151.     FN7    EQU    0    ;get I/O byte
  152.     FN8    EQU    0    ;set I/O byte
  153.     FN9    EQU    0    ;print string
  154.     FN10    EQU    0    ;read console buffer
  155.     FN11    EQU    0    ;get console status
  156.     FN12    EQU    0    ;return version number
  157.     FN13    EQU    0    ;reset disk system
  158.     FN14    EQU    0    ;select disk
  159.     FN15    EQU    0    ;open file
  160.     FN16    EQU    0    ;close file
  161.     FN17    EQU    1    ;search for first    EXIST (1)
  162.     FN18    EQU    0    ;search for next
  163.     FN19    EQU    1    ;delete file        ERASE
  164.     FN20    EQU    0    ;read sequential
  165.     FN21    EQU    0    ;write sequential
  166.     FN22    EQU    0    ;make file
  167.     FN23    EQU    1    ;rename file        RENAME
  168.     FN24    EQU    0    ;return login vector
  169.     FN25    EQU    0    ;return current disk
  170.     FN26    EQU    0    ;set DMA address
  171.     FN27    EQU    0    ;get address (alloc)
  172.     FN28    EQU    0    ;write protect disk
  173.     FN29    EQU    0    ;get R/O vector
  174.     FN30    EQU    0    ;get file attributes
  175.     FN31    EQU    0    ;get address (disk parms)
  176.     FN32    EQU    0    ;set/get user code
  177.     FN33    EQU    0    ;read random
  178.     FN34    EQU    0    ;write random
  179.     FN35    EQU    0    ;compute file size
  180.     FN36    EQU    0    ;set random record
  181.     FN37    EQU    0    ;reset drive
  182.     FN38    EQU    0    ;*** not defined ***
  183.     FN39    EQU    0    ;*** not defined ***
  184.     FN40    EQU    0    ;write random with zero fill
  185. ;
  186. ;    Notes:    (1)    used in RENAME, also.
  187. ;
  188. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  189.     PAGE
  190. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  191. ;
  192. ;    Miscellaneous Equates
  193. ;
  194.     BDOS    EQU    BASE+0005H
  195. ;
  196. ;    Define which classes are active
  197. ;
  198.     CLASSA    EQU    FN0+FN13+FN28
  199.     CLASSB    EQU    FN1+FN3+FN7+FN11+FN18+FN25
  200.     CLASSC    EQU    FN2+FN4+FN5+FN8+FN14
  201.     CLASSD    EQU    FN6+FN32
  202.     CLASSE    EQU    FN9+FN10+FN26+FN35+FN36
  203.     CLF    EQU    FN15+FN16+FN17+FN19+FN20+FN21+FN22+FN23
  204.     CLASSF    EQU    CLF+FN30+FN33+FN34+FN40
  205.     CLASSG    EQU    FN37
  206.     CLASSH    EQU    FN12+FN24+FN29
  207.     CLASSI    EQU    FN27+FN31
  208. ;
  209. ;    Define which temporary variables are needed
  210. ;
  211.     MAKEP2    EQU    CLASSD+CLASSF+CLASSG
  212.     MAKEP1    EQU    MAKEP2+CLASSB+CLASSC+CLASSE+CLASSH
  213. ;
  214.     PAGE
  215. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  216. ;
  217. ;    Define the entry points
  218. ;
  219.     IF    FN0
  220.     ENTRY    CPMF0
  221. CPMF0:    MVI    C,0
  222.     JMP    GOTOA
  223.     ENDIF
  224. ;
  225.     IF    FN1
  226.     ENTRY    CPMF1
  227. CPMF1:    MVI    C,1
  228.     JMP    GOTOB
  229.     ENDIF
  230. ;
  231.     IF    FN2
  232.     ENTRY    CPMF2
  233. CPMF2:    MVI    C,2
  234.     JMP    GOTOC
  235.     ENDIF
  236. ;
  237.     IF    FN3
  238.     ENTRY    CPMF3
  239. CPMF3:    MVI    C,3
  240.     JMP    GOTOB
  241.     ENDIF
  242. ;
  243.     IF    FN4
  244.     ENTRY    CPMF4
  245. CPMF4:    MVI    C,4
  246.     JMP    GOTOC
  247.     ENDIF
  248. ;
  249.     IF    FN5
  250.     ENTRY    CPMF5
  251. CPMF5:    MVI    C,5
  252.     JMP    GOTOC
  253.     ENDIF
  254. ;
  255.     IF    FN6
  256.     ENTRY    CPMF6
  257. CPMF6:    MVI    C,6
  258.     JMP    GOTOD
  259.     ENDIF
  260. ;
  261.     IF    FN7
  262.     ENTRY    CPMF7
  263. CPMF7:    MVI    C,7
  264.     JMP    GOTOB
  265.     ENDIF
  266. ;
  267.     IF    FN8
  268.     ENTRY    CPMF8
  269. CPMF8:    MVI    C,8
  270.     JMP    GOTOC
  271.     ENDIF
  272. ;
  273.     IF    FN9
  274.     ENTRY    CPMF9
  275. CPMF9:    MVI    C,9
  276.     JMP    GOTOE
  277.     ENDIF
  278. ;
  279.     IF    FN10
  280.     ENTRY    CPMF10
  281. CPMF10:    MVI    C,10
  282.     JMP    GOTOE
  283.     ENDIF
  284. ;
  285.     IF    FN11
  286.     ENTRY    CPMF11
  287. CPMF11:    MVI    C,11
  288.     JMP    GOTOB
  289.     ENDIF
  290. ;
  291.     IF    FN12
  292.     ENTRY    CPMF12
  293. CPMF12:    MVI    C,12
  294.     JMP    GOTOH
  295.     ENDIF
  296. ;
  297.     IF    FN13
  298.     ENTRY    CPMF13
  299. CPMF13:    MVI    C,13
  300.     JMP    GOTOA
  301.     ENDIF
  302. ;
  303.     IF    FN14
  304.     ENTRY    CPMF14
  305. CPMF14:    MVI    C,14
  306.     JMP    GOTOC
  307.     ENDIF
  308. ;
  309.     IF    FN15
  310.     ENTRY    CPMF15
  311. CPMF15:    MVI    C,15
  312.     JMP    GOTOF
  313.     ENDIF
  314. ;
  315.     IF    FN16
  316.     ENTRY    CPMF16
  317. CPMF16:    MVI    C,16
  318.     JMP    GOTOF
  319.     ENDIF
  320. ;
  321.     IF    FN17
  322.     ENTRY    CPMF17
  323. CPMF17:    MVI    C,17
  324.     JMP    GOTOF
  325.     ENDIF
  326. ;
  327.     IF    FN18
  328.     ENTRY    CPMF18
  329. CPMF18:    MVI    C,18
  330.     JMP    GOTOB
  331.     ENDIF
  332. ;
  333.     IF    FN19
  334.     ENTRY    CPMF19
  335. CPMF19:    MVI    C,19
  336.     JMP    GOTOF
  337.     ENDIF
  338. ;
  339.     IF    FN20
  340.     ENTRY    CPMF20
  341. CPMF20:    MVI    C,20
  342.     JMP    GOTOF
  343.     ENDIF
  344. ;
  345.     IF    FN21
  346.     ENTRY    CPMF21
  347. CPMF21:    MVI    C,21
  348.     JMP    GOTOF
  349.     ENDIF
  350. ;
  351.     IF    FN22
  352.     ENTRY    CPMF22
  353. CPMF22:    MVI    C,22
  354.     JMP    GOTOF
  355.     ENDIF
  356. ;
  357.     IF    FN23
  358.     ENTRY    CPMF23
  359. CPMF23:    MVI    C,23
  360.     JMP    GOTOF
  361.     ENDIF
  362. ;
  363.     IF    FN24
  364.     ENTRY    CPMF24
  365. CPMF24:    MVI    C,24
  366.     JMP    GOTOH
  367.     ENDIF
  368. ;
  369.     IF    FN25
  370.     ENTRY    CPMF25
  371. CPMF25:    MVI    C,25
  372.     JMP    GOTOB
  373.     ENDIF
  374. ;
  375.     IF    FN26
  376.     ENTRY    CPMF26
  377. CPMF26:    MVI    C,26
  378.     JMP    GOTOE
  379.     ENDIF
  380. ;
  381.     IF    FN27
  382.     ENTRY    CPMF27
  383. CPMF27:    MVI    C,27
  384.     JMP    GOTOI
  385.     ENDIF
  386. ;
  387.     IF    FN28
  388.     ENTRY    CPMF28
  389. CPMF28:    MVI    C,28
  390.     JMP    GOTOA
  391.     ENDIF
  392. ;
  393.     IF    FN29
  394.     ENTRY    CPMF29
  395. CPMF29:    MVI    C,29
  396.     JMP    GOTOH
  397.     ENDIF
  398. ;
  399.     IF    FN30
  400.     ENTRY    CPMF30
  401. CPMF30:    MVI    C,30
  402.     JMP    GOTOF
  403.     ENDIF
  404. ;
  405.     IF    FN31
  406.     ENTRY    CPMF31
  407. CPMF31:    MVI    C,31
  408.     JMP    GOTOI
  409.     ENDIF
  410. ;
  411.     IF    FN32
  412.     ENTRY    CPMF32
  413. CPMF32:    MVI    C,32
  414.     JMP    GOTOD
  415.     ENDIF
  416. ;
  417.     IF    FN33
  418.     ENTRY    CPMF33
  419. CPMF33:    MVI    C,33
  420.     JMP    GOTOF
  421.     ENDIF
  422. ;
  423.     IF    FN34
  424.     ENTRY    CPMF34
  425. CPMF34:    MVI    C,34
  426.     JMP    GOTOF
  427.     ENDIF
  428. ;
  429.     IF    FN35
  430.     ENTRY    CPMF35
  431. CPMF35:    MVI    C,35
  432.     JMP    GOTOE
  433.     ENDIF
  434. ;
  435.     IF    FN36
  436.     ENTRY    CPMF36
  437. CPMF36:    MVI    C,36
  438.     JMP    GOTOE
  439.     ENDIF
  440. ;
  441.     IF    FN37
  442.     ENTRY    CPMF37
  443. CPMF37:    MVI    C,37
  444.     JMP    GOTOG
  445.     ENDIF
  446. ;
  447.     IF    FN38
  448.     .PRINTX /ERROR --- Function 38 is not defined in BDOS./
  449.     ENDIF
  450. ;
  451.     IF    FN39
  452.     .PRINTX /ERROR --- Function 39 is not defined in BDOS./
  453.     ENDIF
  454. ;
  455.     IF    FN40
  456.     ENTRY    CPMF40
  457. CPMF40:    MVI    C,40
  458.     JMP    GOTOF
  459.     ENDIF
  460. ;
  461.     PAGE
  462.     IF    CLASSA
  463. ;
  464. ;            CLASS  A
  465. ;            --------
  466. ;
  467. ;    Arguments    FORTRAN                BDOS
  468. ;    (none)
  469. ;
  470. GOTOA:    CALL    BDOS
  471.     RET
  472.     ENDIF
  473.     PAGE
  474.     IF    CLASSB
  475. ;
  476. ;            CLASS  B
  477. ;            --------
  478. ;
  479. ;    Arguments    FORTRAN                BDOS
  480. ;    P1 (1-byte out)    address of P1 in HL        value of P1 in A
  481. ;
  482. GOTOB:    SHLD    P1    ;save address of param 1
  483.     CALL    BDOS
  484.     LHLD    P1    ;restore address of param 1
  485.     MOV    M,A    ;    and move returned value to it
  486.     RET
  487.     ENDIF
  488.     PAGE
  489.     IF    CLASSC
  490. ;
  491. ;            CLASS  C
  492. ;            --------
  493. ;
  494. ;    Arguments    FORTRAN                BDOS
  495. ;    P1 (1-byte in)    address of P1 in HL        value of P1 in E
  496. ;
  497. GOTOC:    SHLD    P1    ;save address of param 1
  498.     MOV    E,M    ;    and move contents to E
  499.     CALL    BDOS
  500.     LHLD    P1    ;restore address of param 1
  501.     RET
  502.     ENDIF
  503.     PAGE
  504.     IF    CLASSD
  505. ;
  506. ;            CLASS  D
  507. ;            --------
  508. ;
  509. ;    Arguments    FORTRAN                BDOS
  510. ;    P1 (1-byte in)    address of P1 in HL        value of P1 in E
  511. ;    P2 (1-byte out)    address of P2 in DE        value of P2 in A
  512. ;
  513. GOTOD:    SHLD    P1    ;save address of param 1
  514.     XCHG        ;    and swap
  515.     SHLD    P2    ;save address of param 2
  516.     XCHG        ;    and swap back
  517.     MOV    E,M    ;    and move contents to E
  518.     CALL BDOS
  519.     LHLD    P2    ;restore param 2 to HL
  520.     MOV    M,A    ;    move returned value to it
  521.     XCHG        ;    and swap back to DE
  522.     LHLD    P1    ;restore param 1 to HL
  523.     RET
  524.     ENDIF
  525.     PAGE
  526.     IF    CLASSE
  527. ;
  528. ;            CLASS  E
  529. ;            --------
  530. ;
  531. ;    Arguments    FORTRAN                BDOS
  532. ;    P1 (address in)    address of P1 in HL        address of P1 in DE
  533. ;
  534. GOTOE:    SHLD    P1    ;save param 1
  535.     XCHG        ;    and move to DE for BDOS
  536.     CALL    BDOS
  537.     LHLD    P1    ;restore param 1
  538.     RET
  539.     ENDIF
  540.     PAGE
  541.     IF    CLASSF
  542. ;
  543. ;            CLASS  F
  544. ;            --------
  545. ;
  546. ;    Arguments    FORTRAN                BDOS
  547. ;    P1 (address in)    address of P1 in HL        address of P1 in DE
  548. ;    P2 (1-byte out)    address of P2 in DE        value of P2 in A
  549. ;
  550. GOTOF:    SHLD    P1    ;save param 1
  551.     XCHG        ;    and swap params (ok for BDOS, too)
  552.     SHLD    P2    ;save address of param 2
  553.     CALL BDOS
  554.     LHLD    P2    ;restore address of param 2
  555.     MOV    M,A    ;    move returned value to it
  556.     XCHG        ;    and return to DE
  557.     LHLD    P1    ;restore param 1
  558.     RET
  559.     ENDIF
  560.     PAGE
  561.     IF    CLASSG
  562. ;
  563. ;            CLASS  G
  564. ;            --------
  565. ;
  566. ;    Arguments    FORTRAN                BDOS
  567. ;    P1 (2-byte in)    address of P1 in HL        value of P1 in DE
  568. ;    P2 (1-byte out)    address of P2 in DE        value of P2 in A
  569. ;
  570. GOTOG:    SHLD    P1    ;save address of param 1
  571.     XCHG        ;    and swap params
  572.     SHLD    P2    ;save address of param 2
  573.     XCHG        ;    and restore original order
  574.     MOV    E,M    ;transfer 2-byte data in
  575.     INX    H    ;    param 1 into
  576.     MOV    D,M    ;    reg. pair DE
  577.     CALL    BDOS
  578.     LHLD    P2    ;restore param 2 to HL
  579.     MOV    M,A    ;    move returned value to it
  580.     XCHG        ;    and return to DE
  581.     LHLD    P1    ;restore param 1 to HL
  582.     RET
  583.     ENDIF
  584.     PAGE
  585.     IF    CLASSH
  586. ;
  587. ;            CLASS  H
  588. ;            --------
  589. ;
  590. ;    Arguments    FORTRAN                BDOS
  591. ;    P1 (address out)    address of P1 in HL        2-byte value in HL
  592. ;
  593. GOTOH:    SHLD    P1    ;save address of P1
  594.     CALL    BDOS
  595.     XCHG        ;swap HL to DE
  596.     LHLD    P1    ;    and restore param 1 address
  597.     MOV    M,E    ;then, transfer DE contents to
  598.     INX    H    ;    memory at P1 and P1+1
  599.     MOV    M,D
  600.     DCX    H
  601.     RET
  602.     ENDIF
  603.     PAGE
  604.     IF    CLASSI
  605. ;
  606. ;            CLASS  I
  607. ;            --------
  608. ;
  609. ;
  610.     .PRINTX /WARNING -- CLASS I code not implemented yet./
  611.     ENDIF
  612.     PAGE
  613. ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  614. ;
  615. ;    Define temporary variables
  616. ;
  617.     IF    MAKEP1
  618. P1:    DS    2
  619.     ENDIF
  620.     IF    MAKEP2
  621. P2:    DS    2
  622.     ENDIF
  623.     END
  624.