[4.5.9] More Compact / Efficient Attribute Table Loads

CutterCross

Active member
I was looking into implementing a compression system for my attribute and collision tables, but I realized that the default attribute table loading routine was pretty inefficient for what it was being used for. So here's a more efficient doLoadAttributeData script I cooked up, along with its corresponding macro. The original routine used a row and column system, this one just streams each byte from the attribute table one by one.

Code:
;;;; CC Attribute Table Load ;;;;

doLoadAttributeData:

;;; attributes have 8 columns per screen and 7 1/2 rows per screen.
;;;

    ;;; currently, arg0_hold has the bank data
    ;;; arg1_hold has the screen index, if it is needed.
    ;;; arg2_hold has screen bits.
        ;;; bit 0 = overworld (0) underworld (1)
        ;;; bit 1 = metaTable (0) 8x8 table (1)
        ;arg0 = screen bank
    ;arg3_hold = number of 32x32 regions to load
    ;arg4_hold = start position hi
    ;arg5_hold = start position lo
    ;arg6_hold = start column 
  

  
    LDA arg4_hold
    STA $2006
    LDA arg5_hold
    STA $2006
  
    SwitchBank arg0_hold
        LDY arg6_hold ;;; in what column should the column begin?
      
        loop_LoadFullAttTable:
            LDA (temp16),y
            STA $2007
          
        ;; doneDrawingThisAttributeTile:
            INY
            DEC arg3_hold
            BNE loop_LoadFullAttTable
          
            noMoreAttributeTilesToLoad:
        ReturnBank
    RTS


And this is the new macro. Not much different, but it gets rid of the now unused arguments:

Code:
MACRO LoadAttributeData arg0, arg1, arg2, arg3, arg4, arg5, arg6
    ;arg0 = screen bank
    ;arg1 = screen index
    ;arg2 = load screen bits
        ;;; bit 0 = overworld (0) underworld (1)
        ;;; bit 1 = metaTable (0) 8x8 table (1)
    ;arg3 = number of 32x32 regions to load
    ;arg4 = start position hi
    ;arg5 = start position lo
    ;arg6 = start column
  
    LDA arg0
    STA arg0_hold
    LDA arg1
    STA arg1_hold
    LDA arg2
    STA arg2_hold
    LDA arg3
    STA arg3_hold
    LDA arg4
    STA arg4_hold
    LDA arg5
    STA arg5_hold
    LDA arg6
    STA arg6_hold
  
  
    SwitchBank #$16
  
        LDY arg1
        LDA arg2
        AND #%00000001
        BEQ loadAttFromMap1table
            ;;;load from map 2 table
            LDA AttributeTables_Map2_Lo,y
            STA temp16
            LDA AttributeTables_Map2_Hi,y
            STA temp16+1
                LDA arg0_hold
                CLC
                ADC #$08
                STA arg0_hold
            JMP GotAttLoadPointer
        loadAttFromMap1table:
            LDA AttributeTables_Map1_Lo,y
            STA temp16
            LDA AttributeTables_Map1_Hi,y
            STA temp16+1
        GotAttLoadPointer:
            ;;now (temp16) holds the address of the nametable to be loaded.
    ReturnBank
  
  
    JSR doLoadAttributeData
  

    ENDM


Now full disclaimer: I don't know if the original macro is used in places other than doLoadScreen.asm and doLoadScreen2.asm in the other default modules, especially the scrolling ones. So be cautious when implementing this. Otherwise, if you just have this macro used in screen loads, give this a shot. Just be sure to go back and modify the original instances of this macro to fit the new arguments.
 
Last edited:

dale_coop

Moderator
Staff member
Very interesting CutterCross
I will do a few tests as soon as I can (find free time for that).
Thank you for sharing that, it’s awesome !!
 

CutterCross

Active member
Very interesting CutterCross
I will do a few tests as soon as I can (find free time for that).
Thank you for sharing that, it’s awesome !!
I usually don't share most of the code behind what I work on because most of it's really only designed for Prying Eye and nothing else. They're designed for that game's needs, and it'd be too much work [or just flat-out impractical] to try to have it applicable for general NESmaker use. But something like this I feel could be useful to some people as-is, so I'm sharing it.

I'm likely going to modify this further for Prying Eye for its specific attribute table compression, but that wouldn't be useful by itself for general use to share. I don't think most people would like the idea of having to manually rewrite your attribute tables outside the tool every time you want to change something.
 
Top Bottom