Seiken Densetsu 3:RAM map

From Data Crystal
Jump to: navigation, search


0000-1bff		Stack and DP memory for different threads
	00-bf		DP
	c0-ff		Stack
		f8-fa		return address (usually c04bce, sometimes 7f4bce)
		fb-fd		Starting address
		fe-ff		address to thread context
1c00-1cff?		Audio Memory
	1c01		Sound effect id
	1c02		L/R balance for sound effect
	1c10		current music
1d00-1dff		Queued DMA request parameters, used as a stack

2000			Thread ID for Thread 5
2001			Thread ID for Thread 4
2002			Thread ID for Thread 6
2003			Thread ID for Thread 3
2005			Thread ID...
2006			Thread ID for Thread 9
2007			Thread ID for Thread 7
2008			Thread ID for Thread 8
2010-201f		Owning threads for characters/objects in scene
	2010		Thread ID for Character 1
	2011		Thread ID for Character 2
	2012		Thread ID for Character 3
2020			Object Thread ID...
2021			Object Thread ID...
2022			Object Thread ID... (stash for 2020)
2023			Object Thread ID... (stash for 2021)
2040-205f		Addresses to objects in scene (party members, enemies, interactables)
2060-207f		Addresses to character blocks B

20e1			(referenced at c41f3f)

2100-21ff		Memory map of bank 7f. Each byte represents 0x100 bytes in 7f. 00: unclaimed, else: claim ID
2200			Index of top memory in 2100 (first used byte of top section)
2202			Index of bottom memory in 2100 (first unused byte)
2204			(Related to memory management)

2be0-2bff:		Bits (controlled at c43613)

2c00-2eff:		Party Data
	2c00-0b		Character 1 Name
	2c0c-17		Character 2 Name
	2c18-23		Character 3 Name
	2c24-26		Luc
	2c27		Window style
	2c28-37		Window Hue & Value by style. 2 bytes each, 8 sets.

	2d28-2f		Player 1 button mappings
	2d30-37		Player 2 button mappings
			00	A
			01	X
			02	L
			03	R
			04	B
			05	Y
			06	Select
			07	Start
			01	Attack/Confirm
			02	Ring Command
			04	Partner 2
			08	Partner 1
			10	Tech/Run/Cancel
			20	Menu
			40	Leader
			80	Control

	2e38-9e		Storage - Item-by-item quantities

	2eb5		(c0badb) - controlled by sram:1808
	2eb6		(c0badb) - controlled by sram:1808
	2eb7		(c0badb) - controlled by sram:1808
	2eb8		Character presence

	2ee3-e6		Playtime counter (not actively incremented)
	2ee7		Game time pause request count
	2ee9-f2		Item ring items
	2ef3-fc		Item ring quantities

2f00-2fff:	Game data
	Event flags...

	2fd5			bitwise
	2fd6			(high nibble/low nibble)	low nibble set from index of 2021
	2fdb			bitwise
	2fdc			(high nibble/low nibble)

	2ff0			Character choice 1
	2ff1			Character choice 2
	2ff2			Character choice 3

	2ffa			High nibble:
					Low nibble: Game Time - Day of Week (0-6)
	2FFB			High nibble:
					Low nibble: Game Time - Hour (0-15)
	2FFC			Game Time - Minute (0-31)
	2ffe			(nibblewise)
					Bit 1: (set when give item successfully completes)

