Skip to content

Commit 89abadd

Browse files
committed
Add timezone functionality for fn_clock: apple2, atari
1 parent 40bef11 commit 89abadd

27 files changed

+541
-101
lines changed
Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,68 @@
11
.export _clock_get_time
2+
.export _clock_get_time_tz
23

34
.import _sp_count
45
.import _sp_get_clock_id
56
.import _sp_payload
67
.import _sp_status
78

9+
.import _clock_set_alternate_tz
10+
811
.import incsp2
12+
.import incsp4
913
.import popax
1014
.import pusha
1115
.import return0
1216
.import return1
1317

1418
.include "macros.inc"
19+
.include "fujinet-network.inc" ; for FN_ERR_* codes
1520
.include "zp.inc"
1621

17-
; uint8_t clock_get_time(uint8_t* time_data, TimeFormat format);
22+
; for apple2 we support 6
23+
TIMEFORMAT_COUNT := $06
24+
25+
26+
; uint8_t clock_get_time_tz(uint8_t* time_data, const char* tz, TimeFormat format);
27+
_clock_get_time_tz:
28+
ldx #$20 ; convert to lower case
29+
stx lower_mask
30+
31+
sta time_format
32+
cmp #TIMEFORMAT_COUNT ; was the format value in range?
33+
bcc valid_format
34+
35+
jsr incsp4
36+
bad_cmd:
37+
ldx #$00
38+
lda #FN_ERR_BAD_CMD
39+
rts
40+
41+
valid_format:
42+
; first read tz from string given, and set it as the alternate TZ in fujinet.
43+
jsr popax
44+
jsr _clock_set_alternate_tz
1845

46+
beq common_tz
47+
; an error, but we still have an arg on software stack
48+
jsr incsp2
49+
jmp return1 ; FN_ERR_IO_ERROR
50+
51+
52+
; uint8_t clock_get_time(uint8_t* time_data, TimeFormat format);
1953
_clock_get_time:
20-
sta time_format ; format, save it where we need it! saves a BSS byte
54+
ldx #$00 ; don't alter the byte, keep upper case
55+
stx lower_mask
2156

57+
sta time_format
58+
cmp #TIMEFORMAT_COUNT ; was the format value in range?
59+
bcc common_tz
60+
61+
; exit after removing params from stack
62+
jsr incsp2
63+
jmp bad_cmd
64+
65+
common_tz:
2266
; get the device id of the clock, this is stored in _sp_clock_id, but also returned so we can check if it failed (0 is error)
2367
jsr _sp_get_clock_id
2468
bne got_id
@@ -31,23 +75,23 @@ error:
3175

3276
got_id:
3377
; call sp_status(uint8_t dest, uint8_t statcode)
34-
sta tmp1 ; save the clock device id
3578

3679
; convert the time format to the appropriate device specific code.
3780
; SIMPLE_BINARY (0) -> 'T'
3881
; PRODOS_BINARY (1) -> 'P'
39-
; APETIME_TZ_BINARY (2) -> 'A'
40-
; APETIME_BINARY (3) -> 'B'
41-
; TZ_ISO_STRING (4) -> 'S'
82+
; APETIME_TZ_BINARY (2) -> 0x99
83+
; APETIME_BINARY (3) -> 0x93
84+
; TZ_ISO_STRING (4) -> 'I'
4285
; UTC_ISO_STRING (5) -> 'Z'
86+
; APPLE3 SOS format (6) -> 'S'
4387

88+
jsr pusha ; A = destination device (clock id)
4489
ldx #$00
4590
time_format = *-1
46-
; ensure the value is valid
47-
cpx #$06
48-
bcs error
49-
jsr pusha
5091
lda code_table, x
92+
; convert to lower case if needed (set bit 0x20), caller sets the next byte to use
93+
ora #$00
94+
lower_mask = *-1
5195

5296
jsr _sp_status
5397
bne error
@@ -62,9 +106,8 @@ time_format = *-1
62106
cpy _sp_count
63107
bne :-
64108

