[TI ASM] Converting date to number of seconds since epoch

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

[TI ASM] Converting date to number of seconds since epoch

Post by benryves »

(This is for the TI-84 series with its real-time clock).

I need to be able to convert a date and time, where I know the individual numeric components (ie, year, month, day, hour, minute and second) into a number of seconds since 1997/01/01 to set the clock. I also need to be able to go the other way and convert a number of seconds since 1997/01/01 to a date and time.

Does the TI-OS expose such functionality to assembly programmers?

This is for BBC BASIC's TIME$ pseudo-variable. It's a 24-character string in the form Wed,22 Oct 2008.12:46:25. I've written code to convert the string representation to and from the individual components, but the clock chip I'm using makes life easy by storing the date and time components as packed BCD.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: [TI ASM] Converting date to number of seconds since epoch

Post by King Harold »

I tried to search for something like that on WikiTI
But it is an "attack site"?? wtf?
That can't be true, but it makes it annoying to browse it.. I didn't find any useful BCalls - but that doesn't mean that there are none..
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: [TI ASM] Converting date to number of seconds since epoch

Post by benryves »

There's been a problem on Dan's site - something modified the PHP to embed an iframe that linked to a malicious PDF. Andy_J fixed it, but I think he's looking for a new host (current versions of MediaWiki require PHP5, Dan's host only has PHP4).

BrandonW had the answers, though; there are BCALLs to get and set the current date and time via the floating point stack. :)
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: [TI ASM] Converting date to number of seconds since epoch

Post by driesguldolf »

That's why you browse with firefox + noscript (it blocks those attempts) (get adblock too while you're at it) plugin :P
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: [TI ASM] Converting date to number of seconds since epoch

Post by benryves »

driesguldolf wrote:That's why you browse with firefox + noscript (it blocks those attempts) (get adblock too while you're at it) plugin :P
You can disable JavaScript in any browser and as you can clearly see from the screenshot IE blocks said attempts as well. (The restarted tab is because the malicious PDF crashes Foxit).
User avatar
driesguldolf
Extreme Poster
Posts: 395
Joined: Thu 17 May, 2007 4:49 pm
Location: $4080
Contact:

Re: [TI ASM] Converting date to number of seconds since epoch

Post by driesguldolf »

benryves wrote:
driesguldolf wrote:That's why you browse with firefox + noscript (it blocks those attempts) (get adblock too while you're at it) plugin :P
You can disable JavaScript in any browser and as you can clearly see from the screenshot IE blocks said attempts as well. (The restarted tab is because the malicious PDF crashes Foxit).
Well yes, but with noscript allows a much finer degree of control.

(okok... I don't like ie :P)
User avatar
benryves
Maxcoderz Staff
Posts: 3089
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: [TI ASM] Converting date to number of seconds since epoch

Post by benryves »

Or just use Opera where it's built in. ;) Just trying to avoid the browser fanboyism.

Code: Select all

RTC.Write:
	
	ld hl,(Date.Year)	
	.bcall _SetXXXXOP2
	.bcall _OP2ToOP1
	.bcall _PushOP1
	
	ld a,(Date.Month)
	.bcall _SetXXOP1
	.bcall _PushOP1

	ld a,(Date.DayOfMonth)
	.bcall _SetXXOP1
	
	.bcall $516A ; setDate
	
	ld a,(Time.Hour)
	.bcall _SetXXOP1
	.bcall _PushOP1
	
	ld a,(Time.Minute)
	.bcall _SetXXOP1
	.bcall _PushOP1

	ld a,(Time.Second)
	.bcall _SetXXOP1
	
	.bcall $5170 ; setTime
	
	ret
Post Reply