Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* From NES Castlevania II - Simon's Quest ROM hacking project */
- /* Copyright (C) Joel Yliluoma - http://iki.fi/bisqwit/cv2fin/ */
- function ChangeDialogBoxShape()
- {
- global $linker, $space, $PAL, $settings;
- $timer_oneliner = true;
- $decreased_margin = 1;
- $added_lines = 2; // How many lines were added into the shopping text?
- $added_width = 0;
- $tight_lines = true;
- $plans = Array(
- 'status' => $settings['SUPPORT_MULTICLUE']
- ? ($timer_oneliner
- ? 'top/time0/0/LBL1/heart/mid/0/mid/0/0/mid/0/0/0/0/mid/LBL2/bot'
- : 'top/LBL0/time/LBL1/heart/mid/0/mid/0/0/mid/0/0/0/0/mid/LBL2/bot')
- : 'top/LBL0/time/0/LBL1/0/heart/mid/0/mid/0/0/mid/0/0/0/0/bot',
- 'shop' => 'top1/1/1/1/1/1/1/1/cost/1/1/yes/no/bot1',
- 'dfl' => 'top1/1/1/1/1/1/1/1/1/1/1/bot1'
- );
- $graphs = LoadTextConfig($settings['DIALOGBOX_FILE']);
- $allowed_banks = Array(0x1C000);
- if($settings['MOVE_DIALOGBOX_TO_BANK3'])
- {
- $allowed_banks = Array(0xC000);
- }
- foreach($plans as $planname => $plan)
- {
- $b = new Blob("DialogBoxTable_$planname");
- foreach(explode('/', $plan) as $piecename)
- $b->AppendPointerto("DialogBoxGraph_$piecename");
- $linker->AddBlob($b, $allowed_banks); // Put somewhere in this page.
- }
- foreach($graphs as $piecename => $graph)
- {
- $b = new Blob("DialogBoxGraph_$piecename",
- EncodeGfxRender(EncodeDialog($graph,false)));
- $linker->AddBlob($b, $allowed_banks); // Put somewhere in this page.
- }
- $b = new Blob("DialogBoxTable_LengthsMinus1");
- for($round=0; $round<2; ++$round)
- foreach(explode('/', 'status/dfl/shop/dfl/dfl/dfl/dfl/dfl') as $planname)
- {
- $length = count(explode('/', $plans[$planname]));
- if($round == 0) $b->AppendRawData(chr($length - 1));
- else $b->AppendPointerTo("DialogBoxTable_$planname");
- }
- $b->AddPublicAt("DialogBoxTable", $b->GetSize() / 3);
- $b->AddPublicAt("DialogBoxTableHi", $b->GetSize() / 3 + 1);
- #$p = 0;
- #if($PAL) $p -= 77;
- $location = $PAL ? 0x1F5E4 : 0x1F631;
- if($settings['MOVE_DIALOGBOX_TO_BANK3'])
- {
- $linker->AddBlob($b, $allowed_banks);
- $space[$location] = 0x1F708-0x1F631; // Relieve the space that used to store this data.
- $b = new Blob("DialogBox_ReferToLengthTable");
- $b->AppendPointerTo("DialogBoxTable_LengthsMinus1");
- $linker->AddBlob($b, $PAL ? 0x1EFDB-77 : 0x1EFDB, true);
- $b = new Blob("DialogBox_ReferToDialogBoxTable");
- $b->AppendPointerTo("DialogBoxTable");
- $linker->AddBlob($b, $PAL ? 0x1F585-77 : 0x1F585, true);
- $b = new Blob("DialogBox_ReferToDialogBoxTableHi");
- $b->AppendPointerTo("DialogBoxTableHi");
- $linker->AddBlob($b, $PAL ? 0x1F58A-77 : 0x1F58A, true);
- // Jumped to from 1D349
- $b = new Blob("Jump_To_ItemMenuPauseScreen_Run",
- // jsr $D4E6 -- which has code that does lda #3,jsr SwitchBank_NewPage,rts
- // Jmp ItemMenuPauseScreen_Run
- $PAL ? "\x20\x99\xD4\x4C\x06\xEF"
- : "\x20\xE6\xD4\x4C\x53\xEF"
- );
- $linker->AddBlob($b, 0x1C000);
- $b = new Blob("Jump_To_ItemMenuPauseScreen_Run2");
- $b->AppendJumpPointerTo("Jump_To_ItemMenuPauseScreen_Run");
- $linker->AddBlob($b, $PAL ? 0x1D349-77 : 0x1D349, true);
- }
- else
- {
- $linker->AddBlob($b, $location, true); // Fixed location for these pointers + length table
- $space[$location+8*3] = 0x1F708-0x1F649; // Relieve the space that used to store this data.
- }
- $b = new Blob("MerchantDealLine", chr(6+$added_lines)); // Set Y coordinate for deal listing
- $linker->AddBlob($b, $PAL?0x1EC7E:0x1ECCB, true);
- $b = new Blob("MerchantDealItemX", chr(2)); // Set x coordinate for item symbol
- $linker->AddBlob($b, $PAL?0x1EC8C:0x1ECD9, true);
- $b = new Blob("MerchantDealCostX", chr(7)); // Set x coordinate for heart count
- $linker->AddBlob($b, $PAL?0x1ECA1:0x1ECEE, true);
- $b = new Blob("MerchantCursorPatch1", chr(8+$added_lines)); // Set Y coordinate for merchant cursor moving
- $linker->AddBlob($b, $PAL?0x1ED0F:0x1ED5C, true);
- $b = new Blob("MerchantCursorPatch2", chr(8+$added_lines)); // Set Y coordinate for merchant cursor blinking
- $linker->AddBlob($b, $PAL?0x1EDE5:0x1EE32, true);
- $b = new Blob("MerchantCursorPatch3", chr(2-$decreased_margin)); // Set Y coordinate for first text line
- $linker->AddBlob($b, $PAL?0x1EE08:0x1EE55, true);
- $b = new Blob("StatusBoxLengthPatch1", chr( count(explode('/', $plans['status'])) ));
- $linker->AddBlob($b, $PAL?0x1EF81:0x1EFCE, true);
- $b = new Blob("StatusBoxLengthPatch2", chr( count(explode('/', $plans['status'])) ));
- $linker->AddBlob($b, $PAL?0x1F3A3:0x1F3F0, true);
- // Repositioning the merchant cursor horizontally:
- $b = new Blob("MerchantCursorXpatch4", chr(0x17).chr(0x03));
- $linker->AddBlob($b, $PAL ? 0x1EDC3 : 0x1EE10, true);
- // A wider dialog box requires wider attribute patch.
- #$b = new Blob("test", chr(8 + ($added_width/2)));
- #$linker->AddBlob($b, 0x1F715, true);
- if($added_width > 0)
- {
- $b = new Blob("AssignDialogAttributeWidth", "\xEA");
- $b->AppendCallPointerTo("DetermineDialogAttributeWidth");
- $linker->AddBlob($b, $PAL ? 0x1F6C7 : 0x1F714, true);
- /* ldy #8
- * lda DialogText_Saved_CharacterIndex ($7E)
- * beq +
- * ldy #8 + $added_width
- * sty $17 (from 1F716)
- * + rts
- */
- $b = new Blob("DetermineDialogAttributeWidth",
- "\xA0\x08".
- "\xA5\x7E".
- "\xF0\x02".
- "\xA0".chr(8 + ($added_width/2)).
- "\x84\x17".
- "\x60"
- );
- $linker->AddBlob($b, 0x1C000); // anywhere in common bank
- }
- // The following patch causes visual artifacts during dialog rendering,
- // but it allows for larger boxes.
- if($added_width > 0)
- {
- $b = new Blob("ConditionalRemoveDialogBoxLineParityForce", "\xEA");
- $b->AppendCallPointerTo("TestIfDialogBoxIsFast");
- $linker->AddBlob($b, $PAL ? 0x1F44B : 0x1F607, true);
- /*
- lda DialogText_Saved_CharacterIndex ($7E)
- bne +
- ; reached only if $7E=0.
- lda DialogText_Saved_ID ($79)
- and #$01
- rts
- + lda #0 ;return Z
- rts
- */
- $b = new Blob("TestIfDialogBoxIsFast", // nonzero (NE) = render another immediately
- "\xA5\x7E".
- "\xD0\x05".
- "\xA5\x79".
- "\x29\x01".
- "\x60".
- "\xA9\x00\x60" // lda #0; rts
- );
- $linker->AddBlob($b, 0x1C000); // anywhere in common bank
- }
- /* The following patch ensures that if the dialog box includes
- the character [48], or [1C], it is rendered at maximum speed
- and not beeped over.
- Additionally, some punctuation is made to pause slightly longer.
- It also enables dialog text table being 256 elements long
- rather than just 128.
- dialog_fast.s also includes code for turbo-rendering text
- when A button is held.
- */
- $location = $PAL ? 0x1EE57 : 0x1EEA4;
- $asm_name = sprintf('dialog_fast_%s.bin',
- $PAL?'pal':'ntsc');
- $b = LoadAsmBlob("DialogAction_RenderMessage_WithDelayCheck", $asm_name);
- $linker->AddBlob($b, 0xC000); // anywhere in bank 3
- $space[$location] = (0xEF0A-0xEEA4); // Relieve the code that was replaced
- // Patch up references to this code
- foreach(Array(0x1EBBC,0x1EBD1,0x1EBE6,0x1EC18,0x1EC49,0x1EC62) as $location)
- {
- $b = new Blob(sprintf("Refer_DialogAction_RenderMessage_%X", $location), "");
- $b->AppendPointerTo("DialogAction_RenderMessage_WithDelayCheck");
- $linker->AddBlob($b, $location + ($PAL?-77:0), true);
- }
- /*
- Delete Rosary rendering from whip-line:
- F194 lda #$0E
- jsr $F1BD ; move forward
- lda $92 ; items1
- and #$01
- beq + (+8)
- jsr $E394 ; put3bytes
- lda #$5C
- jsr $EB9C ;putAandFF
- + rts;jmp $F0FC ;godowntwolines
- Free until F1BD
- */
- $location = $PAL?0x1F147:0x1F194;
- $space[$location] = 0xF1BD-0xF194;
- $b = new Blob("StatusBox_MoveRosary_Part1",
- "\xA9\x0E".
- ($PAL?"\x20\x70\xF1":"\x20\xBD\xF1").
- "\xA5\x92\x29\x01\xF0\x08".
- ($PAL?"\x20\x47\xE3":"\x20\x94\xE3").
- "\xA9\x5C".
- ($PAL?"\x4C\x4F\xEB":"\x4C\x9C\xEB").
- "\x60");
- $linker->AddBlob($b, $location, true);
- $linker->RemoveSpace($space, $location, $b->GetSize());
- /*
- Add Rosary rendering to the bodyparts line:
- F030 jmp RosaryRender
- RosaryRender:
- lda $92
- and #$02
- beq +
- jsr $E394
- lda #$5A
- jsr $EB9C
- + rts;jmp $F0FC
- */
- $b = new Blob("StatusBox_MoveRosary_Part2");
- $b->AppendJumpPointerTo("RosaryRender");
- $linker->AddBlob($b, $PAL?0x1EFE3:0x1F030, true);
- $b = new Blob("RosaryRender",
- "\xA9\x02".
- ($PAL?"\x20\x70\xF1":"\x20\xBD\xF1").
- "\xA5\x92\x29\x02\xF0\x08".
- ($PAL?"\x20\x47\xE3":"\x20\x94\xE3").
- "\xA9\x5A".
- ($PAL?"\x4C\x4F\xEB":"\x4C\x9C\xEB").
- "\x60");
- $linker->AddBlob($b, 0xC000); // anywhere in page 3
- /* Enable Rosary selection:
- *
- * F289 jmp EnableRosarySelection
- * EnableRosarySelection:
- * sta $93
- * lda $92
- * and #$02
- * beq +
- * lda #$40
- * ora $93
- * sta $93
- * + lda $93
- * jmp $1F2D2
- */
- $b = new Blob("StatusBox_EnableRosarySelect");
- $b->AppendJumpPointerTo("RosarySelectEnabler");
- $linker->AddBlob($b, $PAL?0x1F23C:0x1F289, true);
- $b = new Blob("RosarySelectEnabler",
- "\x85\x93\xA5\x92\x29\x02\xF0\x06".
- "\xA9\x40\x05\x93\x85\x93\xA5\x93".
- ($PAL?"\x4C\x85\xF2":"\x4C\xD2\xF2"));
- $linker->AddBlob($b, 0xC000); // anywhere in page 3
- // Rosary is now a new selectable item in the bodyparts line, so change some limits.
- $b = new Blob("BodyPartMin", "\x07");
- $linker->AddBlob($b, $PAL?0x1F21F:0x1F26C, true);
- $b = new Blob("BodyPartMax", "\x08");
- $linker->AddBlob($b, $PAL?0x1F278:0x1F2C5, true);
- // Rewrite GoDownTwoLines so that we can extract "GoDownOneLine" from it
- $b = new Blob("DialogBox_GoDownTwoLines", "\xE6\x77\xE6\x79" . "\xE6\x77\xE6\x79" . "\x60");
- $b->AddPublicAt("DialogBox_GoDownOneLine", 4);
- $linker->AddBlob($b, 0x1F0FC-($PAL?77:0), true);
- // Utility function for going just one line down.
- $b = new Blob("DialogBox_Go1Down_And_Recalculate");
- $b->AppendCallPointerTo("DialogBox_GoDownOneLine");
- $b->AppendRawData(($PAL ? "\x20\x1C\xEE" : "\x20\x69\xEE")."\xA5\x5E\x29\x20\x85\x16\x60");
- $b->AddPublicAt("Odd_5E16flip", $b->GetSize()-7);
- $linker->AddBlob($b, 0x1C000); // anywhere in common page
- // Declare the locations of these functions, so we can nicely call them by name.
- $linker->AddBlob(new Blob("DialogBox_RenderTwoDigitNumber"), $PAL ? 0x1F17F : 0x1F1CC, true);
- $linker->AddBlob(new Blob("DialogBox_GoForwardHorizontally"), $PAL ? 0x1F170 : 0x1F1BD, true);
- // Original layout of status screen numeric elements.
- $renderers = Array
- (
- //name Yoffs Xoffset Variable=>Xincrement
- 'time' => Array(2, 6, Array(0x83=>0, 0x86=>3, 0x85=>3)),
- 'exp' => Array(4, 4, Array(0x47=>0, 0x46=>2)),
- 'level' => Array(4, 12,Array(0x8B=>0)),
- 'hearts' => Array(6, 4, Array(0x49=>0, 0x48=>2)),
- 'whip' => Array(8, 2, Array( 0xF163 - ($PAL?77:0) => 0) ),
- 'body' => Array(11,0, Array( 0xEFF4 - ($PAL?77:0) => 0) ),
- 'items' => Array(14,0, Array( 0xF042 - ($PAL?77:0) => 0) ), // aka. weapons
- 'herbs' => Array(16,2, Array( 0xF06E - ($PAL?77:0) => 0) )
- );
- $space[0x1EFEB-($PAL?77:0)] = 9; // the beginning of RenderBodyParts
- $space[0x1F069-($PAL?77:0)] = 5; // the beginning of RenderLaurelsAndGarlics
- $space[0x1F105-($PAL?77:0)] = 0xF15E-0xF105; // Renderers for Time, Exp, Level, Hearts.
- // Don't delete the beginning of RenderWhipName, because it is used by whip_ext.s .
- // Change whip, body, items, herbs renderers to NOT call DialogBox_GoDownTwoLines at the end
- foreach(Array(/*0x1F030,*/0x1F066,0x1F0C1/*,0x1F1BA*/) as $location)
- {
- if($PAL) $location -= 77;
- $b = new Blob(sprintf("Patch_%X", $location), "\x60");
- $linker->AddBlob($b, $location, true);
- $space[$location+1] = 2;
- }
- // Rightalign the Exp. value (experience or E-points)
- $renderers['exp'][1] = 10;
- // Move level (L) to the same row as the hearts. Keep it right-aligned.
- $renderers['level'][0] = 6;
- if($settings['SUPPORT_MULTICLUE'])
- {
- // Condense by two lines.
- $renderers['exp'][0] -= 1;
- $renderers['hearts'][0] -= 2;
- $renderers['level'][0] -= 2;
- $renderers['whip'][0] -= 2;
- $renderers['body'][0] -= 2;
- $renderers['items'][0] -= 2;
- $renderers['herbs'][0] -= 2;
- $renderers['clues'] = Array(16,12, Array("DialogBox_RenderClues" => 0));
- // Experimental: Move the clock to the first line.
- $renderers['time'][0] -= 1;
- $renderers['time'][1] -= 1; // Move 1 character to the left, as well
- }
- // For each pair of two lines, list what goes on that linepair.
- $renderers_per_linepair = Array();
- foreach($renderers as $name => $configuration)
- {
- $line = $configuration[0];
- $column = $configuration[1];
- $script = $configuration[2];
- $renderers_per_linepair[ $line &~ 1 ] [ ($line&1) ] [$column] = $script;
- }
- // Generate the renderers for each of these line pairs.
- foreach($renderers_per_linepair as $y2 => $lines)
- {
- ksort($lines);
- $b = new Blob( sprintf("DialogBox_Render_LinePair%d", $y2) );
- $prevline = 0;
- foreach($lines as $line => $columns)
- {
- for(; $line > $prevline; ++$prevline)
- $b->AppendCallPointerTo("DialogBox_Go1Down_And_Recalculate");
- $prevcolumn = 0;
- ksort($columns);
- foreach($columns as $column => $script)
- foreach($script as $item => $increment)
- {
- $column += $increment;
- if($column > $prevcolumn)
- {
- $b->AppendRawData("\xA9" . chr($column - $prevcolumn)); // LDA #imm
- $b->AppendCallPointerTo("DialogBox_GoForwardHorizontally");
- $prevcolumn = $column;
- }
- if(is_string($item))
- $b->AppendCallPointerTo($item);
- elseif($item >= 0x1000)
- {
- $b->AppendRawData("\x20" . chr($item & 0xFF) . chr($item >> 8)); // JSR
- }
- else
- {
- $b->AppendRawData("\xA5" . chr($item & 0xFF)); // LDA zp
- $b->AppendCallPointerTo("DialogBox_RenderTwoDigitNumber");
- $prevcolumn += 1;
- }
- }
- }
- if($prevline == 0) $b->AppendJumpPointerTo("DialogBox_GoDownTwoLines");
- elseif($prevline == 1) $b->AppendJumpPointerTo("DialogBox_GoDownOneLine");
- else $b->AppendRawData("\x60");
- $linker->AddBlob($b, 0xC000); // anywhere in page 3
- }
- $location = 0x1F0CF-($PAL?77:0);
- $space[$location] = 0xF0FC-0xF0CF;
- $b = new Blob("DialogBox_RenderStatusBoxLine_tail");
- $b->AppendCallPointerTo("Odd_5E16flip");
- $b->AppendRawData("\xA5\x79"); // lda linenumber
- $b->AppendJumpPointerTo("DialogBox_RenderStatusBoxLine_Generated");
- $linker->AddBlob($b, $location, true);
- $linker->RemoveSpace($space, $location, $b->GetSize());
- $b = new Blob("DialogBox_RenderStatusBoxLine_Generated");
- foreach($renderers_per_linepair as $y2 => $lines)
- {
- $b->AppendRawData("\xC9" . chr($y2) ); // cmp #imm
- $b->AppendRawData("\xD0\x03"); // bne +
- $b->AppendJumpPointerTo( sprintf("DialogBox_Render_LinePair%d", $y2) );
- }
- $b->AppendJumpPointerTo("DialogBox_GoDownTwoLines");
- $linker->AddBlob($b, 0xC000); // anywhere in page 3
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement