if (n < 33) Select (n) Case 0 ... Case 32 End SelectElse if (n>66) Select (n) Case 67 ... Case 69 End SelectElse Case 33 ... Case66End if
After a bit of experimenting, I've discovered that reflection is slower than I originally thought. About 3.5x slower than using Select/Case. But using function pointers in an array was fastest taking 1/3 the time of Select/Case.
psub oo_opcode(op_byte)on op_byte gosub op_0,op_1,op_2,op_3,op_4,op_5,op_6,op_7,op_8,op_9,op_10,op_11,op_12,op_13,op_14,op_15,op_16,op_17,op_18,op_19,op_20,op_21,op_22,op_23,op_24,op_25,op_26,op_27,op_28,op_29,op_30,op_31,op_32,op_33,op_34,op_35,op_36,op_37,op_38,op_39,op_40,op_41,op_42,op_43,op_44,op_45,op_46,op_47,op_48,op_49,op_50,op_51,op_52,op_53,op_54,op_55,op_56,op_57,op_58,op_59,op_60,op_61,op_62,op_63,op_64,op_65,op_66,op_67,op_68,op_69,op_70,op_71,op_72,op_73,op_74,op_75,op_76,op_77,op_78,op_79,op_80,op_81,op_82,op_83,op_84,op_85,op_86,op_87,op_88,op_89,op_90,op_91,op_92,op_93,op_94,op_95,op_96,op_97,op_98,op_99,op_100,op_101,op_102,op_103,op_104,op_105,op_106,op_107,op_108,op_109,op_110,op_111,op_112,op_113,op_114,op_115,op_116,op_117,op_118,op_119,op_120,op_121,op_122,op_123,op_124,op_125,op_126,op_127,op_128,op_129,op_130,op_131,op_132,op_133,op_134,op_135,op_136,op_137,op_138,op_139,op_140,op_141,op_142,op_143,op_144,op_145,op_146,op_147,op_148,op_149,op_150,op_151,op_152,op_153,op_154,op_155,op_156,op_157,op_158,op_159,op_160,op_161,op_162,op_163,op_164,op_165,op_166,op_167,op_168,op_169,op_170,op_171,op_172,op_173,op_174,op_175,op_176,op_177,op_178,op_179,op_180,op_181,op_182,op_183,op_184,op_185,op_186,op_187,op_188,op_189,op_190,op_191,op_192,op_193,op_194,op_195,op_196,op_197,op_198,op_199,op_200,op_201,op_202,op_203,op_204,op_205,op_206,op_207,op_208,op_209,op_210,op_211,op_212,op_213,op_214,op_215,op_216,op_217,op_218,op_219,op_220,op_221,op_222,op_223,op_224,op_225,op_226,op_227,op_228,op_229,op_230,op_231,op_232,op_233,op_234,op_235,op_236,op_237,op_238,op_239,op_240,op_241,op_242,op_243,op_244,op_245,op_246,op_247,op_248,op_249,op_250,op_251,op_252,op_253,op_254,op_255returnop_0: // NOPnxtpc=1if monitormode=true if hex_or_dec = false // Decimal representation text 1200,placeopcodeslne,digits$(pc,5) text 1270,placeopcodeslne,digits$(op_byte,3) text 1460,placeopcodeslne,"NOP" else // Hex representation text 1200,placeopcodeslne,right$(hex$(pc),4) text 1270,placeopcodeslne,right$(hex$(op_byte),2) text 1460,placeopcodeslne,"NOP" endifendif// Do nothing!if execute=true ; no flags affectedfs = fsfz = fzf5 = f5fh = fhf3 = f3fpv = fpvfn = fnfc = fcexeTstates = 4endifreturn ;doneop_1: // LD BC,nnop$="LD BC,"nxtpc=3if monitormode=true address=pcptr+pc lsb=peekbyte(pcptr+pc+1) msb=peekbyte(pcptr+pc+2) num=msb*256+lsb if hex_or_dec = false // Decimal representation text 1200,placeopcodeslne,digits$(pc,5) text 1270,placeopcodeslne,digits$(op_byte,3) text 1320,placeopcodeslne,digits$(lsb,3) text 1370,placeopcodeslne,digits$(msb,3) text 1460,placeopcodeslne,"LD BC , "+digits$(num,5) else // Hex representation text 1200,placeopcodeslne,right$(hex$(pc),4) text 1270,placeopcodeslne,right$(hex$(op_byte),2) text 1320,placeopcodeslne,right$(hex$(lsb),2) text 1370,placeopcodeslne,right$(hex$(msb),2) text 1460,placeopcodeslne,"LD BC , "+right$(hex$(num),4) endifendifif execute=true lsb=peekbyte(savepc+1) msb=peekbyte(savepc+2) regc=lsb regb=msb ; no flags affected fs = fs fz = fz f5 = f5 ; Not used fh = fh f3 = f3 ; Not used fpv = fpv fn = fn fc = fcexeTstates = 10endifreturn ; DONEop_2: // LD (BC),Anxt_pc=1if monitormode=true if hex_or_dec = false // Decimal representation text 1200,placeopcodeslne,digits$(pc,5) text 1270,placeopcodeslne,digits$(op_byte,3) text 1460,placeopcodeslne,"LD ( BC ) , A"+digits$(num,5) else // Hex representation text 1200,placeopcodeslne,right$(hex$(pc),4) text 1270,placeopcodeslne,right$(hex$(op_byte),2) text 1460,placeopcodeslne,"LD ( BC ) , A"+right$(hex$(num),4) endifendif if execute=true; memorybank positon bc will be loaded with the value of a; we could have array postion (b*256)+c = a but i think banks are needed for speedrega=(regb*256)+regc ; a will loaded in to memory location poke bc,a; no flags affectedfs = fsfz = fzf5 = f5fh = fhf3 = f3fpv = fpvfn = fnfc = fcendifexeTstates = 7return ;done
He is using C++
Takes a bit more typing than with select/case, but works faster.
' OO OpcodesSuperStrict'Import "Z80.bmx"' Create OO opcodes Array Local OO:Byte()[256] ' Create OO opcodes Array ' Assign the Functions into the Array elements Individualy 'OO[0] = OOO 'OO[1] = OO1 'OO[2] = OO2 ' Or ' As A big Line '///Local OO:Byte()[]=[OOO,OO1,OO2] ' Or Automate the decleration process' However the array pointers dont appear to be byte, short, int, string !!!???? For Local x:Byte = 0 To 2 Local text:String="OOO" text$=text$+String.fromint(x) text$= Right$(text$,3) OO[x] = text Next KeyDown(key_space) Print Print "OO Opcodes" Print ' Call Opcode 0 OO[0] ' Call Opcode 2 OO[2] ' Call Opcode 1 OO[1] Print Print "Press SPACE to EXIT" Repeat Until KeyDown(key_space) Function OOO:Byte()' NOP Print "0 ... NOP"End Function Function OO1:Byte()' LD BC,nn Print "1 ... LD BC,nn"End FunctionFunction OO2:Byte()' LD (BC),A Print "2 ... LD (BC),A"End Function
Its like buying a car but before you can use it you need to get some wheels, get some breaks, get some tyres an engine, but do i need petrol or diesel?
Your function names cannot start with a number, they must start with a letter or underscore. So you can have Function Op001() or Function _001(), but not Function 001().