Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,541,249
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 05-05-24 06:11 PM
Guest: Register | Login

0 users currently in SMW Hacking | 2 guests

Main - SMW Hacking - Problems with sprite code New thread | New reply


Buu-Huu
Posted on 02-18-08 08:46 PM (rev. 2 of 02-18-08 09:29 PM) Link | Quote | ID: 78168


Level: 26

Posts: 74/113
EXP: 93278
Next: 8997

Since: 11-01-07

Last post: 5419 days
Last view: 5346 days
I have this sprite code (with help of mikeyks tutorial and especially smkdans help):

dcb "INIT"
RTL

dcb "MAIN"
JSR SUB_GFX
RTL

;;;;;Graphics Routeine

FRAMES dcb $C2,$C0

SUB_GFX
JSR GET_DRAW_INFO

LDA $157C,x
STA $02

LDA $00
STA $0300,y

LDA $01
STA $0301,y

PHX
LDA $13
LSR A
LSR A
AND #$01
TAX
LDA FRAMES,x
STA $0302,y
PLX

LDA $15F6,x

PHX
LDX $02
BNE_NO_FLIP_1
ORA #$40
NO_FLIP_1
PLX

ORA $64
STA $0303,y

INY
INY
INY
INY

LDY #$02
LDA #$00
JSL $01B7B3
RTS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;
; 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;

SPR_T1 dcb $0C,$1C
SPR_T2 dcb $01,$02

GET_DRAW_INFO 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 ON_SCREEN_X ; |
INC $15A0,x ; /

ON_SCREEN_X LDA $14E0,x ; \
XBA ; |
LDA $E4,x ; |
REP #$20 ; |
SEC ; |
SBC $1A ; | mark sprite invalid if far enough off screen
CLC ; |
ADC.W #$0040 ; |
CMP.W #$0180 ; |
SEP #$20 ; |
ROL A ; |
AND #$01 ; |
STA $15C4,x ; /
BNE INVALID ;

LDY #$00 ; \ set up loop:
LDA $1662,x ; |
AND #$20 ; | if not smushed (1662 & 0x20), go through loop twice
BEQ ON_SCREEN_LOOP ; | else, go through loop once
INY ; /
ON_SCREEN_LOOP LDA $D8,x ; \
CLC ; | set vertical offscreen if necessary
ADC SPR_T1,y ; |
PHP ; |
CMP $1C ; | (vert screen boundry)
ROL $00 ; |
PLP ; |
LDA $14D4,x ; |
ADC #$00 ; |
LSR $00 ; |
SBC $1D ; |
BEQ ON_SCREEN_Y ; |
LDA $186C,x ; | (vert offscreen)
ORA SPR_T2,y ; |
STA $186C,x ; |
ON_SCREEN_Y DEY ; |
BPL ON_SCREEN_LOOP ; /

LDY $15EA,x ; get offset to sprite OAM
LDA $E4,x ; \
SEC ; |
SBC $1A ; | $00 = sprite x position relative to screen boarder
STA $00 ; /
LDA $D8,x ; \
SEC ; |
SBC $1C ; | $01 = sprite y position relative to screen boarder
STA $01 ; /
RTS ; return

INVALID PLA ; \ return from *main gfx routine* subroutine...
PLA ; | ...(not just this subroutine)
RTS ; /


The tiles should now switch between the smiley coin and the message box but it looks glitched. Here is the screenshot:



I hope somebody can help me and correct the mistake.

edit by blackhole89: Changed to use code tag for improved readability.

smwedit
Posted on 02-19-08 11:43 PM (rev. 4 of 02-19-08 11:50 PM) Link | Quote | ID: 78365


Goomba
Level: 14

Posts: 25/27
EXP: 11003
Next: 2068

Since: 07-03-07

Last post: 5830 days
Last view: 5041 days
well here's one problem:

PHX
LDX $02
BNE_NO_FLIP_1
ORA #$40
NO_FLIP_1
PLX

there's an underscore between BNE and NO_FLIP_1

EDIT: on side note, use $14 instead of $13 so it doesn't switch while the game is paused/sprites locked/etc.

Buu-Huu
Posted on 02-20-08 08:06 PM Link | Quote | ID: 78435


Level: 26

Posts: 75/113
EXP: 93278
Next: 8997

Since: 11-01-07

Last post: 5419 days
Last view: 5346 days
Won't work either, they're still random tiles. The strange thing is that the sprite works for smkdan but for me it won't work. And it don't switches while in Pause Mode. But it's still on LDA $13. I don't have any clue but this gets slowly annoying.

Buu-Huu
Posted on 02-22-08 03:48 PM Link | Quote | ID: 78567


Level: 26

Posts: 76/113
EXP: 93278
Next: 8997

Since: 11-01-07

Last post: 5419 days
Last view: 5346 days
I give up, nobody can help me. I knew it, I will never be able to code my own sprites, I learned all this shit for nothing...

Main - SMW Hacking - Problems with sprite code New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.019 seconds. (349KB of memory used)
MySQL - queries: 37, rows: 60/61, time: 0.015 seconds.