Optimised *60 and *100 ====================== mdfs.net/Info/Comp/6502/ProgTips/Date/Times60 -- J.G.Harston When manipulating clock times, you often need to multiply by 60 and 100, for example centiseconds=((hours*60+minutes)*60+seconds)*100. This is a small snippet of optimised code to do multiplication by 60 or 100. There are 360000 = &057E40 centiseconds in a day, so this fits into a 3-byte 24-bit number. \ Times60 and Times100 \ ==================== \ Fixed multiplication by 60 or 100 \ \ On entry ws+0..ws+2 = value to multiply \ On exit ws+0..ws+2 = resut of multiplication \ A,X,Y corrupted \ Size 51 bytes \ No check for overflow, if the input is greater than 167772 for \ wsTimes100 or 279620 for wsTimes60 the result will be wrong. \ .wsTimes100 JSR wsTimes10:BCC wsTimes10 :\ n*100 .wsTimes60 BIT SETV:JSR wsTimes6or10 :\ n*6 .wsTimes10 CLV .wsTimes6or10 JSR wsTimes2 :\ n*2 LDY ws+2:LDX ws+1:LDA ws+0 :\ n*2 JSR wsTimes2:BVS wsTimesAdd :\ n*4 JSR wsTimes2 :\ n*8 .wsTimesAdd ADC ws+0:STA ws+0 :\ n*8+n*2 = n*10 TXA:ADC ws+1:STA ws+1 :\ or n*4+n*2 = n*6 TYA:ADC ws+2:STA ws+2 .SETV RTS .wsTimes2 ASL ws+0:ROL ws+1:ROL ws+2:RTS Along with a routine to add to the current value: .wsAdd CLC:ADC ws+0:STA ws+0 LDA #0:ADC ws+1:STA ws+1 LDA #0:ADC ws+2:STA ws+2 RTS a centisecond count can be then calculated with this code: LDA #0:STA ws+1:STA ws+2 :\ Clear accumulator LDA hours :STA ws+0:JSR wsTimes60 :\ Hour LDA minutes:JSR wsAdd:JSR wsTimes60 :\ Mins LDA seconds:JSR wsAdd:JSR wsTimes100 :\ Secs If you need to preserve X and Y, you can use this alternative code. \ Times60 and Times100 \ ==================== \ Fixed multiplication by 60 or 100 \ \ On entry ws+0..ws+2 = value to multiply \ On exit ws+0..ws+2 = result of multiplication \ A corrupted, X,Y preserved \ Size 56 bytes \ No check for overflow, if the input is greater than 167772 for \ wsTimes100 or 279620 for wsTimes60 the result will be wrong. \ .wsTimes100 JSR wsTimes10:JMP wsTimes10 :\ n*100 .wsTimes60 BIT SETV:JSR wsTimes6or10 :\ n*6 .wsTimes10 CLV .wsTimes6or10 JSR wsTimes2 :\ n*2 LDA ws+2:PHA:LDA ws+1:PHA:LDA ws+0:PHA :\ n*2 JSR wsTimes2:BVS wsTimesAdd :\ n*4 JSR wsTimes2 :\ n*8 .wsTimesAdd PLA:ADC ws+0:STA ws+0 :\ n*8+n*2 = n*10 PLA:ADC ws+1:STA ws+1 :\ or n*4+n*2 = n*6 PLA:ADC ws+2:STA ws+2 .SETV RTS .wsTimes2 ASL ws+0:ROL ws+1:ROL ws+2:RTS Credit to gfoot for optimisation using X,Y,A instead of stack: https://stardot.org.uk/forums/viewtopic.php?p=380521#p380521