Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
RAM Poke Problem

 
Post new topic   Reply to topic    Forum Index -> ZBasic Native Mode
Author Message
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 14 July 2008, 1:18 AM    Post subject: RAM Poke Problem Reply with quote

Here is a test program:
Code:
Private msgbuf(1 To 64) as Byte
Private bufEnd as UnsignedInteger

Public Sub Main()   
   bufEnd = msgbuf.DataAddress   
   Debug.Print CStrHex(bufEnd); " "; cstrhex(msgbuf.DataAddress)
   Call RAMPoke(&hD7, bufEnd)
   Call RAMPoke(&h11, bufEnd+1)
   Debug.Print CStrHex(bufEnd); " "; cstrhex(msgbuf.DataAddress); " "; CStrHex(RAMPeekWord(bufEnd))
   
   bufEnd = msgbuf.DataAddress   
   Debug.Print CStrHex(bufEnd); " "; cstrhex(msgbuf.DataAddress)   
   Call RAMPokeWord(&h11D7, bufEnd)
   Debug.Print CStrHex(bufEnd); " "; cstrhex(msgbuf.DataAddress); " "; CStrHex(RAMPeekWord(bufEnd))
End Sub

On a ZX24 the output is correct
Code:
00a0 00a0
00a0 00a0 11d7
00a0 00a0
00a0 00a0 11d7

On a ZX-24n it appears to poke the value into the variable rather than the address where the variable is pointing to
Code:
0102 0102
01d7 0102 1100
0102 0102
11d7 0102 1100
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 14 July 2008, 1:34 AM    Post subject: Re: RAM Poke Problem Reply with quote

mikep wrote:
Call RAMPokeWord(&h11D7, bufEnd)

The generated code is
Code:
*(uint16_t *)&zv_bufEnd = 4567;
rather than
Code:
*(uint16_t *)zv_bufEnd = 4567;
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 14 July 2008, 2:21 AM    Post subject: Re: RAM Poke Problem Reply with quote

mikep wrote:
On a ZX-24n it appears to poke the value into the variable rather than the address where the variable is pointing to
Thanks. It is interesting that the address/dereferencing code generated for RamPeek() is correct. Somehow we missed the problem for RamPoke(). A solution to the problem has been identified and tested preliminarily.

One way to work around the problem is to use a based variable:
Code:
Dim msgWord as UnsignedInteger Based msgBuf.DataAddress
msgWord = &H11D7

If you need to populate several elements of msgBuf, you can use an auxiliary variable:
Code:
Dim addr as UnsignedInteger
Dim msgWord as UnsignedInteger Based addr
addr = msgBuf.DataAddr
msgWord = &H11D7

A third option that may be useful if the message buffer lends itself to being described by a structure is to define a structure matching the message and then define a structure variable based on the address of the message buffer.
Back to top
mikep



Joined: 24 Sep 2005
Posts: 765
Location: Austin, TX

Posted: 14 July 2008, 3:41 AM    Post subject: Re: RAM Poke Problem Reply with quote

dkinzer wrote:
[It is interesting that the address/dereferencing code generated for RamPeek() is correct. Somehow we missed the problem for RamPoke(). A solution to the problem has been identified and tested preliminarily.
Just to point out that all 3 variations have the problem.

dkinzer wrote:
One way to work around the problem is to use a based variable:
Code:
Dim msgWord as UnsignedInteger Based msgBuf.DataAddress
msgWord = &H11D7

If you need to populate several elements of msgBuf, you can use an auxiliary variable:
As it turns out I already had the auxillary variable. Here is my code with the work around:
Code:
#if Option.TargetCode="ZVM"
         Call RAMPoke(CByte(length), bufend)
         bufEnd = bufEnd + 1
         Call RAMPokeWord(sequenceNumber, bufEnd)
#else
         Dim msgWord as UnsignedInteger Based bufend
         Dim msgByte as Byte Based bufend
         msgByte = CByte(length)
         bufend = bufend + 1
         msgWord = sequenceNumber
#endif         
         bufEnd = bufEnd + 2
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 14 July 2008, 5:02 AM    Post subject: Re: RAM Poke Problem Reply with quote

mikep wrote:
Just to point out that all 3 variations have the problem.
Yes, they use common code since the only difference is the type of the cast. Consequently, the correction fixed all three.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Native Mode Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group