65-
jmp return0
109+
jmp return0 ; FN_ERR_OK
66110

67111
.data
68112
code_table:
69-
.byte 'T', 'P', 'A', 'B', 'S', 'Z'
70-
113+
.byte 'T', 'P', 'A', 'I', 'Z', 'S'

apple2/apple2-6502/fn_clock/clock_set_tz.s

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.export _clock_set_tz
2+
.export _clock_set_alternate_tz
23

34
.import _fn_error
45
.import _memcpy
@@ -15,15 +16,29 @@
1516
.include "macros.inc"
1617
.include "zp.inc"
1718

19+
20+
; uint8_t clock_set_alternate_tz(char *tz);
21+
; same as clock_set_tz, but sends 't' ctrl code
22+
_clock_set_alternate_tz:
23+
ldy #'t'
24+
sty ctrl_code
25+
bne _clock_set_tz_common ; always
26+
1827
; uint8_t clock_set_tz(char *tz);
19-
_clock_set_tz:
28+
; sends 'T' ctrl code
29+
_clock_set_tz:
30+
ldy #'T'
31+
sty ctrl_code
32+
; fall through
33+
34+
_clock_set_tz_common:
2035
axinto tmp_tz_ptr ; save the tz
2136

2237
; get the device id of the clock, this is stored in _sp_clock_id, but also returned so we can check if it failed (0 is error)
2338
jsr _sp_get_clock_id
2439
bne got_id
2540

26-
; no clock found, return 1 as an error (FN_ERR_IO_ERROR)
41+
; no clock found, return 1 as an error
2742
jmp return1
2843

2944
got_id:
@@ -47,7 +62,9 @@ got_id:
4762
jsr _memcpy
4863

4964
; src/dst were both stored on s/w stack already
50-
lda #'T' ; set 'T'imezone
65+
; This is written to by the appropriate function, either 'T' for system TZ or 't' for alternate TZ
66+
lda #$00
67+
ctrl_code = *-1
5168
jsr _sp_control
5269

5370
; convert to fujinet ok/error code

atari/src/fn_clock/clock_get_time.s

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,65 @@
22
.export _clock_get_time_tz
33

44
.import _bus
5-
.import _fuji_success
5+
.import _fn_error
66
.import _clock_set_alternate_tz
77

88
.import incsp2
9+
.import incsp4
910
.import popax
1011
.import return0
12+
.import return1
1113

14+
.include "clock.inc"
1215
.include "device.inc"
13-
.include "fujinet-clock.inc"
16+
.include "fujinet-network.inc" ; for the FN_ERR codes
1417
.include "macros.inc"
1518
.include "zp.inc"
1619

1720

18-
; either 2 or 4 bytes to increase sp4 by
19-
exit_bad_tz4:
20-
jsr incsp2
21-
22-
exit_bad_tz2:
23-
jsr incsp2
24-
jmp return0
25-
26-
2721
; uint8_t clock_get_time_tz(uint8_t* time_data, const char* tz, TimeFormat format);
2822
_clock_get_time_tz:
29-
cmp #$06 ; was the format value in range?
30-
bcs exit_bad_tz4 ; too large, exit and remove 2 pointers (4 bytes) from stack
23+
sta time_format
24+
cmp #TIMEFORMAT_COUNT ; was the format value in range?
25+
bcc valid_format
3126

32-
; save it while we deal with the TZ string
33-
sta tmp_format
27+
jsr incsp4
28+
bad_cmd:
29+
ldx #$00
30+
lda #FN_ERR_BAD_CMD
31+
rts
32+
33+
valid_format:
3434
; first read tz from string given, and set it as the alternate TZ in fujinet.
35+
; use alternate FN timezone when calling FN
36+
mva #$01, aux1_val
3537
jsr popax
3638
jsr _clock_set_alternate_tz
39+
beq alternate_ok ; returns success status
3740

