This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
poopslayer78


Newbie


Joined: 10 Sep 2009
Posts: 28

Posted: 10 Sep 2009 06:07:09 pm    Post subject:

I have a TI 84+ SE and alot of the programs that I want to write require the time of day. I was wondering what procedures are out there for getting the time or setting the clock. I went in to TASM's .inc file and searched for things like "time", "clk", and "clock" but didnt find any ROM calls that looked usefull. I guess this was kinda stupid considering these ROM calls are made for the TI 83 which dosnt even have a clock. Anyway, any help would be appreciated, im kinda a noob to ASM but not to programming in general(and im not just talking about just ti basic here!)
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 10 Sep 2009 07:06:18 pm    Post subject:

You have to use ports.
See: wikiti.brandonw.net
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 10 Sep 2009 07:17:42 pm    Post subject:

There is no official documentation from TI on the subject. Look on WikiTI. There are a few system routines for manipulating the clock, which are only provided by OS 2.30 and above, and which are rather slow (they use floating-point math.)

Port 40h tells whether the clock is running. The current time (seconds since 1997-01-01) can be read from ports 45-48h. Setting the clock is slightly more complicated (see WikiTI for the details.)
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 11 Sep 2009 06:14:39 am    Post subject:

In my high school, the bells were controller by a computer. I wrote a program the uses the RTC (Real Time Clock) to count down to the end of the period. For some reason, this always amazed people. Apparently nobody else ever noticed the bells were automated. Anyway, for some reason the program would crash randomly during the start-up sequence. When I put pauses in there to isolate the problem, it seemed to stop crashing (it actually just became more rare), and I never found the problem.

Here are the routines for the program. You'll need to look up some of the 84-only b_calls on WikiTI. By the way, this program won't work on an Nspire because it uses the index register half-registers.

Code:
;====== Routines ===============================================================
;------ Miscellaneous ----------------------------------------------------------
;cphlde:
;   or   a
;   sbc   hl,de
;   add   hl,de
;   ret


;#include "utils.z80"


;------ Time Routines ----------------------------------------------------------
getCurrentTime:
; Returns current time in HLIX
   call   getRealCurrentTime
   loadTimeBCDE(startTime)
   call   subBCDEfromHLIX
   ret
   
   
getRealCurrentTime:
; Returns real current time in HLIX
   ld   hl, currentTime
   in   a, ($45)
   ld   ixl, a
   in   a, ($46)
   ld   ixh, a
   in   a, ($47)
   ld   l, a
   in   a, ($48)
   ld   h, a
   in   a, ($45)
   cp   ixl            ; In the unlikely event that the time changes whilst we are reading it
   jr   nz, getCurrentTime
   ret


setTime:
; Sets the time to HLIX.
   ld   a, ixl
   out   ($41), a
   ld   a, ixh
   out   ($42), a
   ld   a, l
   out   ($43), a
   ld   a, h
   out   ($44), a
   ld   a, 1
   out   ($40), a
   ld   a, 3
   out   ($40), a
   ret
   


secToHMS:
; Converts seconds into hours, minutes, and seconds.
; Input: HLIX
; Output: CDE: HMS
   ld   a, l
   push   ix
   pop   bc
   ld   de, 60*60
   call   divABCbyDE
   push   bc            ; bc has hours, hl minutes
   push   hl
   pop   bc
   ld   de, 60            ; a is already 0
   call   divABCbyDE         ; bc now has mintes, hl seconds
   ld   e, l
   ld   d, c
   pop   hl
   ld   c, l
   ret


HMStoSec:
; Converts an hours, minutes, and seconds time into seconds.
; Input: CDE
; Output: HLIX: seconds
   di
   push   iy
   push   de
   pop   iy
   ld   hl, 60*60
   ld   e, c
   ld   d, 0
   ld   bc, 0            ; is already hours
   call   multBHLbyCDE
   ld   c, b
   ld   b, 0
   push   bc
   push   hl
   ld   hl, 60
   push   iy
   pop   de
   ld   e, d
   ld   d, 0
   ld   bc, 0
   call   multBHLbyCDE
   ld   c, b
   ld   b, 0
   push   hl
   pop   de
   pop   ix
   pop   hl
   addBCDEtoHLIX
   ld   bc, 0
   ld   d, 0
   ld   e, iyl
   addBCDEtoHLIX
   pop   iy
   ei
   ret



aToString:
; Makes a 2-digit long string out of A.  Well, it could be three, but it's
; always at least two.
   ld   l, a
   ld   h, 0
   ld   de, OP1+1
   call   itoa
   ld   hl, OP1+1
   ld   a, (OP1+2)
   or   a
   ret   nz
   dec   hl
   ld   (hl), "0"
   ret


dispTimeString:
; Makes a string out of a the current time, into OP2
; Input:
; - HLIX: time
; Output:
; - OP2: String
; - String is displayed
   di
   push   iy
   ld   iy, OP2
   call   secToHMS
   push   de
   ld   a, c
   call   aToString
   push   hl
   pop   ix
   ld   a, (ix)
   ld   (iy), a
   ld   a, (ix+1)
   ld   (iy+1), a
   ld   a, ":"
   ld   (iy+2), a
   pop   de
   push   de
   ld   a, d
   call   aToString
   push   hl
   pop   ix
   ld   a, (ix)
   ld   (iy+3), a
   ld   a, (ix+1)
   ld   (iy+4), a
   ld   a, ":"
   ld   (iy+5), a
   pop   de
   ld   a, e
   call   aToString
   push   hl
   pop   ix
   ld   a, (ix)
   ld   (iy+6), a
   ld   a, (ix+1)
   ld   (iy+7), a
   ld   (iy+8), 0
   pop   iy
   ei
   ld   hl, op2
   b_call(_PutS)
   ret


