File stakmath.asm * By ASM8 v9.97 Win32 [Monday, December 21, 2020 1:32 pm] 1 ;******************************************************************************* 2 ;* Program : STAKMATH.ASM 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Test the inclusion of the 64/56/48/40/32/24/16-bit versions of 5 ;* : STAKMATH.SUB 6 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 7 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 8 ;* History : N/A 9 ;******************************************************************************* 10 14 *** BEGIN INCLUDE FILE: mcu.inc *** *** BEGIN INCLUDE FILE: GB60.inc *** *** BEGIN INCLUDE FILE: macros.inc *** *** END INCLUDE FILE: macros.inc *** (RESUMING FILE: GB60.inc) *** BEGIN INCLUDE FILE: common.inc *** *** END INCLUDE FILE: common.inc *** (RESUMING FILE: GB60.inc) *** END INCLUDE FILE: GB60.inc *** (RESUMING FILE: mcu.inc) *** END INCLUDE FILE: mcu.inc *** (RESUMING FILE: lib/demo/stakmath.asm) 20 21 Page macro PageNumber 22 mreq 1:PageNumber 23 #if ~#1~ > 7 24 merror PageNumber (~1~) must be in range 0..7 25 #endif 26 #ifmmu 27 #if ~#1~ >= 4 28 #SEG~1~ 29 #else 30 #ROM 31 #endif 32 #endif 33 endm 34 35 ;------------------------------------------------------------------------------- 36 37 ? macro Bits,Page 38 @@Page ~2~ 39 #Uses lib/stkmth{~1~}.sub 40 endm 41 42 ;******************************************************************************* 43 #ROM 44 ;******************************************************************************* 45 46 182C SIGNED 47 #MapOff 48 M @? 32,4 48 M @@Page 4 48 M mreq 1:PageNumber 48 M endm 48 #Uses lib/stkmth32.sub *** BEGIN INCLUDE FILE: lib/stkmth32.sub *** 1 ;******************************************************************************* 2 ;* Module : STKMTH32.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Wrapper for 32-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stkmth32.html 8 ;* Note(s) : See STAKMATH.SUB for details 9 ;******************************************************************************* 10 16 17 ? macro 18 mset 1,~BASENAME~ 19 MATHSIZE set ~1.{:1-1}~ 20 #Include stakmath.sub 21 endm 22 23 M @? 23 M mset 1,STKMTH32 23 M 0020 MATHSIZE set 32 23 #Include stakmath.sub *** BEGIN INCLUDE FILE: lib/stakmath.sub *** 1 ;******************************************************************************* 2 ;* Module : STAKMATH.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : 64/56/48/40/32/24/16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stakmath.html 8 ;* Note(s) : Use: #Include stakmath.sub 9 ;* : 10 ;* : Several externally defined macros are used throughout this code. 11 ;* : All these (and many more) macros are inside the most recent 12 ;* : version of MACROS.INC which can be copied from the web page at 13 ;* : http://www.aspisys.com/code/hc08/macros.html 14 ;* : (and COMMON.INC at http://www.aspisys.com/code/hc08/common.html) 15 ;* : 16 ;* : The default word size is 32-bit. 17 ;* : 18 ;* : By (re)defining the symbol MATHSIZE (to 16) you get 16-bit code. 19 ;* : By (re)defining the symbol MATHSIZE to 24 you get 24-bit code. 20 ;* : By (re)defining the symbol MATHSIZE to 40 you get 40-bit code. 21 ;* : By (re)defining the symbol MATHSIZE to 48 you get 48-bit code. 22 ;* : By (re)defining the symbol MATHSIZE to 56 you get 56-bit code. 23 ;* : By (re)defining the symbol MATHSIZE to 64 you get 64-bit code. 24 ;* : 25 ;* : You can include all (or some) versions in your program like so: 26 ;* : 27 ;* : #ROM ;(or else, some paged memory) 28 ;* : #Include stakmath.sub 29 ;* : MATHSIZE set 16 ;redefine for 16-bit use 30 ;* : #Include stakmath.sub 31 ;* : MATHSIZE set 24 ;redefine for 24-bit use 32 ;* : #Include stakmath.sub 33 ;* : MATHSIZE set 40 ;redefine for 40-bit use 34 ;* : #Include stakmath.sub 35 ;* : MATHSIZE set 48 ;redefine for 48-bit use 36 ;* : #Include stakmath.sub 37 ;* : MATHSIZE set 56 ;redefine for 56-bit use 38 ;* : #Include stakmath.sub 39 ;* : MATHSIZE set 64 ;redefine for 64-bit use 40 ;* : 41 ;* : or, if you use the related wrapper files, like so: 42 ;* : 43 ;* : #ROM ;(or else, some paged memory) 44 ;* : #Uses stkmth16.sub 45 ;* : #Uses stkmth24.sub 46 ;* : #Uses stkmth32.sub 47 ;* : #Uses stkmth40.sub 48 ;* : #Uses stkmth48.sub 49 ;* : #Uses stkmth56.sub 50 ;* : #Uses stkmth64.sub 51 ;* : 52 ;* : Use CALL if assembled in #MMU mode (regardless of placement). 53 ;* : By using CALL and #JUMP (or default -J+ command line option), the 54 ;* : assembler will automatically adjust between CALL and JSR 55 ;* : depending on the current #MMU mode. 56 ;* : 57 ;* : To use the *-bit version of each CALL, use these symbols: 58 ;* : 59 ;* : StackAdd*, StackSub*, StackMul*, StackDiv*, StackMod* 60 ;* : StackSwap*, StackNegate*, StackLoad*, StackSave*, 61 ;* : Stack*ToASCIZ 62 ;* : 63 ;* : replacing * with one of these: 16, 24, 32, 40, 48, 56, or 64. 64 ;* : 65 ;* : Various macros allow using these routines in a variety of ways, 66 ;* : and without worrying about the details of call & parameter setup. 67 ;* : These macros are: Add*, Sub*, Mul*, Div*, Mod*, DivS*, ModS*, 68 ;* : Neg*, Load*, Save*, Str*, StrS*, and Swap* (where the * is 16, 69 ;* : 24, 32, 40, 48, 56, or 64 depending on the version you want to use). 70 ;* : The signed versions are enabled only when the module is assembled 71 ;* : with the SIGNED conditional. 72 ;* : 73 ;* : If working with fixed-address variables, you can use the various 74 ;* : macros (such as Add32, Mul64, etc.) to perform operations in the 75 ;* : easiest possible way, such as: 76 ;* : @Mul32 A,B,Answer 77 ;* : (which multiplies A with B and stores the product in Answer). 78 ;* : But, you may also use the macros to work directly on stack, or to 79 ;* : temporarily save partial results on stack instead of fixed vars. 80 ;* : 81 ;* : I N G E N E R A L T H E N 82 ;* : 83 ;* : @Operation A,B,Answer works with A and B storing result in Answer 84 ;* : @Operation A,B works with A and B leaving result on stack 85 ;* : @Operation A works with TOS and A, result left as TOS 86 ;* : @Operation (no parms) works w/ TOS and [TOS+1], result as new TOS 87 ;* : 88 ;* : (Please note the shown order of the operation may be important.) 89 ;* : 90 ;* : Finally, the Load* (* = 16, 24, 32, 40, 48, 56, 64) operation can 91 ;* : directly load either a variable or a constant (leading #) on the 92 ;* : stack. 93 ;* : 94 ;* : Since v7.00, a HLL-like interface is possible by using the new 95 ;* : Eval* macro (where * = 8, 16, 24, 32, 40, 48, 56, 64) 96 ;* : This is by far the easiest way to use this library, as it closely 97 ;* : resembles using expressions in a HLL compiler. It also can 98 ;* : automatically resize stack after loading from and before saving 99 ;* : to any variable. 100 ;* : 101 ;* : Examine the test section of this file for examples of macro use. 102 ;* : 103 ;* : All routines are re-entrant and work on either the top-of-stack 104 ;* : (TOS) number alone or the two top-most TOS numbers. Similar to 105 ;* : how Reverse Polish Notation (RPN) works. First, you stack the 106 ;* : operand(s) and then call the corresponding routine to perform the 107 ;* : operation. 108 ;* : 109 ;* : The result of any operation is always the updated top of stack. 110 ;* : For operations that require two operands and produce a single 111 ;* : result, the result replaces the two operands (stack is reduced). 112 ;* : 113 ;* : Chain calculations are possible by pushing only the new operand 114 ;* : between operations. Alternatively, one can push all operands in 115 ;* : advance but it's not recommended as stack space may be limited. 116 ;* : When done evaluating an expression, just pull the final 32-bit 117 ;* : result from the stack. 118 ;* : 119 ;* : The TOS is the first (or only) operand of any operation. 120 ;* : This is important, for example, for subtraction and division. 121 ;* : 122 ;* : If the current order of the stack is not as you want it, use the 123 ;* : Swap (StackSwap32) operation to change it. 124 ;* : 125 ;* : All operands and results are exactly 32-bit wide. Overflows are 126 ;* : simply truncated. The lower 32-bit number is valid, though. 127 ;* : 128 ;* : (All references to 32-bit become 16-bit, when MATHSIZE = 16) 129 ;* : (All references to 32-bit become 24-bit, when MATHSIZE = 24) 130 ;* : (All references to 32-bit become 40-bit, when MATHSIZE = 40) 131 ;* : (All references to 32-bit become 48-bit, when MATHSIZE = 48) 132 ;* : (All references to 32-bit become 56-bit, when MATHSIZE = 56) 133 ;* : (All references to 32-bit become 64-bit, when MATHSIZE = 64) 134 ;* : 135 ;* : 64/56/48/40-bit multiplication is done using the shift-add method, 136 ;* : which is much shorter in size for such long operands, but it is 137 ;* : also significantly slower in speed. I opted for size optimization 138 ;* : because the 64/56/48/40-bit versions are not used quite as often. 139 ;* : You may want to re-write it for speed optimization by using the 140 ;* : MUL instruction like it is done for the default 32-bit case. 141 ;* : 142 ;* History : 09.05.22 v1.00 Original (Started on 2009.05.07) 143 ;* : 09.06.04 Optimized by using HX instead of SP, where needed 144 ;* : 09.11.04 Minor optimizations 145 ;* : 09.11.05 Add & Subtract now adjust Carry accordingly 146 ;* : Division by zero error now checked first 147 ;* : 09.11.06 v1.01 Added conditional MATHSIZE for use w/ 16-bit words 148 ;* : 09.11.08 v1.02 Added "Load" operation to ease stack loading 149 ;* : 09.11.11 Use of new LONG pseudo-opcode 150 ;* : 09.12.05 Added cycles display using :cycles 151 ;* : 10.01.06 v1.03 Added MMU auto-support (using :AB internal symbol) 152 ;* : Code is no longer placed in #ROM by default 153 ;* : The few JMPs in the code use [[ to trim possible page 154 ;* : 10.01.08 [[ removed from JMPs (latest ASM8 auto-correction) 155 ;* : 10.01.22 v1.04 Added Save operation for completeness 156 ;* : 10.01.23 v1.05 Added #SP directive examples (latest ASM8) 157 ;* : 10.01.29 v1.06 Added shorter/faster Swap version for 9S08 MCUs 158 ;* : 10.02.01 v1.07 Added #SPAUTO directive 159 ;* : 10.02.04 Added #X directive 160 ;* : 10.02.06 v2.00 Added signed math wrapper calls only for DIV & MOD 161 ;* : (Addition, Subtraction, and Multiplication calls 162 ;* : work either for unsigned or signed operands.) 163 ;* : Signed routines enabled w/ SIGNED conditional. 164 ;* : Division by zero error now reduces stack (operand 165 ;* : A removed) so that the stack is left with same 166 ;* : size on either success or failure (in which case 167 ;* : the TOS result is invalid.) 168 ;* : 10.02.08 v2.01 Fixed signed MOD for correct sign (sign of A) 169 ;* : 10.02.14 v2.10 Added Stack32ToASCIZ and prerequisite StringInsertChar 170 ;* : 10.02.28 v2.11 Minor optimization in StringInsertChar 171 ;* : 10.03.23 Made use of :: internal variable (Build 2010/03/23) 172 ;* : 10.03.30 v2.12 Allowed for HC08 compilation in newer code (?ToStr) 173 ;* : Optimized 9S08 Swap version for size and speed 174 ;* : v2.13 Optimized Negate for size and speed 175 ;* : 10.05.08 v3.00 Added MATHSIZE = 64 option for 64-bit math 176 ;* : Swap operation optimized only for size 177 ;* : 10.05.13 v3.01 Optimized for size and speed by using ,SPX 178 ;* : 10.06.02 v4.00 Added macros for easier use 179 ;* : 10.06.08 v4.10 Improved macros and added new ones (eg Const32) 180 ;* : 10.06.23 v4.20 Added MATHSIZE = 48 option for 48-bit math 181 ;* : 10.06.30 v4.30 Added AddDecimalPoint (to string number) 182 ;* : 10.07.01 v4.40 Added IFSPAUTO conditional 183 ;* : 10.07.03 Moved the functionality of Const macros into Load 184 ;* : 10.07.07 Moved general string routines first 185 ;* : 10.07.17 v4.50 Str* macros may use TOS (if Number parm is missing) 186 ;* : or current HX index (if result pointer is missing) 187 ;* : 10.07.20 _DoLoad*/_DoSave* address now allows for indexed mode 188 ;* : 10.07.21 Minor optimizations; macros now latest ASM8 189 ;* : 10.07.23 Minor bug fix in macro _DoSave for no parm case 190 ;* : 10.08.18 Optimized by using :MINDEX in latest ASM8 191 ;* : 10.08.26 Minor optimizations at the source level 192 ;* : 10.08.31 v4.60 Optimized Load* macros' immediate mode for zeros 193 ;* : 10.10.19 v4.61 Adapted to latest ASM8 (nested macros in Load) 194 ;* : 10.10.22 v4.62 Optimized _DoMath (Added @_DoOperation) 195 ;* : 10.10.26 v4.63 Load48 & Load64 now also accept single #Constant 196 ;* : 10.12.03 v4.64 Adapted to latest ASM8 => macros OK in @@ sub-mode 197 ;* : 11.03.31 v4.65 Moved test code at EOF (to use #EXIT optimization) 198 ;* : 11.04.10 v4.66 Condensed macro definitions (based on MATHSIZE) 199 ;* : 11.04.11 v4.67 Optimized MUL16/MUL32 size & cycles with ,SPX mode 200 ;* : 11.04.12 v4.70 Added MATHSIZE = 24 option for 24-bit math 201 ;* : 11.04.13 v4.71 Reversed some of v4.66's changes 202 ;* : 11.04.13 v4.80 Added MATHSIZE = 40 option for 40-bit math 203 ;* : 11.05.02 v4.81 Save protects HX (it was lost during SP => SPX) 204 ;* : 11.05.05 v4.82 Optimized StringLength by a byte (by using NEGA on exit) 205 ;* : 11.05.25 v4.83 Removed unused Zero constant from test code 206 ;* : 11.10.13 v4.84 Optimized MUL16/24/32 size w/ more ,SPX (same cycles) 207 ;* : 11.11.15 v4.85 Improved StringLength macro 208 ;* : 12.01.26 Changed test code a bit 209 ;* : 12.02.06 v4.86 Optimized SP => SPX at ?RemoveAndReturn 210 ;* : 12.03.05 v4.87 Added ResizeTOS to adjust TOS element's size 211 ;* : 12.05.09 v4.88 Added CCR[C] parameter to ResizeTOS for unsigned operation 212 ;* (signed is default when SIGNED conditional is defined, 213 ;* unsigned operation is default, otherwise) 214 ;* : 12.05.18 v4.89 Removed redundant subtraction in Division (at NotEqual@@) 215 ;* : 12.10.07 v4.90 Load*/Save* now accept indexed mode without separator override 216 ;* : 12.10.10 v5.00 Renamed to (more general) STAKMATH.SUB to use 217 ;* : wrapper files for each bit version, instead. 218 ;* : 12.11.05 Added _STKMTH{MATHSIZE}_ for used-version control 219 ;* : 12.11.09 v6.00 New _LoadStkMthVarAddr macro eases parm address 220 ;* : calculation. 221 ;* : W A R N I N G: SP-based operands now refer to the actual number, 222 ;* : W A R N I N G: and not its address (as was the case before). 223 ;* : W A R N I N G: This is INCOMPATIBLE with previous behavior. Code 224 ;* : W A R N I N G: written for version v5.00 or earlier that uses SP 225 ;* : W A R N I N G: based operands should be modified to refer to the 226 ;* : W A R N I N G: actual value and not to a pointer to the value. 227 ;* : W A R N I N G: Dot-beginning names are still treated as pointers! 228 ;* : 12.11.10 Use COMMON.INC/LEA instead of _LoadStkMthVarAddr 229 ;* : 12.12.04 v6.10 Optimized division just a tad by combining steps 230 ;* : 12.12.12 v6.20 Now use LEA macro inside _DoStr (for ResultString) 231 ;* : 12.12.20 v6.21 Minor optimization (one byte) in 32-bit ?Multiply 232 ;* : (Further 3-byte optimization possible by 233 ;* : re-ordering MULs, but not done for code clarity) 234 ;* : 13.01.09 v6.22 Added Copy* macros to combine Load*/Save* into one 235 ;* : 13.03.20 v7.00 Added Eval* and supporting macros for HLL-like 236 ;* : computations, eg., ans=(a+3)*((1+var,sp)/2) 237 ;* : (with or without spaces between operands/operators) 238 ;* : 13.03.27 v7.50 SIGNED now gives just signed (not unsigned) version 239 ;* : DivS*, ModS*, StrS* macros were removed, and also 240 ;* : ResizeTOS macro's unsigned flag has been removed 241 ;* : BugFix: AddDecimalPoint now prepends zeros after sign 242 ;* : 13.03.27 Optimized ?Negate in SIGNED case to use ?NegX sub 243 ;* : 13.03.27 v7.60 Adapted _EVAL_ macro to latest ASM8 (Much faster!) 244 ;* : 13.04.04 v7.70 _DoLoad and _DoSave macros now auto-adjust the size 245 ;* : so you can use with operands of different sizes, even 246 ;* : if the respective bitsize version isn't loaded. 247 ;* : 13.04.04 v7.71 _Eval_ macro leaves assignment result on TOS if 248 ;* : assignment variable not already defined. Then, 249 ;* : it gives TOS the specified name, if SP-indexed. 250 ;* : 13.04.05 v7.72 Added #size for v7.71 change 251 ;* : Named constants (labels with size zero) now use 252 ;* : immediate mode in Eval/Load 253 ;* : 13.04.05 v7.73 Added NEG() negate, and ABS() absolute functions 254 ;* : in Eval macro, e.g., ans = abs(a - b) 255 ;* : 13.04.09 v7.80 BugFix: Push/Pull macro calls for SP mode 256 ;* : Moved immediate mode to _DoLoad (unified method) 257 ;* : (Over 32-bit immediate value loads not possible 258 ;* : via macros) 259 ;* : 13.04.10 Adapted to v9.35 (no functional changes) 260 ;* : 13.04.11 v7.81 Optimized _DoLoad constant loading by using CLRH 261 ;* : (optimization is evident on certain cases only) 262 ;* : 13.04.15 v7.82 Added _?SEI_ and _?CLI_ macros for multitasker 263 ;* : locking / unlocking of multi-byte variables while 264 ;* : loading / saving (_DoLoad/_DoSave). Under OS8 it 265 ;* : is enabled automatically. Otherwise, simply 266 ;* : define _MTOS_ anytime before including this file. 267 ;* : For keeping code dense, all Eval*/Load*/Save* 268 ;* : macros are assumed to be called only while 269 ;* : interrupts are enabled, so it will not restore to 270 ;* : previous state but always leave as enabled. 271 ;* : Define _NOCLI_ (before including this module) for 272 ;* : canceling the _?SEI_ and _?CLI_ macro effects. 273 ;* : 13.04.18 v7.85 Added 'NeedMath' and 'Eval' general-purpose macros 274 ;* : for automatic selection of needed bit-size based 275 ;* : on only which modules are already included. First, 276 ;* : call the NeedMath macro to define the minimum math 277 ;* : bit-size you need for the next calculation(s), 278 ;* : then call the Eval macro as many times as needed 279 ;* : to perform the actual expression evaluation(s). 280 ;* : Similary, added new macros Load, Save, StkAdd, 281 ;* : StkSub, StkMul, StkDiv, StkMod, StkSwap, StkNeg, 282 ;* : StkAbs, StkStr, and CopyMath to work with the 283 ;* : NeedMath macro, just like the new Eval macro. 284 ;* : 13.04.19 v8.00 Moved all Eval* macros into COMMON.INC and allowed 285 ;* : for all to be active at all times, regardless if 286 ;* : the related bit-version of STAKMATH is included. 287 ;* : The _Eval_ macro was improved to allow it to 288 ;* : automatically locate the next higher version that 289 ;* : is included, if the one requested is not. So, 290 ;* : using Eval32 will use the 32/40/48/64-bit version 291 ;* : (whichever is closer to 32 and included) but nothing 292 ;* : below 32-bit. This allows you to use the relevant 293 ;* : macro based on a specific expression's requirements 294 ;* : but include only one (or just a few) higher bit 295 ;* : version(s), not all those referenced in your code. 296 ;* : (The general Eval is still available, if needed.) 297 ;* : Also, moved all Str* to COMMON.INC 298 ;* : 13.04.21 v8.10 Corrected v8.00 for pointer cases (.num) to use 299 ;* : actual requested size, not next higher. 300 ;* : Relevant #Message now in _DoOperation _ResizeTOS etc. 301 ;* : 13.04.21 v8.11 NeedMath & related macros removed (now redundant) 302 ;* : General Eval macro will try to determine best bit-size 303 ;* : 13.04.23 v8.12 Added EvalS to first check for SIGNED and then call Eval 304 ;* : CopyMath removed. Use "Eval to_var = from_var" instead 305 ;* : _StkMthMax_ improved to use higher size on multiplication 306 ;* : 13.04.25 v8.13 _Eval_ now allows for string constants (eg., @Eval ans = ans + '0') 307 ;* : Removed all ?macros because we now use COMMON xxx.s macros 308 ;* : 13.04.26 v8.15 Corrected test code for Eval when MATHSIZE < 32 309 ;* : Commented out auto-higher bit-size (a bit annoying). 310 ;* : Use Eval* to say 'no less than', instead. 311 ;* : 13.04.27 v8.16 BugFix: StrMath macro (2nd parameter was lost) 312 ;* : Added SQR() function to get the square 313 ;* : 13.05.02 Added #size in ToInt* macros (in test code) 314 ;* : 13.05.03 v8.17 Added size optimization for ADD and SUB operations 315 ;* : New SPEED_SIZE constant in COMMON.INC tells us 316 ;* : whether we need speed (SPEED_SIZE = 1) or 317 ;* : size (SPEED_SIZE = 2) optimization, the current 318 ;* : default being SPEED_SIZE = 2 for size optimization. 319 ;* : 13.05.30 Updated StrMath macro (COMMON.INC and here) 320 ;* : 13.06.04 v8.20 Added bit functions: AND (&), OR (|), XOR (^), and shifts (< and >) 321 ;* : 13.06.05 v8.21 BugFix: ShiftRight now uses ASR if SIGNED 322 ;* : 13.07.25 v8.22 Improved _Eval_ macro (and Push/Pull in COMMON.INC) 323 ;* : BugFix: Added { } to ResizeTOS macro's final case 324 ;* : (Disable bit functions with NO_BIT_OPS conditional) 325 ;* : 13.10.06 Minor changes in test code 326 ;* : 13.11.26 Added warning in _DoLoad: forwards treated as vars 327 ;* : 13.11.29 v8.23 Optimized ?ShiftLeft and ?ShiftRight a bit 328 ;* : 13.12.22 v8.30 Added 56-bit version 329 ;* : 14.01.03 Made use of _CMP_.S macro (instead of custom macro) 330 ;* : 14.02.07 v8.50 Added [ ... ] unsigned override (if SIGNED) 331 ;* : 14.02.14 v8.51 Eval macro now uses #HideMacros 332 ;* : 14.10.14 v8.52 BugFix: Off-by-one error in ResizeTOS when SIGNED 333 ;* : 15.03.21 v8.53 Replaced string dependencies with corresponding #Uses 334 ;* : 15.04.08 v8.54 Replaced AddDecimalPoint with corresponding #Uses 335 ;* : 17.04.03 v8.55 Optimized 24-bit multiply [-2 bytes] 336 ;* : Optimized 32-bit multiply [-7 bytes] 337 ;* : 18.10.23 Suppressed possible warning from JEQ in ?DivStart 338 ;* : 19.03.04 Added warning in _DoStr macro when using StrNN 339 ;* : when NN is different from MATHSIZE and no explicit 340 ;* : variable is given 341 ;* : 19.10.04 v8.56 Minor HC08 mode optimization in SIGNED ?ToStr [-1 byte] 342 ;* : 20.02.12 v8.57 Replaced #Message with @Msg to silence debugging messages 343 ;******************************************************************************* 344 345 ;Synopsis (replace * with 16, 24, 32, 40, 48, 56, 64 for corresponding bit version): 346 ; 347 ;Subroutines Action 348 ;-------------- ---------------------------- 349 ;StackAdd* - TOS := TOS + [TOS+1] (signed or unsigned) [TOS+1] removed 350 ;StackSub* - TOS := TOS - [TOS+1] (signed or unsigned) [TOS+1] removed 351 ;StackMul* - TOS := TOS * [TOS+1] (signed or unsigned) [TOS+1] removed 352 ;StackDiv* - TOS := TOS / [TOS+1] (signed if SIGNED) [TOS+1] removed 353 ;StackMod* - TOS := TOS \ [TOS+1] (signed if SIGNED) [TOS+1] removed 354 ;StackAnd* - TOS := TOS & [TOS+1] (signed or unsigned) [TOS+1] removed 355 ;StackOr* - TOS := TOS | [TOS+1] (signed or unsigned) [TOS+1] removed 356 ;StackXor* - TOS := TOS ^ [TOS+1] (signed or unsigned) [TOS+1] removed 357 ;StackShl* - TOS := TOS < [TOS+1] (signed or unsigned) [TOS+1] removed 358 ;StackShr* - TOS := TOS > [TOS+1] (signed if SIGNED) [TOS+1] removed 359 ;StackSwap* - TOS swapped with [TOS+1] (signed or unsigned) 360 ;StackAbs* - TOS := ABS(TOS) (signed) 361 ;StackNegate* - TOS := -TOS (signed) 362 ;StackLoad* - Load const/variable to TOS (signed or unsigned) TOS created 363 ;StackSave* - Save TOS into variable (signed or unsigned) TOS removed 364 ;ResizeTOS - Adjust TOS old size to new (signed or unsigned) TOS resized 365 ;Stack*ToASCIZ - Convert TOS to ASCIZ str (signed if SIGNED) 366 ; 367 ;Macros Purpose Parameters ([...] means optional part) 368 ;------------------ ------------------- ---------------------------------------- 369 ;Load* Stack const or var #Number | Variable 370 ;Save* Unstack a variable Variable 371 ;Copy* Load* & Save* #Number | Variable,Variable 372 ;ResizeTOS Resize TOS #FromByteSize,#ToByteSize 373 ; 374 ;Add* Addition [Addend[,Adder[,Sum]]] 375 ;Sub* Subtraction [Minuend[,Subtrahend[,Difference]]] 376 ;Mul* Multiplication [Multiplicand[,Multiplier[,Product]]] 377 ;Div* Unsigned division [Dividend[,Divisor[,Quotient]]] 378 ;Mod* Unsigned modulo [Dividend[,Divisor[,Remainder]]] 379 ;Abs* Absolute value [SourceVariable][,DestinationVariable] 380 ;Neg* Negation [SourceVariable][,DestinationVariable] 381 ;Swap* Swap TOS numbers 382 ;Str* Number to ASCIZ [Variable],[ResultString] 383 ;AddDecimalPoint ... to ASCIZ number [[#]DecimalPlaces[,[#]ASCIZ_String]] 384 411 412 0020 MATHSIZE def 32 ;default wordsize is 32-bit 413 417 418 ? macro BitSize 419 #if MATHSIZE = ~1~ 420 ?WORD equ ~1~/8 421 _STKMTH{MATHSIZE}_ ;;specific version included 422 _STAKMATH_ def * ;;any version included 423 #endif 424 endm 425 426 M @? 16 ;16-bit quantity (on request) 426 endm 427 M @? 24 ;24-bit quantity (on request) 427 endm 428 M @? 32 ;32-bit quantity (default) 428 M 0004 ?WORD equ 32/8 428 M 182C _STKMTH32_ 428 M 182C _STAKMATH_ def * 428 endm 429 M @? 40 ;40-bit quantity (on request) 429 endm 430 M @? 48 ;48-bit quantity (on request) 430 endm 431 M @? 56 ;56-bit quantity (on request) 431 endm 432 M @? 64 ;64-bit quantity (on request) 432 endm 433 439 #Message MATHSIZE = {MATHSIZE}-bit version 441 #Message Signed routines enabled 443 ;******************************************************************************* 444 ; Macros to make operations as simple as with a high-level language 445 ; In operations that require two operands and a result, if only one operand is 446 ; provided, then the operation is done completely on stack (no other variables 447 ; used). For example, @Add32 A,B,SUM adds A to B and places result in SUM, 448 ; while @Add32 A adds the current stack top to A and leaves result on stack. 449 ; You can use @Load* and @Save* to load the initial value, and store the final 450 ; result, respectively. (Replace * with 16, 24, 32, 40, 48, 56, or 64) 451 ;******************************************************************************* 452 501 ;=============================================================================== 550 ;=============================================================================== 552 553 Load32 macro #Number|Variable ;load constant or variable 554 @_DoLoad ~0.{:0-1}~\,~@~ 555 endm 556 557 Save32 macro Address 558 @_DoSave 32\,~@~ 559 endm 560 561 Copy32 macro #Constant|Variable,ToAddress 562 mreq 1,2:#Constant|Variable,ToAddress 563 @@Load32 ~1~ 564 @Save32 ~2~ 565 endm 566 567 Swap32 macro 568 @_DoSwap 32 569 endm 570 571 Add32 macro Addend,Adder,Sum 572 @_DoMath ~0~\,32\,~1~\,~2~\,~3~ 573 endm 574 575 Sub32 macro Minuend,Subtrahend,Difference 576 @_DoMath ~0~\,32\,~1~\,~2~\,~3~ 577 endm 578 579 Mul32 macro Multiplicand,Multiplier,Product 580 @_DoMath ~0~\,32\,~1~\,~2~\,~3~ 581 endm 582 583 Div32 macro Dividend,Divisor,Quotient 584 @_DoMath ~0~\,32\,~1~\,~2~\,~3~ 585 endm 586 587 Mod32 macro Dividend,Divisor,Remainder 588 @_DoMath ~0~\,32\,~1~\,~2~\,~3~ 589 endm 590 591 Abs32 macro Source[,Destination] 592 @_DoAbs 32\,~1~\,~2~ 593 endm 594 595 Neg32 macro Source[,Destination] 596 @_DoNeg 32\,~1~\,~2~ 597 endm 599 ;=============================================================================== 648 ;=============================================================================== 697 ;=============================================================================== 746 ;=============================================================================== 795 796 ;******************************************************************************* 797 ; Common macro(s) for all operations defined above (not to be called directly) 798 ;******************************************************************************* 799 801 _signed_ macro 802 #ifndef SIGNED 803 #Warning SIGNED \@~mfilename~\@ expected 804 #endif 805 endm 807 ;------------------------------------------------------------------------------- 867 ;------------------------------------------------------------------------------- 890 ;------------------------------------------------------------------------------- 898 ;------------------------------------------------------------------------------- 916 ;=============================================================================== 933 ;------------------------------------------------------------------------------- 1158 ;------------------------------------------------------------------------------- 1160 _?sei_ macro 1161 #ifdef _NOCLI_ 1162 mexit 1163 #endif 1164 #ifndef _MTOS_ 1165 mexit 1166 #endif 1167 mset # 1168 #ifnb ~','2~ = sp 1169 mexit 1170 #endif 1171 #ifnb ~','2~ = spx 1172 mexit 1173 #endif 1174 #ifnb ~','2~ = psp 1175 mexit 1176 #endif 1177 #ifdef ~1,~ 1178 #if ::~1,~ < 2 1179 mexit 1180 #endif 1181 #endif 1182 sei 1183 endm 1185 ;------------------------------------------------------------------------------- 1187 _?cli_ macro 1188 #ifdef _NOCLI_ 1189 mexit 1190 #endif 1191 #ifndef _MTOS_ 1192 mexit 1193 #endif 1194 mset # 1195 #ifnb ~','2~ = sp 1196 mexit 1197 #endif 1198 #ifnb ~','2~ = spx 1199 mexit 1200 #endif 1201 #ifnb ~','2~ = psp 1202 mexit 1203 #endif 1204 #ifdef ~1,~ 1205 #if ::~1,~ < 2 1206 mexit 1207 #endif 1208 #endif 1209 cli 1210 endm 1212 ;------------------------------------------------------------------------------- 1214 _DoLoad macro BitSize[,Variable] ;if no Variable, wherever HX points 1215 #if :macronest = 1 1216 #Warning Macro NOT to be called directly 1217 #endif 1218 mreq 1:BitSize[,Variable] 1219 #temp ~1~/8 ;;bytesize now in :temp 1220 mdel 1 ;;get rid of bitsize parm 1221 mset # ;;unite all parms into one 1222 mtrim 1 1223 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1224 mset 9 ;;assume signed (when SIGNED) 1225 #ifparm ~1.1.1~~1.{:1}~ = [] 1226 mset 9,unsigned 1227 mset 1,~1.2.{:1-2}~ 1228 #endif 1229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1230 @@_not_x_ ~1~ ;;X-mode not allowed 1231 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1232 #ifnum ~1~ 1233 mset 1,#~1~ ;;numerics use immediate mode 1234 #endif 1235 #ifb ~,1~ 1236 #ifdef ~#1~ 1237 #ifz ::~#1~ 1238 mset 1,#~#1~ ;;named constants use immediate mode 1239 #endif 1240 #endif 1241 #endif 1242 #ifnb ~#~ ;;process immediate mode 1243 @@Msg Load{:temp*8} ~1~ 1244 mset 1,~#1~ 1245 mset 0 ;;use as flag for CLRH usage 1246 mdo 1247 #ifz ~#1~>{:mloop-1*8}&$FF 1248 #ifz :text 1249 clrh 1250 mset 0,clrh ;;flag CLRH was used 1251 #endif 1252 pshh 1253 #else 1254 ldx #~#1~>{:mloop-1*8}&$FF 1255 pshx 1256 #endif 1257 mloop :temp 1258 mexit 1259 #endif 1260 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1261 #ifnb ~1,~ 1262 #ifb ~1.1.1~ = . ;;except for pointers 1263 #ifnz ::~1,~ ;;and constants 1264 #if ::~1,~ <> :temp ;;different-size variables 1265 @@_?sei_ ~1~ 1266 @@pushv ~1~ ;;are pushed and then resized 1267 @@_?cli_ ~1~ 1268 @ResizeTOS #{::~1,~}\,#{:temp}\,\,~9~ 1269 mexit 1270 #endif 1271 #endif 1272 #endif 1273 #endif 1274 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1275 #ifndef ~1,~ 1276 #Warning Loading forward \@~1,~\@ as var 1277 #endif 1278 @@Msg Load{:temp*8} ~1~ 1279 @@lea ~1~ ;;default case 1280 @@_?sei_ ~1~ 1281 call StackLoad{:temp*8} ;;load as is 1282 @@_?cli_ ~1~ 1283 #ifspauto 1284 #spadd :temp 1285 #endif 1286 endm 1288 ;------------------------------------------------------------------------------- 1290 _DoSave macro BitSize[,Variable] ;if no Variable, wherever HX points 1291 #if :macronest = 1 1292 #Warning Macro NOT to be called directly 1293 #endif 1294 mreq 1:BitSize[,Variable] 1295 mset 2,~@@~ 1296 mtrim 2 1297 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1298 mset 9 ;;assume signed (when SIGNED) 1299 #ifparm ~2.1.1~~2.{:1}~ = [] 1300 mset 9,unsigned 1301 mset 2,~2.2.{:2-2}~ 1302 #endif 1303 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1304 @@_not_x_ ~2~ 1305 #ifnb ~2,~ 1306 #ifb ~2.1.1~ = . ;;except for pointers 1307 #ifnz ::~2,~ ;;and constants 1308 #if ::~2,~ <> ~1~/8 ;;different-size variables 1309 @@ResizeTOS #{~1~/8}\,#{::~2,~}\,\,~9~ 1310 @@_?sei_ ~2~ 1311 @@pullv ~2~ ;;are resized and then pulled 1312 @_?cli_ ~2~ 1313 mexit 1314 #endif 1315 #endif 1316 #endif 1317 #endif 1318 @@Msg Save~1~ ~2~ 1319 @@lea ~2~ ;;default case 1320 @@_?sei_ ~2~ 1321 call StackSave~1~ ;;save as is 1322 @@_?cli_ ~2~ 1323 #ifspauto 1324 #spadd -~1~/8 1325 #endif 1326 endm 1328 ;------------------------------------------------------------------------------- 1330 _DoSwap macro BitSize 1331 #if :macronest = 1 1332 #Warning Macro NOT to be called directly 1333 #endif 1334 call StackSwap~1~ 1335 endm 1337 ;------------------------------------------------------------------------------- 1339 _DoOperation macro Operation[,BitSize] 1340 #if :macronest = 1 1341 #Warning Macro NOT to be called directly 1342 #endif 1343 mdef 2,~1.{:1-1}~ 1344 @@Msg ~1~ 1345 call Stack~1~ 1346 #ifspauto 1347 #spadd -~2~/8 1348 #endif 1349 endm 1351 ;------------------------------------------------------------------------------- 1353 _DoMath macro Operation,BitSize[,Operand1[,Operand2[,Answer]]] 1354 #if :macronest = 1 1355 #Warning Macro NOT to be called directly 1356 #endif 1357 #ifnoparm ~3~ 1358 @_DoOperation ~1~ 1359 mexit 1360 #endif 1361 #ifnoparm ~4~ 1362 @@Load~2~ ~3~ 1363 #ifnoparm ~1~ = Add~2~ 1364 #ifnoparm ~1~ = Mul~2~ 1365 ;except for Add and Mul which are commutative, we must swap the stack 1366 call StackSwap~2~ ;one parm is Operand2 (eg, Div32 XXX does TOS/XXX) 1367 #endif 1368 #endif 1369 @_DoOperation ~1~ 1370 mexit 1371 #endif 1372 @@Load~2~ ~4~ 1373 @@Load~2~ ~3~ 1374 @@_DoOperation ~1~ 1375 #ifparm ~5~ 1376 @Save~2~ ~5~ 1377 #endif 1378 endm 1380 ;------------------------------------------------------------------------------- 1382 _DoAbs macro BitSize[,Source][,Destination] 1383 #if :macronest = 1 1384 #Warning Macro NOT to be called directly 1385 #endif 1386 @@Msg Abs~1~ ~@@~ 1387 @@_FindStkMth_ ~1~ 1388 mset 1,{:mexit} 1389 #ifparm ~2~ 1390 @@Load~1~ ~2~ 1391 #endif 1392 call StackAbs~1~ 1393 #ifparm ~2~~3~ 1394 @Save~1~ ~3~ 1395 #endif 1396 endm 1398 ;------------------------------------------------------------------------------- 1400 _DoNeg macro BitSize[,Source][,Destination] 1401 #if :macronest = 1 1402 #Warning Macro NOT to be called directly 1403 #endif 1404 @@Msg Neg~1~ ~@@~ 1405 @@_FindStkMth_ ~1~ 1406 mset 1,{:mexit} 1407 #ifparm ~2~ 1408 @@Load~1~ ~2~ 1409 #endif 1410 call StackNegate~1~ 1411 #ifparm ~2~~3~ 1412 @Save~1~ ~3~ 1413 #endif 1414 endm 1416 ;------------------------------------------------------------------------------- 1418 _DoStr macro BitSize,[Variable],[ResultString] 1419 #if :macronest = 1 1420 #Warning Macro NOT to be called directly 1421 #endif 1422 @@_FindStkMth_ ~1~ 1423 #ifb ~2~ 1424 #if ~1~ <> :mexit 1425 #Warning Size mismatch (Using Str~1~ for MATHSIZE={:mexit}) 1426 #endif 1427 #endif 1428 mset 1,{:mexit} 1429 #ifparm ~'~,3~'.{:3}~ = x 1430 pshhx 1431 #endif 1432 #ifparm ~2~ 1433 @@Load~1~ ~2~ 1434 #ifparm ~'~,3~'.{:3}~ = x 1435 ldhx ~1~/8+1,asp ;reload user HX for next LDHX 1436 #endif 1437 #endif 1438 #ifnb ~2~ 1439 @@Msg Convert \@~2~\@ ({::~2,~*8}-bit) to ASCIZ in \@~3~\@ 1440 #endif 1441 @@lea ~3~ 1442 call Stack~1~ToASCIZ 1443 #ifparm ~2~ 1444 ais #~1~/8 1445 #endif 1446 #ifparm ~'~,3~'.{:3}~ = x 1447 pulhx 1448 #endif 1449 endm 1451 1452 ;******************************************************************************* 1453 ; External dependencies 1454 ;******************************************************************************* 1455 1456 #Uses string/length.sub *** BEGIN INCLUDE FILE: lib/string/length.sub *** 6 182C ?_OBJECT_? 7 ;******************************************************************************* 8 ; Purpose: Return the length of an ASCIZ string 9 ; Input : HX -> string 10 ; Output : A = Length (zero when string is longer than 255) 11 ; : CCR matches RegA contents (a welcome side effect) 12 ; Note(s): 13 14 StringLength macro [[#]StringVariable] ;if no parm, use current HX 15 mset # 16 #ifb ~1~ 17 call ~0~ 18 mexit 19 #endif 20 #push 21 #spauto :sp 22 pshhx 23 @@lea ~1~ 24 call ~0~ 25 pulhx 26 #pull 27 endm 28 29 ;------------------------------------------------------------------------------- 30 31 #spauto 32 33 182C StringLength proc 34 [182C] 182C:898B [ 4] pshhx 35 [182E] 182E:4F [ 1] clra 36 [182F] 182F:7D [ 3] Loop@@ tst ,x 37 [1830] 1830:2704 (1836) [ 3] beq Done@@ ;on ASCIZ terminator, done 38 [1832] 1832:AF01 [ 2] aix #1 ;bump up pointer 39 [1834] 1834:4BF9 (182F) [ 4] dbnza Loop@@ 40 [1836] 1836:40 [ 1] Done@@ nega ;(now CCR matches A value) 41 [1837] 1837:8A88 [ 6] pulhx 42 [1839] 1839:81 [ 6] rtc 43 44 #sp 45 ;******************************************************************************* *** END INCLUDE FILE: lib/string/length.sub *** (RESUMING FILE: lib/stakmath.sub) 1456 #Exit 1457 #Uses string/insertchar.sub *** BEGIN INCLUDE FILE: lib/string/insertchar.sub *** 6 7 ;******************************************************************************* 8 ; Purpose: Insert a character at the beginning of an ASCIZ (sub-)string 9 ; Input : HX -> position in ASCIZ string where to insert new character 10 ; : A = character to insert 11 ; Output : None 12 13 StringInsertChar macro [[#]Char[,[#]StringVar]] 14 #ifb ~1~ 15 call ~0~ ;HX and A pre-loaded correctly 16 mexit 17 #endif 18 #push 19 #spauto :sp 20 #ifparm ~2~ 21 push 22 lda ~1~ 23 @@lea ~@@~ 24 call ~0~ 25 pull 26 #pull 27 mexit 28 #endif 29 psha 30 lda ~1~ 31 call ~0~ 32 pula 33 #pull 34 endm 35 36 ;------------------------------------------------------------------------------- 37 38 #spauto 39 40 183A StringInsertChar proc 41 [183A] 183A:8789 8B [ 6] push 42 [183D] 183D:87 [ 2] psha char_to_ins@@ ;next character to insert 43 [183E] 183E:F6 [ 3] Loop@@ lda ,x ;A = old string character 44 [183F] 183F:87 [ 2] psha ;save it for now 45 [1840] 1840:9EE6 02 [ 4] lda char_to_ins@@,sp ;A = new character 46 [1843] 1843:F7 [ 2] sta ,x ;save it at current position 47 [1844] 1844:86 [ 3] pula ;A = old string character 48 [1845] 1845:2707 (184E) [ 3] beq Done@@ ;if at terminator, we're done 49 [1847] 1847:9EE7 01 [ 4] sta char_to_ins@@,sp ;save old for next iteration 50 [184A] 184A:AF01 [ 2] aix #1 ;HX -> next character position 51 [184C] 184C:20F0 (183E) [ 3] bra Loop@@ ;repeat for all characters 52 [184E] 184E:86 [ 3] Done@@ pula ;remove temp variable(s) 53 [184F] 184F:8A88 86 [ 9] pull 54 [1852] 1852:81 [ 6] rtc 55 56 ;******************************************************************************* 57 #sp 58 ;******************************************************************************* *** END INCLUDE FILE: lib/string/insertchar.sub *** (RESUMING FILE: lib/stakmath.sub) 1458 #Uses string/adddecimalpoint.sub *** BEGIN INCLUDE FILE: lib/string/adddecimalpoint.sub *** 6 #Uses length.sub 7 #Uses insertchar.sub 8 9 ;******************************************************************************* 10 ; Purpose: Add decimal point to ASCIZ 'number' 11 ; Input : HX -> ASCIZ string 'number' 12 ; : A = number of decimal places 13 ; Output : ASCIZ string updated 14 15 AddDecimalPoint macro [[#]DecimalPlaces[,[#]ASCIZ_String]] 16 #ifnoparm ~1~ 17 call ~0~ ;HX and A pre-loaded correctly 18 mexit 19 #endif 20 #push 21 #spauto :sp 22 #ifparm ~2~ 23 push 24 lda ~1~ 25 @@lea ~2~ 26 call ~0~ 27 pull 28 #pull 29 mexit 30 #endif 31 psha 32 lda ~1~ 33 call ~0~ 34 pula 35 #pull 36 endm 37 38 ;------------------------------------------------------------------------------- 39 40 #spauto 41 42 1853 AddDecimalPoint proc 43 [1853] 1853:4100 36(188C) [ 4] cbeqa #0,Return@@ ;zero position is a no-op 44 [1856] 1856:87 [ 2] psha places@@ 45 [1857] 1857:898B [ 4] pshhx 47 [1859] 1859:F6 [ 3] lda ,x 48 [185A] 185A:A12D [ 2] cmpa #'-' ;is it a minus sign? 49 [185C] 185C:2602 (1860) [ 3] bne DoneSign@@ ;no, continue as usual 50 [185E] 185E:AF01 [ 2] aix #1 ;yes, skip the sign 51 1860 DoneSign@@ 53 M @StringLength ;get length of ASCIZ number 53 M mset # 53 M [1860] 1860:CD18 2C [ 6] call StringLength 53 mexit 54 55 [1863] 1863:9EE1 03 [ 4] LeadingZeros@@ cmpa places@@,sp ;while length <= decimal digits, 56 [1866] 1866:220A (1872) [ 3] bhi AddDot@@ 57 M @StringInsertChar #'0' ;... add leading zero 57 M #push 57 M #spauto :sp 57 M [1868] 1868:87 [ 2] psha 57 M [1869] 1869:A630 [ 2] lda #'0' 57 M [186B] 186B:CD18 3A [ 6] call StringInsertChar 57 M [186E] 186E:86 [ 3] pula 57 M #pull 57 endm 58 [186F] 186F:4C [ 1] inca ;update string length 59 [1870] 1870:20F1 (1863) [ 3] bra LeadingZeros@@ 60 61 [1872] 1872:9EE0 03 [ 4] AddDot@@ sub places@@,sp ;calculate dot insertion index 62 M @aax ;HX -> dot insertion spot 62 M mdef 1,1 62 M [1875] 1875:879F 9EEB 0197 [23] !aax 62 M 8B86 A900 878A 62 M 86 62 M mtop 1 62 endm 63 M @StringInsertChar #'.' ;insert dot 63 M #push 63 M #spauto :sp 63 M [1882] 1882:87 [ 2] psha 63 M [1883] 1883:A62E [ 2] lda #'.' 63 M [1885] 1885:CD18 3A [ 6] call StringInsertChar 63 M [1888] 1888:86 [ 3] pula 63 M #pull 63 endm 64 65 [1889] 1889:8A88 86 [ 9] Done@@ pull 66 [188C] 188C:81 [ 6] Return@@ rtc 67 68 ;******************************************************************************* 69 #sp 70 ;******************************************************************************* *** END INCLUDE FILE: lib/string/adddecimalpoint.sub *** (RESUMING FILE: lib/stakmath.sub) 1459 188D ?_OBJECT_? 1460 ;******************************************************************************* 1461 ; One-based (SP-index) offsets to stacked operands (to be used with #SPAUTO :AB) 1462 ;******************************************************************************* 1463 1464 #temp 1 1465 0001 ?a next :temp,?WORD ;top-of-stack (TOS) number (N1) 1466 0005 ?b next :temp,?WORD ;number after TOS (N2) 1467 1468 #Cycles ;reset the cycles counter 1469 1470 ;******************************************************************************* 1471 ; Purpose: Add N1 to N2 and place result on top-of-stack. N1 & N2 removed 1472 ; Input : [TOS+?WORD] = Number2 1473 ; : [TOS] = Number1 1474 ; Output : [TOS] = Result 1475 ; Note(s): Carry Set on overflow 1476 1477 #spauto :ab 1478 1479 188D ?Add proc 1480 [188D] 188D:8789 8B [ 6] push 1481 [1890] 1890:95 [ 2] tsx 1482 1488 [1891] 1891:A604 [ 2] lda #?WORD 1489 [1893] 1893:98 [ 1] clc 1490 #Cycles 1491 [1894] 1894:87 [ 2] Loop@@ psha 1492 [1895] 1895:E608 [ 3] lda ?a+{::?a-1},spx 1493 [1897] 1897:E90C [ 3] adc ?b+{::?b-1},spx 1494 [1899] 1899:E70C [ 3] sta ?b+{::?b-1},spx 1495 [189B] 189B:86 [ 3] pula 1496 [189C] 189C:AFFF [ 2] aix #-1 1497 [189E] 189E:4BF4 (1894) [ 4] dbnza Loop@@ 1498 #Cycles :cycles*?WORD+:ocycles 1500 [18A0] 18A0:CC1B 76 [ 4] jmp ?RemoveAndReturn 1501 1502 005F ?AddCycles equ :cycles 1503 1504 ;******************************************************************************* 1505 ; Purpose: Subtract N2 from N1 and place result on top-of-stack. N1 & N2 removed 1506 ; Input : [TOS+?WORD] = Number2 1507 ; : [TOS] = Number1 1508 ; Output : [TOS] = Result 1509 ; Note(s): Carry Set on borrow 1510 1511 #spauto :ab 1512 1513 18A3 ?Subtract proc 1514 [18A3] 18A3:8789 8B [ 6] push 1515 [18A6] 18A6:95 [ 2] tsx 1521 [18A7] 18A7:A604 [ 2] lda #?WORD 1522 [18A9] 18A9:98 [ 1] clc 1523 #Cycles 1524 [18AA] 18AA:87 [ 2] Loop@@ psha 1525 [18AB] 18AB:E608 [ 3] lda ?a+{::?a-1},spx 1526 [18AD] 18AD:E20C [ 3] sbc ?b+{::?b-1},spx 1527 [18AF] 18AF:E70C [ 3] sta ?b+{::?b-1},spx 1528 [18B1] 18B1:86 [ 3] pula 1529 [18B2] 18B2:AFFF [ 2] aix #-1 1530 [18B4] 18B4:4BF4 (18AA) [ 4] dbnza Loop@@ 1531 #Cycles :cycles*?WORD+:ocycles 1533 [18B6] 18B6:CC1B 76 [ 4] jmp ?RemoveAndReturn 1534 1535 005F ?SubCycles equ :cycles 1536 1540 M @Msg Bit ops enabled (define NO_BIT_OPS to disable) 1540 mexit 1541 ;******************************************************************************* 1542 ; Purpose: AND N1 with N2 and place result on top-of-stack. N1 & N2 removed 1543 ; Input : [TOS+?WORD] = Number2 1544 ; : [TOS] = Number1 1545 ; Output : [TOS] = Result 1546 ; Note(s): 1547 #spauto :ab 1548 1549 18B9 ?BitAnd proc 1550 [18B9] 18B9:8789 8B [ 6] push 1551 [18BC] 18BC:95 [ 2] tsx 1552 1558 [18BD] 18BD:A604 [ 2] lda #?WORD 1559 #Cycles 1560 [18BF] 18BF:87 [ 2] Loop@@ psha 1561 [18C0] 18C0:E608 [ 3] lda ?a+{::?a-1},spx 1562 [18C2] 18C2:E40C [ 3] and ?b+{::?b-1},spx 1563 [18C4] 18C4:E70C [ 3] sta ?b+{::?b-1},spx 1564 [18C6] 18C6:86 [ 3] pula 1565 [18C7] 18C7:AFFF [ 2] aix #-1 1566 [18C9] 18C9:4BF4 (18BF) [ 4] dbnza Loop@@ 1567 #Cycles :cycles*?WORD+:ocycles 1569 [18CB] 18CB:CC1B 76 [ 4] jmp ?RemoveAndReturn 1570 1571 005E ?AndCycles equ :cycles 1572 1573 ;******************************************************************************* 1574 ; Purpose: OR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1575 ; Input : [TOS+?WORD] = Number2 1576 ; : [TOS] = Number1 1577 ; Output : [TOS] = Result 1578 ; Note(s): 1579 #spauto :ab 1580 1581 18CE ?BitOr proc 1582 [18CE] 18CE:8789 8B [ 6] push 1583 [18D1] 18D1:95 [ 2] tsx 1584 1590 [18D2] 18D2:A604 [ 2] lda #?WORD 1591 #Cycles 1592 [18D4] 18D4:87 [ 2] Loop@@ psha 1593 [18D5] 18D5:E608 [ 3] lda ?a+{::?a-1},spx 1594 [18D7] 18D7:EA0C [ 3] ora ?b+{::?b-1},spx 1595 [18D9] 18D9:E70C [ 3] sta ?b+{::?b-1},spx 1596 [18DB] 18DB:86 [ 3] pula 1597 [18DC] 18DC:AFFF [ 2] aix #-1 1598 [18DE] 18DE:4BF4 (18D4) [ 4] dbnza Loop@@ 1599 #Cycles :cycles*?WORD+:ocycles 1601 [18E0] 18E0:CC1B 76 [ 4] jmp ?RemoveAndReturn 1602 1603 005E ?OrCycles equ :cycles 1604 1605 ;******************************************************************************* 1606 ; Purpose: XOR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1607 ; Input : [TOS+?WORD] = Number2 1608 ; : [TOS] = Number1 1609 ; Output : [TOS] = Result 1610 ; Note(s): 1611 #spauto :ab 1612 1613 18E3 ?BitXor proc 1614 [18E3] 18E3:8789 8B [ 6] push 1615 [18E6] 18E6:95 [ 2] tsx 1616 1622 [18E7] 18E7:A604 [ 2] lda #?WORD 1623 #Cycles 1624 [18E9] 18E9:87 [ 2] Loop@@ psha 1625 [18EA] 18EA:E608 [ 3] lda ?a+{::?a-1},spx 1626 [18EC] 18EC:E80C [ 3] eor ?b+{::?b-1},spx 1627 [18EE] 18EE:E70C [ 3] sta ?b+{::?b-1},spx 1628 [18F0] 18F0:86 [ 3] pula 1629 [18F1] 18F1:AFFF [ 2] aix #-1 1630 [18F3] 18F3:4BF4 (18E9) [ 4] dbnza Loop@@ 1631 #Cycles :cycles*?WORD+:ocycles 1633 [18F5] 18F5:CC1B 76 [ 4] jmp ?RemoveAndReturn 1634 1635 005E ?EorCycles equ :cycles 1636 1637 ;******************************************************************************* 1638 ; Purpose: Shift N1 left N2 times and place result on top-of-stack. N1 & N2 removed 1639 ; Input : [TOS+?WORD] = Number2 1640 ; : [TOS] = Number1 1641 ; Output : [TOS] = Result 1642 ; Note(s): CCR[C] = last most significant bit shifted out 1643 ; : Only LSB of second operand (N2) is used, as shifting more than the 1644 ; : highest bit version always produces zero. Any non-zero bytes in the 1645 ; : N2 operand will cause a zero result, regardless. 1646 1647 #spauto :ab 1648 1649 18F8 ?ShiftLeft proc 1650 [18F8] 18F8:8789 8B [ 6] push 1651 #ais 1652 1653 [18FB] 18FB:9EE6 0D [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1654 [18FE] 18FE:87 [ 2] psha counter@@ 1655 1656 [18FF] 18FF:95 [ 2] tsx 1657 1658 [1900] 1900:6F0D [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1659 0005 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1660 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1660 M mset # 1660 M mreq 1 1660 M @@_nosize_ b9,spx 1660 M mset # 1660 M mset 0,mstop [_tst_.s] No size (b9,spx) 1660 M endm 1660 M mdo 1660 M [1902] 1902:E60A [ 3] lda b9+0,spx 1660 M mloop ::b9 1660 M [1904] 1904:EA0B [ 3] ora b9+1,spx 1660 M mloop ::b9 1660 M [1906] 1906:EA0C [ 3] ora b9+2,spx 1660 M mloop ::b9 1660 endm 1661 [1908] 1908:270D (1917) [ 3] beq Go@@ ;if so, proceed normally 1662 1663 [190A] 190A:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1664 [190B] 190B:A120 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1665 [190D] 190D:2508 (1917) [ 3] blo Go@@ ;else zero and exit 1666 1667 M @clr.s, b@@,spx ;else error, so zero result 1667 M mset #' ' 1667 M mreq 1 1667 M @@_nosize_ b9,spx 1667 M mset # 1667 M mset 0,mstop [clr.s] No size (b9,spx) 1667 M endm 1667 M mdef 2,::b9 1667 M mdo 1667 M [190F] 190F:6F0A [ 5] clr b9+0,spx 1667 M mloop ::b9 1667 M [1911] 1911:6F0B [ 5] clr b9+1,spx 1667 M mloop ::b9 1667 M [1913] 1913:6F0C [ 5] clr b9+2,spx 1667 M mloop ::b9 1667 endm 1668 [1915] 1915:201A (1931) [ 3] bra Done@@ ;and get out 1669 1670 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1670 M mset #' ' 1670 M mreq 1,2:Source Destination 1670 M @@_samesize_ ?a,spx ?b,spx 1670 M mreq 1,2:Operand1,Operand2[,Operand]* 1670 M mset 0 1670 M mdo 1670 M mswap 1,1 1670 M @@_nosize_ ?a,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?a,spx) 1670 M endm 1670 M mset 0,?a,spx 1670 M mloop :n 1670 M mswap 1,2 1670 M @@_nosize_ ?b,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?b,spx) 1670 M endm 1670 M mloop :n 1670 M endm 1670 M mset 0 1670 M mdo 1670 M [1917] 1917:E606 [ 3] lda ?a+0,spx 1670 M [1919] 1919:E70A [ 3] sta ?b+0,spx 1670 M mloop ::?b 1670 M [191B] 191B:E607 [ 3] lda ?a+1,spx 1670 M [191D] 191D:E70B [ 3] sta ?b+1,spx 1670 M mloop ::?b 1670 M [191F] 191F:E608 [ 3] lda ?a+2,spx 1670 M [1921] 1921:E70C [ 3] sta ?b+2,spx 1670 M mloop ::?b 1670 M [1923] 1923:E609 [ 3] lda ?a+3,spx 1670 M [1925] 1925:E70D [ 3] sta ?b+3,spx 1670 M mloop ::?b 1670 endm 1671 #Cycles 1672 M Loop@@ @lsl.s, ?b,spx ;shift left one bit position 1672 M mset # 1672 M mreq 1 1672 M @@_nosize_ ?b,spx 1672 M mset # 1672 M mset 0,mstop [lsl.s] No size (?b,spx) 1672 M endm 1672 M mdo 1672 M [1927] 1927:680D [ 5] lsl ?b+3,spx 1672 M mloop ::?b 1672 M [1929] 1929:690C [ 5] rol ?b+2,spx 1672 M mloop ::?b 1672 M [192B] 192B:690B [ 5] rol ?b+1,spx 1672 M mloop ::?b 1672 M [192D] 192D:690A [ 5] rol ?b+0,spx 1672 M mloop ::?b 1672 endm 1673 [192F] 192F:7BF6 (1927) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1674 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1675 1931 Done@@ 1677 [1931] 1931:86 [ 3] pula 1681 [1932] 1932:CC1B 76 [ 4] jmp ?RemoveAndReturn 1682 1683 037E ?ShlCycles equ :cycles 1684 1685 ;******************************************************************************* 1686 ; Purpose: Shift N1 right N2 times and place result on top-of-stack. N1 & N2 removed 1687 ; Input : [TOS+?WORD] = Number2 1688 ; : [TOS] = Number1 1689 ; Output : [TOS] = Result 1690 ; Note(s): CCR[C] = last least significant bit shifted out 1691 ; : Only LSB of second operand (N2) is used, as shifting more than the 1692 ; : highest bit version always produces zero. Any non-zero bytes in the 1693 ; : N2 operand will cause a zero result, regardless. 1694 1695 #spauto :ab 1696 1697 1935 ?ShiftRight proc 1698 [1935] 1935:8789 8B [ 6] push 1699 #ais 1700 1701 [1938] 1938:9EE6 0D [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1702 [193B] 193B:87 [ 2] psha counter@@ 1703 1704 [193C] 193C:95 [ 2] tsx 1705 1706 [193D] 193D:6F0D [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1707 0005 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1708 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1708 M mset # 1708 M mreq 1 1708 M @@_nosize_ b10,spx 1708 M mset # 1708 M mset 0,mstop [_tst_.s] No size (b10,spx) 1708 M endm 1708 M mdo 1708 M [193F] 193F:E60A [ 3] lda b10+0,spx 1708 M mloop ::b10 1708 M [1941] 1941:EA0B [ 3] ora b10+1,spx 1708 M mloop ::b10 1708 M [1943] 1943:EA0C [ 3] ora b10+2,spx 1708 M mloop ::b10 1708 endm 1709 [1945] 1945:270D (1954) [ 3] beq Go@@ ;if so, proceed normally 1710 1711 [1947] 1947:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1712 [1948] 1948:A120 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1713 [194A] 194A:2508 (1954) [ 3] blo Go@@ ;else zero and exit 1714 1715 M @clr.s, b@@,spx ;else error, so zero result 1715 M mset #' ' 1715 M mreq 1 1715 M @@_nosize_ b10,spx 1715 M mset # 1715 M mset 0,mstop [clr.s] No size (b10,spx) 1715 M endm 1715 M mdef 2,::b10 1715 M mdo 1715 M [194C] 194C:6F0A [ 5] clr b10+0,spx 1715 M mloop ::b10 1715 M [194E] 194E:6F0B [ 5] clr b10+1,spx 1715 M mloop ::b10 1715 M [1950] 1950:6F0C [ 5] clr b10+2,spx 1715 M mloop ::b10 1715 endm 1716 [1952] 1952:201A (196E) [ 3] bra Done@@ ;and get out 1717 1718 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1718 M mset #' ' 1718 M mreq 1,2:Source Destination 1718 M @@_samesize_ ?a,spx ?b,spx 1718 M mreq 1,2:Operand1,Operand2[,Operand]* 1718 M mset 0 1718 M mdo 1718 M mswap 1,1 1718 M @@_nosize_ ?a,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?a,spx) 1718 M endm 1718 M mset 0,?a,spx 1718 M mloop :n 1718 M mswap 1,2 1718 M @@_nosize_ ?b,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?b,spx) 1718 M endm 1718 M mloop :n 1718 M endm 1718 M mset 0 1718 M mdo 1718 M [1954] 1954:E606 [ 3] lda ?a+0,spx 1718 M [1956] 1956:E70A [ 3] sta ?b+0,spx 1718 M mloop ::?b 1718 M [1958] 1958:E607 [ 3] lda ?a+1,spx 1718 M [195A] 195A:E70B [ 3] sta ?b+1,spx 1718 M mloop ::?b 1718 M [195C] 195C:E608 [ 3] lda ?a+2,spx 1718 M [195E] 195E:E70C [ 3] sta ?b+2,spx 1718 M mloop ::?b 1718 M [1960] 1960:E609 [ 3] lda ?a+3,spx 1718 M [1962] 1962:E70D [ 3] sta ?b+3,spx 1718 M mloop ::?b 1718 endm 1719 #Cycles 1720 1964 Loop@@ 1722 M @asr.s, ?b,spx ;shift right one bit position 1722 M mset # 1722 M mreq 1 1722 M @@_nosize_ ?b,spx 1722 M mset # 1722 M mset 0,mstop [asr.s] No size (?b,spx) 1722 M endm 1722 M mdo 1722 M [1964] 1964:670A [ 5] asr ?b+0,spx 1722 M mloop ::?b 1722 M [1966] 1966:660B [ 5] ror ?b+1,spx 1722 M mloop ::?b 1722 M [1968] 1968:660C [ 5] ror ?b+2,spx 1722 M mloop ::?b 1722 M [196A] 196A:660D [ 5] ror ?b+3,spx 1722 M mloop ::?b 1722 endm 1726 [196C] 196C:7BF6 (1964) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1727 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1728 196E Done@@ 1730 [196E] 196E:86 [ 3] pula 1734 [196F] 196F:CC1B 76 [ 4] jmp ?RemoveAndReturn 1735 1736 037E ?ShrCycles equ :cycles 1738 1739 ;******************************************************************************* 1740 ; Purpose: Multiply N1 with N2 and place result on top-of-stack. N1 & N2 removed 1741 ; Input : [TOS+?WORD] = Number2 1742 ; : [TOS] = Number1 1743 ; Output : [TOS] = Result 1744 ; Note(s): Overflows lost, Carry state should be ignored 1745 1746 #spauto :ab 1747 1748 1972 ?Multiply proc 1749 [1972] 1972:8789 8B [ 6] push 1773 ;=============================================================================== 1826 ;=============================================================================== 1828 ;-------------------------------------- ;row 1 1829 [1975] 1975:95 [ 2] tsx 1830 [1976] 1976:E608 [ 3] lda ?a+3,spx 1831 [1978] 1978:EE0C [ 3] ldx ?b+3,spx 1832 [197A] 197A:42 [ 5] mul 1833 [197B] 197B:8789 [ 4] pshxa ans@@ ;temporary 32-bit result (3rd & 4th bytes) 1834 1835 [197D] 197D:95 [ 2] tsx 1836 [197E] 197E:E609 [ 3] lda ?a+2,spx 1837 [1980] 1980:EE0D [ 3] ldx ?b+2,spx 1838 [1982] 1982:42 [ 5] mul 1839 [1983] 1983:8789 [ 4] pshxa ans@@,4 ;temporary 32-bit result (1st & 2nd bytes) 1840 1841 [1985] 1985:95 [ 2] tsx 1842 [1986] 1986:E60C [ 3] lda ?a+3,spx 1843 [1988] 1988:EE0F [ 3] ldx ?b+2,spx 1844 [198A] 198A:42 [ 5] mul 1845 [198B] 198B:9EEB 03 [ 4] add ans@@+2,sp 1846 [198E] 198E:9EE7 03 [ 4] sta ans@@+2,sp 1847 [1991] 1991:9F [ 1] txa 1848 [1992] 1992:95 [ 2] tsx 1849 [1993] 1993:E901 [ 3] adc ans@@+1,spx 1850 [1995] 1995:E701 [ 3] sta ans@@+1,spx 1851 1852 [1997] 1997:E60C [ 3] lda ?a+3,spx 1853 [1999] 1999:EE0E [ 3] ldx ?b+1,spx 1854 [199B] 199B:42 [ 5] mul 1855 [199C] 199C:9EEB 02 [ 4] add ans@@+1,sp 1856 [199F] 199F:9EE7 02 [ 4] sta ans@@+1,sp 1857 [19A2] 19A2:9F [ 1] txa 1858 [19A3] 19A3:95 [ 2] tsx 1859 [19A4] 19A4:F9 [ 3] adc ans@@,spx 1860 [19A5] 19A5:F7 [ 2] sta ans@@,spx 1861 1862 [19A6] 19A6:E60C [ 3] lda ?a+3,spx 1863 [19A8] 19A8:EE0D [ 3] ldx ?b+0,spx 1864 [19AA] 19AA:42 [ 5] mul 1865 [19AB] 19AB:95 [ 2] tsx 1866 [19AC] 19AC:FB [ 3] add ans@@,spx 1867 [19AD] 19AD:F7 [ 2] sta ans@@,spx 1868 ;-------------------------------------- ;row 2 1869 [19AE] 19AE:E60B [ 3] lda ?a+2,spx 1870 [19B0] 19B0:EE10 [ 3] ldx ?b+3,spx 1871 [19B2] 19B2:42 [ 5] mul 1872 [19B3] 19B3:9EEB 03 [ 4] add ans@@+2,sp 1873 [19B6] 19B6:9EE7 03 [ 4] sta ans@@+2,sp 1874 [19B9] 19B9:9F [ 1] txa 1875 [19BA] 19BA:95 [ 2] tsx 1876 [19BB] 19BB:E901 [ 3] adc ans@@+1,spx 1877 [19BD] 19BD:E701 [ 3] sta ans@@+1,spx 1878 [19BF] 19BF:4F [ 1] clra 1879 [19C0] 19C0:F9 [ 3] adc ans@@,spx 1880 [19C1] 19C1:F7 [ 2] sta ans@@,spx 1881 1882 [19C2] 19C2:E60B [ 3] lda ?a+2,spx 1883 [19C4] 19C4:EE0E [ 3] ldx ?b+1,spx 1884 [19C6] 19C6:42 [ 5] mul 1885 [19C7] 19C7:95 [ 2] tsx 1886 [19C8] 19C8:FB [ 3] add ans@@,spx 1887 [19C9] 19C9:F7 [ 2] sta ans@@,spx 1888 ;-------------------------------------- ;row 3 1889 [19CA] 19CA:E60A [ 3] lda ?a+1,spx 1890 [19CC] 19CC:EE10 [ 3] ldx ?b+3,spx 1891 [19CE] 19CE:42 [ 5] mul 1892 [19CF] 19CF:9EEB 02 [ 4] add ans@@+1,sp 1893 [19D2] 19D2:9EE7 02 [ 4] sta ans@@+1,sp 1894 [19D5] 19D5:9F [ 1] txa 1895 [19D6] 19D6:95 [ 2] tsx 1896 [19D7] 19D7:F9 [ 3] adc ans@@,spx 1897 [19D8] 19D8:F7 [ 2] sta ans@@,spx 1898 1899 [19D9] 19D9:E60A [ 3] lda ?a+1,spx 1900 [19DB] 19DB:EE0F [ 3] ldx ?b+2,spx 1901 [19DD] 19DD:42 [ 5] mul 1902 [19DE] 19DE:95 [ 2] tsx 1903 [19DF] 19DF:FB [ 3] add ans@@,spx 1904 [19E0] 19E0:F7 [ 2] sta ans@@,spx 1905 ;-------------------------------------- ;row 4 1906 [19E1] 19E1:E609 [ 3] lda ?a+0,spx 1907 [19E3] 19E3:EE10 [ 3] ldx ?b+3,spx 1908 [19E5] 19E5:42 [ 5] mul 1909 [19E6] 19E6:95 [ 2] tsx 1910 [19E7] 19E7:FB [ 3] add ans@@,spx 1911 [19E8] 19E8:F7 [ 2] sta ans@@,spx 1913 #temp :cycles 1914 ;=============================================================================== 1915 ;-------------------------------------- 1916 ; 40, 48, 56, and 64-bit versions use shorter 1917 ; shift/add method (more cycles, though) 1918 ;-------------------------------------- 1945 ;-------------------------------------- 1946 ; copy result to B while removing from stack 1947 ;-------------------------------------- 1948 [19E9] 19E9:AE04 [ 2] ldx #?WORD 1949 #temp :cycles+:temp 1950 [19EB] 19EB:86 [ 3] CopyResult@@ pula 1951 [19EC] 19EC:9EE7 0D [ 4] sta ?b,sp 1952 [19EF] 19EF:5BFA (19EB) [ 4] dbnzx CopyResult@@ 1953 1954 #spadd 1-?WORD 1955 #temp :cycles*?WORD+:temp 1956 [19F1] 19F1:CC1B 76 [ 4] jmp ?RemoveAndReturn 1957 1958 0118 ?MulCycles equ :temp+:cycles 1959 1960 ;******************************************************************************* 1961 ; Purpose: Divide N1 by N2 and place quotient on top-of-stack. N1 & N2 removed 1962 ; Input : [TOS+?WORD] = Divisor (N2) 1963 ; : [TOS] = Dividend (N1) 1964 ; Output : [TOS] = Quotient 1965 ; : Carry Set on error (division by zero) 1966 ; Note(s): 1967 #spauto :ab 1968 1969 19F4 ?Divide proc 1970 [19F4] 19F4:8789 8B [ 6] push 1971 1972 [19F7] 19F7:A601 [ 2] lda #?DIVOP_ ;flag for DIV operation 1974 [19F9] 19F9:87 [ 2] psha 1975 [19FA] 19FA:95 [ 2] tsx 1976 [19FB] 19FB:E606 [ 3] lda ?a,spx 1977 [19FD] 19FD:E80A [ 3] eor ?b,spx 1978 [19FF] 19FF:86 [ 3] pula 1979 [1A00] 1A00:2A02 (1A04) [ 3] bpl Skip@@ 1980 [1A02] 1A02:AA80 [ 2] ora #?SIGN_ ;flag for negative 1981 1A04 Skip@@ 1983 [1A04] 1A04:87 [ 2] psha ;save flags on stack 1984 [1A05] 1A05:202A (1A31) [ 3] bra ?DivStart 1985 1986 001F ?DivCycles equ :cycles 1987 1988 ;******************************************************************************* 1989 ; Purpose: Divide N1 by N2 and place remainder on top-of-stack. N1 & N2 removed 1990 ; Input : [TOS+?WORD] = Divisor (N2) 1991 ; : [TOS] = Dividend (N1) 1992 ; Output : [TOS] = Remainder 1993 ; : Carry Set on error (division by zero) 1994 ; Note(s): 1995 #spauto :ab 1996 FFFFFFFF ?pc equ ::,:ab 1997 1998 1A07 ?Modulo proc 1999 [1A07] 1A07:8789 8B [ 6] push 2000 2001 [1A0A] 1A0A:4F [ 1] clra ;flag for MOD operation 2003 [1A0B] 1A0B:9E6D 06 [ 5] tst ?a,sp 2004 [1A0E] 1A0E:2A02 (1A12) [ 3] bpl Skip@@ 2005 [1A10] 1A10:AA80 [ 2] ora #?SIGN_ ;flag for negative 2006 1A12 Skip@@ 2008 [1A12] 1A12:87 [ 2] psha ;save flags on stack 2009 [1A13] 1A13:201C (1A31) [ 3] bra ?DivStart 2010 2011 0016 ?ModCycles equ :cycles 2012 2013 ;******************************************************************************* 2014 2015 #temp 2017 1A15 ?AbsX proc 2018 [1A15] 1A15:7D [ 3] tst ,ax 2019 [1A16] 1A16:2A12 (1A2A) [ 3] bpl Done@@ 2020 #temp :cycles 2021 0000 var@@ equ 0,?WORD 2022 M ?NegX @neg.s var@@,ax 2022 M mset # 2022 M mreq 1 2022 M @@_nosize_ var14,ax 2022 M mset # 2022 M mset 0,mstop [neg.s] No size (var14,ax) 2022 M endm 2022 M mdo 2022 M [1A18] 1A18:73 [ 4] com var14+0,ax 2022 M mloop ::var14-1 2022 M [1A19] 1A19:6301 [ 5] com var14+1,ax 2022 M mloop ::var14-1 2022 M [1A1B] 1A1B:6302 [ 5] com var14+2,ax 2022 M mloop ::var14-1 2022 M [1A1D] 1A1D:6003 [ 5] neg var14+3,ax 2022 M mdo 2022 M [1A1F] 1A1F:2609 (1A2A) [ 3] bne Done$$$ 2022 M [1A21] 1A21:6C02 [ 5] inc var14+2,ax 2022 M mloop ::var14-1 2022 M [1A23] 1A23:2605 (1A2A) [ 3] bne Done$$$ 2022 M [1A25] 1A25:6C01 [ 5] inc var14+1,ax 2022 M mloop ::var14-1 2022 M [1A27] 1A27:2601 (1A2A) [ 3] bne Done$$$ 2022 M [1A29] 1A29:7C [ 4] inc var14+0,ax 2022 M mloop ::var14-1 2022 M 1A2A Done$$$ 2022 endm 2023 [1A2A] 1A2A:81 [ 6] Done@@ rts 2024 2025 0030 ?AbsXCycles equ :cycles 2026 002A ?NegxCycles equ ?AbsXCycles-:temp 2028 2029 ;******************************************************************************* 2030 2031 0000 ?SF equ 0 ;stack frame (for X-index use) 2032 2033 0000 ?quotient next ?SF,?WORD 2034 0004 ?remainder next ?SF,?WORD 2035 0008 ?temp next ?SF,?WORD 2036 000C ?bits next ?SF 2037 000D ?flags next ?SF 2038 2039 0001 ?DIVOP_ equ %00000001 ;1 = DIV, 0 = MOD 2040 0080 ?SIGN_ equ %10000000 ;result sign (1 = negative) 2041 2042 #push 2043 2044 [1A2B] 1A2B:A70E [ 2] ?DivError ais #?SF ;de-allocate temporaries 2045 [1A2D] 1A2D:99 [ 1] sec ;indicate error condition 2046 [1A2E] 1A2E:CC1B 76 [ 4] jmp ?RemoveAndReturn 2047 2048 #pull 2049 ;------------------------------------------------------------------------------- 2050 1A31 ?DivStart proc 2051 0001 dividend@@ equ ?a,::?a 2052 0005 divisor@@ equ ?b,::?b 2053 0005 ans@@ equ ?b,::?b ;result overwrites divisor 2054 2056 M @lea dividend@@,sp 2056 M mset # 2056 M [1A31] 1A31:95 [ 2] tsx 2056 M [1A32] 1A32:AF06 [ 2] !aix #dividend15+:tsx 2056 mexit 2057 [1A34] 1A34:ADDF (1A15) [ 5] bsr ?AbsX 2058 M @lea divisor@@,sp 2058 M mset # 2058 M [1A36] 1A36:95 [ 2] tsx 2058 M [1A37] 1A37:AF0A [ 2] !aix #divisor15+:tsx 2058 mexit 2059 [1A39] 1A39:ADDA (1A15) [ 5] bsr ?AbsX 2060 #Cycles ?AbsXCycles*2+:cycles 2062 [1A3B] 1A3B:A7F3 [ 2] ais #-?SF+1 ;quotient, remainder, and temp 2063 [1A3D] 1A3D:95 [ 2] tsx ;(+1 for already pushed Flag) 2064 2065 ; remainder := 0 2066 ; quotient := 0 2067 2068 M @clr.s ?remainder,x 2068 M mset #' ' 2068 M mreq 1 2068 M @@_nosize_ ?remainder,x 2068 M mset # 2068 M mset 0,mstop [clr.s] No size (?remainder,x) 2068 M endm 2068 M mdef 2,::?remainder 2068 M mdo 2068 M [1A3E] 1A3E:6F04 [ 5] clr ?remainder+0,x 2068 M mloop ::?remainder 2068 M [1A40] 1A40:6F05 [ 5] clr ?remainder+1,x 2068 M mloop ::?remainder 2068 M [1A42] 1A42:6F06 [ 5] clr ?remainder+2,x 2068 M mloop ::?remainder 2068 M [1A44] 1A44:6F07 [ 5] clr ?remainder+3,x 2068 M mloop ::?remainder 2068 endm 2069 M @clr.s ?quotient,x 2069 M mset #' ' 2069 M mreq 1 2069 M @@_nosize_ ?quotient,x 2069 M mset # 2069 M mset 0,mstop [clr.s] No size (?quotient,x) 2069 M endm 2069 M mdef 2,::?quotient 2069 M mdo 2069 M [1A46] 1A46:7F [ 4] clr ?quotient+0,x 2069 M mloop ::?quotient 2069 M [1A47] 1A47:6F01 [ 5] clr ?quotient+1,x 2069 M mloop ::?quotient 2069 M [1A49] 1A49:6F02 [ 5] clr ?quotient+2,x 2069 M mloop ::?quotient 2069 M [1A4B] 1A4B:6F03 [ 5] clr ?quotient+3,x 2069 M mloop ::?quotient 2069 endm 2070 2071 ; first, test for division by zero error 2072 2073 M @_tst_.s divisor@@,spx 2073 M mset # 2073 M mreq 1 2073 M @@_nosize_ divisor15,spx 2073 M mset # 2073 M mset 0,mstop [_tst_.s] No size (divisor15,spx) 2073 M endm 2073 M mdo 2073 M [1A4D] 1A4D:E617 [ 3] lda divisor15+0,spx 2073 M mloop ::divisor15 2073 M [1A4F] 1A4F:EA18 [ 3] ora divisor15+1,spx 2073 M mloop ::divisor15 2073 M [1A51] 1A51:EA19 [ 3] ora divisor15+2,spx 2073 M mloop ::divisor15 2073 M [1A53] 1A53:EA1A [ 3] ora divisor15+3,spx 2073 M mloop ::divisor15 2073 endm 2074 [1A55] 1A55:27D4 (1A2B) [ 3] beq ?DivError 2075 2076 ; if Dividend = 0, we're done 2077 2078 M @_tst_.s dividend@@,spx 2078 M mset # 2078 M mreq 1 2078 M @@_nosize_ dividend15,spx 2078 M mset # 2078 M mset 0,mstop [_tst_.s] No size (dividend15,spx) 2078 M endm 2078 M mdo 2078 M [1A57] 1A57:E613 [ 3] lda dividend15+0,spx 2078 M mloop ::dividend15 2078 M [1A59] 1A59:EA14 [ 3] ora dividend15+1,spx 2078 M mloop ::dividend15 2078 M [1A5B] 1A5B:EA15 [ 3] ora dividend15+2,spx 2078 M mloop ::dividend15 2078 M [1A5D] 1A5D:EA16 [ 3] ora dividend15+3,spx 2078 M mloop ::dividend15 2078 endm 2079 [1A5F] 1A5F:2603 CC1B 42 [ 7] !jeq Done@@ 2080 2081 ; if (divisor = dividend) then quotient := 1; return 2082 ; if (divisor > dividend) then remainder := dividend; return 2083 2084 M @_cmp_.s divisor@@,spx dividend@@,spx 2084 M mset #' ' 2084 M mreq 1,2:[#]Operand1 [#]Operand2 2084 M @@_samesize_ divisor15,spx dividend@@,spx 2084 M mreq 1,2:Operand1,Operand2[,Operand]* 2084 M mset 0 2084 M mdo 2084 M mswap 1,1 2084 M @@_nosize_ divisor15,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (divisor15,spx) 2084 M endm 2084 M mset 0,divisor15,spx 2084 M mloop :n 2084 M mswap 1,2 2084 M @@_nosize_ dividend@@,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (dividend15,spx) 2084 M endm 2084 M mloop :n 2084 M endm 2084 M #temp 1 2084 M #temp ::divisor15 2084 M #temp ::dividend@@ 2084 M mdo 2084 M [1A64] 1A64:E617 [ 3] lda divisor15+0,spx 2084 M [1A66] 1A66:E113 [ 3] cmpa dividend@@+0,spx 2084 M [1A68] 1A68:2610 (1A7A) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [1A6A] 1A6A:E618 [ 3] lda divisor15+1,spx 2084 M [1A6C] 1A6C:E114 [ 3] cmpa dividend@@+1,spx 2084 M [1A6E] 1A6E:260A (1A7A) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [1A70] 1A70:E619 [ 3] lda divisor15+2,spx 2084 M [1A72] 1A72:E115 [ 3] cmpa dividend@@+2,spx 2084 M [1A74] 1A74:2604 (1A7A) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [1A76] 1A76:E61A [ 3] lda divisor15+3,spx 2084 M [1A78] 1A78:E116 [ 3] cmpa dividend@@+3,spx 2084 M mloop :temp 2084 M 1A7A Done$$$ 2084 endm 2085 [1A7A] 1A7A:2604 (1A80) [ 3] bne NotEqual@@ 2086 2087 [1A7C] 1A7C:6C03 [ 5] inc ?quotient+{::?quotient-1},x ;quotient := 1 2088 [1A7E] 1A7E:2012 (1A92) [ 3] bra ??DivExit ;and get out 2089 2090 1A80 NotEqual@@ ;@sub.s divisor@@,spx dividend@@,spx ;[2012.05.18 REDUNDANT] 2091 [1A80] 1A80:2513 (1A95) [ 3] blo Continue@@ 2092 2093 M @mova.s dividend@@,spx ?remainder,x 2093 M mset #' ' 2093 M mreq 1,2:Source Destination 2093 M @@_samesize_ dividend15,spx ?remainder,x 2093 M mreq 1,2:Operand1,Operand2[,Operand]* 2093 M mset 0 2093 M mdo 2093 M mswap 1,1 2093 M @@_nosize_ dividend15,spx 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (dividend15,spx) 2093 M endm 2093 M mset 0,dividend15,spx 2093 M mloop :n 2093 M mswap 1,2 2093 M @@_nosize_ ?remainder,x 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (?remainder,x) 2093 M endm 2093 M mloop :n 2093 M endm 2093 M mset 0 2093 M mdo 2093 M [1A82] 1A82:E613 [ 3] lda dividend15+0,spx 2093 M [1A84] 1A84:E704 [ 3] sta ?remainder+0,x 2093 M mloop ::?remainder 2093 M [1A86] 1A86:E614 [ 3] lda dividend15+1,spx 2093 M [1A88] 1A88:E705 [ 3] sta ?remainder+1,x 2093 M mloop ::?remainder 2093 M [1A8A] 1A8A:E615 [ 3] lda dividend15+2,spx 2093 M [1A8C] 1A8C:E706 [ 3] sta ?remainder+2,x 2093 M mloop ::?remainder 2093 M [1A8E] 1A8E:E616 [ 3] lda dividend15+3,spx 2093 M [1A90] 1A90:E707 [ 3] sta ?remainder+3,x 2093 M mloop ::?remainder 2093 endm 2094 1A92 ??DivExit ;and get out 2098 [1A92] 1A92:CC1B 42 [ 4] jmp Done@@ 2100 2101 [1A95] 1A95:A620 [ 2] Continue@@ lda #MATHSIZE 2102 [1A97] 1A97:E70C [ 3] sta ?bits,x ;bits := 64/56/48/40/32/24/16-bit 2103 2104 ; while (remainder < divisor) do 2105 2106 M While@@ @cop ;in case of many iterations 2106 M [1A99] 1A99:C718 00 [ 4] sta COP 2106 endm 2107 2108 M @sub.s ?remainder,x divisor@@,spx 2108 M mset #' ' 2108 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2108 M @@_samesize_ ?remainder,x divisor15,spx 2108 M mreq 1,2:Operand1,Operand2[,Operand]* 2108 M mset 0 2108 M mdo 2108 M mswap 1,1 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (?remainder,x) 2108 M endm 2108 M mset 0,?remainder,x 2108 M mloop :n 2108 M mswap 1,2 2108 M @@_nosize_ divisor15,spx 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (divisor15,spx) 2108 M endm 2108 M mloop :n 2108 M endm 2108 M #temp 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [sub.s] No size (?remainder,x) 2108 M endm 2108 M #temp ::?remainder 2108 M mset 0,sub 2108 M mdo 2108 M [1A9C] 1A9C:E607 [ 3] lda ?remainder+3,x 2108 M [1A9E] 1A9E:E01A [ 3] sub divisor15+3,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [1AA0] 1AA0:E606 [ 3] lda ?remainder+2,x 2108 M [1AA2] 1AA2:E219 [ 3] sbc divisor15+2,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [1AA4] 1AA4:E605 [ 3] lda ?remainder+1,x 2108 M [1AA6] 1AA6:E218 [ 3] sbc divisor15+1,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [1AA8] 1AA8:E604 [ 3] lda ?remainder+0,x 2108 M [1AAA] 1AAA:E217 [ 3] sbc divisor15+0,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 endm 2109 [1AAC] 1AAC:2424 (1AD2) [ 3] bcc EndWhile@@ 2110 2111 ; remainder := (remainder shl 1) or msb(dividend) 2112 ;-------------------------------------- ;2012.12.04 optimization (moved up this code from before DEC to here) 2113 M @mova.s dividend@@,spx ?temp,x ; temp := dividend 2113 M mset #' ' 2113 M mreq 1,2:Source Destination 2113 M @@_samesize_ dividend15,spx ?temp,x 2113 M mreq 1,2:Operand1,Operand2[,Operand]* 2113 M mset 0 2113 M mdo 2113 M mswap 1,1 2113 M @@_nosize_ dividend15,spx 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (dividend15,spx) 2113 M endm 2113 M mset 0,dividend15,spx 2113 M mloop :n 2113 M mswap 1,2 2113 M @@_nosize_ ?temp,x 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (?temp,x) 2113 M endm 2113 M mloop :n 2113 M endm 2113 M mset 0 2113 M mdo 2113 M [1AAE] 1AAE:E613 [ 3] lda dividend15+0,spx 2113 M [1AB0] 1AB0:E708 [ 3] sta ?temp+0,x 2113 M mloop ::?temp 2113 M [1AB2] 1AB2:E614 [ 3] lda dividend15+1,spx 2113 M [1AB4] 1AB4:E709 [ 3] sta ?temp+1,x 2113 M mloop ::?temp 2113 M [1AB6] 1AB6:E615 [ 3] lda dividend15+2,spx 2113 M [1AB8] 1AB8:E70A [ 3] sta ?temp+2,x 2113 M mloop ::?temp 2113 M [1ABA] 1ABA:E616 [ 3] lda dividend15+3,spx 2113 M [1ABC] 1ABC:E70B [ 3] sta ?temp+3,x 2113 M mloop ::?temp 2113 endm 2114 M @lsl.s dividend@@,spx ; dividend := dividend shl 1 2114 M mset # 2114 M mreq 1 2114 M @@_nosize_ dividend15,spx 2114 M mset # 2114 M mset 0,mstop [lsl.s] No size (dividend15,spx) 2114 M endm 2114 M mdo 2114 M [1ABE] 1ABE:6816 [ 5] lsl dividend15+3,spx 2114 M mloop ::dividend15 2114 M [1AC0] 1AC0:6915 [ 5] rol dividend15+2,spx 2114 M mloop ::dividend15 2114 M [1AC2] 1AC2:6914 [ 5] rol dividend15+1,spx 2114 M mloop ::dividend15 2114 M [1AC4] 1AC4:6913 [ 5] rol dividend15+0,spx 2114 M mloop ::dividend15 2114 endm 2115 ;-------------------------------------- 2116 M @rol.s ?remainder,x 2116 M mset # 2116 M mreq 1 2116 M @@_nosize_ ?remainder,x 2116 M mset # 2116 M mset 0,mstop [rol.s] No size (?remainder,x) 2116 M endm 2116 M mdo 2116 M [1AC6] 1AC6:6907 [ 5] rol ?remainder+3,x 2116 M mloop ::?remainder 2116 M [1AC8] 1AC8:6906 [ 5] rol ?remainder+2,x 2116 M mloop ::?remainder 2116 M [1ACA] 1ACA:6905 [ 5] rol ?remainder+1,x 2116 M mloop ::?remainder 2116 M [1ACC] 1ACC:6904 [ 5] rol ?remainder+0,x 2116 M mloop ::?remainder 2116 endm 2117 [1ACE] 1ACE:6A0C [ 5] dec ?bits,x ; bits := bits - 1 2118 2119 ; end while 2120 2121 [1AD0] 1AD0:20C7 (1A99) [ 3] bra While@@ 2122 1AD2 EndWhile@@ 2123 M @mova.s ?temp,x dividend@@,spx ; dividend := temp 2123 M mset #' ' 2123 M mreq 1,2:Source Destination 2123 M @@_samesize_ ?temp,x dividend15,spx 2123 M mreq 1,2:Operand1,Operand2[,Operand]* 2123 M mset 0 2123 M mdo 2123 M mswap 1,1 2123 M @@_nosize_ ?temp,x 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (?temp,x) 2123 M endm 2123 M mset 0,?temp,x 2123 M mloop :n 2123 M mswap 1,2 2123 M @@_nosize_ dividend15,spx 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (dividend15,spx) 2123 M endm 2123 M mloop :n 2123 M endm 2123 M mset 0 2123 M mdo 2123 M [1AD2] 1AD2:E608 [ 3] lda ?temp+0,x 2123 M [1AD4] 1AD4:E713 [ 3] sta dividend15+0,spx 2123 M mloop ::dividend15 2123 M [1AD6] 1AD6:E609 [ 3] lda ?temp+1,x 2123 M [1AD8] 1AD8:E714 [ 3] sta dividend15+1,spx 2123 M mloop ::dividend15 2123 M [1ADA] 1ADA:E60A [ 3] lda ?temp+2,x 2123 M [1ADC] 1ADC:E715 [ 3] sta dividend15+2,spx 2123 M mloop ::dividend15 2123 M [1ADE] 1ADE:E60B [ 3] lda ?temp+3,x 2123 M [1AE0] 1AE0:E716 [ 3] sta dividend15+3,spx 2123 M mloop ::dividend15 2123 endm 2124 M @lsr.s ?remainder,x ; remainder := remainder shr 1 2124 M mset # 2124 M mreq 1 2124 M @@_nosize_ ?remainder,x 2124 M mset # 2124 M mset 0,mstop [lsr.s] No size (?remainder,x) 2124 M endm 2124 M mdo 2124 M [1AE2] 1AE2:6404 [ 5] lsr ?remainder+0,x 2124 M mloop ::?remainder 2124 M [1AE4] 1AE4:6605 [ 5] ror ?remainder+1,x 2124 M mloop ::?remainder 2124 M [1AE6] 1AE6:6606 [ 5] ror ?remainder+2,x 2124 M mloop ::?remainder 2124 M [1AE8] 1AE8:6607 [ 5] ror ?remainder+3,x 2124 M mloop ::?remainder 2124 endm 2125 [1AEA] 1AEA:6C0C [ 5] inc ?bits,x ; bits := bits + 1 2126 2127 ; for i := bitCounter-1 downto 0 do 2128 2129 M For@@ @cop ;in case of many iterations 2129 M [1AEC] 1AEC:C718 00 [ 4] sta COP 2129 endm 2130 2131 [1AEF] 1AEF:6D0C [ 4] tst ?bits,x 2133 [1AF1] 1AF1:274F (1B42) [ 3] beq Done@@ 2137 [1AF3] 1AF3:6A0C [ 5] dec ?bits,x 2138 2139 ; remainder := (remainder shl 1) or msb(dividend) 2140 ; dividend := dividend shl 1 2141 2142 M @lsl.s dividend@@,spx ;2012.12.04 optimization 2142 M mset # 2142 M mreq 1 2142 M @@_nosize_ dividend15,spx 2142 M mset # 2142 M mset 0,mstop [lsl.s] No size (dividend15,spx) 2142 M endm 2142 M mdo 2142 M [1AF5] 1AF5:6816 [ 5] lsl dividend15+3,spx 2142 M mloop ::dividend15 2142 M [1AF7] 1AF7:6915 [ 5] rol dividend15+2,spx 2142 M mloop ::dividend15 2142 M [1AF9] 1AF9:6914 [ 5] rol dividend15+1,spx 2142 M mloop ::dividend15 2142 M [1AFB] 1AFB:6913 [ 5] rol dividend15+0,spx 2142 M mloop ::dividend15 2142 endm 2143 M @rol.s ?remainder,x 2143 M mset # 2143 M mreq 1 2143 M @@_nosize_ ?remainder,x 2143 M mset # 2143 M mset 0,mstop [rol.s] No size (?remainder,x) 2143 M endm 2143 M mdo 2143 M [1AFD] 1AFD:6907 [ 5] rol ?remainder+3,x 2143 M mloop ::?remainder 2143 M [1AFF] 1AFF:6906 [ 5] rol ?remainder+2,x 2143 M mloop ::?remainder 2143 M [1B01] 1B01:6905 [ 5] rol ?remainder+1,x 2143 M mloop ::?remainder 2143 M [1B03] 1B03:6904 [ 5] rol ?remainder+0,x 2143 M mloop ::?remainder 2143 endm 2144 2145 ; temp := remainder - divisor 2146 2147 M @sub.s ?remainder,x divisor@@,spx ?temp,x 2147 M mset #' ' 2147 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2147 M @@_samesize_ ?remainder,x divisor15,spx ?temp,x 2147 M mreq 1,2:Operand1,Operand2[,Operand]* 2147 M mset 0 2147 M mdo 2147 M mswap 1,1 2147 M @@_nosize_ ?remainder,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?remainder,x) 2147 M endm 2147 M mset 0,?remainder,x 2147 M mloop :n 2147 M mswap 1,2 2147 M @@_nosize_ divisor15,spx 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (divisor15,spx) 2147 M endm 2147 M mloop :n 2147 M mswap 1,3 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?temp,x) 2147 M endm 2147 M mloop :n 2147 M endm 2147 M #temp 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [sub.s] No size (?temp,x) 2147 M endm 2147 M #temp ::?temp 2147 M mset 0,sub 2147 M mdo 2147 M [1B05] 1B05:E607 [ 3] lda ?remainder+3,x 2147 M [1B07] 1B07:E01A [ 3] sub divisor15+3,spx 2147 M [1B09] 1B09:E70B [ 3] sta ?temp+3,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [1B0B] 1B0B:E606 [ 3] lda ?remainder+2,x 2147 M [1B0D] 1B0D:E219 [ 3] sbc divisor15+2,spx 2147 M [1B0F] 1B0F:E70A [ 3] sta ?temp+2,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [1B11] 1B11:E605 [ 3] lda ?remainder+1,x 2147 M [1B13] 1B13:E218 [ 3] sbc divisor15+1,spx 2147 M [1B15] 1B15:E709 [ 3] sta ?temp+1,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [1B17] 1B17:E604 [ 3] lda ?remainder+0,x 2147 M [1B19] 1B19:E217 [ 3] sbc divisor15+0,spx 2147 M [1B1B] 1B1B:E708 [ 3] sta ?temp+0,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 endm 2148 2149 ; q := not msb(temp) 2150 2151 [1B1D] 1B1D:E608 [ 3] lda ?temp,x 2152 [1B1F] 1B1F:A880 [ 2] eor #%10000000 ;invert msb 2153 [1B21] 1B21:A480 [ 2] and #%10000000 ;isolate msb 2154 2155 ; quotient := (quotient shl 1) or q 2156 2157 [1B23] 1B23:87 [ 2] psha 2158 [1B24] 1B24:48 [ 1] lsla 2159 [1B25] 1B25:86 [ 3] pula 2160 2161 M @rol.s ?quotient,x 2161 M mset # 2161 M mreq 1 2161 M @@_nosize_ ?quotient,x 2161 M mset # 2161 M mset 0,mstop [rol.s] No size (?quotient,x) 2161 M endm 2161 M mdo 2161 M [1B26] 1B26:6903 [ 5] rol ?quotient+3,x 2161 M mloop ::?quotient 2161 M [1B28] 1B28:6902 [ 5] rol ?quotient+2,x 2161 M mloop ::?quotient 2161 M [1B2A] 1B2A:6901 [ 5] rol ?quotient+1,x 2161 M mloop ::?quotient 2161 M [1B2C] 1B2C:79 [ 4] rol ?quotient+0,x 2161 M mloop ::?quotient 2161 endm 2162 2163 ; if q <> 0 then 2164 2165 [1B2D] 1B2D:4100 BC(1AEC) [ 4] cbeqa #0,For@@ 2166 2167 ; remainder := temp 2168 2169 M @mova.s ?temp,x ?remainder,x 2169 M mset #' ' 2169 M mreq 1,2:Source Destination 2169 M @@_samesize_ ?temp,x ?remainder,x 2169 M mreq 1,2:Operand1,Operand2[,Operand]* 2169 M mset 0 2169 M mdo 2169 M mswap 1,1 2169 M @@_nosize_ ?temp,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?temp,x) 2169 M endm 2169 M mset 0,?temp,x 2169 M mloop :n 2169 M mswap 1,2 2169 M @@_nosize_ ?remainder,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?remainder,x) 2169 M endm 2169 M mloop :n 2169 M endm 2169 M mset 0 2169 M mdo 2169 M [1B30] 1B30:E608 [ 3] lda ?temp+0,x 2169 M [1B32] 1B32:E704 [ 3] sta ?remainder+0,x 2169 M mloop ::?remainder 2169 M [1B34] 1B34:E609 [ 3] lda ?temp+1,x 2169 M [1B36] 1B36:E705 [ 3] sta ?remainder+1,x 2169 M mloop ::?remainder 2169 M [1B38] 1B38:E60A [ 3] lda ?temp+2,x 2169 M [1B3A] 1B3A:E706 [ 3] sta ?remainder+2,x 2169 M mloop ::?remainder 2169 M [1B3C] 1B3C:E60B [ 3] lda ?temp+3,x 2169 M [1B3E] 1B3E:E707 [ 3] sta ?remainder+3,x 2169 M mloop ::?remainder 2169 endm 2170 2171 ; end if -- end for 2172 2174 [1B40] 1B40:20AA (1AEC) [ 3] bra For@@ 2178 2179 [1B42] 1B42:E60D [ 3] Done@@ lda ?flags,x 2180 [1B44] 1B44:A501 [ 2] bit #?DIVOP_ 2181 [1B46] 1B46:2711 (1B59) [ 3] beq ExitMod@@ 2182 2183 0251 ?Cycles equ :cycles 2184 2185 ;ExitDiv@@ 2186 M @mova.s ?quotient,x ans@@,spx 2186 M mset #' ' 2186 M mreq 1,2:Source Destination 2186 M @@_samesize_ ?quotient,x ans15,spx 2186 M mreq 1,2:Operand1,Operand2[,Operand]* 2186 M mset 0 2186 M mdo 2186 M mswap 1,1 2186 M @@_nosize_ ?quotient,x 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (?quotient,x) 2186 M endm 2186 M mset 0,?quotient,x 2186 M mloop :n 2186 M mswap 1,2 2186 M @@_nosize_ ans15,spx 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (ans15,spx) 2186 M endm 2186 M mloop :n 2186 M endm 2186 M mset 0 2186 M mdo 2186 M [1B48] 1B48:F6 [ 3] lda ?quotient+0,x 2186 M [1B49] 1B49:E717 [ 3] sta ans15+0,spx 2186 M mloop ::ans15 2186 M [1B4B] 1B4B:E601 [ 3] lda ?quotient+1,x 2186 M [1B4D] 1B4D:E718 [ 3] sta ans15+1,spx 2186 M mloop ::ans15 2186 M [1B4F] 1B4F:E602 [ 3] lda ?quotient+2,x 2186 M [1B51] 1B51:E719 [ 3] sta ans15+2,spx 2186 M mloop ::ans15 2186 M [1B53] 1B53:E603 [ 3] lda ?quotient+3,x 2186 M [1B55] 1B55:E71A [ 3] sta ans15+3,spx 2186 M mloop ::ans15 2186 endm 2187 [1B57] 1B57:2010 (1B69) [ 3] bra ExitBoth@@ 2188 2189 028B ?DivCycles set ?DivCycles+?Cycles+:cycles 2190 2191 M ExitMod@@ @mova.s ?remainder,x ans@@,spx 2191 M mset #' ' 2191 M mreq 1,2:Source Destination 2191 M @@_samesize_ ?remainder,x ans15,spx 2191 M mreq 1,2:Operand1,Operand2[,Operand]* 2191 M mset 0 2191 M mdo 2191 M mswap 1,1 2191 M @@_nosize_ ?remainder,x 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (?remainder,x) 2191 M endm 2191 M mset 0,?remainder,x 2191 M mloop :n 2191 M mswap 1,2 2191 M @@_nosize_ ans15,spx 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (ans15,spx) 2191 M endm 2191 M mloop :n 2191 M endm 2191 M mset 0 2191 M mdo 2191 M [1B59] 1B59:E604 [ 3] lda ?remainder+0,x 2191 M [1B5B] 1B5B:E717 [ 3] sta ans15+0,spx 2191 M mloop ::ans15 2191 M [1B5D] 1B5D:E605 [ 3] lda ?remainder+1,x 2191 M [1B5F] 1B5F:E718 [ 3] sta ans15+1,spx 2191 M mloop ::ans15 2191 M [1B61] 1B61:E606 [ 3] lda ?remainder+2,x 2191 M [1B63] 1B63:E719 [ 3] sta ans15+2,spx 2191 M mloop ::ans15 2191 M [1B65] 1B65:E607 [ 3] lda ?remainder+3,x 2191 M [1B67] 1B67:E71A [ 3] sta ans15+3,spx 2191 M mloop ::ans15 2191 endm 2192 2193 027F ?ModCycles set ?ModCycles+?Cycles+:cycles 2194 2195 1B69 ExitBoth@@ 2197 [1B69] 1B69:6D0D [ 4] tst ?flags,x 2198 [1B6B] 1B6B:2A06 (1B73) [ 3] bpl SkipSign@@ 2199 M @lea ans@@,sp 2199 M mset # 2199 M [1B6D] 1B6D:95 [ 2] tsx 2199 M [1B6E] 1B6E:AF17 [ 2] !aix #ans15+:tsx 2199 mexit 2200 [1B70] 1B70:CD1A 18 [ 6] jsr ?NegX 2201 1B73 SkipSign@@ 2202 #Cycles ?NegxCycles+:cycles 2204 [1B73] 1B73:A70E [ 2] ais #?SF ;de-allocate temporaries 2205 [1B75] 1B75:98 [ 1] clc ;no error(s) 2206 ; bra ?RemoveAndReturn 2207 2208 003E ?Cycles set :cycles 2209 02C9 ?DivCycles set ?DivCycles+?Cycles 2210 02BD ?ModCycles set ?ModCycles+?Cycles 2211 2212 ;******************************************************************************* 2213 ; Common exit removes lower 32-bit stack element and returns to caller 2214 ;******************************************************************************* 2215 2216 1B76 ?RemoveAndReturn proc 2218 [1B76] 1B76:9EFE 04 [ 5] ldhx ?pc,sp ;our return address moved up 2219 [1B79] 1B79:9EFF 08 [ 5] sthx ?pc+?WORD,sp ;above word to remove 2229 [1B7C] 1B7C:8A88 86 [ 9] pull 2230 [1B7F] 1B7F:A704 [ 2] ais #?WORD ;remove top-of-stack ?WORD 2231 [1B81] 1B81:81 [ 6] rtc 2232 2233 001B ?ReturnCycles equ :cycles 2234 2235 ;******************************************************************************* 2236 ; Purpose: Swaps the stacked order of N1 and N2 2237 ; Input : [TOS+?WORD] = Number2 2238 ; : [TOS] = Number1 2239 ; Output : [TOS+?WORD] = Number1 -- TOS & [TOS+?WORD] in reverse order 2240 ; : [TOS] = Number2 2241 ; Note(s): Does not alter stack size 2242 2243 #spauto :ab 2244 2245 1B82 ?Swap proc 2246 [1B82] 1B82:8789 8B [ 6] push 2247 2248 [1B85] 1B85:A604 [ 2] lda #?WORD 2249 [1B87] 1B87:87 [ 2] psha bytes@@ 2250 2251 [1B88] 1B88:95 [ 2] tsx 2252 #temp :cycles 2253 M Loop@@ @_swap_, ?a,spx ?b,spx ;swap A with B ... 2253 M mset #' ' 2253 M #push 2253 M #spauto :sp 2253 M [1B89] 1B89:E606 [ 3] lda ?a,spx 2253 M [1B8B] 1B8B:87 [ 2] psha 2253 M [1B8C] 1B8C:E60A [ 3] lda ?b,spx 2253 M [1B8E] 1B8E:E706 [ 3] sta ?a,spx 2253 M [1B90] 1B90:86 [ 3] pula 2253 M [1B91] 1B91:E70A [ 3] sta ?b,spx 2253 M #pull 2253 endm 2254 2255 [1B93] 1B93:AF01 [ 2] aix #1 ;point to next byte 2256 [1B95] 1B95:9E6B 01F0 (1B89 [ 8] dbnz bytes@@,sp,Loop@@ ;repeat for all bytes 2257 #temp :cycles*?WORD+:temp 2258 [1B99] 1B99:86 [ 3] pula 2259 2260 [1B9A] 1B9A:8A88 86 [ 9] pull 2261 [1B9D] 1B9D:81 [ 6] rtc 2262 2263 008A ?SwapCycles set :cycles+:temp 2264 2265 ;******************************************************************************* 2266 ; Purpose: Get the absolute value of the top-of-stack number 2267 ; Input : [TOS] = Number 2268 ; Output : [TOS] = Abs(Number) 2269 ; Note(s): Does not alter stack size 2270 2271 #spauto :ab 2272 2273 1B9E ?Abs proc 2274 [1B9E] 1B9E:9E6D 03 [ 5] tst ?a,sp 2275 [1BA1] 1BA1:2AFA (1B9D) [ 3] bpl Done@@ 2276 ; bra ?Negate 2277 2278 1B9D Done@@ equ :AnRTC 2279 2280 0008 ?AbsCycles equ :cycles 2281 2282 ;******************************************************************************* 2283 ; Purpose: Negate the top-of-stack number 2284 ; Input : [TOS] = Number 2285 ; Output : [TOS] = -Number 2286 ; Note(s): Does not alter stack size 2287 2288 #spauto :ab 2289 2290 1BA3 ?Negate proc 2291 [1BA3] 1BA3:898B [ 4] pshhx 2293 M @lea ?a,sp 2293 M mset # 2293 M [1BA5] 1BA5:95 [ 2] tsx 2293 M [1BA6] 1BA6:AF04 [ 2] !aix #?a+:tsx 2293 mexit 2294 [1BA8] 1BA8:CD1A 18 [ 6] jsr ?NegX 2295 #Cycles ?NegxCycles+:cycles 2300 [1BAB] 1BAB:8A88 [ 6] pulhx 2301 [1BAD] 1BAD:81 [ 6] rtc 2302 2303 0044 ?NegateCycles equ :cycles 2304 004C ?AbsCycles set ?NegateCycles+?AbsCycles 2305 2306 ;******************************************************************************* 2307 ; Purpose: Create a new top-of-stack and load to it the number pointed to by HX 2308 ; Input : HX -> [Variable with] Number 2309 ; Output : [TOS] = Number 2310 ; Note(s): This operation makes it easier to load a number to the stack. 2311 ; : Hint: To make a copy of the TOS, do: 2312 ; : tsx 2313 ; : call StackLoad32 2314 ; : (Stack is expanded) 2315 2316 #spauto :ab 2317 2318 1BAE ?Load proc 2319 FFFFFFFF old_rts@@ equ ::,:ab 2320 [1BAE] 1BAE:A7FC [ 2] ais #-?WORD ;allocate new TOS memory 2321 #temp :: 2322 FFFFFFFB new_rts@@ next :temp,:ab 2323 FFFFFFFD tos_num@@ next :temp,?WORD 2324 0001 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2325 #ais :temp 2326 2327 [1BB0] 1BB0:87 [ 2] psha 2328 M @mova.s old_rts@@,sp new_rts@@,sp ;move RTS/RTC after new memory 2328 M mset #' ' 2328 M mreq 1,2:Source Destination 2328 M @@_samesize_ old_rts20,sp new_rts@@,sp 2328 M mreq 1,2:Operand1,Operand2[,Operand]* 2328 M mset 0 2328 M mdo 2328 M mswap 1,1 2328 M @@_nosize_ old_rts20,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (old_rts20,sp) 2328 M endm 2328 M mset 0,old_rts20,sp 2328 M mloop :n 2328 M mswap 1,2 2328 M @@_nosize_ new_rts@@,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (new_rts20,sp) 2328 M endm 2328 M mloop :n 2328 M endm 2328 M mset 0 2328 M mdo 2328 M [1BB1] 1BB1:9EE6 06 [ 4] lda old_rts20+0,sp 2328 M [1BB4] 1BB4:9EE7 02 [ 4] sta new_rts@@+0,sp 2328 M mloop ::new_rts@@ 2328 M [1BB7] 1BB7:9EE6 07 [ 4] lda old_rts20+1,sp 2328 M [1BBA] 1BBA:9EE7 03 [ 4] sta new_rts@@+1,sp 2328 M mloop ::new_rts@@ 2328 endm 2329 M @mova.s ,x tos_num@@,sp 2329 M mset #' ' 2329 M mreq 1,2:Source Destination 2329 M @@_samesize_ ,x tos_num20,sp 2329 M mreq 1,2:Operand1,Operand2[,Operand]* 2329 M mset 0 2329 M mdo 2329 M mswap 1,1 2329 M mloop :n 2329 M mswap 1,2 2329 M @@_nosize_ tos_num20,sp 2329 M mset # 2329 M mset 0,mstop [_samesize_] No size (tos_num20,sp) 2329 M endm 2329 M mset 0,tos_num20,sp 2329 M mloop :n 2329 M endm 2329 M mset 0 2329 M mdo 2329 M [1BBD] 1BBD:F6 [ 3] lda +0,x 2329 M [1BBE] 1BBE:9EE7 04 [ 4] sta tos_num20+0,sp 2329 M mloop ::tos_num20 2329 M [1BC1] 1BC1:E601 [ 3] lda +1,x 2329 M [1BC3] 1BC3:9EE7 05 [ 4] sta tos_num20+1,sp 2329 M mloop ::tos_num20 2329 M [1BC6] 1BC6:E602 [ 3] lda +2,x 2329 M [1BC8] 1BC8:9EE7 06 [ 4] sta tos_num20+2,sp 2329 M mloop ::tos_num20 2329 M [1BCB] 1BCB:E603 [ 3] lda +3,x 2329 M [1BCD] 1BCD:9EE7 07 [ 4] sta tos_num20+3,sp 2329 M mloop ::tos_num20 2329 endm 2330 [1BD0] 1BD0:86 [ 3] pula 2331 [1BD1] 1BD1:81 [ 6] rtc 2332 2333 0039 ?LoadCycles equ :cycles 2334 2335 ;******************************************************************************* 2336 ; Purpose: Unload the top-of-stack number into a variable pointed to by HX 2337 ; Input : [TOS] = Number 2338 ; : HX -> Some 32-bit variable 2339 ; Output : Variable pointed to by HX receives TOS number 2340 ; Note(s): This operation makes it easier to unload a number from the stack. 2341 ; : Use: 2342 ; : ldhx #MyVar 2343 ; : call StackSave32 2344 ; : (Stack is reduced) 2345 2346 #spauto :ab 2347 2348 1BD2 ?Save proc 2349 #temp :: 2350 FFFFFFFF old_rts@@ next :temp,:ab 2351 0001 tos_num@@ next :temp,?WORD 2352 0005 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2353 0003 new_rts@@ next :temp,:ab 2354 2355 0000 var@@ equ 0,?WORD 2356 2357 [1BD2] 1BD2:8789 8B [ 6] push 2358 M @mova.s tos_num@@,sp var@@,x 2358 M mset #' ' 2358 M mreq 1,2:Source Destination 2358 M @@_samesize_ tos_num21,sp var@@,x 2358 M mreq 1,2:Operand1,Operand2[,Operand]* 2358 M mset 0 2358 M mdo 2358 M mswap 1,1 2358 M @@_nosize_ tos_num21,sp 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (tos_num21,sp) 2358 M endm 2358 M mset 0,tos_num21,sp 2358 M mloop :n 2358 M mswap 1,2 2358 M @@_nosize_ var@@,x 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (var21,x) 2358 M endm 2358 M mloop :n 2358 M endm 2358 M mset 0 2358 M mdo 2358 M [1BD5] 1BD5:9EE6 06 [ 4] lda tos_num21+0,sp 2358 M [1BD8] 1BD8:F7 [ 2] sta var@@+0,x 2358 M mloop ::var@@ 2358 M [1BD9] 1BD9:9EE6 07 [ 4] lda tos_num21+1,sp 2358 M [1BDC] 1BDC:E701 [ 3] sta var@@+1,x 2358 M mloop ::var@@ 2358 M [1BDE] 1BDE:9EE6 08 [ 4] lda tos_num21+2,sp 2358 M [1BE1] 1BE1:E702 [ 3] sta var@@+2,x 2358 M mloop ::var@@ 2358 M [1BE3] 1BE3:9EE6 09 [ 4] lda tos_num21+3,sp 2358 M [1BE6] 1BE6:E703 [ 3] sta var@@+3,x 2358 M mloop ::var@@ 2358 endm 2359 2360 [1BE8] 1BE8:95 [ 2] tsx 2361 M @mova.s old_rts@@,spx new_rts@@,spx ;move RTS/RTC before old memory 2361 M mset #' ' 2361 M mreq 1,2:Source Destination 2361 M @@_samesize_ old_rts21,spx new_rts@@,spx 2361 M mreq 1,2:Operand1,Operand2[,Operand]* 2361 M mset 0 2361 M mdo 2361 M mswap 1,1 2361 M @@_nosize_ old_rts21,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (old_rts21,spx) 2361 M endm 2361 M mset 0,old_rts21,spx 2361 M mloop :n 2361 M mswap 1,2 2361 M @@_nosize_ new_rts@@,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (new_rts21,spx) 2361 M endm 2361 M mloop :n 2361 M endm 2361 M mset 0 2361 M mdo 2361 M [1BE9] 1BE9:E603 [ 3] lda old_rts21+0,spx 2361 M [1BEB] 1BEB:E707 [ 3] sta new_rts@@+0,spx 2361 M mloop ::new_rts@@ 2361 M [1BED] 1BED:E604 [ 3] lda old_rts21+1,spx 2361 M [1BEF] 1BEF:E708 [ 3] sta new_rts@@+1,spx 2361 M mloop ::new_rts@@ 2361 endm 2362 [1BF1] 1BF1:8A88 86 [ 9] pull 2363 2364 [1BF4] 1BF4:A704 [ 2] ais #?WORD ;de-allocate TOS memory 2365 [1BF6] 1BF6:81 [ 6] rtc 2366 2367 0040 ?SaveCycles equ :cycles 2368 2369 ;******************************************************************************* 2370 ; Purpose: Adjust TOS old size to new 2371 ; Input : H = old (current) byte size 2372 ; : X = new byte size 2373 ; : CCR[C] = 0 -- always positive number 2374 ; : CCR[C] = 1 -- sign extend 2375 ; Output : None 2376 ; Note(s): RegA deliberately not used for parameter passing (for consistency) 2377 ; : Macro destroys RegHX (as we must not use PSHHX/PULHX around call) 2378 2380 2381 ResizeTOS macro #FromByteSize,#ToByteSize,,unsigned_if_present 2382 mreq 1,2:#FromByteSize,#ToByteSize 2383 #ifb ~1.1.1~~2.1.1~ = ## 2384 mstop Usage: ~0~ #FromByteSize,#ToByteSize 2385 #endif 2386 #temp {~#2~}-{~#1~} 2387 #ifz :temp 2388 mexit ;;same sizes, nothing to do 2389 #endif 2390 #ifnb ~4~ 2391 @@Msg {~#1~*8}-bit => {~#2~*8}-bit 2392 #else ifdef SIGNED 2393 @@Msg Signed {~#1~*8}-bit => {~#2~*8}-bit 2394 #else 2395 @@Msg {~#1~*8}-bit => {~#2~*8}-bit 2396 #endif 2397 #if :temp > 0 ;;increase stack (optimized) 2398 #if :temp < 5 ;;up to size 'long' 2399 clrx ;;assume unsigned 2400 #ifb ~4~ ;;if 'unsigned override' not present 2401 #ifdef SIGNED ;;and signed version is used 2402 tst 1,asp ;;test operand sign 2403 bpl *+3 ;;skip over following COMX 2404 !comx ;;sign-extend negative number 2405 #endif 2406 #endif 2407 pshx:{:temp} ;;(added the curly brackets to make the number visible in LST file) 2408 mexit 2409 #endif 2410 #endif 2411 #if :temp < 0 ;;decrease stack (optimized) 2412 #if :temp > -5 2413 ais #-:temp ;;release stack bytes (negative :temp => positive) 2414 mexit 2415 #endif 2416 #endif 2417 ldhx #~#1~<8|{~#2~} ;;(longer sizes use normal method) 2418 #ifdef SIGNED ;;if signed version is used 2419 #ifb ~4~ ;;and if 'unsigned override' not present 2420 sec ;;use sign extension 2421 #else 2422 clc ;;no sign extension 2423 #endif 2424 #endif 2425 call ~0~ ;;call stack resizing routine 2426 #spadd ~#2~-{~#1~} 2427 endm 2428 ;------------------------------------------------------------------------------- 2429 #spauto :ab 2430 2431 1BF7 ResizeTOS proc 2432 [1BF7] 1BF7:8789 8B [ 6] push old@@,1 2433 2434 [1BFA] 1BFA:85 [ 1] tpa 2435 [1BFB] 1BFB:87 [ 2] psha ccr@@ 2436 2437 #ais 2438 #psp 2439 2440 [1BFC] 1BFC:9F [ 1] txa ;A = new byte size 2441 [1BFD] 1BFD:9EE0 02 [ 4] sub old@@,sp ;A = bytes to add/remove 2442 [1C00] 1C00:2735 (1C37) [ 3] beq Done@@ ;nothing to do, get out 2443 [1C02] 1C02:2B20 (1C24) [ 3] bmi Shrink@@ ;go take care of 'remove' case 2444 ;--------------------------------------------------------------------- 2445 ; "positive" case, going from smaller to larger size 2446 ;--------------------------------------------------------------------- 2447 [1C04] 1C04:87 [ 2] Expand@@ psha room@@ ;create room for expansion 2448 [1C05] 1C05:95 [ 2] tsx 2449 2450 [1C06] 1C06:87 [ 2] psha ;protect counter 2451 2452 [1C07] 1C07:A606 [ 2] lda #:sp-:psp 2453 [1C09] 1C09:87 [ 2] ExpandLoop@@ psha 2454 [1C0A] 1C0A:E601 [ 3] lda room@@+1,spx 2455 [1C0C] 1C0C:F7 [ 2] sta room@@,spx 2456 [1C0D] 1C0D:86 [ 3] pula 2457 [1C0E] 1C0E:AF01 [ 2] aix #1 2458 [1C10] 1C10:4BF7 (1C09) [ 4] dbnza ExpandLoop@@ 2459 2460 [1C12] 1C12:7F [ 4] clr ,x ;positive sign extension 2462 [1C13] 1C13:9EE6 02 [ 4] lda ccr@@-1,sp ;BugFix: 2014.10.14 (WAS: ccr@@,sp) 2463 [1C16] 1C16:84 [ 1] tap 2464 [1C17] 1C17:2406 (1C1F) [ 3] bcc ExpandNext@@ 2465 2466 [1C19] 1C19:9E6D 09 [ 5] tst 1,sp 2467 [1C1C] 1C1C:2A01 (1C1F) [ 3] bpl ExpandNext@@ 2468 [1C1E] 1C1E:73 [ 4] com ,x ;negative sign extension 2470 [1C1F] 1C1F:86 [ 3] ExpandNext@@ pula 2471 [1C20] 1C20:4BE2 (1C04) [ 4] dbnza Expand@@ 2472 2473 [1C22] 1C22:2013 (1C37) [ 3] bra Done@@ 2474 ;--------------------------------------------------------------------- 2475 ; "negative" case, going from larger to smaller size 2476 ;--------------------------------------------------------------------- 2477 #push 2478 #spadd -1 ;account for room@@ PSHA above 2479 #psp 2480 2481 [1C24] 1C24:40 [ 1] Shrink@@ nega ;make counter positive 2482 2483 [1C25] 1C25:87 [ 2] ShrinkAgain@@ psha 2484 [1C26] 1C26:95 [ 2] tsx 2485 2486 [1C27] 1C27:A606 [ 2] lda #:sp-:psp 2487 [1C29] 1C29:87 [ 2] ShrinkLoop@@ psha 2488 [1C2A] 1C2A:E606 [ 3] lda 1-1,spx 2489 [1C2C] 1C2C:E707 [ 3] sta 1,spx 2490 [1C2E] 1C2E:86 [ 3] pula 2491 [1C2F] 1C2F:AFFF [ 2] aix #-1 2492 [1C31] 1C31:4BF6 (1C29) [ 4] dbnza ShrinkLoop@@ 2493 2494 [1C33] 1C33:86 [ 3] pula 2495 [1C34] 1C34:88 [ 3] pulx ;get rid of extra room (AIS #1) 2496 [1C35] 1C35:4BEE (1C25) [ 4] dbnza ShrinkAgain@@ 2497 2498 #pull 2499 ;--------------------------------------------------------------------- 2500 [1C37] 1C37:A701 [ 2] Done@@ ais #:ais 2501 [1C39] 1C39:8A88 86 [ 9] pull 2502 [1C3C] 1C3C:81 [ 6] rtc 2504 2505 ;******************************************************************************* 2506 ; Purpose: Convert 32-bit to ASCIZ string 2507 ; Input : Stack: 32-bit number 2508 ; : HX -> Output buffer with enough space to keep the ASCIZ string result 2509 ; Output : None 2510 ; Note(s): Use: 2511 ; : ldhx #Buffer 2512 ; : call Stack32ToASCIZ 2513 2514 #spauto :ab ;account for RTS/RTC 2515 2516 1C3D ?ToStr proc 2517 [1C3D] 1C3D:8789 8B [ 6] push 2518 #ais ;mark beginning of temporaries 2519 2520 [1C40] 1C40:898B [ 4] pshhx .buffer@@ ;working copy of pointer to buffer 2521 [1C42] 1C42:7F [ 4] clr ,x ;make it an ASCIZ string 2522 2523 M @lea 1,sp ;HX -> TOS number of caller 2523 M mset # 2523 M [1C43] 1C43:95 [ 2] tsx 2523 M [1C44] 1C44:AF07 [ 2] !aix #1+:tsx 2523 mexit 2524 [1C46] 1C46:CD1B AE [ 6] call ?Load ;load a working copy on stack 2525 2526 #spadd ?WORD ;stack has grown by a ?WORD 2527 FFFFFFF6 number@@ equ ::,?WORD 2529 [1C49] 1C49:9E6D 01 [ 5] tst number@@,sp 2530 [1C4C] 1C4C:2A0F (1C5D) [ 3] bpl ToStrLoop@@ 2531 [1C4E] 1C4E:CD1B A3 [ 6] call ?Negate 2533 [1C51] 1C51:9EFE 05 [ 5] ldhx .buffer@@,sp 2540 [1C54] 1C54:A62D [ 2] lda #'-' ;a 'minus' sign 2541 [1C56] 1C56:F7 [ 2] sta ,x ; is saved first 2542 2543 [1C57] 1C57:AF01 [ 2] aix #1 ;HX -> past minus sign 2544 [1C59] 1C59:7F [ 4] clr ,x ;make it an ASCIZ string 2546 [1C5A] 1C5A:9EFF 05 [ 5] sthx .buffer@@,sp ;update pointer past sign 2552 ; bra ToStrLoop@@ 2554 ;=============================================================================== 2555 2556 [1C5D] 1C5D:4500 0A [ 3] ToStrLoop@@ ldhx #10 ;H = 0 (always), X = divisor 2557 M @div.s number@@,sp 2557 M mset # 2557 M mreq 1 2557 M @@_not_x_ number23,sp 2557 M mset #' ' 2557 M mdel 1 2557 M mtop 2557 M mset #' ' 2557 M mexit 2557 M @@_nosize_ number23,sp 2557 M mset # 2557 M mset 0,mstop [div.s] No size (number23,sp) 2557 M endm 2557 M #temp 1 2557 M #temp 2 2557 M [1C60] 1C60:86 [ 3] pula 2557 M [1C61] 1C61:52 [ 6] div 2557 M [1C62] 1C62:87 [ 2] psha 2557 M mdo 2 2557 M [1C63] 1C63:9EE6 02 [ 4] lda number23+1,sp 2557 M [1C66] 1C66:52 [ 6] div 2557 M [1C67] 1C67:9EE7 02 [ 4] sta number23+1,sp 2557 M mloop ::number23 2557 M [1C6A] 1C6A:9EE6 03 [ 4] lda number23+2,sp 2557 M [1C6D] 1C6D:52 [ 6] div 2557 M [1C6E] 1C6E:9EE7 03 [ 4] sta number23+2,sp 2557 M mloop ::number23 2557 M [1C71] 1C71:9EE6 04 [ 4] lda number23+3,sp 2557 M [1C74] 1C74:52 [ 6] div 2557 M [1C75] 1C75:9EE7 04 [ 4] sta number23+3,sp 2557 M mloop ::number23 2557 endm 2558 2559 [1C78] 1C78:8B86 [ 5] tha ;A = remainder 2560 [1C7A] 1C7A:AB30 [ 2] add #'0' ;A = ASCII remainder 2562 [1C7C] 1C7C:9EFE 05 [ 5] ldhx .buffer@@,sp 2568 M @StringInsertChar 2568 M [1C7F] 1C7F:CD18 3A [ 6] call StringInsertChar ;HX and A pre-loaded correctly 2568 mexit 2569 2570 [1C82] 1C82:95 [ 2] tsx 2571 2572 M @_tst_.s number@@,spx 2572 M mset # 2572 M mreq 1 2572 M @@_nosize_ number23,spx 2572 M mset # 2572 M mset 0,mstop [_tst_.s] No size (number23,spx) 2572 M endm 2572 M mdo 2572 M [1C83] 1C83:F6 [ 3] lda number23+0,spx 2572 M mloop ::number23 2572 M [1C84] 1C84:EA01 [ 3] ora number23+1,spx 2572 M mloop ::number23 2572 M [1C86] 1C86:EA02 [ 3] ora number23+2,spx 2572 M mloop ::number23 2572 M [1C88] 1C88:EA03 [ 3] ora number23+3,spx 2572 M mloop ::number23 2572 endm 2573 [1C8A] 1C8A:26D1 (1C5D) [ 3] bne ToStrLoop@@ 2574 2575 [1C8C] 1C8C:A706 [ 2] ais #:ais ;free temporaries 2576 [1C8E] 1C8E:8A88 86 [ 9] pull 2577 [1C91] 1C91:81 [ 6] rtc 2578 2579 #sp ;cancel all SP offsets 2580 2581 ;******************************************************************************* 2582 ; Assign global names to the various library calls, depending on version used. 2583 ; Different names for each version means you can include any at the same time. 2584 ;******************************************************************************* 2585 2586 ? macro BitSize ;temp macro to export symbols 2587 mreq 1:Usage: @~0~ BitSize 2588 #if MATHSIZE = ~1~ 2589 StackAdd~1~ exp ?Add 2590 StackSub~1~ exp ?Subtract 2591 StackMul~1~ exp ?Multiply 2592 StackDiv~1~ exp ?Divide 2593 StackMod~1~ exp ?Modulo 2594 StackSwap~1~ exp ?Swap 2595 StackAbs~1~ exp ?Abs 2596 StackNegate~1~ exp ?Negate 2597 StackLoad~1~ exp ?Load 2598 StackSave~1~ exp ?Save 2599 Stack~1~ToASCIZ exp ?ToStr 2600 #ifdef NO_BIT_OPS 2601 mexit ;;bit operations not available 2602 #endif 2603 StackAnd~1~ exp ?BitAnd 2604 StackOr~1~ exp ?BitOr 2605 StackXor~1~ exp ?BitXor 2606 StackShl~1~ exp ?ShiftLeft 2607 StackShr~1~ exp ?ShiftRight 2608 #endif 2609 endm 2610 2611 M @? 64 ;export 64-bit labels 2611 M mreq 1:Usage: @? BitSize 2611 endm 2612 M @? 56 ;export 56-bit labels 2612 M mreq 1:Usage: @? BitSize 2612 endm 2613 M @? 48 ;export 48-bit labels 2613 M mreq 1:Usage: @? BitSize 2613 endm 2614 M @? 40 ;export 40-bit labels 2614 M mreq 1:Usage: @? BitSize 2614 endm 2615 M @? 32 ;export 32-bit labels 2615 M mreq 1:Usage: @? BitSize 2615 M 188D StackAdd32 exp ?Add 2615 M 18A3 StackSub32 exp ?Subtract 2615 M 1972 StackMul32 exp ?Multiply 2615 M 19F4 StackDiv32 exp ?Divide 2615 M 1A07 StackMod32 exp ?Modulo 2615 M 1B82 StackSwap32 exp ?Swap 2615 M 1B9E StackAbs32 exp ?Abs 2615 M 1BA3 StackNegate32 exp ?Negate 2615 M 1BAE StackLoad32 exp ?Load 2615 M 1BD2 StackSave32 exp ?Save 2615 M 1C3D Stack32ToASCIZ exp ?ToStr 2615 M 18B9 StackAnd32 exp ?BitAnd 2615 M 18CE StackOr32 exp ?BitOr 2615 M 18E3 StackXor32 exp ?BitXor 2615 M 18F8 StackShl32 exp ?ShiftLeft 2615 M 1935 StackShr32 exp ?ShiftRight 2615 endm 2616 M @? 24 ;export 24-bit labels 2616 M mreq 1:Usage: @? BitSize 2616 endm 2617 M @? 16 ;export 16-bit labels 2617 M mreq 1:Usage: @? BitSize 2617 endm 2618 2619 ;******************************************************************************* *** END INCLUDE FILE: lib/stakmath.sub *** (RESUMING FILE: lib/stkmth32.sub) 23 #Exit *** END INCLUDE FILE: lib/stkmth32.sub *** (RESUMING FILE: lib/demo/stakmath.asm) 49 M @? 16,4 49 M @@Page 4 49 M mreq 1:PageNumber 49 M endm 49 #Uses lib/stkmth16.sub *** BEGIN INCLUDE FILE: lib/stkmth16.sub *** 1 ;******************************************************************************* 2 ;* Module : STKMTH16.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Wrapper for 16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stkmth16.html 8 ;* Note(s) : See STAKMATH.SUB for details 9 ;******************************************************************************* 10 16 17 ? macro 18 mset 1,~BASENAME~ 19 MATHSIZE set ~1.{:1-1}~ 20 #Include stakmath.sub 21 endm 22 23 M @? 23 M mset 1,STKMTH16 23 M 0010 MATHSIZE set 16 23 #Include stakmath.sub *** BEGIN INCLUDE FILE: lib/stakmath.sub *** 1 ;******************************************************************************* 2 ;* Module : STAKMATH.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : 64/56/48/40/32/24/16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stakmath.html 8 ;* Note(s) : Use: #Include stakmath.sub 9 ;* : 10 ;* : Several externally defined macros are used throughout this code. 11 ;* : All these (and many more) macros are inside the most recent 12 ;* : version of MACROS.INC which can be copied from the web page at 13 ;* : http://www.aspisys.com/code/hc08/macros.html 14 ;* : (and COMMON.INC at http://www.aspisys.com/code/hc08/common.html) 15 ;* : 16 ;* : The default word size is 32-bit. 17 ;* : 18 ;* : By (re)defining the symbol MATHSIZE (to 16) you get 16-bit code. 19 ;* : By (re)defining the symbol MATHSIZE to 24 you get 24-bit code. 20 ;* : By (re)defining the symbol MATHSIZE to 40 you get 40-bit code. 21 ;* : By (re)defining the symbol MATHSIZE to 48 you get 48-bit code. 22 ;* : By (re)defining the symbol MATHSIZE to 56 you get 56-bit code. 23 ;* : By (re)defining the symbol MATHSIZE to 64 you get 64-bit code. 24 ;* : 25 ;* : You can include all (or some) versions in your program like so: 26 ;* : 27 ;* : #ROM ;(or else, some paged memory) 28 ;* : #Include stakmath.sub 29 ;* : MATHSIZE set 16 ;redefine for 16-bit use 30 ;* : #Include stakmath.sub 31 ;* : MATHSIZE set 24 ;redefine for 24-bit use 32 ;* : #Include stakmath.sub 33 ;* : MATHSIZE set 40 ;redefine for 40-bit use 34 ;* : #Include stakmath.sub 35 ;* : MATHSIZE set 48 ;redefine for 48-bit use 36 ;* : #Include stakmath.sub 37 ;* : MATHSIZE set 56 ;redefine for 56-bit use 38 ;* : #Include stakmath.sub 39 ;* : MATHSIZE set 64 ;redefine for 64-bit use 40 ;* : 41 ;* : or, if you use the related wrapper files, like so: 42 ;* : 43 ;* : #ROM ;(or else, some paged memory) 44 ;* : #Uses stkmth16.sub 45 ;* : #Uses stkmth24.sub 46 ;* : #Uses stkmth32.sub 47 ;* : #Uses stkmth40.sub 48 ;* : #Uses stkmth48.sub 49 ;* : #Uses stkmth56.sub 50 ;* : #Uses stkmth64.sub 51 ;* : 52 ;* : Use CALL if assembled in #MMU mode (regardless of placement). 53 ;* : By using CALL and #JUMP (or default -J+ command line option), the 54 ;* : assembler will automatically adjust between CALL and JSR 55 ;* : depending on the current #MMU mode. 56 ;* : 57 ;* : To use the *-bit version of each CALL, use these symbols: 58 ;* : 59 ;* : StackAdd*, StackSub*, StackMul*, StackDiv*, StackMod* 60 ;* : StackSwap*, StackNegate*, StackLoad*, StackSave*, 61 ;* : Stack*ToASCIZ 62 ;* : 63 ;* : replacing * with one of these: 16, 24, 32, 40, 48, 56, or 64. 64 ;* : 65 ;* : Various macros allow using these routines in a variety of ways, 66 ;* : and without worrying about the details of call & parameter setup. 67 ;* : These macros are: Add*, Sub*, Mul*, Div*, Mod*, DivS*, ModS*, 68 ;* : Neg*, Load*, Save*, Str*, StrS*, and Swap* (where the * is 16, 69 ;* : 24, 32, 40, 48, 56, or 64 depending on the version you want to use). 70 ;* : The signed versions are enabled only when the module is assembled 71 ;* : with the SIGNED conditional. 72 ;* : 73 ;* : If working with fixed-address variables, you can use the various 74 ;* : macros (such as Add32, Mul64, etc.) to perform operations in the 75 ;* : easiest possible way, such as: 76 ;* : @Mul32 A,B,Answer 77 ;* : (which multiplies A with B and stores the product in Answer). 78 ;* : But, you may also use the macros to work directly on stack, or to 79 ;* : temporarily save partial results on stack instead of fixed vars. 80 ;* : 81 ;* : I N G E N E R A L T H E N 82 ;* : 83 ;* : @Operation A,B,Answer works with A and B storing result in Answer 84 ;* : @Operation A,B works with A and B leaving result on stack 85 ;* : @Operation A works with TOS and A, result left as TOS 86 ;* : @Operation (no parms) works w/ TOS and [TOS+1], result as new TOS 87 ;* : 88 ;* : (Please note the shown order of the operation may be important.) 89 ;* : 90 ;* : Finally, the Load* (* = 16, 24, 32, 40, 48, 56, 64) operation can 91 ;* : directly load either a variable or a constant (leading #) on the 92 ;* : stack. 93 ;* : 94 ;* : Since v7.00, a HLL-like interface is possible by using the new 95 ;* : Eval* macro (where * = 8, 16, 24, 32, 40, 48, 56, 64) 96 ;* : This is by far the easiest way to use this library, as it closely 97 ;* : resembles using expressions in a HLL compiler. It also can 98 ;* : automatically resize stack after loading from and before saving 99 ;* : to any variable. 100 ;* : 101 ;* : Examine the test section of this file for examples of macro use. 102 ;* : 103 ;* : All routines are re-entrant and work on either the top-of-stack 104 ;* : (TOS) number alone or the two top-most TOS numbers. Similar to 105 ;* : how Reverse Polish Notation (RPN) works. First, you stack the 106 ;* : operand(s) and then call the corresponding routine to perform the 107 ;* : operation. 108 ;* : 109 ;* : The result of any operation is always the updated top of stack. 110 ;* : For operations that require two operands and produce a single 111 ;* : result, the result replaces the two operands (stack is reduced). 112 ;* : 113 ;* : Chain calculations are possible by pushing only the new operand 114 ;* : between operations. Alternatively, one can push all operands in 115 ;* : advance but it's not recommended as stack space may be limited. 116 ;* : When done evaluating an expression, just pull the final 32-bit 117 ;* : result from the stack. 118 ;* : 119 ;* : The TOS is the first (or only) operand of any operation. 120 ;* : This is important, for example, for subtraction and division. 121 ;* : 122 ;* : If the current order of the stack is not as you want it, use the 123 ;* : Swap (StackSwap32) operation to change it. 124 ;* : 125 ;* : All operands and results are exactly 32-bit wide. Overflows are 126 ;* : simply truncated. The lower 32-bit number is valid, though. 127 ;* : 128 ;* : (All references to 32-bit become 16-bit, when MATHSIZE = 16) 129 ;* : (All references to 32-bit become 24-bit, when MATHSIZE = 24) 130 ;* : (All references to 32-bit become 40-bit, when MATHSIZE = 40) 131 ;* : (All references to 32-bit become 48-bit, when MATHSIZE = 48) 132 ;* : (All references to 32-bit become 56-bit, when MATHSIZE = 56) 133 ;* : (All references to 32-bit become 64-bit, when MATHSIZE = 64) 134 ;* : 135 ;* : 64/56/48/40-bit multiplication is done using the shift-add method, 136 ;* : which is much shorter in size for such long operands, but it is 137 ;* : also significantly slower in speed. I opted for size optimization 138 ;* : because the 64/56/48/40-bit versions are not used quite as often. 139 ;* : You may want to re-write it for speed optimization by using the 140 ;* : MUL instruction like it is done for the default 32-bit case. 141 ;* : 142 ;* History : 09.05.22 v1.00 Original (Started on 2009.05.07) 143 ;* : 09.06.04 Optimized by using HX instead of SP, where needed 144 ;* : 09.11.04 Minor optimizations 145 ;* : 09.11.05 Add & Subtract now adjust Carry accordingly 146 ;* : Division by zero error now checked first 147 ;* : 09.11.06 v1.01 Added conditional MATHSIZE for use w/ 16-bit words 148 ;* : 09.11.08 v1.02 Added "Load" operation to ease stack loading 149 ;* : 09.11.11 Use of new LONG pseudo-opcode 150 ;* : 09.12.05 Added cycles display using :cycles 151 ;* : 10.01.06 v1.03 Added MMU auto-support (using :AB internal symbol) 152 ;* : Code is no longer placed in #ROM by default 153 ;* : The few JMPs in the code use [[ to trim possible page 154 ;* : 10.01.08 [[ removed from JMPs (latest ASM8 auto-correction) 155 ;* : 10.01.22 v1.04 Added Save operation for completeness 156 ;* : 10.01.23 v1.05 Added #SP directive examples (latest ASM8) 157 ;* : 10.01.29 v1.06 Added shorter/faster Swap version for 9S08 MCUs 158 ;* : 10.02.01 v1.07 Added #SPAUTO directive 159 ;* : 10.02.04 Added #X directive 160 ;* : 10.02.06 v2.00 Added signed math wrapper calls only for DIV & MOD 161 ;* : (Addition, Subtraction, and Multiplication calls 162 ;* : work either for unsigned or signed operands.) 163 ;* : Signed routines enabled w/ SIGNED conditional. 164 ;* : Division by zero error now reduces stack (operand 165 ;* : A removed) so that the stack is left with same 166 ;* : size on either success or failure (in which case 167 ;* : the TOS result is invalid.) 168 ;* : 10.02.08 v2.01 Fixed signed MOD for correct sign (sign of A) 169 ;* : 10.02.14 v2.10 Added Stack32ToASCIZ and prerequisite StringInsertChar 170 ;* : 10.02.28 v2.11 Minor optimization in StringInsertChar 171 ;* : 10.03.23 Made use of :: internal variable (Build 2010/03/23) 172 ;* : 10.03.30 v2.12 Allowed for HC08 compilation in newer code (?ToStr) 173 ;* : Optimized 9S08 Swap version for size and speed 174 ;* : v2.13 Optimized Negate for size and speed 175 ;* : 10.05.08 v3.00 Added MATHSIZE = 64 option for 64-bit math 176 ;* : Swap operation optimized only for size 177 ;* : 10.05.13 v3.01 Optimized for size and speed by using ,SPX 178 ;* : 10.06.02 v4.00 Added macros for easier use 179 ;* : 10.06.08 v4.10 Improved macros and added new ones (eg Const32) 180 ;* : 10.06.23 v4.20 Added MATHSIZE = 48 option for 48-bit math 181 ;* : 10.06.30 v4.30 Added AddDecimalPoint (to string number) 182 ;* : 10.07.01 v4.40 Added IFSPAUTO conditional 183 ;* : 10.07.03 Moved the functionality of Const macros into Load 184 ;* : 10.07.07 Moved general string routines first 185 ;* : 10.07.17 v4.50 Str* macros may use TOS (if Number parm is missing) 186 ;* : or current HX index (if result pointer is missing) 187 ;* : 10.07.20 _DoLoad*/_DoSave* address now allows for indexed mode 188 ;* : 10.07.21 Minor optimizations; macros now latest ASM8 189 ;* : 10.07.23 Minor bug fix in macro _DoSave for no parm case 190 ;* : 10.08.18 Optimized by using :MINDEX in latest ASM8 191 ;* : 10.08.26 Minor optimizations at the source level 192 ;* : 10.08.31 v4.60 Optimized Load* macros' immediate mode for zeros 193 ;* : 10.10.19 v4.61 Adapted to latest ASM8 (nested macros in Load) 194 ;* : 10.10.22 v4.62 Optimized _DoMath (Added @_DoOperation) 195 ;* : 10.10.26 v4.63 Load48 & Load64 now also accept single #Constant 196 ;* : 10.12.03 v4.64 Adapted to latest ASM8 => macros OK in @@ sub-mode 197 ;* : 11.03.31 v4.65 Moved test code at EOF (to use #EXIT optimization) 198 ;* : 11.04.10 v4.66 Condensed macro definitions (based on MATHSIZE) 199 ;* : 11.04.11 v4.67 Optimized MUL16/MUL32 size & cycles with ,SPX mode 200 ;* : 11.04.12 v4.70 Added MATHSIZE = 24 option for 24-bit math 201 ;* : 11.04.13 v4.71 Reversed some of v4.66's changes 202 ;* : 11.04.13 v4.80 Added MATHSIZE = 40 option for 40-bit math 203 ;* : 11.05.02 v4.81 Save protects HX (it was lost during SP => SPX) 204 ;* : 11.05.05 v4.82 Optimized StringLength by a byte (by using NEGA on exit) 205 ;* : 11.05.25 v4.83 Removed unused Zero constant from test code 206 ;* : 11.10.13 v4.84 Optimized MUL16/24/32 size w/ more ,SPX (same cycles) 207 ;* : 11.11.15 v4.85 Improved StringLength macro 208 ;* : 12.01.26 Changed test code a bit 209 ;* : 12.02.06 v4.86 Optimized SP => SPX at ?RemoveAndReturn 210 ;* : 12.03.05 v4.87 Added ResizeTOS to adjust TOS element's size 211 ;* : 12.05.09 v4.88 Added CCR[C] parameter to ResizeTOS for unsigned operation 212 ;* (signed is default when SIGNED conditional is defined, 213 ;* unsigned operation is default, otherwise) 214 ;* : 12.05.18 v4.89 Removed redundant subtraction in Division (at NotEqual@@) 215 ;* : 12.10.07 v4.90 Load*/Save* now accept indexed mode without separator override 216 ;* : 12.10.10 v5.00 Renamed to (more general) STAKMATH.SUB to use 217 ;* : wrapper files for each bit version, instead. 218 ;* : 12.11.05 Added _STKMTH{MATHSIZE}_ for used-version control 219 ;* : 12.11.09 v6.00 New _LoadStkMthVarAddr macro eases parm address 220 ;* : calculation. 221 ;* : W A R N I N G: SP-based operands now refer to the actual number, 222 ;* : W A R N I N G: and not its address (as was the case before). 223 ;* : W A R N I N G: This is INCOMPATIBLE with previous behavior. Code 224 ;* : W A R N I N G: written for version v5.00 or earlier that uses SP 225 ;* : W A R N I N G: based operands should be modified to refer to the 226 ;* : W A R N I N G: actual value and not to a pointer to the value. 227 ;* : W A R N I N G: Dot-beginning names are still treated as pointers! 228 ;* : 12.11.10 Use COMMON.INC/LEA instead of _LoadStkMthVarAddr 229 ;* : 12.12.04 v6.10 Optimized division just a tad by combining steps 230 ;* : 12.12.12 v6.20 Now use LEA macro inside _DoStr (for ResultString) 231 ;* : 12.12.20 v6.21 Minor optimization (one byte) in 32-bit ?Multiply 232 ;* : (Further 3-byte optimization possible by 233 ;* : re-ordering MULs, but not done for code clarity) 234 ;* : 13.01.09 v6.22 Added Copy* macros to combine Load*/Save* into one 235 ;* : 13.03.20 v7.00 Added Eval* and supporting macros for HLL-like 236 ;* : computations, eg., ans=(a+3)*((1+var,sp)/2) 237 ;* : (with or without spaces between operands/operators) 238 ;* : 13.03.27 v7.50 SIGNED now gives just signed (not unsigned) version 239 ;* : DivS*, ModS*, StrS* macros were removed, and also 240 ;* : ResizeTOS macro's unsigned flag has been removed 241 ;* : BugFix: AddDecimalPoint now prepends zeros after sign 242 ;* : 13.03.27 Optimized ?Negate in SIGNED case to use ?NegX sub 243 ;* : 13.03.27 v7.60 Adapted _EVAL_ macro to latest ASM8 (Much faster!) 244 ;* : 13.04.04 v7.70 _DoLoad and _DoSave macros now auto-adjust the size 245 ;* : so you can use with operands of different sizes, even 246 ;* : if the respective bitsize version isn't loaded. 247 ;* : 13.04.04 v7.71 _Eval_ macro leaves assignment result on TOS if 248 ;* : assignment variable not already defined. Then, 249 ;* : it gives TOS the specified name, if SP-indexed. 250 ;* : 13.04.05 v7.72 Added #size for v7.71 change 251 ;* : Named constants (labels with size zero) now use 252 ;* : immediate mode in Eval/Load 253 ;* : 13.04.05 v7.73 Added NEG() negate, and ABS() absolute functions 254 ;* : in Eval macro, e.g., ans = abs(a - b) 255 ;* : 13.04.09 v7.80 BugFix: Push/Pull macro calls for SP mode 256 ;* : Moved immediate mode to _DoLoad (unified method) 257 ;* : (Over 32-bit immediate value loads not possible 258 ;* : via macros) 259 ;* : 13.04.10 Adapted to v9.35 (no functional changes) 260 ;* : 13.04.11 v7.81 Optimized _DoLoad constant loading by using CLRH 261 ;* : (optimization is evident on certain cases only) 262 ;* : 13.04.15 v7.82 Added _?SEI_ and _?CLI_ macros for multitasker 263 ;* : locking / unlocking of multi-byte variables while 264 ;* : loading / saving (_DoLoad/_DoSave). Under OS8 it 265 ;* : is enabled automatically. Otherwise, simply 266 ;* : define _MTOS_ anytime before including this file. 267 ;* : For keeping code dense, all Eval*/Load*/Save* 268 ;* : macros are assumed to be called only while 269 ;* : interrupts are enabled, so it will not restore to 270 ;* : previous state but always leave as enabled. 271 ;* : Define _NOCLI_ (before including this module) for 272 ;* : canceling the _?SEI_ and _?CLI_ macro effects. 273 ;* : 13.04.18 v7.85 Added 'NeedMath' and 'Eval' general-purpose macros 274 ;* : for automatic selection of needed bit-size based 275 ;* : on only which modules are already included. First, 276 ;* : call the NeedMath macro to define the minimum math 277 ;* : bit-size you need for the next calculation(s), 278 ;* : then call the Eval macro as many times as needed 279 ;* : to perform the actual expression evaluation(s). 280 ;* : Similary, added new macros Load, Save, StkAdd, 281 ;* : StkSub, StkMul, StkDiv, StkMod, StkSwap, StkNeg, 282 ;* : StkAbs, StkStr, and CopyMath to work with the 283 ;* : NeedMath macro, just like the new Eval macro. 284 ;* : 13.04.19 v8.00 Moved all Eval* macros into COMMON.INC and allowed 285 ;* : for all to be active at all times, regardless if 286 ;* : the related bit-version of STAKMATH is included. 287 ;* : The _Eval_ macro was improved to allow it to 288 ;* : automatically locate the next higher version that 289 ;* : is included, if the one requested is not. So, 290 ;* : using Eval32 will use the 32/40/48/64-bit version 291 ;* : (whichever is closer to 32 and included) but nothing 292 ;* : below 32-bit. This allows you to use the relevant 293 ;* : macro based on a specific expression's requirements 294 ;* : but include only one (or just a few) higher bit 295 ;* : version(s), not all those referenced in your code. 296 ;* : (The general Eval is still available, if needed.) 297 ;* : Also, moved all Str* to COMMON.INC 298 ;* : 13.04.21 v8.10 Corrected v8.00 for pointer cases (.num) to use 299 ;* : actual requested size, not next higher. 300 ;* : Relevant #Message now in _DoOperation _ResizeTOS etc. 301 ;* : 13.04.21 v8.11 NeedMath & related macros removed (now redundant) 302 ;* : General Eval macro will try to determine best bit-size 303 ;* : 13.04.23 v8.12 Added EvalS to first check for SIGNED and then call Eval 304 ;* : CopyMath removed. Use "Eval to_var = from_var" instead 305 ;* : _StkMthMax_ improved to use higher size on multiplication 306 ;* : 13.04.25 v8.13 _Eval_ now allows for string constants (eg., @Eval ans = ans + '0') 307 ;* : Removed all ?macros because we now use COMMON xxx.s macros 308 ;* : 13.04.26 v8.15 Corrected test code for Eval when MATHSIZE < 32 309 ;* : Commented out auto-higher bit-size (a bit annoying). 310 ;* : Use Eval* to say 'no less than', instead. 311 ;* : 13.04.27 v8.16 BugFix: StrMath macro (2nd parameter was lost) 312 ;* : Added SQR() function to get the square 313 ;* : 13.05.02 Added #size in ToInt* macros (in test code) 314 ;* : 13.05.03 v8.17 Added size optimization for ADD and SUB operations 315 ;* : New SPEED_SIZE constant in COMMON.INC tells us 316 ;* : whether we need speed (SPEED_SIZE = 1) or 317 ;* : size (SPEED_SIZE = 2) optimization, the current 318 ;* : default being SPEED_SIZE = 2 for size optimization. 319 ;* : 13.05.30 Updated StrMath macro (COMMON.INC and here) 320 ;* : 13.06.04 v8.20 Added bit functions: AND (&), OR (|), XOR (^), and shifts (< and >) 321 ;* : 13.06.05 v8.21 BugFix: ShiftRight now uses ASR if SIGNED 322 ;* : 13.07.25 v8.22 Improved _Eval_ macro (and Push/Pull in COMMON.INC) 323 ;* : BugFix: Added { } to ResizeTOS macro's final case 324 ;* : (Disable bit functions with NO_BIT_OPS conditional) 325 ;* : 13.10.06 Minor changes in test code 326 ;* : 13.11.26 Added warning in _DoLoad: forwards treated as vars 327 ;* : 13.11.29 v8.23 Optimized ?ShiftLeft and ?ShiftRight a bit 328 ;* : 13.12.22 v8.30 Added 56-bit version 329 ;* : 14.01.03 Made use of _CMP_.S macro (instead of custom macro) 330 ;* : 14.02.07 v8.50 Added [ ... ] unsigned override (if SIGNED) 331 ;* : 14.02.14 v8.51 Eval macro now uses #HideMacros 332 ;* : 14.10.14 v8.52 BugFix: Off-by-one error in ResizeTOS when SIGNED 333 ;* : 15.03.21 v8.53 Replaced string dependencies with corresponding #Uses 334 ;* : 15.04.08 v8.54 Replaced AddDecimalPoint with corresponding #Uses 335 ;* : 17.04.03 v8.55 Optimized 24-bit multiply [-2 bytes] 336 ;* : Optimized 32-bit multiply [-7 bytes] 337 ;* : 18.10.23 Suppressed possible warning from JEQ in ?DivStart 338 ;* : 19.03.04 Added warning in _DoStr macro when using StrNN 339 ;* : when NN is different from MATHSIZE and no explicit 340 ;* : variable is given 341 ;* : 19.10.04 v8.56 Minor HC08 mode optimization in SIGNED ?ToStr [-1 byte] 342 ;* : 20.02.12 v8.57 Replaced #Message with @Msg to silence debugging messages 343 ;******************************************************************************* 344 345 ;Synopsis (replace * with 16, 24, 32, 40, 48, 56, 64 for corresponding bit version): 346 ; 347 ;Subroutines Action 348 ;-------------- ---------------------------- 349 ;StackAdd* - TOS := TOS + [TOS+1] (signed or unsigned) [TOS+1] removed 350 ;StackSub* - TOS := TOS - [TOS+1] (signed or unsigned) [TOS+1] removed 351 ;StackMul* - TOS := TOS * [TOS+1] (signed or unsigned) [TOS+1] removed 352 ;StackDiv* - TOS := TOS / [TOS+1] (signed if SIGNED) [TOS+1] removed 353 ;StackMod* - TOS := TOS \ [TOS+1] (signed if SIGNED) [TOS+1] removed 354 ;StackAnd* - TOS := TOS & [TOS+1] (signed or unsigned) [TOS+1] removed 355 ;StackOr* - TOS := TOS | [TOS+1] (signed or unsigned) [TOS+1] removed 356 ;StackXor* - TOS := TOS ^ [TOS+1] (signed or unsigned) [TOS+1] removed 357 ;StackShl* - TOS := TOS < [TOS+1] (signed or unsigned) [TOS+1] removed 358 ;StackShr* - TOS := TOS > [TOS+1] (signed if SIGNED) [TOS+1] removed 359 ;StackSwap* - TOS swapped with [TOS+1] (signed or unsigned) 360 ;StackAbs* - TOS := ABS(TOS) (signed) 361 ;StackNegate* - TOS := -TOS (signed) 362 ;StackLoad* - Load const/variable to TOS (signed or unsigned) TOS created 363 ;StackSave* - Save TOS into variable (signed or unsigned) TOS removed 364 ;ResizeTOS - Adjust TOS old size to new (signed or unsigned) TOS resized 365 ;Stack*ToASCIZ - Convert TOS to ASCIZ str (signed if SIGNED) 366 ; 367 ;Macros Purpose Parameters ([...] means optional part) 368 ;------------------ ------------------- ---------------------------------------- 369 ;Load* Stack const or var #Number | Variable 370 ;Save* Unstack a variable Variable 371 ;Copy* Load* & Save* #Number | Variable,Variable 372 ;ResizeTOS Resize TOS #FromByteSize,#ToByteSize 373 ; 374 ;Add* Addition [Addend[,Adder[,Sum]]] 375 ;Sub* Subtraction [Minuend[,Subtrahend[,Difference]]] 376 ;Mul* Multiplication [Multiplicand[,Multiplier[,Product]]] 377 ;Div* Unsigned division [Dividend[,Divisor[,Quotient]]] 378 ;Mod* Unsigned modulo [Dividend[,Divisor[,Remainder]]] 379 ;Abs* Absolute value [SourceVariable][,DestinationVariable] 380 ;Neg* Negation [SourceVariable][,DestinationVariable] 381 ;Swap* Swap TOS numbers 382 ;Str* Number to ASCIZ [Variable],[ResultString] 383 ;AddDecimalPoint ... to ASCIZ number [[#]DecimalPlaces[,[#]ASCIZ_String]] 384 411 412 0010 MATHSIZE def 32 ;default wordsize is 32-bit 413 417 418 ? macro BitSize 419 #if MATHSIZE = ~1~ 420 ?WORD equ ~1~/8 421 _STKMTH{MATHSIZE}_ ;;specific version included 422 _STAKMATH_ def * ;;any version included 423 #endif 424 endm 425 426 M @? 16 ;16-bit quantity (on request) 426 M 0002 ?WORD equ 16/8 426 M 1C92 _STKMTH16_ 426 M 182C _STAKMATH_ def * 426 endm 427 M @? 24 ;24-bit quantity (on request) 427 endm 428 M @? 32 ;32-bit quantity (default) 428 endm 429 M @? 40 ;40-bit quantity (on request) 429 endm 430 M @? 48 ;48-bit quantity (on request) 430 endm 431 M @? 56 ;56-bit quantity (on request) 431 endm 432 M @? 64 ;64-bit quantity (on request) 432 endm 433 439 #Message MATHSIZE = {MATHSIZE}-bit version 441 #Message Signed routines enabled 443 ;******************************************************************************* 444 ; Macros to make operations as simple as with a high-level language 445 ; In operations that require two operands and a result, if only one operand is 446 ; provided, then the operation is done completely on stack (no other variables 447 ; used). For example, @Add32 A,B,SUM adds A to B and places result in SUM, 448 ; while @Add32 A adds the current stack top to A and leaves result on stack. 449 ; You can use @Load* and @Save* to load the initial value, and store the final 450 ; result, respectively. (Replace * with 16, 24, 32, 40, 48, 56, or 64) 451 ;******************************************************************************* 452 454 455 Load16 macro #Number|Variable ;load constant or variable 456 @_DoLoad ~0.{:0-1}~\,~@~ 457 endm 458 459 Save16 macro Address 460 @_DoSave 16\,~@~ 461 endm 462 463 Copy16 macro #Constant|Variable,ToAddress 464 mreq 1,2:#Constant|Variable,ToAddress 465 @@Load16 ~1~ 466 @Save16 ~2~ 467 endm 468 469 Swap16 macro 470 @_DoSwap 16 471 endm 472 473 Add16 macro Addend,Adder,Sum 474 @_DoMath ~0~\,16\,~1~\,~2~\,~3~ 475 endm 476 477 Sub16 macro Minuend,Subtrahend,Difference 478 @_DoMath ~0~\,16\,~1~\,~2~\,~3~ 479 endm 480 481 Mul16 macro Multiplicand,Multiplier,Product 482 @_DoMath ~0~\,16\,~1~\,~2~\,~3~ 483 endm 484 485 Div16 macro Dividend,Divisor,Quotient 486 @_DoMath ~0~\,16\,~1~\,~2~\,~3~ 487 endm 488 489 Mod16 macro Dividend,Divisor,Remainder 490 @_DoMath ~0~\,16\,~1~\,~2~\,~3~ 491 endm 492 493 Abs16 macro Source[,Destination] 494 @_DoAbs 16\,~1~\,~2~ 495 endm 496 497 Neg16 macro Source[,Destination] 498 @_DoNeg 16\,~1~\,~2~ 499 endm 501 ;=============================================================================== 550 ;=============================================================================== 599 ;=============================================================================== 648 ;=============================================================================== 697 ;=============================================================================== 746 ;=============================================================================== 795 796 ;******************************************************************************* 797 ; Common macro(s) for all operations defined above (not to be called directly) 798 ;******************************************************************************* 799 807 ;------------------------------------------------------------------------------- 867 ;------------------------------------------------------------------------------- 890 ;------------------------------------------------------------------------------- 898 ;------------------------------------------------------------------------------- 916 ;=============================================================================== 933 ;------------------------------------------------------------------------------- 1158 ;------------------------------------------------------------------------------- 1185 ;------------------------------------------------------------------------------- 1212 ;------------------------------------------------------------------------------- 1288 ;------------------------------------------------------------------------------- 1328 ;------------------------------------------------------------------------------- 1337 ;------------------------------------------------------------------------------- 1351 ;------------------------------------------------------------------------------- 1380 ;------------------------------------------------------------------------------- 1398 ;------------------------------------------------------------------------------- 1416 ;------------------------------------------------------------------------------- 1451 1452 ;******************************************************************************* 1453 ; External dependencies 1454 ;******************************************************************************* 1455 1456 #Uses string/length.sub 1457 #Uses string/insertchar.sub 1458 #Uses string/adddecimalpoint.sub 1459 1C92 ?_OBJECT_? 1460 ;******************************************************************************* 1461 ; One-based (SP-index) offsets to stacked operands (to be used with #SPAUTO :AB) 1462 ;******************************************************************************* 1463 1464 #temp 1 1465 0001 ?a next :temp,?WORD ;top-of-stack (TOS) number (N1) 1466 0003 ?b next :temp,?WORD ;number after TOS (N2) 1467 1468 #Cycles ;reset the cycles counter 1469 1470 ;******************************************************************************* 1471 ; Purpose: Add N1 to N2 and place result on top-of-stack. N1 & N2 removed 1472 ; Input : [TOS+?WORD] = Number2 1473 ; : [TOS] = Number1 1474 ; Output : [TOS] = Result 1475 ; Note(s): Carry Set on overflow 1476 1477 #spauto :ab 1478 1479 1C92 ?Add proc 1480 [1C92] 1C92:8789 8B [ 6] push 1481 [1C95] 1C95:95 [ 2] tsx 1482 1484 M @add.s ?a,spx ?b,spx ?b,spx 1484 M mset #' ' 1484 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1484 M @@_samesize_ ?a,spx ?b,spx ?b,spx 1484 M mreq 1,2:Operand1,Operand2[,Operand]* 1484 M mset 0 1484 M mdo 1484 M mswap 1,1 1484 M @@_nosize_ ?a,spx 1484 M mset # 1484 M mset 0,mstop [_samesize_] No size (?a,spx) 1484 M endm 1484 M mset 0,?a,spx 1484 M mloop :n 1484 M mswap 1,2 1484 M @@_nosize_ ?b,spx 1484 M mset # 1484 M mset 0,mstop [_samesize_] No size (?b,spx) 1484 M endm 1484 M mloop :n 1484 M mswap 1,3 1484 M @@_nosize_ ?b,spx 1484 M mset # 1484 M mset 0,mstop [_samesize_] No size (?b,spx) 1484 M endm 1484 M mloop :n 1484 M endm 1484 M mset 0,@@add.b, 1484 M mdo 1484 M mset 0,@@add.b, ?a+1,spx 1484 M mset 0,@@add.b, ?a+1,spx ?b+1,spx 1484 M mset 0,@@add.b, ?a+1,spx ?b+1,spx ?b+1,spx 1484 M @@add.b, ?a+1,spx ?b+1,spx ?b+1,spx 1484 M mswap 1,2 1484 M mswap 1,2 1484 M [1C96] 1C96:E606 [ 3] lda ?a+1,spx 1484 M [1C98] 1C98:EB08 [ 3] add ?b+1,spx 1484 M @_sta_ ?b+1,spx 1484 M [1C9A] 1C9A:E708 [ 3] sta ?b+1,spx 1484 M endm 1484 M mset 0,@@adc.b, 1484 M mloop ::?b 1484 M mset 0,@@adc.b, ?a+0,spx 1484 M mset 0,@@adc.b, ?a+0,spx ?b+0,spx 1484 M mset 0,@@adc.b, ?a+0,spx ?b+0,spx ?b+0,spx 1484 M @@adc.b, ?a+0,spx ?b+0,spx ?b+0,spx 1484 M mswap 1,2 1484 M mswap 1,2 1484 M [1C9C] 1C9C:E605 [ 3] lda ?a+0,spx 1484 M [1C9E] 1C9E:E907 [ 3] adc ?b+0,spx 1484 M @_sta_ ?b+0,spx 1484 M [1CA0] 1CA0:E707 [ 3] sta ?b+0,spx 1484 M endm 1484 M mset 0,@@adc.b, 1484 M mloop ::?b 1484 endm 1500 [1CA2] 1CA2:CC1E 67 [ 4] jmp ?RemoveAndReturn 1501 1502 001E ?AddCycles equ :cycles 1503 1504 ;******************************************************************************* 1505 ; Purpose: Subtract N2 from N1 and place result on top-of-stack. N1 & N2 removed 1506 ; Input : [TOS+?WORD] = Number2 1507 ; : [TOS] = Number1 1508 ; Output : [TOS] = Result 1509 ; Note(s): Carry Set on borrow 1510 1511 #spauto :ab 1512 1513 1CA5 ?Subtract proc 1514 [1CA5] 1CA5:8789 8B [ 6] push 1515 [1CA8] 1CA8:95 [ 2] tsx 1517 M @sub.s ?a,spx ?b,spx ?b,spx 1517 M mset #' ' 1517 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 1517 M @@_samesize_ ?a,spx ?b,spx ?b,spx 1517 M mreq 1,2:Operand1,Operand2[,Operand]* 1517 M mset 0 1517 M mdo 1517 M mswap 1,1 1517 M @@_nosize_ ?a,spx 1517 M mset # 1517 M mset 0,mstop [_samesize_] No size (?a,spx) 1517 M endm 1517 M mset 0,?a,spx 1517 M mloop :n 1517 M mswap 1,2 1517 M @@_nosize_ ?b,spx 1517 M mset # 1517 M mset 0,mstop [_samesize_] No size (?b,spx) 1517 M endm 1517 M mloop :n 1517 M mswap 1,3 1517 M @@_nosize_ ?b,spx 1517 M mset # 1517 M mset 0,mstop [_samesize_] No size (?b,spx) 1517 M endm 1517 M mloop :n 1517 M endm 1517 M #temp 1517 M @@_nosize_ ?b,spx 1517 M mset # 1517 M mset 0,mstop [sub.s] No size (?b,spx) 1517 M endm 1517 M #temp ::?b 1517 M mset 0,sub 1517 M mdo 1517 M [1CA9] 1CA9:E606 [ 3] lda ?a+1,spx 1517 M [1CAB] 1CAB:E008 [ 3] sub ?b+1,spx 1517 M [1CAD] 1CAD:E708 [ 3] sta ?b+1,spx 1517 M mset 0,sbc 1517 M mloop :temp 1517 M [1CAF] 1CAF:E605 [ 3] lda ?a+0,spx 1517 M [1CB1] 1CB1:E207 [ 3] sbc ?b+0,spx 1517 M [1CB3] 1CB3:E707 [ 3] sta ?b+0,spx 1517 M mset 0,sbc 1517 M mloop :temp 1517 endm 1533 [1CB5] 1CB5:CC1E 67 [ 4] jmp ?RemoveAndReturn 1534 1535 001E ?SubCycles equ :cycles 1536 1540 M @Msg Bit ops enabled (define NO_BIT_OPS to disable) 1540 mexit 1541 ;******************************************************************************* 1542 ; Purpose: AND N1 with N2 and place result on top-of-stack. N1 & N2 removed 1543 ; Input : [TOS+?WORD] = Number2 1544 ; : [TOS] = Number1 1545 ; Output : [TOS] = Result 1546 ; Note(s): 1547 #spauto :ab 1548 1549 1CB8 ?BitAnd proc 1550 [1CB8] 1CB8:8789 8B [ 6] push 1551 [1CBB] 1CBB:95 [ 2] tsx 1552 1554 M @and.s ?a,spx ?b,spx ?b,spx 1554 M mset #' ' 1554 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1554 M @@_samesize_ ?a,spx ?b,spx ?b,spx 1554 M mreq 1,2:Operand1,Operand2[,Operand]* 1554 M mset 0 1554 M mdo 1554 M mswap 1,1 1554 M @@_nosize_ ?a,spx 1554 M mset # 1554 M mset 0,mstop [_samesize_] No size (?a,spx) 1554 M endm 1554 M mset 0,?a,spx 1554 M mloop :n 1554 M mswap 1,2 1554 M @@_nosize_ ?b,spx 1554 M mset # 1554 M mset 0,mstop [_samesize_] No size (?b,spx) 1554 M endm 1554 M mloop :n 1554 M mswap 1,3 1554 M @@_nosize_ ?b,spx 1554 M mset # 1554 M mset 0,mstop [_samesize_] No size (?b,spx) 1554 M endm 1554 M mloop :n 1554 M endm 1554 M mdo 1554 M [1CBC] 1CBC:E605 [ 3] lda ?a+0,spx 1554 M [1CBE] 1CBE:E407 [ 3] and ?b+0,spx 1554 M [1CC0] 1CC0:E707 [ 3] sta ?b+0,spx 1554 M mloop ::?b 1554 M [1CC2] 1CC2:E606 [ 3] lda ?a+1,spx 1554 M [1CC4] 1CC4:E408 [ 3] and ?b+1,spx 1554 M [1CC6] 1CC6:E708 [ 3] sta ?b+1,spx 1554 M mloop ::?b 1554 endm 1569 [1CC8] 1CC8:CC1E 67 [ 4] jmp ?RemoveAndReturn 1570 1571 001E ?AndCycles equ :cycles 1572 1573 ;******************************************************************************* 1574 ; Purpose: OR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1575 ; Input : [TOS+?WORD] = Number2 1576 ; : [TOS] = Number1 1577 ; Output : [TOS] = Result 1578 ; Note(s): 1579 #spauto :ab 1580 1581 1CCB ?BitOr proc 1582 [1CCB] 1CCB:8789 8B [ 6] push 1583 [1CCE] 1CCE:95 [ 2] tsx 1584 1586 M @ora.s ?a,spx ?b,spx ?b,spx 1586 M mset #' ' 1586 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1586 M @@_samesize_ ?a,spx ?b,spx ?b,spx 1586 M mreq 1,2:Operand1,Operand2[,Operand]* 1586 M mset 0 1586 M mdo 1586 M mswap 1,1 1586 M @@_nosize_ ?a,spx 1586 M mset # 1586 M mset 0,mstop [_samesize_] No size (?a,spx) 1586 M endm 1586 M mset 0,?a,spx 1586 M mloop :n 1586 M mswap 1,2 1586 M @@_nosize_ ?b,spx 1586 M mset # 1586 M mset 0,mstop [_samesize_] No size (?b,spx) 1586 M endm 1586 M mloop :n 1586 M mswap 1,3 1586 M @@_nosize_ ?b,spx 1586 M mset # 1586 M mset 0,mstop [_samesize_] No size (?b,spx) 1586 M endm 1586 M mloop :n 1586 M endm 1586 M mdo 1586 M [1CCF] 1CCF:E605 [ 3] lda ?a+0,spx 1586 M [1CD1] 1CD1:EA07 [ 3] ora ?b+0,spx 1586 M [1CD3] 1CD3:E707 [ 3] sta ?b+0,spx 1586 M mloop ::?b 1586 M [1CD5] 1CD5:E606 [ 3] lda ?a+1,spx 1586 M [1CD7] 1CD7:EA08 [ 3] ora ?b+1,spx 1586 M [1CD9] 1CD9:E708 [ 3] sta ?b+1,spx 1586 M mloop ::?b 1586 endm 1601 [1CDB] 1CDB:CC1E 67 [ 4] jmp ?RemoveAndReturn 1602 1603 001E ?OrCycles equ :cycles 1604 1605 ;******************************************************************************* 1606 ; Purpose: XOR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1607 ; Input : [TOS+?WORD] = Number2 1608 ; : [TOS] = Number1 1609 ; Output : [TOS] = Result 1610 ; Note(s): 1611 #spauto :ab 1612 1613 1CDE ?BitXor proc 1614 [1CDE] 1CDE:8789 8B [ 6] push 1615 [1CE1] 1CE1:95 [ 2] tsx 1616 1618 M @eor.s ?a,spx ?b,spx ?b,spx 1618 M mset #' ' 1618 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1618 M @@_samesize_ ?a,spx ?b,spx ?b,spx 1618 M mreq 1,2:Operand1,Operand2[,Operand]* 1618 M mset 0 1618 M mdo 1618 M mswap 1,1 1618 M @@_nosize_ ?a,spx 1618 M mset # 1618 M mset 0,mstop [_samesize_] No size (?a,spx) 1618 M endm 1618 M mset 0,?a,spx 1618 M mloop :n 1618 M mswap 1,2 1618 M @@_nosize_ ?b,spx 1618 M mset # 1618 M mset 0,mstop [_samesize_] No size (?b,spx) 1618 M endm 1618 M mloop :n 1618 M mswap 1,3 1618 M @@_nosize_ ?b,spx 1618 M mset # 1618 M mset 0,mstop [_samesize_] No size (?b,spx) 1618 M endm 1618 M mloop :n 1618 M endm 1618 M mdo 1618 M [1CE2] 1CE2:E605 [ 3] lda ?a+0,spx 1618 M [1CE4] 1CE4:E807 [ 3] eor ?b+0,spx 1618 M [1CE6] 1CE6:E707 [ 3] sta ?b+0,spx 1618 M mloop ::?b 1618 M [1CE8] 1CE8:E606 [ 3] lda ?a+1,spx 1618 M [1CEA] 1CEA:E808 [ 3] eor ?b+1,spx 1618 M [1CEC] 1CEC:E708 [ 3] sta ?b+1,spx 1618 M mloop ::?b 1618 endm 1633 [1CEE] 1CEE:CC1E 67 [ 4] jmp ?RemoveAndReturn 1634 1635 001E ?EorCycles equ :cycles 1636 1637 ;******************************************************************************* 1638 ; Purpose: Shift N1 left N2 times and place result on top-of-stack. N1 & N2 removed 1639 ; Input : [TOS+?WORD] = Number2 1640 ; : [TOS] = Number1 1641 ; Output : [TOS] = Result 1642 ; Note(s): CCR[C] = last most significant bit shifted out 1643 ; : Only LSB of second operand (N2) is used, as shifting more than the 1644 ; : highest bit version always produces zero. Any non-zero bytes in the 1645 ; : N2 operand will cause a zero result, regardless. 1646 1647 #spauto :ab 1648 1649 1CF1 ?ShiftLeft proc 1650 [1CF1] 1CF1:8789 8B [ 6] push 1651 #ais 1652 1653 [1CF4] 1CF4:9EE6 09 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1654 [1CF7] 1CF7:87 [ 2] psha counter@@ 1655 1656 [1CF8] 1CF8:95 [ 2] tsx 1657 1658 [1CF9] 1CF9:6F09 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1659 0003 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1660 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1660 M mset # 1660 M mreq 1 1660 M @@_nosize_ b29,spx 1660 M mset # 1660 M mset 0,mstop [_tst_.s] No size (b29,spx) 1660 M endm 1660 M [1CFB] 1CFB:6D08 [ 4] tst b29,spx 1660 mexit 1661 [1CFD] 1CFD:2709 (1D08) [ 3] beq Go@@ ;if so, proceed normally 1662 1663 [1CFF] 1CFF:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1664 [1D00] 1D00:A110 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1665 [1D02] 1D02:2504 (1D08) [ 3] blo Go@@ ;else zero and exit 1666 1667 M @clr.s, b@@,spx ;else error, so zero result 1667 M mset #' ' 1667 M mreq 1 1667 M @@_nosize_ b29,spx 1667 M mset # 1667 M mset 0,mstop [clr.s] No size (b29,spx) 1667 M endm 1667 M mdef 2,::b29 1667 M mdo 1667 M [1D04] 1D04:6F08 [ 5] clr b29+0,spx 1667 M mloop ::b29 1667 endm 1668 [1D06] 1D06:200E (1D16) [ 3] bra Done@@ ;and get out 1669 1670 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1670 M mset #' ' 1670 M mreq 1,2:Source Destination 1670 M @@_samesize_ ?a,spx ?b,spx 1670 M mreq 1,2:Operand1,Operand2[,Operand]* 1670 M mset 0 1670 M mdo 1670 M mswap 1,1 1670 M @@_nosize_ ?a,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?a,spx) 1670 M endm 1670 M mset 0,?a,spx 1670 M mloop :n 1670 M mswap 1,2 1670 M @@_nosize_ ?b,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?b,spx) 1670 M endm 1670 M mloop :n 1670 M endm 1670 M mset 0 1670 M mdo 1670 M [1D08] 1D08:E606 [ 3] lda ?a+0,spx 1670 M [1D0A] 1D0A:E708 [ 3] sta ?b+0,spx 1670 M mloop ::?b 1670 M [1D0C] 1D0C:E607 [ 3] lda ?a+1,spx 1670 M [1D0E] 1D0E:E709 [ 3] sta ?b+1,spx 1670 M mloop ::?b 1670 endm 1671 #Cycles 1672 M Loop@@ @lsl.s, ?b,spx ;shift left one bit position 1672 M mset # 1672 M mreq 1 1672 M @@_nosize_ ?b,spx 1672 M mset # 1672 M mset 0,mstop [lsl.s] No size (?b,spx) 1672 M endm 1672 M mdo 1672 M [1D10] 1D10:6809 [ 5] lsl ?b+1,spx 1672 M mloop ::?b 1672 M [1D12] 1D12:6908 [ 5] rol ?b+0,spx 1672 M mloop ::?b 1672 endm 1673 [1D14] 1D14:7BFA (1D10) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1674 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1675 1D16 Done@@ 1677 [1D16] 1D16:86 [ 3] pula 1681 [1D17] 1D17:CC1E 67 [ 4] jmp ?RemoveAndReturn 1682 1683 012D ?ShlCycles equ :cycles 1684 1685 ;******************************************************************************* 1686 ; Purpose: Shift N1 right N2 times and place result on top-of-stack. N1 & N2 removed 1687 ; Input : [TOS+?WORD] = Number2 1688 ; : [TOS] = Number1 1689 ; Output : [TOS] = Result 1690 ; Note(s): CCR[C] = last least significant bit shifted out 1691 ; : Only LSB of second operand (N2) is used, as shifting more than the 1692 ; : highest bit version always produces zero. Any non-zero bytes in the 1693 ; : N2 operand will cause a zero result, regardless. 1694 1695 #spauto :ab 1696 1697 1D1A ?ShiftRight proc 1698 [1D1A] 1D1A:8789 8B [ 6] push 1699 #ais 1700 1701 [1D1D] 1D1D:9EE6 09 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1702 [1D20] 1D20:87 [ 2] psha counter@@ 1703 1704 [1D21] 1D21:95 [ 2] tsx 1705 1706 [1D22] 1D22:6F09 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1707 0003 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1708 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1708 M mset # 1708 M mreq 1 1708 M @@_nosize_ b30,spx 1708 M mset # 1708 M mset 0,mstop [_tst_.s] No size (b30,spx) 1708 M endm 1708 M [1D24] 1D24:6D08 [ 4] tst b30,spx 1708 mexit 1709 [1D26] 1D26:2709 (1D31) [ 3] beq Go@@ ;if so, proceed normally 1710 1711 [1D28] 1D28:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1712 [1D29] 1D29:A110 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1713 [1D2B] 1D2B:2504 (1D31) [ 3] blo Go@@ ;else zero and exit 1714 1715 M @clr.s, b@@,spx ;else error, so zero result 1715 M mset #' ' 1715 M mreq 1 1715 M @@_nosize_ b30,spx 1715 M mset # 1715 M mset 0,mstop [clr.s] No size (b30,spx) 1715 M endm 1715 M mdef 2,::b30 1715 M mdo 1715 M [1D2D] 1D2D:6F08 [ 5] clr b30+0,spx 1715 M mloop ::b30 1715 endm 1716 [1D2F] 1D2F:200E (1D3F) [ 3] bra Done@@ ;and get out 1717 1718 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1718 M mset #' ' 1718 M mreq 1,2:Source Destination 1718 M @@_samesize_ ?a,spx ?b,spx 1718 M mreq 1,2:Operand1,Operand2[,Operand]* 1718 M mset 0 1718 M mdo 1718 M mswap 1,1 1718 M @@_nosize_ ?a,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?a,spx) 1718 M endm 1718 M mset 0,?a,spx 1718 M mloop :n 1718 M mswap 1,2 1718 M @@_nosize_ ?b,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?b,spx) 1718 M endm 1718 M mloop :n 1718 M endm 1718 M mset 0 1718 M mdo 1718 M [1D31] 1D31:E606 [ 3] lda ?a+0,spx 1718 M [1D33] 1D33:E708 [ 3] sta ?b+0,spx 1718 M mloop ::?b 1718 M [1D35] 1D35:E607 [ 3] lda ?a+1,spx 1718 M [1D37] 1D37:E709 [ 3] sta ?b+1,spx 1718 M mloop ::?b 1718 endm 1719 #Cycles 1720 1D39 Loop@@ 1722 M @asr.s, ?b,spx ;shift right one bit position 1722 M mset # 1722 M mreq 1 1722 M @@_nosize_ ?b,spx 1722 M mset # 1722 M mset 0,mstop [asr.s] No size (?b,spx) 1722 M endm 1722 M mdo 1722 M [1D39] 1D39:6708 [ 5] asr ?b+0,spx 1722 M mloop ::?b 1722 M [1D3B] 1D3B:6609 [ 5] ror ?b+1,spx 1722 M mloop ::?b 1722 endm 1726 [1D3D] 1D3D:7BFA (1D39) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1727 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1728 1D3F Done@@ 1730 [1D3F] 1D3F:86 [ 3] pula 1734 [1D40] 1D40:CC1E 67 [ 4] jmp ?RemoveAndReturn 1735 1736 012D ?ShrCycles equ :cycles 1738 1739 ;******************************************************************************* 1740 ; Purpose: Multiply N1 with N2 and place result on top-of-stack. N1 & N2 removed 1741 ; Input : [TOS+?WORD] = Number2 1742 ; : [TOS] = Number1 1743 ; Output : [TOS] = Result 1744 ; Note(s): Overflows lost, Carry state should be ignored 1745 1746 #spauto :ab 1747 1748 1D43 ?Multiply proc 1749 [1D43] 1D43:8789 8B [ 6] push 1751 ;-------------------------------------- ;row 1 1752 [1D46] 1D46:95 [ 2] tsx 1753 [1D47] 1D47:E606 [ 3] lda ?a+1,spx 1754 [1D49] 1D49:EE08 [ 3] ldx ?b+1,spx 1755 [1D4B] 1D4B:42 [ 5] mul 1756 [1D4C] 1D4C:8789 [ 4] pshxa ans@@ ;temporary 16-bit result (2nd byte) 1757 1758 [1D4E] 1D4E:95 [ 2] tsx 1759 [1D4F] 1D4F:E608 [ 3] lda ?a+1,spx 1760 [1D51] 1D51:EE09 [ 3] ldx ?b+0,spx 1761 [1D53] 1D53:42 [ 5] mul 1762 [1D54] 1D54:95 [ 2] tsx 1763 [1D55] 1D55:FB [ 3] add ans@@,spx 1764 [1D56] 1D56:F7 [ 2] sta ans@@,spx 1765 ;-------------------------------------- ;row 2 1766 [1D57] 1D57:E607 [ 3] lda ?a+0,spx 1767 [1D59] 1D59:EE0A [ 3] ldx ?b+1,spx 1768 [1D5B] 1D5B:42 [ 5] mul 1769 [1D5C] 1D5C:95 [ 2] tsx 1770 [1D5D] 1D5D:FB [ 3] add ans@@,spx 1771 [1D5E] 1D5E:F7 [ 2] sta ans@@,spx 1773 ;=============================================================================== 1826 ;=============================================================================== 1913 #temp :cycles 1914 ;=============================================================================== 1915 ;-------------------------------------- 1916 ; 40, 48, 56, and 64-bit versions use shorter 1917 ; shift/add method (more cycles, though) 1918 ;-------------------------------------- 1945 ;-------------------------------------- 1946 ; copy result to B while removing from stack 1947 ;-------------------------------------- 1948 [1D5F] 1D5F:AE02 [ 2] ldx #?WORD 1949 #temp :cycles+:temp 1950 [1D61] 1D61:86 [ 3] CopyResult@@ pula 1951 [1D62] 1D62:9EE7 09 [ 4] sta ?b,sp 1952 [1D65] 1D65:5BFA (1D61) [ 4] dbnzx CopyResult@@ 1953 1954 #spadd 1-?WORD 1955 #temp :cycles*?WORD+:temp 1956 [1D67] 1D67:CC1E 67 [ 4] jmp ?RemoveAndReturn 1957 1958 0059 ?MulCycles equ :temp+:cycles 1959 1960 ;******************************************************************************* 1961 ; Purpose: Divide N1 by N2 and place quotient on top-of-stack. N1 & N2 removed 1962 ; Input : [TOS+?WORD] = Divisor (N2) 1963 ; : [TOS] = Dividend (N1) 1964 ; Output : [TOS] = Quotient 1965 ; : Carry Set on error (division by zero) 1966 ; Note(s): 1967 #spauto :ab 1968 1969 1D6A ?Divide proc 1970 [1D6A] 1D6A:8789 8B [ 6] push 1971 1972 [1D6D] 1D6D:A601 [ 2] lda #?DIVOP_ ;flag for DIV operation 1974 [1D6F] 1D6F:87 [ 2] psha 1975 [1D70] 1D70:95 [ 2] tsx 1976 [1D71] 1D71:E606 [ 3] lda ?a,spx 1977 [1D73] 1D73:E808 [ 3] eor ?b,spx 1978 [1D75] 1D75:86 [ 3] pula 1979 [1D76] 1D76:2A02 (1D7A) [ 3] bpl Skip@@ 1980 [1D78] 1D78:AA80 [ 2] ora #?SIGN_ ;flag for negative 1981 1D7A Skip@@ 1983 [1D7A] 1D7A:87 [ 2] psha ;save flags on stack 1984 [1D7B] 1D7B:201E (1D9B) [ 3] bra ?DivStart 1985 1986 001F ?DivCycles equ :cycles 1987 1988 ;******************************************************************************* 1989 ; Purpose: Divide N1 by N2 and place remainder on top-of-stack. N1 & N2 removed 1990 ; Input : [TOS+?WORD] = Divisor (N2) 1991 ; : [TOS] = Dividend (N1) 1992 ; Output : [TOS] = Remainder 1993 ; : Carry Set on error (division by zero) 1994 ; Note(s): 1995 #spauto :ab 1996 FFFFFFFF ?pc equ ::,:ab 1997 1998 1D7D ?Modulo proc 1999 [1D7D] 1D7D:8789 8B [ 6] push 2000 2001 [1D80] 1D80:4F [ 1] clra ;flag for MOD operation 2003 [1D81] 1D81:9E6D 06 [ 5] tst ?a,sp 2004 [1D84] 1D84:2A02 (1D88) [ 3] bpl Skip@@ 2005 [1D86] 1D86:AA80 [ 2] ora #?SIGN_ ;flag for negative 2006 1D88 Skip@@ 2008 [1D88] 1D88:87 [ 2] psha ;save flags on stack 2009 [1D89] 1D89:2010 (1D9B) [ 3] bra ?DivStart 2010 2011 0016 ?ModCycles equ :cycles 2012 2013 ;******************************************************************************* 2014 2015 #temp 2017 1D8B ?AbsX proc 2018 [1D8B] 1D8B:7D [ 3] tst ,ax 2019 [1D8C] 1D8C:2A06 (1D94) [ 3] bpl Done@@ 2020 #temp :cycles 2021 0000 var@@ equ 0,?WORD 2022 M ?NegX @neg.s var@@,ax 2022 M mset # 2022 M mreq 1 2022 M @@_nosize_ var34,ax 2022 M mset # 2022 M mset 0,mstop [neg.s] No size (var34,ax) 2022 M endm 2022 M mdo 2022 M [1D8E] 1D8E:73 [ 4] com var34+0,ax 2022 M mloop ::var34-1 2022 M [1D8F] 1D8F:6001 [ 5] neg var34+1,ax 2022 M mdo 2022 M [1D91] 1D91:2601 (1D94) [ 3] bne Done$$$ 2022 M [1D93] 1D93:7C [ 4] inc var34+0,ax 2022 M mloop ::var34-1 2022 M 1D94 Done$$$ 2022 endm 2023 [1D94] 1D94:81 [ 6] Done@@ rts 2024 2025 0016 ?AbsXCycles equ :cycles 2026 0010 ?NegxCycles equ ?AbsXCycles-:temp 2028 2029 ;******************************************************************************* 2030 2031 0000 ?SF equ 0 ;stack frame (for X-index use) 2032 2033 0000 ?quotient next ?SF,?WORD 2034 0002 ?remainder next ?SF,?WORD 2035 0004 ?temp next ?SF,?WORD 2036 0006 ?bits next ?SF 2037 0007 ?flags next ?SF 2038 2039 0001 ?DIVOP_ equ %00000001 ;1 = DIV, 0 = MOD 2040 0080 ?SIGN_ equ %10000000 ;result sign (1 = negative) 2041 2042 #push 2043 2044 [1D95] 1D95:A708 [ 2] ?DivError ais #?SF ;de-allocate temporaries 2045 [1D97] 1D97:99 [ 1] sec ;indicate error condition 2046 [1D98] 1D98:CC1E 67 [ 4] jmp ?RemoveAndReturn 2047 2048 #pull 2049 ;------------------------------------------------------------------------------- 2050 1D9B ?DivStart proc 2051 0001 dividend@@ equ ?a,::?a 2052 0003 divisor@@ equ ?b,::?b 2053 0003 ans@@ equ ?b,::?b ;result overwrites divisor 2054 2056 M @lea dividend@@,sp 2056 M mset # 2056 M [1D9B] 1D9B:95 [ 2] tsx 2056 M [1D9C] 1D9C:AF06 [ 2] !aix #dividend35+:tsx 2056 mexit 2057 [1D9E] 1D9E:ADEB (1D8B) [ 5] bsr ?AbsX 2058 M @lea divisor@@,sp 2058 M mset # 2058 M [1DA0] 1DA0:95 [ 2] tsx 2058 M [1DA1] 1DA1:AF08 [ 2] !aix #divisor35+:tsx 2058 mexit 2059 [1DA3] 1DA3:ADE6 (1D8B) [ 5] bsr ?AbsX 2060 #Cycles ?AbsXCycles*2+:cycles 2062 [1DA5] 1DA5:A7F9 [ 2] ais #-?SF+1 ;quotient, remainder, and temp 2063 [1DA7] 1DA7:95 [ 2] tsx ;(+1 for already pushed Flag) 2064 2065 ; remainder := 0 2066 ; quotient := 0 2067 2068 M @clr.s ?remainder,x 2068 M mset #' ' 2068 M mreq 1 2068 M @@_nosize_ ?remainder,x 2068 M mset # 2068 M mset 0,mstop [clr.s] No size (?remainder,x) 2068 M endm 2068 M mdef 2,::?remainder 2068 M mdo 2068 M [1DA8] 1DA8:6F02 [ 5] clr ?remainder+0,x 2068 M mloop ::?remainder 2068 M [1DAA] 1DAA:6F03 [ 5] clr ?remainder+1,x 2068 M mloop ::?remainder 2068 endm 2069 M @clr.s ?quotient,x 2069 M mset #' ' 2069 M mreq 1 2069 M @@_nosize_ ?quotient,x 2069 M mset # 2069 M mset 0,mstop [clr.s] No size (?quotient,x) 2069 M endm 2069 M mdef 2,::?quotient 2069 M mdo 2069 M [1DAC] 1DAC:7F [ 4] clr ?quotient+0,x 2069 M mloop ::?quotient 2069 M [1DAD] 1DAD:6F01 [ 5] clr ?quotient+1,x 2069 M mloop ::?quotient 2069 endm 2070 2071 ; first, test for division by zero error 2072 2073 M @_tst_.s divisor@@,spx 2073 M mset # 2073 M mreq 1 2073 M @@_nosize_ divisor35,spx 2073 M mset # 2073 M mset 0,mstop [_tst_.s] No size (divisor35,spx) 2073 M endm 2073 M mdo 2073 M [1DAF] 1DAF:E60F [ 3] lda divisor35+0,spx 2073 M mloop ::divisor35 2073 M [1DB1] 1DB1:EA10 [ 3] ora divisor35+1,spx 2073 M mloop ::divisor35 2073 endm 2074 [1DB3] 1DB3:27E0 (1D95) [ 3] beq ?DivError 2075 2076 ; if Dividend = 0, we're done 2077 2078 M @_tst_.s dividend@@,spx 2078 M mset # 2078 M mreq 1 2078 M @@_nosize_ dividend35,spx 2078 M mset # 2078 M mset 0,mstop [_tst_.s] No size (dividend35,spx) 2078 M endm 2078 M mdo 2078 M [1DB5] 1DB5:E60D [ 3] lda dividend35+0,spx 2078 M mloop ::dividend35 2078 M [1DB7] 1DB7:EA0E [ 3] ora dividend35+1,spx 2078 M mloop ::dividend35 2078 endm 2079 [1DB9] 1DB9:2603 CC1E 43 [ 7] !jeq Done@@ 2080 2081 ; if (divisor = dividend) then quotient := 1; return 2082 ; if (divisor > dividend) then remainder := dividend; return 2083 2084 M @_cmp_.s divisor@@,spx dividend@@,spx 2084 M mset #' ' 2084 M mreq 1,2:[#]Operand1 [#]Operand2 2084 M @@_samesize_ divisor35,spx dividend@@,spx 2084 M mreq 1,2:Operand1,Operand2[,Operand]* 2084 M mset 0 2084 M mdo 2084 M mswap 1,1 2084 M @@_nosize_ divisor35,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (divisor35,spx) 2084 M endm 2084 M mset 0,divisor35,spx 2084 M mloop :n 2084 M mswap 1,2 2084 M @@_nosize_ dividend@@,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (dividend35,spx) 2084 M endm 2084 M mloop :n 2084 M endm 2084 M #temp 1 2084 M #temp ::divisor35 2084 M #temp ::dividend@@ 2084 M mdo 2084 M [1DBE] 1DBE:E60F [ 3] lda divisor35+0,spx 2084 M [1DC0] 1DC0:E10D [ 3] cmpa dividend@@+0,spx 2084 M [1DC2] 1DC2:2604 (1DC8) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [1DC4] 1DC4:E610 [ 3] lda divisor35+1,spx 2084 M [1DC6] 1DC6:E10E [ 3] cmpa dividend@@+1,spx 2084 M mloop :temp 2084 M 1DC8 Done$$$ 2084 endm 2085 [1DC8] 1DC8:2604 (1DCE) [ 3] bne NotEqual@@ 2086 2087 [1DCA] 1DCA:6C01 [ 5] inc ?quotient+{::?quotient-1},x ;quotient := 1 2088 [1DCC] 1DCC:200A (1DD8) [ 3] bra ??DivExit ;and get out 2089 2090 1DCE NotEqual@@ ;@sub.s divisor@@,spx dividend@@,spx ;[2012.05.18 REDUNDANT] 2091 [1DCE] 1DCE:250A (1DDA) [ 3] blo Continue@@ 2092 2093 M @mova.s dividend@@,spx ?remainder,x 2093 M mset #' ' 2093 M mreq 1,2:Source Destination 2093 M @@_samesize_ dividend35,spx ?remainder,x 2093 M mreq 1,2:Operand1,Operand2[,Operand]* 2093 M mset 0 2093 M mdo 2093 M mswap 1,1 2093 M @@_nosize_ dividend35,spx 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (dividend35,spx) 2093 M endm 2093 M mset 0,dividend35,spx 2093 M mloop :n 2093 M mswap 1,2 2093 M @@_nosize_ ?remainder,x 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (?remainder,x) 2093 M endm 2093 M mloop :n 2093 M endm 2093 M mset 0 2093 M mdo 2093 M [1DD0] 1DD0:E60D [ 3] lda dividend35+0,spx 2093 M [1DD2] 1DD2:E702 [ 3] sta ?remainder+0,x 2093 M mloop ::?remainder 2093 M [1DD4] 1DD4:E60E [ 3] lda dividend35+1,spx 2093 M [1DD6] 1DD6:E703 [ 3] sta ?remainder+1,x 2093 M mloop ::?remainder 2093 endm 2094 1DD8 ??DivExit ;and get out 2096 [1DD8] 1DD8:2069 (1E43) [ 3] bra Done@@ 2100 2101 [1DDA] 1DDA:A610 [ 2] Continue@@ lda #MATHSIZE 2102 [1DDC] 1DDC:E706 [ 3] sta ?bits,x ;bits := 64/56/48/40/32/24/16-bit 2103 2104 ; while (remainder < divisor) do 2105 2106 M While@@ @cop ;in case of many iterations 2106 M [1DDE] 1DDE:C718 00 [ 4] sta COP 2106 endm 2107 2108 M @sub.s ?remainder,x divisor@@,spx 2108 M mset #' ' 2108 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2108 M @@_samesize_ ?remainder,x divisor35,spx 2108 M mreq 1,2:Operand1,Operand2[,Operand]* 2108 M mset 0 2108 M mdo 2108 M mswap 1,1 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (?remainder,x) 2108 M endm 2108 M mset 0,?remainder,x 2108 M mloop :n 2108 M mswap 1,2 2108 M @@_nosize_ divisor35,spx 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (divisor35,spx) 2108 M endm 2108 M mloop :n 2108 M endm 2108 M #temp 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [sub.s] No size (?remainder,x) 2108 M endm 2108 M #temp ::?remainder 2108 M mset 0,sub 2108 M mdo 2108 M [1DE1] 1DE1:E603 [ 3] lda ?remainder+1,x 2108 M [1DE3] 1DE3:E010 [ 3] sub divisor35+1,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [1DE5] 1DE5:E602 [ 3] lda ?remainder+0,x 2108 M [1DE7] 1DE7:E20F [ 3] sbc divisor35+0,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 endm 2109 [1DE9] 1DE9:2414 (1DFF) [ 3] bcc EndWhile@@ 2110 2111 ; remainder := (remainder shl 1) or msb(dividend) 2112 ;-------------------------------------- ;2012.12.04 optimization (moved up this code from before DEC to here) 2113 M @mova.s dividend@@,spx ?temp,x ; temp := dividend 2113 M mset #' ' 2113 M mreq 1,2:Source Destination 2113 M @@_samesize_ dividend35,spx ?temp,x 2113 M mreq 1,2:Operand1,Operand2[,Operand]* 2113 M mset 0 2113 M mdo 2113 M mswap 1,1 2113 M @@_nosize_ dividend35,spx 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (dividend35,spx) 2113 M endm 2113 M mset 0,dividend35,spx 2113 M mloop :n 2113 M mswap 1,2 2113 M @@_nosize_ ?temp,x 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (?temp,x) 2113 M endm 2113 M mloop :n 2113 M endm 2113 M mset 0 2113 M mdo 2113 M [1DEB] 1DEB:E60D [ 3] lda dividend35+0,spx 2113 M [1DED] 1DED:E704 [ 3] sta ?temp+0,x 2113 M mloop ::?temp 2113 M [1DEF] 1DEF:E60E [ 3] lda dividend35+1,spx 2113 M [1DF1] 1DF1:E705 [ 3] sta ?temp+1,x 2113 M mloop ::?temp 2113 endm 2114 M @lsl.s dividend@@,spx ; dividend := dividend shl 1 2114 M mset # 2114 M mreq 1 2114 M @@_nosize_ dividend35,spx 2114 M mset # 2114 M mset 0,mstop [lsl.s] No size (dividend35,spx) 2114 M endm 2114 M mdo 2114 M [1DF3] 1DF3:680E [ 5] lsl dividend35+1,spx 2114 M mloop ::dividend35 2114 M [1DF5] 1DF5:690D [ 5] rol dividend35+0,spx 2114 M mloop ::dividend35 2114 endm 2115 ;-------------------------------------- 2116 M @rol.s ?remainder,x 2116 M mset # 2116 M mreq 1 2116 M @@_nosize_ ?remainder,x 2116 M mset # 2116 M mset 0,mstop [rol.s] No size (?remainder,x) 2116 M endm 2116 M mdo 2116 M [1DF7] 1DF7:6903 [ 5] rol ?remainder+1,x 2116 M mloop ::?remainder 2116 M [1DF9] 1DF9:6902 [ 5] rol ?remainder+0,x 2116 M mloop ::?remainder 2116 endm 2117 [1DFB] 1DFB:6A06 [ 5] dec ?bits,x ; bits := bits - 1 2118 2119 ; end while 2120 2121 [1DFD] 1DFD:20DF (1DDE) [ 3] bra While@@ 2122 1DFF EndWhile@@ 2123 M @mova.s ?temp,x dividend@@,spx ; dividend := temp 2123 M mset #' ' 2123 M mreq 1,2:Source Destination 2123 M @@_samesize_ ?temp,x dividend35,spx 2123 M mreq 1,2:Operand1,Operand2[,Operand]* 2123 M mset 0 2123 M mdo 2123 M mswap 1,1 2123 M @@_nosize_ ?temp,x 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (?temp,x) 2123 M endm 2123 M mset 0,?temp,x 2123 M mloop :n 2123 M mswap 1,2 2123 M @@_nosize_ dividend35,spx 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (dividend35,spx) 2123 M endm 2123 M mloop :n 2123 M endm 2123 M mset 0 2123 M mdo 2123 M [1DFF] 1DFF:E604 [ 3] lda ?temp+0,x 2123 M [1E01] 1E01:E70D [ 3] sta dividend35+0,spx 2123 M mloop ::dividend35 2123 M [1E03] 1E03:E605 [ 3] lda ?temp+1,x 2123 M [1E05] 1E05:E70E [ 3] sta dividend35+1,spx 2123 M mloop ::dividend35 2123 endm 2124 M @lsr.s ?remainder,x ; remainder := remainder shr 1 2124 M mset # 2124 M mreq 1 2124 M @@_nosize_ ?remainder,x 2124 M mset # 2124 M mset 0,mstop [lsr.s] No size (?remainder,x) 2124 M endm 2124 M mdo 2124 M [1E07] 1E07:6402 [ 5] lsr ?remainder+0,x 2124 M mloop ::?remainder 2124 M [1E09] 1E09:6603 [ 5] ror ?remainder+1,x 2124 M mloop ::?remainder 2124 endm 2125 [1E0B] 1E0B:6C06 [ 5] inc ?bits,x ; bits := bits + 1 2126 2127 ; for i := bitCounter-1 downto 0 do 2128 2129 M For@@ @cop ;in case of many iterations 2129 M [1E0D] 1E0D:C718 00 [ 4] sta COP 2129 endm 2130 2131 [1E10] 1E10:6D06 [ 4] tst ?bits,x 2133 [1E12] 1E12:272F (1E43) [ 3] beq Done@@ 2137 [1E14] 1E14:6A06 [ 5] dec ?bits,x 2138 2139 ; remainder := (remainder shl 1) or msb(dividend) 2140 ; dividend := dividend shl 1 2141 2142 M @lsl.s dividend@@,spx ;2012.12.04 optimization 2142 M mset # 2142 M mreq 1 2142 M @@_nosize_ dividend35,spx 2142 M mset # 2142 M mset 0,mstop [lsl.s] No size (dividend35,spx) 2142 M endm 2142 M mdo 2142 M [1E16] 1E16:680E [ 5] lsl dividend35+1,spx 2142 M mloop ::dividend35 2142 M [1E18] 1E18:690D [ 5] rol dividend35+0,spx 2142 M mloop ::dividend35 2142 endm 2143 M @rol.s ?remainder,x 2143 M mset # 2143 M mreq 1 2143 M @@_nosize_ ?remainder,x 2143 M mset # 2143 M mset 0,mstop [rol.s] No size (?remainder,x) 2143 M endm 2143 M mdo 2143 M [1E1A] 1E1A:6903 [ 5] rol ?remainder+1,x 2143 M mloop ::?remainder 2143 M [1E1C] 1E1C:6902 [ 5] rol ?remainder+0,x 2143 M mloop ::?remainder 2143 endm 2144 2145 ; temp := remainder - divisor 2146 2147 M @sub.s ?remainder,x divisor@@,spx ?temp,x 2147 M mset #' ' 2147 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2147 M @@_samesize_ ?remainder,x divisor35,spx ?temp,x 2147 M mreq 1,2:Operand1,Operand2[,Operand]* 2147 M mset 0 2147 M mdo 2147 M mswap 1,1 2147 M @@_nosize_ ?remainder,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?remainder,x) 2147 M endm 2147 M mset 0,?remainder,x 2147 M mloop :n 2147 M mswap 1,2 2147 M @@_nosize_ divisor35,spx 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (divisor35,spx) 2147 M endm 2147 M mloop :n 2147 M mswap 1,3 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?temp,x) 2147 M endm 2147 M mloop :n 2147 M endm 2147 M #temp 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [sub.s] No size (?temp,x) 2147 M endm 2147 M #temp ::?temp 2147 M mset 0,sub 2147 M mdo 2147 M [1E1E] 1E1E:E603 [ 3] lda ?remainder+1,x 2147 M [1E20] 1E20:E010 [ 3] sub divisor35+1,spx 2147 M [1E22] 1E22:E705 [ 3] sta ?temp+1,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [1E24] 1E24:E602 [ 3] lda ?remainder+0,x 2147 M [1E26] 1E26:E20F [ 3] sbc divisor35+0,spx 2147 M [1E28] 1E28:E704 [ 3] sta ?temp+0,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 endm 2148 2149 ; q := not msb(temp) 2150 2151 [1E2A] 1E2A:E604 [ 3] lda ?temp,x 2152 [1E2C] 1E2C:A880 [ 2] eor #%10000000 ;invert msb 2153 [1E2E] 1E2E:A480 [ 2] and #%10000000 ;isolate msb 2154 2155 ; quotient := (quotient shl 1) or q 2156 2157 [1E30] 1E30:87 [ 2] psha 2158 [1E31] 1E31:48 [ 1] lsla 2159 [1E32] 1E32:86 [ 3] pula 2160 2161 M @rol.s ?quotient,x 2161 M mset # 2161 M mreq 1 2161 M @@_nosize_ ?quotient,x 2161 M mset # 2161 M mset 0,mstop [rol.s] No size (?quotient,x) 2161 M endm 2161 M mdo 2161 M [1E33] 1E33:6901 [ 5] rol ?quotient+1,x 2161 M mloop ::?quotient 2161 M [1E35] 1E35:79 [ 4] rol ?quotient+0,x 2161 M mloop ::?quotient 2161 endm 2162 2163 ; if q <> 0 then 2164 2165 [1E36] 1E36:4100 D4(1E0D) [ 4] cbeqa #0,For@@ 2166 2167 ; remainder := temp 2168 2169 M @mova.s ?temp,x ?remainder,x 2169 M mset #' ' 2169 M mreq 1,2:Source Destination 2169 M @@_samesize_ ?temp,x ?remainder,x 2169 M mreq 1,2:Operand1,Operand2[,Operand]* 2169 M mset 0 2169 M mdo 2169 M mswap 1,1 2169 M @@_nosize_ ?temp,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?temp,x) 2169 M endm 2169 M mset 0,?temp,x 2169 M mloop :n 2169 M mswap 1,2 2169 M @@_nosize_ ?remainder,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?remainder,x) 2169 M endm 2169 M mloop :n 2169 M endm 2169 M mset 0 2169 M mdo 2169 M [1E39] 1E39:E604 [ 3] lda ?temp+0,x 2169 M [1E3B] 1E3B:E702 [ 3] sta ?remainder+0,x 2169 M mloop ::?remainder 2169 M [1E3D] 1E3D:E605 [ 3] lda ?temp+1,x 2169 M [1E3F] 1E3F:E703 [ 3] sta ?remainder+1,x 2169 M mloop ::?remainder 2169 endm 2170 2171 ; end if -- end for 2172 2174 [1E41] 1E41:20CA (1E0D) [ 3] bra For@@ 2178 2179 [1E43] 1E43:E607 [ 3] Done@@ lda ?flags,x 2180 [1E45] 1E45:A501 [ 2] bit #?DIVOP_ 2181 [1E47] 1E47:2709 (1E52) [ 3] beq ExitMod@@ 2182 2183 0160 ?Cycles equ :cycles 2184 2185 ;ExitDiv@@ 2186 M @mova.s ?quotient,x ans@@,spx 2186 M mset #' ' 2186 M mreq 1,2:Source Destination 2186 M @@_samesize_ ?quotient,x ans35,spx 2186 M mreq 1,2:Operand1,Operand2[,Operand]* 2186 M mset 0 2186 M mdo 2186 M mswap 1,1 2186 M @@_nosize_ ?quotient,x 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (?quotient,x) 2186 M endm 2186 M mset 0,?quotient,x 2186 M mloop :n 2186 M mswap 1,2 2186 M @@_nosize_ ans35,spx 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (ans35,spx) 2186 M endm 2186 M mloop :n 2186 M endm 2186 M mset 0 2186 M mdo 2186 M [1E49] 1E49:F6 [ 3] lda ?quotient+0,x 2186 M [1E4A] 1E4A:E70F [ 3] sta ans35+0,spx 2186 M mloop ::ans35 2186 M [1E4C] 1E4C:E601 [ 3] lda ?quotient+1,x 2186 M [1E4E] 1E4E:E710 [ 3] sta ans35+1,spx 2186 M mloop ::ans35 2186 endm 2187 [1E50] 1E50:2008 (1E5A) [ 3] bra ExitBoth@@ 2188 2189 018E ?DivCycles set ?DivCycles+?Cycles+:cycles 2190 2191 M ExitMod@@ @mova.s ?remainder,x ans@@,spx 2191 M mset #' ' 2191 M mreq 1,2:Source Destination 2191 M @@_samesize_ ?remainder,x ans35,spx 2191 M mreq 1,2:Operand1,Operand2[,Operand]* 2191 M mset 0 2191 M mdo 2191 M mswap 1,1 2191 M @@_nosize_ ?remainder,x 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (?remainder,x) 2191 M endm 2191 M mset 0,?remainder,x 2191 M mloop :n 2191 M mswap 1,2 2191 M @@_nosize_ ans35,spx 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (ans35,spx) 2191 M endm 2191 M mloop :n 2191 M endm 2191 M mset 0 2191 M mdo 2191 M [1E52] 1E52:E602 [ 3] lda ?remainder+0,x 2191 M [1E54] 1E54:E70F [ 3] sta ans35+0,spx 2191 M mloop ::ans35 2191 M [1E56] 1E56:E603 [ 3] lda ?remainder+1,x 2191 M [1E58] 1E58:E710 [ 3] sta ans35+1,spx 2191 M mloop ::ans35 2191 endm 2192 2193 0182 ?ModCycles set ?ModCycles+?Cycles+:cycles 2194 2195 1E5A ExitBoth@@ 2197 [1E5A] 1E5A:6D07 [ 4] tst ?flags,x 2198 [1E5C] 1E5C:2A06 (1E64) [ 3] bpl SkipSign@@ 2199 M @lea ans@@,sp 2199 M mset # 2199 M [1E5E] 1E5E:95 [ 2] tsx 2199 M [1E5F] 1E5F:AF0F [ 2] !aix #ans35+:tsx 2199 mexit 2200 [1E61] 1E61:CD1D 8E [ 6] jsr ?NegX 2201 1E64 SkipSign@@ 2202 #Cycles ?NegxCycles+:cycles 2204 [1E64] 1E64:A708 [ 2] ais #?SF ;de-allocate temporaries 2205 [1E66] 1E66:98 [ 1] clc ;no error(s) 2206 ; bra ?RemoveAndReturn 2207 2208 0024 ?Cycles set :cycles 2209 01B2 ?DivCycles set ?DivCycles+?Cycles 2210 01A6 ?ModCycles set ?ModCycles+?Cycles 2211 2212 ;******************************************************************************* 2213 ; Common exit removes lower 32-bit stack element and returns to caller 2214 ;******************************************************************************* 2215 2216 1E67 ?RemoveAndReturn proc 2218 [1E67] 1E67:9EFE 04 [ 5] ldhx ?pc,sp ;our return address moved up 2219 [1E6A] 1E6A:9EFF 06 [ 5] sthx ?pc+?WORD,sp ;above word to remove 2229 [1E6D] 1E6D:8A88 86 [ 9] pull 2230 [1E70] 1E70:A702 [ 2] ais #?WORD ;remove top-of-stack ?WORD 2231 [1E72] 1E72:81 [ 6] rtc 2232 2233 001B ?ReturnCycles equ :cycles 2234 2235 ;******************************************************************************* 2236 ; Purpose: Swaps the stacked order of N1 and N2 2237 ; Input : [TOS+?WORD] = Number2 2238 ; : [TOS] = Number1 2239 ; Output : [TOS+?WORD] = Number1 -- TOS & [TOS+?WORD] in reverse order 2240 ; : [TOS] = Number2 2241 ; Note(s): Does not alter stack size 2242 2243 #spauto :ab 2244 2245 1E73 ?Swap proc 2246 [1E73] 1E73:8789 8B [ 6] push 2247 2248 [1E76] 1E76:A602 [ 2] lda #?WORD 2249 [1E78] 1E78:87 [ 2] psha bytes@@ 2250 2251 [1E79] 1E79:95 [ 2] tsx 2252 #temp :cycles 2253 M Loop@@ @_swap_, ?a,spx ?b,spx ;swap A with B ... 2253 M mset #' ' 2253 M #push 2253 M #spauto :sp 2253 M [1E7A] 1E7A:E606 [ 3] lda ?a,spx 2253 M [1E7C] 1E7C:87 [ 2] psha 2253 M [1E7D] 1E7D:E608 [ 3] lda ?b,spx 2253 M [1E7F] 1E7F:E706 [ 3] sta ?a,spx 2253 M [1E81] 1E81:86 [ 3] pula 2253 M [1E82] 1E82:E708 [ 3] sta ?b,spx 2253 M #pull 2253 endm 2254 2255 [1E84] 1E84:AF01 [ 2] aix #1 ;point to next byte 2256 [1E86] 1E86:9E6B 01F0 (1E7A [ 8] dbnz bytes@@,sp,Loop@@ ;repeat for all bytes 2257 #temp :cycles*?WORD+:temp 2258 [1E8A] 1E8A:86 [ 3] pula 2259 2260 [1E8B] 1E8B:8A88 86 [ 9] pull 2261 [1E8E] 1E8E:81 [ 6] rtc 2262 2263 0054 ?SwapCycles set :cycles+:temp 2264 2265 ;******************************************************************************* 2266 ; Purpose: Get the absolute value of the top-of-stack number 2267 ; Input : [TOS] = Number 2268 ; Output : [TOS] = Abs(Number) 2269 ; Note(s): Does not alter stack size 2270 2271 #spauto :ab 2272 2273 1E8F ?Abs proc 2274 [1E8F] 1E8F:9E6D 03 [ 5] tst ?a,sp 2275 [1E92] 1E92:2AFA (1E8E) [ 3] bpl Done@@ 2276 ; bra ?Negate 2277 2278 1E8E Done@@ equ :AnRTC 2279 2280 0008 ?AbsCycles equ :cycles 2281 2282 ;******************************************************************************* 2283 ; Purpose: Negate the top-of-stack number 2284 ; Input : [TOS] = Number 2285 ; Output : [TOS] = -Number 2286 ; Note(s): Does not alter stack size 2287 2288 #spauto :ab 2289 2290 1E94 ?Negate proc 2291 [1E94] 1E94:898B [ 4] pshhx 2293 M @lea ?a,sp 2293 M mset # 2293 M [1E96] 1E96:95 [ 2] tsx 2293 M [1E97] 1E97:AF04 [ 2] !aix #?a+:tsx 2293 mexit 2294 [1E99] 1E99:CD1D 8E [ 6] jsr ?NegX 2295 #Cycles ?NegxCycles+:cycles 2300 [1E9C] 1E9C:8A88 [ 6] pulhx 2301 [1E9E] 1E9E:81 [ 6] rtc 2302 2303 002A ?NegateCycles equ :cycles 2304 0032 ?AbsCycles set ?NegateCycles+?AbsCycles 2305 2306 ;******************************************************************************* 2307 ; Purpose: Create a new top-of-stack and load to it the number pointed to by HX 2308 ; Input : HX -> [Variable with] Number 2309 ; Output : [TOS] = Number 2310 ; Note(s): This operation makes it easier to load a number to the stack. 2311 ; : Hint: To make a copy of the TOS, do: 2312 ; : tsx 2313 ; : call StackLoad32 2314 ; : (Stack is expanded) 2315 2316 #spauto :ab 2317 2318 1E9F ?Load proc 2319 FFFFFFFF old_rts@@ equ ::,:ab 2320 [1E9F] 1E9F:A7FE [ 2] ais #-?WORD ;allocate new TOS memory 2321 #temp :: 2322 FFFFFFFD new_rts@@ next :temp,:ab 2323 FFFFFFFF tos_num@@ next :temp,?WORD 2324 0001 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2325 #ais :temp 2326 2327 [1EA1] 1EA1:87 [ 2] psha 2328 M @mova.s old_rts@@,sp new_rts@@,sp ;move RTS/RTC after new memory 2328 M mset #' ' 2328 M mreq 1,2:Source Destination 2328 M @@_samesize_ old_rts40,sp new_rts@@,sp 2328 M mreq 1,2:Operand1,Operand2[,Operand]* 2328 M mset 0 2328 M mdo 2328 M mswap 1,1 2328 M @@_nosize_ old_rts40,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (old_rts40,sp) 2328 M endm 2328 M mset 0,old_rts40,sp 2328 M mloop :n 2328 M mswap 1,2 2328 M @@_nosize_ new_rts@@,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (new_rts40,sp) 2328 M endm 2328 M mloop :n 2328 M endm 2328 M mset 0 2328 M mdo 2328 M [1EA2] 1EA2:9EE6 04 [ 4] lda old_rts40+0,sp 2328 M [1EA5] 1EA5:9EE7 02 [ 4] sta new_rts@@+0,sp 2328 M mloop ::new_rts@@ 2328 M [1EA8] 1EA8:9EE6 05 [ 4] lda old_rts40+1,sp 2328 M [1EAB] 1EAB:9EE7 03 [ 4] sta new_rts@@+1,sp 2328 M mloop ::new_rts@@ 2328 endm 2329 M @mova.s ,x tos_num@@,sp 2329 M mset #' ' 2329 M mreq 1,2:Source Destination 2329 M @@_samesize_ ,x tos_num40,sp 2329 M mreq 1,2:Operand1,Operand2[,Operand]* 2329 M mset 0 2329 M mdo 2329 M mswap 1,1 2329 M mloop :n 2329 M mswap 1,2 2329 M @@_nosize_ tos_num40,sp 2329 M mset # 2329 M mset 0,mstop [_samesize_] No size (tos_num40,sp) 2329 M endm 2329 M mset 0,tos_num40,sp 2329 M mloop :n 2329 M endm 2329 M mset 0 2329 M mdo 2329 M [1EAE] 1EAE:F6 [ 3] lda +0,x 2329 M [1EAF] 1EAF:9EE7 04 [ 4] sta tos_num40+0,sp 2329 M mloop ::tos_num40 2329 M [1EB2] 1EB2:E601 [ 3] lda +1,x 2329 M [1EB4] 1EB4:9EE7 05 [ 4] sta tos_num40+1,sp 2329 M mloop ::tos_num40 2329 endm 2330 [1EB7] 1EB7:86 [ 3] pula 2331 [1EB8] 1EB8:81 [ 6] rtc 2332 2333 002B ?LoadCycles equ :cycles 2334 2335 ;******************************************************************************* 2336 ; Purpose: Unload the top-of-stack number into a variable pointed to by HX 2337 ; Input : [TOS] = Number 2338 ; : HX -> Some 32-bit variable 2339 ; Output : Variable pointed to by HX receives TOS number 2340 ; Note(s): This operation makes it easier to unload a number from the stack. 2341 ; : Use: 2342 ; : ldhx #MyVar 2343 ; : call StackSave32 2344 ; : (Stack is reduced) 2345 2346 #spauto :ab 2347 2348 1EB9 ?Save proc 2349 #temp :: 2350 FFFFFFFF old_rts@@ next :temp,:ab 2351 0001 tos_num@@ next :temp,?WORD 2352 0003 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2353 0001 new_rts@@ next :temp,:ab 2354 2355 0000 var@@ equ 0,?WORD 2356 2357 [1EB9] 1EB9:8789 8B [ 6] push 2358 M @mova.s tos_num@@,sp var@@,x 2358 M mset #' ' 2358 M mreq 1,2:Source Destination 2358 M @@_samesize_ tos_num41,sp var@@,x 2358 M mreq 1,2:Operand1,Operand2[,Operand]* 2358 M mset 0 2358 M mdo 2358 M mswap 1,1 2358 M @@_nosize_ tos_num41,sp 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (tos_num41,sp) 2358 M endm 2358 M mset 0,tos_num41,sp 2358 M mloop :n 2358 M mswap 1,2 2358 M @@_nosize_ var@@,x 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (var41,x) 2358 M endm 2358 M mloop :n 2358 M endm 2358 M mset 0 2358 M mdo 2358 M [1EBC] 1EBC:9EE6 06 [ 4] lda tos_num41+0,sp 2358 M [1EBF] 1EBF:F7 [ 2] sta var@@+0,x 2358 M mloop ::var@@ 2358 M [1EC0] 1EC0:9EE6 07 [ 4] lda tos_num41+1,sp 2358 M [1EC3] 1EC3:E701 [ 3] sta var@@+1,x 2358 M mloop ::var@@ 2358 endm 2359 2360 [1EC5] 1EC5:95 [ 2] tsx 2361 M @mova.s old_rts@@,spx new_rts@@,spx ;move RTS/RTC before old memory 2361 M mset #' ' 2361 M mreq 1,2:Source Destination 2361 M @@_samesize_ old_rts41,spx new_rts@@,spx 2361 M mreq 1,2:Operand1,Operand2[,Operand]* 2361 M mset 0 2361 M mdo 2361 M mswap 1,1 2361 M @@_nosize_ old_rts41,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (old_rts41,spx) 2361 M endm 2361 M mset 0,old_rts41,spx 2361 M mloop :n 2361 M mswap 1,2 2361 M @@_nosize_ new_rts@@,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (new_rts41,spx) 2361 M endm 2361 M mloop :n 2361 M endm 2361 M mset 0 2361 M mdo 2361 M [1EC6] 1EC6:E603 [ 3] lda old_rts41+0,spx 2361 M [1EC8] 1EC8:E705 [ 3] sta new_rts@@+0,spx 2361 M mloop ::new_rts@@ 2361 M [1ECA] 1ECA:E604 [ 3] lda old_rts41+1,spx 2361 M [1ECC] 1ECC:E706 [ 3] sta new_rts@@+1,spx 2361 M mloop ::new_rts@@ 2361 endm 2362 [1ECE] 1ECE:8A88 86 [ 9] pull 2363 2364 [1ED1] 1ED1:A702 [ 2] ais #?WORD ;de-allocate TOS memory 2365 [1ED3] 1ED3:81 [ 6] rtc 2366 2367 0032 ?SaveCycles equ :cycles 2368 2369 ;******************************************************************************* 2370 ; Purpose: Adjust TOS old size to new 2371 ; Input : H = old (current) byte size 2372 ; : X = new byte size 2373 ; : CCR[C] = 0 -- always positive number 2374 ; : CCR[C] = 1 -- sign extend 2375 ; Output : None 2376 ; Note(s): RegA deliberately not used for parameter passing (for consistency) 2377 ; : Macro destroys RegHX (as we must not use PSHHX/PULHX around call) 2378 2504 2505 ;******************************************************************************* 2506 ; Purpose: Convert 32-bit to ASCIZ string 2507 ; Input : Stack: 32-bit number 2508 ; : HX -> Output buffer with enough space to keep the ASCIZ string result 2509 ; Output : None 2510 ; Note(s): Use: 2511 ; : ldhx #Buffer 2512 ; : call Stack32ToASCIZ 2513 2514 #spauto :ab ;account for RTS/RTC 2515 2516 1ED4 ?ToStr proc 2517 [1ED4] 1ED4:8789 8B [ 6] push 2518 #ais ;mark beginning of temporaries 2519 2520 [1ED7] 1ED7:898B [ 4] pshhx .buffer@@ ;working copy of pointer to buffer 2521 [1ED9] 1ED9:7F [ 4] clr ,x ;make it an ASCIZ string 2522 2523 M @lea 1,sp ;HX -> TOS number of caller 2523 M mset # 2523 M [1EDA] 1EDA:95 [ 2] tsx 2523 M [1EDB] 1EDB:AF07 [ 2] !aix #1+:tsx 2523 mexit 2524 [1EDD] 1EDD:CD1E 9F [ 6] call ?Load ;load a working copy on stack 2525 2526 #spadd ?WORD ;stack has grown by a ?WORD 2527 FFFFFFF8 number@@ equ ::,?WORD 2529 [1EE0] 1EE0:9E6D 01 [ 5] tst number@@,sp 2530 [1EE3] 1EE3:2A0F (1EF4) [ 3] bpl ToStrLoop@@ 2531 [1EE5] 1EE5:CD1E 94 [ 6] call ?Negate 2533 [1EE8] 1EE8:9EFE 03 [ 5] ldhx .buffer@@,sp 2540 [1EEB] 1EEB:A62D [ 2] lda #'-' ;a 'minus' sign 2541 [1EED] 1EED:F7 [ 2] sta ,x ; is saved first 2542 2543 [1EEE] 1EEE:AF01 [ 2] aix #1 ;HX -> past minus sign 2544 [1EF0] 1EF0:7F [ 4] clr ,x ;make it an ASCIZ string 2546 [1EF1] 1EF1:9EFF 03 [ 5] sthx .buffer@@,sp ;update pointer past sign 2552 ; bra ToStrLoop@@ 2554 ;=============================================================================== 2555 2556 [1EF4] 1EF4:4500 0A [ 3] ToStrLoop@@ ldhx #10 ;H = 0 (always), X = divisor 2557 M @div.s number@@,sp 2557 M mset # 2557 M mreq 1 2557 M @@_not_x_ number42,sp 2557 M mset #' ' 2557 M mdel 1 2557 M mtop 2557 M mset #' ' 2557 M mexit 2557 M @@_nosize_ number42,sp 2557 M mset # 2557 M mset 0,mstop [div.s] No size (number42,sp) 2557 M endm 2557 M #temp 1 2557 M #temp 2 2557 M [1EF7] 1EF7:86 [ 3] pula 2557 M [1EF8] 1EF8:52 [ 6] div 2557 M [1EF9] 1EF9:87 [ 2] psha 2557 M mdo 2 2557 M [1EFA] 1EFA:9EE6 02 [ 4] lda number42+1,sp 2557 M [1EFD] 1EFD:52 [ 6] div 2557 M [1EFE] 1EFE:9EE7 02 [ 4] sta number42+1,sp 2557 M mloop ::number42 2557 endm 2558 2559 [1F01] 1F01:8B86 [ 5] tha ;A = remainder 2560 [1F03] 1F03:AB30 [ 2] add #'0' ;A = ASCII remainder 2562 [1F05] 1F05:9EFE 03 [ 5] ldhx .buffer@@,sp 2568 M @StringInsertChar 2568 M [1F08] 1F08:CD18 3A [ 6] call StringInsertChar ;HX and A pre-loaded correctly 2568 mexit 2569 2570 [1F0B] 1F0B:95 [ 2] tsx 2571 2572 M @_tst_.s number@@,spx 2572 M mset # 2572 M mreq 1 2572 M @@_nosize_ number42,spx 2572 M mset # 2572 M mset 0,mstop [_tst_.s] No size (number42,spx) 2572 M endm 2572 M mdo 2572 M [1F0C] 1F0C:F6 [ 3] lda number42+0,spx 2572 M mloop ::number42 2572 M [1F0D] 1F0D:EA01 [ 3] ora number42+1,spx 2572 M mloop ::number42 2572 endm 2573 [1F0F] 1F0F:26E3 (1EF4) [ 3] bne ToStrLoop@@ 2574 2575 [1F11] 1F11:A704 [ 2] ais #:ais ;free temporaries 2576 [1F13] 1F13:8A88 86 [ 9] pull 2577 [1F16] 1F16:81 [ 6] rtc 2578 2579 #sp ;cancel all SP offsets 2580 2581 ;******************************************************************************* 2582 ; Assign global names to the various library calls, depending on version used. 2583 ; Different names for each version means you can include any at the same time. 2584 ;******************************************************************************* 2585 2586 ? macro BitSize ;temp macro to export symbols 2587 mreq 1:Usage: @~0~ BitSize 2588 #if MATHSIZE = ~1~ 2589 StackAdd~1~ exp ?Add 2590 StackSub~1~ exp ?Subtract 2591 StackMul~1~ exp ?Multiply 2592 StackDiv~1~ exp ?Divide 2593 StackMod~1~ exp ?Modulo 2594 StackSwap~1~ exp ?Swap 2595 StackAbs~1~ exp ?Abs 2596 StackNegate~1~ exp ?Negate 2597 StackLoad~1~ exp ?Load 2598 StackSave~1~ exp ?Save 2599 Stack~1~ToASCIZ exp ?ToStr 2600 #ifdef NO_BIT_OPS 2601 mexit ;;bit operations not available 2602 #endif 2603 StackAnd~1~ exp ?BitAnd 2604 StackOr~1~ exp ?BitOr 2605 StackXor~1~ exp ?BitXor 2606 StackShl~1~ exp ?ShiftLeft 2607 StackShr~1~ exp ?ShiftRight 2608 #endif 2609 endm 2610 2611 M @? 64 ;export 64-bit labels 2611 M mreq 1:Usage: @? BitSize 2611 endm 2612 M @? 56 ;export 56-bit labels 2612 M mreq 1:Usage: @? BitSize 2612 endm 2613 M @? 48 ;export 48-bit labels 2613 M mreq 1:Usage: @? BitSize 2613 endm 2614 M @? 40 ;export 40-bit labels 2614 M mreq 1:Usage: @? BitSize 2614 endm 2615 M @? 32 ;export 32-bit labels 2615 M mreq 1:Usage: @? BitSize 2615 endm 2616 M @? 24 ;export 24-bit labels 2616 M mreq 1:Usage: @? BitSize 2616 endm 2617 M @? 16 ;export 16-bit labels 2617 M mreq 1:Usage: @? BitSize 2617 M 1C92 StackAdd16 exp ?Add 2617 M 1CA5 StackSub16 exp ?Subtract 2617 M 1D43 StackMul16 exp ?Multiply 2617 M 1D6A StackDiv16 exp ?Divide 2617 M 1D7D StackMod16 exp ?Modulo 2617 M 1E73 StackSwap16 exp ?Swap 2617 M 1E8F StackAbs16 exp ?Abs 2617 M 1E94 StackNegate16 exp ?Negate 2617 M 1E9F StackLoad16 exp ?Load 2617 M 1EB9 StackSave16 exp ?Save 2617 M 1ED4 Stack16ToASCIZ exp ?ToStr 2617 M 1CB8 StackAnd16 exp ?BitAnd 2617 M 1CCB StackOr16 exp ?BitOr 2617 M 1CDE StackXor16 exp ?BitXor 2617 M 1CF1 StackShl16 exp ?ShiftLeft 2617 M 1D1A StackShr16 exp ?ShiftRight 2617 endm 2618 2619 ;******************************************************************************* *** END INCLUDE FILE: lib/stakmath.sub *** (RESUMING FILE: lib/stkmth16.sub) 23 #Exit *** END INCLUDE FILE: lib/stkmth16.sub *** (RESUMING FILE: lib/demo/stakmath.asm) 50 M @? 24,4 50 M @@Page 4 50 M mreq 1:PageNumber 50 M endm 50 #Uses lib/stkmth24.sub *** BEGIN INCLUDE FILE: lib/stkmth24.sub *** 1 ;******************************************************************************* 2 ;* Module : STKMTH24.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Wrapper for 24-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stkmth24.html 8 ;* Note(s) : See STAKMATH.SUB for details 9 ;******************************************************************************* 10 16 17 ? macro 18 mset 1,~BASENAME~ 19 MATHSIZE set ~1.{:1-1}~ 20 #Include stakmath.sub 21 endm 22 23 M @? 23 M mset 1,STKMTH24 23 M 0018 MATHSIZE set 24 23 #Include stakmath.sub *** BEGIN INCLUDE FILE: lib/stakmath.sub *** 1 ;******************************************************************************* 2 ;* Module : STAKMATH.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : 64/56/48/40/32/24/16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stakmath.html 8 ;* Note(s) : Use: #Include stakmath.sub 9 ;* : 10 ;* : Several externally defined macros are used throughout this code. 11 ;* : All these (and many more) macros are inside the most recent 12 ;* : version of MACROS.INC which can be copied from the web page at 13 ;* : http://www.aspisys.com/code/hc08/macros.html 14 ;* : (and COMMON.INC at http://www.aspisys.com/code/hc08/common.html) 15 ;* : 16 ;* : The default word size is 32-bit. 17 ;* : 18 ;* : By (re)defining the symbol MATHSIZE (to 16) you get 16-bit code. 19 ;* : By (re)defining the symbol MATHSIZE to 24 you get 24-bit code. 20 ;* : By (re)defining the symbol MATHSIZE to 40 you get 40-bit code. 21 ;* : By (re)defining the symbol MATHSIZE to 48 you get 48-bit code. 22 ;* : By (re)defining the symbol MATHSIZE to 56 you get 56-bit code. 23 ;* : By (re)defining the symbol MATHSIZE to 64 you get 64-bit code. 24 ;* : 25 ;* : You can include all (or some) versions in your program like so: 26 ;* : 27 ;* : #ROM ;(or else, some paged memory) 28 ;* : #Include stakmath.sub 29 ;* : MATHSIZE set 16 ;redefine for 16-bit use 30 ;* : #Include stakmath.sub 31 ;* : MATHSIZE set 24 ;redefine for 24-bit use 32 ;* : #Include stakmath.sub 33 ;* : MATHSIZE set 40 ;redefine for 40-bit use 34 ;* : #Include stakmath.sub 35 ;* : MATHSIZE set 48 ;redefine for 48-bit use 36 ;* : #Include stakmath.sub 37 ;* : MATHSIZE set 56 ;redefine for 56-bit use 38 ;* : #Include stakmath.sub 39 ;* : MATHSIZE set 64 ;redefine for 64-bit use 40 ;* : 41 ;* : or, if you use the related wrapper files, like so: 42 ;* : 43 ;* : #ROM ;(or else, some paged memory) 44 ;* : #Uses stkmth16.sub 45 ;* : #Uses stkmth24.sub 46 ;* : #Uses stkmth32.sub 47 ;* : #Uses stkmth40.sub 48 ;* : #Uses stkmth48.sub 49 ;* : #Uses stkmth56.sub 50 ;* : #Uses stkmth64.sub 51 ;* : 52 ;* : Use CALL if assembled in #MMU mode (regardless of placement). 53 ;* : By using CALL and #JUMP (or default -J+ command line option), the 54 ;* : assembler will automatically adjust between CALL and JSR 55 ;* : depending on the current #MMU mode. 56 ;* : 57 ;* : To use the *-bit version of each CALL, use these symbols: 58 ;* : 59 ;* : StackAdd*, StackSub*, StackMul*, StackDiv*, StackMod* 60 ;* : StackSwap*, StackNegate*, StackLoad*, StackSave*, 61 ;* : Stack*ToASCIZ 62 ;* : 63 ;* : replacing * with one of these: 16, 24, 32, 40, 48, 56, or 64. 64 ;* : 65 ;* : Various macros allow using these routines in a variety of ways, 66 ;* : and without worrying about the details of call & parameter setup. 67 ;* : These macros are: Add*, Sub*, Mul*, Div*, Mod*, DivS*, ModS*, 68 ;* : Neg*, Load*, Save*, Str*, StrS*, and Swap* (where the * is 16, 69 ;* : 24, 32, 40, 48, 56, or 64 depending on the version you want to use). 70 ;* : The signed versions are enabled only when the module is assembled 71 ;* : with the SIGNED conditional. 72 ;* : 73 ;* : If working with fixed-address variables, you can use the various 74 ;* : macros (such as Add32, Mul64, etc.) to perform operations in the 75 ;* : easiest possible way, such as: 76 ;* : @Mul32 A,B,Answer 77 ;* : (which multiplies A with B and stores the product in Answer). 78 ;* : But, you may also use the macros to work directly on stack, or to 79 ;* : temporarily save partial results on stack instead of fixed vars. 80 ;* : 81 ;* : I N G E N E R A L T H E N 82 ;* : 83 ;* : @Operation A,B,Answer works with A and B storing result in Answer 84 ;* : @Operation A,B works with A and B leaving result on stack 85 ;* : @Operation A works with TOS and A, result left as TOS 86 ;* : @Operation (no parms) works w/ TOS and [TOS+1], result as new TOS 87 ;* : 88 ;* : (Please note the shown order of the operation may be important.) 89 ;* : 90 ;* : Finally, the Load* (* = 16, 24, 32, 40, 48, 56, 64) operation can 91 ;* : directly load either a variable or a constant (leading #) on the 92 ;* : stack. 93 ;* : 94 ;* : Since v7.00, a HLL-like interface is possible by using the new 95 ;* : Eval* macro (where * = 8, 16, 24, 32, 40, 48, 56, 64) 96 ;* : This is by far the easiest way to use this library, as it closely 97 ;* : resembles using expressions in a HLL compiler. It also can 98 ;* : automatically resize stack after loading from and before saving 99 ;* : to any variable. 100 ;* : 101 ;* : Examine the test section of this file for examples of macro use. 102 ;* : 103 ;* : All routines are re-entrant and work on either the top-of-stack 104 ;* : (TOS) number alone or the two top-most TOS numbers. Similar to 105 ;* : how Reverse Polish Notation (RPN) works. First, you stack the 106 ;* : operand(s) and then call the corresponding routine to perform the 107 ;* : operation. 108 ;* : 109 ;* : The result of any operation is always the updated top of stack. 110 ;* : For operations that require two operands and produce a single 111 ;* : result, the result replaces the two operands (stack is reduced). 112 ;* : 113 ;* : Chain calculations are possible by pushing only the new operand 114 ;* : between operations. Alternatively, one can push all operands in 115 ;* : advance but it's not recommended as stack space may be limited. 116 ;* : When done evaluating an expression, just pull the final 32-bit 117 ;* : result from the stack. 118 ;* : 119 ;* : The TOS is the first (or only) operand of any operation. 120 ;* : This is important, for example, for subtraction and division. 121 ;* : 122 ;* : If the current order of the stack is not as you want it, use the 123 ;* : Swap (StackSwap32) operation to change it. 124 ;* : 125 ;* : All operands and results are exactly 32-bit wide. Overflows are 126 ;* : simply truncated. The lower 32-bit number is valid, though. 127 ;* : 128 ;* : (All references to 32-bit become 16-bit, when MATHSIZE = 16) 129 ;* : (All references to 32-bit become 24-bit, when MATHSIZE = 24) 130 ;* : (All references to 32-bit become 40-bit, when MATHSIZE = 40) 131 ;* : (All references to 32-bit become 48-bit, when MATHSIZE = 48) 132 ;* : (All references to 32-bit become 56-bit, when MATHSIZE = 56) 133 ;* : (All references to 32-bit become 64-bit, when MATHSIZE = 64) 134 ;* : 135 ;* : 64/56/48/40-bit multiplication is done using the shift-add method, 136 ;* : which is much shorter in size for such long operands, but it is 137 ;* : also significantly slower in speed. I opted for size optimization 138 ;* : because the 64/56/48/40-bit versions are not used quite as often. 139 ;* : You may want to re-write it for speed optimization by using the 140 ;* : MUL instruction like it is done for the default 32-bit case. 141 ;* : 142 ;* History : 09.05.22 v1.00 Original (Started on 2009.05.07) 143 ;* : 09.06.04 Optimized by using HX instead of SP, where needed 144 ;* : 09.11.04 Minor optimizations 145 ;* : 09.11.05 Add & Subtract now adjust Carry accordingly 146 ;* : Division by zero error now checked first 147 ;* : 09.11.06 v1.01 Added conditional MATHSIZE for use w/ 16-bit words 148 ;* : 09.11.08 v1.02 Added "Load" operation to ease stack loading 149 ;* : 09.11.11 Use of new LONG pseudo-opcode 150 ;* : 09.12.05 Added cycles display using :cycles 151 ;* : 10.01.06 v1.03 Added MMU auto-support (using :AB internal symbol) 152 ;* : Code is no longer placed in #ROM by default 153 ;* : The few JMPs in the code use [[ to trim possible page 154 ;* : 10.01.08 [[ removed from JMPs (latest ASM8 auto-correction) 155 ;* : 10.01.22 v1.04 Added Save operation for completeness 156 ;* : 10.01.23 v1.05 Added #SP directive examples (latest ASM8) 157 ;* : 10.01.29 v1.06 Added shorter/faster Swap version for 9S08 MCUs 158 ;* : 10.02.01 v1.07 Added #SPAUTO directive 159 ;* : 10.02.04 Added #X directive 160 ;* : 10.02.06 v2.00 Added signed math wrapper calls only for DIV & MOD 161 ;* : (Addition, Subtraction, and Multiplication calls 162 ;* : work either for unsigned or signed operands.) 163 ;* : Signed routines enabled w/ SIGNED conditional. 164 ;* : Division by zero error now reduces stack (operand 165 ;* : A removed) so that the stack is left with same 166 ;* : size on either success or failure (in which case 167 ;* : the TOS result is invalid.) 168 ;* : 10.02.08 v2.01 Fixed signed MOD for correct sign (sign of A) 169 ;* : 10.02.14 v2.10 Added Stack32ToASCIZ and prerequisite StringInsertChar 170 ;* : 10.02.28 v2.11 Minor optimization in StringInsertChar 171 ;* : 10.03.23 Made use of :: internal variable (Build 2010/03/23) 172 ;* : 10.03.30 v2.12 Allowed for HC08 compilation in newer code (?ToStr) 173 ;* : Optimized 9S08 Swap version for size and speed 174 ;* : v2.13 Optimized Negate for size and speed 175 ;* : 10.05.08 v3.00 Added MATHSIZE = 64 option for 64-bit math 176 ;* : Swap operation optimized only for size 177 ;* : 10.05.13 v3.01 Optimized for size and speed by using ,SPX 178 ;* : 10.06.02 v4.00 Added macros for easier use 179 ;* : 10.06.08 v4.10 Improved macros and added new ones (eg Const32) 180 ;* : 10.06.23 v4.20 Added MATHSIZE = 48 option for 48-bit math 181 ;* : 10.06.30 v4.30 Added AddDecimalPoint (to string number) 182 ;* : 10.07.01 v4.40 Added IFSPAUTO conditional 183 ;* : 10.07.03 Moved the functionality of Const macros into Load 184 ;* : 10.07.07 Moved general string routines first 185 ;* : 10.07.17 v4.50 Str* macros may use TOS (if Number parm is missing) 186 ;* : or current HX index (if result pointer is missing) 187 ;* : 10.07.20 _DoLoad*/_DoSave* address now allows for indexed mode 188 ;* : 10.07.21 Minor optimizations; macros now latest ASM8 189 ;* : 10.07.23 Minor bug fix in macro _DoSave for no parm case 190 ;* : 10.08.18 Optimized by using :MINDEX in latest ASM8 191 ;* : 10.08.26 Minor optimizations at the source level 192 ;* : 10.08.31 v4.60 Optimized Load* macros' immediate mode for zeros 193 ;* : 10.10.19 v4.61 Adapted to latest ASM8 (nested macros in Load) 194 ;* : 10.10.22 v4.62 Optimized _DoMath (Added @_DoOperation) 195 ;* : 10.10.26 v4.63 Load48 & Load64 now also accept single #Constant 196 ;* : 10.12.03 v4.64 Adapted to latest ASM8 => macros OK in @@ sub-mode 197 ;* : 11.03.31 v4.65 Moved test code at EOF (to use #EXIT optimization) 198 ;* : 11.04.10 v4.66 Condensed macro definitions (based on MATHSIZE) 199 ;* : 11.04.11 v4.67 Optimized MUL16/MUL32 size & cycles with ,SPX mode 200 ;* : 11.04.12 v4.70 Added MATHSIZE = 24 option for 24-bit math 201 ;* : 11.04.13 v4.71 Reversed some of v4.66's changes 202 ;* : 11.04.13 v4.80 Added MATHSIZE = 40 option for 40-bit math 203 ;* : 11.05.02 v4.81 Save protects HX (it was lost during SP => SPX) 204 ;* : 11.05.05 v4.82 Optimized StringLength by a byte (by using NEGA on exit) 205 ;* : 11.05.25 v4.83 Removed unused Zero constant from test code 206 ;* : 11.10.13 v4.84 Optimized MUL16/24/32 size w/ more ,SPX (same cycles) 207 ;* : 11.11.15 v4.85 Improved StringLength macro 208 ;* : 12.01.26 Changed test code a bit 209 ;* : 12.02.06 v4.86 Optimized SP => SPX at ?RemoveAndReturn 210 ;* : 12.03.05 v4.87 Added ResizeTOS to adjust TOS element's size 211 ;* : 12.05.09 v4.88 Added CCR[C] parameter to ResizeTOS for unsigned operation 212 ;* (signed is default when SIGNED conditional is defined, 213 ;* unsigned operation is default, otherwise) 214 ;* : 12.05.18 v4.89 Removed redundant subtraction in Division (at NotEqual@@) 215 ;* : 12.10.07 v4.90 Load*/Save* now accept indexed mode without separator override 216 ;* : 12.10.10 v5.00 Renamed to (more general) STAKMATH.SUB to use 217 ;* : wrapper files for each bit version, instead. 218 ;* : 12.11.05 Added _STKMTH{MATHSIZE}_ for used-version control 219 ;* : 12.11.09 v6.00 New _LoadStkMthVarAddr macro eases parm address 220 ;* : calculation. 221 ;* : W A R N I N G: SP-based operands now refer to the actual number, 222 ;* : W A R N I N G: and not its address (as was the case before). 223 ;* : W A R N I N G: This is INCOMPATIBLE with previous behavior. Code 224 ;* : W A R N I N G: written for version v5.00 or earlier that uses SP 225 ;* : W A R N I N G: based operands should be modified to refer to the 226 ;* : W A R N I N G: actual value and not to a pointer to the value. 227 ;* : W A R N I N G: Dot-beginning names are still treated as pointers! 228 ;* : 12.11.10 Use COMMON.INC/LEA instead of _LoadStkMthVarAddr 229 ;* : 12.12.04 v6.10 Optimized division just a tad by combining steps 230 ;* : 12.12.12 v6.20 Now use LEA macro inside _DoStr (for ResultString) 231 ;* : 12.12.20 v6.21 Minor optimization (one byte) in 32-bit ?Multiply 232 ;* : (Further 3-byte optimization possible by 233 ;* : re-ordering MULs, but not done for code clarity) 234 ;* : 13.01.09 v6.22 Added Copy* macros to combine Load*/Save* into one 235 ;* : 13.03.20 v7.00 Added Eval* and supporting macros for HLL-like 236 ;* : computations, eg., ans=(a+3)*((1+var,sp)/2) 237 ;* : (with or without spaces between operands/operators) 238 ;* : 13.03.27 v7.50 SIGNED now gives just signed (not unsigned) version 239 ;* : DivS*, ModS*, StrS* macros were removed, and also 240 ;* : ResizeTOS macro's unsigned flag has been removed 241 ;* : BugFix: AddDecimalPoint now prepends zeros after sign 242 ;* : 13.03.27 Optimized ?Negate in SIGNED case to use ?NegX sub 243 ;* : 13.03.27 v7.60 Adapted _EVAL_ macro to latest ASM8 (Much faster!) 244 ;* : 13.04.04 v7.70 _DoLoad and _DoSave macros now auto-adjust the size 245 ;* : so you can use with operands of different sizes, even 246 ;* : if the respective bitsize version isn't loaded. 247 ;* : 13.04.04 v7.71 _Eval_ macro leaves assignment result on TOS if 248 ;* : assignment variable not already defined. Then, 249 ;* : it gives TOS the specified name, if SP-indexed. 250 ;* : 13.04.05 v7.72 Added #size for v7.71 change 251 ;* : Named constants (labels with size zero) now use 252 ;* : immediate mode in Eval/Load 253 ;* : 13.04.05 v7.73 Added NEG() negate, and ABS() absolute functions 254 ;* : in Eval macro, e.g., ans = abs(a - b) 255 ;* : 13.04.09 v7.80 BugFix: Push/Pull macro calls for SP mode 256 ;* : Moved immediate mode to _DoLoad (unified method) 257 ;* : (Over 32-bit immediate value loads not possible 258 ;* : via macros) 259 ;* : 13.04.10 Adapted to v9.35 (no functional changes) 260 ;* : 13.04.11 v7.81 Optimized _DoLoad constant loading by using CLRH 261 ;* : (optimization is evident on certain cases only) 262 ;* : 13.04.15 v7.82 Added _?SEI_ and _?CLI_ macros for multitasker 263 ;* : locking / unlocking of multi-byte variables while 264 ;* : loading / saving (_DoLoad/_DoSave). Under OS8 it 265 ;* : is enabled automatically. Otherwise, simply 266 ;* : define _MTOS_ anytime before including this file. 267 ;* : For keeping code dense, all Eval*/Load*/Save* 268 ;* : macros are assumed to be called only while 269 ;* : interrupts are enabled, so it will not restore to 270 ;* : previous state but always leave as enabled. 271 ;* : Define _NOCLI_ (before including this module) for 272 ;* : canceling the _?SEI_ and _?CLI_ macro effects. 273 ;* : 13.04.18 v7.85 Added 'NeedMath' and 'Eval' general-purpose macros 274 ;* : for automatic selection of needed bit-size based 275 ;* : on only which modules are already included. First, 276 ;* : call the NeedMath macro to define the minimum math 277 ;* : bit-size you need for the next calculation(s), 278 ;* : then call the Eval macro as many times as needed 279 ;* : to perform the actual expression evaluation(s). 280 ;* : Similary, added new macros Load, Save, StkAdd, 281 ;* : StkSub, StkMul, StkDiv, StkMod, StkSwap, StkNeg, 282 ;* : StkAbs, StkStr, and CopyMath to work with the 283 ;* : NeedMath macro, just like the new Eval macro. 284 ;* : 13.04.19 v8.00 Moved all Eval* macros into COMMON.INC and allowed 285 ;* : for all to be active at all times, regardless if 286 ;* : the related bit-version of STAKMATH is included. 287 ;* : The _Eval_ macro was improved to allow it to 288 ;* : automatically locate the next higher version that 289 ;* : is included, if the one requested is not. So, 290 ;* : using Eval32 will use the 32/40/48/64-bit version 291 ;* : (whichever is closer to 32 and included) but nothing 292 ;* : below 32-bit. This allows you to use the relevant 293 ;* : macro based on a specific expression's requirements 294 ;* : but include only one (or just a few) higher bit 295 ;* : version(s), not all those referenced in your code. 296 ;* : (The general Eval is still available, if needed.) 297 ;* : Also, moved all Str* to COMMON.INC 298 ;* : 13.04.21 v8.10 Corrected v8.00 for pointer cases (.num) to use 299 ;* : actual requested size, not next higher. 300 ;* : Relevant #Message now in _DoOperation _ResizeTOS etc. 301 ;* : 13.04.21 v8.11 NeedMath & related macros removed (now redundant) 302 ;* : General Eval macro will try to determine best bit-size 303 ;* : 13.04.23 v8.12 Added EvalS to first check for SIGNED and then call Eval 304 ;* : CopyMath removed. Use "Eval to_var = from_var" instead 305 ;* : _StkMthMax_ improved to use higher size on multiplication 306 ;* : 13.04.25 v8.13 _Eval_ now allows for string constants (eg., @Eval ans = ans + '0') 307 ;* : Removed all ?macros because we now use COMMON xxx.s macros 308 ;* : 13.04.26 v8.15 Corrected test code for Eval when MATHSIZE < 32 309 ;* : Commented out auto-higher bit-size (a bit annoying). 310 ;* : Use Eval* to say 'no less than', instead. 311 ;* : 13.04.27 v8.16 BugFix: StrMath macro (2nd parameter was lost) 312 ;* : Added SQR() function to get the square 313 ;* : 13.05.02 Added #size in ToInt* macros (in test code) 314 ;* : 13.05.03 v8.17 Added size optimization for ADD and SUB operations 315 ;* : New SPEED_SIZE constant in COMMON.INC tells us 316 ;* : whether we need speed (SPEED_SIZE = 1) or 317 ;* : size (SPEED_SIZE = 2) optimization, the current 318 ;* : default being SPEED_SIZE = 2 for size optimization. 319 ;* : 13.05.30 Updated StrMath macro (COMMON.INC and here) 320 ;* : 13.06.04 v8.20 Added bit functions: AND (&), OR (|), XOR (^), and shifts (< and >) 321 ;* : 13.06.05 v8.21 BugFix: ShiftRight now uses ASR if SIGNED 322 ;* : 13.07.25 v8.22 Improved _Eval_ macro (and Push/Pull in COMMON.INC) 323 ;* : BugFix: Added { } to ResizeTOS macro's final case 324 ;* : (Disable bit functions with NO_BIT_OPS conditional) 325 ;* : 13.10.06 Minor changes in test code 326 ;* : 13.11.26 Added warning in _DoLoad: forwards treated as vars 327 ;* : 13.11.29 v8.23 Optimized ?ShiftLeft and ?ShiftRight a bit 328 ;* : 13.12.22 v8.30 Added 56-bit version 329 ;* : 14.01.03 Made use of _CMP_.S macro (instead of custom macro) 330 ;* : 14.02.07 v8.50 Added [ ... ] unsigned override (if SIGNED) 331 ;* : 14.02.14 v8.51 Eval macro now uses #HideMacros 332 ;* : 14.10.14 v8.52 BugFix: Off-by-one error in ResizeTOS when SIGNED 333 ;* : 15.03.21 v8.53 Replaced string dependencies with corresponding #Uses 334 ;* : 15.04.08 v8.54 Replaced AddDecimalPoint with corresponding #Uses 335 ;* : 17.04.03 v8.55 Optimized 24-bit multiply [-2 bytes] 336 ;* : Optimized 32-bit multiply [-7 bytes] 337 ;* : 18.10.23 Suppressed possible warning from JEQ in ?DivStart 338 ;* : 19.03.04 Added warning in _DoStr macro when using StrNN 339 ;* : when NN is different from MATHSIZE and no explicit 340 ;* : variable is given 341 ;* : 19.10.04 v8.56 Minor HC08 mode optimization in SIGNED ?ToStr [-1 byte] 342 ;* : 20.02.12 v8.57 Replaced #Message with @Msg to silence debugging messages 343 ;******************************************************************************* 344 345 ;Synopsis (replace * with 16, 24, 32, 40, 48, 56, 64 for corresponding bit version): 346 ; 347 ;Subroutines Action 348 ;-------------- ---------------------------- 349 ;StackAdd* - TOS := TOS + [TOS+1] (signed or unsigned) [TOS+1] removed 350 ;StackSub* - TOS := TOS - [TOS+1] (signed or unsigned) [TOS+1] removed 351 ;StackMul* - TOS := TOS * [TOS+1] (signed or unsigned) [TOS+1] removed 352 ;StackDiv* - TOS := TOS / [TOS+1] (signed if SIGNED) [TOS+1] removed 353 ;StackMod* - TOS := TOS \ [TOS+1] (signed if SIGNED) [TOS+1] removed 354 ;StackAnd* - TOS := TOS & [TOS+1] (signed or unsigned) [TOS+1] removed 355 ;StackOr* - TOS := TOS | [TOS+1] (signed or unsigned) [TOS+1] removed 356 ;StackXor* - TOS := TOS ^ [TOS+1] (signed or unsigned) [TOS+1] removed 357 ;StackShl* - TOS := TOS < [TOS+1] (signed or unsigned) [TOS+1] removed 358 ;StackShr* - TOS := TOS > [TOS+1] (signed if SIGNED) [TOS+1] removed 359 ;StackSwap* - TOS swapped with [TOS+1] (signed or unsigned) 360 ;StackAbs* - TOS := ABS(TOS) (signed) 361 ;StackNegate* - TOS := -TOS (signed) 362 ;StackLoad* - Load const/variable to TOS (signed or unsigned) TOS created 363 ;StackSave* - Save TOS into variable (signed or unsigned) TOS removed 364 ;ResizeTOS - Adjust TOS old size to new (signed or unsigned) TOS resized 365 ;Stack*ToASCIZ - Convert TOS to ASCIZ str (signed if SIGNED) 366 ; 367 ;Macros Purpose Parameters ([...] means optional part) 368 ;------------------ ------------------- ---------------------------------------- 369 ;Load* Stack const or var #Number | Variable 370 ;Save* Unstack a variable Variable 371 ;Copy* Load* & Save* #Number | Variable,Variable 372 ;ResizeTOS Resize TOS #FromByteSize,#ToByteSize 373 ; 374 ;Add* Addition [Addend[,Adder[,Sum]]] 375 ;Sub* Subtraction [Minuend[,Subtrahend[,Difference]]] 376 ;Mul* Multiplication [Multiplicand[,Multiplier[,Product]]] 377 ;Div* Unsigned division [Dividend[,Divisor[,Quotient]]] 378 ;Mod* Unsigned modulo [Dividend[,Divisor[,Remainder]]] 379 ;Abs* Absolute value [SourceVariable][,DestinationVariable] 380 ;Neg* Negation [SourceVariable][,DestinationVariable] 381 ;Swap* Swap TOS numbers 382 ;Str* Number to ASCIZ [Variable],[ResultString] 383 ;AddDecimalPoint ... to ASCIZ number [[#]DecimalPlaces[,[#]ASCIZ_String]] 384 411 412 0018 MATHSIZE def 32 ;default wordsize is 32-bit 413 417 418 ? macro BitSize 419 #if MATHSIZE = ~1~ 420 ?WORD equ ~1~/8 421 _STKMTH{MATHSIZE}_ ;;specific version included 422 _STAKMATH_ def * ;;any version included 423 #endif 424 endm 425 426 M @? 16 ;16-bit quantity (on request) 426 endm 427 M @? 24 ;24-bit quantity (on request) 427 M 0003 ?WORD equ 24/8 427 M 1F17 _STKMTH24_ 427 M 182C _STAKMATH_ def * 427 endm 428 M @? 32 ;32-bit quantity (default) 428 endm 429 M @? 40 ;40-bit quantity (on request) 429 endm 430 M @? 48 ;48-bit quantity (on request) 430 endm 431 M @? 56 ;56-bit quantity (on request) 431 endm 432 M @? 64 ;64-bit quantity (on request) 432 endm 433 439 #Message MATHSIZE = {MATHSIZE}-bit version 441 #Message Signed routines enabled 443 ;******************************************************************************* 444 ; Macros to make operations as simple as with a high-level language 445 ; In operations that require two operands and a result, if only one operand is 446 ; provided, then the operation is done completely on stack (no other variables 447 ; used). For example, @Add32 A,B,SUM adds A to B and places result in SUM, 448 ; while @Add32 A adds the current stack top to A and leaves result on stack. 449 ; You can use @Load* and @Save* to load the initial value, and store the final 450 ; result, respectively. (Replace * with 16, 24, 32, 40, 48, 56, or 64) 451 ;******************************************************************************* 452 501 ;=============================================================================== 503 504 Load24 macro #Number|Variable ;load constant or variable 505 @_DoLoad ~0.{:0-1}~\,~@~ 506 endm 507 508 Save24 macro Address 509 @_DoSave 24\,~@~ 510 endm 511 512 Copy24 macro #Constant|Variable,ToAddress 513 mreq 1,2:#Constant|Variable,ToAddress 514 @@Load24 ~1~ 515 @Save24 ~2~ 516 endm 517 518 Swap24 macro 519 @_DoSwap 24 520 endm 521 522 Add24 macro Addend,Adder,Sum 523 @_DoMath ~0~\,24\,~1~\,~2~\,~3~ 524 endm 525 526 Sub24 macro Minuend,Subtrahend,Difference 527 @_DoMath ~0~\,24\,~1~\,~2~\,~3~ 528 endm 529 530 Mul24 macro Multiplicand,Multiplier,Product 531 @_DoMath ~0~\,24\,~1~\,~2~\,~3~ 532 endm 533 534 Div24 macro Dividend,Divisor,Quotient 535 @_DoMath ~0~\,24\,~1~\,~2~\,~3~ 536 endm 537 538 Mod24 macro Dividend,Divisor,Remainder 539 @_DoMath ~0~\,24\,~1~\,~2~\,~3~ 540 endm 541 542 Abs24 macro Source[,Destination] 543 @_DoAbs 24\,~1~\,~2~ 544 endm 545 546 Neg24 macro Source[,Destination] 547 @_DoNeg 24\,~1~\,~2~ 548 endm 550 ;=============================================================================== 599 ;=============================================================================== 648 ;=============================================================================== 697 ;=============================================================================== 746 ;=============================================================================== 795 796 ;******************************************************************************* 797 ; Common macro(s) for all operations defined above (not to be called directly) 798 ;******************************************************************************* 799 807 ;------------------------------------------------------------------------------- 867 ;------------------------------------------------------------------------------- 890 ;------------------------------------------------------------------------------- 898 ;------------------------------------------------------------------------------- 916 ;=============================================================================== 933 ;------------------------------------------------------------------------------- 1158 ;------------------------------------------------------------------------------- 1185 ;------------------------------------------------------------------------------- 1212 ;------------------------------------------------------------------------------- 1288 ;------------------------------------------------------------------------------- 1328 ;------------------------------------------------------------------------------- 1337 ;------------------------------------------------------------------------------- 1351 ;------------------------------------------------------------------------------- 1380 ;------------------------------------------------------------------------------- 1398 ;------------------------------------------------------------------------------- 1416 ;------------------------------------------------------------------------------- 1451 1452 ;******************************************************************************* 1453 ; External dependencies 1454 ;******************************************************************************* 1455 1456 #Uses string/length.sub 1457 #Uses string/insertchar.sub 1458 #Uses string/adddecimalpoint.sub 1459 1F17 ?_OBJECT_? 1460 ;******************************************************************************* 1461 ; One-based (SP-index) offsets to stacked operands (to be used with #SPAUTO :AB) 1462 ;******************************************************************************* 1463 1464 #temp 1 1465 0001 ?a next :temp,?WORD ;top-of-stack (TOS) number (N1) 1466 0004 ?b next :temp,?WORD ;number after TOS (N2) 1467 1468 #Cycles ;reset the cycles counter 1469 1470 ;******************************************************************************* 1471 ; Purpose: Add N1 to N2 and place result on top-of-stack. N1 & N2 removed 1472 ; Input : [TOS+?WORD] = Number2 1473 ; : [TOS] = Number1 1474 ; Output : [TOS] = Result 1475 ; Note(s): Carry Set on overflow 1476 1477 #spauto :ab 1478 1479 1F17 ?Add proc 1480 [1F17] 1F17:8789 8B [ 6] push 1481 [1F1A] 1F1A:95 [ 2] tsx 1482 1488 [1F1B] 1F1B:A603 [ 2] lda #?WORD 1489 [1F1D] 1F1D:98 [ 1] clc 1490 #Cycles 1491 [1F1E] 1F1E:87 [ 2] Loop@@ psha 1492 [1F1F] 1F1F:E607 [ 3] lda ?a+{::?a-1},spx 1493 [1F21] 1F21:E90A [ 3] adc ?b+{::?b-1},spx 1494 [1F23] 1F23:E70A [ 3] sta ?b+{::?b-1},spx 1495 [1F25] 1F25:86 [ 3] pula 1496 [1F26] 1F26:AFFF [ 2] aix #-1 1497 [1F28] 1F28:4BF4 (1F1E) [ 4] dbnza Loop@@ 1498 #Cycles :cycles*?WORD+:ocycles 1500 [1F2A] 1F2A:CC21 74 [ 4] jmp ?RemoveAndReturn 1501 1502 004B ?AddCycles equ :cycles 1503 1504 ;******************************************************************************* 1505 ; Purpose: Subtract N2 from N1 and place result on top-of-stack. N1 & N2 removed 1506 ; Input : [TOS+?WORD] = Number2 1507 ; : [TOS] = Number1 1508 ; Output : [TOS] = Result 1509 ; Note(s): Carry Set on borrow 1510 1511 #spauto :ab 1512 1513 1F2D ?Subtract proc 1514 [1F2D] 1F2D:8789 8B [ 6] push 1515 [1F30] 1F30:95 [ 2] tsx 1521 [1F31] 1F31:A603 [ 2] lda #?WORD 1522 [1F33] 1F33:98 [ 1] clc 1523 #Cycles 1524 [1F34] 1F34:87 [ 2] Loop@@ psha 1525 [1F35] 1F35:E607 [ 3] lda ?a+{::?a-1},spx 1526 [1F37] 1F37:E20A [ 3] sbc ?b+{::?b-1},spx 1527 [1F39] 1F39:E70A [ 3] sta ?b+{::?b-1},spx 1528 [1F3B] 1F3B:86 [ 3] pula 1529 [1F3C] 1F3C:AFFF [ 2] aix #-1 1530 [1F3E] 1F3E:4BF4 (1F34) [ 4] dbnza Loop@@ 1531 #Cycles :cycles*?WORD+:ocycles 1533 [1F40] 1F40:CC21 74 [ 4] jmp ?RemoveAndReturn 1534 1535 004B ?SubCycles equ :cycles 1536 1540 M @Msg Bit ops enabled (define NO_BIT_OPS to disable) 1540 mexit 1541 ;******************************************************************************* 1542 ; Purpose: AND N1 with N2 and place result on top-of-stack. N1 & N2 removed 1543 ; Input : [TOS+?WORD] = Number2 1544 ; : [TOS] = Number1 1545 ; Output : [TOS] = Result 1546 ; Note(s): 1547 #spauto :ab 1548 1549 1F43 ?BitAnd proc 1550 [1F43] 1F43:8789 8B [ 6] push 1551 [1F46] 1F46:95 [ 2] tsx 1552 1558 [1F47] 1F47:A603 [ 2] lda #?WORD 1559 #Cycles 1560 [1F49] 1F49:87 [ 2] Loop@@ psha 1561 [1F4A] 1F4A:E607 [ 3] lda ?a+{::?a-1},spx 1562 [1F4C] 1F4C:E40A [ 3] and ?b+{::?b-1},spx 1563 [1F4E] 1F4E:E70A [ 3] sta ?b+{::?b-1},spx 1564 [1F50] 1F50:86 [ 3] pula 1565 [1F51] 1F51:AFFF [ 2] aix #-1 1566 [1F53] 1F53:4BF4 (1F49) [ 4] dbnza Loop@@ 1567 #Cycles :cycles*?WORD+:ocycles 1569 [1F55] 1F55:CC21 74 [ 4] jmp ?RemoveAndReturn 1570 1571 004A ?AndCycles equ :cycles 1572 1573 ;******************************************************************************* 1574 ; Purpose: OR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1575 ; Input : [TOS+?WORD] = Number2 1576 ; : [TOS] = Number1 1577 ; Output : [TOS] = Result 1578 ; Note(s): 1579 #spauto :ab 1580 1581 1F58 ?BitOr proc 1582 [1F58] 1F58:8789 8B [ 6] push 1583 [1F5B] 1F5B:95 [ 2] tsx 1584 1590 [1F5C] 1F5C:A603 [ 2] lda #?WORD 1591 #Cycles 1592 [1F5E] 1F5E:87 [ 2] Loop@@ psha 1593 [1F5F] 1F5F:E607 [ 3] lda ?a+{::?a-1},spx 1594 [1F61] 1F61:EA0A [ 3] ora ?b+{::?b-1},spx 1595 [1F63] 1F63:E70A [ 3] sta ?b+{::?b-1},spx 1596 [1F65] 1F65:86 [ 3] pula 1597 [1F66] 1F66:AFFF [ 2] aix #-1 1598 [1F68] 1F68:4BF4 (1F5E) [ 4] dbnza Loop@@ 1599 #Cycles :cycles*?WORD+:ocycles 1601 [1F6A] 1F6A:CC21 74 [ 4] jmp ?RemoveAndReturn 1602 1603 004A ?OrCycles equ :cycles 1604 1605 ;******************************************************************************* 1606 ; Purpose: XOR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1607 ; Input : [TOS+?WORD] = Number2 1608 ; : [TOS] = Number1 1609 ; Output : [TOS] = Result 1610 ; Note(s): 1611 #spauto :ab 1612 1613 1F6D ?BitXor proc 1614 [1F6D] 1F6D:8789 8B [ 6] push 1615 [1F70] 1F70:95 [ 2] tsx 1616 1622 [1F71] 1F71:A603 [ 2] lda #?WORD 1623 #Cycles 1624 [1F73] 1F73:87 [ 2] Loop@@ psha 1625 [1F74] 1F74:E607 [ 3] lda ?a+{::?a-1},spx 1626 [1F76] 1F76:E80A [ 3] eor ?b+{::?b-1},spx 1627 [1F78] 1F78:E70A [ 3] sta ?b+{::?b-1},spx 1628 [1F7A] 1F7A:86 [ 3] pula 1629 [1F7B] 1F7B:AFFF [ 2] aix #-1 1630 [1F7D] 1F7D:4BF4 (1F73) [ 4] dbnza Loop@@ 1631 #Cycles :cycles*?WORD+:ocycles 1633 [1F7F] 1F7F:CC21 74 [ 4] jmp ?RemoveAndReturn 1634 1635 004A ?EorCycles equ :cycles 1636 1637 ;******************************************************************************* 1638 ; Purpose: Shift N1 left N2 times and place result on top-of-stack. N1 & N2 removed 1639 ; Input : [TOS+?WORD] = Number2 1640 ; : [TOS] = Number1 1641 ; Output : [TOS] = Result 1642 ; Note(s): CCR[C] = last most significant bit shifted out 1643 ; : Only LSB of second operand (N2) is used, as shifting more than the 1644 ; : highest bit version always produces zero. Any non-zero bytes in the 1645 ; : N2 operand will cause a zero result, regardless. 1646 1647 #spauto :ab 1648 1649 1F82 ?ShiftLeft proc 1650 [1F82] 1F82:8789 8B [ 6] push 1651 #ais 1652 1653 [1F85] 1F85:9EE6 0B [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1654 [1F88] 1F88:87 [ 2] psha counter@@ 1655 1656 [1F89] 1F89:95 [ 2] tsx 1657 1658 [1F8A] 1F8A:6F0B [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1659 0004 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1660 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1660 M mset # 1660 M mreq 1 1660 M @@_nosize_ b48,spx 1660 M mset # 1660 M mset 0,mstop [_tst_.s] No size (b48,spx) 1660 M endm 1660 M mdo 1660 M [1F8C] 1F8C:E609 [ 3] lda b48+0,spx 1660 M mloop ::b48 1660 M [1F8E] 1F8E:EA0A [ 3] ora b48+1,spx 1660 M mloop ::b48 1660 endm 1661 [1F90] 1F90:270B (1F9D) [ 3] beq Go@@ ;if so, proceed normally 1662 1663 [1F92] 1F92:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1664 [1F93] 1F93:A118 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1665 [1F95] 1F95:2506 (1F9D) [ 3] blo Go@@ ;else zero and exit 1666 1667 M @clr.s, b@@,spx ;else error, so zero result 1667 M mset #' ' 1667 M mreq 1 1667 M @@_nosize_ b48,spx 1667 M mset # 1667 M mset 0,mstop [clr.s] No size (b48,spx) 1667 M endm 1667 M mdef 2,::b48 1667 M mdo 1667 M [1F97] 1F97:6F09 [ 5] clr b48+0,spx 1667 M mloop ::b48 1667 M [1F99] 1F99:6F0A [ 5] clr b48+1,spx 1667 M mloop ::b48 1667 endm 1668 [1F9B] 1F9B:2014 (1FB1) [ 3] bra Done@@ ;and get out 1669 1670 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1670 M mset #' ' 1670 M mreq 1,2:Source Destination 1670 M @@_samesize_ ?a,spx ?b,spx 1670 M mreq 1,2:Operand1,Operand2[,Operand]* 1670 M mset 0 1670 M mdo 1670 M mswap 1,1 1670 M @@_nosize_ ?a,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?a,spx) 1670 M endm 1670 M mset 0,?a,spx 1670 M mloop :n 1670 M mswap 1,2 1670 M @@_nosize_ ?b,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?b,spx) 1670 M endm 1670 M mloop :n 1670 M endm 1670 M mset 0 1670 M mdo 1670 M [1F9D] 1F9D:E606 [ 3] lda ?a+0,spx 1670 M [1F9F] 1F9F:E709 [ 3] sta ?b+0,spx 1670 M mloop ::?b 1670 M [1FA1] 1FA1:E607 [ 3] lda ?a+1,spx 1670 M [1FA3] 1FA3:E70A [ 3] sta ?b+1,spx 1670 M mloop ::?b 1670 M [1FA5] 1FA5:E608 [ 3] lda ?a+2,spx 1670 M [1FA7] 1FA7:E70B [ 3] sta ?b+2,spx 1670 M mloop ::?b 1670 endm 1671 #Cycles 1672 M Loop@@ @lsl.s, ?b,spx ;shift left one bit position 1672 M mset # 1672 M mreq 1 1672 M @@_nosize_ ?b,spx 1672 M mset # 1672 M mset 0,mstop [lsl.s] No size (?b,spx) 1672 M endm 1672 M mdo 1672 M [1FA9] 1FA9:680B [ 5] lsl ?b+2,spx 1672 M mloop ::?b 1672 M [1FAB] 1FAB:690A [ 5] rol ?b+1,spx 1672 M mloop ::?b 1672 M [1FAD] 1FAD:6909 [ 5] rol ?b+0,spx 1672 M mloop ::?b 1672 endm 1673 [1FAF] 1FAF:7BF8 (1FA9) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1674 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1675 1FB1 Done@@ 1677 [1FB1] 1FB1:86 [ 3] pula 1681 [1FB2] 1FB2:CC21 74 [ 4] jmp ?RemoveAndReturn 1682 1683 022D ?ShlCycles equ :cycles 1684 1685 ;******************************************************************************* 1686 ; Purpose: Shift N1 right N2 times and place result on top-of-stack. N1 & N2 removed 1687 ; Input : [TOS+?WORD] = Number2 1688 ; : [TOS] = Number1 1689 ; Output : [TOS] = Result 1690 ; Note(s): CCR[C] = last least significant bit shifted out 1691 ; : Only LSB of second operand (N2) is used, as shifting more than the 1692 ; : highest bit version always produces zero. Any non-zero bytes in the 1693 ; : N2 operand will cause a zero result, regardless. 1694 1695 #spauto :ab 1696 1697 1FB5 ?ShiftRight proc 1698 [1FB5] 1FB5:8789 8B [ 6] push 1699 #ais 1700 1701 [1FB8] 1FB8:9EE6 0B [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1702 [1FBB] 1FBB:87 [ 2] psha counter@@ 1703 1704 [1FBC] 1FBC:95 [ 2] tsx 1705 1706 [1FBD] 1FBD:6F0B [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1707 0004 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1708 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1708 M mset # 1708 M mreq 1 1708 M @@_nosize_ b49,spx 1708 M mset # 1708 M mset 0,mstop [_tst_.s] No size (b49,spx) 1708 M endm 1708 M mdo 1708 M [1FBF] 1FBF:E609 [ 3] lda b49+0,spx 1708 M mloop ::b49 1708 M [1FC1] 1FC1:EA0A [ 3] ora b49+1,spx 1708 M mloop ::b49 1708 endm 1709 [1FC3] 1FC3:270B (1FD0) [ 3] beq Go@@ ;if so, proceed normally 1710 1711 [1FC5] 1FC5:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1712 [1FC6] 1FC6:A118 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1713 [1FC8] 1FC8:2506 (1FD0) [ 3] blo Go@@ ;else zero and exit 1714 1715 M @clr.s, b@@,spx ;else error, so zero result 1715 M mset #' ' 1715 M mreq 1 1715 M @@_nosize_ b49,spx 1715 M mset # 1715 M mset 0,mstop [clr.s] No size (b49,spx) 1715 M endm 1715 M mdef 2,::b49 1715 M mdo 1715 M [1FCA] 1FCA:6F09 [ 5] clr b49+0,spx 1715 M mloop ::b49 1715 M [1FCC] 1FCC:6F0A [ 5] clr b49+1,spx 1715 M mloop ::b49 1715 endm 1716 [1FCE] 1FCE:2014 (1FE4) [ 3] bra Done@@ ;and get out 1717 1718 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1718 M mset #' ' 1718 M mreq 1,2:Source Destination 1718 M @@_samesize_ ?a,spx ?b,spx 1718 M mreq 1,2:Operand1,Operand2[,Operand]* 1718 M mset 0 1718 M mdo 1718 M mswap 1,1 1718 M @@_nosize_ ?a,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?a,spx) 1718 M endm 1718 M mset 0,?a,spx 1718 M mloop :n 1718 M mswap 1,2 1718 M @@_nosize_ ?b,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?b,spx) 1718 M endm 1718 M mloop :n 1718 M endm 1718 M mset 0 1718 M mdo 1718 M [1FD0] 1FD0:E606 [ 3] lda ?a+0,spx 1718 M [1FD2] 1FD2:E709 [ 3] sta ?b+0,spx 1718 M mloop ::?b 1718 M [1FD4] 1FD4:E607 [ 3] lda ?a+1,spx 1718 M [1FD6] 1FD6:E70A [ 3] sta ?b+1,spx 1718 M mloop ::?b 1718 M [1FD8] 1FD8:E608 [ 3] lda ?a+2,spx 1718 M [1FDA] 1FDA:E70B [ 3] sta ?b+2,spx 1718 M mloop ::?b 1718 endm 1719 #Cycles 1720 1FDC Loop@@ 1722 M @asr.s, ?b,spx ;shift right one bit position 1722 M mset # 1722 M mreq 1 1722 M @@_nosize_ ?b,spx 1722 M mset # 1722 M mset 0,mstop [asr.s] No size (?b,spx) 1722 M endm 1722 M mdo 1722 M [1FDC] 1FDC:6709 [ 5] asr ?b+0,spx 1722 M mloop ::?b 1722 M [1FDE] 1FDE:660A [ 5] ror ?b+1,spx 1722 M mloop ::?b 1722 M [1FE0] 1FE0:660B [ 5] ror ?b+2,spx 1722 M mloop ::?b 1722 endm 1726 [1FE2] 1FE2:7BF8 (1FDC) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1727 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1728 1FE4 Done@@ 1730 [1FE4] 1FE4:86 [ 3] pula 1734 [1FE5] 1FE5:CC21 74 [ 4] jmp ?RemoveAndReturn 1735 1736 022D ?ShrCycles equ :cycles 1738 1739 ;******************************************************************************* 1740 ; Purpose: Multiply N1 with N2 and place result on top-of-stack. N1 & N2 removed 1741 ; Input : [TOS+?WORD] = Number2 1742 ; : [TOS] = Number1 1743 ; Output : [TOS] = Result 1744 ; Note(s): Overflows lost, Carry state should be ignored 1745 1746 #spauto :ab 1747 1748 1FE8 ?Multiply proc 1749 [1FE8] 1FE8:8789 8B [ 6] push 1773 ;=============================================================================== 1775 ;-------------------------------------- ;row 1 1776 [1FEB] 1FEB:95 [ 2] tsx 1777 [1FEC] 1FEC:E607 [ 3] lda ?a+2,spx 1778 [1FEE] 1FEE:EE0A [ 3] ldx ?b+2,spx 1779 [1FF0] 1FF0:42 [ 5] mul 1780 [1FF1] 1FF1:8789 [ 4] pshxa ans@@ ;temporary 24-bit result (2nd & 3rd bytes) 1781 1782 [1FF3] 1FF3:95 [ 2] tsx 1783 [1FF4] 1FF4:E609 [ 3] lda ?a+2,spx 1784 [1FF6] 1FF6:EE0B [ 3] ldx ?b+1,spx 1785 [1FF8] 1FF8:42 [ 5] mul 1786 [1FF9] 1FF9:89 [ 2] pshx ans@@,3 ;temporary 24-bit result (1st byte) 1787 1788 [1FFA] 1FFA:95 [ 2] tsx 1789 [1FFB] 1FFB:EB01 [ 3] add ans@@+1,spx 1790 [1FFD] 1FFD:E701 [ 3] sta ans@@+1,spx 1791 [1FFF] 1FFF:4F [ 1] clra 1792 [2000] 2000:F9 [ 3] adc ans@@,spx 1793 [2001] 2001:F7 [ 2] sta ans@@,spx 1794 1795 [2002] 2002:E60A [ 3] lda ?a+2,spx 1796 [2004] 2004:EE0B [ 3] ldx ?b+0,spx 1797 [2006] 2006:42 [ 5] mul 1798 [2007] 2007:95 [ 2] tsx 1799 [2008] 2008:FB [ 3] add ans@@,spx 1800 [2009] 2009:F7 [ 2] sta ans@@,spx 1801 ;-------------------------------------- ;row 2 1802 [200A] 200A:E609 [ 3] lda ?a+1,spx 1803 [200C] 200C:EE0D [ 3] ldx ?b+2,spx 1804 [200E] 200E:42 [ 5] mul 1805 [200F] 200F:9EEB 02 [ 4] add ans@@+1,sp 1806 [2012] 2012:9EE7 02 [ 4] sta ans@@+1,sp 1807 [2015] 2015:9F [ 1] txa 1808 [2016] 2016:95 [ 2] tsx 1809 [2017] 2017:F9 [ 3] adc ans@@,spx 1810 [2018] 2018:F7 [ 2] sta ans@@,spx 1811 1812 [2019] 2019:E609 [ 3] lda ?a+1,spx 1813 [201B] 201B:EE0C [ 3] ldx ?b+1,spx 1814 [201D] 201D:42 [ 5] mul 1815 [201E] 201E:95 [ 2] tsx 1816 [201F] 201F:FB [ 3] add ans@@,spx 1817 [2020] 2020:F7 [ 2] sta ans@@,spx 1818 ;-------------------------------------- ;row 3 1819 [2021] 2021:E608 [ 3] lda ?a+0,spx 1820 [2023] 2023:EE0D [ 3] ldx ?b+2,spx 1821 [2025] 2025:42 [ 5] mul 1822 [2026] 2026:95 [ 2] tsx 1823 [2027] 2027:FB [ 3] add ans@@,spx 1824 [2028] 2028:F7 [ 2] sta ans@@,spx 1826 ;=============================================================================== 1913 #temp :cycles 1914 ;=============================================================================== 1915 ;-------------------------------------- 1916 ; 40, 48, 56, and 64-bit versions use shorter 1917 ; shift/add method (more cycles, though) 1918 ;-------------------------------------- 1945 ;-------------------------------------- 1946 ; copy result to B while removing from stack 1947 ;-------------------------------------- 1948 [2029] 2029:AE03 [ 2] ldx #?WORD 1949 #temp :cycles+:temp 1950 [202B] 202B:86 [ 3] CopyResult@@ pula 1951 [202C] 202C:9EE7 0B [ 4] sta ?b,sp 1952 [202F] 202F:5BFA (202B) [ 4] dbnzx CopyResult@@ 1953 1954 #spadd 1-?WORD 1955 #temp :cycles*?WORD+:temp 1956 [2031] 2031:CC21 74 [ 4] jmp ?RemoveAndReturn 1957 1958 00AC ?MulCycles equ :temp+:cycles 1959 1960 ;******************************************************************************* 1961 ; Purpose: Divide N1 by N2 and place quotient on top-of-stack. N1 & N2 removed 1962 ; Input : [TOS+?WORD] = Divisor (N2) 1963 ; : [TOS] = Dividend (N1) 1964 ; Output : [TOS] = Quotient 1965 ; : Carry Set on error (division by zero) 1966 ; Note(s): 1967 #spauto :ab 1968 1969 2034 ?Divide proc 1970 [2034] 2034:8789 8B [ 6] push 1971 1972 [2037] 2037:A601 [ 2] lda #?DIVOP_ ;flag for DIV operation 1974 [2039] 2039:87 [ 2] psha 1975 [203A] 203A:95 [ 2] tsx 1976 [203B] 203B:E606 [ 3] lda ?a,spx 1977 [203D] 203D:E809 [ 3] eor ?b,spx 1978 [203F] 203F:86 [ 3] pula 1979 [2040] 2040:2A02 (2044) [ 3] bpl Skip@@ 1980 [2042] 2042:AA80 [ 2] ora #?SIGN_ ;flag for negative 1981 2044 Skip@@ 1983 [2044] 2044:87 [ 2] psha ;save flags on stack 1984 [2045] 2045:2024 (206B) [ 3] bra ?DivStart 1985 1986 001F ?DivCycles equ :cycles 1987 1988 ;******************************************************************************* 1989 ; Purpose: Divide N1 by N2 and place remainder on top-of-stack. N1 & N2 removed 1990 ; Input : [TOS+?WORD] = Divisor (N2) 1991 ; : [TOS] = Dividend (N1) 1992 ; Output : [TOS] = Remainder 1993 ; : Carry Set on error (division by zero) 1994 ; Note(s): 1995 #spauto :ab 1996 FFFFFFFF ?pc equ ::,:ab 1997 1998 2047 ?Modulo proc 1999 [2047] 2047:8789 8B [ 6] push 2000 2001 [204A] 204A:4F [ 1] clra ;flag for MOD operation 2003 [204B] 204B:9E6D 06 [ 5] tst ?a,sp 2004 [204E] 204E:2A02 (2052) [ 3] bpl Skip@@ 2005 [2050] 2050:AA80 [ 2] ora #?SIGN_ ;flag for negative 2006 2052 Skip@@ 2008 [2052] 2052:87 [ 2] psha ;save flags on stack 2009 [2053] 2053:2016 (206B) [ 3] bra ?DivStart 2010 2011 0016 ?ModCycles equ :cycles 2012 2013 ;******************************************************************************* 2014 2015 #temp 2017 2055 ?AbsX proc 2018 [2055] 2055:7D [ 3] tst ,ax 2019 [2056] 2056:2A0C (2064) [ 3] bpl Done@@ 2020 #temp :cycles 2021 0000 var@@ equ 0,?WORD 2022 M ?NegX @neg.s var@@,ax 2022 M mset # 2022 M mreq 1 2022 M @@_nosize_ var53,ax 2022 M mset # 2022 M mset 0,mstop [neg.s] No size (var53,ax) 2022 M endm 2022 M mdo 2022 M [2058] 2058:73 [ 4] com var53+0,ax 2022 M mloop ::var53-1 2022 M [2059] 2059:6301 [ 5] com var53+1,ax 2022 M mloop ::var53-1 2022 M [205B] 205B:6002 [ 5] neg var53+2,ax 2022 M mdo 2022 M [205D] 205D:2605 (2064) [ 3] bne Done$$$ 2022 M [205F] 205F:6C01 [ 5] inc var53+1,ax 2022 M mloop ::var53-1 2022 M [2061] 2061:2601 (2064) [ 3] bne Done$$$ 2022 M [2063] 2063:7C [ 4] inc var53+0,ax 2022 M mloop ::var53-1 2022 M 2064 Done$$$ 2022 endm 2023 [2064] 2064:81 [ 6] Done@@ rts 2024 2025 0023 ?AbsXCycles equ :cycles 2026 001D ?NegxCycles equ ?AbsXCycles-:temp 2028 2029 ;******************************************************************************* 2030 2031 0000 ?SF equ 0 ;stack frame (for X-index use) 2032 2033 0000 ?quotient next ?SF,?WORD 2034 0003 ?remainder next ?SF,?WORD 2035 0006 ?temp next ?SF,?WORD 2036 0009 ?bits next ?SF 2037 000A ?flags next ?SF 2038 2039 0001 ?DIVOP_ equ %00000001 ;1 = DIV, 0 = MOD 2040 0080 ?SIGN_ equ %10000000 ;result sign (1 = negative) 2041 2042 #push 2043 2044 [2065] 2065:A70B [ 2] ?DivError ais #?SF ;de-allocate temporaries 2045 [2067] 2067:99 [ 1] sec ;indicate error condition 2046 [2068] 2068:CC21 74 [ 4] jmp ?RemoveAndReturn 2047 2048 #pull 2049 ;------------------------------------------------------------------------------- 2050 206B ?DivStart proc 2051 0001 dividend@@ equ ?a,::?a 2052 0004 divisor@@ equ ?b,::?b 2053 0004 ans@@ equ ?b,::?b ;result overwrites divisor 2054 2056 M @lea dividend@@,sp 2056 M mset # 2056 M [206B] 206B:95 [ 2] tsx 2056 M [206C] 206C:AF06 [ 2] !aix #dividend54+:tsx 2056 mexit 2057 [206E] 206E:ADE5 (2055) [ 5] bsr ?AbsX 2058 M @lea divisor@@,sp 2058 M mset # 2058 M [2070] 2070:95 [ 2] tsx 2058 M [2071] 2071:AF09 [ 2] !aix #divisor54+:tsx 2058 mexit 2059 [2073] 2073:ADE0 (2055) [ 5] bsr ?AbsX 2060 #Cycles ?AbsXCycles*2+:cycles 2062 [2075] 2075:A7F6 [ 2] ais #-?SF+1 ;quotient, remainder, and temp 2063 [2077] 2077:95 [ 2] tsx ;(+1 for already pushed Flag) 2064 2065 ; remainder := 0 2066 ; quotient := 0 2067 2068 M @clr.s ?remainder,x 2068 M mset #' ' 2068 M mreq 1 2068 M @@_nosize_ ?remainder,x 2068 M mset # 2068 M mset 0,mstop [clr.s] No size (?remainder,x) 2068 M endm 2068 M mdef 2,::?remainder 2068 M mdo 2068 M [2078] 2078:6F03 [ 5] clr ?remainder+0,x 2068 M mloop ::?remainder 2068 M [207A] 207A:6F04 [ 5] clr ?remainder+1,x 2068 M mloop ::?remainder 2068 M [207C] 207C:6F05 [ 5] clr ?remainder+2,x 2068 M mloop ::?remainder 2068 endm 2069 M @clr.s ?quotient,x 2069 M mset #' ' 2069 M mreq 1 2069 M @@_nosize_ ?quotient,x 2069 M mset # 2069 M mset 0,mstop [clr.s] No size (?quotient,x) 2069 M endm 2069 M mdef 2,::?quotient 2069 M mdo 2069 M [207E] 207E:7F [ 4] clr ?quotient+0,x 2069 M mloop ::?quotient 2069 M [207F] 207F:6F01 [ 5] clr ?quotient+1,x 2069 M mloop ::?quotient 2069 M [2081] 2081:6F02 [ 5] clr ?quotient+2,x 2069 M mloop ::?quotient 2069 endm 2070 2071 ; first, test for division by zero error 2072 2073 M @_tst_.s divisor@@,spx 2073 M mset # 2073 M mreq 1 2073 M @@_nosize_ divisor54,spx 2073 M mset # 2073 M mset 0,mstop [_tst_.s] No size (divisor54,spx) 2073 M endm 2073 M mdo 2073 M [2083] 2083:E613 [ 3] lda divisor54+0,spx 2073 M mloop ::divisor54 2073 M [2085] 2085:EA14 [ 3] ora divisor54+1,spx 2073 M mloop ::divisor54 2073 M [2087] 2087:EA15 [ 3] ora divisor54+2,spx 2073 M mloop ::divisor54 2073 endm 2074 [2089] 2089:27DA (2065) [ 3] beq ?DivError 2075 2076 ; if Dividend = 0, we're done 2077 2078 M @_tst_.s dividend@@,spx 2078 M mset # 2078 M mreq 1 2078 M @@_nosize_ dividend54,spx 2078 M mset # 2078 M mset 0,mstop [_tst_.s] No size (dividend54,spx) 2078 M endm 2078 M mdo 2078 M [208B] 208B:E610 [ 3] lda dividend54+0,spx 2078 M mloop ::dividend54 2078 M [208D] 208D:EA11 [ 3] ora dividend54+1,spx 2078 M mloop ::dividend54 2078 M [208F] 208F:EA12 [ 3] ora dividend54+2,spx 2078 M mloop ::dividend54 2078 endm 2079 [2091] 2091:2603 CC21 48 [ 7] !jeq Done@@ 2080 2081 ; if (divisor = dividend) then quotient := 1; return 2082 ; if (divisor > dividend) then remainder := dividend; return 2083 2084 M @_cmp_.s divisor@@,spx dividend@@,spx 2084 M mset #' ' 2084 M mreq 1,2:[#]Operand1 [#]Operand2 2084 M @@_samesize_ divisor54,spx dividend@@,spx 2084 M mreq 1,2:Operand1,Operand2[,Operand]* 2084 M mset 0 2084 M mdo 2084 M mswap 1,1 2084 M @@_nosize_ divisor54,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (divisor54,spx) 2084 M endm 2084 M mset 0,divisor54,spx 2084 M mloop :n 2084 M mswap 1,2 2084 M @@_nosize_ dividend@@,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (dividend54,spx) 2084 M endm 2084 M mloop :n 2084 M endm 2084 M #temp 1 2084 M #temp ::divisor54 2084 M #temp ::dividend@@ 2084 M mdo 2084 M [2096] 2096:E613 [ 3] lda divisor54+0,spx 2084 M [2098] 2098:E110 [ 3] cmpa dividend@@+0,spx 2084 M [209A] 209A:260A (20A6) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [209C] 209C:E614 [ 3] lda divisor54+1,spx 2084 M [209E] 209E:E111 [ 3] cmpa dividend@@+1,spx 2084 M [20A0] 20A0:2604 (20A6) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [20A2] 20A2:E615 [ 3] lda divisor54+2,spx 2084 M [20A4] 20A4:E112 [ 3] cmpa dividend@@+2,spx 2084 M mloop :temp 2084 M 20A6 Done$$$ 2084 endm 2085 [20A6] 20A6:2604 (20AC) [ 3] bne NotEqual@@ 2086 2087 [20A8] 20A8:6C02 [ 5] inc ?quotient+{::?quotient-1},x ;quotient := 1 2088 [20AA] 20AA:200E (20BA) [ 3] bra ??DivExit ;and get out 2089 2090 20AC NotEqual@@ ;@sub.s divisor@@,spx dividend@@,spx ;[2012.05.18 REDUNDANT] 2091 [20AC] 20AC:250F (20BD) [ 3] blo Continue@@ 2092 2093 M @mova.s dividend@@,spx ?remainder,x 2093 M mset #' ' 2093 M mreq 1,2:Source Destination 2093 M @@_samesize_ dividend54,spx ?remainder,x 2093 M mreq 1,2:Operand1,Operand2[,Operand]* 2093 M mset 0 2093 M mdo 2093 M mswap 1,1 2093 M @@_nosize_ dividend54,spx 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (dividend54,spx) 2093 M endm 2093 M mset 0,dividend54,spx 2093 M mloop :n 2093 M mswap 1,2 2093 M @@_nosize_ ?remainder,x 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (?remainder,x) 2093 M endm 2093 M mloop :n 2093 M endm 2093 M mset 0 2093 M mdo 2093 M [20AE] 20AE:E610 [ 3] lda dividend54+0,spx 2093 M [20B0] 20B0:E703 [ 3] sta ?remainder+0,x 2093 M mloop ::?remainder 2093 M [20B2] 20B2:E611 [ 3] lda dividend54+1,spx 2093 M [20B4] 20B4:E704 [ 3] sta ?remainder+1,x 2093 M mloop ::?remainder 2093 M [20B6] 20B6:E612 [ 3] lda dividend54+2,spx 2093 M [20B8] 20B8:E705 [ 3] sta ?remainder+2,x 2093 M mloop ::?remainder 2093 endm 2094 20BA ??DivExit ;and get out 2098 [20BA] 20BA:CC21 48 [ 4] jmp Done@@ 2100 2101 [20BD] 20BD:A618 [ 2] Continue@@ lda #MATHSIZE 2102 [20BF] 20BF:E709 [ 3] sta ?bits,x ;bits := 64/56/48/40/32/24/16-bit 2103 2104 ; while (remainder < divisor) do 2105 2106 M While@@ @cop ;in case of many iterations 2106 M [20C1] 20C1:C718 00 [ 4] sta COP 2106 endm 2107 2108 M @sub.s ?remainder,x divisor@@,spx 2108 M mset #' ' 2108 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2108 M @@_samesize_ ?remainder,x divisor54,spx 2108 M mreq 1,2:Operand1,Operand2[,Operand]* 2108 M mset 0 2108 M mdo 2108 M mswap 1,1 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (?remainder,x) 2108 M endm 2108 M mset 0,?remainder,x 2108 M mloop :n 2108 M mswap 1,2 2108 M @@_nosize_ divisor54,spx 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (divisor54,spx) 2108 M endm 2108 M mloop :n 2108 M endm 2108 M #temp 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [sub.s] No size (?remainder,x) 2108 M endm 2108 M #temp ::?remainder 2108 M mset 0,sub 2108 M mdo 2108 M [20C4] 20C4:E605 [ 3] lda ?remainder+2,x 2108 M [20C6] 20C6:E015 [ 3] sub divisor54+2,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [20C8] 20C8:E604 [ 3] lda ?remainder+1,x 2108 M [20CA] 20CA:E214 [ 3] sbc divisor54+1,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [20CC] 20CC:E603 [ 3] lda ?remainder+0,x 2108 M [20CE] 20CE:E213 [ 3] sbc divisor54+0,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 endm 2109 [20D0] 20D0:241C (20EE) [ 3] bcc EndWhile@@ 2110 2111 ; remainder := (remainder shl 1) or msb(dividend) 2112 ;-------------------------------------- ;2012.12.04 optimization (moved up this code from before DEC to here) 2113 M @mova.s dividend@@,spx ?temp,x ; temp := dividend 2113 M mset #' ' 2113 M mreq 1,2:Source Destination 2113 M @@_samesize_ dividend54,spx ?temp,x 2113 M mreq 1,2:Operand1,Operand2[,Operand]* 2113 M mset 0 2113 M mdo 2113 M mswap 1,1 2113 M @@_nosize_ dividend54,spx 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (dividend54,spx) 2113 M endm 2113 M mset 0,dividend54,spx 2113 M mloop :n 2113 M mswap 1,2 2113 M @@_nosize_ ?temp,x 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (?temp,x) 2113 M endm 2113 M mloop :n 2113 M endm 2113 M mset 0 2113 M mdo 2113 M [20D2] 20D2:E610 [ 3] lda dividend54+0,spx 2113 M [20D4] 20D4:E706 [ 3] sta ?temp+0,x 2113 M mloop ::?temp 2113 M [20D6] 20D6:E611 [ 3] lda dividend54+1,spx 2113 M [20D8] 20D8:E707 [ 3] sta ?temp+1,x 2113 M mloop ::?temp 2113 M [20DA] 20DA:E612 [ 3] lda dividend54+2,spx 2113 M [20DC] 20DC:E708 [ 3] sta ?temp+2,x 2113 M mloop ::?temp 2113 endm 2114 M @lsl.s dividend@@,spx ; dividend := dividend shl 1 2114 M mset # 2114 M mreq 1 2114 M @@_nosize_ dividend54,spx 2114 M mset # 2114 M mset 0,mstop [lsl.s] No size (dividend54,spx) 2114 M endm 2114 M mdo 2114 M [20DE] 20DE:6812 [ 5] lsl dividend54+2,spx 2114 M mloop ::dividend54 2114 M [20E0] 20E0:6911 [ 5] rol dividend54+1,spx 2114 M mloop ::dividend54 2114 M [20E2] 20E2:6910 [ 5] rol dividend54+0,spx 2114 M mloop ::dividend54 2114 endm 2115 ;-------------------------------------- 2116 M @rol.s ?remainder,x 2116 M mset # 2116 M mreq 1 2116 M @@_nosize_ ?remainder,x 2116 M mset # 2116 M mset 0,mstop [rol.s] No size (?remainder,x) 2116 M endm 2116 M mdo 2116 M [20E4] 20E4:6905 [ 5] rol ?remainder+2,x 2116 M mloop ::?remainder 2116 M [20E6] 20E6:6904 [ 5] rol ?remainder+1,x 2116 M mloop ::?remainder 2116 M [20E8] 20E8:6903 [ 5] rol ?remainder+0,x 2116 M mloop ::?remainder 2116 endm 2117 [20EA] 20EA:6A09 [ 5] dec ?bits,x ; bits := bits - 1 2118 2119 ; end while 2120 2121 [20EC] 20EC:20D3 (20C1) [ 3] bra While@@ 2122 20EE EndWhile@@ 2123 M @mova.s ?temp,x dividend@@,spx ; dividend := temp 2123 M mset #' ' 2123 M mreq 1,2:Source Destination 2123 M @@_samesize_ ?temp,x dividend54,spx 2123 M mreq 1,2:Operand1,Operand2[,Operand]* 2123 M mset 0 2123 M mdo 2123 M mswap 1,1 2123 M @@_nosize_ ?temp,x 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (?temp,x) 2123 M endm 2123 M mset 0,?temp,x 2123 M mloop :n 2123 M mswap 1,2 2123 M @@_nosize_ dividend54,spx 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (dividend54,spx) 2123 M endm 2123 M mloop :n 2123 M endm 2123 M mset 0 2123 M mdo 2123 M [20EE] 20EE:E606 [ 3] lda ?temp+0,x 2123 M [20F0] 20F0:E710 [ 3] sta dividend54+0,spx 2123 M mloop ::dividend54 2123 M [20F2] 20F2:E607 [ 3] lda ?temp+1,x 2123 M [20F4] 20F4:E711 [ 3] sta dividend54+1,spx 2123 M mloop ::dividend54 2123 M [20F6] 20F6:E608 [ 3] lda ?temp+2,x 2123 M [20F8] 20F8:E712 [ 3] sta dividend54+2,spx 2123 M mloop ::dividend54 2123 endm 2124 M @lsr.s ?remainder,x ; remainder := remainder shr 1 2124 M mset # 2124 M mreq 1 2124 M @@_nosize_ ?remainder,x 2124 M mset # 2124 M mset 0,mstop [lsr.s] No size (?remainder,x) 2124 M endm 2124 M mdo 2124 M [20FA] 20FA:6403 [ 5] lsr ?remainder+0,x 2124 M mloop ::?remainder 2124 M [20FC] 20FC:6604 [ 5] ror ?remainder+1,x 2124 M mloop ::?remainder 2124 M [20FE] 20FE:6605 [ 5] ror ?remainder+2,x 2124 M mloop ::?remainder 2124 endm 2125 [2100] 2100:6C09 [ 5] inc ?bits,x ; bits := bits + 1 2126 2127 ; for i := bitCounter-1 downto 0 do 2128 2129 M For@@ @cop ;in case of many iterations 2129 M [2102] 2102:C718 00 [ 4] sta COP 2129 endm 2130 2131 [2105] 2105:6D09 [ 4] tst ?bits,x 2133 [2107] 2107:273F (2148) [ 3] beq Done@@ 2137 [2109] 2109:6A09 [ 5] dec ?bits,x 2138 2139 ; remainder := (remainder shl 1) or msb(dividend) 2140 ; dividend := dividend shl 1 2141 2142 M @lsl.s dividend@@,spx ;2012.12.04 optimization 2142 M mset # 2142 M mreq 1 2142 M @@_nosize_ dividend54,spx 2142 M mset # 2142 M mset 0,mstop [lsl.s] No size (dividend54,spx) 2142 M endm 2142 M mdo 2142 M [210B] 210B:6812 [ 5] lsl dividend54+2,spx 2142 M mloop ::dividend54 2142 M [210D] 210D:6911 [ 5] rol dividend54+1,spx 2142 M mloop ::dividend54 2142 M [210F] 210F:6910 [ 5] rol dividend54+0,spx 2142 M mloop ::dividend54 2142 endm 2143 M @rol.s ?remainder,x 2143 M mset # 2143 M mreq 1 2143 M @@_nosize_ ?remainder,x 2143 M mset # 2143 M mset 0,mstop [rol.s] No size (?remainder,x) 2143 M endm 2143 M mdo 2143 M [2111] 2111:6905 [ 5] rol ?remainder+2,x 2143 M mloop ::?remainder 2143 M [2113] 2113:6904 [ 5] rol ?remainder+1,x 2143 M mloop ::?remainder 2143 M [2115] 2115:6903 [ 5] rol ?remainder+0,x 2143 M mloop ::?remainder 2143 endm 2144 2145 ; temp := remainder - divisor 2146 2147 M @sub.s ?remainder,x divisor@@,spx ?temp,x 2147 M mset #' ' 2147 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2147 M @@_samesize_ ?remainder,x divisor54,spx ?temp,x 2147 M mreq 1,2:Operand1,Operand2[,Operand]* 2147 M mset 0 2147 M mdo 2147 M mswap 1,1 2147 M @@_nosize_ ?remainder,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?remainder,x) 2147 M endm 2147 M mset 0,?remainder,x 2147 M mloop :n 2147 M mswap 1,2 2147 M @@_nosize_ divisor54,spx 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (divisor54,spx) 2147 M endm 2147 M mloop :n 2147 M mswap 1,3 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?temp,x) 2147 M endm 2147 M mloop :n 2147 M endm 2147 M #temp 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [sub.s] No size (?temp,x) 2147 M endm 2147 M #temp ::?temp 2147 M mset 0,sub 2147 M mdo 2147 M [2117] 2117:E605 [ 3] lda ?remainder+2,x 2147 M [2119] 2119:E015 [ 3] sub divisor54+2,spx 2147 M [211B] 211B:E708 [ 3] sta ?temp+2,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [211D] 211D:E604 [ 3] lda ?remainder+1,x 2147 M [211F] 211F:E214 [ 3] sbc divisor54+1,spx 2147 M [2121] 2121:E707 [ 3] sta ?temp+1,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2123] 2123:E603 [ 3] lda ?remainder+0,x 2147 M [2125] 2125:E213 [ 3] sbc divisor54+0,spx 2147 M [2127] 2127:E706 [ 3] sta ?temp+0,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 endm 2148 2149 ; q := not msb(temp) 2150 2151 [2129] 2129:E606 [ 3] lda ?temp,x 2152 [212B] 212B:A880 [ 2] eor #%10000000 ;invert msb 2153 [212D] 212D:A480 [ 2] and #%10000000 ;isolate msb 2154 2155 ; quotient := (quotient shl 1) or q 2156 2157 [212F] 212F:87 [ 2] psha 2158 [2130] 2130:48 [ 1] lsla 2159 [2131] 2131:86 [ 3] pula 2160 2161 M @rol.s ?quotient,x 2161 M mset # 2161 M mreq 1 2161 M @@_nosize_ ?quotient,x 2161 M mset # 2161 M mset 0,mstop [rol.s] No size (?quotient,x) 2161 M endm 2161 M mdo 2161 M [2132] 2132:6902 [ 5] rol ?quotient+2,x 2161 M mloop ::?quotient 2161 M [2134] 2134:6901 [ 5] rol ?quotient+1,x 2161 M mloop ::?quotient 2161 M [2136] 2136:79 [ 4] rol ?quotient+0,x 2161 M mloop ::?quotient 2161 endm 2162 2163 ; if q <> 0 then 2164 2165 [2137] 2137:4100 C8(2102) [ 4] cbeqa #0,For@@ 2166 2167 ; remainder := temp 2168 2169 M @mova.s ?temp,x ?remainder,x 2169 M mset #' ' 2169 M mreq 1,2:Source Destination 2169 M @@_samesize_ ?temp,x ?remainder,x 2169 M mreq 1,2:Operand1,Operand2[,Operand]* 2169 M mset 0 2169 M mdo 2169 M mswap 1,1 2169 M @@_nosize_ ?temp,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?temp,x) 2169 M endm 2169 M mset 0,?temp,x 2169 M mloop :n 2169 M mswap 1,2 2169 M @@_nosize_ ?remainder,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?remainder,x) 2169 M endm 2169 M mloop :n 2169 M endm 2169 M mset 0 2169 M mdo 2169 M [213A] 213A:E606 [ 3] lda ?temp+0,x 2169 M [213C] 213C:E703 [ 3] sta ?remainder+0,x 2169 M mloop ::?remainder 2169 M [213E] 213E:E607 [ 3] lda ?temp+1,x 2169 M [2140] 2140:E704 [ 3] sta ?remainder+1,x 2169 M mloop ::?remainder 2169 M [2142] 2142:E608 [ 3] lda ?temp+2,x 2169 M [2144] 2144:E705 [ 3] sta ?remainder+2,x 2169 M mloop ::?remainder 2169 endm 2170 2171 ; end if -- end for 2172 2174 [2146] 2146:20BA (2102) [ 3] bra For@@ 2178 2179 [2148] 2148:E60A [ 3] Done@@ lda ?flags,x 2180 [214A] 214A:A501 [ 2] bit #?DIVOP_ 2181 [214C] 214C:270D (215B) [ 3] beq ExitMod@@ 2182 2183 01D9 ?Cycles equ :cycles 2184 2185 ;ExitDiv@@ 2186 M @mova.s ?quotient,x ans@@,spx 2186 M mset #' ' 2186 M mreq 1,2:Source Destination 2186 M @@_samesize_ ?quotient,x ans54,spx 2186 M mreq 1,2:Operand1,Operand2[,Operand]* 2186 M mset 0 2186 M mdo 2186 M mswap 1,1 2186 M @@_nosize_ ?quotient,x 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (?quotient,x) 2186 M endm 2186 M mset 0,?quotient,x 2186 M mloop :n 2186 M mswap 1,2 2186 M @@_nosize_ ans54,spx 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (ans54,spx) 2186 M endm 2186 M mloop :n 2186 M endm 2186 M mset 0 2186 M mdo 2186 M [214E] 214E:F6 [ 3] lda ?quotient+0,x 2186 M [214F] 214F:E713 [ 3] sta ans54+0,spx 2186 M mloop ::ans54 2186 M [2151] 2151:E601 [ 3] lda ?quotient+1,x 2186 M [2153] 2153:E714 [ 3] sta ans54+1,spx 2186 M mloop ::ans54 2186 M [2155] 2155:E602 [ 3] lda ?quotient+2,x 2186 M [2157] 2157:E715 [ 3] sta ans54+2,spx 2186 M mloop ::ans54 2186 endm 2187 [2159] 2159:200C (2167) [ 3] bra ExitBoth@@ 2188 2189 020D ?DivCycles set ?DivCycles+?Cycles+:cycles 2190 2191 M ExitMod@@ @mova.s ?remainder,x ans@@,spx 2191 M mset #' ' 2191 M mreq 1,2:Source Destination 2191 M @@_samesize_ ?remainder,x ans54,spx 2191 M mreq 1,2:Operand1,Operand2[,Operand]* 2191 M mset 0 2191 M mdo 2191 M mswap 1,1 2191 M @@_nosize_ ?remainder,x 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (?remainder,x) 2191 M endm 2191 M mset 0,?remainder,x 2191 M mloop :n 2191 M mswap 1,2 2191 M @@_nosize_ ans54,spx 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (ans54,spx) 2191 M endm 2191 M mloop :n 2191 M endm 2191 M mset 0 2191 M mdo 2191 M [215B] 215B:E603 [ 3] lda ?remainder+0,x 2191 M [215D] 215D:E713 [ 3] sta ans54+0,spx 2191 M mloop ::ans54 2191 M [215F] 215F:E604 [ 3] lda ?remainder+1,x 2191 M [2161] 2161:E714 [ 3] sta ans54+1,spx 2191 M mloop ::ans54 2191 M [2163] 2163:E605 [ 3] lda ?remainder+2,x 2191 M [2165] 2165:E715 [ 3] sta ans54+2,spx 2191 M mloop ::ans54 2191 endm 2192 2193 0201 ?ModCycles set ?ModCycles+?Cycles+:cycles 2194 2195 2167 ExitBoth@@ 2197 [2167] 2167:6D0A [ 4] tst ?flags,x 2198 [2169] 2169:2A06 (2171) [ 3] bpl SkipSign@@ 2199 M @lea ans@@,sp 2199 M mset # 2199 M [216B] 216B:95 [ 2] tsx 2199 M [216C] 216C:AF13 [ 2] !aix #ans54+:tsx 2199 mexit 2200 [216E] 216E:CD20 58 [ 6] jsr ?NegX 2201 2171 SkipSign@@ 2202 #Cycles ?NegxCycles+:cycles 2204 [2171] 2171:A70B [ 2] ais #?SF ;de-allocate temporaries 2205 [2173] 2173:98 [ 1] clc ;no error(s) 2206 ; bra ?RemoveAndReturn 2207 2208 0031 ?Cycles set :cycles 2209 023E ?DivCycles set ?DivCycles+?Cycles 2210 0232 ?ModCycles set ?ModCycles+?Cycles 2211 2212 ;******************************************************************************* 2213 ; Common exit removes lower 32-bit stack element and returns to caller 2214 ;******************************************************************************* 2215 2216 2174 ?RemoveAndReturn proc 2218 [2174] 2174:9EFE 04 [ 5] ldhx ?pc,sp ;our return address moved up 2219 [2177] 2177:9EFF 07 [ 5] sthx ?pc+?WORD,sp ;above word to remove 2229 [217A] 217A:8A88 86 [ 9] pull 2230 [217D] 217D:A703 [ 2] ais #?WORD ;remove top-of-stack ?WORD 2231 [217F] 217F:81 [ 6] rtc 2232 2233 001B ?ReturnCycles equ :cycles 2234 2235 ;******************************************************************************* 2236 ; Purpose: Swaps the stacked order of N1 and N2 2237 ; Input : [TOS+?WORD] = Number2 2238 ; : [TOS] = Number1 2239 ; Output : [TOS+?WORD] = Number1 -- TOS & [TOS+?WORD] in reverse order 2240 ; : [TOS] = Number2 2241 ; Note(s): Does not alter stack size 2242 2243 #spauto :ab 2244 2245 2180 ?Swap proc 2246 [2180] 2180:8789 8B [ 6] push 2247 2248 [2183] 2183:A603 [ 2] lda #?WORD 2249 [2185] 2185:87 [ 2] psha bytes@@ 2250 2251 [2186] 2186:95 [ 2] tsx 2252 #temp :cycles 2253 M Loop@@ @_swap_, ?a,spx ?b,spx ;swap A with B ... 2253 M mset #' ' 2253 M #push 2253 M #spauto :sp 2253 M [2187] 2187:E606 [ 3] lda ?a,spx 2253 M [2189] 2189:87 [ 2] psha 2253 M [218A] 218A:E609 [ 3] lda ?b,spx 2253 M [218C] 218C:E706 [ 3] sta ?a,spx 2253 M [218E] 218E:86 [ 3] pula 2253 M [218F] 218F:E709 [ 3] sta ?b,spx 2253 M #pull 2253 endm 2254 2255 [2191] 2191:AF01 [ 2] aix #1 ;point to next byte 2256 [2193] 2193:9E6B 01F0 (2187 [ 8] dbnz bytes@@,sp,Loop@@ ;repeat for all bytes 2257 #temp :cycles*?WORD+:temp 2258 [2197] 2197:86 [ 3] pula 2259 2260 [2198] 2198:8A88 86 [ 9] pull 2261 [219B] 219B:81 [ 6] rtc 2262 2263 006F ?SwapCycles set :cycles+:temp 2264 2265 ;******************************************************************************* 2266 ; Purpose: Get the absolute value of the top-of-stack number 2267 ; Input : [TOS] = Number 2268 ; Output : [TOS] = Abs(Number) 2269 ; Note(s): Does not alter stack size 2270 2271 #spauto :ab 2272 2273 219C ?Abs proc 2274 [219C] 219C:9E6D 03 [ 5] tst ?a,sp 2275 [219F] 219F:2AFA (219B) [ 3] bpl Done@@ 2276 ; bra ?Negate 2277 2278 219B Done@@ equ :AnRTC 2279 2280 0008 ?AbsCycles equ :cycles 2281 2282 ;******************************************************************************* 2283 ; Purpose: Negate the top-of-stack number 2284 ; Input : [TOS] = Number 2285 ; Output : [TOS] = -Number 2286 ; Note(s): Does not alter stack size 2287 2288 #spauto :ab 2289 2290 21A1 ?Negate proc 2291 [21A1] 21A1:898B [ 4] pshhx 2293 M @lea ?a,sp 2293 M mset # 2293 M [21A3] 21A3:95 [ 2] tsx 2293 M [21A4] 21A4:AF04 [ 2] !aix #?a+:tsx 2293 mexit 2294 [21A6] 21A6:CD20 58 [ 6] jsr ?NegX 2295 #Cycles ?NegxCycles+:cycles 2300 [21A9] 21A9:8A88 [ 6] pulhx 2301 [21AB] 21AB:81 [ 6] rtc 2302 2303 0037 ?NegateCycles equ :cycles 2304 003F ?AbsCycles set ?NegateCycles+?AbsCycles 2305 2306 ;******************************************************************************* 2307 ; Purpose: Create a new top-of-stack and load to it the number pointed to by HX 2308 ; Input : HX -> [Variable with] Number 2309 ; Output : [TOS] = Number 2310 ; Note(s): This operation makes it easier to load a number to the stack. 2311 ; : Hint: To make a copy of the TOS, do: 2312 ; : tsx 2313 ; : call StackLoad32 2314 ; : (Stack is expanded) 2315 2316 #spauto :ab 2317 2318 21AC ?Load proc 2319 FFFFFFFF old_rts@@ equ ::,:ab 2320 [21AC] 21AC:A7FD [ 2] ais #-?WORD ;allocate new TOS memory 2321 #temp :: 2322 FFFFFFFC new_rts@@ next :temp,:ab 2323 FFFFFFFE tos_num@@ next :temp,?WORD 2324 0001 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2325 #ais :temp 2326 2327 [21AE] 21AE:87 [ 2] psha 2328 M @mova.s old_rts@@,sp new_rts@@,sp ;move RTS/RTC after new memory 2328 M mset #' ' 2328 M mreq 1,2:Source Destination 2328 M @@_samesize_ old_rts59,sp new_rts@@,sp 2328 M mreq 1,2:Operand1,Operand2[,Operand]* 2328 M mset 0 2328 M mdo 2328 M mswap 1,1 2328 M @@_nosize_ old_rts59,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (old_rts59,sp) 2328 M endm 2328 M mset 0,old_rts59,sp 2328 M mloop :n 2328 M mswap 1,2 2328 M @@_nosize_ new_rts@@,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (new_rts59,sp) 2328 M endm 2328 M mloop :n 2328 M endm 2328 M mset 0 2328 M mdo 2328 M [21AF] 21AF:9EE6 05 [ 4] lda old_rts59+0,sp 2328 M [21B2] 21B2:9EE7 02 [ 4] sta new_rts@@+0,sp 2328 M mloop ::new_rts@@ 2328 M [21B5] 21B5:9EE6 06 [ 4] lda old_rts59+1,sp 2328 M [21B8] 21B8:9EE7 03 [ 4] sta new_rts@@+1,sp 2328 M mloop ::new_rts@@ 2328 endm 2329 M @mova.s ,x tos_num@@,sp 2329 M mset #' ' 2329 M mreq 1,2:Source Destination 2329 M @@_samesize_ ,x tos_num59,sp 2329 M mreq 1,2:Operand1,Operand2[,Operand]* 2329 M mset 0 2329 M mdo 2329 M mswap 1,1 2329 M mloop :n 2329 M mswap 1,2 2329 M @@_nosize_ tos_num59,sp 2329 M mset # 2329 M mset 0,mstop [_samesize_] No size (tos_num59,sp) 2329 M endm 2329 M mset 0,tos_num59,sp 2329 M mloop :n 2329 M endm 2329 M mset 0 2329 M mdo 2329 M [21BB] 21BB:F6 [ 3] lda +0,x 2329 M [21BC] 21BC:9EE7 04 [ 4] sta tos_num59+0,sp 2329 M mloop ::tos_num59 2329 M [21BF] 21BF:E601 [ 3] lda +1,x 2329 M [21C1] 21C1:9EE7 05 [ 4] sta tos_num59+1,sp 2329 M mloop ::tos_num59 2329 M [21C4] 21C4:E602 [ 3] lda +2,x 2329 M [21C6] 21C6:9EE7 06 [ 4] sta tos_num59+2,sp 2329 M mloop ::tos_num59 2329 endm 2330 [21C9] 21C9:86 [ 3] pula 2331 [21CA] 21CA:81 [ 6] rtc 2332 2333 0032 ?LoadCycles equ :cycles 2334 2335 ;******************************************************************************* 2336 ; Purpose: Unload the top-of-stack number into a variable pointed to by HX 2337 ; Input : [TOS] = Number 2338 ; : HX -> Some 32-bit variable 2339 ; Output : Variable pointed to by HX receives TOS number 2340 ; Note(s): This operation makes it easier to unload a number from the stack. 2341 ; : Use: 2342 ; : ldhx #MyVar 2343 ; : call StackSave32 2344 ; : (Stack is reduced) 2345 2346 #spauto :ab 2347 2348 21CB ?Save proc 2349 #temp :: 2350 FFFFFFFF old_rts@@ next :temp,:ab 2351 0001 tos_num@@ next :temp,?WORD 2352 0004 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2353 0002 new_rts@@ next :temp,:ab 2354 2355 0000 var@@ equ 0,?WORD 2356 2357 [21CB] 21CB:8789 8B [ 6] push 2358 M @mova.s tos_num@@,sp var@@,x 2358 M mset #' ' 2358 M mreq 1,2:Source Destination 2358 M @@_samesize_ tos_num60,sp var@@,x 2358 M mreq 1,2:Operand1,Operand2[,Operand]* 2358 M mset 0 2358 M mdo 2358 M mswap 1,1 2358 M @@_nosize_ tos_num60,sp 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (tos_num60,sp) 2358 M endm 2358 M mset 0,tos_num60,sp 2358 M mloop :n 2358 M mswap 1,2 2358 M @@_nosize_ var@@,x 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (var60,x) 2358 M endm 2358 M mloop :n 2358 M endm 2358 M mset 0 2358 M mdo 2358 M [21CE] 21CE:9EE6 06 [ 4] lda tos_num60+0,sp 2358 M [21D1] 21D1:F7 [ 2] sta var@@+0,x 2358 M mloop ::var@@ 2358 M [21D2] 21D2:9EE6 07 [ 4] lda tos_num60+1,sp 2358 M [21D5] 21D5:E701 [ 3] sta var@@+1,x 2358 M mloop ::var@@ 2358 M [21D7] 21D7:9EE6 08 [ 4] lda tos_num60+2,sp 2358 M [21DA] 21DA:E702 [ 3] sta var@@+2,x 2358 M mloop ::var@@ 2358 endm 2359 2360 [21DC] 21DC:95 [ 2] tsx 2361 M @mova.s old_rts@@,spx new_rts@@,spx ;move RTS/RTC before old memory 2361 M mset #' ' 2361 M mreq 1,2:Source Destination 2361 M @@_samesize_ old_rts60,spx new_rts@@,spx 2361 M mreq 1,2:Operand1,Operand2[,Operand]* 2361 M mset 0 2361 M mdo 2361 M mswap 1,1 2361 M @@_nosize_ old_rts60,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (old_rts60,spx) 2361 M endm 2361 M mset 0,old_rts60,spx 2361 M mloop :n 2361 M mswap 1,2 2361 M @@_nosize_ new_rts@@,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (new_rts60,spx) 2361 M endm 2361 M mloop :n 2361 M endm 2361 M mset 0 2361 M mdo 2361 M [21DD] 21DD:E603 [ 3] lda old_rts60+0,spx 2361 M [21DF] 21DF:E706 [ 3] sta new_rts@@+0,spx 2361 M mloop ::new_rts@@ 2361 M [21E1] 21E1:E604 [ 3] lda old_rts60+1,spx 2361 M [21E3] 21E3:E707 [ 3] sta new_rts@@+1,spx 2361 M mloop ::new_rts@@ 2361 endm 2362 [21E5] 21E5:8A88 86 [ 9] pull 2363 2364 [21E8] 21E8:A703 [ 2] ais #?WORD ;de-allocate TOS memory 2365 [21EA] 21EA:81 [ 6] rtc 2366 2367 0039 ?SaveCycles equ :cycles 2368 2369 ;******************************************************************************* 2370 ; Purpose: Adjust TOS old size to new 2371 ; Input : H = old (current) byte size 2372 ; : X = new byte size 2373 ; : CCR[C] = 0 -- always positive number 2374 ; : CCR[C] = 1 -- sign extend 2375 ; Output : None 2376 ; Note(s): RegA deliberately not used for parameter passing (for consistency) 2377 ; : Macro destroys RegHX (as we must not use PSHHX/PULHX around call) 2378 2504 2505 ;******************************************************************************* 2506 ; Purpose: Convert 32-bit to ASCIZ string 2507 ; Input : Stack: 32-bit number 2508 ; : HX -> Output buffer with enough space to keep the ASCIZ string result 2509 ; Output : None 2510 ; Note(s): Use: 2511 ; : ldhx #Buffer 2512 ; : call Stack32ToASCIZ 2513 2514 #spauto :ab ;account for RTS/RTC 2515 2516 21EB ?ToStr proc 2517 [21EB] 21EB:8789 8B [ 6] push 2518 #ais ;mark beginning of temporaries 2519 2520 [21EE] 21EE:898B [ 4] pshhx .buffer@@ ;working copy of pointer to buffer 2521 [21F0] 21F0:7F [ 4] clr ,x ;make it an ASCIZ string 2522 2523 M @lea 1,sp ;HX -> TOS number of caller 2523 M mset # 2523 M [21F1] 21F1:95 [ 2] tsx 2523 M [21F2] 21F2:AF07 [ 2] !aix #1+:tsx 2523 mexit 2524 [21F4] 21F4:CD21 AC [ 6] call ?Load ;load a working copy on stack 2525 2526 #spadd ?WORD ;stack has grown by a ?WORD 2527 FFFFFFF7 number@@ equ ::,?WORD 2529 [21F7] 21F7:9E6D 01 [ 5] tst number@@,sp 2530 [21FA] 21FA:2A0F (220B) [ 3] bpl ToStrLoop@@ 2531 [21FC] 21FC:CD21 A1 [ 6] call ?Negate 2533 [21FF] 21FF:9EFE 04 [ 5] ldhx .buffer@@,sp 2540 [2202] 2202:A62D [ 2] lda #'-' ;a 'minus' sign 2541 [2204] 2204:F7 [ 2] sta ,x ; is saved first 2542 2543 [2205] 2205:AF01 [ 2] aix #1 ;HX -> past minus sign 2544 [2207] 2207:7F [ 4] clr ,x ;make it an ASCIZ string 2546 [2208] 2208:9EFF 04 [ 5] sthx .buffer@@,sp ;update pointer past sign 2552 ; bra ToStrLoop@@ 2554 ;=============================================================================== 2555 2556 [220B] 220B:4500 0A [ 3] ToStrLoop@@ ldhx #10 ;H = 0 (always), X = divisor 2557 M @div.s number@@,sp 2557 M mset # 2557 M mreq 1 2557 M @@_not_x_ number61,sp 2557 M mset #' ' 2557 M mdel 1 2557 M mtop 2557 M mset #' ' 2557 M mexit 2557 M @@_nosize_ number61,sp 2557 M mset # 2557 M mset 0,mstop [div.s] No size (number61,sp) 2557 M endm 2557 M #temp 1 2557 M #temp 2 2557 M [220E] 220E:86 [ 3] pula 2557 M [220F] 220F:52 [ 6] div 2557 M [2210] 2210:87 [ 2] psha 2557 M mdo 2 2557 M [2211] 2211:9EE6 02 [ 4] lda number61+1,sp 2557 M [2214] 2214:52 [ 6] div 2557 M [2215] 2215:9EE7 02 [ 4] sta number61+1,sp 2557 M mloop ::number61 2557 M [2218] 2218:9EE6 03 [ 4] lda number61+2,sp 2557 M [221B] 221B:52 [ 6] div 2557 M [221C] 221C:9EE7 03 [ 4] sta number61+2,sp 2557 M mloop ::number61 2557 endm 2558 2559 [221F] 221F:8B86 [ 5] tha ;A = remainder 2560 [2221] 2221:AB30 [ 2] add #'0' ;A = ASCII remainder 2562 [2223] 2223:9EFE 04 [ 5] ldhx .buffer@@,sp 2568 M @StringInsertChar 2568 M [2226] 2226:CD18 3A [ 6] call StringInsertChar ;HX and A pre-loaded correctly 2568 mexit 2569 2570 [2229] 2229:95 [ 2] tsx 2571 2572 M @_tst_.s number@@,spx 2572 M mset # 2572 M mreq 1 2572 M @@_nosize_ number61,spx 2572 M mset # 2572 M mset 0,mstop [_tst_.s] No size (number61,spx) 2572 M endm 2572 M mdo 2572 M [222A] 222A:F6 [ 3] lda number61+0,spx 2572 M mloop ::number61 2572 M [222B] 222B:EA01 [ 3] ora number61+1,spx 2572 M mloop ::number61 2572 M [222D] 222D:EA02 [ 3] ora number61+2,spx 2572 M mloop ::number61 2572 endm 2573 [222F] 222F:26DA (220B) [ 3] bne ToStrLoop@@ 2574 2575 [2231] 2231:A705 [ 2] ais #:ais ;free temporaries 2576 [2233] 2233:8A88 86 [ 9] pull 2577 [2236] 2236:81 [ 6] rtc 2578 2579 #sp ;cancel all SP offsets 2580 2581 ;******************************************************************************* 2582 ; Assign global names to the various library calls, depending on version used. 2583 ; Different names for each version means you can include any at the same time. 2584 ;******************************************************************************* 2585 2586 ? macro BitSize ;temp macro to export symbols 2587 mreq 1:Usage: @~0~ BitSize 2588 #if MATHSIZE = ~1~ 2589 StackAdd~1~ exp ?Add 2590 StackSub~1~ exp ?Subtract 2591 StackMul~1~ exp ?Multiply 2592 StackDiv~1~ exp ?Divide 2593 StackMod~1~ exp ?Modulo 2594 StackSwap~1~ exp ?Swap 2595 StackAbs~1~ exp ?Abs 2596 StackNegate~1~ exp ?Negate 2597 StackLoad~1~ exp ?Load 2598 StackSave~1~ exp ?Save 2599 Stack~1~ToASCIZ exp ?ToStr 2600 #ifdef NO_BIT_OPS 2601 mexit ;;bit operations not available 2602 #endif 2603 StackAnd~1~ exp ?BitAnd 2604 StackOr~1~ exp ?BitOr 2605 StackXor~1~ exp ?BitXor 2606 StackShl~1~ exp ?ShiftLeft 2607 StackShr~1~ exp ?ShiftRight 2608 #endif 2609 endm 2610 2611 M @? 64 ;export 64-bit labels 2611 M mreq 1:Usage: @? BitSize 2611 endm 2612 M @? 56 ;export 56-bit labels 2612 M mreq 1:Usage: @? BitSize 2612 endm 2613 M @? 48 ;export 48-bit labels 2613 M mreq 1:Usage: @? BitSize 2613 endm 2614 M @? 40 ;export 40-bit labels 2614 M mreq 1:Usage: @? BitSize 2614 endm 2615 M @? 32 ;export 32-bit labels 2615 M mreq 1:Usage: @? BitSize 2615 endm 2616 M @? 24 ;export 24-bit labels 2616 M mreq 1:Usage: @? BitSize 2616 M 1F17 StackAdd24 exp ?Add 2616 M 1F2D StackSub24 exp ?Subtract 2616 M 1FE8 StackMul24 exp ?Multiply 2616 M 2034 StackDiv24 exp ?Divide 2616 M 2047 StackMod24 exp ?Modulo 2616 M 2180 StackSwap24 exp ?Swap 2616 M 219C StackAbs24 exp ?Abs 2616 M 21A1 StackNegate24 exp ?Negate 2616 M 21AC StackLoad24 exp ?Load 2616 M 21CB StackSave24 exp ?Save 2616 M 21EB Stack24ToASCIZ exp ?ToStr 2616 M 1F43 StackAnd24 exp ?BitAnd 2616 M 1F58 StackOr24 exp ?BitOr 2616 M 1F6D StackXor24 exp ?BitXor 2616 M 1F82 StackShl24 exp ?ShiftLeft 2616 M 1FB5 StackShr24 exp ?ShiftRight 2616 endm 2617 M @? 16 ;export 16-bit labels 2617 M mreq 1:Usage: @? BitSize 2617 endm 2618 2619 ;******************************************************************************* *** END INCLUDE FILE: lib/stakmath.sub *** (RESUMING FILE: lib/stkmth24.sub) 23 #Exit *** END INCLUDE FILE: lib/stkmth24.sub *** (RESUMING FILE: lib/demo/stakmath.asm) 51 M @? 40,5 51 M @@Page 5 51 M mreq 1:PageNumber 51 M endm 51 #Uses lib/stkmth40.sub *** BEGIN INCLUDE FILE: lib/stkmth40.sub *** 1 ;******************************************************************************* 2 ;* Module : STKMTH40.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Wrapper for 40-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stkmth40.html 8 ;* Note(s) : See STAKMATH.SUB for details 9 ;******************************************************************************* 10 16 17 ? macro 18 mset 1,~BASENAME~ 19 MATHSIZE set ~1.{:1-1}~ 20 #Include stakmath.sub 21 endm 22 23 M @? 23 M mset 1,STKMTH40 23 M 0028 MATHSIZE set 40 23 #Include stakmath.sub *** BEGIN INCLUDE FILE: lib/stakmath.sub *** 1 ;******************************************************************************* 2 ;* Module : STAKMATH.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : 64/56/48/40/32/24/16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stakmath.html 8 ;* Note(s) : Use: #Include stakmath.sub 9 ;* : 10 ;* : Several externally defined macros are used throughout this code. 11 ;* : All these (and many more) macros are inside the most recent 12 ;* : version of MACROS.INC which can be copied from the web page at 13 ;* : http://www.aspisys.com/code/hc08/macros.html 14 ;* : (and COMMON.INC at http://www.aspisys.com/code/hc08/common.html) 15 ;* : 16 ;* : The default word size is 32-bit. 17 ;* : 18 ;* : By (re)defining the symbol MATHSIZE (to 16) you get 16-bit code. 19 ;* : By (re)defining the symbol MATHSIZE to 24 you get 24-bit code. 20 ;* : By (re)defining the symbol MATHSIZE to 40 you get 40-bit code. 21 ;* : By (re)defining the symbol MATHSIZE to 48 you get 48-bit code. 22 ;* : By (re)defining the symbol MATHSIZE to 56 you get 56-bit code. 23 ;* : By (re)defining the symbol MATHSIZE to 64 you get 64-bit code. 24 ;* : 25 ;* : You can include all (or some) versions in your program like so: 26 ;* : 27 ;* : #ROM ;(or else, some paged memory) 28 ;* : #Include stakmath.sub 29 ;* : MATHSIZE set 16 ;redefine for 16-bit use 30 ;* : #Include stakmath.sub 31 ;* : MATHSIZE set 24 ;redefine for 24-bit use 32 ;* : #Include stakmath.sub 33 ;* : MATHSIZE set 40 ;redefine for 40-bit use 34 ;* : #Include stakmath.sub 35 ;* : MATHSIZE set 48 ;redefine for 48-bit use 36 ;* : #Include stakmath.sub 37 ;* : MATHSIZE set 56 ;redefine for 56-bit use 38 ;* : #Include stakmath.sub 39 ;* : MATHSIZE set 64 ;redefine for 64-bit use 40 ;* : 41 ;* : or, if you use the related wrapper files, like so: 42 ;* : 43 ;* : #ROM ;(or else, some paged memory) 44 ;* : #Uses stkmth16.sub 45 ;* : #Uses stkmth24.sub 46 ;* : #Uses stkmth32.sub 47 ;* : #Uses stkmth40.sub 48 ;* : #Uses stkmth48.sub 49 ;* : #Uses stkmth56.sub 50 ;* : #Uses stkmth64.sub 51 ;* : 52 ;* : Use CALL if assembled in #MMU mode (regardless of placement). 53 ;* : By using CALL and #JUMP (or default -J+ command line option), the 54 ;* : assembler will automatically adjust between CALL and JSR 55 ;* : depending on the current #MMU mode. 56 ;* : 57 ;* : To use the *-bit version of each CALL, use these symbols: 58 ;* : 59 ;* : StackAdd*, StackSub*, StackMul*, StackDiv*, StackMod* 60 ;* : StackSwap*, StackNegate*, StackLoad*, StackSave*, 61 ;* : Stack*ToASCIZ 62 ;* : 63 ;* : replacing * with one of these: 16, 24, 32, 40, 48, 56, or 64. 64 ;* : 65 ;* : Various macros allow using these routines in a variety of ways, 66 ;* : and without worrying about the details of call & parameter setup. 67 ;* : These macros are: Add*, Sub*, Mul*, Div*, Mod*, DivS*, ModS*, 68 ;* : Neg*, Load*, Save*, Str*, StrS*, and Swap* (where the * is 16, 69 ;* : 24, 32, 40, 48, 56, or 64 depending on the version you want to use). 70 ;* : The signed versions are enabled only when the module is assembled 71 ;* : with the SIGNED conditional. 72 ;* : 73 ;* : If working with fixed-address variables, you can use the various 74 ;* : macros (such as Add32, Mul64, etc.) to perform operations in the 75 ;* : easiest possible way, such as: 76 ;* : @Mul32 A,B,Answer 77 ;* : (which multiplies A with B and stores the product in Answer). 78 ;* : But, you may also use the macros to work directly on stack, or to 79 ;* : temporarily save partial results on stack instead of fixed vars. 80 ;* : 81 ;* : I N G E N E R A L T H E N 82 ;* : 83 ;* : @Operation A,B,Answer works with A and B storing result in Answer 84 ;* : @Operation A,B works with A and B leaving result on stack 85 ;* : @Operation A works with TOS and A, result left as TOS 86 ;* : @Operation (no parms) works w/ TOS and [TOS+1], result as new TOS 87 ;* : 88 ;* : (Please note the shown order of the operation may be important.) 89 ;* : 90 ;* : Finally, the Load* (* = 16, 24, 32, 40, 48, 56, 64) operation can 91 ;* : directly load either a variable or a constant (leading #) on the 92 ;* : stack. 93 ;* : 94 ;* : Since v7.00, a HLL-like interface is possible by using the new 95 ;* : Eval* macro (where * = 8, 16, 24, 32, 40, 48, 56, 64) 96 ;* : This is by far the easiest way to use this library, as it closely 97 ;* : resembles using expressions in a HLL compiler. It also can 98 ;* : automatically resize stack after loading from and before saving 99 ;* : to any variable. 100 ;* : 101 ;* : Examine the test section of this file for examples of macro use. 102 ;* : 103 ;* : All routines are re-entrant and work on either the top-of-stack 104 ;* : (TOS) number alone or the two top-most TOS numbers. Similar to 105 ;* : how Reverse Polish Notation (RPN) works. First, you stack the 106 ;* : operand(s) and then call the corresponding routine to perform the 107 ;* : operation. 108 ;* : 109 ;* : The result of any operation is always the updated top of stack. 110 ;* : For operations that require two operands and produce a single 111 ;* : result, the result replaces the two operands (stack is reduced). 112 ;* : 113 ;* : Chain calculations are possible by pushing only the new operand 114 ;* : between operations. Alternatively, one can push all operands in 115 ;* : advance but it's not recommended as stack space may be limited. 116 ;* : When done evaluating an expression, just pull the final 32-bit 117 ;* : result from the stack. 118 ;* : 119 ;* : The TOS is the first (or only) operand of any operation. 120 ;* : This is important, for example, for subtraction and division. 121 ;* : 122 ;* : If the current order of the stack is not as you want it, use the 123 ;* : Swap (StackSwap32) operation to change it. 124 ;* : 125 ;* : All operands and results are exactly 32-bit wide. Overflows are 126 ;* : simply truncated. The lower 32-bit number is valid, though. 127 ;* : 128 ;* : (All references to 32-bit become 16-bit, when MATHSIZE = 16) 129 ;* : (All references to 32-bit become 24-bit, when MATHSIZE = 24) 130 ;* : (All references to 32-bit become 40-bit, when MATHSIZE = 40) 131 ;* : (All references to 32-bit become 48-bit, when MATHSIZE = 48) 132 ;* : (All references to 32-bit become 56-bit, when MATHSIZE = 56) 133 ;* : (All references to 32-bit become 64-bit, when MATHSIZE = 64) 134 ;* : 135 ;* : 64/56/48/40-bit multiplication is done using the shift-add method, 136 ;* : which is much shorter in size for such long operands, but it is 137 ;* : also significantly slower in speed. I opted for size optimization 138 ;* : because the 64/56/48/40-bit versions are not used quite as often. 139 ;* : You may want to re-write it for speed optimization by using the 140 ;* : MUL instruction like it is done for the default 32-bit case. 141 ;* : 142 ;* History : 09.05.22 v1.00 Original (Started on 2009.05.07) 143 ;* : 09.06.04 Optimized by using HX instead of SP, where needed 144 ;* : 09.11.04 Minor optimizations 145 ;* : 09.11.05 Add & Subtract now adjust Carry accordingly 146 ;* : Division by zero error now checked first 147 ;* : 09.11.06 v1.01 Added conditional MATHSIZE for use w/ 16-bit words 148 ;* : 09.11.08 v1.02 Added "Load" operation to ease stack loading 149 ;* : 09.11.11 Use of new LONG pseudo-opcode 150 ;* : 09.12.05 Added cycles display using :cycles 151 ;* : 10.01.06 v1.03 Added MMU auto-support (using :AB internal symbol) 152 ;* : Code is no longer placed in #ROM by default 153 ;* : The few JMPs in the code use [[ to trim possible page 154 ;* : 10.01.08 [[ removed from JMPs (latest ASM8 auto-correction) 155 ;* : 10.01.22 v1.04 Added Save operation for completeness 156 ;* : 10.01.23 v1.05 Added #SP directive examples (latest ASM8) 157 ;* : 10.01.29 v1.06 Added shorter/faster Swap version for 9S08 MCUs 158 ;* : 10.02.01 v1.07 Added #SPAUTO directive 159 ;* : 10.02.04 Added #X directive 160 ;* : 10.02.06 v2.00 Added signed math wrapper calls only for DIV & MOD 161 ;* : (Addition, Subtraction, and Multiplication calls 162 ;* : work either for unsigned or signed operands.) 163 ;* : Signed routines enabled w/ SIGNED conditional. 164 ;* : Division by zero error now reduces stack (operand 165 ;* : A removed) so that the stack is left with same 166 ;* : size on either success or failure (in which case 167 ;* : the TOS result is invalid.) 168 ;* : 10.02.08 v2.01 Fixed signed MOD for correct sign (sign of A) 169 ;* : 10.02.14 v2.10 Added Stack32ToASCIZ and prerequisite StringInsertChar 170 ;* : 10.02.28 v2.11 Minor optimization in StringInsertChar 171 ;* : 10.03.23 Made use of :: internal variable (Build 2010/03/23) 172 ;* : 10.03.30 v2.12 Allowed for HC08 compilation in newer code (?ToStr) 173 ;* : Optimized 9S08 Swap version for size and speed 174 ;* : v2.13 Optimized Negate for size and speed 175 ;* : 10.05.08 v3.00 Added MATHSIZE = 64 option for 64-bit math 176 ;* : Swap operation optimized only for size 177 ;* : 10.05.13 v3.01 Optimized for size and speed by using ,SPX 178 ;* : 10.06.02 v4.00 Added macros for easier use 179 ;* : 10.06.08 v4.10 Improved macros and added new ones (eg Const32) 180 ;* : 10.06.23 v4.20 Added MATHSIZE = 48 option for 48-bit math 181 ;* : 10.06.30 v4.30 Added AddDecimalPoint (to string number) 182 ;* : 10.07.01 v4.40 Added IFSPAUTO conditional 183 ;* : 10.07.03 Moved the functionality of Const macros into Load 184 ;* : 10.07.07 Moved general string routines first 185 ;* : 10.07.17 v4.50 Str* macros may use TOS (if Number parm is missing) 186 ;* : or current HX index (if result pointer is missing) 187 ;* : 10.07.20 _DoLoad*/_DoSave* address now allows for indexed mode 188 ;* : 10.07.21 Minor optimizations; macros now latest ASM8 189 ;* : 10.07.23 Minor bug fix in macro _DoSave for no parm case 190 ;* : 10.08.18 Optimized by using :MINDEX in latest ASM8 191 ;* : 10.08.26 Minor optimizations at the source level 192 ;* : 10.08.31 v4.60 Optimized Load* macros' immediate mode for zeros 193 ;* : 10.10.19 v4.61 Adapted to latest ASM8 (nested macros in Load) 194 ;* : 10.10.22 v4.62 Optimized _DoMath (Added @_DoOperation) 195 ;* : 10.10.26 v4.63 Load48 & Load64 now also accept single #Constant 196 ;* : 10.12.03 v4.64 Adapted to latest ASM8 => macros OK in @@ sub-mode 197 ;* : 11.03.31 v4.65 Moved test code at EOF (to use #EXIT optimization) 198 ;* : 11.04.10 v4.66 Condensed macro definitions (based on MATHSIZE) 199 ;* : 11.04.11 v4.67 Optimized MUL16/MUL32 size & cycles with ,SPX mode 200 ;* : 11.04.12 v4.70 Added MATHSIZE = 24 option for 24-bit math 201 ;* : 11.04.13 v4.71 Reversed some of v4.66's changes 202 ;* : 11.04.13 v4.80 Added MATHSIZE = 40 option for 40-bit math 203 ;* : 11.05.02 v4.81 Save protects HX (it was lost during SP => SPX) 204 ;* : 11.05.05 v4.82 Optimized StringLength by a byte (by using NEGA on exit) 205 ;* : 11.05.25 v4.83 Removed unused Zero constant from test code 206 ;* : 11.10.13 v4.84 Optimized MUL16/24/32 size w/ more ,SPX (same cycles) 207 ;* : 11.11.15 v4.85 Improved StringLength macro 208 ;* : 12.01.26 Changed test code a bit 209 ;* : 12.02.06 v4.86 Optimized SP => SPX at ?RemoveAndReturn 210 ;* : 12.03.05 v4.87 Added ResizeTOS to adjust TOS element's size 211 ;* : 12.05.09 v4.88 Added CCR[C] parameter to ResizeTOS for unsigned operation 212 ;* (signed is default when SIGNED conditional is defined, 213 ;* unsigned operation is default, otherwise) 214 ;* : 12.05.18 v4.89 Removed redundant subtraction in Division (at NotEqual@@) 215 ;* : 12.10.07 v4.90 Load*/Save* now accept indexed mode without separator override 216 ;* : 12.10.10 v5.00 Renamed to (more general) STAKMATH.SUB to use 217 ;* : wrapper files for each bit version, instead. 218 ;* : 12.11.05 Added _STKMTH{MATHSIZE}_ for used-version control 219 ;* : 12.11.09 v6.00 New _LoadStkMthVarAddr macro eases parm address 220 ;* : calculation. 221 ;* : W A R N I N G: SP-based operands now refer to the actual number, 222 ;* : W A R N I N G: and not its address (as was the case before). 223 ;* : W A R N I N G: This is INCOMPATIBLE with previous behavior. Code 224 ;* : W A R N I N G: written for version v5.00 or earlier that uses SP 225 ;* : W A R N I N G: based operands should be modified to refer to the 226 ;* : W A R N I N G: actual value and not to a pointer to the value. 227 ;* : W A R N I N G: Dot-beginning names are still treated as pointers! 228 ;* : 12.11.10 Use COMMON.INC/LEA instead of _LoadStkMthVarAddr 229 ;* : 12.12.04 v6.10 Optimized division just a tad by combining steps 230 ;* : 12.12.12 v6.20 Now use LEA macro inside _DoStr (for ResultString) 231 ;* : 12.12.20 v6.21 Minor optimization (one byte) in 32-bit ?Multiply 232 ;* : (Further 3-byte optimization possible by 233 ;* : re-ordering MULs, but not done for code clarity) 234 ;* : 13.01.09 v6.22 Added Copy* macros to combine Load*/Save* into one 235 ;* : 13.03.20 v7.00 Added Eval* and supporting macros for HLL-like 236 ;* : computations, eg., ans=(a+3)*((1+var,sp)/2) 237 ;* : (with or without spaces between operands/operators) 238 ;* : 13.03.27 v7.50 SIGNED now gives just signed (not unsigned) version 239 ;* : DivS*, ModS*, StrS* macros were removed, and also 240 ;* : ResizeTOS macro's unsigned flag has been removed 241 ;* : BugFix: AddDecimalPoint now prepends zeros after sign 242 ;* : 13.03.27 Optimized ?Negate in SIGNED case to use ?NegX sub 243 ;* : 13.03.27 v7.60 Adapted _EVAL_ macro to latest ASM8 (Much faster!) 244 ;* : 13.04.04 v7.70 _DoLoad and _DoSave macros now auto-adjust the size 245 ;* : so you can use with operands of different sizes, even 246 ;* : if the respective bitsize version isn't loaded. 247 ;* : 13.04.04 v7.71 _Eval_ macro leaves assignment result on TOS if 248 ;* : assignment variable not already defined. Then, 249 ;* : it gives TOS the specified name, if SP-indexed. 250 ;* : 13.04.05 v7.72 Added #size for v7.71 change 251 ;* : Named constants (labels with size zero) now use 252 ;* : immediate mode in Eval/Load 253 ;* : 13.04.05 v7.73 Added NEG() negate, and ABS() absolute functions 254 ;* : in Eval macro, e.g., ans = abs(a - b) 255 ;* : 13.04.09 v7.80 BugFix: Push/Pull macro calls for SP mode 256 ;* : Moved immediate mode to _DoLoad (unified method) 257 ;* : (Over 32-bit immediate value loads not possible 258 ;* : via macros) 259 ;* : 13.04.10 Adapted to v9.35 (no functional changes) 260 ;* : 13.04.11 v7.81 Optimized _DoLoad constant loading by using CLRH 261 ;* : (optimization is evident on certain cases only) 262 ;* : 13.04.15 v7.82 Added _?SEI_ and _?CLI_ macros for multitasker 263 ;* : locking / unlocking of multi-byte variables while 264 ;* : loading / saving (_DoLoad/_DoSave). Under OS8 it 265 ;* : is enabled automatically. Otherwise, simply 266 ;* : define _MTOS_ anytime before including this file. 267 ;* : For keeping code dense, all Eval*/Load*/Save* 268 ;* : macros are assumed to be called only while 269 ;* : interrupts are enabled, so it will not restore to 270 ;* : previous state but always leave as enabled. 271 ;* : Define _NOCLI_ (before including this module) for 272 ;* : canceling the _?SEI_ and _?CLI_ macro effects. 273 ;* : 13.04.18 v7.85 Added 'NeedMath' and 'Eval' general-purpose macros 274 ;* : for automatic selection of needed bit-size based 275 ;* : on only which modules are already included. First, 276 ;* : call the NeedMath macro to define the minimum math 277 ;* : bit-size you need for the next calculation(s), 278 ;* : then call the Eval macro as many times as needed 279 ;* : to perform the actual expression evaluation(s). 280 ;* : Similary, added new macros Load, Save, StkAdd, 281 ;* : StkSub, StkMul, StkDiv, StkMod, StkSwap, StkNeg, 282 ;* : StkAbs, StkStr, and CopyMath to work with the 283 ;* : NeedMath macro, just like the new Eval macro. 284 ;* : 13.04.19 v8.00 Moved all Eval* macros into COMMON.INC and allowed 285 ;* : for all to be active at all times, regardless if 286 ;* : the related bit-version of STAKMATH is included. 287 ;* : The _Eval_ macro was improved to allow it to 288 ;* : automatically locate the next higher version that 289 ;* : is included, if the one requested is not. So, 290 ;* : using Eval32 will use the 32/40/48/64-bit version 291 ;* : (whichever is closer to 32 and included) but nothing 292 ;* : below 32-bit. This allows you to use the relevant 293 ;* : macro based on a specific expression's requirements 294 ;* : but include only one (or just a few) higher bit 295 ;* : version(s), not all those referenced in your code. 296 ;* : (The general Eval is still available, if needed.) 297 ;* : Also, moved all Str* to COMMON.INC 298 ;* : 13.04.21 v8.10 Corrected v8.00 for pointer cases (.num) to use 299 ;* : actual requested size, not next higher. 300 ;* : Relevant #Message now in _DoOperation _ResizeTOS etc. 301 ;* : 13.04.21 v8.11 NeedMath & related macros removed (now redundant) 302 ;* : General Eval macro will try to determine best bit-size 303 ;* : 13.04.23 v8.12 Added EvalS to first check for SIGNED and then call Eval 304 ;* : CopyMath removed. Use "Eval to_var = from_var" instead 305 ;* : _StkMthMax_ improved to use higher size on multiplication 306 ;* : 13.04.25 v8.13 _Eval_ now allows for string constants (eg., @Eval ans = ans + '0') 307 ;* : Removed all ?macros because we now use COMMON xxx.s macros 308 ;* : 13.04.26 v8.15 Corrected test code for Eval when MATHSIZE < 32 309 ;* : Commented out auto-higher bit-size (a bit annoying). 310 ;* : Use Eval* to say 'no less than', instead. 311 ;* : 13.04.27 v8.16 BugFix: StrMath macro (2nd parameter was lost) 312 ;* : Added SQR() function to get the square 313 ;* : 13.05.02 Added #size in ToInt* macros (in test code) 314 ;* : 13.05.03 v8.17 Added size optimization for ADD and SUB operations 315 ;* : New SPEED_SIZE constant in COMMON.INC tells us 316 ;* : whether we need speed (SPEED_SIZE = 1) or 317 ;* : size (SPEED_SIZE = 2) optimization, the current 318 ;* : default being SPEED_SIZE = 2 for size optimization. 319 ;* : 13.05.30 Updated StrMath macro (COMMON.INC and here) 320 ;* : 13.06.04 v8.20 Added bit functions: AND (&), OR (|), XOR (^), and shifts (< and >) 321 ;* : 13.06.05 v8.21 BugFix: ShiftRight now uses ASR if SIGNED 322 ;* : 13.07.25 v8.22 Improved _Eval_ macro (and Push/Pull in COMMON.INC) 323 ;* : BugFix: Added { } to ResizeTOS macro's final case 324 ;* : (Disable bit functions with NO_BIT_OPS conditional) 325 ;* : 13.10.06 Minor changes in test code 326 ;* : 13.11.26 Added warning in _DoLoad: forwards treated as vars 327 ;* : 13.11.29 v8.23 Optimized ?ShiftLeft and ?ShiftRight a bit 328 ;* : 13.12.22 v8.30 Added 56-bit version 329 ;* : 14.01.03 Made use of _CMP_.S macro (instead of custom macro) 330 ;* : 14.02.07 v8.50 Added [ ... ] unsigned override (if SIGNED) 331 ;* : 14.02.14 v8.51 Eval macro now uses #HideMacros 332 ;* : 14.10.14 v8.52 BugFix: Off-by-one error in ResizeTOS when SIGNED 333 ;* : 15.03.21 v8.53 Replaced string dependencies with corresponding #Uses 334 ;* : 15.04.08 v8.54 Replaced AddDecimalPoint with corresponding #Uses 335 ;* : 17.04.03 v8.55 Optimized 24-bit multiply [-2 bytes] 336 ;* : Optimized 32-bit multiply [-7 bytes] 337 ;* : 18.10.23 Suppressed possible warning from JEQ in ?DivStart 338 ;* : 19.03.04 Added warning in _DoStr macro when using StrNN 339 ;* : when NN is different from MATHSIZE and no explicit 340 ;* : variable is given 341 ;* : 19.10.04 v8.56 Minor HC08 mode optimization in SIGNED ?ToStr [-1 byte] 342 ;* : 20.02.12 v8.57 Replaced #Message with @Msg to silence debugging messages 343 ;******************************************************************************* 344 345 ;Synopsis (replace * with 16, 24, 32, 40, 48, 56, 64 for corresponding bit version): 346 ; 347 ;Subroutines Action 348 ;-------------- ---------------------------- 349 ;StackAdd* - TOS := TOS + [TOS+1] (signed or unsigned) [TOS+1] removed 350 ;StackSub* - TOS := TOS - [TOS+1] (signed or unsigned) [TOS+1] removed 351 ;StackMul* - TOS := TOS * [TOS+1] (signed or unsigned) [TOS+1] removed 352 ;StackDiv* - TOS := TOS / [TOS+1] (signed if SIGNED) [TOS+1] removed 353 ;StackMod* - TOS := TOS \ [TOS+1] (signed if SIGNED) [TOS+1] removed 354 ;StackAnd* - TOS := TOS & [TOS+1] (signed or unsigned) [TOS+1] removed 355 ;StackOr* - TOS := TOS | [TOS+1] (signed or unsigned) [TOS+1] removed 356 ;StackXor* - TOS := TOS ^ [TOS+1] (signed or unsigned) [TOS+1] removed 357 ;StackShl* - TOS := TOS < [TOS+1] (signed or unsigned) [TOS+1] removed 358 ;StackShr* - TOS := TOS > [TOS+1] (signed if SIGNED) [TOS+1] removed 359 ;StackSwap* - TOS swapped with [TOS+1] (signed or unsigned) 360 ;StackAbs* - TOS := ABS(TOS) (signed) 361 ;StackNegate* - TOS := -TOS (signed) 362 ;StackLoad* - Load const/variable to TOS (signed or unsigned) TOS created 363 ;StackSave* - Save TOS into variable (signed or unsigned) TOS removed 364 ;ResizeTOS - Adjust TOS old size to new (signed or unsigned) TOS resized 365 ;Stack*ToASCIZ - Convert TOS to ASCIZ str (signed if SIGNED) 366 ; 367 ;Macros Purpose Parameters ([...] means optional part) 368 ;------------------ ------------------- ---------------------------------------- 369 ;Load* Stack const or var #Number | Variable 370 ;Save* Unstack a variable Variable 371 ;Copy* Load* & Save* #Number | Variable,Variable 372 ;ResizeTOS Resize TOS #FromByteSize,#ToByteSize 373 ; 374 ;Add* Addition [Addend[,Adder[,Sum]]] 375 ;Sub* Subtraction [Minuend[,Subtrahend[,Difference]]] 376 ;Mul* Multiplication [Multiplicand[,Multiplier[,Product]]] 377 ;Div* Unsigned division [Dividend[,Divisor[,Quotient]]] 378 ;Mod* Unsigned modulo [Dividend[,Divisor[,Remainder]]] 379 ;Abs* Absolute value [SourceVariable][,DestinationVariable] 380 ;Neg* Negation [SourceVariable][,DestinationVariable] 381 ;Swap* Swap TOS numbers 382 ;Str* Number to ASCIZ [Variable],[ResultString] 383 ;AddDecimalPoint ... to ASCIZ number [[#]DecimalPlaces[,[#]ASCIZ_String]] 384 411 412 0028 MATHSIZE def 32 ;default wordsize is 32-bit 413 417 418 ? macro BitSize 419 #if MATHSIZE = ~1~ 420 ?WORD equ ~1~/8 421 _STKMTH{MATHSIZE}_ ;;specific version included 422 _STAKMATH_ def * ;;any version included 423 #endif 424 endm 425 426 M @? 16 ;16-bit quantity (on request) 426 endm 427 M @? 24 ;24-bit quantity (on request) 427 endm 428 M @? 32 ;32-bit quantity (default) 428 endm 429 M @? 40 ;40-bit quantity (on request) 429 M 0005 ?WORD equ 40/8 429 M 2237 _STKMTH40_ 429 M 182C _STAKMATH_ def * 429 endm 430 M @? 48 ;48-bit quantity (on request) 430 endm 431 M @? 56 ;56-bit quantity (on request) 431 endm 432 M @? 64 ;64-bit quantity (on request) 432 endm 433 439 #Message MATHSIZE = {MATHSIZE}-bit version 441 #Message Signed routines enabled 443 ;******************************************************************************* 444 ; Macros to make operations as simple as with a high-level language 445 ; In operations that require two operands and a result, if only one operand is 446 ; provided, then the operation is done completely on stack (no other variables 447 ; used). For example, @Add32 A,B,SUM adds A to B and places result in SUM, 448 ; while @Add32 A adds the current stack top to A and leaves result on stack. 449 ; You can use @Load* and @Save* to load the initial value, and store the final 450 ; result, respectively. (Replace * with 16, 24, 32, 40, 48, 56, or 64) 451 ;******************************************************************************* 452 501 ;=============================================================================== 550 ;=============================================================================== 599 ;=============================================================================== 601 602 Load40 macro #Number|Variable ;load constant or variable 603 @_DoLoad ~0.{:0-1}~\,~@~ 604 endm 605 606 Save40 macro Address 607 @_DoSave 40\,~@~ 608 endm 609 610 Copy40 macro #Constant|Variable,ToAddress 611 mreq 1,2:#Constant|Variable,ToAddress 612 @@Load40 ~1~ 613 @Save40 ~2~ 614 endm 615 616 Swap40 macro 617 @_DoSwap 40 618 endm 619 620 Add40 macro Addend,Adder,Sum 621 @_DoMath ~0~\,40\,~1~\,~2~\,~3~ 622 endm 623 624 Sub40 macro Minuend,Subtrahend,Difference 625 @_DoMath ~0~\,40\,~1~\,~2~\,~3~ 626 endm 627 628 Mul40 macro Multiplicand,Multiplier,Product 629 @_DoMath ~0~\,40\,~1~\,~2~\,~3~ 630 endm 631 632 Div40 macro Dividend,Divisor,Quotient 633 @_DoMath ~0~\,40\,~1~\,~2~\,~3~ 634 endm 635 636 Mod40 macro Dividend,Divisor,Remainder 637 @_DoMath ~0~\,40\,~1~\,~2~\,~3~ 638 endm 639 640 Abs40 macro Source[,Destination] 641 @_DoAbs 40\,~1~\,~2~ 642 endm 643 644 Neg40 macro Source[,Destination] 645 @_DoNeg 40\,~1~\,~2~ 646 endm 648 ;=============================================================================== 697 ;=============================================================================== 746 ;=============================================================================== 795 796 ;******************************************************************************* 797 ; Common macro(s) for all operations defined above (not to be called directly) 798 ;******************************************************************************* 799 807 ;------------------------------------------------------------------------------- 867 ;------------------------------------------------------------------------------- 890 ;------------------------------------------------------------------------------- 898 ;------------------------------------------------------------------------------- 916 ;=============================================================================== 933 ;------------------------------------------------------------------------------- 1158 ;------------------------------------------------------------------------------- 1185 ;------------------------------------------------------------------------------- 1212 ;------------------------------------------------------------------------------- 1288 ;------------------------------------------------------------------------------- 1328 ;------------------------------------------------------------------------------- 1337 ;------------------------------------------------------------------------------- 1351 ;------------------------------------------------------------------------------- 1380 ;------------------------------------------------------------------------------- 1398 ;------------------------------------------------------------------------------- 1416 ;------------------------------------------------------------------------------- 1451 1452 ;******************************************************************************* 1453 ; External dependencies 1454 ;******************************************************************************* 1455 1456 #Uses string/length.sub 1457 #Uses string/insertchar.sub 1458 #Uses string/adddecimalpoint.sub 1459 2237 ?_OBJECT_? 1460 ;******************************************************************************* 1461 ; One-based (SP-index) offsets to stacked operands (to be used with #SPAUTO :AB) 1462 ;******************************************************************************* 1463 1464 #temp 1 1465 0001 ?a next :temp,?WORD ;top-of-stack (TOS) number (N1) 1466 0006 ?b next :temp,?WORD ;number after TOS (N2) 1467 1468 #Cycles ;reset the cycles counter 1469 1470 ;******************************************************************************* 1471 ; Purpose: Add N1 to N2 and place result on top-of-stack. N1 & N2 removed 1472 ; Input : [TOS+?WORD] = Number2 1473 ; : [TOS] = Number1 1474 ; Output : [TOS] = Result 1475 ; Note(s): Carry Set on overflow 1476 1477 #spauto :ab 1478 1479 2237 ?Add proc 1480 [2237] 2237:8789 8B [ 6] push 1481 [223A] 223A:95 [ 2] tsx 1482 1488 [223B] 223B:A605 [ 2] lda #?WORD 1489 [223D] 223D:98 [ 1] clc 1490 #Cycles 1491 [223E] 223E:87 [ 2] Loop@@ psha 1492 [223F] 223F:E609 [ 3] lda ?a+{::?a-1},spx 1493 [2241] 2241:E90E [ 3] adc ?b+{::?b-1},spx 1494 [2243] 2243:E70E [ 3] sta ?b+{::?b-1},spx 1495 [2245] 2245:86 [ 3] pula 1496 [2246] 2246:AFFF [ 2] aix #-1 1497 [2248] 2248:4BF4 (223E) [ 4] dbnza Loop@@ 1498 #Cycles :cycles*?WORD+:ocycles 1500 [224A] 224A:CC25 43 [ 4] jmp ?RemoveAndReturn 1501 1502 0073 ?AddCycles equ :cycles 1503 1504 ;******************************************************************************* 1505 ; Purpose: Subtract N2 from N1 and place result on top-of-stack. N1 & N2 removed 1506 ; Input : [TOS+?WORD] = Number2 1507 ; : [TOS] = Number1 1508 ; Output : [TOS] = Result 1509 ; Note(s): Carry Set on borrow 1510 1511 #spauto :ab 1512 1513 224D ?Subtract proc 1514 [224D] 224D:8789 8B [ 6] push 1515 [2250] 2250:95 [ 2] tsx 1521 [2251] 2251:A605 [ 2] lda #?WORD 1522 [2253] 2253:98 [ 1] clc 1523 #Cycles 1524 [2254] 2254:87 [ 2] Loop@@ psha 1525 [2255] 2255:E609 [ 3] lda ?a+{::?a-1},spx 1526 [2257] 2257:E20E [ 3] sbc ?b+{::?b-1},spx 1527 [2259] 2259:E70E [ 3] sta ?b+{::?b-1},spx 1528 [225B] 225B:86 [ 3] pula 1529 [225C] 225C:AFFF [ 2] aix #-1 1530 [225E] 225E:4BF4 (2254) [ 4] dbnza Loop@@ 1531 #Cycles :cycles*?WORD+:ocycles 1533 [2260] 2260:CC25 43 [ 4] jmp ?RemoveAndReturn 1534 1535 0073 ?SubCycles equ :cycles 1536 1540 M @Msg Bit ops enabled (define NO_BIT_OPS to disable) 1540 mexit 1541 ;******************************************************************************* 1542 ; Purpose: AND N1 with N2 and place result on top-of-stack. N1 & N2 removed 1543 ; Input : [TOS+?WORD] = Number2 1544 ; : [TOS] = Number1 1545 ; Output : [TOS] = Result 1546 ; Note(s): 1547 #spauto :ab 1548 1549 2263 ?BitAnd proc 1550 [2263] 2263:8789 8B [ 6] push 1551 [2266] 2266:95 [ 2] tsx 1552 1558 [2267] 2267:A605 [ 2] lda #?WORD 1559 #Cycles 1560 [2269] 2269:87 [ 2] Loop@@ psha 1561 [226A] 226A:E609 [ 3] lda ?a+{::?a-1},spx 1562 [226C] 226C:E40E [ 3] and ?b+{::?b-1},spx 1563 [226E] 226E:E70E [ 3] sta ?b+{::?b-1},spx 1564 [2270] 2270:86 [ 3] pula 1565 [2271] 2271:AFFF [ 2] aix #-1 1566 [2273] 2273:4BF4 (2269) [ 4] dbnza Loop@@ 1567 #Cycles :cycles*?WORD+:ocycles 1569 [2275] 2275:CC25 43 [ 4] jmp ?RemoveAndReturn 1570 1571 0072 ?AndCycles equ :cycles 1572 1573 ;******************************************************************************* 1574 ; Purpose: OR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1575 ; Input : [TOS+?WORD] = Number2 1576 ; : [TOS] = Number1 1577 ; Output : [TOS] = Result 1578 ; Note(s): 1579 #spauto :ab 1580 1581 2278 ?BitOr proc 1582 [2278] 2278:8789 8B [ 6] push 1583 [227B] 227B:95 [ 2] tsx 1584 1590 [227C] 227C:A605 [ 2] lda #?WORD 1591 #Cycles 1592 [227E] 227E:87 [ 2] Loop@@ psha 1593 [227F] 227F:E609 [ 3] lda ?a+{::?a-1},spx 1594 [2281] 2281:EA0E [ 3] ora ?b+{::?b-1},spx 1595 [2283] 2283:E70E [ 3] sta ?b+{::?b-1},spx 1596 [2285] 2285:86 [ 3] pula 1597 [2286] 2286:AFFF [ 2] aix #-1 1598 [2288] 2288:4BF4 (227E) [ 4] dbnza Loop@@ 1599 #Cycles :cycles*?WORD+:ocycles 1601 [228A] 228A:CC25 43 [ 4] jmp ?RemoveAndReturn 1602 1603 0072 ?OrCycles equ :cycles 1604 1605 ;******************************************************************************* 1606 ; Purpose: XOR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1607 ; Input : [TOS+?WORD] = Number2 1608 ; : [TOS] = Number1 1609 ; Output : [TOS] = Result 1610 ; Note(s): 1611 #spauto :ab 1612 1613 228D ?BitXor proc 1614 [228D] 228D:8789 8B [ 6] push 1615 [2290] 2290:95 [ 2] tsx 1616 1622 [2291] 2291:A605 [ 2] lda #?WORD 1623 #Cycles 1624 [2293] 2293:87 [ 2] Loop@@ psha 1625 [2294] 2294:E609 [ 3] lda ?a+{::?a-1},spx 1626 [2296] 2296:E80E [ 3] eor ?b+{::?b-1},spx 1627 [2298] 2298:E70E [ 3] sta ?b+{::?b-1},spx 1628 [229A] 229A:86 [ 3] pula 1629 [229B] 229B:AFFF [ 2] aix #-1 1630 [229D] 229D:4BF4 (2293) [ 4] dbnza Loop@@ 1631 #Cycles :cycles*?WORD+:ocycles 1633 [229F] 229F:CC25 43 [ 4] jmp ?RemoveAndReturn 1634 1635 0072 ?EorCycles equ :cycles 1636 1637 ;******************************************************************************* 1638 ; Purpose: Shift N1 left N2 times and place result on top-of-stack. N1 & N2 removed 1639 ; Input : [TOS+?WORD] = Number2 1640 ; : [TOS] = Number1 1641 ; Output : [TOS] = Result 1642 ; Note(s): CCR[C] = last most significant bit shifted out 1643 ; : Only LSB of second operand (N2) is used, as shifting more than the 1644 ; : highest bit version always produces zero. Any non-zero bytes in the 1645 ; : N2 operand will cause a zero result, regardless. 1646 1647 #spauto :ab 1648 1649 22A2 ?ShiftLeft proc 1650 [22A2] 22A2:8789 8B [ 6] push 1651 #ais 1652 1653 [22A5] 22A5:9EE6 0F [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1654 [22A8] 22A8:87 [ 2] psha counter@@ 1655 1656 [22A9] 22A9:95 [ 2] tsx 1657 1658 [22AA] 22AA:6F0F [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1659 0006 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1660 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1660 M mset # 1660 M mreq 1 1660 M @@_nosize_ b67,spx 1660 M mset # 1660 M mset 0,mstop [_tst_.s] No size (b67,spx) 1660 M endm 1660 M mdo 1660 M [22AC] 22AC:E60B [ 3] lda b67+0,spx 1660 M mloop ::b67 1660 M [22AE] 22AE:EA0C [ 3] ora b67+1,spx 1660 M mloop ::b67 1660 M [22B0] 22B0:EA0D [ 3] ora b67+2,spx 1660 M mloop ::b67 1660 M [22B2] 22B2:EA0E [ 3] ora b67+3,spx 1660 M mloop ::b67 1660 endm 1661 [22B4] 22B4:270F (22C5) [ 3] beq Go@@ ;if so, proceed normally 1662 1663 [22B6] 22B6:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1664 [22B7] 22B7:A128 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1665 [22B9] 22B9:250A (22C5) [ 3] blo Go@@ ;else zero and exit 1666 1667 M @clr.s, b@@,spx ;else error, so zero result 1667 M mset #' ' 1667 M mreq 1 1667 M @@_nosize_ b67,spx 1667 M mset # 1667 M mset 0,mstop [clr.s] No size (b67,spx) 1667 M endm 1667 M mdef 2,::b67 1667 M mdo 1667 M [22BB] 22BB:6F0B [ 5] clr b67+0,spx 1667 M mloop ::b67 1667 M [22BD] 22BD:6F0C [ 5] clr b67+1,spx 1667 M mloop ::b67 1667 M [22BF] 22BF:6F0D [ 5] clr b67+2,spx 1667 M mloop ::b67 1667 M [22C1] 22C1:6F0E [ 5] clr b67+3,spx 1667 M mloop ::b67 1667 endm 1668 [22C3] 22C3:2020 (22E5) [ 3] bra Done@@ ;and get out 1669 1670 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1670 M mset #' ' 1670 M mreq 1,2:Source Destination 1670 M @@_samesize_ ?a,spx ?b,spx 1670 M mreq 1,2:Operand1,Operand2[,Operand]* 1670 M mset 0 1670 M mdo 1670 M mswap 1,1 1670 M @@_nosize_ ?a,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?a,spx) 1670 M endm 1670 M mset 0,?a,spx 1670 M mloop :n 1670 M mswap 1,2 1670 M @@_nosize_ ?b,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?b,spx) 1670 M endm 1670 M mloop :n 1670 M endm 1670 M mset 0 1670 M mdo 1670 M [22C5] 22C5:E606 [ 3] lda ?a+0,spx 1670 M [22C7] 22C7:E70B [ 3] sta ?b+0,spx 1670 M mloop ::?b 1670 M [22C9] 22C9:E607 [ 3] lda ?a+1,spx 1670 M [22CB] 22CB:E70C [ 3] sta ?b+1,spx 1670 M mloop ::?b 1670 M [22CD] 22CD:E608 [ 3] lda ?a+2,spx 1670 M [22CF] 22CF:E70D [ 3] sta ?b+2,spx 1670 M mloop ::?b 1670 M [22D1] 22D1:E609 [ 3] lda ?a+3,spx 1670 M [22D3] 22D3:E70E [ 3] sta ?b+3,spx 1670 M mloop ::?b 1670 M [22D5] 22D5:E60A [ 3] lda ?a+4,spx 1670 M [22D7] 22D7:E70F [ 3] sta ?b+4,spx 1670 M mloop ::?b 1670 endm 1671 #Cycles 1672 M Loop@@ @lsl.s, ?b,spx ;shift left one bit position 1672 M mset # 1672 M mreq 1 1672 M @@_nosize_ ?b,spx 1672 M mset # 1672 M mset 0,mstop [lsl.s] No size (?b,spx) 1672 M endm 1672 M mdo 1672 M [22D9] 22D9:680F [ 5] lsl ?b+4,spx 1672 M mloop ::?b 1672 M [22DB] 22DB:690E [ 5] rol ?b+3,spx 1672 M mloop ::?b 1672 M [22DD] 22DD:690D [ 5] rol ?b+2,spx 1672 M mloop ::?b 1672 M [22DF] 22DF:690C [ 5] rol ?b+1,spx 1672 M mloop ::?b 1672 M [22E1] 22E1:690B [ 5] rol ?b+0,spx 1672 M mloop ::?b 1672 endm 1673 [22E3] 22E3:7BF4 (22D9) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1674 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1675 22E5 Done@@ 1677 [22E5] 22E5:86 [ 3] pula 1681 [22E6] 22E6:CC25 43 [ 4] jmp ?RemoveAndReturn 1682 1683 051F ?ShlCycles equ :cycles 1684 1685 ;******************************************************************************* 1686 ; Purpose: Shift N1 right N2 times and place result on top-of-stack. N1 & N2 removed 1687 ; Input : [TOS+?WORD] = Number2 1688 ; : [TOS] = Number1 1689 ; Output : [TOS] = Result 1690 ; Note(s): CCR[C] = last least significant bit shifted out 1691 ; : Only LSB of second operand (N2) is used, as shifting more than the 1692 ; : highest bit version always produces zero. Any non-zero bytes in the 1693 ; : N2 operand will cause a zero result, regardless. 1694 1695 #spauto :ab 1696 1697 22E9 ?ShiftRight proc 1698 [22E9] 22E9:8789 8B [ 6] push 1699 #ais 1700 1701 [22EC] 22EC:9EE6 0F [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1702 [22EF] 22EF:87 [ 2] psha counter@@ 1703 1704 [22F0] 22F0:95 [ 2] tsx 1705 1706 [22F1] 22F1:6F0F [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1707 0006 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1708 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1708 M mset # 1708 M mreq 1 1708 M @@_nosize_ b68,spx 1708 M mset # 1708 M mset 0,mstop [_tst_.s] No size (b68,spx) 1708 M endm 1708 M mdo 1708 M [22F3] 22F3:E60B [ 3] lda b68+0,spx 1708 M mloop ::b68 1708 M [22F5] 22F5:EA0C [ 3] ora b68+1,spx 1708 M mloop ::b68 1708 M [22F7] 22F7:EA0D [ 3] ora b68+2,spx 1708 M mloop ::b68 1708 M [22F9] 22F9:EA0E [ 3] ora b68+3,spx 1708 M mloop ::b68 1708 endm 1709 [22FB] 22FB:270F (230C) [ 3] beq Go@@ ;if so, proceed normally 1710 1711 [22FD] 22FD:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1712 [22FE] 22FE:A128 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1713 [2300] 2300:250A (230C) [ 3] blo Go@@ ;else zero and exit 1714 1715 M @clr.s, b@@,spx ;else error, so zero result 1715 M mset #' ' 1715 M mreq 1 1715 M @@_nosize_ b68,spx 1715 M mset # 1715 M mset 0,mstop [clr.s] No size (b68,spx) 1715 M endm 1715 M mdef 2,::b68 1715 M mdo 1715 M [2302] 2302:6F0B [ 5] clr b68+0,spx 1715 M mloop ::b68 1715 M [2304] 2304:6F0C [ 5] clr b68+1,spx 1715 M mloop ::b68 1715 M [2306] 2306:6F0D [ 5] clr b68+2,spx 1715 M mloop ::b68 1715 M [2308] 2308:6F0E [ 5] clr b68+3,spx 1715 M mloop ::b68 1715 endm 1716 [230A] 230A:2020 (232C) [ 3] bra Done@@ ;and get out 1717 1718 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1718 M mset #' ' 1718 M mreq 1,2:Source Destination 1718 M @@_samesize_ ?a,spx ?b,spx 1718 M mreq 1,2:Operand1,Operand2[,Operand]* 1718 M mset 0 1718 M mdo 1718 M mswap 1,1 1718 M @@_nosize_ ?a,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?a,spx) 1718 M endm 1718 M mset 0,?a,spx 1718 M mloop :n 1718 M mswap 1,2 1718 M @@_nosize_ ?b,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?b,spx) 1718 M endm 1718 M mloop :n 1718 M endm 1718 M mset 0 1718 M mdo 1718 M [230C] 230C:E606 [ 3] lda ?a+0,spx 1718 M [230E] 230E:E70B [ 3] sta ?b+0,spx 1718 M mloop ::?b 1718 M [2310] 2310:E607 [ 3] lda ?a+1,spx 1718 M [2312] 2312:E70C [ 3] sta ?b+1,spx 1718 M mloop ::?b 1718 M [2314] 2314:E608 [ 3] lda ?a+2,spx 1718 M [2316] 2316:E70D [ 3] sta ?b+2,spx 1718 M mloop ::?b 1718 M [2318] 2318:E609 [ 3] lda ?a+3,spx 1718 M [231A] 231A:E70E [ 3] sta ?b+3,spx 1718 M mloop ::?b 1718 M [231C] 231C:E60A [ 3] lda ?a+4,spx 1718 M [231E] 231E:E70F [ 3] sta ?b+4,spx 1718 M mloop ::?b 1718 endm 1719 #Cycles 1720 2320 Loop@@ 1722 M @asr.s, ?b,spx ;shift right one bit position 1722 M mset # 1722 M mreq 1 1722 M @@_nosize_ ?b,spx 1722 M mset # 1722 M mset 0,mstop [asr.s] No size (?b,spx) 1722 M endm 1722 M mdo 1722 M [2320] 2320:670B [ 5] asr ?b+0,spx 1722 M mloop ::?b 1722 M [2322] 2322:660C [ 5] ror ?b+1,spx 1722 M mloop ::?b 1722 M [2324] 2324:660D [ 5] ror ?b+2,spx 1722 M mloop ::?b 1722 M [2326] 2326:660E [ 5] ror ?b+3,spx 1722 M mloop ::?b 1722 M [2328] 2328:660F [ 5] ror ?b+4,spx 1722 M mloop ::?b 1722 endm 1726 [232A] 232A:7BF4 (2320) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1727 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1728 232C Done@@ 1730 [232C] 232C:86 [ 3] pula 1734 [232D] 232D:CC25 43 [ 4] jmp ?RemoveAndReturn 1735 1736 051F ?ShrCycles equ :cycles 1738 1739 ;******************************************************************************* 1740 ; Purpose: Multiply N1 with N2 and place result on top-of-stack. N1 & N2 removed 1741 ; Input : [TOS+?WORD] = Number2 1742 ; : [TOS] = Number1 1743 ; Output : [TOS] = Result 1744 ; Note(s): Overflows lost, Carry state should be ignored 1745 1746 #spauto :ab 1747 1748 2330 ?Multiply proc 1749 [2330] 2330:8789 8B [ 6] push 1773 ;=============================================================================== 1826 ;=============================================================================== 1913 #temp :cycles 1914 ;=============================================================================== 1915 ;-------------------------------------- 1916 ; 40, 48, 56, and 64-bit versions use shorter 1917 ; shift/add method (more cycles, though) 1918 ;-------------------------------------- 1920 1921 [2333] 2333:AE05 [ 2] ldx #?WORD ;make room for result... 1922 [2335] 2335:4F [ 1] clra ;... initialized to zero 1923 #temp :cycles+:temp 1924 [2336] 2336:87 [ 2] Init@@ psha 1925 [2337] 2337:5BFD (2336) [ 4] dbnzx Init@@ 1926 #temp :cycles*?WORD+:temp 1927 #spadd ?WORD-1 ;stack has grown by a ?WORD 1928 FFFFFFF7 ans@@ equ ::,?WORD 1929 1930 [2339] 2339:A628 [ 2] lda #MATHSIZE ;number of bits to process 1931 [233B] 233B:87 [ 2] psha bits@@ 1932 1933 [233C] 233C:95 [ 2] tsx 1934 #temp :cycles+:temp 1935 M Loop@@ @lsr.s ?b,spx ;multiplier lsb into CCR[C] 1935 M mset # 1935 M mreq 1 1935 M @@_nosize_ ?b,spx 1935 M mset # 1935 M mset 0,mstop [lsr.s] No size (?b,spx) 1935 M endm 1935 M mdo 1935 M [233D] 233D:6410 [ 5] lsr ?b+0,spx 1935 M mloop ::?b 1935 M [233F] 233F:6611 [ 5] ror ?b+1,spx 1935 M mloop ::?b 1935 M [2341] 2341:6612 [ 5] ror ?b+2,spx 1935 M mloop ::?b 1935 M [2343] 2343:6613 [ 5] ror ?b+3,spx 1935 M mloop ::?b 1935 M [2345] 2345:6614 [ 5] ror ?b+4,spx 1935 M mloop ::?b 1935 endm 1936 [2347] 2347:241E (2367) [ 3] bcc Skip@@ ;Zeros skip addition 1937 1938 M @add.s ?a,spx ans@@,spx ans@@,spx ;Ones add multiplicand to product 1938 M mset #' ' 1938 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1938 M @@_samesize_ ?a,spx ans69,spx ans@@,spx 1938 M mreq 1,2:Operand1,Operand2[,Operand]* 1938 M mset 0 1938 M mdo 1938 M mswap 1,1 1938 M @@_nosize_ ?a,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (?a,spx) 1938 M endm 1938 M mset 0,?a,spx 1938 M mloop :n 1938 M mswap 1,2 1938 M @@_nosize_ ans69,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans69,spx) 1938 M endm 1938 M mloop :n 1938 M mswap 1,3 1938 M @@_nosize_ ans@@,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans69,spx) 1938 M endm 1938 M mloop :n 1938 M endm 1938 M mset 0,@@add.b, 1938 M mdo 1938 M mset 0,@@add.b, ?a+4,spx 1938 M mset 0,@@add.b, ?a+4,spx ans69+4,spx 1938 M mset 0,@@add.b, ?a+4,spx ans69+4,spx ans@@+4,spx 1938 M @@add.b, ?a+4,spx ans69+4,spx ans@@+4,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2349] 2349:E60F [ 3] lda ?a+4,spx 1938 M [234B] 234B:EB05 [ 3] add ans69+4,spx 1938 M @_sta_ ans@@+4,spx 1938 M [234D] 234D:E705 [ 3] sta ans69+4,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans69+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans69+3,spx ans@@+3,spx 1938 M @@adc.b, ?a+3,spx ans69+3,spx ans@@+3,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [234F] 234F:E60E [ 3] lda ?a+3,spx 1938 M [2351] 2351:E904 [ 3] adc ans69+3,spx 1938 M @_sta_ ans@@+3,spx 1938 M [2353] 2353:E704 [ 3] sta ans69+3,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans69+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans69+2,spx ans@@+2,spx 1938 M @@adc.b, ?a+2,spx ans69+2,spx ans@@+2,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2355] 2355:E60D [ 3] lda ?a+2,spx 1938 M [2357] 2357:E903 [ 3] adc ans69+2,spx 1938 M @_sta_ ans@@+2,spx 1938 M [2359] 2359:E703 [ 3] sta ans69+2,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans69+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans69+1,spx ans@@+1,spx 1938 M @@adc.b, ?a+1,spx ans69+1,spx ans@@+1,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [235B] 235B:E60C [ 3] lda ?a+1,spx 1938 M [235D] 235D:E902 [ 3] adc ans69+1,spx 1938 M @_sta_ ans@@+1,spx 1938 M [235F] 235F:E702 [ 3] sta ans69+1,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans69+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans69+0,spx ans@@+0,spx 1938 M @@adc.b, ?a+0,spx ans69+0,spx ans@@+0,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2361] 2361:E60B [ 3] lda ?a+0,spx 1938 M [2363] 2363:E901 [ 3] adc ans69+0,spx 1938 M @_sta_ ans@@+0,spx 1938 M [2365] 2365:E701 [ 3] sta ans69+0,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 endm 1939 1940 M Skip@@ @lsl.s ?a,spx ;Multiplicand*=2 for each bit 1940 M mset # 1940 M mreq 1 1940 M @@_nosize_ ?a,spx 1940 M mset # 1940 M mset 0,mstop [lsl.s] No size (?a,spx) 1940 M endm 1940 M mdo 1940 M [2367] 2367:680F [ 5] lsl ?a+4,spx 1940 M mloop ::?a 1940 M [2369] 2369:690E [ 5] rol ?a+3,spx 1940 M mloop ::?a 1940 M [236B] 236B:690D [ 5] rol ?a+2,spx 1940 M mloop ::?a 1940 M [236D] 236D:690C [ 5] rol ?a+1,spx 1940 M mloop ::?a 1940 M [236F] 236F:690B [ 5] rol ?a+0,spx 1940 M mloop ::?a 1940 endm 1941 [2371] 2371:7BCA (233D) [ 6] dbnz bits@@,spx,Loop@@ 1942 #temp :cycles*MATHSIZE+:temp 1943 [2373] 2373:86 [ 3] pula ;remove bit counter 1945 ;-------------------------------------- 1946 ; copy result to B while removing from stack 1947 ;-------------------------------------- 1948 [2374] 2374:AE05 [ 2] ldx #?WORD 1949 #temp :cycles+:temp 1950 [2376] 2376:86 [ 3] CopyResult@@ pula 1951 [2377] 2377:9EE7 0F [ 4] sta ?b,sp 1952 [237A] 237A:5BFA (2376) [ 4] dbnzx CopyResult@@ 1953 1954 #spadd 1-?WORD 1955 #temp :cycles*?WORD+:temp 1956 [237C] 237C:CC25 43 [ 4] jmp ?RemoveAndReturn 1957 1958 10AD ?MulCycles equ :temp+:cycles 1959 1960 ;******************************************************************************* 1961 ; Purpose: Divide N1 by N2 and place quotient on top-of-stack. N1 & N2 removed 1962 ; Input : [TOS+?WORD] = Divisor (N2) 1963 ; : [TOS] = Dividend (N1) 1964 ; Output : [TOS] = Quotient 1965 ; : Carry Set on error (division by zero) 1966 ; Note(s): 1967 #spauto :ab 1968 1969 237F ?Divide proc 1970 [237F] 237F:8789 8B [ 6] push 1971 1972 [2382] 2382:A601 [ 2] lda #?DIVOP_ ;flag for DIV operation 1974 [2384] 2384:87 [ 2] psha 1975 [2385] 2385:95 [ 2] tsx 1976 [2386] 2386:E606 [ 3] lda ?a,spx 1977 [2388] 2388:E80B [ 3] eor ?b,spx 1978 [238A] 238A:86 [ 3] pula 1979 [238B] 238B:2A02 (238F) [ 3] bpl Skip@@ 1980 [238D] 238D:AA80 [ 2] ora #?SIGN_ ;flag for negative 1981 238F Skip@@ 1983 [238F] 238F:87 [ 2] psha ;save flags on stack 1984 [2390] 2390:2030 (23C2) [ 3] bra ?DivStart 1985 1986 001F ?DivCycles equ :cycles 1987 1988 ;******************************************************************************* 1989 ; Purpose: Divide N1 by N2 and place remainder on top-of-stack. N1 & N2 removed 1990 ; Input : [TOS+?WORD] = Divisor (N2) 1991 ; : [TOS] = Dividend (N1) 1992 ; Output : [TOS] = Remainder 1993 ; : Carry Set on error (division by zero) 1994 ; Note(s): 1995 #spauto :ab 1996 FFFFFFFF ?pc equ ::,:ab 1997 1998 2392 ?Modulo proc 1999 [2392] 2392:8789 8B [ 6] push 2000 2001 [2395] 2395:4F [ 1] clra ;flag for MOD operation 2003 [2396] 2396:9E6D 06 [ 5] tst ?a,sp 2004 [2399] 2399:2A02 (239D) [ 3] bpl Skip@@ 2005 [239B] 239B:AA80 [ 2] ora #?SIGN_ ;flag for negative 2006 239D Skip@@ 2008 [239D] 239D:87 [ 2] psha ;save flags on stack 2009 [239E] 239E:2022 (23C2) [ 3] bra ?DivStart 2010 2011 0016 ?ModCycles equ :cycles 2012 2013 ;******************************************************************************* 2014 2015 #temp 2017 23A0 ?AbsX proc 2018 [23A0] 23A0:7D [ 3] tst ,ax 2019 [23A1] 23A1:2A18 (23BB) [ 3] bpl Done@@ 2020 #temp :cycles 2021 0000 var@@ equ 0,?WORD 2022 M ?NegX @neg.s var@@,ax 2022 M mset # 2022 M mreq 1 2022 M @@_nosize_ var72,ax 2022 M mset # 2022 M mset 0,mstop [neg.s] No size (var72,ax) 2022 M endm 2022 M mdo 2022 M [23A3] 23A3:73 [ 4] com var72+0,ax 2022 M mloop ::var72-1 2022 M [23A4] 23A4:6301 [ 5] com var72+1,ax 2022 M mloop ::var72-1 2022 M [23A6] 23A6:6302 [ 5] com var72+2,ax 2022 M mloop ::var72-1 2022 M [23A8] 23A8:6303 [ 5] com var72+3,ax 2022 M mloop ::var72-1 2022 M [23AA] 23AA:6004 [ 5] neg var72+4,ax 2022 M mdo 2022 M [23AC] 23AC:260D (23BB) [ 3] bne Done$$$ 2022 M [23AE] 23AE:6C03 [ 5] inc var72+3,ax 2022 M mloop ::var72-1 2022 M [23B0] 23B0:2609 (23BB) [ 3] bne Done$$$ 2022 M [23B2] 23B2:6C02 [ 5] inc var72+2,ax 2022 M mloop ::var72-1 2022 M [23B4] 23B4:2605 (23BB) [ 3] bne Done$$$ 2022 M [23B6] 23B6:6C01 [ 5] inc var72+1,ax 2022 M mloop ::var72-1 2022 M [23B8] 23B8:2601 (23BB) [ 3] bne Done$$$ 2022 M [23BA] 23BA:7C [ 4] inc var72+0,ax 2022 M mloop ::var72-1 2022 M 23BB Done$$$ 2022 endm 2023 [23BB] 23BB:81 [ 6] Done@@ rts 2024 2025 003D ?AbsXCycles equ :cycles 2026 0037 ?NegxCycles equ ?AbsXCycles-:temp 2028 2029 ;******************************************************************************* 2030 2031 0000 ?SF equ 0 ;stack frame (for X-index use) 2032 2033 0000 ?quotient next ?SF,?WORD 2034 0005 ?remainder next ?SF,?WORD 2035 000A ?temp next ?SF,?WORD 2036 000F ?bits next ?SF 2037 0010 ?flags next ?SF 2038 2039 0001 ?DIVOP_ equ %00000001 ;1 = DIV, 0 = MOD 2040 0080 ?SIGN_ equ %10000000 ;result sign (1 = negative) 2041 2042 #push 2043 2044 [23BC] 23BC:A711 [ 2] ?DivError ais #?SF ;de-allocate temporaries 2045 [23BE] 23BE:99 [ 1] sec ;indicate error condition 2046 [23BF] 23BF:CC25 43 [ 4] jmp ?RemoveAndReturn 2047 2048 #pull 2049 ;------------------------------------------------------------------------------- 2050 23C2 ?DivStart proc 2051 0001 dividend@@ equ ?a,::?a 2052 0006 divisor@@ equ ?b,::?b 2053 0006 ans@@ equ ?b,::?b ;result overwrites divisor 2054 2056 M @lea dividend@@,sp 2056 M mset # 2056 M [23C2] 23C2:95 [ 2] tsx 2056 M [23C3] 23C3:AF06 [ 2] !aix #dividend73+:tsx 2056 mexit 2057 [23C5] 23C5:ADD9 (23A0) [ 5] bsr ?AbsX 2058 M @lea divisor@@,sp 2058 M mset # 2058 M [23C7] 23C7:95 [ 2] tsx 2058 M [23C8] 23C8:AF0B [ 2] !aix #divisor73+:tsx 2058 mexit 2059 [23CA] 23CA:ADD4 (23A0) [ 5] bsr ?AbsX 2060 #Cycles ?AbsXCycles*2+:cycles 2062 [23CC] 23CC:A7F0 [ 2] ais #-?SF+1 ;quotient, remainder, and temp 2063 [23CE] 23CE:95 [ 2] tsx ;(+1 for already pushed Flag) 2064 2065 ; remainder := 0 2066 ; quotient := 0 2067 2068 M @clr.s ?remainder,x 2068 M mset #' ' 2068 M mreq 1 2068 M @@_nosize_ ?remainder,x 2068 M mset # 2068 M mset 0,mstop [clr.s] No size (?remainder,x) 2068 M endm 2068 M mdef 2,::?remainder 2068 M mdo 2068 M [23CF] 23CF:6F05 [ 5] clr ?remainder+0,x 2068 M mloop ::?remainder 2068 M [23D1] 23D1:6F06 [ 5] clr ?remainder+1,x 2068 M mloop ::?remainder 2068 M [23D3] 23D3:6F07 [ 5] clr ?remainder+2,x 2068 M mloop ::?remainder 2068 M [23D5] 23D5:6F08 [ 5] clr ?remainder+3,x 2068 M mloop ::?remainder 2068 M [23D7] 23D7:6F09 [ 5] clr ?remainder+4,x 2068 M mloop ::?remainder 2068 endm 2069 M @clr.s ?quotient,x 2069 M mset #' ' 2069 M mreq 1 2069 M @@_nosize_ ?quotient,x 2069 M mset # 2069 M mset 0,mstop [clr.s] No size (?quotient,x) 2069 M endm 2069 M mdef 2,::?quotient 2069 M mdo 2069 M [23D9] 23D9:7F [ 4] clr ?quotient+0,x 2069 M mloop ::?quotient 2069 M [23DA] 23DA:6F01 [ 5] clr ?quotient+1,x 2069 M mloop ::?quotient 2069 M [23DC] 23DC:6F02 [ 5] clr ?quotient+2,x 2069 M mloop ::?quotient 2069 M [23DE] 23DE:6F03 [ 5] clr ?quotient+3,x 2069 M mloop ::?quotient 2069 M [23E0] 23E0:6F04 [ 5] clr ?quotient+4,x 2069 M mloop ::?quotient 2069 endm 2070 2071 ; first, test for division by zero error 2072 2073 M @_tst_.s divisor@@,spx 2073 M mset # 2073 M mreq 1 2073 M @@_nosize_ divisor73,spx 2073 M mset # 2073 M mset 0,mstop [_tst_.s] No size (divisor73,spx) 2073 M endm 2073 M mdo 2073 M [23E2] 23E2:E61B [ 3] lda divisor73+0,spx 2073 M mloop ::divisor73 2073 M [23E4] 23E4:EA1C [ 3] ora divisor73+1,spx 2073 M mloop ::divisor73 2073 M [23E6] 23E6:EA1D [ 3] ora divisor73+2,spx 2073 M mloop ::divisor73 2073 M [23E8] 23E8:EA1E [ 3] ora divisor73+3,spx 2073 M mloop ::divisor73 2073 M [23EA] 23EA:EA1F [ 3] ora divisor73+4,spx 2073 M mloop ::divisor73 2073 endm 2074 [23EC] 23EC:27CE (23BC) [ 3] beq ?DivError 2075 2076 ; if Dividend = 0, we're done 2077 2078 M @_tst_.s dividend@@,spx 2078 M mset # 2078 M mreq 1 2078 M @@_nosize_ dividend73,spx 2078 M mset # 2078 M mset 0,mstop [_tst_.s] No size (dividend73,spx) 2078 M endm 2078 M mdo 2078 M [23EE] 23EE:E616 [ 3] lda dividend73+0,spx 2078 M mloop ::dividend73 2078 M [23F0] 23F0:EA17 [ 3] ora dividend73+1,spx 2078 M mloop ::dividend73 2078 M [23F2] 23F2:EA18 [ 3] ora dividend73+2,spx 2078 M mloop ::dividend73 2078 M [23F4] 23F4:EA19 [ 3] ora dividend73+3,spx 2078 M mloop ::dividend73 2078 M [23F6] 23F6:EA1A [ 3] ora dividend73+4,spx 2078 M mloop ::dividend73 2078 endm 2079 [23F8] 23F8:2603 CC25 07 [ 7] !jeq Done@@ 2080 2081 ; if (divisor = dividend) then quotient := 1; return 2082 ; if (divisor > dividend) then remainder := dividend; return 2083 2084 M @_cmp_.s divisor@@,spx dividend@@,spx 2084 M mset #' ' 2084 M mreq 1,2:[#]Operand1 [#]Operand2 2084 M @@_samesize_ divisor73,spx dividend@@,spx 2084 M mreq 1,2:Operand1,Operand2[,Operand]* 2084 M mset 0 2084 M mdo 2084 M mswap 1,1 2084 M @@_nosize_ divisor73,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (divisor73,spx) 2084 M endm 2084 M mset 0,divisor73,spx 2084 M mloop :n 2084 M mswap 1,2 2084 M @@_nosize_ dividend@@,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (dividend73,spx) 2084 M endm 2084 M mloop :n 2084 M endm 2084 M #temp 1 2084 M #temp ::divisor73 2084 M #temp ::dividend@@ 2084 M mdo 2084 M [23FD] 23FD:E61B [ 3] lda divisor73+0,spx 2084 M [23FF] 23FF:E116 [ 3] cmpa dividend@@+0,spx 2084 M [2401] 2401:2616 (2419) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2403] 2403:E61C [ 3] lda divisor73+1,spx 2084 M [2405] 2405:E117 [ 3] cmpa dividend@@+1,spx 2084 M [2407] 2407:2610 (2419) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2409] 2409:E61D [ 3] lda divisor73+2,spx 2084 M [240B] 240B:E118 [ 3] cmpa dividend@@+2,spx 2084 M [240D] 240D:260A (2419) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [240F] 240F:E61E [ 3] lda divisor73+3,spx 2084 M [2411] 2411:E119 [ 3] cmpa dividend@@+3,spx 2084 M [2413] 2413:2604 (2419) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2415] 2415:E61F [ 3] lda divisor73+4,spx 2084 M [2417] 2417:E11A [ 3] cmpa dividend@@+4,spx 2084 M mloop :temp 2084 M 2419 Done$$$ 2084 endm 2085 [2419] 2419:2604 (241F) [ 3] bne NotEqual@@ 2086 2087 [241B] 241B:6C04 [ 5] inc ?quotient+{::?quotient-1},x ;quotient := 1 2088 [241D] 241D:2016 (2435) [ 3] bra ??DivExit ;and get out 2089 2090 241F NotEqual@@ ;@sub.s divisor@@,spx dividend@@,spx ;[2012.05.18 REDUNDANT] 2091 [241F] 241F:2517 (2438) [ 3] blo Continue@@ 2092 2093 M @mova.s dividend@@,spx ?remainder,x 2093 M mset #' ' 2093 M mreq 1,2:Source Destination 2093 M @@_samesize_ dividend73,spx ?remainder,x 2093 M mreq 1,2:Operand1,Operand2[,Operand]* 2093 M mset 0 2093 M mdo 2093 M mswap 1,1 2093 M @@_nosize_ dividend73,spx 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (dividend73,spx) 2093 M endm 2093 M mset 0,dividend73,spx 2093 M mloop :n 2093 M mswap 1,2 2093 M @@_nosize_ ?remainder,x 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (?remainder,x) 2093 M endm 2093 M mloop :n 2093 M endm 2093 M mset 0 2093 M mdo 2093 M [2421] 2421:E616 [ 3] lda dividend73+0,spx 2093 M [2423] 2423:E705 [ 3] sta ?remainder+0,x 2093 M mloop ::?remainder 2093 M [2425] 2425:E617 [ 3] lda dividend73+1,spx 2093 M [2427] 2427:E706 [ 3] sta ?remainder+1,x 2093 M mloop ::?remainder 2093 M [2429] 2429:E618 [ 3] lda dividend73+2,spx 2093 M [242B] 242B:E707 [ 3] sta ?remainder+2,x 2093 M mloop ::?remainder 2093 M [242D] 242D:E619 [ 3] lda dividend73+3,spx 2093 M [242F] 242F:E708 [ 3] sta ?remainder+3,x 2093 M mloop ::?remainder 2093 M [2431] 2431:E61A [ 3] lda dividend73+4,spx 2093 M [2433] 2433:E709 [ 3] sta ?remainder+4,x 2093 M mloop ::?remainder 2093 endm 2094 2435 ??DivExit ;and get out 2098 [2435] 2435:CC25 07 [ 4] jmp Done@@ 2100 2101 [2438] 2438:A628 [ 2] Continue@@ lda #MATHSIZE 2102 [243A] 243A:E70F [ 3] sta ?bits,x ;bits := 64/56/48/40/32/24/16-bit 2103 2104 ; while (remainder < divisor) do 2105 2106 M While@@ @cop ;in case of many iterations 2106 M [243C] 243C:C718 00 [ 4] sta COP 2106 endm 2107 2108 M @sub.s ?remainder,x divisor@@,spx 2108 M mset #' ' 2108 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2108 M @@_samesize_ ?remainder,x divisor73,spx 2108 M mreq 1,2:Operand1,Operand2[,Operand]* 2108 M mset 0 2108 M mdo 2108 M mswap 1,1 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (?remainder,x) 2108 M endm 2108 M mset 0,?remainder,x 2108 M mloop :n 2108 M mswap 1,2 2108 M @@_nosize_ divisor73,spx 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (divisor73,spx) 2108 M endm 2108 M mloop :n 2108 M endm 2108 M #temp 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [sub.s] No size (?remainder,x) 2108 M endm 2108 M #temp ::?remainder 2108 M mset 0,sub 2108 M mdo 2108 M [243F] 243F:E609 [ 3] lda ?remainder+4,x 2108 M [2441] 2441:E01F [ 3] sub divisor73+4,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2443] 2443:E608 [ 3] lda ?remainder+3,x 2108 M [2445] 2445:E21E [ 3] sbc divisor73+3,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2447] 2447:E607 [ 3] lda ?remainder+2,x 2108 M [2449] 2449:E21D [ 3] sbc divisor73+2,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [244B] 244B:E606 [ 3] lda ?remainder+1,x 2108 M [244D] 244D:E21C [ 3] sbc divisor73+1,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [244F] 244F:E605 [ 3] lda ?remainder+0,x 2108 M [2451] 2451:E21B [ 3] sbc divisor73+0,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 endm 2109 [2453] 2453:242C (2481) [ 3] bcc EndWhile@@ 2110 2111 ; remainder := (remainder shl 1) or msb(dividend) 2112 ;-------------------------------------- ;2012.12.04 optimization (moved up this code from before DEC to here) 2113 M @mova.s dividend@@,spx ?temp,x ; temp := dividend 2113 M mset #' ' 2113 M mreq 1,2:Source Destination 2113 M @@_samesize_ dividend73,spx ?temp,x 2113 M mreq 1,2:Operand1,Operand2[,Operand]* 2113 M mset 0 2113 M mdo 2113 M mswap 1,1 2113 M @@_nosize_ dividend73,spx 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (dividend73,spx) 2113 M endm 2113 M mset 0,dividend73,spx 2113 M mloop :n 2113 M mswap 1,2 2113 M @@_nosize_ ?temp,x 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (?temp,x) 2113 M endm 2113 M mloop :n 2113 M endm 2113 M mset 0 2113 M mdo 2113 M [2455] 2455:E616 [ 3] lda dividend73+0,spx 2113 M [2457] 2457:E70A [ 3] sta ?temp+0,x 2113 M mloop ::?temp 2113 M [2459] 2459:E617 [ 3] lda dividend73+1,spx 2113 M [245B] 245B:E70B [ 3] sta ?temp+1,x 2113 M mloop ::?temp 2113 M [245D] 245D:E618 [ 3] lda dividend73+2,spx 2113 M [245F] 245F:E70C [ 3] sta ?temp+2,x 2113 M mloop ::?temp 2113 M [2461] 2461:E619 [ 3] lda dividend73+3,spx 2113 M [2463] 2463:E70D [ 3] sta ?temp+3,x 2113 M mloop ::?temp 2113 M [2465] 2465:E61A [ 3] lda dividend73+4,spx 2113 M [2467] 2467:E70E [ 3] sta ?temp+4,x 2113 M mloop ::?temp 2113 endm 2114 M @lsl.s dividend@@,spx ; dividend := dividend shl 1 2114 M mset # 2114 M mreq 1 2114 M @@_nosize_ dividend73,spx 2114 M mset # 2114 M mset 0,mstop [lsl.s] No size (dividend73,spx) 2114 M endm 2114 M mdo 2114 M [2469] 2469:681A [ 5] lsl dividend73+4,spx 2114 M mloop ::dividend73 2114 M [246B] 246B:6919 [ 5] rol dividend73+3,spx 2114 M mloop ::dividend73 2114 M [246D] 246D:6918 [ 5] rol dividend73+2,spx 2114 M mloop ::dividend73 2114 M [246F] 246F:6917 [ 5] rol dividend73+1,spx 2114 M mloop ::dividend73 2114 M [2471] 2471:6916 [ 5] rol dividend73+0,spx 2114 M mloop ::dividend73 2114 endm 2115 ;-------------------------------------- 2116 M @rol.s ?remainder,x 2116 M mset # 2116 M mreq 1 2116 M @@_nosize_ ?remainder,x 2116 M mset # 2116 M mset 0,mstop [rol.s] No size (?remainder,x) 2116 M endm 2116 M mdo 2116 M [2473] 2473:6909 [ 5] rol ?remainder+4,x 2116 M mloop ::?remainder 2116 M [2475] 2475:6908 [ 5] rol ?remainder+3,x 2116 M mloop ::?remainder 2116 M [2477] 2477:6907 [ 5] rol ?remainder+2,x 2116 M mloop ::?remainder 2116 M [2479] 2479:6906 [ 5] rol ?remainder+1,x 2116 M mloop ::?remainder 2116 M [247B] 247B:6905 [ 5] rol ?remainder+0,x 2116 M mloop ::?remainder 2116 endm 2117 [247D] 247D:6A0F [ 5] dec ?bits,x ; bits := bits - 1 2118 2119 ; end while 2120 2121 [247F] 247F:20BB (243C) [ 3] bra While@@ 2122 2481 EndWhile@@ 2123 M @mova.s ?temp,x dividend@@,spx ; dividend := temp 2123 M mset #' ' 2123 M mreq 1,2:Source Destination 2123 M @@_samesize_ ?temp,x dividend73,spx 2123 M mreq 1,2:Operand1,Operand2[,Operand]* 2123 M mset 0 2123 M mdo 2123 M mswap 1,1 2123 M @@_nosize_ ?temp,x 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (?temp,x) 2123 M endm 2123 M mset 0,?temp,x 2123 M mloop :n 2123 M mswap 1,2 2123 M @@_nosize_ dividend73,spx 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (dividend73,spx) 2123 M endm 2123 M mloop :n 2123 M endm 2123 M mset 0 2123 M mdo 2123 M [2481] 2481:E60A [ 3] lda ?temp+0,x 2123 M [2483] 2483:E716 [ 3] sta dividend73+0,spx 2123 M mloop ::dividend73 2123 M [2485] 2485:E60B [ 3] lda ?temp+1,x 2123 M [2487] 2487:E717 [ 3] sta dividend73+1,spx 2123 M mloop ::dividend73 2123 M [2489] 2489:E60C [ 3] lda ?temp+2,x 2123 M [248B] 248B:E718 [ 3] sta dividend73+2,spx 2123 M mloop ::dividend73 2123 M [248D] 248D:E60D [ 3] lda ?temp+3,x 2123 M [248F] 248F:E719 [ 3] sta dividend73+3,spx 2123 M mloop ::dividend73 2123 M [2491] 2491:E60E [ 3] lda ?temp+4,x 2123 M [2493] 2493:E71A [ 3] sta dividend73+4,spx 2123 M mloop ::dividend73 2123 endm 2124 M @lsr.s ?remainder,x ; remainder := remainder shr 1 2124 M mset # 2124 M mreq 1 2124 M @@_nosize_ ?remainder,x 2124 M mset # 2124 M mset 0,mstop [lsr.s] No size (?remainder,x) 2124 M endm 2124 M mdo 2124 M [2495] 2495:6405 [ 5] lsr ?remainder+0,x 2124 M mloop ::?remainder 2124 M [2497] 2497:6606 [ 5] ror ?remainder+1,x 2124 M mloop ::?remainder 2124 M [2499] 2499:6607 [ 5] ror ?remainder+2,x 2124 M mloop ::?remainder 2124 M [249B] 249B:6608 [ 5] ror ?remainder+3,x 2124 M mloop ::?remainder 2124 M [249D] 249D:6609 [ 5] ror ?remainder+4,x 2124 M mloop ::?remainder 2124 endm 2125 [249F] 249F:6C0F [ 5] inc ?bits,x ; bits := bits + 1 2126 2127 ; for i := bitCounter-1 downto 0 do 2128 2129 M For@@ @cop ;in case of many iterations 2129 M [24A1] 24A1:C718 00 [ 4] sta COP 2129 endm 2130 2131 [24A4] 24A4:6D0F [ 4] tst ?bits,x 2133 [24A6] 24A6:275F (2507) [ 3] beq Done@@ 2137 [24A8] 24A8:6A0F [ 5] dec ?bits,x 2138 2139 ; remainder := (remainder shl 1) or msb(dividend) 2140 ; dividend := dividend shl 1 2141 2142 M @lsl.s dividend@@,spx ;2012.12.04 optimization 2142 M mset # 2142 M mreq 1 2142 M @@_nosize_ dividend73,spx 2142 M mset # 2142 M mset 0,mstop [lsl.s] No size (dividend73,spx) 2142 M endm 2142 M mdo 2142 M [24AA] 24AA:681A [ 5] lsl dividend73+4,spx 2142 M mloop ::dividend73 2142 M [24AC] 24AC:6919 [ 5] rol dividend73+3,spx 2142 M mloop ::dividend73 2142 M [24AE] 24AE:6918 [ 5] rol dividend73+2,spx 2142 M mloop ::dividend73 2142 M [24B0] 24B0:6917 [ 5] rol dividend73+1,spx 2142 M mloop ::dividend73 2142 M [24B2] 24B2:6916 [ 5] rol dividend73+0,spx 2142 M mloop ::dividend73 2142 endm 2143 M @rol.s ?remainder,x 2143 M mset # 2143 M mreq 1 2143 M @@_nosize_ ?remainder,x 2143 M mset # 2143 M mset 0,mstop [rol.s] No size (?remainder,x) 2143 M endm 2143 M mdo 2143 M [24B4] 24B4:6909 [ 5] rol ?remainder+4,x 2143 M mloop ::?remainder 2143 M [24B6] 24B6:6908 [ 5] rol ?remainder+3,x 2143 M mloop ::?remainder 2143 M [24B8] 24B8:6907 [ 5] rol ?remainder+2,x 2143 M mloop ::?remainder 2143 M [24BA] 24BA:6906 [ 5] rol ?remainder+1,x 2143 M mloop ::?remainder 2143 M [24BC] 24BC:6905 [ 5] rol ?remainder+0,x 2143 M mloop ::?remainder 2143 endm 2144 2145 ; temp := remainder - divisor 2146 2147 M @sub.s ?remainder,x divisor@@,spx ?temp,x 2147 M mset #' ' 2147 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2147 M @@_samesize_ ?remainder,x divisor73,spx ?temp,x 2147 M mreq 1,2:Operand1,Operand2[,Operand]* 2147 M mset 0 2147 M mdo 2147 M mswap 1,1 2147 M @@_nosize_ ?remainder,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?remainder,x) 2147 M endm 2147 M mset 0,?remainder,x 2147 M mloop :n 2147 M mswap 1,2 2147 M @@_nosize_ divisor73,spx 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (divisor73,spx) 2147 M endm 2147 M mloop :n 2147 M mswap 1,3 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?temp,x) 2147 M endm 2147 M mloop :n 2147 M endm 2147 M #temp 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [sub.s] No size (?temp,x) 2147 M endm 2147 M #temp ::?temp 2147 M mset 0,sub 2147 M mdo 2147 M [24BE] 24BE:E609 [ 3] lda ?remainder+4,x 2147 M [24C0] 24C0:E01F [ 3] sub divisor73+4,spx 2147 M [24C2] 24C2:E70E [ 3] sta ?temp+4,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [24C4] 24C4:E608 [ 3] lda ?remainder+3,x 2147 M [24C6] 24C6:E21E [ 3] sbc divisor73+3,spx 2147 M [24C8] 24C8:E70D [ 3] sta ?temp+3,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [24CA] 24CA:E607 [ 3] lda ?remainder+2,x 2147 M [24CC] 24CC:E21D [ 3] sbc divisor73+2,spx 2147 M [24CE] 24CE:E70C [ 3] sta ?temp+2,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [24D0] 24D0:E606 [ 3] lda ?remainder+1,x 2147 M [24D2] 24D2:E21C [ 3] sbc divisor73+1,spx 2147 M [24D4] 24D4:E70B [ 3] sta ?temp+1,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [24D6] 24D6:E605 [ 3] lda ?remainder+0,x 2147 M [24D8] 24D8:E21B [ 3] sbc divisor73+0,spx 2147 M [24DA] 24DA:E70A [ 3] sta ?temp+0,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 endm 2148 2149 ; q := not msb(temp) 2150 2151 [24DC] 24DC:E60A [ 3] lda ?temp,x 2152 [24DE] 24DE:A880 [ 2] eor #%10000000 ;invert msb 2153 [24E0] 24E0:A480 [ 2] and #%10000000 ;isolate msb 2154 2155 ; quotient := (quotient shl 1) or q 2156 2157 [24E2] 24E2:87 [ 2] psha 2158 [24E3] 24E3:48 [ 1] lsla 2159 [24E4] 24E4:86 [ 3] pula 2160 2161 M @rol.s ?quotient,x 2161 M mset # 2161 M mreq 1 2161 M @@_nosize_ ?quotient,x 2161 M mset # 2161 M mset 0,mstop [rol.s] No size (?quotient,x) 2161 M endm 2161 M mdo 2161 M [24E5] 24E5:6904 [ 5] rol ?quotient+4,x 2161 M mloop ::?quotient 2161 M [24E7] 24E7:6903 [ 5] rol ?quotient+3,x 2161 M mloop ::?quotient 2161 M [24E9] 24E9:6902 [ 5] rol ?quotient+2,x 2161 M mloop ::?quotient 2161 M [24EB] 24EB:6901 [ 5] rol ?quotient+1,x 2161 M mloop ::?quotient 2161 M [24ED] 24ED:79 [ 4] rol ?quotient+0,x 2161 M mloop ::?quotient 2161 endm 2162 2163 ; if q <> 0 then 2164 2165 [24EE] 24EE:4100 B0(24A1) [ 4] cbeqa #0,For@@ 2166 2167 ; remainder := temp 2168 2169 M @mova.s ?temp,x ?remainder,x 2169 M mset #' ' 2169 M mreq 1,2:Source Destination 2169 M @@_samesize_ ?temp,x ?remainder,x 2169 M mreq 1,2:Operand1,Operand2[,Operand]* 2169 M mset 0 2169 M mdo 2169 M mswap 1,1 2169 M @@_nosize_ ?temp,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?temp,x) 2169 M endm 2169 M mset 0,?temp,x 2169 M mloop :n 2169 M mswap 1,2 2169 M @@_nosize_ ?remainder,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?remainder,x) 2169 M endm 2169 M mloop :n 2169 M endm 2169 M mset 0 2169 M mdo 2169 M [24F1] 24F1:E60A [ 3] lda ?temp+0,x 2169 M [24F3] 24F3:E705 [ 3] sta ?remainder+0,x 2169 M mloop ::?remainder 2169 M [24F5] 24F5:E60B [ 3] lda ?temp+1,x 2169 M [24F7] 24F7:E706 [ 3] sta ?remainder+1,x 2169 M mloop ::?remainder 2169 M [24F9] 24F9:E60C [ 3] lda ?temp+2,x 2169 M [24FB] 24FB:E707 [ 3] sta ?remainder+2,x 2169 M mloop ::?remainder 2169 M [24FD] 24FD:E60D [ 3] lda ?temp+3,x 2169 M [24FF] 24FF:E708 [ 3] sta ?remainder+3,x 2169 M mloop ::?remainder 2169 M [2501] 2501:E60E [ 3] lda ?temp+4,x 2169 M [2503] 2503:E709 [ 3] sta ?remainder+4,x 2169 M mloop ::?remainder 2169 endm 2170 2171 ; end if -- end for 2172 2174 [2505] 2505:209A (24A1) [ 3] bra For@@ 2178 2179 [2507] 2507:E610 [ 3] Done@@ lda ?flags,x 2180 [2509] 2509:A501 [ 2] bit #?DIVOP_ 2181 [250B] 250B:2715 (2522) [ 3] beq ExitMod@@ 2182 2183 02C9 ?Cycles equ :cycles 2184 2185 ;ExitDiv@@ 2186 M @mova.s ?quotient,x ans@@,spx 2186 M mset #' ' 2186 M mreq 1,2:Source Destination 2186 M @@_samesize_ ?quotient,x ans73,spx 2186 M mreq 1,2:Operand1,Operand2[,Operand]* 2186 M mset 0 2186 M mdo 2186 M mswap 1,1 2186 M @@_nosize_ ?quotient,x 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (?quotient,x) 2186 M endm 2186 M mset 0,?quotient,x 2186 M mloop :n 2186 M mswap 1,2 2186 M @@_nosize_ ans73,spx 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (ans73,spx) 2186 M endm 2186 M mloop :n 2186 M endm 2186 M mset 0 2186 M mdo 2186 M [250D] 250D:F6 [ 3] lda ?quotient+0,x 2186 M [250E] 250E:E71B [ 3] sta ans73+0,spx 2186 M mloop ::ans73 2186 M [2510] 2510:E601 [ 3] lda ?quotient+1,x 2186 M [2512] 2512:E71C [ 3] sta ans73+1,spx 2186 M mloop ::ans73 2186 M [2514] 2514:E602 [ 3] lda ?quotient+2,x 2186 M [2516] 2516:E71D [ 3] sta ans73+2,spx 2186 M mloop ::ans73 2186 M [2518] 2518:E603 [ 3] lda ?quotient+3,x 2186 M [251A] 251A:E71E [ 3] sta ans73+3,spx 2186 M mloop ::ans73 2186 M [251C] 251C:E604 [ 3] lda ?quotient+4,x 2186 M [251E] 251E:E71F [ 3] sta ans73+4,spx 2186 M mloop ::ans73 2186 endm 2187 [2520] 2520:2014 (2536) [ 3] bra ExitBoth@@ 2188 2189 0309 ?DivCycles set ?DivCycles+?Cycles+:cycles 2190 2191 M ExitMod@@ @mova.s ?remainder,x ans@@,spx 2191 M mset #' ' 2191 M mreq 1,2:Source Destination 2191 M @@_samesize_ ?remainder,x ans73,spx 2191 M mreq 1,2:Operand1,Operand2[,Operand]* 2191 M mset 0 2191 M mdo 2191 M mswap 1,1 2191 M @@_nosize_ ?remainder,x 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (?remainder,x) 2191 M endm 2191 M mset 0,?remainder,x 2191 M mloop :n 2191 M mswap 1,2 2191 M @@_nosize_ ans73,spx 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (ans73,spx) 2191 M endm 2191 M mloop :n 2191 M endm 2191 M mset 0 2191 M mdo 2191 M [2522] 2522:E605 [ 3] lda ?remainder+0,x 2191 M [2524] 2524:E71B [ 3] sta ans73+0,spx 2191 M mloop ::ans73 2191 M [2526] 2526:E606 [ 3] lda ?remainder+1,x 2191 M [2528] 2528:E71C [ 3] sta ans73+1,spx 2191 M mloop ::ans73 2191 M [252A] 252A:E607 [ 3] lda ?remainder+2,x 2191 M [252C] 252C:E71D [ 3] sta ans73+2,spx 2191 M mloop ::ans73 2191 M [252E] 252E:E608 [ 3] lda ?remainder+3,x 2191 M [2530] 2530:E71E [ 3] sta ans73+3,spx 2191 M mloop ::ans73 2191 M [2532] 2532:E609 [ 3] lda ?remainder+4,x 2191 M [2534] 2534:E71F [ 3] sta ans73+4,spx 2191 M mloop ::ans73 2191 endm 2192 2193 02FD ?ModCycles set ?ModCycles+?Cycles+:cycles 2194 2195 2536 ExitBoth@@ 2197 [2536] 2536:6D10 [ 4] tst ?flags,x 2198 [2538] 2538:2A06 (2540) [ 3] bpl SkipSign@@ 2199 M @lea ans@@,sp 2199 M mset # 2199 M [253A] 253A:95 [ 2] tsx 2199 M [253B] 253B:AF1B [ 2] !aix #ans73+:tsx 2199 mexit 2200 [253D] 253D:CD23 A3 [ 6] jsr ?NegX 2201 2540 SkipSign@@ 2202 #Cycles ?NegxCycles+:cycles 2204 [2540] 2540:A711 [ 2] ais #?SF ;de-allocate temporaries 2205 [2542] 2542:98 [ 1] clc ;no error(s) 2206 ; bra ?RemoveAndReturn 2207 2208 004B ?Cycles set :cycles 2209 0354 ?DivCycles set ?DivCycles+?Cycles 2210 0348 ?ModCycles set ?ModCycles+?Cycles 2211 2212 ;******************************************************************************* 2213 ; Common exit removes lower 32-bit stack element and returns to caller 2214 ;******************************************************************************* 2215 2216 2543 ?RemoveAndReturn proc 2218 [2543] 2543:9EFE 04 [ 5] ldhx ?pc,sp ;our return address moved up 2219 [2546] 2546:9EFF 09 [ 5] sthx ?pc+?WORD,sp ;above word to remove 2229 [2549] 2549:8A88 86 [ 9] pull 2230 [254C] 254C:A705 [ 2] ais #?WORD ;remove top-of-stack ?WORD 2231 [254E] 254E:81 [ 6] rtc 2232 2233 001B ?ReturnCycles equ :cycles 2234 2235 ;******************************************************************************* 2236 ; Purpose: Swaps the stacked order of N1 and N2 2237 ; Input : [TOS+?WORD] = Number2 2238 ; : [TOS] = Number1 2239 ; Output : [TOS+?WORD] = Number1 -- TOS & [TOS+?WORD] in reverse order 2240 ; : [TOS] = Number2 2241 ; Note(s): Does not alter stack size 2242 2243 #spauto :ab 2244 2245 254F ?Swap proc 2246 [254F] 254F:8789 8B [ 6] push 2247 2248 [2552] 2552:A605 [ 2] lda #?WORD 2249 [2554] 2554:87 [ 2] psha bytes@@ 2250 2251 [2555] 2555:95 [ 2] tsx 2252 #temp :cycles 2253 M Loop@@ @_swap_, ?a,spx ?b,spx ;swap A with B ... 2253 M mset #' ' 2253 M #push 2253 M #spauto :sp 2253 M [2556] 2556:E606 [ 3] lda ?a,spx 2253 M [2558] 2558:87 [ 2] psha 2253 M [2559] 2559:E60B [ 3] lda ?b,spx 2253 M [255B] 255B:E706 [ 3] sta ?a,spx 2253 M [255D] 255D:86 [ 3] pula 2253 M [255E] 255E:E70B [ 3] sta ?b,spx 2253 M #pull 2253 endm 2254 2255 [2560] 2560:AF01 [ 2] aix #1 ;point to next byte 2256 [2562] 2562:9E6B 01F0 (2556 [ 8] dbnz bytes@@,sp,Loop@@ ;repeat for all bytes 2257 #temp :cycles*?WORD+:temp 2258 [2566] 2566:86 [ 3] pula 2259 2260 [2567] 2567:8A88 86 [ 9] pull 2261 [256A] 256A:81 [ 6] rtc 2262 2263 00A5 ?SwapCycles set :cycles+:temp 2264 2265 ;******************************************************************************* 2266 ; Purpose: Get the absolute value of the top-of-stack number 2267 ; Input : [TOS] = Number 2268 ; Output : [TOS] = Abs(Number) 2269 ; Note(s): Does not alter stack size 2270 2271 #spauto :ab 2272 2273 256B ?Abs proc 2274 [256B] 256B:9E6D 03 [ 5] tst ?a,sp 2275 [256E] 256E:2AFA (256A) [ 3] bpl Done@@ 2276 ; bra ?Negate 2277 2278 256A Done@@ equ :AnRTC 2279 2280 0008 ?AbsCycles equ :cycles 2281 2282 ;******************************************************************************* 2283 ; Purpose: Negate the top-of-stack number 2284 ; Input : [TOS] = Number 2285 ; Output : [TOS] = -Number 2286 ; Note(s): Does not alter stack size 2287 2288 #spauto :ab 2289 2290 2570 ?Negate proc 2291 [2570] 2570:898B [ 4] pshhx 2293 M @lea ?a,sp 2293 M mset # 2293 M [2572] 2572:95 [ 2] tsx 2293 M [2573] 2573:AF04 [ 2] !aix #?a+:tsx 2293 mexit 2294 [2575] 2575:CD23 A3 [ 6] jsr ?NegX 2295 #Cycles ?NegxCycles+:cycles 2300 [2578] 2578:8A88 [ 6] pulhx 2301 [257A] 257A:81 [ 6] rtc 2302 2303 0051 ?NegateCycles equ :cycles 2304 0059 ?AbsCycles set ?NegateCycles+?AbsCycles 2305 2306 ;******************************************************************************* 2307 ; Purpose: Create a new top-of-stack and load to it the number pointed to by HX 2308 ; Input : HX -> [Variable with] Number 2309 ; Output : [TOS] = Number 2310 ; Note(s): This operation makes it easier to load a number to the stack. 2311 ; : Hint: To make a copy of the TOS, do: 2312 ; : tsx 2313 ; : call StackLoad32 2314 ; : (Stack is expanded) 2315 2316 #spauto :ab 2317 2318 257B ?Load proc 2319 FFFFFFFF old_rts@@ equ ::,:ab 2320 [257B] 257B:A7FB [ 2] ais #-?WORD ;allocate new TOS memory 2321 #temp :: 2322 FFFFFFFA new_rts@@ next :temp,:ab 2323 FFFFFFFC tos_num@@ next :temp,?WORD 2324 0001 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2325 #ais :temp 2326 2327 [257D] 257D:87 [ 2] psha 2328 M @mova.s old_rts@@,sp new_rts@@,sp ;move RTS/RTC after new memory 2328 M mset #' ' 2328 M mreq 1,2:Source Destination 2328 M @@_samesize_ old_rts78,sp new_rts@@,sp 2328 M mreq 1,2:Operand1,Operand2[,Operand]* 2328 M mset 0 2328 M mdo 2328 M mswap 1,1 2328 M @@_nosize_ old_rts78,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (old_rts78,sp) 2328 M endm 2328 M mset 0,old_rts78,sp 2328 M mloop :n 2328 M mswap 1,2 2328 M @@_nosize_ new_rts@@,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (new_rts78,sp) 2328 M endm 2328 M mloop :n 2328 M endm 2328 M mset 0 2328 M mdo 2328 M [257E] 257E:9EE6 07 [ 4] lda old_rts78+0,sp 2328 M [2581] 2581:9EE7 02 [ 4] sta new_rts@@+0,sp 2328 M mloop ::new_rts@@ 2328 M [2584] 2584:9EE6 08 [ 4] lda old_rts78+1,sp 2328 M [2587] 2587:9EE7 03 [ 4] sta new_rts@@+1,sp 2328 M mloop ::new_rts@@ 2328 endm 2329 M @mova.s ,x tos_num@@,sp 2329 M mset #' ' 2329 M mreq 1,2:Source Destination 2329 M @@_samesize_ ,x tos_num78,sp 2329 M mreq 1,2:Operand1,Operand2[,Operand]* 2329 M mset 0 2329 M mdo 2329 M mswap 1,1 2329 M mloop :n 2329 M mswap 1,2 2329 M @@_nosize_ tos_num78,sp 2329 M mset # 2329 M mset 0,mstop [_samesize_] No size (tos_num78,sp) 2329 M endm 2329 M mset 0,tos_num78,sp 2329 M mloop :n 2329 M endm 2329 M mset 0 2329 M mdo 2329 M [258A] 258A:F6 [ 3] lda +0,x 2329 M [258B] 258B:9EE7 04 [ 4] sta tos_num78+0,sp 2329 M mloop ::tos_num78 2329 M [258E] 258E:E601 [ 3] lda +1,x 2329 M [2590] 2590:9EE7 05 [ 4] sta tos_num78+1,sp 2329 M mloop ::tos_num78 2329 M [2593] 2593:E602 [ 3] lda +2,x 2329 M [2595] 2595:9EE7 06 [ 4] sta tos_num78+2,sp 2329 M mloop ::tos_num78 2329 M [2598] 2598:E603 [ 3] lda +3,x 2329 M [259A] 259A:9EE7 07 [ 4] sta tos_num78+3,sp 2329 M mloop ::tos_num78 2329 M [259D] 259D:E604 [ 3] lda +4,x 2329 M [259F] 259F:9EE7 08 [ 4] sta tos_num78+4,sp 2329 M mloop ::tos_num78 2329 endm 2330 [25A2] 25A2:86 [ 3] pula 2331 [25A3] 25A3:81 [ 6] rtc 2332 2333 0040 ?LoadCycles equ :cycles 2334 2335 ;******************************************************************************* 2336 ; Purpose: Unload the top-of-stack number into a variable pointed to by HX 2337 ; Input : [TOS] = Number 2338 ; : HX -> Some 32-bit variable 2339 ; Output : Variable pointed to by HX receives TOS number 2340 ; Note(s): This operation makes it easier to unload a number from the stack. 2341 ; : Use: 2342 ; : ldhx #MyVar 2343 ; : call StackSave32 2344 ; : (Stack is reduced) 2345 2346 #spauto :ab 2347 2348 25A4 ?Save proc 2349 #temp :: 2350 FFFFFFFF old_rts@@ next :temp,:ab 2351 0001 tos_num@@ next :temp,?WORD 2352 0006 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2353 0004 new_rts@@ next :temp,:ab 2354 2355 0000 var@@ equ 0,?WORD 2356 2357 [25A4] 25A4:8789 8B [ 6] push 2358 M @mova.s tos_num@@,sp var@@,x 2358 M mset #' ' 2358 M mreq 1,2:Source Destination 2358 M @@_samesize_ tos_num79,sp var@@,x 2358 M mreq 1,2:Operand1,Operand2[,Operand]* 2358 M mset 0 2358 M mdo 2358 M mswap 1,1 2358 M @@_nosize_ tos_num79,sp 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (tos_num79,sp) 2358 M endm 2358 M mset 0,tos_num79,sp 2358 M mloop :n 2358 M mswap 1,2 2358 M @@_nosize_ var@@,x 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (var79,x) 2358 M endm 2358 M mloop :n 2358 M endm 2358 M mset 0 2358 M mdo 2358 M [25A7] 25A7:9EE6 06 [ 4] lda tos_num79+0,sp 2358 M [25AA] 25AA:F7 [ 2] sta var@@+0,x 2358 M mloop ::var@@ 2358 M [25AB] 25AB:9EE6 07 [ 4] lda tos_num79+1,sp 2358 M [25AE] 25AE:E701 [ 3] sta var@@+1,x 2358 M mloop ::var@@ 2358 M [25B0] 25B0:9EE6 08 [ 4] lda tos_num79+2,sp 2358 M [25B3] 25B3:E702 [ 3] sta var@@+2,x 2358 M mloop ::var@@ 2358 M [25B5] 25B5:9EE6 09 [ 4] lda tos_num79+3,sp 2358 M [25B8] 25B8:E703 [ 3] sta var@@+3,x 2358 M mloop ::var@@ 2358 M [25BA] 25BA:9EE6 0A [ 4] lda tos_num79+4,sp 2358 M [25BD] 25BD:E704 [ 3] sta var@@+4,x 2358 M mloop ::var@@ 2358 endm 2359 2360 [25BF] 25BF:95 [ 2] tsx 2361 M @mova.s old_rts@@,spx new_rts@@,spx ;move RTS/RTC before old memory 2361 M mset #' ' 2361 M mreq 1,2:Source Destination 2361 M @@_samesize_ old_rts79,spx new_rts@@,spx 2361 M mreq 1,2:Operand1,Operand2[,Operand]* 2361 M mset 0 2361 M mdo 2361 M mswap 1,1 2361 M @@_nosize_ old_rts79,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (old_rts79,spx) 2361 M endm 2361 M mset 0,old_rts79,spx 2361 M mloop :n 2361 M mswap 1,2 2361 M @@_nosize_ new_rts@@,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (new_rts79,spx) 2361 M endm 2361 M mloop :n 2361 M endm 2361 M mset 0 2361 M mdo 2361 M [25C0] 25C0:E603 [ 3] lda old_rts79+0,spx 2361 M [25C2] 25C2:E708 [ 3] sta new_rts@@+0,spx 2361 M mloop ::new_rts@@ 2361 M [25C4] 25C4:E604 [ 3] lda old_rts79+1,spx 2361 M [25C6] 25C6:E709 [ 3] sta new_rts@@+1,spx 2361 M mloop ::new_rts@@ 2361 endm 2362 [25C8] 25C8:8A88 86 [ 9] pull 2363 2364 [25CB] 25CB:A705 [ 2] ais #?WORD ;de-allocate TOS memory 2365 [25CD] 25CD:81 [ 6] rtc 2366 2367 0047 ?SaveCycles equ :cycles 2368 2369 ;******************************************************************************* 2370 ; Purpose: Adjust TOS old size to new 2371 ; Input : H = old (current) byte size 2372 ; : X = new byte size 2373 ; : CCR[C] = 0 -- always positive number 2374 ; : CCR[C] = 1 -- sign extend 2375 ; Output : None 2376 ; Note(s): RegA deliberately not used for parameter passing (for consistency) 2377 ; : Macro destroys RegHX (as we must not use PSHHX/PULHX around call) 2378 2504 2505 ;******************************************************************************* 2506 ; Purpose: Convert 32-bit to ASCIZ string 2507 ; Input : Stack: 32-bit number 2508 ; : HX -> Output buffer with enough space to keep the ASCIZ string result 2509 ; Output : None 2510 ; Note(s): Use: 2511 ; : ldhx #Buffer 2512 ; : call Stack32ToASCIZ 2513 2514 #spauto :ab ;account for RTS/RTC 2515 2516 25CE ?ToStr proc 2517 [25CE] 25CE:8789 8B [ 6] push 2518 #ais ;mark beginning of temporaries 2519 2520 [25D1] 25D1:898B [ 4] pshhx .buffer@@ ;working copy of pointer to buffer 2521 [25D3] 25D3:7F [ 4] clr ,x ;make it an ASCIZ string 2522 2523 M @lea 1,sp ;HX -> TOS number of caller 2523 M mset # 2523 M [25D4] 25D4:95 [ 2] tsx 2523 M [25D5] 25D5:AF07 [ 2] !aix #1+:tsx 2523 mexit 2524 [25D7] 25D7:CD25 7B [ 6] call ?Load ;load a working copy on stack 2525 2526 #spadd ?WORD ;stack has grown by a ?WORD 2527 FFFFFFF5 number@@ equ ::,?WORD 2529 [25DA] 25DA:9E6D 01 [ 5] tst number@@,sp 2530 [25DD] 25DD:2A0F (25EE) [ 3] bpl ToStrLoop@@ 2531 [25DF] 25DF:CD25 70 [ 6] call ?Negate 2533 [25E2] 25E2:9EFE 06 [ 5] ldhx .buffer@@,sp 2540 [25E5] 25E5:A62D [ 2] lda #'-' ;a 'minus' sign 2541 [25E7] 25E7:F7 [ 2] sta ,x ; is saved first 2542 2543 [25E8] 25E8:AF01 [ 2] aix #1 ;HX -> past minus sign 2544 [25EA] 25EA:7F [ 4] clr ,x ;make it an ASCIZ string 2546 [25EB] 25EB:9EFF 06 [ 5] sthx .buffer@@,sp ;update pointer past sign 2552 ; bra ToStrLoop@@ 2554 ;=============================================================================== 2555 2556 [25EE] 25EE:4500 0A [ 3] ToStrLoop@@ ldhx #10 ;H = 0 (always), X = divisor 2557 M @div.s number@@,sp 2557 M mset # 2557 M mreq 1 2557 M @@_not_x_ number80,sp 2557 M mset #' ' 2557 M mdel 1 2557 M mtop 2557 M mset #' ' 2557 M mexit 2557 M @@_nosize_ number80,sp 2557 M mset # 2557 M mset 0,mstop [div.s] No size (number80,sp) 2557 M endm 2557 M #temp 1 2557 M #temp 2 2557 M [25F1] 25F1:86 [ 3] pula 2557 M [25F2] 25F2:52 [ 6] div 2557 M [25F3] 25F3:87 [ 2] psha 2557 M mdo 2 2557 M [25F4] 25F4:9EE6 02 [ 4] lda number80+1,sp 2557 M [25F7] 25F7:52 [ 6] div 2557 M [25F8] 25F8:9EE7 02 [ 4] sta number80+1,sp 2557 M mloop ::number80 2557 M [25FB] 25FB:9EE6 03 [ 4] lda number80+2,sp 2557 M [25FE] 25FE:52 [ 6] div 2557 M [25FF] 25FF:9EE7 03 [ 4] sta number80+2,sp 2557 M mloop ::number80 2557 M [2602] 2602:9EE6 04 [ 4] lda number80+3,sp 2557 M [2605] 2605:52 [ 6] div 2557 M [2606] 2606:9EE7 04 [ 4] sta number80+3,sp 2557 M mloop ::number80 2557 M [2609] 2609:9EE6 05 [ 4] lda number80+4,sp 2557 M [260C] 260C:52 [ 6] div 2557 M [260D] 260D:9EE7 05 [ 4] sta number80+4,sp 2557 M mloop ::number80 2557 endm 2558 2559 [2610] 2610:8B86 [ 5] tha ;A = remainder 2560 [2612] 2612:AB30 [ 2] add #'0' ;A = ASCII remainder 2562 [2614] 2614:9EFE 06 [ 5] ldhx .buffer@@,sp 2568 M @StringInsertChar 2568 M [2617] 2617:CD18 3A [ 6] call StringInsertChar ;HX and A pre-loaded correctly 2568 mexit 2569 2570 [261A] 261A:95 [ 2] tsx 2571 2572 M @_tst_.s number@@,spx 2572 M mset # 2572 M mreq 1 2572 M @@_nosize_ number80,spx 2572 M mset # 2572 M mset 0,mstop [_tst_.s] No size (number80,spx) 2572 M endm 2572 M mdo 2572 M [261B] 261B:F6 [ 3] lda number80+0,spx 2572 M mloop ::number80 2572 M [261C] 261C:EA01 [ 3] ora number80+1,spx 2572 M mloop ::number80 2572 M [261E] 261E:EA02 [ 3] ora number80+2,spx 2572 M mloop ::number80 2572 M [2620] 2620:EA03 [ 3] ora number80+3,spx 2572 M mloop ::number80 2572 M [2622] 2622:EA04 [ 3] ora number80+4,spx 2572 M mloop ::number80 2572 endm 2573 [2624] 2624:26C8 (25EE) [ 3] bne ToStrLoop@@ 2574 2575 [2626] 2626:A707 [ 2] ais #:ais ;free temporaries 2576 [2628] 2628:8A88 86 [ 9] pull 2577 [262B] 262B:81 [ 6] rtc 2578 2579 #sp ;cancel all SP offsets 2580 2581 ;******************************************************************************* 2582 ; Assign global names to the various library calls, depending on version used. 2583 ; Different names for each version means you can include any at the same time. 2584 ;******************************************************************************* 2585 2586 ? macro BitSize ;temp macro to export symbols 2587 mreq 1:Usage: @~0~ BitSize 2588 #if MATHSIZE = ~1~ 2589 StackAdd~1~ exp ?Add 2590 StackSub~1~ exp ?Subtract 2591 StackMul~1~ exp ?Multiply 2592 StackDiv~1~ exp ?Divide 2593 StackMod~1~ exp ?Modulo 2594 StackSwap~1~ exp ?Swap 2595 StackAbs~1~ exp ?Abs 2596 StackNegate~1~ exp ?Negate 2597 StackLoad~1~ exp ?Load 2598 StackSave~1~ exp ?Save 2599 Stack~1~ToASCIZ exp ?ToStr 2600 #ifdef NO_BIT_OPS 2601 mexit ;;bit operations not available 2602 #endif 2603 StackAnd~1~ exp ?BitAnd 2604 StackOr~1~ exp ?BitOr 2605 StackXor~1~ exp ?BitXor 2606 StackShl~1~ exp ?ShiftLeft 2607 StackShr~1~ exp ?ShiftRight 2608 #endif 2609 endm 2610 2611 M @? 64 ;export 64-bit labels 2611 M mreq 1:Usage: @? BitSize 2611 endm 2612 M @? 56 ;export 56-bit labels 2612 M mreq 1:Usage: @? BitSize 2612 endm 2613 M @? 48 ;export 48-bit labels 2613 M mreq 1:Usage: @? BitSize 2613 endm 2614 M @? 40 ;export 40-bit labels 2614 M mreq 1:Usage: @? BitSize 2614 M 2237 StackAdd40 exp ?Add 2614 M 224D StackSub40 exp ?Subtract 2614 M 2330 StackMul40 exp ?Multiply 2614 M 237F StackDiv40 exp ?Divide 2614 M 2392 StackMod40 exp ?Modulo 2614 M 254F StackSwap40 exp ?Swap 2614 M 256B StackAbs40 exp ?Abs 2614 M 2570 StackNegate40 exp ?Negate 2614 M 257B StackLoad40 exp ?Load 2614 M 25A4 StackSave40 exp ?Save 2614 M 25CE Stack40ToASCIZ exp ?ToStr 2614 M 2263 StackAnd40 exp ?BitAnd 2614 M 2278 StackOr40 exp ?BitOr 2614 M 228D StackXor40 exp ?BitXor 2614 M 22A2 StackShl40 exp ?ShiftLeft 2614 M 22E9 StackShr40 exp ?ShiftRight 2614 endm 2615 M @? 32 ;export 32-bit labels 2615 M mreq 1:Usage: @? BitSize 2615 endm 2616 M @? 24 ;export 24-bit labels 2616 M mreq 1:Usage: @? BitSize 2616 endm 2617 M @? 16 ;export 16-bit labels 2617 M mreq 1:Usage: @? BitSize 2617 endm 2618 2619 ;******************************************************************************* *** END INCLUDE FILE: lib/stakmath.sub *** (RESUMING FILE: lib/stkmth40.sub) 23 #Exit *** END INCLUDE FILE: lib/stkmth40.sub *** (RESUMING FILE: lib/demo/stakmath.asm) 52 M @? 48,6 52 M @@Page 6 52 M mreq 1:PageNumber 52 M endm 52 #Uses lib/stkmth48.sub *** BEGIN INCLUDE FILE: lib/stkmth48.sub *** 1 ;******************************************************************************* 2 ;* Module : STKMTH48.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Wrapper for 48-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stkmth48.html 8 ;* Note(s) : See STAKMATH.SUB for details 9 ;******************************************************************************* 10 16 17 ? macro 18 mset 1,~BASENAME~ 19 MATHSIZE set ~1.{:1-1}~ 20 #Include stakmath.sub 21 endm 22 23 M @? 23 M mset 1,STKMTH48 23 M 0030 MATHSIZE set 48 23 #Include stakmath.sub *** BEGIN INCLUDE FILE: lib/stakmath.sub *** 1 ;******************************************************************************* 2 ;* Module : STAKMATH.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : 64/56/48/40/32/24/16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stakmath.html 8 ;* Note(s) : Use: #Include stakmath.sub 9 ;* : 10 ;* : Several externally defined macros are used throughout this code. 11 ;* : All these (and many more) macros are inside the most recent 12 ;* : version of MACROS.INC which can be copied from the web page at 13 ;* : http://www.aspisys.com/code/hc08/macros.html 14 ;* : (and COMMON.INC at http://www.aspisys.com/code/hc08/common.html) 15 ;* : 16 ;* : The default word size is 32-bit. 17 ;* : 18 ;* : By (re)defining the symbol MATHSIZE (to 16) you get 16-bit code. 19 ;* : By (re)defining the symbol MATHSIZE to 24 you get 24-bit code. 20 ;* : By (re)defining the symbol MATHSIZE to 40 you get 40-bit code. 21 ;* : By (re)defining the symbol MATHSIZE to 48 you get 48-bit code. 22 ;* : By (re)defining the symbol MATHSIZE to 56 you get 56-bit code. 23 ;* : By (re)defining the symbol MATHSIZE to 64 you get 64-bit code. 24 ;* : 25 ;* : You can include all (or some) versions in your program like so: 26 ;* : 27 ;* : #ROM ;(or else, some paged memory) 28 ;* : #Include stakmath.sub 29 ;* : MATHSIZE set 16 ;redefine for 16-bit use 30 ;* : #Include stakmath.sub 31 ;* : MATHSIZE set 24 ;redefine for 24-bit use 32 ;* : #Include stakmath.sub 33 ;* : MATHSIZE set 40 ;redefine for 40-bit use 34 ;* : #Include stakmath.sub 35 ;* : MATHSIZE set 48 ;redefine for 48-bit use 36 ;* : #Include stakmath.sub 37 ;* : MATHSIZE set 56 ;redefine for 56-bit use 38 ;* : #Include stakmath.sub 39 ;* : MATHSIZE set 64 ;redefine for 64-bit use 40 ;* : 41 ;* : or, if you use the related wrapper files, like so: 42 ;* : 43 ;* : #ROM ;(or else, some paged memory) 44 ;* : #Uses stkmth16.sub 45 ;* : #Uses stkmth24.sub 46 ;* : #Uses stkmth32.sub 47 ;* : #Uses stkmth40.sub 48 ;* : #Uses stkmth48.sub 49 ;* : #Uses stkmth56.sub 50 ;* : #Uses stkmth64.sub 51 ;* : 52 ;* : Use CALL if assembled in #MMU mode (regardless of placement). 53 ;* : By using CALL and #JUMP (or default -J+ command line option), the 54 ;* : assembler will automatically adjust between CALL and JSR 55 ;* : depending on the current #MMU mode. 56 ;* : 57 ;* : To use the *-bit version of each CALL, use these symbols: 58 ;* : 59 ;* : StackAdd*, StackSub*, StackMul*, StackDiv*, StackMod* 60 ;* : StackSwap*, StackNegate*, StackLoad*, StackSave*, 61 ;* : Stack*ToASCIZ 62 ;* : 63 ;* : replacing * with one of these: 16, 24, 32, 40, 48, 56, or 64. 64 ;* : 65 ;* : Various macros allow using these routines in a variety of ways, 66 ;* : and without worrying about the details of call & parameter setup. 67 ;* : These macros are: Add*, Sub*, Mul*, Div*, Mod*, DivS*, ModS*, 68 ;* : Neg*, Load*, Save*, Str*, StrS*, and Swap* (where the * is 16, 69 ;* : 24, 32, 40, 48, 56, or 64 depending on the version you want to use). 70 ;* : The signed versions are enabled only when the module is assembled 71 ;* : with the SIGNED conditional. 72 ;* : 73 ;* : If working with fixed-address variables, you can use the various 74 ;* : macros (such as Add32, Mul64, etc.) to perform operations in the 75 ;* : easiest possible way, such as: 76 ;* : @Mul32 A,B,Answer 77 ;* : (which multiplies A with B and stores the product in Answer). 78 ;* : But, you may also use the macros to work directly on stack, or to 79 ;* : temporarily save partial results on stack instead of fixed vars. 80 ;* : 81 ;* : I N G E N E R A L T H E N 82 ;* : 83 ;* : @Operation A,B,Answer works with A and B storing result in Answer 84 ;* : @Operation A,B works with A and B leaving result on stack 85 ;* : @Operation A works with TOS and A, result left as TOS 86 ;* : @Operation (no parms) works w/ TOS and [TOS+1], result as new TOS 87 ;* : 88 ;* : (Please note the shown order of the operation may be important.) 89 ;* : 90 ;* : Finally, the Load* (* = 16, 24, 32, 40, 48, 56, 64) operation can 91 ;* : directly load either a variable or a constant (leading #) on the 92 ;* : stack. 93 ;* : 94 ;* : Since v7.00, a HLL-like interface is possible by using the new 95 ;* : Eval* macro (where * = 8, 16, 24, 32, 40, 48, 56, 64) 96 ;* : This is by far the easiest way to use this library, as it closely 97 ;* : resembles using expressions in a HLL compiler. It also can 98 ;* : automatically resize stack after loading from and before saving 99 ;* : to any variable. 100 ;* : 101 ;* : Examine the test section of this file for examples of macro use. 102 ;* : 103 ;* : All routines are re-entrant and work on either the top-of-stack 104 ;* : (TOS) number alone or the two top-most TOS numbers. Similar to 105 ;* : how Reverse Polish Notation (RPN) works. First, you stack the 106 ;* : operand(s) and then call the corresponding routine to perform the 107 ;* : operation. 108 ;* : 109 ;* : The result of any operation is always the updated top of stack. 110 ;* : For operations that require two operands and produce a single 111 ;* : result, the result replaces the two operands (stack is reduced). 112 ;* : 113 ;* : Chain calculations are possible by pushing only the new operand 114 ;* : between operations. Alternatively, one can push all operands in 115 ;* : advance but it's not recommended as stack space may be limited. 116 ;* : When done evaluating an expression, just pull the final 32-bit 117 ;* : result from the stack. 118 ;* : 119 ;* : The TOS is the first (or only) operand of any operation. 120 ;* : This is important, for example, for subtraction and division. 121 ;* : 122 ;* : If the current order of the stack is not as you want it, use the 123 ;* : Swap (StackSwap32) operation to change it. 124 ;* : 125 ;* : All operands and results are exactly 32-bit wide. Overflows are 126 ;* : simply truncated. The lower 32-bit number is valid, though. 127 ;* : 128 ;* : (All references to 32-bit become 16-bit, when MATHSIZE = 16) 129 ;* : (All references to 32-bit become 24-bit, when MATHSIZE = 24) 130 ;* : (All references to 32-bit become 40-bit, when MATHSIZE = 40) 131 ;* : (All references to 32-bit become 48-bit, when MATHSIZE = 48) 132 ;* : (All references to 32-bit become 56-bit, when MATHSIZE = 56) 133 ;* : (All references to 32-bit become 64-bit, when MATHSIZE = 64) 134 ;* : 135 ;* : 64/56/48/40-bit multiplication is done using the shift-add method, 136 ;* : which is much shorter in size for such long operands, but it is 137 ;* : also significantly slower in speed. I opted for size optimization 138 ;* : because the 64/56/48/40-bit versions are not used quite as often. 139 ;* : You may want to re-write it for speed optimization by using the 140 ;* : MUL instruction like it is done for the default 32-bit case. 141 ;* : 142 ;* History : 09.05.22 v1.00 Original (Started on 2009.05.07) 143 ;* : 09.06.04 Optimized by using HX instead of SP, where needed 144 ;* : 09.11.04 Minor optimizations 145 ;* : 09.11.05 Add & Subtract now adjust Carry accordingly 146 ;* : Division by zero error now checked first 147 ;* : 09.11.06 v1.01 Added conditional MATHSIZE for use w/ 16-bit words 148 ;* : 09.11.08 v1.02 Added "Load" operation to ease stack loading 149 ;* : 09.11.11 Use of new LONG pseudo-opcode 150 ;* : 09.12.05 Added cycles display using :cycles 151 ;* : 10.01.06 v1.03 Added MMU auto-support (using :AB internal symbol) 152 ;* : Code is no longer placed in #ROM by default 153 ;* : The few JMPs in the code use [[ to trim possible page 154 ;* : 10.01.08 [[ removed from JMPs (latest ASM8 auto-correction) 155 ;* : 10.01.22 v1.04 Added Save operation for completeness 156 ;* : 10.01.23 v1.05 Added #SP directive examples (latest ASM8) 157 ;* : 10.01.29 v1.06 Added shorter/faster Swap version for 9S08 MCUs 158 ;* : 10.02.01 v1.07 Added #SPAUTO directive 159 ;* : 10.02.04 Added #X directive 160 ;* : 10.02.06 v2.00 Added signed math wrapper calls only for DIV & MOD 161 ;* : (Addition, Subtraction, and Multiplication calls 162 ;* : work either for unsigned or signed operands.) 163 ;* : Signed routines enabled w/ SIGNED conditional. 164 ;* : Division by zero error now reduces stack (operand 165 ;* : A removed) so that the stack is left with same 166 ;* : size on either success or failure (in which case 167 ;* : the TOS result is invalid.) 168 ;* : 10.02.08 v2.01 Fixed signed MOD for correct sign (sign of A) 169 ;* : 10.02.14 v2.10 Added Stack32ToASCIZ and prerequisite StringInsertChar 170 ;* : 10.02.28 v2.11 Minor optimization in StringInsertChar 171 ;* : 10.03.23 Made use of :: internal variable (Build 2010/03/23) 172 ;* : 10.03.30 v2.12 Allowed for HC08 compilation in newer code (?ToStr) 173 ;* : Optimized 9S08 Swap version for size and speed 174 ;* : v2.13 Optimized Negate for size and speed 175 ;* : 10.05.08 v3.00 Added MATHSIZE = 64 option for 64-bit math 176 ;* : Swap operation optimized only for size 177 ;* : 10.05.13 v3.01 Optimized for size and speed by using ,SPX 178 ;* : 10.06.02 v4.00 Added macros for easier use 179 ;* : 10.06.08 v4.10 Improved macros and added new ones (eg Const32) 180 ;* : 10.06.23 v4.20 Added MATHSIZE = 48 option for 48-bit math 181 ;* : 10.06.30 v4.30 Added AddDecimalPoint (to string number) 182 ;* : 10.07.01 v4.40 Added IFSPAUTO conditional 183 ;* : 10.07.03 Moved the functionality of Const macros into Load 184 ;* : 10.07.07 Moved general string routines first 185 ;* : 10.07.17 v4.50 Str* macros may use TOS (if Number parm is missing) 186 ;* : or current HX index (if result pointer is missing) 187 ;* : 10.07.20 _DoLoad*/_DoSave* address now allows for indexed mode 188 ;* : 10.07.21 Minor optimizations; macros now latest ASM8 189 ;* : 10.07.23 Minor bug fix in macro _DoSave for no parm case 190 ;* : 10.08.18 Optimized by using :MINDEX in latest ASM8 191 ;* : 10.08.26 Minor optimizations at the source level 192 ;* : 10.08.31 v4.60 Optimized Load* macros' immediate mode for zeros 193 ;* : 10.10.19 v4.61 Adapted to latest ASM8 (nested macros in Load) 194 ;* : 10.10.22 v4.62 Optimized _DoMath (Added @_DoOperation) 195 ;* : 10.10.26 v4.63 Load48 & Load64 now also accept single #Constant 196 ;* : 10.12.03 v4.64 Adapted to latest ASM8 => macros OK in @@ sub-mode 197 ;* : 11.03.31 v4.65 Moved test code at EOF (to use #EXIT optimization) 198 ;* : 11.04.10 v4.66 Condensed macro definitions (based on MATHSIZE) 199 ;* : 11.04.11 v4.67 Optimized MUL16/MUL32 size & cycles with ,SPX mode 200 ;* : 11.04.12 v4.70 Added MATHSIZE = 24 option for 24-bit math 201 ;* : 11.04.13 v4.71 Reversed some of v4.66's changes 202 ;* : 11.04.13 v4.80 Added MATHSIZE = 40 option for 40-bit math 203 ;* : 11.05.02 v4.81 Save protects HX (it was lost during SP => SPX) 204 ;* : 11.05.05 v4.82 Optimized StringLength by a byte (by using NEGA on exit) 205 ;* : 11.05.25 v4.83 Removed unused Zero constant from test code 206 ;* : 11.10.13 v4.84 Optimized MUL16/24/32 size w/ more ,SPX (same cycles) 207 ;* : 11.11.15 v4.85 Improved StringLength macro 208 ;* : 12.01.26 Changed test code a bit 209 ;* : 12.02.06 v4.86 Optimized SP => SPX at ?RemoveAndReturn 210 ;* : 12.03.05 v4.87 Added ResizeTOS to adjust TOS element's size 211 ;* : 12.05.09 v4.88 Added CCR[C] parameter to ResizeTOS for unsigned operation 212 ;* (signed is default when SIGNED conditional is defined, 213 ;* unsigned operation is default, otherwise) 214 ;* : 12.05.18 v4.89 Removed redundant subtraction in Division (at NotEqual@@) 215 ;* : 12.10.07 v4.90 Load*/Save* now accept indexed mode without separator override 216 ;* : 12.10.10 v5.00 Renamed to (more general) STAKMATH.SUB to use 217 ;* : wrapper files for each bit version, instead. 218 ;* : 12.11.05 Added _STKMTH{MATHSIZE}_ for used-version control 219 ;* : 12.11.09 v6.00 New _LoadStkMthVarAddr macro eases parm address 220 ;* : calculation. 221 ;* : W A R N I N G: SP-based operands now refer to the actual number, 222 ;* : W A R N I N G: and not its address (as was the case before). 223 ;* : W A R N I N G: This is INCOMPATIBLE with previous behavior. Code 224 ;* : W A R N I N G: written for version v5.00 or earlier that uses SP 225 ;* : W A R N I N G: based operands should be modified to refer to the 226 ;* : W A R N I N G: actual value and not to a pointer to the value. 227 ;* : W A R N I N G: Dot-beginning names are still treated as pointers! 228 ;* : 12.11.10 Use COMMON.INC/LEA instead of _LoadStkMthVarAddr 229 ;* : 12.12.04 v6.10 Optimized division just a tad by combining steps 230 ;* : 12.12.12 v6.20 Now use LEA macro inside _DoStr (for ResultString) 231 ;* : 12.12.20 v6.21 Minor optimization (one byte) in 32-bit ?Multiply 232 ;* : (Further 3-byte optimization possible by 233 ;* : re-ordering MULs, but not done for code clarity) 234 ;* : 13.01.09 v6.22 Added Copy* macros to combine Load*/Save* into one 235 ;* : 13.03.20 v7.00 Added Eval* and supporting macros for HLL-like 236 ;* : computations, eg., ans=(a+3)*((1+var,sp)/2) 237 ;* : (with or without spaces between operands/operators) 238 ;* : 13.03.27 v7.50 SIGNED now gives just signed (not unsigned) version 239 ;* : DivS*, ModS*, StrS* macros were removed, and also 240 ;* : ResizeTOS macro's unsigned flag has been removed 241 ;* : BugFix: AddDecimalPoint now prepends zeros after sign 242 ;* : 13.03.27 Optimized ?Negate in SIGNED case to use ?NegX sub 243 ;* : 13.03.27 v7.60 Adapted _EVAL_ macro to latest ASM8 (Much faster!) 244 ;* : 13.04.04 v7.70 _DoLoad and _DoSave macros now auto-adjust the size 245 ;* : so you can use with operands of different sizes, even 246 ;* : if the respective bitsize version isn't loaded. 247 ;* : 13.04.04 v7.71 _Eval_ macro leaves assignment result on TOS if 248 ;* : assignment variable not already defined. Then, 249 ;* : it gives TOS the specified name, if SP-indexed. 250 ;* : 13.04.05 v7.72 Added #size for v7.71 change 251 ;* : Named constants (labels with size zero) now use 252 ;* : immediate mode in Eval/Load 253 ;* : 13.04.05 v7.73 Added NEG() negate, and ABS() absolute functions 254 ;* : in Eval macro, e.g., ans = abs(a - b) 255 ;* : 13.04.09 v7.80 BugFix: Push/Pull macro calls for SP mode 256 ;* : Moved immediate mode to _DoLoad (unified method) 257 ;* : (Over 32-bit immediate value loads not possible 258 ;* : via macros) 259 ;* : 13.04.10 Adapted to v9.35 (no functional changes) 260 ;* : 13.04.11 v7.81 Optimized _DoLoad constant loading by using CLRH 261 ;* : (optimization is evident on certain cases only) 262 ;* : 13.04.15 v7.82 Added _?SEI_ and _?CLI_ macros for multitasker 263 ;* : locking / unlocking of multi-byte variables while 264 ;* : loading / saving (_DoLoad/_DoSave). Under OS8 it 265 ;* : is enabled automatically. Otherwise, simply 266 ;* : define _MTOS_ anytime before including this file. 267 ;* : For keeping code dense, all Eval*/Load*/Save* 268 ;* : macros are assumed to be called only while 269 ;* : interrupts are enabled, so it will not restore to 270 ;* : previous state but always leave as enabled. 271 ;* : Define _NOCLI_ (before including this module) for 272 ;* : canceling the _?SEI_ and _?CLI_ macro effects. 273 ;* : 13.04.18 v7.85 Added 'NeedMath' and 'Eval' general-purpose macros 274 ;* : for automatic selection of needed bit-size based 275 ;* : on only which modules are already included. First, 276 ;* : call the NeedMath macro to define the minimum math 277 ;* : bit-size you need for the next calculation(s), 278 ;* : then call the Eval macro as many times as needed 279 ;* : to perform the actual expression evaluation(s). 280 ;* : Similary, added new macros Load, Save, StkAdd, 281 ;* : StkSub, StkMul, StkDiv, StkMod, StkSwap, StkNeg, 282 ;* : StkAbs, StkStr, and CopyMath to work with the 283 ;* : NeedMath macro, just like the new Eval macro. 284 ;* : 13.04.19 v8.00 Moved all Eval* macros into COMMON.INC and allowed 285 ;* : for all to be active at all times, regardless if 286 ;* : the related bit-version of STAKMATH is included. 287 ;* : The _Eval_ macro was improved to allow it to 288 ;* : automatically locate the next higher version that 289 ;* : is included, if the one requested is not. So, 290 ;* : using Eval32 will use the 32/40/48/64-bit version 291 ;* : (whichever is closer to 32 and included) but nothing 292 ;* : below 32-bit. This allows you to use the relevant 293 ;* : macro based on a specific expression's requirements 294 ;* : but include only one (or just a few) higher bit 295 ;* : version(s), not all those referenced in your code. 296 ;* : (The general Eval is still available, if needed.) 297 ;* : Also, moved all Str* to COMMON.INC 298 ;* : 13.04.21 v8.10 Corrected v8.00 for pointer cases (.num) to use 299 ;* : actual requested size, not next higher. 300 ;* : Relevant #Message now in _DoOperation _ResizeTOS etc. 301 ;* : 13.04.21 v8.11 NeedMath & related macros removed (now redundant) 302 ;* : General Eval macro will try to determine best bit-size 303 ;* : 13.04.23 v8.12 Added EvalS to first check for SIGNED and then call Eval 304 ;* : CopyMath removed. Use "Eval to_var = from_var" instead 305 ;* : _StkMthMax_ improved to use higher size on multiplication 306 ;* : 13.04.25 v8.13 _Eval_ now allows for string constants (eg., @Eval ans = ans + '0') 307 ;* : Removed all ?macros because we now use COMMON xxx.s macros 308 ;* : 13.04.26 v8.15 Corrected test code for Eval when MATHSIZE < 32 309 ;* : Commented out auto-higher bit-size (a bit annoying). 310 ;* : Use Eval* to say 'no less than', instead. 311 ;* : 13.04.27 v8.16 BugFix: StrMath macro (2nd parameter was lost) 312 ;* : Added SQR() function to get the square 313 ;* : 13.05.02 Added #size in ToInt* macros (in test code) 314 ;* : 13.05.03 v8.17 Added size optimization for ADD and SUB operations 315 ;* : New SPEED_SIZE constant in COMMON.INC tells us 316 ;* : whether we need speed (SPEED_SIZE = 1) or 317 ;* : size (SPEED_SIZE = 2) optimization, the current 318 ;* : default being SPEED_SIZE = 2 for size optimization. 319 ;* : 13.05.30 Updated StrMath macro (COMMON.INC and here) 320 ;* : 13.06.04 v8.20 Added bit functions: AND (&), OR (|), XOR (^), and shifts (< and >) 321 ;* : 13.06.05 v8.21 BugFix: ShiftRight now uses ASR if SIGNED 322 ;* : 13.07.25 v8.22 Improved _Eval_ macro (and Push/Pull in COMMON.INC) 323 ;* : BugFix: Added { } to ResizeTOS macro's final case 324 ;* : (Disable bit functions with NO_BIT_OPS conditional) 325 ;* : 13.10.06 Minor changes in test code 326 ;* : 13.11.26 Added warning in _DoLoad: forwards treated as vars 327 ;* : 13.11.29 v8.23 Optimized ?ShiftLeft and ?ShiftRight a bit 328 ;* : 13.12.22 v8.30 Added 56-bit version 329 ;* : 14.01.03 Made use of _CMP_.S macro (instead of custom macro) 330 ;* : 14.02.07 v8.50 Added [ ... ] unsigned override (if SIGNED) 331 ;* : 14.02.14 v8.51 Eval macro now uses #HideMacros 332 ;* : 14.10.14 v8.52 BugFix: Off-by-one error in ResizeTOS when SIGNED 333 ;* : 15.03.21 v8.53 Replaced string dependencies with corresponding #Uses 334 ;* : 15.04.08 v8.54 Replaced AddDecimalPoint with corresponding #Uses 335 ;* : 17.04.03 v8.55 Optimized 24-bit multiply [-2 bytes] 336 ;* : Optimized 32-bit multiply [-7 bytes] 337 ;* : 18.10.23 Suppressed possible warning from JEQ in ?DivStart 338 ;* : 19.03.04 Added warning in _DoStr macro when using StrNN 339 ;* : when NN is different from MATHSIZE and no explicit 340 ;* : variable is given 341 ;* : 19.10.04 v8.56 Minor HC08 mode optimization in SIGNED ?ToStr [-1 byte] 342 ;* : 20.02.12 v8.57 Replaced #Message with @Msg to silence debugging messages 343 ;******************************************************************************* 344 345 ;Synopsis (replace * with 16, 24, 32, 40, 48, 56, 64 for corresponding bit version): 346 ; 347 ;Subroutines Action 348 ;-------------- ---------------------------- 349 ;StackAdd* - TOS := TOS + [TOS+1] (signed or unsigned) [TOS+1] removed 350 ;StackSub* - TOS := TOS - [TOS+1] (signed or unsigned) [TOS+1] removed 351 ;StackMul* - TOS := TOS * [TOS+1] (signed or unsigned) [TOS+1] removed 352 ;StackDiv* - TOS := TOS / [TOS+1] (signed if SIGNED) [TOS+1] removed 353 ;StackMod* - TOS := TOS \ [TOS+1] (signed if SIGNED) [TOS+1] removed 354 ;StackAnd* - TOS := TOS & [TOS+1] (signed or unsigned) [TOS+1] removed 355 ;StackOr* - TOS := TOS | [TOS+1] (signed or unsigned) [TOS+1] removed 356 ;StackXor* - TOS := TOS ^ [TOS+1] (signed or unsigned) [TOS+1] removed 357 ;StackShl* - TOS := TOS < [TOS+1] (signed or unsigned) [TOS+1] removed 358 ;StackShr* - TOS := TOS > [TOS+1] (signed if SIGNED) [TOS+1] removed 359 ;StackSwap* - TOS swapped with [TOS+1] (signed or unsigned) 360 ;StackAbs* - TOS := ABS(TOS) (signed) 361 ;StackNegate* - TOS := -TOS (signed) 362 ;StackLoad* - Load const/variable to TOS (signed or unsigned) TOS created 363 ;StackSave* - Save TOS into variable (signed or unsigned) TOS removed 364 ;ResizeTOS - Adjust TOS old size to new (signed or unsigned) TOS resized 365 ;Stack*ToASCIZ - Convert TOS to ASCIZ str (signed if SIGNED) 366 ; 367 ;Macros Purpose Parameters ([...] means optional part) 368 ;------------------ ------------------- ---------------------------------------- 369 ;Load* Stack const or var #Number | Variable 370 ;Save* Unstack a variable Variable 371 ;Copy* Load* & Save* #Number | Variable,Variable 372 ;ResizeTOS Resize TOS #FromByteSize,#ToByteSize 373 ; 374 ;Add* Addition [Addend[,Adder[,Sum]]] 375 ;Sub* Subtraction [Minuend[,Subtrahend[,Difference]]] 376 ;Mul* Multiplication [Multiplicand[,Multiplier[,Product]]] 377 ;Div* Unsigned division [Dividend[,Divisor[,Quotient]]] 378 ;Mod* Unsigned modulo [Dividend[,Divisor[,Remainder]]] 379 ;Abs* Absolute value [SourceVariable][,DestinationVariable] 380 ;Neg* Negation [SourceVariable][,DestinationVariable] 381 ;Swap* Swap TOS numbers 382 ;Str* Number to ASCIZ [Variable],[ResultString] 383 ;AddDecimalPoint ... to ASCIZ number [[#]DecimalPlaces[,[#]ASCIZ_String]] 384 411 412 0030 MATHSIZE def 32 ;default wordsize is 32-bit 413 417 418 ? macro BitSize 419 #if MATHSIZE = ~1~ 420 ?WORD equ ~1~/8 421 _STKMTH{MATHSIZE}_ ;;specific version included 422 _STAKMATH_ def * ;;any version included 423 #endif 424 endm 425 426 M @? 16 ;16-bit quantity (on request) 426 endm 427 M @? 24 ;24-bit quantity (on request) 427 endm 428 M @? 32 ;32-bit quantity (default) 428 endm 429 M @? 40 ;40-bit quantity (on request) 429 endm 430 M @? 48 ;48-bit quantity (on request) 430 M 0006 ?WORD equ 48/8 430 M 262C _STKMTH48_ 430 M 182C _STAKMATH_ def * 430 endm 431 M @? 56 ;56-bit quantity (on request) 431 endm 432 M @? 64 ;64-bit quantity (on request) 432 endm 433 439 #Message MATHSIZE = {MATHSIZE}-bit version 441 #Message Signed routines enabled 443 ;******************************************************************************* 444 ; Macros to make operations as simple as with a high-level language 445 ; In operations that require two operands and a result, if only one operand is 446 ; provided, then the operation is done completely on stack (no other variables 447 ; used). For example, @Add32 A,B,SUM adds A to B and places result in SUM, 448 ; while @Add32 A adds the current stack top to A and leaves result on stack. 449 ; You can use @Load* and @Save* to load the initial value, and store the final 450 ; result, respectively. (Replace * with 16, 24, 32, 40, 48, 56, or 64) 451 ;******************************************************************************* 452 501 ;=============================================================================== 550 ;=============================================================================== 599 ;=============================================================================== 648 ;=============================================================================== 650 651 Load48 macro #Number|Variable ;load constant or variable 652 @_DoLoad ~0.{:0-1}~\,~@~ 653 endm 654 655 Save48 macro Address 656 @_DoSave 48\,~@~ 657 endm 658 659 Copy48 macro #Constant|Variable,ToAddress 660 mreq 1,2:#Constant|Variable,ToAddress 661 @@Load48 ~1~ 662 @Save48 ~2~ 663 endm 664 665 Swap48 macro 666 @_DoSwap 48 667 endm 668 669 Add48 macro Addend,Adder,Sum 670 @_DoMath ~0~\,48\,~1~\,~2~\,~3~ 671 endm 672 673 Sub48 macro Minuend,Subtrahend,Difference 674 @_DoMath ~0~\,48\,~1~\,~2~\,~3~ 675 endm 676 677 Mul48 macro Multiplicand,Multiplier,Product 678 @_DoMath ~0~\,48\,~1~\,~2~\,~3~ 679 endm 680 681 Div48 macro Dividend,Divisor,Quotient 682 @_DoMath ~0~\,48\,~1~\,~2~\,~3~ 683 endm 684 685 Mod48 macro Dividend,Divisor,Remainder 686 @_DoMath ~0~\,48\,~1~\,~2~\,~3~ 687 endm 688 689 Abs48 macro Source[,Destination] 690 @_DoAbs 48\,~1~\,~2~ 691 endm 692 693 Neg48 macro Source[,Destination] 694 @_DoNeg 48\,~1~\,~2~ 695 endm 697 ;=============================================================================== 746 ;=============================================================================== 795 796 ;******************************************************************************* 797 ; Common macro(s) for all operations defined above (not to be called directly) 798 ;******************************************************************************* 799 807 ;------------------------------------------------------------------------------- 867 ;------------------------------------------------------------------------------- 890 ;------------------------------------------------------------------------------- 898 ;------------------------------------------------------------------------------- 916 ;=============================================================================== 933 ;------------------------------------------------------------------------------- 1158 ;------------------------------------------------------------------------------- 1185 ;------------------------------------------------------------------------------- 1212 ;------------------------------------------------------------------------------- 1288 ;------------------------------------------------------------------------------- 1328 ;------------------------------------------------------------------------------- 1337 ;------------------------------------------------------------------------------- 1351 ;------------------------------------------------------------------------------- 1380 ;------------------------------------------------------------------------------- 1398 ;------------------------------------------------------------------------------- 1416 ;------------------------------------------------------------------------------- 1451 1452 ;******************************************************************************* 1453 ; External dependencies 1454 ;******************************************************************************* 1455 1456 #Uses string/length.sub 1457 #Uses string/insertchar.sub 1458 #Uses string/adddecimalpoint.sub 1459 262C ?_OBJECT_? 1460 ;******************************************************************************* 1461 ; One-based (SP-index) offsets to stacked operands (to be used with #SPAUTO :AB) 1462 ;******************************************************************************* 1463 1464 #temp 1 1465 0001 ?a next :temp,?WORD ;top-of-stack (TOS) number (N1) 1466 0007 ?b next :temp,?WORD ;number after TOS (N2) 1467 1468 #Cycles ;reset the cycles counter 1469 1470 ;******************************************************************************* 1471 ; Purpose: Add N1 to N2 and place result on top-of-stack. N1 & N2 removed 1472 ; Input : [TOS+?WORD] = Number2 1473 ; : [TOS] = Number1 1474 ; Output : [TOS] = Result 1475 ; Note(s): Carry Set on overflow 1476 1477 #spauto :ab 1478 1479 262C ?Add proc 1480 [262C] 262C:8789 8B [ 6] push 1481 [262F] 262F:95 [ 2] tsx 1482 1488 [2630] 2630:A606 [ 2] lda #?WORD 1489 [2632] 2632:98 [ 1] clc 1490 #Cycles 1491 [2633] 2633:87 [ 2] Loop@@ psha 1492 [2634] 2634:E60A [ 3] lda ?a+{::?a-1},spx 1493 [2636] 2636:E910 [ 3] adc ?b+{::?b-1},spx 1494 [2638] 2638:E710 [ 3] sta ?b+{::?b-1},spx 1495 [263A] 263A:86 [ 3] pula 1496 [263B] 263B:AFFF [ 2] aix #-1 1497 [263D] 263D:4BF4 (2633) [ 4] dbnza Loop@@ 1498 #Cycles :cycles*?WORD+:ocycles 1500 [263F] 263F:CC29 98 [ 4] jmp ?RemoveAndReturn 1501 1502 0087 ?AddCycles equ :cycles 1503 1504 ;******************************************************************************* 1505 ; Purpose: Subtract N2 from N1 and place result on top-of-stack. N1 & N2 removed 1506 ; Input : [TOS+?WORD] = Number2 1507 ; : [TOS] = Number1 1508 ; Output : [TOS] = Result 1509 ; Note(s): Carry Set on borrow 1510 1511 #spauto :ab 1512 1513 2642 ?Subtract proc 1514 [2642] 2642:8789 8B [ 6] push 1515 [2645] 2645:95 [ 2] tsx 1521 [2646] 2646:A606 [ 2] lda #?WORD 1522 [2648] 2648:98 [ 1] clc 1523 #Cycles 1524 [2649] 2649:87 [ 2] Loop@@ psha 1525 [264A] 264A:E60A [ 3] lda ?a+{::?a-1},spx 1526 [264C] 264C:E210 [ 3] sbc ?b+{::?b-1},spx 1527 [264E] 264E:E710 [ 3] sta ?b+{::?b-1},spx 1528 [2650] 2650:86 [ 3] pula 1529 [2651] 2651:AFFF [ 2] aix #-1 1530 [2653] 2653:4BF4 (2649) [ 4] dbnza Loop@@ 1531 #Cycles :cycles*?WORD+:ocycles 1533 [2655] 2655:CC29 98 [ 4] jmp ?RemoveAndReturn 1534 1535 0087 ?SubCycles equ :cycles 1536 1540 M @Msg Bit ops enabled (define NO_BIT_OPS to disable) 1540 mexit 1541 ;******************************************************************************* 1542 ; Purpose: AND N1 with N2 and place result on top-of-stack. N1 & N2 removed 1543 ; Input : [TOS+?WORD] = Number2 1544 ; : [TOS] = Number1 1545 ; Output : [TOS] = Result 1546 ; Note(s): 1547 #spauto :ab 1548 1549 2658 ?BitAnd proc 1550 [2658] 2658:8789 8B [ 6] push 1551 [265B] 265B:95 [ 2] tsx 1552 1558 [265C] 265C:A606 [ 2] lda #?WORD 1559 #Cycles 1560 [265E] 265E:87 [ 2] Loop@@ psha 1561 [265F] 265F:E60A [ 3] lda ?a+{::?a-1},spx 1562 [2661] 2661:E410 [ 3] and ?b+{::?b-1},spx 1563 [2663] 2663:E710 [ 3] sta ?b+{::?b-1},spx 1564 [2665] 2665:86 [ 3] pula 1565 [2666] 2666:AFFF [ 2] aix #-1 1566 [2668] 2668:4BF4 (265E) [ 4] dbnza Loop@@ 1567 #Cycles :cycles*?WORD+:ocycles 1569 [266A] 266A:CC29 98 [ 4] jmp ?RemoveAndReturn 1570 1571 0086 ?AndCycles equ :cycles 1572 1573 ;******************************************************************************* 1574 ; Purpose: OR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1575 ; Input : [TOS+?WORD] = Number2 1576 ; : [TOS] = Number1 1577 ; Output : [TOS] = Result 1578 ; Note(s): 1579 #spauto :ab 1580 1581 266D ?BitOr proc 1582 [266D] 266D:8789 8B [ 6] push 1583 [2670] 2670:95 [ 2] tsx 1584 1590 [2671] 2671:A606 [ 2] lda #?WORD 1591 #Cycles 1592 [2673] 2673:87 [ 2] Loop@@ psha 1593 [2674] 2674:E60A [ 3] lda ?a+{::?a-1},spx 1594 [2676] 2676:EA10 [ 3] ora ?b+{::?b-1},spx 1595 [2678] 2678:E710 [ 3] sta ?b+{::?b-1},spx 1596 [267A] 267A:86 [ 3] pula 1597 [267B] 267B:AFFF [ 2] aix #-1 1598 [267D] 267D:4BF4 (2673) [ 4] dbnza Loop@@ 1599 #Cycles :cycles*?WORD+:ocycles 1601 [267F] 267F:CC29 98 [ 4] jmp ?RemoveAndReturn 1602 1603 0086 ?OrCycles equ :cycles 1604 1605 ;******************************************************************************* 1606 ; Purpose: XOR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1607 ; Input : [TOS+?WORD] = Number2 1608 ; : [TOS] = Number1 1609 ; Output : [TOS] = Result 1610 ; Note(s): 1611 #spauto :ab 1612 1613 2682 ?BitXor proc 1614 [2682] 2682:8789 8B [ 6] push 1615 [2685] 2685:95 [ 2] tsx 1616 1622 [2686] 2686:A606 [ 2] lda #?WORD 1623 #Cycles 1624 [2688] 2688:87 [ 2] Loop@@ psha 1625 [2689] 2689:E60A [ 3] lda ?a+{::?a-1},spx 1626 [268B] 268B:E810 [ 3] eor ?b+{::?b-1},spx 1627 [268D] 268D:E710 [ 3] sta ?b+{::?b-1},spx 1628 [268F] 268F:86 [ 3] pula 1629 [2690] 2690:AFFF [ 2] aix #-1 1630 [2692] 2692:4BF4 (2688) [ 4] dbnza Loop@@ 1631 #Cycles :cycles*?WORD+:ocycles 1633 [2694] 2694:CC29 98 [ 4] jmp ?RemoveAndReturn 1634 1635 0086 ?EorCycles equ :cycles 1636 1637 ;******************************************************************************* 1638 ; Purpose: Shift N1 left N2 times and place result on top-of-stack. N1 & N2 removed 1639 ; Input : [TOS+?WORD] = Number2 1640 ; : [TOS] = Number1 1641 ; Output : [TOS] = Result 1642 ; Note(s): CCR[C] = last most significant bit shifted out 1643 ; : Only LSB of second operand (N2) is used, as shifting more than the 1644 ; : highest bit version always produces zero. Any non-zero bytes in the 1645 ; : N2 operand will cause a zero result, regardless. 1646 1647 #spauto :ab 1648 1649 2697 ?ShiftLeft proc 1650 [2697] 2697:8789 8B [ 6] push 1651 #ais 1652 1653 [269A] 269A:9EE6 11 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1654 [269D] 269D:87 [ 2] psha counter@@ 1655 1656 [269E] 269E:95 [ 2] tsx 1657 1658 [269F] 269F:6F11 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1659 0007 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1660 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1660 M mset # 1660 M mreq 1 1660 M @@_nosize_ b86,spx 1660 M mset # 1660 M mset 0,mstop [_tst_.s] No size (b86,spx) 1660 M endm 1660 M mdo 1660 M [26A1] 26A1:E60C [ 3] lda b86+0,spx 1660 M mloop ::b86 1660 M [26A3] 26A3:EA0D [ 3] ora b86+1,spx 1660 M mloop ::b86 1660 M [26A5] 26A5:EA0E [ 3] ora b86+2,spx 1660 M mloop ::b86 1660 M [26A7] 26A7:EA0F [ 3] ora b86+3,spx 1660 M mloop ::b86 1660 M [26A9] 26A9:EA10 [ 3] ora b86+4,spx 1660 M mloop ::b86 1660 endm 1661 [26AB] 26AB:2711 (26BE) [ 3] beq Go@@ ;if so, proceed normally 1662 1663 [26AD] 26AD:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1664 [26AE] 26AE:A130 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1665 [26B0] 26B0:250C (26BE) [ 3] blo Go@@ ;else zero and exit 1666 1667 M @clr.s, b@@,spx ;else error, so zero result 1667 M mset #' ' 1667 M mreq 1 1667 M @@_nosize_ b86,spx 1667 M mset # 1667 M mset 0,mstop [clr.s] No size (b86,spx) 1667 M endm 1667 M mdef 2,::b86 1667 M mdo 1667 M [26B2] 26B2:6F0C [ 5] clr b86+0,spx 1667 M mloop ::b86 1667 M [26B4] 26B4:6F0D [ 5] clr b86+1,spx 1667 M mloop ::b86 1667 M [26B6] 26B6:6F0E [ 5] clr b86+2,spx 1667 M mloop ::b86 1667 M [26B8] 26B8:6F0F [ 5] clr b86+3,spx 1667 M mloop ::b86 1667 M [26BA] 26BA:6F10 [ 5] clr b86+4,spx 1667 M mloop ::b86 1667 endm 1668 [26BC] 26BC:2026 (26E4) [ 3] bra Done@@ ;and get out 1669 1670 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1670 M mset #' ' 1670 M mreq 1,2:Source Destination 1670 M @@_samesize_ ?a,spx ?b,spx 1670 M mreq 1,2:Operand1,Operand2[,Operand]* 1670 M mset 0 1670 M mdo 1670 M mswap 1,1 1670 M @@_nosize_ ?a,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?a,spx) 1670 M endm 1670 M mset 0,?a,spx 1670 M mloop :n 1670 M mswap 1,2 1670 M @@_nosize_ ?b,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?b,spx) 1670 M endm 1670 M mloop :n 1670 M endm 1670 M mset 0 1670 M mdo 1670 M [26BE] 26BE:E606 [ 3] lda ?a+0,spx 1670 M [26C0] 26C0:E70C [ 3] sta ?b+0,spx 1670 M mloop ::?b 1670 M [26C2] 26C2:E607 [ 3] lda ?a+1,spx 1670 M [26C4] 26C4:E70D [ 3] sta ?b+1,spx 1670 M mloop ::?b 1670 M [26C6] 26C6:E608 [ 3] lda ?a+2,spx 1670 M [26C8] 26C8:E70E [ 3] sta ?b+2,spx 1670 M mloop ::?b 1670 M [26CA] 26CA:E609 [ 3] lda ?a+3,spx 1670 M [26CC] 26CC:E70F [ 3] sta ?b+3,spx 1670 M mloop ::?b 1670 M [26CE] 26CE:E60A [ 3] lda ?a+4,spx 1670 M [26D0] 26D0:E710 [ 3] sta ?b+4,spx 1670 M mloop ::?b 1670 M [26D2] 26D2:E60B [ 3] lda ?a+5,spx 1670 M [26D4] 26D4:E711 [ 3] sta ?b+5,spx 1670 M mloop ::?b 1670 endm 1671 #Cycles 1672 M Loop@@ @lsl.s, ?b,spx ;shift left one bit position 1672 M mset # 1672 M mreq 1 1672 M @@_nosize_ ?b,spx 1672 M mset # 1672 M mset 0,mstop [lsl.s] No size (?b,spx) 1672 M endm 1672 M mdo 1672 M [26D6] 26D6:6811 [ 5] lsl ?b+5,spx 1672 M mloop ::?b 1672 M [26D8] 26D8:6910 [ 5] rol ?b+4,spx 1672 M mloop ::?b 1672 M [26DA] 26DA:690F [ 5] rol ?b+3,spx 1672 M mloop ::?b 1672 M [26DC] 26DC:690E [ 5] rol ?b+2,spx 1672 M mloop ::?b 1672 M [26DE] 26DE:690D [ 5] rol ?b+1,spx 1672 M mloop ::?b 1672 M [26E0] 26E0:690C [ 5] rol ?b+0,spx 1672 M mloop ::?b 1672 endm 1673 [26E2] 26E2:7BF2 (26D6) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1674 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1675 26E4 Done@@ 1677 [26E4] 26E4:86 [ 3] pula 1681 [26E5] 26E5:CC29 98 [ 4] jmp ?RemoveAndReturn 1682 1683 0710 ?ShlCycles equ :cycles 1684 1685 ;******************************************************************************* 1686 ; Purpose: Shift N1 right N2 times and place result on top-of-stack. N1 & N2 removed 1687 ; Input : [TOS+?WORD] = Number2 1688 ; : [TOS] = Number1 1689 ; Output : [TOS] = Result 1690 ; Note(s): CCR[C] = last least significant bit shifted out 1691 ; : Only LSB of second operand (N2) is used, as shifting more than the 1692 ; : highest bit version always produces zero. Any non-zero bytes in the 1693 ; : N2 operand will cause a zero result, regardless. 1694 1695 #spauto :ab 1696 1697 26E8 ?ShiftRight proc 1698 [26E8] 26E8:8789 8B [ 6] push 1699 #ais 1700 1701 [26EB] 26EB:9EE6 11 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1702 [26EE] 26EE:87 [ 2] psha counter@@ 1703 1704 [26EF] 26EF:95 [ 2] tsx 1705 1706 [26F0] 26F0:6F11 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1707 0007 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1708 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1708 M mset # 1708 M mreq 1 1708 M @@_nosize_ b87,spx 1708 M mset # 1708 M mset 0,mstop [_tst_.s] No size (b87,spx) 1708 M endm 1708 M mdo 1708 M [26F2] 26F2:E60C [ 3] lda b87+0,spx 1708 M mloop ::b87 1708 M [26F4] 26F4:EA0D [ 3] ora b87+1,spx 1708 M mloop ::b87 1708 M [26F6] 26F6:EA0E [ 3] ora b87+2,spx 1708 M mloop ::b87 1708 M [26F8] 26F8:EA0F [ 3] ora b87+3,spx 1708 M mloop ::b87 1708 M [26FA] 26FA:EA10 [ 3] ora b87+4,spx 1708 M mloop ::b87 1708 endm 1709 [26FC] 26FC:2711 (270F) [ 3] beq Go@@ ;if so, proceed normally 1710 1711 [26FE] 26FE:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1712 [26FF] 26FF:A130 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1713 [2701] 2701:250C (270F) [ 3] blo Go@@ ;else zero and exit 1714 1715 M @clr.s, b@@,spx ;else error, so zero result 1715 M mset #' ' 1715 M mreq 1 1715 M @@_nosize_ b87,spx 1715 M mset # 1715 M mset 0,mstop [clr.s] No size (b87,spx) 1715 M endm 1715 M mdef 2,::b87 1715 M mdo 1715 M [2703] 2703:6F0C [ 5] clr b87+0,spx 1715 M mloop ::b87 1715 M [2705] 2705:6F0D [ 5] clr b87+1,spx 1715 M mloop ::b87 1715 M [2707] 2707:6F0E [ 5] clr b87+2,spx 1715 M mloop ::b87 1715 M [2709] 2709:6F0F [ 5] clr b87+3,spx 1715 M mloop ::b87 1715 M [270B] 270B:6F10 [ 5] clr b87+4,spx 1715 M mloop ::b87 1715 endm 1716 [270D] 270D:2026 (2735) [ 3] bra Done@@ ;and get out 1717 1718 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1718 M mset #' ' 1718 M mreq 1,2:Source Destination 1718 M @@_samesize_ ?a,spx ?b,spx 1718 M mreq 1,2:Operand1,Operand2[,Operand]* 1718 M mset 0 1718 M mdo 1718 M mswap 1,1 1718 M @@_nosize_ ?a,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?a,spx) 1718 M endm 1718 M mset 0,?a,spx 1718 M mloop :n 1718 M mswap 1,2 1718 M @@_nosize_ ?b,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?b,spx) 1718 M endm 1718 M mloop :n 1718 M endm 1718 M mset 0 1718 M mdo 1718 M [270F] 270F:E606 [ 3] lda ?a+0,spx 1718 M [2711] 2711:E70C [ 3] sta ?b+0,spx 1718 M mloop ::?b 1718 M [2713] 2713:E607 [ 3] lda ?a+1,spx 1718 M [2715] 2715:E70D [ 3] sta ?b+1,spx 1718 M mloop ::?b 1718 M [2717] 2717:E608 [ 3] lda ?a+2,spx 1718 M [2719] 2719:E70E [ 3] sta ?b+2,spx 1718 M mloop ::?b 1718 M [271B] 271B:E609 [ 3] lda ?a+3,spx 1718 M [271D] 271D:E70F [ 3] sta ?b+3,spx 1718 M mloop ::?b 1718 M [271F] 271F:E60A [ 3] lda ?a+4,spx 1718 M [2721] 2721:E710 [ 3] sta ?b+4,spx 1718 M mloop ::?b 1718 M [2723] 2723:E60B [ 3] lda ?a+5,spx 1718 M [2725] 2725:E711 [ 3] sta ?b+5,spx 1718 M mloop ::?b 1718 endm 1719 #Cycles 1720 2727 Loop@@ 1722 M @asr.s, ?b,spx ;shift right one bit position 1722 M mset # 1722 M mreq 1 1722 M @@_nosize_ ?b,spx 1722 M mset # 1722 M mset 0,mstop [asr.s] No size (?b,spx) 1722 M endm 1722 M mdo 1722 M [2727] 2727:670C [ 5] asr ?b+0,spx 1722 M mloop ::?b 1722 M [2729] 2729:660D [ 5] ror ?b+1,spx 1722 M mloop ::?b 1722 M [272B] 272B:660E [ 5] ror ?b+2,spx 1722 M mloop ::?b 1722 M [272D] 272D:660F [ 5] ror ?b+3,spx 1722 M mloop ::?b 1722 M [272F] 272F:6610 [ 5] ror ?b+4,spx 1722 M mloop ::?b 1722 M [2731] 2731:6611 [ 5] ror ?b+5,spx 1722 M mloop ::?b 1722 endm 1726 [2733] 2733:7BF2 (2727) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1727 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1728 2735 Done@@ 1730 [2735] 2735:86 [ 3] pula 1734 [2736] 2736:CC29 98 [ 4] jmp ?RemoveAndReturn 1735 1736 0710 ?ShrCycles equ :cycles 1738 1739 ;******************************************************************************* 1740 ; Purpose: Multiply N1 with N2 and place result on top-of-stack. N1 & N2 removed 1741 ; Input : [TOS+?WORD] = Number2 1742 ; : [TOS] = Number1 1743 ; Output : [TOS] = Result 1744 ; Note(s): Overflows lost, Carry state should be ignored 1745 1746 #spauto :ab 1747 1748 2739 ?Multiply proc 1749 [2739] 2739:8789 8B [ 6] push 1773 ;=============================================================================== 1826 ;=============================================================================== 1913 #temp :cycles 1914 ;=============================================================================== 1915 ;-------------------------------------- 1916 ; 40, 48, 56, and 64-bit versions use shorter 1917 ; shift/add method (more cycles, though) 1918 ;-------------------------------------- 1920 1921 [273C] 273C:AE06 [ 2] ldx #?WORD ;make room for result... 1922 [273E] 273E:4F [ 1] clra ;... initialized to zero 1923 #temp :cycles+:temp 1924 [273F] 273F:87 [ 2] Init@@ psha 1925 [2740] 2740:5BFD (273F) [ 4] dbnzx Init@@ 1926 #temp :cycles*?WORD+:temp 1927 #spadd ?WORD-1 ;stack has grown by a ?WORD 1928 FFFFFFF6 ans@@ equ ::,?WORD 1929 1930 [2742] 2742:A630 [ 2] lda #MATHSIZE ;number of bits to process 1931 [2744] 2744:87 [ 2] psha bits@@ 1932 1933 [2745] 2745:95 [ 2] tsx 1934 #temp :cycles+:temp 1935 M Loop@@ @lsr.s ?b,spx ;multiplier lsb into CCR[C] 1935 M mset # 1935 M mreq 1 1935 M @@_nosize_ ?b,spx 1935 M mset # 1935 M mset 0,mstop [lsr.s] No size (?b,spx) 1935 M endm 1935 M mdo 1935 M [2746] 2746:6412 [ 5] lsr ?b+0,spx 1935 M mloop ::?b 1935 M [2748] 2748:6613 [ 5] ror ?b+1,spx 1935 M mloop ::?b 1935 M [274A] 274A:6614 [ 5] ror ?b+2,spx 1935 M mloop ::?b 1935 M [274C] 274C:6615 [ 5] ror ?b+3,spx 1935 M mloop ::?b 1935 M [274E] 274E:6616 [ 5] ror ?b+4,spx 1935 M mloop ::?b 1935 M [2750] 2750:6617 [ 5] ror ?b+5,spx 1935 M mloop ::?b 1935 endm 1936 [2752] 2752:2424 (2778) [ 3] bcc Skip@@ ;Zeros skip addition 1937 1938 M @add.s ?a,spx ans@@,spx ans@@,spx ;Ones add multiplicand to product 1938 M mset #' ' 1938 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1938 M @@_samesize_ ?a,spx ans88,spx ans@@,spx 1938 M mreq 1,2:Operand1,Operand2[,Operand]* 1938 M mset 0 1938 M mdo 1938 M mswap 1,1 1938 M @@_nosize_ ?a,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (?a,spx) 1938 M endm 1938 M mset 0,?a,spx 1938 M mloop :n 1938 M mswap 1,2 1938 M @@_nosize_ ans88,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans88,spx) 1938 M endm 1938 M mloop :n 1938 M mswap 1,3 1938 M @@_nosize_ ans@@,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans88,spx) 1938 M endm 1938 M mloop :n 1938 M endm 1938 M mset 0,@@add.b, 1938 M mdo 1938 M mset 0,@@add.b, ?a+5,spx 1938 M mset 0,@@add.b, ?a+5,spx ans88+5,spx 1938 M mset 0,@@add.b, ?a+5,spx ans88+5,spx ans@@+5,spx 1938 M @@add.b, ?a+5,spx ans88+5,spx ans@@+5,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2754] 2754:E611 [ 3] lda ?a+5,spx 1938 M [2756] 2756:EB06 [ 3] add ans88+5,spx 1938 M @_sta_ ans@@+5,spx 1938 M [2758] 2758:E706 [ 3] sta ans88+5,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+4,spx 1938 M mset 0,@@adc.b, ?a+4,spx ans88+4,spx 1938 M mset 0,@@adc.b, ?a+4,spx ans88+4,spx ans@@+4,spx 1938 M @@adc.b, ?a+4,spx ans88+4,spx ans@@+4,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [275A] 275A:E610 [ 3] lda ?a+4,spx 1938 M [275C] 275C:E905 [ 3] adc ans88+4,spx 1938 M @_sta_ ans@@+4,spx 1938 M [275E] 275E:E705 [ 3] sta ans88+4,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans88+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans88+3,spx ans@@+3,spx 1938 M @@adc.b, ?a+3,spx ans88+3,spx ans@@+3,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2760] 2760:E60F [ 3] lda ?a+3,spx 1938 M [2762] 2762:E904 [ 3] adc ans88+3,spx 1938 M @_sta_ ans@@+3,spx 1938 M [2764] 2764:E704 [ 3] sta ans88+3,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans88+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans88+2,spx ans@@+2,spx 1938 M @@adc.b, ?a+2,spx ans88+2,spx ans@@+2,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2766] 2766:E60E [ 3] lda ?a+2,spx 1938 M [2768] 2768:E903 [ 3] adc ans88+2,spx 1938 M @_sta_ ans@@+2,spx 1938 M [276A] 276A:E703 [ 3] sta ans88+2,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans88+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans88+1,spx ans@@+1,spx 1938 M @@adc.b, ?a+1,spx ans88+1,spx ans@@+1,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [276C] 276C:E60D [ 3] lda ?a+1,spx 1938 M [276E] 276E:E902 [ 3] adc ans88+1,spx 1938 M @_sta_ ans@@+1,spx 1938 M [2770] 2770:E702 [ 3] sta ans88+1,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans88+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans88+0,spx ans@@+0,spx 1938 M @@adc.b, ?a+0,spx ans88+0,spx ans@@+0,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2772] 2772:E60C [ 3] lda ?a+0,spx 1938 M [2774] 2774:E901 [ 3] adc ans88+0,spx 1938 M @_sta_ ans@@+0,spx 1938 M [2776] 2776:E701 [ 3] sta ans88+0,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 endm 1939 1940 M Skip@@ @lsl.s ?a,spx ;Multiplicand*=2 for each bit 1940 M mset # 1940 M mreq 1 1940 M @@_nosize_ ?a,spx 1940 M mset # 1940 M mset 0,mstop [lsl.s] No size (?a,spx) 1940 M endm 1940 M mdo 1940 M [2778] 2778:6811 [ 5] lsl ?a+5,spx 1940 M mloop ::?a 1940 M [277A] 277A:6910 [ 5] rol ?a+4,spx 1940 M mloop ::?a 1940 M [277C] 277C:690F [ 5] rol ?a+3,spx 1940 M mloop ::?a 1940 M [277E] 277E:690E [ 5] rol ?a+2,spx 1940 M mloop ::?a 1940 M [2780] 2780:690D [ 5] rol ?a+1,spx 1940 M mloop ::?a 1940 M [2782] 2782:690C [ 5] rol ?a+0,spx 1940 M mloop ::?a 1940 endm 1941 [2784] 2784:7BC0 (2746) [ 6] dbnz bits@@,spx,Loop@@ 1942 #temp :cycles*MATHSIZE+:temp 1943 [2786] 2786:86 [ 3] pula ;remove bit counter 1945 ;-------------------------------------- 1946 ; copy result to B while removing from stack 1947 ;-------------------------------------- 1948 [2787] 2787:AE06 [ 2] ldx #?WORD 1949 #temp :cycles+:temp 1950 [2789] 2789:86 [ 3] CopyResult@@ pula 1951 [278A] 278A:9EE7 11 [ 4] sta ?b,sp 1952 [278D] 278D:5BFA (2789) [ 4] dbnzx CopyResult@@ 1953 1954 #spadd 1-?WORD 1955 #temp :cycles*?WORD+:temp 1956 [278F] 278F:CC29 98 [ 4] jmp ?RemoveAndReturn 1957 1958 178E ?MulCycles equ :temp+:cycles 1959 1960 ;******************************************************************************* 1961 ; Purpose: Divide N1 by N2 and place quotient on top-of-stack. N1 & N2 removed 1962 ; Input : [TOS+?WORD] = Divisor (N2) 1963 ; : [TOS] = Dividend (N1) 1964 ; Output : [TOS] = Quotient 1965 ; : Carry Set on error (division by zero) 1966 ; Note(s): 1967 #spauto :ab 1968 1969 2792 ?Divide proc 1970 [2792] 2792:8789 8B [ 6] push 1971 1972 [2795] 2795:A601 [ 2] lda #?DIVOP_ ;flag for DIV operation 1974 [2797] 2797:87 [ 2] psha 1975 [2798] 2798:95 [ 2] tsx 1976 [2799] 2799:E606 [ 3] lda ?a,spx 1977 [279B] 279B:E80C [ 3] eor ?b,spx 1978 [279D] 279D:86 [ 3] pula 1979 [279E] 279E:2A02 (27A2) [ 3] bpl Skip@@ 1980 [27A0] 27A0:AA80 [ 2] ora #?SIGN_ ;flag for negative 1981 27A2 Skip@@ 1983 [27A2] 27A2:87 [ 2] psha ;save flags on stack 1984 [27A3] 27A3:2036 (27DB) [ 3] bra ?DivStart 1985 1986 001F ?DivCycles equ :cycles 1987 1988 ;******************************************************************************* 1989 ; Purpose: Divide N1 by N2 and place remainder on top-of-stack. N1 & N2 removed 1990 ; Input : [TOS+?WORD] = Divisor (N2) 1991 ; : [TOS] = Dividend (N1) 1992 ; Output : [TOS] = Remainder 1993 ; : Carry Set on error (division by zero) 1994 ; Note(s): 1995 #spauto :ab 1996 FFFFFFFF ?pc equ ::,:ab 1997 1998 27A5 ?Modulo proc 1999 [27A5] 27A5:8789 8B [ 6] push 2000 2001 [27A8] 27A8:4F [ 1] clra ;flag for MOD operation 2003 [27A9] 27A9:9E6D 06 [ 5] tst ?a,sp 2004 [27AC] 27AC:2A02 (27B0) [ 3] bpl Skip@@ 2005 [27AE] 27AE:AA80 [ 2] ora #?SIGN_ ;flag for negative 2006 27B0 Skip@@ 2008 [27B0] 27B0:87 [ 2] psha ;save flags on stack 2009 [27B1] 27B1:2028 (27DB) [ 3] bra ?DivStart 2010 2011 0016 ?ModCycles equ :cycles 2012 2013 ;******************************************************************************* 2014 2015 #temp 2017 27B3 ?AbsX proc 2018 [27B3] 27B3:7D [ 3] tst ,ax 2019 [27B4] 27B4:2A1E (27D4) [ 3] bpl Done@@ 2020 #temp :cycles 2021 0000 var@@ equ 0,?WORD 2022 M ?NegX @neg.s var@@,ax 2022 M mset # 2022 M mreq 1 2022 M @@_nosize_ var91,ax 2022 M mset # 2022 M mset 0,mstop [neg.s] No size (var91,ax) 2022 M endm 2022 M mdo 2022 M [27B6] 27B6:73 [ 4] com var91+0,ax 2022 M mloop ::var91-1 2022 M [27B7] 27B7:6301 [ 5] com var91+1,ax 2022 M mloop ::var91-1 2022 M [27B9] 27B9:6302 [ 5] com var91+2,ax 2022 M mloop ::var91-1 2022 M [27BB] 27BB:6303 [ 5] com var91+3,ax 2022 M mloop ::var91-1 2022 M [27BD] 27BD:6304 [ 5] com var91+4,ax 2022 M mloop ::var91-1 2022 M [27BF] 27BF:6005 [ 5] neg var91+5,ax 2022 M mdo 2022 M [27C1] 27C1:2611 (27D4) [ 3] bne Done$$$ 2022 M [27C3] 27C3:6C04 [ 5] inc var91+4,ax 2022 M mloop ::var91-1 2022 M [27C5] 27C5:260D (27D4) [ 3] bne Done$$$ 2022 M [27C7] 27C7:6C03 [ 5] inc var91+3,ax 2022 M mloop ::var91-1 2022 M [27C9] 27C9:2609 (27D4) [ 3] bne Done$$$ 2022 M [27CB] 27CB:6C02 [ 5] inc var91+2,ax 2022 M mloop ::var91-1 2022 M [27CD] 27CD:2605 (27D4) [ 3] bne Done$$$ 2022 M [27CF] 27CF:6C01 [ 5] inc var91+1,ax 2022 M mloop ::var91-1 2022 M [27D1] 27D1:2601 (27D4) [ 3] bne Done$$$ 2022 M [27D3] 27D3:7C [ 4] inc var91+0,ax 2022 M mloop ::var91-1 2022 M 27D4 Done$$$ 2022 endm 2023 [27D4] 27D4:81 [ 6] Done@@ rts 2024 2025 004A ?AbsXCycles equ :cycles 2026 0044 ?NegxCycles equ ?AbsXCycles-:temp 2028 2029 ;******************************************************************************* 2030 2031 0000 ?SF equ 0 ;stack frame (for X-index use) 2032 2033 0000 ?quotient next ?SF,?WORD 2034 0006 ?remainder next ?SF,?WORD 2035 000C ?temp next ?SF,?WORD 2036 0012 ?bits next ?SF 2037 0013 ?flags next ?SF 2038 2039 0001 ?DIVOP_ equ %00000001 ;1 = DIV, 0 = MOD 2040 0080 ?SIGN_ equ %10000000 ;result sign (1 = negative) 2041 2042 #push 2043 2044 [27D5] 27D5:A714 [ 2] ?DivError ais #?SF ;de-allocate temporaries 2045 [27D7] 27D7:99 [ 1] sec ;indicate error condition 2046 [27D8] 27D8:CC29 98 [ 4] jmp ?RemoveAndReturn 2047 2048 #pull 2049 ;------------------------------------------------------------------------------- 2050 27DB ?DivStart proc 2051 0001 dividend@@ equ ?a,::?a 2052 0007 divisor@@ equ ?b,::?b 2053 0007 ans@@ equ ?b,::?b ;result overwrites divisor 2054 2056 M @lea dividend@@,sp 2056 M mset # 2056 M [27DB] 27DB:95 [ 2] tsx 2056 M [27DC] 27DC:AF06 [ 2] !aix #dividend92+:tsx 2056 mexit 2057 [27DE] 27DE:ADD3 (27B3) [ 5] bsr ?AbsX 2058 M @lea divisor@@,sp 2058 M mset # 2058 M [27E0] 27E0:95 [ 2] tsx 2058 M [27E1] 27E1:AF0C [ 2] !aix #divisor92+:tsx 2058 mexit 2059 [27E3] 27E3:ADCE (27B3) [ 5] bsr ?AbsX 2060 #Cycles ?AbsXCycles*2+:cycles 2062 [27E5] 27E5:A7ED [ 2] ais #-?SF+1 ;quotient, remainder, and temp 2063 [27E7] 27E7:95 [ 2] tsx ;(+1 for already pushed Flag) 2064 2065 ; remainder := 0 2066 ; quotient := 0 2067 2068 M @clr.s ?remainder,x 2068 M mset #' ' 2068 M mreq 1 2068 M @@_nosize_ ?remainder,x 2068 M mset # 2068 M mset 0,mstop [clr.s] No size (?remainder,x) 2068 M endm 2068 M mdef 2,::?remainder 2068 M mdo 2068 M [27E8] 27E8:6F06 [ 5] clr ?remainder+0,x 2068 M mloop ::?remainder 2068 M [27EA] 27EA:6F07 [ 5] clr ?remainder+1,x 2068 M mloop ::?remainder 2068 M [27EC] 27EC:6F08 [ 5] clr ?remainder+2,x 2068 M mloop ::?remainder 2068 M [27EE] 27EE:6F09 [ 5] clr ?remainder+3,x 2068 M mloop ::?remainder 2068 M [27F0] 27F0:6F0A [ 5] clr ?remainder+4,x 2068 M mloop ::?remainder 2068 M [27F2] 27F2:6F0B [ 5] clr ?remainder+5,x 2068 M mloop ::?remainder 2068 endm 2069 M @clr.s ?quotient,x 2069 M mset #' ' 2069 M mreq 1 2069 M @@_nosize_ ?quotient,x 2069 M mset # 2069 M mset 0,mstop [clr.s] No size (?quotient,x) 2069 M endm 2069 M mdef 2,::?quotient 2069 M mdo 2069 M [27F4] 27F4:7F [ 4] clr ?quotient+0,x 2069 M mloop ::?quotient 2069 M [27F5] 27F5:6F01 [ 5] clr ?quotient+1,x 2069 M mloop ::?quotient 2069 M [27F7] 27F7:6F02 [ 5] clr ?quotient+2,x 2069 M mloop ::?quotient 2069 M [27F9] 27F9:6F03 [ 5] clr ?quotient+3,x 2069 M mloop ::?quotient 2069 M [27FB] 27FB:6F04 [ 5] clr ?quotient+4,x 2069 M mloop ::?quotient 2069 M [27FD] 27FD:6F05 [ 5] clr ?quotient+5,x 2069 M mloop ::?quotient 2069 endm 2070 2071 ; first, test for division by zero error 2072 2073 M @_tst_.s divisor@@,spx 2073 M mset # 2073 M mreq 1 2073 M @@_nosize_ divisor92,spx 2073 M mset # 2073 M mset 0,mstop [_tst_.s] No size (divisor92,spx) 2073 M endm 2073 M mdo 2073 M [27FF] 27FF:E61F [ 3] lda divisor92+0,spx 2073 M mloop ::divisor92 2073 M [2801] 2801:EA20 [ 3] ora divisor92+1,spx 2073 M mloop ::divisor92 2073 M [2803] 2803:EA21 [ 3] ora divisor92+2,spx 2073 M mloop ::divisor92 2073 M [2805] 2805:EA22 [ 3] ora divisor92+3,spx 2073 M mloop ::divisor92 2073 M [2807] 2807:EA23 [ 3] ora divisor92+4,spx 2073 M mloop ::divisor92 2073 M [2809] 2809:EA24 [ 3] ora divisor92+5,spx 2073 M mloop ::divisor92 2073 endm 2074 [280B] 280B:27C8 (27D5) [ 3] beq ?DivError 2075 2076 ; if Dividend = 0, we're done 2077 2078 M @_tst_.s dividend@@,spx 2078 M mset # 2078 M mreq 1 2078 M @@_nosize_ dividend92,spx 2078 M mset # 2078 M mset 0,mstop [_tst_.s] No size (dividend92,spx) 2078 M endm 2078 M mdo 2078 M [280D] 280D:E619 [ 3] lda dividend92+0,spx 2078 M mloop ::dividend92 2078 M [280F] 280F:EA1A [ 3] ora dividend92+1,spx 2078 M mloop ::dividend92 2078 M [2811] 2811:EA1B [ 3] ora dividend92+2,spx 2078 M mloop ::dividend92 2078 M [2813] 2813:EA1C [ 3] ora dividend92+3,spx 2078 M mloop ::dividend92 2078 M [2815] 2815:EA1D [ 3] ora dividend92+4,spx 2078 M mloop ::dividend92 2078 M [2817] 2817:EA1E [ 3] ora dividend92+5,spx 2078 M mloop ::dividend92 2078 endm 2079 [2819] 2819:2603 CC29 54 [ 7] !jeq Done@@ 2080 2081 ; if (divisor = dividend) then quotient := 1; return 2082 ; if (divisor > dividend) then remainder := dividend; return 2083 2084 M @_cmp_.s divisor@@,spx dividend@@,spx 2084 M mset #' ' 2084 M mreq 1,2:[#]Operand1 [#]Operand2 2084 M @@_samesize_ divisor92,spx dividend@@,spx 2084 M mreq 1,2:Operand1,Operand2[,Operand]* 2084 M mset 0 2084 M mdo 2084 M mswap 1,1 2084 M @@_nosize_ divisor92,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (divisor92,spx) 2084 M endm 2084 M mset 0,divisor92,spx 2084 M mloop :n 2084 M mswap 1,2 2084 M @@_nosize_ dividend@@,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (dividend92,spx) 2084 M endm 2084 M mloop :n 2084 M endm 2084 M #temp 1 2084 M #temp ::divisor92 2084 M #temp ::dividend@@ 2084 M mdo 2084 M [281E] 281E:E61F [ 3] lda divisor92+0,spx 2084 M [2820] 2820:E119 [ 3] cmpa dividend@@+0,spx 2084 M [2822] 2822:261C (2840) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2824] 2824:E620 [ 3] lda divisor92+1,spx 2084 M [2826] 2826:E11A [ 3] cmpa dividend@@+1,spx 2084 M [2828] 2828:2616 (2840) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [282A] 282A:E621 [ 3] lda divisor92+2,spx 2084 M [282C] 282C:E11B [ 3] cmpa dividend@@+2,spx 2084 M [282E] 282E:2610 (2840) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2830] 2830:E622 [ 3] lda divisor92+3,spx 2084 M [2832] 2832:E11C [ 3] cmpa dividend@@+3,spx 2084 M [2834] 2834:260A (2840) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2836] 2836:E623 [ 3] lda divisor92+4,spx 2084 M [2838] 2838:E11D [ 3] cmpa dividend@@+4,spx 2084 M [283A] 283A:2604 (2840) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [283C] 283C:E624 [ 3] lda divisor92+5,spx 2084 M [283E] 283E:E11E [ 3] cmpa dividend@@+5,spx 2084 M mloop :temp 2084 M 2840 Done$$$ 2084 endm 2085 [2840] 2840:2604 (2846) [ 3] bne NotEqual@@ 2086 2087 [2842] 2842:6C05 [ 5] inc ?quotient+{::?quotient-1},x ;quotient := 1 2088 [2844] 2844:201A (2860) [ 3] bra ??DivExit ;and get out 2089 2090 2846 NotEqual@@ ;@sub.s divisor@@,spx dividend@@,spx ;[2012.05.18 REDUNDANT] 2091 [2846] 2846:251B (2863) [ 3] blo Continue@@ 2092 2093 M @mova.s dividend@@,spx ?remainder,x 2093 M mset #' ' 2093 M mreq 1,2:Source Destination 2093 M @@_samesize_ dividend92,spx ?remainder,x 2093 M mreq 1,2:Operand1,Operand2[,Operand]* 2093 M mset 0 2093 M mdo 2093 M mswap 1,1 2093 M @@_nosize_ dividend92,spx 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (dividend92,spx) 2093 M endm 2093 M mset 0,dividend92,spx 2093 M mloop :n 2093 M mswap 1,2 2093 M @@_nosize_ ?remainder,x 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (?remainder,x) 2093 M endm 2093 M mloop :n 2093 M endm 2093 M mset 0 2093 M mdo 2093 M [2848] 2848:E619 [ 3] lda dividend92+0,spx 2093 M [284A] 284A:E706 [ 3] sta ?remainder+0,x 2093 M mloop ::?remainder 2093 M [284C] 284C:E61A [ 3] lda dividend92+1,spx 2093 M [284E] 284E:E707 [ 3] sta ?remainder+1,x 2093 M mloop ::?remainder 2093 M [2850] 2850:E61B [ 3] lda dividend92+2,spx 2093 M [2852] 2852:E708 [ 3] sta ?remainder+2,x 2093 M mloop ::?remainder 2093 M [2854] 2854:E61C [ 3] lda dividend92+3,spx 2093 M [2856] 2856:E709 [ 3] sta ?remainder+3,x 2093 M mloop ::?remainder 2093 M [2858] 2858:E61D [ 3] lda dividend92+4,spx 2093 M [285A] 285A:E70A [ 3] sta ?remainder+4,x 2093 M mloop ::?remainder 2093 M [285C] 285C:E61E [ 3] lda dividend92+5,spx 2093 M [285E] 285E:E70B [ 3] sta ?remainder+5,x 2093 M mloop ::?remainder 2093 endm 2094 2860 ??DivExit ;and get out 2098 [2860] 2860:CC29 54 [ 4] jmp Done@@ 2100 2101 [2863] 2863:A630 [ 2] Continue@@ lda #MATHSIZE 2102 [2865] 2865:E712 [ 3] sta ?bits,x ;bits := 64/56/48/40/32/24/16-bit 2103 2104 ; while (remainder < divisor) do 2105 2106 M While@@ @cop ;in case of many iterations 2106 M [2867] 2867:C718 00 [ 4] sta COP 2106 endm 2107 2108 M @sub.s ?remainder,x divisor@@,spx 2108 M mset #' ' 2108 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2108 M @@_samesize_ ?remainder,x divisor92,spx 2108 M mreq 1,2:Operand1,Operand2[,Operand]* 2108 M mset 0 2108 M mdo 2108 M mswap 1,1 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (?remainder,x) 2108 M endm 2108 M mset 0,?remainder,x 2108 M mloop :n 2108 M mswap 1,2 2108 M @@_nosize_ divisor92,spx 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (divisor92,spx) 2108 M endm 2108 M mloop :n 2108 M endm 2108 M #temp 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [sub.s] No size (?remainder,x) 2108 M endm 2108 M #temp ::?remainder 2108 M mset 0,sub 2108 M mdo 2108 M [286A] 286A:E60B [ 3] lda ?remainder+5,x 2108 M [286C] 286C:E024 [ 3] sub divisor92+5,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [286E] 286E:E60A [ 3] lda ?remainder+4,x 2108 M [2870] 2870:E223 [ 3] sbc divisor92+4,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2872] 2872:E609 [ 3] lda ?remainder+3,x 2108 M [2874] 2874:E222 [ 3] sbc divisor92+3,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2876] 2876:E608 [ 3] lda ?remainder+2,x 2108 M [2878] 2878:E221 [ 3] sbc divisor92+2,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [287A] 287A:E607 [ 3] lda ?remainder+1,x 2108 M [287C] 287C:E220 [ 3] sbc divisor92+1,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [287E] 287E:E606 [ 3] lda ?remainder+0,x 2108 M [2880] 2880:E21F [ 3] sbc divisor92+0,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 endm 2109 [2882] 2882:2434 (28B8) [ 3] bcc EndWhile@@ 2110 2111 ; remainder := (remainder shl 1) or msb(dividend) 2112 ;-------------------------------------- ;2012.12.04 optimization (moved up this code from before DEC to here) 2113 M @mova.s dividend@@,spx ?temp,x ; temp := dividend 2113 M mset #' ' 2113 M mreq 1,2:Source Destination 2113 M @@_samesize_ dividend92,spx ?temp,x 2113 M mreq 1,2:Operand1,Operand2[,Operand]* 2113 M mset 0 2113 M mdo 2113 M mswap 1,1 2113 M @@_nosize_ dividend92,spx 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (dividend92,spx) 2113 M endm 2113 M mset 0,dividend92,spx 2113 M mloop :n 2113 M mswap 1,2 2113 M @@_nosize_ ?temp,x 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (?temp,x) 2113 M endm 2113 M mloop :n 2113 M endm 2113 M mset 0 2113 M mdo 2113 M [2884] 2884:E619 [ 3] lda dividend92+0,spx 2113 M [2886] 2886:E70C [ 3] sta ?temp+0,x 2113 M mloop ::?temp 2113 M [2888] 2888:E61A [ 3] lda dividend92+1,spx 2113 M [288A] 288A:E70D [ 3] sta ?temp+1,x 2113 M mloop ::?temp 2113 M [288C] 288C:E61B [ 3] lda dividend92+2,spx 2113 M [288E] 288E:E70E [ 3] sta ?temp+2,x 2113 M mloop ::?temp 2113 M [2890] 2890:E61C [ 3] lda dividend92+3,spx 2113 M [2892] 2892:E70F [ 3] sta ?temp+3,x 2113 M mloop ::?temp 2113 M [2894] 2894:E61D [ 3] lda dividend92+4,spx 2113 M [2896] 2896:E710 [ 3] sta ?temp+4,x 2113 M mloop ::?temp 2113 M [2898] 2898:E61E [ 3] lda dividend92+5,spx 2113 M [289A] 289A:E711 [ 3] sta ?temp+5,x 2113 M mloop ::?temp 2113 endm 2114 M @lsl.s dividend@@,spx ; dividend := dividend shl 1 2114 M mset # 2114 M mreq 1 2114 M @@_nosize_ dividend92,spx 2114 M mset # 2114 M mset 0,mstop [lsl.s] No size (dividend92,spx) 2114 M endm 2114 M mdo 2114 M [289C] 289C:681E [ 5] lsl dividend92+5,spx 2114 M mloop ::dividend92 2114 M [289E] 289E:691D [ 5] rol dividend92+4,spx 2114 M mloop ::dividend92 2114 M [28A0] 28A0:691C [ 5] rol dividend92+3,spx 2114 M mloop ::dividend92 2114 M [28A2] 28A2:691B [ 5] rol dividend92+2,spx 2114 M mloop ::dividend92 2114 M [28A4] 28A4:691A [ 5] rol dividend92+1,spx 2114 M mloop ::dividend92 2114 M [28A6] 28A6:6919 [ 5] rol dividend92+0,spx 2114 M mloop ::dividend92 2114 endm 2115 ;-------------------------------------- 2116 M @rol.s ?remainder,x 2116 M mset # 2116 M mreq 1 2116 M @@_nosize_ ?remainder,x 2116 M mset # 2116 M mset 0,mstop [rol.s] No size (?remainder,x) 2116 M endm 2116 M mdo 2116 M [28A8] 28A8:690B [ 5] rol ?remainder+5,x 2116 M mloop ::?remainder 2116 M [28AA] 28AA:690A [ 5] rol ?remainder+4,x 2116 M mloop ::?remainder 2116 M [28AC] 28AC:6909 [ 5] rol ?remainder+3,x 2116 M mloop ::?remainder 2116 M [28AE] 28AE:6908 [ 5] rol ?remainder+2,x 2116 M mloop ::?remainder 2116 M [28B0] 28B0:6907 [ 5] rol ?remainder+1,x 2116 M mloop ::?remainder 2116 M [28B2] 28B2:6906 [ 5] rol ?remainder+0,x 2116 M mloop ::?remainder 2116 endm 2117 [28B4] 28B4:6A12 [ 5] dec ?bits,x ; bits := bits - 1 2118 2119 ; end while 2120 2121 [28B6] 28B6:20AF (2867) [ 3] bra While@@ 2122 28B8 EndWhile@@ 2123 M @mova.s ?temp,x dividend@@,spx ; dividend := temp 2123 M mset #' ' 2123 M mreq 1,2:Source Destination 2123 M @@_samesize_ ?temp,x dividend92,spx 2123 M mreq 1,2:Operand1,Operand2[,Operand]* 2123 M mset 0 2123 M mdo 2123 M mswap 1,1 2123 M @@_nosize_ ?temp,x 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (?temp,x) 2123 M endm 2123 M mset 0,?temp,x 2123 M mloop :n 2123 M mswap 1,2 2123 M @@_nosize_ dividend92,spx 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (dividend92,spx) 2123 M endm 2123 M mloop :n 2123 M endm 2123 M mset 0 2123 M mdo 2123 M [28B8] 28B8:E60C [ 3] lda ?temp+0,x 2123 M [28BA] 28BA:E719 [ 3] sta dividend92+0,spx 2123 M mloop ::dividend92 2123 M [28BC] 28BC:E60D [ 3] lda ?temp+1,x 2123 M [28BE] 28BE:E71A [ 3] sta dividend92+1,spx 2123 M mloop ::dividend92 2123 M [28C0] 28C0:E60E [ 3] lda ?temp+2,x 2123 M [28C2] 28C2:E71B [ 3] sta dividend92+2,spx 2123 M mloop ::dividend92 2123 M [28C4] 28C4:E60F [ 3] lda ?temp+3,x 2123 M [28C6] 28C6:E71C [ 3] sta dividend92+3,spx 2123 M mloop ::dividend92 2123 M [28C8] 28C8:E610 [ 3] lda ?temp+4,x 2123 M [28CA] 28CA:E71D [ 3] sta dividend92+4,spx 2123 M mloop ::dividend92 2123 M [28CC] 28CC:E611 [ 3] lda ?temp+5,x 2123 M [28CE] 28CE:E71E [ 3] sta dividend92+5,spx 2123 M mloop ::dividend92 2123 endm 2124 M @lsr.s ?remainder,x ; remainder := remainder shr 1 2124 M mset # 2124 M mreq 1 2124 M @@_nosize_ ?remainder,x 2124 M mset # 2124 M mset 0,mstop [lsr.s] No size (?remainder,x) 2124 M endm 2124 M mdo 2124 M [28D0] 28D0:6406 [ 5] lsr ?remainder+0,x 2124 M mloop ::?remainder 2124 M [28D2] 28D2:6607 [ 5] ror ?remainder+1,x 2124 M mloop ::?remainder 2124 M [28D4] 28D4:6608 [ 5] ror ?remainder+2,x 2124 M mloop ::?remainder 2124 M [28D6] 28D6:6609 [ 5] ror ?remainder+3,x 2124 M mloop ::?remainder 2124 M [28D8] 28D8:660A [ 5] ror ?remainder+4,x 2124 M mloop ::?remainder 2124 M [28DA] 28DA:660B [ 5] ror ?remainder+5,x 2124 M mloop ::?remainder 2124 endm 2125 [28DC] 28DC:6C12 [ 5] inc ?bits,x ; bits := bits + 1 2126 2127 ; for i := bitCounter-1 downto 0 do 2128 2129 M For@@ @cop ;in case of many iterations 2129 M [28DE] 28DE:C718 00 [ 4] sta COP 2129 endm 2130 2131 [28E1] 28E1:6D12 [ 4] tst ?bits,x 2133 [28E3] 28E3:276F (2954) [ 3] beq Done@@ 2137 [28E5] 28E5:6A12 [ 5] dec ?bits,x 2138 2139 ; remainder := (remainder shl 1) or msb(dividend) 2140 ; dividend := dividend shl 1 2141 2142 M @lsl.s dividend@@,spx ;2012.12.04 optimization 2142 M mset # 2142 M mreq 1 2142 M @@_nosize_ dividend92,spx 2142 M mset # 2142 M mset 0,mstop [lsl.s] No size (dividend92,spx) 2142 M endm 2142 M mdo 2142 M [28E7] 28E7:681E [ 5] lsl dividend92+5,spx 2142 M mloop ::dividend92 2142 M [28E9] 28E9:691D [ 5] rol dividend92+4,spx 2142 M mloop ::dividend92 2142 M [28EB] 28EB:691C [ 5] rol dividend92+3,spx 2142 M mloop ::dividend92 2142 M [28ED] 28ED:691B [ 5] rol dividend92+2,spx 2142 M mloop ::dividend92 2142 M [28EF] 28EF:691A [ 5] rol dividend92+1,spx 2142 M mloop ::dividend92 2142 M [28F1] 28F1:6919 [ 5] rol dividend92+0,spx 2142 M mloop ::dividend92 2142 endm 2143 M @rol.s ?remainder,x 2143 M mset # 2143 M mreq 1 2143 M @@_nosize_ ?remainder,x 2143 M mset # 2143 M mset 0,mstop [rol.s] No size (?remainder,x) 2143 M endm 2143 M mdo 2143 M [28F3] 28F3:690B [ 5] rol ?remainder+5,x 2143 M mloop ::?remainder 2143 M [28F5] 28F5:690A [ 5] rol ?remainder+4,x 2143 M mloop ::?remainder 2143 M [28F7] 28F7:6909 [ 5] rol ?remainder+3,x 2143 M mloop ::?remainder 2143 M [28F9] 28F9:6908 [ 5] rol ?remainder+2,x 2143 M mloop ::?remainder 2143 M [28FB] 28FB:6907 [ 5] rol ?remainder+1,x 2143 M mloop ::?remainder 2143 M [28FD] 28FD:6906 [ 5] rol ?remainder+0,x 2143 M mloop ::?remainder 2143 endm 2144 2145 ; temp := remainder - divisor 2146 2147 M @sub.s ?remainder,x divisor@@,spx ?temp,x 2147 M mset #' ' 2147 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2147 M @@_samesize_ ?remainder,x divisor92,spx ?temp,x 2147 M mreq 1,2:Operand1,Operand2[,Operand]* 2147 M mset 0 2147 M mdo 2147 M mswap 1,1 2147 M @@_nosize_ ?remainder,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?remainder,x) 2147 M endm 2147 M mset 0,?remainder,x 2147 M mloop :n 2147 M mswap 1,2 2147 M @@_nosize_ divisor92,spx 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (divisor92,spx) 2147 M endm 2147 M mloop :n 2147 M mswap 1,3 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?temp,x) 2147 M endm 2147 M mloop :n 2147 M endm 2147 M #temp 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [sub.s] No size (?temp,x) 2147 M endm 2147 M #temp ::?temp 2147 M mset 0,sub 2147 M mdo 2147 M [28FF] 28FF:E60B [ 3] lda ?remainder+5,x 2147 M [2901] 2901:E024 [ 3] sub divisor92+5,spx 2147 M [2903] 2903:E711 [ 3] sta ?temp+5,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2905] 2905:E60A [ 3] lda ?remainder+4,x 2147 M [2907] 2907:E223 [ 3] sbc divisor92+4,spx 2147 M [2909] 2909:E710 [ 3] sta ?temp+4,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [290B] 290B:E609 [ 3] lda ?remainder+3,x 2147 M [290D] 290D:E222 [ 3] sbc divisor92+3,spx 2147 M [290F] 290F:E70F [ 3] sta ?temp+3,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2911] 2911:E608 [ 3] lda ?remainder+2,x 2147 M [2913] 2913:E221 [ 3] sbc divisor92+2,spx 2147 M [2915] 2915:E70E [ 3] sta ?temp+2,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2917] 2917:E607 [ 3] lda ?remainder+1,x 2147 M [2919] 2919:E220 [ 3] sbc divisor92+1,spx 2147 M [291B] 291B:E70D [ 3] sta ?temp+1,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [291D] 291D:E606 [ 3] lda ?remainder+0,x 2147 M [291F] 291F:E21F [ 3] sbc divisor92+0,spx 2147 M [2921] 2921:E70C [ 3] sta ?temp+0,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 endm 2148 2149 ; q := not msb(temp) 2150 2151 [2923] 2923:E60C [ 3] lda ?temp,x 2152 [2925] 2925:A880 [ 2] eor #%10000000 ;invert msb 2153 [2927] 2927:A480 [ 2] and #%10000000 ;isolate msb 2154 2155 ; quotient := (quotient shl 1) or q 2156 2157 [2929] 2929:87 [ 2] psha 2158 [292A] 292A:48 [ 1] lsla 2159 [292B] 292B:86 [ 3] pula 2160 2161 M @rol.s ?quotient,x 2161 M mset # 2161 M mreq 1 2161 M @@_nosize_ ?quotient,x 2161 M mset # 2161 M mset 0,mstop [rol.s] No size (?quotient,x) 2161 M endm 2161 M mdo 2161 M [292C] 292C:6905 [ 5] rol ?quotient+5,x 2161 M mloop ::?quotient 2161 M [292E] 292E:6904 [ 5] rol ?quotient+4,x 2161 M mloop ::?quotient 2161 M [2930] 2930:6903 [ 5] rol ?quotient+3,x 2161 M mloop ::?quotient 2161 M [2932] 2932:6902 [ 5] rol ?quotient+2,x 2161 M mloop ::?quotient 2161 M [2934] 2934:6901 [ 5] rol ?quotient+1,x 2161 M mloop ::?quotient 2161 M [2936] 2936:79 [ 4] rol ?quotient+0,x 2161 M mloop ::?quotient 2161 endm 2162 2163 ; if q <> 0 then 2164 2165 [2937] 2937:4100 A4(28DE) [ 4] cbeqa #0,For@@ 2166 2167 ; remainder := temp 2168 2169 M @mova.s ?temp,x ?remainder,x 2169 M mset #' ' 2169 M mreq 1,2:Source Destination 2169 M @@_samesize_ ?temp,x ?remainder,x 2169 M mreq 1,2:Operand1,Operand2[,Operand]* 2169 M mset 0 2169 M mdo 2169 M mswap 1,1 2169 M @@_nosize_ ?temp,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?temp,x) 2169 M endm 2169 M mset 0,?temp,x 2169 M mloop :n 2169 M mswap 1,2 2169 M @@_nosize_ ?remainder,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?remainder,x) 2169 M endm 2169 M mloop :n 2169 M endm 2169 M mset 0 2169 M mdo 2169 M [293A] 293A:E60C [ 3] lda ?temp+0,x 2169 M [293C] 293C:E706 [ 3] sta ?remainder+0,x 2169 M mloop ::?remainder 2169 M [293E] 293E:E60D [ 3] lda ?temp+1,x 2169 M [2940] 2940:E707 [ 3] sta ?remainder+1,x 2169 M mloop ::?remainder 2169 M [2942] 2942:E60E [ 3] lda ?temp+2,x 2169 M [2944] 2944:E708 [ 3] sta ?remainder+2,x 2169 M mloop ::?remainder 2169 M [2946] 2946:E60F [ 3] lda ?temp+3,x 2169 M [2948] 2948:E709 [ 3] sta ?remainder+3,x 2169 M mloop ::?remainder 2169 M [294A] 294A:E610 [ 3] lda ?temp+4,x 2169 M [294C] 294C:E70A [ 3] sta ?remainder+4,x 2169 M mloop ::?remainder 2169 M [294E] 294E:E611 [ 3] lda ?temp+5,x 2169 M [2950] 2950:E70B [ 3] sta ?remainder+5,x 2169 M mloop ::?remainder 2169 endm 2170 2171 ; end if -- end for 2172 2174 [2952] 2952:208A (28DE) [ 3] bra For@@ 2178 2179 [2954] 2954:E613 [ 3] Done@@ lda ?flags,x 2180 [2956] 2956:A501 [ 2] bit #?DIVOP_ 2181 [2958] 2958:2719 (2973) [ 3] beq ExitMod@@ 2182 2183 0341 ?Cycles equ :cycles 2184 2185 ;ExitDiv@@ 2186 M @mova.s ?quotient,x ans@@,spx 2186 M mset #' ' 2186 M mreq 1,2:Source Destination 2186 M @@_samesize_ ?quotient,x ans92,spx 2186 M mreq 1,2:Operand1,Operand2[,Operand]* 2186 M mset 0 2186 M mdo 2186 M mswap 1,1 2186 M @@_nosize_ ?quotient,x 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (?quotient,x) 2186 M endm 2186 M mset 0,?quotient,x 2186 M mloop :n 2186 M mswap 1,2 2186 M @@_nosize_ ans92,spx 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (ans92,spx) 2186 M endm 2186 M mloop :n 2186 M endm 2186 M mset 0 2186 M mdo 2186 M [295A] 295A:F6 [ 3] lda ?quotient+0,x 2186 M [295B] 295B:E71F [ 3] sta ans92+0,spx 2186 M mloop ::ans92 2186 M [295D] 295D:E601 [ 3] lda ?quotient+1,x 2186 M [295F] 295F:E720 [ 3] sta ans92+1,spx 2186 M mloop ::ans92 2186 M [2961] 2961:E602 [ 3] lda ?quotient+2,x 2186 M [2963] 2963:E721 [ 3] sta ans92+2,spx 2186 M mloop ::ans92 2186 M [2965] 2965:E603 [ 3] lda ?quotient+3,x 2186 M [2967] 2967:E722 [ 3] sta ans92+3,spx 2186 M mloop ::ans92 2186 M [2969] 2969:E604 [ 3] lda ?quotient+4,x 2186 M [296B] 296B:E723 [ 3] sta ans92+4,spx 2186 M mloop ::ans92 2186 M [296D] 296D:E605 [ 3] lda ?quotient+5,x 2186 M [296F] 296F:E724 [ 3] sta ans92+5,spx 2186 M mloop ::ans92 2186 endm 2187 [2971] 2971:2018 (298B) [ 3] bra ExitBoth@@ 2188 2189 0387 ?DivCycles set ?DivCycles+?Cycles+:cycles 2190 2191 M ExitMod@@ @mova.s ?remainder,x ans@@,spx 2191 M mset #' ' 2191 M mreq 1,2:Source Destination 2191 M @@_samesize_ ?remainder,x ans92,spx 2191 M mreq 1,2:Operand1,Operand2[,Operand]* 2191 M mset 0 2191 M mdo 2191 M mswap 1,1 2191 M @@_nosize_ ?remainder,x 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (?remainder,x) 2191 M endm 2191 M mset 0,?remainder,x 2191 M mloop :n 2191 M mswap 1,2 2191 M @@_nosize_ ans92,spx 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (ans92,spx) 2191 M endm 2191 M mloop :n 2191 M endm 2191 M mset 0 2191 M mdo 2191 M [2973] 2973:E606 [ 3] lda ?remainder+0,x 2191 M [2975] 2975:E71F [ 3] sta ans92+0,spx 2191 M mloop ::ans92 2191 M [2977] 2977:E607 [ 3] lda ?remainder+1,x 2191 M [2979] 2979:E720 [ 3] sta ans92+1,spx 2191 M mloop ::ans92 2191 M [297B] 297B:E608 [ 3] lda ?remainder+2,x 2191 M [297D] 297D:E721 [ 3] sta ans92+2,spx 2191 M mloop ::ans92 2191 M [297F] 297F:E609 [ 3] lda ?remainder+3,x 2191 M [2981] 2981:E722 [ 3] sta ans92+3,spx 2191 M mloop ::ans92 2191 M [2983] 2983:E60A [ 3] lda ?remainder+4,x 2191 M [2985] 2985:E723 [ 3] sta ans92+4,spx 2191 M mloop ::ans92 2191 M [2987] 2987:E60B [ 3] lda ?remainder+5,x 2191 M [2989] 2989:E724 [ 3] sta ans92+5,spx 2191 M mloop ::ans92 2191 endm 2192 2193 037B ?ModCycles set ?ModCycles+?Cycles+:cycles 2194 2195 298B ExitBoth@@ 2197 [298B] 298B:6D13 [ 4] tst ?flags,x 2198 [298D] 298D:2A06 (2995) [ 3] bpl SkipSign@@ 2199 M @lea ans@@,sp 2199 M mset # 2199 M [298F] 298F:95 [ 2] tsx 2199 M [2990] 2990:AF1F [ 2] !aix #ans92+:tsx 2199 mexit 2200 [2992] 2992:CD27 B6 [ 6] jsr ?NegX 2201 2995 SkipSign@@ 2202 #Cycles ?NegxCycles+:cycles 2204 [2995] 2995:A714 [ 2] ais #?SF ;de-allocate temporaries 2205 [2997] 2997:98 [ 1] clc ;no error(s) 2206 ; bra ?RemoveAndReturn 2207 2208 0058 ?Cycles set :cycles 2209 03DF ?DivCycles set ?DivCycles+?Cycles 2210 03D3 ?ModCycles set ?ModCycles+?Cycles 2211 2212 ;******************************************************************************* 2213 ; Common exit removes lower 32-bit stack element and returns to caller 2214 ;******************************************************************************* 2215 2216 2998 ?RemoveAndReturn proc 2218 [2998] 2998:9EFE 04 [ 5] ldhx ?pc,sp ;our return address moved up 2219 [299B] 299B:9EFF 0A [ 5] sthx ?pc+?WORD,sp ;above word to remove 2229 [299E] 299E:8A88 86 [ 9] pull 2230 [29A1] 29A1:A706 [ 2] ais #?WORD ;remove top-of-stack ?WORD 2231 [29A3] 29A3:81 [ 6] rtc 2232 2233 001B ?ReturnCycles equ :cycles 2234 2235 ;******************************************************************************* 2236 ; Purpose: Swaps the stacked order of N1 and N2 2237 ; Input : [TOS+?WORD] = Number2 2238 ; : [TOS] = Number1 2239 ; Output : [TOS+?WORD] = Number1 -- TOS & [TOS+?WORD] in reverse order 2240 ; : [TOS] = Number2 2241 ; Note(s): Does not alter stack size 2242 2243 #spauto :ab 2244 2245 29A4 ?Swap proc 2246 [29A4] 29A4:8789 8B [ 6] push 2247 2248 [29A7] 29A7:A606 [ 2] lda #?WORD 2249 [29A9] 29A9:87 [ 2] psha bytes@@ 2250 2251 [29AA] 29AA:95 [ 2] tsx 2252 #temp :cycles 2253 M Loop@@ @_swap_, ?a,spx ?b,spx ;swap A with B ... 2253 M mset #' ' 2253 M #push 2253 M #spauto :sp 2253 M [29AB] 29AB:E606 [ 3] lda ?a,spx 2253 M [29AD] 29AD:87 [ 2] psha 2253 M [29AE] 29AE:E60C [ 3] lda ?b,spx 2253 M [29B0] 29B0:E706 [ 3] sta ?a,spx 2253 M [29B2] 29B2:86 [ 3] pula 2253 M [29B3] 29B3:E70C [ 3] sta ?b,spx 2253 M #pull 2253 endm 2254 2255 [29B5] 29B5:AF01 [ 2] aix #1 ;point to next byte 2256 [29B7] 29B7:9E6B 01F0 (29AB [ 8] dbnz bytes@@,sp,Loop@@ ;repeat for all bytes 2257 #temp :cycles*?WORD+:temp 2258 [29BB] 29BB:86 [ 3] pula 2259 2260 [29BC] 29BC:8A88 86 [ 9] pull 2261 [29BF] 29BF:81 [ 6] rtc 2262 2263 00C0 ?SwapCycles set :cycles+:temp 2264 2265 ;******************************************************************************* 2266 ; Purpose: Get the absolute value of the top-of-stack number 2267 ; Input : [TOS] = Number 2268 ; Output : [TOS] = Abs(Number) 2269 ; Note(s): Does not alter stack size 2270 2271 #spauto :ab 2272 2273 29C0 ?Abs proc 2274 [29C0] 29C0:9E6D 03 [ 5] tst ?a,sp 2275 [29C3] 29C3:2AFA (29BF) [ 3] bpl Done@@ 2276 ; bra ?Negate 2277 2278 29BF Done@@ equ :AnRTC 2279 2280 0008 ?AbsCycles equ :cycles 2281 2282 ;******************************************************************************* 2283 ; Purpose: Negate the top-of-stack number 2284 ; Input : [TOS] = Number 2285 ; Output : [TOS] = -Number 2286 ; Note(s): Does not alter stack size 2287 2288 #spauto :ab 2289 2290 29C5 ?Negate proc 2291 [29C5] 29C5:898B [ 4] pshhx 2293 M @lea ?a,sp 2293 M mset # 2293 M [29C7] 29C7:95 [ 2] tsx 2293 M [29C8] 29C8:AF04 [ 2] !aix #?a+:tsx 2293 mexit 2294 [29CA] 29CA:CD27 B6 [ 6] jsr ?NegX 2295 #Cycles ?NegxCycles+:cycles 2300 [29CD] 29CD:8A88 [ 6] pulhx 2301 [29CF] 29CF:81 [ 6] rtc 2302 2303 005E ?NegateCycles equ :cycles 2304 0066 ?AbsCycles set ?NegateCycles+?AbsCycles 2305 2306 ;******************************************************************************* 2307 ; Purpose: Create a new top-of-stack and load to it the number pointed to by HX 2308 ; Input : HX -> [Variable with] Number 2309 ; Output : [TOS] = Number 2310 ; Note(s): This operation makes it easier to load a number to the stack. 2311 ; : Hint: To make a copy of the TOS, do: 2312 ; : tsx 2313 ; : call StackLoad32 2314 ; : (Stack is expanded) 2315 2316 #spauto :ab 2317 2318 29D0 ?Load proc 2319 FFFFFFFF old_rts@@ equ ::,:ab 2320 [29D0] 29D0:A7FA [ 2] ais #-?WORD ;allocate new TOS memory 2321 #temp :: 2322 FFFFFFF9 new_rts@@ next :temp,:ab 2323 FFFFFFFB tos_num@@ next :temp,?WORD 2324 0001 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2325 #ais :temp 2326 2327 [29D2] 29D2:87 [ 2] psha 2328 M @mova.s old_rts@@,sp new_rts@@,sp ;move RTS/RTC after new memory 2328 M mset #' ' 2328 M mreq 1,2:Source Destination 2328 M @@_samesize_ old_rts97,sp new_rts@@,sp 2328 M mreq 1,2:Operand1,Operand2[,Operand]* 2328 M mset 0 2328 M mdo 2328 M mswap 1,1 2328 M @@_nosize_ old_rts97,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (old_rts97,sp) 2328 M endm 2328 M mset 0,old_rts97,sp 2328 M mloop :n 2328 M mswap 1,2 2328 M @@_nosize_ new_rts@@,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (new_rts97,sp) 2328 M endm 2328 M mloop :n 2328 M endm 2328 M mset 0 2328 M mdo 2328 M [29D3] 29D3:9EE6 08 [ 4] lda old_rts97+0,sp 2328 M [29D6] 29D6:9EE7 02 [ 4] sta new_rts@@+0,sp 2328 M mloop ::new_rts@@ 2328 M [29D9] 29D9:9EE6 09 [ 4] lda old_rts97+1,sp 2328 M [29DC] 29DC:9EE7 03 [ 4] sta new_rts@@+1,sp 2328 M mloop ::new_rts@@ 2328 endm 2329 M @mova.s ,x tos_num@@,sp 2329 M mset #' ' 2329 M mreq 1,2:Source Destination 2329 M @@_samesize_ ,x tos_num97,sp 2329 M mreq 1,2:Operand1,Operand2[,Operand]* 2329 M mset 0 2329 M mdo 2329 M mswap 1,1 2329 M mloop :n 2329 M mswap 1,2 2329 M @@_nosize_ tos_num97,sp 2329 M mset # 2329 M mset 0,mstop [_samesize_] No size (tos_num97,sp) 2329 M endm 2329 M mset 0,tos_num97,sp 2329 M mloop :n 2329 M endm 2329 M mset 0 2329 M mdo 2329 M [29DF] 29DF:F6 [ 3] lda +0,x 2329 M [29E0] 29E0:9EE7 04 [ 4] sta tos_num97+0,sp 2329 M mloop ::tos_num97 2329 M [29E3] 29E3:E601 [ 3] lda +1,x 2329 M [29E5] 29E5:9EE7 05 [ 4] sta tos_num97+1,sp 2329 M mloop ::tos_num97 2329 M [29E8] 29E8:E602 [ 3] lda +2,x 2329 M [29EA] 29EA:9EE7 06 [ 4] sta tos_num97+2,sp 2329 M mloop ::tos_num97 2329 M [29ED] 29ED:E603 [ 3] lda +3,x 2329 M [29EF] 29EF:9EE7 07 [ 4] sta tos_num97+3,sp 2329 M mloop ::tos_num97 2329 M [29F2] 29F2:E604 [ 3] lda +4,x 2329 M [29F4] 29F4:9EE7 08 [ 4] sta tos_num97+4,sp 2329 M mloop ::tos_num97 2329 M [29F7] 29F7:E605 [ 3] lda +5,x 2329 M [29F9] 29F9:9EE7 09 [ 4] sta tos_num97+5,sp 2329 M mloop ::tos_num97 2329 endm 2330 [29FC] 29FC:86 [ 3] pula 2331 [29FD] 29FD:81 [ 6] rtc 2332 2333 0047 ?LoadCycles equ :cycles 2334 2335 ;******************************************************************************* 2336 ; Purpose: Unload the top-of-stack number into a variable pointed to by HX 2337 ; Input : [TOS] = Number 2338 ; : HX -> Some 32-bit variable 2339 ; Output : Variable pointed to by HX receives TOS number 2340 ; Note(s): This operation makes it easier to unload a number from the stack. 2341 ; : Use: 2342 ; : ldhx #MyVar 2343 ; : call StackSave32 2344 ; : (Stack is reduced) 2345 2346 #spauto :ab 2347 2348 29FE ?Save proc 2349 #temp :: 2350 FFFFFFFF old_rts@@ next :temp,:ab 2351 0001 tos_num@@ next :temp,?WORD 2352 0007 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2353 0005 new_rts@@ next :temp,:ab 2354 2355 0000 var@@ equ 0,?WORD 2356 2357 [29FE] 29FE:8789 8B [ 6] push 2358 M @mova.s tos_num@@,sp var@@,x 2358 M mset #' ' 2358 M mreq 1,2:Source Destination 2358 M @@_samesize_ tos_num98,sp var@@,x 2358 M mreq 1,2:Operand1,Operand2[,Operand]* 2358 M mset 0 2358 M mdo 2358 M mswap 1,1 2358 M @@_nosize_ tos_num98,sp 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (tos_num98,sp) 2358 M endm 2358 M mset 0,tos_num98,sp 2358 M mloop :n 2358 M mswap 1,2 2358 M @@_nosize_ var@@,x 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (var98,x) 2358 M endm 2358 M mloop :n 2358 M endm 2358 M mset 0 2358 M mdo 2358 M [2A01] 2A01:9EE6 06 [ 4] lda tos_num98+0,sp 2358 M [2A04] 2A04:F7 [ 2] sta var@@+0,x 2358 M mloop ::var@@ 2358 M [2A05] 2A05:9EE6 07 [ 4] lda tos_num98+1,sp 2358 M [2A08] 2A08:E701 [ 3] sta var@@+1,x 2358 M mloop ::var@@ 2358 M [2A0A] 2A0A:9EE6 08 [ 4] lda tos_num98+2,sp 2358 M [2A0D] 2A0D:E702 [ 3] sta var@@+2,x 2358 M mloop ::var@@ 2358 M [2A0F] 2A0F:9EE6 09 [ 4] lda tos_num98+3,sp 2358 M [2A12] 2A12:E703 [ 3] sta var@@+3,x 2358 M mloop ::var@@ 2358 M [2A14] 2A14:9EE6 0A [ 4] lda tos_num98+4,sp 2358 M [2A17] 2A17:E704 [ 3] sta var@@+4,x 2358 M mloop ::var@@ 2358 M [2A19] 2A19:9EE6 0B [ 4] lda tos_num98+5,sp 2358 M [2A1C] 2A1C:E705 [ 3] sta var@@+5,x 2358 M mloop ::var@@ 2358 endm 2359 2360 [2A1E] 2A1E:95 [ 2] tsx 2361 M @mova.s old_rts@@,spx new_rts@@,spx ;move RTS/RTC before old memory 2361 M mset #' ' 2361 M mreq 1,2:Source Destination 2361 M @@_samesize_ old_rts98,spx new_rts@@,spx 2361 M mreq 1,2:Operand1,Operand2[,Operand]* 2361 M mset 0 2361 M mdo 2361 M mswap 1,1 2361 M @@_nosize_ old_rts98,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (old_rts98,spx) 2361 M endm 2361 M mset 0,old_rts98,spx 2361 M mloop :n 2361 M mswap 1,2 2361 M @@_nosize_ new_rts@@,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (new_rts98,spx) 2361 M endm 2361 M mloop :n 2361 M endm 2361 M mset 0 2361 M mdo 2361 M [2A1F] 2A1F:E603 [ 3] lda old_rts98+0,spx 2361 M [2A21] 2A21:E709 [ 3] sta new_rts@@+0,spx 2361 M mloop ::new_rts@@ 2361 M [2A23] 2A23:E604 [ 3] lda old_rts98+1,spx 2361 M [2A25] 2A25:E70A [ 3] sta new_rts@@+1,spx 2361 M mloop ::new_rts@@ 2361 endm 2362 [2A27] 2A27:8A88 86 [ 9] pull 2363 2364 [2A2A] 2A2A:A706 [ 2] ais #?WORD ;de-allocate TOS memory 2365 [2A2C] 2A2C:81 [ 6] rtc 2366 2367 004E ?SaveCycles equ :cycles 2368 2369 ;******************************************************************************* 2370 ; Purpose: Adjust TOS old size to new 2371 ; Input : H = old (current) byte size 2372 ; : X = new byte size 2373 ; : CCR[C] = 0 -- always positive number 2374 ; : CCR[C] = 1 -- sign extend 2375 ; Output : None 2376 ; Note(s): RegA deliberately not used for parameter passing (for consistency) 2377 ; : Macro destroys RegHX (as we must not use PSHHX/PULHX around call) 2378 2504 2505 ;******************************************************************************* 2506 ; Purpose: Convert 32-bit to ASCIZ string 2507 ; Input : Stack: 32-bit number 2508 ; : HX -> Output buffer with enough space to keep the ASCIZ string result 2509 ; Output : None 2510 ; Note(s): Use: 2511 ; : ldhx #Buffer 2512 ; : call Stack32ToASCIZ 2513 2514 #spauto :ab ;account for RTS/RTC 2515 2516 2A2D ?ToStr proc 2517 [2A2D] 2A2D:8789 8B [ 6] push 2518 #ais ;mark beginning of temporaries 2519 2520 [2A30] 2A30:898B [ 4] pshhx .buffer@@ ;working copy of pointer to buffer 2521 [2A32] 2A32:7F [ 4] clr ,x ;make it an ASCIZ string 2522 2523 M @lea 1,sp ;HX -> TOS number of caller 2523 M mset # 2523 M [2A33] 2A33:95 [ 2] tsx 2523 M [2A34] 2A34:AF07 [ 2] !aix #1+:tsx 2523 mexit 2524 [2A36] 2A36:CD29 D0 [ 6] call ?Load ;load a working copy on stack 2525 2526 #spadd ?WORD ;stack has grown by a ?WORD 2527 FFFFFFF4 number@@ equ ::,?WORD 2529 [2A39] 2A39:9E6D 01 [ 5] tst number@@,sp 2530 [2A3C] 2A3C:2A0F (2A4D) [ 3] bpl ToStrLoop@@ 2531 [2A3E] 2A3E:CD29 C5 [ 6] call ?Negate 2533 [2A41] 2A41:9EFE 07 [ 5] ldhx .buffer@@,sp 2540 [2A44] 2A44:A62D [ 2] lda #'-' ;a 'minus' sign 2541 [2A46] 2A46:F7 [ 2] sta ,x ; is saved first 2542 2543 [2A47] 2A47:AF01 [ 2] aix #1 ;HX -> past minus sign 2544 [2A49] 2A49:7F [ 4] clr ,x ;make it an ASCIZ string 2546 [2A4A] 2A4A:9EFF 07 [ 5] sthx .buffer@@,sp ;update pointer past sign 2552 ; bra ToStrLoop@@ 2554 ;=============================================================================== 2555 2556 [2A4D] 2A4D:4500 0A [ 3] ToStrLoop@@ ldhx #10 ;H = 0 (always), X = divisor 2557 M @div.s number@@,sp 2557 M mset # 2557 M mreq 1 2557 M @@_not_x_ number99,sp 2557 M mset #' ' 2557 M mdel 1 2557 M mtop 2557 M mset #' ' 2557 M mexit 2557 M @@_nosize_ number99,sp 2557 M mset # 2557 M mset 0,mstop [div.s] No size (number99,sp) 2557 M endm 2557 M #temp 1 2557 M #temp 2 2557 M [2A50] 2A50:86 [ 3] pula 2557 M [2A51] 2A51:52 [ 6] div 2557 M [2A52] 2A52:87 [ 2] psha 2557 M mdo 2 2557 M [2A53] 2A53:9EE6 02 [ 4] lda number99+1,sp 2557 M [2A56] 2A56:52 [ 6] div 2557 M [2A57] 2A57:9EE7 02 [ 4] sta number99+1,sp 2557 M mloop ::number99 2557 M [2A5A] 2A5A:9EE6 03 [ 4] lda number99+2,sp 2557 M [2A5D] 2A5D:52 [ 6] div 2557 M [2A5E] 2A5E:9EE7 03 [ 4] sta number99+2,sp 2557 M mloop ::number99 2557 M [2A61] 2A61:9EE6 04 [ 4] lda number99+3,sp 2557 M [2A64] 2A64:52 [ 6] div 2557 M [2A65] 2A65:9EE7 04 [ 4] sta number99+3,sp 2557 M mloop ::number99 2557 M [2A68] 2A68:9EE6 05 [ 4] lda number99+4,sp 2557 M [2A6B] 2A6B:52 [ 6] div 2557 M [2A6C] 2A6C:9EE7 05 [ 4] sta number99+4,sp 2557 M mloop ::number99 2557 M [2A6F] 2A6F:9EE6 06 [ 4] lda number99+5,sp 2557 M [2A72] 2A72:52 [ 6] div 2557 M [2A73] 2A73:9EE7 06 [ 4] sta number99+5,sp 2557 M mloop ::number99 2557 endm 2558 2559 [2A76] 2A76:8B86 [ 5] tha ;A = remainder 2560 [2A78] 2A78:AB30 [ 2] add #'0' ;A = ASCII remainder 2562 [2A7A] 2A7A:9EFE 07 [ 5] ldhx .buffer@@,sp 2568 M @StringInsertChar 2568 M [2A7D] 2A7D:CD18 3A [ 6] call StringInsertChar ;HX and A pre-loaded correctly 2568 mexit 2569 2570 [2A80] 2A80:95 [ 2] tsx 2571 2572 M @_tst_.s number@@,spx 2572 M mset # 2572 M mreq 1 2572 M @@_nosize_ number99,spx 2572 M mset # 2572 M mset 0,mstop [_tst_.s] No size (number99,spx) 2572 M endm 2572 M mdo 2572 M [2A81] 2A81:F6 [ 3] lda number99+0,spx 2572 M mloop ::number99 2572 M [2A82] 2A82:EA01 [ 3] ora number99+1,spx 2572 M mloop ::number99 2572 M [2A84] 2A84:EA02 [ 3] ora number99+2,spx 2572 M mloop ::number99 2572 M [2A86] 2A86:EA03 [ 3] ora number99+3,spx 2572 M mloop ::number99 2572 M [2A88] 2A88:EA04 [ 3] ora number99+4,spx 2572 M mloop ::number99 2572 M [2A8A] 2A8A:EA05 [ 3] ora number99+5,spx 2572 M mloop ::number99 2572 endm 2573 [2A8C] 2A8C:26BF (2A4D) [ 3] bne ToStrLoop@@ 2574 2575 [2A8E] 2A8E:A708 [ 2] ais #:ais ;free temporaries 2576 [2A90] 2A90:8A88 86 [ 9] pull 2577 [2A93] 2A93:81 [ 6] rtc 2578 2579 #sp ;cancel all SP offsets 2580 2581 ;******************************************************************************* 2582 ; Assign global names to the various library calls, depending on version used. 2583 ; Different names for each version means you can include any at the same time. 2584 ;******************************************************************************* 2585 2586 ? macro BitSize ;temp macro to export symbols 2587 mreq 1:Usage: @~0~ BitSize 2588 #if MATHSIZE = ~1~ 2589 StackAdd~1~ exp ?Add 2590 StackSub~1~ exp ?Subtract 2591 StackMul~1~ exp ?Multiply 2592 StackDiv~1~ exp ?Divide 2593 StackMod~1~ exp ?Modulo 2594 StackSwap~1~ exp ?Swap 2595 StackAbs~1~ exp ?Abs 2596 StackNegate~1~ exp ?Negate 2597 StackLoad~1~ exp ?Load 2598 StackSave~1~ exp ?Save 2599 Stack~1~ToASCIZ exp ?ToStr 2600 #ifdef NO_BIT_OPS 2601 mexit ;;bit operations not available 2602 #endif 2603 StackAnd~1~ exp ?BitAnd 2604 StackOr~1~ exp ?BitOr 2605 StackXor~1~ exp ?BitXor 2606 StackShl~1~ exp ?ShiftLeft 2607 StackShr~1~ exp ?ShiftRight 2608 #endif 2609 endm 2610 2611 M @? 64 ;export 64-bit labels 2611 M mreq 1:Usage: @? BitSize 2611 endm 2612 M @? 56 ;export 56-bit labels 2612 M mreq 1:Usage: @? BitSize 2612 endm 2613 M @? 48 ;export 48-bit labels 2613 M mreq 1:Usage: @? BitSize 2613 M 262C StackAdd48 exp ?Add 2613 M 2642 StackSub48 exp ?Subtract 2613 M 2739 StackMul48 exp ?Multiply 2613 M 2792 StackDiv48 exp ?Divide 2613 M 27A5 StackMod48 exp ?Modulo 2613 M 29A4 StackSwap48 exp ?Swap 2613 M 29C0 StackAbs48 exp ?Abs 2613 M 29C5 StackNegate48 exp ?Negate 2613 M 29D0 StackLoad48 exp ?Load 2613 M 29FE StackSave48 exp ?Save 2613 M 2A2D Stack48ToASCIZ exp ?ToStr 2613 M 2658 StackAnd48 exp ?BitAnd 2613 M 266D StackOr48 exp ?BitOr 2613 M 2682 StackXor48 exp ?BitXor 2613 M 2697 StackShl48 exp ?ShiftLeft 2613 M 26E8 StackShr48 exp ?ShiftRight 2613 endm 2614 M @? 40 ;export 40-bit labels 2614 M mreq 1:Usage: @? BitSize 2614 endm 2615 M @? 32 ;export 32-bit labels 2615 M mreq 1:Usage: @? BitSize 2615 endm 2616 M @? 24 ;export 24-bit labels 2616 M mreq 1:Usage: @? BitSize 2616 endm 2617 M @? 16 ;export 16-bit labels 2617 M mreq 1:Usage: @? BitSize 2617 endm 2618 2619 ;******************************************************************************* *** END INCLUDE FILE: lib/stakmath.sub *** (RESUMING FILE: lib/stkmth48.sub) 23 #Exit *** END INCLUDE FILE: lib/stkmth48.sub *** (RESUMING FILE: lib/demo/stakmath.asm) 53 M @? 56,7 53 M @@Page 7 53 M mreq 1:PageNumber 53 M endm 53 #Uses lib/stkmth56.sub *** BEGIN INCLUDE FILE: lib/stkmth56.sub *** 1 ;******************************************************************************* 2 ;* Module : STKMTH56.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Wrapper for 56-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stkmth56.html 8 ;* Note(s) : See STAKMATH.SUB for details 9 ;******************************************************************************* 10 16 17 ? macro 18 mset 1,~BASENAME~ 19 MATHSIZE set ~1.{:1-1}~ 20 #Include stakmath.sub 21 endm 22 23 M @? 23 M mset 1,STKMTH56 23 M 0038 MATHSIZE set 56 23 #Include stakmath.sub *** BEGIN INCLUDE FILE: lib/stakmath.sub *** 1 ;******************************************************************************* 2 ;* Module : STAKMATH.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : 64/56/48/40/32/24/16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stakmath.html 8 ;* Note(s) : Use: #Include stakmath.sub 9 ;* : 10 ;* : Several externally defined macros are used throughout this code. 11 ;* : All these (and many more) macros are inside the most recent 12 ;* : version of MACROS.INC which can be copied from the web page at 13 ;* : http://www.aspisys.com/code/hc08/macros.html 14 ;* : (and COMMON.INC at http://www.aspisys.com/code/hc08/common.html) 15 ;* : 16 ;* : The default word size is 32-bit. 17 ;* : 18 ;* : By (re)defining the symbol MATHSIZE (to 16) you get 16-bit code. 19 ;* : By (re)defining the symbol MATHSIZE to 24 you get 24-bit code. 20 ;* : By (re)defining the symbol MATHSIZE to 40 you get 40-bit code. 21 ;* : By (re)defining the symbol MATHSIZE to 48 you get 48-bit code. 22 ;* : By (re)defining the symbol MATHSIZE to 56 you get 56-bit code. 23 ;* : By (re)defining the symbol MATHSIZE to 64 you get 64-bit code. 24 ;* : 25 ;* : You can include all (or some) versions in your program like so: 26 ;* : 27 ;* : #ROM ;(or else, some paged memory) 28 ;* : #Include stakmath.sub 29 ;* : MATHSIZE set 16 ;redefine for 16-bit use 30 ;* : #Include stakmath.sub 31 ;* : MATHSIZE set 24 ;redefine for 24-bit use 32 ;* : #Include stakmath.sub 33 ;* : MATHSIZE set 40 ;redefine for 40-bit use 34 ;* : #Include stakmath.sub 35 ;* : MATHSIZE set 48 ;redefine for 48-bit use 36 ;* : #Include stakmath.sub 37 ;* : MATHSIZE set 56 ;redefine for 56-bit use 38 ;* : #Include stakmath.sub 39 ;* : MATHSIZE set 64 ;redefine for 64-bit use 40 ;* : 41 ;* : or, if you use the related wrapper files, like so: 42 ;* : 43 ;* : #ROM ;(or else, some paged memory) 44 ;* : #Uses stkmth16.sub 45 ;* : #Uses stkmth24.sub 46 ;* : #Uses stkmth32.sub 47 ;* : #Uses stkmth40.sub 48 ;* : #Uses stkmth48.sub 49 ;* : #Uses stkmth56.sub 50 ;* : #Uses stkmth64.sub 51 ;* : 52 ;* : Use CALL if assembled in #MMU mode (regardless of placement). 53 ;* : By using CALL and #JUMP (or default -J+ command line option), the 54 ;* : assembler will automatically adjust between CALL and JSR 55 ;* : depending on the current #MMU mode. 56 ;* : 57 ;* : To use the *-bit version of each CALL, use these symbols: 58 ;* : 59 ;* : StackAdd*, StackSub*, StackMul*, StackDiv*, StackMod* 60 ;* : StackSwap*, StackNegate*, StackLoad*, StackSave*, 61 ;* : Stack*ToASCIZ 62 ;* : 63 ;* : replacing * with one of these: 16, 24, 32, 40, 48, 56, or 64. 64 ;* : 65 ;* : Various macros allow using these routines in a variety of ways, 66 ;* : and without worrying about the details of call & parameter setup. 67 ;* : These macros are: Add*, Sub*, Mul*, Div*, Mod*, DivS*, ModS*, 68 ;* : Neg*, Load*, Save*, Str*, StrS*, and Swap* (where the * is 16, 69 ;* : 24, 32, 40, 48, 56, or 64 depending on the version you want to use). 70 ;* : The signed versions are enabled only when the module is assembled 71 ;* : with the SIGNED conditional. 72 ;* : 73 ;* : If working with fixed-address variables, you can use the various 74 ;* : macros (such as Add32, Mul64, etc.) to perform operations in the 75 ;* : easiest possible way, such as: 76 ;* : @Mul32 A,B,Answer 77 ;* : (which multiplies A with B and stores the product in Answer). 78 ;* : But, you may also use the macros to work directly on stack, or to 79 ;* : temporarily save partial results on stack instead of fixed vars. 80 ;* : 81 ;* : I N G E N E R A L T H E N 82 ;* : 83 ;* : @Operation A,B,Answer works with A and B storing result in Answer 84 ;* : @Operation A,B works with A and B leaving result on stack 85 ;* : @Operation A works with TOS and A, result left as TOS 86 ;* : @Operation (no parms) works w/ TOS and [TOS+1], result as new TOS 87 ;* : 88 ;* : (Please note the shown order of the operation may be important.) 89 ;* : 90 ;* : Finally, the Load* (* = 16, 24, 32, 40, 48, 56, 64) operation can 91 ;* : directly load either a variable or a constant (leading #) on the 92 ;* : stack. 93 ;* : 94 ;* : Since v7.00, a HLL-like interface is possible by using the new 95 ;* : Eval* macro (where * = 8, 16, 24, 32, 40, 48, 56, 64) 96 ;* : This is by far the easiest way to use this library, as it closely 97 ;* : resembles using expressions in a HLL compiler. It also can 98 ;* : automatically resize stack after loading from and before saving 99 ;* : to any variable. 100 ;* : 101 ;* : Examine the test section of this file for examples of macro use. 102 ;* : 103 ;* : All routines are re-entrant and work on either the top-of-stack 104 ;* : (TOS) number alone or the two top-most TOS numbers. Similar to 105 ;* : how Reverse Polish Notation (RPN) works. First, you stack the 106 ;* : operand(s) and then call the corresponding routine to perform the 107 ;* : operation. 108 ;* : 109 ;* : The result of any operation is always the updated top of stack. 110 ;* : For operations that require two operands and produce a single 111 ;* : result, the result replaces the two operands (stack is reduced). 112 ;* : 113 ;* : Chain calculations are possible by pushing only the new operand 114 ;* : between operations. Alternatively, one can push all operands in 115 ;* : advance but it's not recommended as stack space may be limited. 116 ;* : When done evaluating an expression, just pull the final 32-bit 117 ;* : result from the stack. 118 ;* : 119 ;* : The TOS is the first (or only) operand of any operation. 120 ;* : This is important, for example, for subtraction and division. 121 ;* : 122 ;* : If the current order of the stack is not as you want it, use the 123 ;* : Swap (StackSwap32) operation to change it. 124 ;* : 125 ;* : All operands and results are exactly 32-bit wide. Overflows are 126 ;* : simply truncated. The lower 32-bit number is valid, though. 127 ;* : 128 ;* : (All references to 32-bit become 16-bit, when MATHSIZE = 16) 129 ;* : (All references to 32-bit become 24-bit, when MATHSIZE = 24) 130 ;* : (All references to 32-bit become 40-bit, when MATHSIZE = 40) 131 ;* : (All references to 32-bit become 48-bit, when MATHSIZE = 48) 132 ;* : (All references to 32-bit become 56-bit, when MATHSIZE = 56) 133 ;* : (All references to 32-bit become 64-bit, when MATHSIZE = 64) 134 ;* : 135 ;* : 64/56/48/40-bit multiplication is done using the shift-add method, 136 ;* : which is much shorter in size for such long operands, but it is 137 ;* : also significantly slower in speed. I opted for size optimization 138 ;* : because the 64/56/48/40-bit versions are not used quite as often. 139 ;* : You may want to re-write it for speed optimization by using the 140 ;* : MUL instruction like it is done for the default 32-bit case. 141 ;* : 142 ;* History : 09.05.22 v1.00 Original (Started on 2009.05.07) 143 ;* : 09.06.04 Optimized by using HX instead of SP, where needed 144 ;* : 09.11.04 Minor optimizations 145 ;* : 09.11.05 Add & Subtract now adjust Carry accordingly 146 ;* : Division by zero error now checked first 147 ;* : 09.11.06 v1.01 Added conditional MATHSIZE for use w/ 16-bit words 148 ;* : 09.11.08 v1.02 Added "Load" operation to ease stack loading 149 ;* : 09.11.11 Use of new LONG pseudo-opcode 150 ;* : 09.12.05 Added cycles display using :cycles 151 ;* : 10.01.06 v1.03 Added MMU auto-support (using :AB internal symbol) 152 ;* : Code is no longer placed in #ROM by default 153 ;* : The few JMPs in the code use [[ to trim possible page 154 ;* : 10.01.08 [[ removed from JMPs (latest ASM8 auto-correction) 155 ;* : 10.01.22 v1.04 Added Save operation for completeness 156 ;* : 10.01.23 v1.05 Added #SP directive examples (latest ASM8) 157 ;* : 10.01.29 v1.06 Added shorter/faster Swap version for 9S08 MCUs 158 ;* : 10.02.01 v1.07 Added #SPAUTO directive 159 ;* : 10.02.04 Added #X directive 160 ;* : 10.02.06 v2.00 Added signed math wrapper calls only for DIV & MOD 161 ;* : (Addition, Subtraction, and Multiplication calls 162 ;* : work either for unsigned or signed operands.) 163 ;* : Signed routines enabled w/ SIGNED conditional. 164 ;* : Division by zero error now reduces stack (operand 165 ;* : A removed) so that the stack is left with same 166 ;* : size on either success or failure (in which case 167 ;* : the TOS result is invalid.) 168 ;* : 10.02.08 v2.01 Fixed signed MOD for correct sign (sign of A) 169 ;* : 10.02.14 v2.10 Added Stack32ToASCIZ and prerequisite StringInsertChar 170 ;* : 10.02.28 v2.11 Minor optimization in StringInsertChar 171 ;* : 10.03.23 Made use of :: internal variable (Build 2010/03/23) 172 ;* : 10.03.30 v2.12 Allowed for HC08 compilation in newer code (?ToStr) 173 ;* : Optimized 9S08 Swap version for size and speed 174 ;* : v2.13 Optimized Negate for size and speed 175 ;* : 10.05.08 v3.00 Added MATHSIZE = 64 option for 64-bit math 176 ;* : Swap operation optimized only for size 177 ;* : 10.05.13 v3.01 Optimized for size and speed by using ,SPX 178 ;* : 10.06.02 v4.00 Added macros for easier use 179 ;* : 10.06.08 v4.10 Improved macros and added new ones (eg Const32) 180 ;* : 10.06.23 v4.20 Added MATHSIZE = 48 option for 48-bit math 181 ;* : 10.06.30 v4.30 Added AddDecimalPoint (to string number) 182 ;* : 10.07.01 v4.40 Added IFSPAUTO conditional 183 ;* : 10.07.03 Moved the functionality of Const macros into Load 184 ;* : 10.07.07 Moved general string routines first 185 ;* : 10.07.17 v4.50 Str* macros may use TOS (if Number parm is missing) 186 ;* : or current HX index (if result pointer is missing) 187 ;* : 10.07.20 _DoLoad*/_DoSave* address now allows for indexed mode 188 ;* : 10.07.21 Minor optimizations; macros now latest ASM8 189 ;* : 10.07.23 Minor bug fix in macro _DoSave for no parm case 190 ;* : 10.08.18 Optimized by using :MINDEX in latest ASM8 191 ;* : 10.08.26 Minor optimizations at the source level 192 ;* : 10.08.31 v4.60 Optimized Load* macros' immediate mode for zeros 193 ;* : 10.10.19 v4.61 Adapted to latest ASM8 (nested macros in Load) 194 ;* : 10.10.22 v4.62 Optimized _DoMath (Added @_DoOperation) 195 ;* : 10.10.26 v4.63 Load48 & Load64 now also accept single #Constant 196 ;* : 10.12.03 v4.64 Adapted to latest ASM8 => macros OK in @@ sub-mode 197 ;* : 11.03.31 v4.65 Moved test code at EOF (to use #EXIT optimization) 198 ;* : 11.04.10 v4.66 Condensed macro definitions (based on MATHSIZE) 199 ;* : 11.04.11 v4.67 Optimized MUL16/MUL32 size & cycles with ,SPX mode 200 ;* : 11.04.12 v4.70 Added MATHSIZE = 24 option for 24-bit math 201 ;* : 11.04.13 v4.71 Reversed some of v4.66's changes 202 ;* : 11.04.13 v4.80 Added MATHSIZE = 40 option for 40-bit math 203 ;* : 11.05.02 v4.81 Save protects HX (it was lost during SP => SPX) 204 ;* : 11.05.05 v4.82 Optimized StringLength by a byte (by using NEGA on exit) 205 ;* : 11.05.25 v4.83 Removed unused Zero constant from test code 206 ;* : 11.10.13 v4.84 Optimized MUL16/24/32 size w/ more ,SPX (same cycles) 207 ;* : 11.11.15 v4.85 Improved StringLength macro 208 ;* : 12.01.26 Changed test code a bit 209 ;* : 12.02.06 v4.86 Optimized SP => SPX at ?RemoveAndReturn 210 ;* : 12.03.05 v4.87 Added ResizeTOS to adjust TOS element's size 211 ;* : 12.05.09 v4.88 Added CCR[C] parameter to ResizeTOS for unsigned operation 212 ;* (signed is default when SIGNED conditional is defined, 213 ;* unsigned operation is default, otherwise) 214 ;* : 12.05.18 v4.89 Removed redundant subtraction in Division (at NotEqual@@) 215 ;* : 12.10.07 v4.90 Load*/Save* now accept indexed mode without separator override 216 ;* : 12.10.10 v5.00 Renamed to (more general) STAKMATH.SUB to use 217 ;* : wrapper files for each bit version, instead. 218 ;* : 12.11.05 Added _STKMTH{MATHSIZE}_ for used-version control 219 ;* : 12.11.09 v6.00 New _LoadStkMthVarAddr macro eases parm address 220 ;* : calculation. 221 ;* : W A R N I N G: SP-based operands now refer to the actual number, 222 ;* : W A R N I N G: and not its address (as was the case before). 223 ;* : W A R N I N G: This is INCOMPATIBLE with previous behavior. Code 224 ;* : W A R N I N G: written for version v5.00 or earlier that uses SP 225 ;* : W A R N I N G: based operands should be modified to refer to the 226 ;* : W A R N I N G: actual value and not to a pointer to the value. 227 ;* : W A R N I N G: Dot-beginning names are still treated as pointers! 228 ;* : 12.11.10 Use COMMON.INC/LEA instead of _LoadStkMthVarAddr 229 ;* : 12.12.04 v6.10 Optimized division just a tad by combining steps 230 ;* : 12.12.12 v6.20 Now use LEA macro inside _DoStr (for ResultString) 231 ;* : 12.12.20 v6.21 Minor optimization (one byte) in 32-bit ?Multiply 232 ;* : (Further 3-byte optimization possible by 233 ;* : re-ordering MULs, but not done for code clarity) 234 ;* : 13.01.09 v6.22 Added Copy* macros to combine Load*/Save* into one 235 ;* : 13.03.20 v7.00 Added Eval* and supporting macros for HLL-like 236 ;* : computations, eg., ans=(a+3)*((1+var,sp)/2) 237 ;* : (with or without spaces between operands/operators) 238 ;* : 13.03.27 v7.50 SIGNED now gives just signed (not unsigned) version 239 ;* : DivS*, ModS*, StrS* macros were removed, and also 240 ;* : ResizeTOS macro's unsigned flag has been removed 241 ;* : BugFix: AddDecimalPoint now prepends zeros after sign 242 ;* : 13.03.27 Optimized ?Negate in SIGNED case to use ?NegX sub 243 ;* : 13.03.27 v7.60 Adapted _EVAL_ macro to latest ASM8 (Much faster!) 244 ;* : 13.04.04 v7.70 _DoLoad and _DoSave macros now auto-adjust the size 245 ;* : so you can use with operands of different sizes, even 246 ;* : if the respective bitsize version isn't loaded. 247 ;* : 13.04.04 v7.71 _Eval_ macro leaves assignment result on TOS if 248 ;* : assignment variable not already defined. Then, 249 ;* : it gives TOS the specified name, if SP-indexed. 250 ;* : 13.04.05 v7.72 Added #size for v7.71 change 251 ;* : Named constants (labels with size zero) now use 252 ;* : immediate mode in Eval/Load 253 ;* : 13.04.05 v7.73 Added NEG() negate, and ABS() absolute functions 254 ;* : in Eval macro, e.g., ans = abs(a - b) 255 ;* : 13.04.09 v7.80 BugFix: Push/Pull macro calls for SP mode 256 ;* : Moved immediate mode to _DoLoad (unified method) 257 ;* : (Over 32-bit immediate value loads not possible 258 ;* : via macros) 259 ;* : 13.04.10 Adapted to v9.35 (no functional changes) 260 ;* : 13.04.11 v7.81 Optimized _DoLoad constant loading by using CLRH 261 ;* : (optimization is evident on certain cases only) 262 ;* : 13.04.15 v7.82 Added _?SEI_ and _?CLI_ macros for multitasker 263 ;* : locking / unlocking of multi-byte variables while 264 ;* : loading / saving (_DoLoad/_DoSave). Under OS8 it 265 ;* : is enabled automatically. Otherwise, simply 266 ;* : define _MTOS_ anytime before including this file. 267 ;* : For keeping code dense, all Eval*/Load*/Save* 268 ;* : macros are assumed to be called only while 269 ;* : interrupts are enabled, so it will not restore to 270 ;* : previous state but always leave as enabled. 271 ;* : Define _NOCLI_ (before including this module) for 272 ;* : canceling the _?SEI_ and _?CLI_ macro effects. 273 ;* : 13.04.18 v7.85 Added 'NeedMath' and 'Eval' general-purpose macros 274 ;* : for automatic selection of needed bit-size based 275 ;* : on only which modules are already included. First, 276 ;* : call the NeedMath macro to define the minimum math 277 ;* : bit-size you need for the next calculation(s), 278 ;* : then call the Eval macro as many times as needed 279 ;* : to perform the actual expression evaluation(s). 280 ;* : Similary, added new macros Load, Save, StkAdd, 281 ;* : StkSub, StkMul, StkDiv, StkMod, StkSwap, StkNeg, 282 ;* : StkAbs, StkStr, and CopyMath to work with the 283 ;* : NeedMath macro, just like the new Eval macro. 284 ;* : 13.04.19 v8.00 Moved all Eval* macros into COMMON.INC and allowed 285 ;* : for all to be active at all times, regardless if 286 ;* : the related bit-version of STAKMATH is included. 287 ;* : The _Eval_ macro was improved to allow it to 288 ;* : automatically locate the next higher version that 289 ;* : is included, if the one requested is not. So, 290 ;* : using Eval32 will use the 32/40/48/64-bit version 291 ;* : (whichever is closer to 32 and included) but nothing 292 ;* : below 32-bit. This allows you to use the relevant 293 ;* : macro based on a specific expression's requirements 294 ;* : but include only one (or just a few) higher bit 295 ;* : version(s), not all those referenced in your code. 296 ;* : (The general Eval is still available, if needed.) 297 ;* : Also, moved all Str* to COMMON.INC 298 ;* : 13.04.21 v8.10 Corrected v8.00 for pointer cases (.num) to use 299 ;* : actual requested size, not next higher. 300 ;* : Relevant #Message now in _DoOperation _ResizeTOS etc. 301 ;* : 13.04.21 v8.11 NeedMath & related macros removed (now redundant) 302 ;* : General Eval macro will try to determine best bit-size 303 ;* : 13.04.23 v8.12 Added EvalS to first check for SIGNED and then call Eval 304 ;* : CopyMath removed. Use "Eval to_var = from_var" instead 305 ;* : _StkMthMax_ improved to use higher size on multiplication 306 ;* : 13.04.25 v8.13 _Eval_ now allows for string constants (eg., @Eval ans = ans + '0') 307 ;* : Removed all ?macros because we now use COMMON xxx.s macros 308 ;* : 13.04.26 v8.15 Corrected test code for Eval when MATHSIZE < 32 309 ;* : Commented out auto-higher bit-size (a bit annoying). 310 ;* : Use Eval* to say 'no less than', instead. 311 ;* : 13.04.27 v8.16 BugFix: StrMath macro (2nd parameter was lost) 312 ;* : Added SQR() function to get the square 313 ;* : 13.05.02 Added #size in ToInt* macros (in test code) 314 ;* : 13.05.03 v8.17 Added size optimization for ADD and SUB operations 315 ;* : New SPEED_SIZE constant in COMMON.INC tells us 316 ;* : whether we need speed (SPEED_SIZE = 1) or 317 ;* : size (SPEED_SIZE = 2) optimization, the current 318 ;* : default being SPEED_SIZE = 2 for size optimization. 319 ;* : 13.05.30 Updated StrMath macro (COMMON.INC and here) 320 ;* : 13.06.04 v8.20 Added bit functions: AND (&), OR (|), XOR (^), and shifts (< and >) 321 ;* : 13.06.05 v8.21 BugFix: ShiftRight now uses ASR if SIGNED 322 ;* : 13.07.25 v8.22 Improved _Eval_ macro (and Push/Pull in COMMON.INC) 323 ;* : BugFix: Added { } to ResizeTOS macro's final case 324 ;* : (Disable bit functions with NO_BIT_OPS conditional) 325 ;* : 13.10.06 Minor changes in test code 326 ;* : 13.11.26 Added warning in _DoLoad: forwards treated as vars 327 ;* : 13.11.29 v8.23 Optimized ?ShiftLeft and ?ShiftRight a bit 328 ;* : 13.12.22 v8.30 Added 56-bit version 329 ;* : 14.01.03 Made use of _CMP_.S macro (instead of custom macro) 330 ;* : 14.02.07 v8.50 Added [ ... ] unsigned override (if SIGNED) 331 ;* : 14.02.14 v8.51 Eval macro now uses #HideMacros 332 ;* : 14.10.14 v8.52 BugFix: Off-by-one error in ResizeTOS when SIGNED 333 ;* : 15.03.21 v8.53 Replaced string dependencies with corresponding #Uses 334 ;* : 15.04.08 v8.54 Replaced AddDecimalPoint with corresponding #Uses 335 ;* : 17.04.03 v8.55 Optimized 24-bit multiply [-2 bytes] 336 ;* : Optimized 32-bit multiply [-7 bytes] 337 ;* : 18.10.23 Suppressed possible warning from JEQ in ?DivStart 338 ;* : 19.03.04 Added warning in _DoStr macro when using StrNN 339 ;* : when NN is different from MATHSIZE and no explicit 340 ;* : variable is given 341 ;* : 19.10.04 v8.56 Minor HC08 mode optimization in SIGNED ?ToStr [-1 byte] 342 ;* : 20.02.12 v8.57 Replaced #Message with @Msg to silence debugging messages 343 ;******************************************************************************* 344 345 ;Synopsis (replace * with 16, 24, 32, 40, 48, 56, 64 for corresponding bit version): 346 ; 347 ;Subroutines Action 348 ;-------------- ---------------------------- 349 ;StackAdd* - TOS := TOS + [TOS+1] (signed or unsigned) [TOS+1] removed 350 ;StackSub* - TOS := TOS - [TOS+1] (signed or unsigned) [TOS+1] removed 351 ;StackMul* - TOS := TOS * [TOS+1] (signed or unsigned) [TOS+1] removed 352 ;StackDiv* - TOS := TOS / [TOS+1] (signed if SIGNED) [TOS+1] removed 353 ;StackMod* - TOS := TOS \ [TOS+1] (signed if SIGNED) [TOS+1] removed 354 ;StackAnd* - TOS := TOS & [TOS+1] (signed or unsigned) [TOS+1] removed 355 ;StackOr* - TOS := TOS | [TOS+1] (signed or unsigned) [TOS+1] removed 356 ;StackXor* - TOS := TOS ^ [TOS+1] (signed or unsigned) [TOS+1] removed 357 ;StackShl* - TOS := TOS < [TOS+1] (signed or unsigned) [TOS+1] removed 358 ;StackShr* - TOS := TOS > [TOS+1] (signed if SIGNED) [TOS+1] removed 359 ;StackSwap* - TOS swapped with [TOS+1] (signed or unsigned) 360 ;StackAbs* - TOS := ABS(TOS) (signed) 361 ;StackNegate* - TOS := -TOS (signed) 362 ;StackLoad* - Load const/variable to TOS (signed or unsigned) TOS created 363 ;StackSave* - Save TOS into variable (signed or unsigned) TOS removed 364 ;ResizeTOS - Adjust TOS old size to new (signed or unsigned) TOS resized 365 ;Stack*ToASCIZ - Convert TOS to ASCIZ str (signed if SIGNED) 366 ; 367 ;Macros Purpose Parameters ([...] means optional part) 368 ;------------------ ------------------- ---------------------------------------- 369 ;Load* Stack const or var #Number | Variable 370 ;Save* Unstack a variable Variable 371 ;Copy* Load* & Save* #Number | Variable,Variable 372 ;ResizeTOS Resize TOS #FromByteSize,#ToByteSize 373 ; 374 ;Add* Addition [Addend[,Adder[,Sum]]] 375 ;Sub* Subtraction [Minuend[,Subtrahend[,Difference]]] 376 ;Mul* Multiplication [Multiplicand[,Multiplier[,Product]]] 377 ;Div* Unsigned division [Dividend[,Divisor[,Quotient]]] 378 ;Mod* Unsigned modulo [Dividend[,Divisor[,Remainder]]] 379 ;Abs* Absolute value [SourceVariable][,DestinationVariable] 380 ;Neg* Negation [SourceVariable][,DestinationVariable] 381 ;Swap* Swap TOS numbers 382 ;Str* Number to ASCIZ [Variable],[ResultString] 383 ;AddDecimalPoint ... to ASCIZ number [[#]DecimalPlaces[,[#]ASCIZ_String]] 384 411 412 0038 MATHSIZE def 32 ;default wordsize is 32-bit 413 417 418 ? macro BitSize 419 #if MATHSIZE = ~1~ 420 ?WORD equ ~1~/8 421 _STKMTH{MATHSIZE}_ ;;specific version included 422 _STAKMATH_ def * ;;any version included 423 #endif 424 endm 425 426 M @? 16 ;16-bit quantity (on request) 426 endm 427 M @? 24 ;24-bit quantity (on request) 427 endm 428 M @? 32 ;32-bit quantity (default) 428 endm 429 M @? 40 ;40-bit quantity (on request) 429 endm 430 M @? 48 ;48-bit quantity (on request) 430 endm 431 M @? 56 ;56-bit quantity (on request) 431 M 0007 ?WORD equ 56/8 431 M 2A94 _STKMTH56_ 431 M 182C _STAKMATH_ def * 431 endm 432 M @? 64 ;64-bit quantity (on request) 432 endm 433 439 #Message MATHSIZE = {MATHSIZE}-bit version 441 #Message Signed routines enabled 443 ;******************************************************************************* 444 ; Macros to make operations as simple as with a high-level language 445 ; In operations that require two operands and a result, if only one operand is 446 ; provided, then the operation is done completely on stack (no other variables 447 ; used). For example, @Add32 A,B,SUM adds A to B and places result in SUM, 448 ; while @Add32 A adds the current stack top to A and leaves result on stack. 449 ; You can use @Load* and @Save* to load the initial value, and store the final 450 ; result, respectively. (Replace * with 16, 24, 32, 40, 48, 56, or 64) 451 ;******************************************************************************* 452 501 ;=============================================================================== 550 ;=============================================================================== 599 ;=============================================================================== 648 ;=============================================================================== 697 ;=============================================================================== 699 700 Load56 macro #Number|Variable ;load constant or variable 701 @_DoLoad ~0.{:0-1}~\,~@~ 702 endm 703 704 Save56 macro Address 705 @_DoSave 56\,~@~ 706 endm 707 708 Copy56 macro #Constant|Variable,ToAddress 709 mreq 1,2:#Constant|Variable,ToAddress 710 @@Load56 ~1~ 711 @Save56 ~2~ 712 endm 713 714 Swap56 macro 715 @_DoSwap 56 716 endm 717 718 Add56 macro Addend,Adder,Sum 719 @_DoMath ~0~\,56\,~1~\,~2~\,~3~ 720 endm 721 722 Sub56 macro Minuend,Subtrahend,Difference 723 @_DoMath ~0~\,56\,~1~\,~2~\,~3~ 724 endm 725 726 Mul56 macro Multiplicand,Multiplier,Product 727 @_DoMath ~0~\,56\,~1~\,~2~\,~3~ 728 endm 729 730 Div56 macro Dividend,Divisor,Quotient 731 @_DoMath ~0~\,56\,~1~\,~2~\,~3~ 732 endm 733 734 Mod56 macro Dividend,Divisor,Remainder 735 @_DoMath ~0~\,56\,~1~\,~2~\,~3~ 736 endm 737 738 Abs56 macro Source[,Destination] 739 @_DoAbs 56\,~1~\,~2~ 740 endm 741 742 Neg56 macro Source[,Destination] 743 @_DoNeg 56\,~1~\,~2~ 744 endm 746 ;=============================================================================== 795 796 ;******************************************************************************* 797 ; Common macro(s) for all operations defined above (not to be called directly) 798 ;******************************************************************************* 799 807 ;------------------------------------------------------------------------------- 867 ;------------------------------------------------------------------------------- 890 ;------------------------------------------------------------------------------- 898 ;------------------------------------------------------------------------------- 916 ;=============================================================================== 933 ;------------------------------------------------------------------------------- 1158 ;------------------------------------------------------------------------------- 1185 ;------------------------------------------------------------------------------- 1212 ;------------------------------------------------------------------------------- 1288 ;------------------------------------------------------------------------------- 1328 ;------------------------------------------------------------------------------- 1337 ;------------------------------------------------------------------------------- 1351 ;------------------------------------------------------------------------------- 1380 ;------------------------------------------------------------------------------- 1398 ;------------------------------------------------------------------------------- 1416 ;------------------------------------------------------------------------------- 1451 1452 ;******************************************************************************* 1453 ; External dependencies 1454 ;******************************************************************************* 1455 1456 #Uses string/length.sub 1457 #Uses string/insertchar.sub 1458 #Uses string/adddecimalpoint.sub 1459 2A94 ?_OBJECT_? 1460 ;******************************************************************************* 1461 ; One-based (SP-index) offsets to stacked operands (to be used with #SPAUTO :AB) 1462 ;******************************************************************************* 1463 1464 #temp 1 1465 0001 ?a next :temp,?WORD ;top-of-stack (TOS) number (N1) 1466 0008 ?b next :temp,?WORD ;number after TOS (N2) 1467 1468 #Cycles ;reset the cycles counter 1469 1470 ;******************************************************************************* 1471 ; Purpose: Add N1 to N2 and place result on top-of-stack. N1 & N2 removed 1472 ; Input : [TOS+?WORD] = Number2 1473 ; : [TOS] = Number1 1474 ; Output : [TOS] = Result 1475 ; Note(s): Carry Set on overflow 1476 1477 #spauto :ab 1478 1479 2A94 ?Add proc 1480 [2A94] 2A94:8789 8B [ 6] push 1481 [2A97] 2A97:95 [ 2] tsx 1482 1488 [2A98] 2A98:A607 [ 2] lda #?WORD 1489 [2A9A] 2A9A:98 [ 1] clc 1490 #Cycles 1491 [2A9B] 2A9B:87 [ 2] Loop@@ psha 1492 [2A9C] 2A9C:E60B [ 3] lda ?a+{::?a-1},spx 1493 [2A9E] 2A9E:E912 [ 3] adc ?b+{::?b-1},spx 1494 [2AA0] 2AA0:E712 [ 3] sta ?b+{::?b-1},spx 1495 [2AA2] 2AA2:86 [ 3] pula 1496 [2AA3] 2AA3:AFFF [ 2] aix #-1 1497 [2AA5] 2AA5:4BF4 (2A9B) [ 4] dbnza Loop@@ 1498 #Cycles :cycles*?WORD+:ocycles 1500 [2AA7] 2AA7:CC2E 64 [ 4] jmp ?RemoveAndReturn 1501 1502 009B ?AddCycles equ :cycles 1503 1504 ;******************************************************************************* 1505 ; Purpose: Subtract N2 from N1 and place result on top-of-stack. N1 & N2 removed 1506 ; Input : [TOS+?WORD] = Number2 1507 ; : [TOS] = Number1 1508 ; Output : [TOS] = Result 1509 ; Note(s): Carry Set on borrow 1510 1511 #spauto :ab 1512 1513 2AAA ?Subtract proc 1514 [2AAA] 2AAA:8789 8B [ 6] push 1515 [2AAD] 2AAD:95 [ 2] tsx 1521 [2AAE] 2AAE:A607 [ 2] lda #?WORD 1522 [2AB0] 2AB0:98 [ 1] clc 1523 #Cycles 1524 [2AB1] 2AB1:87 [ 2] Loop@@ psha 1525 [2AB2] 2AB2:E60B [ 3] lda ?a+{::?a-1},spx 1526 [2AB4] 2AB4:E212 [ 3] sbc ?b+{::?b-1},spx 1527 [2AB6] 2AB6:E712 [ 3] sta ?b+{::?b-1},spx 1528 [2AB8] 2AB8:86 [ 3] pula 1529 [2AB9] 2AB9:AFFF [ 2] aix #-1 1530 [2ABB] 2ABB:4BF4 (2AB1) [ 4] dbnza Loop@@ 1531 #Cycles :cycles*?WORD+:ocycles 1533 [2ABD] 2ABD:CC2E 64 [ 4] jmp ?RemoveAndReturn 1534 1535 009B ?SubCycles equ :cycles 1536 1540 M @Msg Bit ops enabled (define NO_BIT_OPS to disable) 1540 mexit 1541 ;******************************************************************************* 1542 ; Purpose: AND N1 with N2 and place result on top-of-stack. N1 & N2 removed 1543 ; Input : [TOS+?WORD] = Number2 1544 ; : [TOS] = Number1 1545 ; Output : [TOS] = Result 1546 ; Note(s): 1547 #spauto :ab 1548 1549 2AC0 ?BitAnd proc 1550 [2AC0] 2AC0:8789 8B [ 6] push 1551 [2AC3] 2AC3:95 [ 2] tsx 1552 1558 [2AC4] 2AC4:A607 [ 2] lda #?WORD 1559 #Cycles 1560 [2AC6] 2AC6:87 [ 2] Loop@@ psha 1561 [2AC7] 2AC7:E60B [ 3] lda ?a+{::?a-1},spx 1562 [2AC9] 2AC9:E412 [ 3] and ?b+{::?b-1},spx 1563 [2ACB] 2ACB:E712 [ 3] sta ?b+{::?b-1},spx 1564 [2ACD] 2ACD:86 [ 3] pula 1565 [2ACE] 2ACE:AFFF [ 2] aix #-1 1566 [2AD0] 2AD0:4BF4 (2AC6) [ 4] dbnza Loop@@ 1567 #Cycles :cycles*?WORD+:ocycles 1569 [2AD2] 2AD2:CC2E 64 [ 4] jmp ?RemoveAndReturn 1570 1571 009A ?AndCycles equ :cycles 1572 1573 ;******************************************************************************* 1574 ; Purpose: OR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1575 ; Input : [TOS+?WORD] = Number2 1576 ; : [TOS] = Number1 1577 ; Output : [TOS] = Result 1578 ; Note(s): 1579 #spauto :ab 1580 1581 2AD5 ?BitOr proc 1582 [2AD5] 2AD5:8789 8B [ 6] push 1583 [2AD8] 2AD8:95 [ 2] tsx 1584 1590 [2AD9] 2AD9:A607 [ 2] lda #?WORD 1591 #Cycles 1592 [2ADB] 2ADB:87 [ 2] Loop@@ psha 1593 [2ADC] 2ADC:E60B [ 3] lda ?a+{::?a-1},spx 1594 [2ADE] 2ADE:EA12 [ 3] ora ?b+{::?b-1},spx 1595 [2AE0] 2AE0:E712 [ 3] sta ?b+{::?b-1},spx 1596 [2AE2] 2AE2:86 [ 3] pula 1597 [2AE3] 2AE3:AFFF [ 2] aix #-1 1598 [2AE5] 2AE5:4BF4 (2ADB) [ 4] dbnza Loop@@ 1599 #Cycles :cycles*?WORD+:ocycles 1601 [2AE7] 2AE7:CC2E 64 [ 4] jmp ?RemoveAndReturn 1602 1603 009A ?OrCycles equ :cycles 1604 1605 ;******************************************************************************* 1606 ; Purpose: XOR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1607 ; Input : [TOS+?WORD] = Number2 1608 ; : [TOS] = Number1 1609 ; Output : [TOS] = Result 1610 ; Note(s): 1611 #spauto :ab 1612 1613 2AEA ?BitXor proc 1614 [2AEA] 2AEA:8789 8B [ 6] push 1615 [2AED] 2AED:95 [ 2] tsx 1616 1622 [2AEE] 2AEE:A607 [ 2] lda #?WORD 1623 #Cycles 1624 [2AF0] 2AF0:87 [ 2] Loop@@ psha 1625 [2AF1] 2AF1:E60B [ 3] lda ?a+{::?a-1},spx 1626 [2AF3] 2AF3:E812 [ 3] eor ?b+{::?b-1},spx 1627 [2AF5] 2AF5:E712 [ 3] sta ?b+{::?b-1},spx 1628 [2AF7] 2AF7:86 [ 3] pula 1629 [2AF8] 2AF8:AFFF [ 2] aix #-1 1630 [2AFA] 2AFA:4BF4 (2AF0) [ 4] dbnza Loop@@ 1631 #Cycles :cycles*?WORD+:ocycles 1633 [2AFC] 2AFC:CC2E 64 [ 4] jmp ?RemoveAndReturn 1634 1635 009A ?EorCycles equ :cycles 1636 1637 ;******************************************************************************* 1638 ; Purpose: Shift N1 left N2 times and place result on top-of-stack. N1 & N2 removed 1639 ; Input : [TOS+?WORD] = Number2 1640 ; : [TOS] = Number1 1641 ; Output : [TOS] = Result 1642 ; Note(s): CCR[C] = last most significant bit shifted out 1643 ; : Only LSB of second operand (N2) is used, as shifting more than the 1644 ; : highest bit version always produces zero. Any non-zero bytes in the 1645 ; : N2 operand will cause a zero result, regardless. 1646 1647 #spauto :ab 1648 1649 2AFF ?ShiftLeft proc 1650 [2AFF] 2AFF:8789 8B [ 6] push 1651 #ais 1652 1653 [2B02] 2B02:9EE6 13 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1654 [2B05] 2B05:87 [ 2] psha counter@@ 1655 1656 [2B06] 2B06:95 [ 2] tsx 1657 1658 [2B07] 2B07:6F13 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1659 0008 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1660 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1660 M mset # 1660 M mreq 1 1660 M @@_nosize_ b105,spx 1660 M mset # 1660 M mset 0,mstop [_tst_.s] No size (b105,spx) 1660 M endm 1660 M mdo 1660 M [2B09] 2B09:E60D [ 3] lda b105+0,spx 1660 M mloop ::b105 1660 M [2B0B] 2B0B:EA0E [ 3] ora b105+1,spx 1660 M mloop ::b105 1660 M [2B0D] 2B0D:EA0F [ 3] ora b105+2,spx 1660 M mloop ::b105 1660 M [2B0F] 2B0F:EA10 [ 3] ora b105+3,spx 1660 M mloop ::b105 1660 M [2B11] 2B11:EA11 [ 3] ora b105+4,spx 1660 M mloop ::b105 1660 M [2B13] 2B13:EA12 [ 3] ora b105+5,spx 1660 M mloop ::b105 1660 endm 1661 [2B15] 2B15:2713 (2B2A) [ 3] beq Go@@ ;if so, proceed normally 1662 1663 [2B17] 2B17:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1664 [2B18] 2B18:A138 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1665 [2B1A] 2B1A:250E (2B2A) [ 3] blo Go@@ ;else zero and exit 1666 1667 M @clr.s, b@@,spx ;else error, so zero result 1667 M mset #' ' 1667 M mreq 1 1667 M @@_nosize_ b105,spx 1667 M mset # 1667 M mset 0,mstop [clr.s] No size (b105,spx) 1667 M endm 1667 M mdef 2,::b105 1667 M mdo 1667 M [2B1C] 2B1C:6F0D [ 5] clr b105+0,spx 1667 M mloop ::b105 1667 M [2B1E] 2B1E:6F0E [ 5] clr b105+1,spx 1667 M mloop ::b105 1667 M [2B20] 2B20:6F0F [ 5] clr b105+2,spx 1667 M mloop ::b105 1667 M [2B22] 2B22:6F10 [ 5] clr b105+3,spx 1667 M mloop ::b105 1667 M [2B24] 2B24:6F11 [ 5] clr b105+4,spx 1667 M mloop ::b105 1667 M [2B26] 2B26:6F12 [ 5] clr b105+5,spx 1667 M mloop ::b105 1667 endm 1668 [2B28] 2B28:202C (2B56) [ 3] bra Done@@ ;and get out 1669 1670 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1670 M mset #' ' 1670 M mreq 1,2:Source Destination 1670 M @@_samesize_ ?a,spx ?b,spx 1670 M mreq 1,2:Operand1,Operand2[,Operand]* 1670 M mset 0 1670 M mdo 1670 M mswap 1,1 1670 M @@_nosize_ ?a,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?a,spx) 1670 M endm 1670 M mset 0,?a,spx 1670 M mloop :n 1670 M mswap 1,2 1670 M @@_nosize_ ?b,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?b,spx) 1670 M endm 1670 M mloop :n 1670 M endm 1670 M mset 0 1670 M mdo 1670 M [2B2A] 2B2A:E606 [ 3] lda ?a+0,spx 1670 M [2B2C] 2B2C:E70D [ 3] sta ?b+0,spx 1670 M mloop ::?b 1670 M [2B2E] 2B2E:E607 [ 3] lda ?a+1,spx 1670 M [2B30] 2B30:E70E [ 3] sta ?b+1,spx 1670 M mloop ::?b 1670 M [2B32] 2B32:E608 [ 3] lda ?a+2,spx 1670 M [2B34] 2B34:E70F [ 3] sta ?b+2,spx 1670 M mloop ::?b 1670 M [2B36] 2B36:E609 [ 3] lda ?a+3,spx 1670 M [2B38] 2B38:E710 [ 3] sta ?b+3,spx 1670 M mloop ::?b 1670 M [2B3A] 2B3A:E60A [ 3] lda ?a+4,spx 1670 M [2B3C] 2B3C:E711 [ 3] sta ?b+4,spx 1670 M mloop ::?b 1670 M [2B3E] 2B3E:E60B [ 3] lda ?a+5,spx 1670 M [2B40] 2B40:E712 [ 3] sta ?b+5,spx 1670 M mloop ::?b 1670 M [2B42] 2B42:E60C [ 3] lda ?a+6,spx 1670 M [2B44] 2B44:E713 [ 3] sta ?b+6,spx 1670 M mloop ::?b 1670 endm 1671 #Cycles 1672 M Loop@@ @lsl.s, ?b,spx ;shift left one bit position 1672 M mset # 1672 M mreq 1 1672 M @@_nosize_ ?b,spx 1672 M mset # 1672 M mset 0,mstop [lsl.s] No size (?b,spx) 1672 M endm 1672 M mdo 1672 M [2B46] 2B46:6813 [ 5] lsl ?b+6,spx 1672 M mloop ::?b 1672 M [2B48] 2B48:6912 [ 5] rol ?b+5,spx 1672 M mloop ::?b 1672 M [2B4A] 2B4A:6911 [ 5] rol ?b+4,spx 1672 M mloop ::?b 1672 M [2B4C] 2B4C:6910 [ 5] rol ?b+3,spx 1672 M mloop ::?b 1672 M [2B4E] 2B4E:690F [ 5] rol ?b+2,spx 1672 M mloop ::?b 1672 M [2B50] 2B50:690E [ 5] rol ?b+1,spx 1672 M mloop ::?b 1672 M [2B52] 2B52:690D [ 5] rol ?b+0,spx 1672 M mloop ::?b 1672 endm 1673 [2B54] 2B54:7BF0 (2B46) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1674 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1675 2B56 Done@@ 1677 [2B56] 2B56:86 [ 3] pula 1681 [2B57] 2B57:CC2E 64 [ 4] jmp ?RemoveAndReturn 1682 1683 0951 ?ShlCycles equ :cycles 1684 1685 ;******************************************************************************* 1686 ; Purpose: Shift N1 right N2 times and place result on top-of-stack. N1 & N2 removed 1687 ; Input : [TOS+?WORD] = Number2 1688 ; : [TOS] = Number1 1689 ; Output : [TOS] = Result 1690 ; Note(s): CCR[C] = last least significant bit shifted out 1691 ; : Only LSB of second operand (N2) is used, as shifting more than the 1692 ; : highest bit version always produces zero. Any non-zero bytes in the 1693 ; : N2 operand will cause a zero result, regardless. 1694 1695 #spauto :ab 1696 1697 2B5A ?ShiftRight proc 1698 [2B5A] 2B5A:8789 8B [ 6] push 1699 #ais 1700 1701 [2B5D] 2B5D:9EE6 13 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1702 [2B60] 2B60:87 [ 2] psha counter@@ 1703 1704 [2B61] 2B61:95 [ 2] tsx 1705 1706 [2B62] 2B62:6F13 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1707 0008 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1708 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1708 M mset # 1708 M mreq 1 1708 M @@_nosize_ b106,spx 1708 M mset # 1708 M mset 0,mstop [_tst_.s] No size (b106,spx) 1708 M endm 1708 M mdo 1708 M [2B64] 2B64:E60D [ 3] lda b106+0,spx 1708 M mloop ::b106 1708 M [2B66] 2B66:EA0E [ 3] ora b106+1,spx 1708 M mloop ::b106 1708 M [2B68] 2B68:EA0F [ 3] ora b106+2,spx 1708 M mloop ::b106 1708 M [2B6A] 2B6A:EA10 [ 3] ora b106+3,spx 1708 M mloop ::b106 1708 M [2B6C] 2B6C:EA11 [ 3] ora b106+4,spx 1708 M mloop ::b106 1708 M [2B6E] 2B6E:EA12 [ 3] ora b106+5,spx 1708 M mloop ::b106 1708 endm 1709 [2B70] 2B70:2713 (2B85) [ 3] beq Go@@ ;if so, proceed normally 1710 1711 [2B72] 2B72:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1712 [2B73] 2B73:A138 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1713 [2B75] 2B75:250E (2B85) [ 3] blo Go@@ ;else zero and exit 1714 1715 M @clr.s, b@@,spx ;else error, so zero result 1715 M mset #' ' 1715 M mreq 1 1715 M @@_nosize_ b106,spx 1715 M mset # 1715 M mset 0,mstop [clr.s] No size (b106,spx) 1715 M endm 1715 M mdef 2,::b106 1715 M mdo 1715 M [2B77] 2B77:6F0D [ 5] clr b106+0,spx 1715 M mloop ::b106 1715 M [2B79] 2B79:6F0E [ 5] clr b106+1,spx 1715 M mloop ::b106 1715 M [2B7B] 2B7B:6F0F [ 5] clr b106+2,spx 1715 M mloop ::b106 1715 M [2B7D] 2B7D:6F10 [ 5] clr b106+3,spx 1715 M mloop ::b106 1715 M [2B7F] 2B7F:6F11 [ 5] clr b106+4,spx 1715 M mloop ::b106 1715 M [2B81] 2B81:6F12 [ 5] clr b106+5,spx 1715 M mloop ::b106 1715 endm 1716 [2B83] 2B83:202C (2BB1) [ 3] bra Done@@ ;and get out 1717 1718 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1718 M mset #' ' 1718 M mreq 1,2:Source Destination 1718 M @@_samesize_ ?a,spx ?b,spx 1718 M mreq 1,2:Operand1,Operand2[,Operand]* 1718 M mset 0 1718 M mdo 1718 M mswap 1,1 1718 M @@_nosize_ ?a,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?a,spx) 1718 M endm 1718 M mset 0,?a,spx 1718 M mloop :n 1718 M mswap 1,2 1718 M @@_nosize_ ?b,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?b,spx) 1718 M endm 1718 M mloop :n 1718 M endm 1718 M mset 0 1718 M mdo 1718 M [2B85] 2B85:E606 [ 3] lda ?a+0,spx 1718 M [2B87] 2B87:E70D [ 3] sta ?b+0,spx 1718 M mloop ::?b 1718 M [2B89] 2B89:E607 [ 3] lda ?a+1,spx 1718 M [2B8B] 2B8B:E70E [ 3] sta ?b+1,spx 1718 M mloop ::?b 1718 M [2B8D] 2B8D:E608 [ 3] lda ?a+2,spx 1718 M [2B8F] 2B8F:E70F [ 3] sta ?b+2,spx 1718 M mloop ::?b 1718 M [2B91] 2B91:E609 [ 3] lda ?a+3,spx 1718 M [2B93] 2B93:E710 [ 3] sta ?b+3,spx 1718 M mloop ::?b 1718 M [2B95] 2B95:E60A [ 3] lda ?a+4,spx 1718 M [2B97] 2B97:E711 [ 3] sta ?b+4,spx 1718 M mloop ::?b 1718 M [2B99] 2B99:E60B [ 3] lda ?a+5,spx 1718 M [2B9B] 2B9B:E712 [ 3] sta ?b+5,spx 1718 M mloop ::?b 1718 M [2B9D] 2B9D:E60C [ 3] lda ?a+6,spx 1718 M [2B9F] 2B9F:E713 [ 3] sta ?b+6,spx 1718 M mloop ::?b 1718 endm 1719 #Cycles 1720 2BA1 Loop@@ 1722 M @asr.s, ?b,spx ;shift right one bit position 1722 M mset # 1722 M mreq 1 1722 M @@_nosize_ ?b,spx 1722 M mset # 1722 M mset 0,mstop [asr.s] No size (?b,spx) 1722 M endm 1722 M mdo 1722 M [2BA1] 2BA1:670D [ 5] asr ?b+0,spx 1722 M mloop ::?b 1722 M [2BA3] 2BA3:660E [ 5] ror ?b+1,spx 1722 M mloop ::?b 1722 M [2BA5] 2BA5:660F [ 5] ror ?b+2,spx 1722 M mloop ::?b 1722 M [2BA7] 2BA7:6610 [ 5] ror ?b+3,spx 1722 M mloop ::?b 1722 M [2BA9] 2BA9:6611 [ 5] ror ?b+4,spx 1722 M mloop ::?b 1722 M [2BAB] 2BAB:6612 [ 5] ror ?b+5,spx 1722 M mloop ::?b 1722 M [2BAD] 2BAD:6613 [ 5] ror ?b+6,spx 1722 M mloop ::?b 1722 endm 1726 [2BAF] 2BAF:7BF0 (2BA1) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1727 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1728 2BB1 Done@@ 1730 [2BB1] 2BB1:86 [ 3] pula 1734 [2BB2] 2BB2:CC2E 64 [ 4] jmp ?RemoveAndReturn 1735 1736 0951 ?ShrCycles equ :cycles 1738 1739 ;******************************************************************************* 1740 ; Purpose: Multiply N1 with N2 and place result on top-of-stack. N1 & N2 removed 1741 ; Input : [TOS+?WORD] = Number2 1742 ; : [TOS] = Number1 1743 ; Output : [TOS] = Result 1744 ; Note(s): Overflows lost, Carry state should be ignored 1745 1746 #spauto :ab 1747 1748 2BB5 ?Multiply proc 1749 [2BB5] 2BB5:8789 8B [ 6] push 1773 ;=============================================================================== 1826 ;=============================================================================== 1913 #temp :cycles 1914 ;=============================================================================== 1915 ;-------------------------------------- 1916 ; 40, 48, 56, and 64-bit versions use shorter 1917 ; shift/add method (more cycles, though) 1918 ;-------------------------------------- 1920 1921 [2BB8] 2BB8:AE07 [ 2] ldx #?WORD ;make room for result... 1922 [2BBA] 2BBA:4F [ 1] clra ;... initialized to zero 1923 #temp :cycles+:temp 1924 [2BBB] 2BBB:87 [ 2] Init@@ psha 1925 [2BBC] 2BBC:5BFD (2BBB) [ 4] dbnzx Init@@ 1926 #temp :cycles*?WORD+:temp 1927 #spadd ?WORD-1 ;stack has grown by a ?WORD 1928 FFFFFFF5 ans@@ equ ::,?WORD 1929 1930 [2BBE] 2BBE:A638 [ 2] lda #MATHSIZE ;number of bits to process 1931 [2BC0] 2BC0:87 [ 2] psha bits@@ 1932 1933 [2BC1] 2BC1:95 [ 2] tsx 1934 #temp :cycles+:temp 1935 M Loop@@ @lsr.s ?b,spx ;multiplier lsb into CCR[C] 1935 M mset # 1935 M mreq 1 1935 M @@_nosize_ ?b,spx 1935 M mset # 1935 M mset 0,mstop [lsr.s] No size (?b,spx) 1935 M endm 1935 M mdo 1935 M [2BC2] 2BC2:6414 [ 5] lsr ?b+0,spx 1935 M mloop ::?b 1935 M [2BC4] 2BC4:6615 [ 5] ror ?b+1,spx 1935 M mloop ::?b 1935 M [2BC6] 2BC6:6616 [ 5] ror ?b+2,spx 1935 M mloop ::?b 1935 M [2BC8] 2BC8:6617 [ 5] ror ?b+3,spx 1935 M mloop ::?b 1935 M [2BCA] 2BCA:6618 [ 5] ror ?b+4,spx 1935 M mloop ::?b 1935 M [2BCC] 2BCC:6619 [ 5] ror ?b+5,spx 1935 M mloop ::?b 1935 M [2BCE] 2BCE:661A [ 5] ror ?b+6,spx 1935 M mloop ::?b 1935 endm 1936 [2BD0] 2BD0:242A (2BFC) [ 3] bcc Skip@@ ;Zeros skip addition 1937 1938 M @add.s ?a,spx ans@@,spx ans@@,spx ;Ones add multiplicand to product 1938 M mset #' ' 1938 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1938 M @@_samesize_ ?a,spx ans107,spx ans@@,spx 1938 M mreq 1,2:Operand1,Operand2[,Operand]* 1938 M mset 0 1938 M mdo 1938 M mswap 1,1 1938 M @@_nosize_ ?a,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (?a,spx) 1938 M endm 1938 M mset 0,?a,spx 1938 M mloop :n 1938 M mswap 1,2 1938 M @@_nosize_ ans107,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans107,spx) 1938 M endm 1938 M mloop :n 1938 M mswap 1,3 1938 M @@_nosize_ ans@@,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans107,spx) 1938 M endm 1938 M mloop :n 1938 M endm 1938 M mset 0,@@add.b, 1938 M mdo 1938 M mset 0,@@add.b, ?a+6,spx 1938 M mset 0,@@add.b, ?a+6,spx ans107+6,spx 1938 M mset 0,@@add.b, ?a+6,spx ans107+6,spx ans@@+6,spx 1938 M @@add.b, ?a+6,spx ans107+6,spx ans@@+6,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2BD2] 2BD2:E613 [ 3] lda ?a+6,spx 1938 M [2BD4] 2BD4:EB07 [ 3] add ans107+6,spx 1938 M @_sta_ ans@@+6,spx 1938 M [2BD6] 2BD6:E707 [ 3] sta ans107+6,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+5,spx 1938 M mset 0,@@adc.b, ?a+5,spx ans107+5,spx 1938 M mset 0,@@adc.b, ?a+5,spx ans107+5,spx ans@@+5,spx 1938 M @@adc.b, ?a+5,spx ans107+5,spx ans@@+5,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2BD8] 2BD8:E612 [ 3] lda ?a+5,spx 1938 M [2BDA] 2BDA:E906 [ 3] adc ans107+5,spx 1938 M @_sta_ ans@@+5,spx 1938 M [2BDC] 2BDC:E706 [ 3] sta ans107+5,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+4,spx 1938 M mset 0,@@adc.b, ?a+4,spx ans107+4,spx 1938 M mset 0,@@adc.b, ?a+4,spx ans107+4,spx ans@@+4,spx 1938 M @@adc.b, ?a+4,spx ans107+4,spx ans@@+4,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2BDE] 2BDE:E611 [ 3] lda ?a+4,spx 1938 M [2BE0] 2BE0:E905 [ 3] adc ans107+4,spx 1938 M @_sta_ ans@@+4,spx 1938 M [2BE2] 2BE2:E705 [ 3] sta ans107+4,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans107+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans107+3,spx ans@@+3,spx 1938 M @@adc.b, ?a+3,spx ans107+3,spx ans@@+3,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2BE4] 2BE4:E610 [ 3] lda ?a+3,spx 1938 M [2BE6] 2BE6:E904 [ 3] adc ans107+3,spx 1938 M @_sta_ ans@@+3,spx 1938 M [2BE8] 2BE8:E704 [ 3] sta ans107+3,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans107+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans107+2,spx ans@@+2,spx 1938 M @@adc.b, ?a+2,spx ans107+2,spx ans@@+2,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2BEA] 2BEA:E60F [ 3] lda ?a+2,spx 1938 M [2BEC] 2BEC:E903 [ 3] adc ans107+2,spx 1938 M @_sta_ ans@@+2,spx 1938 M [2BEE] 2BEE:E703 [ 3] sta ans107+2,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans107+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans107+1,spx ans@@+1,spx 1938 M @@adc.b, ?a+1,spx ans107+1,spx ans@@+1,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2BF0] 2BF0:E60E [ 3] lda ?a+1,spx 1938 M [2BF2] 2BF2:E902 [ 3] adc ans107+1,spx 1938 M @_sta_ ans@@+1,spx 1938 M [2BF4] 2BF4:E702 [ 3] sta ans107+1,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans107+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans107+0,spx ans@@+0,spx 1938 M @@adc.b, ?a+0,spx ans107+0,spx ans@@+0,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [2BF6] 2BF6:E60D [ 3] lda ?a+0,spx 1938 M [2BF8] 2BF8:E901 [ 3] adc ans107+0,spx 1938 M @_sta_ ans@@+0,spx 1938 M [2BFA] 2BFA:E701 [ 3] sta ans107+0,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 endm 1939 1940 M Skip@@ @lsl.s ?a,spx ;Multiplicand*=2 for each bit 1940 M mset # 1940 M mreq 1 1940 M @@_nosize_ ?a,spx 1940 M mset # 1940 M mset 0,mstop [lsl.s] No size (?a,spx) 1940 M endm 1940 M mdo 1940 M [2BFC] 2BFC:6813 [ 5] lsl ?a+6,spx 1940 M mloop ::?a 1940 M [2BFE] 2BFE:6912 [ 5] rol ?a+5,spx 1940 M mloop ::?a 1940 M [2C00] 2C00:6911 [ 5] rol ?a+4,spx 1940 M mloop ::?a 1940 M [2C02] 2C02:6910 [ 5] rol ?a+3,spx 1940 M mloop ::?a 1940 M [2C04] 2C04:690F [ 5] rol ?a+2,spx 1940 M mloop ::?a 1940 M [2C06] 2C06:690E [ 5] rol ?a+1,spx 1940 M mloop ::?a 1940 M [2C08] 2C08:690D [ 5] rol ?a+0,spx 1940 M mloop ::?a 1940 endm 1941 [2C0A] 2C0A:7BB6 (2BC2) [ 6] dbnz bits@@,spx,Loop@@ 1942 #temp :cycles*MATHSIZE+:temp 1943 [2C0C] 2C0C:86 [ 3] pula ;remove bit counter 1945 ;-------------------------------------- 1946 ; copy result to B while removing from stack 1947 ;-------------------------------------- 1948 [2C0D] 2C0D:AE07 [ 2] ldx #?WORD 1949 #temp :cycles+:temp 1950 [2C0F] 2C0F:86 [ 3] CopyResult@@ pula 1951 [2C10] 2C10:9EE7 13 [ 4] sta ?b,sp 1952 [2C13] 2C13:5BFA (2C0F) [ 4] dbnzx CopyResult@@ 1953 1954 #spadd 1-?WORD 1955 #temp :cycles*?WORD+:temp 1956 [2C15] 2C15:CC2E 64 [ 4] jmp ?RemoveAndReturn 1957 1958 1F9F ?MulCycles equ :temp+:cycles 1959 1960 ;******************************************************************************* 1961 ; Purpose: Divide N1 by N2 and place quotient on top-of-stack. N1 & N2 removed 1962 ; Input : [TOS+?WORD] = Divisor (N2) 1963 ; : [TOS] = Dividend (N1) 1964 ; Output : [TOS] = Quotient 1965 ; : Carry Set on error (division by zero) 1966 ; Note(s): 1967 #spauto :ab 1968 1969 2C18 ?Divide proc 1970 [2C18] 2C18:8789 8B [ 6] push 1971 1972 [2C1B] 2C1B:A601 [ 2] lda #?DIVOP_ ;flag for DIV operation 1974 [2C1D] 2C1D:87 [ 2] psha 1975 [2C1E] 2C1E:95 [ 2] tsx 1976 [2C1F] 2C1F:E606 [ 3] lda ?a,spx 1977 [2C21] 2C21:E80D [ 3] eor ?b,spx 1978 [2C23] 2C23:86 [ 3] pula 1979 [2C24] 2C24:2A02 (2C28) [ 3] bpl Skip@@ 1980 [2C26] 2C26:AA80 [ 2] ora #?SIGN_ ;flag for negative 1981 2C28 Skip@@ 1983 [2C28] 2C28:87 [ 2] psha ;save flags on stack 1984 [2C29] 2C29:203C (2C67) [ 3] bra ?DivStart 1985 1986 001F ?DivCycles equ :cycles 1987 1988 ;******************************************************************************* 1989 ; Purpose: Divide N1 by N2 and place remainder on top-of-stack. N1 & N2 removed 1990 ; Input : [TOS+?WORD] = Divisor (N2) 1991 ; : [TOS] = Dividend (N1) 1992 ; Output : [TOS] = Remainder 1993 ; : Carry Set on error (division by zero) 1994 ; Note(s): 1995 #spauto :ab 1996 FFFFFFFF ?pc equ ::,:ab 1997 1998 2C2B ?Modulo proc 1999 [2C2B] 2C2B:8789 8B [ 6] push 2000 2001 [2C2E] 2C2E:4F [ 1] clra ;flag for MOD operation 2003 [2C2F] 2C2F:9E6D 06 [ 5] tst ?a,sp 2004 [2C32] 2C32:2A02 (2C36) [ 3] bpl Skip@@ 2005 [2C34] 2C34:AA80 [ 2] ora #?SIGN_ ;flag for negative 2006 2C36 Skip@@ 2008 [2C36] 2C36:87 [ 2] psha ;save flags on stack 2009 [2C37] 2C37:202E (2C67) [ 3] bra ?DivStart 2010 2011 0016 ?ModCycles equ :cycles 2012 2013 ;******************************************************************************* 2014 2015 #temp 2017 2C39 ?AbsX proc 2018 [2C39] 2C39:7D [ 3] tst ,ax 2019 [2C3A] 2C3A:2A24 (2C60) [ 3] bpl Done@@ 2020 #temp :cycles 2021 0000 var@@ equ 0,?WORD 2022 M ?NegX @neg.s var@@,ax 2022 M mset # 2022 M mreq 1 2022 M @@_nosize_ var110,ax 2022 M mset # 2022 M mset 0,mstop [neg.s] No size (var110,ax) 2022 M endm 2022 M mdo 2022 M [2C3C] 2C3C:73 [ 4] com var110+0,ax 2022 M mloop ::var110-1 2022 M [2C3D] 2C3D:6301 [ 5] com var110+1,ax 2022 M mloop ::var110-1 2022 M [2C3F] 2C3F:6302 [ 5] com var110+2,ax 2022 M mloop ::var110-1 2022 M [2C41] 2C41:6303 [ 5] com var110+3,ax 2022 M mloop ::var110-1 2022 M [2C43] 2C43:6304 [ 5] com var110+4,ax 2022 M mloop ::var110-1 2022 M [2C45] 2C45:6305 [ 5] com var110+5,ax 2022 M mloop ::var110-1 2022 M [2C47] 2C47:6006 [ 5] neg var110+6,ax 2022 M mdo 2022 M [2C49] 2C49:2615 (2C60) [ 3] bne Done$$$ 2022 M [2C4B] 2C4B:6C05 [ 5] inc var110+5,ax 2022 M mloop ::var110-1 2022 M [2C4D] 2C4D:2611 (2C60) [ 3] bne Done$$$ 2022 M [2C4F] 2C4F:6C04 [ 5] inc var110+4,ax 2022 M mloop ::var110-1 2022 M [2C51] 2C51:260D (2C60) [ 3] bne Done$$$ 2022 M [2C53] 2C53:6C03 [ 5] inc var110+3,ax 2022 M mloop ::var110-1 2022 M [2C55] 2C55:2609 (2C60) [ 3] bne Done$$$ 2022 M [2C57] 2C57:6C02 [ 5] inc var110+2,ax 2022 M mloop ::var110-1 2022 M [2C59] 2C59:2605 (2C60) [ 3] bne Done$$$ 2022 M [2C5B] 2C5B:6C01 [ 5] inc var110+1,ax 2022 M mloop ::var110-1 2022 M [2C5D] 2C5D:2601 (2C60) [ 3] bne Done$$$ 2022 M [2C5F] 2C5F:7C [ 4] inc var110+0,ax 2022 M mloop ::var110-1 2022 M 2C60 Done$$$ 2022 endm 2023 [2C60] 2C60:81 [ 6] Done@@ rts 2024 2025 0057 ?AbsXCycles equ :cycles 2026 0051 ?NegxCycles equ ?AbsXCycles-:temp 2028 2029 ;******************************************************************************* 2030 2031 0000 ?SF equ 0 ;stack frame (for X-index use) 2032 2033 0000 ?quotient next ?SF,?WORD 2034 0007 ?remainder next ?SF,?WORD 2035 000E ?temp next ?SF,?WORD 2036 0015 ?bits next ?SF 2037 0016 ?flags next ?SF 2038 2039 0001 ?DIVOP_ equ %00000001 ;1 = DIV, 0 = MOD 2040 0080 ?SIGN_ equ %10000000 ;result sign (1 = negative) 2041 2042 #push 2043 2044 [2C61] 2C61:A717 [ 2] ?DivError ais #?SF ;de-allocate temporaries 2045 [2C63] 2C63:99 [ 1] sec ;indicate error condition 2046 [2C64] 2C64:CC2E 64 [ 4] jmp ?RemoveAndReturn 2047 2048 #pull 2049 ;------------------------------------------------------------------------------- 2050 2C67 ?DivStart proc 2051 0001 dividend@@ equ ?a,::?a 2052 0008 divisor@@ equ ?b,::?b 2053 0008 ans@@ equ ?b,::?b ;result overwrites divisor 2054 2056 M @lea dividend@@,sp 2056 M mset # 2056 M [2C67] 2C67:95 [ 2] tsx 2056 M [2C68] 2C68:AF06 [ 2] !aix #dividend111+:tsx 2056 mexit 2057 [2C6A] 2C6A:ADCD (2C39) [ 5] bsr ?AbsX 2058 M @lea divisor@@,sp 2058 M mset # 2058 M [2C6C] 2C6C:95 [ 2] tsx 2058 M [2C6D] 2C6D:AF0D [ 2] !aix #divisor111+:tsx 2058 mexit 2059 [2C6F] 2C6F:ADC8 (2C39) [ 5] bsr ?AbsX 2060 #Cycles ?AbsXCycles*2+:cycles 2062 [2C71] 2C71:A7EA [ 2] ais #-?SF+1 ;quotient, remainder, and temp 2063 [2C73] 2C73:95 [ 2] tsx ;(+1 for already pushed Flag) 2064 2065 ; remainder := 0 2066 ; quotient := 0 2067 2068 M @clr.s ?remainder,x 2068 M mset #' ' 2068 M mreq 1 2068 M @@_nosize_ ?remainder,x 2068 M mset # 2068 M mset 0,mstop [clr.s] No size (?remainder,x) 2068 M endm 2068 M mdef 2,::?remainder 2068 M mdo 2068 M [2C74] 2C74:6F07 [ 5] clr ?remainder+0,x 2068 M mloop ::?remainder 2068 M [2C76] 2C76:6F08 [ 5] clr ?remainder+1,x 2068 M mloop ::?remainder 2068 M [2C78] 2C78:6F09 [ 5] clr ?remainder+2,x 2068 M mloop ::?remainder 2068 M [2C7A] 2C7A:6F0A [ 5] clr ?remainder+3,x 2068 M mloop ::?remainder 2068 M [2C7C] 2C7C:6F0B [ 5] clr ?remainder+4,x 2068 M mloop ::?remainder 2068 M [2C7E] 2C7E:6F0C [ 5] clr ?remainder+5,x 2068 M mloop ::?remainder 2068 M [2C80] 2C80:6F0D [ 5] clr ?remainder+6,x 2068 M mloop ::?remainder 2068 endm 2069 M @clr.s ?quotient,x 2069 M mset #' ' 2069 M mreq 1 2069 M @@_nosize_ ?quotient,x 2069 M mset # 2069 M mset 0,mstop [clr.s] No size (?quotient,x) 2069 M endm 2069 M mdef 2,::?quotient 2069 M mdo 2069 M [2C82] 2C82:7F [ 4] clr ?quotient+0,x 2069 M mloop ::?quotient 2069 M [2C83] 2C83:6F01 [ 5] clr ?quotient+1,x 2069 M mloop ::?quotient 2069 M [2C85] 2C85:6F02 [ 5] clr ?quotient+2,x 2069 M mloop ::?quotient 2069 M [2C87] 2C87:6F03 [ 5] clr ?quotient+3,x 2069 M mloop ::?quotient 2069 M [2C89] 2C89:6F04 [ 5] clr ?quotient+4,x 2069 M mloop ::?quotient 2069 M [2C8B] 2C8B:6F05 [ 5] clr ?quotient+5,x 2069 M mloop ::?quotient 2069 M [2C8D] 2C8D:6F06 [ 5] clr ?quotient+6,x 2069 M mloop ::?quotient 2069 endm 2070 2071 ; first, test for division by zero error 2072 2073 M @_tst_.s divisor@@,spx 2073 M mset # 2073 M mreq 1 2073 M @@_nosize_ divisor111,spx 2073 M mset # 2073 M mset 0,mstop [_tst_.s] No size (divisor111,spx) 2073 M endm 2073 M mdo 2073 M [2C8F] 2C8F:E623 [ 3] lda divisor111+0,spx 2073 M mloop ::divisor111 2073 M [2C91] 2C91:EA24 [ 3] ora divisor111+1,spx 2073 M mloop ::divisor111 2073 M [2C93] 2C93:EA25 [ 3] ora divisor111+2,spx 2073 M mloop ::divisor111 2073 M [2C95] 2C95:EA26 [ 3] ora divisor111+3,spx 2073 M mloop ::divisor111 2073 M [2C97] 2C97:EA27 [ 3] ora divisor111+4,spx 2073 M mloop ::divisor111 2073 M [2C99] 2C99:EA28 [ 3] ora divisor111+5,spx 2073 M mloop ::divisor111 2073 M [2C9B] 2C9B:EA29 [ 3] ora divisor111+6,spx 2073 M mloop ::divisor111 2073 endm 2074 [2C9D] 2C9D:27C2 (2C61) [ 3] beq ?DivError 2075 2076 ; if Dividend = 0, we're done 2077 2078 M @_tst_.s dividend@@,spx 2078 M mset # 2078 M mreq 1 2078 M @@_nosize_ dividend111,spx 2078 M mset # 2078 M mset 0,mstop [_tst_.s] No size (dividend111,spx) 2078 M endm 2078 M mdo 2078 M [2C9F] 2C9F:E61C [ 3] lda dividend111+0,spx 2078 M mloop ::dividend111 2078 M [2CA1] 2CA1:EA1D [ 3] ora dividend111+1,spx 2078 M mloop ::dividend111 2078 M [2CA3] 2CA3:EA1E [ 3] ora dividend111+2,spx 2078 M mloop ::dividend111 2078 M [2CA5] 2CA5:EA1F [ 3] ora dividend111+3,spx 2078 M mloop ::dividend111 2078 M [2CA7] 2CA7:EA20 [ 3] ora dividend111+4,spx 2078 M mloop ::dividend111 2078 M [2CA9] 2CA9:EA21 [ 3] ora dividend111+5,spx 2078 M mloop ::dividend111 2078 M [2CAB] 2CAB:EA22 [ 3] ora dividend111+6,spx 2078 M mloop ::dividend111 2078 endm 2079 [2CAD] 2CAD:2603 CC2E 18 [ 7] !jeq Done@@ 2080 2081 ; if (divisor = dividend) then quotient := 1; return 2082 ; if (divisor > dividend) then remainder := dividend; return 2083 2084 M @_cmp_.s divisor@@,spx dividend@@,spx 2084 M mset #' ' 2084 M mreq 1,2:[#]Operand1 [#]Operand2 2084 M @@_samesize_ divisor111,spx dividend@@,spx 2084 M mreq 1,2:Operand1,Operand2[,Operand]* 2084 M mset 0 2084 M mdo 2084 M mswap 1,1 2084 M @@_nosize_ divisor111,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (divisor111,spx) 2084 M endm 2084 M mset 0,divisor111,spx 2084 M mloop :n 2084 M mswap 1,2 2084 M @@_nosize_ dividend@@,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (dividend111,spx) 2084 M endm 2084 M mloop :n 2084 M endm 2084 M #temp 1 2084 M #temp ::divisor111 2084 M #temp ::dividend@@ 2084 M mdo 2084 M [2CB2] 2CB2:E623 [ 3] lda divisor111+0,spx 2084 M [2CB4] 2CB4:E11C [ 3] cmpa dividend@@+0,spx 2084 M [2CB6] 2CB6:2622 (2CDA) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2CB8] 2CB8:E624 [ 3] lda divisor111+1,spx 2084 M [2CBA] 2CBA:E11D [ 3] cmpa dividend@@+1,spx 2084 M [2CBC] 2CBC:261C (2CDA) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2CBE] 2CBE:E625 [ 3] lda divisor111+2,spx 2084 M [2CC0] 2CC0:E11E [ 3] cmpa dividend@@+2,spx 2084 M [2CC2] 2CC2:2616 (2CDA) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2CC4] 2CC4:E626 [ 3] lda divisor111+3,spx 2084 M [2CC6] 2CC6:E11F [ 3] cmpa dividend@@+3,spx 2084 M [2CC8] 2CC8:2610 (2CDA) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2CCA] 2CCA:E627 [ 3] lda divisor111+4,spx 2084 M [2CCC] 2CCC:E120 [ 3] cmpa dividend@@+4,spx 2084 M [2CCE] 2CCE:260A (2CDA) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2CD0] 2CD0:E628 [ 3] lda divisor111+5,spx 2084 M [2CD2] 2CD2:E121 [ 3] cmpa dividend@@+5,spx 2084 M [2CD4] 2CD4:2604 (2CDA) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [2CD6] 2CD6:E629 [ 3] lda divisor111+6,spx 2084 M [2CD8] 2CD8:E122 [ 3] cmpa dividend@@+6,spx 2084 M mloop :temp 2084 M 2CDA Done$$$ 2084 endm 2085 [2CDA] 2CDA:2604 (2CE0) [ 3] bne NotEqual@@ 2086 2087 [2CDC] 2CDC:6C06 [ 5] inc ?quotient+{::?quotient-1},x ;quotient := 1 2088 [2CDE] 2CDE:201E (2CFE) [ 3] bra ??DivExit ;and get out 2089 2090 2CE0 NotEqual@@ ;@sub.s divisor@@,spx dividend@@,spx ;[2012.05.18 REDUNDANT] 2091 [2CE0] 2CE0:251F (2D01) [ 3] blo Continue@@ 2092 2093 M @mova.s dividend@@,spx ?remainder,x 2093 M mset #' ' 2093 M mreq 1,2:Source Destination 2093 M @@_samesize_ dividend111,spx ?remainder,x 2093 M mreq 1,2:Operand1,Operand2[,Operand]* 2093 M mset 0 2093 M mdo 2093 M mswap 1,1 2093 M @@_nosize_ dividend111,spx 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (dividend111,spx) 2093 M endm 2093 M mset 0,dividend111,spx 2093 M mloop :n 2093 M mswap 1,2 2093 M @@_nosize_ ?remainder,x 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (?remainder,x) 2093 M endm 2093 M mloop :n 2093 M endm 2093 M mset 0 2093 M mdo 2093 M [2CE2] 2CE2:E61C [ 3] lda dividend111+0,spx 2093 M [2CE4] 2CE4:E707 [ 3] sta ?remainder+0,x 2093 M mloop ::?remainder 2093 M [2CE6] 2CE6:E61D [ 3] lda dividend111+1,spx 2093 M [2CE8] 2CE8:E708 [ 3] sta ?remainder+1,x 2093 M mloop ::?remainder 2093 M [2CEA] 2CEA:E61E [ 3] lda dividend111+2,spx 2093 M [2CEC] 2CEC:E709 [ 3] sta ?remainder+2,x 2093 M mloop ::?remainder 2093 M [2CEE] 2CEE:E61F [ 3] lda dividend111+3,spx 2093 M [2CF0] 2CF0:E70A [ 3] sta ?remainder+3,x 2093 M mloop ::?remainder 2093 M [2CF2] 2CF2:E620 [ 3] lda dividend111+4,spx 2093 M [2CF4] 2CF4:E70B [ 3] sta ?remainder+4,x 2093 M mloop ::?remainder 2093 M [2CF6] 2CF6:E621 [ 3] lda dividend111+5,spx 2093 M [2CF8] 2CF8:E70C [ 3] sta ?remainder+5,x 2093 M mloop ::?remainder 2093 M [2CFA] 2CFA:E622 [ 3] lda dividend111+6,spx 2093 M [2CFC] 2CFC:E70D [ 3] sta ?remainder+6,x 2093 M mloop ::?remainder 2093 endm 2094 2CFE ??DivExit ;and get out 2098 [2CFE] 2CFE:CC2E 18 [ 4] jmp Done@@ 2100 2101 [2D01] 2D01:A638 [ 2] Continue@@ lda #MATHSIZE 2102 [2D03] 2D03:E715 [ 3] sta ?bits,x ;bits := 64/56/48/40/32/24/16-bit 2103 2104 ; while (remainder < divisor) do 2105 2106 M While@@ @cop ;in case of many iterations 2106 M [2D05] 2D05:C718 00 [ 4] sta COP 2106 endm 2107 2108 M @sub.s ?remainder,x divisor@@,spx 2108 M mset #' ' 2108 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2108 M @@_samesize_ ?remainder,x divisor111,spx 2108 M mreq 1,2:Operand1,Operand2[,Operand]* 2108 M mset 0 2108 M mdo 2108 M mswap 1,1 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (?remainder,x) 2108 M endm 2108 M mset 0,?remainder,x 2108 M mloop :n 2108 M mswap 1,2 2108 M @@_nosize_ divisor111,spx 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (divisor111,spx) 2108 M endm 2108 M mloop :n 2108 M endm 2108 M #temp 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [sub.s] No size (?remainder,x) 2108 M endm 2108 M #temp ::?remainder 2108 M mset 0,sub 2108 M mdo 2108 M [2D08] 2D08:E60D [ 3] lda ?remainder+6,x 2108 M [2D0A] 2D0A:E029 [ 3] sub divisor111+6,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2D0C] 2D0C:E60C [ 3] lda ?remainder+5,x 2108 M [2D0E] 2D0E:E228 [ 3] sbc divisor111+5,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2D10] 2D10:E60B [ 3] lda ?remainder+4,x 2108 M [2D12] 2D12:E227 [ 3] sbc divisor111+4,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2D14] 2D14:E60A [ 3] lda ?remainder+3,x 2108 M [2D16] 2D16:E226 [ 3] sbc divisor111+3,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2D18] 2D18:E609 [ 3] lda ?remainder+2,x 2108 M [2D1A] 2D1A:E225 [ 3] sbc divisor111+2,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2D1C] 2D1C:E608 [ 3] lda ?remainder+1,x 2108 M [2D1E] 2D1E:E224 [ 3] sbc divisor111+1,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [2D20] 2D20:E607 [ 3] lda ?remainder+0,x 2108 M [2D22] 2D22:E223 [ 3] sbc divisor111+0,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 endm 2109 [2D24] 2D24:243C (2D62) [ 3] bcc EndWhile@@ 2110 2111 ; remainder := (remainder shl 1) or msb(dividend) 2112 ;-------------------------------------- ;2012.12.04 optimization (moved up this code from before DEC to here) 2113 M @mova.s dividend@@,spx ?temp,x ; temp := dividend 2113 M mset #' ' 2113 M mreq 1,2:Source Destination 2113 M @@_samesize_ dividend111,spx ?temp,x 2113 M mreq 1,2:Operand1,Operand2[,Operand]* 2113 M mset 0 2113 M mdo 2113 M mswap 1,1 2113 M @@_nosize_ dividend111,spx 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (dividend111,spx) 2113 M endm 2113 M mset 0,dividend111,spx 2113 M mloop :n 2113 M mswap 1,2 2113 M @@_nosize_ ?temp,x 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (?temp,x) 2113 M endm 2113 M mloop :n 2113 M endm 2113 M mset 0 2113 M mdo 2113 M [2D26] 2D26:E61C [ 3] lda dividend111+0,spx 2113 M [2D28] 2D28:E70E [ 3] sta ?temp+0,x 2113 M mloop ::?temp 2113 M [2D2A] 2D2A:E61D [ 3] lda dividend111+1,spx 2113 M [2D2C] 2D2C:E70F [ 3] sta ?temp+1,x 2113 M mloop ::?temp 2113 M [2D2E] 2D2E:E61E [ 3] lda dividend111+2,spx 2113 M [2D30] 2D30:E710 [ 3] sta ?temp+2,x 2113 M mloop ::?temp 2113 M [2D32] 2D32:E61F [ 3] lda dividend111+3,spx 2113 M [2D34] 2D34:E711 [ 3] sta ?temp+3,x 2113 M mloop ::?temp 2113 M [2D36] 2D36:E620 [ 3] lda dividend111+4,spx 2113 M [2D38] 2D38:E712 [ 3] sta ?temp+4,x 2113 M mloop ::?temp 2113 M [2D3A] 2D3A:E621 [ 3] lda dividend111+5,spx 2113 M [2D3C] 2D3C:E713 [ 3] sta ?temp+5,x 2113 M mloop ::?temp 2113 M [2D3E] 2D3E:E622 [ 3] lda dividend111+6,spx 2113 M [2D40] 2D40:E714 [ 3] sta ?temp+6,x 2113 M mloop ::?temp 2113 endm 2114 M @lsl.s dividend@@,spx ; dividend := dividend shl 1 2114 M mset # 2114 M mreq 1 2114 M @@_nosize_ dividend111,spx 2114 M mset # 2114 M mset 0,mstop [lsl.s] No size (dividend111,spx) 2114 M endm 2114 M mdo 2114 M [2D42] 2D42:6822 [ 5] lsl dividend111+6,spx 2114 M mloop ::dividend111 2114 M [2D44] 2D44:6921 [ 5] rol dividend111+5,spx 2114 M mloop ::dividend111 2114 M [2D46] 2D46:6920 [ 5] rol dividend111+4,spx 2114 M mloop ::dividend111 2114 M [2D48] 2D48:691F [ 5] rol dividend111+3,spx 2114 M mloop ::dividend111 2114 M [2D4A] 2D4A:691E [ 5] rol dividend111+2,spx 2114 M mloop ::dividend111 2114 M [2D4C] 2D4C:691D [ 5] rol dividend111+1,spx 2114 M mloop ::dividend111 2114 M [2D4E] 2D4E:691C [ 5] rol dividend111+0,spx 2114 M mloop ::dividend111 2114 endm 2115 ;-------------------------------------- 2116 M @rol.s ?remainder,x 2116 M mset # 2116 M mreq 1 2116 M @@_nosize_ ?remainder,x 2116 M mset # 2116 M mset 0,mstop [rol.s] No size (?remainder,x) 2116 M endm 2116 M mdo 2116 M [2D50] 2D50:690D [ 5] rol ?remainder+6,x 2116 M mloop ::?remainder 2116 M [2D52] 2D52:690C [ 5] rol ?remainder+5,x 2116 M mloop ::?remainder 2116 M [2D54] 2D54:690B [ 5] rol ?remainder+4,x 2116 M mloop ::?remainder 2116 M [2D56] 2D56:690A [ 5] rol ?remainder+3,x 2116 M mloop ::?remainder 2116 M [2D58] 2D58:6909 [ 5] rol ?remainder+2,x 2116 M mloop ::?remainder 2116 M [2D5A] 2D5A:6908 [ 5] rol ?remainder+1,x 2116 M mloop ::?remainder 2116 M [2D5C] 2D5C:6907 [ 5] rol ?remainder+0,x 2116 M mloop ::?remainder 2116 endm 2117 [2D5E] 2D5E:6A15 [ 5] dec ?bits,x ; bits := bits - 1 2118 2119 ; end while 2120 2121 [2D60] 2D60:20A3 (2D05) [ 3] bra While@@ 2122 2D62 EndWhile@@ 2123 M @mova.s ?temp,x dividend@@,spx ; dividend := temp 2123 M mset #' ' 2123 M mreq 1,2:Source Destination 2123 M @@_samesize_ ?temp,x dividend111,spx 2123 M mreq 1,2:Operand1,Operand2[,Operand]* 2123 M mset 0 2123 M mdo 2123 M mswap 1,1 2123 M @@_nosize_ ?temp,x 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (?temp,x) 2123 M endm 2123 M mset 0,?temp,x 2123 M mloop :n 2123 M mswap 1,2 2123 M @@_nosize_ dividend111,spx 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (dividend111,spx) 2123 M endm 2123 M mloop :n 2123 M endm 2123 M mset 0 2123 M mdo 2123 M [2D62] 2D62:E60E [ 3] lda ?temp+0,x 2123 M [2D64] 2D64:E71C [ 3] sta dividend111+0,spx 2123 M mloop ::dividend111 2123 M [2D66] 2D66:E60F [ 3] lda ?temp+1,x 2123 M [2D68] 2D68:E71D [ 3] sta dividend111+1,spx 2123 M mloop ::dividend111 2123 M [2D6A] 2D6A:E610 [ 3] lda ?temp+2,x 2123 M [2D6C] 2D6C:E71E [ 3] sta dividend111+2,spx 2123 M mloop ::dividend111 2123 M [2D6E] 2D6E:E611 [ 3] lda ?temp+3,x 2123 M [2D70] 2D70:E71F [ 3] sta dividend111+3,spx 2123 M mloop ::dividend111 2123 M [2D72] 2D72:E612 [ 3] lda ?temp+4,x 2123 M [2D74] 2D74:E720 [ 3] sta dividend111+4,spx 2123 M mloop ::dividend111 2123 M [2D76] 2D76:E613 [ 3] lda ?temp+5,x 2123 M [2D78] 2D78:E721 [ 3] sta dividend111+5,spx 2123 M mloop ::dividend111 2123 M [2D7A] 2D7A:E614 [ 3] lda ?temp+6,x 2123 M [2D7C] 2D7C:E722 [ 3] sta dividend111+6,spx 2123 M mloop ::dividend111 2123 endm 2124 M @lsr.s ?remainder,x ; remainder := remainder shr 1 2124 M mset # 2124 M mreq 1 2124 M @@_nosize_ ?remainder,x 2124 M mset # 2124 M mset 0,mstop [lsr.s] No size (?remainder,x) 2124 M endm 2124 M mdo 2124 M [2D7E] 2D7E:6407 [ 5] lsr ?remainder+0,x 2124 M mloop ::?remainder 2124 M [2D80] 2D80:6608 [ 5] ror ?remainder+1,x 2124 M mloop ::?remainder 2124 M [2D82] 2D82:6609 [ 5] ror ?remainder+2,x 2124 M mloop ::?remainder 2124 M [2D84] 2D84:660A [ 5] ror ?remainder+3,x 2124 M mloop ::?remainder 2124 M [2D86] 2D86:660B [ 5] ror ?remainder+4,x 2124 M mloop ::?remainder 2124 M [2D88] 2D88:660C [ 5] ror ?remainder+5,x 2124 M mloop ::?remainder 2124 M [2D8A] 2D8A:660D [ 5] ror ?remainder+6,x 2124 M mloop ::?remainder 2124 endm 2125 [2D8C] 2D8C:6C15 [ 5] inc ?bits,x ; bits := bits + 1 2126 2127 ; for i := bitCounter-1 downto 0 do 2128 2129 M For@@ @cop ;in case of many iterations 2129 M [2D8E] 2D8E:C718 00 [ 4] sta COP 2129 endm 2130 2131 [2D91] 2D91:6D15 [ 4] tst ?bits,x 2135 [2D93] 2D93:2603 CC2E 18 [ 7] jeq Done@@ 2137 [2D98] 2D98:6A15 [ 5] dec ?bits,x 2138 2139 ; remainder := (remainder shl 1) or msb(dividend) 2140 ; dividend := dividend shl 1 2141 2142 M @lsl.s dividend@@,spx ;2012.12.04 optimization 2142 M mset # 2142 M mreq 1 2142 M @@_nosize_ dividend111,spx 2142 M mset # 2142 M mset 0,mstop [lsl.s] No size (dividend111,spx) 2142 M endm 2142 M mdo 2142 M [2D9A] 2D9A:6822 [ 5] lsl dividend111+6,spx 2142 M mloop ::dividend111 2142 M [2D9C] 2D9C:6921 [ 5] rol dividend111+5,spx 2142 M mloop ::dividend111 2142 M [2D9E] 2D9E:6920 [ 5] rol dividend111+4,spx 2142 M mloop ::dividend111 2142 M [2DA0] 2DA0:691F [ 5] rol dividend111+3,spx 2142 M mloop ::dividend111 2142 M [2DA2] 2DA2:691E [ 5] rol dividend111+2,spx 2142 M mloop ::dividend111 2142 M [2DA4] 2DA4:691D [ 5] rol dividend111+1,spx 2142 M mloop ::dividend111 2142 M [2DA6] 2DA6:691C [ 5] rol dividend111+0,spx 2142 M mloop ::dividend111 2142 endm 2143 M @rol.s ?remainder,x 2143 M mset # 2143 M mreq 1 2143 M @@_nosize_ ?remainder,x 2143 M mset # 2143 M mset 0,mstop [rol.s] No size (?remainder,x) 2143 M endm 2143 M mdo 2143 M [2DA8] 2DA8:690D [ 5] rol ?remainder+6,x 2143 M mloop ::?remainder 2143 M [2DAA] 2DAA:690C [ 5] rol ?remainder+5,x 2143 M mloop ::?remainder 2143 M [2DAC] 2DAC:690B [ 5] rol ?remainder+4,x 2143 M mloop ::?remainder 2143 M [2DAE] 2DAE:690A [ 5] rol ?remainder+3,x 2143 M mloop ::?remainder 2143 M [2DB0] 2DB0:6909 [ 5] rol ?remainder+2,x 2143 M mloop ::?remainder 2143 M [2DB2] 2DB2:6908 [ 5] rol ?remainder+1,x 2143 M mloop ::?remainder 2143 M [2DB4] 2DB4:6907 [ 5] rol ?remainder+0,x 2143 M mloop ::?remainder 2143 endm 2144 2145 ; temp := remainder - divisor 2146 2147 M @sub.s ?remainder,x divisor@@,spx ?temp,x 2147 M mset #' ' 2147 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2147 M @@_samesize_ ?remainder,x divisor111,spx ?temp,x 2147 M mreq 1,2:Operand1,Operand2[,Operand]* 2147 M mset 0 2147 M mdo 2147 M mswap 1,1 2147 M @@_nosize_ ?remainder,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?remainder,x) 2147 M endm 2147 M mset 0,?remainder,x 2147 M mloop :n 2147 M mswap 1,2 2147 M @@_nosize_ divisor111,spx 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (divisor111,spx) 2147 M endm 2147 M mloop :n 2147 M mswap 1,3 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?temp,x) 2147 M endm 2147 M mloop :n 2147 M endm 2147 M #temp 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [sub.s] No size (?temp,x) 2147 M endm 2147 M #temp ::?temp 2147 M mset 0,sub 2147 M mdo 2147 M [2DB6] 2DB6:E60D [ 3] lda ?remainder+6,x 2147 M [2DB8] 2DB8:E029 [ 3] sub divisor111+6,spx 2147 M [2DBA] 2DBA:E714 [ 3] sta ?temp+6,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2DBC] 2DBC:E60C [ 3] lda ?remainder+5,x 2147 M [2DBE] 2DBE:E228 [ 3] sbc divisor111+5,spx 2147 M [2DC0] 2DC0:E713 [ 3] sta ?temp+5,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2DC2] 2DC2:E60B [ 3] lda ?remainder+4,x 2147 M [2DC4] 2DC4:E227 [ 3] sbc divisor111+4,spx 2147 M [2DC6] 2DC6:E712 [ 3] sta ?temp+4,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2DC8] 2DC8:E60A [ 3] lda ?remainder+3,x 2147 M [2DCA] 2DCA:E226 [ 3] sbc divisor111+3,spx 2147 M [2DCC] 2DCC:E711 [ 3] sta ?temp+3,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2DCE] 2DCE:E609 [ 3] lda ?remainder+2,x 2147 M [2DD0] 2DD0:E225 [ 3] sbc divisor111+2,spx 2147 M [2DD2] 2DD2:E710 [ 3] sta ?temp+2,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2DD4] 2DD4:E608 [ 3] lda ?remainder+1,x 2147 M [2DD6] 2DD6:E224 [ 3] sbc divisor111+1,spx 2147 M [2DD8] 2DD8:E70F [ 3] sta ?temp+1,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [2DDA] 2DDA:E607 [ 3] lda ?remainder+0,x 2147 M [2DDC] 2DDC:E223 [ 3] sbc divisor111+0,spx 2147 M [2DDE] 2DDE:E70E [ 3] sta ?temp+0,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 endm 2148 2149 ; q := not msb(temp) 2150 2151 [2DE0] 2DE0:E60E [ 3] lda ?temp,x 2152 [2DE2] 2DE2:A880 [ 2] eor #%10000000 ;invert msb 2153 [2DE4] 2DE4:A480 [ 2] and #%10000000 ;isolate msb 2154 2155 ; quotient := (quotient shl 1) or q 2156 2157 [2DE6] 2DE6:87 [ 2] psha 2158 [2DE7] 2DE7:48 [ 1] lsla 2159 [2DE8] 2DE8:86 [ 3] pula 2160 2161 M @rol.s ?quotient,x 2161 M mset # 2161 M mreq 1 2161 M @@_nosize_ ?quotient,x 2161 M mset # 2161 M mset 0,mstop [rol.s] No size (?quotient,x) 2161 M endm 2161 M mdo 2161 M [2DE9] 2DE9:6906 [ 5] rol ?quotient+6,x 2161 M mloop ::?quotient 2161 M [2DEB] 2DEB:6905 [ 5] rol ?quotient+5,x 2161 M mloop ::?quotient 2161 M [2DED] 2DED:6904 [ 5] rol ?quotient+4,x 2161 M mloop ::?quotient 2161 M [2DEF] 2DEF:6903 [ 5] rol ?quotient+3,x 2161 M mloop ::?quotient 2161 M [2DF1] 2DF1:6902 [ 5] rol ?quotient+2,x 2161 M mloop ::?quotient 2161 M [2DF3] 2DF3:6901 [ 5] rol ?quotient+1,x 2161 M mloop ::?quotient 2161 M [2DF5] 2DF5:79 [ 4] rol ?quotient+0,x 2161 M mloop ::?quotient 2161 endm 2162 2163 ; if q <> 0 then 2164 2165 [2DF6] 2DF6:4100 95(2D8E) [ 4] cbeqa #0,For@@ 2166 2167 ; remainder := temp 2168 2169 M @mova.s ?temp,x ?remainder,x 2169 M mset #' ' 2169 M mreq 1,2:Source Destination 2169 M @@_samesize_ ?temp,x ?remainder,x 2169 M mreq 1,2:Operand1,Operand2[,Operand]* 2169 M mset 0 2169 M mdo 2169 M mswap 1,1 2169 M @@_nosize_ ?temp,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?temp,x) 2169 M endm 2169 M mset 0,?temp,x 2169 M mloop :n 2169 M mswap 1,2 2169 M @@_nosize_ ?remainder,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?remainder,x) 2169 M endm 2169 M mloop :n 2169 M endm 2169 M mset 0 2169 M mdo 2169 M [2DF9] 2DF9:E60E [ 3] lda ?temp+0,x 2169 M [2DFB] 2DFB:E707 [ 3] sta ?remainder+0,x 2169 M mloop ::?remainder 2169 M [2DFD] 2DFD:E60F [ 3] lda ?temp+1,x 2169 M [2DFF] 2DFF:E708 [ 3] sta ?remainder+1,x 2169 M mloop ::?remainder 2169 M [2E01] 2E01:E610 [ 3] lda ?temp+2,x 2169 M [2E03] 2E03:E709 [ 3] sta ?remainder+2,x 2169 M mloop ::?remainder 2169 M [2E05] 2E05:E611 [ 3] lda ?temp+3,x 2169 M [2E07] 2E07:E70A [ 3] sta ?remainder+3,x 2169 M mloop ::?remainder 2169 M [2E09] 2E09:E612 [ 3] lda ?temp+4,x 2169 M [2E0B] 2E0B:E70B [ 3] sta ?remainder+4,x 2169 M mloop ::?remainder 2169 M [2E0D] 2E0D:E613 [ 3] lda ?temp+5,x 2169 M [2E0F] 2E0F:E70C [ 3] sta ?remainder+5,x 2169 M mloop ::?remainder 2169 M [2E11] 2E11:E614 [ 3] lda ?temp+6,x 2169 M [2E13] 2E13:E70D [ 3] sta ?remainder+6,x 2169 M mloop ::?remainder 2169 endm 2170 2171 ; end if -- end for 2172 2176 [2E15] 2E15:CC2D 8E [ 4] jmp For@@ 2178 2179 [2E18] 2E18:E616 [ 3] Done@@ lda ?flags,x 2180 [2E1A] 2E1A:A501 [ 2] bit #?DIVOP_ 2181 [2E1C] 2E1C:271D (2E3B) [ 3] beq ExitMod@@ 2182 2183 03BE ?Cycles equ :cycles 2184 2185 ;ExitDiv@@ 2186 M @mova.s ?quotient,x ans@@,spx 2186 M mset #' ' 2186 M mreq 1,2:Source Destination 2186 M @@_samesize_ ?quotient,x ans111,spx 2186 M mreq 1,2:Operand1,Operand2[,Operand]* 2186 M mset 0 2186 M mdo 2186 M mswap 1,1 2186 M @@_nosize_ ?quotient,x 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (?quotient,x) 2186 M endm 2186 M mset 0,?quotient,x 2186 M mloop :n 2186 M mswap 1,2 2186 M @@_nosize_ ans111,spx 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (ans111,spx) 2186 M endm 2186 M mloop :n 2186 M endm 2186 M mset 0 2186 M mdo 2186 M [2E1E] 2E1E:F6 [ 3] lda ?quotient+0,x 2186 M [2E1F] 2E1F:E723 [ 3] sta ans111+0,spx 2186 M mloop ::ans111 2186 M [2E21] 2E21:E601 [ 3] lda ?quotient+1,x 2186 M [2E23] 2E23:E724 [ 3] sta ans111+1,spx 2186 M mloop ::ans111 2186 M [2E25] 2E25:E602 [ 3] lda ?quotient+2,x 2186 M [2E27] 2E27:E725 [ 3] sta ans111+2,spx 2186 M mloop ::ans111 2186 M [2E29] 2E29:E603 [ 3] lda ?quotient+3,x 2186 M [2E2B] 2E2B:E726 [ 3] sta ans111+3,spx 2186 M mloop ::ans111 2186 M [2E2D] 2E2D:E604 [ 3] lda ?quotient+4,x 2186 M [2E2F] 2E2F:E727 [ 3] sta ans111+4,spx 2186 M mloop ::ans111 2186 M [2E31] 2E31:E605 [ 3] lda ?quotient+5,x 2186 M [2E33] 2E33:E728 [ 3] sta ans111+5,spx 2186 M mloop ::ans111 2186 M [2E35] 2E35:E606 [ 3] lda ?quotient+6,x 2186 M [2E37] 2E37:E729 [ 3] sta ans111+6,spx 2186 M mloop ::ans111 2186 endm 2187 [2E39] 2E39:201C (2E57) [ 3] bra ExitBoth@@ 2188 2189 040A ?DivCycles set ?DivCycles+?Cycles+:cycles 2190 2191 M ExitMod@@ @mova.s ?remainder,x ans@@,spx 2191 M mset #' ' 2191 M mreq 1,2:Source Destination 2191 M @@_samesize_ ?remainder,x ans111,spx 2191 M mreq 1,2:Operand1,Operand2[,Operand]* 2191 M mset 0 2191 M mdo 2191 M mswap 1,1 2191 M @@_nosize_ ?remainder,x 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (?remainder,x) 2191 M endm 2191 M mset 0,?remainder,x 2191 M mloop :n 2191 M mswap 1,2 2191 M @@_nosize_ ans111,spx 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (ans111,spx) 2191 M endm 2191 M mloop :n 2191 M endm 2191 M mset 0 2191 M mdo 2191 M [2E3B] 2E3B:E607 [ 3] lda ?remainder+0,x 2191 M [2E3D] 2E3D:E723 [ 3] sta ans111+0,spx 2191 M mloop ::ans111 2191 M [2E3F] 2E3F:E608 [ 3] lda ?remainder+1,x 2191 M [2E41] 2E41:E724 [ 3] sta ans111+1,spx 2191 M mloop ::ans111 2191 M [2E43] 2E43:E609 [ 3] lda ?remainder+2,x 2191 M [2E45] 2E45:E725 [ 3] sta ans111+2,spx 2191 M mloop ::ans111 2191 M [2E47] 2E47:E60A [ 3] lda ?remainder+3,x 2191 M [2E49] 2E49:E726 [ 3] sta ans111+3,spx 2191 M mloop ::ans111 2191 M [2E4B] 2E4B:E60B [ 3] lda ?remainder+4,x 2191 M [2E4D] 2E4D:E727 [ 3] sta ans111+4,spx 2191 M mloop ::ans111 2191 M [2E4F] 2E4F:E60C [ 3] lda ?remainder+5,x 2191 M [2E51] 2E51:E728 [ 3] sta ans111+5,spx 2191 M mloop ::ans111 2191 M [2E53] 2E53:E60D [ 3] lda ?remainder+6,x 2191 M [2E55] 2E55:E729 [ 3] sta ans111+6,spx 2191 M mloop ::ans111 2191 endm 2192 2193 03FE ?ModCycles set ?ModCycles+?Cycles+:cycles 2194 2195 2E57 ExitBoth@@ 2197 [2E57] 2E57:6D16 [ 4] tst ?flags,x 2198 [2E59] 2E59:2A06 (2E61) [ 3] bpl SkipSign@@ 2199 M @lea ans@@,sp 2199 M mset # 2199 M [2E5B] 2E5B:95 [ 2] tsx 2199 M [2E5C] 2E5C:AF23 [ 2] !aix #ans111+:tsx 2199 mexit 2200 [2E5E] 2E5E:CD2C 3C [ 6] jsr ?NegX 2201 2E61 SkipSign@@ 2202 #Cycles ?NegxCycles+:cycles 2204 [2E61] 2E61:A717 [ 2] ais #?SF ;de-allocate temporaries 2205 [2E63] 2E63:98 [ 1] clc ;no error(s) 2206 ; bra ?RemoveAndReturn 2207 2208 0065 ?Cycles set :cycles 2209 046F ?DivCycles set ?DivCycles+?Cycles 2210 0463 ?ModCycles set ?ModCycles+?Cycles 2211 2212 ;******************************************************************************* 2213 ; Common exit removes lower 32-bit stack element and returns to caller 2214 ;******************************************************************************* 2215 2216 2E64 ?RemoveAndReturn proc 2218 [2E64] 2E64:9EFE 04 [ 5] ldhx ?pc,sp ;our return address moved up 2219 [2E67] 2E67:9EFF 0B [ 5] sthx ?pc+?WORD,sp ;above word to remove 2229 [2E6A] 2E6A:8A88 86 [ 9] pull 2230 [2E6D] 2E6D:A707 [ 2] ais #?WORD ;remove top-of-stack ?WORD 2231 [2E6F] 2E6F:81 [ 6] rtc 2232 2233 001B ?ReturnCycles equ :cycles 2234 2235 ;******************************************************************************* 2236 ; Purpose: Swaps the stacked order of N1 and N2 2237 ; Input : [TOS+?WORD] = Number2 2238 ; : [TOS] = Number1 2239 ; Output : [TOS+?WORD] = Number1 -- TOS & [TOS+?WORD] in reverse order 2240 ; : [TOS] = Number2 2241 ; Note(s): Does not alter stack size 2242 2243 #spauto :ab 2244 2245 2E70 ?Swap proc 2246 [2E70] 2E70:8789 8B [ 6] push 2247 2248 [2E73] 2E73:A607 [ 2] lda #?WORD 2249 [2E75] 2E75:87 [ 2] psha bytes@@ 2250 2251 [2E76] 2E76:95 [ 2] tsx 2252 #temp :cycles 2253 M Loop@@ @_swap_, ?a,spx ?b,spx ;swap A with B ... 2253 M mset #' ' 2253 M #push 2253 M #spauto :sp 2253 M [2E77] 2E77:E606 [ 3] lda ?a,spx 2253 M [2E79] 2E79:87 [ 2] psha 2253 M [2E7A] 2E7A:E60D [ 3] lda ?b,spx 2253 M [2E7C] 2E7C:E706 [ 3] sta ?a,spx 2253 M [2E7E] 2E7E:86 [ 3] pula 2253 M [2E7F] 2E7F:E70D [ 3] sta ?b,spx 2253 M #pull 2253 endm 2254 2255 [2E81] 2E81:AF01 [ 2] aix #1 ;point to next byte 2256 [2E83] 2E83:9E6B 01F0 (2E77 [ 8] dbnz bytes@@,sp,Loop@@ ;repeat for all bytes 2257 #temp :cycles*?WORD+:temp 2258 [2E87] 2E87:86 [ 3] pula 2259 2260 [2E88] 2E88:8A88 86 [ 9] pull 2261 [2E8B] 2E8B:81 [ 6] rtc 2262 2263 00DB ?SwapCycles set :cycles+:temp 2264 2265 ;******************************************************************************* 2266 ; Purpose: Get the absolute value of the top-of-stack number 2267 ; Input : [TOS] = Number 2268 ; Output : [TOS] = Abs(Number) 2269 ; Note(s): Does not alter stack size 2270 2271 #spauto :ab 2272 2273 2E8C ?Abs proc 2274 [2E8C] 2E8C:9E6D 03 [ 5] tst ?a,sp 2275 [2E8F] 2E8F:2AFA (2E8B) [ 3] bpl Done@@ 2276 ; bra ?Negate 2277 2278 2E8B Done@@ equ :AnRTC 2279 2280 0008 ?AbsCycles equ :cycles 2281 2282 ;******************************************************************************* 2283 ; Purpose: Negate the top-of-stack number 2284 ; Input : [TOS] = Number 2285 ; Output : [TOS] = -Number 2286 ; Note(s): Does not alter stack size 2287 2288 #spauto :ab 2289 2290 2E91 ?Negate proc 2291 [2E91] 2E91:898B [ 4] pshhx 2293 M @lea ?a,sp 2293 M mset # 2293 M [2E93] 2E93:95 [ 2] tsx 2293 M [2E94] 2E94:AF04 [ 2] !aix #?a+:tsx 2293 mexit 2294 [2E96] 2E96:CD2C 3C [ 6] jsr ?NegX 2295 #Cycles ?NegxCycles+:cycles 2300 [2E99] 2E99:8A88 [ 6] pulhx 2301 [2E9B] 2E9B:81 [ 6] rtc 2302 2303 006B ?NegateCycles equ :cycles 2304 0073 ?AbsCycles set ?NegateCycles+?AbsCycles 2305 2306 ;******************************************************************************* 2307 ; Purpose: Create a new top-of-stack and load to it the number pointed to by HX 2308 ; Input : HX -> [Variable with] Number 2309 ; Output : [TOS] = Number 2310 ; Note(s): This operation makes it easier to load a number to the stack. 2311 ; : Hint: To make a copy of the TOS, do: 2312 ; : tsx 2313 ; : call StackLoad32 2314 ; : (Stack is expanded) 2315 2316 #spauto :ab 2317 2318 2E9C ?Load proc 2319 FFFFFFFF old_rts@@ equ ::,:ab 2320 [2E9C] 2E9C:A7F9 [ 2] ais #-?WORD ;allocate new TOS memory 2321 #temp :: 2322 FFFFFFF8 new_rts@@ next :temp,:ab 2323 FFFFFFFA tos_num@@ next :temp,?WORD 2324 0001 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2325 #ais :temp 2326 2327 [2E9E] 2E9E:87 [ 2] psha 2328 M @mova.s old_rts@@,sp new_rts@@,sp ;move RTS/RTC after new memory 2328 M mset #' ' 2328 M mreq 1,2:Source Destination 2328 M @@_samesize_ old_rts116,sp new_rts@@,sp 2328 M mreq 1,2:Operand1,Operand2[,Operand]* 2328 M mset 0 2328 M mdo 2328 M mswap 1,1 2328 M @@_nosize_ old_rts116,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (old_rts116,sp) 2328 M endm 2328 M mset 0,old_rts116,sp 2328 M mloop :n 2328 M mswap 1,2 2328 M @@_nosize_ new_rts@@,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (new_rts116,sp) 2328 M endm 2328 M mloop :n 2328 M endm 2328 M mset 0 2328 M mdo 2328 M [2E9F] 2E9F:9EE6 09 [ 4] lda old_rts116+0,sp 2328 M [2EA2] 2EA2:9EE7 02 [ 4] sta new_rts@@+0,sp 2328 M mloop ::new_rts@@ 2328 M [2EA5] 2EA5:9EE6 0A [ 4] lda old_rts116+1,sp 2328 M [2EA8] 2EA8:9EE7 03 [ 4] sta new_rts@@+1,sp 2328 M mloop ::new_rts@@ 2328 endm 2329 M @mova.s ,x tos_num@@,sp 2329 M mset #' ' 2329 M mreq 1,2:Source Destination 2329 M @@_samesize_ ,x tos_num116,sp 2329 M mreq 1,2:Operand1,Operand2[,Operand]* 2329 M mset 0 2329 M mdo 2329 M mswap 1,1 2329 M mloop :n 2329 M mswap 1,2 2329 M @@_nosize_ tos_num116,sp 2329 M mset # 2329 M mset 0,mstop [_samesize_] No size (tos_num116,sp) 2329 M endm 2329 M mset 0,tos_num116,sp 2329 M mloop :n 2329 M endm 2329 M mset 0 2329 M mdo 2329 M [2EAB] 2EAB:F6 [ 3] lda +0,x 2329 M [2EAC] 2EAC:9EE7 04 [ 4] sta tos_num116+0,sp 2329 M mloop ::tos_num116 2329 M [2EAF] 2EAF:E601 [ 3] lda +1,x 2329 M [2EB1] 2EB1:9EE7 05 [ 4] sta tos_num116+1,sp 2329 M mloop ::tos_num116 2329 M [2EB4] 2EB4:E602 [ 3] lda +2,x 2329 M [2EB6] 2EB6:9EE7 06 [ 4] sta tos_num116+2,sp 2329 M mloop ::tos_num116 2329 M [2EB9] 2EB9:E603 [ 3] lda +3,x 2329 M [2EBB] 2EBB:9EE7 07 [ 4] sta tos_num116+3,sp 2329 M mloop ::tos_num116 2329 M [2EBE] 2EBE:E604 [ 3] lda +4,x 2329 M [2EC0] 2EC0:9EE7 08 [ 4] sta tos_num116+4,sp 2329 M mloop ::tos_num116 2329 M [2EC3] 2EC3:E605 [ 3] lda +5,x 2329 M [2EC5] 2EC5:9EE7 09 [ 4] sta tos_num116+5,sp 2329 M mloop ::tos_num116 2329 M [2EC8] 2EC8:E606 [ 3] lda +6,x 2329 M [2ECA] 2ECA:9EE7 0A [ 4] sta tos_num116+6,sp 2329 M mloop ::tos_num116 2329 endm 2330 [2ECD] 2ECD:86 [ 3] pula 2331 [2ECE] 2ECE:81 [ 6] rtc 2332 2333 004E ?LoadCycles equ :cycles 2334 2335 ;******************************************************************************* 2336 ; Purpose: Unload the top-of-stack number into a variable pointed to by HX 2337 ; Input : [TOS] = Number 2338 ; : HX -> Some 32-bit variable 2339 ; Output : Variable pointed to by HX receives TOS number 2340 ; Note(s): This operation makes it easier to unload a number from the stack. 2341 ; : Use: 2342 ; : ldhx #MyVar 2343 ; : call StackSave32 2344 ; : (Stack is reduced) 2345 2346 #spauto :ab 2347 2348 2ECF ?Save proc 2349 #temp :: 2350 FFFFFFFF old_rts@@ next :temp,:ab 2351 0001 tos_num@@ next :temp,?WORD 2352 0008 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2353 0006 new_rts@@ next :temp,:ab 2354 2355 0000 var@@ equ 0,?WORD 2356 2357 [2ECF] 2ECF:8789 8B [ 6] push 2358 M @mova.s tos_num@@,sp var@@,x 2358 M mset #' ' 2358 M mreq 1,2:Source Destination 2358 M @@_samesize_ tos_num117,sp var@@,x 2358 M mreq 1,2:Operand1,Operand2[,Operand]* 2358 M mset 0 2358 M mdo 2358 M mswap 1,1 2358 M @@_nosize_ tos_num117,sp 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (tos_num117,sp) 2358 M endm 2358 M mset 0,tos_num117,sp 2358 M mloop :n 2358 M mswap 1,2 2358 M @@_nosize_ var@@,x 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (var117,x) 2358 M endm 2358 M mloop :n 2358 M endm 2358 M mset 0 2358 M mdo 2358 M [2ED2] 2ED2:9EE6 06 [ 4] lda tos_num117+0,sp 2358 M [2ED5] 2ED5:F7 [ 2] sta var@@+0,x 2358 M mloop ::var@@ 2358 M [2ED6] 2ED6:9EE6 07 [ 4] lda tos_num117+1,sp 2358 M [2ED9] 2ED9:E701 [ 3] sta var@@+1,x 2358 M mloop ::var@@ 2358 M [2EDB] 2EDB:9EE6 08 [ 4] lda tos_num117+2,sp 2358 M [2EDE] 2EDE:E702 [ 3] sta var@@+2,x 2358 M mloop ::var@@ 2358 M [2EE0] 2EE0:9EE6 09 [ 4] lda tos_num117+3,sp 2358 M [2EE3] 2EE3:E703 [ 3] sta var@@+3,x 2358 M mloop ::var@@ 2358 M [2EE5] 2EE5:9EE6 0A [ 4] lda tos_num117+4,sp 2358 M [2EE8] 2EE8:E704 [ 3] sta var@@+4,x 2358 M mloop ::var@@ 2358 M [2EEA] 2EEA:9EE6 0B [ 4] lda tos_num117+5,sp 2358 M [2EED] 2EED:E705 [ 3] sta var@@+5,x 2358 M mloop ::var@@ 2358 M [2EEF] 2EEF:9EE6 0C [ 4] lda tos_num117+6,sp 2358 M [2EF2] 2EF2:E706 [ 3] sta var@@+6,x 2358 M mloop ::var@@ 2358 endm 2359 2360 [2EF4] 2EF4:95 [ 2] tsx 2361 M @mova.s old_rts@@,spx new_rts@@,spx ;move RTS/RTC before old memory 2361 M mset #' ' 2361 M mreq 1,2:Source Destination 2361 M @@_samesize_ old_rts117,spx new_rts@@,spx 2361 M mreq 1,2:Operand1,Operand2[,Operand]* 2361 M mset 0 2361 M mdo 2361 M mswap 1,1 2361 M @@_nosize_ old_rts117,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (old_rts117,spx) 2361 M endm 2361 M mset 0,old_rts117,spx 2361 M mloop :n 2361 M mswap 1,2 2361 M @@_nosize_ new_rts@@,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (new_rts117,spx) 2361 M endm 2361 M mloop :n 2361 M endm 2361 M mset 0 2361 M mdo 2361 M [2EF5] 2EF5:E603 [ 3] lda old_rts117+0,spx 2361 M [2EF7] 2EF7:E70A [ 3] sta new_rts@@+0,spx 2361 M mloop ::new_rts@@ 2361 M [2EF9] 2EF9:E604 [ 3] lda old_rts117+1,spx 2361 M [2EFB] 2EFB:E70B [ 3] sta new_rts@@+1,spx 2361 M mloop ::new_rts@@ 2361 endm 2362 [2EFD] 2EFD:8A88 86 [ 9] pull 2363 2364 [2F00] 2F00:A707 [ 2] ais #?WORD ;de-allocate TOS memory 2365 [2F02] 2F02:81 [ 6] rtc 2366 2367 0055 ?SaveCycles equ :cycles 2368 2369 ;******************************************************************************* 2370 ; Purpose: Adjust TOS old size to new 2371 ; Input : H = old (current) byte size 2372 ; : X = new byte size 2373 ; : CCR[C] = 0 -- always positive number 2374 ; : CCR[C] = 1 -- sign extend 2375 ; Output : None 2376 ; Note(s): RegA deliberately not used for parameter passing (for consistency) 2377 ; : Macro destroys RegHX (as we must not use PSHHX/PULHX around call) 2378 2504 2505 ;******************************************************************************* 2506 ; Purpose: Convert 32-bit to ASCIZ string 2507 ; Input : Stack: 32-bit number 2508 ; : HX -> Output buffer with enough space to keep the ASCIZ string result 2509 ; Output : None 2510 ; Note(s): Use: 2511 ; : ldhx #Buffer 2512 ; : call Stack32ToASCIZ 2513 2514 #spauto :ab ;account for RTS/RTC 2515 2516 2F03 ?ToStr proc 2517 [2F03] 2F03:8789 8B [ 6] push 2518 #ais ;mark beginning of temporaries 2519 2520 [2F06] 2F06:898B [ 4] pshhx .buffer@@ ;working copy of pointer to buffer 2521 [2F08] 2F08:7F [ 4] clr ,x ;make it an ASCIZ string 2522 2523 M @lea 1,sp ;HX -> TOS number of caller 2523 M mset # 2523 M [2F09] 2F09:95 [ 2] tsx 2523 M [2F0A] 2F0A:AF07 [ 2] !aix #1+:tsx 2523 mexit 2524 [2F0C] 2F0C:CD2E 9C [ 6] call ?Load ;load a working copy on stack 2525 2526 #spadd ?WORD ;stack has grown by a ?WORD 2527 FFFFFFF3 number@@ equ ::,?WORD 2529 [2F0F] 2F0F:9E6D 01 [ 5] tst number@@,sp 2530 [2F12] 2F12:2A0F (2F23) [ 3] bpl ToStrLoop@@ 2531 [2F14] 2F14:CD2E 91 [ 6] call ?Negate 2533 [2F17] 2F17:9EFE 08 [ 5] ldhx .buffer@@,sp 2540 [2F1A] 2F1A:A62D [ 2] lda #'-' ;a 'minus' sign 2541 [2F1C] 2F1C:F7 [ 2] sta ,x ; is saved first 2542 2543 [2F1D] 2F1D:AF01 [ 2] aix #1 ;HX -> past minus sign 2544 [2F1F] 2F1F:7F [ 4] clr ,x ;make it an ASCIZ string 2546 [2F20] 2F20:9EFF 08 [ 5] sthx .buffer@@,sp ;update pointer past sign 2552 ; bra ToStrLoop@@ 2554 ;=============================================================================== 2555 2556 [2F23] 2F23:4500 0A [ 3] ToStrLoop@@ ldhx #10 ;H = 0 (always), X = divisor 2557 M @div.s number@@,sp 2557 M mset # 2557 M mreq 1 2557 M @@_not_x_ number118,sp 2557 M mset #' ' 2557 M mdel 1 2557 M mtop 2557 M mset #' ' 2557 M mexit 2557 M @@_nosize_ number118,sp 2557 M mset # 2557 M mset 0,mstop [div.s] No size (number118,sp) 2557 M endm 2557 M #temp 1 2557 M #temp 2 2557 M [2F26] 2F26:86 [ 3] pula 2557 M [2F27] 2F27:52 [ 6] div 2557 M [2F28] 2F28:87 [ 2] psha 2557 M mdo 2 2557 M [2F29] 2F29:9EE6 02 [ 4] lda number118+1,sp 2557 M [2F2C] 2F2C:52 [ 6] div 2557 M [2F2D] 2F2D:9EE7 02 [ 4] sta number118+1,sp 2557 M mloop ::number118 2557 M [2F30] 2F30:9EE6 03 [ 4] lda number118+2,sp 2557 M [2F33] 2F33:52 [ 6] div 2557 M [2F34] 2F34:9EE7 03 [ 4] sta number118+2,sp 2557 M mloop ::number118 2557 M [2F37] 2F37:9EE6 04 [ 4] lda number118+3,sp 2557 M [2F3A] 2F3A:52 [ 6] div 2557 M [2F3B] 2F3B:9EE7 04 [ 4] sta number118+3,sp 2557 M mloop ::number118 2557 M [2F3E] 2F3E:9EE6 05 [ 4] lda number118+4,sp 2557 M [2F41] 2F41:52 [ 6] div 2557 M [2F42] 2F42:9EE7 05 [ 4] sta number118+4,sp 2557 M mloop ::number118 2557 M [2F45] 2F45:9EE6 06 [ 4] lda number118+5,sp 2557 M [2F48] 2F48:52 [ 6] div 2557 M [2F49] 2F49:9EE7 06 [ 4] sta number118+5,sp 2557 M mloop ::number118 2557 M [2F4C] 2F4C:9EE6 07 [ 4] lda number118+6,sp 2557 M [2F4F] 2F4F:52 [ 6] div 2557 M [2F50] 2F50:9EE7 07 [ 4] sta number118+6,sp 2557 M mloop ::number118 2557 endm 2558 2559 [2F53] 2F53:8B86 [ 5] tha ;A = remainder 2560 [2F55] 2F55:AB30 [ 2] add #'0' ;A = ASCII remainder 2562 [2F57] 2F57:9EFE 08 [ 5] ldhx .buffer@@,sp 2568 M @StringInsertChar 2568 M [2F5A] 2F5A:CD18 3A [ 6] call StringInsertChar ;HX and A pre-loaded correctly 2568 mexit 2569 2570 [2F5D] 2F5D:95 [ 2] tsx 2571 2572 M @_tst_.s number@@,spx 2572 M mset # 2572 M mreq 1 2572 M @@_nosize_ number118,spx 2572 M mset # 2572 M mset 0,mstop [_tst_.s] No size (number118,spx) 2572 M endm 2572 M mdo 2572 M [2F5E] 2F5E:F6 [ 3] lda number118+0,spx 2572 M mloop ::number118 2572 M [2F5F] 2F5F:EA01 [ 3] ora number118+1,spx 2572 M mloop ::number118 2572 M [2F61] 2F61:EA02 [ 3] ora number118+2,spx 2572 M mloop ::number118 2572 M [2F63] 2F63:EA03 [ 3] ora number118+3,spx 2572 M mloop ::number118 2572 M [2F65] 2F65:EA04 [ 3] ora number118+4,spx 2572 M mloop ::number118 2572 M [2F67] 2F67:EA05 [ 3] ora number118+5,spx 2572 M mloop ::number118 2572 M [2F69] 2F69:EA06 [ 3] ora number118+6,spx 2572 M mloop ::number118 2572 endm 2573 [2F6B] 2F6B:26B6 (2F23) [ 3] bne ToStrLoop@@ 2574 2575 [2F6D] 2F6D:A709 [ 2] ais #:ais ;free temporaries 2576 [2F6F] 2F6F:8A88 86 [ 9] pull 2577 [2F72] 2F72:81 [ 6] rtc 2578 2579 #sp ;cancel all SP offsets 2580 2581 ;******************************************************************************* 2582 ; Assign global names to the various library calls, depending on version used. 2583 ; Different names for each version means you can include any at the same time. 2584 ;******************************************************************************* 2585 2586 ? macro BitSize ;temp macro to export symbols 2587 mreq 1:Usage: @~0~ BitSize 2588 #if MATHSIZE = ~1~ 2589 StackAdd~1~ exp ?Add 2590 StackSub~1~ exp ?Subtract 2591 StackMul~1~ exp ?Multiply 2592 StackDiv~1~ exp ?Divide 2593 StackMod~1~ exp ?Modulo 2594 StackSwap~1~ exp ?Swap 2595 StackAbs~1~ exp ?Abs 2596 StackNegate~1~ exp ?Negate 2597 StackLoad~1~ exp ?Load 2598 StackSave~1~ exp ?Save 2599 Stack~1~ToASCIZ exp ?ToStr 2600 #ifdef NO_BIT_OPS 2601 mexit ;;bit operations not available 2602 #endif 2603 StackAnd~1~ exp ?BitAnd 2604 StackOr~1~ exp ?BitOr 2605 StackXor~1~ exp ?BitXor 2606 StackShl~1~ exp ?ShiftLeft 2607 StackShr~1~ exp ?ShiftRight 2608 #endif 2609 endm 2610 2611 M @? 64 ;export 64-bit labels 2611 M mreq 1:Usage: @? BitSize 2611 endm 2612 M @? 56 ;export 56-bit labels 2612 M mreq 1:Usage: @? BitSize 2612 M 2A94 StackAdd56 exp ?Add 2612 M 2AAA StackSub56 exp ?Subtract 2612 M 2BB5 StackMul56 exp ?Multiply 2612 M 2C18 StackDiv56 exp ?Divide 2612 M 2C2B StackMod56 exp ?Modulo 2612 M 2E70 StackSwap56 exp ?Swap 2612 M 2E8C StackAbs56 exp ?Abs 2612 M 2E91 StackNegate56 exp ?Negate 2612 M 2E9C StackLoad56 exp ?Load 2612 M 2ECF StackSave56 exp ?Save 2612 M 2F03 Stack56ToASCIZ exp ?ToStr 2612 M 2AC0 StackAnd56 exp ?BitAnd 2612 M 2AD5 StackOr56 exp ?BitOr 2612 M 2AEA StackXor56 exp ?BitXor 2612 M 2AFF StackShl56 exp ?ShiftLeft 2612 M 2B5A StackShr56 exp ?ShiftRight 2612 endm 2613 M @? 48 ;export 48-bit labels 2613 M mreq 1:Usage: @? BitSize 2613 endm 2614 M @? 40 ;export 40-bit labels 2614 M mreq 1:Usage: @? BitSize 2614 endm 2615 M @? 32 ;export 32-bit labels 2615 M mreq 1:Usage: @? BitSize 2615 endm 2616 M @? 24 ;export 24-bit labels 2616 M mreq 1:Usage: @? BitSize 2616 endm 2617 M @? 16 ;export 16-bit labels 2617 M mreq 1:Usage: @? BitSize 2617 endm 2618 2619 ;******************************************************************************* *** END INCLUDE FILE: lib/stakmath.sub *** (RESUMING FILE: lib/stkmth56.sub) 23 #Exit *** END INCLUDE FILE: lib/stkmth56.sub *** (RESUMING FILE: lib/demo/stakmath.asm) 54 M @? 64,7 54 M @@Page 7 54 M mreq 1:PageNumber 54 M endm 54 #Uses lib/stkmth64.sub *** BEGIN INCLUDE FILE: lib/stkmth64.sub *** 1 ;******************************************************************************* 2 ;* Module : STKMTH64.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : Wrapper for 64-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stkmth64.html 8 ;* Note(s) : See STAKMATH.SUB for details 9 ;******************************************************************************* 10 16 17 ? macro 18 mset 1,~BASENAME~ 19 MATHSIZE set ~1.{:1-1}~ 20 #Include stakmath.sub 21 endm 22 23 M @? 23 M mset 1,STKMTH64 23 M 0040 MATHSIZE set 64 23 #Include stakmath.sub *** BEGIN INCLUDE FILE: lib/stakmath.sub *** 1 ;******************************************************************************* 2 ;* Module : STAKMATH.SUB 3 ;* Programmer: Tony Papadimitriou <tonyp@acm.org> 4 ;* Purpose : 64/56/48/40/32/24/16-bit stack-based basic math routines (RPN style) 5 ;* Language : Motorola/Freescale/NXP HC08/9S08 Assembly Language (aspisys.com/ASM8) 6 ;* Status : FREEWARE Copyright (c) 2020 by Tony Papadimitriou <tonyp@acm.org> 7 ;* Original : http://www.aspisys.com/code/hc08/stakmath.html 8 ;* Note(s) : Use: #Include stakmath.sub 9 ;* : 10 ;* : Several externally defined macros are used throughout this code. 11 ;* : All these (and many more) macros are inside the most recent 12 ;* : version of MACROS.INC which can be copied from the web page at 13 ;* : http://www.aspisys.com/code/hc08/macros.html 14 ;* : (and COMMON.INC at http://www.aspisys.com/code/hc08/common.html) 15 ;* : 16 ;* : The default word size is 32-bit. 17 ;* : 18 ;* : By (re)defining the symbol MATHSIZE (to 16) you get 16-bit code. 19 ;* : By (re)defining the symbol MATHSIZE to 24 you get 24-bit code. 20 ;* : By (re)defining the symbol MATHSIZE to 40 you get 40-bit code. 21 ;* : By (re)defining the symbol MATHSIZE to 48 you get 48-bit code. 22 ;* : By (re)defining the symbol MATHSIZE to 56 you get 56-bit code. 23 ;* : By (re)defining the symbol MATHSIZE to 64 you get 64-bit code. 24 ;* : 25 ;* : You can include all (or some) versions in your program like so: 26 ;* : 27 ;* : #ROM ;(or else, some paged memory) 28 ;* : #Include stakmath.sub 29 ;* : MATHSIZE set 16 ;redefine for 16-bit use 30 ;* : #Include stakmath.sub 31 ;* : MATHSIZE set 24 ;redefine for 24-bit use 32 ;* : #Include stakmath.sub 33 ;* : MATHSIZE set 40 ;redefine for 40-bit use 34 ;* : #Include stakmath.sub 35 ;* : MATHSIZE set 48 ;redefine for 48-bit use 36 ;* : #Include stakmath.sub 37 ;* : MATHSIZE set 56 ;redefine for 56-bit use 38 ;* : #Include stakmath.sub 39 ;* : MATHSIZE set 64 ;redefine for 64-bit use 40 ;* : 41 ;* : or, if you use the related wrapper files, like so: 42 ;* : 43 ;* : #ROM ;(or else, some paged memory) 44 ;* : #Uses stkmth16.sub 45 ;* : #Uses stkmth24.sub 46 ;* : #Uses stkmth32.sub 47 ;* : #Uses stkmth40.sub 48 ;* : #Uses stkmth48.sub 49 ;* : #Uses stkmth56.sub 50 ;* : #Uses stkmth64.sub 51 ;* : 52 ;* : Use CALL if assembled in #MMU mode (regardless of placement). 53 ;* : By using CALL and #JUMP (or default -J+ command line option), the 54 ;* : assembler will automatically adjust between CALL and JSR 55 ;* : depending on the current #MMU mode. 56 ;* : 57 ;* : To use the *-bit version of each CALL, use these symbols: 58 ;* : 59 ;* : StackAdd*, StackSub*, StackMul*, StackDiv*, StackMod* 60 ;* : StackSwap*, StackNegate*, StackLoad*, StackSave*, 61 ;* : Stack*ToASCIZ 62 ;* : 63 ;* : replacing * with one of these: 16, 24, 32, 40, 48, 56, or 64. 64 ;* : 65 ;* : Various macros allow using these routines in a variety of ways, 66 ;* : and without worrying about the details of call & parameter setup. 67 ;* : These macros are: Add*, Sub*, Mul*, Div*, Mod*, DivS*, ModS*, 68 ;* : Neg*, Load*, Save*, Str*, StrS*, and Swap* (where the * is 16, 69 ;* : 24, 32, 40, 48, 56, or 64 depending on the version you want to use). 70 ;* : The signed versions are enabled only when the module is assembled 71 ;* : with the SIGNED conditional. 72 ;* : 73 ;* : If working with fixed-address variables, you can use the various 74 ;* : macros (such as Add32, Mul64, etc.) to perform operations in the 75 ;* : easiest possible way, such as: 76 ;* : @Mul32 A,B,Answer 77 ;* : (which multiplies A with B and stores the product in Answer). 78 ;* : But, you may also use the macros to work directly on stack, or to 79 ;* : temporarily save partial results on stack instead of fixed vars. 80 ;* : 81 ;* : I N G E N E R A L T H E N 82 ;* : 83 ;* : @Operation A,B,Answer works with A and B storing result in Answer 84 ;* : @Operation A,B works with A and B leaving result on stack 85 ;* : @Operation A works with TOS and A, result left as TOS 86 ;* : @Operation (no parms) works w/ TOS and [TOS+1], result as new TOS 87 ;* : 88 ;* : (Please note the shown order of the operation may be important.) 89 ;* : 90 ;* : Finally, the Load* (* = 16, 24, 32, 40, 48, 56, 64) operation can 91 ;* : directly load either a variable or a constant (leading #) on the 92 ;* : stack. 93 ;* : 94 ;* : Since v7.00, a HLL-like interface is possible by using the new 95 ;* : Eval* macro (where * = 8, 16, 24, 32, 40, 48, 56, 64) 96 ;* : This is by far the easiest way to use this library, as it closely 97 ;* : resembles using expressions in a HLL compiler. It also can 98 ;* : automatically resize stack after loading from and before saving 99 ;* : to any variable. 100 ;* : 101 ;* : Examine the test section of this file for examples of macro use. 102 ;* : 103 ;* : All routines are re-entrant and work on either the top-of-stack 104 ;* : (TOS) number alone or the two top-most TOS numbers. Similar to 105 ;* : how Reverse Polish Notation (RPN) works. First, you stack the 106 ;* : operand(s) and then call the corresponding routine to perform the 107 ;* : operation. 108 ;* : 109 ;* : The result of any operation is always the updated top of stack. 110 ;* : For operations that require two operands and produce a single 111 ;* : result, the result replaces the two operands (stack is reduced). 112 ;* : 113 ;* : Chain calculations are possible by pushing only the new operand 114 ;* : between operations. Alternatively, one can push all operands in 115 ;* : advance but it's not recommended as stack space may be limited. 116 ;* : When done evaluating an expression, just pull the final 32-bit 117 ;* : result from the stack. 118 ;* : 119 ;* : The TOS is the first (or only) operand of any operation. 120 ;* : This is important, for example, for subtraction and division. 121 ;* : 122 ;* : If the current order of the stack is not as you want it, use the 123 ;* : Swap (StackSwap32) operation to change it. 124 ;* : 125 ;* : All operands and results are exactly 32-bit wide. Overflows are 126 ;* : simply truncated. The lower 32-bit number is valid, though. 127 ;* : 128 ;* : (All references to 32-bit become 16-bit, when MATHSIZE = 16) 129 ;* : (All references to 32-bit become 24-bit, when MATHSIZE = 24) 130 ;* : (All references to 32-bit become 40-bit, when MATHSIZE = 40) 131 ;* : (All references to 32-bit become 48-bit, when MATHSIZE = 48) 132 ;* : (All references to 32-bit become 56-bit, when MATHSIZE = 56) 133 ;* : (All references to 32-bit become 64-bit, when MATHSIZE = 64) 134 ;* : 135 ;* : 64/56/48/40-bit multiplication is done using the shift-add method, 136 ;* : which is much shorter in size for such long operands, but it is 137 ;* : also significantly slower in speed. I opted for size optimization 138 ;* : because the 64/56/48/40-bit versions are not used quite as often. 139 ;* : You may want to re-write it for speed optimization by using the 140 ;* : MUL instruction like it is done for the default 32-bit case. 141 ;* : 142 ;* History : 09.05.22 v1.00 Original (Started on 2009.05.07) 143 ;* : 09.06.04 Optimized by using HX instead of SP, where needed 144 ;* : 09.11.04 Minor optimizations 145 ;* : 09.11.05 Add & Subtract now adjust Carry accordingly 146 ;* : Division by zero error now checked first 147 ;* : 09.11.06 v1.01 Added conditional MATHSIZE for use w/ 16-bit words 148 ;* : 09.11.08 v1.02 Added "Load" operation to ease stack loading 149 ;* : 09.11.11 Use of new LONG pseudo-opcode 150 ;* : 09.12.05 Added cycles display using :cycles 151 ;* : 10.01.06 v1.03 Added MMU auto-support (using :AB internal symbol) 152 ;* : Code is no longer placed in #ROM by default 153 ;* : The few JMPs in the code use [[ to trim possible page 154 ;* : 10.01.08 [[ removed from JMPs (latest ASM8 auto-correction) 155 ;* : 10.01.22 v1.04 Added Save operation for completeness 156 ;* : 10.01.23 v1.05 Added #SP directive examples (latest ASM8) 157 ;* : 10.01.29 v1.06 Added shorter/faster Swap version for 9S08 MCUs 158 ;* : 10.02.01 v1.07 Added #SPAUTO directive 159 ;* : 10.02.04 Added #X directive 160 ;* : 10.02.06 v2.00 Added signed math wrapper calls only for DIV & MOD 161 ;* : (Addition, Subtraction, and Multiplication calls 162 ;* : work either for unsigned or signed operands.) 163 ;* : Signed routines enabled w/ SIGNED conditional. 164 ;* : Division by zero error now reduces stack (operand 165 ;* : A removed) so that the stack is left with same 166 ;* : size on either success or failure (in which case 167 ;* : the TOS result is invalid.) 168 ;* : 10.02.08 v2.01 Fixed signed MOD for correct sign (sign of A) 169 ;* : 10.02.14 v2.10 Added Stack32ToASCIZ and prerequisite StringInsertChar 170 ;* : 10.02.28 v2.11 Minor optimization in StringInsertChar 171 ;* : 10.03.23 Made use of :: internal variable (Build 2010/03/23) 172 ;* : 10.03.30 v2.12 Allowed for HC08 compilation in newer code (?ToStr) 173 ;* : Optimized 9S08 Swap version for size and speed 174 ;* : v2.13 Optimized Negate for size and speed 175 ;* : 10.05.08 v3.00 Added MATHSIZE = 64 option for 64-bit math 176 ;* : Swap operation optimized only for size 177 ;* : 10.05.13 v3.01 Optimized for size and speed by using ,SPX 178 ;* : 10.06.02 v4.00 Added macros for easier use 179 ;* : 10.06.08 v4.10 Improved macros and added new ones (eg Const32) 180 ;* : 10.06.23 v4.20 Added MATHSIZE = 48 option for 48-bit math 181 ;* : 10.06.30 v4.30 Added AddDecimalPoint (to string number) 182 ;* : 10.07.01 v4.40 Added IFSPAUTO conditional 183 ;* : 10.07.03 Moved the functionality of Const macros into Load 184 ;* : 10.07.07 Moved general string routines first 185 ;* : 10.07.17 v4.50 Str* macros may use TOS (if Number parm is missing) 186 ;* : or current HX index (if result pointer is missing) 187 ;* : 10.07.20 _DoLoad*/_DoSave* address now allows for indexed mode 188 ;* : 10.07.21 Minor optimizations; macros now latest ASM8 189 ;* : 10.07.23 Minor bug fix in macro _DoSave for no parm case 190 ;* : 10.08.18 Optimized by using :MINDEX in latest ASM8 191 ;* : 10.08.26 Minor optimizations at the source level 192 ;* : 10.08.31 v4.60 Optimized Load* macros' immediate mode for zeros 193 ;* : 10.10.19 v4.61 Adapted to latest ASM8 (nested macros in Load) 194 ;* : 10.10.22 v4.62 Optimized _DoMath (Added @_DoOperation) 195 ;* : 10.10.26 v4.63 Load48 & Load64 now also accept single #Constant 196 ;* : 10.12.03 v4.64 Adapted to latest ASM8 => macros OK in @@ sub-mode 197 ;* : 11.03.31 v4.65 Moved test code at EOF (to use #EXIT optimization) 198 ;* : 11.04.10 v4.66 Condensed macro definitions (based on MATHSIZE) 199 ;* : 11.04.11 v4.67 Optimized MUL16/MUL32 size & cycles with ,SPX mode 200 ;* : 11.04.12 v4.70 Added MATHSIZE = 24 option for 24-bit math 201 ;* : 11.04.13 v4.71 Reversed some of v4.66's changes 202 ;* : 11.04.13 v4.80 Added MATHSIZE = 40 option for 40-bit math 203 ;* : 11.05.02 v4.81 Save protects HX (it was lost during SP => SPX) 204 ;* : 11.05.05 v4.82 Optimized StringLength by a byte (by using NEGA on exit) 205 ;* : 11.05.25 v4.83 Removed unused Zero constant from test code 206 ;* : 11.10.13 v4.84 Optimized MUL16/24/32 size w/ more ,SPX (same cycles) 207 ;* : 11.11.15 v4.85 Improved StringLength macro 208 ;* : 12.01.26 Changed test code a bit 209 ;* : 12.02.06 v4.86 Optimized SP => SPX at ?RemoveAndReturn 210 ;* : 12.03.05 v4.87 Added ResizeTOS to adjust TOS element's size 211 ;* : 12.05.09 v4.88 Added CCR[C] parameter to ResizeTOS for unsigned operation 212 ;* (signed is default when SIGNED conditional is defined, 213 ;* unsigned operation is default, otherwise) 214 ;* : 12.05.18 v4.89 Removed redundant subtraction in Division (at NotEqual@@) 215 ;* : 12.10.07 v4.90 Load*/Save* now accept indexed mode without separator override 216 ;* : 12.10.10 v5.00 Renamed to (more general) STAKMATH.SUB to use 217 ;* : wrapper files for each bit version, instead. 218 ;* : 12.11.05 Added _STKMTH{MATHSIZE}_ for used-version control 219 ;* : 12.11.09 v6.00 New _LoadStkMthVarAddr macro eases parm address 220 ;* : calculation. 221 ;* : W A R N I N G: SP-based operands now refer to the actual number, 222 ;* : W A R N I N G: and not its address (as was the case before). 223 ;* : W A R N I N G: This is INCOMPATIBLE with previous behavior. Code 224 ;* : W A R N I N G: written for version v5.00 or earlier that uses SP 225 ;* : W A R N I N G: based operands should be modified to refer to the 226 ;* : W A R N I N G: actual value and not to a pointer to the value. 227 ;* : W A R N I N G: Dot-beginning names are still treated as pointers! 228 ;* : 12.11.10 Use COMMON.INC/LEA instead of _LoadStkMthVarAddr 229 ;* : 12.12.04 v6.10 Optimized division just a tad by combining steps 230 ;* : 12.12.12 v6.20 Now use LEA macro inside _DoStr (for ResultString) 231 ;* : 12.12.20 v6.21 Minor optimization (one byte) in 32-bit ?Multiply 232 ;* : (Further 3-byte optimization possible by 233 ;* : re-ordering MULs, but not done for code clarity) 234 ;* : 13.01.09 v6.22 Added Copy* macros to combine Load*/Save* into one 235 ;* : 13.03.20 v7.00 Added Eval* and supporting macros for HLL-like 236 ;* : computations, eg., ans=(a+3)*((1+var,sp)/2) 237 ;* : (with or without spaces between operands/operators) 238 ;* : 13.03.27 v7.50 SIGNED now gives just signed (not unsigned) version 239 ;* : DivS*, ModS*, StrS* macros were removed, and also 240 ;* : ResizeTOS macro's unsigned flag has been removed 241 ;* : BugFix: AddDecimalPoint now prepends zeros after sign 242 ;* : 13.03.27 Optimized ?Negate in SIGNED case to use ?NegX sub 243 ;* : 13.03.27 v7.60 Adapted _EVAL_ macro to latest ASM8 (Much faster!) 244 ;* : 13.04.04 v7.70 _DoLoad and _DoSave macros now auto-adjust the size 245 ;* : so you can use with operands of different sizes, even 246 ;* : if the respective bitsize version isn't loaded. 247 ;* : 13.04.04 v7.71 _Eval_ macro leaves assignment result on TOS if 248 ;* : assignment variable not already defined. Then, 249 ;* : it gives TOS the specified name, if SP-indexed. 250 ;* : 13.04.05 v7.72 Added #size for v7.71 change 251 ;* : Named constants (labels with size zero) now use 252 ;* : immediate mode in Eval/Load 253 ;* : 13.04.05 v7.73 Added NEG() negate, and ABS() absolute functions 254 ;* : in Eval macro, e.g., ans = abs(a - b) 255 ;* : 13.04.09 v7.80 BugFix: Push/Pull macro calls for SP mode 256 ;* : Moved immediate mode to _DoLoad (unified method) 257 ;* : (Over 32-bit immediate value loads not possible 258 ;* : via macros) 259 ;* : 13.04.10 Adapted to v9.35 (no functional changes) 260 ;* : 13.04.11 v7.81 Optimized _DoLoad constant loading by using CLRH 261 ;* : (optimization is evident on certain cases only) 262 ;* : 13.04.15 v7.82 Added _?SEI_ and _?CLI_ macros for multitasker 263 ;* : locking / unlocking of multi-byte variables while 264 ;* : loading / saving (_DoLoad/_DoSave). Under OS8 it 265 ;* : is enabled automatically. Otherwise, simply 266 ;* : define _MTOS_ anytime before including this file. 267 ;* : For keeping code dense, all Eval*/Load*/Save* 268 ;* : macros are assumed to be called only while 269 ;* : interrupts are enabled, so it will not restore to 270 ;* : previous state but always leave as enabled. 271 ;* : Define _NOCLI_ (before including this module) for 272 ;* : canceling the _?SEI_ and _?CLI_ macro effects. 273 ;* : 13.04.18 v7.85 Added 'NeedMath' and 'Eval' general-purpose macros 274 ;* : for automatic selection of needed bit-size based 275 ;* : on only which modules are already included. First, 276 ;* : call the NeedMath macro to define the minimum math 277 ;* : bit-size you need for the next calculation(s), 278 ;* : then call the Eval macro as many times as needed 279 ;* : to perform the actual expression evaluation(s). 280 ;* : Similary, added new macros Load, Save, StkAdd, 281 ;* : StkSub, StkMul, StkDiv, StkMod, StkSwap, StkNeg, 282 ;* : StkAbs, StkStr, and CopyMath to work with the 283 ;* : NeedMath macro, just like the new Eval macro. 284 ;* : 13.04.19 v8.00 Moved all Eval* macros into COMMON.INC and allowed 285 ;* : for all to be active at all times, regardless if 286 ;* : the related bit-version of STAKMATH is included. 287 ;* : The _Eval_ macro was improved to allow it to 288 ;* : automatically locate the next higher version that 289 ;* : is included, if the one requested is not. So, 290 ;* : using Eval32 will use the 32/40/48/64-bit version 291 ;* : (whichever is closer to 32 and included) but nothing 292 ;* : below 32-bit. This allows you to use the relevant 293 ;* : macro based on a specific expression's requirements 294 ;* : but include only one (or just a few) higher bit 295 ;* : version(s), not all those referenced in your code. 296 ;* : (The general Eval is still available, if needed.) 297 ;* : Also, moved all Str* to COMMON.INC 298 ;* : 13.04.21 v8.10 Corrected v8.00 for pointer cases (.num) to use 299 ;* : actual requested size, not next higher. 300 ;* : Relevant #Message now in _DoOperation _ResizeTOS etc. 301 ;* : 13.04.21 v8.11 NeedMath & related macros removed (now redundant) 302 ;* : General Eval macro will try to determine best bit-size 303 ;* : 13.04.23 v8.12 Added EvalS to first check for SIGNED and then call Eval 304 ;* : CopyMath removed. Use "Eval to_var = from_var" instead 305 ;* : _StkMthMax_ improved to use higher size on multiplication 306 ;* : 13.04.25 v8.13 _Eval_ now allows for string constants (eg., @Eval ans = ans + '0') 307 ;* : Removed all ?macros because we now use COMMON xxx.s macros 308 ;* : 13.04.26 v8.15 Corrected test code for Eval when MATHSIZE < 32 309 ;* : Commented out auto-higher bit-size (a bit annoying). 310 ;* : Use Eval* to say 'no less than', instead. 311 ;* : 13.04.27 v8.16 BugFix: StrMath macro (2nd parameter was lost) 312 ;* : Added SQR() function to get the square 313 ;* : 13.05.02 Added #size in ToInt* macros (in test code) 314 ;* : 13.05.03 v8.17 Added size optimization for ADD and SUB operations 315 ;* : New SPEED_SIZE constant in COMMON.INC tells us 316 ;* : whether we need speed (SPEED_SIZE = 1) or 317 ;* : size (SPEED_SIZE = 2) optimization, the current 318 ;* : default being SPEED_SIZE = 2 for size optimization. 319 ;* : 13.05.30 Updated StrMath macro (COMMON.INC and here) 320 ;* : 13.06.04 v8.20 Added bit functions: AND (&), OR (|), XOR (^), and shifts (< and >) 321 ;* : 13.06.05 v8.21 BugFix: ShiftRight now uses ASR if SIGNED 322 ;* : 13.07.25 v8.22 Improved _Eval_ macro (and Push/Pull in COMMON.INC) 323 ;* : BugFix: Added { } to ResizeTOS macro's final case 324 ;* : (Disable bit functions with NO_BIT_OPS conditional) 325 ;* : 13.10.06 Minor changes in test code 326 ;* : 13.11.26 Added warning in _DoLoad: forwards treated as vars 327 ;* : 13.11.29 v8.23 Optimized ?ShiftLeft and ?ShiftRight a bit 328 ;* : 13.12.22 v8.30 Added 56-bit version 329 ;* : 14.01.03 Made use of _CMP_.S macro (instead of custom macro) 330 ;* : 14.02.07 v8.50 Added [ ... ] unsigned override (if SIGNED) 331 ;* : 14.02.14 v8.51 Eval macro now uses #HideMacros 332 ;* : 14.10.14 v8.52 BugFix: Off-by-one error in ResizeTOS when SIGNED 333 ;* : 15.03.21 v8.53 Replaced string dependencies with corresponding #Uses 334 ;* : 15.04.08 v8.54 Replaced AddDecimalPoint with corresponding #Uses 335 ;* : 17.04.03 v8.55 Optimized 24-bit multiply [-2 bytes] 336 ;* : Optimized 32-bit multiply [-7 bytes] 337 ;* : 18.10.23 Suppressed possible warning from JEQ in ?DivStart 338 ;* : 19.03.04 Added warning in _DoStr macro when using StrNN 339 ;* : when NN is different from MATHSIZE and no explicit 340 ;* : variable is given 341 ;* : 19.10.04 v8.56 Minor HC08 mode optimization in SIGNED ?ToStr [-1 byte] 342 ;* : 20.02.12 v8.57 Replaced #Message with @Msg to silence debugging messages 343 ;******************************************************************************* 344 345 ;Synopsis (replace * with 16, 24, 32, 40, 48, 56, 64 for corresponding bit version): 346 ; 347 ;Subroutines Action 348 ;-------------- ---------------------------- 349 ;StackAdd* - TOS := TOS + [TOS+1] (signed or unsigned) [TOS+1] removed 350 ;StackSub* - TOS := TOS - [TOS+1] (signed or unsigned) [TOS+1] removed 351 ;StackMul* - TOS := TOS * [TOS+1] (signed or unsigned) [TOS+1] removed 352 ;StackDiv* - TOS := TOS / [TOS+1] (signed if SIGNED) [TOS+1] removed 353 ;StackMod* - TOS := TOS \ [TOS+1] (signed if SIGNED) [TOS+1] removed 354 ;StackAnd* - TOS := TOS & [TOS+1] (signed or unsigned) [TOS+1] removed 355 ;StackOr* - TOS := TOS | [TOS+1] (signed or unsigned) [TOS+1] removed 356 ;StackXor* - TOS := TOS ^ [TOS+1] (signed or unsigned) [TOS+1] removed 357 ;StackShl* - TOS := TOS < [TOS+1] (signed or unsigned) [TOS+1] removed 358 ;StackShr* - TOS := TOS > [TOS+1] (signed if SIGNED) [TOS+1] removed 359 ;StackSwap* - TOS swapped with [TOS+1] (signed or unsigned) 360 ;StackAbs* - TOS := ABS(TOS) (signed) 361 ;StackNegate* - TOS := -TOS (signed) 362 ;StackLoad* - Load const/variable to TOS (signed or unsigned) TOS created 363 ;StackSave* - Save TOS into variable (signed or unsigned) TOS removed 364 ;ResizeTOS - Adjust TOS old size to new (signed or unsigned) TOS resized 365 ;Stack*ToASCIZ - Convert TOS to ASCIZ str (signed if SIGNED) 366 ; 367 ;Macros Purpose Parameters ([...] means optional part) 368 ;------------------ ------------------- ---------------------------------------- 369 ;Load* Stack const or var #Number | Variable 370 ;Save* Unstack a variable Variable 371 ;Copy* Load* & Save* #Number | Variable,Variable 372 ;ResizeTOS Resize TOS #FromByteSize,#ToByteSize 373 ; 374 ;Add* Addition [Addend[,Adder[,Sum]]] 375 ;Sub* Subtraction [Minuend[,Subtrahend[,Difference]]] 376 ;Mul* Multiplication [Multiplicand[,Multiplier[,Product]]] 377 ;Div* Unsigned division [Dividend[,Divisor[,Quotient]]] 378 ;Mod* Unsigned modulo [Dividend[,Divisor[,Remainder]]] 379 ;Abs* Absolute value [SourceVariable][,DestinationVariable] 380 ;Neg* Negation [SourceVariable][,DestinationVariable] 381 ;Swap* Swap TOS numbers 382 ;Str* Number to ASCIZ [Variable],[ResultString] 383 ;AddDecimalPoint ... to ASCIZ number [[#]DecimalPlaces[,[#]ASCIZ_String]] 384 411 412 0040 MATHSIZE def 32 ;default wordsize is 32-bit 413 417 418 ? macro BitSize 419 #if MATHSIZE = ~1~ 420 ?WORD equ ~1~/8 421 _STKMTH{MATHSIZE}_ ;;specific version included 422 _STAKMATH_ def * ;;any version included 423 #endif 424 endm 425 426 M @? 16 ;16-bit quantity (on request) 426 endm 427 M @? 24 ;24-bit quantity (on request) 427 endm 428 M @? 32 ;32-bit quantity (default) 428 endm 429 M @? 40 ;40-bit quantity (on request) 429 endm 430 M @? 48 ;48-bit quantity (on request) 430 endm 431 M @? 56 ;56-bit quantity (on request) 431 endm 432 M @? 64 ;64-bit quantity (on request) 432 M 0008 ?WORD equ 64/8 432 M 2F73 _STKMTH64_ 432 M 182C _STAKMATH_ def * 432 endm 433 439 #Message MATHSIZE = {MATHSIZE}-bit version 441 #Message Signed routines enabled 443 ;******************************************************************************* 444 ; Macros to make operations as simple as with a high-level language 445 ; In operations that require two operands and a result, if only one operand is 446 ; provided, then the operation is done completely on stack (no other variables 447 ; used). For example, @Add32 A,B,SUM adds A to B and places result in SUM, 448 ; while @Add32 A adds the current stack top to A and leaves result on stack. 449 ; You can use @Load* and @Save* to load the initial value, and store the final 450 ; result, respectively. (Replace * with 16, 24, 32, 40, 48, 56, or 64) 451 ;******************************************************************************* 452 501 ;=============================================================================== 550 ;=============================================================================== 599 ;=============================================================================== 648 ;=============================================================================== 697 ;=============================================================================== 746 ;=============================================================================== 748 749 Load64 macro #Number|Variable ;load constant or variable 750 @_DoLoad ~0.{:0-1}~\,~@~ 751 endm 752 753 Save64 macro Address 754 @_DoSave 64\,~@~ 755 endm 756 757 Copy64 macro #Constant|Variable,ToAddress 758 mreq 1,2:#Constant|Variable,ToAddress 759 @@Load64 ~1~ 760 @Save64 ~2~ 761 endm 762 763 Swap64 macro 764 @_DoSwap 64 765 endm 766 767 Add64 macro Addend,Adder,Sum 768 @_DoMath ~0~\,64\,~1~\,~2~\,~3~ 769 endm 770 771 Sub64 macro Minuend,Subtrahend,Difference 772 @_DoMath ~0~\,64\,~1~\,~2~\,~3~ 773 endm 774 775 Mul64 macro Multiplicand,Multiplier,Product 776 @_DoMath ~0~\,64\,~1~\,~2~\,~3~ 777 endm 778 779 Div64 macro Dividend,Divisor,Quotient 780 @_DoMath ~0~\,64\,~1~\,~2~\,~3~ 781 endm 782 783 Mod64 macro Dividend,Divisor,Remainder 784 @_DoMath ~0~\,64\,~1~\,~2~\,~3~ 785 endm 786 787 Abs64 macro Source[,Destination] 788 @_DoAbs 64\,~1~\,~2~ 789 endm 790 791 Neg64 macro Source[,Destination] 792 @_DoNeg 64\,~1~\,~2~ 793 endm 795 796 ;******************************************************************************* 797 ; Common macro(s) for all operations defined above (not to be called directly) 798 ;******************************************************************************* 799 807 ;------------------------------------------------------------------------------- 867 ;------------------------------------------------------------------------------- 890 ;------------------------------------------------------------------------------- 898 ;------------------------------------------------------------------------------- 916 ;=============================================================================== 933 ;------------------------------------------------------------------------------- 1158 ;------------------------------------------------------------------------------- 1185 ;------------------------------------------------------------------------------- 1212 ;------------------------------------------------------------------------------- 1288 ;------------------------------------------------------------------------------- 1328 ;------------------------------------------------------------------------------- 1337 ;------------------------------------------------------------------------------- 1351 ;------------------------------------------------------------------------------- 1380 ;------------------------------------------------------------------------------- 1398 ;------------------------------------------------------------------------------- 1416 ;------------------------------------------------------------------------------- 1451 1452 ;******************************************************************************* 1453 ; External dependencies 1454 ;******************************************************************************* 1455 1456 #Uses string/length.sub 1457 #Uses string/insertchar.sub 1458 #Uses string/adddecimalpoint.sub 1459 2F73 ?_OBJECT_? 1460 ;******************************************************************************* 1461 ; One-based (SP-index) offsets to stacked operands (to be used with #SPAUTO :AB) 1462 ;******************************************************************************* 1463 1464 #temp 1 1465 0001 ?a next :temp,?WORD ;top-of-stack (TOS) number (N1) 1466 0009 ?b next :temp,?WORD ;number after TOS (N2) 1467 1468 #Cycles ;reset the cycles counter 1469 1470 ;******************************************************************************* 1471 ; Purpose: Add N1 to N2 and place result on top-of-stack. N1 & N2 removed 1472 ; Input : [TOS+?WORD] = Number2 1473 ; : [TOS] = Number1 1474 ; Output : [TOS] = Result 1475 ; Note(s): Carry Set on overflow 1476 1477 #spauto :ab 1478 1479 2F73 ?Add proc 1480 [2F73] 2F73:8789 8B [ 6] push 1481 [2F76] 2F76:95 [ 2] tsx 1482 1488 [2F77] 2F77:A608 [ 2] lda #?WORD 1489 [2F79] 2F79:98 [ 1] clc 1490 #Cycles 1491 [2F7A] 2F7A:87 [ 2] Loop@@ psha 1492 [2F7B] 2F7B:E60C [ 3] lda ?a+{::?a-1},spx 1493 [2F7D] 2F7D:E914 [ 3] adc ?b+{::?b-1},spx 1494 [2F7F] 2F7F:E714 [ 3] sta ?b+{::?b-1},spx 1495 [2F81] 2F81:86 [ 3] pula 1496 [2F82] 2F82:AFFF [ 2] aix #-1 1497 [2F84] 2F84:4BF4 (2F7A) [ 4] dbnza Loop@@ 1498 #Cycles :cycles*?WORD+:ocycles 1500 [2F86] 2F86:CC33 A3 [ 4] jmp ?RemoveAndReturn 1501 1502 00AF ?AddCycles equ :cycles 1503 1504 ;******************************************************************************* 1505 ; Purpose: Subtract N2 from N1 and place result on top-of-stack. N1 & N2 removed 1506 ; Input : [TOS+?WORD] = Number2 1507 ; : [TOS] = Number1 1508 ; Output : [TOS] = Result 1509 ; Note(s): Carry Set on borrow 1510 1511 #spauto :ab 1512 1513 2F89 ?Subtract proc 1514 [2F89] 2F89:8789 8B [ 6] push 1515 [2F8C] 2F8C:95 [ 2] tsx 1521 [2F8D] 2F8D:A608 [ 2] lda #?WORD 1522 [2F8F] 2F8F:98 [ 1] clc 1523 #Cycles 1524 [2F90] 2F90:87 [ 2] Loop@@ psha 1525 [2F91] 2F91:E60C [ 3] lda ?a+{::?a-1},spx 1526 [2F93] 2F93:E214 [ 3] sbc ?b+{::?b-1},spx 1527 [2F95] 2F95:E714 [ 3] sta ?b+{::?b-1},spx 1528 [2F97] 2F97:86 [ 3] pula 1529 [2F98] 2F98:AFFF [ 2] aix #-1 1530 [2F9A] 2F9A:4BF4 (2F90) [ 4] dbnza Loop@@ 1531 #Cycles :cycles*?WORD+:ocycles 1533 [2F9C] 2F9C:CC33 A3 [ 4] jmp ?RemoveAndReturn 1534 1535 00AF ?SubCycles equ :cycles 1536 1540 M @Msg Bit ops enabled (define NO_BIT_OPS to disable) 1540 mexit 1541 ;******************************************************************************* 1542 ; Purpose: AND N1 with N2 and place result on top-of-stack. N1 & N2 removed 1543 ; Input : [TOS+?WORD] = Number2 1544 ; : [TOS] = Number1 1545 ; Output : [TOS] = Result 1546 ; Note(s): 1547 #spauto :ab 1548 1549 2F9F ?BitAnd proc 1550 [2F9F] 2F9F:8789 8B [ 6] push 1551 [2FA2] 2FA2:95 [ 2] tsx 1552 1558 [2FA3] 2FA3:A608 [ 2] lda #?WORD 1559 #Cycles 1560 [2FA5] 2FA5:87 [ 2] Loop@@ psha 1561 [2FA6] 2FA6:E60C [ 3] lda ?a+{::?a-1},spx 1562 [2FA8] 2FA8:E414 [ 3] and ?b+{::?b-1},spx 1563 [2FAA] 2FAA:E714 [ 3] sta ?b+{::?b-1},spx 1564 [2FAC] 2FAC:86 [ 3] pula 1565 [2FAD] 2FAD:AFFF [ 2] aix #-1 1566 [2FAF] 2FAF:4BF4 (2FA5) [ 4] dbnza Loop@@ 1567 #Cycles :cycles*?WORD+:ocycles 1569 [2FB1] 2FB1:CC33 A3 [ 4] jmp ?RemoveAndReturn 1570 1571 00AE ?AndCycles equ :cycles 1572 1573 ;******************************************************************************* 1574 ; Purpose: OR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1575 ; Input : [TOS+?WORD] = Number2 1576 ; : [TOS] = Number1 1577 ; Output : [TOS] = Result 1578 ; Note(s): 1579 #spauto :ab 1580 1581 2FB4 ?BitOr proc 1582 [2FB4] 2FB4:8789 8B [ 6] push 1583 [2FB7] 2FB7:95 [ 2] tsx 1584 1590 [2FB8] 2FB8:A608 [ 2] lda #?WORD 1591 #Cycles 1592 [2FBA] 2FBA:87 [ 2] Loop@@ psha 1593 [2FBB] 2FBB:E60C [ 3] lda ?a+{::?a-1},spx 1594 [2FBD] 2FBD:EA14 [ 3] ora ?b+{::?b-1},spx 1595 [2FBF] 2FBF:E714 [ 3] sta ?b+{::?b-1},spx 1596 [2FC1] 2FC1:86 [ 3] pula 1597 [2FC2] 2FC2:AFFF [ 2] aix #-1 1598 [2FC4] 2FC4:4BF4 (2FBA) [ 4] dbnza Loop@@ 1599 #Cycles :cycles*?WORD+:ocycles 1601 [2FC6] 2FC6:CC33 A3 [ 4] jmp ?RemoveAndReturn 1602 1603 00AE ?OrCycles equ :cycles 1604 1605 ;******************************************************************************* 1606 ; Purpose: XOR N1 with N2 and place result on top-of-stack. N1 & N2 removed 1607 ; Input : [TOS+?WORD] = Number2 1608 ; : [TOS] = Number1 1609 ; Output : [TOS] = Result 1610 ; Note(s): 1611 #spauto :ab 1612 1613 2FC9 ?BitXor proc 1614 [2FC9] 2FC9:8789 8B [ 6] push 1615 [2FCC] 2FCC:95 [ 2] tsx 1616 1622 [2FCD] 2FCD:A608 [ 2] lda #?WORD 1623 #Cycles 1624 [2FCF] 2FCF:87 [ 2] Loop@@ psha 1625 [2FD0] 2FD0:E60C [ 3] lda ?a+{::?a-1},spx 1626 [2FD2] 2FD2:E814 [ 3] eor ?b+{::?b-1},spx 1627 [2FD4] 2FD4:E714 [ 3] sta ?b+{::?b-1},spx 1628 [2FD6] 2FD6:86 [ 3] pula 1629 [2FD7] 2FD7:AFFF [ 2] aix #-1 1630 [2FD9] 2FD9:4BF4 (2FCF) [ 4] dbnza Loop@@ 1631 #Cycles :cycles*?WORD+:ocycles 1633 [2FDB] 2FDB:CC33 A3 [ 4] jmp ?RemoveAndReturn 1634 1635 00AE ?EorCycles equ :cycles 1636 1637 ;******************************************************************************* 1638 ; Purpose: Shift N1 left N2 times and place result on top-of-stack. N1 & N2 removed 1639 ; Input : [TOS+?WORD] = Number2 1640 ; : [TOS] = Number1 1641 ; Output : [TOS] = Result 1642 ; Note(s): CCR[C] = last most significant bit shifted out 1643 ; : Only LSB of second operand (N2) is used, as shifting more than the 1644 ; : highest bit version always produces zero. Any non-zero bytes in the 1645 ; : N2 operand will cause a zero result, regardless. 1646 1647 #spauto :ab 1648 1649 2FDE ?ShiftLeft proc 1650 [2FDE] 2FDE:8789 8B [ 6] push 1651 #ais 1652 1653 [2FE1] 2FE1:9EE6 15 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1654 [2FE4] 2FE4:87 [ 2] psha counter@@ 1655 1656 [2FE5] 2FE5:95 [ 2] tsx 1657 1658 [2FE6] 2FE6:6F15 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1659 0009 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1660 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1660 M mset # 1660 M mreq 1 1660 M @@_nosize_ b124,spx 1660 M mset # 1660 M mset 0,mstop [_tst_.s] No size (b124,spx) 1660 M endm 1660 M mdo 1660 M [2FE8] 2FE8:E60E [ 3] lda b124+0,spx 1660 M mloop ::b124 1660 M [2FEA] 2FEA:EA0F [ 3] ora b124+1,spx 1660 M mloop ::b124 1660 M [2FEC] 2FEC:EA10 [ 3] ora b124+2,spx 1660 M mloop ::b124 1660 M [2FEE] 2FEE:EA11 [ 3] ora b124+3,spx 1660 M mloop ::b124 1660 M [2FF0] 2FF0:EA12 [ 3] ora b124+4,spx 1660 M mloop ::b124 1660 M [2FF2] 2FF2:EA13 [ 3] ora b124+5,spx 1660 M mloop ::b124 1660 M [2FF4] 2FF4:EA14 [ 3] ora b124+6,spx 1660 M mloop ::b124 1660 endm 1661 [2FF6] 2FF6:2715 (300D) [ 3] beq Go@@ ;if so, proceed normally 1662 1663 [2FF8] 2FF8:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1664 [2FF9] 2FF9:A140 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1665 [2FFB] 2FFB:2510 (300D) [ 3] blo Go@@ ;else zero and exit 1666 1667 M @clr.s, b@@,spx ;else error, so zero result 1667 M mset #' ' 1667 M mreq 1 1667 M @@_nosize_ b124,spx 1667 M mset # 1667 M mset 0,mstop [clr.s] No size (b124,spx) 1667 M endm 1667 M mdef 2,::b124 1667 M mdo 1667 M [2FFD] 2FFD:6F0E [ 5] clr b124+0,spx 1667 M mloop ::b124 1667 M [2FFF] 2FFF:6F0F [ 5] clr b124+1,spx 1667 M mloop ::b124 1667 M [3001] 3001:6F10 [ 5] clr b124+2,spx 1667 M mloop ::b124 1667 M [3003] 3003:6F11 [ 5] clr b124+3,spx 1667 M mloop ::b124 1667 M [3005] 3005:6F12 [ 5] clr b124+4,spx 1667 M mloop ::b124 1667 M [3007] 3007:6F13 [ 5] clr b124+5,spx 1667 M mloop ::b124 1667 M [3009] 3009:6F14 [ 5] clr b124+6,spx 1667 M mloop ::b124 1667 endm 1668 [300B] 300B:2032 (303F) [ 3] bra Done@@ ;and get out 1669 1670 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1670 M mset #' ' 1670 M mreq 1,2:Source Destination 1670 M @@_samesize_ ?a,spx ?b,spx 1670 M mreq 1,2:Operand1,Operand2[,Operand]* 1670 M mset 0 1670 M mdo 1670 M mswap 1,1 1670 M @@_nosize_ ?a,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?a,spx) 1670 M endm 1670 M mset 0,?a,spx 1670 M mloop :n 1670 M mswap 1,2 1670 M @@_nosize_ ?b,spx 1670 M mset # 1670 M mset 0,mstop [_samesize_] No size (?b,spx) 1670 M endm 1670 M mloop :n 1670 M endm 1670 M mset 0 1670 M mdo 1670 M [300D] 300D:E606 [ 3] lda ?a+0,spx 1670 M [300F] 300F:E70E [ 3] sta ?b+0,spx 1670 M mloop ::?b 1670 M [3011] 3011:E607 [ 3] lda ?a+1,spx 1670 M [3013] 3013:E70F [ 3] sta ?b+1,spx 1670 M mloop ::?b 1670 M [3015] 3015:E608 [ 3] lda ?a+2,spx 1670 M [3017] 3017:E710 [ 3] sta ?b+2,spx 1670 M mloop ::?b 1670 M [3019] 3019:E609 [ 3] lda ?a+3,spx 1670 M [301B] 301B:E711 [ 3] sta ?b+3,spx 1670 M mloop ::?b 1670 M [301D] 301D:E60A [ 3] lda ?a+4,spx 1670 M [301F] 301F:E712 [ 3] sta ?b+4,spx 1670 M mloop ::?b 1670 M [3021] 3021:E60B [ 3] lda ?a+5,spx 1670 M [3023] 3023:E713 [ 3] sta ?b+5,spx 1670 M mloop ::?b 1670 M [3025] 3025:E60C [ 3] lda ?a+6,spx 1670 M [3027] 3027:E714 [ 3] sta ?b+6,spx 1670 M mloop ::?b 1670 M [3029] 3029:E60D [ 3] lda ?a+7,spx 1670 M [302B] 302B:E715 [ 3] sta ?b+7,spx 1670 M mloop ::?b 1670 endm 1671 #Cycles 1672 M Loop@@ @lsl.s, ?b,spx ;shift left one bit position 1672 M mset # 1672 M mreq 1 1672 M @@_nosize_ ?b,spx 1672 M mset # 1672 M mset 0,mstop [lsl.s] No size (?b,spx) 1672 M endm 1672 M mdo 1672 M [302D] 302D:6815 [ 5] lsl ?b+7,spx 1672 M mloop ::?b 1672 M [302F] 302F:6914 [ 5] rol ?b+6,spx 1672 M mloop ::?b 1672 M [3031] 3031:6913 [ 5] rol ?b+5,spx 1672 M mloop ::?b 1672 M [3033] 3033:6912 [ 5] rol ?b+4,spx 1672 M mloop ::?b 1672 M [3035] 3035:6911 [ 5] rol ?b+3,spx 1672 M mloop ::?b 1672 M [3037] 3037:6910 [ 5] rol ?b+2,spx 1672 M mloop ::?b 1672 M [3039] 3039:690F [ 5] rol ?b+1,spx 1672 M mloop ::?b 1672 M [303B] 303B:690E [ 5] rol ?b+0,spx 1672 M mloop ::?b 1672 endm 1673 [303D] 303D:7BEE (302D) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1674 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1675 303F Done@@ 1677 [303F] 303F:86 [ 3] pula 1681 [3040] 3040:CC33 A3 [ 4] jmp ?RemoveAndReturn 1682 1683 0BE2 ?ShlCycles equ :cycles 1684 1685 ;******************************************************************************* 1686 ; Purpose: Shift N1 right N2 times and place result on top-of-stack. N1 & N2 removed 1687 ; Input : [TOS+?WORD] = Number2 1688 ; : [TOS] = Number1 1689 ; Output : [TOS] = Result 1690 ; Note(s): CCR[C] = last least significant bit shifted out 1691 ; : Only LSB of second operand (N2) is used, as shifting more than the 1692 ; : highest bit version always produces zero. Any non-zero bytes in the 1693 ; : N2 operand will cause a zero result, regardless. 1694 1695 #spauto :ab 1696 1697 3043 ?ShiftRight proc 1698 [3043] 3043:8789 8B [ 6] push 1699 #ais 1700 1701 [3046] 3046:9EE6 15 [ 4] lda ?b+{::?b-1},sp ;A = shift counter 1702 [3049] 3049:87 [ 2] psha counter@@ 1703 1704 [304A] 304A:95 [ 2] tsx 1705 1706 [304B] 304B:6F15 [ 5] clr ?b+{::?b-1},spx ;clear original shift counter 1707 0009 b@@ equ ?b,::?b-1 ;(b@@ = ?b but excludes final already cleared byte - 2013.11.29 optimization) 1708 M @_tst_.s, b@@,spx ;test whole word for zero (counter <= 8-bit) 1708 M mset # 1708 M mreq 1 1708 M @@_nosize_ b125,spx 1708 M mset # 1708 M mset 0,mstop [_tst_.s] No size (b125,spx) 1708 M endm 1708 M mdo 1708 M [304D] 304D:E60E [ 3] lda b125+0,spx 1708 M mloop ::b125 1708 M [304F] 304F:EA0F [ 3] ora b125+1,spx 1708 M mloop ::b125 1708 M [3051] 3051:EA10 [ 3] ora b125+2,spx 1708 M mloop ::b125 1708 M [3053] 3053:EA11 [ 3] ora b125+3,spx 1708 M mloop ::b125 1708 M [3055] 3055:EA12 [ 3] ora b125+4,spx 1708 M mloop ::b125 1708 M [3057] 3057:EA13 [ 3] ora b125+5,spx 1708 M mloop ::b125 1708 M [3059] 3059:EA14 [ 3] ora b125+6,spx 1708 M mloop ::b125 1708 endm 1709 [305B] 305B:2715 (3072) [ 3] beq Go@@ ;if so, proceed normally 1710 1711 [305D] 305D:F6 [ 3] lda counter@@,spx ;if shift counter is less than 1712 [305E] 305E:A140 [ 2] cmpa #MATHSIZE ;MATHSIZE, proceed normally, 1713 [3060] 3060:2510 (3072) [ 3] blo Go@@ ;else zero and exit 1714 1715 M @clr.s, b@@,spx ;else error, so zero result 1715 M mset #' ' 1715 M mreq 1 1715 M @@_nosize_ b125,spx 1715 M mset # 1715 M mset 0,mstop [clr.s] No size (b125,spx) 1715 M endm 1715 M mdef 2,::b125 1715 M mdo 1715 M [3062] 3062:6F0E [ 5] clr b125+0,spx 1715 M mloop ::b125 1715 M [3064] 3064:6F0F [ 5] clr b125+1,spx 1715 M mloop ::b125 1715 M [3066] 3066:6F10 [ 5] clr b125+2,spx 1715 M mloop ::b125 1715 M [3068] 3068:6F11 [ 5] clr b125+3,spx 1715 M mloop ::b125 1715 M [306A] 306A:6F12 [ 5] clr b125+4,spx 1715 M mloop ::b125 1715 M [306C] 306C:6F13 [ 5] clr b125+5,spx 1715 M mloop ::b125 1715 M [306E] 306E:6F14 [ 5] clr b125+6,spx 1715 M mloop ::b125 1715 endm 1716 [3070] 3070:2032 (30A4) [ 3] bra Done@@ ;and get out 1717 1718 M Go@@ @mova.s ?a,spx ?b,spx ;copy operand to result 1718 M mset #' ' 1718 M mreq 1,2:Source Destination 1718 M @@_samesize_ ?a,spx ?b,spx 1718 M mreq 1,2:Operand1,Operand2[,Operand]* 1718 M mset 0 1718 M mdo 1718 M mswap 1,1 1718 M @@_nosize_ ?a,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?a,spx) 1718 M endm 1718 M mset 0,?a,spx 1718 M mloop :n 1718 M mswap 1,2 1718 M @@_nosize_ ?b,spx 1718 M mset # 1718 M mset 0,mstop [_samesize_] No size (?b,spx) 1718 M endm 1718 M mloop :n 1718 M endm 1718 M mset 0 1718 M mdo 1718 M [3072] 3072:E606 [ 3] lda ?a+0,spx 1718 M [3074] 3074:E70E [ 3] sta ?b+0,spx 1718 M mloop ::?b 1718 M [3076] 3076:E607 [ 3] lda ?a+1,spx 1718 M [3078] 3078:E70F [ 3] sta ?b+1,spx 1718 M mloop ::?b 1718 M [307A] 307A:E608 [ 3] lda ?a+2,spx 1718 M [307C] 307C:E710 [ 3] sta ?b+2,spx 1718 M mloop ::?b 1718 M [307E] 307E:E609 [ 3] lda ?a+3,spx 1718 M [3080] 3080:E711 [ 3] sta ?b+3,spx 1718 M mloop ::?b 1718 M [3082] 3082:E60A [ 3] lda ?a+4,spx 1718 M [3084] 3084:E712 [ 3] sta ?b+4,spx 1718 M mloop ::?b 1718 M [3086] 3086:E60B [ 3] lda ?a+5,spx 1718 M [3088] 3088:E713 [ 3] sta ?b+5,spx 1718 M mloop ::?b 1718 M [308A] 308A:E60C [ 3] lda ?a+6,spx 1718 M [308C] 308C:E714 [ 3] sta ?b+6,spx 1718 M mloop ::?b 1718 M [308E] 308E:E60D [ 3] lda ?a+7,spx 1718 M [3090] 3090:E715 [ 3] sta ?b+7,spx 1718 M mloop ::?b 1718 endm 1719 #Cycles 1720 3092 Loop@@ 1722 M @asr.s, ?b,spx ;shift right one bit position 1722 M mset # 1722 M mreq 1 1722 M @@_nosize_ ?b,spx 1722 M mset # 1722 M mset 0,mstop [asr.s] No size (?b,spx) 1722 M endm 1722 M mdo 1722 M [3092] 3092:670E [ 5] asr ?b+0,spx 1722 M mloop ::?b 1722 M [3094] 3094:660F [ 5] ror ?b+1,spx 1722 M mloop ::?b 1722 M [3096] 3096:6610 [ 5] ror ?b+2,spx 1722 M mloop ::?b 1722 M [3098] 3098:6611 [ 5] ror ?b+3,spx 1722 M mloop ::?b 1722 M [309A] 309A:6612 [ 5] ror ?b+4,spx 1722 M mloop ::?b 1722 M [309C] 309C:6613 [ 5] ror ?b+5,spx 1722 M mloop ::?b 1722 M [309E] 309E:6614 [ 5] ror ?b+6,spx 1722 M mloop ::?b 1722 M [30A0] 30A0:6615 [ 5] ror ?b+7,spx 1722 M mloop ::?b 1722 endm 1726 [30A2] 30A2:7BEE (3092) [ 6] dbnz counter@@,spx,Loop@@ ;repeat for all bits 1727 #Cycles :cycles*{MATHSIZE-1}+:ocycles 1728 30A4 Done@@ 1730 [30A4] 30A4:86 [ 3] pula 1734 [30A5] 30A5:CC33 A3 [ 4] jmp ?RemoveAndReturn 1735 1736 0BE2 ?ShrCycles equ :cycles 1738 1739 ;******************************************************************************* 1740 ; Purpose: Multiply N1 with N2 and place result on top-of-stack. N1 & N2 removed 1741 ; Input : [TOS+?WORD] = Number2 1742 ; : [TOS] = Number1 1743 ; Output : [TOS] = Result 1744 ; Note(s): Overflows lost, Carry state should be ignored 1745 1746 #spauto :ab 1747 1748 30A8 ?Multiply proc 1749 [30A8] 30A8:8789 8B [ 6] push 1773 ;=============================================================================== 1826 ;=============================================================================== 1913 #temp :cycles 1914 ;=============================================================================== 1915 ;-------------------------------------- 1916 ; 40, 48, 56, and 64-bit versions use shorter 1917 ; shift/add method (more cycles, though) 1918 ;-------------------------------------- 1920 1921 [30AB] 30AB:AE08 [ 2] ldx #?WORD ;make room for result... 1922 [30AD] 30AD:4F [ 1] clra ;... initialized to zero 1923 #temp :cycles+:temp 1924 [30AE] 30AE:87 [ 2] Init@@ psha 1925 [30AF] 30AF:5BFD (30AE) [ 4] dbnzx Init@@ 1926 #temp :cycles*?WORD+:temp 1927 #spadd ?WORD-1 ;stack has grown by a ?WORD 1928 FFFFFFF4 ans@@ equ ::,?WORD 1929 1930 [30B1] 30B1:A640 [ 2] lda #MATHSIZE ;number of bits to process 1931 [30B3] 30B3:87 [ 2] psha bits@@ 1932 1933 [30B4] 30B4:95 [ 2] tsx 1934 #temp :cycles+:temp 1935 M Loop@@ @lsr.s ?b,spx ;multiplier lsb into CCR[C] 1935 M mset # 1935 M mreq 1 1935 M @@_nosize_ ?b,spx 1935 M mset # 1935 M mset 0,mstop [lsr.s] No size (?b,spx) 1935 M endm 1935 M mdo 1935 M [30B5] 30B5:6416 [ 5] lsr ?b+0,spx 1935 M mloop ::?b 1935 M [30B7] 30B7:6617 [ 5] ror ?b+1,spx 1935 M mloop ::?b 1935 M [30B9] 30B9:6618 [ 5] ror ?b+2,spx 1935 M mloop ::?b 1935 M [30BB] 30BB:6619 [ 5] ror ?b+3,spx 1935 M mloop ::?b 1935 M [30BD] 30BD:661A [ 5] ror ?b+4,spx 1935 M mloop ::?b 1935 M [30BF] 30BF:661B [ 5] ror ?b+5,spx 1935 M mloop ::?b 1935 M [30C1] 30C1:661C [ 5] ror ?b+6,spx 1935 M mloop ::?b 1935 M [30C3] 30C3:661D [ 5] ror ?b+7,spx 1935 M mloop ::?b 1935 endm 1936 [30C5] 30C5:2430 (30F7) [ 3] bcc Skip@@ ;Zeros skip addition 1937 1938 M @add.s ?a,spx ans@@,spx ans@@,spx ;Ones add multiplicand to product 1938 M mset #' ' 1938 M mreq 1,2,3:[#]Operand1 [#]Operand2 Destination 1938 M @@_samesize_ ?a,spx ans126,spx ans@@,spx 1938 M mreq 1,2:Operand1,Operand2[,Operand]* 1938 M mset 0 1938 M mdo 1938 M mswap 1,1 1938 M @@_nosize_ ?a,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (?a,spx) 1938 M endm 1938 M mset 0,?a,spx 1938 M mloop :n 1938 M mswap 1,2 1938 M @@_nosize_ ans126,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans126,spx) 1938 M endm 1938 M mloop :n 1938 M mswap 1,3 1938 M @@_nosize_ ans@@,spx 1938 M mset # 1938 M mset 0,mstop [_samesize_] No size (ans126,spx) 1938 M endm 1938 M mloop :n 1938 M endm 1938 M mset 0,@@add.b, 1938 M mdo 1938 M mset 0,@@add.b, ?a+7,spx 1938 M mset 0,@@add.b, ?a+7,spx ans126+7,spx 1938 M mset 0,@@add.b, ?a+7,spx ans126+7,spx ans@@+7,spx 1938 M @@add.b, ?a+7,spx ans126+7,spx ans@@+7,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30C7] 30C7:E615 [ 3] lda ?a+7,spx 1938 M [30C9] 30C9:EB08 [ 3] add ans126+7,spx 1938 M @_sta_ ans@@+7,spx 1938 M [30CB] 30CB:E708 [ 3] sta ans126+7,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+6,spx 1938 M mset 0,@@adc.b, ?a+6,spx ans126+6,spx 1938 M mset 0,@@adc.b, ?a+6,spx ans126+6,spx ans@@+6,spx 1938 M @@adc.b, ?a+6,spx ans126+6,spx ans@@+6,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30CD] 30CD:E614 [ 3] lda ?a+6,spx 1938 M [30CF] 30CF:E907 [ 3] adc ans126+6,spx 1938 M @_sta_ ans@@+6,spx 1938 M [30D1] 30D1:E707 [ 3] sta ans126+6,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+5,spx 1938 M mset 0,@@adc.b, ?a+5,spx ans126+5,spx 1938 M mset 0,@@adc.b, ?a+5,spx ans126+5,spx ans@@+5,spx 1938 M @@adc.b, ?a+5,spx ans126+5,spx ans@@+5,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30D3] 30D3:E613 [ 3] lda ?a+5,spx 1938 M [30D5] 30D5:E906 [ 3] adc ans126+5,spx 1938 M @_sta_ ans@@+5,spx 1938 M [30D7] 30D7:E706 [ 3] sta ans126+5,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+4,spx 1938 M mset 0,@@adc.b, ?a+4,spx ans126+4,spx 1938 M mset 0,@@adc.b, ?a+4,spx ans126+4,spx ans@@+4,spx 1938 M @@adc.b, ?a+4,spx ans126+4,spx ans@@+4,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30D9] 30D9:E612 [ 3] lda ?a+4,spx 1938 M [30DB] 30DB:E905 [ 3] adc ans126+4,spx 1938 M @_sta_ ans@@+4,spx 1938 M [30DD] 30DD:E705 [ 3] sta ans126+4,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans126+3,spx 1938 M mset 0,@@adc.b, ?a+3,spx ans126+3,spx ans@@+3,spx 1938 M @@adc.b, ?a+3,spx ans126+3,spx ans@@+3,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30DF] 30DF:E611 [ 3] lda ?a+3,spx 1938 M [30E1] 30E1:E904 [ 3] adc ans126+3,spx 1938 M @_sta_ ans@@+3,spx 1938 M [30E3] 30E3:E704 [ 3] sta ans126+3,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans126+2,spx 1938 M mset 0,@@adc.b, ?a+2,spx ans126+2,spx ans@@+2,spx 1938 M @@adc.b, ?a+2,spx ans126+2,spx ans@@+2,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30E5] 30E5:E610 [ 3] lda ?a+2,spx 1938 M [30E7] 30E7:E903 [ 3] adc ans126+2,spx 1938 M @_sta_ ans@@+2,spx 1938 M [30E9] 30E9:E703 [ 3] sta ans126+2,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans126+1,spx 1938 M mset 0,@@adc.b, ?a+1,spx ans126+1,spx ans@@+1,spx 1938 M @@adc.b, ?a+1,spx ans126+1,spx ans@@+1,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30EB] 30EB:E60F [ 3] lda ?a+1,spx 1938 M [30ED] 30ED:E902 [ 3] adc ans126+1,spx 1938 M @_sta_ ans@@+1,spx 1938 M [30EF] 30EF:E702 [ 3] sta ans126+1,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 M mset 0,@@adc.b, ?a+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans126+0,spx 1938 M mset 0,@@adc.b, ?a+0,spx ans126+0,spx ans@@+0,spx 1938 M @@adc.b, ?a+0,spx ans126+0,spx ans@@+0,spx 1938 M mswap 1,2 1938 M mswap 1,2 1938 M [30F1] 30F1:E60E [ 3] lda ?a+0,spx 1938 M [30F3] 30F3:E901 [ 3] adc ans126+0,spx 1938 M @_sta_ ans@@+0,spx 1938 M [30F5] 30F5:E701 [ 3] sta ans126+0,spx 1938 M endm 1938 M mset 0,@@adc.b, 1938 M mloop ::ans@@ 1938 endm 1939 1940 M Skip@@ @lsl.s ?a,spx ;Multiplicand*=2 for each bit 1940 M mset # 1940 M mreq 1 1940 M @@_nosize_ ?a,spx 1940 M mset # 1940 M mset 0,mstop [lsl.s] No size (?a,spx) 1940 M endm 1940 M mdo 1940 M [30F7] 30F7:6815 [ 5] lsl ?a+7,spx 1940 M mloop ::?a 1940 M [30F9] 30F9:6914 [ 5] rol ?a+6,spx 1940 M mloop ::?a 1940 M [30FB] 30FB:6913 [ 5] rol ?a+5,spx 1940 M mloop ::?a 1940 M [30FD] 30FD:6912 [ 5] rol ?a+4,spx 1940 M mloop ::?a 1940 M [30FF] 30FF:6911 [ 5] rol ?a+3,spx 1940 M mloop ::?a 1940 M [3101] 3101:6910 [ 5] rol ?a+2,spx 1940 M mloop ::?a 1940 M [3103] 3103:690F [ 5] rol ?a+1,spx 1940 M mloop ::?a 1940 M [3105] 3105:690E [ 5] rol ?a+0,spx 1940 M mloop ::?a 1940 endm 1941 [3107] 3107:7BAC (30B5) [ 6] dbnz bits@@,spx,Loop@@ 1942 #temp :cycles*MATHSIZE+:temp 1943 [3109] 3109:86 [ 3] pula ;remove bit counter 1945 ;-------------------------------------- 1946 ; copy result to B while removing from stack 1947 ;-------------------------------------- 1948 [310A] 310A:AE08 [ 2] ldx #?WORD 1949 #temp :cycles+:temp 1950 [310C] 310C:86 [ 3] CopyResult@@ pula 1951 [310D] 310D:9EE7 15 [ 4] sta ?b,sp 1952 [3110] 3110:5BFA (310C) [ 4] dbnzx CopyResult@@ 1953 1954 #spadd 1-?WORD 1955 #temp :cycles*?WORD+:temp 1956 [3112] 3112:CC33 A3 [ 4] jmp ?RemoveAndReturn 1957 1958 28E0 ?MulCycles equ :temp+:cycles 1959 1960 ;******************************************************************************* 1961 ; Purpose: Divide N1 by N2 and place quotient on top-of-stack. N1 & N2 removed 1962 ; Input : [TOS+?WORD] = Divisor (N2) 1963 ; : [TOS] = Dividend (N1) 1964 ; Output : [TOS] = Quotient 1965 ; : Carry Set on error (division by zero) 1966 ; Note(s): 1967 #spauto :ab 1968 1969 3115 ?Divide proc 1970 [3115] 3115:8789 8B [ 6] push 1971 1972 [3118] 3118:A601 [ 2] lda #?DIVOP_ ;flag for DIV operation 1974 [311A] 311A:87 [ 2] psha 1975 [311B] 311B:95 [ 2] tsx 1976 [311C] 311C:E606 [ 3] lda ?a,spx 1977 [311E] 311E:E80E [ 3] eor ?b,spx 1978 [3120] 3120:86 [ 3] pula 1979 [3121] 3121:2A02 (3125) [ 3] bpl Skip@@ 1980 [3123] 3123:AA80 [ 2] ora #?SIGN_ ;flag for negative 1981 3125 Skip@@ 1983 [3125] 3125:87 [ 2] psha ;save flags on stack 1984 [3126] 3126:2042 (316A) [ 3] bra ?DivStart 1985 1986 001F ?DivCycles equ :cycles 1987 1988 ;******************************************************************************* 1989 ; Purpose: Divide N1 by N2 and place remainder on top-of-stack. N1 & N2 removed 1990 ; Input : [TOS+?WORD] = Divisor (N2) 1991 ; : [TOS] = Dividend (N1) 1992 ; Output : [TOS] = Remainder 1993 ; : Carry Set on error (division by zero) 1994 ; Note(s): 1995 #spauto :ab 1996 FFFFFFFF ?pc equ ::,:ab 1997 1998 3128 ?Modulo proc 1999 [3128] 3128:8789 8B [ 6] push 2000 2001 [312B] 312B:4F [ 1] clra ;flag for MOD operation 2003 [312C] 312C:9E6D 06 [ 5] tst ?a,sp 2004 [312F] 312F:2A02 (3133) [ 3] bpl Skip@@ 2005 [3131] 3131:AA80 [ 2] ora #?SIGN_ ;flag for negative 2006 3133 Skip@@ 2008 [3133] 3133:87 [ 2] psha ;save flags on stack 2009 [3134] 3134:2034 (316A) [ 3] bra ?DivStart 2010 2011 0016 ?ModCycles equ :cycles 2012 2013 ;******************************************************************************* 2014 2015 #temp 2017 3136 ?AbsX proc 2018 [3136] 3136:7D [ 3] tst ,ax 2019 [3137] 3137:2A2A (3163) [ 3] bpl Done@@ 2020 #temp :cycles 2021 0000 var@@ equ 0,?WORD 2022 M ?NegX @neg.s var@@,ax 2022 M mset # 2022 M mreq 1 2022 M @@_nosize_ var129,ax 2022 M mset # 2022 M mset 0,mstop [neg.s] No size (var129,ax) 2022 M endm 2022 M mdo 2022 M [3139] 3139:73 [ 4] com var129+0,ax 2022 M mloop ::var129-1 2022 M [313A] 313A:6301 [ 5] com var129+1,ax 2022 M mloop ::var129-1 2022 M [313C] 313C:6302 [ 5] com var129+2,ax 2022 M mloop ::var129-1 2022 M [313E] 313E:6303 [ 5] com var129+3,ax 2022 M mloop ::var129-1 2022 M [3140] 3140:6304 [ 5] com var129+4,ax 2022 M mloop ::var129-1 2022 M [3142] 3142:6305 [ 5] com var129+5,ax 2022 M mloop ::var129-1 2022 M [3144] 3144:6306 [ 5] com var129+6,ax 2022 M mloop ::var129-1 2022 M [3146] 3146:6007 [ 5] neg var129+7,ax 2022 M mdo 2022 M [3148] 3148:2619 (3163) [ 3] bne Done$$$ 2022 M [314A] 314A:6C06 [ 5] inc var129+6,ax 2022 M mloop ::var129-1 2022 M [314C] 314C:2615 (3163) [ 3] bne Done$$$ 2022 M [314E] 314E:6C05 [ 5] inc var129+5,ax 2022 M mloop ::var129-1 2022 M [3150] 3150:2611 (3163) [ 3] bne Done$$$ 2022 M [3152] 3152:6C04 [ 5] inc var129+4,ax 2022 M mloop ::var129-1 2022 M [3154] 3154:260D (3163) [ 3] bne Done$$$ 2022 M [3156] 3156:6C03 [ 5] inc var129+3,ax 2022 M mloop ::var129-1 2022 M [3158] 3158:2609 (3163) [ 3] bne Done$$$ 2022 M [315A] 315A:6C02 [ 5] inc var129+2,ax 2022 M mloop ::var129-1 2022 M [315C] 315C:2605 (3163) [ 3] bne Done$$$ 2022 M [315E] 315E:6C01 [ 5] inc var129+1,ax 2022 M mloop ::var129-1 2022 M [3160] 3160:2601 (3163) [ 3] bne Done$$$ 2022 M [3162] 3162:7C [ 4] inc var129+0,ax 2022 M mloop ::var129-1 2022 M 3163 Done$$$ 2022 endm 2023 [3163] 3163:81 [ 6] Done@@ rts 2024 2025 0064 ?AbsXCycles equ :cycles 2026 005E ?NegxCycles equ ?AbsXCycles-:temp 2028 2029 ;******************************************************************************* 2030 2031 0000 ?SF equ 0 ;stack frame (for X-index use) 2032 2033 0000 ?quotient next ?SF,?WORD 2034 0008 ?remainder next ?SF,?WORD 2035 0010 ?temp next ?SF,?WORD 2036 0018 ?bits next ?SF 2037 0019 ?flags next ?SF 2038 2039 0001 ?DIVOP_ equ %00000001 ;1 = DIV, 0 = MOD 2040 0080 ?SIGN_ equ %10000000 ;result sign (1 = negative) 2041 2042 #push 2043 2044 [3164] 3164:A71A [ 2] ?DivError ais #?SF ;de-allocate temporaries 2045 [3166] 3166:99 [ 1] sec ;indicate error condition 2046 [3167] 3167:CC33 A3 [ 4] jmp ?RemoveAndReturn 2047 2048 #pull 2049 ;------------------------------------------------------------------------------- 2050 316A ?DivStart proc 2051 0001 dividend@@ equ ?a,::?a 2052 0009 divisor@@ equ ?b,::?b 2053 0009 ans@@ equ ?b,::?b ;result overwrites divisor 2054 2056 M @lea dividend@@,sp 2056 M mset # 2056 M [316A] 316A:95 [ 2] tsx 2056 M [316B] 316B:AF06 [ 2] !aix #dividend130+:tsx 2056 mexit 2057 [316D] 316D:ADC7 (3136) [ 5] bsr ?AbsX 2058 M @lea divisor@@,sp 2058 M mset # 2058 M [316F] 316F:95 [ 2] tsx 2058 M [3170] 3170:AF0E [ 2] !aix #divisor130+:tsx 2058 mexit 2059 [3172] 3172:ADC2 (3136) [ 5] bsr ?AbsX 2060 #Cycles ?AbsXCycles*2+:cycles 2062 [3174] 3174:A7E7 [ 2] ais #-?SF+1 ;quotient, remainder, and temp 2063 [3176] 3176:95 [ 2] tsx ;(+1 for already pushed Flag) 2064 2065 ; remainder := 0 2066 ; quotient := 0 2067 2068 M @clr.s ?remainder,x 2068 M mset #' ' 2068 M mreq 1 2068 M @@_nosize_ ?remainder,x 2068 M mset # 2068 M mset 0,mstop [clr.s] No size (?remainder,x) 2068 M endm 2068 M mdef 2,::?remainder 2068 M mdo 2068 M [3177] 3177:6F08 [ 5] clr ?remainder+0,x 2068 M mloop ::?remainder 2068 M [3179] 3179:6F09 [ 5] clr ?remainder+1,x 2068 M mloop ::?remainder 2068 M [317B] 317B:6F0A [ 5] clr ?remainder+2,x 2068 M mloop ::?remainder 2068 M [317D] 317D:6F0B [ 5] clr ?remainder+3,x 2068 M mloop ::?remainder 2068 M [317F] 317F:6F0C [ 5] clr ?remainder+4,x 2068 M mloop ::?remainder 2068 M [3181] 3181:6F0D [ 5] clr ?remainder+5,x 2068 M mloop ::?remainder 2068 M [3183] 3183:6F0E [ 5] clr ?remainder+6,x 2068 M mloop ::?remainder 2068 M [3185] 3185:6F0F [ 5] clr ?remainder+7,x 2068 M mloop ::?remainder 2068 endm 2069 M @clr.s ?quotient,x 2069 M mset #' ' 2069 M mreq 1 2069 M @@_nosize_ ?quotient,x 2069 M mset # 2069 M mset 0,mstop [clr.s] No size (?quotient,x) 2069 M endm 2069 M mdef 2,::?quotient 2069 M mdo 2069 M [3187] 3187:7F [ 4] clr ?quotient+0,x 2069 M mloop ::?quotient 2069 M [3188] 3188:6F01 [ 5] clr ?quotient+1,x 2069 M mloop ::?quotient 2069 M [318A] 318A:6F02 [ 5] clr ?quotient+2,x 2069 M mloop ::?quotient 2069 M [318C] 318C:6F03 [ 5] clr ?quotient+3,x 2069 M mloop ::?quotient 2069 M [318E] 318E:6F04 [ 5] clr ?quotient+4,x 2069 M mloop ::?quotient 2069 M [3190] 3190:6F05 [ 5] clr ?quotient+5,x 2069 M mloop ::?quotient 2069 M [3192] 3192:6F06 [ 5] clr ?quotient+6,x 2069 M mloop ::?quotient 2069 M [3194] 3194:6F07 [ 5] clr ?quotient+7,x 2069 M mloop ::?quotient 2069 endm 2070 2071 ; first, test for division by zero error 2072 2073 M @_tst_.s divisor@@,spx 2073 M mset # 2073 M mreq 1 2073 M @@_nosize_ divisor130,spx 2073 M mset # 2073 M mset 0,mstop [_tst_.s] No size (divisor130,spx) 2073 M endm 2073 M mdo 2073 M [3196] 3196:E627 [ 3] lda divisor130+0,spx 2073 M mloop ::divisor130 2073 M [3198] 3198:EA28 [ 3] ora divisor130+1,spx 2073 M mloop ::divisor130 2073 M [319A] 319A:EA29 [ 3] ora divisor130+2,spx 2073 M mloop ::divisor130 2073 M [319C] 319C:EA2A [ 3] ora divisor130+3,spx 2073 M mloop ::divisor130 2073 M [319E] 319E:EA2B [ 3] ora divisor130+4,spx 2073 M mloop ::divisor130 2073 M [31A0] 31A0:EA2C [ 3] ora divisor130+5,spx 2073 M mloop ::divisor130 2073 M [31A2] 31A2:EA2D [ 3] ora divisor130+6,spx 2073 M mloop ::divisor130 2073 M [31A4] 31A4:EA2E [ 3] ora divisor130+7,spx 2073 M mloop ::divisor130 2073 endm 2074 [31A6] 31A6:27BC (3164) [ 3] beq ?DivError 2075 2076 ; if Dividend = 0, we're done 2077 2078 M @_tst_.s dividend@@,spx 2078 M mset # 2078 M mreq 1 2078 M @@_nosize_ dividend130,spx 2078 M mset # 2078 M mset 0,mstop [_tst_.s] No size (dividend130,spx) 2078 M endm 2078 M mdo 2078 M [31A8] 31A8:E61F [ 3] lda dividend130+0,spx 2078 M mloop ::dividend130 2078 M [31AA] 31AA:EA20 [ 3] ora dividend130+1,spx 2078 M mloop ::dividend130 2078 M [31AC] 31AC:EA21 [ 3] ora dividend130+2,spx 2078 M mloop ::dividend130 2078 M [31AE] 31AE:EA22 [ 3] ora dividend130+3,spx 2078 M mloop ::dividend130 2078 M [31B0] 31B0:EA23 [ 3] ora dividend130+4,spx 2078 M mloop ::dividend130 2078 M [31B2] 31B2:EA24 [ 3] ora dividend130+5,spx 2078 M mloop ::dividend130 2078 M [31B4] 31B4:EA25 [ 3] ora dividend130+6,spx 2078 M mloop ::dividend130 2078 M [31B6] 31B6:EA26 [ 3] ora dividend130+7,spx 2078 M mloop ::dividend130 2078 endm 2079 [31B8] 31B8:2603 CC33 4F [ 7] !jeq Done@@ 2080 2081 ; if (divisor = dividend) then quotient := 1; return 2082 ; if (divisor > dividend) then remainder := dividend; return 2083 2084 M @_cmp_.s divisor@@,spx dividend@@,spx 2084 M mset #' ' 2084 M mreq 1,2:[#]Operand1 [#]Operand2 2084 M @@_samesize_ divisor130,spx dividend@@,spx 2084 M mreq 1,2:Operand1,Operand2[,Operand]* 2084 M mset 0 2084 M mdo 2084 M mswap 1,1 2084 M @@_nosize_ divisor130,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (divisor130,spx) 2084 M endm 2084 M mset 0,divisor130,spx 2084 M mloop :n 2084 M mswap 1,2 2084 M @@_nosize_ dividend@@,spx 2084 M mset # 2084 M mset 0,mstop [_samesize_] No size (dividend130,spx) 2084 M endm 2084 M mloop :n 2084 M endm 2084 M #temp 1 2084 M #temp ::divisor130 2084 M #temp ::dividend@@ 2084 M mdo 2084 M [31BD] 31BD:E627 [ 3] lda divisor130+0,spx 2084 M [31BF] 31BF:E11F [ 3] cmpa dividend@@+0,spx 2084 M [31C1] 31C1:2628 (31EB) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [31C3] 31C3:E628 [ 3] lda divisor130+1,spx 2084 M [31C5] 31C5:E120 [ 3] cmpa dividend@@+1,spx 2084 M [31C7] 31C7:2622 (31EB) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [31C9] 31C9:E629 [ 3] lda divisor130+2,spx 2084 M [31CB] 31CB:E121 [ 3] cmpa dividend@@+2,spx 2084 M [31CD] 31CD:261C (31EB) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [31CF] 31CF:E62A [ 3] lda divisor130+3,spx 2084 M [31D1] 31D1:E122 [ 3] cmpa dividend@@+3,spx 2084 M [31D3] 31D3:2616 (31EB) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [31D5] 31D5:E62B [ 3] lda divisor130+4,spx 2084 M [31D7] 31D7:E123 [ 3] cmpa dividend@@+4,spx 2084 M [31D9] 31D9:2610 (31EB) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [31DB] 31DB:E62C [ 3] lda divisor130+5,spx 2084 M [31DD] 31DD:E124 [ 3] cmpa dividend@@+5,spx 2084 M [31DF] 31DF:260A (31EB) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [31E1] 31E1:E62D [ 3] lda divisor130+6,spx 2084 M [31E3] 31E3:E125 [ 3] cmpa dividend@@+6,spx 2084 M [31E5] 31E5:2604 (31EB) [ 3] bne Done$$$ 2084 M mloop :temp 2084 M [31E7] 31E7:E62E [ 3] lda divisor130+7,spx 2084 M [31E9] 31E9:E126 [ 3] cmpa dividend@@+7,spx 2084 M mloop :temp 2084 M 31EB Done$$$ 2084 endm 2085 [31EB] 31EB:2604 (31F1) [ 3] bne NotEqual@@ 2086 2087 [31ED] 31ED:6C07 [ 5] inc ?quotient+{::?quotient-1},x ;quotient := 1 2088 [31EF] 31EF:2022 (3213) [ 3] bra ??DivExit ;and get out 2089 2090 31F1 NotEqual@@ ;@sub.s divisor@@,spx dividend@@,spx ;[2012.05.18 REDUNDANT] 2091 [31F1] 31F1:2523 (3216) [ 3] blo Continue@@ 2092 2093 M @mova.s dividend@@,spx ?remainder,x 2093 M mset #' ' 2093 M mreq 1,2:Source Destination 2093 M @@_samesize_ dividend130,spx ?remainder,x 2093 M mreq 1,2:Operand1,Operand2[,Operand]* 2093 M mset 0 2093 M mdo 2093 M mswap 1,1 2093 M @@_nosize_ dividend130,spx 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (dividend130,spx) 2093 M endm 2093 M mset 0,dividend130,spx 2093 M mloop :n 2093 M mswap 1,2 2093 M @@_nosize_ ?remainder,x 2093 M mset # 2093 M mset 0,mstop [_samesize_] No size (?remainder,x) 2093 M endm 2093 M mloop :n 2093 M endm 2093 M mset 0 2093 M mdo 2093 M [31F3] 31F3:E61F [ 3] lda dividend130+0,spx 2093 M [31F5] 31F5:E708 [ 3] sta ?remainder+0,x 2093 M mloop ::?remainder 2093 M [31F7] 31F7:E620 [ 3] lda dividend130+1,spx 2093 M [31F9] 31F9:E709 [ 3] sta ?remainder+1,x 2093 M mloop ::?remainder 2093 M [31FB] 31FB:E621 [ 3] lda dividend130+2,spx 2093 M [31FD] 31FD:E70A [ 3] sta ?remainder+2,x 2093 M mloop ::?remainder 2093 M [31FF] 31FF:E622 [ 3] lda dividend130+3,spx 2093 M [3201] 3201:E70B [ 3] sta ?remainder+3,x 2093 M mloop ::?remainder 2093 M [3203] 3203:E623 [ 3] lda dividend130+4,spx 2093 M [3205] 3205:E70C [ 3] sta ?remainder+4,x 2093 M mloop ::?remainder 2093 M [3207] 3207:E624 [ 3] lda dividend130+5,spx 2093 M [3209] 3209:E70D [ 3] sta ?remainder+5,x 2093 M mloop ::?remainder 2093 M [320B] 320B:E625 [ 3] lda dividend130+6,spx 2093 M [320D] 320D:E70E [ 3] sta ?remainder+6,x 2093 M mloop ::?remainder 2093 M [320F] 320F:E626 [ 3] lda dividend130+7,spx 2093 M [3211] 3211:E70F [ 3] sta ?remainder+7,x 2093 M mloop ::?remainder 2093 endm 2094 3213 ??DivExit ;and get out 2098 [3213] 3213:CC33 4F [ 4] jmp Done@@ 2100 2101 [3216] 3216:A640 [ 2] Continue@@ lda #MATHSIZE 2102 [3218] 3218:E718 [ 3] sta ?bits,x ;bits := 64/56/48/40/32/24/16-bit 2103 2104 ; while (remainder < divisor) do 2105 2106 M While@@ @cop ;in case of many iterations 2106 M [321A] 321A:C718 00 [ 4] sta COP 2106 endm 2107 2108 M @sub.s ?remainder,x divisor@@,spx 2108 M mset #' ' 2108 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2108 M @@_samesize_ ?remainder,x divisor130,spx 2108 M mreq 1,2:Operand1,Operand2[,Operand]* 2108 M mset 0 2108 M mdo 2108 M mswap 1,1 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (?remainder,x) 2108 M endm 2108 M mset 0,?remainder,x 2108 M mloop :n 2108 M mswap 1,2 2108 M @@_nosize_ divisor130,spx 2108 M mset # 2108 M mset 0,mstop [_samesize_] No size (divisor130,spx) 2108 M endm 2108 M mloop :n 2108 M endm 2108 M #temp 2108 M @@_nosize_ ?remainder,x 2108 M mset # 2108 M mset 0,mstop [sub.s] No size (?remainder,x) 2108 M endm 2108 M #temp ::?remainder 2108 M mset 0,sub 2108 M mdo 2108 M [321D] 321D:E60F [ 3] lda ?remainder+7,x 2108 M [321F] 321F:E02E [ 3] sub divisor130+7,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [3221] 3221:E60E [ 3] lda ?remainder+6,x 2108 M [3223] 3223:E22D [ 3] sbc divisor130+6,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [3225] 3225:E60D [ 3] lda ?remainder+5,x 2108 M [3227] 3227:E22C [ 3] sbc divisor130+5,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [3229] 3229:E60C [ 3] lda ?remainder+4,x 2108 M [322B] 322B:E22B [ 3] sbc divisor130+4,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [322D] 322D:E60B [ 3] lda ?remainder+3,x 2108 M [322F] 322F:E22A [ 3] sbc divisor130+3,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [3231] 3231:E60A [ 3] lda ?remainder+2,x 2108 M [3233] 3233:E229 [ 3] sbc divisor130+2,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [3235] 3235:E609 [ 3] lda ?remainder+1,x 2108 M [3237] 3237:E228 [ 3] sbc divisor130+1,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 M [3239] 3239:E608 [ 3] lda ?remainder+0,x 2108 M [323B] 323B:E227 [ 3] sbc divisor130+0,spx 2108 M mset 0,sbc 2108 M mloop :temp 2108 endm 2109 [323D] 323D:2444 (3283) [ 3] bcc EndWhile@@ 2110 2111 ; remainder := (remainder shl 1) or msb(dividend) 2112 ;-------------------------------------- ;2012.12.04 optimization (moved up this code from before DEC to here) 2113 M @mova.s dividend@@,spx ?temp,x ; temp := dividend 2113 M mset #' ' 2113 M mreq 1,2:Source Destination 2113 M @@_samesize_ dividend130,spx ?temp,x 2113 M mreq 1,2:Operand1,Operand2[,Operand]* 2113 M mset 0 2113 M mdo 2113 M mswap 1,1 2113 M @@_nosize_ dividend130,spx 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (dividend130,spx) 2113 M endm 2113 M mset 0,dividend130,spx 2113 M mloop :n 2113 M mswap 1,2 2113 M @@_nosize_ ?temp,x 2113 M mset # 2113 M mset 0,mstop [_samesize_] No size (?temp,x) 2113 M endm 2113 M mloop :n 2113 M endm 2113 M mset 0 2113 M mdo 2113 M [323F] 323F:E61F [ 3] lda dividend130+0,spx 2113 M [3241] 3241:E710 [ 3] sta ?temp+0,x 2113 M mloop ::?temp 2113 M [3243] 3243:E620 [ 3] lda dividend130+1,spx 2113 M [3245] 3245:E711 [ 3] sta ?temp+1,x 2113 M mloop ::?temp 2113 M [3247] 3247:E621 [ 3] lda dividend130+2,spx 2113 M [3249] 3249:E712 [ 3] sta ?temp+2,x 2113 M mloop ::?temp 2113 M [324B] 324B:E622 [ 3] lda dividend130+3,spx 2113 M [324D] 324D:E713 [ 3] sta ?temp+3,x 2113 M mloop ::?temp 2113 M [324F] 324F:E623 [ 3] lda dividend130+4,spx 2113 M [3251] 3251:E714 [ 3] sta ?temp+4,x 2113 M mloop ::?temp 2113 M [3253] 3253:E624 [ 3] lda dividend130+5,spx 2113 M [3255] 3255:E715 [ 3] sta ?temp+5,x 2113 M mloop ::?temp 2113 M [3257] 3257:E625 [ 3] lda dividend130+6,spx 2113 M [3259] 3259:E716 [ 3] sta ?temp+6,x 2113 M mloop ::?temp 2113 M [325B] 325B:E626 [ 3] lda dividend130+7,spx 2113 M [325D] 325D:E717 [ 3] sta ?temp+7,x 2113 M mloop ::?temp 2113 endm 2114 M @lsl.s dividend@@,spx ; dividend := dividend shl 1 2114 M mset # 2114 M mreq 1 2114 M @@_nosize_ dividend130,spx 2114 M mset # 2114 M mset 0,mstop [lsl.s] No size (dividend130,spx) 2114 M endm 2114 M mdo 2114 M [325F] 325F:6826 [ 5] lsl dividend130+7,spx 2114 M mloop ::dividend130 2114 M [3261] 3261:6925 [ 5] rol dividend130+6,spx 2114 M mloop ::dividend130 2114 M [3263] 3263:6924 [ 5] rol dividend130+5,spx 2114 M mloop ::dividend130 2114 M [3265] 3265:6923 [ 5] rol dividend130+4,spx 2114 M mloop ::dividend130 2114 M [3267] 3267:6922 [ 5] rol dividend130+3,spx 2114 M mloop ::dividend130 2114 M [3269] 3269:6921 [ 5] rol dividend130+2,spx 2114 M mloop ::dividend130 2114 M [326B] 326B:6920 [ 5] rol dividend130+1,spx 2114 M mloop ::dividend130 2114 M [326D] 326D:691F [ 5] rol dividend130+0,spx 2114 M mloop ::dividend130 2114 endm 2115 ;-------------------------------------- 2116 M @rol.s ?remainder,x 2116 M mset # 2116 M mreq 1 2116 M @@_nosize_ ?remainder,x 2116 M mset # 2116 M mset 0,mstop [rol.s] No size (?remainder,x) 2116 M endm 2116 M mdo 2116 M [326F] 326F:690F [ 5] rol ?remainder+7,x 2116 M mloop ::?remainder 2116 M [3271] 3271:690E [ 5] rol ?remainder+6,x 2116 M mloop ::?remainder 2116 M [3273] 3273:690D [ 5] rol ?remainder+5,x 2116 M mloop ::?remainder 2116 M [3275] 3275:690C [ 5] rol ?remainder+4,x 2116 M mloop ::?remainder 2116 M [3277] 3277:690B [ 5] rol ?remainder+3,x 2116 M mloop ::?remainder 2116 M [3279] 3279:690A [ 5] rol ?remainder+2,x 2116 M mloop ::?remainder 2116 M [327B] 327B:6909 [ 5] rol ?remainder+1,x 2116 M mloop ::?remainder 2116 M [327D] 327D:6908 [ 5] rol ?remainder+0,x 2116 M mloop ::?remainder 2116 endm 2117 [327F] 327F:6A18 [ 5] dec ?bits,x ; bits := bits - 1 2118 2119 ; end while 2120 2121 [3281] 3281:2097 (321A) [ 3] bra While@@ 2122 3283 EndWhile@@ 2123 M @mova.s ?temp,x dividend@@,spx ; dividend := temp 2123 M mset #' ' 2123 M mreq 1,2:Source Destination 2123 M @@_samesize_ ?temp,x dividend130,spx 2123 M mreq 1,2:Operand1,Operand2[,Operand]* 2123 M mset 0 2123 M mdo 2123 M mswap 1,1 2123 M @@_nosize_ ?temp,x 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (?temp,x) 2123 M endm 2123 M mset 0,?temp,x 2123 M mloop :n 2123 M mswap 1,2 2123 M @@_nosize_ dividend130,spx 2123 M mset # 2123 M mset 0,mstop [_samesize_] No size (dividend130,spx) 2123 M endm 2123 M mloop :n 2123 M endm 2123 M mset 0 2123 M mdo 2123 M [3283] 3283:E610 [ 3] lda ?temp+0,x 2123 M [3285] 3285:E71F [ 3] sta dividend130+0,spx 2123 M mloop ::dividend130 2123 M [3287] 3287:E611 [ 3] lda ?temp+1,x 2123 M [3289] 3289:E720 [ 3] sta dividend130+1,spx 2123 M mloop ::dividend130 2123 M [328B] 328B:E612 [ 3] lda ?temp+2,x 2123 M [328D] 328D:E721 [ 3] sta dividend130+2,spx 2123 M mloop ::dividend130 2123 M [328F] 328F:E613 [ 3] lda ?temp+3,x 2123 M [3291] 3291:E722 [ 3] sta dividend130+3,spx 2123 M mloop ::dividend130 2123 M [3293] 3293:E614 [ 3] lda ?temp+4,x 2123 M [3295] 3295:E723 [ 3] sta dividend130+4,spx 2123 M mloop ::dividend130 2123 M [3297] 3297:E615 [ 3] lda ?temp+5,x 2123 M [3299] 3299:E724 [ 3] sta dividend130+5,spx 2123 M mloop ::dividend130 2123 M [329B] 329B:E616 [ 3] lda ?temp+6,x 2123 M [329D] 329D:E725 [ 3] sta dividend130+6,spx 2123 M mloop ::dividend130 2123 M [329F] 329F:E617 [ 3] lda ?temp+7,x 2123 M [32A1] 32A1:E726 [ 3] sta dividend130+7,spx 2123 M mloop ::dividend130 2123 endm 2124 M @lsr.s ?remainder,x ; remainder := remainder shr 1 2124 M mset # 2124 M mreq 1 2124 M @@_nosize_ ?remainder,x 2124 M mset # 2124 M mset 0,mstop [lsr.s] No size (?remainder,x) 2124 M endm 2124 M mdo 2124 M [32A3] 32A3:6408 [ 5] lsr ?remainder+0,x 2124 M mloop ::?remainder 2124 M [32A5] 32A5:6609 [ 5] ror ?remainder+1,x 2124 M mloop ::?remainder 2124 M [32A7] 32A7:660A [ 5] ror ?remainder+2,x 2124 M mloop ::?remainder 2124 M [32A9] 32A9:660B [ 5] ror ?remainder+3,x 2124 M mloop ::?remainder 2124 M [32AB] 32AB:660C [ 5] ror ?remainder+4,x 2124 M mloop ::?remainder 2124 M [32AD] 32AD:660D [ 5] ror ?remainder+5,x 2124 M mloop ::?remainder 2124 M [32AF] 32AF:660E [ 5] ror ?remainder+6,x 2124 M mloop ::?remainder 2124 M [32B1] 32B1:660F [ 5] ror ?remainder+7,x 2124 M mloop ::?remainder 2124 endm 2125 [32B3] 32B3:6C18 [ 5] inc ?bits,x ; bits := bits + 1 2126 2127 ; for i := bitCounter-1 downto 0 do 2128 2129 M For@@ @cop ;in case of many iterations 2129 M [32B5] 32B5:C718 00 [ 4] sta COP 2129 endm 2130 2131 [32B8] 32B8:6D18 [ 4] tst ?bits,x 2135 [32BA] 32BA:2603 CC33 4F [ 7] jeq Done@@ 2137 [32BF] 32BF:6A18 [ 5] dec ?bits,x 2138 2139 ; remainder := (remainder shl 1) or msb(dividend) 2140 ; dividend := dividend shl 1 2141 2142 M @lsl.s dividend@@,spx ;2012.12.04 optimization 2142 M mset # 2142 M mreq 1 2142 M @@_nosize_ dividend130,spx 2142 M mset # 2142 M mset 0,mstop [lsl.s] No size (dividend130,spx) 2142 M endm 2142 M mdo 2142 M [32C1] 32C1:6826 [ 5] lsl dividend130+7,spx 2142 M mloop ::dividend130 2142 M [32C3] 32C3:6925 [ 5] rol dividend130+6,spx 2142 M mloop ::dividend130 2142 M [32C5] 32C5:6924 [ 5] rol dividend130+5,spx 2142 M mloop ::dividend130 2142 M [32C7] 32C7:6923 [ 5] rol dividend130+4,spx 2142 M mloop ::dividend130 2142 M [32C9] 32C9:6922 [ 5] rol dividend130+3,spx 2142 M mloop ::dividend130 2142 M [32CB] 32CB:6921 [ 5] rol dividend130+2,spx 2142 M mloop ::dividend130 2142 M [32CD] 32CD:6920 [ 5] rol dividend130+1,spx 2142 M mloop ::dividend130 2142 M [32CF] 32CF:691F [ 5] rol dividend130+0,spx 2142 M mloop ::dividend130 2142 endm 2143 M @rol.s ?remainder,x 2143 M mset # 2143 M mreq 1 2143 M @@_nosize_ ?remainder,x 2143 M mset # 2143 M mset 0,mstop [rol.s] No size (?remainder,x) 2143 M endm 2143 M mdo 2143 M [32D1] 32D1:690F [ 5] rol ?remainder+7,x 2143 M mloop ::?remainder 2143 M [32D3] 32D3:690E [ 5] rol ?remainder+6,x 2143 M mloop ::?remainder 2143 M [32D5] 32D5:690D [ 5] rol ?remainder+5,x 2143 M mloop ::?remainder 2143 M [32D7] 32D7:690C [ 5] rol ?remainder+4,x 2143 M mloop ::?remainder 2143 M [32D9] 32D9:690B [ 5] rol ?remainder+3,x 2143 M mloop ::?remainder 2143 M [32DB] 32DB:690A [ 5] rol ?remainder+2,x 2143 M mloop ::?remainder 2143 M [32DD] 32DD:6909 [ 5] rol ?remainder+1,x 2143 M mloop ::?remainder 2143 M [32DF] 32DF:6908 [ 5] rol ?remainder+0,x 2143 M mloop ::?remainder 2143 endm 2144 2145 ; temp := remainder - divisor 2146 2147 M @sub.s ?remainder,x divisor@@,spx ?temp,x 2147 M mset #' ' 2147 M mreq 1,2:[#]Operand1 [#]Operand2 Destination 2147 M @@_samesize_ ?remainder,x divisor130,spx ?temp,x 2147 M mreq 1,2:Operand1,Operand2[,Operand]* 2147 M mset 0 2147 M mdo 2147 M mswap 1,1 2147 M @@_nosize_ ?remainder,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?remainder,x) 2147 M endm 2147 M mset 0,?remainder,x 2147 M mloop :n 2147 M mswap 1,2 2147 M @@_nosize_ divisor130,spx 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (divisor130,spx) 2147 M endm 2147 M mloop :n 2147 M mswap 1,3 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [_samesize_] No size (?temp,x) 2147 M endm 2147 M mloop :n 2147 M endm 2147 M #temp 2147 M @@_nosize_ ?temp,x 2147 M mset # 2147 M mset 0,mstop [sub.s] No size (?temp,x) 2147 M endm 2147 M #temp ::?temp 2147 M mset 0,sub 2147 M mdo 2147 M [32E1] 32E1:E60F [ 3] lda ?remainder+7,x 2147 M [32E3] 32E3:E02E [ 3] sub divisor130+7,spx 2147 M [32E5] 32E5:E717 [ 3] sta ?temp+7,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [32E7] 32E7:E60E [ 3] lda ?remainder+6,x 2147 M [32E9] 32E9:E22D [ 3] sbc divisor130+6,spx 2147 M [32EB] 32EB:E716 [ 3] sta ?temp+6,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [32ED] 32ED:E60D [ 3] lda ?remainder+5,x 2147 M [32EF] 32EF:E22C [ 3] sbc divisor130+5,spx 2147 M [32F1] 32F1:E715 [ 3] sta ?temp+5,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [32F3] 32F3:E60C [ 3] lda ?remainder+4,x 2147 M [32F5] 32F5:E22B [ 3] sbc divisor130+4,spx 2147 M [32F7] 32F7:E714 [ 3] sta ?temp+4,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [32F9] 32F9:E60B [ 3] lda ?remainder+3,x 2147 M [32FB] 32FB:E22A [ 3] sbc divisor130+3,spx 2147 M [32FD] 32FD:E713 [ 3] sta ?temp+3,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [32FF] 32FF:E60A [ 3] lda ?remainder+2,x 2147 M [3301] 3301:E229 [ 3] sbc divisor130+2,spx 2147 M [3303] 3303:E712 [ 3] sta ?temp+2,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [3305] 3305:E609 [ 3] lda ?remainder+1,x 2147 M [3307] 3307:E228 [ 3] sbc divisor130+1,spx 2147 M [3309] 3309:E711 [ 3] sta ?temp+1,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 M [330B] 330B:E608 [ 3] lda ?remainder+0,x 2147 M [330D] 330D:E227 [ 3] sbc divisor130+0,spx 2147 M [330F] 330F:E710 [ 3] sta ?temp+0,x 2147 M mset 0,sbc 2147 M mloop :temp 2147 endm 2148 2149 ; q := not msb(temp) 2150 2151 [3311] 3311:E610 [ 3] lda ?temp,x 2152 [3313] 3313:A880 [ 2] eor #%10000000 ;invert msb 2153 [3315] 3315:A480 [ 2] and #%10000000 ;isolate msb 2154 2155 ; quotient := (quotient shl 1) or q 2156 2157 [3317] 3317:87 [ 2] psha 2158 [3318] 3318:48 [ 1] lsla 2159 [3319] 3319:86 [ 3] pula 2160 2161 M @rol.s ?quotient,x 2161 M mset # 2161 M mreq 1 2161 M @@_nosize_ ?quotient,x 2161 M mset # 2161 M mset 0,mstop [rol.s] No size (?quotient,x) 2161 M endm 2161 M mdo 2161 M [331A] 331A:6907 [ 5] rol ?quotient+7,x 2161 M mloop ::?quotient 2161 M [331C] 331C:6906 [ 5] rol ?quotient+6,x 2161 M mloop ::?quotient 2161 M [331E] 331E:6905 [ 5] rol ?quotient+5,x 2161 M mloop ::?quotient 2161 M [3320] 3320:6904 [ 5] rol ?quotient+4,x 2161 M mloop ::?quotient 2161 M [3322] 3322:6903 [ 5] rol ?quotient+3,x 2161 M mloop ::?quotient 2161 M [3324] 3324:6902 [ 5] rol ?quotient+2,x 2161 M mloop ::?quotient 2161 M [3326] 3326:6901 [ 5] rol ?quotient+1,x 2161 M mloop ::?quotient 2161 M [3328] 3328:79 [ 4] rol ?quotient+0,x 2161 M mloop ::?quotient 2161 endm 2162 2163 ; if q <> 0 then 2164 2165 [3329] 3329:4100 89(32B5) [ 4] cbeqa #0,For@@ 2166 2167 ; remainder := temp 2168 2169 M @mova.s ?temp,x ?remainder,x 2169 M mset #' ' 2169 M mreq 1,2:Source Destination 2169 M @@_samesize_ ?temp,x ?remainder,x 2169 M mreq 1,2:Operand1,Operand2[,Operand]* 2169 M mset 0 2169 M mdo 2169 M mswap 1,1 2169 M @@_nosize_ ?temp,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?temp,x) 2169 M endm 2169 M mset 0,?temp,x 2169 M mloop :n 2169 M mswap 1,2 2169 M @@_nosize_ ?remainder,x 2169 M mset # 2169 M mset 0,mstop [_samesize_] No size (?remainder,x) 2169 M endm 2169 M mloop :n 2169 M endm 2169 M mset 0 2169 M mdo 2169 M [332C] 332C:E610 [ 3] lda ?temp+0,x 2169 M [332E] 332E:E708 [ 3] sta ?remainder+0,x 2169 M mloop ::?remainder 2169 M [3330] 3330:E611 [ 3] lda ?temp+1,x 2169 M [3332] 3332:E709 [ 3] sta ?remainder+1,x 2169 M mloop ::?remainder 2169 M [3334] 3334:E612 [ 3] lda ?temp+2,x 2169 M [3336] 3336:E70A [ 3] sta ?remainder+2,x 2169 M mloop ::?remainder 2169 M [3338] 3338:E613 [ 3] lda ?temp+3,x 2169 M [333A] 333A:E70B [ 3] sta ?remainder+3,x 2169 M mloop ::?remainder 2169 M [333C] 333C:E614 [ 3] lda ?temp+4,x 2169 M [333E] 333E:E70C [ 3] sta ?remainder+4,x 2169 M mloop ::?remainder 2169 M [3340] 3340:E615 [ 3] lda ?temp+5,x 2169 M [3342] 3342:E70D [ 3] sta ?remainder+5,x 2169 M mloop ::?remainder 2169 M [3344] 3344:E616 [ 3] lda ?temp+6,x 2169 M [3346] 3346:E70E [ 3] sta ?remainder+6,x 2169 M mloop ::?remainder 2169 M [3348] 3348:E617 [ 3] lda ?temp+7,x 2169 M [334A] 334A:E70F [ 3] sta ?remainder+7,x 2169 M mloop ::?remainder 2169 endm 2170 2171 ; end if -- end for 2172 2176 [334C] 334C:CC32 B5 [ 4] jmp For@@ 2178 2179 [334F] 334F:E619 [ 3] Done@@ lda ?flags,x 2180 [3351] 3351:A501 [ 2] bit #?DIVOP_ 2181 [3353] 3353:2721 (3376) [ 3] beq ExitMod@@ 2182 2183 0436 ?Cycles equ :cycles 2184 2185 ;ExitDiv@@ 2186 M @mova.s ?quotient,x ans@@,spx 2186 M mset #' ' 2186 M mreq 1,2:Source Destination 2186 M @@_samesize_ ?quotient,x ans130,spx 2186 M mreq 1,2:Operand1,Operand2[,Operand]* 2186 M mset 0 2186 M mdo 2186 M mswap 1,1 2186 M @@_nosize_ ?quotient,x 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (?quotient,x) 2186 M endm 2186 M mset 0,?quotient,x 2186 M mloop :n 2186 M mswap 1,2 2186 M @@_nosize_ ans130,spx 2186 M mset # 2186 M mset 0,mstop [_samesize_] No size (ans130,spx) 2186 M endm 2186 M mloop :n 2186 M endm 2186 M mset 0 2186 M mdo 2186 M [3355] 3355:F6 [ 3] lda ?quotient+0,x 2186 M [3356] 3356:E727 [ 3] sta ans130+0,spx 2186 M mloop ::ans130 2186 M [3358] 3358:E601 [ 3] lda ?quotient+1,x 2186 M [335A] 335A:E728 [ 3] sta ans130+1,spx 2186 M mloop ::ans130 2186 M [335C] 335C:E602 [ 3] lda ?quotient+2,x 2186 M [335E] 335E:E729 [ 3] sta ans130+2,spx 2186 M mloop ::ans130 2186 M [3360] 3360:E603 [ 3] lda ?quotient+3,x 2186 M [3362] 3362:E72A [ 3] sta ans130+3,spx 2186 M mloop ::ans130 2186 M [3364] 3364:E604 [ 3] lda ?quotient+4,x 2186 M [3366] 3366:E72B [ 3] sta ans130+4,spx 2186 M mloop ::ans130 2186 M [3368] 3368:E605 [ 3] lda ?quotient+5,x 2186 M [336A] 336A:E72C [ 3] sta ans130+5,spx 2186 M mloop ::ans130 2186 M [336C] 336C:E606 [ 3] lda ?quotient+6,x 2186 M [336E] 336E:E72D [ 3] sta ans130+6,spx 2186 M mloop ::ans130 2186 M [3370] 3370:E607 [ 3] lda ?quotient+7,x 2186 M [3372] 3372:E72E [ 3] sta ans130+7,spx 2186 M mloop ::ans130 2186 endm 2187 [3374] 3374:2020 (3396) [ 3] bra ExitBoth@@ 2188 2189 0488 ?DivCycles set ?DivCycles+?Cycles+:cycles 2190 2191 M ExitMod@@ @mova.s ?remainder,x ans@@,spx 2191 M mset #' ' 2191 M mreq 1,2:Source Destination 2191 M @@_samesize_ ?remainder,x ans130,spx 2191 M mreq 1,2:Operand1,Operand2[,Operand]* 2191 M mset 0 2191 M mdo 2191 M mswap 1,1 2191 M @@_nosize_ ?remainder,x 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (?remainder,x) 2191 M endm 2191 M mset 0,?remainder,x 2191 M mloop :n 2191 M mswap 1,2 2191 M @@_nosize_ ans130,spx 2191 M mset # 2191 M mset 0,mstop [_samesize_] No size (ans130,spx) 2191 M endm 2191 M mloop :n 2191 M endm 2191 M mset 0 2191 M mdo 2191 M [3376] 3376:E608 [ 3] lda ?remainder+0,x 2191 M [3378] 3378:E727 [ 3] sta ans130+0,spx 2191 M mloop ::ans130 2191 M [337A] 337A:E609 [ 3] lda ?remainder+1,x 2191 M [337C] 337C:E728 [ 3] sta ans130+1,spx 2191 M mloop ::ans130 2191 M [337E] 337E:E60A [ 3] lda ?remainder+2,x 2191 M [3380] 3380:E729 [ 3] sta ans130+2,spx 2191 M mloop ::ans130 2191 M [3382] 3382:E60B [ 3] lda ?remainder+3,x 2191 M [3384] 3384:E72A [ 3] sta ans130+3,spx 2191 M mloop ::ans130 2191 M [3386] 3386:E60C [ 3] lda ?remainder+4,x 2191 M [3388] 3388:E72B [ 3] sta ans130+4,spx 2191 M mloop ::ans130 2191 M [338A] 338A:E60D [ 3] lda ?remainder+5,x 2191 M [338C] 338C:E72C [ 3] sta ans130+5,spx 2191 M mloop ::ans130 2191 M [338E] 338E:E60E [ 3] lda ?remainder+6,x 2191 M [3390] 3390:E72D [ 3] sta ans130+6,spx 2191 M mloop ::ans130 2191 M [3392] 3392:E60F [ 3] lda ?remainder+7,x 2191 M [3394] 3394:E72E [ 3] sta ans130+7,spx 2191 M mloop ::ans130 2191 endm 2192 2193 047C ?ModCycles set ?ModCycles+?Cycles+:cycles 2194 2195 3396 ExitBoth@@ 2197 [3396] 3396:6D19 [ 4] tst ?flags,x 2198 [3398] 3398:2A06 (33A0) [ 3] bpl SkipSign@@ 2199 M @lea ans@@,sp 2199 M mset # 2199 M [339A] 339A:95 [ 2] tsx 2199 M [339B] 339B:AF27 [ 2] !aix #ans130+:tsx 2199 mexit 2200 [339D] 339D:CD31 39 [ 6] jsr ?NegX 2201 33A0 SkipSign@@ 2202 #Cycles ?NegxCycles+:cycles 2204 [33A0] 33A0:A71A [ 2] ais #?SF ;de-allocate temporaries 2205 [33A2] 33A2:98 [ 1] clc ;no error(s) 2206 ; bra ?RemoveAndReturn 2207 2208 0072 ?Cycles set :cycles 2209 04FA ?DivCycles set ?DivCycles+?Cycles 2210 04EE ?ModCycles set ?ModCycles+?Cycles 2211 2212 ;******************************************************************************* 2213 ; Common exit removes lower 32-bit stack element and returns to caller 2214 ;******************************************************************************* 2215 2216 33A3 ?RemoveAndReturn proc 2218 [33A3] 33A3:9EFE 04 [ 5] ldhx ?pc,sp ;our return address moved up 2219 [33A6] 33A6:9EFF 0C [ 5] sthx ?pc+?WORD,sp ;above word to remove 2229 [33A9] 33A9:8A88 86 [ 9] pull 2230 [33AC] 33AC:A708 [ 2] ais #?WORD ;remove top-of-stack ?WORD 2231 [33AE] 33AE:81 [ 6] rtc 2232 2233 001B ?ReturnCycles equ :cycles 2234 2235 ;******************************************************************************* 2236 ; Purpose: Swaps the stacked order of N1 and N2 2237 ; Input : [TOS+?WORD] = Number2 2238 ; : [TOS] = Number1 2239 ; Output : [TOS+?WORD] = Number1 -- TOS & [TOS+?WORD] in reverse order 2240 ; : [TOS] = Number2 2241 ; Note(s): Does not alter stack size 2242 2243 #spauto :ab 2244 2245 33AF ?Swap proc 2246 [33AF] 33AF:8789 8B [ 6] push 2247 2248 [33B2] 33B2:A608 [ 2] lda #?WORD 2249 [33B4] 33B4:87 [ 2] psha bytes@@ 2250 2251 [33B5] 33B5:95 [ 2] tsx 2252 #temp :cycles 2253 M Loop@@ @_swap_, ?a,spx ?b,spx ;swap A with B ... 2253 M mset #' ' 2253 M #push 2253 M #spauto :sp 2253 M [33B6] 33B6:E606 [ 3] lda ?a,spx 2253 M [33B8] 33B8:87 [ 2] psha 2253 M [33B9] 33B9:E60E [ 3] lda ?b,spx 2253 M [33BB] 33BB:E706 [ 3] sta ?a,spx 2253 M [33BD] 33BD:86 [ 3] pula 2253 M [33BE] 33BE:E70E [ 3] sta ?b,spx 2253 M #pull 2253 endm 2254 2255 [33C0] 33C0:AF01 [ 2] aix #1 ;point to next byte 2256 [33C2] 33C2:9E6B 01F0 (33B6 [ 8] dbnz bytes@@,sp,Loop@@ ;repeat for all bytes 2257 #temp :cycles*?WORD+:temp 2258 [33C6] 33C6:86 [ 3] pula 2259 2260 [33C7] 33C7:8A88 86 [ 9] pull 2261 [33CA] 33CA:81 [ 6] rtc 2262 2263 00F6 ?SwapCycles set :cycles+:temp 2264 2265 ;******************************************************************************* 2266 ; Purpose: Get the absolute value of the top-of-stack number 2267 ; Input : [TOS] = Number 2268 ; Output : [TOS] = Abs(Number) 2269 ; Note(s): Does not alter stack size 2270 2271 #spauto :ab 2272 2273 33CB ?Abs proc 2274 [33CB] 33CB:9E6D 03 [ 5] tst ?a,sp 2275 [33CE] 33CE:2AFA (33CA) [ 3] bpl Done@@ 2276 ; bra ?Negate 2277 2278 33CA Done@@ equ :AnRTC 2279 2280 0008 ?AbsCycles equ :cycles 2281 2282 ;******************************************************************************* 2283 ; Purpose: Negate the top-of-stack number 2284 ; Input : [TOS] = Number 2285 ; Output : [TOS] = -Number 2286 ; Note(s): Does not alter stack size 2287 2288 #spauto :ab 2289 2290 33D0 ?Negate proc 2291 [33D0] 33D0:898B [ 4] pshhx 2293 M @lea ?a,sp 2293 M mset # 2293 M [33D2] 33D2:95 [ 2] tsx 2293 M [33D3] 33D3:AF04 [ 2] !aix #?a+:tsx 2293 mexit 2294 [33D5] 33D5:CD31 39 [ 6] jsr ?NegX 2295 #Cycles ?NegxCycles+:cycles 2300 [33D8] 33D8:8A88 [ 6] pulhx 2301 [33DA] 33DA:81 [ 6] rtc 2302 2303 0078 ?NegateCycles equ :cycles 2304 0080 ?AbsCycles set ?NegateCycles+?AbsCycles 2305 2306 ;******************************************************************************* 2307 ; Purpose: Create a new top-of-stack and load to it the number pointed to by HX 2308 ; Input : HX -> [Variable with] Number 2309 ; Output : [TOS] = Number 2310 ; Note(s): This operation makes it easier to load a number to the stack. 2311 ; : Hint: To make a copy of the TOS, do: 2312 ; : tsx 2313 ; : call StackLoad32 2314 ; : (Stack is expanded) 2315 2316 #spauto :ab 2317 2318 33DB ?Load proc 2319 FFFFFFFF old_rts@@ equ ::,:ab 2320 [33DB] 33DB:A7F8 [ 2] ais #-?WORD ;allocate new TOS memory 2321 #temp :: 2322 FFFFFFF7 new_rts@@ next :temp,:ab 2323 FFFFFFF9 tos_num@@ next :temp,?WORD 2324 0001 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2325 #ais :temp 2326 2327 [33DD] 33DD:87 [ 2] psha 2328 M @mova.s old_rts@@,sp new_rts@@,sp ;move RTS/RTC after new memory 2328 M mset #' ' 2328 M mreq 1,2:Source Destination 2328 M @@_samesize_ old_rts135,sp new_rts@@,sp 2328 M mreq 1,2:Operand1,Operand2[,Operand]* 2328 M mset 0 2328 M mdo 2328 M mswap 1,1 2328 M @@_nosize_ old_rts135,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (old_rts135,sp) 2328 M endm 2328 M mset 0,old_rts135,sp 2328 M mloop :n 2328 M mswap 1,2 2328 M @@_nosize_ new_rts@@,sp 2328 M mset # 2328 M mset 0,mstop [_samesize_] No size (new_rts135,sp) 2328 M endm 2328 M mloop :n 2328 M endm 2328 M mset 0 2328 M mdo 2328 M [33DE] 33DE:9EE6 0A [ 4] lda old_rts135+0,sp 2328 M [33E1] 33E1:9EE7 02 [ 4] sta new_rts@@+0,sp 2328 M mloop ::new_rts@@ 2328 M [33E4] 33E4:9EE6 0B [ 4] lda old_rts135+1,sp 2328 M [33E7] 33E7:9EE7 03 [ 4] sta new_rts@@+1,sp 2328 M mloop ::new_rts@@ 2328 endm 2329 M @mova.s ,x tos_num@@,sp 2329 M mset #' ' 2329 M mreq 1,2:Source Destination 2329 M @@_samesize_ ,x tos_num135,sp 2329 M mreq 1,2:Operand1,Operand2[,Operand]* 2329 M mset 0 2329 M mdo 2329 M mswap 1,1 2329 M mloop :n 2329 M mswap 1,2 2329 M @@_nosize_ tos_num135,sp 2329 M mset # 2329 M mset 0,mstop [_samesize_] No size (tos_num135,sp) 2329 M endm 2329 M mset 0,tos_num135,sp 2329 M mloop :n 2329 M endm 2329 M mset 0 2329 M mdo 2329 M [33EA] 33EA:F6 [ 3] lda +0,x 2329 M [33EB] 33EB:9EE7 04 [ 4] sta tos_num135+0,sp 2329 M mloop ::tos_num135 2329 M [33EE] 33EE:E601 [ 3] lda +1,x 2329 M [33F0] 33F0:9EE7 05 [ 4] sta tos_num135+1,sp 2329 M mloop ::tos_num135 2329 M [33F3] 33F3:E602 [ 3] lda +2,x 2329 M [33F5] 33F5:9EE7 06 [ 4] sta tos_num135+2,sp 2329 M mloop ::tos_num135 2329 M [33F8] 33F8:E603 [ 3] lda +3,x 2329 M [33FA] 33FA:9EE7 07 [ 4] sta tos_num135+3,sp 2329 M mloop ::tos_num135 2329 M [33FD] 33FD:E604 [ 3] lda +4,x 2329 M [33FF] 33FF:9EE7 08 [ 4] sta tos_num135+4,sp 2329 M mloop ::tos_num135 2329 M [3402] 3402:E605 [ 3] lda +5,x 2329 M [3404] 3404:9EE7 09 [ 4] sta tos_num135+5,sp 2329 M mloop ::tos_num135 2329 M [3407] 3407:E606 [ 3] lda +6,x 2329 M [3409] 3409:9EE7 0A [ 4] sta tos_num135+6,sp 2329 M mloop ::tos_num135 2329 M [340C] 340C:E607 [ 3] lda +7,x 2329 M [340E] 340E:9EE7 0B [ 4] sta tos_num135+7,sp 2329 M mloop ::tos_num135 2329 endm 2330 [3411] 3411:86 [ 3] pula 2331 [3412] 3412:81 [ 6] rtc 2332 2333 0055 ?LoadCycles equ :cycles 2334 2335 ;******************************************************************************* 2336 ; Purpose: Unload the top-of-stack number into a variable pointed to by HX 2337 ; Input : [TOS] = Number 2338 ; : HX -> Some 32-bit variable 2339 ; Output : Variable pointed to by HX receives TOS number 2340 ; Note(s): This operation makes it easier to unload a number from the stack. 2341 ; : Use: 2342 ; : ldhx #MyVar 2343 ; : call StackSave32 2344 ; : (Stack is reduced) 2345 2346 #spauto :ab 2347 2348 3413 ?Save proc 2349 #temp :: 2350 FFFFFFFF old_rts@@ next :temp,:ab 2351 0001 tos_num@@ next :temp,?WORD 2352 0009 next :temp,-:ab ;-:AB as old_rts@@ will be gone 2353 0007 new_rts@@ next :temp,:ab 2354 2355 0000 var@@ equ 0,?WORD 2356 2357 [3413] 3413:8789 8B [ 6] push 2358 M @mova.s tos_num@@,sp var@@,x 2358 M mset #' ' 2358 M mreq 1,2:Source Destination 2358 M @@_samesize_ tos_num136,sp var@@,x 2358 M mreq 1,2:Operand1,Operand2[,Operand]* 2358 M mset 0 2358 M mdo 2358 M mswap 1,1 2358 M @@_nosize_ tos_num136,sp 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (tos_num136,sp) 2358 M endm 2358 M mset 0,tos_num136,sp 2358 M mloop :n 2358 M mswap 1,2 2358 M @@_nosize_ var@@,x 2358 M mset # 2358 M mset 0,mstop [_samesize_] No size (var136,x) 2358 M endm 2358 M mloop :n 2358 M endm 2358 M mset 0 2358 M mdo 2358 M [3416] 3416:9EE6 06 [ 4] lda tos_num136+0,sp 2358 M [3419] 3419:F7 [ 2] sta var@@+0,x 2358 M mloop ::var@@ 2358 M [341A] 341A:9EE6 07 [ 4] lda tos_num136+1,sp 2358 M [341D] 341D:E701 [ 3] sta var@@+1,x 2358 M mloop ::var@@ 2358 M [341F] 341F:9EE6 08 [ 4] lda tos_num136+2,sp 2358 M [3422] 3422:E702 [ 3] sta var@@+2,x 2358 M mloop ::var@@ 2358 M [3424] 3424:9EE6 09 [ 4] lda tos_num136+3,sp 2358 M [3427] 3427:E703 [ 3] sta var@@+3,x 2358 M mloop ::var@@ 2358 M [3429] 3429:9EE6 0A [ 4] lda tos_num136+4,sp 2358 M [342C] 342C:E704 [ 3] sta var@@+4,x 2358 M mloop ::var@@ 2358 M [342E] 342E:9EE6 0B [ 4] lda tos_num136+5,sp 2358 M [3431] 3431:E705 [ 3] sta var@@+5,x 2358 M mloop ::var@@ 2358 M [3433] 3433:9EE6 0C [ 4] lda tos_num136+6,sp 2358 M [3436] 3436:E706 [ 3] sta var@@+6,x 2358 M mloop ::var@@ 2358 M [3438] 3438:9EE6 0D [ 4] lda tos_num136+7,sp 2358 M [343B] 343B:E707 [ 3] sta var@@+7,x 2358 M mloop ::var@@ 2358 endm 2359 2360 [343D] 343D:95 [ 2] tsx 2361 M @mova.s old_rts@@,spx new_rts@@,spx ;move RTS/RTC before old memory 2361 M mset #' ' 2361 M mreq 1,2:Source Destination 2361 M @@_samesize_ old_rts136,spx new_rts@@,spx 2361 M mreq 1,2:Operand1,Operand2[,Operand]* 2361 M mset 0 2361 M mdo 2361 M mswap 1,1 2361 M @@_nosize_ old_rts136,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (old_rts136,spx) 2361 M endm 2361 M mset 0,old_rts136,spx 2361 M mloop :n 2361 M mswap 1,2 2361 M @@_nosize_ new_rts@@,spx 2361 M mset # 2361 M mset 0,mstop [_samesize_] No size (new_rts136,spx) 2361 M endm 2361 M mloop :n 2361 M endm 2361 M mset 0 2361 M mdo 2361 M [343E] 343E:E603 [ 3] lda old_rts136+0,spx 2361 M [3440] 3440:E70B [ 3] sta new_rts@@+0,spx 2361 M mloop ::new_rts@@ 2361 M [3442] 3442:E604 [ 3] lda old_rts136+1,spx 2361 M [3444] 3444:E70C [ 3] sta new_rts@@+1,spx 2361 M mloop ::new_rts@@ 2361 endm 2362 [3446] 3446:8A88 86 [ 9] pull 2363 2364 [3449] 3449:A708 [ 2] ais #?WORD ;de-allocate TOS memory 2365 [344B] 344B:81 [ 6] rtc 2366 2367 005C ?SaveCycles equ :cycles 2368 2369 ;******************************************************************************* 2370 ; Purpose: Adjust TOS old size to new 2371 ; Input : H = old (current) byte size 2372 ; : X = new byte size 2373 ; : CCR[C] = 0 -- always positive number 2374 ; : CCR[C] = 1 -- sign extend 2375 ; Output : None 2376 ; Note(s): RegA deliberately not used for parameter passing (for consistency) 2377 ; : Macro destroys RegHX (as we must not use PSHHX/PULHX around call) 2378 2504 2505 ;******************************************************************************* 2506 ; Purpose: Convert 32-bit to ASCIZ string 2507 ; Input : Stack: 32-bit number 2508 ; : HX -> Output buffer with enough space to keep the ASCIZ string result 2509 ; Output : None 2510 ; Note(s): Use: 2511 ; : ldhx #Buffer 2512 ; : call Stack32ToASCIZ 2513 2514 #spauto :ab ;account for RTS/RTC 2515 2516 344C ?ToStr proc 2517 [344C] 344C:8789 8B [ 6] push 2518 #ais ;mark beginning of temporaries 2519 2520 [344F] 344F:898B [ 4] pshhx .buffer@@ ;working copy of pointer to buffer 2521 [3451] 3451:7F [ 4] clr ,x ;make it an ASCIZ string 2522 2523 M @lea 1,sp ;HX -> TOS number of caller 2523 M mset # 2523 M [3452] 3452:95 [ 2] tsx 2523 M [3453] 3453:AF07 [ 2] !aix #1+:tsx 2523 mexit 2524 [3455] 3455:CD33 DB [ 6] call ?Load ;load a working copy on stack 2525 2526 #spadd ?WORD ;stack has grown by a ?WORD 2527 FFFFFFF2 number@@ equ ::,?WORD 2529 [3458] 3458:9E6D 01 [ 5] tst number@@,sp 2530 [345B] 345B:2A0F (346C) [ 3] bpl ToStrLoop@@ 2531 [345D] 345D:CD33 D0 [ 6] call ?Negate 2533 [3460] 3460:9EFE 09 [ 5] ldhx .buffer@@,sp 2540 [3463] 3463:A62D [ 2] lda #'-' ;a 'minus' sign 2541 [3465] 3465:F7 [ 2] sta ,x ; is saved first 2542 2543 [3466] 3466:AF01 [ 2] aix #1 ;HX -> past minus sign 2544 [3468] 3468:7F [ 4] clr ,x ;make it an ASCIZ string 2546 [3469] 3469:9EFF 09 [ 5] sthx .buffer@@,sp ;update pointer past sign 2552 ; bra ToStrLoop@@ 2554 ;=============================================================================== 2555 2556 [346C] 346C:4500 0A [ 3] ToStrLoop@@ ldhx #10 ;H = 0 (always), X = divisor 2557 M @div.s number@@,sp 2557 M mset # 2557 M mreq 1 2557 M @@_not_x_ number137,sp 2557 M mset #' ' 2557 M mdel 1 2557 M mtop 2557 M mset #' ' 2557 M mexit 2557 M @@_nosize_ number137,sp 2557 M mset # 2557 M mset 0,mstop [div.s] No size (number137,sp) 2557 M endm 2557 M #temp 1 2557 M #temp 2 2557 M [346F] 346F:86 [ 3] pula 2557 M [3470] 3470:52 [ 6] div 2557 M [3471] 3471:87 [ 2] psha 2557 M mdo 2 2557 M [3472] 3472:9EE6 02 [ 4] lda number137+1,sp 2557 M [3475] 3475:52 [ 6] div 2557 M [3476] 3476:9EE7 02 [ 4] sta number137+1,sp 2557 M mloop ::number137 2557 M [3479] 3479:9EE6 03 [ 4] lda number137+2,sp 2557 M [347C] 347C:52 [ 6] div 2557 M [347D] 347D:9EE7 03 [ 4] sta number137+2,sp 2557 M mloop ::number137 2557 M [3480] 3480:9EE6 04 [ 4] lda number137+3,sp 2557 M [3483] 3483:52 [ 6] div 2557 M [3484] 3484:9EE7 04 [ 4] sta number137+3,sp 2557 M mloop ::number137 2557 M [3487] 3487:9EE6 05 [ 4] lda number137+4,sp 2557 M [348A] 348A:52 [ 6] div 2557 M [348B] 348B:9EE7 05 [ 4] sta number137+4,sp 2557 M mloop ::number137 2557 M [348E] 348E:9EE6 06 [ 4] lda number137+5,sp 2557 M [3491] 3491:52 [ 6] div 2557 M [3492] 3492:9EE7 06 [ 4] sta number137+5,sp 2557 M mloop ::number137 2557 M [3495] 3495:9EE6 07 [ 4] lda number137+6,sp 2557 M [3498] 3498:52 [ 6] div 2557 M [3499] 3499:9EE7 07 [ 4] sta number137+6,sp 2557 M mloop ::number137 2557 M [349C] 349C:9EE6 08 [ 4] lda number137+7,sp 2557 M [349F] 349F:52 [ 6] div 2557 M [34A0] 34A0:9EE7 08 [ 4] sta number137+7,sp 2557 M mloop ::number137 2557 endm 2558 2559 [34A3] 34A3:8B86 [ 5] tha ;A = remainder 2560 [34A5] 34A5:AB30 [ 2] add #'0' ;A = ASCII remainder 2562 [34A7] 34A7:9EFE 09 [ 5] ldhx .buffer@@,sp 2568 M @StringInsertChar 2568 M [34AA] 34AA:CD18 3A [ 6] call StringInsertChar ;HX and A pre-loaded correctly 2568 mexit 2569 2570 [34AD] 34AD:95 [ 2] tsx 2571 2572 M @_tst_.s number@@,spx 2572 M mset # 2572 M mreq 1 2572 M @@_nosize_ number137,spx 2572 M mset # 2572 M mset 0,mstop [_tst_.s] No size (number137,spx) 2572 M endm 2572 M mdo 2572 M [34AE] 34AE:F6 [ 3] lda number137+0,spx 2572 M mloop ::number137 2572 M [34AF] 34AF:EA01 [ 3] ora number137+1,spx 2572 M mloop ::number137 2572 M [34B1] 34B1:EA02 [ 3] ora number137+2,spx 2572 M mloop ::number137 2572 M [34B3] 34B3:EA03 [ 3] ora number137+3,spx 2572 M mloop ::number137 2572 M [34B5] 34B5:EA04 [ 3] ora number137+4,spx 2572 M mloop ::number137 2572 M [34B7] 34B7:EA05 [ 3] ora number137+5,spx 2572 M mloop ::number137 2572 M [34B9] 34B9:EA06 [ 3] ora number137+6,spx 2572 M mloop ::number137 2572 M [34BB] 34BB:EA07 [ 3] ora number137+7,spx 2572 M mloop ::number137 2572 endm 2573 [34BD] 34BD:26AD (346C) [ 3] bne ToStrLoop@@ 2574 2575 [34BF] 34BF:A70A [ 2] ais #:ais ;free temporaries 2576 [34C1] 34C1:8A88 86 [ 9] pull 2577 [34C4] 34C4:81 [ 6] rtc 2578 2579 #sp ;cancel all SP offsets 2580 2581 ;******************************************************************************* 2582 ; Assign global names to the various library calls, depending on version used. 2583 ; Different names for each version means you can include any at the same time. 2584 ;******************************************************************************* 2585 2586 ? macro BitSize ;temp macro to export symbols 2587 mreq 1:Usage: @~0~ BitSize 2588 #if MATHSIZE = ~1~ 2589 StackAdd~1~ exp ?Add 2590 StackSub~1~ exp ?Subtract 2591 StackMul~1~ exp ?Multiply 2592 StackDiv~1~ exp ?Divide 2593 StackMod~1~ exp ?Modulo 2594 StackSwap~1~ exp ?Swap 2595 StackAbs~1~ exp ?Abs 2596 StackNegate~1~ exp ?Negate 2597 StackLoad~1~ exp ?Load 2598 StackSave~1~ exp ?Save 2599 Stack~1~ToASCIZ exp ?ToStr 2600 #ifdef NO_BIT_OPS 2601 mexit ;;bit operations not available 2602 #endif 2603 StackAnd~1~ exp ?BitAnd 2604 StackOr~1~ exp ?BitOr 2605 StackXor~1~ exp ?BitXor 2606 StackShl~1~ exp ?ShiftLeft 2607 StackShr~1~ exp ?ShiftRight 2608 #endif 2609 endm 2610 2611 M @? 64 ;export 64-bit labels 2611 M mreq 1:Usage: @? BitSize 2611 M 2F73 StackAdd64 exp ?Add 2611 M 2F89 StackSub64 exp ?Subtract 2611 M 30A8 StackMul64 exp ?Multiply 2611 M 3115 StackDiv64 exp ?Divide 2611 M 3128 StackMod64 exp ?Modulo 2611 M 33AF StackSwap64 exp ?Swap 2611 M 33CB StackAbs64 exp ?Abs 2611 M 33D0 StackNegate64 exp ?Negate 2611 M 33DB StackLoad64 exp ?Load 2611 M 3413 StackSave64 exp ?Save 2611 M 344C Stack64ToASCIZ exp ?ToStr 2611 M 2F9F StackAnd64 exp ?BitAnd 2611 M 2FB4 StackOr64 exp ?BitOr 2611 M 2FC9 StackXor64 exp ?BitXor 2611 M 2FDE StackShl64 exp ?ShiftLeft 2611 M 3043 StackShr64 exp ?ShiftRight 2611 endm 2612 M @? 56 ;export 56-bit labels 2612 M mreq 1:Usage: @? BitSize 2612 endm 2613 M @? 48 ;export 48-bit labels 2613 M mreq 1:Usage: @? BitSize 2613 endm 2614 M @? 40 ;export 40-bit labels 2614 M mreq 1:Usage: @? BitSize 2614 endm 2615 M @? 32 ;export 32-bit labels 2615 M mreq 1:Usage: @? BitSize 2615 endm 2616 M @? 24 ;export 24-bit labels 2616 M mreq 1:Usage: @? BitSize 2616 endm 2617 M @? 16 ;export 16-bit labels 2617 M mreq 1:Usage: @? BitSize 2617 endm 2618 2619 ;******************************************************************************* *** END INCLUDE FILE: lib/stakmath.sub *** (RESUMING FILE: lib/stkmth64.sub) 23 #Exit *** END INCLUDE FILE: lib/stkmth64.sub *** (RESUMING FILE: lib/demo/stakmath.asm) 55 #MapOn 56 57 ;******************************************************************************* 58 59 0008 DebuggerHexDumpSize def 8 60 61 M @XRAM 61 M #RAM 61 M #XRAM 61 endm 62 63 0100 align DebuggerHexDumpSize 64 0100+0004 a rmb 4 65 66 0108 align DebuggerHexDumpSize 67 0108+0004 b rmb 4 68 69 0110 align DebuggerHexDumpSize 70 0110+0004 ans rmb 4 71 72 0118 align DebuggerHexDumpSize 73 0118+0018 String rmb 24 74 75 ;------------------------------------------------------------------------------- 76 77 7D00 A def 32000 78 1388 B def 5000 79 80 ;******************************************************************************* 81 #ROM 82 ;******************************************************************************* 83 84 #spauto 85 86 34C5 Start proc 87 M @rsp 87 M mdef 1,#STACKTOP 87 M @lds #STACKTOP 87 M [34C5] 34C5:4510 80 [ 3] ldhx #STACKTOP 87 M [34C8] 34C8:94 [ 2] txs 87 endm 88 89 M @mova.s #A a 89 M mset #' ' 89 M mreq 1,2:Source Destination 89 M @@_nosize_ a 89 M mset # 89 M mset 0,mstop [mova.s] No size (a) 89 M endm 89 M mset 0 89 M mdo 89 M #temp 89 M [34C9] 34C9:4F [ 1] clra 89 M mset 0,clra 89 M #temp 1 89 M [34CA] 34CA:C701 00 [ 4] sta a+0 89 M mloop ::a 89 M #temp 89 M mset 0,clra 89 M #temp 1 89 M [34CD] 34CD:C701 01 [ 4] sta a+1 89 M mloop ::a 89 M #temp 89 M [34D0] 34D0:A67D [ 2] lda #A>8&$FF 89 M mset 0 89 M [34D2] 34D2:C701 02 [ 4] sta a+2 89 M mloop ::a 89 M #temp 89 M [34D5] 34D5:4F [ 1] clra 89 M mset 0,clra 89 M #temp 1 89 M [34D6] 34D6:C701 03 [ 4] sta a+3 89 M mloop ::a 89 endm 90 M @mova.s #B b 90 M mset #' ' 90 M mreq 1,2:Source Destination 90 M @@_nosize_ b 90 M mset # 90 M mset 0,mstop [mova.s] No size (b) 90 M endm 90 M mset 0 90 M mdo 90 M #temp 90 M [34D9] 34D9:4F [ 1] clra 90 M mset 0,clra 90 M #temp 1 90 M [34DA] 34DA:C701 08 [ 4] sta b+0 90 M mloop ::b 90 M #temp 90 M mset 0,clra 90 M #temp 1 90 M [34DD] 34DD:C701 09 [ 4] sta b+1 90 M mloop ::b 90 M #temp 90 M [34E0] 34E0:A613 [ 2] lda #B>8&$FF 90 M mset 0 90 M [34E2] 34E2:C701 0A [ 4] sta b+2 90 M mloop ::b 90 M #temp 90 M [34E5] 34E5:A688 [ 2] lda #B>0&$FF 90 M mset 0 90 M [34E7] 34E7:C701 0B [ 4] sta b+3 90 M mloop ::b 90 endm 91 92 [34EA] 34EA:8C5F [ 2] clrhx 93 [34EC] 34EC:4F [ 1] clra 94 95 ;------------------------------------------------------------------------------- 96 ; Test code inside a macro allows for easier editing of all bit versions at once 97 ;------------------------------------------------------------------------------- 98 99 Test macro 100 ;------------------------------------------------------------------------------- 101 ; Test the ~1~-bit version 102 ;------------------------------------------------------------------------------- 103 104 ;------------------------------------------------------------------------------- 105 ; @@Load~1~ a 106 ;------------------------------------------------------------------------------- 107 @@Load~1~ a 108 ;------------------------------------------------------------------------------- 109 ; @@Load~1~ b 110 ;------------------------------------------------------------------------------- 111 @@Load~1~ b 112 ;------------------------------------------------------------------------------- 113 ; @@Swap~1~ 114 ;------------------------------------------------------------------------------- 115 @@Swap~1~ 116 ;------------------------------------------------------------------------------- 117 ; @@Save~1~ ans 118 ;------------------------------------------------------------------------------- 119 @@Save~1~ ans 120 ;------------------------------------------------------------------------------- 121 ; @@Save~1~ ans 122 ;------------------------------------------------------------------------------- 123 @@Save~1~ ans 124 ;------------------------------------------------------------------------------- 125 ; @@Add~1~ a,b,ans 126 ;------------------------------------------------------------------------------- 127 @@Add~1~ a,b,ans 128 ;------------------------------------------------------------------------------- 129 ; @@Sub~1~ a,b,ans 130 ;------------------------------------------------------------------------------- 131 @@Sub~1~ a,b,ans 132 ;------------------------------------------------------------------------------- 133 ; @@Mul~1~ a,b,ans 134 ;------------------------------------------------------------------------------- 135 @@Mul~1~ a,b,ans 136 ;------------------------------------------------------------------------------- 137 ; @@Div~1~ a,b,ans 138 ;------------------------------------------------------------------------------- 139 @@Div~1~ a,b,ans 140 ;------------------------------------------------------------------------------- 141 ; @@Mod~1~ a,b,ans 142 ;------------------------------------------------------------------------------- 143 @@Mod~1~ a,b,ans 144 ;------------------------------------------------------------------------------- 145 ; @@Neg~1~ ans 146 ;------------------------------------------------------------------------------- 147 @@Neg~1~ ans 148 ;------------------------------------------------------------------------------- 149 ; @@Abs~1~ ans 150 ;------------------------------------------------------------------------------- 151 @@Abs~1~ ans 152 ;------------------------------------------------------------------------------- 153 ; @@Str~1~ ans,String 154 ;------------------------------------------------------------------------------- 155 @@Str~1~ ans,String 156 ;------------------------------------------------------------------------------- 157 ; @@Eval~1~ ans = (a + b) * abs(a - b) / 2 158 ;------------------------------------------------------------------------------- 159 @@Eval~1~ ans = abs(a + b) * abs(a - b) / 2 160 endm 161 162 M @Test 16 162 M ;------------------------------------------------------------------------------- 162 M ; Test the 16-bit version 162 M ;------------------------------------------------------------------------------- 162 M 162 M ;------------------------------------------------------------------------------- 162 M ; @@Load16 a 162 M ;------------------------------------------------------------------------------- 162 M @@Load16 a 162 M @_DoLoad 16,a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [34ED] 34ED:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [34F0] 34F0:E603 [ 3] lda 3,x 162 M [34F2] 34F2:87 [ 2] psha 162 M mloop 4 162 M [34F3] 34F3:E602 [ 3] lda 2,x 162 M [34F5] 34F5:87 [ 2] psha 162 M mloop 4 162 M [34F6] 34F6:E601 [ 3] lda 1,x 162 M [34F8] 34F8:87 [ 2] psha 162 M mloop 4 162 M [34F9] 34F9:F6 [ 3] lda 0,x 162 M [34FA] 34FA:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [34FB] 34FB:A702 [ 2] ais #-:temp 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Load16 b 162 M ;------------------------------------------------------------------------------- 162 M @@Load16 b 162 M @_DoLoad 16,b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [34FD] 34FD:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [3500] 3500:E603 [ 3] lda 3,x 162 M [3502] 3502:87 [ 2] psha 162 M mloop 4 162 M [3503] 3503:E602 [ 3] lda 2,x 162 M [3505] 3505:87 [ 2] psha 162 M mloop 4 162 M [3506] 3506:E601 [ 3] lda 1,x 162 M [3508] 3508:87 [ 2] psha 162 M mloop 4 162 M [3509] 3509:F6 [ 3] lda 0,x 162 M [350A] 350A:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [350B] 350B:A702 [ 2] ais #-:temp 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Swap16 162 M ;------------------------------------------------------------------------------- 162 M @@Swap16 162 M @_DoSwap 16 162 M [350D] 350D:CD1E 73 [ 6] call StackSwap16 162 M endm 162 M ;------------------------------------------------------------------------------- 162 M ; @@Save16 ans 162 M ;------------------------------------------------------------------------------- 162 M @@Save16 ans 162 M @_DoSave 16,ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2,#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [3510] 3510:5F [ 1] clrx 162 M [3511] 3511:9E6D 01 [ 5] tst 1,asp 162 M [3514] 3514:2A01 (3517) [ 3] bpl *+3 162 M [3516] 3516:53 [ 1] !comx 162 M [3517] 3517:89 [ 2] pshx:2 162 M [3518] 3518:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [3519] 3519:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [351C] 351C:86 [ 3] pula 162 M [351D] 351D:F7 [ 2] sta 0,x 162 M mloop 4 162 M [351E] 351E:86 [ 3] pula 162 M [351F] 351F:E701 [ 3] sta 1,x 162 M mloop 4 162 M [3521] 3521:86 [ 3] pula 162 M [3522] 3522:E702 [ 3] sta 2,x 162 M mloop 4 162 M [3524] 3524:86 [ 3] pula 162 M [3525] 3525:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Save16 ans 162 M ;------------------------------------------------------------------------------- 162 M @@Save16 ans 162 M @_DoSave 16,ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2,#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [3527] 3527:5F [ 1] clrx 162 M [3528] 3528:9E6D 01 [ 5] tst 1,asp 162 M [352B] 352B:2A01 (352E) [ 3] bpl *+3 162 M [352D] 352D:53 [ 1] !comx 162 M [352E] 352E:89 [ 2] pshx:2 162 M [352F] 352F:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [3530] 3530:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [3533] 3533:86 [ 3] pula 162 M [3534] 3534:F7 [ 2] sta 0,x 162 M mloop 4 162 M [3535] 3535:86 [ 3] pula 162 M [3536] 3536:E701 [ 3] sta 1,x 162 M mloop 4 162 M [3538] 3538:86 [ 3] pula 162 M [3539] 3539:E702 [ 3] sta 2,x 162 M mloop 4 162 M [353B] 353B:86 [ 3] pula 162 M [353C] 353C:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Add16 a,b,ans 162 M ;------------------------------------------------------------------------------- 162 M @@Add16 a,b,ans 162 M @_DoMath Add16,16,a,b,ans 162 M @@Load16 b 162 M @_DoLoad 16,b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [353E] 353E:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [3541] 3541:E603 [ 3] lda 3,x 162 M [3543] 3543:87 [ 2] psha 162 M mloop 4 162 M [3544] 3544:E602 [ 3] lda 2,x 162 M [3546] 3546:87 [ 2] psha 162 M mloop 4 162 M [3547] 3547:E601 [ 3] lda 1,x 162 M [3549] 3549:87 [ 2] psha 162 M mloop 4 162 M [354A] 354A:F6 [ 3] lda 0,x 162 M [354B] 354B:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [354C] 354C:A702 [ 2] ais #-:temp 162 M mexit 162 M @@Load16 a 162 M @_DoLoad 16,a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [354E] 354E:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [3551] 3551:E603 [ 3] lda 3,x 162 M [3553] 3553:87 [ 2] psha 162 M mloop 4 162 M [3554] 3554:E602 [ 3] lda 2,x 162 M [3556] 3556:87 [ 2] psha 162 M mloop 4 162 M [3557] 3557:E601 [ 3] lda 1,x 162 M [3559] 3559:87 [ 2] psha 162 M mloop 4 162 M [355A] 355A:F6 [ 3] lda 0,x 162 M [355B] 355B:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [355C] 355C:A702 [ 2] ais #-:temp 162 M mexit 162 M @@_DoOperation Add16 162 M mdef 2,16 162 M @@Msg Add16 162 M mexit 162 M [355E] 355E:CD1C 92 [ 6] call StackAdd16 162 M #spadd -16/8 162 M endm 162 M @Save16 ans 162 M @_DoSave 16,ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2,#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [3561] 3561:5F [ 1] clrx 162 M [3562] 3562:9E6D 01 [ 5] tst 1,asp 162 M [3565] 3565:2A01 (3568) [ 3] bpl *+3 162 M [3567] 3567:53 [ 1] !comx 162 M [3568] 3568:89 [ 2] pshx:2 162 M [3569] 3569:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [356A] 356A:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [356D] 356D:86 [ 3] pula 162 M [356E] 356E:F7 [ 2] sta 0,x 162 M mloop 4 162 M [356F] 356F:86 [ 3] pula 162 M [3570] 3570:E701 [ 3] sta 1,x 162 M mloop 4 162 M [3572] 3572:86 [ 3] pula 162 M [3573] 3573:E702 [ 3] sta 2,x 162 M mloop 4 162 M [3575] 3575:86 [ 3] pula 162 M [3576] 3576:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Sub16 a,b,ans 162 M ;------------------------------------------------------------------------------- 162 M @@Sub16 a,b,ans 162 M @_DoMath Sub16,16,a,b,ans 162 M @@Load16 b 162 M @_DoLoad 16,b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [3578] 3578:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [357B] 357B:E603 [ 3] lda 3,x 162 M [357D] 357D:87 [ 2] psha 162 M mloop 4 162 M [357E] 357E:E602 [ 3] lda 2,x 162 M [3580] 3580:87 [ 2] psha 162 M mloop 4 162 M [3581] 3581:E601 [ 3] lda 1,x 162 M [3583] 3583:87 [ 2] psha 162 M mloop 4 162 M [3584] 3584:F6 [ 3] lda 0,x 162 M [3585] 3585:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [3586] 3586:A702 [ 2] ais #-:temp 162 M mexit 162 M @@Load16 a 162 M @_DoLoad 16,a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [3588] 3588:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [358B] 358B:E603 [ 3] lda 3,x 162 M [358D] 358D:87 [ 2] psha 162 M mloop 4 162 M [358E] 358E:E602 [ 3] lda 2,x 162 M [3590] 3590:87 [ 2] psha 162 M mloop 4 162 M [3591] 3591:E601 [ 3] lda 1,x 162 M [3593] 3593:87 [ 2] psha 162 M mloop 4 162 M [3594] 3594:F6 [ 3] lda 0,x 162 M [3595] 3595:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [3596] 3596:A702 [ 2] ais #-:temp 162 M mexit 162 M @@_DoOperation Sub16 162 M mdef 2,16 162 M @@Msg Sub16 162 M mexit 162 M [3598] 3598:CD1C A5 [ 6] call StackSub16 162 M #spadd -16/8 162 M endm 162 M @Save16 ans 162 M @_DoSave 16,ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2,#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [359B] 359B:5F [ 1] clrx 162 M [359C] 359C:9E6D 01 [ 5] tst 1,asp 162 M [359F] 359F:2A01 (35A2) [ 3] bpl *+3 162 M [35A1] 35A1:53 [ 1] !comx 162 M [35A2] 35A2:89 [ 2] pshx:2 162 M [35A3] 35A3:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [35A4] 35A4:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [35A7] 35A7:86 [ 3] pula 162 M [35A8] 35A8:F7 [ 2] sta 0,x 162 M mloop 4 162 M [35A9] 35A9:86 [ 3] pula 162 M [35AA] 35AA:E701 [ 3] sta 1,x 162 M mloop 4 162 M [35AC] 35AC:86 [ 3] pula 162 M [35AD] 35AD:E702 [ 3] sta 2,x 162 M mloop 4 162 M [35AF] 35AF:86 [ 3] pula 162 M [35B0] 35B0:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Mul16 a,b,ans 162 M ;------------------------------------------------------------------------------- 162 M @@Mul16 a,b,ans 162 M @_DoMath Mul16,16,a,b,ans 162 M @@Load16 b 162 M @_DoLoad 16,b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [35B2] 35B2:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [35B5] 35B5:E603 [ 3] lda 3,x 162 M [35B7] 35B7:87 [ 2] psha 162 M mloop 4 162 M [35B8] 35B8:E602 [ 3] lda 2,x 162 M [35BA] 35BA:87 [ 2] psha 162 M mloop 4 162 M [35BB] 35BB:E601 [ 3] lda 1,x 162 M [35BD] 35BD:87 [ 2] psha 162 M mloop 4 162 M [35BE] 35BE:F6 [ 3] lda 0,x 162 M [35BF] 35BF:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [35C0] 35C0:A702 [ 2] ais #-:temp 162 M mexit 162 M @@Load16 a 162 M @_DoLoad 16,a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [35C2] 35C2:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [35C5] 35C5:E603 [ 3] lda 3,x 162 M [35C7] 35C7:87 [ 2] psha 162 M mloop 4 162 M [35C8] 35C8:E602 [ 3] lda 2,x 162 M [35CA] 35CA:87 [ 2] psha 162 M mloop 4 162 M [35CB] 35CB:E601 [ 3] lda 1,x 162 M [35CD] 35CD:87 [ 2] psha 162 M mloop 4 162 M [35CE] 35CE:F6 [ 3] lda 0,x 162 M [35CF] 35CF:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [35D0] 35D0:A702 [ 2] ais #-:temp 162 M mexit 162 M @@_DoOperation Mul16 162 M mdef 2,16 162 M @@Msg Mul16 162 M mexit 162 M [35D2] 35D2:CD1D 43 [ 6] call StackMul16 162 M #spadd -16/8 162 M endm 162 M @Save16 ans 162 M @_DoSave 16,ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2,#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [35D5] 35D5:5F [ 1] clrx 162 M [35D6] 35D6:9E6D 01 [ 5] tst 1,asp 162 M [35D9] 35D9:2A01 (35DC) [ 3] bpl *+3 162 M [35DB] 35DB:53 [ 1] !comx 162 M [35DC] 35DC:89 [ 2] pshx:2 162 M [35DD] 35DD:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [35DE] 35DE:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [35E1] 35E1:86 [ 3] pula 162 M [35E2] 35E2:F7 [ 2] sta 0,x 162 M mloop 4 162 M [35E3] 35E3:86 [ 3] pula 162 M [35E4] 35E4:E701 [ 3] sta 1,x 162 M mloop 4 162 M [35E6] 35E6:86 [ 3] pula 162 M [35E7] 35E7:E702 [ 3] sta 2,x 162 M mloop 4 162 M [35E9] 35E9:86 [ 3] pula 162 M [35EA] 35EA:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Div16 a,b,ans 162 M ;------------------------------------------------------------------------------- 162 M @@Div16 a,b,ans 162 M @_DoMath Div16,16,a,b,ans 162 M @@Load16 b 162 M @_DoLoad 16,b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [35EC] 35EC:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [35EF] 35EF:E603 [ 3] lda 3,x 162 M [35F1] 35F1:87 [ 2] psha 162 M mloop 4 162 M [35F2] 35F2:E602 [ 3] lda 2,x 162 M [35F4] 35F4:87 [ 2] psha 162 M mloop 4 162 M [35F5] 35F5:E601 [ 3] lda 1,x 162 M [35F7] 35F7:87 [ 2] psha 162 M mloop 4 162 M [35F8] 35F8:F6 [ 3] lda 0,x 162 M [35F9] 35F9:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [35FA] 35FA:A702 [ 2] ais #-:temp 162 M mexit 162 M @@Load16 a 162 M @_DoLoad 16,a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [35FC] 35FC:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [35FF] 35FF:E603 [ 3] lda 3,x 162 M [3601] 3601:87 [ 2] psha 162 M mloop 4 162 M [3602] 3602:E602 [ 3] lda 2,x 162 M [3604] 3604:87 [ 2] psha 162 M mloop 4 162 M [3605] 3605:E601 [ 3] lda 1,x 162 M [3607] 3607:87 [ 2] psha 162 M mloop 4 162 M [3608] 3608:F6 [ 3] lda 0,x 162 M [3609] 3609:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [360A] 360A:A702 [ 2] ais #-:temp 162 M mexit 162 M @@_DoOperation Div16 162 M mdef 2,16 162 M @@Msg Div16 162 M mexit 162 M [360C] 360C:CD1D 6A [ 6] call StackDiv16 162 M #spadd -16/8 162 M endm 162 M @Save16 ans 162 M @_DoSave 16,ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2,#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [360F] 360F:5F [ 1] clrx 162 M [3610] 3610:9E6D 01 [ 5] tst 1,asp 162 M [3613] 3613:2A01 (3616) [ 3] bpl *+3 162 M [3615] 3615:53 [ 1] !comx 162 M [3616] 3616:89 [ 2] pshx:2 162 M [3617] 3617:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [3618] 3618:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [361B] 361B:86 [ 3] pula 162 M [361C] 361C:F7 [ 2] sta 0,x 162 M mloop 4 162 M [361D] 361D:86 [ 3] pula 162 M [361E] 361E:E701 [ 3] sta 1,x 162 M mloop 4 162 M [3620] 3620:86 [ 3] pula 162 M [3621] 3621:E702 [ 3] sta 2,x 162 M mloop 4 162 M [3623] 3623:86 [ 3] pula 162 M [3624] 3624:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Mod16 a,b,ans 162 M ;------------------------------------------------------------------------------- 162 M @@Mod16 a,b,ans 162 M @_DoMath Mod16,16,a,b,ans 162 M @@Load16 b 162 M @_DoLoad 16,b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [3626] 3626:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [3629] 3629:E603 [ 3] lda 3,x 162 M [362B] 362B:87 [ 2] psha 162 M mloop 4 162 M [362C] 362C:E602 [ 3] lda 2,x 162 M [362E] 362E:87 [ 2] psha 162 M mloop 4 162 M [362F] 362F:E601 [ 3] lda 1,x 162 M [3631] 3631:87 [ 2] psha 162 M mloop 4 162 M [3632] 3632:F6 [ 3] lda 0,x 162 M [3633] 3633:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [3634] 3634:A702 [ 2] ais #-:temp 162 M mexit 162 M @@Load16 a 162 M @_DoLoad 16,a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [3636] 3636:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [3639] 3639:E603 [ 3] lda 3,x 162 M [363B] 363B:87 [ 2] psha 162 M mloop 4 162 M [363C] 363C:E602 [ 3] lda 2,x 162 M [363E] 363E:87 [ 2] psha 162 M mloop 4 162 M [363F] 363F:E601 [ 3] lda 1,x 162 M [3641] 3641:87 [ 2] psha 162 M mloop 4 162 M [3642] 3642:F6 [ 3] lda 0,x 162 M [3643] 3643:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [3644] 3644:A702 [ 2] ais #-:temp 162 M mexit 162 M @@_DoOperation Mod16 162 M mdef 2,16 162 M @@Msg Mod16 162 M mexit 162 M [3646] 3646:CD1D 7D [ 6] call StackMod16 162 M #spadd -16/8 162 M endm 162 M @Save16 ans 162 M @_DoSave 16,ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2,#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [3649] 3649:5F [ 1] clrx 162 M [364A] 364A:9E6D 01 [ 5] tst 1,asp 162 M [364D] 364D:2A01 (3650) [ 3] bpl *+3 162 M [364F] 364F:53 [ 1] !comx 162 M [3650] 3650:89 [ 2] pshx:2 162 M [3651] 3651:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [3652] 3652:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [3655] 3655:86 [ 3] pula 162 M [3656] 3656:F7 [ 2] sta 0,x 162 M mloop 4 162 M [3657] 3657:86 [ 3] pula 162 M [3658] 3658:E701 [ 3] sta 1,x 162 M mloop 4 162 M [365A] 365A:86 [ 3] pula 162 M [365B] 365B:E702 [ 3] sta 2,x 162 M mloop 4 162 M [365D] 365D:86 [ 3] pula 162 M [365E] 365E:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 M ;------------------------------------------------------------------------------- 162 M ; @@Neg16 ans 162 M ;------------------------------------------------------------------------------- 162 M @@Neg16 ans 162 M @_DoNeg 16,ans 162 M @@Msg Neg16 ans 162 M mexit 162 M @@_FindStkMth_ 16 162 M #temp 162 M mdo 16/8 162 M #temp :mloop*8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mexit :temp 162 M mset 1,16 162 M @@Load16 ans 162 M @_DoLoad 16,ans 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ ans 162 M mexit 162 M @@pushv ans 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [3660] 3660:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [3663] 3663:E603 [ 3] lda 3,x 162 M [3665] 3665:87 [ 2] psha 162 M mloop 4 162 M [3666] 3666:E602 [ 3] lda 2,x 162 M [3668] 3668:87 [ 2] psha 162 M mloop 4 162 M [3669] 3669:E601 [ 3] lda 1,x 162 M [366B] 366B:87 [ 2] psha 162 M mloop 4 162 M [366C] 366C:F6 [ 3] lda 0,x 162 M [366D] 366D:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ ans 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [366E] 366E:A702 [ 2] ais #-:temp 162 M mexit 162 M [3670] 3670:CD1E 94 [ 6] call StackNegate16 162 M @Save16 162 M @_DoSave 16 162 M mreq 1:BitSize[,Variable] 162 M mset 2 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ 162 M mset #' ' 162 M mexit 162 M @@Msg Save16 162 M mexit 162 M @@lea 162 M mset # 162 M mexit 162 M @@_?sei_ 162 M mexit 162 M [3673] 3673:CD1E B9 [ 6] call StackSave16 162 M @@_?cli_ 162 M mexit 162 M #spadd -16/8 162 M endm 162 M ;------------------------------------------------------------------------------- 162 M ; @@Abs16 ans 162 M ;------------------------------------------------------------------------------- 162 M @@Abs16 ans 162 M @_DoAbs 16,ans 162 M @@Msg Abs16 ans 162 M mexit 162 M @@_FindStkMth_ 16 162 M #temp 162 M mdo 16/8 162 M #temp :mloop*8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mexit :temp 162 M mset 1,16 162 M @@Load16 ans 162 M @_DoLoad 16,ans 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ ans 162 M mexit 162 M @@pushv ans 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [3676] 3676:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [3679] 3679:E603 [ 3] lda 3,x 162 M [367B] 367B:87 [ 2] psha 162 M mloop 4 162 M [367C] 367C:E602 [ 3] lda 2,x 162 M [367E] 367E:87 [ 2] psha 162 M mloop 4 162 M [367F] 367F:E601 [ 3] lda 1,x 162 M [3681] 3681:87 [ 2] psha 162 M mloop 4 162 M [3682] 3682:F6 [ 3] lda 0,x 162 M [3683] 3683:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ ans 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [3684] 3684:A702 [ 2] ais #-:temp 162 M mexit 162 M [3686] 3686:CD1E 8F [ 6] call StackAbs16 162 M @Save16 162 M @_DoSave 16 162 M mreq 1:BitSize[,Variable] 162 M mset 2 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ 162 M mset #' ' 162 M mexit 162 M @@Msg Save16 162 M mexit 162 M @@lea 162 M mset # 162 M mexit 162 M @@_?sei_ 162 M mexit 162 M [3689] 3689:CD1E B9 [ 6] call StackSave16 162 M @@_?cli_ 162 M mexit 162 M #spadd -16/8 162 M endm 162 M ;------------------------------------------------------------------------------- 162 M ; @@Str16 ans,String 162 M ;------------------------------------------------------------------------------- 162 M @@Str16 ans,String 162 M @_DoStr 16,ans,String 162 M @@_FindStkMth_ 16 162 M #temp 162 M mdo 16/8 162 M #temp :mloop*8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mexit :temp 162 M mset 1,16 162 M @@Load16 ans 162 M @_DoLoad 16,ans 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ ans 162 M mexit 162 M @@pushv ans 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [368C] 368C:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [368F] 368F:E603 [ 3] lda 3,x 162 M [3691] 3691:87 [ 2] psha 162 M mloop 4 162 M [3692] 3692:E602 [ 3] lda 2,x 162 M [3694] 3694:87 [ 2] psha 162 M mloop 4 162 M [3695] 3695:E601 [ 3] lda 1,x 162 M [3697] 3697:87 [ 2] psha 162 M mloop 4 162 M [3698] 3698:F6 [ 3] lda 0,x 162 M [3699] 3699:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ ans 162 M mexit 162 M @ResizeTOS #4,#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [369A] 369A:A702 [ 2] ais #-:temp 162 M mexit 162 M @@Msg Convert 'ans' (32-bit) to ASCIZ in 'String' 162 M mexit 162 M @@lea String 162 M mset # 162 M [369C] 369C:4501 18 [ 3] ldhx #String 162 M endm 162 M [369F] 369F:CD1E D4 [ 6] call Stack16ToASCIZ 162 M [36A2] 36A2:A702 [ 2] ais #16/8 162 M endm 162 M ;------------------------------------------------------------------------------- 162 M ; @@Eval16 ans = (a + b) * abs(a - b) / 2 162 M ;------------------------------------------------------------------------------- 162 M @@Eval16 ans = abs(a + b) * abs(a - b) / 2 162 M mset # 162 M @_Eval_ 16,ans = abs(a + b) * abs(a - b) / 2 162 M @@_needs_spauto_ 162 M mexit 162 M mdef 1,32 162 M mswap 0,1 162 M mdel 1 162 M mset # 162 M @@Msg -------------------------------------------------- 162 M mexit 162 M @@Msg Expr: ans = abs(a + b) * abs(a - b) / 2 162 M mexit 162 M @@Msg -------------------------------------------------- 162 M mexit 162 M @@_FindStkMth_ 16 162 M #temp 162 M mdo 16/8 162 M #temp :mloop*8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mloop 8 162 M mexit :temp 162 M mset 0,16,16 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M mtrim 1 162 M mset #'=' 162 M @@_Eval_ abs(a+b)*abs(a-b)/2 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M mdo 2 162 M @@_Eval_ 2 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M 162 M 162 M 162 M 162 M 162 M mset 9 162 M 162 M mset 1,#2 162 M mset 1,#2 162 M @Load16 #2 162 M @_DoLoad 16=#2 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ #2 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M mset 1,#2 162 M @@Msg Load16 #2 162 M mexit 162 M mset 1,2 162 M mset 0 162 M mdo 162 M [36A4] 36A4:AE02 [ 2] ldx #2>0&$FF 162 M [36A6] 36A6:89 [ 2] pshx 162 M mloop :temp 162 M [36A7] 36A7:8C [ 1] clrh 162 M mset 0,clrh 162 M [36A8] 36A8:8B [ 2] pshh 162 M mloop :temp 162 M mexit 162 M mloop :nn 162 M @@_Eval_ abs(a-b) 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M 162 M 162 M @@_Eval_ a-b 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M mdo 2 162 M @@_Eval_ b 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M 162 M 162 M 162 M 162 M 162 M mset 9 162 M 162 M @Load16 b 162 M @_DoLoad 16=b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [36A9] 36A9:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [36AC] 36AC:E603 [ 3] lda 3,x 162 M [36AE] 36AE:87 [ 2] psha 162 M mloop 4 162 M [36AF] 36AF:E602 [ 3] lda 2,x 162 M [36B1] 36B1:87 [ 2] psha 162 M mloop 4 162 M [36B2] 36B2:E601 [ 3] lda 1,x 162 M [36B4] 36B4:87 [ 2] psha 162 M mloop 4 162 M [36B5] 36B5:F6 [ 3] lda 0,x 162 M [36B6] 36B6:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4=#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [36B7] 36B7:A702 [ 2] ais #-:temp 162 M mexit 162 M mloop :nn 162 M @@_Eval_ a 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M 162 M 162 M 162 M 162 M 162 M mset 9 162 M 162 M @Load16 a 162 M @_DoLoad 16=a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [36B9] 36B9:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [36BC] 36BC:E603 [ 3] lda 3,x 162 M [36BE] 36BE:87 [ 2] psha 162 M mloop 4 162 M [36BF] 36BF:E602 [ 3] lda 2,x 162 M [36C1] 36C1:87 [ 2] psha 162 M mloop 4 162 M [36C2] 36C2:E601 [ 3] lda 1,x 162 M [36C4] 36C4:87 [ 2] psha 162 M mloop 4 162 M [36C5] 36C5:F6 [ 3] lda 0,x 162 M [36C6] 36C6:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4=#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [36C7] 36C7:A702 [ 2] ais #-:temp 162 M mexit 162 M mdo 2 162 M @@Msg Sub16 162 M mexit 162 M [36C9] 36C9:CD1C A5 [ 6] call StackSub16 162 M #spadd -2 162 M mloop :nn 162 M mexit 162 M @@Msg Abs16 162 M mexit 162 M [36CC] 36CC:CD1E 8F [ 6] call StackAbs16 162 M mexit 162 M mloop :nn 162 M @@_Eval_ abs(a+b) 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M 162 M 162 M @@_Eval_ a+b 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M mdo 2 162 M @@_Eval_ b 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M 162 M 162 M 162 M 162 M 162 M mset 9 162 M 162 M @Load16 b 162 M @_DoLoad 16=b 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ b 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ b 162 M mexit 162 M @@pushv b 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV b (32-bit) 162 M mexit 162 M #push 162 M @@lea b 162 M mset # 162 M [36CF] 36CF:4501 08 [ 3] ldhx #b 162 M endm 162 M #x 162 M mdo 162 M [36D2] 36D2:E603 [ 3] lda 3,x 162 M [36D4] 36D4:87 [ 2] psha 162 M mloop 4 162 M [36D5] 36D5:E602 [ 3] lda 2,x 162 M [36D7] 36D7:87 [ 2] psha 162 M mloop 4 162 M [36D8] 36D8:E601 [ 3] lda 1,x 162 M [36DA] 36DA:87 [ 2] psha 162 M mloop 4 162 M [36DB] 36DB:F6 [ 3] lda 0,x 162 M [36DC] 36DC:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ b 162 M mexit 162 M @ResizeTOS #4=#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [36DD] 36DD:A702 [ 2] ais #-:temp 162 M mexit 162 M mloop :nn 162 M @@_Eval_ a 162 M mset # 162 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 162 M 162 M 162 M 162 M 162 M mset #'+-|^' 162 M 162 M mset #'*\/&><' 162 M 162 M 162 M 162 M 162 M 162 M mset 9 162 M 162 M @Load16 a 162 M @_DoLoad 16=a 162 M mreq 1:BitSize[,Variable] 162 M #temp 16/8 162 M mdel 1 162 M mset # 162 M mtrim 1 162 M 162 M mset 9 162 M 162 M @@_not_x_ a 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M 162 M 162 M @@_?sei_ a 162 M mexit 162 M @@pushv a 162 M mset #' ' 162 M mset 0 162 M mreq 1:variable[ SizeOf(var)][ 'newname'] 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PushV a (32-bit) 162 M mexit 162 M #push 162 M @@lea a 162 M mset # 162 M [36DF] 36DF:4501 00 [ 3] ldhx #a 162 M endm 162 M #x 162 M mdo 162 M [36E2] 36E2:E603 [ 3] lda 3,x 162 M [36E4] 36E4:87 [ 2] psha 162 M mloop 4 162 M [36E5] 36E5:E602 [ 3] lda 2,x 162 M [36E7] 36E7:87 [ 2] psha 162 M mloop 4 162 M [36E8] 36E8:E601 [ 3] lda 1,x 162 M [36EA] 36EA:87 [ 2] psha 162 M mloop 4 162 M [36EB] 36EB:F6 [ 3] lda 0,x 162 M [36EC] 36EC:87 [ 2] psha 162 M mloop 4 162 M #pull 162 M #spadd 4 162 M endm 162 M @@_?cli_ a 162 M mexit 162 M @ResizeTOS #4=#2 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 2-4 162 M @@Msg Signed 32-bit => 16-bit 162 M mexit 162 M [36ED] 36ED:A702 [ 2] ais #-:temp 162 M mexit 162 M mdo 2 162 M @@Msg Add16 162 M mexit 162 M [36EF] 36EF:CD1C 92 [ 6] call StackAdd16 162 M #spadd -2 162 M mloop :nn 162 M mexit 162 M @@Msg Abs16 162 M mexit 162 M [36F2] 36F2:CD1E 8F [ 6] call StackAbs16 162 M mexit 162 M mdo 2 162 M @@Msg Mul16 162 M mexit 162 M [36F5] 36F5:CD1D 43 [ 6] call StackMul16 162 M #spadd -2 162 M mloop :nn 162 M @@Msg Div16 162 M mexit 162 M [36F8] 36F8:CD1D 6A [ 6] call StackDiv16 162 M #spadd -2 162 M mloop :nn 162 M mexit 162 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 162 M mset 9 162 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 162 M @Save16 ans 162 M @_DoSave 16=ans 162 M mreq 1:BitSize[,Variable] 162 M mset 2,ans 162 M mtrim 2 162 M 162 M mset 9 162 M 162 M @@_not_x_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M @@ResizeTOS #2=#4 162 M mreq 1,2:#FromByteSize,#ToByteSize 162 M #temp 4-2 162 M @@Msg Signed 16-bit => 32-bit 162 M mexit 162 M [36FB] 36FB:5F [ 1] clrx 162 M [36FC] 36FC:9E6D 01 [ 5] tst 1,asp 162 M [36FF] 36FF:2A01 (3702) [ 3] bpl *+3 162 M [3701] 3701:53 [ 1] !comx 162 M [3702] 3702:89 [ 2] pshx:2 162 M [3703] 3703:89 [ 2] 162 M mexit 162 M @@_?sei_ ans 162 M mexit 162 M @@pullv ans 162 M mset #' ' 162 M mreq 1:Variable[ SizeOf(Variable)] 162 M @@_not_#_ ans 162 M mset #' ' 162 M mdel 1 162 M mtop 162 M mset #' ' 162 M mexit 162 M mdef 2,4 162 M mdef 2,1 162 M @@Msg PullV ans (32-bit) 162 M mexit 162 M #push 162 M @@lea ans 162 M mset # 162 M [3704] 3704:4501 10 [ 3] ldhx #ans 162 M endm 162 M #x 162 M mdo 162 M [3707] 3707:86 [ 3] pula 162 M [3708] 3708:F7 [ 2] sta 0,x 162 M mloop 4 162 M [3709] 3709:86 [ 3] pula 162 M [370A] 370A:E701 [ 3] sta 1,x 162 M mloop 4 162 M [370C] 370C:86 [ 3] pula 162 M [370D] 370D:E702 [ 3] sta 2,x 162 M mloop 4 162 M [370F] 370F:86 [ 3] pula 162 M [3710] 3710:E703 [ 3] sta 3,x 162 M mloop 4 162 M #pull 162 M #spadd -4 162 M endm 162 M @_?cli_ ans 162 M mexit 162 endm 163 M @Test 24 163 M ;------------------------------------------------------------------------------- 163 M ; Test the 24-bit version 163 M ;------------------------------------------------------------------------------- 163 M 163 M ;------------------------------------------------------------------------------- 163 M ; @@Load24 a 163 M ;------------------------------------------------------------------------------- 163 M @@Load24 a 163 M @_DoLoad 24,a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [3712] 3712:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [3715] 3715:E603 [ 3] lda 3,x 163 M [3717] 3717:87 [ 2] psha 163 M mloop 4 163 M [3718] 3718:E602 [ 3] lda 2,x 163 M [371A] 371A:87 [ 2] psha 163 M mloop 4 163 M [371B] 371B:E601 [ 3] lda 1,x 163 M [371D] 371D:87 [ 2] psha 163 M mloop 4 163 M [371E] 371E:F6 [ 3] lda 0,x 163 M [371F] 371F:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [3720] 3720:A701 [ 2] ais #-:temp 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Load24 b 163 M ;------------------------------------------------------------------------------- 163 M @@Load24 b 163 M @_DoLoad 24,b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [3722] 3722:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [3725] 3725:E603 [ 3] lda 3,x 163 M [3727] 3727:87 [ 2] psha 163 M mloop 4 163 M [3728] 3728:E602 [ 3] lda 2,x 163 M [372A] 372A:87 [ 2] psha 163 M mloop 4 163 M [372B] 372B:E601 [ 3] lda 1,x 163 M [372D] 372D:87 [ 2] psha 163 M mloop 4 163 M [372E] 372E:F6 [ 3] lda 0,x 163 M [372F] 372F:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [3730] 3730:A701 [ 2] ais #-:temp 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Swap24 163 M ;------------------------------------------------------------------------------- 163 M @@Swap24 163 M @_DoSwap 24 163 M [3732] 3732:CD21 80 [ 6] call StackSwap24 163 M endm 163 M ;------------------------------------------------------------------------------- 163 M ; @@Save24 ans 163 M ;------------------------------------------------------------------------------- 163 M @@Save24 ans 163 M @_DoSave 24,ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3,#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [3735] 3735:5F [ 1] clrx 163 M [3736] 3736:9E6D 01 [ 5] tst 1,asp 163 M [3739] 3739:2A01 (373C) [ 3] bpl *+3 163 M [373B] 373B:53 [ 1] !comx 163 M [373C] 373C:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [373D] 373D:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [3740] 3740:86 [ 3] pula 163 M [3741] 3741:F7 [ 2] sta 0,x 163 M mloop 4 163 M [3742] 3742:86 [ 3] pula 163 M [3743] 3743:E701 [ 3] sta 1,x 163 M mloop 4 163 M [3745] 3745:86 [ 3] pula 163 M [3746] 3746:E702 [ 3] sta 2,x 163 M mloop 4 163 M [3748] 3748:86 [ 3] pula 163 M [3749] 3749:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Save24 ans 163 M ;------------------------------------------------------------------------------- 163 M @@Save24 ans 163 M @_DoSave 24,ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3,#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [374B] 374B:5F [ 1] clrx 163 M [374C] 374C:9E6D 01 [ 5] tst 1,asp 163 M [374F] 374F:2A01 (3752) [ 3] bpl *+3 163 M [3751] 3751:53 [ 1] !comx 163 M [3752] 3752:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [3753] 3753:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [3756] 3756:86 [ 3] pula 163 M [3757] 3757:F7 [ 2] sta 0,x 163 M mloop 4 163 M [3758] 3758:86 [ 3] pula 163 M [3759] 3759:E701 [ 3] sta 1,x 163 M mloop 4 163 M [375B] 375B:86 [ 3] pula 163 M [375C] 375C:E702 [ 3] sta 2,x 163 M mloop 4 163 M [375E] 375E:86 [ 3] pula 163 M [375F] 375F:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Add24 a,b,ans 163 M ;------------------------------------------------------------------------------- 163 M @@Add24 a,b,ans 163 M @_DoMath Add24,24,a,b,ans 163 M @@Load24 b 163 M @_DoLoad 24,b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [3761] 3761:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [3764] 3764:E603 [ 3] lda 3,x 163 M [3766] 3766:87 [ 2] psha 163 M mloop 4 163 M [3767] 3767:E602 [ 3] lda 2,x 163 M [3769] 3769:87 [ 2] psha 163 M mloop 4 163 M [376A] 376A:E601 [ 3] lda 1,x 163 M [376C] 376C:87 [ 2] psha 163 M mloop 4 163 M [376D] 376D:F6 [ 3] lda 0,x 163 M [376E] 376E:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [376F] 376F:A701 [ 2] ais #-:temp 163 M mexit 163 M @@Load24 a 163 M @_DoLoad 24,a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [3771] 3771:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [3774] 3774:E603 [ 3] lda 3,x 163 M [3776] 3776:87 [ 2] psha 163 M mloop 4 163 M [3777] 3777:E602 [ 3] lda 2,x 163 M [3779] 3779:87 [ 2] psha 163 M mloop 4 163 M [377A] 377A:E601 [ 3] lda 1,x 163 M [377C] 377C:87 [ 2] psha 163 M mloop 4 163 M [377D] 377D:F6 [ 3] lda 0,x 163 M [377E] 377E:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [377F] 377F:A701 [ 2] ais #-:temp 163 M mexit 163 M @@_DoOperation Add24 163 M mdef 2,24 163 M @@Msg Add24 163 M mexit 163 M [3781] 3781:CD1F 17 [ 6] call StackAdd24 163 M #spadd -24/8 163 M endm 163 M @Save24 ans 163 M @_DoSave 24,ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3,#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [3784] 3784:5F [ 1] clrx 163 M [3785] 3785:9E6D 01 [ 5] tst 1,asp 163 M [3788] 3788:2A01 (378B) [ 3] bpl *+3 163 M [378A] 378A:53 [ 1] !comx 163 M [378B] 378B:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [378C] 378C:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [378F] 378F:86 [ 3] pula 163 M [3790] 3790:F7 [ 2] sta 0,x 163 M mloop 4 163 M [3791] 3791:86 [ 3] pula 163 M [3792] 3792:E701 [ 3] sta 1,x 163 M mloop 4 163 M [3794] 3794:86 [ 3] pula 163 M [3795] 3795:E702 [ 3] sta 2,x 163 M mloop 4 163 M [3797] 3797:86 [ 3] pula 163 M [3798] 3798:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Sub24 a,b,ans 163 M ;------------------------------------------------------------------------------- 163 M @@Sub24 a,b,ans 163 M @_DoMath Sub24,24,a,b,ans 163 M @@Load24 b 163 M @_DoLoad 24,b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [379A] 379A:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [379D] 379D:E603 [ 3] lda 3,x 163 M [379F] 379F:87 [ 2] psha 163 M mloop 4 163 M [37A0] 37A0:E602 [ 3] lda 2,x 163 M [37A2] 37A2:87 [ 2] psha 163 M mloop 4 163 M [37A3] 37A3:E601 [ 3] lda 1,x 163 M [37A5] 37A5:87 [ 2] psha 163 M mloop 4 163 M [37A6] 37A6:F6 [ 3] lda 0,x 163 M [37A7] 37A7:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [37A8] 37A8:A701 [ 2] ais #-:temp 163 M mexit 163 M @@Load24 a 163 M @_DoLoad 24,a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [37AA] 37AA:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [37AD] 37AD:E603 [ 3] lda 3,x 163 M [37AF] 37AF:87 [ 2] psha 163 M mloop 4 163 M [37B0] 37B0:E602 [ 3] lda 2,x 163 M [37B2] 37B2:87 [ 2] psha 163 M mloop 4 163 M [37B3] 37B3:E601 [ 3] lda 1,x 163 M [37B5] 37B5:87 [ 2] psha 163 M mloop 4 163 M [37B6] 37B6:F6 [ 3] lda 0,x 163 M [37B7] 37B7:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [37B8] 37B8:A701 [ 2] ais #-:temp 163 M mexit 163 M @@_DoOperation Sub24 163 M mdef 2,24 163 M @@Msg Sub24 163 M mexit 163 M [37BA] 37BA:CD1F 2D [ 6] call StackSub24 163 M #spadd -24/8 163 M endm 163 M @Save24 ans 163 M @_DoSave 24,ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3,#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [37BD] 37BD:5F [ 1] clrx 163 M [37BE] 37BE:9E6D 01 [ 5] tst 1,asp 163 M [37C1] 37C1:2A01 (37C4) [ 3] bpl *+3 163 M [37C3] 37C3:53 [ 1] !comx 163 M [37C4] 37C4:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [37C5] 37C5:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [37C8] 37C8:86 [ 3] pula 163 M [37C9] 37C9:F7 [ 2] sta 0,x 163 M mloop 4 163 M [37CA] 37CA:86 [ 3] pula 163 M [37CB] 37CB:E701 [ 3] sta 1,x 163 M mloop 4 163 M [37CD] 37CD:86 [ 3] pula 163 M [37CE] 37CE:E702 [ 3] sta 2,x 163 M mloop 4 163 M [37D0] 37D0:86 [ 3] pula 163 M [37D1] 37D1:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Mul24 a,b,ans 163 M ;------------------------------------------------------------------------------- 163 M @@Mul24 a,b,ans 163 M @_DoMath Mul24,24,a,b,ans 163 M @@Load24 b 163 M @_DoLoad 24,b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [37D3] 37D3:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [37D6] 37D6:E603 [ 3] lda 3,x 163 M [37D8] 37D8:87 [ 2] psha 163 M mloop 4 163 M [37D9] 37D9:E602 [ 3] lda 2,x 163 M [37DB] 37DB:87 [ 2] psha 163 M mloop 4 163 M [37DC] 37DC:E601 [ 3] lda 1,x 163 M [37DE] 37DE:87 [ 2] psha 163 M mloop 4 163 M [37DF] 37DF:F6 [ 3] lda 0,x 163 M [37E0] 37E0:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [37E1] 37E1:A701 [ 2] ais #-:temp 163 M mexit 163 M @@Load24 a 163 M @_DoLoad 24,a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [37E3] 37E3:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [37E6] 37E6:E603 [ 3] lda 3,x 163 M [37E8] 37E8:87 [ 2] psha 163 M mloop 4 163 M [37E9] 37E9:E602 [ 3] lda 2,x 163 M [37EB] 37EB:87 [ 2] psha 163 M mloop 4 163 M [37EC] 37EC:E601 [ 3] lda 1,x 163 M [37EE] 37EE:87 [ 2] psha 163 M mloop 4 163 M [37EF] 37EF:F6 [ 3] lda 0,x 163 M [37F0] 37F0:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [37F1] 37F1:A701 [ 2] ais #-:temp 163 M mexit 163 M @@_DoOperation Mul24 163 M mdef 2,24 163 M @@Msg Mul24 163 M mexit 163 M [37F3] 37F3:CD1F E8 [ 6] call StackMul24 163 M #spadd -24/8 163 M endm 163 M @Save24 ans 163 M @_DoSave 24,ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3,#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [37F6] 37F6:5F [ 1] clrx 163 M [37F7] 37F7:9E6D 01 [ 5] tst 1,asp 163 M [37FA] 37FA:2A01 (37FD) [ 3] bpl *+3 163 M [37FC] 37FC:53 [ 1] !comx 163 M [37FD] 37FD:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [37FE] 37FE:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [3801] 3801:86 [ 3] pula 163 M [3802] 3802:F7 [ 2] sta 0,x 163 M mloop 4 163 M [3803] 3803:86 [ 3] pula 163 M [3804] 3804:E701 [ 3] sta 1,x 163 M mloop 4 163 M [3806] 3806:86 [ 3] pula 163 M [3807] 3807:E702 [ 3] sta 2,x 163 M mloop 4 163 M [3809] 3809:86 [ 3] pula 163 M [380A] 380A:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Div24 a,b,ans 163 M ;------------------------------------------------------------------------------- 163 M @@Div24 a,b,ans 163 M @_DoMath Div24,24,a,b,ans 163 M @@Load24 b 163 M @_DoLoad 24,b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [380C] 380C:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [380F] 380F:E603 [ 3] lda 3,x 163 M [3811] 3811:87 [ 2] psha 163 M mloop 4 163 M [3812] 3812:E602 [ 3] lda 2,x 163 M [3814] 3814:87 [ 2] psha 163 M mloop 4 163 M [3815] 3815:E601 [ 3] lda 1,x 163 M [3817] 3817:87 [ 2] psha 163 M mloop 4 163 M [3818] 3818:F6 [ 3] lda 0,x 163 M [3819] 3819:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [381A] 381A:A701 [ 2] ais #-:temp 163 M mexit 163 M @@Load24 a 163 M @_DoLoad 24,a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [381C] 381C:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [381F] 381F:E603 [ 3] lda 3,x 163 M [3821] 3821:87 [ 2] psha 163 M mloop 4 163 M [3822] 3822:E602 [ 3] lda 2,x 163 M [3824] 3824:87 [ 2] psha 163 M mloop 4 163 M [3825] 3825:E601 [ 3] lda 1,x 163 M [3827] 3827:87 [ 2] psha 163 M mloop 4 163 M [3828] 3828:F6 [ 3] lda 0,x 163 M [3829] 3829:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [382A] 382A:A701 [ 2] ais #-:temp 163 M mexit 163 M @@_DoOperation Div24 163 M mdef 2,24 163 M @@Msg Div24 163 M mexit 163 M [382C] 382C:CD20 34 [ 6] call StackDiv24 163 M #spadd -24/8 163 M endm 163 M @Save24 ans 163 M @_DoSave 24,ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3,#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [382F] 382F:5F [ 1] clrx 163 M [3830] 3830:9E6D 01 [ 5] tst 1,asp 163 M [3833] 3833:2A01 (3836) [ 3] bpl *+3 163 M [3835] 3835:53 [ 1] !comx 163 M [3836] 3836:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [3837] 3837:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [383A] 383A:86 [ 3] pula 163 M [383B] 383B:F7 [ 2] sta 0,x 163 M mloop 4 163 M [383C] 383C:86 [ 3] pula 163 M [383D] 383D:E701 [ 3] sta 1,x 163 M mloop 4 163 M [383F] 383F:86 [ 3] pula 163 M [3840] 3840:E702 [ 3] sta 2,x 163 M mloop 4 163 M [3842] 3842:86 [ 3] pula 163 M [3843] 3843:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Mod24 a,b,ans 163 M ;------------------------------------------------------------------------------- 163 M @@Mod24 a,b,ans 163 M @_DoMath Mod24,24,a,b,ans 163 M @@Load24 b 163 M @_DoLoad 24,b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [3845] 3845:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [3848] 3848:E603 [ 3] lda 3,x 163 M [384A] 384A:87 [ 2] psha 163 M mloop 4 163 M [384B] 384B:E602 [ 3] lda 2,x 163 M [384D] 384D:87 [ 2] psha 163 M mloop 4 163 M [384E] 384E:E601 [ 3] lda 1,x 163 M [3850] 3850:87 [ 2] psha 163 M mloop 4 163 M [3851] 3851:F6 [ 3] lda 0,x 163 M [3852] 3852:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [3853] 3853:A701 [ 2] ais #-:temp 163 M mexit 163 M @@Load24 a 163 M @_DoLoad 24,a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [3855] 3855:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [3858] 3858:E603 [ 3] lda 3,x 163 M [385A] 385A:87 [ 2] psha 163 M mloop 4 163 M [385B] 385B:E602 [ 3] lda 2,x 163 M [385D] 385D:87 [ 2] psha 163 M mloop 4 163 M [385E] 385E:E601 [ 3] lda 1,x 163 M [3860] 3860:87 [ 2] psha 163 M mloop 4 163 M [3861] 3861:F6 [ 3] lda 0,x 163 M [3862] 3862:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [3863] 3863:A701 [ 2] ais #-:temp 163 M mexit 163 M @@_DoOperation Mod24 163 M mdef 2,24 163 M @@Msg Mod24 163 M mexit 163 M [3865] 3865:CD20 47 [ 6] call StackMod24 163 M #spadd -24/8 163 M endm 163 M @Save24 ans 163 M @_DoSave 24,ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3,#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [3868] 3868:5F [ 1] clrx 163 M [3869] 3869:9E6D 01 [ 5] tst 1,asp 163 M [386C] 386C:2A01 (386F) [ 3] bpl *+3 163 M [386E] 386E:53 [ 1] !comx 163 M [386F] 386F:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [3870] 3870:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [3873] 3873:86 [ 3] pula 163 M [3874] 3874:F7 [ 2] sta 0,x 163 M mloop 4 163 M [3875] 3875:86 [ 3] pula 163 M [3876] 3876:E701 [ 3] sta 1,x 163 M mloop 4 163 M [3878] 3878:86 [ 3] pula 163 M [3879] 3879:E702 [ 3] sta 2,x 163 M mloop 4 163 M [387B] 387B:86 [ 3] pula 163 M [387C] 387C:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 M ;------------------------------------------------------------------------------- 163 M ; @@Neg24 ans 163 M ;------------------------------------------------------------------------------- 163 M @@Neg24 ans 163 M @_DoNeg 24,ans 163 M @@Msg Neg24 ans 163 M mexit 163 M @@_FindStkMth_ 24 163 M #temp 163 M mdo 24/8 163 M #temp :mloop*8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mexit :temp 163 M mset 1,24 163 M @@Load24 ans 163 M @_DoLoad 24,ans 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ ans 163 M mexit 163 M @@pushv ans 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [387E] 387E:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [3881] 3881:E603 [ 3] lda 3,x 163 M [3883] 3883:87 [ 2] psha 163 M mloop 4 163 M [3884] 3884:E602 [ 3] lda 2,x 163 M [3886] 3886:87 [ 2] psha 163 M mloop 4 163 M [3887] 3887:E601 [ 3] lda 1,x 163 M [3889] 3889:87 [ 2] psha 163 M mloop 4 163 M [388A] 388A:F6 [ 3] lda 0,x 163 M [388B] 388B:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ ans 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [388C] 388C:A701 [ 2] ais #-:temp 163 M mexit 163 M [388E] 388E:CD21 A1 [ 6] call StackNegate24 163 M @Save24 163 M @_DoSave 24 163 M mreq 1:BitSize[,Variable] 163 M mset 2 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ 163 M mset #' ' 163 M mexit 163 M @@Msg Save24 163 M mexit 163 M @@lea 163 M mset # 163 M mexit 163 M @@_?sei_ 163 M mexit 163 M [3891] 3891:CD21 CB [ 6] call StackSave24 163 M @@_?cli_ 163 M mexit 163 M #spadd -24/8 163 M endm 163 M ;------------------------------------------------------------------------------- 163 M ; @@Abs24 ans 163 M ;------------------------------------------------------------------------------- 163 M @@Abs24 ans 163 M @_DoAbs 24,ans 163 M @@Msg Abs24 ans 163 M mexit 163 M @@_FindStkMth_ 24 163 M #temp 163 M mdo 24/8 163 M #temp :mloop*8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mexit :temp 163 M mset 1,24 163 M @@Load24 ans 163 M @_DoLoad 24,ans 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ ans 163 M mexit 163 M @@pushv ans 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [3894] 3894:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [3897] 3897:E603 [ 3] lda 3,x 163 M [3899] 3899:87 [ 2] psha 163 M mloop 4 163 M [389A] 389A:E602 [ 3] lda 2,x 163 M [389C] 389C:87 [ 2] psha 163 M mloop 4 163 M [389D] 389D:E601 [ 3] lda 1,x 163 M [389F] 389F:87 [ 2] psha 163 M mloop 4 163 M [38A0] 38A0:F6 [ 3] lda 0,x 163 M [38A1] 38A1:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ ans 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [38A2] 38A2:A701 [ 2] ais #-:temp 163 M mexit 163 M [38A4] 38A4:CD21 9C [ 6] call StackAbs24 163 M @Save24 163 M @_DoSave 24 163 M mreq 1:BitSize[,Variable] 163 M mset 2 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ 163 M mset #' ' 163 M mexit 163 M @@Msg Save24 163 M mexit 163 M @@lea 163 M mset # 163 M mexit 163 M @@_?sei_ 163 M mexit 163 M [38A7] 38A7:CD21 CB [ 6] call StackSave24 163 M @@_?cli_ 163 M mexit 163 M #spadd -24/8 163 M endm 163 M ;------------------------------------------------------------------------------- 163 M ; @@Str24 ans,String 163 M ;------------------------------------------------------------------------------- 163 M @@Str24 ans,String 163 M @_DoStr 24,ans,String 163 M @@_FindStkMth_ 24 163 M #temp 163 M mdo 24/8 163 M #temp :mloop*8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mexit :temp 163 M mset 1,24 163 M @@Load24 ans 163 M @_DoLoad 24,ans 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ ans 163 M mexit 163 M @@pushv ans 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [38AA] 38AA:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [38AD] 38AD:E603 [ 3] lda 3,x 163 M [38AF] 38AF:87 [ 2] psha 163 M mloop 4 163 M [38B0] 38B0:E602 [ 3] lda 2,x 163 M [38B2] 38B2:87 [ 2] psha 163 M mloop 4 163 M [38B3] 38B3:E601 [ 3] lda 1,x 163 M [38B5] 38B5:87 [ 2] psha 163 M mloop 4 163 M [38B6] 38B6:F6 [ 3] lda 0,x 163 M [38B7] 38B7:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ ans 163 M mexit 163 M @ResizeTOS #4,#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [38B8] 38B8:A701 [ 2] ais #-:temp 163 M mexit 163 M @@Msg Convert 'ans' (32-bit) to ASCIZ in 'String' 163 M mexit 163 M @@lea String 163 M mset # 163 M [38BA] 38BA:4501 18 [ 3] ldhx #String 163 M endm 163 M [38BD] 38BD:CD21 EB [ 6] call Stack24ToASCIZ 163 M [38C0] 38C0:A703 [ 2] ais #24/8 163 M endm 163 M ;------------------------------------------------------------------------------- 163 M ; @@Eval24 ans = (a + b) * abs(a - b) / 2 163 M ;------------------------------------------------------------------------------- 163 M @@Eval24 ans = abs(a + b) * abs(a - b) / 2 163 M mset # 163 M @_Eval_ 24,ans = abs(a + b) * abs(a - b) / 2 163 M @@_needs_spauto_ 163 M mexit 163 M mdef 1,32 163 M mswap 0,1 163 M mdel 1 163 M mset # 163 M @@Msg -------------------------------------------------- 163 M mexit 163 M @@Msg Expr: ans = abs(a + b) * abs(a - b) / 2 163 M mexit 163 M @@Msg -------------------------------------------------- 163 M mexit 163 M @@_FindStkMth_ 24 163 M #temp 163 M mdo 24/8 163 M #temp :mloop*8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mloop 8 163 M mexit :temp 163 M mset 0,24,24 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M mtrim 1 163 M mset #'=' 163 M @@_Eval_ abs(a+b)*abs(a-b)/2 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M mdo 2 163 M @@_Eval_ 2 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M 163 M 163 M 163 M 163 M 163 M mset 9 163 M 163 M mset 1,#2 163 M mset 1,#2 163 M @Load24 #2 163 M @_DoLoad 24=#2 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ #2 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M mset 1,#2 163 M @@Msg Load24 #2 163 M mexit 163 M mset 1,2 163 M mset 0 163 M mdo 163 M [38C2] 38C2:AE02 [ 2] ldx #2>0&$FF 163 M [38C4] 38C4:89 [ 2] pshx 163 M mloop :temp 163 M [38C5] 38C5:8C [ 1] clrh 163 M mset 0,clrh 163 M [38C6] 38C6:8B [ 2] pshh 163 M mloop :temp 163 M [38C7] 38C7:8B [ 2] pshh 163 M mloop :temp 163 M mexit 163 M mloop :nn 163 M @@_Eval_ abs(a-b) 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M 163 M 163 M @@_Eval_ a-b 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M mdo 2 163 M @@_Eval_ b 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M 163 M 163 M 163 M 163 M 163 M mset 9 163 M 163 M @Load24 b 163 M @_DoLoad 24=b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [38C8] 38C8:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [38CB] 38CB:E603 [ 3] lda 3,x 163 M [38CD] 38CD:87 [ 2] psha 163 M mloop 4 163 M [38CE] 38CE:E602 [ 3] lda 2,x 163 M [38D0] 38D0:87 [ 2] psha 163 M mloop 4 163 M [38D1] 38D1:E601 [ 3] lda 1,x 163 M [38D3] 38D3:87 [ 2] psha 163 M mloop 4 163 M [38D4] 38D4:F6 [ 3] lda 0,x 163 M [38D5] 38D5:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4=#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [38D6] 38D6:A701 [ 2] ais #-:temp 163 M mexit 163 M mloop :nn 163 M @@_Eval_ a 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M 163 M 163 M 163 M 163 M 163 M mset 9 163 M 163 M @Load24 a 163 M @_DoLoad 24=a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [38D8] 38D8:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [38DB] 38DB:E603 [ 3] lda 3,x 163 M [38DD] 38DD:87 [ 2] psha 163 M mloop 4 163 M [38DE] 38DE:E602 [ 3] lda 2,x 163 M [38E0] 38E0:87 [ 2] psha 163 M mloop 4 163 M [38E1] 38E1:E601 [ 3] lda 1,x 163 M [38E3] 38E3:87 [ 2] psha 163 M mloop 4 163 M [38E4] 38E4:F6 [ 3] lda 0,x 163 M [38E5] 38E5:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4=#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [38E6] 38E6:A701 [ 2] ais #-:temp 163 M mexit 163 M mdo 2 163 M @@Msg Sub24 163 M mexit 163 M [38E8] 38E8:CD1F 2D [ 6] call StackSub24 163 M #spadd -3 163 M mloop :nn 163 M mexit 163 M @@Msg Abs24 163 M mexit 163 M [38EB] 38EB:CD21 9C [ 6] call StackAbs24 163 M mexit 163 M mloop :nn 163 M @@_Eval_ abs(a+b) 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M 163 M 163 M @@_Eval_ a+b 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M mdo 2 163 M @@_Eval_ b 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M 163 M 163 M 163 M 163 M 163 M mset 9 163 M 163 M @Load24 b 163 M @_DoLoad 24=b 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ b 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ b 163 M mexit 163 M @@pushv b 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV b (32-bit) 163 M mexit 163 M #push 163 M @@lea b 163 M mset # 163 M [38EE] 38EE:4501 08 [ 3] ldhx #b 163 M endm 163 M #x 163 M mdo 163 M [38F1] 38F1:E603 [ 3] lda 3,x 163 M [38F3] 38F3:87 [ 2] psha 163 M mloop 4 163 M [38F4] 38F4:E602 [ 3] lda 2,x 163 M [38F6] 38F6:87 [ 2] psha 163 M mloop 4 163 M [38F7] 38F7:E601 [ 3] lda 1,x 163 M [38F9] 38F9:87 [ 2] psha 163 M mloop 4 163 M [38FA] 38FA:F6 [ 3] lda 0,x 163 M [38FB] 38FB:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ b 163 M mexit 163 M @ResizeTOS #4=#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [38FC] 38FC:A701 [ 2] ais #-:temp 163 M mexit 163 M mloop :nn 163 M @@_Eval_ a 163 M mset # 163 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 163 M 163 M 163 M 163 M 163 M mset #'+-|^' 163 M 163 M mset #'*\/&><' 163 M 163 M 163 M 163 M 163 M 163 M mset 9 163 M 163 M @Load24 a 163 M @_DoLoad 24=a 163 M mreq 1:BitSize[,Variable] 163 M #temp 24/8 163 M mdel 1 163 M mset # 163 M mtrim 1 163 M 163 M mset 9 163 M 163 M @@_not_x_ a 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M 163 M 163 M @@_?sei_ a 163 M mexit 163 M @@pushv a 163 M mset #' ' 163 M mset 0 163 M mreq 1:variable[ SizeOf(var)][ 'newname'] 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PushV a (32-bit) 163 M mexit 163 M #push 163 M @@lea a 163 M mset # 163 M [38FE] 38FE:4501 00 [ 3] ldhx #a 163 M endm 163 M #x 163 M mdo 163 M [3901] 3901:E603 [ 3] lda 3,x 163 M [3903] 3903:87 [ 2] psha 163 M mloop 4 163 M [3904] 3904:E602 [ 3] lda 2,x 163 M [3906] 3906:87 [ 2] psha 163 M mloop 4 163 M [3907] 3907:E601 [ 3] lda 1,x 163 M [3909] 3909:87 [ 2] psha 163 M mloop 4 163 M [390A] 390A:F6 [ 3] lda 0,x 163 M [390B] 390B:87 [ 2] psha 163 M mloop 4 163 M #pull 163 M #spadd 4 163 M endm 163 M @@_?cli_ a 163 M mexit 163 M @ResizeTOS #4=#3 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 3-4 163 M @@Msg Signed 32-bit => 24-bit 163 M mexit 163 M [390C] 390C:A701 [ 2] ais #-:temp 163 M mexit 163 M mdo 2 163 M @@Msg Add24 163 M mexit 163 M [390E] 390E:CD1F 17 [ 6] call StackAdd24 163 M #spadd -3 163 M mloop :nn 163 M mexit 163 M @@Msg Abs24 163 M mexit 163 M [3911] 3911:CD21 9C [ 6] call StackAbs24 163 M mexit 163 M mdo 2 163 M @@Msg Mul24 163 M mexit 163 M [3914] 3914:CD1F E8 [ 6] call StackMul24 163 M #spadd -3 163 M mloop :nn 163 M @@Msg Div24 163 M mexit 163 M [3917] 3917:CD20 34 [ 6] call StackDiv24 163 M #spadd -3 163 M mloop :nn 163 M mexit 163 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 163 M mset 9 163 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 163 M @Save24 ans 163 M @_DoSave 24=ans 163 M mreq 1:BitSize[,Variable] 163 M mset 2,ans 163 M mtrim 2 163 M 163 M mset 9 163 M 163 M @@_not_x_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M @@ResizeTOS #3=#4 163 M mreq 1,2:#FromByteSize,#ToByteSize 163 M #temp 4-3 163 M @@Msg Signed 24-bit => 32-bit 163 M mexit 163 M [391A] 391A:5F [ 1] clrx 163 M [391B] 391B:9E6D 01 [ 5] tst 1,asp 163 M [391E] 391E:2A01 (3921) [ 3] bpl *+3 163 M [3920] 3920:53 [ 1] !comx 163 M [3921] 3921:89 [ 2] pshx:1 163 M mexit 163 M @@_?sei_ ans 163 M mexit 163 M @@pullv ans 163 M mset #' ' 163 M mreq 1:Variable[ SizeOf(Variable)] 163 M @@_not_#_ ans 163 M mset #' ' 163 M mdel 1 163 M mtop 163 M mset #' ' 163 M mexit 163 M mdef 2,4 163 M mdef 2,1 163 M @@Msg PullV ans (32-bit) 163 M mexit 163 M #push 163 M @@lea ans 163 M mset # 163 M [3922] 3922:4501 10 [ 3] ldhx #ans 163 M endm 163 M #x 163 M mdo 163 M [3925] 3925:86 [ 3] pula 163 M [3926] 3926:F7 [ 2] sta 0,x 163 M mloop 4 163 M [3927] 3927:86 [ 3] pula 163 M [3928] 3928:E701 [ 3] sta 1,x 163 M mloop 4 163 M [392A] 392A:86 [ 3] pula 163 M [392B] 392B:E702 [ 3] sta 2,x 163 M mloop 4 163 M [392D] 392D:86 [ 3] pula 163 M [392E] 392E:E703 [ 3] sta 3,x 163 M mloop 4 163 M #pull 163 M #spadd -4 163 M endm 163 M @_?cli_ ans 163 M mexit 163 endm 164 M @Test 32 164 M ;------------------------------------------------------------------------------- 164 M ; Test the 32-bit version 164 M ;------------------------------------------------------------------------------- 164 M 164 M ;------------------------------------------------------------------------------- 164 M ; @@Load32 a 164 M ;------------------------------------------------------------------------------- 164 M @@Load32 a 164 M @_DoLoad 32,a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [3930] 3930:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [3933] 3933:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Load32 b 164 M ;------------------------------------------------------------------------------- 164 M @@Load32 b 164 M @_DoLoad 32,b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [3936] 3936:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [3939] 3939:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Swap32 164 M ;------------------------------------------------------------------------------- 164 M @@Swap32 164 M @_DoSwap 32 164 M [393C] 393C:CD1B 82 [ 6] call StackSwap32 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Save32 ans 164 M ;------------------------------------------------------------------------------- 164 M @@Save32 ans 164 M @_DoSave 32,ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [393F] 393F:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [3942] 3942:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Save32 ans 164 M ;------------------------------------------------------------------------------- 164 M @@Save32 ans 164 M @_DoSave 32,ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [3945] 3945:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [3948] 3948:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Add32 a,b,ans 164 M ;------------------------------------------------------------------------------- 164 M @@Add32 a,b,ans 164 M @_DoMath Add32,32,a,b,ans 164 M @@Load32 b 164 M @_DoLoad 32,b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [394B] 394B:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [394E] 394E:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@Load32 a 164 M @_DoLoad 32,a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [3951] 3951:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [3954] 3954:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@_DoOperation Add32 164 M mdef 2,32 164 M @@Msg Add32 164 M mexit 164 M [3957] 3957:CD18 8D [ 6] call StackAdd32 164 M #spadd -32/8 164 M endm 164 M @Save32 ans 164 M @_DoSave 32,ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [395A] 395A:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [395D] 395D:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Sub32 a,b,ans 164 M ;------------------------------------------------------------------------------- 164 M @@Sub32 a,b,ans 164 M @_DoMath Sub32,32,a,b,ans 164 M @@Load32 b 164 M @_DoLoad 32,b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [3960] 3960:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [3963] 3963:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@Load32 a 164 M @_DoLoad 32,a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [3966] 3966:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [3969] 3969:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@_DoOperation Sub32 164 M mdef 2,32 164 M @@Msg Sub32 164 M mexit 164 M [396C] 396C:CD18 A3 [ 6] call StackSub32 164 M #spadd -32/8 164 M endm 164 M @Save32 ans 164 M @_DoSave 32,ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [396F] 396F:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [3972] 3972:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Mul32 a,b,ans 164 M ;------------------------------------------------------------------------------- 164 M @@Mul32 a,b,ans 164 M @_DoMath Mul32,32,a,b,ans 164 M @@Load32 b 164 M @_DoLoad 32,b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [3975] 3975:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [3978] 3978:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@Load32 a 164 M @_DoLoad 32,a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [397B] 397B:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [397E] 397E:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@_DoOperation Mul32 164 M mdef 2,32 164 M @@Msg Mul32 164 M mexit 164 M [3981] 3981:CD19 72 [ 6] call StackMul32 164 M #spadd -32/8 164 M endm 164 M @Save32 ans 164 M @_DoSave 32,ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [3984] 3984:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [3987] 3987:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Div32 a,b,ans 164 M ;------------------------------------------------------------------------------- 164 M @@Div32 a,b,ans 164 M @_DoMath Div32,32,a,b,ans 164 M @@Load32 b 164 M @_DoLoad 32,b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [398A] 398A:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [398D] 398D:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@Load32 a 164 M @_DoLoad 32,a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [3990] 3990:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [3993] 3993:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@_DoOperation Div32 164 M mdef 2,32 164 M @@Msg Div32 164 M mexit 164 M [3996] 3996:CD19 F4 [ 6] call StackDiv32 164 M #spadd -32/8 164 M endm 164 M @Save32 ans 164 M @_DoSave 32,ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [3999] 3999:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [399C] 399C:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Mod32 a,b,ans 164 M ;------------------------------------------------------------------------------- 164 M @@Mod32 a,b,ans 164 M @_DoMath Mod32,32,a,b,ans 164 M @@Load32 b 164 M @_DoLoad 32,b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [399F] 399F:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [39A2] 39A2:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@Load32 a 164 M @_DoLoad 32,a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [39A5] 39A5:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [39A8] 39A8:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@_DoOperation Mod32 164 M mdef 2,32 164 M @@Msg Mod32 164 M mexit 164 M [39AB] 39AB:CD1A 07 [ 6] call StackMod32 164 M #spadd -32/8 164 M endm 164 M @Save32 ans 164 M @_DoSave 32,ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [39AE] 39AE:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [39B1] 39B1:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Neg32 ans 164 M ;------------------------------------------------------------------------------- 164 M @@Neg32 ans 164 M @_DoNeg 32,ans 164 M @@Msg Neg32 ans 164 M mexit 164 M @@_FindStkMth_ 32 164 M #temp 164 M mdo 32/8 164 M #temp :mloop*8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mexit :temp 164 M mset 1,32 164 M @@Load32 ans 164 M @_DoLoad 32,ans 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [39B4] 39B4:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [39B7] 39B7:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd :temp 164 M endm 164 M [39BA] 39BA:CD1B A3 [ 6] call StackNegate32 164 M @Save32 164 M @_DoSave 32 164 M mreq 1:BitSize[,Variable] 164 M mset 2 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 164 M mexit 164 M @@lea 164 M mset # 164 M mexit 164 M @@_?sei_ 164 M mexit 164 M [39BD] 39BD:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Abs32 ans 164 M ;------------------------------------------------------------------------------- 164 M @@Abs32 ans 164 M @_DoAbs 32,ans 164 M @@Msg Abs32 ans 164 M mexit 164 M @@_FindStkMth_ 32 164 M #temp 164 M mdo 32/8 164 M #temp :mloop*8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mexit :temp 164 M mset 1,32 164 M @@Load32 ans 164 M @_DoLoad 32,ans 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [39C0] 39C0:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [39C3] 39C3:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd :temp 164 M endm 164 M [39C6] 39C6:CD1B 9E [ 6] call StackAbs32 164 M @Save32 164 M @_DoSave 32 164 M mreq 1:BitSize[,Variable] 164 M mset 2 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 164 M mexit 164 M @@lea 164 M mset # 164 M mexit 164 M @@_?sei_ 164 M mexit 164 M [39C9] 39C9:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ 164 M mexit 164 M #spadd -32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Str32 ans,String 164 M ;------------------------------------------------------------------------------- 164 M @@Str32 ans,String 164 M @_DoStr 32,ans,String 164 M @@_FindStkMth_ 32 164 M #temp 164 M mdo 32/8 164 M #temp :mloop*8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mexit :temp 164 M mset 1,32 164 M @@Load32 ans 164 M @_DoLoad 32,ans 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [39CC] 39CC:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [39CF] 39CF:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd :temp 164 M endm 164 M @@Msg Convert 'ans' (32-bit) to ASCIZ in 'String' 164 M mexit 164 M @@lea String 164 M mset # 164 M [39D2] 39D2:4501 18 [ 3] ldhx #String 164 M endm 164 M [39D5] 39D5:CD1C 3D [ 6] call Stack32ToASCIZ 164 M [39D8] 39D8:A704 [ 2] ais #32/8 164 M endm 164 M ;------------------------------------------------------------------------------- 164 M ; @@Eval32 ans = (a + b) * abs(a - b) / 2 164 M ;------------------------------------------------------------------------------- 164 M @@Eval32 ans = abs(a + b) * abs(a - b) / 2 164 M mset # 164 M @_Eval_ 32,ans = abs(a + b) * abs(a - b) / 2 164 M @@_needs_spauto_ 164 M mexit 164 M mdef 1,32 164 M mswap 0,1 164 M mdel 1 164 M mset # 164 M @@Msg -------------------------------------------------- 164 M mexit 164 M @@Msg Expr: ans = abs(a + b) * abs(a - b) / 2 164 M mexit 164 M @@Msg -------------------------------------------------- 164 M mexit 164 M @@_FindStkMth_ 32 164 M #temp 164 M mdo 32/8 164 M #temp :mloop*8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mloop 8 164 M mexit :temp 164 M mset 0,32,32 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M mtrim 1 164 M mset #'=' 164 M @@_Eval_ abs(a+b)*abs(a-b)/2 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M mdo 2 164 M @@_Eval_ 2 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M 164 M 164 M 164 M 164 M 164 M mset 9 164 M 164 M mset 1,#2 164 M mset 1,#2 164 M @Load32 #2 164 M @_DoLoad 32=#2 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ #2 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M mset 1,#2 164 M @@Msg Load32 #2 164 M mexit 164 M mset 1,2 164 M mset 0 164 M mdo 164 M [39DA] 39DA:AE02 [ 2] ldx #2>0&$FF 164 M [39DC] 39DC:89 [ 2] pshx 164 M mloop :temp 164 M [39DD] 39DD:8C [ 1] clrh 164 M mset 0,clrh 164 M [39DE] 39DE:8B [ 2] pshh 164 M mloop :temp 164 M [39DF] 39DF:8B [ 2] pshh 164 M mloop :temp 164 M [39E0] 39E0:8B [ 2] pshh 164 M mloop :temp 164 M mexit 164 M mloop :nn 164 M @@_Eval_ abs(a-b) 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M 164 M 164 M @@_Eval_ a-b 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M mdo 2 164 M @@_Eval_ b 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M 164 M 164 M 164 M 164 M 164 M mset 9 164 M 164 M @Load32 b 164 M @_DoLoad 32=b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [39E1] 39E1:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [39E4] 39E4:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M mloop :nn 164 M @@_Eval_ a 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M 164 M 164 M 164 M 164 M 164 M mset 9 164 M 164 M @Load32 a 164 M @_DoLoad 32=a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [39E7] 39E7:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [39EA] 39EA:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M mdo 2 164 M @@Msg Sub32 164 M mexit 164 M [39ED] 39ED:CD18 A3 [ 6] call StackSub32 164 M #spadd -4 164 M mloop :nn 164 M mexit 164 M @@Msg Abs32 164 M mexit 164 M [39F0] 39F0:CD1B 9E [ 6] call StackAbs32 164 M mexit 164 M mloop :nn 164 M @@_Eval_ abs(a+b) 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M 164 M 164 M @@_Eval_ a+b 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M mdo 2 164 M @@_Eval_ b 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M 164 M 164 M 164 M 164 M 164 M mset 9 164 M 164 M @Load32 b 164 M @_DoLoad 32=b 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ b 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 b 164 M mexit 164 M @@lea b 164 M mset # 164 M [39F3] 39F3:4501 08 [ 3] ldhx #b 164 M endm 164 M @@_?sei_ b 164 M mexit 164 M [39F6] 39F6:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ b 164 M mexit 164 M #spadd :temp 164 M endm 164 M mloop :nn 164 M @@_Eval_ a 164 M mset # 164 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 164 M 164 M 164 M 164 M 164 M mset #'+-|^' 164 M 164 M mset #'*\/&><' 164 M 164 M 164 M 164 M 164 M 164 M mset 9 164 M 164 M @Load32 a 164 M @_DoLoad 32=a 164 M mreq 1:BitSize[,Variable] 164 M #temp 32/8 164 M mdel 1 164 M mset # 164 M mtrim 1 164 M 164 M mset 9 164 M 164 M @@_not_x_ a 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M 164 M 164 M 164 M @@Msg Load32 a 164 M mexit 164 M @@lea a 164 M mset # 164 M [39F9] 39F9:4501 00 [ 3] ldhx #a 164 M endm 164 M @@_?sei_ a 164 M mexit 164 M [39FC] 39FC:CD1B AE [ 6] call StackLoad32 164 M @@_?cli_ a 164 M mexit 164 M #spadd :temp 164 M endm 164 M mdo 2 164 M @@Msg Add32 164 M mexit 164 M [39FF] 39FF:CD18 8D [ 6] call StackAdd32 164 M #spadd -4 164 M mloop :nn 164 M mexit 164 M @@Msg Abs32 164 M mexit 164 M [3A02] 3A02:CD1B 9E [ 6] call StackAbs32 164 M mexit 164 M mdo 2 164 M @@Msg Mul32 164 M mexit 164 M [3A05] 3A05:CD19 72 [ 6] call StackMul32 164 M #spadd -4 164 M mloop :nn 164 M @@Msg Div32 164 M mexit 164 M [3A08] 3A08:CD19 F4 [ 6] call StackDiv32 164 M #spadd -4 164 M mloop :nn 164 M mexit 164 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 164 M mset 9 164 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 164 M @Save32 ans 164 M @_DoSave 32=ans 164 M mreq 1:BitSize[,Variable] 164 M mset 2,ans 164 M mtrim 2 164 M 164 M mset 9 164 M 164 M @@_not_x_ ans 164 M mset #' ' 164 M mdel 1 164 M mtop 164 M mset #' ' 164 M mexit 164 M @@Msg Save32 ans 164 M mexit 164 M @@lea ans 164 M mset # 164 M [3A0B] 3A0B:4501 10 [ 3] ldhx #ans 164 M endm 164 M @@_?sei_ ans 164 M mexit 164 M [3A0E] 3A0E:CD1B D2 [ 6] call StackSave32 164 M @@_?cli_ ans 164 M mexit 164 M #spadd -32/8 164 M endm 164 endm 165 M @Test 40 165 M ;------------------------------------------------------------------------------- 165 M ; Test the 40-bit version 165 M ;------------------------------------------------------------------------------- 165 M 165 M ;------------------------------------------------------------------------------- 165 M ; @@Load40 a 165 M ;------------------------------------------------------------------------------- 165 M @@Load40 a 165 M @_DoLoad 40,a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3A11] 3A11:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3A14] 3A14:E603 [ 3] lda 3,x 165 M [3A16] 3A16:87 [ 2] psha 165 M mloop 4 165 M [3A17] 3A17:E602 [ 3] lda 2,x 165 M [3A19] 3A19:87 [ 2] psha 165 M mloop 4 165 M [3A1A] 3A1A:E601 [ 3] lda 1,x 165 M [3A1C] 3A1C:87 [ 2] psha 165 M mloop 4 165 M [3A1D] 3A1D:F6 [ 3] lda 0,x 165 M [3A1E] 3A1E:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3A1F] 3A1F:5F [ 1] clrx 165 M [3A20] 3A20:9E6D 01 [ 5] tst 1,asp 165 M [3A23] 3A23:2A01 (3A26) [ 3] bpl *+3 165 M [3A25] 3A25:53 [ 1] !comx 165 M [3A26] 3A26:89 [ 2] pshx:1 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Load40 b 165 M ;------------------------------------------------------------------------------- 165 M @@Load40 b 165 M @_DoLoad 40,b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3A27] 3A27:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3A2A] 3A2A:E603 [ 3] lda 3,x 165 M [3A2C] 3A2C:87 [ 2] psha 165 M mloop 4 165 M [3A2D] 3A2D:E602 [ 3] lda 2,x 165 M [3A2F] 3A2F:87 [ 2] psha 165 M mloop 4 165 M [3A30] 3A30:E601 [ 3] lda 1,x 165 M [3A32] 3A32:87 [ 2] psha 165 M mloop 4 165 M [3A33] 3A33:F6 [ 3] lda 0,x 165 M [3A34] 3A34:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3A35] 3A35:5F [ 1] clrx 165 M [3A36] 3A36:9E6D 01 [ 5] tst 1,asp 165 M [3A39] 3A39:2A01 (3A3C) [ 3] bpl *+3 165 M [3A3B] 3A3B:53 [ 1] !comx 165 M [3A3C] 3A3C:89 [ 2] pshx:1 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Swap40 165 M ;------------------------------------------------------------------------------- 165 M @@Swap40 165 M @_DoSwap 40 165 M [3A3D] 3A3D:CD25 4F [ 6] call StackSwap40 165 M endm 165 M ;------------------------------------------------------------------------------- 165 M ; @@Save40 ans 165 M ;------------------------------------------------------------------------------- 165 M @@Save40 ans 165 M @_DoSave 40,ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5,#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3A40] 3A40:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3A42] 3A42:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3A45] 3A45:86 [ 3] pula 165 M [3A46] 3A46:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3A47] 3A47:86 [ 3] pula 165 M [3A48] 3A48:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3A4A] 3A4A:86 [ 3] pula 165 M [3A4B] 3A4B:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3A4D] 3A4D:86 [ 3] pula 165 M [3A4E] 3A4E:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Save40 ans 165 M ;------------------------------------------------------------------------------- 165 M @@Save40 ans 165 M @_DoSave 40,ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5,#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3A50] 3A50:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3A52] 3A52:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3A55] 3A55:86 [ 3] pula 165 M [3A56] 3A56:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3A57] 3A57:86 [ 3] pula 165 M [3A58] 3A58:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3A5A] 3A5A:86 [ 3] pula 165 M [3A5B] 3A5B:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3A5D] 3A5D:86 [ 3] pula 165 M [3A5E] 3A5E:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Add40 a,b,ans 165 M ;------------------------------------------------------------------------------- 165 M @@Add40 a,b,ans 165 M @_DoMath Add40,40,a,b,ans 165 M @@Load40 b 165 M @_DoLoad 40,b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3A60] 3A60:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3A63] 3A63:E603 [ 3] lda 3,x 165 M [3A65] 3A65:87 [ 2] psha 165 M mloop 4 165 M [3A66] 3A66:E602 [ 3] lda 2,x 165 M [3A68] 3A68:87 [ 2] psha 165 M mloop 4 165 M [3A69] 3A69:E601 [ 3] lda 1,x 165 M [3A6B] 3A6B:87 [ 2] psha 165 M mloop 4 165 M [3A6C] 3A6C:F6 [ 3] lda 0,x 165 M [3A6D] 3A6D:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3A6E] 3A6E:5F [ 1] clrx 165 M [3A6F] 3A6F:9E6D 01 [ 5] tst 1,asp 165 M [3A72] 3A72:2A01 (3A75) [ 3] bpl *+3 165 M [3A74] 3A74:53 [ 1] !comx 165 M [3A75] 3A75:89 [ 2] pshx:1 165 M mexit 165 M @@Load40 a 165 M @_DoLoad 40,a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3A76] 3A76:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3A79] 3A79:E603 [ 3] lda 3,x 165 M [3A7B] 3A7B:87 [ 2] psha 165 M mloop 4 165 M [3A7C] 3A7C:E602 [ 3] lda 2,x 165 M [3A7E] 3A7E:87 [ 2] psha 165 M mloop 4 165 M [3A7F] 3A7F:E601 [ 3] lda 1,x 165 M [3A81] 3A81:87 [ 2] psha 165 M mloop 4 165 M [3A82] 3A82:F6 [ 3] lda 0,x 165 M [3A83] 3A83:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3A84] 3A84:5F [ 1] clrx 165 M [3A85] 3A85:9E6D 01 [ 5] tst 1,asp 165 M [3A88] 3A88:2A01 (3A8B) [ 3] bpl *+3 165 M [3A8A] 3A8A:53 [ 1] !comx 165 M [3A8B] 3A8B:89 [ 2] pshx:1 165 M mexit 165 M @@_DoOperation Add40 165 M mdef 2,40 165 M @@Msg Add40 165 M mexit 165 M [3A8C] 3A8C:CD22 37 [ 6] call StackAdd40 165 M #spadd -40/8 165 M endm 165 M @Save40 ans 165 M @_DoSave 40,ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5,#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3A8F] 3A8F:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3A91] 3A91:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3A94] 3A94:86 [ 3] pula 165 M [3A95] 3A95:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3A96] 3A96:86 [ 3] pula 165 M [3A97] 3A97:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3A99] 3A99:86 [ 3] pula 165 M [3A9A] 3A9A:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3A9C] 3A9C:86 [ 3] pula 165 M [3A9D] 3A9D:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Sub40 a,b,ans 165 M ;------------------------------------------------------------------------------- 165 M @@Sub40 a,b,ans 165 M @_DoMath Sub40,40,a,b,ans 165 M @@Load40 b 165 M @_DoLoad 40,b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3A9F] 3A9F:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3AA2] 3AA2:E603 [ 3] lda 3,x 165 M [3AA4] 3AA4:87 [ 2] psha 165 M mloop 4 165 M [3AA5] 3AA5:E602 [ 3] lda 2,x 165 M [3AA7] 3AA7:87 [ 2] psha 165 M mloop 4 165 M [3AA8] 3AA8:E601 [ 3] lda 1,x 165 M [3AAA] 3AAA:87 [ 2] psha 165 M mloop 4 165 M [3AAB] 3AAB:F6 [ 3] lda 0,x 165 M [3AAC] 3AAC:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3AAD] 3AAD:5F [ 1] clrx 165 M [3AAE] 3AAE:9E6D 01 [ 5] tst 1,asp 165 M [3AB1] 3AB1:2A01 (3AB4) [ 3] bpl *+3 165 M [3AB3] 3AB3:53 [ 1] !comx 165 M [3AB4] 3AB4:89 [ 2] pshx:1 165 M mexit 165 M @@Load40 a 165 M @_DoLoad 40,a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3AB5] 3AB5:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3AB8] 3AB8:E603 [ 3] lda 3,x 165 M [3ABA] 3ABA:87 [ 2] psha 165 M mloop 4 165 M [3ABB] 3ABB:E602 [ 3] lda 2,x 165 M [3ABD] 3ABD:87 [ 2] psha 165 M mloop 4 165 M [3ABE] 3ABE:E601 [ 3] lda 1,x 165 M [3AC0] 3AC0:87 [ 2] psha 165 M mloop 4 165 M [3AC1] 3AC1:F6 [ 3] lda 0,x 165 M [3AC2] 3AC2:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3AC3] 3AC3:5F [ 1] clrx 165 M [3AC4] 3AC4:9E6D 01 [ 5] tst 1,asp 165 M [3AC7] 3AC7:2A01 (3ACA) [ 3] bpl *+3 165 M [3AC9] 3AC9:53 [ 1] !comx 165 M [3ACA] 3ACA:89 [ 2] pshx:1 165 M mexit 165 M @@_DoOperation Sub40 165 M mdef 2,40 165 M @@Msg Sub40 165 M mexit 165 M [3ACB] 3ACB:CD22 4D [ 6] call StackSub40 165 M #spadd -40/8 165 M endm 165 M @Save40 ans 165 M @_DoSave 40,ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5,#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3ACE] 3ACE:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3AD0] 3AD0:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3AD3] 3AD3:86 [ 3] pula 165 M [3AD4] 3AD4:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3AD5] 3AD5:86 [ 3] pula 165 M [3AD6] 3AD6:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3AD8] 3AD8:86 [ 3] pula 165 M [3AD9] 3AD9:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3ADB] 3ADB:86 [ 3] pula 165 M [3ADC] 3ADC:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Mul40 a,b,ans 165 M ;------------------------------------------------------------------------------- 165 M @@Mul40 a,b,ans 165 M @_DoMath Mul40,40,a,b,ans 165 M @@Load40 b 165 M @_DoLoad 40,b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3ADE] 3ADE:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3AE1] 3AE1:E603 [ 3] lda 3,x 165 M [3AE3] 3AE3:87 [ 2] psha 165 M mloop 4 165 M [3AE4] 3AE4:E602 [ 3] lda 2,x 165 M [3AE6] 3AE6:87 [ 2] psha 165 M mloop 4 165 M [3AE7] 3AE7:E601 [ 3] lda 1,x 165 M [3AE9] 3AE9:87 [ 2] psha 165 M mloop 4 165 M [3AEA] 3AEA:F6 [ 3] lda 0,x 165 M [3AEB] 3AEB:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3AEC] 3AEC:5F [ 1] clrx 165 M [3AED] 3AED:9E6D 01 [ 5] tst 1,asp 165 M [3AF0] 3AF0:2A01 (3AF3) [ 3] bpl *+3 165 M [3AF2] 3AF2:53 [ 1] !comx 165 M [3AF3] 3AF3:89 [ 2] pshx:1 165 M mexit 165 M @@Load40 a 165 M @_DoLoad 40,a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3AF4] 3AF4:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3AF7] 3AF7:E603 [ 3] lda 3,x 165 M [3AF9] 3AF9:87 [ 2] psha 165 M mloop 4 165 M [3AFA] 3AFA:E602 [ 3] lda 2,x 165 M [3AFC] 3AFC:87 [ 2] psha 165 M mloop 4 165 M [3AFD] 3AFD:E601 [ 3] lda 1,x 165 M [3AFF] 3AFF:87 [ 2] psha 165 M mloop 4 165 M [3B00] 3B00:F6 [ 3] lda 0,x 165 M [3B01] 3B01:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3B02] 3B02:5F [ 1] clrx 165 M [3B03] 3B03:9E6D 01 [ 5] tst 1,asp 165 M [3B06] 3B06:2A01 (3B09) [ 3] bpl *+3 165 M [3B08] 3B08:53 [ 1] !comx 165 M [3B09] 3B09:89 [ 2] pshx:1 165 M mexit 165 M @@_DoOperation Mul40 165 M mdef 2,40 165 M @@Msg Mul40 165 M mexit 165 M [3B0A] 3B0A:CD23 30 [ 6] call StackMul40 165 M #spadd -40/8 165 M endm 165 M @Save40 ans 165 M @_DoSave 40,ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5,#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3B0D] 3B0D:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3B0F] 3B0F:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3B12] 3B12:86 [ 3] pula 165 M [3B13] 3B13:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3B14] 3B14:86 [ 3] pula 165 M [3B15] 3B15:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3B17] 3B17:86 [ 3] pula 165 M [3B18] 3B18:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3B1A] 3B1A:86 [ 3] pula 165 M [3B1B] 3B1B:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Div40 a,b,ans 165 M ;------------------------------------------------------------------------------- 165 M @@Div40 a,b,ans 165 M @_DoMath Div40,40,a,b,ans 165 M @@Load40 b 165 M @_DoLoad 40,b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3B1D] 3B1D:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3B20] 3B20:E603 [ 3] lda 3,x 165 M [3B22] 3B22:87 [ 2] psha 165 M mloop 4 165 M [3B23] 3B23:E602 [ 3] lda 2,x 165 M [3B25] 3B25:87 [ 2] psha 165 M mloop 4 165 M [3B26] 3B26:E601 [ 3] lda 1,x 165 M [3B28] 3B28:87 [ 2] psha 165 M mloop 4 165 M [3B29] 3B29:F6 [ 3] lda 0,x 165 M [3B2A] 3B2A:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3B2B] 3B2B:5F [ 1] clrx 165 M [3B2C] 3B2C:9E6D 01 [ 5] tst 1,asp 165 M [3B2F] 3B2F:2A01 (3B32) [ 3] bpl *+3 165 M [3B31] 3B31:53 [ 1] !comx 165 M [3B32] 3B32:89 [ 2] pshx:1 165 M mexit 165 M @@Load40 a 165 M @_DoLoad 40,a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3B33] 3B33:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3B36] 3B36:E603 [ 3] lda 3,x 165 M [3B38] 3B38:87 [ 2] psha 165 M mloop 4 165 M [3B39] 3B39:E602 [ 3] lda 2,x 165 M [3B3B] 3B3B:87 [ 2] psha 165 M mloop 4 165 M [3B3C] 3B3C:E601 [ 3] lda 1,x 165 M [3B3E] 3B3E:87 [ 2] psha 165 M mloop 4 165 M [3B3F] 3B3F:F6 [ 3] lda 0,x 165 M [3B40] 3B40:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3B41] 3B41:5F [ 1] clrx 165 M [3B42] 3B42:9E6D 01 [ 5] tst 1,asp 165 M [3B45] 3B45:2A01 (3B48) [ 3] bpl *+3 165 M [3B47] 3B47:53 [ 1] !comx 165 M [3B48] 3B48:89 [ 2] pshx:1 165 M mexit 165 M @@_DoOperation Div40 165 M mdef 2,40 165 M @@Msg Div40 165 M mexit 165 M [3B49] 3B49:CD23 7F [ 6] call StackDiv40 165 M #spadd -40/8 165 M endm 165 M @Save40 ans 165 M @_DoSave 40,ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5,#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3B4C] 3B4C:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3B4E] 3B4E:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3B51] 3B51:86 [ 3] pula 165 M [3B52] 3B52:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3B53] 3B53:86 [ 3] pula 165 M [3B54] 3B54:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3B56] 3B56:86 [ 3] pula 165 M [3B57] 3B57:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3B59] 3B59:86 [ 3] pula 165 M [3B5A] 3B5A:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Mod40 a,b,ans 165 M ;------------------------------------------------------------------------------- 165 M @@Mod40 a,b,ans 165 M @_DoMath Mod40,40,a,b,ans 165 M @@Load40 b 165 M @_DoLoad 40,b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3B5C] 3B5C:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3B5F] 3B5F:E603 [ 3] lda 3,x 165 M [3B61] 3B61:87 [ 2] psha 165 M mloop 4 165 M [3B62] 3B62:E602 [ 3] lda 2,x 165 M [3B64] 3B64:87 [ 2] psha 165 M mloop 4 165 M [3B65] 3B65:E601 [ 3] lda 1,x 165 M [3B67] 3B67:87 [ 2] psha 165 M mloop 4 165 M [3B68] 3B68:F6 [ 3] lda 0,x 165 M [3B69] 3B69:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3B6A] 3B6A:5F [ 1] clrx 165 M [3B6B] 3B6B:9E6D 01 [ 5] tst 1,asp 165 M [3B6E] 3B6E:2A01 (3B71) [ 3] bpl *+3 165 M [3B70] 3B70:53 [ 1] !comx 165 M [3B71] 3B71:89 [ 2] pshx:1 165 M mexit 165 M @@Load40 a 165 M @_DoLoad 40,a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3B72] 3B72:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3B75] 3B75:E603 [ 3] lda 3,x 165 M [3B77] 3B77:87 [ 2] psha 165 M mloop 4 165 M [3B78] 3B78:E602 [ 3] lda 2,x 165 M [3B7A] 3B7A:87 [ 2] psha 165 M mloop 4 165 M [3B7B] 3B7B:E601 [ 3] lda 1,x 165 M [3B7D] 3B7D:87 [ 2] psha 165 M mloop 4 165 M [3B7E] 3B7E:F6 [ 3] lda 0,x 165 M [3B7F] 3B7F:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3B80] 3B80:5F [ 1] clrx 165 M [3B81] 3B81:9E6D 01 [ 5] tst 1,asp 165 M [3B84] 3B84:2A01 (3B87) [ 3] bpl *+3 165 M [3B86] 3B86:53 [ 1] !comx 165 M [3B87] 3B87:89 [ 2] pshx:1 165 M mexit 165 M @@_DoOperation Mod40 165 M mdef 2,40 165 M @@Msg Mod40 165 M mexit 165 M [3B88] 3B88:CD23 92 [ 6] call StackMod40 165 M #spadd -40/8 165 M endm 165 M @Save40 ans 165 M @_DoSave 40,ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5,#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3B8B] 3B8B:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3B8D] 3B8D:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3B90] 3B90:86 [ 3] pula 165 M [3B91] 3B91:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3B92] 3B92:86 [ 3] pula 165 M [3B93] 3B93:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3B95] 3B95:86 [ 3] pula 165 M [3B96] 3B96:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3B98] 3B98:86 [ 3] pula 165 M [3B99] 3B99:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 M ;------------------------------------------------------------------------------- 165 M ; @@Neg40 ans 165 M ;------------------------------------------------------------------------------- 165 M @@Neg40 ans 165 M @_DoNeg 40,ans 165 M @@Msg Neg40 ans 165 M mexit 165 M @@_FindStkMth_ 40 165 M #temp 165 M mdo 40/8 165 M #temp :mloop*8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mexit :temp 165 M mset 1,40 165 M @@Load40 ans 165 M @_DoLoad 40,ans 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ ans 165 M mexit 165 M @@pushv ans 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3B9B] 3B9B:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3B9E] 3B9E:E603 [ 3] lda 3,x 165 M [3BA0] 3BA0:87 [ 2] psha 165 M mloop 4 165 M [3BA1] 3BA1:E602 [ 3] lda 2,x 165 M [3BA3] 3BA3:87 [ 2] psha 165 M mloop 4 165 M [3BA4] 3BA4:E601 [ 3] lda 1,x 165 M [3BA6] 3BA6:87 [ 2] psha 165 M mloop 4 165 M [3BA7] 3BA7:F6 [ 3] lda 0,x 165 M [3BA8] 3BA8:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ ans 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3BA9] 3BA9:5F [ 1] clrx 165 M [3BAA] 3BAA:9E6D 01 [ 5] tst 1,asp 165 M [3BAD] 3BAD:2A01 (3BB0) [ 3] bpl *+3 165 M [3BAF] 3BAF:53 [ 1] !comx 165 M [3BB0] 3BB0:89 [ 2] pshx:1 165 M mexit 165 M [3BB1] 3BB1:CD25 70 [ 6] call StackNegate40 165 M @Save40 165 M @_DoSave 40 165 M mreq 1:BitSize[,Variable] 165 M mset 2 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ 165 M mset #' ' 165 M mexit 165 M @@Msg Save40 165 M mexit 165 M @@lea 165 M mset # 165 M mexit 165 M @@_?sei_ 165 M mexit 165 M [3BB4] 3BB4:CD25 A4 [ 6] call StackSave40 165 M @@_?cli_ 165 M mexit 165 M #spadd -40/8 165 M endm 165 M ;------------------------------------------------------------------------------- 165 M ; @@Abs40 ans 165 M ;------------------------------------------------------------------------------- 165 M @@Abs40 ans 165 M @_DoAbs 40,ans 165 M @@Msg Abs40 ans 165 M mexit 165 M @@_FindStkMth_ 40 165 M #temp 165 M mdo 40/8 165 M #temp :mloop*8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mexit :temp 165 M mset 1,40 165 M @@Load40 ans 165 M @_DoLoad 40,ans 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ ans 165 M mexit 165 M @@pushv ans 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3BB7] 3BB7:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3BBA] 3BBA:E603 [ 3] lda 3,x 165 M [3BBC] 3BBC:87 [ 2] psha 165 M mloop 4 165 M [3BBD] 3BBD:E602 [ 3] lda 2,x 165 M [3BBF] 3BBF:87 [ 2] psha 165 M mloop 4 165 M [3BC0] 3BC0:E601 [ 3] lda 1,x 165 M [3BC2] 3BC2:87 [ 2] psha 165 M mloop 4 165 M [3BC3] 3BC3:F6 [ 3] lda 0,x 165 M [3BC4] 3BC4:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ ans 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3BC5] 3BC5:5F [ 1] clrx 165 M [3BC6] 3BC6:9E6D 01 [ 5] tst 1,asp 165 M [3BC9] 3BC9:2A01 (3BCC) [ 3] bpl *+3 165 M [3BCB] 3BCB:53 [ 1] !comx 165 M [3BCC] 3BCC:89 [ 2] pshx:1 165 M mexit 165 M [3BCD] 3BCD:CD25 6B [ 6] call StackAbs40 165 M @Save40 165 M @_DoSave 40 165 M mreq 1:BitSize[,Variable] 165 M mset 2 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ 165 M mset #' ' 165 M mexit 165 M @@Msg Save40 165 M mexit 165 M @@lea 165 M mset # 165 M mexit 165 M @@_?sei_ 165 M mexit 165 M [3BD0] 3BD0:CD25 A4 [ 6] call StackSave40 165 M @@_?cli_ 165 M mexit 165 M #spadd -40/8 165 M endm 165 M ;------------------------------------------------------------------------------- 165 M ; @@Str40 ans,String 165 M ;------------------------------------------------------------------------------- 165 M @@Str40 ans,String 165 M @_DoStr 40,ans,String 165 M @@_FindStkMth_ 40 165 M #temp 165 M mdo 40/8 165 M #temp :mloop*8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mexit :temp 165 M mset 1,40 165 M @@Load40 ans 165 M @_DoLoad 40,ans 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ ans 165 M mexit 165 M @@pushv ans 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3BD3] 3BD3:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3BD6] 3BD6:E603 [ 3] lda 3,x 165 M [3BD8] 3BD8:87 [ 2] psha 165 M mloop 4 165 M [3BD9] 3BD9:E602 [ 3] lda 2,x 165 M [3BDB] 3BDB:87 [ 2] psha 165 M mloop 4 165 M [3BDC] 3BDC:E601 [ 3] lda 1,x 165 M [3BDE] 3BDE:87 [ 2] psha 165 M mloop 4 165 M [3BDF] 3BDF:F6 [ 3] lda 0,x 165 M [3BE0] 3BE0:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ ans 165 M mexit 165 M @ResizeTOS #4,#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3BE1] 3BE1:5F [ 1] clrx 165 M [3BE2] 3BE2:9E6D 01 [ 5] tst 1,asp 165 M [3BE5] 3BE5:2A01 (3BE8) [ 3] bpl *+3 165 M [3BE7] 3BE7:53 [ 1] !comx 165 M [3BE8] 3BE8:89 [ 2] pshx:1 165 M mexit 165 M @@Msg Convert 'ans' (32-bit) to ASCIZ in 'String' 165 M mexit 165 M @@lea String 165 M mset # 165 M [3BE9] 3BE9:4501 18 [ 3] ldhx #String 165 M endm 165 M [3BEC] 3BEC:CD25 CE [ 6] call Stack40ToASCIZ 165 M [3BEF] 3BEF:A705 [ 2] ais #40/8 165 M endm 165 M ;------------------------------------------------------------------------------- 165 M ; @@Eval40 ans = (a + b) * abs(a - b) / 2 165 M ;------------------------------------------------------------------------------- 165 M @@Eval40 ans = abs(a + b) * abs(a - b) / 2 165 M mset # 165 M @_Eval_ 40,ans = abs(a + b) * abs(a - b) / 2 165 M @@_needs_spauto_ 165 M mexit 165 M mdef 1,32 165 M mswap 0,1 165 M mdel 1 165 M mset # 165 M @@Msg -------------------------------------------------- 165 M mexit 165 M @@Msg Expr: ans = abs(a + b) * abs(a - b) / 2 165 M mexit 165 M @@Msg -------------------------------------------------- 165 M mexit 165 M @@_FindStkMth_ 40 165 M #temp 165 M mdo 40/8 165 M #temp :mloop*8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mloop 8 165 M mexit :temp 165 M mset 0,40,40 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M mtrim 1 165 M mset #'=' 165 M @@_Eval_ abs(a+b)*abs(a-b)/2 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M mdo 2 165 M @@_Eval_ 2 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M 165 M 165 M 165 M 165 M 165 M mset 9 165 M 165 M mset 1,#2 165 M mset 1,#2 165 M @Load40 #2 165 M @_DoLoad 40=#2 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ #2 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M mset 1,#2 165 M @@Msg Load40 #2 165 M mexit 165 M mset 1,2 165 M mset 0 165 M mdo 165 M [3BF1] 3BF1:AE02 [ 2] ldx #2>0&$FF 165 M [3BF3] 3BF3:89 [ 2] pshx 165 M mloop :temp 165 M [3BF4] 3BF4:8C [ 1] clrh 165 M mset 0,clrh 165 M [3BF5] 3BF5:8B [ 2] pshh 165 M mloop :temp 165 M [3BF6] 3BF6:8B [ 2] pshh 165 M mloop :temp 165 M [3BF7] 3BF7:8B [ 2] pshh 165 M mloop :temp 165 M [3BF8] 3BF8:8B [ 2] pshh 165 M mloop :temp 165 M mexit 165 M mloop :nn 165 M @@_Eval_ abs(a-b) 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M 165 M 165 M @@_Eval_ a-b 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M mdo 2 165 M @@_Eval_ b 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M 165 M 165 M 165 M 165 M 165 M mset 9 165 M 165 M @Load40 b 165 M @_DoLoad 40=b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3BF9] 3BF9:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3BFC] 3BFC:E603 [ 3] lda 3,x 165 M [3BFE] 3BFE:87 [ 2] psha 165 M mloop 4 165 M [3BFF] 3BFF:E602 [ 3] lda 2,x 165 M [3C01] 3C01:87 [ 2] psha 165 M mloop 4 165 M [3C02] 3C02:E601 [ 3] lda 1,x 165 M [3C04] 3C04:87 [ 2] psha 165 M mloop 4 165 M [3C05] 3C05:F6 [ 3] lda 0,x 165 M [3C06] 3C06:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4=#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3C07] 3C07:5F [ 1] clrx 165 M [3C08] 3C08:9E6D 01 [ 5] tst 1,asp 165 M [3C0B] 3C0B:2A01 (3C0E) [ 3] bpl *+3 165 M [3C0D] 3C0D:53 [ 1] !comx 165 M [3C0E] 3C0E:89 [ 2] pshx:1 165 M mexit 165 M mloop :nn 165 M @@_Eval_ a 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M 165 M 165 M 165 M 165 M 165 M mset 9 165 M 165 M @Load40 a 165 M @_DoLoad 40=a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3C0F] 3C0F:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3C12] 3C12:E603 [ 3] lda 3,x 165 M [3C14] 3C14:87 [ 2] psha 165 M mloop 4 165 M [3C15] 3C15:E602 [ 3] lda 2,x 165 M [3C17] 3C17:87 [ 2] psha 165 M mloop 4 165 M [3C18] 3C18:E601 [ 3] lda 1,x 165 M [3C1A] 3C1A:87 [ 2] psha 165 M mloop 4 165 M [3C1B] 3C1B:F6 [ 3] lda 0,x 165 M [3C1C] 3C1C:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4=#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3C1D] 3C1D:5F [ 1] clrx 165 M [3C1E] 3C1E:9E6D 01 [ 5] tst 1,asp 165 M [3C21] 3C21:2A01 (3C24) [ 3] bpl *+3 165 M [3C23] 3C23:53 [ 1] !comx 165 M [3C24] 3C24:89 [ 2] pshx:1 165 M mexit 165 M mdo 2 165 M @@Msg Sub40 165 M mexit 165 M [3C25] 3C25:CD22 4D [ 6] call StackSub40 165 M #spadd -5 165 M mloop :nn 165 M mexit 165 M @@Msg Abs40 165 M mexit 165 M [3C28] 3C28:CD25 6B [ 6] call StackAbs40 165 M mexit 165 M mloop :nn 165 M @@_Eval_ abs(a+b) 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M 165 M 165 M @@_Eval_ a+b 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M mdo 2 165 M @@_Eval_ b 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M 165 M 165 M 165 M 165 M 165 M mset 9 165 M 165 M @Load40 b 165 M @_DoLoad 40=b 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ b 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ b 165 M mexit 165 M @@pushv b 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV b (32-bit) 165 M mexit 165 M #push 165 M @@lea b 165 M mset # 165 M [3C2B] 3C2B:4501 08 [ 3] ldhx #b 165 M endm 165 M #x 165 M mdo 165 M [3C2E] 3C2E:E603 [ 3] lda 3,x 165 M [3C30] 3C30:87 [ 2] psha 165 M mloop 4 165 M [3C31] 3C31:E602 [ 3] lda 2,x 165 M [3C33] 3C33:87 [ 2] psha 165 M mloop 4 165 M [3C34] 3C34:E601 [ 3] lda 1,x 165 M [3C36] 3C36:87 [ 2] psha 165 M mloop 4 165 M [3C37] 3C37:F6 [ 3] lda 0,x 165 M [3C38] 3C38:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ b 165 M mexit 165 M @ResizeTOS #4=#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3C39] 3C39:5F [ 1] clrx 165 M [3C3A] 3C3A:9E6D 01 [ 5] tst 1,asp 165 M [3C3D] 3C3D:2A01 (3C40) [ 3] bpl *+3 165 M [3C3F] 3C3F:53 [ 1] !comx 165 M [3C40] 3C40:89 [ 2] pshx:1 165 M mexit 165 M mloop :nn 165 M @@_Eval_ a 165 M mset # 165 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 165 M 165 M 165 M 165 M 165 M mset #'+-|^' 165 M 165 M mset #'*\/&><' 165 M 165 M 165 M 165 M 165 M 165 M mset 9 165 M 165 M @Load40 a 165 M @_DoLoad 40=a 165 M mreq 1:BitSize[,Variable] 165 M #temp 40/8 165 M mdel 1 165 M mset # 165 M mtrim 1 165 M 165 M mset 9 165 M 165 M @@_not_x_ a 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M 165 M 165 M @@_?sei_ a 165 M mexit 165 M @@pushv a 165 M mset #' ' 165 M mset 0 165 M mreq 1:variable[ SizeOf(var)][ 'newname'] 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PushV a (32-bit) 165 M mexit 165 M #push 165 M @@lea a 165 M mset # 165 M [3C41] 3C41:4501 00 [ 3] ldhx #a 165 M endm 165 M #x 165 M mdo 165 M [3C44] 3C44:E603 [ 3] lda 3,x 165 M [3C46] 3C46:87 [ 2] psha 165 M mloop 4 165 M [3C47] 3C47:E602 [ 3] lda 2,x 165 M [3C49] 3C49:87 [ 2] psha 165 M mloop 4 165 M [3C4A] 3C4A:E601 [ 3] lda 1,x 165 M [3C4C] 3C4C:87 [ 2] psha 165 M mloop 4 165 M [3C4D] 3C4D:F6 [ 3] lda 0,x 165 M [3C4E] 3C4E:87 [ 2] psha 165 M mloop 4 165 M #pull 165 M #spadd 4 165 M endm 165 M @@_?cli_ a 165 M mexit 165 M @ResizeTOS #4=#5 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 5-4 165 M @@Msg Signed 32-bit => 40-bit 165 M mexit 165 M [3C4F] 3C4F:5F [ 1] clrx 165 M [3C50] 3C50:9E6D 01 [ 5] tst 1,asp 165 M [3C53] 3C53:2A01 (3C56) [ 3] bpl *+3 165 M [3C55] 3C55:53 [ 1] !comx 165 M [3C56] 3C56:89 [ 2] pshx:1 165 M mexit 165 M mdo 2 165 M @@Msg Add40 165 M mexit 165 M [3C57] 3C57:CD22 37 [ 6] call StackAdd40 165 M #spadd -5 165 M mloop :nn 165 M mexit 165 M @@Msg Abs40 165 M mexit 165 M [3C5A] 3C5A:CD25 6B [ 6] call StackAbs40 165 M mexit 165 M mdo 2 165 M @@Msg Mul40 165 M mexit 165 M [3C5D] 3C5D:CD23 30 [ 6] call StackMul40 165 M #spadd -5 165 M mloop :nn 165 M @@Msg Div40 165 M mexit 165 M [3C60] 3C60:CD23 7F [ 6] call StackDiv40 165 M #spadd -5 165 M mloop :nn 165 M mexit 165 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 165 M mset 9 165 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 165 M @Save40 ans 165 M @_DoSave 40=ans 165 M mreq 1:BitSize[,Variable] 165 M mset 2,ans 165 M mtrim 2 165 M 165 M mset 9 165 M 165 M @@_not_x_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M @@ResizeTOS #5=#4 165 M mreq 1,2:#FromByteSize,#ToByteSize 165 M #temp 4-5 165 M @@Msg Signed 40-bit => 32-bit 165 M mexit 165 M [3C63] 3C63:A701 [ 2] ais #-:temp 165 M mexit 165 M @@_?sei_ ans 165 M mexit 165 M @@pullv ans 165 M mset #' ' 165 M mreq 1:Variable[ SizeOf(Variable)] 165 M @@_not_#_ ans 165 M mset #' ' 165 M mdel 1 165 M mtop 165 M mset #' ' 165 M mexit 165 M mdef 2,4 165 M mdef 2,1 165 M @@Msg PullV ans (32-bit) 165 M mexit 165 M #push 165 M @@lea ans 165 M mset # 165 M [3C65] 3C65:4501 10 [ 3] ldhx #ans 165 M endm 165 M #x 165 M mdo 165 M [3C68] 3C68:86 [ 3] pula 165 M [3C69] 3C69:F7 [ 2] sta 0,x 165 M mloop 4 165 M [3C6A] 3C6A:86 [ 3] pula 165 M [3C6B] 3C6B:E701 [ 3] sta 1,x 165 M mloop 4 165 M [3C6D] 3C6D:86 [ 3] pula 165 M [3C6E] 3C6E:E702 [ 3] sta 2,x 165 M mloop 4 165 M [3C70] 3C70:86 [ 3] pula 165 M [3C71] 3C71:E703 [ 3] sta 3,x 165 M mloop 4 165 M #pull 165 M #spadd -4 165 M endm 165 M @_?cli_ ans 165 M mexit 165 endm 166 M @Test 48 166 M ;------------------------------------------------------------------------------- 166 M ; Test the 48-bit version 166 M ;------------------------------------------------------------------------------- 166 M 166 M ;------------------------------------------------------------------------------- 166 M ; @@Load48 a 166 M ;------------------------------------------------------------------------------- 166 M @@Load48 a 166 M @_DoLoad 48,a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3C73] 3C73:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3C76] 3C76:E603 [ 3] lda 3,x 166 M [3C78] 3C78:87 [ 2] psha 166 M mloop 4 166 M [3C79] 3C79:E602 [ 3] lda 2,x 166 M [3C7B] 3C7B:87 [ 2] psha 166 M mloop 4 166 M [3C7C] 3C7C:E601 [ 3] lda 1,x 166 M [3C7E] 3C7E:87 [ 2] psha 166 M mloop 4 166 M [3C7F] 3C7F:F6 [ 3] lda 0,x 166 M [3C80] 3C80:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3C81] 3C81:5F [ 1] clrx 166 M [3C82] 3C82:9E6D 01 [ 5] tst 1,asp 166 M [3C85] 3C85:2A01 (3C88) [ 3] bpl *+3 166 M [3C87] 3C87:53 [ 1] !comx 166 M [3C88] 3C88:89 [ 2] pshx:2 166 M [3C89] 3C89:89 [ 2] 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Load48 b 166 M ;------------------------------------------------------------------------------- 166 M @@Load48 b 166 M @_DoLoad 48,b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3C8A] 3C8A:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3C8D] 3C8D:E603 [ 3] lda 3,x 166 M [3C8F] 3C8F:87 [ 2] psha 166 M mloop 4 166 M [3C90] 3C90:E602 [ 3] lda 2,x 166 M [3C92] 3C92:87 [ 2] psha 166 M mloop 4 166 M [3C93] 3C93:E601 [ 3] lda 1,x 166 M [3C95] 3C95:87 [ 2] psha 166 M mloop 4 166 M [3C96] 3C96:F6 [ 3] lda 0,x 166 M [3C97] 3C97:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3C98] 3C98:5F [ 1] clrx 166 M [3C99] 3C99:9E6D 01 [ 5] tst 1,asp 166 M [3C9C] 3C9C:2A01 (3C9F) [ 3] bpl *+3 166 M [3C9E] 3C9E:53 [ 1] !comx 166 M [3C9F] 3C9F:89 [ 2] pshx:2 166 M [3CA0] 3CA0:89 [ 2] 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Swap48 166 M ;------------------------------------------------------------------------------- 166 M @@Swap48 166 M @_DoSwap 48 166 M [3CA1] 3CA1:CD29 A4 [ 6] call StackSwap48 166 M endm 166 M ;------------------------------------------------------------------------------- 166 M ; @@Save48 ans 166 M ;------------------------------------------------------------------------------- 166 M @@Save48 ans 166 M @_DoSave 48,ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6,#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3CA4] 3CA4:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3CA6] 3CA6:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3CA9] 3CA9:86 [ 3] pula 166 M [3CAA] 3CAA:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3CAB] 3CAB:86 [ 3] pula 166 M [3CAC] 3CAC:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3CAE] 3CAE:86 [ 3] pula 166 M [3CAF] 3CAF:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3CB1] 3CB1:86 [ 3] pula 166 M [3CB2] 3CB2:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Save48 ans 166 M ;------------------------------------------------------------------------------- 166 M @@Save48 ans 166 M @_DoSave 48,ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6,#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3CB4] 3CB4:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3CB6] 3CB6:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3CB9] 3CB9:86 [ 3] pula 166 M [3CBA] 3CBA:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3CBB] 3CBB:86 [ 3] pula 166 M [3CBC] 3CBC:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3CBE] 3CBE:86 [ 3] pula 166 M [3CBF] 3CBF:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3CC1] 3CC1:86 [ 3] pula 166 M [3CC2] 3CC2:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Add48 a,b,ans 166 M ;------------------------------------------------------------------------------- 166 M @@Add48 a,b,ans 166 M @_DoMath Add48,48,a,b,ans 166 M @@Load48 b 166 M @_DoLoad 48,b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3CC4] 3CC4:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3CC7] 3CC7:E603 [ 3] lda 3,x 166 M [3CC9] 3CC9:87 [ 2] psha 166 M mloop 4 166 M [3CCA] 3CCA:E602 [ 3] lda 2,x 166 M [3CCC] 3CCC:87 [ 2] psha 166 M mloop 4 166 M [3CCD] 3CCD:E601 [ 3] lda 1,x 166 M [3CCF] 3CCF:87 [ 2] psha 166 M mloop 4 166 M [3CD0] 3CD0:F6 [ 3] lda 0,x 166 M [3CD1] 3CD1:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3CD2] 3CD2:5F [ 1] clrx 166 M [3CD3] 3CD3:9E6D 01 [ 5] tst 1,asp 166 M [3CD6] 3CD6:2A01 (3CD9) [ 3] bpl *+3 166 M [3CD8] 3CD8:53 [ 1] !comx 166 M [3CD9] 3CD9:89 [ 2] pshx:2 166 M [3CDA] 3CDA:89 [ 2] 166 M mexit 166 M @@Load48 a 166 M @_DoLoad 48,a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3CDB] 3CDB:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3CDE] 3CDE:E603 [ 3] lda 3,x 166 M [3CE0] 3CE0:87 [ 2] psha 166 M mloop 4 166 M [3CE1] 3CE1:E602 [ 3] lda 2,x 166 M [3CE3] 3CE3:87 [ 2] psha 166 M mloop 4 166 M [3CE4] 3CE4:E601 [ 3] lda 1,x 166 M [3CE6] 3CE6:87 [ 2] psha 166 M mloop 4 166 M [3CE7] 3CE7:F6 [ 3] lda 0,x 166 M [3CE8] 3CE8:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3CE9] 3CE9:5F [ 1] clrx 166 M [3CEA] 3CEA:9E6D 01 [ 5] tst 1,asp 166 M [3CED] 3CED:2A01 (3CF0) [ 3] bpl *+3 166 M [3CEF] 3CEF:53 [ 1] !comx 166 M [3CF0] 3CF0:89 [ 2] pshx:2 166 M [3CF1] 3CF1:89 [ 2] 166 M mexit 166 M @@_DoOperation Add48 166 M mdef 2,48 166 M @@Msg Add48 166 M mexit 166 M [3CF2] 3CF2:CD26 2C [ 6] call StackAdd48 166 M #spadd -48/8 166 M endm 166 M @Save48 ans 166 M @_DoSave 48,ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6,#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3CF5] 3CF5:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3CF7] 3CF7:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3CFA] 3CFA:86 [ 3] pula 166 M [3CFB] 3CFB:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3CFC] 3CFC:86 [ 3] pula 166 M [3CFD] 3CFD:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3CFF] 3CFF:86 [ 3] pula 166 M [3D00] 3D00:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3D02] 3D02:86 [ 3] pula 166 M [3D03] 3D03:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Sub48 a,b,ans 166 M ;------------------------------------------------------------------------------- 166 M @@Sub48 a,b,ans 166 M @_DoMath Sub48,48,a,b,ans 166 M @@Load48 b 166 M @_DoLoad 48,b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3D05] 3D05:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3D08] 3D08:E603 [ 3] lda 3,x 166 M [3D0A] 3D0A:87 [ 2] psha 166 M mloop 4 166 M [3D0B] 3D0B:E602 [ 3] lda 2,x 166 M [3D0D] 3D0D:87 [ 2] psha 166 M mloop 4 166 M [3D0E] 3D0E:E601 [ 3] lda 1,x 166 M [3D10] 3D10:87 [ 2] psha 166 M mloop 4 166 M [3D11] 3D11:F6 [ 3] lda 0,x 166 M [3D12] 3D12:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3D13] 3D13:5F [ 1] clrx 166 M [3D14] 3D14:9E6D 01 [ 5] tst 1,asp 166 M [3D17] 3D17:2A01 (3D1A) [ 3] bpl *+3 166 M [3D19] 3D19:53 [ 1] !comx 166 M [3D1A] 3D1A:89 [ 2] pshx:2 166 M [3D1B] 3D1B:89 [ 2] 166 M mexit 166 M @@Load48 a 166 M @_DoLoad 48,a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3D1C] 3D1C:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3D1F] 3D1F:E603 [ 3] lda 3,x 166 M [3D21] 3D21:87 [ 2] psha 166 M mloop 4 166 M [3D22] 3D22:E602 [ 3] lda 2,x 166 M [3D24] 3D24:87 [ 2] psha 166 M mloop 4 166 M [3D25] 3D25:E601 [ 3] lda 1,x 166 M [3D27] 3D27:87 [ 2] psha 166 M mloop 4 166 M [3D28] 3D28:F6 [ 3] lda 0,x 166 M [3D29] 3D29:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3D2A] 3D2A:5F [ 1] clrx 166 M [3D2B] 3D2B:9E6D 01 [ 5] tst 1,asp 166 M [3D2E] 3D2E:2A01 (3D31) [ 3] bpl *+3 166 M [3D30] 3D30:53 [ 1] !comx 166 M [3D31] 3D31:89 [ 2] pshx:2 166 M [3D32] 3D32:89 [ 2] 166 M mexit 166 M @@_DoOperation Sub48 166 M mdef 2,48 166 M @@Msg Sub48 166 M mexit 166 M [3D33] 3D33:CD26 42 [ 6] call StackSub48 166 M #spadd -48/8 166 M endm 166 M @Save48 ans 166 M @_DoSave 48,ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6,#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3D36] 3D36:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3D38] 3D38:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3D3B] 3D3B:86 [ 3] pula 166 M [3D3C] 3D3C:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3D3D] 3D3D:86 [ 3] pula 166 M [3D3E] 3D3E:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3D40] 3D40:86 [ 3] pula 166 M [3D41] 3D41:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3D43] 3D43:86 [ 3] pula 166 M [3D44] 3D44:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Mul48 a,b,ans 166 M ;------------------------------------------------------------------------------- 166 M @@Mul48 a,b,ans 166 M @_DoMath Mul48,48,a,b,ans 166 M @@Load48 b 166 M @_DoLoad 48,b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3D46] 3D46:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3D49] 3D49:E603 [ 3] lda 3,x 166 M [3D4B] 3D4B:87 [ 2] psha 166 M mloop 4 166 M [3D4C] 3D4C:E602 [ 3] lda 2,x 166 M [3D4E] 3D4E:87 [ 2] psha 166 M mloop 4 166 M [3D4F] 3D4F:E601 [ 3] lda 1,x 166 M [3D51] 3D51:87 [ 2] psha 166 M mloop 4 166 M [3D52] 3D52:F6 [ 3] lda 0,x 166 M [3D53] 3D53:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3D54] 3D54:5F [ 1] clrx 166 M [3D55] 3D55:9E6D 01 [ 5] tst 1,asp 166 M [3D58] 3D58:2A01 (3D5B) [ 3] bpl *+3 166 M [3D5A] 3D5A:53 [ 1] !comx 166 M [3D5B] 3D5B:89 [ 2] pshx:2 166 M [3D5C] 3D5C:89 [ 2] 166 M mexit 166 M @@Load48 a 166 M @_DoLoad 48,a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3D5D] 3D5D:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3D60] 3D60:E603 [ 3] lda 3,x 166 M [3D62] 3D62:87 [ 2] psha 166 M mloop 4 166 M [3D63] 3D63:E602 [ 3] lda 2,x 166 M [3D65] 3D65:87 [ 2] psha 166 M mloop 4 166 M [3D66] 3D66:E601 [ 3] lda 1,x 166 M [3D68] 3D68:87 [ 2] psha 166 M mloop 4 166 M [3D69] 3D69:F6 [ 3] lda 0,x 166 M [3D6A] 3D6A:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3D6B] 3D6B:5F [ 1] clrx 166 M [3D6C] 3D6C:9E6D 01 [ 5] tst 1,asp 166 M [3D6F] 3D6F:2A01 (3D72) [ 3] bpl *+3 166 M [3D71] 3D71:53 [ 1] !comx 166 M [3D72] 3D72:89 [ 2] pshx:2 166 M [3D73] 3D73:89 [ 2] 166 M mexit 166 M @@_DoOperation Mul48 166 M mdef 2,48 166 M @@Msg Mul48 166 M mexit 166 M [3D74] 3D74:CD27 39 [ 6] call StackMul48 166 M #spadd -48/8 166 M endm 166 M @Save48 ans 166 M @_DoSave 48,ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6,#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3D77] 3D77:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3D79] 3D79:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3D7C] 3D7C:86 [ 3] pula 166 M [3D7D] 3D7D:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3D7E] 3D7E:86 [ 3] pula 166 M [3D7F] 3D7F:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3D81] 3D81:86 [ 3] pula 166 M [3D82] 3D82:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3D84] 3D84:86 [ 3] pula 166 M [3D85] 3D85:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Div48 a,b,ans 166 M ;------------------------------------------------------------------------------- 166 M @@Div48 a,b,ans 166 M @_DoMath Div48,48,a,b,ans 166 M @@Load48 b 166 M @_DoLoad 48,b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3D87] 3D87:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3D8A] 3D8A:E603 [ 3] lda 3,x 166 M [3D8C] 3D8C:87 [ 2] psha 166 M mloop 4 166 M [3D8D] 3D8D:E602 [ 3] lda 2,x 166 M [3D8F] 3D8F:87 [ 2] psha 166 M mloop 4 166 M [3D90] 3D90:E601 [ 3] lda 1,x 166 M [3D92] 3D92:87 [ 2] psha 166 M mloop 4 166 M [3D93] 3D93:F6 [ 3] lda 0,x 166 M [3D94] 3D94:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3D95] 3D95:5F [ 1] clrx 166 M [3D96] 3D96:9E6D 01 [ 5] tst 1,asp 166 M [3D99] 3D99:2A01 (3D9C) [ 3] bpl *+3 166 M [3D9B] 3D9B:53 [ 1] !comx 166 M [3D9C] 3D9C:89 [ 2] pshx:2 166 M [3D9D] 3D9D:89 [ 2] 166 M mexit 166 M @@Load48 a 166 M @_DoLoad 48,a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3D9E] 3D9E:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3DA1] 3DA1:E603 [ 3] lda 3,x 166 M [3DA3] 3DA3:87 [ 2] psha 166 M mloop 4 166 M [3DA4] 3DA4:E602 [ 3] lda 2,x 166 M [3DA6] 3DA6:87 [ 2] psha 166 M mloop 4 166 M [3DA7] 3DA7:E601 [ 3] lda 1,x 166 M [3DA9] 3DA9:87 [ 2] psha 166 M mloop 4 166 M [3DAA] 3DAA:F6 [ 3] lda 0,x 166 M [3DAB] 3DAB:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3DAC] 3DAC:5F [ 1] clrx 166 M [3DAD] 3DAD:9E6D 01 [ 5] tst 1,asp 166 M [3DB0] 3DB0:2A01 (3DB3) [ 3] bpl *+3 166 M [3DB2] 3DB2:53 [ 1] !comx 166 M [3DB3] 3DB3:89 [ 2] pshx:2 166 M [3DB4] 3DB4:89 [ 2] 166 M mexit 166 M @@_DoOperation Div48 166 M mdef 2,48 166 M @@Msg Div48 166 M mexit 166 M [3DB5] 3DB5:CD27 92 [ 6] call StackDiv48 166 M #spadd -48/8 166 M endm 166 M @Save48 ans 166 M @_DoSave 48,ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6,#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3DB8] 3DB8:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3DBA] 3DBA:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3DBD] 3DBD:86 [ 3] pula 166 M [3DBE] 3DBE:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3DBF] 3DBF:86 [ 3] pula 166 M [3DC0] 3DC0:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3DC2] 3DC2:86 [ 3] pula 166 M [3DC3] 3DC3:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3DC5] 3DC5:86 [ 3] pula 166 M [3DC6] 3DC6:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Mod48 a,b,ans 166 M ;------------------------------------------------------------------------------- 166 M @@Mod48 a,b,ans 166 M @_DoMath Mod48,48,a,b,ans 166 M @@Load48 b 166 M @_DoLoad 48,b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3DC8] 3DC8:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3DCB] 3DCB:E603 [ 3] lda 3,x 166 M [3DCD] 3DCD:87 [ 2] psha 166 M mloop 4 166 M [3DCE] 3DCE:E602 [ 3] lda 2,x 166 M [3DD0] 3DD0:87 [ 2] psha 166 M mloop 4 166 M [3DD1] 3DD1:E601 [ 3] lda 1,x 166 M [3DD3] 3DD3:87 [ 2] psha 166 M mloop 4 166 M [3DD4] 3DD4:F6 [ 3] lda 0,x 166 M [3DD5] 3DD5:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3DD6] 3DD6:5F [ 1] clrx 166 M [3DD7] 3DD7:9E6D 01 [ 5] tst 1,asp 166 M [3DDA] 3DDA:2A01 (3DDD) [ 3] bpl *+3 166 M [3DDC] 3DDC:53 [ 1] !comx 166 M [3DDD] 3DDD:89 [ 2] pshx:2 166 M [3DDE] 3DDE:89 [ 2] 166 M mexit 166 M @@Load48 a 166 M @_DoLoad 48,a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3DDF] 3DDF:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3DE2] 3DE2:E603 [ 3] lda 3,x 166 M [3DE4] 3DE4:87 [ 2] psha 166 M mloop 4 166 M [3DE5] 3DE5:E602 [ 3] lda 2,x 166 M [3DE7] 3DE7:87 [ 2] psha 166 M mloop 4 166 M [3DE8] 3DE8:E601 [ 3] lda 1,x 166 M [3DEA] 3DEA:87 [ 2] psha 166 M mloop 4 166 M [3DEB] 3DEB:F6 [ 3] lda 0,x 166 M [3DEC] 3DEC:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3DED] 3DED:5F [ 1] clrx 166 M [3DEE] 3DEE:9E6D 01 [ 5] tst 1,asp 166 M [3DF1] 3DF1:2A01 (3DF4) [ 3] bpl *+3 166 M [3DF3] 3DF3:53 [ 1] !comx 166 M [3DF4] 3DF4:89 [ 2] pshx:2 166 M [3DF5] 3DF5:89 [ 2] 166 M mexit 166 M @@_DoOperation Mod48 166 M mdef 2,48 166 M @@Msg Mod48 166 M mexit 166 M [3DF6] 3DF6:CD27 A5 [ 6] call StackMod48 166 M #spadd -48/8 166 M endm 166 M @Save48 ans 166 M @_DoSave 48,ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6,#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3DF9] 3DF9:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3DFB] 3DFB:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3DFE] 3DFE:86 [ 3] pula 166 M [3DFF] 3DFF:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3E00] 3E00:86 [ 3] pula 166 M [3E01] 3E01:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3E03] 3E03:86 [ 3] pula 166 M [3E04] 3E04:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3E06] 3E06:86 [ 3] pula 166 M [3E07] 3E07:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 M ;------------------------------------------------------------------------------- 166 M ; @@Neg48 ans 166 M ;------------------------------------------------------------------------------- 166 M @@Neg48 ans 166 M @_DoNeg 48,ans 166 M @@Msg Neg48 ans 166 M mexit 166 M @@_FindStkMth_ 48 166 M #temp 166 M mdo 48/8 166 M #temp :mloop*8 166 M mloop 8 166 M mloop 8 166 M mloop 8 166 M mexit :temp 166 M mset 1,48 166 M @@Load48 ans 166 M @_DoLoad 48,ans 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ ans 166 M mexit 166 M @@pushv ans 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3E09] 3E09:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3E0C] 3E0C:E603 [ 3] lda 3,x 166 M [3E0E] 3E0E:87 [ 2] psha 166 M mloop 4 166 M [3E0F] 3E0F:E602 [ 3] lda 2,x 166 M [3E11] 3E11:87 [ 2] psha 166 M mloop 4 166 M [3E12] 3E12:E601 [ 3] lda 1,x 166 M [3E14] 3E14:87 [ 2] psha 166 M mloop 4 166 M [3E15] 3E15:F6 [ 3] lda 0,x 166 M [3E16] 3E16:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ ans 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3E17] 3E17:5F [ 1] clrx 166 M [3E18] 3E18:9E6D 01 [ 5] tst 1,asp 166 M [3E1B] 3E1B:2A01 (3E1E) [ 3] bpl *+3 166 M [3E1D] 3E1D:53 [ 1] !comx 166 M [3E1E] 3E1E:89 [ 2] pshx:2 166 M [3E1F] 3E1F:89 [ 2] 166 M mexit 166 M [3E20] 3E20:CD29 C5 [ 6] call StackNegate48 166 M @Save48 166 M @_DoSave 48 166 M mreq 1:BitSize[,Variable] 166 M mset 2 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ 166 M mset #' ' 166 M mexit 166 M @@Msg Save48 166 M mexit 166 M @@lea 166 M mset # 166 M mexit 166 M @@_?sei_ 166 M mexit 166 M [3E23] 3E23:CD29 FE [ 6] call StackSave48 166 M @@_?cli_ 166 M mexit 166 M #spadd -48/8 166 M endm 166 M ;------------------------------------------------------------------------------- 166 M ; @@Abs48 ans 166 M ;------------------------------------------------------------------------------- 166 M @@Abs48 ans 166 M @_DoAbs 48,ans 166 M @@Msg Abs48 ans 166 M mexit 166 M @@_FindStkMth_ 48 166 M #temp 166 M mdo 48/8 166 M #temp :mloop*8 166 M mloop 8 166 M mloop 8 166 M mloop 8 166 M mexit :temp 166 M mset 1,48 166 M @@Load48 ans 166 M @_DoLoad 48,ans 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ ans 166 M mexit 166 M @@pushv ans 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3E26] 3E26:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3E29] 3E29:E603 [ 3] lda 3,x 166 M [3E2B] 3E2B:87 [ 2] psha 166 M mloop 4 166 M [3E2C] 3E2C:E602 [ 3] lda 2,x 166 M [3E2E] 3E2E:87 [ 2] psha 166 M mloop 4 166 M [3E2F] 3E2F:E601 [ 3] lda 1,x 166 M [3E31] 3E31:87 [ 2] psha 166 M mloop 4 166 M [3E32] 3E32:F6 [ 3] lda 0,x 166 M [3E33] 3E33:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ ans 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3E34] 3E34:5F [ 1] clrx 166 M [3E35] 3E35:9E6D 01 [ 5] tst 1,asp 166 M [3E38] 3E38:2A01 (3E3B) [ 3] bpl *+3 166 M [3E3A] 3E3A:53 [ 1] !comx 166 M [3E3B] 3E3B:89 [ 2] pshx:2 166 M [3E3C] 3E3C:89 [ 2] 166 M mexit 166 M [3E3D] 3E3D:CD29 C0 [ 6] call StackAbs48 166 M @Save48 166 M @_DoSave 48 166 M mreq 1:BitSize[,Variable] 166 M mset 2 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ 166 M mset #' ' 166 M mexit 166 M @@Msg Save48 166 M mexit 166 M @@lea 166 M mset # 166 M mexit 166 M @@_?sei_ 166 M mexit 166 M [3E40] 3E40:CD29 FE [ 6] call StackSave48 166 M @@_?cli_ 166 M mexit 166 M #spadd -48/8 166 M endm 166 M ;------------------------------------------------------------------------------- 166 M ; @@Str48 ans,String 166 M ;------------------------------------------------------------------------------- 166 M @@Str48 ans,String 166 M @_DoStr 48,ans,String 166 M @@_FindStkMth_ 48 166 M #temp 166 M mdo 48/8 166 M #temp :mloop*8 166 M mloop 8 166 M mloop 8 166 M mloop 8 166 M mexit :temp 166 M mset 1,48 166 M @@Load48 ans 166 M @_DoLoad 48,ans 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ ans 166 M mexit 166 M @@pushv ans 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3E43] 3E43:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3E46] 3E46:E603 [ 3] lda 3,x 166 M [3E48] 3E48:87 [ 2] psha 166 M mloop 4 166 M [3E49] 3E49:E602 [ 3] lda 2,x 166 M [3E4B] 3E4B:87 [ 2] psha 166 M mloop 4 166 M [3E4C] 3E4C:E601 [ 3] lda 1,x 166 M [3E4E] 3E4E:87 [ 2] psha 166 M mloop 4 166 M [3E4F] 3E4F:F6 [ 3] lda 0,x 166 M [3E50] 3E50:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ ans 166 M mexit 166 M @ResizeTOS #4,#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3E51] 3E51:5F [ 1] clrx 166 M [3E52] 3E52:9E6D 01 [ 5] tst 1,asp 166 M [3E55] 3E55:2A01 (3E58) [ 3] bpl *+3 166 M [3E57] 3E57:53 [ 1] !comx 166 M [3E58] 3E58:89 [ 2] pshx:2 166 M [3E59] 3E59:89 [ 2] 166 M mexit 166 M @@Msg Convert 'ans' (32-bit) to ASCIZ in 'String' 166 M mexit 166 M @@lea String 166 M mset # 166 M [3E5A] 3E5A:4501 18 [ 3] ldhx #String 166 M endm 166 M [3E5D] 3E5D:CD2A 2D [ 6] call Stack48ToASCIZ 166 M [3E60] 3E60:A706 [ 2] ais #48/8 166 M endm 166 M ;------------------------------------------------------------------------------- 166 M ; @@Eval48 ans = (a + b) * abs(a - b) / 2 166 M ;------------------------------------------------------------------------------- 166 M @@Eval48 ans = abs(a + b) * abs(a - b) / 2 166 M mset # 166 M @_Eval_ 48,ans = abs(a + b) * abs(a - b) / 2 166 M @@_needs_spauto_ 166 M mexit 166 M mdef 1,32 166 M mswap 0,1 166 M mdel 1 166 M mset # 166 M @@Msg -------------------------------------------------- 166 M mexit 166 M @@Msg Expr: ans = abs(a + b) * abs(a - b) / 2 166 M mexit 166 M @@Msg -------------------------------------------------- 166 M mexit 166 M @@_FindStkMth_ 48 166 M #temp 166 M mdo 48/8 166 M #temp :mloop*8 166 M mloop 8 166 M mloop 8 166 M mloop 8 166 M mexit :temp 166 M mset 0,48,48 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M mtrim 1 166 M mset #'=' 166 M @@_Eval_ abs(a+b)*abs(a-b)/2 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M mdo 2 166 M @@_Eval_ 2 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M 166 M 166 M 166 M 166 M 166 M mset 9 166 M 166 M mset 1,#2 166 M mset 1,#2 166 M @Load48 #2 166 M @_DoLoad 48=#2 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ #2 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M mset 1,#2 166 M @@Msg Load48 #2 166 M mexit 166 M mset 1,2 166 M mset 0 166 M mdo 166 M [3E62] 3E62:AE02 [ 2] ldx #2>0&$FF 166 M [3E64] 3E64:89 [ 2] pshx 166 M mloop :temp 166 M [3E65] 3E65:8C [ 1] clrh 166 M mset 0,clrh 166 M [3E66] 3E66:8B [ 2] pshh 166 M mloop :temp 166 M [3E67] 3E67:8B [ 2] pshh 166 M mloop :temp 166 M [3E68] 3E68:8B [ 2] pshh 166 M mloop :temp 166 M [3E69] 3E69:8B [ 2] pshh 166 M mloop :temp 166 M [3E6A] 3E6A:8B [ 2] pshh 166 M mloop :temp 166 M mexit 166 M mloop :nn 166 M @@_Eval_ abs(a-b) 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M 166 M 166 M @@_Eval_ a-b 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M mdo 2 166 M @@_Eval_ b 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M 166 M 166 M 166 M 166 M 166 M mset 9 166 M 166 M @Load48 b 166 M @_DoLoad 48=b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3E6B] 3E6B:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3E6E] 3E6E:E603 [ 3] lda 3,x 166 M [3E70] 3E70:87 [ 2] psha 166 M mloop 4 166 M [3E71] 3E71:E602 [ 3] lda 2,x 166 M [3E73] 3E73:87 [ 2] psha 166 M mloop 4 166 M [3E74] 3E74:E601 [ 3] lda 1,x 166 M [3E76] 3E76:87 [ 2] psha 166 M mloop 4 166 M [3E77] 3E77:F6 [ 3] lda 0,x 166 M [3E78] 3E78:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4=#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3E79] 3E79:5F [ 1] clrx 166 M [3E7A] 3E7A:9E6D 01 [ 5] tst 1,asp 166 M [3E7D] 3E7D:2A01 (3E80) [ 3] bpl *+3 166 M [3E7F] 3E7F:53 [ 1] !comx 166 M [3E80] 3E80:89 [ 2] pshx:2 166 M [3E81] 3E81:89 [ 2] 166 M mexit 166 M mloop :nn 166 M @@_Eval_ a 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M 166 M 166 M 166 M 166 M 166 M mset 9 166 M 166 M @Load48 a 166 M @_DoLoad 48=a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3E82] 3E82:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3E85] 3E85:E603 [ 3] lda 3,x 166 M [3E87] 3E87:87 [ 2] psha 166 M mloop 4 166 M [3E88] 3E88:E602 [ 3] lda 2,x 166 M [3E8A] 3E8A:87 [ 2] psha 166 M mloop 4 166 M [3E8B] 3E8B:E601 [ 3] lda 1,x 166 M [3E8D] 3E8D:87 [ 2] psha 166 M mloop 4 166 M [3E8E] 3E8E:F6 [ 3] lda 0,x 166 M [3E8F] 3E8F:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4=#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3E90] 3E90:5F [ 1] clrx 166 M [3E91] 3E91:9E6D 01 [ 5] tst 1,asp 166 M [3E94] 3E94:2A01 (3E97) [ 3] bpl *+3 166 M [3E96] 3E96:53 [ 1] !comx 166 M [3E97] 3E97:89 [ 2] pshx:2 166 M [3E98] 3E98:89 [ 2] 166 M mexit 166 M mdo 2 166 M @@Msg Sub48 166 M mexit 166 M [3E99] 3E99:CD26 42 [ 6] call StackSub48 166 M #spadd -6 166 M mloop :nn 166 M mexit 166 M @@Msg Abs48 166 M mexit 166 M [3E9C] 3E9C:CD29 C0 [ 6] call StackAbs48 166 M mexit 166 M mloop :nn 166 M @@_Eval_ abs(a+b) 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M 166 M 166 M @@_Eval_ a+b 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M mdo 2 166 M @@_Eval_ b 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M 166 M 166 M 166 M 166 M 166 M mset 9 166 M 166 M @Load48 b 166 M @_DoLoad 48=b 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ b 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ b 166 M mexit 166 M @@pushv b 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV b (32-bit) 166 M mexit 166 M #push 166 M @@lea b 166 M mset # 166 M [3E9F] 3E9F:4501 08 [ 3] ldhx #b 166 M endm 166 M #x 166 M mdo 166 M [3EA2] 3EA2:E603 [ 3] lda 3,x 166 M [3EA4] 3EA4:87 [ 2] psha 166 M mloop 4 166 M [3EA5] 3EA5:E602 [ 3] lda 2,x 166 M [3EA7] 3EA7:87 [ 2] psha 166 M mloop 4 166 M [3EA8] 3EA8:E601 [ 3] lda 1,x 166 M [3EAA] 3EAA:87 [ 2] psha 166 M mloop 4 166 M [3EAB] 3EAB:F6 [ 3] lda 0,x 166 M [3EAC] 3EAC:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ b 166 M mexit 166 M @ResizeTOS #4=#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3EAD] 3EAD:5F [ 1] clrx 166 M [3EAE] 3EAE:9E6D 01 [ 5] tst 1,asp 166 M [3EB1] 3EB1:2A01 (3EB4) [ 3] bpl *+3 166 M [3EB3] 3EB3:53 [ 1] !comx 166 M [3EB4] 3EB4:89 [ 2] pshx:2 166 M [3EB5] 3EB5:89 [ 2] 166 M mexit 166 M mloop :nn 166 M @@_Eval_ a 166 M mset # 166 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 166 M 166 M 166 M 166 M 166 M mset #'+-|^' 166 M 166 M mset #'*\/&><' 166 M 166 M 166 M 166 M 166 M 166 M mset 9 166 M 166 M @Load48 a 166 M @_DoLoad 48=a 166 M mreq 1:BitSize[,Variable] 166 M #temp 48/8 166 M mdel 1 166 M mset # 166 M mtrim 1 166 M 166 M mset 9 166 M 166 M @@_not_x_ a 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M 166 M 166 M @@_?sei_ a 166 M mexit 166 M @@pushv a 166 M mset #' ' 166 M mset 0 166 M mreq 1:variable[ SizeOf(var)][ 'newname'] 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PushV a (32-bit) 166 M mexit 166 M #push 166 M @@lea a 166 M mset # 166 M [3EB6] 3EB6:4501 00 [ 3] ldhx #a 166 M endm 166 M #x 166 M mdo 166 M [3EB9] 3EB9:E603 [ 3] lda 3,x 166 M [3EBB] 3EBB:87 [ 2] psha 166 M mloop 4 166 M [3EBC] 3EBC:E602 [ 3] lda 2,x 166 M [3EBE] 3EBE:87 [ 2] psha 166 M mloop 4 166 M [3EBF] 3EBF:E601 [ 3] lda 1,x 166 M [3EC1] 3EC1:87 [ 2] psha 166 M mloop 4 166 M [3EC2] 3EC2:F6 [ 3] lda 0,x 166 M [3EC3] 3EC3:87 [ 2] psha 166 M mloop 4 166 M #pull 166 M #spadd 4 166 M endm 166 M @@_?cli_ a 166 M mexit 166 M @ResizeTOS #4=#6 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 6-4 166 M @@Msg Signed 32-bit => 48-bit 166 M mexit 166 M [3EC4] 3EC4:5F [ 1] clrx 166 M [3EC5] 3EC5:9E6D 01 [ 5] tst 1,asp 166 M [3EC8] 3EC8:2A01 (3ECB) [ 3] bpl *+3 166 M [3ECA] 3ECA:53 [ 1] !comx 166 M [3ECB] 3ECB:89 [ 2] pshx:2 166 M [3ECC] 3ECC:89 [ 2] 166 M mexit 166 M mdo 2 166 M @@Msg Add48 166 M mexit 166 M [3ECD] 3ECD:CD26 2C [ 6] call StackAdd48 166 M #spadd -6 166 M mloop :nn 166 M mexit 166 M @@Msg Abs48 166 M mexit 166 M [3ED0] 3ED0:CD29 C0 [ 6] call StackAbs48 166 M mexit 166 M mdo 2 166 M @@Msg Mul48 166 M mexit 166 M [3ED3] 3ED3:CD27 39 [ 6] call StackMul48 166 M #spadd -6 166 M mloop :nn 166 M @@Msg Div48 166 M mexit 166 M [3ED6] 3ED6:CD27 92 [ 6] call StackDiv48 166 M #spadd -6 166 M mloop :nn 166 M mexit 166 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 166 M mset 9 166 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 166 M @Save48 ans 166 M @_DoSave 48=ans 166 M mreq 1:BitSize[,Variable] 166 M mset 2,ans 166 M mtrim 2 166 M 166 M mset 9 166 M 166 M @@_not_x_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M @@ResizeTOS #6=#4 166 M mreq 1,2:#FromByteSize,#ToByteSize 166 M #temp 4-6 166 M @@Msg Signed 48-bit => 32-bit 166 M mexit 166 M [3ED9] 3ED9:A702 [ 2] ais #-:temp 166 M mexit 166 M @@_?sei_ ans 166 M mexit 166 M @@pullv ans 166 M mset #' ' 166 M mreq 1:Variable[ SizeOf(Variable)] 166 M @@_not_#_ ans 166 M mset #' ' 166 M mdel 1 166 M mtop 166 M mset #' ' 166 M mexit 166 M mdef 2,4 166 M mdef 2,1 166 M @@Msg PullV ans (32-bit) 166 M mexit 166 M #push 166 M @@lea ans 166 M mset # 166 M [3EDB] 3EDB:4501 10 [ 3] ldhx #ans 166 M endm 166 M #x 166 M mdo 166 M [3EDE] 3EDE:86 [ 3] pula 166 M [3EDF] 3EDF:F7 [ 2] sta 0,x 166 M mloop 4 166 M [3EE0] 3EE0:86 [ 3] pula 166 M [3EE1] 3EE1:E701 [ 3] sta 1,x 166 M mloop 4 166 M [3EE3] 3EE3:86 [ 3] pula 166 M [3EE4] 3EE4:E702 [ 3] sta 2,x 166 M mloop 4 166 M [3EE6] 3EE6:86 [ 3] pula 166 M [3EE7] 3EE7:E703 [ 3] sta 3,x 166 M mloop 4 166 M #pull 166 M #spadd -4 166 M endm 166 M @_?cli_ ans 166 M mexit 166 endm 167 M @Test 56 167 M ;------------------------------------------------------------------------------- 167 M ; Test the 56-bit version 167 M ;------------------------------------------------------------------------------- 167 M 167 M ;------------------------------------------------------------------------------- 167 M ; @@Load56 a 167 M ;------------------------------------------------------------------------------- 167 M @@Load56 a 167 M @_DoLoad 56,a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [3EE9] 3EE9:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [3EEC] 3EEC:E603 [ 3] lda 3,x 167 M [3EEE] 3EEE:87 [ 2] psha 167 M mloop 4 167 M [3EEF] 3EEF:E602 [ 3] lda 2,x 167 M [3EF1] 3EF1:87 [ 2] psha 167 M mloop 4 167 M [3EF2] 3EF2:E601 [ 3] lda 1,x 167 M [3EF4] 3EF4:87 [ 2] psha 167 M mloop 4 167 M [3EF5] 3EF5:F6 [ 3] lda 0,x 167 M [3EF6] 3EF6:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3EF7] 3EF7:5F [ 1] clrx 167 M [3EF8] 3EF8:9E6D 01 [ 5] tst 1,asp 167 M [3EFB] 3EFB:2A01 (3EFE) [ 3] bpl *+3 167 M [3EFD] 3EFD:53 [ 1] !comx 167 M [3EFE] 3EFE:89 [ 2] pshx:3 167 M [3EFF] 3EFF:89 [ 2] 167 M [3F00] 3F00:89 [ 2] 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Load56 b 167 M ;------------------------------------------------------------------------------- 167 M @@Load56 b 167 M @_DoLoad 56,b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [3F01] 3F01:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [3F04] 3F04:E603 [ 3] lda 3,x 167 M [3F06] 3F06:87 [ 2] psha 167 M mloop 4 167 M [3F07] 3F07:E602 [ 3] lda 2,x 167 M [3F09] 3F09:87 [ 2] psha 167 M mloop 4 167 M [3F0A] 3F0A:E601 [ 3] lda 1,x 167 M [3F0C] 3F0C:87 [ 2] psha 167 M mloop 4 167 M [3F0D] 3F0D:F6 [ 3] lda 0,x 167 M [3F0E] 3F0E:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3F0F] 3F0F:5F [ 1] clrx 167 M [3F10] 3F10:9E6D 01 [ 5] tst 1,asp 167 M [3F13] 3F13:2A01 (3F16) [ 3] bpl *+3 167 M [3F15] 3F15:53 [ 1] !comx 167 M [3F16] 3F16:89 [ 2] pshx:3 167 M [3F17] 3F17:89 [ 2] 167 M [3F18] 3F18:89 [ 2] 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Swap56 167 M ;------------------------------------------------------------------------------- 167 M @@Swap56 167 M @_DoSwap 56 167 M [3F19] 3F19:CD2E 70 [ 6] call StackSwap56 167 M endm 167 M ;------------------------------------------------------------------------------- 167 M ; @@Save56 ans 167 M ;------------------------------------------------------------------------------- 167 M @@Save56 ans 167 M @_DoSave 56,ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7,#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [3F1C] 3F1C:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [3F1E] 3F1E:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [3F21] 3F21:86 [ 3] pula 167 M [3F22] 3F22:F7 [ 2] sta 0,x 167 M mloop 4 167 M [3F23] 3F23:86 [ 3] pula 167 M [3F24] 3F24:E701 [ 3] sta 1,x 167 M mloop 4 167 M [3F26] 3F26:86 [ 3] pula 167 M [3F27] 3F27:E702 [ 3] sta 2,x 167 M mloop 4 167 M [3F29] 3F29:86 [ 3] pula 167 M [3F2A] 3F2A:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Save56 ans 167 M ;------------------------------------------------------------------------------- 167 M @@Save56 ans 167 M @_DoSave 56,ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7,#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [3F2C] 3F2C:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [3F2E] 3F2E:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [3F31] 3F31:86 [ 3] pula 167 M [3F32] 3F32:F7 [ 2] sta 0,x 167 M mloop 4 167 M [3F33] 3F33:86 [ 3] pula 167 M [3F34] 3F34:E701 [ 3] sta 1,x 167 M mloop 4 167 M [3F36] 3F36:86 [ 3] pula 167 M [3F37] 3F37:E702 [ 3] sta 2,x 167 M mloop 4 167 M [3F39] 3F39:86 [ 3] pula 167 M [3F3A] 3F3A:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Add56 a,b,ans 167 M ;------------------------------------------------------------------------------- 167 M @@Add56 a,b,ans 167 M @_DoMath Add56,56,a,b,ans 167 M @@Load56 b 167 M @_DoLoad 56,b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [3F3C] 3F3C:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [3F3F] 3F3F:E603 [ 3] lda 3,x 167 M [3F41] 3F41:87 [ 2] psha 167 M mloop 4 167 M [3F42] 3F42:E602 [ 3] lda 2,x 167 M [3F44] 3F44:87 [ 2] psha 167 M mloop 4 167 M [3F45] 3F45:E601 [ 3] lda 1,x 167 M [3F47] 3F47:87 [ 2] psha 167 M mloop 4 167 M [3F48] 3F48:F6 [ 3] lda 0,x 167 M [3F49] 3F49:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3F4A] 3F4A:5F [ 1] clrx 167 M [3F4B] 3F4B:9E6D 01 [ 5] tst 1,asp 167 M [3F4E] 3F4E:2A01 (3F51) [ 3] bpl *+3 167 M [3F50] 3F50:53 [ 1] !comx 167 M [3F51] 3F51:89 [ 2] pshx:3 167 M [3F52] 3F52:89 [ 2] 167 M [3F53] 3F53:89 [ 2] 167 M mexit 167 M @@Load56 a 167 M @_DoLoad 56,a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [3F54] 3F54:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [3F57] 3F57:E603 [ 3] lda 3,x 167 M [3F59] 3F59:87 [ 2] psha 167 M mloop 4 167 M [3F5A] 3F5A:E602 [ 3] lda 2,x 167 M [3F5C] 3F5C:87 [ 2] psha 167 M mloop 4 167 M [3F5D] 3F5D:E601 [ 3] lda 1,x 167 M [3F5F] 3F5F:87 [ 2] psha 167 M mloop 4 167 M [3F60] 3F60:F6 [ 3] lda 0,x 167 M [3F61] 3F61:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3F62] 3F62:5F [ 1] clrx 167 M [3F63] 3F63:9E6D 01 [ 5] tst 1,asp 167 M [3F66] 3F66:2A01 (3F69) [ 3] bpl *+3 167 M [3F68] 3F68:53 [ 1] !comx 167 M [3F69] 3F69:89 [ 2] pshx:3 167 M [3F6A] 3F6A:89 [ 2] 167 M [3F6B] 3F6B:89 [ 2] 167 M mexit 167 M @@_DoOperation Add56 167 M mdef 2,56 167 M @@Msg Add56 167 M mexit 167 M [3F6C] 3F6C:CD2A 94 [ 6] call StackAdd56 167 M #spadd -56/8 167 M endm 167 M @Save56 ans 167 M @_DoSave 56,ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7,#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [3F6F] 3F6F:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [3F71] 3F71:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [3F74] 3F74:86 [ 3] pula 167 M [3F75] 3F75:F7 [ 2] sta 0,x 167 M mloop 4 167 M [3F76] 3F76:86 [ 3] pula 167 M [3F77] 3F77:E701 [ 3] sta 1,x 167 M mloop 4 167 M [3F79] 3F79:86 [ 3] pula 167 M [3F7A] 3F7A:E702 [ 3] sta 2,x 167 M mloop 4 167 M [3F7C] 3F7C:86 [ 3] pula 167 M [3F7D] 3F7D:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Sub56 a,b,ans 167 M ;------------------------------------------------------------------------------- 167 M @@Sub56 a,b,ans 167 M @_DoMath Sub56,56,a,b,ans 167 M @@Load56 b 167 M @_DoLoad 56,b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [3F7F] 3F7F:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [3F82] 3F82:E603 [ 3] lda 3,x 167 M [3F84] 3F84:87 [ 2] psha 167 M mloop 4 167 M [3F85] 3F85:E602 [ 3] lda 2,x 167 M [3F87] 3F87:87 [ 2] psha 167 M mloop 4 167 M [3F88] 3F88:E601 [ 3] lda 1,x 167 M [3F8A] 3F8A:87 [ 2] psha 167 M mloop 4 167 M [3F8B] 3F8B:F6 [ 3] lda 0,x 167 M [3F8C] 3F8C:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3F8D] 3F8D:5F [ 1] clrx 167 M [3F8E] 3F8E:9E6D 01 [ 5] tst 1,asp 167 M [3F91] 3F91:2A01 (3F94) [ 3] bpl *+3 167 M [3F93] 3F93:53 [ 1] !comx 167 M [3F94] 3F94:89 [ 2] pshx:3 167 M [3F95] 3F95:89 [ 2] 167 M [3F96] 3F96:89 [ 2] 167 M mexit 167 M @@Load56 a 167 M @_DoLoad 56,a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [3F97] 3F97:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [3F9A] 3F9A:E603 [ 3] lda 3,x 167 M [3F9C] 3F9C:87 [ 2] psha 167 M mloop 4 167 M [3F9D] 3F9D:E602 [ 3] lda 2,x 167 M [3F9F] 3F9F:87 [ 2] psha 167 M mloop 4 167 M [3FA0] 3FA0:E601 [ 3] lda 1,x 167 M [3FA2] 3FA2:87 [ 2] psha 167 M mloop 4 167 M [3FA3] 3FA3:F6 [ 3] lda 0,x 167 M [3FA4] 3FA4:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3FA5] 3FA5:5F [ 1] clrx 167 M [3FA6] 3FA6:9E6D 01 [ 5] tst 1,asp 167 M [3FA9] 3FA9:2A01 (3FAC) [ 3] bpl *+3 167 M [3FAB] 3FAB:53 [ 1] !comx 167 M [3FAC] 3FAC:89 [ 2] pshx:3 167 M [3FAD] 3FAD:89 [ 2] 167 M [3FAE] 3FAE:89 [ 2] 167 M mexit 167 M @@_DoOperation Sub56 167 M mdef 2,56 167 M @@Msg Sub56 167 M mexit 167 M [3FAF] 3FAF:CD2A AA [ 6] call StackSub56 167 M #spadd -56/8 167 M endm 167 M @Save56 ans 167 M @_DoSave 56,ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7,#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [3FB2] 3FB2:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [3FB4] 3FB4:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [3FB7] 3FB7:86 [ 3] pula 167 M [3FB8] 3FB8:F7 [ 2] sta 0,x 167 M mloop 4 167 M [3FB9] 3FB9:86 [ 3] pula 167 M [3FBA] 3FBA:E701 [ 3] sta 1,x 167 M mloop 4 167 M [3FBC] 3FBC:86 [ 3] pula 167 M [3FBD] 3FBD:E702 [ 3] sta 2,x 167 M mloop 4 167 M [3FBF] 3FBF:86 [ 3] pula 167 M [3FC0] 3FC0:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Mul56 a,b,ans 167 M ;------------------------------------------------------------------------------- 167 M @@Mul56 a,b,ans 167 M @_DoMath Mul56,56,a,b,ans 167 M @@Load56 b 167 M @_DoLoad 56,b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [3FC2] 3FC2:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [3FC5] 3FC5:E603 [ 3] lda 3,x 167 M [3FC7] 3FC7:87 [ 2] psha 167 M mloop 4 167 M [3FC8] 3FC8:E602 [ 3] lda 2,x 167 M [3FCA] 3FCA:87 [ 2] psha 167 M mloop 4 167 M [3FCB] 3FCB:E601 [ 3] lda 1,x 167 M [3FCD] 3FCD:87 [ 2] psha 167 M mloop 4 167 M [3FCE] 3FCE:F6 [ 3] lda 0,x 167 M [3FCF] 3FCF:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3FD0] 3FD0:5F [ 1] clrx 167 M [3FD1] 3FD1:9E6D 01 [ 5] tst 1,asp 167 M [3FD4] 3FD4:2A01 (3FD7) [ 3] bpl *+3 167 M [3FD6] 3FD6:53 [ 1] !comx 167 M [3FD7] 3FD7:89 [ 2] pshx:3 167 M [3FD8] 3FD8:89 [ 2] 167 M [3FD9] 3FD9:89 [ 2] 167 M mexit 167 M @@Load56 a 167 M @_DoLoad 56,a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [3FDA] 3FDA:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [3FDD] 3FDD:E603 [ 3] lda 3,x 167 M [3FDF] 3FDF:87 [ 2] psha 167 M mloop 4 167 M [3FE0] 3FE0:E602 [ 3] lda 2,x 167 M [3FE2] 3FE2:87 [ 2] psha 167 M mloop 4 167 M [3FE3] 3FE3:E601 [ 3] lda 1,x 167 M [3FE5] 3FE5:87 [ 2] psha 167 M mloop 4 167 M [3FE6] 3FE6:F6 [ 3] lda 0,x 167 M [3FE7] 3FE7:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [3FE8] 3FE8:5F [ 1] clrx 167 M [3FE9] 3FE9:9E6D 01 [ 5] tst 1,asp 167 M [3FEC] 3FEC:2A01 (3FEF) [ 3] bpl *+3 167 M [3FEE] 3FEE:53 [ 1] !comx 167 M [3FEF] 3FEF:89 [ 2] pshx:3 167 M [3FF0] 3FF0:89 [ 2] 167 M [3FF1] 3FF1:89 [ 2] 167 M mexit 167 M @@_DoOperation Mul56 167 M mdef 2,56 167 M @@Msg Mul56 167 M mexit 167 M [3FF2] 3FF2:CD2B B5 [ 6] call StackMul56 167 M #spadd -56/8 167 M endm 167 M @Save56 ans 167 M @_DoSave 56,ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7,#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [3FF5] 3FF5:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [3FF7] 3FF7:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [3FFA] 3FFA:86 [ 3] pula 167 M [3FFB] 3FFB:F7 [ 2] sta 0,x 167 M mloop 4 167 M [3FFC] 3FFC:86 [ 3] pula 167 M [3FFD] 3FFD:E701 [ 3] sta 1,x 167 M mloop 4 167 M [3FFF] 3FFF:86 [ 3] pula 167 M [4000] 4000:E702 [ 3] sta 2,x 167 M mloop 4 167 M [4002] 4002:86 [ 3] pula 167 M [4003] 4003:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Div56 a,b,ans 167 M ;------------------------------------------------------------------------------- 167 M @@Div56 a,b,ans 167 M @_DoMath Div56,56,a,b,ans 167 M @@Load56 b 167 M @_DoLoad 56,b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [4005] 4005:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [4008] 4008:E603 [ 3] lda 3,x 167 M [400A] 400A:87 [ 2] psha 167 M mloop 4 167 M [400B] 400B:E602 [ 3] lda 2,x 167 M [400D] 400D:87 [ 2] psha 167 M mloop 4 167 M [400E] 400E:E601 [ 3] lda 1,x 167 M [4010] 4010:87 [ 2] psha 167 M mloop 4 167 M [4011] 4011:F6 [ 3] lda 0,x 167 M [4012] 4012:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [4013] 4013:5F [ 1] clrx 167 M [4014] 4014:9E6D 01 [ 5] tst 1,asp 167 M [4017] 4017:2A01 (401A) [ 3] bpl *+3 167 M [4019] 4019:53 [ 1] !comx 167 M [401A] 401A:89 [ 2] pshx:3 167 M [401B] 401B:89 [ 2] 167 M [401C] 401C:89 [ 2] 167 M mexit 167 M @@Load56 a 167 M @_DoLoad 56,a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [401D] 401D:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [4020] 4020:E603 [ 3] lda 3,x 167 M [4022] 4022:87 [ 2] psha 167 M mloop 4 167 M [4023] 4023:E602 [ 3] lda 2,x 167 M [4025] 4025:87 [ 2] psha 167 M mloop 4 167 M [4026] 4026:E601 [ 3] lda 1,x 167 M [4028] 4028:87 [ 2] psha 167 M mloop 4 167 M [4029] 4029:F6 [ 3] lda 0,x 167 M [402A] 402A:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [402B] 402B:5F [ 1] clrx 167 M [402C] 402C:9E6D 01 [ 5] tst 1,asp 167 M [402F] 402F:2A01 (4032) [ 3] bpl *+3 167 M [4031] 4031:53 [ 1] !comx 167 M [4032] 4032:89 [ 2] pshx:3 167 M [4033] 4033:89 [ 2] 167 M [4034] 4034:89 [ 2] 167 M mexit 167 M @@_DoOperation Div56 167 M mdef 2,56 167 M @@Msg Div56 167 M mexit 167 M [4035] 4035:CD2C 18 [ 6] call StackDiv56 167 M #spadd -56/8 167 M endm 167 M @Save56 ans 167 M @_DoSave 56,ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7,#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [4038] 4038:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [403A] 403A:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [403D] 403D:86 [ 3] pula 167 M [403E] 403E:F7 [ 2] sta 0,x 167 M mloop 4 167 M [403F] 403F:86 [ 3] pula 167 M [4040] 4040:E701 [ 3] sta 1,x 167 M mloop 4 167 M [4042] 4042:86 [ 3] pula 167 M [4043] 4043:E702 [ 3] sta 2,x 167 M mloop 4 167 M [4045] 4045:86 [ 3] pula 167 M [4046] 4046:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Mod56 a,b,ans 167 M ;------------------------------------------------------------------------------- 167 M @@Mod56 a,b,ans 167 M @_DoMath Mod56,56,a,b,ans 167 M @@Load56 b 167 M @_DoLoad 56,b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [4048] 4048:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [404B] 404B:E603 [ 3] lda 3,x 167 M [404D] 404D:87 [ 2] psha 167 M mloop 4 167 M [404E] 404E:E602 [ 3] lda 2,x 167 M [4050] 4050:87 [ 2] psha 167 M mloop 4 167 M [4051] 4051:E601 [ 3] lda 1,x 167 M [4053] 4053:87 [ 2] psha 167 M mloop 4 167 M [4054] 4054:F6 [ 3] lda 0,x 167 M [4055] 4055:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [4056] 4056:5F [ 1] clrx 167 M [4057] 4057:9E6D 01 [ 5] tst 1,asp 167 M [405A] 405A:2A01 (405D) [ 3] bpl *+3 167 M [405C] 405C:53 [ 1] !comx 167 M [405D] 405D:89 [ 2] pshx:3 167 M [405E] 405E:89 [ 2] 167 M [405F] 405F:89 [ 2] 167 M mexit 167 M @@Load56 a 167 M @_DoLoad 56,a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [4060] 4060:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [4063] 4063:E603 [ 3] lda 3,x 167 M [4065] 4065:87 [ 2] psha 167 M mloop 4 167 M [4066] 4066:E602 [ 3] lda 2,x 167 M [4068] 4068:87 [ 2] psha 167 M mloop 4 167 M [4069] 4069:E601 [ 3] lda 1,x 167 M [406B] 406B:87 [ 2] psha 167 M mloop 4 167 M [406C] 406C:F6 [ 3] lda 0,x 167 M [406D] 406D:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [406E] 406E:5F [ 1] clrx 167 M [406F] 406F:9E6D 01 [ 5] tst 1,asp 167 M [4072] 4072:2A01 (4075) [ 3] bpl *+3 167 M [4074] 4074:53 [ 1] !comx 167 M [4075] 4075:89 [ 2] pshx:3 167 M [4076] 4076:89 [ 2] 167 M [4077] 4077:89 [ 2] 167 M mexit 167 M @@_DoOperation Mod56 167 M mdef 2,56 167 M @@Msg Mod56 167 M mexit 167 M [4078] 4078:CD2C 2B [ 6] call StackMod56 167 M #spadd -56/8 167 M endm 167 M @Save56 ans 167 M @_DoSave 56,ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7,#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [407B] 407B:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [407D] 407D:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [4080] 4080:86 [ 3] pula 167 M [4081] 4081:F7 [ 2] sta 0,x 167 M mloop 4 167 M [4082] 4082:86 [ 3] pula 167 M [4083] 4083:E701 [ 3] sta 1,x 167 M mloop 4 167 M [4085] 4085:86 [ 3] pula 167 M [4086] 4086:E702 [ 3] sta 2,x 167 M mloop 4 167 M [4088] 4088:86 [ 3] pula 167 M [4089] 4089:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 M ;------------------------------------------------------------------------------- 167 M ; @@Neg56 ans 167 M ;------------------------------------------------------------------------------- 167 M @@Neg56 ans 167 M @_DoNeg 56,ans 167 M @@Msg Neg56 ans 167 M mexit 167 M @@_FindStkMth_ 56 167 M #temp 167 M mdo 56/8 167 M #temp :mloop*8 167 M mloop 8 167 M mloop 8 167 M mexit :temp 167 M mset 1,56 167 M @@Load56 ans 167 M @_DoLoad 56,ans 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ ans 167 M mexit 167 M @@pushv ans 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [408B] 408B:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [408E] 408E:E603 [ 3] lda 3,x 167 M [4090] 4090:87 [ 2] psha 167 M mloop 4 167 M [4091] 4091:E602 [ 3] lda 2,x 167 M [4093] 4093:87 [ 2] psha 167 M mloop 4 167 M [4094] 4094:E601 [ 3] lda 1,x 167 M [4096] 4096:87 [ 2] psha 167 M mloop 4 167 M [4097] 4097:F6 [ 3] lda 0,x 167 M [4098] 4098:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ ans 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [4099] 4099:5F [ 1] clrx 167 M [409A] 409A:9E6D 01 [ 5] tst 1,asp 167 M [409D] 409D:2A01 (40A0) [ 3] bpl *+3 167 M [409F] 409F:53 [ 1] !comx 167 M [40A0] 40A0:89 [ 2] pshx:3 167 M [40A1] 40A1:89 [ 2] 167 M [40A2] 40A2:89 [ 2] 167 M mexit 167 M [40A3] 40A3:CD2E 91 [ 6] call StackNegate56 167 M @Save56 167 M @_DoSave 56 167 M mreq 1:BitSize[,Variable] 167 M mset 2 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ 167 M mset #' ' 167 M mexit 167 M @@Msg Save56 167 M mexit 167 M @@lea 167 M mset # 167 M mexit 167 M @@_?sei_ 167 M mexit 167 M [40A6] 40A6:CD2E CF [ 6] call StackSave56 167 M @@_?cli_ 167 M mexit 167 M #spadd -56/8 167 M endm 167 M ;------------------------------------------------------------------------------- 167 M ; @@Abs56 ans 167 M ;------------------------------------------------------------------------------- 167 M @@Abs56 ans 167 M @_DoAbs 56,ans 167 M @@Msg Abs56 ans 167 M mexit 167 M @@_FindStkMth_ 56 167 M #temp 167 M mdo 56/8 167 M #temp :mloop*8 167 M mloop 8 167 M mloop 8 167 M mexit :temp 167 M mset 1,56 167 M @@Load56 ans 167 M @_DoLoad 56,ans 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ ans 167 M mexit 167 M @@pushv ans 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [40A9] 40A9:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [40AC] 40AC:E603 [ 3] lda 3,x 167 M [40AE] 40AE:87 [ 2] psha 167 M mloop 4 167 M [40AF] 40AF:E602 [ 3] lda 2,x 167 M [40B1] 40B1:87 [ 2] psha 167 M mloop 4 167 M [40B2] 40B2:E601 [ 3] lda 1,x 167 M [40B4] 40B4:87 [ 2] psha 167 M mloop 4 167 M [40B5] 40B5:F6 [ 3] lda 0,x 167 M [40B6] 40B6:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ ans 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [40B7] 40B7:5F [ 1] clrx 167 M [40B8] 40B8:9E6D 01 [ 5] tst 1,asp 167 M [40BB] 40BB:2A01 (40BE) [ 3] bpl *+3 167 M [40BD] 40BD:53 [ 1] !comx 167 M [40BE] 40BE:89 [ 2] pshx:3 167 M [40BF] 40BF:89 [ 2] 167 M [40C0] 40C0:89 [ 2] 167 M mexit 167 M [40C1] 40C1:CD2E 8C [ 6] call StackAbs56 167 M @Save56 167 M @_DoSave 56 167 M mreq 1:BitSize[,Variable] 167 M mset 2 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ 167 M mset #' ' 167 M mexit 167 M @@Msg Save56 167 M mexit 167 M @@lea 167 M mset # 167 M mexit 167 M @@_?sei_ 167 M mexit 167 M [40C4] 40C4:CD2E CF [ 6] call StackSave56 167 M @@_?cli_ 167 M mexit 167 M #spadd -56/8 167 M endm 167 M ;------------------------------------------------------------------------------- 167 M ; @@Str56 ans,String 167 M ;------------------------------------------------------------------------------- 167 M @@Str56 ans,String 167 M @_DoStr 56,ans,String 167 M @@_FindStkMth_ 56 167 M #temp 167 M mdo 56/8 167 M #temp :mloop*8 167 M mloop 8 167 M mloop 8 167 M mexit :temp 167 M mset 1,56 167 M @@Load56 ans 167 M @_DoLoad 56,ans 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ ans 167 M mexit 167 M @@pushv ans 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [40C7] 40C7:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [40CA] 40CA:E603 [ 3] lda 3,x 167 M [40CC] 40CC:87 [ 2] psha 167 M mloop 4 167 M [40CD] 40CD:E602 [ 3] lda 2,x 167 M [40CF] 40CF:87 [ 2] psha 167 M mloop 4 167 M [40D0] 40D0:E601 [ 3] lda 1,x 167 M [40D2] 40D2:87 [ 2] psha 167 M mloop 4 167 M [40D3] 40D3:F6 [ 3] lda 0,x 167 M [40D4] 40D4:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ ans 167 M mexit 167 M @ResizeTOS #4,#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [40D5] 40D5:5F [ 1] clrx 167 M [40D6] 40D6:9E6D 01 [ 5] tst 1,asp 167 M [40D9] 40D9:2A01 (40DC) [ 3] bpl *+3 167 M [40DB] 40DB:53 [ 1] !comx 167 M [40DC] 40DC:89 [ 2] pshx:3 167 M [40DD] 40DD:89 [ 2] 167 M [40DE] 40DE:89 [ 2] 167 M mexit 167 M @@Msg Convert 'ans' (32-bit) to ASCIZ in 'String' 167 M mexit 167 M @@lea String 167 M mset # 167 M [40DF] 40DF:4501 18 [ 3] ldhx #String 167 M endm 167 M [40E2] 40E2:CD2F 03 [ 6] call Stack56ToASCIZ 167 M [40E5] 40E5:A707 [ 2] ais #56/8 167 M endm 167 M ;------------------------------------------------------------------------------- 167 M ; @@Eval56 ans = (a + b) * abs(a - b) / 2 167 M ;------------------------------------------------------------------------------- 167 M @@Eval56 ans = abs(a + b) * abs(a - b) / 2 167 M mset # 167 M @_Eval_ 56,ans = abs(a + b) * abs(a - b) / 2 167 M @@_needs_spauto_ 167 M mexit 167 M mdef 1,32 167 M mswap 0,1 167 M mdel 1 167 M mset # 167 M @@Msg -------------------------------------------------- 167 M mexit 167 M @@Msg Expr: ans = abs(a + b) * abs(a - b) / 2 167 M mexit 167 M @@Msg -------------------------------------------------- 167 M mexit 167 M @@_FindStkMth_ 56 167 M #temp 167 M mdo 56/8 167 M #temp :mloop*8 167 M mloop 8 167 M mloop 8 167 M mexit :temp 167 M mset 0,56,56 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M mtrim 1 167 M mset #'=' 167 M @@_Eval_ abs(a+b)*abs(a-b)/2 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M mdo 2 167 M @@_Eval_ 2 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M 167 M 167 M 167 M 167 M 167 M mset 9 167 M 167 M mset 1,#2 167 M mset 1,#2 167 M @Load56 #2 167 M @_DoLoad 56=#2 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ #2 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M mset 1,#2 167 M @@Msg Load56 #2 167 M mexit 167 M mset 1,2 167 M mset 0 167 M mdo 167 M [40E7] 40E7:AE02 [ 2] ldx #2>0&$FF 167 M [40E9] 40E9:89 [ 2] pshx 167 M mloop :temp 167 M [40EA] 40EA:8C [ 1] clrh 167 M mset 0,clrh 167 M [40EB] 40EB:8B [ 2] pshh 167 M mloop :temp 167 M [40EC] 40EC:8B [ 2] pshh 167 M mloop :temp 167 M [40ED] 40ED:8B [ 2] pshh 167 M mloop :temp 167 M [40EE] 40EE:8B [ 2] pshh 167 M mloop :temp 167 M [40EF] 40EF:8B [ 2] pshh 167 M mloop :temp 167 M [40F0] 40F0:8B [ 2] pshh 167 M mloop :temp 167 M mexit 167 M mloop :nn 167 M @@_Eval_ abs(a-b) 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M 167 M 167 M @@_Eval_ a-b 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M mdo 2 167 M @@_Eval_ b 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M 167 M 167 M 167 M 167 M 167 M mset 9 167 M 167 M @Load56 b 167 M @_DoLoad 56=b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [40F1] 40F1:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [40F4] 40F4:E603 [ 3] lda 3,x 167 M [40F6] 40F6:87 [ 2] psha 167 M mloop 4 167 M [40F7] 40F7:E602 [ 3] lda 2,x 167 M [40F9] 40F9:87 [ 2] psha 167 M mloop 4 167 M [40FA] 40FA:E601 [ 3] lda 1,x 167 M [40FC] 40FC:87 [ 2] psha 167 M mloop 4 167 M [40FD] 40FD:F6 [ 3] lda 0,x 167 M [40FE] 40FE:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4=#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [40FF] 40FF:5F [ 1] clrx 167 M [4100] 4100:9E6D 01 [ 5] tst 1,asp 167 M [4103] 4103:2A01 (4106) [ 3] bpl *+3 167 M [4105] 4105:53 [ 1] !comx 167 M [4106] 4106:89 [ 2] pshx:3 167 M [4107] 4107:89 [ 2] 167 M [4108] 4108:89 [ 2] 167 M mexit 167 M mloop :nn 167 M @@_Eval_ a 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M 167 M 167 M 167 M 167 M 167 M mset 9 167 M 167 M @Load56 a 167 M @_DoLoad 56=a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [4109] 4109:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [410C] 410C:E603 [ 3] lda 3,x 167 M [410E] 410E:87 [ 2] psha 167 M mloop 4 167 M [410F] 410F:E602 [ 3] lda 2,x 167 M [4111] 4111:87 [ 2] psha 167 M mloop 4 167 M [4112] 4112:E601 [ 3] lda 1,x 167 M [4114] 4114:87 [ 2] psha 167 M mloop 4 167 M [4115] 4115:F6 [ 3] lda 0,x 167 M [4116] 4116:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4=#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [4117] 4117:5F [ 1] clrx 167 M [4118] 4118:9E6D 01 [ 5] tst 1,asp 167 M [411B] 411B:2A01 (411E) [ 3] bpl *+3 167 M [411D] 411D:53 [ 1] !comx 167 M [411E] 411E:89 [ 2] pshx:3 167 M [411F] 411F:89 [ 2] 167 M [4120] 4120:89 [ 2] 167 M mexit 167 M mdo 2 167 M @@Msg Sub56 167 M mexit 167 M [4121] 4121:CD2A AA [ 6] call StackSub56 167 M #spadd -7 167 M mloop :nn 167 M mexit 167 M @@Msg Abs56 167 M mexit 167 M [4124] 4124:CD2E 8C [ 6] call StackAbs56 167 M mexit 167 M mloop :nn 167 M @@_Eval_ abs(a+b) 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M 167 M 167 M @@_Eval_ a+b 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M mdo 2 167 M @@_Eval_ b 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M 167 M 167 M 167 M 167 M 167 M mset 9 167 M 167 M @Load56 b 167 M @_DoLoad 56=b 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ b 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ b 167 M mexit 167 M @@pushv b 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV b (32-bit) 167 M mexit 167 M #push 167 M @@lea b 167 M mset # 167 M [4127] 4127:4501 08 [ 3] ldhx #b 167 M endm 167 M #x 167 M mdo 167 M [412A] 412A:E603 [ 3] lda 3,x 167 M [412C] 412C:87 [ 2] psha 167 M mloop 4 167 M [412D] 412D:E602 [ 3] lda 2,x 167 M [412F] 412F:87 [ 2] psha 167 M mloop 4 167 M [4130] 4130:E601 [ 3] lda 1,x 167 M [4132] 4132:87 [ 2] psha 167 M mloop 4 167 M [4133] 4133:F6 [ 3] lda 0,x 167 M [4134] 4134:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ b 167 M mexit 167 M @ResizeTOS #4=#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [4135] 4135:5F [ 1] clrx 167 M [4136] 4136:9E6D 01 [ 5] tst 1,asp 167 M [4139] 4139:2A01 (413C) [ 3] bpl *+3 167 M [413B] 413B:53 [ 1] !comx 167 M [413C] 413C:89 [ 2] pshx:3 167 M [413D] 413D:89 [ 2] 167 M [413E] 413E:89 [ 2] 167 M mexit 167 M mloop :nn 167 M @@_Eval_ a 167 M mset # 167 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 167 M 167 M 167 M 167 M 167 M mset #'+-|^' 167 M 167 M mset #'*\/&><' 167 M 167 M 167 M 167 M 167 M 167 M mset 9 167 M 167 M @Load56 a 167 M @_DoLoad 56=a 167 M mreq 1:BitSize[,Variable] 167 M #temp 56/8 167 M mdel 1 167 M mset # 167 M mtrim 1 167 M 167 M mset 9 167 M 167 M @@_not_x_ a 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M 167 M 167 M @@_?sei_ a 167 M mexit 167 M @@pushv a 167 M mset #' ' 167 M mset 0 167 M mreq 1:variable[ SizeOf(var)][ 'newname'] 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PushV a (32-bit) 167 M mexit 167 M #push 167 M @@lea a 167 M mset # 167 M [413F] 413F:4501 00 [ 3] ldhx #a 167 M endm 167 M #x 167 M mdo 167 M [4142] 4142:E603 [ 3] lda 3,x 167 M [4144] 4144:87 [ 2] psha 167 M mloop 4 167 M [4145] 4145:E602 [ 3] lda 2,x 167 M [4147] 4147:87 [ 2] psha 167 M mloop 4 167 M [4148] 4148:E601 [ 3] lda 1,x 167 M [414A] 414A:87 [ 2] psha 167 M mloop 4 167 M [414B] 414B:F6 [ 3] lda 0,x 167 M [414C] 414C:87 [ 2] psha 167 M mloop 4 167 M #pull 167 M #spadd 4 167 M endm 167 M @@_?cli_ a 167 M mexit 167 M @ResizeTOS #4=#7 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 7-4 167 M @@Msg Signed 32-bit => 56-bit 167 M mexit 167 M [414D] 414D:5F [ 1] clrx 167 M [414E] 414E:9E6D 01 [ 5] tst 1,asp 167 M [4151] 4151:2A01 (4154) [ 3] bpl *+3 167 M [4153] 4153:53 [ 1] !comx 167 M [4154] 4154:89 [ 2] pshx:3 167 M [4155] 4155:89 [ 2] 167 M [4156] 4156:89 [ 2] 167 M mexit 167 M mdo 2 167 M @@Msg Add56 167 M mexit 167 M [4157] 4157:CD2A 94 [ 6] call StackAdd56 167 M #spadd -7 167 M mloop :nn 167 M mexit 167 M @@Msg Abs56 167 M mexit 167 M [415A] 415A:CD2E 8C [ 6] call StackAbs56 167 M mexit 167 M mdo 2 167 M @@Msg Mul56 167 M mexit 167 M [415D] 415D:CD2B B5 [ 6] call StackMul56 167 M #spadd -7 167 M mloop :nn 167 M @@Msg Div56 167 M mexit 167 M [4160] 4160:CD2C 18 [ 6] call StackDiv56 167 M #spadd -7 167 M mloop :nn 167 M mexit 167 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 167 M mset 9 167 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 167 M @Save56 ans 167 M @_DoSave 56=ans 167 M mreq 1:BitSize[,Variable] 167 M mset 2,ans 167 M mtrim 2 167 M 167 M mset 9 167 M 167 M @@_not_x_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M @@ResizeTOS #7=#4 167 M mreq 1,2:#FromByteSize,#ToByteSize 167 M #temp 4-7 167 M @@Msg Signed 56-bit => 32-bit 167 M mexit 167 M [4163] 4163:A703 [ 2] ais #-:temp 167 M mexit 167 M @@_?sei_ ans 167 M mexit 167 M @@pullv ans 167 M mset #' ' 167 M mreq 1:Variable[ SizeOf(Variable)] 167 M @@_not_#_ ans 167 M mset #' ' 167 M mdel 1 167 M mtop 167 M mset #' ' 167 M mexit 167 M mdef 2,4 167 M mdef 2,1 167 M @@Msg PullV ans (32-bit) 167 M mexit 167 M #push 167 M @@lea ans 167 M mset # 167 M [4165] 4165:4501 10 [ 3] ldhx #ans 167 M endm 167 M #x 167 M mdo 167 M [4168] 4168:86 [ 3] pula 167 M [4169] 4169:F7 [ 2] sta 0,x 167 M mloop 4 167 M [416A] 416A:86 [ 3] pula 167 M [416B] 416B:E701 [ 3] sta 1,x 167 M mloop 4 167 M [416D] 416D:86 [ 3] pula 167 M [416E] 416E:E702 [ 3] sta 2,x 167 M mloop 4 167 M [4170] 4170:86 [ 3] pula 167 M [4171] 4171:E703 [ 3] sta 3,x 167 M mloop 4 167 M #pull 167 M #spadd -4 167 M endm 167 M @_?cli_ ans 167 M mexit 167 endm 168 M @Test 64 168 M ;------------------------------------------------------------------------------- 168 M ; Test the 64-bit version 168 M ;------------------------------------------------------------------------------- 168 M 168 M ;------------------------------------------------------------------------------- 168 M ; @@Load64 a 168 M ;------------------------------------------------------------------------------- 168 M @@Load64 a 168 M @_DoLoad 64,a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [4173] 4173:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [4176] 4176:E603 [ 3] lda 3,x 168 M [4178] 4178:87 [ 2] psha 168 M mloop 4 168 M [4179] 4179:E602 [ 3] lda 2,x 168 M [417B] 417B:87 [ 2] psha 168 M mloop 4 168 M [417C] 417C:E601 [ 3] lda 1,x 168 M [417E] 417E:87 [ 2] psha 168 M mloop 4 168 M [417F] 417F:F6 [ 3] lda 0,x 168 M [4180] 4180:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [4181] 4181:5F [ 1] clrx 168 M [4182] 4182:9E6D 01 [ 5] tst 1,asp 168 M [4185] 4185:2A01 (4188) [ 3] bpl *+3 168 M [4187] 4187:53 [ 1] !comx 168 M [4188] 4188:89 [ 2] pshx:4 168 M [4189] 4189:89 [ 2] 168 M [418A] 418A:89 [ 2] 168 M [418B] 418B:89 [ 2] 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Load64 b 168 M ;------------------------------------------------------------------------------- 168 M @@Load64 b 168 M @_DoLoad 64,b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [418C] 418C:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [418F] 418F:E603 [ 3] lda 3,x 168 M [4191] 4191:87 [ 2] psha 168 M mloop 4 168 M [4192] 4192:E602 [ 3] lda 2,x 168 M [4194] 4194:87 [ 2] psha 168 M mloop 4 168 M [4195] 4195:E601 [ 3] lda 1,x 168 M [4197] 4197:87 [ 2] psha 168 M mloop 4 168 M [4198] 4198:F6 [ 3] lda 0,x 168 M [4199] 4199:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [419A] 419A:5F [ 1] clrx 168 M [419B] 419B:9E6D 01 [ 5] tst 1,asp 168 M [419E] 419E:2A01 (41A1) [ 3] bpl *+3 168 M [41A0] 41A0:53 [ 1] !comx 168 M [41A1] 41A1:89 [ 2] pshx:4 168 M [41A2] 41A2:89 [ 2] 168 M [41A3] 41A3:89 [ 2] 168 M [41A4] 41A4:89 [ 2] 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Swap64 168 M ;------------------------------------------------------------------------------- 168 M @@Swap64 168 M @_DoSwap 64 168 M [41A5] 41A5:CD33 AF [ 6] call StackSwap64 168 M endm 168 M ;------------------------------------------------------------------------------- 168 M ; @@Save64 ans 168 M ;------------------------------------------------------------------------------- 168 M @@Save64 ans 168 M @_DoSave 64,ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8,#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [41A8] 41A8:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [41AA] 41AA:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [41AD] 41AD:86 [ 3] pula 168 M [41AE] 41AE:F7 [ 2] sta 0,x 168 M mloop 4 168 M [41AF] 41AF:86 [ 3] pula 168 M [41B0] 41B0:E701 [ 3] sta 1,x 168 M mloop 4 168 M [41B2] 41B2:86 [ 3] pula 168 M [41B3] 41B3:E702 [ 3] sta 2,x 168 M mloop 4 168 M [41B5] 41B5:86 [ 3] pula 168 M [41B6] 41B6:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Save64 ans 168 M ;------------------------------------------------------------------------------- 168 M @@Save64 ans 168 M @_DoSave 64,ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8,#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [41B8] 41B8:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [41BA] 41BA:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [41BD] 41BD:86 [ 3] pula 168 M [41BE] 41BE:F7 [ 2] sta 0,x 168 M mloop 4 168 M [41BF] 41BF:86 [ 3] pula 168 M [41C0] 41C0:E701 [ 3] sta 1,x 168 M mloop 4 168 M [41C2] 41C2:86 [ 3] pula 168 M [41C3] 41C3:E702 [ 3] sta 2,x 168 M mloop 4 168 M [41C5] 41C5:86 [ 3] pula 168 M [41C6] 41C6:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Add64 a,b,ans 168 M ;------------------------------------------------------------------------------- 168 M @@Add64 a,b,ans 168 M @_DoMath Add64,64,a,b,ans 168 M @@Load64 b 168 M @_DoLoad 64,b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [41C8] 41C8:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [41CB] 41CB:E603 [ 3] lda 3,x 168 M [41CD] 41CD:87 [ 2] psha 168 M mloop 4 168 M [41CE] 41CE:E602 [ 3] lda 2,x 168 M [41D0] 41D0:87 [ 2] psha 168 M mloop 4 168 M [41D1] 41D1:E601 [ 3] lda 1,x 168 M [41D3] 41D3:87 [ 2] psha 168 M mloop 4 168 M [41D4] 41D4:F6 [ 3] lda 0,x 168 M [41D5] 41D5:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [41D6] 41D6:5F [ 1] clrx 168 M [41D7] 41D7:9E6D 01 [ 5] tst 1,asp 168 M [41DA] 41DA:2A01 (41DD) [ 3] bpl *+3 168 M [41DC] 41DC:53 [ 1] !comx 168 M [41DD] 41DD:89 [ 2] pshx:4 168 M [41DE] 41DE:89 [ 2] 168 M [41DF] 41DF:89 [ 2] 168 M [41E0] 41E0:89 [ 2] 168 M mexit 168 M @@Load64 a 168 M @_DoLoad 64,a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [41E1] 41E1:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [41E4] 41E4:E603 [ 3] lda 3,x 168 M [41E6] 41E6:87 [ 2] psha 168 M mloop 4 168 M [41E7] 41E7:E602 [ 3] lda 2,x 168 M [41E9] 41E9:87 [ 2] psha 168 M mloop 4 168 M [41EA] 41EA:E601 [ 3] lda 1,x 168 M [41EC] 41EC:87 [ 2] psha 168 M mloop 4 168 M [41ED] 41ED:F6 [ 3] lda 0,x 168 M [41EE] 41EE:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [41EF] 41EF:5F [ 1] clrx 168 M [41F0] 41F0:9E6D 01 [ 5] tst 1,asp 168 M [41F3] 41F3:2A01 (41F6) [ 3] bpl *+3 168 M [41F5] 41F5:53 [ 1] !comx 168 M [41F6] 41F6:89 [ 2] pshx:4 168 M [41F7] 41F7:89 [ 2] 168 M [41F8] 41F8:89 [ 2] 168 M [41F9] 41F9:89 [ 2] 168 M mexit 168 M @@_DoOperation Add64 168 M mdef 2,64 168 M @@Msg Add64 168 M mexit 168 M [41FA] 41FA:CD2F 73 [ 6] call StackAdd64 168 M #spadd -64/8 168 M endm 168 M @Save64 ans 168 M @_DoSave 64,ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8,#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [41FD] 41FD:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [41FF] 41FF:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [4202] 4202:86 [ 3] pula 168 M [4203] 4203:F7 [ 2] sta 0,x 168 M mloop 4 168 M [4204] 4204:86 [ 3] pula 168 M [4205] 4205:E701 [ 3] sta 1,x 168 M mloop 4 168 M [4207] 4207:86 [ 3] pula 168 M [4208] 4208:E702 [ 3] sta 2,x 168 M mloop 4 168 M [420A] 420A:86 [ 3] pula 168 M [420B] 420B:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Sub64 a,b,ans 168 M ;------------------------------------------------------------------------------- 168 M @@Sub64 a,b,ans 168 M @_DoMath Sub64,64,a,b,ans 168 M @@Load64 b 168 M @_DoLoad 64,b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [420D] 420D:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [4210] 4210:E603 [ 3] lda 3,x 168 M [4212] 4212:87 [ 2] psha 168 M mloop 4 168 M [4213] 4213:E602 [ 3] lda 2,x 168 M [4215] 4215:87 [ 2] psha 168 M mloop 4 168 M [4216] 4216:E601 [ 3] lda 1,x 168 M [4218] 4218:87 [ 2] psha 168 M mloop 4 168 M [4219] 4219:F6 [ 3] lda 0,x 168 M [421A] 421A:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [421B] 421B:5F [ 1] clrx 168 M [421C] 421C:9E6D 01 [ 5] tst 1,asp 168 M [421F] 421F:2A01 (4222) [ 3] bpl *+3 168 M [4221] 4221:53 [ 1] !comx 168 M [4222] 4222:89 [ 2] pshx:4 168 M [4223] 4223:89 [ 2] 168 M [4224] 4224:89 [ 2] 168 M [4225] 4225:89 [ 2] 168 M mexit 168 M @@Load64 a 168 M @_DoLoad 64,a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [4226] 4226:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [4229] 4229:E603 [ 3] lda 3,x 168 M [422B] 422B:87 [ 2] psha 168 M mloop 4 168 M [422C] 422C:E602 [ 3] lda 2,x 168 M [422E] 422E:87 [ 2] psha 168 M mloop 4 168 M [422F] 422F:E601 [ 3] lda 1,x 168 M [4231] 4231:87 [ 2] psha 168 M mloop 4 168 M [4232] 4232:F6 [ 3] lda 0,x 168 M [4233] 4233:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [4234] 4234:5F [ 1] clrx 168 M [4235] 4235:9E6D 01 [ 5] tst 1,asp 168 M [4238] 4238:2A01 (423B) [ 3] bpl *+3 168 M [423A] 423A:53 [ 1] !comx 168 M [423B] 423B:89 [ 2] pshx:4 168 M [423C] 423C:89 [ 2] 168 M [423D] 423D:89 [ 2] 168 M [423E] 423E:89 [ 2] 168 M mexit 168 M @@_DoOperation Sub64 168 M mdef 2,64 168 M @@Msg Sub64 168 M mexit 168 M [423F] 423F:CD2F 89 [ 6] call StackSub64 168 M #spadd -64/8 168 M endm 168 M @Save64 ans 168 M @_DoSave 64,ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8,#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [4242] 4242:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [4244] 4244:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [4247] 4247:86 [ 3] pula 168 M [4248] 4248:F7 [ 2] sta 0,x 168 M mloop 4 168 M [4249] 4249:86 [ 3] pula 168 M [424A] 424A:E701 [ 3] sta 1,x 168 M mloop 4 168 M [424C] 424C:86 [ 3] pula 168 M [424D] 424D:E702 [ 3] sta 2,x 168 M mloop 4 168 M [424F] 424F:86 [ 3] pula 168 M [4250] 4250:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Mul64 a,b,ans 168 M ;------------------------------------------------------------------------------- 168 M @@Mul64 a,b,ans 168 M @_DoMath Mul64,64,a,b,ans 168 M @@Load64 b 168 M @_DoLoad 64,b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [4252] 4252:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [4255] 4255:E603 [ 3] lda 3,x 168 M [4257] 4257:87 [ 2] psha 168 M mloop 4 168 M [4258] 4258:E602 [ 3] lda 2,x 168 M [425A] 425A:87 [ 2] psha 168 M mloop 4 168 M [425B] 425B:E601 [ 3] lda 1,x 168 M [425D] 425D:87 [ 2] psha 168 M mloop 4 168 M [425E] 425E:F6 [ 3] lda 0,x 168 M [425F] 425F:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [4260] 4260:5F [ 1] clrx 168 M [4261] 4261:9E6D 01 [ 5] tst 1,asp 168 M [4264] 4264:2A01 (4267) [ 3] bpl *+3 168 M [4266] 4266:53 [ 1] !comx 168 M [4267] 4267:89 [ 2] pshx:4 168 M [4268] 4268:89 [ 2] 168 M [4269] 4269:89 [ 2] 168 M [426A] 426A:89 [ 2] 168 M mexit 168 M @@Load64 a 168 M @_DoLoad 64,a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [426B] 426B:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [426E] 426E:E603 [ 3] lda 3,x 168 M [4270] 4270:87 [ 2] psha 168 M mloop 4 168 M [4271] 4271:E602 [ 3] lda 2,x 168 M [4273] 4273:87 [ 2] psha 168 M mloop 4 168 M [4274] 4274:E601 [ 3] lda 1,x 168 M [4276] 4276:87 [ 2] psha 168 M mloop 4 168 M [4277] 4277:F6 [ 3] lda 0,x 168 M [4278] 4278:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [4279] 4279:5F [ 1] clrx 168 M [427A] 427A:9E6D 01 [ 5] tst 1,asp 168 M [427D] 427D:2A01 (4280) [ 3] bpl *+3 168 M [427F] 427F:53 [ 1] !comx 168 M [4280] 4280:89 [ 2] pshx:4 168 M [4281] 4281:89 [ 2] 168 M [4282] 4282:89 [ 2] 168 M [4283] 4283:89 [ 2] 168 M mexit 168 M @@_DoOperation Mul64 168 M mdef 2,64 168 M @@Msg Mul64 168 M mexit 168 M [4284] 4284:CD30 A8 [ 6] call StackMul64 168 M #spadd -64/8 168 M endm 168 M @Save64 ans 168 M @_DoSave 64,ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8,#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [4287] 4287:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [4289] 4289:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [428C] 428C:86 [ 3] pula 168 M [428D] 428D:F7 [ 2] sta 0,x 168 M mloop 4 168 M [428E] 428E:86 [ 3] pula 168 M [428F] 428F:E701 [ 3] sta 1,x 168 M mloop 4 168 M [4291] 4291:86 [ 3] pula 168 M [4292] 4292:E702 [ 3] sta 2,x 168 M mloop 4 168 M [4294] 4294:86 [ 3] pula 168 M [4295] 4295:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Div64 a,b,ans 168 M ;------------------------------------------------------------------------------- 168 M @@Div64 a,b,ans 168 M @_DoMath Div64,64,a,b,ans 168 M @@Load64 b 168 M @_DoLoad 64,b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [4297] 4297:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [429A] 429A:E603 [ 3] lda 3,x 168 M [429C] 429C:87 [ 2] psha 168 M mloop 4 168 M [429D] 429D:E602 [ 3] lda 2,x 168 M [429F] 429F:87 [ 2] psha 168 M mloop 4 168 M [42A0] 42A0:E601 [ 3] lda 1,x 168 M [42A2] 42A2:87 [ 2] psha 168 M mloop 4 168 M [42A3] 42A3:F6 [ 3] lda 0,x 168 M [42A4] 42A4:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [42A5] 42A5:5F [ 1] clrx 168 M [42A6] 42A6:9E6D 01 [ 5] tst 1,asp 168 M [42A9] 42A9:2A01 (42AC) [ 3] bpl *+3 168 M [42AB] 42AB:53 [ 1] !comx 168 M [42AC] 42AC:89 [ 2] pshx:4 168 M [42AD] 42AD:89 [ 2] 168 M [42AE] 42AE:89 [ 2] 168 M [42AF] 42AF:89 [ 2] 168 M mexit 168 M @@Load64 a 168 M @_DoLoad 64,a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [42B0] 42B0:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [42B3] 42B3:E603 [ 3] lda 3,x 168 M [42B5] 42B5:87 [ 2] psha 168 M mloop 4 168 M [42B6] 42B6:E602 [ 3] lda 2,x 168 M [42B8] 42B8:87 [ 2] psha 168 M mloop 4 168 M [42B9] 42B9:E601 [ 3] lda 1,x 168 M [42BB] 42BB:87 [ 2] psha 168 M mloop 4 168 M [42BC] 42BC:F6 [ 3] lda 0,x 168 M [42BD] 42BD:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [42BE] 42BE:5F [ 1] clrx 168 M [42BF] 42BF:9E6D 01 [ 5] tst 1,asp 168 M [42C2] 42C2:2A01 (42C5) [ 3] bpl *+3 168 M [42C4] 42C4:53 [ 1] !comx 168 M [42C5] 42C5:89 [ 2] pshx:4 168 M [42C6] 42C6:89 [ 2] 168 M [42C7] 42C7:89 [ 2] 168 M [42C8] 42C8:89 [ 2] 168 M mexit 168 M @@_DoOperation Div64 168 M mdef 2,64 168 M @@Msg Div64 168 M mexit 168 M [42C9] 42C9:CD31 15 [ 6] call StackDiv64 168 M #spadd -64/8 168 M endm 168 M @Save64 ans 168 M @_DoSave 64,ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8,#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [42CC] 42CC:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [42CE] 42CE:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [42D1] 42D1:86 [ 3] pula 168 M [42D2] 42D2:F7 [ 2] sta 0,x 168 M mloop 4 168 M [42D3] 42D3:86 [ 3] pula 168 M [42D4] 42D4:E701 [ 3] sta 1,x 168 M mloop 4 168 M [42D6] 42D6:86 [ 3] pula 168 M [42D7] 42D7:E702 [ 3] sta 2,x 168 M mloop 4 168 M [42D9] 42D9:86 [ 3] pula 168 M [42DA] 42DA:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Mod64 a,b,ans 168 M ;------------------------------------------------------------------------------- 168 M @@Mod64 a,b,ans 168 M @_DoMath Mod64,64,a,b,ans 168 M @@Load64 b 168 M @_DoLoad 64,b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [42DC] 42DC:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [42DF] 42DF:E603 [ 3] lda 3,x 168 M [42E1] 42E1:87 [ 2] psha 168 M mloop 4 168 M [42E2] 42E2:E602 [ 3] lda 2,x 168 M [42E4] 42E4:87 [ 2] psha 168 M mloop 4 168 M [42E5] 42E5:E601 [ 3] lda 1,x 168 M [42E7] 42E7:87 [ 2] psha 168 M mloop 4 168 M [42E8] 42E8:F6 [ 3] lda 0,x 168 M [42E9] 42E9:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [42EA] 42EA:5F [ 1] clrx 168 M [42EB] 42EB:9E6D 01 [ 5] tst 1,asp 168 M [42EE] 42EE:2A01 (42F1) [ 3] bpl *+3 168 M [42F0] 42F0:53 [ 1] !comx 168 M [42F1] 42F1:89 [ 2] pshx:4 168 M [42F2] 42F2:89 [ 2] 168 M [42F3] 42F3:89 [ 2] 168 M [42F4] 42F4:89 [ 2] 168 M mexit 168 M @@Load64 a 168 M @_DoLoad 64,a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [42F5] 42F5:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [42F8] 42F8:E603 [ 3] lda 3,x 168 M [42FA] 42FA:87 [ 2] psha 168 M mloop 4 168 M [42FB] 42FB:E602 [ 3] lda 2,x 168 M [42FD] 42FD:87 [ 2] psha 168 M mloop 4 168 M [42FE] 42FE:E601 [ 3] lda 1,x 168 M [4300] 4300:87 [ 2] psha 168 M mloop 4 168 M [4301] 4301:F6 [ 3] lda 0,x 168 M [4302] 4302:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [4303] 4303:5F [ 1] clrx 168 M [4304] 4304:9E6D 01 [ 5] tst 1,asp 168 M [4307] 4307:2A01 (430A) [ 3] bpl *+3 168 M [4309] 4309:53 [ 1] !comx 168 M [430A] 430A:89 [ 2] pshx:4 168 M [430B] 430B:89 [ 2] 168 M [430C] 430C:89 [ 2] 168 M [430D] 430D:89 [ 2] 168 M mexit 168 M @@_DoOperation Mod64 168 M mdef 2,64 168 M @@Msg Mod64 168 M mexit 168 M [430E] 430E:CD31 28 [ 6] call StackMod64 168 M #spadd -64/8 168 M endm 168 M @Save64 ans 168 M @_DoSave 64,ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8,#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [4311] 4311:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [4313] 4313:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [4316] 4316:86 [ 3] pula 168 M [4317] 4317:F7 [ 2] sta 0,x 168 M mloop 4 168 M [4318] 4318:86 [ 3] pula 168 M [4319] 4319:E701 [ 3] sta 1,x 168 M mloop 4 168 M [431B] 431B:86 [ 3] pula 168 M [431C] 431C:E702 [ 3] sta 2,x 168 M mloop 4 168 M [431E] 431E:86 [ 3] pula 168 M [431F] 431F:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 M ;------------------------------------------------------------------------------- 168 M ; @@Neg64 ans 168 M ;------------------------------------------------------------------------------- 168 M @@Neg64 ans 168 M @_DoNeg 64,ans 168 M @@Msg Neg64 ans 168 M mexit 168 M @@_FindStkMth_ 64 168 M #temp 168 M mdo 64/8 168 M #temp :mloop*8 168 M mloop 8 168 M mexit :temp 168 M mset 1,64 168 M @@Load64 ans 168 M @_DoLoad 64,ans 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ ans 168 M mexit 168 M @@pushv ans 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [4321] 4321:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [4324] 4324:E603 [ 3] lda 3,x 168 M [4326] 4326:87 [ 2] psha 168 M mloop 4 168 M [4327] 4327:E602 [ 3] lda 2,x 168 M [4329] 4329:87 [ 2] psha 168 M mloop 4 168 M [432A] 432A:E601 [ 3] lda 1,x 168 M [432C] 432C:87 [ 2] psha 168 M mloop 4 168 M [432D] 432D:F6 [ 3] lda 0,x 168 M [432E] 432E:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ ans 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [432F] 432F:5F [ 1] clrx 168 M [4330] 4330:9E6D 01 [ 5] tst 1,asp 168 M [4333] 4333:2A01 (4336) [ 3] bpl *+3 168 M [4335] 4335:53 [ 1] !comx 168 M [4336] 4336:89 [ 2] pshx:4 168 M [4337] 4337:89 [ 2] 168 M [4338] 4338:89 [ 2] 168 M [4339] 4339:89 [ 2] 168 M mexit 168 M [433A] 433A:CD33 D0 [ 6] call StackNegate64 168 M @Save64 168 M @_DoSave 64 168 M mreq 1:BitSize[,Variable] 168 M mset 2 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ 168 M mset #' ' 168 M mexit 168 M @@Msg Save64 168 M mexit 168 M @@lea 168 M mset # 168 M mexit 168 M @@_?sei_ 168 M mexit 168 M [433D] 433D:CD34 13 [ 6] call StackSave64 168 M @@_?cli_ 168 M mexit 168 M #spadd -64/8 168 M endm 168 M ;------------------------------------------------------------------------------- 168 M ; @@Abs64 ans 168 M ;------------------------------------------------------------------------------- 168 M @@Abs64 ans 168 M @_DoAbs 64,ans 168 M @@Msg Abs64 ans 168 M mexit 168 M @@_FindStkMth_ 64 168 M #temp 168 M mdo 64/8 168 M #temp :mloop*8 168 M mloop 8 168 M mexit :temp 168 M mset 1,64 168 M @@Load64 ans 168 M @_DoLoad 64,ans 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ ans 168 M mexit 168 M @@pushv ans 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [4340] 4340:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [4343] 4343:E603 [ 3] lda 3,x 168 M [4345] 4345:87 [ 2] psha 168 M mloop 4 168 M [4346] 4346:E602 [ 3] lda 2,x 168 M [4348] 4348:87 [ 2] psha 168 M mloop 4 168 M [4349] 4349:E601 [ 3] lda 1,x 168 M [434B] 434B:87 [ 2] psha 168 M mloop 4 168 M [434C] 434C:F6 [ 3] lda 0,x 168 M [434D] 434D:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ ans 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [434E] 434E:5F [ 1] clrx 168 M [434F] 434F:9E6D 01 [ 5] tst 1,asp 168 M [4352] 4352:2A01 (4355) [ 3] bpl *+3 168 M [4354] 4354:53 [ 1] !comx 168 M [4355] 4355:89 [ 2] pshx:4 168 M [4356] 4356:89 [ 2] 168 M [4357] 4357:89 [ 2] 168 M [4358] 4358:89 [ 2] 168 M mexit 168 M [4359] 4359:CD33 CB [ 6] call StackAbs64 168 M @Save64 168 M @_DoSave 64 168 M mreq 1:BitSize[,Variable] 168 M mset 2 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ 168 M mset #' ' 168 M mexit 168 M @@Msg Save64 168 M mexit 168 M @@lea 168 M mset # 168 M mexit 168 M @@_?sei_ 168 M mexit 168 M [435C] 435C:CD34 13 [ 6] call StackSave64 168 M @@_?cli_ 168 M mexit 168 M #spadd -64/8 168 M endm 168 M ;------------------------------------------------------------------------------- 168 M ; @@Str64 ans,String 168 M ;------------------------------------------------------------------------------- 168 M @@Str64 ans,String 168 M @_DoStr 64,ans,String 168 M @@_FindStkMth_ 64 168 M #temp 168 M mdo 64/8 168 M #temp :mloop*8 168 M mloop 8 168 M mexit :temp 168 M mset 1,64 168 M @@Load64 ans 168 M @_DoLoad 64,ans 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ ans 168 M mexit 168 M @@pushv ans 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [435F] 435F:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [4362] 4362:E603 [ 3] lda 3,x 168 M [4364] 4364:87 [ 2] psha 168 M mloop 4 168 M [4365] 4365:E602 [ 3] lda 2,x 168 M [4367] 4367:87 [ 2] psha 168 M mloop 4 168 M [4368] 4368:E601 [ 3] lda 1,x 168 M [436A] 436A:87 [ 2] psha 168 M mloop 4 168 M [436B] 436B:F6 [ 3] lda 0,x 168 M [436C] 436C:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ ans 168 M mexit 168 M @ResizeTOS #4,#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [436D] 436D:5F [ 1] clrx 168 M [436E] 436E:9E6D 01 [ 5] tst 1,asp 168 M [4371] 4371:2A01 (4374) [ 3] bpl *+3 168 M [4373] 4373:53 [ 1] !comx 168 M [4374] 4374:89 [ 2] pshx:4 168 M [4375] 4375:89 [ 2] 168 M [4376] 4376:89 [ 2] 168 M [4377] 4377:89 [ 2] 168 M mexit 168 M @@Msg Convert 'ans' (32-bit) to ASCIZ in 'String' 168 M mexit 168 M @@lea String 168 M mset # 168 M [4378] 4378:4501 18 [ 3] ldhx #String 168 M endm 168 M [437B] 437B:CD34 4C [ 6] call Stack64ToASCIZ 168 M [437E] 437E:A708 [ 2] ais #64/8 168 M endm 168 M ;------------------------------------------------------------------------------- 168 M ; @@Eval64 ans = (a + b) * abs(a - b) / 2 168 M ;------------------------------------------------------------------------------- 168 M @@Eval64 ans = abs(a + b) * abs(a - b) / 2 168 M mset # 168 M @_Eval_ 64,ans = abs(a + b) * abs(a - b) / 2 168 M @@_needs_spauto_ 168 M mexit 168 M mdef 1,32 168 M mswap 0,1 168 M mdel 1 168 M mset # 168 M @@Msg -------------------------------------------------- 168 M mexit 168 M @@Msg Expr: ans = abs(a + b) * abs(a - b) / 2 168 M mexit 168 M @@Msg -------------------------------------------------- 168 M mexit 168 M @@_FindStkMth_ 64 168 M #temp 168 M mdo 64/8 168 M #temp :mloop*8 168 M mloop 8 168 M mexit :temp 168 M mset 0,64,64 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M mtrim 1 168 M mset #'=' 168 M @@_Eval_ abs(a+b)*abs(a-b)/2 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M mdo 2 168 M @@_Eval_ 2 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M 168 M 168 M 168 M 168 M 168 M mset 9 168 M 168 M mset 1,#2 168 M mset 1,#2 168 M @Load64 #2 168 M @_DoLoad 64=#2 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ #2 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M mset 1,#2 168 M @@Msg Load64 #2 168 M mexit 168 M mset 1,2 168 M mset 0 168 M mdo 168 M [4380] 4380:AE02 [ 2] ldx #2>0&$FF 168 M [4382] 4382:89 [ 2] pshx 168 M mloop :temp 168 M [4383] 4383:8C [ 1] clrh 168 M mset 0,clrh 168 M [4384] 4384:8B [ 2] pshh 168 M mloop :temp 168 M [4385] 4385:8B [ 2] pshh 168 M mloop :temp 168 M [4386] 4386:8B [ 2] pshh 168 M mloop :temp 168 M [4387] 4387:8B [ 2] pshh 168 M mloop :temp 168 M [4388] 4388:8B [ 2] pshh 168 M mloop :temp 168 M [4389] 4389:8B [ 2] pshh 168 M mloop :temp 168 M [438A] 438A:8B [ 2] pshh 168 M mloop :temp 168 M mexit 168 M mloop :nn 168 M @@_Eval_ abs(a-b) 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M 168 M 168 M @@_Eval_ a-b 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M mdo 2 168 M @@_Eval_ b 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M 168 M 168 M 168 M 168 M 168 M mset 9 168 M 168 M @Load64 b 168 M @_DoLoad 64=b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [438B] 438B:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [438E] 438E:E603 [ 3] lda 3,x 168 M [4390] 4390:87 [ 2] psha 168 M mloop 4 168 M [4391] 4391:E602 [ 3] lda 2,x 168 M [4393] 4393:87 [ 2] psha 168 M mloop 4 168 M [4394] 4394:E601 [ 3] lda 1,x 168 M [4396] 4396:87 [ 2] psha 168 M mloop 4 168 M [4397] 4397:F6 [ 3] lda 0,x 168 M [4398] 4398:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4=#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [4399] 4399:5F [ 1] clrx 168 M [439A] 439A:9E6D 01 [ 5] tst 1,asp 168 M [439D] 439D:2A01 (43A0) [ 3] bpl *+3 168 M [439F] 439F:53 [ 1] !comx 168 M [43A0] 43A0:89 [ 2] pshx:4 168 M [43A1] 43A1:89 [ 2] 168 M [43A2] 43A2:89 [ 2] 168 M [43A3] 43A3:89 [ 2] 168 M mexit 168 M mloop :nn 168 M @@_Eval_ a 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M 168 M 168 M 168 M 168 M 168 M mset 9 168 M 168 M @Load64 a 168 M @_DoLoad 64=a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [43A4] 43A4:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [43A7] 43A7:E603 [ 3] lda 3,x 168 M [43A9] 43A9:87 [ 2] psha 168 M mloop 4 168 M [43AA] 43AA:E602 [ 3] lda 2,x 168 M [43AC] 43AC:87 [ 2] psha 168 M mloop 4 168 M [43AD] 43AD:E601 [ 3] lda 1,x 168 M [43AF] 43AF:87 [ 2] psha 168 M mloop 4 168 M [43B0] 43B0:F6 [ 3] lda 0,x 168 M [43B1] 43B1:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4=#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [43B2] 43B2:5F [ 1] clrx 168 M [43B3] 43B3:9E6D 01 [ 5] tst 1,asp 168 M [43B6] 43B6:2A01 (43B9) [ 3] bpl *+3 168 M [43B8] 43B8:53 [ 1] !comx 168 M [43B9] 43B9:89 [ 2] pshx:4 168 M [43BA] 43BA:89 [ 2] 168 M [43BB] 43BB:89 [ 2] 168 M [43BC] 43BC:89 [ 2] 168 M mexit 168 M mdo 2 168 M @@Msg Sub64 168 M mexit 168 M [43BD] 43BD:CD2F 89 [ 6] call StackSub64 168 M #spadd -8 168 M mloop :nn 168 M mexit 168 M @@Msg Abs64 168 M mexit 168 M [43C0] 43C0:CD33 CB [ 6] call StackAbs64 168 M mexit 168 M mloop :nn 168 M @@_Eval_ abs(a+b) 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M 168 M 168 M @@_Eval_ a+b 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M mdo 2 168 M @@_Eval_ b 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M 168 M 168 M 168 M 168 M 168 M mset 9 168 M 168 M @Load64 b 168 M @_DoLoad 64=b 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ b 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ b 168 M mexit 168 M @@pushv b 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV b (32-bit) 168 M mexit 168 M #push 168 M @@lea b 168 M mset # 168 M [43C3] 43C3:4501 08 [ 3] ldhx #b 168 M endm 168 M #x 168 M mdo 168 M [43C6] 43C6:E603 [ 3] lda 3,x 168 M [43C8] 43C8:87 [ 2] psha 168 M mloop 4 168 M [43C9] 43C9:E602 [ 3] lda 2,x 168 M [43CB] 43CB:87 [ 2] psha 168 M mloop 4 168 M [43CC] 43CC:E601 [ 3] lda 1,x 168 M [43CE] 43CE:87 [ 2] psha 168 M mloop 4 168 M [43CF] 43CF:F6 [ 3] lda 0,x 168 M [43D0] 43D0:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ b 168 M mexit 168 M @ResizeTOS #4=#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [43D1] 43D1:5F [ 1] clrx 168 M [43D2] 43D2:9E6D 01 [ 5] tst 1,asp 168 M [43D5] 43D5:2A01 (43D8) [ 3] bpl *+3 168 M [43D7] 43D7:53 [ 1] !comx 168 M [43D8] 43D8:89 [ 2] pshx:4 168 M [43D9] 43D9:89 [ 2] 168 M [43DA] 43DA:89 [ 2] 168 M [43DB] 43DB:89 [ 2] 168 M mexit 168 M mloop :nn 168 M @@_Eval_ a 168 M mset # 168 M mreq 1:Expression (eg. [ans=](a+b)*(a-b)/2 -- spaces OK) 168 M 168 M 168 M 168 M 168 M mset #'+-|^' 168 M 168 M mset #'*\/&><' 168 M 168 M 168 M 168 M 168 M 168 M mset 9 168 M 168 M @Load64 a 168 M @_DoLoad 64=a 168 M mreq 1:BitSize[,Variable] 168 M #temp 64/8 168 M mdel 1 168 M mset # 168 M mtrim 1 168 M 168 M mset 9 168 M 168 M @@_not_x_ a 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M 168 M 168 M @@_?sei_ a 168 M mexit 168 M @@pushv a 168 M mset #' ' 168 M mset 0 168 M mreq 1:variable[ SizeOf(var)][ 'newname'] 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PushV a (32-bit) 168 M mexit 168 M #push 168 M @@lea a 168 M mset # 168 M [43DC] 43DC:4501 00 [ 3] ldhx #a 168 M endm 168 M #x 168 M mdo 168 M [43DF] 43DF:E603 [ 3] lda 3,x 168 M [43E1] 43E1:87 [ 2] psha 168 M mloop 4 168 M [43E2] 43E2:E602 [ 3] lda 2,x 168 M [43E4] 43E4:87 [ 2] psha 168 M mloop 4 168 M [43E5] 43E5:E601 [ 3] lda 1,x 168 M [43E7] 43E7:87 [ 2] psha 168 M mloop 4 168 M [43E8] 43E8:F6 [ 3] lda 0,x 168 M [43E9] 43E9:87 [ 2] psha 168 M mloop 4 168 M #pull 168 M #spadd 4 168 M endm 168 M @@_?cli_ a 168 M mexit 168 M @ResizeTOS #4=#8 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 8-4 168 M @@Msg Signed 32-bit => 64-bit 168 M mexit 168 M [43EA] 43EA:5F [ 1] clrx 168 M [43EB] 43EB:9E6D 01 [ 5] tst 1,asp 168 M [43EE] 43EE:2A01 (43F1) [ 3] bpl *+3 168 M [43F0] 43F0:53 [ 1] !comx 168 M [43F1] 43F1:89 [ 2] pshx:4 168 M [43F2] 43F2:89 [ 2] 168 M [43F3] 43F3:89 [ 2] 168 M [43F4] 43F4:89 [ 2] 168 M mexit 168 M mdo 2 168 M @@Msg Add64 168 M mexit 168 M [43F5] 43F5:CD2F 73 [ 6] call StackAdd64 168 M #spadd -8 168 M mloop :nn 168 M mexit 168 M @@Msg Abs64 168 M mexit 168 M [43F8] 43F8:CD33 CB [ 6] call StackAbs64 168 M mexit 168 M mdo 2 168 M @@Msg Mul64 168 M mexit 168 M [43FB] 43FB:CD30 A8 [ 6] call StackMul64 168 M #spadd -8 168 M mloop :nn 168 M @@Msg Div64 168 M mexit 168 M [43FE] 43FE:CD31 15 [ 6] call StackDiv64 168 M #spadd -8 168 M mloop :nn 168 M mexit 168 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 168 M mset 9 168 M ;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;-;- 168 M @Save64 ans 168 M @_DoSave 64=ans 168 M mreq 1:BitSize[,Variable] 168 M mset 2,ans 168 M mtrim 2 168 M 168 M mset 9 168 M 168 M @@_not_x_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M @@ResizeTOS #8=#4 168 M mreq 1,2:#FromByteSize,#ToByteSize 168 M #temp 4-8 168 M @@Msg Signed 64-bit => 32-bit 168 M mexit 168 M [4401] 4401:A704 [ 2] ais #-:temp 168 M mexit 168 M @@_?sei_ ans 168 M mexit 168 M @@pullv ans 168 M mset #' ' 168 M mreq 1:Variable[ SizeOf(Variable)] 168 M @@_not_#_ ans 168 M mset #' ' 168 M mdel 1 168 M mtop 168 M mset #' ' 168 M mexit 168 M mdef 2,4 168 M mdef 2,1 168 M @@Msg PullV ans (32-bit) 168 M mexit 168 M #push 168 M @@lea ans 168 M mset # 168 M [4403] 4403:4501 10 [ 3] ldhx #ans 168 M endm 168 M #x 168 M mdo 168 M [4406] 4406:86 [ 3] pula 168 M [4407] 4407:F7 [ 2] sta 0,x 168 M mloop 4 168 M [4408] 4408:86 [ 3] pula 168 M [4409] 4409:E701 [ 3] sta 1,x 168 M mloop 4 168 M [440B] 440B:86 [ 3] pula 168 M [440C] 440C:E702 [ 3] sta 2,x 168 M mloop 4 168 M [440E] 440E:86 [ 3] pula 168 M [440F] 440F:E703 [ 3] sta 3,x 168 M mloop 4 168 M #pull 168 M #spadd -4 168 M endm 168 M @_?cli_ ans 168 M mexit 168 endm 169 170 [4411] 4411:20FE (4411) [ 3] bra * 171 172 ;******************************************************************************* 173 M @vector Vreset,Start 173 M mdef 2,AnRTI 173 M #push 173 M #VECTORS 173 M #ppc 173 M FFFE org Vreset 173 M [FFFE] FFFE.34C5 dw Start 173 M FFCC org :ppc 173 M #pull 173 endm 174 ;******************************************************************************* (Legend: [S19 address] O=Offset active, M=Macro active) ----------------------------------------------------------- S E G M E N T U S A G E R E P O R T Segment Start End Size CodObj DatObj TotObj Lines ------- ----- ----- ----- ------ ------ ------ ----- XRAM $0100 $012F $0030 $0000 $0000 $0000 23 ROM $182C $4412 $2BE7 $2BE7 $0000 $2BE7 25340 DATA $FFBD $FFBF $0003 $0000 $0002 $0002 31 VECTORS $FFFE $FFFF $0002 $0000 $0002 $0002 3 Summary $182C $FFFF $E7D4 $2BE7 $0004 $2BEB 25397 ----------------------------------------------------------- O V E R A L L M E M O R Y U S A G E Total RAM size: 36 $0024 0.04 KB Total CODE size: 11239 $2BE7 10.98 KB (6080 instructions) Total DATA size: 4 $0004 0.00 KB Total IMAGE size: 11243 $2BEB 10.98 KB Lowest address : 6188 $182C Highest address : 65535 $FFFF Address Range : 61250 $EF42 59.81 KB (Used Range: 18.36%) Number of INCLUDE files: 21 Number of MACROs called: 3627 Number of [#]PROCs used: 138 Assembled 25403 lines (No Errors, Warnings: 0), CRC: $263C *** End of stakmath.asm listing ***