Heroes of Might and Magic Community
visiting hero! Register | Today's Posts | Games | Search! | FAQ/Rules | AvatarList | MemberList | Profile


Age of Heroes Headlines:  
5 Oct 2016: Heroes VII development comes to an end.. - read more
6 Aug 2016: Troubled Heroes VII Expansion Release - read more
26 Apr 2016: Heroes VII XPack - Trial by Fire - Coming out in June! - read more
17 Apr 2016: Global Alternative Creatures MOD for H7 after 1.8 Patch! - read more
7 Mar 2016: Romero launches a Piano Sonata Album Kickstarter! - read more
19 Feb 2016: Heroes 5.5 RC6, Heroes VII patch 1.7 are out! - read more
13 Jan 2016: Horn of the Abyss 1.4 Available for Download! - read more
17 Dec 2015: Heroes 5.5 update, 1.6 out for H7 - read more
23 Nov 2015: H7 1.4 & 1.5 patches Released - read more
31 Oct 2015: First H7 patches are out, End of DoC development - read more
5 Oct 2016: Heroes VII development comes to an end.. - read more
[X] Remove Ads
LOGIN:     Username:     Password:         [ Register ]
HOMM1: info forum | HOMM2: info forum | HOMM3: info mods forum | HOMM4: info CTG forum | HOMM5: info mods forum | MMH6: wiki forum | MMH7: wiki forum
Heroes Community > Heroes 3.5 - WoG and Beyond > Thread: ERM codes
Thread: ERM codes
Yanzhangcan
Yanzhangcan


Known Hero
*Dance*
posted February 18, 2007 12:05 AM

ERM codes

This thread should be for those people who want to show their skill and place some codes here, to edit the game.

Therefore you can come to this thread and find interesting edits done by the experts

ERM Scripting for those to lazy to do it themselves. Also a place for ideas and concepts.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Yanzhangcan
Yanzhangcan


Known Hero
*Dance*
posted February 19, 2007 09:03 AM

Here is a castle modification. Use the Castle in your scenario.

Copy what's between the ** And paste them into seperate timed events.

*ZVSE
!#UN:T0/0/0/143;
!#UN:T0/0/6;
!#UN:T0/1/0/29;
!#UN:T0/1/1/173;
!#UN:T0/2/0/32;
!#UN:T0/2/1/116;
!#UN:T0/3/0/108;
!#UN:T0/3/1/109;
!#UN:T0/4/0/9;
!#UN:T0/4/1/169;
!#UN:T0/5/0/121;
!#UN:T0/5/1/40;
!#UN:T0/6/0/94;
!#UN:T0/6/1/95;
!#MA:U108/109;*

This places the monsters into their new buildings

*ZVSE
!#MA:U143/6;
!#MA:U29/173;
!#MA:U32/116;
!#MA:U108/109;
!#MA:U7/169;
!#MA:U121/40;*

That changes the upgrade path for the monsters

New changes in stats for the monsters

*ZVSE
!#MA: C6/6/120 A6/4 D6/4 P6/10 S6/5 M6/3 E6/3 N6/0 G6/10 B6/0 R6/0 I6/445 F6/445 L6/0 O6/0 X6/16; Swordsman*

*ZVSE
!#MA: C94/6/1200 A94/15 D94/12 P94/200 S94/8 M94/25 E94/25 N94/16 G94/1 B94/0 R94/0 I94/1266 F94/1055 L94/5 O94/6 X94/1049652; Cyclops*

*ZVSE
!#MA: C95/6/2000 A95/17 D95/13 P95/300 S95/8 M95/50 E95/50 N95/50 G95/1 B95/0 R95/0 I95/1443 F95/1110 L95/5 O95/0 X95/102964; Cyclops King*

*ZVSE
!#MA: C108/6/350 A108/8 D108/8 P108/45 S108/6 M108/7 E108/10 N108/0 G108/4 B108/0 R108/0 I108/1350 F108/1050 L108/5 O108/7 X108/19; Wyvern*

*ZVSE
!#MA: C109/6/400 A109/8 D109/8 P109/50 S109/9 M109/8 E109/12 N109/0 G109/4 B109/0 R109/0 I109/1518 F109/1181 L109/5 O109/7 X109/19; Wyvern Monarch*

*ZVSE
!#MA: C173/6/200 A173/5 D173/5 P173/5 S173/5 M173/2 E173/3 N173/0 G173/12 B173/1000 R173/0 I173/200 F173/500 L173/9 O173/9 X173/16; Santa Gremlin*

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
doom3d
doom3d


Known Hero
Avatar of general Z
posted March 11, 2007 04:44 PM
Edited by doom3d at 21:07, 12 Mar 2007.

I have created a database service script to handle n-bit (signed) integers on continuous bitfield, created from v variable sequence.
It gives you basic i/o interface to index tables, and composite variables. I provide it with comments. Under the terms of GPL. ;)
Amongst others, I will use it as a low level service for H3 Caravans script.

