Language…
12 users online: Buflen, caioskii, Cristian Cardoso, fanfan21, Green Jerry, Hayashi Neru, Josuke Yoshikage, KoJi, Metakabe, Shomi, signature_steve, toady - Guests: 233 - Bots: 348
Users: 64,795 (2,377 active)
Latest user: mathew

Copy the frame counter and array code to another custom block?

Creating a teleport_block with random level_destinations?

Hey, I've been trying to rework the custom block: Teleport_To_Specified_Level from Teo17 for a while now.

Here is the custom block TTSL. ->https://www.smwcentral.net/?p=section&a=details&id=4025
(file name: TTSL.asm)

I am trying to add 4 level destinations with an array instead of just 1.
A random level target should then be chosen with a frame counter or a math.random.
Basicly a warp to a random level-destination chosen from a pool/array of four levels.
I found the custom block: Specific_screen_teleport_block_&_door_v1.2 from Alcaro, GreenHammerBro, Iχtab, MarioE and wye,
which use one of four screens exits at "random" by a frame-counter.

Here is the custom block SSTB. -> https://www.smwcentral.net/?p=section&a=details&id=19063
(file name: screentele_rand.asm)

I would like to take these two sections of code (array & frame-counter) to the teleport block,
so instead of a random screen-exit, I can get a random level-destination.
I think determining the array worked, but I still need to set a value to the array-position("x") in the array: "randomtable,x", by the frame-counter.
Then get the result from the array to the "teleport-function" to teleport to a "random" level.

I'm not sure what I need to consider when creating an array from a variable, or how to specify it correctly.
I'm not really familiar with asm, so I wanted to ask here for advice if someone could look over the code and help me out.
(Of course, only if copying all this is even possible and it is as simple as I imagine it to be right now.)


Here is my Edited version of Teo17 custom block: TTSL.asm:



Comments marked with "#///" inside the code are from me and show the changes I am trying to make/achive.
I am aware that this version of the code does not work and I probably cannot just copy code snippets from other ASM files.
But if only a few changes are needed to make this work, I would be very grateful!

First of all, I'd generally recommend writing code yourself and thinking about the logic while looking at other code as a reference instead of just copy pasting said code.

Currently, the if conditions in the code don't even match up, there's at least one endif missing somewhere.
The code in question that's missing the endif here
Quote
Code
if !EXLEVEL
	JSL $03BCDC|!bank
else
	LDA $5B
	AND #$01
	ASL 
	TAX 
	LDA $95,x
	TAX							;#/// Im not even sure if this is still part to determine a value via frame-counter
								;#/// Pls help, dunno what Im doing

is, as the comment suspects, not part of the code to determine the frame-counter anymore. The frame counter is stored at $13 and another one at $14 so this part of the code is already getting the frame counter. (The AND #$03 essentially does "modulo 4" here)
Quote
Code
	LDA $14			;\use frame #$00-#$03
	AND #$03		;/
	TAX			;\use for table


at this point the frame counter modulo 4 is already in X and everything after that is code to get the screen exit information of the selected screen.


now, the next part to load from an array (usually referred to as a table in this case) doesn't work because the or operation marked in orange here tries to get a constant at compile time, which isn't possible here.
Quote
Code
	REP #$20
	LDA randomtable,x|(((!Water<<3)|(1<<2)|(!Secondary<<1))<<8)	;#/// I changed "#!Level" to "randomtable,x" to use the array.
	%teleport()


You want to remove that as it's not necessary for the %teleport() routine to work in the first place.

Then there's a PHY but no PLY to go with it, that will crash when the code runs in the end. The PHY/PLY is used to preserve the acts like number, but only necessary if Y actually changes, if you get rid of the screen exit code then you won't need that and can just remove it.

With those changes in mind, the code itself would work in theory at least, last problem is just that a level number and the value the %teleport() routine expects are 16-bit, but you're only storing 8-bit of that in your table. You want to use dw (which puts a 16-bit value in rom) instead of db (which is an 8-bit value)
Keep in mind that each entry in the table will be 2 bytes then so to adjust for that you need to multiply the index (the value you get from the frame counter) by 2 to get the correct one. You can do that using an ASL before the TAX storing it in X.

If you clean up everything then you should end up with something similar to this:
(I recommend trying to do it yourself first if you want to learn)