3000-33ff:		Thread 6, Character UI Thread, Thread c4681b
	3000-30ff	Temporary buffer memory
		3002-11		(overlay UI related)
		3022-31		(overlay UI related)
		3042-51		(overlay UI related)
		3080-bf		Text string for loading

	3122-23		(letter loading loop length)
	3124-25		(loop counter)

	312a-2b		(DMA size)
	3132-3c		5 DMARequests
	313e-3f		pointer

	3148		(character ID)
	314a		(thread ID)
	314e-4f		Loop counter
	3150-51		Count/size
	3152-53		(loop counter)
	3158-59		(CopyCommand)

	3304			(c430e2)

	3322-23		(direct page for Character UI Thread)


	33e0-e1			(cleared at c42e7e, c439a1, checked at c272f9)
	33e6-e7			(cleared at c4399a, c43bba)
	33e8-e9		(Thread ID) (copied to 33e4)
	33ea-eb				(copied to 33e0)
	33ec-ed				(copied to 33e6)
	33ee-ef		Current event script opcode
	33f0			bitwise	(c46252)
					Bit 1: set at c45109, c48c2e (thread start)
					Bit 2: cleared at c46158, set at c45e62, c462a5
	33f1		Character UI Thread ID
	33f2-f3		(set to ffff at c45fe3)

	33f6-f7		(Character UI Thread)
				Bit 1:	Overlay UI enabled?

	33fb				(cleared at c42e21, c43109)

Graphics buffers
3c00-3eff:	used at c49550 (fullscreen menu)
4000-	:		Character overlay UI tiles

5f85			(thread 5 inits to 0)
5f86			(thread 5 inits to 0)


	6016-1f			location data (from cb73dc)
	6018			last level
	6028			current level

	6041-42				(at c42bea)

	6045-46			DMARequest (Type 5)
	6047			(Thread 8)

	6051-52				(7f:fef0 - 78)
	6055-56				(7f:feee - 80)

	6079-7a				(7f:feee >> 4)

	607d-7e				(7f:fef0 >> 4)

	60c1-d0				(c27622 - copied from 6016-25)


	60ec->			stash for 2f00->

	6184-85			pointer to size 6 buffer

	6198-99			Timer

	619c-9d			Timer

	61a0-a1			Timer

	61a6-a7			Timer

	61ac-ad			Timer

	61b2-b3			Timer

	61ba-bb			Timer

	61d6-d7			counter
	61da-db			counter
	61dc-dd			counter
	61ed-f8				(6 items 2 bytes each)
	61f9-2fa			(every 0x10 bytes for 0x100 bytes)
	62fc-fd			Timer
	62fe-ff			Timer (Thread 8)

	6306			(Thread 8)
	6386			overworld timer
	638c				(set at c20ea8)

8700-897F		solidity set L1
8980-8BFF		solidity set L2

a220-21			counter for 16-byte sructures
a228-a4d1		16-byte strcutures
	00-02:		address
	03-05:		address (7e:0003)

b000-bfff:		(related to Thread 4)
	b6a2-a3		Timer
	b6a6-a7		Pointer: b7a8 if it gets a sender ff message, else b6a8


0000			(Thread ID) (used by Thread 5)
0001			(used by Thread 5)
0002			(Thread ID?) (used by Thread 5)
0004			(counter) (related to type fe message)

0010-11			(counter for queued DMA transfer sizes?)
0012-13			Top of stack pointer for DMA operations (bottom is 1d00)

0024			Flag for thread c01e25
0026-27			Root DMA Request pointer
0028-29			Unused DMA Request list
002a-2b			Queued Type 1-4 DMA Request queue
002c-2d			Pointer to end of above queue
002e-2f			DMARequest delete queue (only used on cleanup)
0030-31			Pointer to end of above queue
0032			Bit mask of active (H)DMA channels (Type 5 requests)
0034-3b			Thread IDs, slots for active Type 5 DMA Requests
003c-3d			Current Channel 0 Type 5 DMARequest?
003e-3f			stash for 0010
0040-41			stash for 0012
0042-43			stash for 0040[1]
0044-45			stash for 0040[3]
0046			dma related? inc at c03303, dec at c03355
0048			Copy of 004200 (NMI, V/H Count, and Joypad Enable)
004c-4d			Root InputHandler pointer
004e-4f			Unused InputHandler list
0050-51			InputHandler list...
0052-53			InputHandler list...
0054-55			InputHandler list...
0056-57			InputHandler list...
0058-59			InputHandler list...

005c			(result of last 4594 controller check)	(referenced on cutting room floor)
005d			(thread ID)	(referenced on cutting room floor)
005e-5f			(stack pointer)
0060-61			Thread count, excluding some system thread(s)
0062-63			Root ThreadContext pointer (0c00)
0064-65			Current ThreadContext pointer
0066-67			ThreadContext Ready List (Ordered by ascending priority--lowest first)
0068-69			ThreadContext Waiting List
006a-6b			ThreadContext Finished List
006c-6d			ThreadContext Empty List (ready to be initialized)
006e-6f			<Unused>
0070-8b			Thread memory slot map
					Low 5 bits: Parent thread IDs by memory slot
					Next 2 bits: incremented when thread finishes, loop back to zero after 3 times
008c			Current Thread ID
008d			Last created Thread ID
008e-8f			Flag: managing buffer memory
0090-91			Root ThreadMessage pointer (1000)
0092-93			Unused ThreadMessage list
0094-95			Root HardwareSettings pointer (0900)
0096-97			Unused HardwareSettings list
0098-99			HardwareSettings list...
009a-9b			End pointer for above HardwareSettings list
009c-9d			HardwareSettings list...
009e-9f			End pointer for above HardwareSettings list
00a0-a1			(pointer) (0800)
00a2			Random number counter
00a3-b1			Random numbers
00b2-b3			pointer to 2-byte buffer
00b4-b5			Root CopyCommand pointer (0b00)
00b6-b7			Unused CopyCommand list
00b8-b9			CopyCommand list (offset from root 0b00 pointer)
00ba-bb			list end pointer (00b8)
00bc-bd			CopyCommand list (offset from root 0b00 pointer)
00be-bf			list end pointer (00bc)
00c0-c1			Root Timer pointer (1800)
00c2-c3			Unused Timer list
00c4-c5			Active Timer list
00c6-c9			Playtime counter

