DMA limits in Donkey Kong Country.

Share and discuss all facets of DKC ROM hacking...

DMA limits in Donkey Kong Country.

Postby Aaendi » March 8th, 2013, 5:04 am

I've asked this question on here several times, but I have never got a response.

Here are some facts I was a able to find on this website.
1) DKC animates sprites at 30fps
2) DKC has up to 14 animated objects, excluding bananas and HUD.
3) Objects cannot exceed 32 8x8 tiles, except for bosses.

Now here's the part I don't understand.

If you have 14 objects updated in 2 frames, and all objects take up the full 32 8x8 tiles, you'd be updating 7kB per frame, which is too much data for the DMA to handle in one frame. Did the level designers hide this limitation through carefully level placement of enemies and objects, or was there some other kind of workaround that was built into the game engine?
Trainee Trekker
Bananas received 2
Posts: 80
Joined: 2011

Re: DMA limits in Donkey Kong Country.

Postby Simion32 » March 8th, 2013, 5:52 am

I thought that DMA/HDMA wasn't directly involved in displaying hardware sprites, but is for actual memory transfers...? The SNES has sprite registers for a reason. :|
Sage of Discovery
Bananas received 332
Posts: 2738
Joined: 2008

Re: DMA limits in Donkey Kong Country.

Postby Aaendi » March 8th, 2013, 9:01 am

DKC has a dynamic animation engine, where VRAM is constantly being updated, while the characters are being animated.
Trainee Trekker
Bananas received 2
Posts: 80
Joined: 2011

Re: DMA limits in Donkey Kong Country.

Postby Mattrizzle » March 8th, 2013, 1:43 pm

:scratch: I don't know the exact answer to your question, but perhaps this info will help you get closer to answering it.

This subroutine is executed once per frame:
Code: Select all
$818CB0:
LDA #$1801
STA $4300
SEP #$10
LDY #$01
LDX #$00

$818CBC:
LDA $1715, x
BPL $818CE4   //If non-negative, skip writing to the VRAM registers
STA $4304
LDA $170F, x
STA $4305
LDA $1711, x
STA $2116
LDA $1713, x
STA $4302
STZ $1715, x
STY $420B
TXA
CLC
ADC #$0008
TAX
BRA $818CBC

$818CE4:
REP #$10
RTL

RAM Addresses:
$170F Length of graphic data block
$1711 VRAM destination
$1713 Low and middle bytes of graphic pointer
$1715 High (bank) byte of graphic pointer, followed by FF

The bytes in the table at $170F-$1746(?) are populated by a subroutine also responsible for selecting the hardware sprite values to be written to OAM. That subroutine is at SNES $BBA849.
Veteran Venturer
Bananas received 221
Posts: 545
Joined: 2008

Re: DMA limits in Donkey Kong Country.

Postby Aaendi » March 8th, 2013, 2:22 pm

Interesting. The actual DMA code just follows a list of updates that is generated through the non-vblank part of the game's code, and stops when encountering a bank that is in the $00-$7f range. All the trickery must be in the code that generates the list.

EDIT: Woops. The accumulator is in 16-bit mode, so that means the bit that signifies when to stop is bit 7 of $1716, not bit 7 of $1715.
Trainee Trekker
Bananas received 2
Posts: 80
Joined: 2011

Re: DMA limits in Donkey Kong Country.

Postby Mattrizzle » March 8th, 2013, 10:31 pm

Yes, that is why I mentioned that the bank byte is normally followed by FF when describing the contents of $1715. Guess I should have specified which processor bits are normally set/reset at those lines in the code.

There are some cases in which bank bytes of 7E or 7F are used, but not in the first DKC. DKC3 has a few area-specific compressed sprites which it decompresses to WRAM.
Veteran Venturer
Bananas received 221
Posts: 545
Joined: 2008

Re: DMA limits in Donkey Kong Country.

Postby Aaendi » March 9th, 2013, 6:06 am

