Shop OBEX P1 Docs P2 Docs Learn Events
Easier way to access table of data in COG? — Parallax Forums

Easier way to access table of data in COG?

RaymanRayman Posts: 13,898
edited 2016-05-14 15:44 in Propeller 2
I just got something working, but thinking there has to be an easier way...

For this USB stuff, I want to send a series of bytes.
Maybe what I should do is put those bytes in a hub table and use that ptra thing
But, decided to store them as a series of longs in cog for now.

Anyway, first long is #of entries in table, following longs are table entries.
Here's the code I came up with. It works, but seems very awkward to do something so simple:
DAT 'init Mouse
InitMouse              
              'Send Setup
              mov       x2,#1  'SeO
              call      #TransmitByte
              waitx     ##50
              mov       x2,#0
              call      #TransmitByte
              waitx     ##5000

              sets      SendPacket,#Setup
              nop            
              call      #SendPacket

testz
              jmp       #testz
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Setup         long      3,$2D,$00,$10
GetDeviceD    long      11,$C3,$80,$06,$00,$01,$00,$00,$40,$00,$DD,$94
DAT 'SendPacket Sub
SendPacket
              mov       i2,0-0
              mov       tx_out,i2
              call      #OutputByteSub
              sets      SendByte,SendPacket
              add       SendByte,#1
              nop
              nop
SendByte
              mov       x2,0-0
              add       SendByte,#1
              mov       tx_out,x2
              call      #OutputByteSub
              djnz      i2,#SendByte
              RET

Self-modifying code hurts my brain...

Comments

  • RaymanRayman Posts: 13,898
    edited 2016-05-14 15:57
    BTW, the
    call      #OutputByteSub
    

    Sends the byte out over serial port, so I can see what's going on.

    It's wasn't easy for me to figure out whether to use #0-0 or just 0-0 or whether the SETS arguments should have a # in front of them or not.
    In then end, I just figured it out by trial and error...
  • potatoheadpotatohead Posts: 10,254
    edited 2016-05-14 19:03
    Look at altds. It has auto increment, etc... it negates the need for your add and if you use rep, you can lose your end of loop compare.

    Andy uses it in his all cog char driver. Fast, simple. I'm not on a machine where I have a code snippet.

    We should start a snippet pile. There is so much here. I know I'm not using it all very well yet. That is due to treating P2 like a P1. :D



  • potatoheadpotatohead Posts: 10,254
    edited 2016-05-14 19:14
    You want the octothorpe when the value you write to the instruction is the cog memory address. You skip it when the value is the address of the cog memory containing the value, which is the address, I think.... :D

  • RaymanRayman Posts: 13,898
    Thanks, I'm trying this out now.

    It appears to be called alti now.
  • Yes, I think that's right. Sometimes, it's hard when the instructions have changed, or overlap with the "hot" one.

  • Yep, ALTDS is gone now, and so has the auto increment and decrement too.
     What was ALTDS is now ALTI.
    
     There are three new instructions that share the opcode space with ALTI (no more C/Z writing options, as they were meaningless for these instructions):
    
     ALTR D,S/# - use the sum of D and S/# for the result register in the next instruction
     ALTD D,S/# - use the sum of D and S/# for the D register in the next instruction
     ALTS D,S/# - use the sum of D and S/# for the S register in the next instruction
    
     The idea is that D is an offset and S/# is a base:
    
     ALTx offset,#base
    
    
  • Wow, missed that change. When did that happen?
  • RaymanRayman Posts: 13,898
    I wonder if the docs here are right then:
    https://docs.google.com/document/d/1O27nO2tMjBTvUNblFFRtEp5DHvcvsSGXcPvH9FaJ9u8/pub#h.8eh0m9l68srf

    There is some explanation at the bottom, but it's still called ALTDS there.

    I tried using it, but couldn't make it work so did something else...
Sign In or Register to comment.