Language…
20 users online: akawo, Alex No, CroNo, DanMario24YT, Gemini0, Golden Yoshi, Green, Gulaschko, Hammerer, kurtistrydiz,  MarioFanGamer, MarkVD100, Maw, mtheordinarygamer, rafaelfutbal, Rykon-V73, Spedinja, steelsburg, superbot12, Tulip Time Scholarship Games - Guests: 289 - Bots: 536
Users: 64,795 (2,370 active)
Latest user: mathew

Official Hex/ASM/Etc. Help Thread

  • Pages:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 418
  • 419
  • 420
Originally posted by Monster
Do AND #$40 instead of CMP $40

You're checking ram address $15 against ram address $40 currently.



If it's crashing with BRA, something's wrong with InAction.

Ok, now it no longer crashes the game, but it just does nothing. I'm sure that's an error with other parts of the code though
Yeah, when using AND instead of CMP, be sure to also use BNE instead of BEQ. Your could should look somewhat like this:

LDA $15
AND #$40
BNE InAction
RTL
InAction:
;blah


 
It crashes the game.

ASM hates me.

*Edit* ok, it no longer crashes the game (I tweaked some stuff around) But it just does nothing instead. Sometimes I wonder why I even bother trying.
Could you post the entire code you're using?
My YouTube channel
Get the official ASMT resource pack here!

Originally posted by Stack-O-Munchers
Could you post the entire code you're using?

Very well.

Originally posted by my shitty codey bollocks
;; My RAM addresses
RAM_ExtraBits = $7FAB10
RAM_NewSpriteNumber = $7FAB9E
RAM_HammerIndex = $7F8823

;; Original subroutines
GetSpriteClippingA = $03B69F
GetSpriteClippingB = $03B6E5
CheckForContact = $03B72B
SprContactGfx = $01AB72
GivePoints = $02ACE5
SprGfxRt1x1 = $0190B2

;; Original RAM addresses
RAM_SpriteStatus = $14C8
RAM_SpriteYLo = $D8
RAM_SpriteXLo = $E4
RAM_SpriteYHi = $14D4
RAM_SpriteXHi = $14E0
RAM_MarioXPos = $94
RAM_MarioXPosHi = $95
RAM_MarioYPos = $D3
RAM_MarioYPosHi = $D4
RAM_SprOAMIndex = $15EA
OAM_Tile = $0302

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sprite init JSL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

dcb "INIT"
RTL

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sprite main JSL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

dcb "MAIN"
PHB
JSR MarioHasHammer

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Mario has hammer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MarioImages:
dcb $35,$35,$35,$36,$36,$37,$37,$37
DispX:
dcb $F4,$FF,$0D,$10,$10,$10,$0D,$FF
DispXHi:
dcb $FF,$FF,$00,$00,$00,$00,$00,$FF
DispY:
dcb $00,$FC,$02,$06,$10,$06,$02,$FC
dcb $FB,$F6,$FD,$06,$10,$06,$FD,$F6
DispYHi:
dcb $00,$FF,$00,$00,$00,$00,$00,$FF
dcb $FF,$FF,$FF,$00,$00,$00,$FF,$FF

MarioHasHammer:
LDA $16
AND #$40
BNE Normal
RTS

Normal:
LDA #$02
STA $7F8824 ; Disable cape spin and fire
STA $7F8825
STA $148F ; Set carrying sprite

STZ $7D ; Stops Mario's x movement

STZ $149F ; Disable flying

LDA $14 ; Set Mario image 7B
INC A
LSR A
AND #$07
TAY
LDA MarioImages,Y
STA $13E0

LDA $14 ; Calculate which frame to show
LSR A
AND #$07
STA $03

PHX ; Y displacement is different if Mario is small
LDX $19
BEQ NotSmall
CLC
ADC #$08
NotSmall:
PLX

TAY ; Set sprite Y position relative to Mario
LDA RAM_MarioYPos
CLC
ADC DispY,y
STA RAM_SpriteYLo,x
LDA RAM_MarioYPosHi
ADC DispYHi,y
STA RAM_SpriteYHi,x

LDY $03
LDA $76
BEQ Subtract

