{"id":135,"date":"2013-08-06T15:41:33","date_gmt":"2013-08-06T23:41:33","guid":{"rendered":"http:\/\/adamantyr.com\/blog\/?p=135"},"modified":"2013-08-06T15:41:33","modified_gmt":"2013-08-06T23:41:33","slug":"cause-and-effect","status":"publish","type":"post","link":"http:\/\/www.adamantyr.com\/index.php\/2013\/08\/06\/cause-and-effect\/","title":{"rendered":"Cause And Effect"},"content":{"rendered":"<p>So, I finished up the changes to my effects code&#8230; although it remains to plug it in and integrate it with the main code base! I thought I would take this opportunity to show what was done and why&#8230;<\/p>\n<p>Effects in the CRPG are, essentially, things that alter the status of a player, a monster, or the party in itself. This includes dealing wound damage, setting a counter for a spell effect, increasing the party&#8217;s rations, and so forth. There are around 40 effects in the game in total.<\/p>\n<p>Originally, the code I wrote to process the effects was linear; each effect was a separate routine, and it used a passed register for the &#8220;address&#8221; to update, as well as values in a few extra registers. (For party effects, no passed register is needed, since there&#8217;s only one party ever.) Here&#8217;s a sample of how it looked:<\/p>\n<pre>* Effects subroutine\n* R0 = Variable one\n* R3 = Variable two\n* R2 = STATE location pointer (player or monster)\n* R1 = Effect\nEFFCTS MOV\u00a0 R11,*R10+\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SLA\u00a0 R1,1\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 @EFCASE(R1),R4\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 B\u00a0\u00a0\u00a0 *R4\n\n* Reduces R0 fatigue\nEF1\u00a0\u00a0\u00a0 AI\u00a0\u00a0 R2,4\n* Reduces R0 wounds\nEF0\u00a0\u00a0\u00a0 S\u00a0\u00a0\u00a0 R0,*R2\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JGT\u00a0 EF0A\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CLR\u00a0 *R2\nEF0A\u00a0\u00a0 B\u00a0\u00a0\u00a0 @SUBRET\n\n* Inflicts R0 fatigue\nEF3\u00a0\u00a0\u00a0 AI\u00a0\u00a0 R2,4\n* Inflicts R0 wounds\nEF2\u00a0\u00a0\u00a0 A\u00a0\u00a0\u00a0 R0,*R2\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 B\u00a0\u00a0\u00a0 @SUBRET\n\n* Effects case array\nEFCASE DATA EF0,EF1,EF2,EF3,EF4,EF5,EF6,EF7\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA EF8,EF9,EF10,EF11,EF12,EF13,EF14,EF15\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA EF16,EF17,EF18,EF19,EF20,EF21,EF22,EF23\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA EF24,EF25,EF26,EF27,EF28,EF29,EF30,EF31\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA EF32,EF33,EF34<\/pre>\n<p>So what&#8217;s the problem with that? Nothing&#8230; except that by the end, after crunching all the routines together along with the large reference array for each function (EFCASE), the routines take up around 426 bytes of space. Not a HUGE amount of space, even in a 32k system, but fairly significant. It also is hard to expand and maintain; I&#8217;ve had to revise effects multiple times and every time has been a hassle.<\/p>\n<p>So, my new approach was to create an effects processing method. First, it&#8217;s in a separate workspace so that the registers can&#8217;t be corrupted by prior called routines. Second, all of the uniqueness of each effects is defined in a data structure, not as logic checks inside linear code. There&#8217;s more overhead writing a more &#8220;generic&#8221; processing system, but if your data is tight enough you eventually get more out of it.<\/p>\n<p>The new code looks like this:<\/p>\n<pre>* Effects subroutine\n*\n* Inputs\n* \n* @WORK - Effect #\n* @WORK+2 - Array location for player\/monster\n* @WORK+4 - Value #1\n* @WORK+5 = Value #2 (or #1 overflow)\nEFFCTS DATA AWS,EFC0\nEFC0\u00a0\u00a0 LI\u00a0\u00a0 R0,EFCDAT\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Get effects data into R0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 LI\u00a0\u00a0 R9,60\nEFC1\u00a0\u00a0 CB\u00a0\u00a0 @WORK,*R0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Check if current effect is in record\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JNE\u00a0 EFC4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * If not, jump to loop\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 INC\u00a0 R0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Increment R0 to type byte\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOVB *R0+,R1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Copy type byte to R1\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 R1,R2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Copy type byte to R2\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 R1,R3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Copy type byte to R3\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ANDI R2,&gt;1000\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Get player\/party bit\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JNE\u00a0 EFC2\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 @WORK+2,R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Copy player\/monster state to R4\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC3\nEFC2\u00a0\u00a0 LI\u00a0\u00a0 R4,PARTY\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Copy party state to R4\nEFC3\u00a0\u00a0 AB\u00a0\u00a0 *R0+,@&gt;8389\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Add Offset to R4 low-byte\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ANDI R3,&gt;2000\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Get byte\/word bit\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ANDI R1,&gt;0F00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SRL\u00a0 R1,8\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 @EFCASE(R1),R2\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 B\u00a0\u00a0\u00a0 *R2\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\nEFC4\u00a0\u00a0 AI\u00a0\u00a0 R0,4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Move to next record\nEFC5\u00a0\u00a0 DEC\u00a0 R9\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Decrease effect count\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JNE\u00a0 EFC1\nEFC6\u00a0\u00a0 RTWP\n\n* Effect \"is zero\"\nEFZERO INC\u00a0 R0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set R0 to next record\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CB\u00a0\u00a0 @ZERO,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Check if target value is zero\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JEQ\u00a0 EFC5\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * If so, go to next record\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Otherwise skip next record\n\n* Effects add\nEFADD\u00a0 INC\u00a0 R0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set R0 to next record\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 R3,R3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Word or byte operation?\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JEQ\u00a0 EFADD1\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 A\u00a0\u00a0\u00a0 @WORK+4,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Add word value\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\nEFADD1 AB\u00a0\u00a0 @WORK+4,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Add byte value\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\n\n* Effects subtract\nEFSUB\u00a0 INC\u00a0 R0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set R0 to next record\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 R3,R3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Word or byte operation?\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JEQ\u00a0 EFSUB1\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 S\u00a0\u00a0\u00a0 @WORK+4,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Subtract word value\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JLT\u00a0 EFSUB3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * If negative, clear to 0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\nEFSUB1 SB\u00a0\u00a0 @WORK+4,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Subtract byte value\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JLT\u00a0 EFSUB2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * If negative, clear to 0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\nEFSUB2 MOVB @ZERO,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set to 0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\nEFSUB3 CLR\u00a0 *R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set to 0\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\n\n* Effect set\nEFSET\u00a0 INC\u00a0 R0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set R0 to next record\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 R3,R3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Word or byte operation?\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JEQ\u00a0 EFADD1\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MOV\u00a0 @WORK+4,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set word value\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\nEFSET1 MOVB @WORK+4,*R4\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set byte value\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\n\n* Effect clear\nEFCLR\u00a0 MOVB *R0+,R3\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 SRL\u00a0 R3,8\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Set R3 to count of bytes to clear\nEFCLR1 MOVB @ZERO,*R4+\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 * Clear location\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DEC\u00a0 R3\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JNE\u00a0 EFCLR1\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 JMP\u00a0 EFC5\n\n* Effects cases\nEFCASE DATA EFADD,EFSUB,EFSET,EFCLR,EFZERO\n\n* Effects data\nEFCDAT DATA &gt;0022,&gt;0000\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0122,&gt;0400\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0220,&gt;0000\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0320,&gt;0400\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0424,&gt;0000\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0522,&gt;0000\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0522,&gt;0400\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0632,&gt;1C00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0730,&gt;1C00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0802,&gt;0F00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0902,&gt;1300\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0902,&gt;1400\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0902,&gt;1600\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0A06,&gt;1E01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0B06,&gt;1F01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0C06,&gt;0816\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0D14,&gt;0700\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0D10,&gt;1401\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0E10,&gt;1500\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;0F10,&gt;1600\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1010,&gt;1700\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1100,&gt;0800\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1106,&gt;0901\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1200,&gt;0900\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1206,&gt;0801\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1300,&gt;0A00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1306,&gt;0B01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1400,&gt;0B00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1406,&gt;0A01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1500,&gt;0C00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1506,&gt;0D01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1600,&gt;0D00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1606,&gt;0C01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1700,&gt;0E00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1706,&gt;0F01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1800,&gt;0F00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1806,&gt;0E01\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1900,&gt;1200\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1906,&gt;1301\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1A00,&gt;1300\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1A06,&gt;1201\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1B00,&gt;1400\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1C08,&gt;1C00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1C00,&gt;1500\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1D08,&gt;1C00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1D00,&gt;1600\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1E00,&gt;1700\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;1F00,&gt;1800\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2008,&gt;1C00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2000,&gt;1900\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2100,&gt;1A00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2200,&gt;1B00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2300,&gt;1C00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2408,&gt;1000\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2400,&gt;1100\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2508,&gt;1100\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2500,&gt;1000\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2600,&gt;1D00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2700,&gt;1E00\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 DATA &gt;2800,&gt;1F00<\/pre>\n<p>Each effect is defined with a one or more 4-byte records. The first byte indicates which effect it applies to. The second is the type (adding, subtracting, checking for zero, etc.), whether to do word or byte operations, and whether it&#8217;s a player\/monster or party change. The last two bytes are used for values or ranges to change, depending on the type.<\/p>\n<p>The entire effects array is parsed each time a new effect is done. That is so every case is checked and every record potentially ran. In BASIC this would be a terrible waste, but for assembly language this is fairly fast. Given that the most effects calculated at any time is under a dozen, even a human user wouldn&#8217;t notice it taking much longer than a split second.<\/p>\n<p>I haven&#8217;t crunched the numbers yet, but my initial calculations were very favorable for the size of the new Effects system&#8230; The data table is 240 bytes, and the instructions add around another 128 or so&#8230; It may not be much smaller than the original, but it&#8217;s VERY easy for me to maintain and add new records.<\/p>\n<p>I also need to integrate it better into the combat system itself. My attack routines for melee and ranged are adding wounds directly; they should use the effects system instead. That will allow me to substitute in different effects, such as spells, within the same framework.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, I finished up the changes to my effects code&#8230; although it remains to plug it in and integrate it with the main code base! I thought I would take this opportunity to show what was done and why&#8230; Effects &hellip; <a href=\"http:\/\/www.adamantyr.com\/index.php\/2013\/08\/06\/cause-and-effect\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,4,12],"tags":[],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-coding","category-crpg","category-ti-994a"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pgaeMJ-2b","_links":{"self":[{"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":0,"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.adamantyr.com\/index.php\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}