//GAME NAME:		Dragon Warrior II (U) [!].nes

// Define required TABLE variables and load the corresponding tables
#VAR(Table_0, TABLE)
#ADDTBL("credits.tbl", Table_0)
#VAR(Table_1, TABLE)
#ADDTBL("credits_spacer.tbl", Table_1)
#VAR(Table_2, TABLE)
#ADDTBL("cursor.tbl", Table_2)
#VAR(Table_3, TABLE)
#ADDTBL("dw2.tbl", Table_3)
#VAR(Table_4, TABLE)
#ADDTBL("dw2_script.tbl", Table_4)
#VAR(Table_5, TABLE)
#ADDTBL("heights.tbl", Table_5)
#VAR(Table_6, TABLE)
#ADDTBL("menu.tbl", Table_6)
#VAR(Table_7, TABLE)
#ADDTBL("menu_links.tbl", Table_7)
#VAR(Table_8, TABLE)
#ADDTBL("menu_params.tbl", Table_8)
#VAR(Table_9, TABLE)
#ADDTBL("pos.tbl", Table_9)
#VAR(Table_10, TABLE)
#ADDTBL("pos2.tbl", Table_10)
#VAR(Table_11, TABLE)
#ADDTBL("spacer.tbl", Table_11)
#VAR(Table_12, TABLE)
#ADDTBL("widths.tbl", Table_12)

#VAR(pointerNum, CALCVAR) // create a CALCVAR variable named pointerNum
#CALC(pointerNum, "0") // initialize pointerNum to 0

// Auto-commands for when DW2 does a mid-string bankswap and resets its read address.
// Note that DW2's text engine reads the first 2 bytes at the current pointer's target *before* the code for checking whether the read address has reached RAM $BFD7 runs, so if you're unlucky enough to have a pointer point to RAM $BFD6 or $BFD7, change these AUTOCMD addresses from $17FE7 to $17FE5 or $17FE6 respectively and try inserting again.
#AUTOCMD($17FE7, #HDR($10))
#AUTOCMD($17FE7, #JMP($B7C2, $BE0F))
// update the code that controls which pointer starts the next bank
#AUTOCMD($17FE7, #WLB(pointerNum, $3FA90))

//BLOCK #000 NAME:		Main Script Part 1
#ACTIVETBL(Table_4) // Activate this block's starting TABLE

#JMP($14010) // Jump to insertion point
#HDR($C010) // Difference between ROM and RAM addresses for pointer value calculations

//POINTER #0 @ $B762 - STRING #0 @ $14010
#W16($B762)
#CALC(pointerNum, "!pointerNum + 1")
//[name] stood guard.[end-FC]
[name] stood guard.[end-FC]

//[cardinal #] [monster(s)],[end-FC]
[cardinal #] [monster(s)],[end-FC]

//But it wasn't real.[end-FC]
But it wasn't real.[end-FC]

//[name] attacked![end-FC]
[name] attacked![end-FC]

//Before [name] was set for battle.[end-FC]
Before [name] was set for battle.[end-FC]

//But the [name] did not see thee.[end-FC]
But the [name] did not see thee.[end-FC]

//[name] attacked![end-FC]
[name] attacked![end-FC]

//But missed![end-FC]
But missed![end-FC]

//[name] was wounded.[end-FC]
[name] was wounded.[end-FC]

//[name] was not hurt.[end-FC]
[name] was not hurt.[end-FC]

//[name] dodged the blow.[end-FC]
[name] dodged the blow.[end-FC]

//[name]'s HP is reduced by [number].[end-FC]
[name]'s HP is reduced by [number].[end-FC]

//[name]'s HP is reduced by [number].[end-FC]
[name]'s HP is reduced by [number].[end-FC]

//A tremendous blow![end-FC]
A tremendous blow![end-FC]

//A heroic attack![end-FC]
A heroic attack![end-FC]

//[name] broke away and ran.[end-FC]
[name] broke away and ran.[end-FC]
// current address: $140C2

//POINTER #1 @ $B764 - STRING #1 @ $140C3
#W16($B764)
#CALC(pointerNum, "!pointerNum + 1")
//But there was no escape.[end-FC]
But there was no escape.[end-FC]

//Thy MP is low.[end-FC]
Thy MP is low.[end-FC]

//But the spell was blocked.[end-FC]
But the spell was blocked.[end-FC]

//[name] called for help.[end-FC]
[name] called for help.[end-FC]

//But no help came.[end-FC]
But no help came.[end-FC]

//[name] came to help.[end-FC]
[name] came to help.[end-FC]

//The enemies was confused.[end-FC]
The enemies was confused.[end-FC]

//[name]'s wounds were healed.[end-FC]
[name]'s wounds were healed.[end-FC]

//But the spell had no effect on [name].[end-FC]
But the spell had no effect on [name].[end-FC]

//Thou hast defeated the [name].[end-FC]
Thou hast defeated the [name].[end-FC]

//[name] chanted the spell of [spell].[end-FC]
[name] chanted the spell of [spell].[end-FC]

//Alas, brave [name] hast died.[end-FC]
Alas, brave [name] hast died.[end-FC]

//[name] fell asleep.[end-FC]
[name] fell asleep.[end-FC]

//[name] did not fall asleep.[end-FC]
[name] did not fall asleep.[end-FC]

//[name] fell asleep.[end-FC]
[name] fell asleep.[end-FC]

//[name] is asleep.[end-FC]
[name] is asleep.[end-FC]
// current address: $14186

// etc., etc.

// due to the way the game's bank bridging code works, the first byte of the second script bank needs to be copied to the byte after the last byte of the first script bank in order to ensure consistency between banks
#VAR(copy, CALCVAR)
#READ(copy, $B7C2)
#JMP($17FE7)
#PRINT(copy, 8)

//BLOCK #002 NAME:		Menus
#ACTIVETBL(Table_8) // Activate this block's starting TABLE

#JMP($76E6, $7FDF) // Jump to insertion point
#HDR($-3FF0) // Difference between ROM and RAM addresses for pointer value calculations

//POINTER #0 @ $7652 - STRING #0 @ $76E6
#W16($7652)
//[menu format 01: no cursor, not linked, double-spaced]
//[height:4 tiles]
//[width:18 tiles]
//[position:(10,22)]
//NAME═LV══HP══MP[border line]
//[Midenhall's short name] [Midenhall's level] [Midenhall's current HP] [Midenhall's current MP][line]
[menu format 01: no cursor, not linked, double-spaced]
[height:4 tiles]
[width:18 tiles]
[position:(10,22)]
NAME═LV══HP══MP[border line]
[Midenhall's short name] [Midenhall's level] [Midenhall's current HP] [Midenhall's current MP][line]
// current address: $7700

//POINTER #1 @ $7654 - STRING #1 @ $7700
#W16($7654)
//[menu format 01: no cursor, not linked, double-spaced]
//[height:4 tiles]
//[width:18 tiles]
//[position:(4,2)]
//NAME═LV══HP══MP[border line]
//[Midenhall's short name] [Midenhall's level] [Midenhall's current HP] [Midenhall's current MP][line]
[menu format 01: no cursor, not linked, double-spaced]
[height:4 tiles]
[width:18 tiles]
[position:(4,2)]
NAME═LV══HP══MP[border line]
[Midenhall's short name] [Midenhall's level] [Midenhall's current HP] [Midenhall's current MP][line]
// current address: $771A

// etc., etc.

//BLOCK #003 NAME:		"ADVENTURE LOG", stored backwards
#ACTIVETBL(Table_3) // Activate this block's starting TABLE

#JMP($3EDCF, $3EDDB) // Jump to insertion point
#HDR($30011) // Difference between ROM and RAM addresses for pointer value calculations

//POINTER #0 @ $3EDC4 - STRING #0 @ $3EDCF
#W16($3EDC4)
//GOL ERUTNEVDA
GOL ERUTNEVDA
// current address: $3EDDC

//BLOCK #004 NAME:		Prologue
#ACTIVETBL(Table_11) // Activate this block's starting TABLE

#JMP($1CAC2, $1CC22) // Jump to insertion point
#HDR($14010) // Difference between ROM and RAM addresses for pointer value calculations

//POINTER #0 @ $1CAB1 - STRING #0 @ $1CAC2
#W16($1CAB1)
//
//            PROLOGUE
//[line]
//[line]
//     Many years ago a young
//     warrior who was of the
//       line of the great
//    Erdrick came to Alefgard
//    and defeated the dreaded
//     Dragonlord, restoring
//       peace to the land.
//[line]
//[line]
//      For many generations
//     the descendants of that
//     warrior ruled Alefgard
//      and the surrounding
//      lands, including the
//     Kingdom of Moonbrooke
//     across the eastern sea
//         from Alefgard.[end]

            PROLOGUE
[line]
[line]
     Many years ago a young
     warrior who was of the
       line of the great
    Erdrick came to Alefgard
    and defeated the dreaded
     Dragonlord, restoring
       peace to the land.
[line]
[line]
      For many generations
     the descendants of that
     warrior ruled Alefgard
      and the surrounding
      lands, including the
     Kingdom of Moonbrooke
     across the eastern sea
         from Alefgard.[end]
// current address: $1CC23

// etc., etc.