nesdev.com
http://forums.nesdev.com/

PPU COPY TO SRAM
http://forums.nesdev.com/viewtopic.php?f=2&t=16073
Page 1 of 1

Author:  FlameCyclone [ Mon Jun 12, 2017 3:18 am ]
Post subject:  PPU COPY TO SRAM

Code:
;[FC][复制PPU到SRAM]
;FlameCyclone 2017.6.11


 .ORG $A100

COPY_FROM_L = $40
COPY_FROM_H = $41
COPY_TO_L = $42
COPY_TO_H = $43


COPY_DATA:
 LDX #$00
 LDY #$00
 LDA #$00
 STA $2001
 JSR TIMEDELAY
COPY_TO_SET:   ;目的开始地址设置
 LDA COPY_TO_ADDR
 STA COPY_TO_H
 LDA COPY_TO_ADDR+1
 STA COPY_TO_L

COPY_FROM_SET:   ;数据源开始地址设置
 LDA COPY_FROM_ADDR+1
 STA COPY_FROM_L
 LDA COPY_FROM_ADDR
 STA COPY_FROM_H
 JSR COPY_FROM_PPU
 
COPY_START:   ;复制开始
 LDA COPY_TO_L
 CMP COPY_OVER_ADDR+1
 BNE COPY_DATA_START
 LDA COPY_TO_H
 CMP COPY_OVER_ADDR
 BEQ COPY_OVER
COPY_DATA_START:   ;开始复制数据
 JSR PPU_DATA_READ
 STA (COPY_TO_L),Y
 JSR COPY_TO_ADD
 JSR COPY_FROM_ADD
 JSR COPY_FROM_PPU
 JMP COPY_START

COPY_OVER:    ;结束数据复制
 JSR PPU_DATA_READ
 STA (COPY_TO_L),Y
 JSR TIMEDELAY
 RTS
 
PPU_DATA_READ:    ;PPU数据读取
 LDA $2007
 LDA $2007
 RTS
 
COPY_FROM_ADD:    ;原地址递增
 INC COPY_FROM_L
 BNE COPY_FROM_ADD_RTS
 INC COPY_FROM_H
COPY_FROM_ADD_RTS:
 RTS
 
COPY_TO_ADD:    ;目的地址递增
 INC COPY_TO_L
 BNE COPY_TO_ADD_RTS
 INC COPY_TO_H
COPY_TO_ADD_RTS:
 RTS
 
COPY_FROM_PPU:    ;设置数据源PPU地址
 LDA COPY_FROM_H
 STA $2006
 LDA COPY_FROM_L
 STA $2006
 RTS


COPY_FROM_ADDR:    ;数据源开始地址
 .DB $30,$00
COPY_TO_ADDR:    ;目的开始地址
 .DB $70,$00
COPY_OVER_ADDR:    ;目的结束地址
 .DB $7E,$FF

TIMEDELAY:
 LDA $2002
 BPL TIMEDELAY
 RTS

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/