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#chip 12F683,8#config Osc = Int
#DefineKeyMapButnMap2' < Select keycode table to compileMain: KeyVal = 233 If KeyVal > 231 and KeyVal < 237 then Index1 = KeyVal - 231 ReadTable KeyMap, Index1, ButnVal Else ButnVal = 0 End IfGoto MainEndTableButnMap1' Map Button number to Key Code'Butn, KeyVal1' 2322' 2333' 2344' 2355' 236 End TableTableButnMap2' Map Button number to Alt Key Code'Butn, KeyVal5' 2322' 2331' 2343' 2354' 236 End Table
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.
if frame=0 then;which sprite to draw
erase_sprite (oldspx(temp),oldspy(temp)) ;erase sprite at last position
' 1 ;pointer to sprite 1 in table
sprite (spx(temp),spy(temp), 1 ) ;draw sprite1 at new position
else
erase_sprite (oldspx(temp),oldspy(temp)) ;erase sprite at last position
' 257 ;pointer to sprite 2 in table
sprite (spx(temp),spy(temp), 257) ;draw sprite2 at new position
end if
sub sprite ( in sprite_x, in sprite_y, in spritedata_ptr ) ;fills box with sprite data
table spritedata ;sprite 1
wh,bl,bl,bl,bl,bg,bg,bg,bg,bg,bg,bl,bl,bl,bl,wh
bg,bl,re,re,re,bl,bl,bg,bg,bl,bl,re,re,re,bl,bg
bg,bg,bl,re,re,re,bl,b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,bg
bg,bg,bg,bg,ye,ye,bg,bg,bg,bg,ye,ye,bg,bg,bg,bg
bg,bg,bg,bg,ye,bg,bg,bg,bg,bg,bg,ye,bg,bg,bg,bg
bg,bg,bg,ye,bg,bg,bg,bg,bg,bg,bg,bg,ye,bg,bg,bg
bg,bg,ye,bg,bg,bg,bg,bg,bg,bg,bg,bg,bg,ye,bg,bg
bg,bg,bg,ye,ye,bg,bg,bg,bg,bg,bg,ye,ye,bg,bg,bg
bg,bg,bg,bg,ye,ye,bg,bg,bg,bg,ye,ye,bg,bg,bg,bg
bg,bg,bg,bg,bg,ye,bg,bg,bg,bg,ye,bg,bg,bg,bg,bg
bg,bg,bg,bg,bg,bg,ye,bg,bg,ye,bg,bg,bg,bg,bg,bg
end table
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