Simplify long, repetitive code.

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
OmegaMax
Posts: 83
Joined: Wed Sep 21, 2016 8:55 am
Location: Calgary.Alberta,Canada

Re: Simplify long, repetitive code.

Post by OmegaMax » Thu Jul 13, 2017 1:52 pm

Oziphantom wrote:Yeah but Garth, they are having trouble making an array of Words, lets keep the -1, stack push tricks to latter yeah ;)
Agreed and that's why I used your code example to help him.

Garth
Posts: 195
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Simplify long, repetitive code.

Post by Garth » Thu Jul 13, 2017 3:08 pm

What I presented is really basic stuff, not rocket science. Make the table say,

Code: Select all

LvlFuncPtrTableLo
   .byte  LOW(LEV01-1), LOW(LEV02-1), LOW(LEV03-1, <etc.>
LvlFuncPtrTableHi
   .byte  HIGH(LEV01-1), HIGH(LEV02-1), HIGH(LEV03-1), <etc.>
Using the RTS for a jump simplifies things by eliminating the need for a variable and removing it from the constant battle for ZP space (since it was suggested to put it there). It also makes the program more efficient.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
rainwarrior
Posts: 7902
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Simplify long, repetitive code.

Post by rainwarrior » Thu Jul 13, 2017 3:18 pm

Garth wrote:It also makes the program more efficient.
Depends what you mean by "efficient". Using RTS takes 1 more cycle vs an indirect jump, but it saves some bytes of code at least?

Code: Select all

STA zp +3
STA zp +3
JMP (addr) +5

PHA +3
PHA +3
RTS +6
The JMP pointer does not need to be on the zeropage, either (JMP's indirection is always from an absolute address, ZP is irrelevant to that instruction), though that would cost another 2 cycles from the STAs.
Last edited by rainwarrior on Thu Jul 13, 2017 3:25 pm, edited 1 time in total.

User avatar
OmegaMax
Posts: 83
Joined: Wed Sep 21, 2016 8:55 am
Location: Calgary.Alberta,Canada

Re: Simplify long, repetitive code.

Post by OmegaMax » Thu Jul 13, 2017 3:25 pm

This is becoming "use my way" instead,you left an example Garth so if sdm chooses to use it that's fine also.

Garth
Posts: 195
Joined: Wed Nov 30, 2016 4:45 pm
Location: Southern California
Contact:

Re: Simplify long, repetitive code.

Post by Garth » Thu Jul 13, 2017 3:30 pm

Depends what you mean by "efficient".
It saves several bytes; and if the indirect address is not in ZP, it's slightly faster, too.
This is becoming "use my way" instead of helping another programmer.
I believe it's always helpful to present a more elegant solution.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
OmegaMax
Posts: 83
Joined: Wed Sep 21, 2016 8:55 am
Location: Calgary.Alberta,Canada

Re: Simplify long, repetitive code.

Post by OmegaMax » Thu Jul 13, 2017 3:39 pm

I believe when your new the code Oziphantom showed is easier to grasp,that's why I choose his code to help sdm.Now that he understands and has it working he can explore other ways if he chooses,it's not really necessary though but it's up to him.

sdm
Posts: 306
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Re: Simplify long, repetitive code.

Post by sdm » Mon Jul 17, 2017 5:13 am

I would still like to ask for help with a slightly different, large code. Rule similar, but slightly different. Each bit in the "GOLD_xx_xx_UnLock" byte slot is responsible for the collected (1) or not (0) gold. I tried to make the simplified code as above in posts, but this time instead of jump (JMP) to the label are operations on different bits. And now I have a problem, because I do not know if any one can do it in a similar way: /

Collecting the "GOLD" item can be random, there is no pre-assigned order of collection order (one big map consisting of 64-nametables)

GOLD_Checker - is the variable that depends on which "map" we enter, the number of this map is loaded (Specify: the value with the map number is uploaded exactly in the "collision" of the gold with the hero, and after that time is again zero)

Code: Select all

GOLD_Checker		.ds 1
GOLD_01_08_UnLock	.ds 1
GOLD_09_16_UnLock	.ds 1
GOLD_17_24_UnLock	.ds 1
GOLD_25_32_UnLock	.ds 1
GOLD_33_40_UnLock	.ds 1
GOLD_41_48_UnLock	.ds 1
GOLD_49_56_UnLock	.ds 1
GOLD_57_64_UnLock	.ds 1



GOLD_Check:

	LDA GOLD_Checker
	CMP #1
	BNE NoGC_01

	LDA GOLD_01_08_UnLock
	ORA #%00000001
	STA GOLD_01_08_UnLock

NoGC_01:
	LDA GOLD_Checker
	CMP #2
	BNE NoGC_02

	LDA GOLD_01_08_UnLock
	ORA #%00000010
	STA GOLD_01_08_UnLock

NoGC_02:
	LDA GOLD_Checker
	CMP #3
	BNE NoGC_03

	LDA GOLD_01_08_UnLock
	ORA #%00000100
	STA GOLD_01_08_UnLock

NoGC_03:
	LDA GOLD_Checker
	CMP #4
	BNE NoGC_04

	LDA GOLD_01_08_UnLock
	ORA #%00001000
	STA GOLD_01_08_UnLock

NoGC_04:
	LDA GOLD_Checker
	CMP #5
	BNE NoGC_05

	LDA GOLD_01_08_UnLock
	ORA #%00010000
	STA GOLD_01_08_UnLock

NoGC_05:
	LDA GOLD_Checker
	CMP #6
	BNE NoGC_06

	LDA GOLD_01_08_UnLock
	ORA #%00100000
	STA GOLD_01_08_UnLock

NoGC_06:
	LDA GOLD_Checker
	CMP #7
	BNE NoGC_07

	LDA GOLD_01_08_UnLock
	ORA #%01000000
	STA GOLD_01_08_UnLock

NoGC_07:
	LDA GOLD_Checker
	CMP #8
	BNE NoGC_08

	LDA GOLD_01_08_UnLock
	ORA #%10000000
	STA GOLD_01_08_UnLock

NoGC_08:
	LDA GOLD_Checker
	CMP #9
	BNE NoGC_09

	LDA GOLD_09_16_UnLock
	ORA #%00000001
	STA GOLD_09_16_UnLock

NoGC_09:
	LDA GOLD_Checker
	CMP #10
	BNE NoGC_10

	LDA GOLD_09_16_UnLock
	ORA #%00000010
	STA GOLD_09_16_UnLock

NoGC_10:
	LDA GOLD_Checker
	CMP #11
	BNE NoGC_11

	LDA GOLD_09_16_UnLock
	ORA #%00000100
	STA GOLD_09_16_UnLock

NoGC_11:
	LDA GOLD_Checker
	CMP #12
	BNE NoGC_12

	LDA GOLD_09_16_UnLock
	ORA #%00001000
	STA GOLD_09_16_UnLock

NoGC_12:
	LDA GOLD_Checker
	CMP #13
	BNE NoGC_13

	LDA GOLD_09_16_UnLock
	ORA #%00010000
	STA GOLD_09_16_UnLock

NoGC_13:
	LDA GOLD_Checker
	CMP #14
	BNE NoGC_14

	LDA GOLD_09_16_UnLock
	ORA #%00100000
	STA GOLD_09_16_UnLock

NoGC_14:
	LDA GOLD_Checker
	CMP #15
	BNE NoGC_15

	LDA GOLD_09_16_UnLock
	ORA #%01000000
	STA GOLD_09_16_UnLock

NoGC_15:
	LDA GOLD_Checker
	CMP #16
	BNE NoGC_16

	LDA GOLD_09_16_UnLock
	ORA #%10000000
	STA GOLD_09_16_UnLock

NoGC_16:
	LDA GOLD_Checker
	CMP #17
	BNE NoGC_17

	LDA GOLD_17_24_UnLock
	ORA #%00000001
	STA GOLD_17_24_UnLock

NoGC_17:
	LDA GOLD_Checker
	CMP #18
	BNE NoGC_18

	LDA GOLD_17_24_UnLock
	ORA #%00000010
	STA GOLD_17_24_UnLock

NoGC_18:
	LDA GOLD_Checker
	CMP #19
	BNE NoGC_19

	LDA GOLD_17_24_UnLock
	ORA #%00000100
	STA GOLD_17_24_UnLock

NoGC_19:
	LDA GOLD_Checker
	CMP #20
	BNE NoGC_20

	LDA GOLD_17_24_UnLock
	ORA #%00001000
	STA GOLD_17_24_UnLock

NoGC_20:
	LDA GOLD_Checker
	CMP #21
	BNE NoGC_21

	LDA GOLD_17_24_UnLock
	ORA #%00010000
	STA GOLD_17_24_UnLock

NoGC_21:
	LDA GOLD_Checker
	CMP #22
	BNE NoGC_22

	LDA GOLD_17_24_UnLock
	ORA #%00100000
	STA GOLD_17_24_UnLock

NoGC_22:
	LDA GOLD_Checker
	CMP #23
	BNE NoGC_23

	LDA GOLD_17_24_UnLock
	ORA #%01000000
	STA GOLD_17_24_UnLock

NoGC_23:
	LDA GOLD_Checker
	CMP #24
	BNE NoGC_24

	LDA GOLD_17_24_UnLock
	ORA #%10000000
	STA GOLD_17_24_UnLock

NoGC_24:
	LDA GOLD_Checker
	CMP #25
	BNE NoGC_25

	LDA GOLD_25_32_UnLock
	ORA #%00000001
	STA GOLD_25_32_UnLock

NoGC_25:
	LDA GOLD_Checker
	CMP #26
	BNE NoGC_26

	LDA GOLD_25_32_UnLock
	ORA #%00000010
	STA GOLD_25_32_UnLock

NoGC_26:
	LDA GOLD_Checker
	CMP #27
	BNE NoGC_27

	LDA GOLD_25_32_UnLock
	ORA #%00000100
	STA GOLD_25_32_UnLock

NoGC_27:
	LDA GOLD_Checker
	CMP #28
	BNE NoGC_28

	LDA GOLD_25_32_UnLock
	ORA #%00001000
	STA GOLD_25_32_UnLock

NoGC_28:
	LDA GOLD_Checker
	CMP #29
	BNE NoGC_29

	LDA GOLD_25_32_UnLock
	ORA #%00010000
	STA GOLD_25_32_UnLock

NoGC_29:
	LDA GOLD_Checker
	CMP #30
	BNE NoGC_30

	LDA GOLD_25_32_UnLock
	ORA #%00100000
	STA GOLD_25_32_UnLock

NoGC_30:
	LDA GOLD_Checker
	CMP #31
	BNE NoGC_31

	LDA GOLD_25_32_UnLock
	ORA #%01000000
	STA GOLD_25_32_UnLock

NoGC_31:
	LDA GOLD_Checker
	CMP #32
	BNE NoGC_32

	LDA GOLD_25_32_UnLock
	ORA #%10000000
	STA GOLD_25_32_UnLock

NoGC_32:
	LDA GOLD_Checker
	CMP #33
	BNE NoGC_33

	LDA GOLD_33_40_UnLock
	ORA #%00000001
	STA GOLD_33_40_UnLock

NoGC_33:
	LDA GOLD_Checker
	CMP #34
	BNE NoGC_34

	LDA GOLD_33_40_UnLock
	ORA #%00000010
	STA GOLD_33_40_UnLock

NoGC_34:
	LDA GOLD_Checker
	CMP #35
	BNE NoGC_35

	LDA GOLD_33_40_UnLock
	ORA #%00000100
	STA GOLD_33_40_UnLock

NoGC_35:
	LDA GOLD_Checker
	CMP #36
	BNE NoGC_36

	LDA GOLD_33_40_UnLock
	ORA #%00001000
	STA GOLD_33_40_UnLock

NoGC_36:
	LDA GOLD_Checker
	CMP #37
	BNE NoGC_37

	LDA GOLD_33_40_UnLock
	ORA #%00010000
	STA GOLD_33_40_UnLock

NoGC_37:
	LDA GOLD_Checker
	CMP #38
	BNE NoGC_38

	LDA GOLD_33_40_UnLock
	ORA #%00100000
	STA GOLD_33_40_UnLock

NoGC_38:
	LDA GOLD_Checker
	CMP #39
	BNE NoGC_39

	LDA GOLD_33_40_UnLock
	ORA #%01000000
	STA GOLD_33_40_UnLock

NoGC_39:
	LDA GOLD_Checker
	CMP #40
	BNE NoGC_40

	LDA GOLD_33_40_UnLock
	ORA #%10000000
	STA GOLD_33_40_UnLock

NoGC_40:
	LDA GOLD_Checker
	CMP #41
	BNE NoGC_41

	LDA GOLD_41_48_UnLock
	ORA #%00000001
	STA GOLD_41_48_UnLock

NoGC_41:
	LDA GOLD_Checker
	CMP #42
	BNE NoGC_42

	LDA GOLD_41_48_UnLock
	ORA #%00000010
	STA GOLD_41_48_UnLock

NoGC_42:
	LDA GOLD_Checker
	CMP #43
	BNE NoGC_43

	LDA GOLD_41_48_UnLock
	ORA #%00000100
	STA GOLD_41_48_UnLock

NoGC_43:
	LDA GOLD_Checker
	CMP #44
	BNE NoGC_44

	LDA GOLD_41_48_UnLock
	ORA #%00001000
	STA GOLD_41_48_UnLock

NoGC_44:
	LDA GOLD_Checker
	CMP #45
	BNE NoGC_45

	LDA GOLD_41_48_UnLock
	ORA #%00010000
	STA GOLD_41_48_UnLock

NoGC_45:
	LDA GOLD_Checker
	CMP #46
	BNE NoGC_46

	LDA GOLD_41_48_UnLock
	ORA #%00100000
	STA GOLD_41_48_UnLock

NoGC_46:
	LDA GOLD_Checker
	CMP #47
	BNE NoGC_47

	LDA GOLD_41_48_UnLock
	ORA #%01000000
	STA GOLD_41_48_UnLock

NoGC_47:
	LDA GOLD_Checker
	CMP #48
	BNE NoGC_48

	LDA GOLD_41_48_UnLock
	ORA #%10000000
	STA GOLD_41_48_UnLock

NoGC_48:
	LDA GOLD_Checker
	CMP #49
	BNE NoGC_49

	LDA GOLD_49_56_UnLock
	ORA #%00000001
	STA GOLD_49_56_UnLock

NoGC_49:
	LDA GOLD_Checker
	CMP #50
	BNE NoGC_50

	LDA GOLD_49_56_UnLock
	ORA #%00000010
	STA GOLD_49_56_UnLock

NoGC_50:
	LDA GOLD_Checker
	CMP #51
	BNE NoGC_51

	LDA GOLD_49_56_UnLock
	ORA #%00000100
	STA GOLD_49_56_UnLock

NoGC_51:
	LDA GOLD_Checker
	CMP #52
	BNE NoGC_52

	LDA GOLD_49_56_UnLock
	ORA #%00001000
	STA GOLD_49_56_UnLock

NoGC_52:
	LDA GOLD_Checker
	CMP #53
	BNE NoGC_53

	LDA GOLD_49_56_UnLock
	ORA #%00010000
	STA GOLD_49_56_UnLock

NoGC_53:
	LDA GOLD_Checker
	CMP #54
	BNE NoGC_54

	LDA GOLD_49_56_UnLock
	ORA #%00100000
	STA GOLD_49_56_UnLock

NoGC_54:
	LDA GOLD_Checker
	CMP #55
	BNE NoGC_55

	LDA GOLD_49_56_UnLock
	ORA #%01000000
	STA GOLD_49_56_UnLock

NoGC_55:
	LDA GOLD_Checker
	CMP #56
	BNE NoGC_56

	LDA GOLD_49_56_UnLock
	ORA #%10000000
	STA GOLD_49_56_UnLock

NoGC_56:
	LDA GOLD_Checker
	CMP #57
	BNE NoGC_57

	LDA GOLD_57_64_UnLock
	ORA #%00000001
	STA GOLD_57_64_UnLock

NoGC_57:
	LDA GOLD_Checker
	CMP #58
	BNE NoGC_58

	LDA GOLD_57_64_UnLock
	ORA #%00000010
	STA GOLD_57_64_UnLock

NoGC_58:
	LDA GOLD_Checker
	CMP #59
	BNE NoGC_59

	LDA GOLD_57_64_UnLock
	ORA #%00000100
	STA GOLD_57_64_UnLock

NoGC_59:
	LDA GOLD_Checker
	CMP #60
	BNE NoGC_60

	LDA GOLD_57_64_UnLock
	ORA #%00001000
	STA GOLD_57_64_UnLock

NoGC_60:
	LDA GOLD_Checker
	CMP #61
	BNE NoGC_61

	LDA GOLD_57_64_UnLock
	ORA #%00010000
	STA GOLD_57_64_UnLock

NoGC_61:
	LDA GOLD_Checker
	CMP #62
	BNE NoGC_62

	LDA GOLD_57_64_UnLock
	ORA #%00100000
	STA GOLD_57_64_UnLock

NoGC_62:
	LDA GOLD_Checker
	CMP #63
	BNE NoGC_63

	LDA GOLD_57_64_UnLock
	ORA #%01000000
	STA GOLD_57_64_UnLock

NoGC_63:
	LDA GOLD_Checker
	CMP #64
	BNE NoGC_64

	LDA GOLD_57_64_UnLock
	ORA #%10000000
	STA GOLD_57_64_UnLock

NoGC_64:
	RTS



User avatar
thefox
Posts: 3141
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Simplify long, repetitive code.

Post by thefox » Mon Jul 17, 2017 6:52 am

Something like this:

- A = GOLD_Checker-1. This is your 0-based level index 0..63.
- A/8 (range 0..7) tells you which byte to modify. You can divide by 8 by shifting right (LSR) 3 times.
- A & %111 (range 0..7) tells you which bit to modify (& = bitwise AND). You can use a lookup table with 8 elements (%1, %10, %100, ..., %10000000) to retrieve a mask for ORA.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi

User avatar
tokumaru
Posts: 11909
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Simplify long, repetitive code.

Post by tokumaru » Mon Jul 17, 2017 9:08 am

Here's one way to do it:

Code: Select all

BitMasks:

	.byte %00000001
	.byte %00000010
	.byte %00000100
	.byte %00001000
	.byte %00010000
	.byte %00100000
	.byte %01000000
	.byte %10000000

;************************

	sec
	lda GOLD_Checker
	sbc #$01
	tay
	and #%00000111
	tax
	tya
	lsr
	lsr
	lsr
	tay
	lda GOLD_01_08_UnLock, y
	ora BitMasks, x
	sta GOLD_01_08_UnLock, y
EDIT: Whenever you find yourself doing lots of comparisons against consecutive numbers, you should probably be using indexing instead. And when you're indexing stuff, the bits in the index usually have meanings that you can exploit, so when you realize what the bit pattern of the index/address is, you'll be able to find/manipulate the target data after a few bit manipulations rather than tons of comparisons for specific cases. For example, the way that the layout of a name table address is %0010NNYY YYXXXXX (NN = name table, XXXXX = horizontal tile coordinate, YYYYY = vertical tile coordinate) or an attribute table address is %0010NN11 11YYYXXX (NN = name table, XXX = horizontal 32x32 block coordinate, YYY = vertical 32x32 block coordinate) while the highest unused X and Y bits can be combined to index bit masks for manipulating the 16x16 blocks inside the 32x32 blocks (the lower X and Y bits are discarded for good, since you can't set palettes for individual tiles).

sdm2
Posts: 33
Joined: Wed Feb 05, 2020 12:59 pm
Location: Poland

Re: Simplify long, repetitive code.

Post by sdm2 » Fri Sep 04, 2020 4:40 am

Another long code size optimization request.I always have problems with that ... :oops:

The "ENEMY_CLR_LEV_CHECK" function is triggered at the time of a collision / killing of one of the eight enemies on a certain level. For example, when you are on the level no. 20 I will kill enemy nr. 6, bit5 is set in ENEMY_LEV_Clear_Temp, which is transferred to the "magazine" of information about killed enemies on a given level:

LDA ENEMY_LEV020_Flags
ORA ENEMY_LEV_Clear_Temp
STA ENEMY_LEV020_Flags

Now this bit is moved to ENEMY_LEV020_Flags and re-entering level 20 will result in missing the enemy that was previously killed.
Each level has a maximum of 8 opponents assigned to one of the bits, not set bit - the opponent has to appear, set bit will not appear.

I can not use BitMasks as in the case of the earlier one because the universal temp variable is used here

Code: Select all

ENEMY_CLR_LEV_CHECK:

	LDA LEV_Memory
	CMP #1
	BNE NoENMCLC_001

	LDA ENEMY_LEV001_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV001_Flags

NoENMCLC_001:

	LDA LEV_Memory
	CMP #2
	BNE NoENMCLC_002

	LDA ENEMY_LEV002_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV002_Flags

NoENMCLC_002:

	LDA LEV_Memory
	CMP #3
	BNE NoENMCLC_003

	LDA ENEMY_LEV003_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV003_Flags

NoENMCLC_003:

	LDA LEV_Memory
	CMP #4
	BNE NoENMCLC_004

	LDA ENEMY_LEV004_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV004_Flags

NoENMCLC_004:

	LDA LEV_Memory
	CMP #5
	BNE NoENMCLC_005

	LDA ENEMY_LEV005_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV005_Flags

NoENMCLC_005:

	LDA LEV_Memory
	CMP #6
	BNE NoENMCLC_006

	LDA ENEMY_LEV006_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV006_Flags

NoENMCLC_006:

	LDA LEV_Memory
	CMP #7
	BNE NoENMCLC_007

	LDA ENEMY_LEV007_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV007_Flags

NoENMCLC_007:

	LDA LEV_Memory
	CMP #8
	BNE NoENMCLC_008

	LDA ENEMY_LEV008_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV008_Flags

NoENMCLC_008:

	LDA LEV_Memory
	CMP #9
	BNE NoENMCLC_009

	LDA ENEMY_LEV009_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV009_Flags

NoENMCLC_009:

	LDA LEV_Memory
	CMP #10
	BNE NoENMCLC_010

	LDA ENEMY_LEV010_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV010_Flags

NoENMCLC_010:

	LDA LEV_Memory
	CMP #11
	BNE NoENMCLC_011

	LDA ENEMY_LEV011_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV011_Flags

NoENMCLC_011:

	LDA LEV_Memory
	CMP #12
	BNE NoENMCLC_012

	LDA ENEMY_LEV012_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV012_Flags

NoENMCLC_012:

	LDA LEV_Memory
	CMP #13
	BNE NoENMCLC_013

	LDA ENEMY_LEV013_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV013_Flags

NoENMCLC_013:

	LDA LEV_Memory
	CMP #14
	BNE NoENMCLC_014

	LDA ENEMY_LEV014_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV014_Flags

NoENMCLC_014:

	LDA LEV_Memory
	CMP #15
	BNE NoENMCLC_015

	LDA ENEMY_LEV015_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV015_Flags

NoENMCLC_015:

	LDA LEV_Memory
	CMP #16
	BNE NoENMCLC_016

	LDA ENEMY_LEV016_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV016_Flags

NoENMCLC_016:

	LDA LEV_Memory
	CMP #17
	BNE NoENMCLC_017

	LDA ENEMY_LEV017_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV017_Flags

NoENMCLC_017:

	LDA LEV_Memory
	CMP #18
	BNE NoENMCLC_018

	LDA ENEMY_LEV018_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV018_Flags

NoENMCLC_018:

	LDA LEV_Memory
	CMP #19
	BNE NoENMCLC_019

	LDA ENEMY_LEV019_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV019_Flags

NoENMCLC_019:

	LDA LEV_Memory
	CMP #20
	BNE NoENMCLC_020

	LDA ENEMY_LEV020_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV020_Flags

NoENMCLC_020:

	LDA LEV_Memory
	CMP #21
	BNE NoENMCLC_021

	LDA ENEMY_LEV021_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV021_Flags

NoENMCLC_021:

	LDA LEV_Memory
	CMP #22
	BNE NoENMCLC_022

	LDA ENEMY_LEV022_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV022_Flags

NoENMCLC_022:

	LDA LEV_Memory
	CMP #23
	BNE NoENMCLC_023

	LDA ENEMY_LEV023_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV023_Flags

NoENMCLC_023:

	LDA LEV_Memory
	CMP #24
	BNE NoENMCLC_024

	LDA ENEMY_LEV024_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV024_Flags

NoENMCLC_024:

	LDA LEV_Memory
	CMP #25
	BNE NoENMCLC_025

	LDA ENEMY_LEV025_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV025_Flags

NoENMCLC_025:

	LDA LEV_Memory
	CMP #26
	BNE NoENMCLC_026

	LDA ENEMY_LEV026_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV026_Flags

NoENMCLC_026:

	LDA LEV_Memory
	CMP #27
	BNE NoENMCLC_027

	LDA ENEMY_LEV027_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV027_Flags

NoENMCLC_027:

	LDA LEV_Memory
	CMP #28
	BNE NoENMCLC_028

	LDA ENEMY_LEV028_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV028_Flags

NoENMCLC_028:

	LDA LEV_Memory
	CMP #29
	BNE NoENMCLC_029

	LDA ENEMY_LEV029_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV029_Flags

NoENMCLC_029:

	LDA LEV_Memory
	CMP #30
	BNE NoENMCLC_030

	LDA ENEMY_LEV030_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV030_Flags

NoENMCLC_030:

	LDA LEV_Memory
	CMP #31
	BNE NoENMCLC_031

	LDA ENEMY_LEV031_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV031_Flags

NoENMCLC_031:

	LDA LEV_Memory
	CMP #32
	BNE NoENMCLC_032

	LDA ENEMY_LEV032_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV032_Flags

NoENMCLC_032:

	LDA LEV_Memory
	CMP #33
	BNE NoENMCLC_033

	LDA ENEMY_LEV033_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV033_Flags

NoENMCLC_033:

	LDA LEV_Memory
	CMP #34
	BNE NoENMCLC_034

	LDA ENEMY_LEV034_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV034_Flags

NoENMCLC_034:

	LDA LEV_Memory
	CMP #35
	BNE NoENMCLC_035

	LDA ENEMY_LEV035_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV035_Flags

NoENMCLC_035:

	LDA LEV_Memory
	CMP #36
	BNE NoENMCLC_036

	LDA ENEMY_LEV036_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV036_Flags

NoENMCLC_036:

	LDA LEV_Memory
	CMP #37
	BNE NoENMCLC_037

	LDA ENEMY_LEV037_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV037_Flags

NoENMCLC_037:

	LDA LEV_Memory
	CMP #38
	BNE NoENMCLC_038

	LDA ENEMY_LEV038_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV038_Flags

NoENMCLC_038:

	LDA LEV_Memory
	CMP #39
	BNE NoENMCLC_039

	LDA ENEMY_LEV039_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV039_Flags

NoENMCLC_039:

	LDA LEV_Memory
	CMP #40
	BNE NoENMCLC_040

	LDA ENEMY_LEV040_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV040_Flags

NoENMCLC_040:

	LDA LEV_Memory
	CMP #41
	BNE NoENMCLC_041

	LDA ENEMY_LEV041_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV041_Flags

NoENMCLC_041:

	LDA LEV_Memory
	CMP #42
	BNE NoENMCLC_042

	LDA ENEMY_LEV042_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV042_Flags

NoENMCLC_042:

	LDA LEV_Memory
	CMP #43
	BNE NoENMCLC_043

	LDA ENEMY_LEV043_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV043_Flags

NoENMCLC_043:

	LDA LEV_Memory
	CMP #44
	BNE NoENMCLC_044

	LDA ENEMY_LEV044_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV044_Flags

NoENMCLC_044:

	LDA LEV_Memory
	CMP #45
	BNE NoENMCLC_045

	LDA ENEMY_LEV045_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV045_Flags

NoENMCLC_045:

	LDA LEV_Memory
	CMP #46
	BNE NoENMCLC_046

	LDA ENEMY_LEV046_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV046_Flags

NoENMCLC_046:

	LDA LEV_Memory
	CMP #47
	BNE NoENMCLC_047

	LDA ENEMY_LEV047_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV047_Flags

NoENMCLC_047:

	LDA LEV_Memory
	CMP #48
	BNE NoENMCLC_048

	LDA ENEMY_LEV048_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV048_Flags

NoENMCLC_048:

	LDA LEV_Memory
	CMP #49
	BNE NoENMCLC_049

	LDA ENEMY_LEV049_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV049_Flags

NoENMCLC_049:

	LDA LEV_Memory
	CMP #50
	BNE NoENMCLC_050

	LDA ENEMY_LEV050_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV050_Flags

NoENMCLC_050:

	LDA LEV_Memory
	CMP #51
	BNE NoENMCLC_051

	LDA ENEMY_LEV051_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV051_Flags

NoENMCLC_051:

	LDA LEV_Memory
	CMP #52
	BNE NoENMCLC_052

	LDA ENEMY_LEV052_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV052_Flags

NoENMCLC_052:

	LDA LEV_Memory
	CMP #53
	BNE NoENMCLC_053

	LDA ENEMY_LEV053_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV053_Flags

NoENMCLC_053:

	LDA LEV_Memory
	CMP #54
	BNE NoENMCLC_054

	LDA ENEMY_LEV054_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV054_Flags

NoENMCLC_054:

	LDA LEV_Memory
	CMP #55
	BNE NoENMCLC_055

	LDA ENEMY_LEV055_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV055_Flags

NoENMCLC_055:

	LDA LEV_Memory
	CMP #56
	BNE NoENMCLC_056

	LDA ENEMY_LEV056_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV056_Flags

NoENMCLC_056:

	LDA LEV_Memory
	CMP #57
	BNE NoENMCLC_057

	LDA ENEMY_LEV057_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV057_Flags

NoENMCLC_057:

	LDA LEV_Memory
	CMP #58
	BNE NoENMCLC_058

	LDA ENEMY_LEV058_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV058_Flags

NoENMCLC_058:

	LDA LEV_Memory
	CMP #59
	BNE NoENMCLC_059

	LDA ENEMY_LEV059_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV059_Flags

NoENMCLC_059:

	LDA LEV_Memory
	CMP #60
	BNE NoENMCLC_060

	LDA ENEMY_LEV060_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV060_Flags

NoENMCLC_060:

	LDA LEV_Memory
	CMP #61
	BNE NoENMCLC_061

	LDA ENEMY_LEV061_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV061_Flags

NoENMCLC_061:

	LDA LEV_Memory
	CMP #62
	BNE NoENMCLC_062

	LDA ENEMY_LEV062_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV062_Flags

NoENMCLC_062:

	LDA LEV_Memory
	CMP #63
	BNE NoENMCLC_063

	LDA ENEMY_LEV063_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV063_Flags

NoENMCLC_063:

	LDA LEV_Memory
	CMP #64
	BNE NoENMCLC_064

	LDA ENEMY_LEV064_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV064_Flags

NoENMCLC_064:

	LDA LEV_Memory
	CMP #65
	BNE NoENMCLC_065

	LDA ENEMY_LEV065_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV065_Flags

NoENMCLC_065:

	LDA LEV_Memory
	CMP #66
	BNE NoENMCLC_066

	LDA ENEMY_LEV066_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV066_Flags

NoENMCLC_066:

	LDA LEV_Memory
	CMP #67
	BNE NoENMCLC_067

	LDA ENEMY_LEV067_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV067_Flags

NoENMCLC_067:

	LDA LEV_Memory
	CMP #68
	BNE NoENMCLC_068

	LDA ENEMY_LEV068_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV068_Flags

NoENMCLC_068:

	LDA LEV_Memory
	CMP #69
	BNE NoENMCLC_069

	LDA ENEMY_LEV069_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV069_Flags

NoENMCLC_069:

	LDA LEV_Memory
	CMP #70
	BNE NoENMCLC_070

	LDA ENEMY_LEV070_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV070_Flags

NoENMCLC_070:

	LDA LEV_Memory
	CMP #71
	BNE NoENMCLC_071

	LDA ENEMY_LEV071_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV071_Flags

NoENMCLC_071:

	LDA LEV_Memory
	CMP #72
	BNE NoENMCLC_072

	LDA ENEMY_LEV072_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV072_Flags

NoENMCLC_072:

	LDA LEV_Memory
	CMP #73
	BNE NoENMCLC_073

	LDA ENEMY_LEV073_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV073_Flags

NoENMCLC_073:

	LDA LEV_Memory
	CMP #74
	BNE NoENMCLC_074

	LDA ENEMY_LEV074_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV074_Flags

NoENMCLC_074:

	LDA LEV_Memory
	CMP #75
	BNE NoENMCLC_075

	LDA ENEMY_LEV075_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV075_Flags

NoENMCLC_075:

	LDA LEV_Memory
	CMP #76
	BNE NoENMCLC_076

	LDA ENEMY_LEV076_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV076_Flags

NoENMCLC_076:

	LDA LEV_Memory
	CMP #77
	BNE NoENMCLC_077

	LDA ENEMY_LEV077_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV077_Flags

NoENMCLC_077:

	LDA LEV_Memory
	CMP #78
	BNE NoENMCLC_078

	LDA ENEMY_LEV078_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV078_Flags

NoENMCLC_078:

	LDA LEV_Memory
	CMP #79
	BNE NoENMCLC_079

	LDA ENEMY_LEV079_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV079_Flags

NoENMCLC_079:

	LDA LEV_Memory
	CMP #80
	BNE NoENMCLC_080

	LDA ENEMY_LEV080_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV080_Flags

NoENMCLC_080:

	LDA LEV_Memory
	CMP #81
	BNE NoENMCLC_081

	LDA ENEMY_LEV081_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV081_Flags

NoENMCLC_081:

	LDA LEV_Memory
	CMP #82
	BNE NoENMCLC_082

	LDA ENEMY_LEV082_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV082_Flags

NoENMCLC_082:

	LDA LEV_Memory
	CMP #83
	BNE NoENMCLC_083

	LDA ENEMY_LEV083_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV083_Flags

NoENMCLC_083:

	LDA LEV_Memory
	CMP #84
	BNE NoENMCLC_084

	LDA ENEMY_LEV084_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV084_Flags

NoENMCLC_084:

	LDA LEV_Memory
	CMP #85
	BNE NoENMCLC_085

	LDA ENEMY_LEV085_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV085_Flags

NoENMCLC_085:

	LDA LEV_Memory
	CMP #86
	BNE NoENMCLC_086

	LDA ENEMY_LEV086_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV086_Flags

NoENMCLC_086:

	LDA LEV_Memory
	CMP #87
	BNE NoENMCLC_087

	LDA ENEMY_LEV087_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV087_Flags

NoENMCLC_087:

	LDA LEV_Memory
	CMP #88
	BNE NoENMCLC_088

	LDA ENEMY_LEV088_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV088_Flags

NoENMCLC_088:

	LDA LEV_Memory
	CMP #89
	BNE NoENMCLC_089

	LDA ENEMY_LEV089_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV089_Flags

NoENMCLC_089:

	LDA LEV_Memory
	CMP #90
	BNE NoENMCLC_090

	LDA ENEMY_LEV090_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV090_Flags

NoENMCLC_090:

	LDA LEV_Memory
	CMP #91
	BNE NoENMCLC_091

	LDA ENEMY_LEV091_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV091_Flags

NoENMCLC_091:

	LDA LEV_Memory
	CMP #92
	BNE NoENMCLC_092

	LDA ENEMY_LEV092_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV092_Flags

NoENMCLC_092:

	LDA LEV_Memory
	CMP #93
	BNE NoENMCLC_093

	LDA ENEMY_LEV093_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV093_Flags

NoENMCLC_093:

	LDA LEV_Memory
	CMP #94
	BNE NoENMCLC_094

	LDA ENEMY_LEV094_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV094_Flags

NoENMCLC_094:

	LDA LEV_Memory
	CMP #95
	BNE NoENMCLC_095

	LDA ENEMY_LEV095_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV095_Flags

NoENMCLC_095:

	LDA LEV_Memory
	CMP #96
	BNE NoENMCLC_096

	LDA ENEMY_LEV096_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV096_Flags

NoENMCLC_096:

	LDA LEV_Memory
	CMP #97
	BNE NoENMCLC_097

	LDA ENEMY_LEV097_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV097_Flags

NoENMCLC_097:

	LDA LEV_Memory
	CMP #98
	BNE NoENMCLC_098

	LDA ENEMY_LEV098_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV098_Flags

NoENMCLC_098:

	LDA LEV_Memory
	CMP #99
	BNE NoENMCLC_099

	LDA ENEMY_LEV099_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV099_Flags

NoENMCLC_099:

	LDA LEV_Memory
	CMP #100
	BNE NoENMCLC_100

	LDA ENEMY_LEV100_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV100_Flags

NoENMCLC_100:

	LDA LEV_Memory
	CMP #101
	BNE NoENMCLC_101

	LDA ENEMY_LEV101_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV101_Flags

NoENMCLC_101:

	LDA LEV_Memory
	CMP #102
	BNE NoENMCLC_102

	LDA ENEMY_LEV102_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV102_Flags

NoENMCLC_102:

	LDA LEV_Memory
	CMP #103
	BNE NoENMCLC_103

	LDA ENEMY_LEV103_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV103_Flags

NoENMCLC_103:

	LDA LEV_Memory
	CMP #104
	BNE NoENMCLC_104

	LDA ENEMY_LEV104_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV104_Flags

NoENMCLC_104:

	LDA LEV_Memory
	CMP #105
	BNE NoENMCLC_105

	LDA ENEMY_LEV105_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV105_Flags

NoENMCLC_105:

	LDA LEV_Memory
	CMP #106
	BNE NoENMCLC_106

	LDA ENEMY_LEV106_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV106_Flags

NoENMCLC_106:

	LDA LEV_Memory
	CMP #107
	BNE NoENMCLC_107

	LDA ENEMY_LEV107_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV107_Flags

NoENMCLC_107:

	LDA LEV_Memory
	CMP #108
	BNE NoENMCLC_108

	LDA ENEMY_LEV108_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV108_Flags

NoENMCLC_108:

	LDA LEV_Memory
	CMP #109
	BNE NoENMCLC_109

	LDA ENEMY_LEV109_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV109_Flags

NoENMCLC_109:

	LDA LEV_Memory
	CMP #110
	BNE NoENMCLC_110

	LDA ENEMY_LEV110_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV110_Flags

NoENMCLC_110:

	LDA LEV_Memory
	CMP #111
	BNE NoENMCLC_111

	LDA ENEMY_LEV111_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV111_Flags

NoENMCLC_111:

	LDA LEV_Memory
	CMP #112
	BNE NoENMCLC_112

	LDA ENEMY_LEV112_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV112_Flags

NoENMCLC_112:

	LDA LEV_Memory
	CMP #113
	BNE NoENMCLC_113

	LDA ENEMY_LEV113_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV113_Flags

NoENMCLC_113:

	LDA LEV_Memory
	CMP #114
	BNE NoENMCLC_114

	LDA ENEMY_LEV114_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV114_Flags

NoENMCLC_114:

	LDA LEV_Memory
	CMP #115
	BNE NoENMCLC_115

	LDA ENEMY_LEV115_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV115_Flags

NoENMCLC_115:

	LDA LEV_Memory
	CMP #116
	BNE NoENMCLC_116

	LDA ENEMY_LEV116_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV116_Flags

NoENMCLC_116:

	LDA LEV_Memory
	CMP #117
	BNE NoENMCLC_117

	LDA ENEMY_LEV117_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV117_Flags

NoENMCLC_117:

	LDA LEV_Memory
	CMP #118
	BNE NoENMCLC_118

	LDA ENEMY_LEV118_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV118_Flags

NoENMCLC_118:

	LDA LEV_Memory
	CMP #119
	BNE NoENMCLC_119

	LDA ENEMY_LEV119_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV119_Flags

NoENMCLC_119:

	LDA LEV_Memory
	CMP #120
	BNE NoENMCLC_120

	LDA ENEMY_LEV120_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV120_Flags

NoENMCLC_120:

	LDA LEV_Memory
	CMP #121
	BNE NoENMCLC_121

	LDA ENEMY_LEV121_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV121_Flags

NoENMCLC_121:

	LDA LEV_Memory
	CMP #122
	BNE NoENMCLC_122

	LDA ENEMY_LEV122_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV122_Flags

NoENMCLC_122:

	LDA LEV_Memory
	CMP #123
	BNE NoENMCLC_123

	LDA ENEMY_LEV123_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV123_Flags

NoENMCLC_123:

	LDA LEV_Memory
	CMP #124
	BNE NoENMCLC_124

	LDA ENEMY_LEV124_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV124_Flags

NoENMCLC_124:

	LDA LEV_Memory
	CMP #125
	BNE NoENMCLC_125

	LDA ENEMY_LEV125_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV125_Flags

NoENMCLC_125:

	LDA LEV_Memory
	CMP #126
	BNE NoENMCLC_126

	LDA ENEMY_LEV126_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV126_Flags

NoENMCLC_126:

	LDA LEV_Memory
	CMP #127
	BNE NoENMCLC_127

	LDA ENEMY_LEV127_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV127_Flags

NoENMCLC_127:

	LDA LEV_Memory
	CMP #128
	BNE NoENMCLC_128

	LDA ENEMY_LEV128_Flags
	ORA ENEMY_LEV_Clear_Temp
	STA ENEMY_LEV128_Flags

NoENMCLC_128:
	RTS

Fiskbit
Posts: 202
Joined: Sat Nov 18, 2017 9:15 pm

Re: Simplify long, repetitive code.

Post by Fiskbit » Fri Sep 04, 2020 6:15 am

Is this any more complicated than just doing this?

Code: Select all

  LDX LEV_Memory
  BEQ Done
  CPX #129
  BCS Done
  LDA ENEMY_LEV_Flags_Table-1,X
  ORA ENEMY_LEV_Clear_Temp
  STA ENEMY_LEV_Flags_Table-1,X
Done:
  RTS
This assumes your level flags are all consecutive in memory.

sdm2
Posts: 33
Joined: Wed Feb 05, 2020 12:59 pm
Location: Poland

Re: Simplify long, repetitive code.

Post by sdm2 » Fri Sep 04, 2020 10:08 am

Can I make an table with variables in it? I thought not.
How to define them? .dw? .db?
Fiskbit wrote:
Fri Sep 04, 2020 6:15 am
This assumes your level flags are all consecutive in memory.
Yes.

Fiskbit
Posts: 202
Joined: Sat Nov 18, 2017 9:15 pm

Re: Simplify long, repetitive code.

Post by Fiskbit » Fri Sep 04, 2020 5:08 pm

Here, ENEMY_LEV_Flags_Table = ENEMY_LEV001_Flags. I used this name for clarity. This is simply an array of all of the levels' flags, where the index is the level number. Because your levels start at 1 instead of 0, I have to subtract 1 from the address.

If you're using .dw, that implies you want indirection, which you only need if the data isn't laid out in memory consecutively. In that case, you would have the address of each variable in ROM, load that address into a zero-page variable, set X to 0, and access the variable with LDA ($zp,X) and STA ($zp,X). This is slower and clunkier, and doesn't make sense when you can do the code I wrote in my last post.

It sounds like you're really not familiar with indexed instructions, so I suggest you practice using them; they are critical. LDA address,X will load from address+X. In this case, because all of your variables are consecutive, the level number is the offset of a given variable from the first one; that is, level 1 is at n+0, 2 is at n+1, 3 is at n+2, 4 is at n+3, etc. So, you can simply use the level number as the offset. The one caveat is that you're using 1 to mean level 1 instead of using 0. This is inconvenient because the first thing is at address+0, not address+1, so you either need to subtract 1 from the index (LDX LEV_Memory, DEX) or from the address (LDA address-1,X). You would normally want to represent the first of something as 0 instead of 1.

sdm2
Posts: 33
Joined: Wed Feb 05, 2020 12:59 pm
Location: Poland

Re: Simplify long, repetitive code.

Post by sdm2 » Fri Sep 04, 2020 5:21 pm

thanks, that explains a lot.
Fiskbit wrote:
Fri Sep 04, 2020 5:08 pm
It sounds like you're really not familiar with indexed instructions, so I suggest you practice using them; they are critical
It's true, I have a poor understanding of programming at all - I try to do something, but generally still with poor results.

So I can just use the memory address where the first variable "ENEMY_LEV001_Flags" starts:

LDA $0700-1,X
ORA ENEMY_LEV_Clear_Temp
STA $0700-1,X

?

Fiskbit
Posts: 202
Joined: Sat Nov 18, 2017 9:15 pm

Re: Simplify long, repetitive code.

Post by Fiskbit » Fri Sep 04, 2020 5:29 pm

Yes, but use a label, not a raw value. Since ENEMY_LEV001_Flags is your first one, use ENEMY_LEV001_Flags-1.

Post Reply