In DKC2, there is a similar code at $B5A919, only with the table located at $1732.

Here is the code in DKC2 that generates the table at $1732.

Code: Select all
CODE_B59F40:        E2 20         SEP #$20                  ;
CODE_B59F42:        A5 70         LDA $70                   ;
CODE_B59F44:        4A            LSR A                     ;
CODE_B59F45:        4A            LSR A                     ;
CODE_B59F46:        4A            LSR A                     ;
CODE_B59F47:        4A            LSR A                     ;
CODE_B59F48:        29 1F         AND #$1F                  ;
CODE_B59F4A:        85 56         STA $56                   ;
CODE_B59F4C:        C2 20         REP #$20                  ;
CODE_B59F4E:        64 62         STZ $62                   ;
CODE_B59F50:        9C 38 06      STZ $0638                 ;
CODE_B59F53:        A5 70         LDA $70                   ;
CODE_B59F55:        C9 00 04      CMP #$0400                ;
CODE_B59F58:        D0 0F         BNE CODE_B59F69           ;
CODE_B59F5A:        E2 20         SEP #$20                  ;
CODE_B59F5C:        A9 07         LDA #$07                  ;
CODE_B59F5E:        8D 00 21      STA $2100                 ;
CODE_B59F61:        C2 20         REP #$20                  ;
CODE_B59F63:        F4 80 80      PEA $8080                 ;
CODE_B59F66:        AB            PLB                       ;
CODE_B59F67:        AB            PLB                       ;
CODE_B59F68:        6B            RTL                       ;

CODE_B59F69:        4B            PHK                       ;
CODE_B59F6A:        AB            PLB                       ;
CODE_B59F6B:        A4 62         LDY $62                   ;
CODE_B59F6D:        B9 FE 16      LDA $16FE,y               ;
CODE_B59F70:        A8            TAY                       ;
CODE_B59F71:        B9 00 00      LDA $0000,y               ;
CODE_B59F74:        D0 03         BNE CODE_B59F79           ;
CODE_B59F76:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B59F79:        AD 30 17      LDA $1730                 ;
CODE_B59F7C:        C5 78         CMP $78                   ;
CODE_B59F7E:        B0 04         BCS CODE_B59F84           ;
CODE_B59F80:        B6 1A         LDX $1A,y                 ;
CODE_B59F82:        80 09         BRA CODE_B59F8D           ;

CODE_B59F84:        B6 1A         LDX $1A,y                 ;
CODE_B59F86:        E0 C5 02      CPX #$02C5                ;
CODE_B59F89:        90 02         BCC CODE_B59F8D           ;
CODE_B59F8B:        B6 16         LDX $16,y                 ;
CODE_B59F8D:        8A            TXA                       ;
CODE_B59F8E:        99 18 00      STA $0018,y               ;
CODE_B59F91:        F0 E3         BEQ CODE_B59F76           ;
CODE_B59F93:        BF 00 80 BC   LDA $BC8000,x             ;
CODE_B59F97:        85 40         STA $40                   ;
CODE_B59F99:        1A            INC A                     ;
CODE_B59F9A:        85 44         STA $44                   ;
CODE_B59F9C:        BF 02 80 BC   LDA $BC8002,x             ;
CODE_B59FA0:        85 42         STA $42                   ;
CODE_B59FA2:        85 46         STA $46                   ;
CODE_B59FA4:        EB            XBA                       ;
CODE_B59FA5:        29 FF 00      AND #$00FF                ;
CODE_B59FA8:        18            CLC                       ;
CODE_B59FA9:        79 02 00      ADC $0002,y               ;
CODE_B59FAC:        99 14 00      STA $0014,y               ;
CODE_B59FAF:        B9 1C 00      LDA $001C,y               ;
CODE_B59FB2:        30 70         BMI CODE_B5A024           ;
CODE_B59FB4:        B9 0A 00      LDA $000A,y               ;
CODE_B59FB7:        38            SEC                       ;
CODE_B59FB8:        E9 80 00      SBC #$0080                ;
CODE_B59FBB:        38            SEC                       ;
CODE_B59FBC:        ED C0 17      SBC $17C0                 ;
CODE_B59FBF:        85 74         STA $74                   ;
CODE_B59FC1:        69 90 00      ADC #$0090                ;
CODE_B59FC4:        C9 30 01      CMP #$0130                ;
CODE_B59FC7:        B0 AD         BCS CODE_B59F76           ;
CODE_B59FC9:        B9 06 00      LDA $0006,y               ;
CODE_B59FCC:        ED BA 17      SBC $17BA                 ;
CODE_B59FCF:        85 72         STA $72                   ;
CODE_B59FD1:        18            CLC                       ;
CODE_B59FD2:        69 30 00      ADC #$0030                ;
CODE_B59FD5:        C9 60 01      CMP #$0160                ;
CODE_B59FD8:        90 62         BCC CODE_B5A03C           ;
CODE_B59FDA:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B59FDD:        B9 50 00      LDA $0050,y               ;
CODE_B59FE0:        30 05         BMI CODE_B59FE7           ;
CODE_B59FE2:        29 00 FF      AND #$FF00                ;
CODE_B59FE5:        80 03         BRA CODE_B59FEA           ;

