Jump to content

Photo
- - - - -

[Scripting / 2.11] ZASM Tutorial


  • Please log in to reply
40 replies to this topic

#1 Revfan9

Revfan9

    Hero of Time

  • Banned
  • Real Name:Dr. Pajamas
  • Location:In front of a screen

Posted 04 January 2007 - 02:35 PM

Please excuse me, I've just hi-jacked the start of this thread to offer a little help to those who might be starting to learn.
I've left it here because I thought it was the most appropriate place, rather than in one of the sub-forums.

Just a note to those who may have stumbled in here by accident: ZASM (as it appears to me) is only really included as a way for ZScript to be linked to ZC's internal code.
By all means have a go at trying to use it, but you're unlikely to get any help as almost all scripts for Zelda Classic are written in our C-based ZScript.
AGN is very likely to be a better place to get help than here with regards to ZASM.
For help learning ZScript, check the sub-forums.

~Joe123


Alright. I'm going to give a tutorial on Zasm (To the best of my ability, I haven't exactly mastered it yet myself). There is quite a bit more than this, but here are the basics...

EDIT: I guess I should explain what Zasm is and how it is used then :P

Zasm scripts are used to move FFCs (and do some other things) in special ways that you can't do with changer combos. A Zasm script is a TXT file that is imported using Data->Import FFC script. Scripts can be used to do many things, from chaser traps to full-fledged custom bosses.

Structure:

A Zasm script has labels and functions. A label has no space in front of it, a function has a space in front of it. Like so...

CODE
WAIT WAITFRAME
GOTO WAIT


The label WAIT has no space, telling the compiler that it is a label. You put a space next to the label and put a function next to taht. You must use only one function per line.

CODE
WAIT WAITFRAME
SETV D0,1
GOTO WAIT


Like so. After the function goes a space, with the arguments after that. Each function other than WAITFRAME (stops executing lines until the next frame starts, quite useful for timers and the such) and QUIT (ends the script) has arguments. Arguments are seperated by a comma (,). Now for functions...

GOTO sends it to the label after GOTO. So GOTO WAIT would send the execution to the label WAIT.
COMPAREV compares a register with a number. COMPARER compares the first register to the second register. An important note is that if the last letter of a function is V, that means that the first argument is a register and the second is a number. If the laster letter is R, that means that both are registers.

After COMPAREV or COMPARER, you put another function (or multiple functions, you can use as many as you want for each COMPARE, as long as you want the same values to be compared each time). Here they are...

GOTOTRUE goes to the label if both values are equal.
GOTOFALSE goes to the label if the values are not equal.
GOTOLESS goes to the label if the first value is less than the second value.
GOTOMORE goes to the label if the first value is greater than or equal to (which I find really weird) the second value.

Now for some other functions that just do math. For the R functions, the first one is the register being changed, and the second register is from where the value is being taken from.

SETR Sets the register to a value
SETV
ADDR Adds the second one to the first one
ADDV
SUBR Subtracts the second value from the first one
SUBV
MULTR Multiplies both
MULTV
DIVR Divides teh first one by the second one.
DIVV
ANDR Not sure...
ANDV
ORR Also not sure... (if anyone knows, can they please tell me?)
ORV
XORR Exponents. The first register ^ the second one.
XORV

Now, for variables. Here are a few basic ones to get you started:

x The FFC's x position on the screen.
y The Y position of the FFC
linkx Link's X position
linky Link's Y position
xd The FFC's x speed
yd The FFC's y speed
Ax The FFC's X acceleration
Ay the FFC's Y acceleration
INPUTUP/DOWN/LEFT/RIGHT/START/A/B wether or not (1 if pressed, 0 if not) the button is pressed.

^ Of course, there are many more hard-coded variables, but those are the ones that you will see in practically every script. Every last variable can be read from and written to. Meaning that you can change and call from every last one of them, making Zasm very, very flexible.

Now, with what we have learned, let's make a script, shall we?

CODE
WAIT WAITFRAME
COMPAREV INPUTUP,1
GOTOTRUE UP
COMPAREV INPUTDOWN,1
GOTOTRUE DOWN
COMPAREV INPUTLEFT,1
GOTOTRUE LEFT
COMPAREV INPUTRIGHT,1
GOTOTRUE RIGHT
GOTO WAITFRAME
UP SETV y,-1
GOTO WAIT
DOWN SETV y,1
GOTO WAIT
LEFT SETV x,-1
GOTO WAIT
RIGHT SETV x,1
GOTO WAIT


Now, what will this script do? It will move the FFC around using the 4 directional keys.


Here's another trick: random values.

RNDV and RNDR set the first argument as a random number (the infinite number of decimals inbetween included) between 0 and the second argument. You can say, use RNDV x,240 to place the FFC on a random spot on the screen horizontally. That works fine and all, but say you want the minimum value to be something other than 0? Here's how you do it...

CODE
RNDV d0,1
MULTV d0,5
ADDV d0,5


That code sets the register d0 to a random value between 5 and 10. Why? Lemme explain how it works.

RNDV d0,1

This sets d0 to a random value between 0 and 1.

MULTV d0,5

This multiplies whatever value came out by 5. That way, if the value is 0.5, it will now be 2.5

ADDV d0,5

