Skip to content

Commit 759f00c

Browse files
committed
Tandy HX BIOS BDA fix, clear RTC regs before access
1 parent 4b92c52 commit 759f00c

File tree

3 files changed

+59
-18
lines changed

3 files changed

+59
-18
lines changed

src/GLALIB.INC

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ROM_INIT_SP DW ? ; 69H or Option ROM init
5050
TIMER_CT_L DW ? ; 6CH Timer Counter Low Word (ticks)
5151
TIMER_CT_H DW ? ; 6EH Timer Counter High Word (hours)
5252
TIMER_CT_OF DB ? ; 70H Timer Overflow flag
53-
ORG 0B0H
54-
RTC_DATA RTC_DAT <> ; B0H GLaTICK address and RTC type
53+
ORG 0EEH
54+
RTC_DATA RTC_DAT <> ; EEH GLaTICK address and RTC type
5555
_BDA ENDS
5656

5757
;----------------------------------------------------------------------------;

src/GLATICK.ASM

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
; TODO:
3434
; - RTC Detection with overlapping port numbers: 240h, 2C0h, 340h
3535
; - Other Clock Types:
36-
; - MSM-58321 (is different than 5832?): 2C0, 27E, 37E, 02A2-02A3?
36+
; - MSM-58321: 2C0, 27E, 37E, 02A2-02A3?
3737
; - INT 1Ah services 6h and 7h (where supported)
3838
;
3939
; https://bochs.sourceforge.io/techspec/PORTS.LST
@@ -50,6 +50,7 @@ COPY_YEAR EQU '2023'
5050
SHOW_BANNER = 1 ; always show full banner at POST
5151
SHOW_RTC = 1 ; show detected RTC and clock
5252
SHOW_CLOCK = 1 ; if above, show date/time at POST
53+
PAUSE_BANNER = 0 ; pause after showing banner
5354

5455
MAGIC_WORD EQU 0AA55H ; Magic Word used for option ROM
5556
ROM_SIZE EQU 800H ; size of ROM (2K)
@@ -131,7 +132,7 @@ ROM_INIT PROC
131132
;----------------------------------------------------------------------------;
132133
; Ensure GLaTICK has not already been loaded
133134
;
134-
MOV AX, SEG _BDA ; CX = BDA segment, CH = 0
135+
MOV AX, SEG _BDA ; AX = BDA segment, AH = 0
135136
MOV DS, AX ; DS = BDA
136137
CMP RTC_DATA, 0 ; already been set up?
137138
JNZ ROM_INIT_DONE ; exit if so
@@ -147,12 +148,12 @@ ROM_INIT PROC
147148
CALL IS_GLABIOS ; is GLaBIOS?
148149
JZ DETECT_RTCS ; if so, don't display banner
149150
PRINTLN_SZ VER_BANNER ; otherwise display it
150-
ENDIF
151151

152152
;----------------------------------------------------------------------------;
153153
; Detect Supported RTCs
154154
;----------------------------------------------------------------------------;
155155
DETECT_RTCS:
156+
ENDIF
156157

157158
IFDEF RTC_AT
158159
;----------------------------------------------------------------------------;
@@ -277,6 +278,26 @@ DETECT_SET:
277278
DETECT_DONE:
278279
IF SHOW_RTC EQ 1
279280
CALL PRINT_DETECTED ; display on POST screen
281+
282+
IF PAUSE_BANNER EQ 1
283+
;----------------------------------------------------------------------------;
284+
; Optionally pause a little bit to allow output to be displayed if system
285+
; BIOS clears the screen before option ROMs can be read.
286+
;
287+
CALL IS_GLABIOS
288+
JZ PAUSE_END ; unnecessary to pause on GLaBIOS
289+
XCHG AX, CX ; preserve CX (necessary?)
290+
XOR CX, CX
291+
PAUSE_LOOP_1:
292+
MOV DI, 10H ; arbitrary pause duration
293+
PAUSE_LOOP_2:
294+
DEC DI
295+
JNZ PAUSE_LOOP_2
296+
LOOP PAUSE_LOOP_1
297+
XCHG AX, CX ; restore CX
298+
PAUSE_END:
299+
ENDIF ; end optional pause
300+
280301
ENDIF
281302
POP ES ; restore all regs
282303
POP DI

src/RTC_SW.ASM

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
;----------------------------------------------------------------------------;
55
; GLaTICK (Generational Logic and Time Interval Cadence Keeper)
66
;----------------------------------------------------------------------------;
7-
; RTC Support for DS-1216x/DS1315 "SmartWatch".
7+
; RTC Support for DS-1216x/DS1315 "SmartWatch" ROM.
88
;
99
; TODO:
1010
; - RAM
@@ -27,20 +27,27 @@ TEST_MMDD EQU 0814H ; month / day
2727
TEST_YY EQU 23H ; year
2828
TEST_HHMM EQU 1009H ; hour / minute
2929
TEST_SS EQU 33H ; seconds
30-
TEST_READ EQU 10H
30+
TEST_READ EQU 10H ; a valid register byte (2010-10-10 10:10:10)
3131
ENDIF
3232

