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

0 users currently in ROM Hacking | 1 guest

Main - ROM Hacking - 6502 ASM Questions... [Please?] New thread | New reply


MapleMario
Posted on 02-17-10 02:59 AM (rev. 4 of 02-21-10 12:04 AM) Link | Quote | ID: 127148


Red Koopa
Level: 27

Posts: 17/126
EXP: 111383
Next: 4776

Since: 04-28-07
From: USA

Last post: 5063 days
Last view: 3882 days
I tried compiling my ASM file with asm6, and it gave me errors on the labels. In addition I tried compiling some of the snippets posted earlier and again it gave me errors. Ca65 worked fine for me but it outputted a ".o" file and I don't know how to inject that into NES ROM.

Also, just out of curiosity... how would I draw, say, a fire flower (or really any sprite) to a certain position on the game screen? I haven't seen this kind of thing covered in any tutorial and I can't begin to think of how to do it.

So I just learned how to inject ASM code into freespace and call it earlier today, and I'm wondering a couple of things.

First, how do you do conditionals? Would the easiest/most efficient way for, say, checking if the accumulator is less than a certain RAM value be to use a CMP/CPX/CPY or a BEQ/BNE/something of that sort? In addition, for either of these, how would I run certain code if the condition evaluates to be true, and certain other code if it doesn't?

Also, can someone tell me how to do ROM expansion? I'm not very good at finding freespace XD.

I haven't had much experience with low-level programming languages so be gentle with me please.


____________________


SGMB3 is now being developed with Reuben. Hopefully v1.0 will be released by the time I get world 1 done...

- Layout: MM v0.31




boingboingsplat
Posted on 02-17-10 04:18 AM Link | Quote | ID: 127150


Giant Koopa
[PREFSTRING:wonderful bounciness]
Level: 74

Posts: 1214/1292
EXP: 3632013
Next: 21531

Since: 07-23-07
From: Michicola

Last post: 4836 days
Last view: 4799 days
Conditions? The easiest way to do it is to load the RAM address you want to check into the accumulator and then CMP it and then branch.

Like, say $06 contained, say player coins.

To check if it they have 16 (decimal) coins, and then continue the code if they do, you'd do this:

LDA $06   ;Load $06 into accumulator
CMP #$10 ;\ If it is equal to 16...
BEQ Label ;/ ...go to Label
RTS ;If not, return
Label:
(Put the rest of your code here)

(There may be some discrepancies because I'm more familiar with 65c816, but that should be fine in 6502 too.)

As far as NES rom expansions goes, I've looked into it before, and it has to do a lot with the mapper your rom is using. From what I understand it may be that you will have to change mappers, or something to that effect, in order to expand the rom. I wish that I could help more but I didn't get that far into it, since I don't think the game I was working with could be expanded further.

____________________
 

smkdan
Posted on 02-17-10 04:36 AM Link | Quote | ID: 127152


Ninji
Level: 36

Posts: 225/238
EXP: 288515
Next: 19595

Since: 05-26-07

Last post: 4057 days
Last view: 4006 days
CMP sets carry flag if content of A is larger or equal to the value used in the CMP. It will not branch, it will simply fall through to the instruction if carry flag ends up being set. BCC just branches if carry flag is clear. BCS being the opposite. BEQ/BNE is the same for zero flag and there's more for negative/overflow. It's important to know that much about how they actually work to get the full use out of them.

Another way to do conditional stuff (can be faster in some places) is to follow up an increment/decrement with BEQ or BNE. INX/INY/DEX/DEY set the zero flag based on the result in X or Y. If I wanted to do a loop using this...

LDA #$00 ;value to store
LDX #$40 ;do this $40 times
loop:
STA $2007
DEX
BNE loop
;after 64 times it will break out of loop


bit more obscure: this tests the number of '1' bits in a RAM address:

LDX #$08 ;loop count
LDY #$00 ;bit count
LDA $0200 ;value from ram to rest
loop:
LSR A ;LSR shifts content of A right one position and loads carry flag with bit0
BCC clear ;branch if carry flag clear, or bit0 was clear
INY ;bit0 was set, incrementing bit count
clear:
DEX ;loop 8 times for all 8 bits
BNE loop


DEX sets zero flag based on what result was after decrementing X. Until it hits zero, it will keep branching back to loop so STA $2007 is run 64 times. The branches just act based on what flags in status register are at the time and instructions like INX/CMP/ADC etc. modify them. The other example uses the fact that LSR puts bit0 into carry flag so it can then be used by BCC to determine if bit0 was set or not.

---

For rom expansion I'm guessing this is the NES? You have to take a look at what mapper the game uses (if it uses one that is, a 32KB program ROM on a mapperless game demands you hack in a mapper before increasing amount of PRG ROM). nesdevwiki is a decent reference for popular ones. If the games uses CHR ROM then the PRG ROM is sandwiched between the iNES header and CHR. If the mapper allows for expansion based on the current ROM isze, you can insert however many banks of data for your own use. But then you have to hack the game to actually take advantage of the free space, you must insert a hack to switch to the free bank (how you do this depends on the mapper of your game) since the NES only sees 32KB or sometimes 40KB of ROM at any given time. On the SNES it's not really an issue since you have direct access normally to 4MB of ROM without bank switching. On the NES you have to switch manually for almost every game.

MapleMario
Posted on 02-17-10 09:19 PM Link | Quote | ID: 127206


Red Koopa
Level: 27

Posts: 18/126
EXP: 111383
Next: 4776

Since: 04-28-07
From: USA

Last post: 5063 days
Last view: 3882 days
About the ROM expansion, I'm hacking SMB3. I think it uses PRG but I'm not sure.

About the ASM, I think I understand what you're saying about BEQ/BNE/BCC/BCS, but I'd like to ask one thing: When you declare a label, how do you compile that into bytecode? For example, if you could just take your first example there and compile that for me, I think it'd be easier.
Or can I just use a subroutine there? Can I say BEQ $DCD0 in the same way that I use JSR $DCD0?

____________________


SGMB3 is now being developed with Reuben. Hopefully v1.0 will be released by the time I get world 1 done...

- Layout: MM v0.31




Kawa
Posted on 02-17-10 09:52 PM Link | Quote | ID: 127210


CHIKKN NI A BAAZZKIT!!!
80's Cheerilee is best pony
Level: 138

Posts: 3276/5344
EXP: 30930698
Next: 732283

Since: 02-20-07
From: The Netherlands

Last post: 4492 days
Last view: 2627 days
Posted by MapleMario
I think it uses PRG but I'm not sure.
Isn't that a bit of a given? I think you meant to say it uses the MMC3 mapper

____________________
Wife make lunch - Shampoo
Opera - give it a spin
Spare some of your free time?
<GreyMaria> I walked around the Lake so many goddamn times that my sex drive was brutally murdered
Kawa rocks — byuu

never-obsolete
Posted on 02-17-10 10:47 PM (rev. 3 of 02-17-10 10:50 PM) Link | Quote | ID: 127217


Rat
Level: 24

Posts: 61/96
EXP: 74461
Next: 3664

Since: 02-22-07
From: Phoenix, AZ

Last post: 2590 days
Last view: 2590 days


Or can I just use a subroutine there? Can I say BEQ $DCD0 in the same way that I use JSR $DCD0?



The operand for branches is an 8bit signed displacement, so as long as the destination is within range, you can. Keep in mind that a return address will not be pushed onto the stack.

MapleMario
Posted on 02-17-10 11:15 PM Link | Quote | ID: 127223


Red Koopa
Level: 27

Posts: 21/126
EXP: 111383
Next: 4776

Since: 04-28-07
From: USA

Last post: 5063 days
Last view: 3882 days
Posted by Kawa
Isn't that a bit of a given? I think you meant to say it uses the MMC3 mapper

Lol, yeah, that's what I meant.

Posted by never-obsolete
The operand for branches is an 8bit signed displacement, so as long as the destination is within range, you can. Keep in mind that a return address will not be pushed onto the stack.

That'd be fine. Thanks.

So I'm assuming that for CMP, using something like the following:

LDX $DCD0 ; assuming DCD0 is the address I want to load from
CPX #$10
JSR $3F0C ; the subroutine to be executed if X >= 16
JSR $3FBD ; the subroutine to be executed if X < 16


Would that work the way I intend it to?

____________________


SGMB3 is now being developed with Reuben. Hopefully v1.0 will be released by the time I get world 1 done...

- Layout: MM v0.31




never-obsolete
Posted on 02-17-10 11:36 PM (rev. 3 of 02-17-10 11:41 PM) Link | Quote | ID: 127224


Rat
Level: 24

Posts: 62/96
EXP: 74461
Next: 3664

Since: 02-22-07
From: Phoenix, AZ

Last post: 2590 days
Last view: 2590 days
You need to put a branch and destination. A JMP is needed if you don't want the second function called.


LDX $DCD0
CPX #$10
BCC _isLess
_isMore: JSR $3F0C
JMP _exit
_isLess: JSR $3FBD
_exit:



Here's an explanation on how the compares work. There's a table in the middle that shows which branch to use for each equality test.

MapleMario
Posted on 02-17-10 11:54 PM (rev. 3 of 02-17-10 11:56 PM) Link | Quote | ID: 127226


Red Koopa
Level: 27

Posts: 22/126
EXP: 111383
Next: 4776

Since: 04-28-07
From: USA

Last post: 5063 days
Last view: 3882 days
Posted by never-obsolete
You need to put a branch and destination. A JMP is needed if you don't want the second function called.


LDX $DCD0
CPX #$10
BCC _isLess
_isMore: JSR $3F0C
JMP _exit
_isLess: JSR $3FBD
_exit:



Here's an explanation on how the compares work. There's a table in the middle that shows which branch to use for each equality test.



Thanks, but I still don't understand how you could compile _isMore and _isLess and _exit into bytecode insertable into the SMB3 ROM.

EDIT: Wait, sorry, I didn't see your link when I posted. Let me go check that out.

EDIT2: Yeah, I still can't see how you would compile those names into bytecode.

____________________


SGMB3 is now being developed with Reuben. Hopefully v1.0 will be released by the time I get world 1 done...

- Layout: MM v0.31




boingboingsplat
Posted on 02-18-10 03:20 AM Link | Quote | ID: 127232


Giant Koopa
[PREFSTRING:wonderful bounciness]
Level: 74

Posts: 1216/1292
EXP: 3632013
Next: 21531

Since: 07-23-07
From: Michicola

Last post: 4836 days
Last view: 4799 days
Your assembler will (well, should) do the labels automatically, provided they aren't out of range. (Which would be 128 bytes in either direction.) I don't know any specific 6502 assemblers, though.

____________________
 

smkdan
Posted on 02-18-10 05:46 AM Link | Quote | ID: 127242


Ninji
Level: 36

Posts: 226/238
EXP: 288515
Next: 19595

Since: 05-26-07

Last post: 4057 days
Last view: 4006 days
http://www.romhacking.net/utils/674/

Is easy to use and has decent feature set. I used ca65 before for NES stuff but it requires some setting up to get it up and running, but it's very powerful. Not the best one to use for starting out for sure.

Labels, includes and whole bunch of other stuff (depends on feature set) are specific to the assembler so try out asm6.

MapleMario
Posted on 02-18-10 11:43 PM (rev. 2 of 02-20-10 08:43 PM) Link | Quote | ID: 127291


Red Koopa
Level: 27

Posts: 23/126
EXP: 111383
Next: 4776

Since: 04-28-07
From: USA

Last post: 5063 days
Last view: 3882 days
Posted by smkdan
http://www.romhacking.net/utils/674/

Is easy to use and has decent feature set. I used ca65 before for NES stuff but it requires some setting up to get it up and running, but it's very powerful. Not the best one to use for starting out for sure.

Labels, includes and whole bunch of other stuff (depends on feature set) are specific to the assembler so try out asm6.

Thanks, that looks about perfect.

I tried compiling my ASM file, and it gave me errors on the labels. In addition I tried compiling some of the snippets posted earlier and again it gave me errors. Ca65 worked fine for me but it outputted a ".o" file and I don't know how to inject that into NES ROM.

____________________


SGMB3 is now being developed with Reuben. Hopefully v1.0 will be released by the time I get world 1 done...

- Layout: MM v0.31




Main - ROM Hacking - 6502 ASM Questions... [Please?] New thread | New reply

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

Page rendered in 0.026 seconds. (341KB of memory used)
MySQL - queries: 87, rows: 118/119, time: 0.017 seconds.