User Tools

Site Tools


asm_stylesheet

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
asm_stylesheet [2015/10/25 12:53] – [3. xkas command structurization (WIP)] black_falconasm_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 ''Language > User-defined'' (at the very bottom)
 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)
  
 {{:asmguidecustomlang1.png|}} {{:asmguidecustomlang1.png|}}
  
-In the opened window, click 'import' and select my stylesheet:+In the opened window, click ''Import'' and select my stylesheet:
  
 {{:asmguidecustomlang2.png|}} {{:asmguidecustomlang2.png|}}
Line 103: Line 103:
 ====== 2. Basic code structure ====== ====== 2. Basic code structure ======
  
-===== One Event Per Line =====+===== One Event/Statement Per Line =====
  
 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/masking >> writing/checking+Most statements consist of three steps: //reading >> calculating/masking >> writing/checking//
  
 an example statement would be an addition operation: an example statement would be an addition operation:
Line 142: Line 142:
  STA $09C2 ;writing (simple, nuh?)  STA $09C2 ;writing (simple, nuh?)
  
-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?!" Sure thing you can!+"What, you can actually do that?!" Sure thing you can!
  
 Unorganized check statement(also referred to as conditional branching): Unorganized check statement(also referred to as conditional branching):
Line 178: Line 178:
  Branch: LDA #$0E00 : STA $09C2  Branch: LDA #$0E00 : STA $09C2
  
-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 **avoid** trying to merge multiple statements all into one line like this:+Though please **avoid** merging multiple statements all into one line like this:
  
          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/changing an address value, and increasing/checking X), thus I used three lines.+Three statements make up this loop: Initializing X, calculating/changing an address value, and increasing/checking X), thus I used three lines.\\
 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 register statements as well as conditionless jumps (''BRA'', ''JMP'', ''JML'') should each be on a single line:+Status register changes (''SEP'',''REP''as well as conditionless jumps (''BRA'', ''JMP'', ''JML'') should each be on a single line:
  
  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/pulling from stack is the main reason for emulator crashes!):+(wrong order of pushing onto/pulling from stack is the most common reason for emulator crashes!):
  
  PHX : PHY : PHP  PHX : PHY : PHP
Line 356: Line 356:
 ===== Folding Blocks Of Code ===== ===== Folding Blocks Of Code =====
    
-You can use the braces ''{ }'' to collapse code by clicking the (by default) [-] box on the left.+You can use the brackets/braces ''{ }'' to collapse code by clicking the [-] box on the left.
 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/collapse all the text blocks, goto view > Fold all+To fold/collapse all the text blocks, goto ''View > Fold All''
  
  
Line 387: Line 387:
  
  
-Commentary is very important for getting a better understanding of what's going on. +Commentary is very important for getting and keeping a better understanding of what's going on. 
-But it's easy to cross the line and soak your code with unnecessarily detailed comments on every line. +But it's easy to cross the line and soak your code with unnecessarily detailed comments about things\\
 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 since I showed you the concept of one event/statement per line, it'll actually prevent you from doing so.
  
 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't need that much info, a simple comment about the event itself is totally sufficient, but still better than none. +You notice that it doesn't need that much info, a simple comment about the event/statement itself is totally sufficient, but still better than none.\\ 
-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 ''DB'' (Data Byte), ''DW'' (Data Word), ''DL'' (Data Long) and ''org'' (sets file position) Most commonly used commands are ''DB'' (Data Byte), ''DW'' (Data Word), ''DL'' (Data Long) and ''org'' (sets file position)
 ''org'' along with an optional label should always be put onto a single line, and if necessary be on the same line after the open brace to collapse the code that is following afterwards. ''org'' along with an optional label should always be put onto a single line, and if necessary be on the same line after the open brace to collapse the code that is following afterwards.
Line 433: Line 434:
  }  }
  
-__Xkas fill functions organzation:__+===== Label Definitions =====
  
- org $808000 padbyte $FF pad $808010 ;should always be on one line +Defines are awesome and very helpful, though only if organized properly. 
- fillbyte $ff fill 16+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++: 
 + 
 +{{:asmguidedef1.png|}} 
 + 
 +===== 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 upcodes using # and a number (always decimal):+...you can let xkas create pseudo opcodes using # and numbers (always decimal):
  
  NOP #7 ;this equals NOP : NOP : NOP : NOP : NOP : NOP : NOP  NOP #7 ;this equals NOP : NOP : NOP : NOP : NOP : NOP : NOP
  LDA $07A5 : AND #$00FF : ASL #4 : STA $0AF6  LDA $07A5 : AND #$00FF : ASL #4 : STA $0AF6
  
-But be careful when writing to status register (''SEP'',''REP''or 8 bit operations to not forget the '$' sign:+But be careful at status register (''SEP'',''REP''and 8 bit operations to not forget the '$' sign:
  
  SEP #$20  SEP #$20
Line 459: Line 512:
  REP #20 ;forgetting '$' will instead write REP #$00 20 times, meaning a total 40 bytes are written!  REP #20 ;forgetting '$' will instead write REP #$00 20 times, meaning a total 40 bytes are written!
  
 +__Xkas fill functions organzation:__
  
- + org $808000 : padbyte $FF : pad $808010 ;should always be on one line 
- + fillbyte $ff : fill 16
- +
- +
 ====== 4. Tips for Optimizing Your Workflow using N++ Macros (Pending) ====== ====== 4. Tips for Optimizing Your Workflow using N++ Macros (Pending) ======