***********************************************************************
*[BITWISE PACKER];
* used to copy data between bitfield bits/variables and variable list, and to count matches with mask
* 'read' means: copy from bitfield to variable list, 'write' means: copy from variable list to bitfield
* bitfield: consecutive (next to each other) 'v' variables handled bitwise&continuosly (15 v vars=480 bits, and so on..)
* variable list: consecutive (next to each other) 'v' variables handled as separate 32 bit signed integers.

* data will be copied between bitfield v1 variable b1 bit, bit sequence lenght L,
* and bitfied/variable list v2 variable (b2 bit, same L lenght), number of repetitions set in SC counter,
* and search may be performed to find "MO"th occurence of "M" bit sequence, or total number of matches.

* lookup table to store 2^0..2^31 in v1460-v1491, READ ONLY
* You may also use v1460-v1491 directly (but, as read only!!): **VRv10:&v1480 will select bit 20 (1480-1460=20),
* or  **VRv9:S1460 +v8  --> v9=2^v8. / to select bit v8 /
* Bit macro was modified to use this methode in WoG 3.59.

* build6:
* - FU644 Debug mode(x1= -1): direct bit to bit copy between bitfields.
* - Enhanced Counter: x4/x5 added to give back position of x4th occurence of M mask on bitfield in vx5.

* pre-release bugfixes:

* bugfix1: vx5 was set until (x4+1)th occurence,
* one "&" check was missing (counter was incremented this turn?), all related modes

* bugfix2: Mode5: "Is it last turn?" check now placed before    "Exit if Counter only mode"
* bugfix3: Mode0/1: pointer v315 was incremented before match count, but was used in it, y92 reset was missing

* BUGFIX4: Mode3: pointer was used instead of value for shifting. y7=1460+v314, instead of v(1460..)
* BUGFIX5: Mode5's template was Mode3, including the bug above. Corrected.
* BUGFIX6: Mode6: Completely rewritten. Wrong methode was used. ;)
* BUGFIX7: Mode6: wrong offset was used for masks 1460 ->1459
* BUGFIX8: Mode6: sign check was incorrect, "=0 xor =1" instead of "=0 xor <>0", without going down to bit0.
* variable lenght limited to 31 bit, so sign value always non-negative -> "=0 xor >0" used.

**
* build5 (first external beta release)
* enhancements: 'Match count only' mode (x3). FU 647: signed integer conversion.
*
*build4
* patch1: lookup table moved from v1420-1451 to v1460-1491, there was a sharing violation.
* bugfix1: FU645 part2 check: exit if y3<0 instead of y3<1.  (NOT ">0" means "<1" for integers)
------
*Overview of used variables:  /*X means pointer to X; -- means not used/
             .
; must be set, except '--' and MC:
      Debug; normal..             .
 *FU:  644;  644   645   646   647   remarks
*v313  v1*   v1*   v1*   v1*   --    bitfield variable pointer: actual v1 variable
*v314  b1*   b1*   b1*   b1*   --    starting bit of bit sequence in v1, can be out of [0,31] (handled)
*v315  v2*   v2*   v2*   v2*   v2*   variable sequence pointer: actual v2 variable
*v316  SC    SC    SC    SC    SC    Step Counter, number of rounds to be executed (compared with x16)
*v317  b2*   --    L*    L     L     L: actual bit sequence Lenght (pointer*, or value: 1 to 31), b2 bit pos. in v2
*v318  S1    S1    --    S1    S2    Shift per turn, S1: added to v314 (shifting b1), S2: added to v315(shifting v2)
*v319  MC    MC    --    MC    MC    Match Counter: counts unpacked value matches with x2.

**x1   -1    0/1   2/3   4/5   6     Mode: selects functionality(read/write for FU 644-647, or FU644 debug mode)
;optional:
**x2   M*    M*    --    M     M     Match Counter selection Mask: add +1 to MC, if actual read value= M value
**x3   0/x   0/x   --    0/x   0/x   Write Enabled/Disabled: Output will be written to target or not. Disabled if <>0.
**x4   MO    MO    --    MO    MO    Mask Occurence:search for position of "MO"th occurence of M.
**x5   MP*   MP*   --    MP*   MP*   Match Position: position of "MO"th occurence of M(x16-1) will be written to vx5.
**x6   S2    --    --    --    --    Shift per turn, S2: added to v317, additional shifting of b2 (not v2)

 ** additional remarks:

** SC: Originally it's value was changed during execution, but now compaired with x16 from build3.
** So it isn't really a counter, but name remained.
** x1: Functionality selected with FU number and mode. Read/Write mode values differ for different FUs.
** It is redundant, but more safe, than FU1 mode 0/1, FU2 mode 0/1.. Helps to prevent typos.
** FU names also indicate intended usage: 644: 1 bit flags Read/Write, 645 Composite variables,
** 646 index tables/ sub-variable sequences, 647 signed n-bit<-> signed 32 bit conversion.
** L* Sequence lenght list: set it up with VRvv317:C.. // L sequence lenght value: set up with VRv313:C..
** Sequence Lenght have to be 1-31 bit
** S1,S2: can be negative.SC can be negative.(-x,0 means 1) , b1 can be <0 or >31.
** x2: M* means 0/not0, M means real values compaired. ie.: if read value is 1, M* value<>0(not0), then they match.
** x2: Mode0,4,6: compaires to output values. Mode1,5,7: compairs to input values. So always to 'unpacked' values.
** x2,4,5: I.F MC=x4 A.N.D x5>0 T.H.E.N vx5 = x16 -1 (=offset). If there is no x4th match, then no change to vx5.
** (Hint: set up vx5 to -1) (x4 and x5 considered as 'not used', if You don't set x5>0.)
** x3: 0 by default (Write Enabled), default if not set. Write Disabled if <>0.

** v1460-v1491: read only lookup table to store 2^0..2^31. (can be shared with other scripts as read only)
---

** Usage: ~~DO64'$1'/1/'$2'/1:P'$3'; where '$1'=4,5,6,7; v316<='$2'<=999; and $3=0/1,2/3,4/5 or 6/7 for read/write
** exemple: ~~VRv313:C.. followed by ~~DO 645/1/999/1:P2; means read user defined composite variables
** You can always set '$2' to 999, but You can lower it for security reasons.
** Bitwise packer may overwrite foreign variables, if You mistype v316 counter value.
* Please, double check VR:C settings at least for v313..v317. Thanks.
**
* FU644
* Mode-1: direct copy between bitfields, from v1 b1 to v2 b2, bit by bit. Can be used as debug mode.
* The x6/S2 additional shift enables you to copy bits (amongst others) in reverse direction.  (just for fun)
* Mode0 read bits from bitfield, and write to variable sequence
* Mode1 read ZERO/NOT ZERO state of variables, and write bitfield bits accordingly  (NOT ZERO means 1)
** Count matches with mask: 0/not 0.

* FU645
* Mode2 read user defined bit sequences from bitfield, and write to variable sequence
* Mode3 read bit sequences from variable sequence, and write them to bitfield
** Variable lenght list used. ( Match counter not used.We should not sum up different types of variables.)

* FU646
* Mode4 read user defined bit sequences with fixed lenght and shift, and write to variable sequence,
** and count number of matches in v319.
* Mode5 read bit sequences with fixed lenght and shift from variables, and write them to bitfield,
** and count number of matches in v319.
*** So if you start to read from v24 bit15 with lenght 3, shift 45,
*** then sequence lenght will be 3 bit, and next 3 bit sequence will start at v24b15 +45= v25 bit28

* FU647
* Mode6 convert user defined n bit signed integers to 32 bit signed integers, and count number of matches in v319.
** n bit signed integers have to be stored in separate variables. So copy out from bitfield with FU 645/646,
** and then convert with FU 647.  Matches will be counted to 32 bit integer forms.

HINTs;
* FU 644 is intended to read/write 1 bit 'system flags' stored in v variables.
* Mode-1: direct copy of bits. (FU645/646 is faster and easier-to-use for longer bit sequences)

* FU644 x4, x5: (Hipothetical) Exemple of usage: Let say, that You always want to offer a secret skill to Hero during
* levelups, if "Heroes can have 10 skills" option is active.
* So we want to choose a skill at level0 randomly. Now we check all secondairy skill's level one by one in a loop,
* and store "don't have skill x/have skill x" info by setting v24 bit x to "0/1" (using bit macro, or FU 644).
* Now we count y= number of occurencies of "0" on v24 bits 1-28, that means number of not learned skills. (out of 28)
* If number of '1'-s (equals with 28-y :) is less, then max. amount of skills allowed, then continue..
* Just generate an x =RND(y) number(from 1 to y). Let say, that now x=9.
* So we want to offer the 9th not learned skill to hero, thus we need
* the position of 9th "0" on bitfield v24 bits 1-28..
* so we need to use FU644 with x1=0 (read Mode), x2=0 (count '0's), x4=9 (search 9th zero), &x5=your variable nr.
* Exemple: v313..v319: 24/1/600*/28/0/1/0, x1..x5: 0/0/1*/9/600*. Write disabled(x3=1), so You can reuse v600.
* You will have the number of skill to offer in v600.

* FU 645 is intended to read/write user defined composite variables with several(different) sub-variables.
** (hypotethical) Exemple 1:
** "Caravan to Town" variable consists of (owner, creature type, quantity, experience, timer, Warlords Banner flag),
** sub-variable lenghts are, let say: 3,8,10,13,4,1 bits.  39 bits in total.
** It makes no sense to count matches with different type of (sub-)variables.

* FU 646 is intended to read/write a given sub-variable sequence of user defined composite variables,
** or variable sequence in an index table (variables of the same type).
** (hypotethical) Exemple 1: Arrival times of Caravans for a given Town: subtype timer(lenght=4bit),
** shift= lenght of "Caravan variable" (39 bits, see above),max. 7 Caravans per Town, so (lenght=4, shift=39, counter=7)
** Exemple 2: Number of potions owned by actual hero: max. 7 potion/type, 6 type ->6* 3bit in w variable.
** First you have to copy out the w variable to a v variable, then everything as usual. (lenght=3,shift=3, counter=6)
** Exemple 3: Lookup table for 'Caravans': max. 7 caravans per target Town, actual number stored in a 48*3bit table.
** /max. 48 Towns per map, 3 bit to store 0..7 values, so a 144 bit long bitfield needed/(lenght=3,shift=3,counter=48)

* FU 647: Convert n-bit signed integers to 32 bit signed.    (hypotethical) Exemple 1:
** Let say, that You want to store number of won battles minus number of lost battles for every hero;
** and You want to store values in packed form. Let say, values from -128 to +127,
** so You want to store 8 bit signed integers in w vars with bitwise packer.
** Reading out values: copy w to v variable, read out range with FU 645 Mode2 or FU 646 Mode4, and convert
** value with FU647 Mode6: read 8-bit signed. After the battle You change it (+-1),
** and copy back v to w variable.

--------------------------------------------------------------------------------
BITWISE PACKER SETUP;  lookup table to calculate 2^x (x:0-31) placed on v1460-v1491 for speedup
!#VRv1460:C1/2/4/8/16/32/64/128/256/512/1024/2048/4096/8192/16384/32768;
!#VRv1476:C65536/131072/262144/524288/1048576/2097152/4194304/8388608/16777216/33554432/67108864/134217728/268435456/536870912/1073741824/-2147483648;
** v1491= +2147483648 also tested ok, but -2147483648 is used ..    can be shared as read-only
--------------------------------------------------------------------------------
* y1..y10: "more important" values, y90-100:temporary
* counter(Last Turn?) checks: "<="  instead of "=" for safety reasons

*FU 644;
* v313 pointer: starting variable of bitfield (v1)
* v314 pointer: starting bit of bitfield  (b1)
* v315 pointer: starting variable of variable list(v2)
* v316 value: step counter (total number of executions), MAX. 999  (sc)
* v317 not used (lenght always 1) // Debug mode: starting bit of bitfield2 (b2)
* v318 value: Shift per turn  (S1)
* v319 not used, or match counter   (nu, MC)   HAVE TO BE RESETED MANUALLY. Hint:set to '0'.
** vx5: Match position (MP). Hint: always set to '-1'
** x1: mode, including read/write sub-mode
** x2: match counter selection mask (0 or not 0, if used) /0 by default/  (M)
** x3: write enabled(=0)/disabled(<>0) for 'match count only' mode, enabled by default (WE)
** x4: search for x4th occurence of M.
** x5: Match Position output pointer (MP*), position of x4th occurence of M will be written to vx5, if x5>0.
*  , calculated as x16-1. x16 starts with 1.
** x6: value added to v317, additional b2 shifting. (default Mode-1 b2 shift is 1 bit)

** Match Counter is always ON.

MODE-1, DEBUG MODE;  Copied out from Mode 0/1, changes marked with ***
; copy bit values one by one from bitfield1 var1 bit1 to bitfield2 var2 bit2, until x16<step counter  (v1 b1 -> v2 b2)
; setup v313-v319 with VR:C and then ~~DO644/1/999/1:P-1;     v317=bit2

!?FU644;
!!FU&x1<>-1:E;   ***

; offset handling: actual v1,b1 / v2,b2
!!VRy90:Sv314 :32; dv1
!!VRv314:%32;b1
!!VRv313:Sdy90;v1
* y90 free                 *** ->
!!VRy90:Sv317 :32; dv2
!!VRv317:%32;b2
!!VRv315:Sdy90;v2
* y90 free                -> ***

; create selection mask for var v1 bit b1
!!VRy90:S1460 +v314;
!!VRy1:Svy90;  mask
*** y2 inverted mask not needed (copy to another bitfield means read mode only)
; select b1
!!VRy3:Svv313 &y1;
!!VRy3&y3<>0:S1;
* y1-2,y90 free

; create selection mask for var v2 bit b2    *** ->
!!VRy90:S1460 +v317;
!!VRy1:Svy90; mask
!!VRy2:S-1 -y1; inverted mask
; select b1
!!VRvv315:&y2; target reset
!!VRvv315&y3=1: |y1; write to target
* y1-2, y90 free

; increment pointers for next turn
!!VRv314:Sdv318;b1
!!VRv317:Sd1 +x6;   b2                     -> ***
; check step counter
!!VRx16&v316<=x16:S999; Is it last turn?
; Match count (0, or not 0)
!!VRy91&x2<>0:S1; selection mask
!!VRv319&y3=y91:Sd1; count

; x4th Match position
!!VRvx5&x4=v319/x5>0/y3=y91:Sx16 -1; set position, if x5 is in use, and x4th occurence just found

--------------------------------------------------------------------------------
MODE0;
; copy bit values from bitfield var1 bit1 to variable sequence starting with vv317, until x16<step counter
; setup v313-v319 with VR:C and then ~~DO644/1/999/1:P0;
MODE1;
;write bits to bitfield, if v2 not 0, until x16<step counter
; setup v313-v319 with VR:C and then ~~DO644/1/999/1:P1;

