home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / os968ka / k6outf.asm < prev   
Assembly Source File  |  2020-01-01  |  14KB  |  259 lines

  1.           nam       Kermit68K
  2.           ttl       Utility subroutines module
  3.  
  4. *         Kermit68K: source file K68UTF
  5. *
  6. * Author: Roberto Bagnara (Bagnara@Iboinfn.Bitnet),
  7. * Bologna University, Physics Department, July 1987.
  8. *
  9. * All rights reserved to Bologna University, Italy.
  10. *
  11. * Permission is granted to any individual or institution
  12. * to use, copy, or redistribute this software so long as
  13. * it  is not  sold for  profit, provided  this copyright
  14. * notice is retained.
  15. *
  16. * Modification History:
  17. *
  18. * Version  Date    Who              Comments
  19. *
  20. * 1.0.00   870701  Roberto Bagnara  First official release
  21.  
  22.           use       DefsFile
  23.  
  24. Edition   equ       0
  25.           psect     K68UtilitySubs,0,0,Edition,0,0
  26.  
  27. ********************************* CopyStr *****************************ok
  28. *                                                                     *
  29. *  Null terminated strings copy subroutine.                           *
  30. *                                                                     *
  31. *         Entry conditions : D0.W target string maximum length        *
  32. *                            A0.L pointer to target string            *
  33. *                            A1.L pointer to source string            *
  34. *                                                                     *
  35. *         Exit  conditions : A0.L pointer to target string            *
  36. *                            A1.L pointer to source string            *
  37. *                                                                     *
  38. ***********************************************************************
  39. CopyStr:  TST.W     D0                 Null strings ?
  40.           BEQ.S     CopyStr4           Yes, do nothing
  41.           MOVEM.L   A0-A1,-(A7)        Save pointers
  42. CopyStr1  SUBQ.W    #1,D0              Decrement counter
  43.           BNE.S     CopyStr2           Continue copy, if there is room
  44.           MOVE.B    D0,(A0)            End of target string, write terminator
  45.           BRA.S     CopyStr3           Restore pointers and return
  46. CopyStr2  MOVE.B    (A1)+,(A0)+        Copy a character
  47.           BNE.S     CopyStr1           Repeat until end of source string
  48. CopyStr3  MOVEM.L   (A7)+,A0-A1        Restore pointers
  49. CopyStr4  RTS
  50.  
  51. ********************************* CompStr *****************************ok
  52. *                                                                     *
  53. *  Null terminated strings compare subroutine.                        *
  54. *                                                                     *
  55. *         Entry conditions : A0.L pointer to string 1                 *
  56. *                            A1.L pointer to string 2                 *
  57. *                                                                     *
  58. *         Exit  conditions : D0.B completion code                     *
  59. *                            A0.L pointer to string 1                 *
  60. *                            A1.L pointer to string 2                 *
  61. *                                                                     *
  62. ***********************************************************************
  63. CompStr:  MOVEM.L   A0-A1,-(A7)        Save pointers
  64. CompStr1  MOVE.B    (A0)+,D0           Get a character from string 1
  65.           CMP.B     (A1)+,D0           Compare whit string 2 correspondent char
  66.           BNE.S     CompStr2           Compare failed, exit loop
  67.           TST.B     D0                 Compare succeed, end of strings ?
  68.           BNE.S     CompStr1           No, stay in loop
  69. CompStr2  SEQ       D0                 Set completion code accordingly
  70.           MOVEM.L   (A7)+,A0-A1        Restore pointers
  71.           RTS
  72.  
  73. ********************************* DoPrity *****************************ok
  74. *                                                                     *
  75. *  Add an appropriate parity bit to a character.                      *
  76. *                                                                     *
  77. *         Entry conditions : D0.B 7-bit character                     *
  78. *                                                                     *
  79. *         Exit  conditions : D0.B character with parity bit added     *
  80. *                                                                     *
  81. ***********************************************************************
  82. DoPrity:  MOVEM.L   D1-D2,-(A7)        Save working registers
  83.           MOVE.B    Parity(A6),D1      Some kind of parity enabled ?
  84.           BEQ.S     DoPrity5           No, return
  85.           ANDI.B    #$7F,D0            Clear bit 7
  86.           CMPI.B    #'M',D1            Mark ?
  87.           BNE.S     DoPrity1           No
  88.           ORI.B     #$80,D0            Yes, set bit 7
  89.           BRA.S     DoPrity5           Return
  90. DoPrity1  CMPI.B    #'S',D1            Space ?
  91.           BEQ.S     DoPrity5           Yes, return, bit 7 already cleared
  92.           CLR.B     D2                 Clear the ones counter
  93.           CMPI.B    #'O',D1            Odd ?
  94.           BNE.S     DoPrity2           No
  95.           ADDQ.B    #1,D2              Yes, the ones counter starts from 1
  96. DoPrity2  MOVEQ     #6,D1              Set up for bit addressing
  97. DoPrity3  BTST      D1,D0              Bit setted ?
  98.           BEQ.S     DoPrity4           No, try the next
  99.           ADDQ.B    #1,D2              Yes, increment the counter
  100. DoPrity4  DBF       D1,DoPrity3        Repeat for bits 6-0
  101.           LSL.B     #7,D2              Position the parity bit
  102.           OR.B      D2,D0              Ok, that's all
  103. DoPrity5  MOVEM.L   (A7)+,D1-D2        Restore working registers
  104.           RTS
  105.  
  106. ****************************** HndlPar ********************************ok
  107. *                                                                     *
  108. *  Handle 8-th bit accordingly to parity selected.                    *
  109. *                                                                     *
  110. *         Entry conditions : D0.B character to be processed           *
  111. *                                                                     *
  112. *         Exit  conditions : D0.B processed character                 *
  113. *                                                                     *
  114. ***********************************************************************
  115. HndlPar:  TST.B     Parity(A6)         Parity selected ?
  116.           BEQ.S     HndlPar1           No, do nothing
  117.           ANDI.B    #$7F,D0            Yes, mask parity bit
  118. HndlPar1  RTS
  119.  
  120. ********************************* UDiv ********************************ok
  121. *                                                                     *
  122. *  32-bit/16-bit unsigned division.                                   *
  123. *                                                                     *
  124. *         Entry conditions : D2.L dividend                            *
  125. *                            D3.W divisor                             *
  126. *                                                                     *
  127. *         Exit  conditions : D0.L quotient                            *
  128. *                            D1.L remainder                           *
  129. *                                                                     *
  130. ***********************************************************************
  131. UDiv:     MOVE.L    D2,D0              Get Dividend
  132.           CLR.W     D0                 Clear lower part
  133.           SWAP      D0                 Upper Dividend
  134.           DIVU      D3,D0              Divide
  135.           MOVE.W    D0,-(A7)           Save upper quotient
  136.           MOVE.W    D2,D0              Remainder and lower Dividend
  137.           DIVU      D3,D0              Divide
  138.           SWAP      D0
  139.           CLR.L     D1
  140.           MOVE.W    D0,D1              Final remainder
  141.           MOVE.W    (A7)+,D0           Lower and upper quotients
  142.           SWAP      D0                 Final quotient
  143.           RTS                          Return
  144.  
  145. ******************************* IntToAs *******************************ok
  146. *                                                                     *
  147. *  Integer to ASCII string conversion routine.                        *
  148. *                                                                     *
  149. *         Entry conditions : A0.L pointer to string buffer end        *
  150. *                            D0.L number to convert                   *
  151. *                            D1.B flag for signed or unsigned number  *
  152. *                            D2.L field length                        *
  153. *                            D3.L number base                         *
  154. *                                                                     *
  155. *         Exit  conditions : A0.L pointer to string buffer start      *
  156. *                                                                     *
  157. ***********************************************************************
  158. IntToAs:  MOVEM.W   D4-D6,-(A7)        Save working registers
  159.           MOVE.B    D1,D4              Load our flag for negative numbers
  160.           BEQ.S     IntToAs1           Unsigned number processing wanted
  161.           TST.L     D0                 Signed, negative number ?
  162.           SLT       D4                 Set our flag accordingly
  163.           BGE.S     IntToAs1           If positive number then continue
  164.           NEG.L     D0                 Else negate it
  165. IntToAs1  MOVE.B    D2,D5              Save field length
  166.           CLR.B     -(A0)              Mark the end of string
  167.           CLR.B     D6                 Clear the character counter
  168. IntToAs2  MOVE.L    D0,D2              Dividend
  169.           BSR       UDiv               Divide number by base (in D3)
  170.           CMPI.B    #9,D1              Convert remainder to ascii
  171.           BGT.S     IntToAs3
  172.           ADDI.B    #$30,D1
  173.           BRA.S     IntToAs4
  174. IntToAs3  ADDI.B    #$37,D1
  175. IntToAs4  MOVE.B    D1,-(A0)           Store the obtained character
  176.           ADDQ.B    #1,D6              Increment the character counter
  177.           TST.L     D0                 End of conversion ?
  178.           BNE.S     IntToAs2           No, repeat
  179.           TST.B     D4                 Yes, was a negative number ?
  180.           BEQ.S     IntToAs5           No, continue
  181.           MOVE.B    #'-',-(A0)         Yes, insert the minus sign
  182.           ADDQ.B    #1,D6              Increment the character counter
  183. IntToAs5  CMP.B     D6,D5              Field full ?
  184.           BLE.S     IntToAs6           Yes
  185.           MOVE.B    #' ',-(A0)         No, write a leading blank
  186.           ADDQ.B    #1,D6              Increment the character counter
  187.           BRA.S     IntToAs5           Continue padding until the field is full
  188. IntToAs6  MOVEM.W   (A7)+,D4-D6        Restore working registers
  189.           RTS
  190.  
  191. ******************************* UppCase *******************************ok
  192. *                                                                     *
  193. *  Make a character upper-cased.                                      *
  194. *                                                                     *
  195. *         Entry conditions : D3.B character to be converted           *
  196. *                                                                     *
  197. *         Exit  conditions : D3.B converted character                 *
  198. *                                                                     *
  199. ***********************************************************************
  200. UppCase:  CMPI.B    #'a',D3            Below a ?
  201.           BCS.S     UppCase1           Yes, return
  202.           CMPI.B    #'z',D3            Above z ?
  203.           BHI.S     UppCase1           Yes, return
  204.           SUBI.B    #32,D3             No, make the character upper-cased
  205. UppCase1  RTS
  206.  
  207. ******************************* IndxJump ******************************ok
  208. *                                                                     *
  209. *  Indexed jump, extract an address from a relative addresses table   *
  210. *  and jump to it.                                                    *
  211. *                                                                     *
  212. *         Entry conditions : D0.B index to jump table                 *
  213. *                            A1.L jump table start address            *
  214. *                                                                     *
  215. *         Exit  conditions : none, don't return                       *
  216. *                                                                     *
  217. ***********************************************************************
  218. IndxJump: ANDI.W    #$FF,D0            Make sure upper byte is cleared
  219.           LSL.W     #1,D0              Scale factor of 2
  220.           MOVE.W    (A1,D0.W),D0       Load relative pointer
  221.           JMP       (A1,D0.W)          Jump to service subroutine
  222.  
  223. MacFind:  BSR       UppCasS            Make the macro name upper-cased
  224.           LEA       MacroTbl(A6),A1    Load start address of macro table
  225.           CMPA.L    MTNxtChF(A6),A1    The macro table is empty ?
  226.           BEQ.S     MacFind2           Yes, return a bad completion code
  227. MacFind1  BSR       CompStr            Compare the two names
  228.           TST.B     D0                 The two names are equal ?
  229.           BNE.S     MacFind3           Yes, return the macro address
  230.           BSR       MacSkip            No, skip to next macro name
  231.           TST.B     D0                 It was the last macro ?
  232.           BEQ.S     MacFind1           No, so check this one
  233. MacFind2  MOVEA.L   A1,A0              Yes, this points to table end
  234.           SF        D0                 Return a bad completion code
  235.           RTS
  236. MacFind3  MOVEA.L   A1,A0              This is the desired macro address
  237.           ST        D0                 Return a positive completion code
  238.           RTS
  239.  
  240. MacSkip:  TST.B     (A1)+              Find the end of the macro name
  241.           BNE.S     MacSkip            Loop until end of macro name found
  242. MacSkip1  TST.B     (A1)+              Find the end of the macro body
  243.           BNE.S     MacSkip1           Loop until end of macro body found
  244.           CMPA.L    MTNxtChF(A6),A1    End of macro table ?
  245.           SEQ       D0                 Set the completion code accordingly
  246.           RTS
  247.  
  248. UppCasS   MOVE.L    A0,-(A7)
  249. UppCasS1  MOVE.B    (A0),D3
  250.           BEQ.S     UppCasS2
  251.           BSR       UppCase
  252.           MOVE.B    D3,(A0)+
  253.           BRA.S     UppCasS1
  254. UppCasS2  MOVE.L    (A7)+,A0
  255.           RTS
  256.  
  257.           ends
  258.           END
  259.