Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Loading ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LDA = Load Data into Accumulator
- LDX = Load Data into X
- LDY = Load Data into Y
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Storing ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- STA = Store Accumulator
- STX = Store X
- STY = Store Y
- STZ = Store 0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Returning ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- RTS = Return from Subroutine
- RTL = Return from Subroutine, Long
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Adding ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- INC = Increment, +1
- INX
- INY
- ADC = Add with Carry
- CLC = Clear Carry Flag, usually goes before ADC
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Subtracting ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- DEC = Decrease, -1
- SBC = Subtract with Carry
- SEC = Set Carry Flag, usually goes before SBC
- DEX
- DEY
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Multiplying ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ASL = Accumulator Shift Left, x2, can stack
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Dividing ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LSR = Logical Shift Right, /2, can stack
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Transferring ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- TYA = Y to A
- TAY = A to Y
- TXA = X to A
- TAX = A to X
- TYX = Y to X
- TXY = X to Y
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Comparing ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- CMP = Compare
- LDA $19 ;Loads player's powerup
- CMP #$02 ;Checks if cape
- ;Branching without CMP assumes value is 0
- CPX = Compare to X
- CPY = Compare to Y
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Branching ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- BRA = Branch
- BRL = Branch Long
- BEQ = Branch if Equal, aka CMP = A
- BNE = Branch if Not Equal, aka CMP != A
- LDA $19
- CMP #$02
- BNE Return
- (do something here)
- Return:
- RTS
- BCC = Branch if Carry Clear, aka CMP > A
- LDA $19 ;Loads powerup status
- CMP #$02 ;Checks if cape
- BCC Return ;Branch if 0 or 1
- LDA #$14 ;Load 20 into A
- STA $13CC ;Store 20 to coin counter
- Return:
- RTS
- BCS = Branch if Carry Set, aka CMP <= A
- LDA $19 ;
- CMP #$02 ;
- BCS Return ;Branch if A >= 02
- LDA #$14 ;Mario is small or big, no powerups
- STA $13CC ;
- Return: ;He has fire or cape
- RTS ;
- BPL = Branch if Plus (00-7F), can be used for looping
- LDX #$03 ;X at 03
- Loop:
- (insert code)
- DEX ;X-1
- BPL Loop ;02 is still positive, so branch
- BMI = Branch if Minus (80-FF)
- BVC = Branch if Overflow Clear
- BVS = Branch if Overflow Set
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Jumping ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- JMP = Jump
- 1. LDA #$01 ;go to 2
- 2. STA $19 ;go to 3
- 3. JMP Label ;go to 6
- 4. INC $0DBE
- 5. RTS
- 6. Label: ;go to 7
- 7. LDA #$10 ;go to 8
- 8. STA $1490 ;go to 9
- 9. RTS ;rinse and repeat
- JML = Jump Long, can go outside bank
- JSR = Jump to Subroutine (uses 2 bytes of stack)
- 1. LDA #$01 ;go to 2
- 2. STA $19 ;go to 3
- 3. JMP Label ;go to 6
- 4. INC $0DBE ;go to 5
- 5. RTS ;rinse and repeat
- 6. Label: ;go to 7
- 7. LDA #$10 ;go to 8
- 8. STA $1490 ;go to 9
- 9. RTS ;go to 4
- JSL = Jump to Subroutine, Long (uses 3 bytes of stack)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Blocks ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- See base block.asm
- Turn block into blank tile:
- LDA #$02
- STA $9C
- JSL $00BEB0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Indexing ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- $0000,x
- $0000,y
- Example:
- LDY $95 ;load the current screen number into y
- LDA #$C2 ;load level c2 to a
- STA $19B8,y ;store c2 as the exit for the current screen
- Example:
- LDX $19 ;load mario's powerup status to x
- LDA InvincibilityTimer,x;jump to table
- STA $1490 ;star power timer
- RTL
- InvincibilityTimer:
- db $FF,$7F,$3F,$1F ;pick byte depending on powerup
- dp,x = direct (8-bit) address
- abs,x = absolute (16-bit)
- long,x = long (24-bit)
- abs,y = absolute
- You can sort of index a direct address by Y by simply adding 00 at the
- beginning, like so:
- LDA $00C2,y (or if you're doing something that requires xkas, LDA.w
- $00C2,y)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Bitwise Operations ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- AND = AND Accumulator with Memory, compares A to value after AND, puts new value
- into A. If either bit is 0, the result will be a 0.
- LDA #$5A (0 1 0 1 1 0 1 0)
- AND #$93 (1 0 0 1 0 0 1 1)
- (? ? ? ? ? ? ? ?)
- (? ? ? ? ? ? ? 0)
- (? ? ? ? ? ? 1 0)
- (? ? ? ? ? 0 1 0)
- (? ? ? ? 0 0 1 0)
- (? ? ? 1 0 0 1 0)
- (? ? 0 1 0 0 1 0)
- (? 0 0 1 0 0 1 0)
- (0 0 0 1 0 0 1 0)
- ;;;;;;;;;;;;;;;;;
- LDA $77 ;SxxMUDLR - which sides player is blocked by
- AND #$04 ;clears all bits except D
- (? ? ? ? ? x ? ?)
- (0 0 0 0 0 1 0 0)
- ORA = OR Accumulator with Memory. If either bit is 1, the result will be a 1.
- LDA #$5A (0 1 0 1 1 0 1 0)
- AND #$93 (1 0 0 1 0 0 1 1)
- (1 1 0 1 1 0 1 1)
- ;;;;;;;;;;;;;;;;;
- LDA $1490 ;star invincibility timer
- ORA $1497 ;flashing invincibility timer
- ORA $73 ;if player is ducking
- ORA $187A ;if riding yoshi
- ORA $1493 ;if level is ending
- BNE LeaveHimAloneYouJerk;if any are 1, enemy can't attack
- ;;;;;;;;;;;;;;;;;
- LDA $15 ;controller data
- ORA #$41 ;player pressing y and right
- STA $15 ;force it
- EOR = Exclusive OR Accumulator with Memory, if one bit is 1, the result will be
- a 1. If both are 0 or both are 1, returns a 0.
- LDA #$5A (0 1 0 1 1 0 1 0)
- AND #$93 (1 0 0 1 0 0 1 1)
- (1 1 0 0 1 0 0 1)
- ;;;;;;;;;;;;;;;;;
- LDA $14AF ;if switch was 00 (on)
- EOR #$01 ;set it to 01 (off)
- STA $14AF
- ;;;;;;;;;;;;;;;;;
- LDA ---
- EOR #$FF ;flips all bits
- TRB = Test and Reset Bits, clears bits quickly
- LDA #$08 ;load bit 3
- TRB $0F40 ;clear it
- TSB = Test and Set Bits, sets bits quickly
- LDA #$08 ;load bit 3
- TSB $0F40 ;set it
- BIT = Bit Test
- LDA $7FAB10,x ;load the address holding the extra bits for
- custom sprites
- BIT #$04 ;check value without changing A
- BNE BitSet ;branch if value is 04, don't if 00
- ROL = Rotate Left, brings the carry flag back around
- CLC
- LDA #%01101010 ; #%01101010 = #$6A
- ROL ; A is now 11010100, or #$D4; the carry flag is clear
- ROL ; A is now 10101000, or #$A8; the carry flag is set
- ROL ; A is now 01010001, or #$51; the carry flag is set
- ROL ; A is now 10100011, or #$A3; the carry flag is clear
- ROL ; A is now 01000110, or #$46; the carry flag is set
- ROL ; A is now 10001101, or #$8D; the carry flag is clear
- ROL ; A is now 00011010, or #$1A; the carry flag is set
- ROR = Rotate Right
- CLC
- LDA #%01101010 ; #%01101010 = #$6A
- ROR ; A is now 00110101, or #$35; the carry flag is clear
- ROR ; A is now 00011010, or #$1A; the carry flag is set
- ROR ; A is now 10001101, or #$8D; the carry flag is clear
- ROR ; A is now 01000110, or #$46; the carry flag is set
- ROR ; A is now 10100011, or #$A3; the carry flag is clear
- ROR ; A is now 01010001, or #$51; the carry flag is set
- ROR ; A is now 10101000, or #$A8; the carry flag is set
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Processor Flags ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- envmxdizc
- e - emulation bit
- n -
- v -
- m - if clear, enables 16-bit values with A
- x - if clear, enables 16-bit values with X and Y
- d - decimal mode
- i - interrupt/IRQ disable
- z -
- c -
- SEP - Set Processor Bits, set any except e
- REP - Reset Processor Bit, any except e
- LDA #$24
- LDX #$60
- LDY #$40
- REP #$20 ;#$30 = REP #%00110000 -> nvMXdizc
- LDA #$0380 ;enables A to hold 16-bit numbers
- LDX #$01FF ;enables X to hold 16-bit numbers
- LDY #$14C0 ;enables Y to hold 16-bit numbers
- LDA #$1280 ;80 goes into $7E
- STA $7E ;12 goes into $7F
- LDA $7E ;$7E and $7F
- CMP $80 ;compared with $80 and $81
- Table16:
- dw $0001,$0403,$0807,$0C0B,$100F,$1413,$1817,$1C1B
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LDA $13 ;load frame counter
- AND #$07 ;clear top 5 bits
- ASL
- TAX ;transfer to x
- LDA Table16,x ;load 16-bit value from table based on result
- if 16-bit value's high byte is 00, opcode suffix should be .w
- XBA - Exchange Bytes of A, swaps high byte and low byte
- LDA #$10 ;load 10 to accumulator
- XBA ;swap high and low bytes -> 10??
- LDA #$23 ;load 23 into accumulator
- REP #$20 ;enable 16-bit mode, A is now #$1023
- SEI - Set Interrupt Flag, sets i bit
- CLI - Clear Interrupt Flag, clears i bit
- SED - Set Decimal Flag, sets d bit
- CLD - Clear Decimal Flag, clears d bit
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Stack ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- PHA - Push Accumulator
- LDA $1588,x ;load sledge bro's blocked status
- PHA ;push it into the stack
- JSL $01802A ;move the sprite
- LDA $1588,x ;$1588 now holds sprite's blocked status after moving
- AND #$04 ;check to make sure it isn't in the air
- BEQ NoShake ;branch if sledge bro is on the ground
- PLA ;pull the sprite's original blocked status
- AND #$04 ;check that it wasn't in the air
- BNE NoShake ;if it was on ground before moving, no shake
- PLA - Pull Accumulator
- PHX - Push X
- PLX - Pull X
- PHY - Push Y
- PHY ;preserve Y
- JSL $028663 ;make block shatter
- PLY ;bring back Y
- PLY - Pull Y
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LDA #$03
- STA $19
- LDA $03,s ;pull byte from 3 bytes down in stack
- STA $0F
- RTS
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- TCS - Transfer Accumulator C to Stack Pointer
- REP #$20
- LDA #$1100
- TCS
- TXS - Transfer X to Stack Pointer
- TSC - Transfer Stack Pointer to Accumulator C
- TSX - Transfer X to Stack Pointer
- TCD - Transfer 16-bit Accumulator to Direct Page, takes A & copies to direct
- page
- LDA #$1200 ;load #$1200 to C
- TCD ;transfer C to direct page
- LDA $40 ;load from $1240
- TCD - Transfer Direct Page register to 16-bit Accumulator
- PHD - Push Direct Page register
- PLD - Pull Direct Page register
- PHD ;push direct page into the stack
- LDA #$00 ;Load #$00
- XBA ;Swap the bytes
- LDA #$13 ;Now load #$13
- TCD ;Set the direct page to #$1300
- LDA $37 ;Load these values starting from #$1300
- STA $38
- LDA $39
- STA $3A
- LDA $3B
- STA $3C
- LDA $3D
- STA $3E
- LDA $3F
- STA $40
- LDA $41
- STA $42
- LDA $43
- STA $44
- PLD ;pull direct page from stack
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Patches ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- header - tells xkas the rom has a header
- lorom - tells xkas the rom is in LoROM format
- org - loads a ROM address
- db - stores values at the starting ROM address
- (See drop.asm for example)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Data Bank + Program Bank ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- Program Bank - indicates the bank in which code is currently running
- Data Bank - indicates the bank from which data will be loaded if the specified
- address isn't 24-bit
- LDA $A178,x ;\same thing, assuming data bank is 05
- LDA $05A178,x ;/
- opcode.l - force xkas to parse operand as 24-bit address
- LDA.l $8000,x ;assembles as $008000,x
- PHB - Push Data Bank Register, pushes value of data bank onto stack
- PLB - Pull Data Bank Register, pulls top byte of stack into data bank
- PHK - Push Program Bank Register, pushes value of program bank onto stack
- Wrapper:
- PHB ;pushes value of current data bank onto stack
- PHK ;pushes value of program bank onto stack
- PLB ;pulls value of the prgm bank into data bank
- JSR MainCode
- PLB ;pull original data bank value
- RTL
- MainCode:
- ;some stuff here
- RTS
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- PHB
- LDA #$02
- PHA ;push #$02 into stack
- PLB ;now the data bank is 02
- JSL $028663 ;subroutine that makes a block shatter
- PLB ;bring back original data bank value
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Pointers+Indirect Addressing ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- Examples:
- LDA #$14 ;\ store 14 to $01
- STA $01 ;/
- LDA #$20 ;\ store 20 to $00
- STA $00 ;/
- LDA ($00) ; Load from $1420
- LDA #$7F ;\ store 7F to $02
- STA $02 ;/
- LDA #$14 ;\ store 14 to $01
- STA $01 ;/
- LDA #$20 ;\ store 20 to $00
- STA $00 ;/
- LDA [$00] ; Load from $7F1420
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- HighBytes:
- db $10,$12,$14,$16
- Code:
- LDA #$7F ;\ store 7F as the bank byte
- STA $02 ;/
- LDY $19 ;\
- LDA HighBytes,y ; | pick high byte depending on powerup status
- STA $01 ;/
- STZ $00 ; set 00 as the low byte
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LDA $0F33 ; load ones digit of the timer
- STA $01 ; make it the high byte
- STZ $00 ; now make it divisible by 100
- LDY $19 ; load powerup status to Y
- LDA ($00),y ; load $(ones digit)(powerup status)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LDX $13BE ; item memory settings (can be 0-2)
- LDA #$F8 ; load F8
- CLC ;\add # of bytes from table depending on value
- ADC data1,x ;/
- STA $08 ; store that value to $08
- LDA #$19 ; load 19
- ADC data2,x ; add # of bytes from table depending on value
- STA $09 ; store that value to $09
- data1: ;\
- .db $00,$80,$00 ; | if $13BE = 00, value is 19F8, first table
- ; | if = 01, value is 19F8+80, second table
- data2: ; | if = 02, value is 19F8+100, third table
- .db $00,$00,$01 ;/
- LDY $57 ;
- AND #$07 ;
- TAX ;
- LDY $0E ; byte index into item memory table
- LDA ($08),y ; not the same as $19F8,y unless item memory setting = 0
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ($00,x) - Using [$00],x or ($00),x will not work. Using this method indexes the
- pointer itself. ($00), y on the other hand indexes the address being pointed to.
- LDA #$88 : STA $00
- LDA #$99 : STA $01
- LDA #$AA : STA $02
- LDA #$BB : STA $03
- LDA #$CC : STA $04
- LDA #$DD : STA $05
- LDA #$EE : STA $06
- LDA #$FF : STA $07
- LDA $13BF ; load overworld level number
- AND #$07 ; lower 3 bits of address
- TAX ; transfer the value to X
- LDA ($00,x) ; if at overworld level 20, x = 00, so start at $00, A
- is whatever is at $9988
- ; if level = 19, x = 01, start at $AA99
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- JMP ($0000)
- JMP ($0000,x)
- JML [$0000]
- JSR ($0000,x)
- REP #$30
- LDA !LevelNum
- ASL A
- TAX
- LDA LevelPtrs,x
- STA $00
- SEP #$30
- LDX #$00 ; ensures that pointer will always be $0000
- JSR ($0000,x) ; jumps to levelasm code for particular level
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- JSL $0086DF - subroutine used for pointer tables, just load pointer index into
- A, JSL to it, and put pointer table after - erases the three bytes JSL pushes
- onto the stack when it executes
- STZ $1491
- LDA RAM_SpriteNum,X
- JSL ExecutePtr
- dw ShellessKoopas ; 00 - Green Koopa, no shell
- dw ShellessKoopas ; 01 - Red Koopa, no shell
- dw Code
- ...
- Code:
- RTS
- JSL $0086FA - same as above, but for 24-bit pointers
- LDA $13BF
- AND #$07
- JSL $0086FA
- dl Code1
- dl Code2
- ...
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LDA $1100
- JSR Routine
- Label1:
- RTS
- Routine:
- LDY #$40
- PER $0007 ; 2 pointers * 2 + 3 = 7, if 24-bit pointers, 2 pointers
- * 3 + 3 = 9
- JSL $0086DF
- dw Sub1
- dw Sub2
- Sub3:
- STA $43
- STY $44
- RTS
- Sub1:
- STA $00
- RTS
- Sub2:
- STY $01
- RTS
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- LDA $1100
- JSL Routine
- Label1:
- RTS
- Routine:
- LDY #$40
- PHK
- PER $0009 ; 2 pointers * 3 + 3 = 9
- JSL $0086FA
- dl Sub1
- dl Sub2
- Sub3:
- STA $43
- STY $44
- RTL
- Sub1:
- STA $00
- RTL
- Sub2:
- STY $01
- RTL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement