I am trying to use #IfDef to select either of 2 tables to compile & use but GCB always compiles the first table only (see in .asm).
I suspect the pre-processor is doing the tables first & as the 2 tables have the same name it ignores the second. [or out of scope for IfDef / I am not using correctly?]
I edit the table names ButnMap1 & ButnMap2 (& ReadTable ButnMap2, ...) with result = both tables in asm file, this confirms the 2 table same name condition.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The code below shows the method to use - It is a small tweak on what you had.
The compiler does not does what you typically expected with #IF. All tables are initially preprocessed and then when you 'use' that table the compiler the handles the actual table. The #IF have no impact on the tables - the compiler simply finds the first table (in your case as you have two of the same name) and then 'uses' it.
So, the method to resolve. Use different table names and then access via a constant.
' Testing #IfDef to choose Table
#chip12F683,8
#configOsc=Int
#DefineKeyMapButnMap2' < Select keycode table to compileMain:
KeyVal=233IfKeyVal>231andKeyVal<237thenIndex1=KeyVal-231ReadTableKeyMap, Index1, ButnValElseButnVal=0EndIfGotoMainEndTableButnMap1' Map Button number to Key Code'Butn, KeyVal1' 2322' 2333' 2344' 2355' 236EndTableTableButnMap2' Map Button number to Alt Key Code'Butn, KeyVal5' 2322' 2331' 2343' 2354' 236EndTable
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I used 2 tables same size for graphic shape data under the same name but used a pointer to the table name and added 257 for second table.
ifframe=0then;which sprite to drawerase_sprite(oldspx(temp),oldspy(temp));erase sprite at last position' 1 ;pointer to sprite 1 in tablesprite(spx(temp),spy(temp), 1);draw sprite1 at new positionelseerase_sprite(oldspx(temp),oldspy(temp));erase sprite at last position' 257 ;pointer to sprite 2 in tablesprite(spx(temp),spy(temp), 257);draw sprite2 at new positionendifsubsprite(insprite_x, insprite_y, inspritedata_ptr);fills box with sprite datatablespritedata;sprite 1wh,bl,bl,bl,bl,bg,bg,bg,bg,bg,bg,bl,bl,bl,bl,whbg,bl,re,re,re,bl,bl,bg,bg,bl,bl,re,re,re,bl,bgbg,bg,bl,re,re,re,bl,bg,bg,bl,re,re,re,bl,bg,bgbg,bg,bg,bl,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ye,bg,bg,bg,bg,bg,bg,ye,bg,bg,bg,bgbg,bg,bg,ye,bg,bg,bg,bg,bg,bg,bg,bg,ye,bg,bg,bgbg,bg,ye,bg,bg,bg,bg,bg,bg,bg,bg,bg,bg,ye,bg,bgbg,bg,bg,ye,ye,bg,bg,bg,bg,bg,bg,ye,ye,bg,bg,bgbg,bg,bg,bg,ye,ye,bg,bg,bg,bg,ye,ye,bg,bg,bg,bgbg,bg,bg,bg,bg,ye,bg,bg,bg,bg,ye,bg,bg,bg,bg,bgbg,bg,bg,bg,bg,bg,ye,bg,bg,ye,bg,bg,bg,bg,bg,bgendtable
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That was my method years ago. I sorted that method but wanted a read mydata where mydata could be table1, table2, table xxx., etc. So I'm interested in a different/better way.
Can mydata be table1, table2 when in a running program?
Last edit: stan cartwright 2022-04-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not really, just what worked at the time. Is there a way to read different tables other than if then or case?
I'm doing a sub "in my head" to read any table from a number. It will need an array and some vars. Just thinking of an elegant method of making a var be the pointer to any table.
I posted reading a table to an array and using the array vs just using reading the table.
Visually on glcd no difference! No speed difference but I didn't time it. So reading tables, which are in program memory ... lots of usually, is worth a thought to make it "easier".
See what I can do.
assuming tables are constant when compiled so know size of. This could .. or not be interesting.
Last edit: stan cartwright 2022-04-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to use #IfDef to select either of 2 tables to compile & use but GCB always compiles the first table only (see in .asm).
I suspect the pre-processor is doing the tables first & as the 2 tables have the same name it ignores the second.
[or out of scope for IfDef / I am not using correctly?]
I edit the table names ButnMap1 & ButnMap2 (& ReadTable ButnMap2, ...) with result = both tables in asm file, this confirms the 2 table same name condition.
ToniG a great post. Nice and easy to understand.
The code below shows the method to use - It is a small tweak on what you had.
The compiler does not does what you typically expected with #IF. All tables are initially preprocessed and then when you 'use' that table the compiler the handles the actual table. The #IF have no impact on the tables - the compiler simply finds the first table (in your case as you have two of the same name) and then 'uses' it.
So, the method to resolve. Use different table names and then access via a constant.
I used 2 tables same size for graphic shape data under the same name but used a pointer to the table name and added 257 for second table.
That was my method years ago. I sorted that method but wanted a read mydata where mydata could be table1, table2, table xxx., etc. So I'm interested in a different/better way.
Can mydata be table1, table2 when in a running program?
Last edit: stan cartwright 2022-04-25
@Stan - I remember this method. Very good.
Not really, just what worked at the time. Is there a way to read different tables other than if then or case?
I'm doing a sub "in my head" to read any table from a number. It will need an array and some vars. Just thinking of an elegant method of making a var be the pointer to any table.
I posted reading a table to an array and using the array vs just using reading the table.
Visually on glcd no difference! No speed difference but I didn't time it. So reading tables, which are in program memory ... lots of usually, is worth a thought to make it "easier".
See what I can do.
assuming tables are constant when compiled so know size of. This could .. or not be interesting.
Last edit: stan cartwright 2022-04-25