Views: 827,361,911Time: 2020-05-28 02:41:34 AM 22 users online: , cleversoncprado, containercore, Doug Walker, FYRE150, giu, HackSMW, , Ixitxachitl, JamesD28, jeyson88, Lumy, Magmatic, MarioriaM, , , Nicoke42, , SF - The Dark Warrior, Slash Chen, Sleppy, Sping bot - Guests: 78 - Bots: 162 Users: 44,254 (2,537 active)Latest: Mista_Jub
 Tip: You can use the File Bin to upload screenshots, videos, etc. of your hack. Not logged in.
Advanced Documentation and ASM Code Library
Forum Index - SMW Hacking - SMW Hacking Help - ASM & Related Topics - Advanced Documentation and ASM Code Library
 Pages: 1 2 3 4 5 6 7 8
Someone may find this useful, a routine I made to multiply two numbers. The main benefit of this is that you can multiply two 8-bit numbers, a 16-bit number and a 8-bit number, or two 16-bit numbers.

Code
```; Multiplication routine - works with 8-bit and 16-bit numbers.
; It won't however give a 24-bit number (it could probably be edited to do so).
;
; Input:
; A should be 00(00) when entering (unless you want to add the multiplied number to what is already in A)
; \$00 should be the  number you want to multiply and \$02 is what you are multiplying it by. \$00 * \$02
; You can enter in either 8-bit or 16-bit mode A
;
; Ouput:
; Result will go in A
; \$00 and \$02 will no longer hold their original values
;

Multiply:
-
LSR \$02
BEQ .end
BCC +
CLC
+
ASL \$00
BRA -

.end
CLC
RTS```
Here is a square root approximation routine:

In order to use it, load a 16-bit value into A, with the carry bit acting as a 17th bit and call it. It will return the approximation to the square root as a 16-bit value in A, with the carry bit acting as a 17th bit. The return value should be interpreted as 9.8 fixed point.

For example, a return value of \$45A0 (C) should be interpreted as \$0145.A0.
Using an inlined reciprocal square root routine, I've created a pretty accurate aiming routine. Link

In order to use it, set \$00 to be the 16-bit value (shooter_x - target_x), set \$02 to be the 16-bit value (shooter_y - target_y), and set A to be the 8-bit projectile speed. It will return the projectile's X speed in \$00 and the projectile's Y speed in \$02. Note that distances over \$0100 pixels are not allowed.

Explanation: Suppose one fired the projectile with X speed dx, and Y speed dy. Then its speed would be sqrt(dx2+dy2). Thus, we can adjust its speed by multiplying by speed / sqrt(dx2+dy2). This routine calculates the reciprocal 1 / sqrt(dx2+dy2), multiplies by speed, then multiplies by either dx or dy.

erik edit: fixed link because dropbox
added the sa-1 compatible variant (requires a !SA1 detection if you're using spritetool)
Did you miss the other DMA routines by imamelia, The ones that write to and from VRAM and CGRAM?
Just a small macro for ASM palette changes :
Code
```%palette(!destination, #\$XX, #\$XX)

macro palette(destination, lowbyte, highbyte)
LDA <Destination>
STA \$2121

LDA <lowbyte>		; Yes, you need a high byte too
STA \$2122

LDA <highbyte>
STA \$2122		; Remember: \$2122 is a ‘write twice’ register (you must store again into the address).
endmacro```

But it can slow down a bit if you're using it to much (I didn't used it).

--------------------
Okay, my layout looks ugly.
but you should mention that you can't use that code in sprites or the palette will screw up... (must be done in V-blank)
Originally posted by mzuenni
but you should mention that you can't use that code in sprites or the palette will screw up... (must be done in V-blank)

Air Meter? Ultimate Noob Boss?

--------------------
Okay, my layout looks ugly.
Simply put, that code must run in NMI, or you could use something like HDMA to modify the palettes.
If you use an acurate emulator not ZSNES than the palette will screw up when you change the palette with that code in a sprite...
thats the reasen why all SMW sprites which modify the palette use the table at \$0682
Oh right, ZSNES is inaccurat. And not only with the palette, every adress in the SNES regrister must have a mirror to not screw up the other things (with esception of [like MarioEdit has written] [H]DMA).

--------------------
Okay, my layout looks ugly.
Originally posted by wiiqwertyuiop
Direct writes to registers should with no problems.

The following code in levelasm/uberasm
Code
```level105:
REP #\$20
LDA #\$2000
.x
DEC A ; waste some time so we're not in vblank
BNE .x
SEP #\$20
LDA \$14
LSR #3
AND #\$07
ASL
TAX
LDA #\$24
STA \$2121
LDA \$00B61C,x
STA \$2122
LDA \$00B61D,x
STA \$2122
RTS```

(clean ROM, not even LM) intends to create the following results (bsnes092c+ZMZ)

but on real hardware, it creates the following instead (bsnes092a+ZMZ)

Therefore, it is safe to concluce that writing to CGRAM outside of a blank will glitch up. It will go to a semi-randomly chosen color and ignore what you aim for.

--------------------
<blm> zsnes users are the flatearthers of emulation
Here's some code for parallax scrolling that scrolls vertically:

Code
```parallax:
LDA #\$7F
STA \$4334

REP #\$20
LDA #\$0F02
STA \$4330
LDA #\$8600
STA \$4332
STZ \$00

TAX
TAY
.loop	LDA scanlines,y
CLC
STA \$00
SBC \$20
BMI .next

CMP scanlines,y
BCC +
LDA scanlines,y
+	SEP #\$20
STA \$7F8600,x

LDA \$1E
STA \$211B
LDA \$1F
STA \$211B
LDA speeds,y
STA \$211C

REP #\$20
LDA \$2134
LSR #4
STA \$7F8601,x
INX #3
.next	INY #2
CPY.b #speeds-scanlines+2
BNE .loop
SEP #\$20

LDA #\$08
TSB \$0D9F
RTS

scanlines:
dw \$0030,\$0030,\$0030,\$0030,\$0030,\$0030,\$0030,\$0030
dw \$0030
speeds:
dw \$0010,\$0018,\$0020,\$0028,\$0030,\$0038,\$0040,\$0048
dw \$0050```

scanlines should add up to greater than \$01B0 in a horizontal level.
speeds is divided by \$10 to get the true scrolling value; the speed ranges from \$0000 to \$007F.

Note: The parallax appears to flicker for a single frame when scrolling up sometimes -- I have no idea why.
^
Is the HDMA patch necessary for this?

--------------------
What-A-Blast! - My WIP Super Mario World hack
**Layout by Erik557

No, you can just plop it in uberASM's level_code.asm. However, it seems like the HDMA is always a frame behind -- not exactly sure why. =\
Maybe that HDMA can't handle running at full frames while the code is in effect? It probably could if the code was small, right?

--------------------
What-A-Blast! - My WIP Super Mario World hack
**Layout by Erik557

The SNES isn't that weak that that'd give it problems.

--------------------
Originally posted by MarioE
...scanlines needs to add up to \$01B0.

It scrolled fine when it was less/more than...
But it did just happen to me that the more scanlines and scrolls, the emulator slows down immediately.

Is that why it needs to add to \$01B0?

edit: nvm I'm probably wrong about the emulator thing.

--------------------
What-A-Blast! - My WIP Super Mario World hack
**Layout by Erik557

 Pages: 1 2 3 4 5 6 7 8
Forum Index - SMW Hacking - SMW Hacking Help - ASM & Related Topics - Advanced Documentation and ASM Code Library

The purpose of this site is not to distribute copyrighted material, but to honor one of our favourite games.