3841
; an error, but we still have an arg on software stack
39-
bne exit_bad_tz2
42+
jsr incsp2
43+
jmp return1 ; FN_ERR_IO_ERROR
4044

41-
ldy tmp_format
42-
bpl common_tz ; it's between 0 and 6 validated, so this will always branch
45+
alternate_ok:
46+
ldy #$00
47+
time_format = *-1
48+
bpl common_tz ; always
4349

4450
; uint8_t clock_get_time(uint8_t* time_data, TimeFormat format);
4551
_clock_get_time:
4652
tay ; time format enum
47-
cpy #$06 ; was the format value in range?
48-
bcs exit_bad_tz2
53+
; use system FN timezone when calling FN
54+
mva #$00, aux1_val
55+
cpy #TIMEFORMAT_COUNT ; was the format value in range?
56+
bcc common_tz
57+
58+
; exit after removing params from stack
59+
jsr incsp2
60+
jmp bad_cmd
4961

5062
common_tz:
63+
5164
lda t_clock_get_time_cmd, y
5265
sta IO_DCB::dcomnd
5366
lda t_clock_get_time_len, y
@@ -60,25 +73,27 @@ common_tz:
6073
mva #$40, IO_DCB::dstats
6174
ldx #$00
6275
stx IO_DCB::dunuse
63-
stx IO_DCB::daux1
6476
stx IO_DCB::daux2
6577
stx IO_DCB::dbythi
6678
inx ; x = 1
6779
stx IO_DCB::dunit
6880
inx ; x = 2 - as this is a FN non network call, we can keep this low
6981
stx IO_DCB::dtimlo
70-
jsr _bus
71-
jmp _fuji_success
7282

73-
.bss
74-
tmp_format: .res 1
83+
; need to set daux1 to 1 if this is an alternate tz call
84+
ldx #$00
85+
aux1_val = *-1
86+
stx IO_DCB::daux1
87+
88+
jsr _bus
89+
jmp _fn_error
7590

7691
.rodata
7792

7893
; tables for the commands that have to be sent for the different types of time command
7994
; see fuji_clock.h
8095
t_clock_get_time_cmd:
81-
.byte 'T', 'P', SIO_APETIMECMD_GETTZTIME, SIO_APETIMECMD_GETTIME, 'S', 'Z'
96+
.byte 'T', 'P', SIO_APETIMECMD_GETTIME, 'I', 'Z', 'S'
8297

8398
t_clock_get_time_len:
84-
.byte 7, 4, 6, 6, 25, 25
99+
.byte 7, 4, 6, 25, 25, 19

atari/src/fn_clock/clock_get_tz.s

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.export _clock_get_tz
22

33
.import _bus
4-
.import _fuji_success
4+
.import _fn_error
55

66
.import popax
77
.import return0
88

99
.include "device.inc"
10-
.include "fujinet-clock.inc"
10+
.include "clock.inc"
1111
.include "macros.inc"
1212
.include "zp.inc"
1313

@@ -33,8 +33,9 @@ _clock_get_tz:
3333
jsr _bus
3434

3535
; check if we had a success (dstats holds status result)
36-
jsr _fuji_success
37-
bne ok
36+
lda IO_DCB::dstats
37+
jsr _fn_error
38+
beq ok
3839

3940
; error return, we weren't able to find the length of the current timezone
4041
rts
@@ -57,7 +58,8 @@ ok:
5758
; inx ; x = 2 - as this is a FN non network call, we can keep this low
5859
; stx IO_DCB::dtimlo
5960
jsr _bus
60-
jmp _fuji_success
61+
lda IO_DCB::dstats
62+
jmp _fn_error
6163

6264

6365
.bss

atari/src/fn_clock/clock_set_tz.s

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
.export _clock_set_apetime_tz
21
.export _clock_set_tz
2+
.export _clock_set_alternate_tz
33

44
.import _bus
5-
.import _fuji_success
5+
.import _fn_error
66
.import _strlen
77

88
.import popax
99

