Use : 7lt engine

Lay	type	comment
---------------------------
1	tile	bottom blocks (ground)
2	tile	impassable blocks
3	mask	items on map
4	mask	npc
5	mask	hero
6	mask	decor sprites (birds, effects...)
7	tile	tables, text

* characters can't go through other characters or impassable block

Constant map structure:

+0	256 words - address of maps (0..3fff - page1, 4000..7fff - page2)
+512	maps data

maps data:

+0	N map (255:no map)
+1	E map
+2	S map
+3	W map
+4	color
+5	tileset nr
+6	flags (b0:checkpoint)
+7	lay 1 data (as {mapDX x mapDY} tile numbers, packed hr1 w/o header)
+?	lay 2 data
+?	lay 5 data

Zones table:

+0	ID (255:end)
+1	flag b0 : zone is inactive
+2	map
+3,4	X,Y
+5,6	dX,dY
+7,8	script.adr

Doors table:

+0	ID (255:end)
+1	flag		; b0:inactive; b1 = b0 init
+2	mapID (255:door is inactive)
+3	X
+4	Y
+5	dX
+6	dY
+7	move.mapID	; place to move
+8	move.X
+9	nove.Y
+10	new.dir

Items table:

+0	ID (255:end)
+1	mapID (255:item is not on map)
+2	X
+3	Y
+4	tile nr for small icon (on map)
+5,6	sprite adr for big icon (2x2,inventory)
+7,8,9	= map,x,y for init
+10	amount (drop:bag->item; pickup:item->bag)
+11,12	name adr
+13	amount in bag (0:none)

Non-constant map parts table:

+0	ID (255:end)
+1	mapID (255:item is inactive / char is not on map)
+2	X
+3	Y
+4	layer
+5,6	sprite.addr
+7	anim.count (0:no anim)
+8,9	anim.addr
+10,11	affect.script.adr
+12	= +1 init
+13	= +2 init
+14	= +3 init
+15,16	= +5,6 init
+17,18  = +8,9 init (+7 = 0 ? 0 : 1)
+19,20	= +10,11 init
+21	cycle counter
+22,23	cycle.adr

NPC table:

+0	ID (255:end)
+1	mapID (255:item is inactive / char is not on map)
+2	X
+3	Y
+4	layer (4:NPC, 5:hero)
+5,6	sprite.addr
+7	anim.count (0:no anim)
+8,9	anim.addr
+10	dir
+11	reserved
+12	= +1 init
+13	= +2 init
+14	= +3 init
+15,16	= +5,6 init
+17,18  = +8,9 init (+7 = 0 ? 0 : 1)
+19,20	= +10,11 init (capability)
+21	cycle counter
+22,23	cycle.adr

== BATTLE

Battle tab:

+0	battleID (255 : end)
+1,2	battle data addr

Battle data:

+0,1	main script adr
+2,3	start script adr (0 : none)
+4,5	lose script (0 : none)
+6,7	win script (0 : none)
+8 (6)	id,X,Y,<dsc.adr>,flag	: battle NPCs (8 max, id=0 hero, id=255 end)
	flag : b0 - attack off

Battle NPC DSC:

+0	NPC id (from charTab. 255 : end)
+1,2	actions table
+3	HP
+4	maxHP
+5	MP
+6	maxMP
+7,8	atk/def tab.adr
+9	flag	0:passive
		1:ally

== EQUIPMENT

+0..3	atack or defence levels
+4,5	name.adr
+6,7	info.adr

== POTION

+0	id
+1	type
+2	amount (0)
+3	duration
+4	countdown (0)
+5,6	use.script.adr
+7,8	effect.script.adr (call each turn while it works)
+9,10	name.adr

== MAGIC

+0	id	FF:end
+1	flag	b0:available
+2	MP required
+3,4	script.adr (use)
+5,6	name.adr

== MENU

menu flag:
b0 : don't close window on select
b1 : exec.adr is code, not a script

punkts:
+0	condition
+1	punkt.data (send to exec.adr in C)
+2,3	exec.adr
+4,5	text.adr

inner table:
+0	Y.pos (FF:end)
+1	flag
	b0 : this is not menu punkt
+2,3	DSC.addr

menu conditions:
00	allways true
01	NPC ahead
02	item on ground
03	item in hand
04	enable to drop item (item in hand + free place under feet)
05	enable to give item (item in hand + npc ahead)
06,n	bit n set
07	ahead is element which can be affected

