This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
asm_stylesheet [2015/10/25 12:53] – [3. xkas command structurization (WIP)] black_falcon | asm_stylesheet [2015/10/25 13:53] – [3. Organization of Xkas Commands] black_falcon | ||
---|---|---|---|
Line 23: | Line 23: | ||
- Commentary | - Commentary | ||
- | 3. xkas command structurization **in progress** | + | 3. Organizing Xkas Commands **done** |
4. Tips for Optimizing Your Workflow using N++ Macros **pending** | 4. Tips for Optimizing Your Workflow using N++ Macros **pending** | ||
Line 84: | Line 84: | ||
N++ is one of, if not the most versatile and popular code viewers out there. It supports lots of different programming languages such as batch or C++. | N++ is one of, if not the most versatile and popular code viewers out there. It supports lots of different programming languages such as batch or C++. | ||
If the language you need is not supported, you can simply define it nice and easy using the custom language feature. | If the language you need is not supported, you can simply define it nice and easy using the custom language feature. | ||
- | Lucky for you I already made one for SNES ASM so you don't have to bother. | + | Lucky for you I already made one for SNES ASM so you don't have to bother.\\ |
- | To add the ASM language stylesheet, open up N++ and go to Language > User-defined (at the very bottom) | + | To add the ASM language stylesheet, open up N++ and go to '' |
Alternatively you can simply click the toolbar icon for it (it's a window with a lightning drawn into it) | Alternatively you can simply click the toolbar icon for it (it's a window with a lightning drawn into it) | ||
{{: | {{: | ||
- | In the opened window, click 'import' and select my stylesheet: | + | In the opened window, click '' |
{{: | {{: | ||
Line 103: | Line 103: | ||
====== 2. Basic code structure ====== | ====== 2. Basic code structure ====== | ||
- | ===== One Event Per Line ===== | + | ===== One Event/ |
The following example shows how I used to write code when I just got started: | The following example shows how I used to write code when I just got started: | ||
Line 130: | Line 130: | ||
Now what's a statement? | Now what's a statement? | ||
---- | ---- | ||
- | //**A statement is a combination of opcodes and arguments, which creates either a check, performs an operation or causes any kind of change to a value and things such as RAM adresses and hardware registers.**// | + | **A statement is a combination of opcodes and arguments, which creates either a check, performs an operation or causes any kind of change to a value and things such as RAM adresses and hardware registers.** |
---- | ---- | ||
- | Most statements consist of three steps: reading >> calculating/ | + | Most statements consist of three steps: |
an example statement would be an addition operation: | an example statement would be an addition operation: | ||
Line 142: | Line 142: | ||
STA $09C2 ; | STA $09C2 ; | ||
- | Now this can be organized to have the operation on a single line: | + | Now this can be organized to have the operation on a single line using colons as separators: |
LDA $09C2 : CLC : ADC #$0001 : STA $09C2 | LDA $09C2 : CLC : ADC #$0001 : STA $09C2 | ||
- | "What, you could do that? | + | "What, you can actually |
Unorganized check statement(also referred to as conditional branching): | Unorganized check statement(also referred to as conditional branching): | ||
Line 178: | Line 178: | ||
Branch: | Branch: | ||
- | Notice that the branch labels can be put into the same line right before the code without looking cluttered. | + | Notice that the branch labels can be put into the same line right before the code without looking cluttered.\\ |
- | Please | + | Though please |
LDA $09C2 : CMP #$0E00 : BEQ Branch : LDA $09C2 : CLC : ADC #$0001 : STA $09C2 | LDA $09C2 : CMP #$0E00 : BEQ Branch : LDA $09C2 : CLC : ADC #$0001 : STA $09C2 | ||
Line 196: | Line 196: | ||
DEX : CPX #$0000 : BPL back | DEX : CPX #$0000 : BPL back | ||
- | Three statements make up this loop: Initializing X, calculating/ | + | Three statements make up this loop: Initializing X, calculating/ |
Now there are some special cases of statements, especially when it comes to checking several bits in a respective order like button inputs or items: | Now there are some special cases of statements, especially when it comes to checking several bits in a respective order like button inputs or items: | ||
Line 224: | Line 224: | ||
SEC : RTL | SEC : RTL | ||
- | Any kind of status | + | Status |
SEP #$30 | SEP #$30 | ||
Line 232: | Line 232: | ||
**Stack operations** should be put together onto a **single line**, for easy recognition of the order they are in | **Stack operations** should be put together onto a **single line**, for easy recognition of the order they are in | ||
- | (wrong order of pushing onto/ | + | (wrong order of pushing onto/ |
PHX : PHY : PHP | PHX : PHY : PHP | ||
Line 356: | Line 356: | ||
===== Folding Blocks Of Code ===== | ===== Folding Blocks Of Code ===== | ||
- | You can use the braces '' | + | You can use the brackets/braces '' |
Xkas will ignore them, so you're free to use them anywhere. | Xkas will ignore them, so you're free to use them anywhere. | ||
- | example: | + | __Example:__ |
JSR $A4D6 | JSR $A4D6 | ||
Line 381: | Line 381: | ||
Not really much to say, except you should have as many open brackets as closed ones, else N++ won't collapse them correctly. | Not really much to say, except you should have as many open brackets as closed ones, else N++ won't collapse them correctly. | ||
By default, if you open a asm file in N++, everything is unfold. | By default, if you open a asm file in N++, everything is unfold. | ||
- | To fold/ | + | To fold/ |
Line 387: | Line 387: | ||
- | Commentary is very important for getting a better understanding of what's going on. | + | Commentary is very important for getting |
- | But it's easy to cross the line and soak your code with unnecessarily detailed comments | + | But it's easy to cross the line and soak your code with unnecessarily detailed comments |
It helps just about as much as having bareboned code without any extra word, no one's gonna read anything. | It helps just about as much as having bareboned code without any extra word, no one's gonna read anything. | ||
- | But since I showed you the concept of one event per line, it'll actually prevent you from doing so. | + | However |
This code has too much info, which is only useful for absolute ASM beginners: | This code has too much info, which is only useful for absolute ASM beginners: | ||
Line 400: | Line 399: | ||
BEQ VAR ;branch if varia is equipped | BEQ VAR ;branch if varia is equipped | ||
- | Using the one-event-per-line rule: | + | Using the one-statement-per-line rule: |
LDA $09A2 : AND #$0001 : CMP #$0001 : BEQ VAR ;check if varia is equipped | LDA $09A2 : AND #$0001 : CMP #$0001 : BEQ VAR ;check if varia is equipped | ||
- | You notice that it doesn' | + | You notice that it doesn' |
- | If you don't know how specific opcodes work exactly, feel free to ask, that's what Metconst is for after all! | + | If you don't know how specific opcodes work exactly, feel free to ask, that's what Metconst is for after all!\\ |
Now again you don't HAVE to use comments, only if you feel things need a short explaination. | Now again you don't HAVE to use comments, only if you feel things need a short explaination. | ||
- | ====== 3. xkas command structurization (WIP) ====== | + | ====== 3. Organizing Xkas Commands |
+ | In the ASM stylesheet, xkas commands are blue, operators are teal (or red in previous versions). | ||
+ | |||
+ | ===== Org and Data Commands ===== | ||
- | In the ASM stylesheet, all the xkas commands are blue by default. | ||
Most commonly used commands are '' | Most commonly used commands are '' | ||
'' | '' | ||
Line 433: | Line 434: | ||
} | } | ||
- | __Xkas fill functions organzation: | + | ===== Label Definitions ===== |
- | org $808000 | + | Defines are awesome and very helpful, though only if organized properly. |
- | fillbyte | + | This is how I used to write label definitions: |
+ | !input = $8B | ||
+ | !frameinput = $8F | ||
+ | !up = $09AA | ||
+ | !down = $09AC | ||
+ | !left = $09AE | ||
+ | !right = $09B0 | ||
+ | !speed = #$0006 | ||
+ | !jump = $09B4 | ||
+ | !timer = $072D | ||
+ | !EnemySizeX = #$0020 | ||
+ | !EnemySizeY = #$0010 | ||
+ | !SMILEspeed = $0FB4 | ||
+ | !SMILEspeed2 = $0FB6 | ||
+ | !bomby = $0B82,x | ||
+ | !samusy = $0AFA | ||
+ | !pby = $0CE4 | ||
+ | !projectiley = $0B78,x | ||
+ | |||
+ | Having them like this is especially bad if you have a large file with tons of asm defines, so try to categorize and visually separate them: | ||
+ | |||
+ | { ; LABEL DEFINES ====================== | ||
+ | { ; BUTTON INPUT ----------------- | ||
+ | !input = $8B : !frameinput = $8F | ||
+ | !up = $09AA : !down = $09AC | ||
+ | !left = $09AE : !right = $09B0 | ||
+ | !jump = $09B4 | ||
+ | } | ||
+ | |||
+ | { ;IMMEDIATE VALUES--------------- | ||
+ | !speed = #$0006 : !region = #$0005 | ||
+ | !EnemySizeX = #$0020 : !EnemySizeY = #$0010 | ||
+ | } | ||
+ | |||
+ | { ;SMILE ENEMY EDITOR ------------ | ||
+ | !SMILEspeed = $0FB4 : !SMILEspeed2 = $0FB6 | ||
+ | } | ||
+ | |||
+ | { ;Y POSITIONS-------------------- | ||
+ | !samusy = $0AFA : !bomby = $0B82,x | ||
+ | !projectiley = $0B78,x : !pby = $0CE4 | ||
+ | } | ||
+ | |||
+ | { ;MISC -------------------------- | ||
+ | !timer = $072D | ||
+ | } | ||
+ | } | ||
+ | |||
+ | In N++: | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ===== Repeatitions ===== | ||
__Repeatedly used opcodes:__ | __Repeatedly used opcodes:__ | ||
Line 448: | Line 501: | ||
LDA $07A5 : AND #$00FF : ASL : ASL : ASL : ASL : STA $0AF6 | LDA $07A5 : AND #$00FF : ASL : ASL : ASL : ASL : STA $0AF6 | ||
- | ...you can let xkas create pseudo | + | ...you can let xkas create pseudo |
NOP # | NOP # | ||
LDA $07A5 : AND #$00FF : ASL #4 : STA $0AF6 | LDA $07A5 : AND #$00FF : ASL #4 : STA $0AF6 | ||
- | But be careful | + | But be careful |
SEP #$20 | SEP #$20 | ||
Line 459: | Line 512: | ||
REP # | REP # | ||
+ | __Xkas fill functions organzation: | ||
- | + | org $808000 : padbyte $FF : pad $808010 ; | |
- | + | fillbyte $ff : fill 16 | |
- | + | ||
- | + | ||
====== 4. Tips for Optimizing Your Workflow using N++ Macros (Pending) ====== | ====== 4. Tips for Optimizing Your Workflow using N++ Macros (Pending) ====== | ||