Skip to content

Commit b904450

Browse files
committed
Byte golf time-to-ticks routine
1 parent ff60027 commit b904450

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/GLATICK.ASM

+21-21
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
; - Other Clock Types:
3636
; - MSM-58321: 2C0, 27E, 37E, 02A2-02A3?
3737
; - INT 1Ah services 6h and 7h (where supported)
38+
; - Clean up include/config file structure
39+
; - Command line build process
3840
;
3941
; https://bochs.sourceforge.io/techspec/PORTS.LST
4042
;
4143
;----------------------------------------------------------------------------;
4244
VER_NAME EQU 'GLaTICK'
4345
VER_NUM EQU '0.8.6' ; (max 6 chars)
44-
VER_DATE EQU '08/14/23' ; must be MM/DD/YY format
46+
VER_DATE EQU '08/18/23' ; must be MM/DD/YY format
4547
COPY_YEAR EQU '2023'
4648

4749
;----------------------------------------------------------------------------;
@@ -736,33 +738,31 @@ TIME_TO_TICKS PROC
736738
ADD AX, CX ; AX = total minutes (hour + min)
737739
MOV CL, 60 ; convert minutes to seconds
738740
MUL CX ; DX:AX = total seconds (hour + min)
739-
ADD AX, DI ; add second to sum
741+
ADD DI, AX ; add second to sum
740742
ADC DX, 0 ; carry to high word
743+
PUSHF ; ZF if seconds < 65536
741744

742745
;----------------------------------------------------------------------------;
743746
; Convert Ticks = seconds * 1193180 / 65536
744747
;
745748
; This is a 21 bit x 17 bit multiply, which can be simplified for 16 bit
746-
; operations by adjusting to a 22 x 16 bit multiply using the following:
747-
; A*B == A/2 * B*2 + B[A is odd]
748-
;
749-
SHR DX, 1 ; divide seconds by 2 to fit in word
750-
RCR AX, 1 ; shift into high bit of low word
751-
PUSHF ; save CF if odd
752-
XCHG AX, DI ; DI = low total seconds (hour + min)
753-
MOV AX, 34DCH * 2 ; low ( 1193180 * 2 )
754-
MUL DI ; DX:AX = low ( ticks * 2 ) * sec / 2
755-
POPF ; restore CF
756-
JNC TTT_EVEN_SEC ; skip if even
757-
ADD AX, 34DCH ; add 1 second of ticks if an odd second
758-
ADC DX, 12H ; was shifted off
759-
TTT_EVEN_SEC:
749+
; operations by using the following:
750+
; (AX * 1193180) >> 8 + DX * 1193180
751+
;
752+
MOV AX, 34DCH ; low ( 1193180 * 2 )
753+
MUL DI ; DX = low ( ticks * sec ) >> 8
760754
MOV CX, DX ; CX:AX = working product
761-
MOV AX, 12H * 2 ; high ( 1193180 * 2 )
762-
MUL DI ; DX:AX = high ( ticks * 2 ) * sec / 2
763-
ADD CX, AX ; add working products
764-
ADC DX, 0 ; carry to high word
765-
XCHG DX, CX ; move to CX:DX
755+
MOV AX, 12H ; high ( 1193180 * 2 )
756+
MUL DI ; DX:AX = high ( ticks * sec )
757+
ADD AX, CX ; add working products and carry
758+
ADC DX, 0 ; DX:AX = ( AX * 1193180 ) >> 8
759+
POPF ; restore ZF
760+
JZ TTT_HIGH ; jump if < 65536
761+
ADD AX, 34DCH ; add 1 second of ticks to high word
762+
ADC DX, 12H ; if high bit (17) was 1
763+
TTT_HIGH:
764+
XCHG AX, DX ; move to CX:DX
765+
XCHG AX, CX
766766
POP DI
767767
RET
768768
TIME_TO_TICKS ENDP

0 commit comments

Comments
 (0)