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.
And this is the new macro. Not much different, but it gets rid of the now unused arguments:
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.
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: