Code: Select all
fix_HDMA_length_overload_byte:
ldy #$0000
tyx
-;
lda {HDMA_buffer_1},y
bit #$00ff
beq ++
bit #$0080
beq +
sec
sbc #$007f
sta {HDMA_buffer_2},x
and #$ff00
ora #$007f
inx #2
+;
sta {HDMA_buffer_2},x
inx #2
iny #2
bra -
+;
sta {HDMA_buffer_2},x
rts
fix_HDMA_length_overload_word:
ldy #$0000
tyx
-;
sep #$20
lda {HDMA_buffer_1},y
bpl +
sec
sbc #$7f
sta {HDMA_buffer_2},x
lda #$7f
sta {HDMA_buffer_2}+3,x
rep #$21
lda {HDMA_buffer_1}+1,y
sta {HDMA_buffer_2}+1,x
sta {HDMA_buffer_2}+4,x
iny #3
txa
adc #$0006
tax
bra -
+;
sta {HDMA_buffer_2},x
beq +
rep #$20
lda {HDMA_buffer_1}+1,y
sta {HDMA_buffer_2}+1,x
iny #3
inx #3
bra -
+;
rep #$20
rts
fix_HDMA_length_overload_long:
ldy #$0000
tyx
-;
sep #$20
lda {HDMA_buffer_1},y
bpl +
sec
sbc #$7f
sta {HDMA_buffer_2},x
lda #$7f
sta {HDMA_buffer_2}+5,x
rep #$21
lda {HDMA_buffer_1}+1,y
sta {HDMA_buffer_2}+1,x
sta {HDMA_buffer_2}+6,x
lda {HDMA_buffer_1}+3,y
sta {HDMA_buffer_2}+3,x
sta {HDMA_buffer_2}+8,x
tya
adc #$0005
tay
txa
adc #$000a
tax
bra -
+;
sta {HDMA_buffer_2},x
beq +
rep #$21
lda {HDMA_buffer_1}+1,y
sta {HDMA_buffer_2}+1,x
lda {HDMA_buffer_1}+3,y
sta {HDMA_buffer_2}+3,x
tya
adc #$0005
tay
txa
adc #$0005
tax
bra -
+;
rep #$20
rts
I made another version of this that makes use of block move instructions:
Code: Select all
fix_HDMA_length_overload_byte:
ldx #$0000
sep #$20
-;
lda {HDMA_buffer},x
beq ++
bmi +
inx #2
bra -
+;
rep #$20
stx {temp}
lda {HDMA_buffer_size}
tax
sec
sbc {temp}
txy
iny #2
sty {HDMA_buffer_size}
mvp {dest_bank}={source_bank} //some assemblers have these reversed
sep #$21
ldx {temp}
lda {HDMA_buffer},x
sbc #$7f
sta {HDMA_buffer},x
lda #$7f
sta {HDMA_buffer}+2,x
+;
rep #$20
rts
fix_HDMA_length_overload_word:
ldx #$0000
sep #$20
-;
lda {HDMA_buffer},x
beq ++
bmi +
inx #3
bra -
+;
rep #$20
stx {temp}
lda {HDMA_buffer_size}
tax
sec
sbc {temp}
txy
iny #3
sty {HDMA_buffer_size}
mvp {dest_bank}={source_bank} //some assemblers have these reversed
sep #$21
ldx {temp}
lda {HDMA_buffer},x
sbc #$7f
sta {HDMA_buffer},x
lda #$7f
sta {HDMA_buffer}+3,x
+;
rep #$20
rts
fix_HDMA_length_overload_long:
ldx #$0000
sep #$20
-;
lda {HDMA_buffer},x
beq ++
bmi +
inx #5
bra -
+;
rep #$20
stx {temp}
lda {HDMA_buffer_size}
tax
sec
sbc {temp}
txy
iny #5
sty {HDMA_buffer_size}
mvp {dest_bank}={source_bank} //some assemblers have these reversed
sep #$21
ldx {temp}
lda {HDMA_buffer},x
sbc #$7f
sta {HDMA_buffer},x
lda #$7f
sta {HDMA_buffer}+5,x
+;
rep #$20
rts