Utility Functions



 


Api92::WaitKey

The Api92::WaitKey function wait for a key pressed by the user of the program

  • Parameters :
    nothing
  • Return Values :
    D0.w : ScanCode of key pressed
    No other register modified

Api92::util_GetAPD

The Api92::util_GetAPD function gets the current APD value. Notice that on a normal calculator, you can divide by 20 to convert the returned tick value in seconds.

  • Parameters :
    nothing
  • Return Values :
    D0.l : tick value of the current APD
    No other register modified

Api92::util_SetAPD

The Api92::util_SetAPD function sets the current APD value. Notice that on a normal calculator, you can multiply by 20 to convert seconds in tick value.

  • Parameters :
    D0.l : tick value
  • Return Values :
    No register modified

Api92::CopyStr

The Api92::CopyStr copy at max d0 chars from source string to a destination buffer. The source string can be null terminated or 0xD terminated. The output buffer will be null terminated. If the source string length is bigger than d0 chars, the three last chars of the destination buffer will be '…'.

  • Parameters :
    A0.l : Address of source string
    A1.l : Address of destination buffer
    D0.l : Number of chars to copy at max
  • Return Values :
    No register modified

Api92::DecimalToStr

The Api92::DecimalToStr function convert a decimal number to a string.

  • Parameters :
    D0.l : The number to convert (32 bits at max)
    A0.l : Address of the end of the buffer where the string should be put (It must be large enough)
  • Return Values :
    A0.l : Address of the beginning of the zero terminated string.
    No other register modified

Example :

The following example convert the number 211081 in a string

          moveq.l #211081,d0
          lea     EndBuffer(PC),a0
          jsr     api92::InvertArea
          (…)
Buffer:   dcb.b   10,0                ;create a static 10 bytes buffer
EndBuffer:


Api92::HexaToStr

The Api92::HexaToStr function convert a hexadecimal number to a string.

  • Parameters :
    D0.l : The number to convert (32 bits at max)
    D1.l : The number of digit - 1
    A0.l : Address of the beginning of the string buffer (it must be large enough)
  • Return Values :
    None.
    No register modified

Example

The following example draw on the screen at (10,10) the number of folders in hexadecimal.

          moveq.w #FOLDER_HDL,d0         ;$0B for TI-92 (II), $08 for TI-92/TI-89
          jsr     Api92::DEREFd0a0       ;Get address of handle
          addq.l  #2,a0                  ;skip first word
          move.w  (a0),d0                ;number of folders
          moveq.w #3,d1                  ;4 digits
          lea     Buffer(PC),a0
          jsr     api92::HexaToStr
          move.l  a0,a1                  ;for Api92::DrawStringSpecial
          moveq.w #10,d0
          moveq.w #10,d1
          jsr     api92::DrawStringSpecial
          (…)
Buffer:   dcb.b 10,0                     ;create a static 10 bytes buffer


Api92::GetFreeRAM

The Api92::GetFreeRAM function gets the size of free RAM available.

  • Parameters :
    None.
  • Return Values :
    D0.l : Free RAM available
    No other register modified

Example

The following example get the free RAM and draw it at (10,10)


          jsr     api92::GetFreeRAM
          lea     EndBuffer(PC),a0
          jsr     api92::DecimalToStr
          move.l  a0,a1
          moveq.w #10,d0
          moveq.w #10,d1
          jsr     api92::DrawStringSpecial
          (…)
Buffer:   dcb.b   10,0 ;create a static 10 bytes buffer
EndBuffer:dc.b 0




Api92::DEREFd0a0

The Api92::DEREFd0a0 function is used for size-optimization : with only one library call, it gets the address of the memory associated with handle by passing parameters throw CPU registers, modifying only A0.

  • Parameters :
    D0.l : Handle
  • Return Values :
    A0.l : Address of the buffer associated with the handle
    No other register modified

Api92::SetIntVector

The Api92::SetIntvector function modify a interrupt vector in the interrupt vectors table : it should be used both to set a new interrupt vector routine and to restore the old one. Don't forget to save the previous interrupt vector routine address returned in A1.l.

  • Parameters :
    A0.l : Address of the interrupt vector in the table (see INTx_VECTOR and TRAPx_VECTOR constants)
    A1.l : Address of the new interrupt vector routine.
  • Return Values :
    A1.l : Address of the previous interrupt vector routine
    No other register modified

Example

The following example install a new timer interrupt routine and restore it.

move.l  #INT1_VECTOR,a0           ;Set new timer routine address
lea     timer_routine(PC),a1
jsr     api92::SetIntVector
move.l  a1,save_old_vect
(…)
move.l  #INT1_VECTOR,a0           ;Restore old timer routine
move.l  save_old_vect(PC),a1
jsr     api92::SetIntVector
(…)
timer_routine:
(…)                               ;your timer routine
move.l  save_old_vect(PC),-(a7)   ;call old timer routine
rts

(…)
save_old_vect: dc.l 0


Api92::util_BatteriesState

The Api92::util_BatteriesState function gets the current level of batteries on the calculator.

  • Parameters :
    None
  • Return Values :
    D0.w : Batteries Level
      4 - full battery state
    3 - medium battery state
    2 - low battery state
    1 - BATT symbol appears (very low)
    0 - extrem
    No other register modified

Api92::GetBasicArgString

The Api92::GetBasicArgString function returns the string of the arguments required to run a BASIC program

  • Parameters :
    D0.w : Handle of the program
    D1.w : Size of the buffer
    A0.l : Address of the buffer
  • Return Values :
    No other register modified

Api92::RunProg

The Api92::RunProg function executes a program exactly as if it were launch from the Home. Don't forget to delete the HRESULT

  • Parameters :
    On the stack : address of the 0-terminated file name
  • Return Values :
    D0.w : HRESULT of the execution
    No other register modified

Exemple

       pea    filename(PC)
       jsr    api92::RunProg
       addq.l #4,a7
       move.w d0,-(a7)
       beq.s  \nodel
       jsr    tios::HeapFree
\nodel addq.l #2,a7

filename: dc.b "main\ess()",0