LDA RAM_MarioXPos ; Set sprite X position relative to Mario
CLC ; (Mario facing right)
ADC DispX,y
STA RAM_SpriteXLo,x
LDA RAM_MarioXPosHi
ADC DispXHi,y
STA RAM_SpriteXHi,x

BRA DoGfx

Subtract:
LDA RAM_MarioXPos ; Set sprite X position relative to Mario
SEC ; (Mario facing left)
SBC DispX,y
STA RAM_SpriteXLo,x
LDA RAM_MarioXPosHi
SBC DispXHi,y
STA RAM_SpriteXHi,x

DoGfx:
JSR SubGfx ; Draw hammer
LDA $9D
BNE Return
JSR Interact

LDA $14 ; The timer only ticks down every fourth frame
AND #$03
BEQ Return
INC $1540,X
Return:
RTS


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Process interaction with other sprites
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Interact:
LDY.B #$0B
LoopStart:
LDA RAM_SpriteStatus,Y ; Skip dead sprites
CMP #$08
BCC NextSprite
LDA $1686,Y ; Skip sprites that don't interact with others
AND #$08
BNE NextSprite
JSR SprSprInteract
NextSprite:
DEY
BPL LoopStart
RTS

SprSprInteract:
JSL GetSpriteClippingA
PHX
TYX
JSL GetSpriteClippingB
PLX
JSL CheckForContact
BCC Return1
PHX
TYX
LDA #$02 ; Sprite status = star killed
STA $14C8,x
LDA #$D0
STA $AA,x
JSL SprContactGfx
PLX

LDA RAM_ExtraBits,x
AND #$04
BNE BounusTime

LDA #$03 ; Play sound and give 200 points
STA $1DF9
LDA #$01
JSL GivePoints
RTS

BounusTime:
PHY ; Handle sound and points/1ups
LDY $1528,x
INY
CPY #$08
BCS NoStarSound
LDA StarSounds,y
STA $1DF9
BRA SetPoints
NoStarSound:
LDY #$08
SetPoints:
TYA
STA $1528,x
JSL GivePoints
PLY

Return1:
RTS

StarSounds
dcb $00,$13,$14,$15,$16,$17,$18,$19

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Draw Hammer graphics
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HammerTiles:
dcb $E6,$E4,$E6,$E8,$E6,$E8,$E6,$E4
Direction:
dcb $40,$00,$00,$00,$80,$00,$00,$00
Flip:
dcb $40,$00

SubGfx:
LDA $1540,x
CMP #$14
BNE NoSound
LDY #$24 ; \ play sound effect
STY $1DFC ; /
NoSound:

JSR GetDrawInfo
PHX

LDX $76
LDA Flip,x
STA $02

LDX $03

LDA $00
STA $0300,y

LDA $01
STA $0301,y

LDA HammerTiles,x
STA $0302,y

PHX
LDX $15E9
LDA $15F6,x ; get palette info
PLX
ORA $02
EOR Direction,x
ORA $64 ; add in tile priority of level
STA $0303,y ; store tile properties

PLX
LDY #$02
LDA #$01
JSL $01B7B3
NoDraw:
RTS




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; $B85D - off screen processing code - shared
; sprites enter at different points
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TABLE3 dcb $40,$B0
TABLE6 dcb $01,$FF
TABLE4 dcb $30,$C0,$A0,$80,$A0,$40,$60,$B0
TABLE5 dcb $01,$FF,$01,$FF,$01,$00,$01,$FF

SubOffScreen: JSR SUB_IS_OFF_SCREEN ; \ if sprite is not off screen, return
BEQ RETURN_2 ; /
LDA $5B ; \ goto VERTICAL_LEVEL if vertical level
AND #$01 ; |
BNE VERTICAL_LEVEL ; /
LDA $D8,x ; \
CLC ; |
ADC #$50 ; | if the sprite has gone off the bottom of the level...
LDA $14D4,x ; | (if adding 0x50 to the sprite y position would make the high byte >= 2)
ADC #$00 ; |
CMP #$02 ; |
BPL ERASE_SPRITE ; / ...erase the sprite
LDA $167A,x ; \ if "process offscreen" flag is set, return
AND #$04 ; |
BNE RETURN_2 ; /
LDA $13 ; \
AND #$01 ; |
STA $01 ; |
TAY ; /
LDA $1A ;x boundry
CLC
ADC TABLE4,y
ROL $00
CMP $E4,x ;x pos
PHP
LDA $1B ;x boundry hi
LSR $00
ADC TABLE5,y
PLP
SBC $14E0,x ;x pos high
STA $00
LSR $01
BCC LABEL20
EOR #$80
STA $00
LABEL20 LDA $00
BPL RETURN_2
ERASE_SPRITE LDA $14C8,x ; \ if sprite status < 8, permanently erase sprite
CMP #$08 ; |
BCC KILL_SPRITE ; /
LDY $161A,x
CPY #$FF
BEQ KILL_SPRITE
LDA #$00 ; \ mark sprite to come back
STA $1938,y ; /
KILL_SPRITE STZ $14C8,x ; erase sprite
RETURN_2 RTS ; return