!?FU644;                                                                          *
!!FU|x1<0/x1>1:E;

; offset handling: actual v1,b1
!!VRy90:Sv314 :32; dv1
!!VRv314:%32;b1
!!VRv313:Sdy90;v1
* y90 free
; create selection mask for var v1 bit b1
!!VRy90:S1460 +v314;
!!VRy1:Svy90;
!!VRy2:S-1 -y1; inverted mask
; select b1
!!VRy3:Svv313 &y1;
!!VRy3&y3<>0:S1;
; read
!!VRvv315&x1=0/x3=0:Sy3;
; write
!!VRy1&vv315=0:S0; check if zero
!!VRvv313&x1=1/x3=0:&y2 |y1; reset b1 bit, and set if vv315 not zero
* 0/not0 stored in y3 (read) and y1 (write)

; increment pointers for next turn
!!VRv314:Sdv318;b1
!!VRv315:Sd1;   v2
; check step counter
!!VRx16&v316<=x16:S999; Is it last turn?
; Match count (0, or not 0)
!!VRy91&x2<>0:S1; selection mask
* read value: y3
* write value: y92
!!VRy92:S0; reset
!!VRy92&x1=1/y1<>0:S1; v2 is 0, or not 0?
!!VRv319&y3=y91/x1=0:Sd1; count if read
!!VRv319&y92=y91/x1=1:Sd1; count if write
; x4th Match position
!!VRvx5&x4=v319/x5>0/y3=y91/x1=0:Sx16 -1; set position, if x5 is in use, and x4th occurence just found and read mode
!!VRvx5&x4=v319/x5>0/y92=y91/x1=1:Sx16 -1; set position if write mode
--------------------------------------------------------------------------------
*FU 645
* v313 pointer: starting variable of bitfield (v1)
* v314 pointer: starting bit of bitfield  (b1)
* v315 pointer: starting variable of variable list(v2)
* v316 value: step counter (total number of executions), MAX. 999  (sc)
* v317 pointer: variable lenght(L) list
* v318 not used
* v319 not used
** x1: mode, including read/write sub-mode

** Remark: This FU is used to copy a set of different variables(= user defined data type),
** so Match counter makes no sense.

MODE2;
; read bit sequence FROM variable vv313 bit v314, lenght vv317, and write output TO vv315,
*until  x16< v316 step counter.   /v# -> vv# pointers will be shifted for next round/
; setup v313-v319 with VR:C and then ~~DO645/1/999/1:P2;

!?FU645;
!!FU&x1<>2:E;
; offset handling: actual v1,b1
!!VRy90:Sv314 :32; dv1
!!VRv314:%32;b1
!!VRv313:Sdy90;v1
* y90 free
; copy source values
!!VRy1:Svv313; v1
!!VRy2:Svv317; L
; actual bit sequence is in one, or two variables?
!!VRy3:Sv314 +y2 -32; calculate next var starting bit=lenght2 if two parts (y3>0)
!!VRy2&y3>0:-y3; L1
; first step: down to bit0
!!VRy90:S1460 +v314; lookup 2^b1
!!VRy4:Svy90;
*y90 free

*down to bit0* there are no unsigned 32 integers in WoG; going  around the problem..
!!VRy5:Sy1 &2147483647 :y4; select bit0-30. bit31 not shifted now(-10:32=0, instead of 67108864..shifted bit31 missing)
!!VRy90:S2147483648 :y4; select bit31. playing with signed 32 integer abilities. 2^31 handled as -2^31, not -0 :))
* remarks: y90<0, so if y1<1, all bits above shifted bit31 will become 1, but later we have a selection mask.

!!VRy5&y1<0:|y90; copy parts together. Now shifting is ok.
*y90 free
; selection mask for bit sequence, calculate 2^L1-1
!!VRy90:S1460 +y2;
!!VRy6:Svy90; needed for part2
!!VRy7:Sy6 -1; mask
!!VRvv315:Sy5 &y7; OUTPUT PART1
* y1,2,4,5,7,90 free

;increment pointers for next turn
!!VRv314:Sdy2; b1+L1
!!VRv315&y3<1:Sd1; v2 pointer*  "not >0" equals  with "<1" (y3 is integer)
!!VRv317:Sd1;    L pointer
; counter
!!VRx16&v316<=x16:S999; Is it last turn?
!!FU&y3<1:E;

** PART2
; lenght2 in y3, v1= v313 +1, output2 offset in y6, v315 actual
!!VRy90:Sv313 +1; v1+1 pointer
; select sequence part2, calculate 2^L2-1
!!VRy91:S1460 +y3;
!!VRy92:Svy91 -1; mask
!!VRy4:Svy90 &y92 *y6; OUTPUT PART2 (shifted up)
!!VRvv315:|y4; OUTPUT

;increment pointers for next turn
!!VRv314:Sdy3; b1+L2
!!VRv315:Sd1; v2 pointer*

