From 51f406e7f2becd31a4150619f6d94f3626c562eb Mon Sep 17 00:00:00 2001 From: Craig Patterson Date: Fri, 12 Jan 2024 21:51:54 -0600 Subject: [PATCH] General life rulesets working --- Debug/life.bin | Bin 1650 -> 1730 bytes Debug/life.hex | 42 +++++++++--------- Life.wsp | 60 +++---------------------- main.asm | 116 ++++++++++++++++++++++++------------------------- 4 files changed, 84 insertions(+), 134 deletions(-) diff --git a/Debug/life.bin b/Debug/life.bin index 9617ececb8c305f204866570f5de7378a92b2672..a0bea7f4f1f88ff191dada9a7af27d3341a8f76e 100644 GIT binary patch delta 328 zcmeywbBK3?Goy+O3j-q?14H!vvv-*o&OT#e_-Alx1|x$aTwIZdWpX;BlAt6D!#<6t z<&qF-q#53BP_$HH5VTT)^G_8KP*ceXU1scGhICruFvqDt77^4+X;%q%L!#_q15itfUpb7|2f$eS`!!yS4s&eJK z$^v_V#6f{AigSUE0cwXh?c~*9+0*v23csH*DzMlwTs&#VcoE5Xd0jEaf6N*@VhsP7 TP)$1zHtiUyX`81p-(dm(cs*kF delta 274 zcmX@a`-x|RGo#8GW(Gz!28QVSXYVpGoPEZ`@Xz4X3`Pb;xVYjT=E>=dN`fbu8TM&B zEswri$NEoN;f~^>$+H+0)Q>SUC>F6X2o|$3tS@IQlV*6kLGh&`gWxMgIRB*LHMYqQ z8D*KSu}xxf=*B BSuX$p diff --git a/Debug/life.hex b/Debug/life.hex index b3e300e..ee64f29 100644 --- a/Debug/life.hex +++ b/Debug/life.hex @@ -7,25 +7,27 @@ :40008000D15BC1F15BFDE1FDF95BFDE149C9014500CDEC005BDD0F005BDD235BDD235BDD23CDE300010100060FC55BE5CDD200795BD1C1B7C85BDD1F005BE55BD1CDE300CE :4000C000AF5B125BDD235BDD235BDD230C79B838D8C90E005B7EB7C8FE0DC8FE20C85B230C18F15B7EFE20C05B2318F75BE55BC55B210200005B395B775BC15BE1C95BDD2A :40010000E55BDD210200005BDD395BDD77005BDDE1C9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007D -:40014000000021CC0300010600005BDFCDDD0200CDE60200FE30CA98010021CC0300010600005BDF21BC0300CD5A0200CDB50100CDDE0100CD380200CDFB0100CD1903003A -:400180003E0849CF5BDD7E1921C90300BE28E5775BDD7E05FE1B20DC21A20300010000003E0049DF3E175BD73E015BD73E015BD721000000C92100000022C60300217206EE -:4001C0000011730600AF7701761B00EDB021E9210011EA2100AF7701761B00EDB0C921D606000645C50662E5CDAB0200E13E013801AF772310F123C110EAC9D5DD21D606EE +:400140000000211C0400010600005BDFCDDD0200CDE60200FE30CA980100211C0400010600005BDF210C0400CD5A0200CDB50100CDDE0100CD380200CDFB0100CD19030047 +:400180003E0849CF5BDD7E1921190400BE28E5775BDD7E05FE1B20DC21F20300010000003E0049DF3E175BD73E015BD73E015BD721000000C9210000002216040021C206AC +:4001C0000011C30600AF7701761B00EDB021392200113A2200AF7701761B00EDB0C9212607000645C50662E5CDAB0200E13E013801AF772310F123C110EAC9D5DD2126075A :4002000000064550C5066258DD7E00CD1E0200CD2B0200DD2310F0DD23C110E7D1C9F53E1F5BD77B5BD77A5BD7F1C94FFE013E2020023E8249D779C93E1F5BD73E005BD784 -:400240003E475BD721AF0300CD5A02002AC603002322C60300CD630200C9010000003E0049DFC9FDE5D5C5FD2191020006060E06FD1700ED33043E2F3CA7ED5230FA19FE4A -:400280003020030D20045BD70E0110E4C1D1FDE1C9A086010010270000E8030000640000000A000000010000000000C501000000793CE60732AC020021970300094EEB61EE -:4002C00068ED42ED42ED420E00097C32C802007D2F12E6B837E2DA02003F17C1C921D20300CD5A0200C93E0049CFB7CAE60200FE30CA180300FE61FAE60200FE77F2E602FF -:4003000000D6616F2600291144060019ED0779327106007832700600C9DD21D60600214D22000645C50662DD7E9CDD869DDD869EDD86FFDD8601DD8662DD8663DD86645F04 -:40034000433A710600CD820300791601FE012816433A700600CD820300791600FE012006DD7E00E601577A7723DD2310BA23DD23C110B1214D220011D6060001761B00ED59 -:40038000B0C9F5C5DA8D0300070FA020050E00C1F1C90E01C1F1C95261786F6674140C0A0D000A0D46696E69736865640A0D0047656E65726174696F6E3A20001782183C5C -:4003C0007EFFFF7E3C1800000000000016111701000C0A0D094C6966652046616D696C792043656C6C756C6172204175746F6D6174610A0D0A0D09412E20436F6E7761795B -:400400002773204C696665202D204368616F7469630A0D09422E20327832202D204368616F7469630A0D09432E203334204C696665202D204578706C6F64696E670A0D09B7 -:40044000442E20416D6F656261202D204368616F7469630A0D09452E20417373696D696C6174696F6E202D20537461626C650A0D09462E20436F6167756C6174696F6E7378 -:40048000202D204578706C6F64696E670A0D09472E20436F72616C202D204578706C6F64696E670A0D09482E204461792026204E69676874202D20537461626C650A0D094C -:4004C000492E204469616D6F656261202D204368616F7469630A0D094A2E20466C616B6573202D20457870616E64696E670A0D094B2E20476E61726C202D204578706C6FF0 -:4005000064696E670A0D094C2E20486967684C696665202D204368616F7469630A0D094D2E204C6F6E67204C696665202D20537461626C650A0D094E2E204D617A65202DEE -:40054000204578706C6F64696E670A0D094F2E204D617A656374726963202D204578706C6F64696E670A0D09502E204D6F7665202D20537461626C650A0D09512E2050739C -:400580006575646F204C696665202D204368616F7469630A0D09522E205265706C696361746F72202D204578706C6F64696E670A0D09532E205365656473202D204578708B -:4005C0006C6F64696E670A0D09542E2053657276696574746573202D204578706C6F64696E670A0D09552E20537461696E73202D20537461626C650A0D09562E2057616C92 -:400600006C6564436974696573202D20537461626C650A0D0A0D09302E2045786974207468652070726F6772616D0A0D0A0D095069636B20612072756C65736574205B4175 -:320640005D3A2000040624130C0C54951C78C4F604F8E4ECF4F004FF010124061C10041F040FA41A5486555502000E00E4F6F81E0000BE +:400240003E475BD721FF0300CD5A02002A1604002322160400CD630200C9010000003E0049DFC9FDE5D5C5FD2191020006060E06FD1700ED33043E2F3CA7ED5230FA19FE58 +:400280003020030D20045BD70E0110E4C1D1FDE1C9A086010010270000E8030000640000000A000000010000000000C501000000793CE60732AC020021E70300094EEB619E +:4002C00068ED42ED42ED420E00097C32C802007D2F12E6B837E2DA02003F17C1C921220400CD5A0200C93E0049CFB7CAE60200FE30CA180300FE61FAE60200FE77F2E602AE +:4003000000D6616F2600291194060019ED077932C106007832C00600C9DD21260700219D22000645C50662DD7E9CDD869DDD869EDD86FFDD8601DD8662DD8663DD86645F73 +:400340005F16013AC10600CD7F0300FE01281416003AC00600CD7F0300FE012006DD7E00E601577A7723DD2310BD23DD23C110B4219D22001126070001761B00EDB0C9D5E5 +:40038000531DCB3F1D20FBE60120043E00D1C93E01D1C9DD21260700219D22000645C50662DD7E9CDD869DDD869EDD86FFDD8601DD8662DD8663DD86641601FE03280C16DA +:4003C00000FE022006DD7E00E601577A7723DD2310CF23DD23C110C6219D22001126070001761B00EDB0C95261786F6674140C0A0D000A0D46696E69736865640A0D004731 +:40040000656E65726174696F6E3A20001782183C7EFFFF7E3C1800000000000016111701000C0A0D094C6966652046616D696C792043656C6C756C6172204175746F6D611A +:4004400074610A0D0A0D09412E20436F6E7761792773204C696665202D204368616F7469630A0D09422E20327832202D204368616F7469630A0D09432E203334204C696607 +:4004800065202D204578706C6F64696E670A0D09442E20416D6F656261202D204368616F7469630A0D09452E20417373696D696C6174696F6E202D20537461626C650A0D22 +:4004C00009462E20436F6167756C6174696F6E73202D204578706C6F64696E670A0D09472E20436F72616C202D204578706C6F64696E670A0D09482E204461792026204E1A +:4005000069676874202D20537461626C650A0D09492E204469616D6F656261202D204368616F7469630A0D094A2E20466C616B6573202D20457870616E64696E670A0D091D +:400540004B2E20476E61726C202D204578706C6F64696E670A0D094C2E20486967684C696665202D204368616F7469630A0D094D2E204C6F6E67204C696665202D205374D6 +:4005800061626C650A0D094E2E204D617A65202D204578706C6F64696E670A0D094F2E204D617A656374726963202D204578706C6F64696E670A0D09502E204D6F7665205C +:4005C0002D20537461626C650A0D09512E2050736575646F204C696665202D204368616F7469630A0D09522E205265706C696361746F72202D204578706C6F64696E670A66 +:400600000D09532E205365656473202D204578706C6F64696E670A0D09542E2053657276696574746573202D204578706C6F64696E670A0D09552E20537461696E73202D6F +:4006400020537461626C650A0D09562E2057616C6C6564436974696573202D20537461626C650A0D0A0D09302E2045786974207468652070726F6772616D0A0D0A0D09506A +:4006800069636B20612072756C65736574205B415D3A2000040624130C0C54951C78C4F604F8E4ECF4F004FF010124061C10041F040FA41A5486555502000E00E4F6F81ED8 +:0206C000000038 :00000001FF diff --git a/Life.wsp b/Life.wsp index 65f0304..85e3538 100644 --- a/Life.wsp +++ b/Life.wsp @@ -8,85 +8,37 @@ ptn_Child1=ChildFrames ptn_Child1=Document-0 ptn_Child2=Document-1 ptn_Child3=Document-2 -ptn_Child4=Document-3 -ptn_Child5=Document-4 -ptn_Child6=Document-5 -ptn_Child7=Document-6 [WorkState_v1_2.Frames.ChildFrames.Document-0] ptn_Child1=ViewFrame-0 [WorkState_v1_2.Frames.ChildFrames.Document-0.ViewFrame-0] -DocPathName=.\init.asm +DocPathName=.\main.asm DocTemplateIndex=0 DocumentString=IDE.Document IsActiveChildFrame=False IsFrameVisible=True -WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPKBAAAAAAKBAAAAAAKIHAAAAAMGDAAAAA +WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPAAAAAAAAAAAAAAAAMGDAAAAAFOBAAAAA [WorkState_v1_2.Frames.ChildFrames.Document-1] ptn_Child1=ViewFrame-0 [WorkState_v1_2.Frames.ChildFrames.Document-1.ViewFrame-0] -DocPathName=.\main.asm +DocPathName=.\README.md DocTemplateIndex=0 DocumentString=IDE.Document IsActiveChildFrame=True IsFrameVisible=True -WindowPlacement=MCAAAAAACAAAAAAADAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPEDAAAAAAEDAAAAAAIEFAAAAAIBDAAAAA +WindowPlacement=MCAAAAAACAAAAAAADAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPKBAAAAAAKBAAAAAAKIDAAAAADACAAAAA [WorkState_v1_2.Frames.ChildFrames.Document-2] ptn_Child1=ViewFrame-0 [WorkState_v1_2.Frames.ChildFrames.Document-2.ViewFrame-0] -DocPathName=.\equs.inc -DocTemplateIndex=0 -DocumentString=IDE.Document -IsActiveChildFrame=False -IsFrameVisible=True -WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPMJAAAAAAMJAAAAAAEEIAAAAANJDAAAAA - -[WorkState_v1_2.Frames.ChildFrames.Document-3] -ptn_Child1=ViewFrame-0 - -[WorkState_v1_2.Frames.ChildFrames.Document-3.ViewFrame-0] -DocPathName=.\mos_api.inc -DocTemplateIndex=0 -DocumentString=IDE.Document -IsActiveChildFrame=False -IsFrameVisible=True -WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPGLAAAAAAGLAAAAAAOFIAAAAAHLDAAAAA - -[WorkState_v1_2.Frames.ChildFrames.Document-4] -ptn_Child1=ViewFrame-0 - -[WorkState_v1_2.Frames.ChildFrames.Document-4.ViewFrame-0] -DocPathName=.\README.md -DocTemplateIndex=0 -DocumentString=IDE.Document -IsActiveChildFrame=False -IsFrameVisible=True -WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPMJAAAAAAMJAAAAAAKIDAAAAADIDAAAAA - -[WorkState_v1_2.Frames.ChildFrames.Document-5] -ptn_Child1=ViewFrame-0 - -[WorkState_v1_2.Frames.ChildFrames.Document-5.ViewFrame-0] -DocPathName=.\helper_functions.asm -DocTemplateIndex=0 -DocumentString=IDE.Document -IsActiveChildFrame=False -IsFrameVisible=True -WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPMJAAAAAAMJAAAAAAMAEAAAAAFICAAAAA - -[WorkState_v1_2.Frames.ChildFrames.Document-6] -ptn_Child1=ViewFrame-0 - -[WorkState_v1_2.Frames.ChildFrames.Document-6.ViewFrame-0] -DocPathName=.\helper_macros.inc +DocPathName=.\LICENSE DocTemplateIndex=0 DocumentString=IDE.Document IsActiveChildFrame=False IsFrameVisible=True -WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPGLAAAAAAGLAAAAAAGCEAAAAAPJCAAAAA +WindowPlacement=MCAAAAAAAAAAAAAABAAAAAAAPPPPPPPPPPPPPPPPIPPPPPPPBOPPPPPPEDAAAAAAEDAAAAAAEKDAAAAANBCAAAAA diff --git a/main.asm b/main.asm index b20c732..0249f29 100644 --- a/main.asm +++ b/main.asm @@ -42,10 +42,10 @@ _main: RST.LIL 18h ;Display menu of life configurations - ;call print_menu - ;call get_rule_choice - ;cp ZERO - ;jp z, stop + call print_menu + call get_rule_choice + cp ZERO + jp z, stop ;Clear the screen and init screen mode LD HL, init_screen @@ -62,7 +62,7 @@ start: life: CALL print_statusline CALL print_cells - CALL conway ;Do Life Rules on current cells + CALL process_rules ;conway ;Do Life Rules on current cells MOSCALL mos_sysvars ;get the sysvars location - consider saving IX for speed ld.lil a,(IX+sysvar_vkeycount) ;check if any key has been pressed @@ -351,37 +351,36 @@ process_rules: ADD A,(IX+BOTTOM_RIGHT) ;A will contain the count of live cells in the - ;neighborhood. Return cell in D. + ;neighborhood. LD E, A EVALUATE: ;Evaluate surrounding cell count to create or destroy current cell ;This is the rules being applied for the cell + ld E, A ;Save neighborhood count - LD B, E - LD A, (b_SURVIVE) - CALL checkBit - LD A, C - ;A contains 1 if cell survives, 0 if not + ld D, 01h ;Alive + ;Check for survivors + ld A, (b_SURVIVE) ;Load ruleset into A - LD D,01h ;Alive - CP 01h ;Compare A to 01h. - JR Z,STORE_CELL ;Save Alive cell - - LD B, E - LD A, (b_BORN) - CALL checkBit - LD A, C + call checkBit + ;A contains 1 if cell survives, 0 if not + cp 01h ;Compare A to 01h. + jr Z, STORE_CELL ;Save Alive cell + + ld D, 00h ;Assume dead until found otherwise + ;Check for births +; ld B, E + ld A, (b_BORN) + call checkBit ;A contains 1 if cell is born, 0 if not + cp 01h ;Compare A to 01h. + jr NZ,STORE_CELL ;Save Dead cell - LD D,00h ;Assume dead until found otherwise - CP 01h ;Compare A to 01h. - JR NZ,STORE_CELL ;Save Dead cell - LD A,(IX+0) - AND 01h ;Keep it alive if already alive. - LD D,A ;Load current cell in A - + ld A,(IX+0) ;Keep it alive if already alive. + and 01h + ld D, A STORE_CELL: ;Save the new cell to the Next Cell Cycle table @@ -405,43 +404,40 @@ process_rules: RET ;Exit -; Subroutine to check if a bit position in a byte is set +; check_bit subroutine +; ; Input: -; A - rule byte -; B - cell neighborhood count (bit position to check) +; A - Rule set, with data represented by the position of each set bit +; E - Neighborhood count, containing a value of 0 to 8 +; ; Output: -; C - 1 if bit position is set, 0 otherwise +; A - 1 if the neighborhood count value corresponds to a bit position in the ruleset byte that is set, 0 otherwise +; checkBit: - ; Save registers - push af - push bc - - jp c, check_bit_position_not_set - - ; Mask out all but the specified bit - rlca ; Rotate left with carry through, effectively shifting B to the leftmost position - rrca ; Rotate right with carry through, effectively shifting B back to its original position - and a, b - - ; Check if the bit is set - jr nz, check_bit_position_set - -check_bit_position_not_set: - ld c, 0 - - ; Restore registers and return - pop bc - pop af - ret - -check_bit_position_set: - ; Bit is set - ld c, 1 - - ; Restore registers and return - pop bc - pop af - ret + push de +; Loop to shift the accumulator right by the value of register B + ld d,e + dec e +loop: + srl a + dec e + jr nz, loop + +; Check if the least significant bit is set + and 01h + +; If it is set, return 1 + jr nz, check_bit_return + +; Otherwise, return 0 + ld a, 00h + pop de + ret + +check_bit_return: + ld a, 01h + pop de + ret ;Update the matrix with Conway Rules.