home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / apple / apbdsc.pat < prev    next >
Encoding:
Text File  |  1983-09-09  |  7.0 KB  |  218 lines

  1.               Customizing BDS-C for the Apple ][
  2.                  Jeff Martin 10/24/81
  3.  
  4. The Softcard-equipped Apple runs a pretty standard CP/M 2.2, and so in most
  5. respects supports the BDS C package without modification.  Problems arise only
  6. if C programs invoke certain standard library functions involved with physical
  7. input/output.  Specifically, the standard library is incompatible with the
  8. Apple in the following two areas:
  9.  
  10.       The plotting functions (setplot, clrplot, plot,
  11.           txtplot, and line) don't apply to the Apple, being
  12.           oriented towards an S-100 VDM1-like video board.
  13.  
  14.       The inp() and outp() functions assume the
  15.           processor does its input and output via I/O ports.
  16.           The Apple's I/O is strictly memory-mapped, so the
  17.           standard inp and outp functions won't work.
  18.  
  19. A third potential problem is the csw() function, but it's so blatantly
  20. non-portable that I assume nobody ever uses it.  Letting it sit there and read
  21. an unequipped port seems as good an approach as any.
  22.  
  23. The solution to the first problem is simply to disable (undefine) the plotting
  24. functions, so accidental invocation won't do horrible things to RAM. (The
  25. default initialization done by C.CCC sets the plotting base at CC00H, which for
  26. 56K Apple CP/M points a loaded gun at the BDOS).
  27.  
  28. The second problem requires a little more thought. First it should be noted
  29. that programs that use these functions can hope at best for near-portability at
  30. the C-source level.  Even among CP/M systems that use I/O ports, there is
  31. little standardization of the port assignments.  It is expected that programs
  32. using inp and outp will need easily-modified defines for the ports. On that
  33. basis, the best inward portability for the Apple can be achieved by changing
  34. inp and outp to do memory reads and writes, respectively.  Then the only
  35. required change to a source program will be changing the "port" definition
  36. value to the appropriate memory address.  This scheme also allows for outward
  37. portability, with one caveat: Apple programmers must resist the temptation to
  38. do I/O via pointers or the peek() and poke() functions and instead use the
  39. "redundant" (for the Apple) inp() and outp().
  40.  
  41. Now for the nuts-and-bolts of making the required mods.  Changes must be made
  42. to five source files, and the order of the changes is sometimes important.
  43.  
  44. 1. Make the following changes to CCC.ASM:
  45.     a. Change the DMAVIO equate to 0.
  46.     b. Insert a new equate, MEMMAPIO EQU 1.
  47.     c. Surround the iohack initialization code in "init" with an
  48.        IF NOT MEMMAPIO...ENDIF conditional assembly directive.
  49.     d. Similarly "feature out" the iohack ds directive.
  50.     e. Feature the ds's for pbase through psize as a function
  51.        of DMAVIO.
  52.  
  53. 2. Assemble CCC.ASM, noting the new locations of "ram" and "setdma".  Load
  54.    the result of the assembly, and rename it as your new C.CCC.
  55.  
  56. 3. Make the following changes in BDS.LIB:
  57.     a. Change the equates for ram and setdma to the values
  58.        noted above.
  59.     b. Add equates for MEMMAPIO (1) and DMAVIO (0).
  60.     c. "Feature" the ds's for iohack and pbase-psize
  61.        the same as you did in CCC.ASM.
  62.  
  63. 4. Make the following changes in DEFF2.ASM:
  64.     a. Change the "inp" function to generate code identical to
  65.        that of the "peek" function if MEMMAPIO is 1.
  66.     b. Change the "outp" function to generate code identical
  67.        to that of the "poke" function if MEMMAPIO is 1.
  68.  
  69. 5. Change DEFF2A.ASM so functions "setplot" through "txtplot" are not assembled
  70.    if DMAVIO is 0.  Note that directives must also be put in the "direct" area.
  71.  
  72. 6. Assemble and load DEFF2.ASM and DEFF2A.ASM, and merge them with CLIB to
  73.    create a new DEFF2.CRL.
  74.  
  75. 7. Finally, change the "port" definitions (and other attributes) in BDSCIO.H
  76.    to the correct memory addresses and masks for your console and modem.
  77.  
  78. Just so you won't think I missed the obvious, I'll point out that the inp() and
  79. outp() problems could have been "solved" in most cases by adding the following
  80. two lines to BDSCIO.H: 
  81. #define inp peek 
  82. #define outp poke
  83. I just don't think it's good to have unusable and potentially dangerous code
  84. lying around in libraries.
  85.  
  86. To be \really/ specific, what follows are UNIX-style "diff" outputs that
  87. indicate the specific changes made to V1.44 sources.  The BDSCIO.H changes
  88. are for a CCS serial card in slot 3 (for the console) and a MICROMODEM ][
  89. in slot 2.
  90.  
  91. ************************************************************
  92. Difference listing for CCC.ASM
  93.  
  94. 34c34
  95. < DMAVIO:    EQU 1        ;True if using DMA video library routines and
  96. ---
  97. > DMAVIO:    EQU 0        ;True if using DMA video library routines and
  98. 35a36,37
  99. > MEMMAPIO: EQU 1        ;True if I/O is memory-mapped, false if uses I/O ports
  100. >
  101. 681c683
  102. <             ;Initialize I/O hack locations:
  103. ---
  104. >     IF NOT MEMMAPIO    ;Initialize I/O hack locations:
  105. 689c691
  106. <
  107. ---
  108. >     ENDIF
  109. 1098a1101
  110. >     IF DMAVIO
  111. 1102a1106
  112. >     ENDIF
  113. 1107a1112
  114. >     IF NOT MEMMAPIO
  115. 1109a1115
  116. >     ENDIF
  117.  
  118.  
  119. ************************************************************
  120. Difference listing for BDS.LIB
  121.  
  122. 16a17,18
  123. > MEMMAPIO: EQU 1        ;true if I/O is memory-mapped, false if uses I/O ports
  124. > DMAVIO    EQU 0        ;true if equipped with DMA video I/O board, else false
  125. 43c45
  126. < ram:    equ cccorg+471h    ;THIS WILL PROBABLY CHANGE IF YOU CUSTOMIZE CCC.ASM
  127. ---
  128. > ram:    equ cccorg+447h    ;THIS WILL PROBABLY CHANGE IF YOU CUSTOMIZE CCC.ASM
  129. 89d90
  130. < setdma:    equ cccorg+460h    ;set CP/M internal DMA pointer to BASE+80h (tbuff)
  131. 90a92,96
  132. >             ;**************************************************
  133. >             ;THIS WILL PROBABLY CHANGE IF YOU CUSTOMIZE CCC.ASM
  134. > setdma:    equ cccorg+436h    ;set CP/M internal DMA pointer to BASE+80h (tbuff)
  135. >             ;**************************************************
  136. >
  137. 104a111
  138. >     if dmavio
  139. 108a116
  140. >     endif
  141. 113a122
  142. >     if not memmapio
  143. 114a124
  144. >     endif
  145.  
  146.  
  147. ************************************************************
  148. Difference listing for DEFF2.ASM
  149.  
  150. 731c731
  151. < ; Sample data at an input port:
  152. ---
  153. > ; Sample data at an input port (or address, if memory mapped):
  154. 734a735,740
  155. >     if memmapio
  156. >     call ma1toh    ;when mapped, inp == peek
  157. >     mov l,m
  158. >     mvi h,0
  159. >     ret
  160. >     else
  161. 740a747
  162. >     endif
  163. 749c756
  164. < ; Output a byte to an output port:
  165. ---
  166. > ; Output a byte to an output port (or address, if memory mapped):
  167. 752a760,766
  168. >     if memmapio
  169. >     call arghak    ;when mapped, outp == poke
  170. >     lhld arg1
  171. >     lda arg2
  172. >     mov m,a
  173. >     ret
  174. >     else
  175. 757a772
  176. >     endif
  177.  
  178.  
  179. ************************************************************
  180. Difference listing for DEFF2A.ASM
  181.  
  182. 11a12
  183. >     if dmavio
  184. 16a18
  185. >     endif
  186. 27c29
  187. <
  188. ---
  189. >     if dmavio
  190. 313a316
  191. >     endif    ;dmavio
  192. 315d317
  193. <
  194.  
  195. ************************************************************
  196. Difference listing for BDSCIO.H:
  197.  
  198. 41,42c41,42
  199. < #define CSTAT    0355    /* status port    */
  200. < #define CDATA    0350    /* data port    */
  201. ---
  202. > #define CSTAT    0xE0BE    /* status port    */
  203. > #define CDATA    0xE0BF    /* data port    */
  204. 44c44
  205. < #define COMASK    0x20    /* output data ready mask  */
  206. ---
  207. > #define COMASK    0x02    /* output data ready mask  */
  208. 53,54c53,54
  209. < #define    MSTAT    0335    /* status port    */
  210. < #define MDATA    0330    /* data port    */
  211. ---
  212. > #define    MSTAT    0xE0AE    /* status port    */
  213. > #define MDATA    0xE0AF    /* data port    */
  214. 56c56
  215. < #define MOMASK    0x20    /* ready to send a character mask    */
  216. ---
  217. > #define MOMASK    0x02    /* ready to send a character mask    */
  218.