---
MODE3;
; write bit sequence TO variable vv313 bit v314, lenght vv317, FROM vv315, until  x16< v316 step counter
* /v# -> vv# pointers will be shifted for next round/
; setup v313-v319 with VR:C and then ~~DO645/1/999/1:P3;
** Variable boundary inside bit sequence enabled,
** for exemple: sequence from v600 bit 24 to v601 bit 7: v313 600, v314 (b1) 24, Lenght vv317=16
** Max. allowed sequence lenght is 31 bit, so source bit31 shift not needed.

!?FU645;
!!FU&x1<>3:E;
; offset handling: actual v1,b1
!!VRy90:Sv314 :32; dv1
!!VRv314:%32;b1
!!VRv313:Sdy90;v1
* y90 free
; copy source&target values
**VRy1:Svv313; v1  not needed
!!VRy2:Svv317; L
!!VRy1:Sy2; copy for inc
!!VRy4:Svv315; v2

; sequence will be in one, or two variables?
!!VRy3:Sv314 +y2 -32; calculate next var starting bit=lenght2 if two parts  L2
!!VRy2&y3>0:-y3; L1
; preparations for part1
* calculate 2^L1-1 for 0x0 selection mask, *2^v314 to shift in position
!!VRy90:S1460 +y2;
!!VRy5:Svy90; needed for part2 for source shifting
!!VRy6:Sy5 -1; 0x0 mask  2^L1-1

!!VRy90:S1460 +v314; ** S1460+v314 pointer                                           ***
!!VRy7:Svy90;      shift
*y90 free
; write part1:
* create 101 mask to target region reset, OR it with shifted source
* remarks: yyy AND 101= y0y, OR 0x0 = yxy, where yyy target, xxx source, selected region to write: 0x0.
!!VRy8:Sy4 &y6 *y7; shifted source 0x0
!!VRy90:Sy6 *y7; shifted  010 mask
!!VRy9:S-1 -y90; 101 mask
*y90 free
!!VRvv313:&y9 |y8;     part1 OUTPUT

;increment pointers for next turn
!!VRv314:Sdy1; b1+L * not used in part2
!!VRv315:Sd1; v2 pointer *not used in part2
!!VRv317:Sd1;    L pointer
; counter
!!VRx16&v316<=x16:S999; Is it last turn?
!!FU&y3<1:E; exit if only one part
** y1-y2,y6-y9 free;  source in y4, y3 lenght2, y5 2^L1

** PART2
; preparations for part2
!!VRy90:S1460 +y3; 2^L2
!!VRy1:Svy90 -1; 010 mask (read)
!!VRy2:S-1 -y1;  101 mask  (reset)
!!VRy6:Sv313 +1; target2 pointer
; write part2
* Down to bit0 with source2, selection mask, reset target2, OR with source2
!!VRy4::y5 &y1; down to bit0 & select
!!VRvy6:&y2 |y4; reset target2, OR with selected source part; part2 OUTPUT

--------------------------------------------------------------------------------
*FU 646
* v313 pointer: starting variable of bitfield (v1)
* v314 pointer: starting bit of bitfield  (b1)
* v315 pointer: starting variable of variable list(v2)
* v316 value: step counter (total number of executions), MAX. 999  (sc)
* v317 value: variable lenght(L)
* v318 value: Shift per turn  (S)
* v319 match counter   (MC)   HAVE TO BE RESETED MANUALLY.
** vx5: Match position (MP). Hint: always set to '-1', if you used it
** x1: mode, including read/write sub-mode
** x2: match counter selection mask
** x3: write enabled(=0)or disabled(<>0) for 'counter only' mode (WE)
** x4: Match Occurence
** x5: Match Position pointer (MP*). Position (x16 -1) of 'MO'th occurence of M will be written to vx5, if x5>0.

** Match Counter is always ON.

MODE4; biggest part copied out from mode 2, changes marked with ***
; read bit sequence FROM variable vv313 bit v314, lenght v317, and write output TO vv315,
*until  x16< v316 step counter.   /v# -> vv# pointers will be shifted for next round/
; setup v313-v319 with VR:C and then ~~DO646/1/999/1:P4/SM/WE;

!?FU646;
!!FU&x1<>4:E;            ***
; offset handling: actual v1,b1
!!VRy90:Sv314 :32; dv1
!!VRv314:%32;b1
!!VRv313:Sdy90;v1
* y90 free
; copy source values
!!VRy1:Svv313; v1
!!VRy2:Sv317; L               *** Am I lazy? :)
; actual bit sequence is in one, or two variables?
!!VRy3:Sv314 +y2 -32; calculate next var starting bit=lenght2 if two parts
!!VRy2&y3>0:-y3; L1
; first step: down to bit0
!!VRy90:S1460 +v314; lookup 2^b1
!!VRy4:Svy90;
*y90 free

*down to bit0* there are no unsigned 32 integers in WoG; going  around the problem..
!!VRy5:Sy1 &2147483647 :y4; select bit0-30. bit31 not shifted now(-10:32=0, instead of 67108864..shifted bit31 missing)
!!VRy90:S2147483648 :y4; select bit31. playing with signed 32 integer abilities. 2^31 handled as -2^31, not -0 :))
* remarks: y90<0, so if y1<1, all bits above shifted bit31 will become 1, but later we have a selection mask.

