Shop OBEX P1 Docs P2 Docs Learn Events
ASM memory acess problem — Parallax Forums

ASM memory acess problem

KyeKye Posts: 2,200
edited 2009-01-01 05:08 in Propeller 1
Hello all,

I've been having a bit of problems with the rdbyte instruction and using inbedded address when starting a cog process with asm. Basically here is what I'm doing.


~VAR

byte scaling

~PUB setScaling(value)

scaling := value

~PUB driver

scalingAddress := @scaling

cognew(@intialization, $00000000)

~DAT

... More code here

rdbyte buffer, scalingAddress

....More code here

scalingAddress long 0


The set scaling command is not working, I believe that the address of the scaling value is not being passed propely.

The idea is that I embed the address of the varaible in the main memory into the cog when the cog is launched so I can eassily acess the variable without a look table or any type of translation. I have used this approach now with my own homebrew video driver, mouse, and keyboard driver and the method has always worked.

Basically, I know the rdbyte command is the problem in my program, I inserted some mov commands in after to set the value to a test value and the program behaves as it should. I even inserted an address into the scalingAddress variable to grab the first few bytes out of the main memory looking at the image that is created by the complier and the program works as it should.

So what am I doing wrong? I using the same method for wrbyte in the program and everything works fine. But for rdbyte it seems as if the instruction is grabing the wrong variable...


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Nyamekye,

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-29 18:21
    What you wrote should work. Perhaps what you didn't show is where the problem is. As a matter of style, I would probably pass the address of the data via the PAR register using COGNEW like:

    COGNEW(@initialization,@scaling)

    then do:

    rdbyte buffer,PAR

    or

    wrbyte buffer,PAR
  • KyeKye Posts: 2,200
    edited 2008-12-29 22:10
    Okay, this is the code that's not working

    PUB setScaling
     
    scaling := !scaling
    
    

    PUB mouseEngine
     
    '' Initializes the mouse driver.
     
      scalingAddress      := @scaling
     
      cognew(@initalization, $00000000)
    

                            rdbyte  packetState,     scalingAddress      ' Update mouse scaling.
                            and     packetState,     #$FF wz             '
    if_z                    mov     packetState,     #$E6                '
    if_nz                   mov     packetState,     #$E7                '
                            call    #transmitPacket                      '
    

    scalingAddress          long    0                         ' Address of scaling setting.  
    

    Its for a mouse driver, actually. I have everything else working perfectly fine except for the ability to change the mouses current scaling during run time.

    I'm using a few wrbyte commands using the same techinique, and·they are all working like they should. Its just the rdbyte command that's not working. I think is an addressing problem.

    Would it help to know the the scaling byte is the fourth bytes in a series of bytes I made in the main memory?

    Also the packet state long starts off uninitalized and usualy contains random data that is transmited or recieved from the mouse.

    The idea of this program is that when scaling is equal to $FF the feature turns on and when its equal to $00 the feature turns off.

    This section of code is run in a loop.

    Anyway, thanks for your help.


    ·

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,

    Post Edited (Kye) : 12/29/2008 10:16:46 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-12-29 22:28
    Kye said...
    The idea of this program is that when scaling is equal to $FF the feature turns on and when its equal to $00 the feature turns off.
    Your code checks for zero or non-zero, not zero or $FF. To perform the check you want, do this:

            test    packetstate,packetstate wz
            cmp     packetstate,#$FF wc        'Carry is cleared iff packetstate => $FF; set otherwise.
    if_z    mov     packetstate,#$E6
    if_nc   mov     packetstate,#$E7
    
    
    


    This assumes that the upper three bytes of packetstate are always zero.

    -Phil
  • KyeKye Posts: 2,200
    edited 2008-12-29 22:37
    Oh sorry, the idea was more like true or false. That being said the value could only take a true (non zero) or false form (0).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-12-30 01:22
    Kye,

    The code you've shown looks okay. I would almost bet that you've got some long definitions in your DAT section after some res definitions, which will cause a loss of sync between cog and hub addressing. Always put your res definitions last.

    Did I guess correctly?

    -Phil
  • KyeKye Posts: 2,200
    edited 2009-01-01 03:36
    Okay, this really makes no sense now. Its not a problem in my asm code. Its a problem in the spin code. For some reason I·cannot set a variable and I believe that is the problem.

    I tracked the problem all the way up to this part.

      var      byte  scaling   
     
      PUB setScaling(logic) 
     
         scaling := logic
     
      PUB getScaling
     
         return scaling
     
      PUB mouseEngine
     
      '' Initializes the mouse driver.
     
         scalingAddress      := @scaling
     
         cognew(@initalization, $00000000)
    

    '' In the top object
    

    mouse.mouseEngine
    

    mouse.setScaling(true)
    

    I have tried repeated to set the variable to any non zero value and it won't change. I even wrote a method in the object that launches my driver and the value does not change fom zero even after reapeatedly being acessed.
    To check all this I tried passing addresses of random bytes in the memory after looking at the complied map and the driver worked as expected.
    Whats not expected is that I cannot set the scaling address value to anything other than zero...
    I hope its not a problem with the spin compiler or interpreter...but I can't find any other bugs in this code.
    The driver interprets anything other than 0 as true and 0 as false so it should be very easy to see results but I cannot.
    The bug is somewhere is this piece of code. Everything works except the scaling part...
    VAR
      long  xAxis
      long  yAxis
      long  zAxis
       
      byte  leftButton
      byte  rightButton
      byte  middleButton
      byte  scaling
     
    PUB getLeftButtonState
    '' Gets the left mouse button state, returns an 8 bit logical true or false.
    return  leftButton
     
    PUB getRightButtonState
    '' Gets the right mouse button state, returns an 8 bit logical true or false. 
    return rightButton
     
    PUB getMiddleButtonState
    '' Gets the middle mouse button state, returns an 8 bit logical true or false. 
    return middleButton
     
    PUB getXAxis
    '' Gets the current mouse x axis position, returns a 32 bit 2's complement number.  
    return xAxis
     
    PUB getYAxis
    '' Gets the current mouse y axis position, returns a 32 bit 2's complement number.
    return yAxis
     
    PUB getZAxis
    '' Gets the current mouse z axis position, returns a 32 bit 2's complement number.
    return zAxis
     
    PUB setScaling(logic)
    scaling := logic
     
    PUB getScaling
    return scaling
     
    PUB mouseEngine
     
    '' Initializes the mouse driver.
     
      xAxisAddress        := @xAxis
    
      yAxisAddress        := @yAxis
    
      zAxisAddress        := @zAxis
     
      leftButtonAddress   := @leftButton
    
      rightButtonAddress  := @rightButton
    
      middleButtonAddress := @middleButton
     
      scalingAddress      := @scaling
     
      cognew(@initalization, $00000000)
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Nyamekye,
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-01-01 05:08
    You've posted bits and pieces of your code. Now it's time to post (or attach) everything, so we can have a look at it.

    -Phil
Sign In or Register to comment.