0100-01			(value for character 1)
0102-03			(value for character 2)
0104-05			(value for character 3)

	032e-2f			(initialized to 7f00a0 (800 pointer))
				Bit 4: (set at c46482, c46770)
	0352-53			Flag for which messages to look for. Non-zero: Type #12. (initialized to 0)
	0354-55			Thread5.24 (related to $24)
	0370			(initilalized to 5c)
	0373			(initilalized to fd)
	0374			(initilalized to 5c)
	0377			(initilalized to d7)
	0378			(counter)
	0379			(counter)
	037b-7c			(initialized to cb0308-09)
	0381			(initilalized to 5c)
	0382-83			(Thread 5's)
	0384			(initilalized to fd)
	0386			Thread ID for thread 0a
	0391-92			Ring menu (pointer) (e4d0)
		00:	ring menu selected index
		01:	ring menu size
		42:	(flag)
		6e-6f:		pointer (b0e4)
	039c-9d			Thread 5 Timer
	03ea-eb			(initilalized to cb0202 (sprite palette switch colors?))
	03ec-ed			(initilalized to cb0204 (sprite palette switch colors?))
	03fa-fb			Thread5.24 (used by 4521)

042e-2f			(at 4778)

Linked List memory:
	0800-0fff		??, every 0x08 bytes
	0800-08ff		Stash/staging for HardwareSettings
		64-ff:		Unused
	0900-0aff		HardwareSettings, every 0x08 bytes
		00-01:		pointer to next object
		02:			Hardware register offset (also offset into table at c0ab64)
		03:			Thread Id
		04:			Hardware register value
		05:			Additional value/param
	0b00-0bff		CopyCommand, every 0x08 bytes
		When unused:
			00-01:		pointer to next object
		When active:
			00:			offset from root address of next object
			01-03:		Destination
			04:			Length (0 becomes 0x100)
			05-07:		Source, or data if length <= 3
	0c00-0f7f		ThreadContext, every 0x20 bytes
		00-01:		pointer to next ThreadContext
		02:			Status
					00	Empty
					01	Running  (set to this when resumed/started)
					02	Ready    (In list at 0066)
					04	Waiting  (In list at 0068)
					08	New      (dp memory is cleared when resuming, dp isn't restored)
					10	Finished?(Stack is reset to default, return address comes from fb)
		03:			Priority (lower values get to execute sooner)
					02	Managing buffer memory
					04	High priority (set when message list size reaches 16)
		04:			Low 5 bits: Thread ID (== memory slot + 2)
		05:			Low 5 bits: Parent Thread ID
		06:			ThreadMessage Type Mask (matches ThreadMessage[3]) (message types we're currently looking to execute)
		07:			Thread Type
		08-09:		Stack Pointer
		0a-0b:		Buffer pointer (set on creation)
		0c-0d:		ThreadMessage list
		0e-0f:		Last ThreadMessage on list
		13:			Stashed Priority
		16:			Stashed ThreadMessage Type Mask
		17:			ThreadMessage list size
						When >= #10, Priority is stashed, Priority is set to 4
						When < #10, Priority is restored from stash
		18-19:		Timer (set on creation)
		1a-1b:		Used BufferBlock list?
		1c-1d:		Available BufferBlock list
		1e-1f:		Available BufferBlock cache (most recently used)
	1000-17ff		ThreadMessage, every 0x08 bytes
					Used to pass data back and forth between threads
		00-01:		pointer to next object (when in list)
		02:			Sender thread ID
					FF: Timer expired
		03:			Type
		04-07:		Params (depends on type and context)
	1800-1bff		Timer, every 0x10 bytes
		00-01:		pointer to next object
		02:			Thread ID to notify
		03:			Settings (bitwise)
			01:		Notify as Type 1 Message
			80:		Recurring (add back when expired)
		04-05:		Due time
		06-07:		Length
		08-09:		Remaining time (if paused)
		0a-0b:		param
		0c-0d:		param
		0e-0f:		param
	1c00-207f		InputHandler, every 0x30 bytes
		00-01:		pointer to next object
		02:			Active flag?
		03:			Thread ID
		04-05:		? associated list index (0-4) or related
		06-07:		Buttons down
				bit 1:	Confirm/Attack		(default A)
				bit 2:	Ring menu			(default X)
				bit 4:	Partner 2			(default L)
				bit 8:	Partner 1			(default R)
				bit 10:	Cancel/Special		(default B)
				bit 20:	Main Menu			(default Y)
				bit 40:	Switch Character	(default Select)
				bit 80:	Storage				(default Start)
				bit 1:	Up
				bit 2:	Down
				bit 4:	Left
				bit 8:	Right
			A and B both cleared when 7e2022 is zero
			A Set when char[8a] bit 1 is set
			L Set when char[8a] bit 2 is clear
			R Set when char[8a] bit 2 is set
		08-09:		Buttons pressed this frame
		0a-0b:		Buttons released this frame
		0c-0d:		Enabled buttons
		0e-0f:		Instant buttons (when bit is clear, button remains active for about a second when pressed)
		10-2f:		Button->action mappings, 2 byte values initialized to 1, 2, 4, 8, 10... 8000
	2100-24ff		DMARequest, every 0x10 bytes
		00-01:		pointer to next object
		02:			DMA params (43x0)
		03:			B address
		04-06:		A address
		07-08:		Transfer size
		09:			Data bank for H-DMA
		0a:			For Type 5: DMA channel (by bit position)
					For Type 1: VRAM address increment value
		0b-0c:		VRAM address
		0e:			Requester Thread ID
		0f:			Type and Settings
				Low 3 bits: Type
					1:	VRAM DMA (channel 0)
					2:	CG-RAM DMA (channel 0)
					3:	OAM DMA (channel 0)
					4:	WRAM DMA (channel 0)
					5:	DMA/HDMA (Variable channel)
						(Seems to be programmed to support either regular or HDMA, but in actuality only does HDMA)
				Bit 08:	Send Type1 Message when complete (with [5-6] = A address)
				Bit 10:	Send Type4 Message when complete (with [4-5] = A address, [6-7] = VRAM address)
				Bit 40:	in the active list

2500-ffff?	Heap Memory

Dynamically allocated structs:
		00-01:		pointer to next object
		02-03:		size (including header)
		04-end:		buffer

	CumulativeByteTreeDecompressor (Size 48)
		00-0c:	TreeReader 1 (used when stack is empty)
		0d-17:	TreeReader 2 (used when stack is empty)
		18-23:	TreeReader 3 (used when stack is active)
		24-2f:	TreeReader 4 (used when stack is active)
		30-37:	BitStream (non-stackable)
		38-39:	pointer to TreeReader 1
		3a-3b:	pointer to TreeReader 2
		3c-3d:	pointer to TreeReader 3
		3e-3f:	pointer to TreeReader 4
		40-41:	pointer to ShortAddressTreeDecompressor or BitStream (stackable)
		44-45:	BitStream stack counter (related to [40])
		46-47:	some data substitute, similar to ShortAddressTreeDecompressor[2a]

	TreeReader (Size 0c)
		00-01:	pointer to BitStream
		02-04:	long address to tree
		06-07:	tree size in nodes, or tree end address for address trees 
		08-09:	counter? (decremented)
		0a-0b:	? (0000)

	BitStream (Size 0a, or 8 if not stackable)
		00-02:	Stream cursor
			If bank is 0, address to (parent?) ShortAddressTreeDecompressor
		04-05:	Number of bits remaining in loaded data, or number steps to take in the tree (decremented)
		06-07:	Data (tree walk code, bits left to right (shifted left))
		08-09:	Previous BitStream (initialized to 0)

	ShortAddressTreeDecompressor (Size 2e)
		00-01:	pointer to BitStream (self + 18)
		02-03:	poniter to large buffer
		04-05:	bits 17-32 (set at the end of thread c02694)
		06-07:	address into large buffer (pointer + above value * 4) (set at the end of thread c02694)
		08-09:	pointer to another ShortAddressTreeDecompressor (stack/list)
		0a:		thread ID
		0c-17:	TreeReader
			0c-0d: pointer to BitStream (self + 18)
			0e-0f: pointer to large buffer (tree in memory)
		18-21:	BitStream
			20-21: pointer to parent?
		22-23:	TreeReader (self + c)
		24-25:	pointer to BitStream (stack)
		26-27:	(counter)
		28-29:	BitStream stack size
		2a-2b:	data substitute (set to and compared against FEFE)
		2c-2d:	(counter)

		9e-9f:	Routine addr to call (at c145e0)
		a5-a6:	Pointer to next (list at 03fa, 61)
		a7-a8:	Pointer to next (list at 5b)
		a9-aa:	Pointer to prev (list at 5b)

		00-01:	Pointer to next
		02-04:	Long

	Char.4 (Size >= 84) (Transform?)
		In the code, I see
			08-09	(c0782e)
			0a-0b	(c0783b)
			0c-0d	(bit 1 checked at c014aa, 757f)
			83-84:	related to $0322
			87-88:	(c4416d)
			1ae-af:	(c0780e)
		In practice?
			05-06:	X position in scene
			09-0a:	Y position in scene

		Previous 0x100 bytes are script context
		00 			(c07c3c)
		01 			Object Type
			01: party member
			04: object? save statue?
		02			Owning thread ID
		03			Character index
		04			pointer to Char.4 (e.g. ed9c)
		06			Current animation index?
		08			Current action?
						00: idle, attacking
						01: walking (battle)
						02: walking (outside battle)
						04: running
		09			(74b6)
		0b			Compared to FF (c07c52), 4 (c077cb)
		10-11		Target Character
		18-32		List of 9 script addresses (queued scripts to run?)
		3f			Ally count (array at 40)
		40-49		Array of allies (Character pointers) (no length enforcement)
		4a			Enemy count (array at 4b)
		4b-56?		Array of enemies (Character pointers) (no length enforcement)
		57			List of Timers where [0a] points to next
		59			Paused Timers array
		5b			Count of pause requests (if > 0, Timers are paused and stored at 59)
		5c			pointer...
		65			counter of some sort?
		68			added to 69
		69			added to 68
		6e			bitwise
						bit 08: toggles behavior at c08184
							clears bit 80
		6f			bitwise
						bit 02: toggles behavior at c0749d, 77e8
						bit 08: toggles routine execution from 118 at c0a5d9
						bit 80: toggles behavior at c091df, 926f, bda3
		70			pointer...
		72			Scene object index (of... target? next?)
		74			InputHandler pointer (linked list)
		76			Thread ID
		8a			bitwise
						bit 01: related to bit 01 of InputHandler[06], 9277
						bit 02: related to bits 04, 08 of InputHandler[06]
		8b			bitwise
						but 02: related to bit 01 of InputHandler[06], set at a7e0

		90			Character ID
		92			Current HP
		94			Current MP
		96			Strength
		97			Agility
		98			Constitution
		99			Intelligence
		9a			Spirit
		9b			Luck
		9c			Tech gauge current
		9d			Total experience / 50000
		9f			Total experience (remainder)
		a1			bitwise
		a2			Max HP
		a4			Max MP
		a6			last chosen stat at level up (0-5)

		ac 			Tech Gauge max
		ad 			XP for next level / 50000
		af 			XP for next level (remainder)
		b1 			Level
		b2 			Levels since class change (incremented at beginning of level up)
		b3 			Class family
		b4 			Class stage
		b5 			Light/dark scale

		bc 			Weapon
		bd 			Helmet
		be 			Armor
		bf 			Ring
		c0 			Shield
		c3 			defensive equipment stat 18-19 ORed together
		c5 			stat modifiers	(HP and MP are done twice... do they stack?) (also, equipment bonuses are ANDed instead of ORed, which I think would make more sense)
					if 0: no effect
					if 1: boost: +20% (+30% for attack)
					if 2: diminish: -20% (-30% for attack)
					if 3: negate: 0
					bits 2-3 (evade), 4-5, 6-7 (attack) come from def equipment[0a], weapon [08]
					bits 0-1, 2-3 (defense), 4-5 (healing received, damage given/received), 6-7 (magic defense and magic evade?) come from def equipment[09], weapon[07]
					bits 0-1, 2-3, 4-5 (HP), 6-7 (MP) come from def equipment[08], weapon[06]
						bits 6-7 special case, >= 2 becomes 0, else AND result
		c8 			stat modifiers (same as above, not sure the exact difference)
		cb 			defensive equipment stat 16-17 ORed together
		cd 			(character specific[17])

		d1			defensive equipment stat 0b ORed together
		d2			defensive equipment stat 0c ORed together
		d3			Elemental immunities
		d4			Elemental weaknesses (doubled)
		d5			Elemental weaknesses (1.5x + 38)
		db			(character specific[7-9])
		de			(set to 0)
		df			weapon[0b]
		Calculated stats:
			e1		Evade reduction (from weapon)
			e2		(Crit?) weapon[0e] + Luck (max 20)
			e3		Attack
			e5		Chance to avoid (some behavior based on stat modifiers) (from weapon[11] + Luck (max 100)) (d0c39f(attacker), d0c313(target))
			e6		weapon[12] (d0c9af, d0c9b8, d0c353(target))
			e8		weapon[14] (d0c9a0)
			ea		Evade
			eb		Defense
			ed		Magic defense
			ef		Magic related?
		Base stats:
			f1		Evade reduction (base)
			f2		weapon[0e] + Luck (base) (max 20)
			f3		Attack (base)
			f5		(unused?)
			f6		weapon[12]
			f8		weapon[14] (base)
			fa		Evade (base)
			fb		Defense (base)
			fd		Magic defense (base)
			ff		Magic related? (base)
		101			Weapon inventory
		111			Helmet inventory
		118			Armor inventory
		121			Ring inventory
		128			Shield inventory

		138			(d0ccc8, d0cdf7)
		13b			(d0ccd1)

		145			Spell list
		151			Spell targeting

		167			Max HP (base)
		169			Max MP (base)
		16d			(classspecific[0])

		16f			(c4455a)

		17b			Related to 183

		181			(d0cce6, d0cd10)
		182			stored when healed, used to determine defense stat used against a skill
		183			Pending damage/heal amount
		185			decremented on level up (level ups to do?)

		18c			char ID zero-based (charspecific[0])
		18d			tech gauge related
		190			two nibbles
		191			two nibbles
		19a			level * 7