Hi.

As the title says, I'm looking for how to take a hardcoded string in my program and put it into the Ans variable in eZ80. I'm not very familiar with the whole OP0-OP9 thing but I believe those are somewhat involved. If you could also point me to somewhere to learn about OP0-OP9 and their uses, that would be greatly appreciated!
In Asm, using TIOS asm routines:
Code:
include '../fasmg-ez80/ez80.inc'
include '../fasmg-ez80/tiformat.inc'
include '../ti84pceg.inc'
format ti protected executable program 'ANSSTRNG'

   call   ti.AnsName
   call   ti.FindSym
   call   nc, ti.DelVar
   ld   hl, hardcoded.size
   call   ti.CreateStrng
   inc   de
   inc   de
   ld   hl, hardcoded
   ldir
   ret

hardcoded db ti.tP, ti.t2ByteTok, ti.tLi, ti.tSpace, ti.tEQ, ti.tSpace, ti.t3, ti.tDecPt, ti.t1, ti.t4
.size := $ - .
In Asm, using TIOS C routine:
Code:
include '../fasmg-ez80/ez80.inc'
include '../fasmg-ez80/tiformat.inc'
include '../ti84pceg.inc'
format ti protected executable program 'ANSSTRNG'

   ld   hl, hardcoded
   push   hl
   ld   hl, ans
   push   hl
   call   ti.os.CreateString
   pop   bc
   pop   bc
   ret

ans db ti.tAns, 0
hardcoded dw hardcoded.size
.data db ti.tP, ti.t2ByteTok, ti.tLi, ti.tSpace, ti.tEQ, ti.tSpace, ti.t3, ti.tDecPt, ti.t1, ti.t4
.size := $ - .data
In C, using fileioc:
Code:
#include <fileioc.h>
#include <stdint.h>
#include <tice.h>

#define tsSpace "\x29"
#define ts1     "1"
#define ts3     "3"
#define ts4     "4"
#define tsDecPt "\x3A"
#define tsP     "P"
#define tsEQ    "\x6A"
#define tsLi    "\xBB\xB8"

#define TI_CONST_STRING(name, value) \
    struct { \
        uint16_t length; \
        char data[sizeof(value) - 1]; \
    } name = { \
        .length = sizeof(value) - 1, \
        .data = value, \
    }

int main() {
    static const TI_CONST_STRING(hardcoded, tsP tsLi tsSpace tsEQ tsSpace ts3 tsDecPt ts1 ts4);
    ti_SetVar(TI_STRING_TYPE, ti_Ans, &hardcoded);
}
In C, using TIOS C routine, when toolchain updates:
Code:
#include <stdint.h>
#include <tice.h>

#define tsSpace "\x29"
#define ts1     "1"
#define ts3     "3"
#define ts4     "4"
#define tsDecPt "\x3A"
#define tsP     "P"
#define tsEQ    "\x6A"
#define tsLi    "\xBB\xB8"

#define os_Ans  "\x72"

#define TI_CONST_STRING(name, value) \
    struct { \
        uint16_t length; \
        char data[sizeof(value) - 1]; \
    } name = { \
        .length = sizeof(value) - 1, \
        .data = value, \
    }

int main() {
    static const TI_CONST_STRING(hardcoded, tsP tsLi tsSpace tsEQ tsSpace ts3 tsDecPt ts1 ts4);
    os_CreateString(os_Ans, (const string_t *)&hardcoded);
}
Look at the source code to TextLib.


Code:

StoStringToAns:
; Stores a string to Ans.
; This will throw an error if there's insufficient memory.
; Inputs:
;  - HL: Pointer to string
;  - DE: Size of string IN BYTES NOT TOKENS
;  - IY: Should already be set to point to flags
; Outputs:
;  - String stored
; Destroys:
;  - Assume all registers
   push   hl
   push   de
   ; Check if size is zero, but don't use result yet
   or   a, a
   sbc   hl, hl
   sbc   hl, de
   push   af
   call   CreateTempString
   pop   af
   pop   bc
   pop   hl
   ; Skip over size bytes
   inc   de
   inc   de
   jr   z, $+4   ; If the string is zero-length, skip the copy
   ldir
   call   _OP4ToOP1
   call   _OP1ToOP6
   call   _StoAns   ; Performs the actual store-to-Ans
   ; Now delete the temporary variable
   call   _OP6ToOP1
   call   _FindSym
   ret   c   ; This should never happen. . . .
   call   _DelVar
   ret


;------ CreateTempString -------------------------------------------------------
CreateTempString:
; Creates a temporary string variable.
; WARNING: If insufficient RAM is available, this will throw an error!
; You might want to push an error handler to the stack before calling this.
; Inputs:
;  - DE: Size
; Outputs:
;  - HL: Pointer to VAT entry
;  - DE: Pointer to data
;  - OP4: Name of temporary item.
;    You can B_CALL(_OP4ToOP1) and then B_CALL(_StoAns) to store it to Ans.
; Destroys:
;  - Assume all
   call   TempStringName
   ex   de, hl
   call   _CreateStrng
   ret

TempStringName:
; Creates a unique temporary string name.
; Inputs:
;  - None
; Outputs:
;  - Name in OP1
; Destroys:
;  - HL
   ld   hl, '$' | (StrngObj << 8)
   ld   (OP1), hl
   ld   hl, (pTempCnt)
   ld   (OP1 + 2), hl
   inc   hl
   ld.sis   (0FFFFh and pTempCnt), hl
   ret
  
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
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement