News:

RIP GoReds

Main Menu

PHP RBI Stat extractor (and an editor question)

Started by Turd, 04/20/09, 01:40:18 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BeefMaster

Quote from: tecmoturd on 04/23/09, 11:57:20 AM
I was just about to say, what if you subbed in the second SP...but you're right, that violates our league rules.

Just for educational purposes, wouldn't that situation look like:

FF 09 00 00

Yep... the only time that you couldn't determine the SP is if both starters pitched, and they were both subbed out - in that case, they're both hosed.

If you're into assembly hackage, the way to track that might be to set a counter for each team that decrements every time a player is subbed - instead of replacing their lineup position with 0xFF, you replace it with the counter (1st sub - 0xFF, 2nd sub - 0xFE, etc.).
"Nobody in football should be called a genius. A genius is a guy like Norman Einstein." - Joe Theismann

Turd

That'd be a great beginner project once I learn 6502...

nightwulf

That's a good idea, and I'd take it one step further. Start a counter at 0xFF, and decrement it every time an out is recorded. Then not only would you know the substitution order, but you could also pinpoint when substitutions are made and determine how many innings each pitcher went.

Of course you'd have a problem if the game went over 41 innings ...

nightwulf

#43
Here's the culprit:

$AEEE> A9 FF:   LDA #$FF     ;
$AEF0> 99 4006: STA $0640,Y  ;


Found in page 5 of the disassembly. Now to find space to change that ...

Even better. Same page, incrementing the error counter ...

$AB9B> EE 1E01: INC $011E    ;

I'm making an executive decision and defining 0x07F0 as our out counter, since I can't find it being used anywhere else. We're also fortunate in that page 4 has unused space at the end and is loaded at 0x8000 in both instances above. Make the following changes:

- Change incrementing the error counter to include decrementing our out counter:
page 4:
$9F9B> EE 1E01:   INC $011E;
$9F9E> CE F007:   DEC $07F0;
$9FA1> 4C 9EAB:   JMP $AB9E;

page 5:
$AB9B> 4C 9B9F:   JMP $9F9B;


- Change the byte written on a player substitution from #0xFF to the value at 0x07F0:
page 4:
$9FA4> A8:   TAY;
$9FA5> AD F007:   LDA $07F0;
$9FA8> 4C F0AE:   JMP $AEF0;

page 5:
$AEED> 4C A49F: JMP $9FA4;


Next we need to find a way to initialize 0x07F0 with #0xFF ...

Fantastic. 0xFD66 is the location of the subroutine that plays the "start game" music. Good time to initialize data. It's called from:

$A8E8> 20 66FD: JSR $FD66    ;

Which is, once again, in page 5. And page 4 is still loaded at 0x8000. Booyah.

page 4:
$9FAB> A9 FF:   LDA #$FF;
$9FAD> 8D F007:   STA $07F0;
$9FB0> 20 66FD:   JSR $FD66;
$9FB3> 4C EBA8:   JMP $A8EB;

page 5:
$A8E8> 4C AB9F:   JMP $9FAB;


Last thing to do is make sure the check for usable players won't puke at this ...

Problem.

$A482> A9 FE:   LDA #$FE     ;
$A484> A0 02:   LDY #$02     ;
$A486> 91 36:   STA ($36),Y  ;
$A488> C8:      INY          ;
$A489> BD 4006: LDA $0640,X  ;
$A48C> D0 06:   BNE $A494    ;


The accumulator is loaded to #0xFE then directly compared to the team lineup data discussed above, checking for a not equal condition. That needs to be changed. I just wrote out a bunch of shit and now I don't think it's right. I'll come back to this after work tomorrow.

Turd

HAHA! Awesome...much more rubust than my "If x68D == xFF" { $starter = 'SP1' }

nightwulf

Apparently too much of this shit at once makes me stop thinking clearly. The lines above ...

$A489> BD 4006: LDA $0640,X  ;
$A48C> D0 06:   BNE $A494    ;


... load that pitcher's data from the lineup. If the current value is 0, that pitcher is available. If it's non-zero, the pitcher is not available. So, the changes made don't affect the game engine at all with regards to determining which pitchers are available.

Next up is actually patching all of this into a ROM to see if it works ...

Turd

Just finished (or almost finished my 2009 league rom). Perfect timing for you to come up with this, as I know the league will enjoy it...

If it's all ready, I'll be glad to throw it on my rom and give it a whirl...

nightwulf

#47
Minor problems. The increment statement at 0xAB9B only runs when an out is recorded due to a strike out. Any out in the field is incremented from 0xD78E. Simple fix ... just have to add a routine there.

Other problem is that the game crashes any time the computer "randomly" picks a pitcher while the game is in play. Since this doesn't affect 2-player play it's a low priority to fix, but I don't like putting out anything that doesn't work properly.

Problem found. The game jumps to 0xAEEE after "random" pitcher selection, which is right in the middle of our patched code, causing the crash. Moving ...

Everything works, but when a pitcher is brought in via pinch-hitting in the ninth spot, the pitcher's "out count" is overwritten. Fixing ...

nightwulf

I think everything works. Did a bunch of reordering ...


- decrement counter on out, from strikeout
$9F93> EE 1E01:   INC $011E;
$9F96> CE F007:   DEC $07F0;
$9F99> 4C 9EAB:   JMP $AB9E;

$AB9B> 4C 939F:   JMP $9F93;

- decrement counter on out, from field
$9F9C> EE 1E01:   INC $011E;
$9F9F> CE F007:   DEC $07F0;
$9FA2> 4C 91D7:   JMP $D791;

$D78E> 4C 9C9F: JMP $9F9C;

- replace lineup data with out decrementer (pitcher sub)
$9FA5> AD F007: LDA $07F0;
$9FA8> 99 4006: STA $0640,Y;
$9FAB> 4C F3AE: JMP $AEF3;

$AEF0> 4C A59F: JMP $9FA5;

- replace lineup data with out decrementer (pinch hitter in ninth spot)
$9FAE> AD F007: LDA $07F0;
$9FB1> 99 4006: STA $0640,Y;
$9FB4> 4C A3AE: JMP $AEA3;

$AEA0> 4C AE9F: JMP $9FAE;

- initialize counter on game start
$9FB7> A9 FF:   LDA #$FF;
$9FB9> 8D F007:   STA $07F0;
$9FBC> 20 66FD:   JSR $FD66;
$9FBF> 4C EBA8:   JMP $A8EB;

$A8E8> 4C B79F: JMP $9FB7;


This can be patched into any 96k ROM by anyone handy with a hex editor, at the following ROM (not RAM) offsets ...

0x9FA3> EE 1E 01 CE F0 07 4C 9E AB
0x9FAC> EE 1E 01 CE F0 07 4C 91 D7
0x9FB5> AD F0 07 99 40 06 4C F3 AE
0x9FBE> AD F0 07 99 40 06 4C A3 AE
0x9FC7> A9 FF 8D F0 07 20 66 FD 4C EB A8

0xA8F8> 4C B7 9F

0xABAB> 4C 93 9F

0xAEB0> 4C AE 9F

0xAF00> 4C A5 9F

0xD79E> 4C 9C 9F


A sample ROM is attached.

Turd

Perfect, I'll try it out tonight...I'll update the stat extractor too and post an alternate version...

Turd

Tried this out...

Inning 1, my lineup went:

SP2, SP1, RP, Closer. The save state file gave me this:

x678 - 01 02 03 04 05 06 07 08 00 00 00 00 FD FD FD 09

Is the expected?  This tells me that the SP1, SP2, and RP were all subbed out, and the game ended with the closer...

I would have thought each spot would contain the value at which they were subbed, so in the aforementioned situation, the pitchers would contain:

... FE FF FD 09

Perhaps I'm misunderstanding...

nightwulf

Quote from: nightwulf on 04/23/09, 11:00:06 PM
That's a good idea, and I'd take it one step further. Start a counter at 0xFF, and decrement it every time an out is recorded. Then not only would you know the substitution order, but you could also pinpoint when substitutions are made and determine how many innings each pitcher went.

Of course you'd have a problem if the game went over 41 innings ...

I'm guessing you subbed them with the same number of outs.

Turd

I did...does the counter only decrement after an out? I didn't catch that part...

Quote...decrement it every time an out is recorded.

I just read that now.  Jesus, my bad.  I was thinking it'd decrement when the player is subbed, not when an out occurred...

Turd

Started working on the editor, got the meat of it done so players can be edited and the 2 player pause hack can be applied. I did everything in php reading data from a spreadsheet first so I had the locations and layout working, and when it's done I'll port it over to a c# application. Been fun so far, lots of work left to do.

Gantry

Awesome, keep up informed of the updates and I'm sure you'll have plenty of beta testers on here if need be. 

Turd

#55
Will do. I think I'm gonna make it text bases like TSB Tool is for easy manipulation and moving between csv and excel and all that. Only thing I don't know if I can duplicate from wulfs editor is the auto generation of the two-letter team abbreviations. I still don't understand how that all works, as for graphics I usually just did that stuff by hand.  It'd be nice not to have to.  That'll just have to be something I try and figure out at the end.

Other than that I'll shoot for most of the features he provides.