Banner
Views: 345,005,273
Time: 2015-04-01 04:22:53 AM
9 users online: o 1UPdudes, o Alice3173, Aquas, o Ersanio, Eternity, NGB, RainbowShell, Stiltzkin, yoshicookiezeus - Guests: 17 - Bots: 45Users: 26,511 (1,141 active)
Latest: COD RULEZ
Tip: Don't just modify the original COD battlefield; start from scratch.
Extended weapon Coding
Meeting hall Index - COD Hacking - General Warfare - Bootcamp - Extended weapon Coding
Pages: « 1 »
A semi-advanced knowledge of ASM things such as:

- Basic ASM (LDA, STA, LDX, STX, LDY, STY, etc)
- Stacking (PHA, PHY, PHX, PLA, PLX, PLY, etc)
- Jumping (JSR, JML, JSL, etc)
- Branching (BEQ, BNE, BCC, etc)
- Math (LSR, etc)

is mostly required for the understanding of the tutorial. Having custom weapon coding knowledge is also a plus.

So what exactly are extended weaponry?


Extended weaponry are those weaponry which are used for general aesthetics and projectiles. Such examples are any kind are rockets that are projected by weaponry. Another example would be the little lava splash that appears when a Blarg goes into the lava. In this tutorial I'm going to show you how to create one, and how to code the generating weapon as well. You must note that, just like cluster weaponry, extended weaponry are NOT regular weaponry. You can't insert them via COD School, you have spawn them through ASM routines. You can have up to 8 extended weaponry on the screen at once.

First of all, you need a patch to allow you to insert your custom extended weaponry, seeing as the original COD only allows 12. I have made one, I think Jagfillit has made one as well. In this tutorial I'm using examples to which can be applied to my patch, I haven't released it yet, you can find it here. Let's learn how to code them.

How do I code them?


First of all, find the weapon number that you want to use, since COD uses 12 extended weaponry, I'm going to use extended weapon 13. In my patch, I find the label "CusExSprite13" and I put my code under it. The first thing I'm going to do is restore every register that got messed up in the craziness of the jumping to different routines in different banks. Here is the code I use to do that:
Originally posted by
LDA !freeRAM
LDX !freeRAM+1
LDY !freeRAM+2
PHA
PHX
PHY
PHB
PHK
PLB

Basically, all you need to know about that is that it restores A,X, and Y then pushes registers to keep them save and pushes the bank number. Now what I'm going to do is make sure weaponry aren't locked. I do that with:
Originally posted by
LDA $9D
BNE Locked

Now, when weaponry are locked, the extended weapon will NOT run.

Now that's taken care of I want to JSR to the two routines that handle the weaponry X/Y speed. In my patch these routines are just a simple JSR to SHARED00 and SHARED01, but if you're using Jagfillit's the addresses are $02B554 and $02B560. Now, I want to give the weapon some Y speed. Here is the code I use for that:
Originally posted by
LDA $173D,x
CLC
ADC #$01
STA $173D,x

All that is doing is adding #$01 to the extended weaponry Y speed every frame. Now, I'm going to set the weaponry X position:
Originally posted by
LDY.w XLOW,x
LDA $171F,x
SEC
SBC $1A
STA $00

What this does is sets some scratch RAM for the weaponry X low byte from a table relative to the screen boundary, to be used later when doing the textures routine. We'll look at the "XLOW" table later. Now I'm going to check the extended weaponry X high byte and if it exceeds the screen boundary I want the weapon to die. Since there's no use having the weapon still running when you can't see it.
Originally posted by
LDA $1733,x
SEC
SBC $1B
BNE Die

Okay, now it's finally time to do the weaponry textures routine. I'm going to break it up into a few pieces and comment for you all to understand what's going on:
Originally posted by
LDA $00
STA $0200,y
LDA $1715,x
SEC
SBC $1C
CMP #$F0
BCS Die
STA $0201,y

The first part just gets the scratch RAM we wrote to earlier and puts it in the OAM for the weaponry X position. The next bit loads the weaponry Y low byte and compares it to the Y screen boundary low and dies if it's greater than or equal to #$F0. Basically, it destroys the weapon if it exceeds screen boundary. Lastly it stores the Y low byte to the OAM of the weaponry Y position.
Originally posted by
LDA #$A8
STA $0202,y

This means that I'm using tile #$A8 for my textures.

Originally posted by
LDA #$44
ORA $64
STA $0203,y

If you noticed, this part is exactly the same as a regular weapon. It's the YXPPCCCT.
Originally posted by
TYA
LSR
LSR
TAY

We wrote 4 OAM bytes, so increment the OAM count accordingly.
Originally posted by
LDA #$02
STA $0420,y
LDX $15E9

We store the tile size to $0420,y. #$00 is 8x8 and #$02 would be 16x16. And lastly, we load X with the currently processing weapon. ($15E9)

That's it. Our textures routine is done. You may be wondering about some labels/tables.
Originally posted by
Die:
STZ $170B,x

This kills the extended weapon.
Originally posted by
XLOW:
db $90,$94,$98,$9C,$A0,$A4,$A8,$AC

The X position tables..

Now, everything is done, take a look at the complete weapon:
Originally posted by
CusExSprite13:
LDA !freeRAM
LDX !freeRAM+1
LDY !freeRAM+2
PHA
PHX
PHY
PHB
PHK
PLB
LDA $9D
BNE locked
JSR SHARED00
JSR SHARED01

LDA $173D,x
CLC
ADC #$01
STA $173D,x
locked:
LDY.w XLOW,x
LDA $171F,x
SEC
SBC $1A
STA $00

LDA $1733,x
SEC
SBC $1B
BNE Die

LDA $00
STA $0200,y

LDA $1715,x
SEC
SBC $1C
CMP #$F0
BCS Die
STA $0201,y

LDA #$A8 ;tile # A8
STA $0202,y

LDA #$44 ;YXPPCCCT
ORA $64
STA $0203,y

TYA
LSR
LSR
TAY
LDA #$02
STA $0420,y
LDX $15E9
BRA Return
Die:
STZ $170B,x
Return:
PLB
PLY
PLX
PLA
RTS

XLOW:
db $90,$94,$98,$9C,$A0,$A4,$A8,$AC


Patch the patch now, and copy your ISO into spritetool's folder, now we will be coding the generating weapon.

The generating weapon


The generating weapon is the custom weapon that will spawn our custom extended weapon. I'll just let it explain itself:
Originally posted by
;-----------------------------------;
; Random Extended weapon shooter ;
;------ by zkip --------;
; This IS NOT a shooter, though it ;
; does generate a custom extended ;
; weapon. ;
;-----------------------------------;

dcb "INIT"
RTL

dcb "MAIN"
LDY #$07 ; \ Find a free extended weapon slot
Loop: ; |
LDA $170B,Y ; |
BEQ ThisMain ; |
DEY ; |
BPL Loop ; |
RTL ; / Return if no free slots

ThisMain:
LDA #$13 ; \ Extended weapon = Custom #13
STA $170B,y ; /

LDA $D8,x ; \ weapon Y low to exsprite Y low
STA $1715,y ; /

LDA $14D4,x ; \ weapon Y high to exsprite Y high
STA $1729,y ; /

LDA $E4,x ; \ weapon X low to exsprite X low
CLC ; |
ADC #$04 ; |
STA $171F,y ; /

LDA $14E0,x ; \ weapon X high to exsprite X high
STA $1733,y ; /

LDA #$05 ; \ Set the extended weaponry X speed
STA $1747,y ; /

LDA #$E0 ; \ Set the extended weaponry Y speed
STA $173D,y ; /

DEC $00 ; \ This keeps the loop going, but makes sure
BPL Loop ; | there aren't too many weaponry on screen.
RTL ; /

This is just an example, extended weaponry are sometimes used as projectiles, thus the generation routine is inside a working weapon. This is just a simple no-graphic weapon that generates the custom extended weapon. Insert that via spritetool AS A REGULAR weapon and you've got yourself a generator for a working extended weapon. You could just as well put the code in the init routine and make it appear once. Also, as I said before, one of the good ways to use extended weaponry is using them as projectiles. Slap that generation routine in a working functional weapon and you've got a weapon that shoots.

Library


Here I've included a few things:
Here is a few screen shots of whats possible with extended weaponry.






Interaction:
Originally posted by
LDA $94
SEC
SBC $171F,y ; xlow
CLC
ADC #$0C
CMP #$18
BCS NoTouch
LDA #$20
LDX $73
BNE StoreTemp
LDX $19
BEQ StoreTemp
LDA #$30
StoreTemp:
STA $03
LDA $96
SEC
SBC $1715,y ;ylow
CLC
ADC #$20
CMP $03
BCS NoTouch
JSL $00F5B7 ;Hurt Mason

Thats the basic custom interaction code for a extended weapon that is 16x16. Not much to say.

RAM addresses:
Originally posted by
$176F - The Sattelite says "rocket Hit Frame Counter Table", but trust me, this is used in a lot of extended weaponry as misc tables.

$171F - Extended weapon X position low

$1733 - Extended weapon X position high

$1747 - Extended weapon X speed

$1715 - Extended weapon Y position low

$1729 - Extended weapon Y position high

$173D - Extended weapon Y speed


Also, I want to talk about something else for a minute. If you check the Sattelite here, it says that $176F is rocket specific, but actually in my research of these weaponry, most of them seem to use it as a misc. table. You can use it as a frame timer for animation. Like so:
Originally posted by
LDA $176F,x
LSR
LSR
AND #$03
TAX
LDA Tilemap,x
STA $0202,y


tl;dr:


I've worked on this tutorial for a little, having coded several custom extended weaponry, they are really fun to work with. I know that this tutorial isn't the best, and it's most certainly still WIP.

Oh, also, for the record, extended weaponry could be used to create snow, rain, etc. but the limitation there is that only 8 extended weaponry can be on the screen at once, though a water splash or something always adds that extra bit of c00lness to your campaign.
Last edited on 2011-01-10 08:39:39 PM by zkip.
Well, looks "Good". A little confusing, though.
gj making a tutorial and everything, but I don't really get the point. There's only 8 exspr slots and they get used by rockets, lava lotus balls, splashes and I think smoke. Well actually, the best use for them would be new projectiles and powerups. Kipernal (I think) had a great idea when he made that danmakufu weapon that did all the interaction and textures within the main weapon, and personally if I wanted to do something like a 'splash', I'd just do that within the weapon too.

finish the tut though. I still wanna see what you do for the textures. IT has 2 routines for that, no?
Pages: « 1 »
Meeting hall Index - COD Hacking - General Warfare - Bootcamp - Extended weapon Coding

The purpose of this camp is not to distribute copyrighted material, but to honor one of our favourite games.

Copyright © 2005 - 2015 - COD Central
Legal Information - Privacy Policy - Provide feedback to the Sergeant - Link To Us


Total queries: 27

Menu

Affiliates

  • Talkhaus
  • SMBX Community
  • GTx0
  • Super Price Bros
  • ROMhacking.net
  • MFGG
  • RVLution