FD	skip this punkt
FE	just a text, not a menu punkt
FF	end of table

-----

...script bytecode...

00			end of text

01,00			remove dialog box
01,02,<adr>		menu.exec, adr = menu.dsc.adr (X,Y,flag,<callback>,{menu.data}>)

02,00,id		del item id from bag
02,01,id		add item id in bag
02,02,id,cnt		add cnt items id in bag
02,03,id,n		add equip n of type id
02,04,id,n		del equip n of type id
02,05,id		add potion id
02,06,id		del potion id
02,07,id,map,x,y	place item id to map,x,y
02,08,dir		rotate bag; b0,dir : 0:left 1:right
02,09,id		enable magic id
02,0a,id		disable magic id

03,00,n			bit n = 0
03,01,n			bit n = 1
03,02,n			bit n = !bit n
03,03,n,m		bit n &= bit m
03,04,n,m		bit n |= bit m
03,10,n,x		var n = x
03,11,n,m		var n = var m
03,12,n,x		var n += x
03,13,n,m		var n += var m
03,14,n,x		var n -= x
03,15,n,m		var n -= var m

04,00,id,adr		set anim adr to NPC id (id=0 : hero)
04,01,id,adr		set anim adr to element id
04,02,id		enable door id
04,03,id		disable door id
04,04,id,adr		set sprite adr to element id
04,05,id,map,x,y	move NPC to map,x,y
04,06,id,map,x,y	move Elem to map,x,y (id=255 : wElem)
04,07,id,adr		set sprite adr to NPC id
04,08,id,adr		set affect adr to Elem id (adr=0:non-affectable)
04,09,id		wait NPC id animation end (id=0:hero)
04,0a,id		activate zone id
04,0b,id		deactivate zone id
04,0c			scan zones & exec scripts
04,0d,id		wait Elem id animation end

05,00,hp,mp,<exp>	add hp,mp,experience & print info line until 5sec/keypress
05,01,"text",00		print text info line
05,02			print name of current item & wait keypress
05,03,lay,x,y,{row},0	out {row} tiles (until 00) in layer lay at x,y
05,04,lay,x,y,dx,dy	clear rect in lay

