"Lead DMA?" 】
Yes, the protagonist DMA. Do you remember how we used $2003 and $2004 registers to write to Spr-ram (OAM)? In fact, this practice is unreliable in real systems. We should use memory as the OAM, then write values to a register, and everything is automatically copied to the real OAM. If you don't understand it, we'll understand it once and for all.
"What memory?" 】
As I said above, we need to use "variable" memory to replicate an OAM. This tutorial uses $0300 to replicate the OAM. Note that there are only 64 characters in the NES (Occupy 64*4b=256b,0x100). So basically you define your own variables as much as possible within the $0000-$0200. The layout from $0300-$0400 should be fully consistent with the OAM.
Also remember that the $ A is a memory address, not like a memory variable. Instead of continuing to read and write the same address, we must add one to the address after each read and write.
We use even numbers in the hundred for our OAM copy. I'll tell you why.
Well, I hope you understand the above theory, see the assembly code below.
;; ---code to begin---;;. Inesmap 0 ;. INESPRG 1 ;. INESCHR 1 ;. Inesmir 1 ;. Bank 1.org $FFFA. DW 0.dw start.dw 0.bank 0 ; code snippet. org $0000; Define the. org $0300 here; The OAM image starts here sprite1_y: . db 0 ; 1th ordinate sprite1_t: . db 0 ; 1th lead tile number sprite1_s: . db 0 ; Special treatment for number 1th sprite1_x: . db 0 ; 1th axis sprite2_y: . db 0 ; 2nd lead ordinate sprite2_t: . db 0 ; Needless to say, huh? sprite2_s: . db 0 ; Sprite2_x: . db 0; and so on go ... org $8000; code starts start:;; first sell a xiaoguanzi; The detailed code infin:jmp Infin in the back ; ---end of code---;;
If you don't understand, email me to tell me where you really don't understand.
"DMA Register"
The DMA register address is $4014, we need to write 3 in. Why is it 3? Because we have a memory OAM at the $. When you write n to $4014, copy the content from $0n00 to the true OAM. That is, if starting from $0400, then write 4, if starting from $0500, then write 5, understand?
Here's how to carry our OAM into the real OAM:
LDA #$3 ; it can also be written as a #3 because it is obvious that 3 of the decimal and hexadecimal representations are the same STA $4014; once written, the copy begins
That's it, it's much more reliable than our old way, and it's easier!
"How do I modify the Nineth day code as described above?" 】
We need to do a few things.
First, copy. org $0300 and back that pile of stuff into our old variable area. We don't use those variables anymore because our protagonist, X, Y uses OAM copies.
Second, use the Find and replace function to change all x_pos and Y_pos to Sprite1_x and sprite1_y.
Again, find the code block that writes $2003, replaced by:
LDA #$3 ; STA $4014;
That's it! We also saved a few bytes of code space in this way.
"Review Today"
I hope you like the main character DMA, I've made it as colloquial as possible. Today we learned a better way to write OAM data, and tomorrow we will see a better way to capture Vblank. Next up is ..... Interrupt!
I hope your code doesn't have a bug.
Nesasm Tutorial--Tenth day--lead DMA