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
Last revisionBoth sides next revision
asm_stylesheet [2015/10/25 13:00] – [Folding Blocks Of Code] black_falconasm_stylesheet [2015/10/25 19:57] – [Super Metroid Assembly Style Guide] black_falcon
Line 2: Line 2:
 ====== Super Metroid Assembly Style Guide ====== ====== Super Metroid Assembly Style Guide ======
  
-**A guide that helps you correctly writing and organizing your ASM code to optimize your workflow and keep you motivated! :)+**A guide that helps you correctly writing and organizing your ASM code to optimize your workflow and keep you motivated! :)\\
 Please note that this is __NO ASM TUTORIAL!__. \\ Please note that this is __NO ASM TUTORIAL!__. \\
 You have to know how ASM code works and how it is stored in the game's ROM in order to make use of this guide. You have to know how ASM code works and how it is stored in the game's ROM in order to make use of this guide.
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 409: Line 409:
  
  
-====== 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 432: 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 447: 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 458: 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) ======