!!VRy5&y1<0:|y90; copy parts together. Now shifting is ok.
*y90 free
; selection mask for bit sequence, calculate 2^L1-1
!!VRy90:S1460 +y2;
!!VRy6:Svy90; needed for part2
!!VRy7:Sy6 -1; mask
!!VRy8:Sy5 &y7;                     *** speeding up match count, OP1 temp value
!!VRvv315&x3=0:Sy8; OUTPUT PART1              *** write enabled?
* y1,2,4,5,7,90 free

;increment pointers for next turn
*** NO v314 shift with L1
!!VRv314:Sdv318; because shift value is set manually  (v314 not used in part2)
!!VRv315&y3<1:Sd1; v2 pointer*  "not >0" equals  with "<1" (y3 is integer)
*** NO v317 shift

; Match Count, PART1   ***
!!VRv319&y8=x2/y3<1:Sd1;
; x4th Match position, PART1 ***
!!VRvx5&x4=v319/x5>0/y3<1/y8=x2:Sx16 -1; set position, if x5 is in use, only one part and x4th occurence just found

; step counter
!!VRx16&v316<=x16:S999; Is it last turn?
!!FU&y3<1:E;

** PART2
; lenght2 in y3, v1= v313 +1, output2 offset in y6, v315 actual, output1 in y8
!!VRy90:Sv313 +1; v1+1 pointer
; select sequence part2, calculate 2^L2-1
!!VRy91:S1460 +y3;
!!VRy92:Svy91 -1; mask
!!VRy4:Svy90 &y92 *y6; Output Part2 (shifted up)
!!VRy9:Sy8 |y4;    *** speeding up match count, final OP temp value
!!VRvv315&x3=0:Sy9; OUTPUT                        *** write enabled?

;increment pointers for next turn
*** NO v314 shift with L2
!!VRv315:Sd1; v2 pointer*

; Match Count, PART2   ***
!!VRv319&y9=x2:Sd1;
; x4th Match position, PART2 ***
!!VRvx5&x4=v319/x5>0/y9=x2:Sx16 -1; set position, if x5 is in use, and x4th occurence just found

---
MODE5; biggest part copied out from Mode3, changes marked with ***
; write bit sequence TO variable vv313 bit v314, lenght v317, FROM vv315, until  x16< v316 step counter
* /v# -> vv# pointers will be shifted for next round/
; setup v313-v319 with VR:C and then ~~DO646/1/999/1:P5;
** Variable boundary inside bit sequence enabled,
** for exemple: sequence from v600 bit 24 to v601 bit 7: v313=600, v314 (b1) 24, Lenght v317=16
** Max. allowed sequence lenght is 31 bit, so source bit31 shift not needed.

!?FU646;
!!FU&x1<>5:E;          ***

; Match count         *** ->
!!VRv319&vv315=x2:Sd1;
; x4th Match position
!!VRvx5&x4=v319/x5>0/vv315=x2:Sx16 -1; set position, if x5 is in use, and x4th occurence found
; step counter
!!VRx16&v316<=x16:S999; Is it last turn?

!!VRv315&x3<>0:Sd1; increment pointers if write disabled
!!FU&x3<>0:E;       -> *** exit if write disabled

; offset handling: actual v1,b1
!!VRy90:Sv314 :32; dv1
!!VRv314:%32;b1
!!VRv313:Sdy90;v1
* y90 free
; copy source&target values
**VRy1:Svv313; v1  not needed
!!VRy2:Sv317; L           ***
** copy y2 to y1 for inc ***
!!VRy4:Svv315; v2

; sequence will be in one, or two variables?
!!VRy3:Sv314 +y2 -32; calculate next var starting bit=lenght2 if two parts  L2
!!VRy2&y3>0:-y3; L1
; preparations for part1
* calculate 2^L1-1 for 0x0 selection mask, *2^v314 to shift in position
!!VRy90:S1460 +y2;
!!VRy5:Svy90; needed for part2 for source shifting
!!VRy6:Sy5 -1; 0x0 mask  2^L1-1
!!VRy90:S1460 +v314; shift
!!VRy7:Svy90;
*y90 free

; write part1:
* create 101 mask to target region reset, OR it with shifted source
* remarks: yyy AND 101= y0y, OR 0x0 = yxy, where yyy target, xxx source, selected region to write: 0x0.
!!VRy8:Sy4 &y6 *y7; shifted source 0x0
!!VRy90:Sy6 *y7; shifted  010 mask
!!VRy9:S-1 -y90; 101 mask
*y90 free
!!VRvv313:&y9 |y8;     part1 OUTPUT

;increment pointers for next turn
!!VRv314:Sdv317; b1+v317 * not used in part2 ***
!!VRv315:Sd1; v2 pointer *not used in part2
**   L not in pointer  ***

!!FU&y3<1:E; exit if only one part
** y1-y2,y6-y9 free;  source in y4, y3 lenght2, y5 2^L1

