Midnight is 12 AM and noon is 12 PM (see https://en.wikipedia.org/wiki/12-hour_clock). Therefore we need to subtract 12 hours in exactly those two hours.
jsr pushax
lda CIA1_TODHR
- bpl AM
- and #%01111111
sed
+ tax ; Save PM flag
+ and #%01111111
+ cmp #$12 ; 12 AM/PM
+ bcc @L1
+ sbc #$12
+@L1: inx ; Get PM flag
+ bpl @L2
clc
adc #$12
- cld
-AM: jsr BCD2dec
+@L2: cld
+ jsr BCD2dec
sta TM + tm::tm_hour
lda CIA1_TODMIN
jsr BCD2dec
jsr pushax
lda CIA1_TODHR
- bpl AM
- and #%01111111
sed
+ tax ; Save PM flag
+ and #%01111111
+ cmp #$12 ; 12 AM/PM
+ bcc @L1
+ sbc #$12
+@L1: inx ; Get PM flag
+ bpl @L2
clc
adc #$12
- cld
-AM: jsr BCD2dec
+@L2: cld
+ jsr BCD2dec
sta TM + tm::tm_hour
lda CIA1_TODMIN
jsr BCD2dec
ldy #CIA::TODHR
lda (cia2),y
- bpl AM
- and #%01111111
sed
+ tax ; Save PM flag
+ and #%01111111
+ cmp #$12 ; 12 AM/PM
+ bcc @L1
+ sbc #$12
+@L1: inx ; Get PM flag
+ bpl @L2
clc
adc #$12
- cld
-AM: jsr BCD2dec
+@L2: cld
+ jsr BCD2dec
sta TM + tm::tm_hour
ldy #CIA::TODMIN
lda (cia2),y
ldy #CIA::TODHR
lda (cia),y
- bpl AM
- and #%01111111
sed
+ tax ; Save PM flag
+ and #%01111111
+ cmp #$12 ; 12 AM/PM
+ bcc @L1
+ sbc #$12
+@L1: inx ; Get PM flag
+ bpl @L2
clc
adc #$12
- cld
-AM: jsr BCD2dec
+@L2: cld
+ jsr BCD2dec
sta TM + tm::tm_hour
ldy #CIA::TODMIN
lda (cia),y