Author Topic: How do I load a symbol into a string?  (Read 7943 times)

0 Members and 1 Guest are viewing this topic.

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
How do I load a symbol into a string?
« on: April 16, 2019, 07:03:45 pm »
I'm trying to put A into Str0, but I don't know how.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: How do I load a symbol into a string?
« Reply #1 on: April 16, 2019, 07:28:48 pm »
Do you mean the token, "A" ?
You'll need to verify that the string exists, then verify its size. Then it is simply a matter of writing the token. In this case, it is a 1-byte token and happens to correspond to the ASCII value (0x41).

If all you want is to make Str0="A", the easy way is to check if it exists, delete it if so, then create a new string of size 1, then load the bytes into it.
Code: [Select]
; Load the name into OP1
 ld hl,$09AA    ; internally, Str0 is represented as 0xAA09
 ld (OP1+1),hl

; Check if it exists and delete if necessary
 rst rFindSym
 jr c,make_str0
 bcall(_DelvarArc)
make_str0:

; Now create Str0 with size 1. Put the name in OP1 first
 ld hl,$09AA
 ld (OP1+1),hl

; Size is 1 byte
 ld hl,1
 bcall(_CreateStrng)

;Pointer to size bytes is in DE. Switch to HL
 ex de,hl

; Don't need the size, so skip those two bytes and get to the start of the data
 inc hl
 Inc hl

; Now write the token
 ld (hl),tA    ; if using ti83plus.inc. same as $41 or in this specific case, 'A'

;Done!
 ret
Please note that I haven't tested this; I'm on mobile so it was heck to type as it is :D

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: How do I load a symbol into a string?
« Reply #2 on: April 16, 2019, 08:13:34 pm »
No, I wanna put the contents of the A register into Str0, as a character/symbol, not a number.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: How do I load a symbol into a string?
« Reply #3 on: April 16, 2019, 08:17:26 pm »
Oh, just do same code, but push af first, and then instead of ld (hl),tA use pop af \ ld (hl),a

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: How do I load a symbol into a string?
« Reply #4 on: April 16, 2019, 08:31:58 pm »
 ,Doesn't seem to work, send me the code to store Ans (as a character) into Str0 maybe?

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: How do I load a symbol into a string?
« Reply #5 on: April 16, 2019, 08:34:44 pm »
I'm going to be honest: at this point, I'm not sure I understand what you are asking. I thought you wanted to store the A register into Str0 as a byte?

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: How do I load a symbol into a string?
« Reply #6 on: April 16, 2019, 08:38:34 pm »
What I'm trying to say is I want the code to store Ans as a byte into Str0, I'll add a please if needed.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: How do I load a symbol into a string?
« Reply #7 on: April 16, 2019, 08:40:24 pm »
You mean the OS variable, Ans (which is a float), converted to an 8-bit integer and then stored as a byte in Str0 ?

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: How do I load a symbol into a string?
« Reply #8 on: April 16, 2019, 08:45:56 pm »
Yeah, the idea is to enter a number from 0 to 255 into Ans and then run the program, That way you'll get the corresponding symbol stored into Str0.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: How do I load a symbol into a string?
« Reply #9 on: April 16, 2019, 08:50:06 pm »
Well it should be the same code with the push \ pop and at the top bcall(_RclAns) \ bcall(_ConvOP1).

Offline joshuarpl

  • LV2 Member (Next: 40)
  • **
  • Posts: 23
  • Rating: +0/-0
    • View Profile
Re: How do I load a symbol into a string?
« Reply #10 on: April 16, 2019, 08:57:15 pm »
I don't know what you mean on where to put the extra or replaced instructions, I tried this
Code: [Select]
bcall(_RclAns)
 bcall(_ConvOP1)
 push af
; Load the name into OP1
 ld hl,$09AA    ; internally, Str0 is represented as 0xAA09
 ld (OP1+1),hl

; Check if it exists and delete if necessary
 rst rFindSym
 jr c,make_str0
 bcall(_DelvarArc)
make_str0:

; Now create Str0 with size 1. Put the name in OP1 first
 ld hl,$09AA
 ld (OP1+1),hl

; Size is 1 byte
 ld hl,1
 bcall(_CreateStrng)

;Pointer to size bytes is in DE. Switch to HL
 ex de,hl

; Don't need the size, so skip those two bytes and get to the start of the data
 inc hl
 Inc hl

; Now write the token
 pop af    ; if using ti83plus.inc. same as $41 or in this specific case, 'A'
 ld (hl),a

;Done!
 ret
But it didn't store anything into Str0, infact it did nothing, I feel ripped off, could you send me the code itself instead of telling to "put instructions in certain locations"?
Also, I don't mean to be rude.

Offline E37

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 358
  • Rating: +23/-0
  • Trial and error is the best teacher
    • View Profile
Re: How do I load a symbol into a string?
« Reply #11 on: April 18, 2019, 01:25:39 pm »
I don't know what you mean on where to put the extra or replaced instructions, I tried this
Code: [Select]
bcall(_RclAns)
 bcall(_ConvOP1)
 push af
; Load the name into OP1
 ld hl,$09AA    ; internally, Str0 is represented as 0xAA09
 ld (OP1+1),hl

; Check if it exists and delete if necessary
 rst rFindSym
 jr c,make_str0
 bcall(_DelvarArc)
make_str0:

; Now create Str0 with size 1. Put the name in OP1 first
 ld hl,$09AA
 ld (OP1+1),hl

; Size is 1 byte
 ld hl,1
 bcall(_CreateStrng)

;Pointer to size bytes is in DE. Switch to HL
 ex de,hl

; Don't need the size, so skip those two bytes and get to the start of the data
 inc hl
 Inc hl

; Now write the token
 pop af    ; if using ti83plus.inc. same as $41 or in this specific case, 'A'
 ld (hl),a

;Done!
 ret
But it didn't store anything into Str0, infact it did nothing, I feel ripped off, could you send me the code itself instead of telling to "put instructions in certain locations"?
Also, I don't mean to be rude.

Since you seem to be trying to do something for a basic program, here is a solution in basic.

First you got to go through ti83plus.txt and go to the tokens section. Pull up an ascii chart and start hunting. It will take a lot of work to go through every ascii character and find the token equivalent to it.Then you take all of them in order and include them as data in an asm program. Many of the tokens will be 2 bytes long, but remember that the ones that aren't take up only one byte and don't need to be headed by a 0. Then have your program copy all of that into a new basic program. There you go. You have all 255 ascii characters in a basic program. It is a simple task to put some quotes around that do 'sub(' directly on that with Ans being your index. It might be easier to just put all the tokens in one program and then sort and order them from there. Alternately if you can't be bothered to do a bit of work, there is some basic program out there on ticalc that has all the ascii characters in order. If you can find it you can skip right to the 'sub(' part. I, for one, can't be bothered to hunt for it but I know it is out there.

Maybe if you told why you want to do this it would be easier to help you.  :P
I'm still around... kind of.