|
| 1 | + .export _clock_get_time |
| 2 | + |
| 3 | + .import _sp_count |
| 4 | + .import _sp_get_clock_id |
| 5 | + .import _sp_payload |
| 6 | + .import _sp_status |
| 7 | + |
| 8 | + .import incsp2 |
| 9 | + .import popax |
| 10 | + .import pusha |
| 11 | + .import return0 |
| 12 | + .import return1 |
| 13 | + |
| 14 | + .include "macros.inc" |
| 15 | + .include "zp.inc" |
| 16 | + |
| 17 | +; uint8_t clock_get_time(uint8_t* time_data, TimeFormat format); |
| 18 | + |
| 19 | +_clock_get_time: |
| 20 | + sta time_format ; format, save it where we need it! saves a BSS byte |
| 21 | + |
| 22 | + ; 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) |
| 23 | + jsr _sp_get_clock_id |
| 24 | + bne got_id |
| 25 | + |
| 26 | + ; no clock found, return 1 as an error (FN_ERR_IO_ERROR) |
| 27 | + ; but first adjust the stack to remove the data pointer |
| 28 | +error: |
| 29 | + jsr incsp2 |
| 30 | + jmp return1 |
| 31 | + |
| 32 | +got_id: |
| 33 | + ; call sp_status(uint8_t dest, uint8_t statcode) |
| 34 | + sta tmp1 ; save the clock device id |
| 35 | + |
| 36 | + ; convert the time format to the appropriate device specific code. |
| 37 | + ; SIMPLE_BINARY (0) -> 'T' |
| 38 | + ; PRODOS_BINARY (1) -> 'P' |
| 39 | + ; APETIME_TZ_BINARY (2) -> 'A' |
| 40 | + ; APETIME_BINARY (3) -> 'B' |
| 41 | + ; TZ_ISO_STRING (4) -> 'S' |
| 42 | + ; UTC_ISO_STRING (5) -> 'Z' |
| 43 | + |
| 44 | + ldx #$00 |
| 45 | +time_format = *-1 |
| 46 | + ; ensure the value is valid |
| 47 | + cpx #$06 |
| 48 | + bcs error |
| 49 | + pusha tmp1 |
| 50 | + lda code_table, x |
| 51 | + |
| 52 | + jsr _sp_status |
| 53 | + bne error |
| 54 | + |
| 55 | + ; results are in sp_payload, the clock data returned is small (4 to 26 bytes) |
| 56 | + ; _sp_count holds the number of bytes to copy from sp_payload, will always contain at least 1 byte (null terminator) |
| 57 | + popax ptr1 ; read the time_data location into ptr1 |
| 58 | + ldy #$00 |
| 59 | +: lda _sp_payload, y |
| 60 | + sta (ptr1), y |
| 61 | + iny |
| 62 | + cpy _sp_count |
| 63 | + bne :- |
| 64 | + |
| 65 | + jmp return0 |
| 66 | + |
| 67 | +.data |
| 68 | +code_table: |
| 69 | + .byte 'T', 'P', 'A', 'B', 'S', 'Z' |
| 70 | + |
0 commit comments