peek (was Re: CHDK 1.4 release + bug reports) - CHDK Releases - CHDK Forum  

peek (was Re: CHDK 1.4 release + bug reports)

  • 6 Replies
  • 423 Views
*

Offline Caefix

  • **
  • 66
  • Sorry, busy deleting test shots...
peek (was Re: CHDK 1.4 release + bug reports)
« on: 27 / November / 2019, 12:58:58 »
Advertisements
 :-X :o :o :-X Troubleshouting is an old bavarian tradition. We call it "Jodeln".

Here I have a simple Lua ask for value[addr]:
Code: [Select]
--[[--
@title peekdemo
@chdk_version 1.4
@param    p peek Address /4*4
 @range   p 4 999996
 @default p 1000
@subtitle :...,....1....,....2....,....3....,....4..
@param    u Logging
 @default u 1
 @range   u 0 1
@param    l Log:
 @default l -23
 --]]--
 print_screen(l)
p=p/4*4 -- avoid nil loop
print(string.format("%08x at 0x%08x",peek(p,4),p ))
print(string.format("%04x:%04x %08x ",peek(p-2,2),peek(p,2),peek(p,4)))
print(string.format("%02x %02x:%02x %02x at %d",peek(p-3,1),peek(p-2,1),peek(p-1,1),peek(p,1),p))

 print_screen(0)
wait_click(0)
The answer I expect is repeating only 4 char values, but only the peek(addr,1) line fits.
9002a011 at 0x00000490
7684:a011 9002a011
95 84:76 11 at 1168

that´s my current private ubasic factor peek, returning int´s 4 chars in expected order.
Code: [Select]
  } elseif x=6 exec {
?"Line1---------",x,bug:=% p,=%peek p,4.
? =%peek p-2,2;":";=%peek p,2,=%peek p,4
? =%peek p-3,1,=%peek p-2,1;":";=%peek p-1,1,=%peek p,1
  break

0x0490 0x95847611
0x9584:0x7611 0x95847611
0x95 0x84:0x76 0x11

edit: upper big endian values outdated, peek polarity switched below. ::)
Code: [Select]
  case TOKENIZER_PEEK:
    accept(TOKENIZER_PEEK);
long x,a=expr(); char s=4;
if (tokenizer_token()==TOKENIZER_COMMA) {
accept(TOKENIZER_COMMA); s=expr()%5; }
    if (a & (s-1)) {ended=1; break;}
    if (s==4) r=(unsigned int) *(unsigned int *)(a); else
    if (s==2) r=(unsigned short) *(unsigned short *)(a); else
    if (s==1) r=(unsigned char) *(unsigned char *)(a);
  break;

/*
memset(&r, (char)(*(char *)a),1);
    if (s>1) { x=0;
memset(&x, (char)(*(char *)(a+1)),1); // for big-endian (a-1) ...
x<<=8; r+=x;
    if (s>3) { x=0;
memset(&x, (char)(*(char *)(a+2)),1);
x<<=16; r+=x; x=0;
memset(&x, (char)(*(char *)(a+3)),1);
x<<=24; r+=x; }
}
break; */
« Last Edit: 29 / November / 2019, 15:49:12 by Caefix »
All lifetime is a loan from eternity.

*

Offline reyalp

  • ******
  • 12218
Re: peek (was Re: CHDK 1.4 release + bug reports)
« Reply #1 on: 27 / November / 2019, 13:38:53 »
Code: [Select]
print(string.format("%04x:%04x %08x ",peek(p-2,2),peek(p,2),peek(p,4)))
p-2 is a different address. If you want to look at the same word as the first version, you need to use peek(p,2) and peek(p+2,2), order depending on your endian preferences.
Don't forget what the H stands for.

*

Offline Caefix

  • **
  • 66
  • Sorry, busy deleting test shots...
Re: peek (was Re: CHDK 1.4 release + bug reports)
« Reply #2 on: 27 / November / 2019, 14:49:50 »
 ??? I expected that line printing 'left short' : 'right short' 'same int'.

edit: int following 95 86:76 11 > e0 02 90 da (p+1,p+2..)
« Last Edit: 27 / November / 2019, 15:03:26 by Caefix »
All lifetime is a loan from eternity.

*

Offline reyalp

  • ******
  • 12218
Re: peek (was Re: CHDK 1.4 release + bug reports)
« Reply #3 on: 27 / November / 2019, 16:20:53 »
??? I expected that line printing 'left short' : 'right short' 'same int'.

edit: int following 95 86:76 11 > e0 02 90 da (p+1,p+2..)
I don't understand.

If p is 100 in your example, then
Code: [Select]
print(string.format("%04x:%04x %08x ",peek(p-2,2),peek(p,2),peek(p,4)))
prints the halfword starting at 98, the halfword starting at 100, and the word starting at 100
The halfword at 98 is a totally different value, not part of the word at 100.
The halfword at 100 is lower two bytes of the word at 100, which on a little endian system like this will be the least significant values, appearing on the right when you print the whole word.
Example (chdkptp, because I'm lazy)
Code: [Select]
con 1> =p=0xff810000 return string.format('0x%08x',peek(p))
2:return:'0xea000001'
con 3> =p=0xff810000 return string.format('0x%04x0x%04x',peek(p,2),peek(p+2,2))
4:return:'0x0001 0xea00'
con 4> =p=0xff810000 return string.format('0x%02x 0x%02x 0x%02x 0x%02x',peek(p,1),peek(p+1,1),peek(p+2,1),peek(p+3,1))
5:return:'0x01 0x00 0x00 0xea'
Don't forget what the H stands for.


*

Offline Caefix

  • **
  • 66
  • Sorry, busy deleting test shots...
Re: peek (was Re: CHDK 1.4 release + bug reports)
« Reply #4 on: 28 / November / 2019, 11:09:29 »
We are talking about int value | eulav tni ( ( (  :lol
90.02:a0.11 at 0x00000490
7684:a011 9002a011
95 84:76 11 at 1168
 95 86:76 < 11 > e0 02 90 (da) | 90.02:a0.11

peeking for char at 0x00000490 =11 is the axis.
I expect there the lowest char of "my" int, Lua-peek takes it as the first char of a string.
"My" int/short is built reading backwards from 11, the other is reading forward and returns that mirrored.
(btw. it´s a 'funny' address in Sx710, something lives there.)
All lifetime is a loan from eternity.

*

Offline reyalp

  • ******
  • 12218
Re: peek (was Re: CHDK 1.4 release + bug reports)
« Reply #5 on: 28 / November / 2019, 16:58:16 »
I still don't understand what you are trying to say, but I'm confident Lua peek works correctly.  It literally just does return *(type *)(address)

That returns the byte/halfword/word starting at the given address in the cameras native little endian byte order. Nothing is "mirrored", that's just how it's stored in memory.
Don't forget what the H stands for.

*

Offline Caefix

  • **
  • 66
  • Sorry, busy deleting test shots...
Re: peek (was Re: CHDK 1.4 release + bug reports)
« Reply #6 on: 30 / November / 2019, 11:10:04 »
Thx @vergilius for that journey, gimmy a ":P".

Now I know  :), that little endian is not a font, and I will not distort the native bytes.

Peek is done.
My con-fusion is gone!  :D


Oops, :blink:?? that´s  conf.using....



 :haha Where  :-X is it gone? :-X?                                                                                                                                          (  (  ( ;)


 :-X :o :o :-X  Beware of not-endian confusion outside!!
All lifetime is a loan from eternity.

 

Related Topics