1010
.include "device.inc"
11-
.include "fujinet-clock.inc"
1211
.include "macros.inc"
1312
.include "zp.inc"
13+
.include "clock.inc"
1414

1515

16-
; uint8_t clock_set_alternate_tz(char *tz);
16+
; uint8_t clock_set_alternate_tz(const char *tz);
1717
_clock_set_alternate_tz:
1818
; for backwards compatibility, this is the same as the old "APETIME" settz
1919
ldy #SIO_APETIMECMD_SETTZ
2020
sty IO_DCB::dcomnd
2121
bne _clock_set_tz_common
2222

23-
; uint8_t clock_set_tz(char *tz);
23+
; uint8_t clock_set_tz(const char *tz);
2424
_clock_set_tz:
2525
ldy #'t'
2626
sty IO_DCB::dcomnd
@@ -50,4 +50,5 @@ _clock_set_tz_common:
5050
inx ; x = 2
5151
stx IO_DCB::dtimlo
5252
jsr _bus
53-
jmp _fuji_success
53+
lda IO_DCB::dstats
54+
jmp _fn_error

atari/src/include/clock.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
SIO_APETIMECMD_GETTIME := $93
2+
SIO_APETIMECMD_SETTZ := $99
3+
4+
SIO_CLOCK_DEVICE_ID := $45
5+
6+
; the number of timeformat entries, values are 0.. (TIMEFORMAT_COUNT - 1)
7+
TIMEFORMAT_COUNT := $07

fujinet-clock.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ typedef enum time_format_t {
1919
// BINARY formats are just the numbers, not ascii characters for the number.
2020
SIMPLE_BINARY, // 7 bytes: [Y(century, e.g. 20), Y(hundreds, e.g. 24), M(1-12), D(1-31), H(0-23), M(0-59), S(0-59)] - Uses the current FN Timezone
2121
PRODOS_BINARY, // 4 bytes: special PRODOS format, see https://prodos8.com/docs/techref/adding-routines-to-prodos/ - Uses the current FN Timezone
22-
APETIME_TZ_BINARY, // 6 bytes: [Day, Mon, Yr (YY), Hour, Min, Sec] - This version honours the Timezone either set in the WebUI or below in the clock_set_tz (both of which update the FN global timezone value)
23-
APETIME_BINARY, // 6 bytes: [Day, Mon, Yr (YY), Hour, Min, Sec] - UTC version of the apetime data. This is for backwards compatibility for Atari Apetime with no TZ set.
22+
APETIME_BINARY, // 6 bytes: [Day, Mon, Yr (YY), Hour, Min, Sec]
2423

2524
// STRING formats are full null terminated strings
2625
TZ_ISO_STRING, // an ISO format: YYYY-MM-DDTHH:MM:SS+HHMM - Uses the current FN Timezone
27-
UTC_ISO_STRING // Current UTC time, still ISO format, but with 0000 offset: YYYY-MM-DDTHH:MM:SS+HHMM
26+
UTC_ISO_STRING, // Current UTC time, still ISO format, but with 0000 offset: YYYY-MM-DDTHH:MM:SS+HHMM
27+
28+
// APPLE 3 SOS format
29+
APPLE3_SOS_BINARY // Apple 3 SOS format, YYYYMMDD0HHMMSS000
2830

2931
} TimeFormat;
3032

@@ -59,10 +61,4 @@ uint8_t clock_get_time(uint8_t* time_data, TimeFormat format);
5961
*/
6062
uint8_t clock_get_time_tz(uint8_t* time_data, const char* tz, TimeFormat format);
6163

62-
// for C implementations, these shouldn't be used by consumer
63-
#define SIO_APETIMECMD_GETTIME 0x93
64-
#define SIO_APETIMECMD_SETTZ 0x99
65-
#define SIO_APETIMECMD_GETTZTIME 0x9A
66-
67-
6864
#endif // FUJINET_CLOCK_H

0 commit comments

Comments
 (0)