VERTICAL_LEVEL LDA $167A,x ; \ if "process offscreen" flag is set, return
AND #$04 ; |
BNE RETURN_2 ; /
LDA $13 ; \ only handle every other frame??
LSR A ; |
BCS RETURN_2 ; /
AND #$01
STA $01
TAY
LDA $1C
CLC
ADC TABLE3,y
ROL $00
CMP $D8,x
PHP
LDA.W $001D
LSR $00
ADC TABLE6,y
PLP
SBC $14D4,x
STA $00
LDY $01
BEQ LABEL22
EOR #$80
STA $00
LABEL22 LDA $00
BPL RETURN_2
BMI ERASE_SPRITE

SUB_IS_OFF_SCREEN LDA $15A0,x ; \ if sprite is on screen, accumulator = 0
ORA $186C,x ; |
RTS ; / return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GET_DRAW_INFO
; This is a helper for the graphics routine. It sets off screen flags, and sets up
; variables. It will return with the following:
;
; Y = index to sprite OAM ($300)
; $00 = sprite x position relative to screen boarder
; $01 = sprite y position relative to screen boarder
;
; It is adapted from the subroutine at $03B760
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATA_03B75C: dcb $0C,$1C
DATA_03B75E: dcb $01,$02

GetDrawInfo: STZ $186C,X ; Reset sprite offscreen flag, vertical
STZ $15A0,X ; Reset sprite offscreen flag, horizontal
LDA $E4,X ; \
CMP $1A ; | Set horizontal offscreen if necessary
LDA $14E0,X ; |
SBC $1B ; |
BEQ ADDR_03B774 ; |
INC $15A0,X ; /
ADDR_03B774: LDA $14E0,X ; \
XBA ; | Mark sprite invalid if far enough off screen
LDA $E4,X ; |
REP #$20 ; Accum (16 bit)
SEC ; |
SBC $1A ; |
CLC ; |
ADC.W #$0040 ; |
CMP.W #$0180 ; |
SEP #$20 ; Accum (8 bit)
ROL ; |
AND.B #$01 ; |
STA $15C4,X ; |
BNE ADDR_03B7CF ; /
LDY.B #$00 ; \ set up loop:
LDA $1662,X ; |
AND.B #$20 ; | if not smushed (1662 & 0x20), go through loop twice
BEQ ADDR_03B79A ; | else, go through loop once
INY ; /
ADDR_03B79A: LDA $D8,X ; \
CLC ; | set vertical offscree
ADC DATA_03B75C,Y ; |
PHP ; |
CMP $1C ; | (vert screen boundry)
ROL $00 ; |
PLP ; |
LDA $14D4,X ; |
ADC.B #$00 ; |
LSR $00 ; |
SBC $1D ; |
BEQ ADDR_03B7BA ; |
LDA $186C,X ; | (vert offscreen)
ORA DATA_03B75E,Y ; |
STA $186C,X ; |
ADDR_03B7BA: DEY ; |
BPL ADDR_03B79A ; /
LDY $15EA,X ; get offset to sprite OAM
LDA $E4,X ; \
SEC ; |
SBC $1A ; |
STA $00 ; / $00 = sprite x position relative to screen boarder
LDA $D8,X ; \
SEC ; |
SBC $1C ; |
STA $01 ; / $01 = sprite y position relative to screen boarder
RTS ; Return

ADDR_03B7CF: PLA ; \ Return from *main gfx routine* subroutine...
PLA ; | ...(not just this subroutine)
RTS ; /