** PART2
; preparations for part2
!!VRy90:S1460 +y3; 2^L2
!!VRy1:Svy90 -1; 010 mask
!!VRy2:S-1 -y1;  101 mask
!!VRy6:Sv313 +1; target2 pointer
; write part2
* Down to bit0 with source2, selection mask, reset target2, OR with source2
!!VRy4::y5 &y1; down to bit0 & select
!!VRvy6:&y2 |y4; reset target2, OR with selected source part; part2 OUTPUT

--------------------------------------------------------------------------------
*FU 647: Conversion from n-bit to 32bit signed values.
* bits(0..n-2) hold value + bit(n-1) for sign -> n>=2
* sign bit set alone = -2^n

* v313  not used
* v314  not used
* v315 pointer: starting variable of variable list(v2)
* v316 value: step counter (total number of executions), MAX. 999  (sc)
* v317 value: variable lenght(L), 2-31
* v318 value: Shift per turn  (S)  FOR v2, counted in 32 bit variables
* v319 match counter   (MC)   HAVE TO RESET MANUALLY.
** vx5: Match position (MP). Hint: always set to '-1', if you used it
** x1: mode, including read/write sub-mode
** x2: match counter selection mask
** x3: write enabled(=0)or disabled(<>0) for 'counter only' mode (WE)
** x4: Match Occurence
** x5: Match Position pointer (MP*).

** Match Counter is always ON.
* Please, don't forget to set and check v318.

*(BS)00000..00(AS)xxxxxx

MODE6; convert n bit signed integers to 32 bit signed integers.

!?FU647;
!!FU&x1<>6|v317<2/v317>31:E;
; convert
!!VRy1:Svv315; read in
!!VRy90:S1459 +v317;                                                     ***
!!VRy92:Svy90;select sign bit    As mask  0x0
!!VRy91:Sy92 -1; select range   A mask  0x0

!!VRy93:S-1 -y91; select upper range  B mask 0x0
!!VRy2:Sy1 &y92; sign bit

!!VRy1&y2=0:&y91; fill up zeroes  for >=0
!!VRy1&y2>0:|y93; fill up 1's     for <0   (n<32, so y2 bit 31 not set)      ***

!!VRvv315&x3=0:Sy1; write if enabled

; Match count
!!VRv319&y1=x2:Sd1;
; x4th Match position
!!VRvx5&x4=v319/x5>0/y1=x2:Sx16 -1; set position, if x5 is in use, and x4th occurence just found
; Increment pointers
!!VRv315:Sdv318;
; step counter
!!VRx16&v316<=x16:S999; Is it last turn?

* reverse direction: just copy the needed bits ;)

* END of Bitwise Packer *

--------------------------------------------------------------------------------
[smileys]
UPDATE: Thank You for this info below. I will try it out. BTW, what the hack is stealth edit? Am not a native english, and don't want to try it out on this post. OFF, I have spoken.  

UPDATE2: Let see, how it works..

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Yanzhangcan
Yanzhangcan


Known Hero
*Dance*
posted March 11, 2007 07:24 PM

Excellent

In order to make it easier to copy you may want to disable smileys in your text (The red circle with a white x on the left below "Compose Reply")

Other than that good work

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
doom3d
doom3d


Known Hero
Avatar of general Z
posted March 12, 2007 09:24 PM

Some additional info about FU multiplexing..
In WoG 3.58f we don't have IF blocks. ( IF..THEN.. ELSE IF.. END IF)
We also don't have GOTO or GOSUB.
But..

[ IF BLOCK]
!!VRv24&5/6:S10;
!!VRv24&5/-6:S11;
!!VRv24&-5/6:S12;
!!VRv24&-5/-6:S13;
!!VRv24&v313=113|v890=-1/7:S14;
...

!!FU800;

!?FU800&v24=10;
*** code ***

!?FU800&v24=11;
*** code ***
...

!?FU800&v24=14;
[IF block like above]
!!FU801;
*** code ***
...
!?FU801;
----------------
Other possibility:
*** code ***
!!VRv24:S10;
!!FU800;
*** code ***
!!VRv24:S11;
!!FU800;
*** code ***

-------------

That's what I call FU multiplexing. This way You can emulate IF ... THEN GOTO, or SELECT CASE, or use one FU name for 50 different tasks.

This trick was also used in the lib script above.
BTW, Bitwise packer will be released as part of WoG 3.59 with variables and FU names and settings above, so the whole code actually is 3.59 compatible. ;)




 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Yanzhangcan
Yanzhangcan


Known Hero
*Dance*
posted March 19, 2007 06:27 AM

It's usually best if someone suits the popular needs, good thing you managed to make it compatible. Good job

I hope everyone takes the time to contribute to this thread, It makes it easy for those lazy people who enjoy using ERM but can't or don't want to do it themselves.

 Send Instant Message | Send E-Mail | View Profile | Quote Reply | Link
Jump To: « Prev Thread . . . Next Thread »
Post New Poll    Post New Topic    Post New Reply

Page compiled in 0.1032 seconds