CODE_B59FE7:        09 FF 00      ORA #$00FF                ;
CODE_B59FEA:        EB            XBA                       ;
CODE_B59FEB:        18            CLC                       ;
CODE_B59FEC:        79 0A 00      ADC $000A,y               ;
CODE_B59FEF:        38            SEC                       ;
CODE_B59FF0:        E9 80 00      SBC #$0080                ;
CODE_B59FF3:        38            SEC                       ;
CODE_B59FF4:        ED C0 17      SBC $17C0                 ;
CODE_B59FF7:        85 74         STA $74                   ;
CODE_B59FF9:        69 90 00      ADC #$0090                ;
CODE_B59FFC:        C9 30 01      CMP #$0130                ;
CODE_B59FFF:        B0 20         BCS CODE_B5A021           ;
CODE_B5A001:        B9 4F 00      LDA $004F,y               ;
CODE_B5A004:        30 05         BMI CODE_B5A00B           ;
CODE_B5A006:        29 00 FF      AND #$FF00                ;
CODE_B5A009:        80 03         BRA CODE_B5A00E           ;

CODE_B5A00B:        09 FF 00      ORA #$00FF                ;
CODE_B5A00E:        EB            XBA                       ;
CODE_B5A00F:        18            CLC                       ;
CODE_B5A010:        79 06 00      ADC $0006,y               ;
CODE_B5A013:        ED BA 17      SBC $17BA                 ;
CODE_B5A016:        85 72         STA $72                   ;
CODE_B5A018:        18            CLC                       ;
CODE_B5A019:        69 30 00      ADC #$0030                ;
CODE_B5A01C:        C9 60 01      CMP #$0160                ;
CODE_B5A01F:        90 1B         BCC CODE_B5A03C           ;
CODE_B5A021:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B5A024:        89 00 40      BIT #$4000                ;
CODE_B5A027:        D0 3F         BNE CODE_B5A068           ;
CODE_B5A029:        29 0F 00      AND #$000F                ;
CODE_B5A02C:        D0 AF         BNE CODE_B59FDD           ;
CODE_B5A02E:        B9 06 00      LDA $0006,y               ;
CODE_B5A031:        85 72         STA $72                   ;
CODE_B5A033:        B9 0A 00      LDA $000A,y               ;
CODE_B5A036:        38            SEC                       ;
CODE_B5A037:        E9 80 00      SBC #$0080                ;
CODE_B5A03A:        85 74         STA $74                   ;
CODE_B5A03C:        B9 12 00      LDA $0012,y               ;
CODE_B5A03F:        85 32         STA $32                   ;
CODE_B5A041:        85 34         STA $34                   ;
CODE_B5A043:        89 00 80      BIT #$8000                ;
CODE_B5A046:        D0 65         BNE CODE_B5A0AD           ;
CODE_B5A048:        89 00 40      BIT #$4000                ;
CODE_B5A04B:        D0 40         BNE CODE_B5A08D           ;
CODE_B5A04D:        A5 72         LDA $72                   ;
CODE_B5A04F:        38            SEC                       ;
CODE_B5A050:        E9 80 00      SBC #$0080                ;
CODE_B5A053:        85 72         STA $72                   ;
CODE_B5A055:        A5 74         LDA $74                   ;
CODE_B5A057:        18            CLC                       ;
CODE_B5A058:        69 10 00      ADC #$0010                ;
CODE_B5A05B:        85 74         STA $74                   ;
CODE_B5A05D:        E0 C4 02      CPX #$02C4                ;
CODE_B5A060:        B0 26         BCS CODE_B5A088           ;
CODE_B5A062:        20 14 A2      JSR CODE_B5A214           ;
CODE_B5A065:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B5A068:        89 00 20      BIT #$2000                ;
CODE_B5A06B:        F0 12         BEQ CODE_B5A07F           ;
CODE_B5A06D:        98            TYA                       ;
CODE_B5A06E:        AC 38 06      LDY $0638                 ;
CODE_B5A071:        C0 10 00      CPY #$0010                ;
CODE_B5A074:        B0 08         BCS CODE_B5A07E           ;
CODE_B5A076:        99 3A 06      STA $063A,y               ;
CODE_B5A079:        C8            INY                       ;
CODE_B5A07A:        C8            INY                       ;
CODE_B5A07B:        8C 38 06      STY $0638                 ;
CODE_B5A07E:        A8            TAY                       ;
CODE_B5A07F:        B9 16 00      LDA $0016,y               ;
CODE_B5A082:        99 18 00      STA $0018,y               ;
CODE_B5A085:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B5A088:        20 2F A2      JSR CODE_B5A22F           ;
CODE_B5A08B:        80 57         BRA CODE_B5A0E4           ;

CODE_B5A08D:        A5 72         LDA $72                   ;
CODE_B5A08F:        38            SEC                       ;
CODE_B5A090:        E9 8F 00      SBC #$008F                ;
CODE_B5A093:        85 72         STA $72                   ;
CODE_B5A095:        A5 74         LDA $74                   ;
CODE_B5A097:        18            CLC                       ;
CODE_B5A098:        69 10 00      ADC #$0010                ;
CODE_B5A09B:        85 74         STA $74                   ;
CODE_B5A09D:        E0 C4 02      CPX #$02C4                ;
CODE_B5A0A0:        B0 06         BCS CODE_B5A0A8           ;
CODE_B5A0A2:        20 B3 A3      JSR CODE_B5A3B3           ;
CODE_B5A0A5:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B5A0A8:        20 CE A3      JSR CODE_B5A3CE           ;
CODE_B5A0AB:        80 37         BRA CODE_B5A0E4           ;

CODE_B5A0AD:        89 00 40      BIT #$4000                ;
CODE_B5A0B0:        D0 1A         BNE CODE_B5A0CC           ;
CODE_B5A0B2:        A5 72         LDA $72                   ;
CODE_B5A0B4:        38            SEC                       ;
CODE_B5A0B5:        E9 80 00      SBC #$0080                ;
CODE_B5A0B8:        85 72         STA $72                   ;
CODE_B5A0BA:        E6 74         INC $74                   ;
CODE_B5A0BC:        E0 C4 02      CPX #$02C4                ;
CODE_B5A0BF:        B0 06         BCS CODE_B5A0C7           ;
CODE_B5A0C1:        20 67 A5      JSR CODE_B5A567           ;
CODE_B5A0C4:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B5A0C7:        20 82 A5      JSR CODE_B5A582           ;
CODE_B5A0CA:        80 18         BRA CODE_B5A0E4           ;