3333
;----------------------------------------------------------------------------;
34-
; F000:0000 - SmartWatch RAM access segment/offsets
34+
; F600:0000 - SmartWatch ROM access segment and address offsets
3535
;----------------------------------------------------------------------------;
36+
; The SmartWatch uses the ROM's address lines for data transfer in and out.
37+
;
3638
; Scan for clock begins at the below segment, and at every 8K segment
3739
; boundary until 0000h.
3840
;----------------------------------------------------------------------------;
3941
_SW_ACC SEGMENT AT 0F600H ; set the start segment for scan
40-
ORG 0010B
41-
SW_WR0 DB ? ; 010 Set Read/Write=Write, D0=00H
42-
SW_WR1 DB ? ; 011 Set Read/Write=Write, D0=01H
43-
SR_RD DB ? ; 100 Set Read/Write=Read, D0=XX
42+
;_SW_ACC SEGMENT AT 0C000H ; set the start segment for scan
43+
44+
;----------------------------------------------------------------------------;
45+
; Non-interleaved ROM access offsets
46+
;
47+
ORG 0010B
48+
SW_WR0 DB ? ; 010b: A2=write, A0=0
49+
SW_WR1 DB ? ; 011b: A2=write, A0=1
50+
SR_RD DB ? ; 100b: A2=read, DQ0=in
4451
_SW_ACC ENDS
4552

4653
;----------------------------------------------------------------------------;
@@ -56,7 +63,6 @@ SW_REG_DATE DB ? ; 05h: day of month (01-31)
5663
SW_REG_MON DB ? ; 06h: month (01-12)
5764
SW_REG_YEAR DB ? ; 07h: year (00-99)
5865
SW_REG ENDS
59-
SW_DATA_SZ EQU SIZE SW_REG ; 8 bytes size
6066

6167
;----------------------------------------------------------------------------;
6268
; SW 00h: centi-sec (00-99)
@@ -139,6 +145,9 @@ SW_MON RECORD MNX1:3, MON10:1, MON01:4
139145
;----------------------------------------------------------------------------;
140146
SW_YEAR RECORD YR10:4, YR01:4
141147

148+
SW_DATA_SZ EQU SIZE SW_REG ; 8 byte buffer size
149+
SW_DATA_SZB EQU SW_DATA_SZ * WIDTH SW_CS ; 64 bit buffer size
150+
142151
INCLUDE GLALIB.INC
143152
INCLUDE MACROS.INC
144153

@@ -573,7 +582,7 @@ SW_READ_BIT:
573582
DEC CH ; decrement bit counter
574583
JNZ SW_READ_BIT ; loop until end of byte
575584
IF TEST_MODE EQ 1
576-
MOV AL, TEST_READ ; test data byte read
585+
MOV AH, TEST_READ ; test data byte read
577586
ENDIF
578587
MOV [SI], AH ; save byte to data buffer
579588
INC SI ; next output byte in buffer
@@ -641,7 +650,17 @@ SW_WRITE_ALL PROC
641650
; Clobbers: AX, CX, SI
642651
;----------------------------------------------------------------------------;
643652
SW_ACCESS PROC
644-
MOV AH, ES:SR_RD ; reset comparison register pointer
653+
654+
;----------------------------------------------------------------------------;
655+
; When power is cycled, 64 reads should be executed prior to any writes to
656+
; ensure that the RTC registers are not written.
657+
;
658+
MOV CX, SW_DATA_SZB + 1
659+
SW_ACCESS_CLEAR:
660+
MOV AL, ES:SR_RD ; read next bit from RTC
661+
LOOP SW_ACCESS_CLEAR
662+
IO_DELAY_SHORT ; short delay before continuing
663+
645664
LEA SI, _RAM_ACC ; RAM access data pattern
646665
; fall through to write
647666

@@ -765,11 +784,12 @@ DOW PROC
765784
; (3 = March, 4 = April, 5 = May, ..., 14 = February)
766785
;
767786
SUB AL, 2 ; compare and perform (m-2) operation below
787+
; (1 = Mar, ..., 10 = Dec)
768788
JA DOW_1 ; jump if Mar-Dec
769789
ADD AL, 12 ; 11 = Jan, 12 = Feb
770790

771791
;----------------------------------------------------------------------------;
772-
; decrement year in BCD
792+
; if Jan or Feb, decrement year (in BCD)
773793
;
774794
XCHG AX, CX ; AX = year (BCD)
775795
SUB AL, 1 ; decrement low digits
@@ -812,11 +832,11 @@ DOW_1:
812832
;
813833
MOV AL, CH ; J century
814834
CALL BCD_TO_BYTE
815-
PUSH AX ; save byte century
835+
MOV CX, AX ; save byte century
816836
SHR AX, 1 ; J / 4
817837
SHR AX, 1
818838
ADD BX, AX ; add to running sum
819-
POP AX
839+
XCHG AX, CX ; restore byte century
820840

821841
;----------------------------------------------------------------------------;
822842
; + 5*J

0 commit comments

Comments
 (0)