; ITOA
; --------------------------------------------------------------
; Converts a signed integer value to a zero-terminated ASCII
; string representative of that value (using radix 10).
; --------------------------------------------------------------
; INPUTS:
;     HL     Value to convert (two's complement integer).
;     DE     Base address of string destination. (pointer).
; --------------------------------------------------------------
; OUTPUTS:
;     None
; --------------------------------------------------------------
; REGISTERS/MEMORY DESTROYED
; AF HL
; --------------------------------------------------------------
; Modifed to not be signed by nobody special
itoa:
   push   de
   push   bc
; Convert HL to digit characters
_DoConvert:
   ld   b,   0         ; B will count character length of number
m:
   ld   a,   10
   b_call(_DivHLByA)         ; HL = HL / A, A = remainder
   push   af
   inc   b
   ld   a,   h
   or   l
   jr   nz,   m   
; Retrieve digits from stack
n:
   pop   af
   or   $30
   ld   (de),   a
   inc   de
   djnz   n
; Terminate string with NULL
   xor   a
   ld   (de),   a
   pop   bc
   pop   de
   ret


;------ Math Routines ----------------------------------------------------------
;addBCDEtoHLIX:
; 32-bit addition routine
; Input:
; - HLIX: first operand
; - BCDE: second operand
; Output:
; - HLIX: sum
; - carry if overflow

; AHEM.  Now a macro.


subBCDEfromHLIX:
; 32 subtraction routine
; is slightly more complicated.
; Input:
; - HLIX: number to subtract from
; - BCDE: number to subtract
; Output:
; - HLIX: result
; - carrynderflow
   or   a
   push   hl
   push   ix
   pop   hl
   sbc   hl, de
   push   hl
   pop   ix
   pop   hl
sub32nc:
   sbc   hl, bc
   ret

;-------------------------------------------------------------------------------
; These routines are by Milos "baze" Bazelides, from the web page
; [url="http://baze.au.com/misc/z80bits.html"]http://baze.au.com/misc/z80bits.html[/url]
divABCbyDE:
; 24-bit over 16-bit divide
; Input:
; - ABC: Dividend
; - DE: Divisor
; Output:
; - ABC: Quotient
; - HL: Remainder
   ld   hl, 0
   ld   ixl, 24
divABCbyDEloop:
   sll   c      ; unroll 24 times
   rl   b      ; ...
   rla         ; ...
   adc   hl,hl      ; ...
   sbc   hl,de      ; ...
   jr   nc,$+4      ; ...
   add   hl,de      ; ...
   dec   c      ; ...
   dec   ixl
   jr   nz, divABCbyDEloop
   ret
   
   
divHLbyC:
; 16-bit over 8-bit divide
; Input:
; - HL: Dividend
; - C: Divisor
; Output:
; - HL: Quotient
; - A: Remainder
   xor   a
   ld   b, 16
divHLbyCloop:
   add   hl,hl      ; unroll 16 times
   rla         ; ...
   cp   c      ; ...
   jr   c,$+4      ; ...
   sub   c      ; ...
   inc   l      ; ...
   djnz   divHLbyCloop
   ret


;-------------------------------------------------------------------------------
; This routine is by sigma, retrived from
; [url="http://www.detachedsolutions.com/forum/mv/msg/1154/0/15/"]http://www.detachedsolutions.com/forum/mv/msg/1154/0/15/[/url]

multBHLbyCDE:
; 24-bit multiply routine
; Input:
; - BHL: factor
; - CDE: factor
; Output:
; - BHL: product
; - CY: 0
; If there was overflow:
; - BHL = garbage
; - CY = 1
; Disables interrupts
   call   MulS_24
   ei
   ret
   
MulS_24:
   di
   ld   a,b
   xor   c
   push   af
   xor   c
;   call   m,Negate_BHL
   ld   a,c
   or   a
;   call   m,Negate_CDE
   push   iy
   .db   $FD
   ld   h,24
   push   hl
   pop   ix
   xor   a
   sbc   hl,hl
   call   MulLoop
   pop   iy
   jp   pe,Overflow
   ld   b,a
   pop   af
   ret   p
   jp   quit
   
Overflow:
   pop   af
   scf
   ret

MulLoop:
   add   hl,hl
   adc   a,a
   ret   pe
   add   ix,ix
   rl   b
   jr   nc,DontAdd
   add   hl,de
   adc   a,c
   ret   pe
DontAdd:
   .db   $FD
   dec   h
   jr   nz,MulLoop
   ret


If you want, here's the rest of the program. I'd advise against using this code because it has that unfound bug.

Code:
; ==============================================================================
; Countdown timer, by Dr. D'nar
; October 9, 2008
; Bugs:
; - Random crashing on start-up.
; To-do:
; - getStartTime could be done with HMStoSec
;
; Note to self: I no longer fully understand this program.  And I wrote it.


#include "ti83plus.txt"


;====== Equates ================================================================

; Constants
;nameLocation   .equ   $0000
bannerTextLoc   .equ   $0000
timeLocation   .equ   $0801
timeTextLoc   .equ   $0001
endLocation   .equ   $0802
pdEndLocation   .equ   $0002
remainTextLoc   .equ   $0003
remainLocation   .equ   $0803
helpTextLoc   .equ   $0005
maxNumOfPeriods   .equ   50
fooFlags   .equ   xapFlag         ; Mirage uses some Asm_Flags
timeIsUp   .equ   0
statusFlags   .equ   xapFlag
runRestoreFlag   .equ   1


; RAM
spaddr      .equ   appBackUpScreen
; 32-bit times are stored as follows:
; sample number:
; 0x11223344
; byte order in memory:
; 22114433
currentTime   .equ   spaddr+2
startTime   .equ   currentTime+4
targetTime   .equ   startTime+4
foo      .equ   targetTime+4
bar      .equ   foo+2
baz      .equ   bar+2
listPdsLeft   .equ   foo
listLoc      .equ   bar
currentPeriod   .equ   baz+2
numberOfPeriods   .equ   currentPeriod+1
currentPdData   .equ   numberOfPeriods+1
periodTimeTable   .equ   currentPdData+2

; Macros
#define saveTimeBCDE(xxxx) ld (xxxx), bc \ ld (xxxx+2), de
#define loadTimeBCDE(xxxx) ld bc, (xxxx) \ ld de, (xxxx+2)
#define saveTimeHLIX(xxxx) ld (xxxx), hl \ ld (xxxx+2), ix
#define loadTimeHLIX(xxxx) ld hl, (xxxx) \ ld ix, (xxxx+2)
#define breakPoint di \ xor a \ jr z, $ \ ei
#define addBCDEtoHLIX add ix, de \ adc hl, bc   
#define debug
.list
;====== Header =================================================================
   .org   $9D93
   .db   t2ByteTok, tAsmCmp
   
   xor   a
   jr   nc, start
   .db   "Timer (10/28/08)",0
start:
   bit   indicRun, (iy+indicFlags)
   jr   z, noRunIndic
   set   runRestoreFlag, (iy+statusFlags)
   jr   runIndicCont
noRunIndic:
   res   runRestoreFlag, (iy+statusFlags)
runIndicCont:
   res   indicRun, (iy+indicFlags)

; Empty vars area (some may need to be zero)
   ld   hl, appbackupscreen
   ld   b, 700
initApp:
   ld   (hl), 0
   inc   hl
   djnz   initApp
   
   ld   (spaddr), sp
   
; Find model
   in   a, (2)
   bit   5, a
;   jp   z, errModel
   
#ifdef debug
   ld   hl, 0
   ld   (currow), hl
   ld   a, '0'
   b_call(_PutC)
   b_call(_getkey)
#endif

; Load the lists.
   ld   hl, listPDHname
   ld   bc, periodTimeTable
   call   loadListData
   jp   c, errNoLists
   ld   hl, listPDMname
   ld   bc, periodTimeTable+1
   call   loadListData
   jp   c, errNoLists
   ld   hl, listPDSname
   ld   bc, periodTimeTable+2
   call   loadListData
   jr   doneListLoading

loadListData:
   push   bc
   rst   20h            ; Mov9ToOP1
   rst   10h            ; FindSym | hl vat de ram b rom
   pop   ix
   ret   c
   push   ix
   ld   a, b
   or   a
   jp   nz, errArchived
PLDcont:
   inc   de
   ld   a, (de)
   or   a
   jp   nz, errDimMismatch
   dec   de
   ld   a, (de)
   cp   maxNumOfPeriods
   jp   nc, errDimMismatch
   ld   a, (numberOfPeriods)
   or   a
   jr   nz, numberOfPeriodsIsInit
   ld   a, (de)
   ld   (numberOfPeriods), a
numberOfPeriodsIsInit:
   ld   a, (numberOfPeriods)
   ld   c, a
   ld   a, (de)
   cp   c
   jp   nz, errDimMismatch
   ; ---
   ld   hl, 1
   ld   ixl, a
   pop   bc
loadLoop:
   push   de
   push   hl
   push   bc
   di
   ex   af, af'            ; I'm too lazy to figure out which need to be saved
   exx
   ld   hl, errListLoad
   call   APP_PUSH_ERRORH
   exx
   ex   af, af'
   ; No real need to ei yet.
   b_call(_GetLToOP1)         ; hl ele num; de pointer; OP1 output; hl ptr to next ele
   b_call(_ConvOP1)
   di
   ex   af, af'
   exx
   call   APP_POP_ERRORH
   exx
   ex   af, af'
   ei
   pop   bc
   ld   (bc), a
   inc   bc
   inc   bc
   inc   bc
   inc   bc
   pop   hl
   pop   de
   inc   hl
   dec   ixl
   jr   nz, loadLoop
   or   a
   ret

doneListLoading:   
#ifdef debug
   ld   hl, 0
   ld   (currow), hl
   ld   a, '1'
   b_call(_PutC)
   b_call(_getkey)
#endif

; Convert the useless HMS times we just loaded
   ld   a, (numberOfPeriods)
   ld   (listPdsLeft), a
   ld   hl, periodTimeTable
   ld   (listLoc), hl
   
listProcessLoop:
   ld   hl, (listLoc)
   ld   c, (hl)
   inc   hl
   ld   d, (hl)
   inc   hl
   ld   e, (hl)
   call   HMStoSec
   push   hl
   pop   bc
   push   ix
   pop   de
   ld   hl, (listLoc)
   ld   (hl), c
   inc   hl
   ld   (hl), b
   inc   hl
   ld   (hl), e
   inc   hl
   ld   (hl), d
   inc   hl
   ld   (listLoc), hl
   ld   a, (listPdsLeft)
   dec   a
   ld   (listPdsLeft), a
   jr   nz, listProcessLoop
   ld   a, (numberOfPeriods)
   inc   a
   inc   a
   ld   (numberOfPeriods), a
   ld   (hl), $01
   inc   hl
   ld   (hl), $00
   inc   hl
   ld   (hl), $80
   inc   hl
   ld   (hl), $51
   inc   hl

#ifdef debug
   ld   hl, 0
   ld   (currow), hl
   ld   a, '2'
   b_call(_PutC)
   b_call(_getkey)
#endif
   
getStartTime:
; Figure out when today began
   call   getRealCurrentTime
   saveTimeHLIX(startTime)
   push   ix
   b_call(_GetTime)
   call   getRealCurrentTime
   push   ix
   pop   de
   pop   hl
   or   a
   sbc   hl, de
   jr   nz, getStartTime
   ; Calculate the number of seconds since midnight
   b_call(_PopRealO1)
   b_call(_ConvOP1)
   push   de
   b_call(_PopRealO1)
   b_call(_ConvOP1)
   ld   bc, 0
   ld   hl, 60
   call   multBHLbyCDE
   pop   bc
   add   hl, bc
   push   hl
   b_call(_PopRealO1)
   b_call(_ConvOP1)
   ld   bc, 0
   ld   hl, 60*60
   call   multBHLbyCDE
   ld   c, b
   ld   b, 0
   push   hl
   pop   de
   ; BCDE now has the (hours since midnight) turned into (seconds since midnight)
   ld   hl, 0
   pop   ix
   addBCDEtoHLIX   
   ; HLIX now has the number of seconds since midnight
   push   hl
   pop   bc
   push   ix
   pop   de
   loadTimeHLIX(startTime)
   call   subBCDEfromHLIX
   saveTimeHLIX(startTime)

#ifdef debug
   ld   hl, 0
   ld   (currow), hl
   ld   a, '3'
   b_call(_PutC)
   b_call(_getkey)
#endif

findCurrentPeriod:
; Now we want to know what period it is.
   ld   a, (numberOfPeriods)
   ld   (listPdsLeft), a
   ld   hl, periodTimeTable
   ld   (listLoc), hl
findPeriodLoop:
   ld   a, (listPdsLeft)
   dec   a
   ld   (listPdsLeft), a
   jp   z, errCannotFindPeriod
   call   getCurrentTime
   push   hl
   ld   hl, (listLoc)
   ld   c, (hl)
   inc   hl
   ld   b, (hl)
   inc   hl
   ld   e, (hl)
   inc   hl
   ld   d, (hl)
   inc   hl
   ld   (listLoc), hl
   pop   hl
   call   subBCDEfromHLIX
   jr   nc, findPeriodLoop
   ld   hl, (listLoc)
   dec   hl
   dec   hl
   dec   hl
   dec   hl
   ld   (currentPdData), hl
   loadTimeHLIX(startTime)
   addBCDEtoHLIX
   saveTimeHLIX(targetTime)

#ifdef debug
   ld   hl, 0
   ld   (currow), hl
   ld   a, '4'
   b_call(_PutC)
   b_call(_getkey)
#endif

;doneListProcessing:
; Okay, we're past the places likely to get errors, so clear the screen and all.
   b_call(_ClrScrn)

; Time for the main loop
   
   ld   hl, bannerTextLoc
   ld   (CurRow), hl
   ld   hl, bannerText
   set   TextInverse, (iy+TextFlags)
   b_call(_PutS)
   res   TextInverse, (iy+TextFlags)
   ld   hl, helpTextLoc
   ld   (CurRow), hl
   ld   hl, helpText
   b_call(_PutS)
   ld   hl, timeTextLoc
   ld   (CurRow), hl
   ld   hl, timeText
   b_call(_PutS)
   ld   hl, pdEndLocation
   ld   (CurRow), hl
   ld   hl, pdEndText
   b_call(_PutS)
   ld   hl, remainTextLoc
   ld   (CurRow), hl
   ld   hl, remainText
   b_call(_PutS)
   ld   hl, endLocation
   ld   (CurRow), hl
   loadTimeHLIX(targetTime)
   loadTimeBCDE(startTime)
   call   subBCDEfromHLIX
   call   dispTimeString
      
   res   timeIsUp, (iy+fooFlags)
timerLoop:
   
   ; Display current time
   ld   hl, timeLocation
   ld   (CurRow), hl
   call   getCurrentTime
   call   dispTimeString
   
   ; Display time remaining
   ld   hl, remainLocation
   ld   (CurRow), hl
   call   getRealCurrentTime
   saveTimeHLIX(currentTime)
   push   hl
   pop   bc
   push   ix
   pop   de
   loadTimeHLIX(targetTime)
   call   subBCDEfromHLIX
   call   dispTimeString
   
   ; Wait until next second.
   in   a, ($45)
   ld   b, a
loopWaitLoop:
; halt?
   b_call(_GetCSC)
   cp   skClear
   jp   z, quitAndClear
   cp   skStore
   jr   z, sync
   cp   skAdd
   jr   z, syncUp
   cp   skSub
   jr   z, syncDown
   in   a, ($45)
   cp   b
   jr   z, loopWaitLoop
   
   bit   timeIsUp, (iy+fooFlags)   
   jp   nz, getStartTime
   loadTimeBCDE(currentTime)
   loadTimeHLIX(targetTime)
   call   subBCDEfromHLIX
   ld   a, ixh
   or   a
   jr   nz, timerLoop
   ld   a, ixl
   or   a
   jr   nz, timerLoop
   set   timeIsUp, (iy+fooFlags)
   jp   getStartTime


sync:
   call   getRealCurrentTime
   call   setTime
   jp   getStartTime


syncUp:
   loadTimeHLIX(targetTime)
   call   setTime
   jp   getStartTime


syncDown:
   ld   hl, (currentPdData)
   ld   de, periodTimeTable
   or   a
   sbc   hl, de
   add   hl, de
   jr   z, loopWaitLoop   
   dec   hl
   ld   d, (hl)
   dec   hl
   ld   e, (hl)
   dec   hl
   push   de
   pop   ix
   ld   d, (hl)
   dec   hl
   ld   e, (hl)
   push   de
   pop   hl
   loadTimeBCDE(startTime)
   addBCDEtoHLIX
   call   setTime
   jp   getStartTime
   
   

;-------------------------------------------------------------------------------
errListLoad:
   push   af
   b_call(_NewLine)
   ld   hl, errListLoadText
   b_call(_PutS)
   pop   af
   ld   l, a
   ld   h, 0
   b_call(_DispHL)
   ld   a, $29
   b_call(_PutC)
   jr   quit
quitAndClear:
   b_call(_ClrScrn)
   b_call(_HomeUp)
   jr   quitNoNewLine
errArchived:
   ld   hl, errArchivedText
   jr   quitErrMsg
errDimMismatch:
   ld   hl, errDimMismatchText
   jr   quitErrMsg
errCannotFindPeriod:
   ld   hl, errCannotFindPeriodText
   jr   quitErrMsg
errNoLists:
   ld   hl, errNoListsText
   jr   quitErrMsg
errModel:
   ld   hl, errModelText
quitErrMsg:
   push   hl
   b_call(_NewLine)
   pop   hl
   b_call(_PutS)
quit:
   b_call(_NewLine)
quitNoNewLine:
   bit   runRestoreFlag, (iy+statusFlags)
   jr   z, quitNoRunIndic
   set   indicRun, (iy+indicFlags)
   jr   quitRunIndicCont
quitNoRunIndic:
   res   indicRun, (iy+indicFlags)
quitRunIndicCont:
;   b_call(_RunIndicOn)
   res   DonePrgm, (iy+DoneFlags)
   res   OnInterrupt, (iy+OnFlags)
   ld   sp, (spaddr)
   ret

; ROUTINES GO HERE!

;====== Data ===================================================================
;       1234567890123456
errModelText:
   .db   "A TI-84/SE is   required.", 0
errNoListsText:
;       lPDH and lPDM   required.
   .db   $DC, "PDH and ", $DC, "PDM   required.", 0
errCannotFindPeriodText:
   .db   "Could not find  period.", 0
errArchivedText:
   .db   "Lists are       archived.", 0
errDimMismatchText:
   .db   "Lists do not    match.", 0
errListLoadText:
   .db   "List load error (#", 0
listPDHname:
   .db   RealObj, tVarLst, "PDH", 0
listPDMname:
   .db   RealObj, tVarLst, "PDM", 0
listPDSname:
   .db   RealObj, tVarLst, "PDS", 0
;       1234567890123456
timeText:
   .db   "Time:", 0
pdEndText:
   .db   "Pd End:", 0
remainText:
   .db   "Remain:", 0
bannerText:
   .db   "  Period Timer  ", 0
helpText:
;       1234567890123456
   .db   "STO for sync    "
   .db   "+ sync to next  "
   .db   "- sync to prev", 0
.end
.end

If anyone finds the problem, do tell me. I'd like to actually publish this.


Last edited by Guest on 11 Sep 2009 06:31:04 am; edited 1 time in total
Back to top
poopslayer78


Newbie


Joined: 10 Sep 2009
Posts: 28

Posted: 11 Sep 2009 07:30:54 am    Post subject:

I wrote a program to do that in ti basic Smile so everyone asks me for the countdown so they can run to lunch. Im basicly upgrading it and the program to sync it to asm, Great minds think alike i guess. Anyway, do you have the utils.z80 file so i can download it?

Last edited by Guest on 11 Sep 2009 07:33:38 am; edited 1 time in total
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 11 Sep 2009 07:58:57 am    Post subject:

Yeah, I started in BASIC too.

If you've never programmed in assembly, I really think you should not try to fix the start-up code. Scrap it. I'm not sure it handles the error handlers correctly. (See the SDK.)

The utilities file just contains some code for debugging. Milos has a better routine for display bytes.

Code:
dispByte:
; Displays a byte in hex.
; A is the byte to display.
   push   af
   push   bc
   push   af
   ; first nibble
   srl   a
   srl   a
   srl   a
   srl   a
   ld   b, '0'
   cp   $0A
   jr   c, disp_nibble_next_nibble
   ld   b, 'A'-$0A
disp_nibble_next_nibble:   
   add   a, b
   b_call(_putc)
   
   ; second nibble
   pop   af
   ld   b, %00001111
   and   b
   ld   b, '0'
   cp   $0A
   jr   c, disp_nibble_last_nibble
disp_nibble_2_letter:
   ld   b, 'A'-$0A
disp_nibble_last_nibble:
   add   a, b
   b_call(_putc)
   pop   bc
   pop   af
   ret

dispHLIX:
   ld   a, h
   call   dispByte
   ld   a, l
   call   dispByte
   ld   a, ixh
   call   dispByte
   ld   a, ixl
   call   dispByte
   ret
   
dispBCDE:
   ld   a, b
   call   dispByte
   ld   a, c
   call   dispByte
   ld   a, d
   call   dispByte
   ld   a, e
   call   dispByte
   ret


The Milos routine for displaying hex. You can just call LToHexString to display a single byte.

Code:
HLToHexString:
;Input: HL = number to convert, DE = location of ASCII string
;Output: ASCII string at (DE)
   ld   a,h
   call   LNum1
   ld   a,h
   call   LNum2
LToHexString:   ld   a,l
   call   LNum1
   ld   a,l
   jr   LNum2

LNum1:   rra
   rra
   rra
   rra
LNum2:   or   0F0h
   daa
   add   a,0A0h
   adc   a,40h

   ld   (de),a
   inc   de
   xor   a
   ld   (de), a
   ret


Last edited by Guest on 11 Sep 2009 01:21:38 pm; edited 1 time in total
Back to top
poopslayer78


Newbie


Joined: 10 Sep 2009
Posts: 28

Posted: 11 Sep 2009 10:49:40 am    Post subject:

In the comments in your source code, what exactly go you mean by HLIX? does that mean hex? Time stamp?
Back to top
Mapar007


Advanced Member


Joined: 04 Oct 2008
Posts: 365

Posted: 11 Sep 2009 11:28:36 am    Post subject:

Display the bytes of HL, then IX after each other.
Back to top
poopslayer78


Newbie


Joined: 10 Sep 2009
Posts: 28

Posted: 11 Sep 2009 11:33:53 am    Post subject:

ok i think i get it, but i still need the #include file that contains all the 84 only procedures before i can write any code. i can only find stuff for the ti83 on wikiti and nothing for the 84. Google search has yeilded nothing so far.

Last edited by Guest on 11 Sep 2009 11:36:08 am; edited 1 time in total
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 11 Sep 2009 01:19:27 pm    Post subject:

The Z80 is an 8-bit CPU with 16-bit addresses. Squeezing 32-bit math out of it isn't easy. HLIX and BCDE are 32-bit register combos used to store 32-bit times. Much like HL has the MSB of a 16-bit number in H and the LSB in L; BCDE has the MSB in B, the next most significant byte in C, the next most significant in D, and the least significant in E.

If you want the equates for the new bcalls, look in WikiTI. The Wiki is somewhat broken (*looks at BrandonW*), but it's still a good source of information. Try doing Google queries like "site:wikiti.brandonw.net foo bar" to find foo bar on the Wiki. This Wiki page lists all of the Clock routines. To add getTmFmt to your include file, do:
[font="Lucida Console"]_getTmFmt .equ 5161h

because the BCALL address is 5161. Don't forget the [font="Lucida Console"]h.

If you haven't already, check out Learn Assembly in 28 Days and TI's official SDK. Both are out-dated and have some incorrect information, but are very helpful. You can also download LAI28D from TICalc.org for offline reference. In addition to running WikiTI, Brandon Wilson also has some other good things on his site.

Despite my efforts to the contrary, it seems my code always ends up being disjointed and full of kludges. So it's probably not a good idea to read it for help or ideas.
Back to top
poopslayer78


Newbie


Joined: 10 Sep 2009
Posts: 28

Posted: 12 Sep 2009 12:07:36 pm    Post subject:

OK im close, Ive managed to get it to display the seconds part of the time by calling _getTime and then moving the value in OP1 to HL then displaying it. On wikiti it says that the outputs are as follows...

OP1=Seconds
FPST=Seconds
FPS1=Minutes
FPS2=Hours

It says that FPST is a pointer to the top of the floating point stack at the end of free RAM. The problem is i havnt been able to get anything from whatever FPST is. Help?
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 12 Sep 2009 01:14:55 pm    Post subject:

The FPST is the floating point stack. It is described on page 57 (67 of 188) in the [http://education.ti.com/downloads/guidebooks/sdk/83p/sdk83pguide.pdf]SDK guide[/url]. The FPST is much like the Z80's stack in that you can push and pop numbers to it, but the numbers are floating-point numbers in TI's format. The FPST is used to evaluate expressions in calculations. You can use _PopRealOn to pop the entries on the FPST into OPn. Please note:
[quote name='"TI's Offical SDK' date=' p59"']• Any allocations (pushes) to the FPS are the responsibility of the routine that made the allocation. Some system routines will take arguments that have been put onto the FPS and will remove them.
• Not cleaning the FPS properly could cause system lockups during application execution or after the application is exited.[/quote]
Some of the math routines you will want to use might throw errors. If you can't find a way to check for the condition before-hand, you should try installing an error handler. Beware! Errors cannot be safely thrown from within MirageOS. If your program is a nostub program, you can use the OS error handler to quit; but if you're running from a shell, using the error handler to quit is not safe. If you're running from within a shell, you must use an error handler.
Back to top
poopslayer78


Newbie


Joined: 10 Sep 2009
Posts: 28

Posted: 12 Sep 2009 01:32:39 pm    Post subject:

OMG!!!! IT WORKS!!!! ty sooooo much!
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 12 Sep 2009 02:04:07 pm    Post subject:

If you use the system routines to read the clock, do be sure to set an error handler (for memory or math errors) and do be sure to check the OS version beforehand. And always pop as many times as you push. :)

Also realize that those routines will not play well with ionDetect.


Last edited by Guest on 12 Sep 2009 02:06:18 pm; edited 1 time in total
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 12 Sep 2009 02:22:13 pm    Post subject:

It's the Law of Conservation of Stack Space: For every PUSH, there must be an equal and opposite POP.

For information on error handlers, check out page 99 (109 of 188) of the SDK. It's important to use them if you're loading information from variables that the user sets. If you set an error handler and the user inputs bad data, you get an error. Or a crash, if you're running from a shell.
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 12 Sep 2009 02:31:45 pm    Post subject:

[quote name='Dr. D'nar' post='136484' date='Sep 12 2009, 03:22 PM']It's the Law of Conservation of Stack Space: For every PUSH, there must be an equal and opposite POP.[/quote]
Actually, in this case WikiTI isn't entirely clear: do the getTime and getDate routines push results onto the FPS, or simply copy the results there (replacing the former contents?)

We should have a Wiki cleanup party. Smile


Last edited by Guest on 12 Sep 2009 02:59:21 pm; edited 1 time in total
Back to top
DrDnar


Member


Joined: 28 Aug 2009
Posts: 116

Posted: 12 Sep 2009 03:07:19 pm    Post subject:

I assumed they pushed them on. Could that explain the random crashes---I wasn't cleaning up the FPST properly?
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 12 Sep 2009 04:16:17 pm    Post subject:

I don't know the answer, and I don't have a calculator or a disassembler handy at the moment.
Back to top
poopslayer78


Newbie


Joined: 10 Sep 2009
Posts: 28

Posted: 18 Sep 2009 05:21:56 pm    Post subject:

Why not just push something on to the stack, run the getTime routine, and see if the value you pushed on first is under the time that the routine apparently pushes on? I kinda assumed that the routine acted as a PUSH.
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 18 Sep 2009 08:07:16 pm    Post subject:

Sure, that would work. There are plenty of ways to test it. I just tested it myself; both routines do indeed push three values onto the FPS.
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement