Language…
7 users online: Daizo Dee Von, ezdeez85, GRIMMKIN,  Ringo,  Segment1Zone2,  Telinc1, toady - Guests: 236 - Bots: 313
Users: 64,795 (2,375 active)
Latest user: mathew

Shared Subroutines v2.3

SMW Patches → Shared Subroutines v2.3

Submission Details

Name: Shared Subroutines v2.3
Author: imamelia
Added:
Version History: View
Tool: Asar
Requires Free Space: Yes
Bug Fix: No
Featured: Yes
Description: This patch inserts some commonly-used subroutines into your ROM so that you can just call them with a JSL instead of copy-pasting them, which saves a significant amount of ROM space.

Note that some subroutines cannot be converted to SA-1 since either the registers become inaccessible or that they rely on unsigned math operations.
Tags: lorom subroutine
Comments: 14 (jump to comments)
Download 23.33 KiB | 331 downloads

Comments (14)

HammerBrother Link
This patch is very useful in situations when dealing tools like GPS, uberasm tool, and PIXI that you cannot call another subroutine that is located in a separate file, from a subroutine file. Therefore you can avoid having duplicate subroutines in your ROM by multiple different tools.

I experienced that subroutine isolation problem when developing the graphical bar tutorial for programming sprites.

This also enables global access to all ASM codes regardless to its type of tool. A custom subroutine useable by pixi and uberasm tool, for example.
HammerBrother Link
Updates include:
-Print command to make Asar window now display the list memory usage and range. This is useful to tell if it overwrites other data.
-Several routines JSLs to a list, then back into the code, changed to just simply jump directly to the routine since it is unnecessary; because they are in the same ASM file, so labels are found within it.
AuraDee Link
Tested with:
Asar v1.71, Free Space Logger (checking for addresses), Snes9x v1.55
HammerBrother From older version: Shared Subroutines v2.2 Link
Actually, JSL read3(!DefineRoutine) to directly jump to a freespace code is a bad idea. Because the JSL now jumps directly to freespace instead a fixed location, anytime you make the subroutine code move, there is tendency that the destination address JSL jumps to could end up jumping to wrong address (which can crash the game) if the user didn't update the codes that uses the shared subroutine patch (sprites, outside patches, blocks, etc containing a JSL to a moving freespace block).

This happens on the second and later routine if any code/data's bytes before it changes.

Unless if you manually add subroutines in fixed locations in the ROM, and don't edit those codes at all.
HammerBrother From older version: Shared Subroutines v2.2 Link
Quote
4.- A big improvement to this patch would be to just include the pointer to the routine (autoclean dl) instead of a JML. That way one could do JSL read3(!GetRand2) and he'd be directly taken to the routine. It's just a small byte and cycle save, yeah, but it's better than nothing.


you mean like this?:

Code
autoclean dl Routine0
autoclean dl Routine1
autoclean dl Routine2
...


Code
;in a seperate ASM file to use shared subroutine
LDA #$00
STA $19
JSL read3(!Routine1)


I don't think it's possible, since the address the JML jumps to cannot be transferred into a define, as asar would error out. Can you show me a working example? JML [$xxxxxx] does not exist.
 Erik From older version: Shared Subroutines v2.2 Link
After trying to save my semester and other IRL stuff, I'm finally done moderating this. Has many minor issues, I honestly debated between removing this or not, but most of these are just small issues or nitpicks. Overall I don't see any purpose in this patch anymore, in the age of shared routines within GPS and PIXI/GIEPY, and the UberASM library. I don't think this has many use-cases left, but that's just my opinion.

I found some problems with the RATS tag. There are two issues in it:
1.- The if condition you made to check for banks outside the original game area is broken, because if you set your definition to a FastROM bank it'd still add the tag in the unexpanded area. Add an &$7F to the check to disregard for the high bit if the ROM isn't SA-1 (SA-1 uses banks $80+ for other things, as you'll see below).
2.- As you comment in it, it is size-1, however you aren't actually subtracting 1 from the RATS tag. Use:
Code
  dw JMLListEnd-JMLListStart-1
  dw JMLListEnd-JMLListStart-1^$FFFF

to correct this issue.
I fixed these for you, but be more careful next time.

Some other things:
1.- Removed the SA-1 tag. Most of these aren't SA-1 compatible. Be it because of the registers, or because you decided to throw !F into most ROM mentions. This breaks in SA-1 ROMs. SA-1 uses the portion after $80 for other stuff, unlike a normal LoROM where it's just a mirror of the lower area. I didn't fix these.
2.- Additionally, making reads from tables FastROM doesn't make them faster.
3.- Not really an issue, but why do you define JMLListRatsTagSize twice? You only use it in SubroutineDefs.asm anyway. There's no need to repeat such define.
4.- A big improvement to this patch would be to just include the pointer to the routine (autoclean dl) instead of a JML. That way one could do JSL read3(!GetRand2) and he'd be directly taken to the routine. It's just a small byte and cycle save, yeah, but it's better than nothing.
5.- This patch has stuff all over the place! It's so annoying to configure. You can call it tidiness, but really it just makes finding stuff harder. Just stick to one defines file if it's really necessary, and put it within the main folder.
HammerBrother From older version: Shared Subroutines v2.2 Link
WAIT - don’t use this patch yet, I’ll update it later today. It has a fatel bug currently.

Edit: Patch updated.
HammerBrother From older version: Shared Subroutines v2.2 Link
2.1 update: After learning from my enemy HP meter patch removal, it is necessary to have this protection since location-fixed codes aren't automatically have the rats tag inserted.
zacmario From older version: Shared Subroutines v2.2 Link
Not sure how that applies to this patch.. But truthfully some one might better off porting them from the smb1 disassembly. Icemans's have alot of differences.
CalHal From older version: Shared Subroutines v2.2 Link
Can you read this forum, uses the patch, and fix and update the platform sprites.

Can you use the SMB1 scale platforms to make act more better than the other games? Don’t forget to fix it and add SA-1. The platforms needs that patch.
HammerBrother From older version: Shared Subroutines v2.2 Link
Thanks for fixing, I have forgotten to switch that to asar.
CalHal From older version: Shared Subroutines v2.2 Link
I know xkas patches are not SA-1.
 RPG Hacker From older version: Shared Subroutines v2.2 Link
It's no xkas patch, it was just labeled incorrectly. Fixed it.
CalHal From older version: Shared Subroutines v2.2 Link
We don’t expect xkas patches. But I don’t mind.