This adds 5 to what just came out. So now, 2.5 becomes 7.5, a value between 5 and 10. Using this, you can plug any value in you want as the random number (as long as it is between 0 and 1, and is not 0, as RNDV/R will never give you 0) and you will always get a number between 5 and 10. So this is how it works...

CODE
RNDV d0,1
MULTV d0,(minimum value)
ADDV d0,(The minimum value you want subtracted from the maximum value)


To set min/max values and get a random number. Have fun.

(Credits to Saffith, who taught me pretty much everything I know about Zasm)

I will be editing this post to include more as I write it, and feel free to ask me any questions you want, and I will answer them for you.

Also, I personally think this topic denotes a sticky ;)

#2 Revfan9

Revfan9

    Hero of Time

  • Banned
  • Real Name:Dr. Pajamas
  • Location:In front of a screen

Posted 05 January 2007 - 04:06 PM

Added how to use Random Values.

#3 Sharon Daniel

Sharon Daniel

    .

  • Banned

Posted 06 January 2007 - 10:44 PM

I don't get it. icon_eyebrow.gif What is "Zasm"?

#4 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 06 January 2007 - 10:50 PM

One of the two forms of Freeform Combo scripting.

#5 Revfan9

Revfan9

    Hero of Time

  • Banned
  • Real Name:Dr. Pajamas
  • Location:In front of a screen

Posted 07 January 2007 - 03:51 AM

I guess I should add what Zasm is and how to use them then.

#6 hakan92

hakan92

    Newbie

  • Members
  • Real Name:Håkan

Posted 07 January 2007 - 04:26 AM

Two kind of scripting? This one is Zasm and the othrer one is??

#7 Revfan9

Revfan9

    Hero of Time

  • Banned
  • Real Name:Dr. Pajamas
  • Location:In front of a screen

Posted 07 January 2007 - 04:29 AM

The other one is Zscript. I don't know much about Zscript though, so I wrote a tutorial on Zasm.

#8 /M/

/M/

    6♣7♠8♥9♥10♥

  • Members
  • Location:Gotham City

Posted 07 January 2007 - 11:23 AM

This is such a strange scripting technique. It seems simple at first glance, but when you attempt to make a script... That is the hard part. Even worst, ZQuest doesn't even tell what you've done wrong, instead it just crashes on you.

#9 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 07 January 2007 - 01:21 PM

Show me what you have typed for the script, and I'll help you fix it. icon_wink.gif

I agree, it is extremely simple and easy and compared to other ASM-based languages. Like z80 (Ti-83 calculator) ASM... not strange at all, IMO.

#10 Revfan9

Revfan9

    Hero of Time

  • Banned
  • Real Name:Dr. Pajamas
  • Location:In front of a screen

Posted 09 January 2007 - 05:24 AM

As it says in the above post, please feel free to post any problems or questions you have and I will help you.

#11 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 11 January 2007 - 07:38 PM

I'm trying out ZASM now. Unfortunately, it's not working. Here's what I have:

CODE
BEGIN WAITFRAME
RNDV X,240
RNDV Y,160
GOTO BEGIN


It's supposed to set the FFC it's set to to a random x and y position, right? Well, it says that instruction 2 is invalid. It goes on to say:

"The command was (x,240) (,)."

WHAT'S SO WRONG ABOUT A COMMA?!

#12 Revfan9

Revfan9

    Hero of Time

  • Banned
  • Real Name:Dr. Pajamas
  • Location:In front of a screen

Posted 11 January 2007 - 07:51 PM

Hmm... *goes to test*

What version are you using? It compiles in 12.9.1 (Sadly, I don't have any version older than that which supports scripting).

Other than that, it should be just fine. You may also want to (just for practicality)

A. The script will make it flash about the screen so fast as to be nearly impossible for the player to see. Try slowing down it's position.

B. The script also takes the full screen into account, instead of the parameters of the walls. I suggest that you make it only move about the center of the screen (I did explain min/max values in my above tutorial).

Of course, if it's just a test script, then nevermind.

#13 Fire Wizzrobe

Fire Wizzrobe

    Master

  • Members
  • Real Name:T

Posted 11 January 2007 - 08:00 PM

Nevermind, I got it. lol

Edited by Fire Wizzrobe, 11 January 2007 - 09:20 PM.


#14 Revfan9

Revfan9

    Hero of Time

  • Banned
  • Real Name:Dr. Pajamas
  • Location:In front of a screen

Posted 11 January 2007 - 08:06 PM

Hmm? I have copied/compiled the script in every version I have that supports Zscripts, and it all works. I wonder what is wrong?

#15 Nimono

Nimono

    Ultra Miyoa Extraordinaire!

  • Members
  • Real Name:Matthew
  • Location:Static Void Kingdom

Posted 11 January 2007 - 08:39 PM

Uhh.... Have you even TRIED beta 16? How can you STILL have 12.9.1 when more versions have come out?? Beta 15 supports scripting. Beta 16 does, too. I have beta 16b. And yes, it's just a test script.

Edit:


XD My problem has been solved. I forgot toput a space before the last three lines, so it took "RNDV" and "GOTO" as... uh, what did you call those things again? XD Anyways, I put spaces there, and now it works. icon_biggrin.gif

Edited by Matthew, 11 January 2007 - 08:44 PM.



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users