Quantcast
Channel: nesdev.org
Viewing all articles
Browse latest Browse all 785

HDMA's 127 scanline limit workaround code

$
0
0
Since the fact that the SNES's HDMA is limited to runs of 127 scanlines which is much smaller than the screen and requires a lot of register juggling in order to compensate for this, I decided to make some general use routines to get around this problem. I'll add comments later on tonight, when I feel like doing it.

Code:

fix_HDMA_length_overload_byte:ldy #$0000tyx-;lda {HDMA_buffer_1},ybit #$00ffbeq ++bit #$0080beq +secsbc #$007fsta {HDMA_buffer_2},xand #$ff00ora #$007finx #2+;sta {HDMA_buffer_2},xinx #2iny #2bra -+;sta {HDMA_buffer_2},xrtsfix_HDMA_length_overload_word:ldy #$0000tyx-;sep #$20lda {HDMA_buffer_1},ybpl +secsbc #$7fsta {HDMA_buffer_2},xlda #$7fsta {HDMA_buffer_2}+3,xrep #$21lda {HDMA_buffer_1}+1,ysta {HDMA_buffer_2}+1,xsta {HDMA_buffer_2}+4,xiny #3txaadc #$0006taxbra -+;sta {HDMA_buffer_2},xbeq +rep #$20lda {HDMA_buffer_1}+1,ysta {HDMA_buffer_2}+1,xiny #3inx #3bra -+;rep #$20rtsfix_HDMA_length_overload_long:ldy #$0000tyx-;sep #$20lda {HDMA_buffer_1},ybpl +secsbc #$7fsta {HDMA_buffer_2},xlda #$7fsta {HDMA_buffer_2}+5,xrep #$21lda {HDMA_buffer_1}+1,ysta {HDMA_buffer_2}+1,xsta {HDMA_buffer_2}+6,xlda {HDMA_buffer_1}+3,ysta {HDMA_buffer_2}+3,xsta {HDMA_buffer_2}+8,xtyaadc #$0005taytxaadc #$000ataxbra -+;sta {HDMA_buffer_2},xbeq +rep #$21lda {HDMA_buffer_1}+1,ysta {HDMA_buffer_2}+1,xlda {HDMA_buffer_1}+3,ysta {HDMA_buffer_2}+3,xtyaadc #$0005taytxaadc #$0005taxbra -+;rep #$20rts

I made another version of this that makes use of block move instructions:

Code:

fix_HDMA_length_overload_byte:ldx #$0000sep #$20-;lda {HDMA_buffer},xbeq ++bmi +inx #2bra -+;rep #$20stx {temp}lda {HDMA_buffer_size}taxsecsbc {temp}txyiny #2sty {HDMA_buffer_size}mvp {dest_bank}={source_bank}//some assemblers have these reversedsep #$21ldx {temp}lda {HDMA_buffer},xsbc #$7fsta {HDMA_buffer},xlda #$7fsta {HDMA_buffer}+2,x+;rep #$20rtsfix_HDMA_length_overload_word:ldx #$0000sep #$20-;lda {HDMA_buffer},xbeq ++bmi +inx #3bra -+;rep #$20stx {temp}lda {HDMA_buffer_size}taxsecsbc {temp}txyiny #3sty {HDMA_buffer_size}mvp {dest_bank}={source_bank}//some assemblers have these reversedsep #$21ldx {temp}lda {HDMA_buffer},xsbc #$7fsta {HDMA_buffer},xlda #$7fsta {HDMA_buffer}+3,x+;rep #$20rtsfix_HDMA_length_overload_long:ldx #$0000sep #$20-;lda {HDMA_buffer},xbeq ++bmi +inx #5bra -+;rep #$20stx {temp}lda {HDMA_buffer_size}taxsecsbc {temp}txyiny #5sty {HDMA_buffer_size}mvp {dest_bank}={source_bank}//some assemblers have these reversedsep #$21ldx {temp}lda {HDMA_buffer},xsbc #$7fsta {HDMA_buffer},xlda #$7fsta {HDMA_buffer}+5,x+;rep #$20rts
I haven't tested either of these sets of routines, so if I made a mistake, you can point it out.

Statistics: Posted by psycopathicteen — Fri Nov 29, 2024 3:30 pm — Replies 0 — Views 77



Viewing all articles
Browse latest Browse all 785

Trending Articles