06,00,id,n		add n HP to battle npc id, show n (id=255:eDSCAdr; n=255:bDamage)
06,01,id,n		sub n HP to battle npc id, show n
06,02,id,n		add n MP to battle npc id
06,03,id,n		sub n MP to battle npc id
06,04,id,<adr>		select enemy ad BID(id) or jump <adr> if canceled
06,05,id		pick random enemy as BID(id)
06,06,id1,id2		npc id1 std.atack to npc id2 : calculate damage to (bDamage), set fatkIP, fatkAP
06,07			show HP/MP window
06,08,id,sid		run script sid to battle npc id; sid = script id
06,09,id,st,<adr>	if battle npc id is (st ? alive : dead), jump <adr>
06,0a			magic menu
06,0b			cancel current turn, return to battle actions menu
06,0c			potion menu
06,0d,id,n,<adr>	if battle npc HP < n, jump <adr>
06,0e,id,n		set NPC HP (don't show)
06,0f,id		current (255) is NPC id
06,10,id		activate potion id (it doesn't remove potion from bag)
06,11,id,<adr>		replace attack of NPC id : <adr> = 4 bytes of atk.force
06,12,id,<adr>		replace defence of NPC id : <adr> = 4 bytes of def.force
06,13,id,<adr>		replace actions table (AT) for NPC id (AT = {bsID,<script.adr>},0xff)
06,14,id,prc		maxHP of battle NPC id +prc%
06,15,prc		damage +prc%
06,16,prc		damage -prc%
06,17,num		damage = num
06,18,id,prc		raise HP on prc% of max to npc id (battle)
06,19			run battle start script
06,1a			run battle win script
06,1b			run battle lose script
06,1c,<adr>		if all enemies is dead, jump adr
06,1d,<adr>		if all heros is dead, jump adr
06,1e			battle turn (potion time decrease)
06,1f,id		apply affects id (fxSTART, fxTURN, ...)
06,20,id,prc		raise MP on prc% of max to npc id (battle)
06,21,id,<adr>		same as 06,04 but select ally (when more 1) as BID(id)
06,22,id		pick random ally as BID(id)
06,23,n			n = 0|* = res|set turn cancel bit

07,00,<adr>		talk, adr = talkTable
07,01,<adr>		give, adr = giveTable
07,02			pick up
07,03			drop
07,04			affect
07,05,<adr>		use, adr = useTable
07,06			equip
07,07			craft

08,00,<adr>		scan keys of table <adr> : table = {port,mask,<script.adr>},0
08,01			game init
08,02,col		border col
08,03
08,04,hp,mp,<at.adr>	set hero start params (at.adr = battle actions table)
08,05			breakpoint : stop & wait here
08,06,lm,bm		set layers mask (lm), impassable mask (bm)
08,07,x,y,dx,dy		set game viewport
08,08,atr		fill screen with atr
08,09,atr		gradient cls, fill atr
08,0a,atr		atr cls, fill atr
08,0b,<src>,<dst>	depack (hr1 w/o head) from <src> to <dst>
08,0c,dx,dy,<adr>,<scr>	draw sprite dx:dy boxes from <adr> to adr <scr> (not engine)
08,0d,<adr>,len,val	fillmem : len bytes (1..256) at addr <adr> with byte val
08,0e,msk		set map format. bits0..6 = 1 if map have this lay (1..7)
08,0f,<adr>		init lay colors

09,00,flag		flag = 0/1/* = off/on/trig music
09,01,id		play music id
09,02,id		play SFX id

0d			cr+lf

1e,00			halt : call aniSR
1e,01,id,<adr>		call battle id and go adr if lose
1e,02			clear craft items
1e,03,<adr>		call script <adr> from extend page (text/bits/vars only)
1e,04			refresh & wait keypress
1e,05,flag		animation on|off (flag = *|0)
1e,06,n			pause n/50 sec
1e,07,<adr>		call script adr (tEnd = ret)
1e,08,<adr>		do "call adr"
1e,09,n			go to map n (n:255 = hero.map)
1e,0a			return to last checkpoint
1e,0b			restart game
1e,0c,flag		L7 off|on (flag = 0|*)

1f,00,n,<adr>		if bit n res, jump adr
1f,01,n,<adr>		if bit n set, jump adr
1f,02,<adr>		jump adr (allways true)
1f,03
1f,04,n,x,<adr>		if var n = x, jump adr
1f,05,n,m,<adr>		if var n = var m jump adr
1f,06,n,x,<adr>		if var n < x, jump adr
1f,07,n,m,<adr>		if var n < var m jump adr
1f,08,n,x,<adr>		if var n != x, jump adr
1f,09,n,x,<adr>		if var n != var m, jump adr
1f,0a,id,<adr>		if person id ahead, jump adr (charTab)
1f,0b,id,<adr>		if element id ahead, jump adr (actvTab)
1f,0c,id,<adr>		if NPC id have animation (charTab)
1f,0d
1f,0e,num,<adr>		if RND < num, jump adr
1f,0f,num,msk,<adr>	if (var(num) & msk != 0) jump adr
1f,10,msk,<adr>	if (RND & msk) jump adr
1f,11,id,<adr>		if have item id, jump adr
1f,12,id,<adr>		if have magic id, jump adr
1f,13,id,<adr>		if have potion id, jump adr
1f,14,<adr>		if turn canceled

"text"			print text (if dialog window on)

-----
direction
0	N (up)
1	E (rg)
2	S (dn)
3	W (lf)

Animation (for NPC & elements)

00		stop animation
01..EF,<addr>	set sprite addr and wait 01..EF frames
F0..FF		commands

commands:

00		end anim

F0,00,d		move sprite in direction d(0..3)
F0,01,d		dir = d (chars)
F0,02,d		go to map in dir d
F0,03,z		remove (z==0) or draw (z!=0) sprite
F0,04,x,y	change coordinates
F0,05,dx,dy	shift coordinates

F1... = text.03...

F2,00,<adr>	check door ahead, go <adr> when present
F2,01,<adr>	run script
F2,03,id	play SFX id

FF,FF,<adr>	jump adr
FF,00,n,<adr>	if (bit n res) jump adr
FF,01,n,<adr>	if (bit n set) jump adr
FF,02,n,<adr>	if (pos.x == n) jump adr
FF,03,n,<adr>	if (pos.y == n) jump adr
FF,04,d,<adr>	if at least one tile @ dir d is impassable, jump adr
FF,05,d,<adr>	if (dir != d) jump adr
FF,06,d,<adr>	if no map @ dir d
FF,07,n,<adr>	if (rnd < num)
FF,08,n,m,<adr>	if (var n == m)
FF,09,n,m,<adr>	if (var n != m)