CODE_B5A0CC:        A5 72         LDA $72                   ;
CODE_B5A0CE:        38            SEC                       ;
CODE_B5A0CF:        E9 8F 00      SBC #$008F                ;
CODE_B5A0D2:        85 72         STA $72                   ;
CODE_B5A0D4:        E6 74         INC $74                   ;
CODE_B5A0D6:        E0 C4 02      CPX #$02C4                ;
CODE_B5A0D9:        B0 06         BCS CODE_B5A0E1           ;
CODE_B5A0DB:        20 18 A7      JSR CODE_B5A718           ;
CODE_B5A0DE:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B5A0E1:        20 33 A7      JSR CODE_B5A733           ;
CODE_B5A0E4:        AD 30 17      LDA $1730                 ;
CODE_B5A0E7:        C5 78         CMP $78                   ;
CODE_B5A0E9:        B0 0C         BCS CODE_B5A0F7           ;
CODE_B5A0EB:        A6 62         LDX $62                   ;
CODE_B5A0ED:        BD FE 16      LDA $16FE,x               ;
CODE_B5A0F0:        AA            TAX                       ;
CODE_B5A0F1:        B5 1A         LDA $1A,x                 ;
CODE_B5A0F3:        D5 16         CMP $16,x                 ;
CODE_B5A0F5:        D0 03         BNE CODE_B5A0FA           ;
CODE_B5A0F7:        4C 7C A1      JMP CODE_B5A17C           ;

CODE_B5A0FA:        95 16         STA $16,x                 ;
CODE_B5A0FC:        AE 30 17      LDX $1730                 ;
CODE_B5A0FF:        98            TYA                       ;
CODE_B5A100:        18            CLC                       ;
CODE_B5A101:        65 40         ADC $40                   ;
CODE_B5A103:        A8            TAY                       ;
CODE_B5A104:        9D 36 17      STA $1736,x               ;
CODE_B5A107:        A5 3B         LDA $3B                   ;
CODE_B5A109:        29 FF 00      AND #$00FF                ;
CODE_B5A10C:        0A            ASL A                     ;
CODE_B5A10D:        0A            ASL A                     ;
CODE_B5A10E:        0A            ASL A                     ;
CODE_B5A10F:        0A            ASL A                     ;
CODE_B5A110:        0A            ASL A                     ;
CODE_B5A111:        9D 32 17      STA $1732,x               ;
CODE_B5A114:        85 54         STA $54                   ;
CODE_B5A116:        98            TYA                       ;
CODE_B5A117:        18            CLC                       ;
CODE_B5A118:        65 54         ADC $54                   ;
CODE_B5A11A:        A8            TAY                       ;
CODE_B5A11B:        A5 32         LDA $32                   ;
CODE_B5A11D:        29 FF 01      AND #$01FF                ;
CODE_B5A120:        0A            ASL A                     ;
CODE_B5A121:        0A            ASL A                     ;
CODE_B5A122:        0A            ASL A                     ;
CODE_B5A123:        0A            ASL A                     ;
CODE_B5A124:        9D 34 17      STA $1734,x               ;
CODE_B5A127:        A5 42         LDA $42                   ;
CODE_B5A129:        09 00 FF      ORA #$FF00                ;
CODE_B5A12C:        9D 38 17      STA $1738,x               ;
CODE_B5A12F:        8A            TXA                       ;
CODE_B5A130:        18            CLC                       ;
CODE_B5A131:        69 08 00      ADC #$0008                ;
CODE_B5A134:        AA            TAX                       ;
CODE_B5A135:        9E 38 17      STZ $1738,x               ;
CODE_B5A138:        A5 3D         LDA $3D                   ;
CODE_B5A13A:        29 0F 00      AND #$000F                ;
CODE_B5A13D:        C9 00 00      CMP #$0000                ;
CODE_B5A140:        F0 34         BEQ CODE_B5A176           ;
CODE_B5A142:        0A            ASL A                     ;
CODE_B5A143:        0A            ASL A                     ;
CODE_B5A144:        0A            ASL A                     ;
CODE_B5A145:        0A            ASL A                     ;
CODE_B5A146:        0A            ASL A                     ;
CODE_B5A147:        9D 32 17      STA $1732,x               ;
CODE_B5A14A:        A5 3C         LDA $3C                   ;
CODE_B5A14C:        29 FF 00      AND #$00FF                ;
CODE_B5A14F:        0A            ASL A                     ;
CODE_B5A150:        0A            ASL A                     ;
CODE_B5A151:        0A            ASL A                     ;
CODE_B5A152:        0A            ASL A                     ;
CODE_B5A153:        85 54         STA $54                   ;
CODE_B5A155:        A5 32         LDA $32                   ;
CODE_B5A157:        29 FF 01      AND #$01FF                ;
CODE_B5A15A:        0A            ASL A                     ;
CODE_B5A15B:        0A            ASL A                     ;
CODE_B5A15C:        0A            ASL A                     ;
CODE_B5A15D:        0A            ASL A                     ;
CODE_B5A15E:        18            CLC                       ;
CODE_B5A15F:        65 54         ADC $54                   ;
CODE_B5A161:        9D 34 17      STA $1734,x               ;
CODE_B5A164:        98            TYA                       ;
CODE_B5A165:        9D 36 17      STA $1736,x               ;
CODE_B5A168:        A5 42         LDA $42                   ;
CODE_B5A16A:        09 00 FF      ORA #$FF00                ;
CODE_B5A16D:        9D 38 17      STA $1738,x               ;
CODE_B5A170:        8A            TXA                       ;
CODE_B5A171:        18            CLC                       ;
CODE_B5A172:        69 08 00      ADC #$0008                ;
CODE_B5A175:        AA            TAX                       ;
CODE_B5A176:        8E 30 17      STX $1730                 ;
CODE_B5A179:        9E 38 17      STZ $1738,x               ;
CODE_B5A17C:        E6 62         INC $62                   ;
CODE_B5A17E:        E6 62         INC $62                   ;
CODE_B5A180:        A5 62         LDA $62                   ;
CODE_B5A182:        C9 32 00      CMP #$0032                ;
CODE_B5A185:        F0 03         BEQ CODE_B5A18A           ;
CODE_B5A187:        4C 53 9F      JMP CODE_B59F53           ;

