Author Topic: how do you put program data->string?  (Read 2578 times)

0 Members and 1 Guest are viewing this topic.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
how do you put program data->string?
« on: June 24, 2011, 11:34:13 am »
The title says it all :P I tried to put program data (tokens) into str2, str1 containing the program name, but i I have no clue how to start this..  ???

Ashbad

  • Guest
Re: how do you put program data->string?
« Reply #1 on: June 24, 2011, 11:37:41 am »
Could you explain a bit more specifically what you're trying t do?  I can guess what it is, but I would rathe be sure before walking you through, as would many others here.

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: how do you put program data->string?
« Reply #2 on: June 24, 2011, 11:51:39 am »
Well i saw Celtic3, it made data in program to str9, (prgm name in str0), so i tried making it, but i didnt know where to start.. point is im trying to use the program to read what's inside other program :D

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: how do you put program data->string?
« Reply #3 on: June 24, 2011, 01:54:04 pm »
First, you need to find the program and store its size and pointer:

Code: (Z80 Assembly) [Select]
ld HL,ProgName ; Get the program name data
rst 20h ; and load it into OP1 (_Mov9ToOp1)
bcall(_ChkFindSym) ; then use _ChkFindSym to find it (_FindSym doesn't work on programs)
ex DE,HL ; and load the pointer to the size bytes (returned as DE) into HL
ld E,(HL) ; then use that to load the low byte into E
inc HL ; and the high byte into D
ld D,(HL) ; effectively loading the size of the program into DE
inc HL ; then inc HL so it points to the actual data
push HL ; push it to save it for later
push DE ; and do the same for DE

Then before you store anything to a string, you need to create that string first (and delete the string before that if it already exists):

Code: (Z80 Assembly) [Select]
ld HL,StrName ; Get the string name data
rst 20h ; and load it into OP1 (_Mov9ToOp1)
rst 10h ; then use _FindSym to find it
jr c,Nonex ; jumping ahead if it already doesn't exist
bcall(_DelVarArc) ; otherwise deleting it
Nonex: ; so it's clean
pop HL ; and popping the DE we saved earlier into HL
push HL ; pushing it again to save it again
bcall(_CreateStrng) ; we create the string (_CreateStrng takes the size of the new string in HL)

Then all you have to do is load the data straight from the program to the string.

Code: (Z80 Assembly) [Select]
pop BC ; Pop the size into BC
pop HL ; and the pointer to the program back into HL
inc DE ; and inc DE twice to skip the size bytes
inc DE ; so it points to the data section of the new string
ldir ; and load the data in
ret ; and we're done :)

And to finish up, here's the data for a program prgmMYPROG and a string Str9.

Code: (Z80 Assembly) [Select]
ProgName:
.db ProgObj,tM,tY,tP,tR,tO,tG,$00
StrName:
.db StrngObj,tVarStrng,tStr9,$00

Haven't tested it yet (doing that right now), but it should work.

EDIT: Checked, and yep it works, except that Spasm does something weird with RSTs :P Changed the two rst rMov9ToOp1's to rst 20h so it compiles.

EDIT2: Added a few comments and optimized it a bit.
« Last Edit: June 24, 2011, 03:28:07 pm by Deep Thought »




Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: how do you put program data->string?
« Reply #4 on: June 24, 2011, 05:24:29 pm »
Thank you so much Deep Thought! and how can i move the progname in str0 to HL?

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: how do you put program data->string?
« Reply #5 on: June 24, 2011, 10:33:50 pm »
Well i saw Celtic3, it made data in program to str9, (prgm name in str0), so i tried making it, but i didnt know where to start.. point is im trying to use the program to read what's inside other program :D

I'm not sure why you would want to put a program's contents into a string unless it was for a BASIC library. ASM has much better ways of reading program data such as reading the program directly from memory. You're looking up the pointer and reading its data to create the string anyway, so...
« Last Edit: June 24, 2011, 10:34:39 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline TiAddict

  • LV3 Member (Next: 100)
  • ***
  • Posts: 68
  • Rating: +0/-0
    • View Profile
Re: how do you put program data->string?
« Reply #6 on: June 25, 2011, 01:08:53 pm »
well i'm not really fluent at ASM so.. :(