kvisc/ka/crt/time.k

85 lines
1.3 KiB
Plaintext

; The OS/K Team licenses this file to you under the MIT license.
; See the LICENSE file in the project root for more information.
;
; struct TIME
; {
; byte sec; +0 (0-59)
; byte min; +1 (0-59)
; byte hour; +2 (0-23)
; byte mday; +3 (0-31)
; byte month; +4 (0-11)
; byte; +5 (pad)
; word year; +6 (0-65536)
; word yday; +8 (0-365)
; word; +10 (pad)
; dword; +12 (pad)
; } 16 bytes
;
;
; int DaysInYear(int year)
;
DaysInYear:
mov rax, 365
; divisible by 4?
rem rcx, ax0, 4
jrcxnz .end
; divisible by 100?
rem rcx, ax0, 100
jrcxnz .leap
; divisible by 400?
rem rcx, ax0, 400
jrcxnz .end
.leap:
inc rax, 1
.end:
ret
;
; TIME *GetTimeUTC(void)
;
GetTimeUTC:
ytime
mov rdi, .buf
; seconds
rem rsi, rax, 60
mov b[rdi], rsi
; minutes
div rsi, rax, 60
rem rsi, 60
mov b[rdi+1], rsi
; hours
div rsi, rax, 3600
rem rsi, 24
mov b[rdi+2], rsi
; month days
div rsi, rax, 3600*24
mov b[rdi+3], rsi
; month
mov b[rdi+4], rbx
; years
mov w[rdi+6], rcx
;
; ydays (TODO)
;
mov rax, .buf
ret
.buf = [24]