CODE_B5A18A:        F4 80 80      PEA $8080                 ;
CODE_B5A18D:        AB            PLB                       ;
CODE_B5A18E:        AB            PLB                       ;
CODE_B5A18F:        6B            RTL                       ;
Trainee Trekker
Bananas received 2
Posts: 80
Joined: 2011

Re: DMA limits in Donkey Kong Country.

Postby Mattrizzle » March 9th, 2013, 9:46 am

DKC3's equivalent to $818CB0 in DKC and $B5A919 in DKC2 is at $B3D843, with the RAM table located at $1562.

The code that generates the table at $1562 in DKC3 begins at $B78857.
Veteran Venturer
Bananas received 221
Posts: 545
Joined: 2008

Re: DMA limits in Donkey Kong Country.

Postby Aaendi » March 9th, 2013, 12:50 pm

Code: Select all
CODE_B5A0FC:        AE 30 17      LDX $1730                 ; $1730 is dma transfer table pointer
CODE_B5A0FF:        98            TYA                       ;
CODE_B5A100:        18            CLC                       ;
CODE_B5A101:        65 40         ADC $40                   ;
CODE_B5A103:        A8            TAY                       ; index Y is graphics source address
CODE_B5A104:        9D 36 17      STA $1736,x               ; set dma address
CODE_B5A107:        A5 3B         LDA $3B                   ; tiles to upload in "group 1"
CODE_B5A109:        29 FF 00      AND #$00FF                ; up to 255 tiles
CODE_B5A10C:        0A            ASL A                     ;
CODE_B5A10D:        0A            ASL A                     ;
CODE_B5A10E:        0A            ASL A                     ;
CODE_B5A10F:        0A            ASL A                     ;
CODE_B5A110:        0A            ASL A                     ;
CODE_B5A111:        9D 32 17      STA $1732,x               ; set dma legnth
CODE_B5A114:        85 54         STA $54                   ;
CODE_B5A116:        98            TYA                       ;
CODE_B5A117:        18            CLC                       ;
CODE_B5A118:        65 54         ADC $54                   ;
CODE_B5A11A:        A8            TAY                       ; add dma legnth to graphics source address
CODE_B5A11B:        A5 32         LDA $32                   ; attribute word is at $32
CODE_B5A11D:        29 FF 01      AND #$01FF                ;
CODE_B5A120:        0A            ASL A                     ;
CODE_B5A121:        0A            ASL A                     ;
CODE_B5A122:        0A            ASL A                     ;
CODE_B5A123:        0A            ASL A                     ;
CODE_B5A124:        9D 34 17      STA $1734,x               ; set dma vram destination
CODE_B5A127:        A5 42         LDA $42                   ; $42 is bank
CODE_B5A129:        09 00 FF      ORA #$FF00                ;
CODE_B5A12C:        9D 38 17      STA $1738,x               ; set dma bank
CODE_B5A12F:        8A            TXA                       ;
CODE_B5A130:        18            CLC                       ;
CODE_B5A131:        69 08 00      ADC #$0008                ;
CODE_B5A134:        AA            TAX                       ;
CODE_B5A135:        9E 38 17      STZ $1738,x               ;
CODE_B5A138:        A5 3D         LDA $3D                   ; tiles to upload in "group 2"
CODE_B5A13A:        29 0F 00      AND #$000F                ; cant upload more than 15 tiles at once
CODE_B5A13D:        C9 00 00      CMP #$0000                ;
CODE_B5A140:        F0 34         BEQ CODE_B5A176         ; dont dma if no tiles to upload
CODE_B5A142:        0A            ASL A                     ;
CODE_B5A143:        0A            ASL A                     ;
CODE_B5A144:        0A            ASL A                     ;
CODE_B5A145:        0A            ASL A                     ;
CODE_B5A146:        0A            ASL A                     ;
CODE_B5A147:        9D 32 17      STA $1732,x               ; set dma legnth
CODE_B5A14A:        A5 3C         LDA $3C                   ; $3c is location of "group 2" relative to "group 1"
CODE_B5A14C:        29 FF 00      AND #$00FF                ;
CODE_B5A14F:        0A            ASL A                     ;
CODE_B5A150:        0A            ASL A                     ;
CODE_B5A151:        0A            ASL A                     ;
CODE_B5A152:        0A            ASL A                     ;
CODE_B5A153:        85 54         STA $54                   ;
CODE_B5A155:        A5 32         LDA $32                   ; attribute word is at $32
CODE_B5A157:        29 FF 01      AND #$01FF                ;
CODE_B5A15A:        0A            ASL A                     ;
CODE_B5A15B:        0A            ASL A                     ;
CODE_B5A15C:        0A            ASL A                     ;
CODE_B5A15D:        0A            ASL A                     ;
CODE_B5A15E:        18            CLC                       ;
CODE_B5A15F:        65 54         ADC $54                   ;
CODE_B5A161:        9D 34 17      STA $1734,x               ; set dma vram destination
CODE_B5A164:        98            TYA                       ;
CODE_B5A165:        9D 36 17      STA $1736,x               ; set dma address
CODE_B5A168:        A5 42         LDA $42                   ; $42 is bank
CODE_B5A16A:        09 00 FF      ORA #$FF00                ;
CODE_B5A16D:        9D 38 17      STA $1738,x               ; set dma bank
CODE_B5A170:        8A            TXA                       ;
CODE_B5A171:        18            CLC                       ;
CODE_B5A172:        69 08 00      ADC #$0008                ;
CODE_B5A175:        AA            TAX                       ;
CODE_B5A176:        8E 30 17      STX $1730                 ; $1730 is dma transfer table pointer
CODE_B5A179:        9E 38 17      STZ $1738,x               ; store zero for next DMA transfer's bank
CODE_B5A17C:        E6 62         INC $62                   ;
CODE_B5A17E:        E6 62         INC $62                   ;
CODE_B5A180:        A5 62         LDA $62                   ; increment $62 by 2
CODE_B5A182:        C9 32 00      CMP #$0032                ;
CODE_B5A185:        F0 03         BEQ CODE_B5A18A           ; terminate routine if $62 = #$0032
CODE_B5A187:        4C 53 9F      JMP CODE_B59F53           ;

