| 1 |
88 |
robfinch |
; ============================================================================
|
| 2 |
|
|
; __
|
| 3 |
|
|
; \\__/ o\ (C) 2022 Robert Finch, Waterloo
|
| 4 |
|
|
; \ __ / All rights reserved.
|
| 5 |
|
|
; \/_// robfinch@opencores.org
|
| 6 |
|
|
; ||
|
| 7 |
|
|
;
|
| 8 |
|
|
;
|
| 9 |
|
|
; BSD 3-Clause License
|
| 10 |
|
|
; Redistribution and use in source and binary forms, with or without
|
| 11 |
|
|
; modification, are permitted provided that the following conditions are met:
|
| 12 |
|
|
;
|
| 13 |
|
|
; 1. Redistributions of source code must retain the above copyright notice, this
|
| 14 |
|
|
; list of conditions and the following disclaimer.
|
| 15 |
|
|
;
|
| 16 |
|
|
; 2. Redistributions in binary form must reproduce the above copyright notice,
|
| 17 |
|
|
; this list of conditions and the following disclaimer in the documentation
|
| 18 |
|
|
; and/or other materials provided with the distribution.
|
| 19 |
|
|
;
|
| 20 |
|
|
; 3. Neither the name of the copyright holder nor the names of its
|
| 21 |
|
|
; contributors may be used to endorse or promote products derived from
|
| 22 |
|
|
; this software without specific prior written permission.
|
| 23 |
|
|
;
|
| 24 |
|
|
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 25 |
|
|
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 26 |
|
|
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 27 |
|
|
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 28 |
|
|
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 29 |
|
|
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 30 |
|
|
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 31 |
|
|
; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 32 |
|
|
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 33 |
|
|
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 34 |
|
|
;
|
| 35 |
|
|
; ============================================================================
|
| 36 |
|
|
;
|
| 37 |
|
|
; Get a floating point number
|
| 38 |
|
|
;
|
| 39 |
|
|
_GetFloatGetChar:
|
| 40 |
|
|
move.b (a0),d1
|
| 41 |
|
|
add.l d0,a0
|
| 42 |
|
|
rts
|
| 43 |
|
|
_GetFloatIgnBlanks:
|
| 44 |
|
|
.0001
|
| 45 |
|
|
bsr _GetFloatGetChar
|
| 46 |
|
|
cmpi.b #' ',d1
|
| 47 |
|
|
beq .0001
|
| 48 |
|
|
_GetFloatBackupChar:
|
| 49 |
|
|
sub.l d0,a0
|
| 50 |
|
|
rts
|
| 51 |
|
|
|
| 52 |
|
|
;-------------------------------------------------------------------------------
|
| 53 |
|
|
; Get fractional part of a number, 25 digits max, into a float register.
|
| 54 |
|
|
;
|
| 55 |
|
|
; Register Usage:
|
| 56 |
|
|
; d1 = digit from input screen
|
| 57 |
|
|
; d4 = digit count
|
| 58 |
|
|
; d6 = digit scaling factor
|
| 59 |
|
|
; fp1 = digit as float number
|
| 60 |
|
|
; Returns:
|
| 61 |
|
|
; fp0 = fraction
|
| 62 |
|
|
;-------------------------------------------------------------------------------
|
| 63 |
|
|
|
| 64 |
|
|
_GetFraction:
|
| 65 |
|
|
link a2,#-28
|
| 66 |
|
|
move.l _canary,24(sp)
|
| 67 |
|
|
movem.l d1/d4/d6,(sp)
|
| 68 |
|
|
fmove.x fp1,12(sp)
|
| 69 |
|
|
clr.l d6 ; d6 = scale factor
|
| 70 |
|
|
fmove.w #0,fp0 ; fract = 0.0
|
| 71 |
|
|
moveq #24,d4
|
| 72 |
|
|
.0002
|
| 73 |
|
|
bsr _GetFloatGetChar
|
| 74 |
|
|
cmpi.b #'0',d1
|
| 75 |
|
|
blo .0001
|
| 76 |
|
|
cmpi.b #'9',d1 ; make sure between 0 and 9
|
| 77 |
|
|
bhi .0001
|
| 78 |
|
|
subi.b #'0',d1
|
| 79 |
|
|
fscale.w #1,fp0 ; fract * 10.0
|
| 80 |
|
|
addq #1,d6 ; record scaling
|
| 81 |
|
|
fmove.b d1,fp1 ; fp1 = digit
|
| 82 |
|
|
fadd fp1,fp0 ; fract += digit
|
| 83 |
|
|
addq.w #1,d5 ; increment number of digits in number
|
| 84 |
|
|
dbra d4,.0002
|
| 85 |
|
|
.0001
|
| 86 |
|
|
bsr _GetFloatBackupChar
|
| 87 |
|
|
neg d6
|
| 88 |
|
|
fscale.l d6,fp0 ; fract /= scale
|
| 89 |
|
|
movem.l (sp),d1/d4/d6
|
| 90 |
|
|
fmove.x 12(sp),fp1
|
| 91 |
|
|
cchk 24(sp)
|
| 92 |
|
|
unlk a2
|
| 93 |
|
|
rts
|
| 94 |
|
|
|
| 95 |
|
|
;-------------------------------------------------------------------------------
|
| 96 |
|
|
; Get exponent part of a number, 4 digits max, into a float register.
|
| 97 |
|
|
;
|
| 98 |
|
|
; Register Usage:
|
| 99 |
|
|
; d1 = digit from input screen
|
| 100 |
|
|
; d2 = exponent
|
| 101 |
|
|
; d3 = temp, number times 2
|
| 102 |
|
|
; d4 = digit counter
|
| 103 |
|
|
; Parameters:
|
| 104 |
|
|
; fp0 = float number
|
| 105 |
|
|
; Returns:
|
| 106 |
|
|
; fp0 = float number with exponent factored in
|
| 107 |
|
|
;-------------------------------------------------------------------------------
|
| 108 |
|
|
|
| 109 |
|
|
_GetExponent:
|
| 110 |
|
|
link a2,#-32
|
| 111 |
|
|
move.l _canary,28(sp)
|
| 112 |
|
|
movem.l d1/d2/d3/d4,(sp)
|
| 113 |
|
|
fmove.x fp2,16(sp)
|
| 114 |
|
|
clr.l d2 ; d2 = number = 0
|
| 115 |
|
|
fmove.w #0,fp2 ; fp2 = exp = 0.0
|
| 116 |
|
|
moveq #1,d3 ; d3 = exscale = 1
|
| 117 |
|
|
bsr _GetFloatGetChar
|
| 118 |
|
|
cmpi.b #'-',d1
|
| 119 |
|
|
bne .0001
|
| 120 |
|
|
neg.l d3 ; exscale = -1
|
| 121 |
|
|
.0006
|
| 122 |
|
|
bsr _GetFloatIgnBlanks
|
| 123 |
|
|
bra .0002
|
| 124 |
|
|
.0001
|
| 125 |
|
|
cmpi.b #'+',d1
|
| 126 |
|
|
beq .0006
|
| 127 |
|
|
bsr _GetFloatBackupChar
|
| 128 |
|
|
.0002
|
| 129 |
|
|
moveq #3,d4 ; d4 = max 4 digits
|
| 130 |
|
|
.0004
|
| 131 |
|
|
bsr _GetFloatGetChar ; d1 = digit char
|
| 132 |
|
|
cmpi.b #'0',d1
|
| 133 |
|
|
blo .0003
|
| 134 |
|
|
cmpi.b #'9',d1 ; ensure between 0 and 9
|
| 135 |
|
|
bhi .0003
|
| 136 |
|
|
subi.b #'0',d1
|
| 137 |
|
|
add.l d2,d2 ; number *2
|
| 138 |
|
|
move.l d2,d3
|
| 139 |
|
|
lsl.l #2,d2 ; number *8
|
| 140 |
|
|
add.l d3,d2 ; number *10
|
| 141 |
|
|
ext.w d1
|
| 142 |
|
|
ext.l d1
|
| 143 |
|
|
add.l d1,d2 ; number + digit
|
| 144 |
|
|
addq.w #1,d5 ; increment number of digits in number
|
| 145 |
|
|
dbra d4,.0004
|
| 146 |
|
|
.0003
|
| 147 |
|
|
bsr _GetFloatBackupChar ; backup a character
|
| 148 |
|
|
mulu d3,d2 ; *1 or *-1
|
| 149 |
|
|
ext.l d2
|
| 150 |
|
|
fscale.l d2,fp2 ; exp * exmul
|
| 151 |
|
|
fmul fp2,fp0 ; rval *= exp
|
| 152 |
|
|
movem.l (sp),d1/d2/d3/d4
|
| 153 |
|
|
fmove.x 16(sp),fp2
|
| 154 |
|
|
cchk 28(sp)
|
| 155 |
|
|
unlk a2
|
| 156 |
|
|
rts
|
| 157 |
|
|
|
| 158 |
|
|
;-------------------------------------------------------------------------------
|
| 159 |
|
|
; Get an integer number, positive or negative, 25 digits max, into a float
|
| 160 |
|
|
; register.
|
| 161 |
|
|
;
|
| 162 |
|
|
; Register Usage:
|
| 163 |
|
|
; d1 = digit from input screen
|
| 164 |
|
|
; d2 = digit down counter
|
| 165 |
|
|
; d3 = sign of number '+' or '-'
|
| 166 |
|
|
; fp1 = digit
|
| 167 |
|
|
; Modifies:
|
| 168 |
|
|
; a0,fp0
|
| 169 |
|
|
; Returns:
|
| 170 |
|
|
; a0 = updated buffer pointer
|
| 171 |
|
|
; fp0 = integer number
|
| 172 |
|
|
;-------------------------------------------------------------------------------
|
| 173 |
|
|
|
| 174 |
|
|
_GetInteger:
|
| 175 |
|
|
link a2,#-28
|
| 176 |
|
|
move.l _canary,24(sp)
|
| 177 |
|
|
movem.l d1/d2/d3,(sp)
|
| 178 |
|
|
fmove.x fp1,12(sp)
|
| 179 |
|
|
fmove.w #0,fp0
|
| 180 |
|
|
moveq #24,d2 ; d2 = digit count (25 max)
|
| 181 |
|
|
bsr _GetFloatIgnBlanks
|
| 182 |
|
|
bsr _GetFloatGetChar ; get the sign of the number
|
| 183 |
|
|
cmpi.b #'+',d1
|
| 184 |
|
|
beq .0002
|
| 185 |
|
|
.0003
|
| 186 |
|
|
cmpi.b #'-',d1
|
| 187 |
|
|
bne .0004
|
| 188 |
|
|
move.b #'-',d7
|
| 189 |
|
|
.0002
|
| 190 |
|
|
bsr _GetFloatGetChar
|
| 191 |
|
|
.0004
|
| 192 |
|
|
cmpi.b #'0',d1 ; only characters 0 to 9 valid
|
| 193 |
|
|
blo .0001
|
| 194 |
|
|
cmpi.b #'9',d1
|
| 195 |
|
|
bhi .0001
|
| 196 |
|
|
subi.b #'0',d1
|
| 197 |
|
|
fscale.w #1,fp0 ; number *10
|
| 198 |
|
|
fmove.b d1,fp1 ; fp1 = digit
|
| 199 |
|
|
fadd fp1,fp0
|
| 200 |
|
|
addq.w #1,d5
|
| 201 |
|
|
dbra d2,.0002
|
| 202 |
|
|
.0001
|
| 203 |
|
|
bsr _GetFloatBackupChar
|
| 204 |
|
|
movem.l (sp),d1/d2/d3
|
| 205 |
|
|
fmove.x 12(sp),fp1
|
| 206 |
|
|
cchk 24(sp)
|
| 207 |
|
|
unlk a2
|
| 208 |
|
|
rts
|
| 209 |
|
|
|
| 210 |
|
|
;-------------------------------------------------------------------------------
|
| 211 |
|
|
; Get a floating point number off the input screen.
|
| 212 |
|
|
;
|
| 213 |
|
|
; Parameters:
|
| 214 |
|
|
; a0 = pointer to buffer containing string
|
| 215 |
|
|
; d0 = stride of buffer (increment / decrement amount)
|
| 216 |
|
|
; Register Usage:
|
| 217 |
|
|
; d1 = character from input screen
|
| 218 |
|
|
; d5.lo = number of digits in number, d5.hi = number of characters fetched
|
| 219 |
|
|
; Returns:
|
| 220 |
|
|
; fp0 = number
|
| 221 |
|
|
; a0 = updated buffer pointer
|
| 222 |
|
|
; d0 = length of number >0 if a number
|
| 223 |
|
|
;-------------------------------------------------------------------------------
|
| 224 |
|
|
|
| 225 |
|
|
_GetFloat:
|
| 226 |
|
|
link a2,#-32
|
| 227 |
|
|
move.l _canary,28(sp)
|
| 228 |
|
|
movem.l d1/d5/d7/a1,(sp)
|
| 229 |
|
|
fmove.x fp2,16(sp)
|
| 230 |
|
|
clr.l d5
|
| 231 |
|
|
move.b #'+',d7 ; assume a positive number
|
| 232 |
|
|
move.l a0,a1 ; a1 = copy of pointer to buffer
|
| 233 |
|
|
bsr _GetInteger ; rval = integer
|
| 234 |
|
|
fmove.x fp0,fp2
|
| 235 |
|
|
bsr _GetFloatGetChar
|
| 236 |
|
|
cmpi.b #'.',d1
|
| 237 |
|
|
beq .0004
|
| 238 |
|
|
.0005
|
| 239 |
|
|
bsr _GetFloatBackupChar
|
| 240 |
|
|
bra .0002
|
| 241 |
|
|
.0004
|
| 242 |
|
|
bsr _GetFraction
|
| 243 |
|
|
fadd fp2,fp0 ; rval += fraction
|
| 244 |
|
|
bsr _GetFloatGetChar
|
| 245 |
|
|
cmpi.b #'e',d1 ; accept either 'e' or 'E' indicating exponent
|
| 246 |
|
|
beq .0001
|
| 247 |
|
|
cmpi.b #'E',d1
|
| 248 |
|
|
bne .0005
|
| 249 |
|
|
.0001
|
| 250 |
|
|
bsr _GetExponent ; factor exponent into fp0
|
| 251 |
|
|
.0002
|
| 252 |
|
|
cmpi.b #'-',d7 ; adjust number for sign
|
| 253 |
|
|
bne .0003
|
| 254 |
|
|
fneg fp0
|
| 255 |
|
|
.0003
|
| 256 |
|
|
suba.l a0,a1 ; compute number of characters fetched
|
| 257 |
|
|
move.w a1,d0 ; move it to d0.hi
|
| 258 |
|
|
swap d0
|
| 259 |
|
|
move.w d5,d0 ; return digit/character count in d0 (non zero for a number)
|
| 260 |
|
|
movem.l (sp),d1/d5/d7/a1
|
| 261 |
|
|
fmove.x 16(sp),fp2
|
| 262 |
|
|
cchk 28(sp)
|
| 263 |
|
|
unlk a2
|
| 264 |
|
|
rts
|
| 265 |
|
|
|
| 266 |
|
|
|