Shop OBEX P1 Docs P2 Docs Learn Events
Understanding SX48 INTPARAMFSR, RAM bank 0, etc — Parallax Forums

Understanding SX48 INTPARAMFSR, RAM bank 0, etc

ZootZoot Posts: 2,227
edited 2009-03-29 19:42 in General Discussion
Bean -- after hours of hair pulling last night and this morning, I discovered a bug/error in the latest beta release for the SX48. This is my first SX48 project, so I know there are few differences (bank in asm, loading m, read-write-modify on setb/clrb), but this is what burned me:

SX28 list:

··· 75· =000000F7······ __INTPARAMFSR··· EQU· $F7

SX48 list

·· 63· =00000010······ __INTPARAMFSR··· EQU· $10

So if you use INTPARAMFSR in anyway, and have a regular variable at $10 (as I did), the app will be wacky. In my case, while I usually use NOCODE or NOPRESERVE in my ISRs, I often alias INTPARAMFSR registers for my own "shadow" purposes (say, to save/restore M in the ISR for apps that may change tris states in both the ISR and the mainline).

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST

1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php


Post Edited (Zoot) : 3/29/2009 7:11:32 PM GMT

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-03-29 18:03
    Hi Zoot,

    It is NOT a bug. The sx48/52 stores __paramX variables in rambank0
    using semi_direct addressing, eg. clr fsr, mov __INTPARAMFSR,__PARAM1

    You'd better use conditional compilation so you can use the same
    routine name for storing/retrieving variables no matter what device.

    regards peter
  • ZootZoot Posts: 2,227
    edited 2009-03-29 18:53
    You're missing my point -- it's not the assignment location that matters, it's that a regularly declared variable in SXB was assigned the EXACT same location as the INTPARAMFSR location. The "normal" variable is only used in regular SX/B; my ISR had instructions like


    MOV FSR, #__INTPARAMFSR+0
    MOV W, IND
    MOV M, W


    Which came into direct conflict and wiped out the "regular" variable in the mainline.

    When I manually assign all my variables and DON'T use INTPARAMFSR in any way, I have no conflicts. This was borne out by both my list file AND by the application in action.

    Now if there is something else I am missing here, please enlighten me.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • ZootZoot Posts: 2,227
    edited 2009-03-29 19:00
    Here's the definitions that give me the described results. I can attach the full app if anyone wants, but I need to zip it up with my include files.

    In any case, in the following, in 2.00.18 for SX48, __INTPARAMFSR and idx are both assigned location $10:

    flags VAR Byte
    mMov  VAR flags.0
    mDir  VAR flags.1
    mDone VAR flags.2
    mUD   VAR flags.2
    bMode VAR flags.7
    idx   VAR Byte
    state VAR Byte
    tmpW1 VAR Word
    tmpW2 VAR Word
    tmpB1 VAR Byte
    tmpB2 VAR Byte
    tmpB3 VAR tmpW2_LSB
    tmpB4 VAR tmpW2_MSB
    motor VAR Byte(16) BANK
    mflags VAR motor(0)
    mpwm   VAR motor(1)
    mact  VAR motor(2)
    muser VAR motor(3)
    mtarg VAR motor(4)
    mramp VAR motor(5)
    mrate VAR motor(6)
    tracks VAR Byte motor(7)  ' relay on/offs
      northSouth VAR tracks.0
      eastSiding VAR tracks.1
      westSiding VAR tracks.2
      mountTrack VAR tracks.3
    mRampCntr VAR motor(12)
    maccm VAR motor(13)
    mcntr VAR motor(14)
    mTmp  VAR motor(15)
    servo VAR Byte(16) BANK
    svoPntr VAR servo(8)
    svoPin  VAR servo(9)
    svoFrame VAR servo(10)  ' ms 
    svoPulse VAR servo(11) ' 11/12
    svoPad   VAR servo(12)
    svoFlags VAR servo(13) ' pos reached flags
    svoRampFrame VAR servo(14) ' every x ticks, do pos update
    svo VAR Byte(16) BANK  ' user pos (targ)
      eastNorthSvo VAR svo(0) ' svo 0
      eastSouthSvo VAR svo(1) ' svo 1
    svoRamp VAR svo(8)     ' ramp
    svoAccum VAR Byte(8) BANK
    timeCounters VAR Byte(8) BANK
    msCntr VAR timeCounters(0)
    msClock VAR timeCounters(1)
    msTmr   VAR timeCounters(2)
    secCntr VAR Word @ timeCounters(3) '4
    secClock VAR timeCounters(5)
    secTmr   VAR timeCounters(6)
    ' 2 free
    miscDat   VAR Byte(16) BANK
      buttonDat VAR miscDat(0)
      buttons   VAR buttonDat(0)
         buttonLeft VAR buttons.0
         buttonCtr  VAR buttons.1
         buttonRight VAR buttons.3
         buttonBottom VAR buttons.2
      buttonsLast VAR buttonDat(1)
      buttonsCntr VAR buttonDat(2)
      buttonsTmp VAR buttonDat(3)
    turnoutDat VAR Byte(16) BANK
      turnouts VAR turnoutDat(0)
      eastNorth VAR turnouts.0 ' svo 0
      eastSouth VAR turnouts.1 ' svo 1
    
    var3 var byte(16) bank
    var4 var byte(16) bank
    var5 var byte(16) bank
    var6 var byte(16) bank
    var7 var byte(16) bank
    var8 var byte(16) bank
    var9 var byte(16) bank
    var10 var byte(8) bank
      mSave VAR var10(0)
    

    The list output for above yields:

        32                    ; DEFINE SYSTEM VARIABLES
        33  =00000000       __RAM            EQU  $00
        34  =00000006       RBC              EQU  $06
        35  =00000006       RBC_LSB          EQU  $06
        36  =00000007       RBC_MSB          EQU  $07
        37  =00000007       RCD              EQU  $07
        38  =00000007       RCD_LSB          EQU  $07
        39  =00000008       RCD_MSB          EQU  $08
        40  =00000008       RDE              EQU  $08
        41  =00000008       RDE_LSB          EQU  $08
        42  =00000009       RDE_MSB          EQU  $09
        43  =0000000A       __PARAM1         EQU  $0A
        44  =0000000B       __PARAM2         EQU  $0B
        45  =0000000C       __PARAM3         EQU  $0C
        46  =0000000D       __PARAM4         EQU  $0D
        47  =0000000E       __PARAM5         EQU  $0E
        48  =0000000E       __PARAMCNT       EQU  $0E
        49  =0000000A       __WPARAM12       EQU  $0A
        50  =0000000A       __WPARAM12_LSB   EQU  $0A
        51  =0000000B       __WPARAM12_MSB   EQU  $0B
        52  =0000000B       __WPARAM23       EQU  $0B
        53  =0000000B       __WPARAM23_LSB   EQU  $0B
        54  =0000000C       __WPARAM23_MSB   EQU  $0C
        55  =0000000C       __WPARAM34       EQU  $0C
        56  =0000000C       __WPARAM34_LSB   EQU  $0C
        57  =0000000D       __WPARAM34_MSB   EQU  $0D
        58  =0000000D       __WPARAM45       EQU  $0D
        59  =0000000D       __WPARAM45_LSB   EQU  $0D
        60  =0000000E       __WPARAM45_MSB   EQU  $0E
        61  =000000FF       TRIS_X           EQU  $FF
        62  =000000FF       __TRIS           EQU  $FF
        63  =00000010       __INTPARAMFSR    EQU  $10
        64  =0000000A       __REMAINDER      EQU  __PARAM1
        65  =0000000A       __WREMAINDER     EQU  __PARAM1
        66  =0000000A       __WREMAINDER_LSB EQU  __PARAM1
        67  =0000000B       __WREMAINDER_MSB EQU  __PARAM2 
    

    ·and

       184                                                   ;' -------------------------------------------------------------------------
       185                                                   ;' Variables
       186                                                   ;' -------------------------------------------------------------------------
       187                  
       188  =0000000F       flags            EQU  $0F        ;flags VAR Byte
       189                  
       190  =0000000F       mMov             EQU  flags.0    ;mMov  VAR flags.0
       191                  
       192  =0000000F.1     mDir             EQU  flags.1    ;mDir  VAR flags.1
       193                  
       194  =0000000F.2     mDone            EQU  flags.2    ;mDone VAR flags.2
       195                  
       196  =0000000F.2     mUD              EQU  flags.2    ;mUD   VAR flags.2
       197                  
       198  =0000000F.7     bMode            EQU  flags.7    ;bMode VAR flags.7
       199                  
       200                  
       201  =00000010       idx              EQU  $10        ;idx   VAR Byte
       202                  
       203  =00000011       state            EQU  $11        ;state VAR Byte
       204                  
       205                  
       206  =00000012       tmpW1            EQU  $12        ;tmpW1 VAR Word
       207  =00000012       tmpW1_LSB        EQU  tmpW1     
       208  =00000013       tmpW1_MSB        EQU  tmpW1+1   
       209                  
       210  =00000014       tmpW2            EQU  $14        ;tmpW2 VAR Word
       211  =00000014       tmpW2_LSB        EQU  tmpW2     
       212  =00000015       tmpW2_MSB        EQU  tmpW2+1   
       213                  
       214  =00000016       tmpB1            EQU  $16        ;tmpB1 VAR Byte
       215                  
       216  =00000017       tmpB2            EQU  $17        ;tmpB2 VAR Byte
       217                  
       218  =00000014       tmpB3            EQU  tmpW2_LSB  ;tmpB3 VAR tmpW2_LSB
       219                  
       220  =00000015       tmpB4            EQU  tmpW2_MSB  ;tmpB4 VAR tmpW2_MSB
       221                  
       222                  
       223  =00000020       motor            EQU  $20        ;motor VAR Byte(16) BANK
       224                  
       225  =00000020       mflags           EQU  motor+0    ;mflags VAR motor(0)
       226                  
       227  =00000021       mpwm             EQU  motor+1    ;mpwm   VAR motor(1)
       228                  
       229  =00000022       mact             EQU  motor+2    ;mact  VAR motor(2)
       230                  
       231  =00000023       muser            EQU  motor+3    ;muser VAR motor(3)
       232                  
       233  =00000024       mtarg            EQU  motor+4    ;mtarg VAR motor(4)
       234                  
       235  =00000025       mramp            EQU  motor+5    ;mramp VAR motor(5)
       236                  
       237  =00000026       mrate            EQU  motor+6    ;mrate VAR motor(6)
       238                  
       239                  
       240  =00000018       tracks           EQU  $18        ;tracks VAR Byte motor(7)  ' relay on/offs
       241                  
       242  =00000018       northSouth       EQU  tracks.0   ;  northSouth VAR tracks.0
       243                  
       244  =00000018.1     eastSiding       EQU  tracks.1   ;  eastSiding VAR tracks.1
       245                  
       246  =00000018.2     westSiding       EQU  tracks.2   ;  westSiding VAR tracks.2
       247                  
       248  =00000018.3     mountTrack       EQU  tracks.3   ;  mountTrack VAR tracks.3
       249                  
       250                  
       251  =0000002C       mRampCntr        EQU  motor+12   ;mRampCntr VAR motor(12)
       252                  
       253  =0000002D       maccm            EQU  motor+13   ;maccm VAR motor(13)
       254                  
       255  =0000002E       mcntr            EQU  motor+14   ;mcntr VAR motor(14)
       256                  
       257  =0000002F       mTmp             EQU  motor+15   ;mTmp  VAR motor(15)
       258                  
       259                  
       260  =00000030       servo            EQU  $30        ;servo VAR Byte(16) BANK
       261                  
       262  =00000038       svoPntr          EQU  servo+8    ;svoPntr VAR servo(8)
       263                  
       264  =00000039       svoPin           EQU  servo+9    ;svoPin  VAR servo(9)
       265                  
       266  =0000003A       svoFrame         EQU  servo+10   ;svoFrame VAR servo(10)  ' ms 
       267                  
       268  =0000003B       svoPulse         EQU  servo+11   ;svoPulse VAR servo(11) ' 11/12
       269                  
       270  =0000003C       svoPad           EQU  servo+12   ;svoPad   VAR servo(12)
       271                  
       272  =0000003D       svoFlags         EQU  servo+13   ;svoFlags VAR servo(13) ' pos reached flags
       273                  
       274  =0000003E       svoRampFrame     EQU  servo+14   ;svoRampFrame VAR servo(14) ' every x ticks, do pos update
       275                  
       276                  
       277  =00000040       svo              EQU  $40        ;svo VAR Byte(16) BANK  ' user pos (targ)
       278                  
       279  =00000040       eastNorthSvo     EQU  svo+0      ;  eastNorthSvo VAR svo(0) ' svo 0
       280                  
       281  =00000041       eastSouthSvo     EQU  svo+1      ;  eastSouthSvo VAR svo(1) ' svo 1
       282                  
       283                  
       284  =00000048       svoRamp          EQU  svo+8      ;svoRamp VAR svo(8)     ' ramp
       285                  
       286                  
       287  =00000050       svoAccum         EQU  $50        ;svoAccum VAR Byte(8) BANK
       288                  
       289                  
       290  =00000058       timeCounters     EQU  $58        ;timeCounters VAR Byte(8) BANK
       291                  
       292  =00000058       msCntr           EQU  timeCounters+0 ;msCntr VAR timeCounters(0)
       293                  
       294  =00000059       msClock          EQU  timeCounters+1 ;msClock VAR timeCounters(1)
       295                  
       296  =0000005A       msTmr            EQU  timeCounters+2 ;msTmr   VAR timeCounters(2)
       297                  
       298  =0000005B       secCntr          EQU  timeCounters+3 ;secCntr VAR Word @ timeCounters(3) '4
       299  =0000005B       secCntr_LSB      EQU  secCntr   
       300  =0000005C       secCntr_MSB      EQU  secCntr+1 
       301                  
       302  =0000005D       secClock         EQU  timeCounters+5 ;secClock VAR timeCounters(5)
       303                  
       304  =0000005E       secTmr           EQU  timeCounters+6 ;secTmr   VAR timeCounters(6)
       305                  
       306                                                   ;' 2 free
       307                  
       308  =00000060       miscDat          EQU  $60        ;miscDat   VAR Byte(16) BANK
       309                  
       310  =00000060       buttonDat        EQU  miscDat+0  ;  buttonDat VAR miscDat(0)
       311                  
       312  =00000060       buttons          EQU  buttonDat+0 ;  buttons   VAR buttonDat(0)
       313                  
       314                  
       315  =00000060       buttonLeft       EQU  buttons.0  ;     buttonLeft VAR buttons.0
       316                  
       317  =00000060.1     buttonCtr        EQU  buttons.1  ;     buttonCtr  VAR buttons.1
       318                  
       319  =00000060.3     buttonRight      EQU  buttons.3  ;     buttonRight VAR buttons.3
       320                  
       321  =00000060.2     buttonBottom     EQU  buttons.2  ;     buttonBottom VAR buttons.2
       322                  
       323                  
       324  =00000061       buttonsLast      EQU  buttonDat+1 ;  buttonsLast VAR buttonDat(1)
       325                  
       326  =00000062       buttonsCntr      EQU  buttonDat+2 ;  buttonsCntr VAR buttonDat(2)
       327                  
       328  =00000063       buttonsTmp       EQU  buttonDat+3 ;  buttonsTmp VAR buttonDat(3)
       329                  
       330                  
       331  =00000070       turnoutDat       EQU  $70        ;turnoutDat VAR Byte(16) BANK
       332                  
       333  =00000070       turnouts         EQU  turnoutDat+0 ;  turnouts VAR turnoutDat(0)
       334                  
       335  =00000070       eastNorth        EQU  turnouts.0 ;  eastNorth VAR turnouts.0 ' svo 0
       336                  
       337  =00000070.1     eastSouth        EQU  turnouts.1 ;  eastSouth VAR turnouts.1 ' svo 1
       338                  
       339                  
       340                  
       341  =00000080       var3             EQU  $80        ;var3 var byte(16) bank
       342                  
       343  =00000090       var4             EQU  $90        ;var4 var byte(16) bank
       344                  
       345                  
       346  =000000A0       var5             EQU  $A0        ;var5 var byte(16) bank
       347                  
       348  =000000B0       var6             EQU  $B0        ;var6 var byte(16) bank
       349                  
       350  =000000C0       var7             EQU  $C0        ;var7 var byte(16) bank
       351                  
       352  =000000D0       var8             EQU  $D0        ;var8 var byte(16) bank
       353                  
       354  =000000E0       var9             EQU  $E0        ;var9 var byte(16) bank
       355                  
       356  =000000F0       var10            EQU  $F0        ;var10 var byte(8) bank
       357                  
       358  =000000F0       mSave            EQU  var10+0    ;  mSave VAR var10(0)
       359
    




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-03-29 19:02
    Zoot,
    For the sx48/52, when fsr=0, rambank0 is enabled at $10-$1F,
    that's why INTPARAMFSR equ $10
    You then use direct addressing to access the ram
    (indirect via IND is pointless as fsr is 0)
    So for sx48/52 you would use
    CLR FSR
    MOV·W,__INTPARAMFSR+0
    MOV M, W

    That's the only way to access rambank0.

    regards peter
  • ZootZoot Posts: 2,227
    edited 2009-03-29 19:06
    OK, now I get it -- I checked INTPARAMFSR use with NOCODE turned off:

       476  0000  0064        CLR FSR ; Use BANK 0 for storage
       477  0001  020A        MOV __INTPARAMFSR,__PARAM1    
            0002  0030
       478  0003  020B        MOV __INTPARAMFSR+1,__PARAM2  
            0004  0031
       479  0005  020C        MOV __INTPARAMFSR+2,__PARAM3  
            0006  0032
       480  0007  020D        MOV __INTPARAMFSR+3,__PARAM4  
            0008  0033
       481  0009  020E        MOV __INTPARAMFSR+4,__PARAM5  
    

    You know what, I get it, but I must be fuzzy on memory mapping for the SX48... rambank0 really has 32 bytes?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-03-29 19:18
    No, rambank0 has 16 bytes ($10-$1F), the lower half
    $00-$0F are the global bytes that are always accesible

    regards peter
  • ZootZoot Posts: 2,227
    edited 2009-03-29 19:26
    OK, bear with me then .... sorry if this is basic stuff... I've looked over the memory map for the SX48 and the register access scheme, and I'd be lying if I said I'm clear here...

    Are you saying that:

    "bank 0" registers are really at $10-$1F and can *only* be accessed as follows:
    CLR FSR
    MOV fr, W· ; where fr is $10-$1F

    But that $00-$0F are always the globals, e.g., without having to change banks or set FSR:
    MOV fr, W ; where fr is $00-$0F
    (that doesn't sound right; wouldn't FSR.4 have to be·1 to get the "globals"?)

    And that $10-$Fx are "normal" in that you can either:
    BANK fr
    SETB/CLRB FSR.7
    MOV fr, W

    or

    MOV FSR, #fr
    MOV fr, #1

    or

    MOV FSR, #fr
    MOV IND, #1

    Shoot... 30+ SX28 projects and I'm hung up on this :-)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-03-29 19:42
    Zoot,
    You said...
    "bank 0" registers are really at $10-$1F and can *only* be accessed as follows:
    CLR FSR
    MOV fr, W· ; where fr is $10-$1F

    Yes, for sx48/52.
    For sx18/20/28, bank0 is $10-$1F
    You said...
    But that $00-$0F are always the globals, e.g., without having to change banks or set FSR:
    MOV fr, W ; where fr is $00-$0F
    (that doesn't sound right; wouldn't FSR.4 have to be·1 to get the "globals"?)

    Yes, and you don't need to set fsr.4 for the globals
    You must set fsr.4 to access any bank via $10-$1F on sx18/20/28
    And you can use indirect addressing for the globals except IND.
    mov fsr,#5
    clr ind· 'this actually does clr ra

    regards peter
Sign In or Register to comment.