| Writing a pseudo-NCP with ASM | |
|---|---|
| Topic Started: Feb 16 2011, 09:25 PM (1,054 Views) | |
|
|
Feb 16 2011, 09:25 PM Post #1 |
|
Programmer!
![]()
|
All ASM code starts with 00 B5, but its specifically pointed to at the B5. Make sure you do not mess this up, or the assembler will not read this ASM code as THUMB.
This is a simple routine of 2 NCPs(specifically UnderShirt and FstBarrier) clouded together. This is the same thing as an NCP routine, except there are some reorders and 2 new THUMB opcodes, bx and ldr. Notice the pattern on how I smashed them together. ldr=load register bx=branch and exchange If you pop all of this into a disassembler(specifically VBA's disassembler), you'll get something like what I'm telling you right now. The b500(00 B5, actually) denotes the ASM code(THUMB specifically). The next 2 lines control the NCP family and so. The mov r2,0x01 just moves 1h into r2(which is needed). Now the ldr r3, [$0880001c] (=$0801379f). This opcode loads 0801379f into r3(location=0880001c). We are doing this because the $0801379f is too far away from 08800000. Next, mov lr, pc. Basically move r15 into r14. Just so it knows its a subroutine, right? bx r3. This is the important one. In the offset that was moved into r3, it branches into there, does all that stuff, and then comes back. Very important to have this. 0801379f is an offset that is shared by all NCPs specifically. The last few things are clean up things. Now if you want to add more things, add a 00 at the end of the NCP routine you are at, recopy it, and paste it again with changes you want. Credits to Prof. 9 in the end for introducing me to the bx statement and how to clone an ASM routine. |
|
|
|
| IngusRogeth | Mar 2 2011, 06:01 PM Post #2 |
|
TREZian
|
I think my brain just fried into a crisp. loljk |
Siggy by me:3![]() OoT Run is done! 1:39:45 Non-TAS console Currently planning and practicing for Zelda MM | |
|
|
|
|
|
Mar 2 2011, 06:06 PM Post #3 |
|
Programmer!
![]()
|
I don't think I explained that well for most people... Vote for a rewrite? |
|
|
|
| IngusRogeth | Mar 2 2011, 06:09 PM Post #4 |
|
TREZian
|
lol cuz off me. No you explained it greatly i was only jk. I get it now lol |
Siggy by me:3![]() OoT Run is done! 1:39:45 Non-TAS console Currently planning and practicing for Zelda MM | |
|
|
|
| Zanerus | Aug 28 2011, 12:40 AM Post #5 |
![]()
Dedicated Member
|
Old thread is old but Argo you got the 20 00 mixed up the second time around. |
|
Zane's poetry Hour here: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8752185/1/ AEZ Patch version 4 finally out: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8667690/1/ Chip hacker starters can find my notes here: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8685052/1/ PM me for any questions. modding Guide Index can be found here: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8750547/1/ Insanity is simply silliness misunderstood. | |
|
|
|
| Prof. 9 | Aug 28 2011, 04:55 AM Post #6 |
![]()
Moderaptor
![]()
|
I guess I should explain what the r0, r1 and r2 values do for the "0801379F" subroutine. I am not 100% sure what r0 does, but I believe it denotes who or what is affected by the NCP effect. In any case, using 0 for r0 will make it work like most NCPs. r1 is the effect family: it's a relative pointer that decides where the subroutine stores the r2 value. r2 is the effect sublevel: it's a value that decides the magnitude or properties of the NCP effect. For example, for HP Bug, the higher this value the more HP you lose. "0801379F" is the standard "apply NCP effect" routine. There is a similar one with the same input of r0 and r1, but it will LOAD the NCP sublevel instead, for checking purposes. EDIT: Agro got some other things wrong, but it's still quite useful if you're trying to learn ASM. Edited by Prof. 9, Aug 28 2011, 04:58 AM.
|
Follow me on Twitter! Fork me on GitHub!
| |
|
|
|
|
|
Aug 28 2011, 07:59 AM Post #7 |
|
Programmer!
![]()
|
Sorry about any mistakes, because I was writing it from memory, i didn't c+p the whole ASM snippet. |
|
|
|
| Prof. 9 | Aug 28 2011, 08:32 AM Post #8 |
![]()
Moderaptor
![]()
|
Another correction, just for the record: you say ASM routines are pointed to at the B5, but that's wrong; they are really pointed to the 00 before it. When you add 1 to an even number, that will only flip a single bit. That bit is not actually part of an ASM pointer. Because in ARM and THUMB all opcodes are either 2 or 4 bytes long, they're always located at even offsets (ending in 0, 2, 4, 6, 8, A, C or E for THUMB, or 0, 4, 8, C for ARM). By adding 1 to an ASM pointer, you flip the lowest bit. That bit is not part of the pointer, so it doesn't change the address pointed to. When a "bx rN" opcode is execute, the CPU will jump to that address and continue executing. However, the lowest bit determines in what mode it continues; if it's 0 (address is even) it continues in ARM mode, if it's 1 (address is odd) it continues in THUMB mode. I think I was gonna write some more but I had to do something and I have no idea what I was going to write anymore. |
Follow me on Twitter! Fork me on GitHub!
| |
|
|
|
| Zanerus | Aug 28 2011, 08:44 AM Post #9 |
![]()
Dedicated Member
|
That's some pretty interesting stuff there. Also besides the second 20 00 being wrong I tested it and works just fine. Gonna be using this pretty often here shortly. |
|
Zane's poetry Hour here: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8752185/1/ AEZ Patch version 4 finally out: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8667690/1/ Chip hacker starters can find my notes here: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8685052/1/ PM me for any questions. modding Guide Index can be found here: http://s6.zetaboards.com/The_Rockman_EXE_Zone/topic/8750547/1/ Insanity is simply silliness misunderstood. | |
|
|
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| « Previous Topic · Guides & Research · Next Topic » |