In case you can't tell, it's only a very mild edit of MikeyK's Hammer powerup sprite. What this is supposed to do is only work when you press Y, however it's now reverted to simply crashing the game.

my areas of tinkering are highlighted
Looks like you forgot the RTL after JSR MarioHasHammer. If you don't put it there, the code will continue with "MarioImages" and interpret the bytes as (faulty) code.

Edit: Oh yeah, and you forgot the PLB. Do what Alcaro said.


 
Originally posted by Doomdragon
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; sprite main JSL
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

dcb "MAIN"
PHB
JSR MarioHasHammer

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Mario has hammer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MarioImages:
dcb $35,$35,$35,$36,$36,$37,$37,$37

Wrong. Executing a table as code is 80% chance of crash and 99% chance of incorrece behavior. May I suggest this instead of the PHB JSR?
Quote
PHB
PHK
PLB
JSR MarioHasHammer
PLB
RTL

<blm> zsnes users are the flatearthers of emulation
Originally posted by WhiteYoshiEgg
Looks like you forgot the RTL after JSR MarioHasHammer. If you don't put it there, the code will continue with "MarioImages" and interpret the bytes as (faulty) code.

That's a fairly stu0pid mistake on my part. I've changed it accordingly.

However, it still crashes the game. Anything else that i've done woefully wrong?
Try this as your main routine:

dcb "MAIN"
PHB
JSR MarioHasHammer
PLB
RTL

If that doesn't work, use Alcaro's code.


 
Hmm, that appears to have worked to an extent. It does something cool now.

When you press Y, mario briefly flashes up as big mario (Literally for about a frame), and the stomping o Koopa sound effect is played. However, this only happens once: After this, pressing Y or X does nothing.

Any further pointers? if you'd prefer we can continue this conversation via PM to save space
_________________

*Edit*

Awesome, i just tried Alacro's code and it works almost perfectly.

When you press Y or X, mario clearly swings the hammer once, and it does kill enemies. The problem is it's too fast: It's literally a split-second animation. Also, i need to implement some kind of timer that limits how often you can swing the hammer (eg. A 1 second pause between swings).

This video should help explain:

<embed width="600" height="361" type="application/x-shockwave-flash" allowFullscreen="true" allowNetworking="all" wmode="transparent" src="http://static.photobucket.com/player.swf?file=http://vid165.photobucket.com/albums/u67/doomdragon_2007/merged-3.flv">

Also, For some reason when you swing the hammer for the first time, it appears to hit and kill something invisible. You can see the points and everything. What's this about?
I've got a small problem of my own...

How can I execute code for a certain amount of frames? I don't want it to run every x frames, I want it to run for x frames and then stop.


 
Originally posted by WhiteYoshiEgg
I've got a small problem of my own...

How can I execute code for a certain amount of frames? I don't want it to run every x frames, I want it to run for x frames and then stop.

A frame counter than increases every frame?

What about RAM Address $7E:0013?


I know about that, but I don't know how exactly to use it in my code. This is the code I currently have:

Loop:
LDA $13
CMP #$80
BCS Loop
JSR SUB_GFX
RTS

Doesn't seem to do anything.


 
You could decrement a RAM address every frame. But, since you appear to be coding a sprite (JSR SUB_GFX) you could use some of the sprite tables that already decrement themselves every frame. (Such as $1540 or $1558. Check the RAM map for others.)


Someone could make a code for LevelASM that causes the layer 3 water start with high tide and never go down?
You could try this.
<blm> zsnes users are the flatearthers of emulation
Really. I did not know that with this generator I could do custom heights. Thank you Alcaro.
I'm trying to make a sprite that bounces along the ground (like a green bouncing koopa).

How would a code like that look? (that would determines the y speed of the sprite that is...)

Thanks in advance.
Waluigi needs his own game, he doesn't even have character!
...
Currently working on Waluigi's Treasure Hunt.
Set the y speed whenever it touches the ground downwards. Lesson2b.asm has the "touch ground" code, and I assume you know how to set y speeds.
I see this in many blocks:

LDA #01
STA #$19
RTL

But it would be the same thing?

LDY #01
STY #$19
RTL

If the answer is yes, because many use it, and what to use?
LDY #00
LDA #01
STA #$19
RTL
  • Pages:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 418
  • 419
  • 420