CODE_B5A18A:        F4 80 80      PEA $8080                 ;
CODE_B5A18D:        AB            PLB                       ;
CODE_B5A18E:        AB            PLB                       ;
CODE_B5A18F:        6B            RTL                       ;


I figured out how the second part of this routine works. Apparently it updates "animation slots" in two different groups of tiles, so I labeled them as "group 1" and "group 2." I don't know what $62 is, but I'm guessing it is an object slot pointer.
Trainee Trekker
Bananas received 2
Posts: 80
Joined: 2011

Re: DMA limits in Donkey Kong Country.

Postby Mattrizzle » March 9th, 2013, 4:26 pm

Aaendi wrote:I don't know what $62 is, but I'm guessing it is an object slot pointer.

That is correct. $62 is loaded into the Y register and used as an index into the table at $16FE, as seen in one snippet of the code you disassembled:
Code: Select all
CODE_B59F6B:        A4 62         LDY $62                   ;
CODE_B59F6D:        B9 FE 16      LDA $16FE,y               ;
This table contains, as you'd expect, the pointers to all of the object structures in RAM. Each object structure is 94 (#$5E hex) bytes in length, and there are a maximum of 25, which explains why the routine breaks out of the loop when $62 contains the value #$0032 (25d = #$19h, * 2 bytes per pointer = #$32h; slot #$00 is also considered an object)

Here are some of the offsets in the object structure that are read in the routine:
Code: Select all
Offset Description
------ -----------
0x00:  Object type (16 bits, values are multiples of 4; #$0000=No object)
0x02:  Object rendering order (16 bits, but only uses lower 8; unsigned; higher values layer the object's sprite over the sprites of objects that have lower values for this address)
0x06:  X-coordinate
0x0A:  Y-coordinate
0x12:  Hardware sprite (OAM) attributes
     Bits 0-8  (#$01FF): Starting tile value in VRAM (also dictates VRAM destination)
     Bits 9-11 (#$0E00): Palette
     Bits 12-13(#$3000): Background Layer Priority
     Bit  14   (#$4000): Horizontal Flip
     Bit  15   (#$8000): Vertical Flip
0x16:  Sprite index, last frame (16 bits, values are multiples of 4 and are indexes into the sprite pointer table at $BC8000 in the ROM)
0x18:  Sprite index, ? (see note for 0x16)
0x1A:  Sprite index, current frame (see note for 0x16)

In normal levels, Diddy's object structure always begins at $0DE2; Dixie's begins at $0E40.

(Information here applies specifically to DKC2. While DKC3's object structures are somewhat similar, DKC's are not as neatly organized.)
Veteran Venturer
Bananas received 221
Posts: 545
Joined: 2008


Re: DMA limits in Donkey Kong Country.

Postby Mattrizzle » March 11th, 2013, 4:13 am

You're close. The table at $BC8000-$BCB59F simply contains 24-bit pointers to all of the sprites. The topics you linked describe the actual format of this sprite data.
Veteran Venturer
Bananas received 221
Posts: 545
Joined: 2008


Return to ROM Hacking

Who is online

Users browsing this forum: No registered users and 3 guests