From 690ee7137f9530b0ceb1a5565ec6cd0c0a2eaa51 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 23 Aug 2021 18:49:36 -0500 Subject: [PATCH] Add a function to get the proper value of CLOCKS_PER_SEC. This may be either 50 or 60, depending on the system's video frequency setting (50Hz PAL or 60Hz NTSC). The video setting can be determined by inspecting bit 4 of the LANGSEL soft switch, documented in Appendix E of the Apple IIGS Firmware Reference. --- time.asm | 24 ++++++++++++++++++++++++ time.macros | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/time.asm b/time.asm index 4af8d83..b2b0a8b 100644 --- a/time.asm +++ b/time.asm @@ -46,6 +46,30 @@ lasttime ds 4 last time_t value returned by time() lastDST dc i2'-1' tm_isdst value for lasttime end +**************************************************************** +* +* clock_t __clocks_per_sec() +* +* Outputs: +* X-A - the number of clock ticks per second (50 or 60) +* +**************************************************************** +* +__clocks_per_sec start +LANGSEL equ $E1C02B LANGSEL soft switch + + short I,M + ldy #60 + ldx #0 + lda >LANGSEL + and #$10 test NTSC/PAL bit of LANGSEL + beq lb1 + ldy #50 +lb1 long I,M + tya + rtl + end + **************************************************************** * * char *asctime(struct tm *ts) diff --git a/time.macros b/time.macros index 01fb94f..c50a85f 100644 --- a/time.macros +++ b/time.macros @@ -560,3 +560,43 @@ &lab ldx #$0C03 jsl $E10000 MEND + macro +&l long &a,&b + lclb &i + lclb &m +&a amid &a,1,1 +&m setb ("&a"="M").or.("&a"="m") +&i setb ("&a"="I").or.("&a"="i") + aif c:&b=0,.a +&b amid &b,1,1 +&m setb ("&b"="M").or.("&b"="m").or.&m +&i setb ("&b"="I").or.("&b"="i").or.&i +.a +&l rep #&m*32+&i*16 + aif .not.&m,.b + longa on +.b + aif .not.&i,.c + longi on +.c + mend + macro +&l short &a,&b + lclb &i + lclb &m +&a amid &a,1,1 +&m setb ("&a"="M").or.("&a"="m") +&i setb ("&a"="I").or.("&a"="i") + aif c:&b=0,.a +&b amid &b,1,1 +&m setb ("&b"="M").or.("&b"="m").or.&m +&i setb ("&b"="I").or.("&b"="i").or.&i +.a +&l sep #&m*32+&i*16 + aif .not.&m,.b + longa off +.b + aif .not.&i,.c + longi off +.c + mend