+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  Could someone explain some of this NES DTE code to me?
Pages: [1]
Author Topic: Could someone explain some of this NES DTE code to me?  (Read 2 times)
Kagemusha
Guest
« on: January 14, 2008, 10:42:23 pm »

Code:
$BDD0:8E FE 07  STX $07FE = #$07           A:9C X:00 Y:00 P:nvUbdIZc
$BDD3:C0 00     CPY #$00                   A:9C X:00 Y:00 P:nvUbdIZc
$BDD5:D0 03     BNE $BDDA                  A:9C X:00 Y:00 P:nvUbdIZC
$BDD7:8C FF 07  STY $07FF = #$00           A:9C X:00 Y:00 P:nvUbdIZC
$BDDA:AE FF 07  LDX $07FF = #$00           A:9C X:00 Y:00 P:nvUbdIZC
$BDDD:F0 08     BEQ $BDE7                  A:9C X:00 Y:00 P:nvUbdIZC
$BDE7:B1 68     LDA ($68),Y @ $9C3C = #$61 A:9C X:00 Y:00 P:nvUbdIZC
$BDE9:C8        INY                        A:61 X:00 Y:00 P:nvUbdIzC
$BDEA:C9 46     CMP #$46                   A:61 X:00 Y:01 P:nvUbdIzC
$BDEC:90 11     BCC $BDFF                  A:61 X:00 Y:01 P:nvUbdIzC
$BDEE:C9 A0     CMP #$A0                   A:61 X:00 Y:01 P:nvUbdIzC
$BDF0:B0 0D     BCS $BDFF                  A:61 X:00 Y:01 P:NvUbdIzc
$BDF2:38        SEC                        A:61 X:00 Y:01 P:NvUbdIzc
$BDF3:E9 46     SBC #$46                   A:61 X:00 Y:01 P:NvUbdIzC
$BDF5:0A        ASL                        A:1B X:00 Y:01 P:nvUbdIzC
$BDF6:AA        TAX                        A:36 X:00 Y:01 P:nvUbdIzc
$BDF7:E8        INX                        A:36 X:36 Y:01 P:nvUbdIzc
$BDF8:8E FF 07  STX $07FF = #$00           A:36 X:37 Y:01 P:nvUbdIzc
$BDFB:CA        DEX                        A:36 X:37 Y:01 P:nvUbdIzc
$BDFC:BD 03 BE  LDA $BE03,X @ $BE39 = #$12 A:36 X:36 Y:01 P:nvUbdIzc
$BDFF:AE FE 07  LDX $07FE = #$00           A:12 X:36 Y:01 P:nvUbdIzc
$BE02:60        RTS                        A:12 X:00 Y:01 P:nvUbdIZc

*Please do not explain this to me right now if anyone's up to it* I have to go through the code and break down the parts I don't understand completely. Tomorrow I'll break it down as it's getting kind of late and I'm in one of those state of minds where I don't feel like doing anything. Better make an attempt now or else I'll never do it. I've been meaning to do something like this for a few weeks now. Just been too lazy to actually do it.

Obviously I did not come up with this code and it is somewhat different from my DTE code for Goemon. I'd like to use this code for Goemon, but I need to completely understand it before I can adapt it. Also I need to make a modification to this code. I believe I need to split it up to have a main routine and some sub routines. (More on that later)
« Last Edit: January 15, 2008, 01:20:11 am by Spikeman »
KingMike
Guest
« Reply #1 on: January 15, 2008, 09:49:24 am »

You're missing the code between $BDDD and $BDE7.

It looks like $07FE is the X from whatever the previous code was doing, and $07FF is used for the DTE table offset.

Code:
$BDD0:8E FE 07  STX $07FE = #$07           A:9C X:00 Y:00 P:nvUbdIZc
;save original X
$BDD3:C0 00     CPY #$00                   A:9C X:00 Y:00 P:nvUbdIZc
$BDD5:D0 03     BNE $BDDA                  A:9C X:00 Y:00 P:nvUbdIZC
$BDD7:8C FF 07  STY $07FF = #$00           A:9C X:00 Y:00 P:nvUbdIZC
;store Y to $07FF if it's not 0.
$BDDA:AE FF 07  LDX $07FF = #$00           A:9C X:00 Y:00 P:nvUbdIZC
;load DTE table offset.
$BDDD:F0 08     BEQ $BDE7                  A:9C X:00 Y:00 P:nvUbdIZC
;skip ahead if it's 0.
$BDE7:B1 68     LDA ($68),Y @ $9C3C = #$61 A:9C X:00 Y:00 P:nvUbdIZC
;read some data (the script?) from the ROM.
$BDE9:C8        INY                        A:61 X:00 Y:00 P:nvUbdIzC
;increment Y (the script offset?)
$BDEA:C9 46     CMP #$46                   A:61 X:00 Y:01 P:nvUbdIzC
$BDEC:90 11     BCC $BDFF                  A:61 X:00 Y:01 P:nvUbdIzC
$BDEE:C9 A0     CMP #$A0                   A:61 X:00 Y:01 P:nvUbdIzC
$BDF0:B0 0D     BCS $BDFF                  A:61 X:00 Y:01 P:NvUbdIzc
;these check if the character read is within the DTE table boundaries ($46-9F)
$BDF2:38        SEC                        A:61 X:00 Y:01 P:NvUbdIzc
$BDF3:E9 46     SBC #$46                   A:61 X:00 Y:01 P:NvUbdIzC
;subtract $46 (since I guess $46 is the code for the first DTE pair) to get the index in the DTE table
$BDF5:0A        ASL                        A:1B X:00 Y:01 P:nvUbdIzC
;double, since each index is 2 bytes
$BDF6:AA        TAX                        A:36 X:00 Y:01 P:nvUbdIzc
;store the DTE table offset
$BDF7:E8        INX                        A:36 X:36 Y:01 P:nvUbdIzc
$BDF8:8E FF 07  STX $07FF = #$00           A:36 X:37 Y:01 P:nvUbdIzc
;increment to ensure at least a value of 1, and store (since it seems DTE offset of 0 is a flag to indicate no DTE)
$BDFB:CA        DEX                        A:36 X:37 Y:01 P:nvUbdIzc
;decrement the offset to cancel the last increment
$BDFC:BD 03 BE  LDA $BE03,X @ $BE39 = #$12 A:36 X:36 Y:01 P:nvUbdIzc
;read the table
$BDFF:AE FE 07  LDX $07FE = #$00           A:12 X:36 Y:01 P:nvUbdIzc
;restore X's value from before this code
$BE02:60        RTS                        A:12 X:00 Y:01 P:nvUbdIZc
Kagemusha
Guest
« Reply #2 on: January 16, 2008, 09:51:46 am »

So does the STX $07FE store X's previous value at the end of RAM? Not too sure it just seems logical to me.
« Last Edit: January 16, 2008, 10:25:14 am by Pennywise »
KingMike
Guest
« Reply #3 on: January 16, 2008, 12:42:05 pm »

The NES system RAM is $0000-07FF. So,  yes, it is the end of RAM.
(though it can be accessed using mirrors at $0800, $1000, and $1800, but I've never seen it done.)

If present, in-cart RAM can be accessed from $6000-7FFF.
Kagemusha
Guest
« Reply #4 on: January 17, 2008, 02:07:43 pm »

I've been tinkering around with the code and I've broken the game once again. This game uses more than one spot in RAM to read the scripts(B1 66) and instead of writing another DTE routine for it I thought maybe I could create a main routine and then a few subroutines. Would anyone want to take a look at it? I'm sure I'm doing a no-no that's pretty simple.

http://www.mediafire.com/?6z02hcbvjxb

There's two JSR's at $1403B, $14CD6. The DTE table is located at $17E13 and the code is immediately before it. For the stuff  I was trying out the modifications are a little ways down (Two small chunks of code surrounded by FF's).
tomaitheous
Guest
« Reply #5 on: January 17, 2008, 07:15:12 pm »


Ok, so you're trying to add DTE code to a game that did not originally support it, right? If you PM me some details, I can take a look at it.
Kagemusha
Guest
« Reply #6 on: March 27, 2008, 01:15:51 pm »

Well, I've got a few threads already made. Might as well make the best use of them.

Anyways, I'm in the process of improving my DTE code for Ganbare Goemon 2 and the first step I've decided to do is make a few corrections. Mainly, the free RAM byte I've been using isn't that safe as it's probably game RAM (or something like that) and that the safest free RAM byte is usually at the end of RAM. Mostly a matter of changing a few opcodes around which I've done, but for some reason the game's slightly broken now. I believe it actually loads the DTE values, but after that the string never ends. It just keeps on going and going. So, would someone be willing to take a quick look at it? I'm sure it's nothing major, probably a dumb mistake or something.

The routine's at FF88-FFC4 in RAM or 1FF98-1FFD4. The intro text starts at 17CF2

http://www.mediafire.com/?gmxw3jmxzdy
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC