Author Topic: Problems reading and displaying data from programs  (Read 4185 times)

0 Members and 1 Guest are viewing this topic.

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Problems reading and displaying data from programs
« on: May 16, 2011, 11:52:04 am »
0.5.1
Im trying to store program names to a program in the following format:
Code: [Select]
4BOB[00] ;length of name, name, terminator

But when i try to read from it, the first character (number) is always 0, and if i try to copy the progname to L1, it either crashes when i execute it, or Axe crashes on compile.

Ok so i have a program called ADAT which holds the data, and the main program looks like this:

Code: [Select]
.ADATRD
GetCalc("prgmADAT")->P ;get pointer to program
Copy("4ABC"[00],P,5) ;Copy first progname to ADAT
Copy("5DEFG"[00],P+4,6) ;Copy next progname to ADAT
Copy(P,A,1) ;Get specified length of first progname
Disp A>Dec ;Display the length (this is always 0 for some reason?)
Copy(P+1,L1,A) ;Copy name+terminator to L1 (this part crashes the calc on compile?)
Disp i
Disp L1 ;Hopefully display the name of the program

???
It also crashes on compile if I replace A in Copy(P+1, L1,A) with 4.
« Last Edit: May 16, 2011, 12:08:06 pm by Broseph Radson »

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Problems reading and displaying data from programs
« Reply #1 on: May 16, 2011, 12:50:36 pm »
You are not creating the program. To create a prog, use GetCalc("prgmBLABLABB",size)-> pointer.
I'm not a nerd but I pretend:

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Problems reading and displaying data from programs
« Reply #2 on: May 16, 2011, 12:55:42 pm »
Forgot to mention i made the prog separate. And after throwing my phone and openly yelling at it in class, my internet seems to be working again.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Problems reading and displaying data from programs
« Reply #3 on: May 16, 2011, 12:59:15 pm »
lol. I have to think 'bout this problem.
I'm not a nerd but I pretend:

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Problems reading and displaying data from programs
« Reply #4 on: May 16, 2011, 01:01:22 pm »
Ill update my axe this thursday

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Problems reading and displaying data from programs
« Reply #5 on: May 16, 2011, 01:07:05 pm »
The problem resides in this line:
Code: [Select]
Copy(P,A,1) ;Get specified length of first progname

It seems that what you want to do is read {P} and put it into A. However, what this is actually doing is reading {P} and putting it into {A}. The reason your debug text always displays 0 is because A retains whatever value it had before your program started, which was probably 0. At the next Copy(), you may think the copy would at least do nothing because A equals 0, but this is not the case. Because of how copying works, it will copy a whopping 65536 bytes from P+1 to L1, horribly corrupting the contents of RAM and causing a certain crash. You want to use this instead:
Code: [Select]
{P}→A


Also, although this isn't causing any fatal errors, the P+4 in line 4 should be P+5.

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Problems reading and displaying data from programs
« Reply #6 on: May 16, 2011, 01:08:36 pm »
The solution came from the soluted person who solves all solvable solutions. Idk what that means. Runer, nice explaination.
I'm not a nerd but I pretend:

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Problems reading and displaying data from programs
« Reply #7 on: May 16, 2011, 01:23:18 pm »
Changing P+4 to P+5 seemed to stop the crashing. Its returning BOB properly now, but {P}->A returns 52 instead of 4.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Problems reading and displaying data from programs
« Reply #8 on: May 16, 2011, 01:42:10 pm »
Oh right, I forgot. Instead of defining program names like "4ABC"[00], you should define them like [04]"ABC"[00]. You want the first byte to be 4, not the ASCII value for 4.
« Last Edit: May 16, 2011, 01:42:52 pm by Runer112 »

Offline Broseph Radson

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 295
  • Rating: +20/-1
  • Its 0x1A4 somewhere
    • View Profile
Re: Problems reading and displaying data from programs
« Reply #9 on: May 16, 2011, 01:46:59 pm »
Ah! IDK why i didnt think of that :banghead:

Thanks :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Problems reading and displaying data from programs
« Reply #10 on: May 25, 2011, 04:32:12 am »
I always had troubles with data myself, I always kept inverting the two different getcalc syntaxes or misordering the code I need, as I never figured out how it worked. This was pretty much what made me drop out of Axe programming a year ago :(