I am new to GCB (as in just started using it over thse last 6 months).
The compiler I am using is v98 (Installed Aug 18 on WIn 7 64bit).
The code compiles with no errors, yet when I want to make a "hex" file the process returns an error.
The Error is:
Error: GCASM: Symbol 40.0 has not been defined
Why or more importantly how can this be solved.
It still creates a hex file and when i have looked at the ".lst" file it does not list any errors in the assembly, so what gives? I have assumed the hex file is just a by-prodcut of the process and cannot be sure it is okay to use as is.
The code is for the PIC 18F4550 to initially handle a PS/2 keyboard or mouse input and re-map it to my old 1985 computer (AMSTRAD CPC6128).
The code is:
'===============================================================''Purpose:TohandleaPS/2keyboardormouseconnectedtoa'PICchipwhichcanreadinthePS/2codesequence'andthendecodeittotheequivalentCPCscanline'code.TheMappingwilltakewhattheusertypesin'asseenonthePS/2keyboardandcorrectitforthe'CPCequivalent.''Thisprogramdoesmapnotkeyforkey,rathertoget'thesameuserexpectationwhenaPS/2keypressed.'Forexampleshift2onPS/2isan'@'butonthe'CPCitsa" so the "@" is mapped to the cpc'scanlinewhichwouldbeusedforCPCkeyboard'equivalent.Thebenefittothismodeofoperationis'thattheuserisnotgoingtoseeanunexpectedkey'displayedforwhatisshownontheactualPS/2'keyboard.Theexceptiontothisisthepoundsymbol'whichisnotshownonastandardPS/2keyboard,but'isontheCPC.Thepoundsymbolisaccessedviathe'shift`(Shiftbacktick,aboveTABkey).''ThekeymappingisthedefaultQWERTYkeyboardand'theuseofanunusedkeysmaybeexpandedtoselect'AZERTYorQWERTYkeyboard.''===============================================================#option explicit'#chip PIC18F4550,20'#define CONF_WORD = 0x3f3a#define CLOCK_FREQUENCY = 20#define SIMULATION_WAITMS_VALUE = 0''DefinePortsdirectiontouse'#option Volatile PortA.7#option Volatile PortA.6'DIRPORTAIn'PS/2keyboard/MousetoPIC'PICtoHostkeyscanlinerequest.'CPCtoPICscanlinerequest'DIRPORTBOut'PICtoCPCscanlinecoderesponse''hardwaredefinedlinesinschematic'#define cpc_scan = PORTA 'Bits 0 to 3 for CPC scan line request#define cpc_output = PORTB 'defines our output scan data port'#define ps2_kdata = PORTA.7 'ps/2 keyboard data pin#define ps2_kclock = PORTA.6 'ps/2 keyboard clock pin#define ps2_mdata = PORTA.4 'ps/2 mouse data pin#define ps2_mclock = PORTA.5 'PS/2 mouse clock pin'#define PS2_CTRLKEY = 0x14#define PS2_LEFTSHIFT = 0x12#define PS2_RIGHTSHIFT = 0x59#define PS2_CAPSLOCK = 0x58'==============================================================='VariablesDeclarations'===============================================================Dimreg_wAswordDimreg_statusAsByte''PS/2control/shift/capslockkeyflags'Dimps2_shiftAsBitDimps2_capsAsBitDimps2_ctrlAsBit'Dimps2_keyupasBit'Detectionofkeyup/downDimps2_doublecodeAsBit''datato/fromPS/2device'Dimps2_k_dataAsByteDimps2_m_dataasbyte''PS/2I/Oprocessingflags'Dimps2_kreadingAsBitDimps2_kwritingAsBitDimps2_kreaddoneAsBitDimps2_kparityAsBitDimps2_kbitcountAsByte'Dimps2_mreaddoneAsBitDimps2_mreadingAsBitDimps2_mparityAsBitDimps2_mbitcountAsByteDimps2_mousedat(4)asByteDimps2_mdidxasByte''cpckeymappingflags/variables'Dimsenddata2cpcasBitDimcpc_keyscanasByte'Outputfrom8255(lowernibble)Dimcpc_prevksasByteDimcpc_capsasbitDimcpc_yline(17)asbyte'outputforeachscanlineDimtiasByteDimyiasbyteDimxiasbyteDimsiasByteDimcpc_rowcolasbyteDimbit_mask(9)asByteDimIntProcFlagasBit'===============================================================''PS/2keyboardscancodes.'Formatofeachbyteis:'cpcrowvalueinupper'cpccolumninlower''IndexisthePS/2keycode.''ScancodesinthesetablesarefortheUSkeyboardlayout.''===============================================================Tablecpc_qwerty_kb''unshiftedcodes(128byte,indexof0to127)'255,255,255,255,255,255,255,255,255,255,255,255,255,149,55,255255,34,54,255,56,148,145,255,255,255,152,119,150,132,146,255255,135,136,134,131,129,130,255,255,104,120,118,116,115,114,255255,103,119,101,117,100,113,255,255,255,87,102,99,98,97,255255,88,86,84,83,81,82,255,255,72,71,67,69,68,80,255255,255,146,255,50,69,255,255,151,54,23,52,255,255,255,255255,255,255,255,255,255,168,255,255,38,255,53,255,255,255,25540,24,39,37,21,36,147,255,255,69,22,66,70,20,255,255''shiftedcodes(128bytes,indexof128to255)'255,255,255,255,255,255,255,255,255,255,255,255,255,149,65,255255,34,54,255,56,148,145,255,255,255,152,119,150,132,67,255255,135,136,134,131,129,130,255,255,104,120,118,116,115,114,255255,103,119,101,117,100,65,255,255,255,87,102,99,113,70,255255,88,86,84,83,82,97,255,255,72,71,67,70,68,66,255255,255,55,255,50,66,255,255,151,54,23,52,255,255,255,255255,255,255,255,255,255,168,255,255,38,255,53,255,255,255,25540,24,39,37,21,36,147,255,255,69,22,66,70,20,255,255'EndTable'======================================================================'StartofexecutableofPICChip'======================================================================bit_mask=1,2,4,8,16,32,64,128cpc_yline=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0'ps2_mdidx=1ps2_mreaddone=0'ps2_kreaddone=0ps2_kwriting=0'ps2_caps=0'Nocapslockps2_shift=0'noleftorrightshiftkeypressedps2_ctrl=0'noleft/rightcontrolkeypressed''OPTION_REG.INTEDG=0INTCON2=0x70'triggersinterruptsonfallingedgeINTCON.INT0E=1'enablesRB0Interruptforps/2INTCON.GIE=1'enableallinterruptsIntProcFlag=0'OnInterruptPORTChangecallMyIntHandler'HandleInt'ps2_kclock=ps2_kclock'Triggerinteruptps2_mclock=ps2_mclock'Triggerinterupt'Wait1000ms'pauses1secondforPS/2I/OTosettle'IntProcFlag=1'loop:'=================================================================''AnsweringscanlinerequestsfromCPCtodeterminewhichkey'thecpcthinkswaspressed.''Scanlinerequests0to9areforkeyboard'Scanlinerequests10to15areforjoystick''=================================================================cpc_keyscan=cpc_scan'getCPCscanrequest'ifcpc_prevks<>cpc_keyscanthen''Newscanlinerequest'cpc_prevks=cpc_keyscancpc_keyscan=(cpc_keyscanAND15)+1'Calcindexintoarraycpc_output=!cpc_yline(cpc_keyscan)'SenddatatoCPCcpc_yline(cpc_keyscan)=0'ifps2_capsthencpc_yline(9)=cpc_yline(9)ORbit_mask(7)'Bit6endif'ifps2_shiftthencpc_yline(3)=cpc_yline(3)ORbit_mask(6)'Bit5endif'ifps2_ctrlthencpc_yline(3)=cpc_yline(3)ORbit_mask(8)'Bit7endif'endif'=================================================================''CheckifPS/2devicedatahasbeenreadin''=================================================================Ifps2_kreaddoneThen''HavenowcompletedreadingPS/2keyboardcodesequence'LetsnowconverttoAMSTRADCPCscanlinecode''ps2_k_data=PS/2keycodeforthekeypressed(7bit)'ps2_keyup=0keyhasbeenpressed.'1keyreleased.'ifps2_k_data=PS2_CAPSLOCKandnotps2_keyupThen''CAPSlockhasbeenpressed(togglestate)'ps2_caps=notcpc_capsps2_keyup=1'skipanyprocessingwiththiskeyendif'ifps2_k_data=PS2_CTRLKEYThen''SetupCtrlflagifpressedorreleased'ps2_ctrl=notps2_keyupendif'ifps2_k_data=PS2_LEFTSHIFTorps2_k_data=PS2_RIGHTSHIFTThen''SetupshiftflagviaPS/2leftorrightshiftkeydetection'ps2_shift=notps2_keyupps2_k_data=ps2_k_data+128'indextoshiftedcodesendif'==================================================================''SearchforwhichCPCequivalenttobecomeactive''==================================================================if!ps2_keyupthen''Akeyhasbeenpressed'ps2_keyup=1ifps2_doublecodethen'cpc_rowcol=255ifps2_k_data=17thencpc_rowcol=34'copykeyendififps2_k_data=20thencpc_rowcol=56'Controlkeyendififps2_k_data=90thencpc_rowcol=23'KeypadEnterendififps2_k_data=107thencpc_rowcol=33'Cursorleftendififps2_k_data=113thencpc_rowcol=49'ClearKeyendififps2_k_data=114thencpc_rowcol=19'CursorDownendififps2_k_data=116thencpc_rowcol=18'CursorRightendififps2_k_data=117thencpc_rowcol=17'CursorUpendif'elseReadTablecpc_qwerty_kb,ps2_k_data,cpc_rowcolendif'ifcpc_rowcol<>255Then''Assumerowisnotgreaterthan10'Assumerowisnotgreaterthen8'yi=cpc_rowcol/16'Calculaterowxi=cpc_rowcol-yi*16'Calculatecolumn'cpc_yline(yi)=cpc_yline(yi)ORbit_mask(xi)endifendifendif'exitforloop:''=================================================================''Checkmouseinputs''=================================================================ifps2_mreaddoneThen''DatafromPS/2mousenowreadin,soletshandleitnow''PS/2mousedataformatis:'bit76543210'Byte1YOXOYSXS1MBRBLB'2--------XMovement-----'3--------YMovement-----''YO=Yoverflow(1=meansmovement>255)'XO=Xoverflow(1=meansmovement>255)'YS=Ydirectionsign(0=Up,1=Down)'XS=Xdirectionsign(0=Right,1=Left)'MB=Middlebutton(1=Pressed,0=notpressed)'RB=Rightbutton(1=Pressed,0=notpressed)'LB=Leftbutton(1=Pressed,0=notpressed)'yi=16'MouseactslikeJoysticktoCPC'ifcpc_yline(yi)=0then''CPCisfreetogetmouseinput'ifps2_mousedat(3)<>0then''Mousehasmovedupordown'ifps2_mousedat(1).5Then''MousehasmovedDown(SetBit1)'xi=2'bit1Else''MousehasmovedUp(SetBit0)'xi=1'bit0endif'cpc_yline(yi)=cpc_yline(yi)ORbit_mask(xi)endif'ifps2_mousedat(2)<>0then''Mousehasmovedleftorright'ifps2_mousedat(1).4Then''MousehasmovedLeft(SetBit2)'xi=3'bit2Else''MousehasmovedRight(SetBit3)'xi=4'bit3endif'cpc_yline(yi)=cpc_yline(yi)ORbit_mask(xi)endif'ifps2_mousedat(1).1Then''Mousehasrightbuttondepressed'AssignthistoFire1(Bit4)'cpc_yline(yi)=cpc_yline(yi)ORbit_mask(5)'bit4endif'ifps2_mousedat(1).0Then''Mousehasleftbuttondepressed'AssignthistoFire2(Bit5)'cpc_yline(yi)=cpc_yline(yi)ORbit_mask(6)'bit5endif'ifps2_mousedat(1).2Then''Mousehasmiddlebuttondepressed'Assigntheactionto'spare'lineofjoystick(Bit6)'cpc_yline(yi)=cpc_yline(yi)ORbit_mask(7)'bit6endif'endifendif'ps2_mreaddone=0ps2_kreaddone=0ps2_mreading=1'flagreadanothermousesequenceps2_kreading=1'flagreadanotherkeyboardsequenceps2_keyup=1'Gotoloop'End'SubMyIntHandler'HandleInt''handleinterruptsonPORTAtoget/sendPS/2Data(KB/Mouse).'ifIntProcFlag=0Then''Flagnowprocessingthisinterrupt(preventanotherinterrupt'interferingwiththisone).'IntProcFlag=1'Preventre-enterwhilehandingcurrent'reg_status=STATUS'preservestatusreg_w=WREG'preserveWREG''================================================================='Ifps2_kreadingThen'ifnotps2_kclockthen''KeyboardtoPICtransmission(PS/2Keyboardclockislow)''CodedoesnothandlePAUSEandPRNTSCRNkeys(dontusethem!)'ifps2_kbitcount<>0then'ifps2_kbitcount<9then'ps2_k_data=FnLSR(ps2_k_data,1)ps2_k_data.7=ps2_kdataps2_kparity=ps2_k_dataXorps2_kparityendifelse''firstbitgot,somoretoget'ps2_kreaddone=0ps2_kparity=0ps2_k_data=0endif'ps2_kbitcount=ps2_kbitcount+1'ifps2_kbitcount=11then''Alldataforthisbytegot.'ps2_kbitcount=0''Checkifthesequenceisadoublecodesequence'ifps2_k_data=0xE0thenps2_doublecode=1'flagdoublebytesequenceElseps2_doublecode=0'flagsequenceis1Byteendif''Checkifthesequenceisabreaksequence'ifps2_k_data=0xF0thenps2_keyup=1'flagnon-breaksequenceElseps2_keyup=0'flagbreaksequenceendif'ifps2_k_data<>0xE0ANDps2_k_data<>0xF0then''ThecurrentdatafromthePS/2isnowcompleted'thecodesequence'ps2_kreaddone=1endif'endifendifendif''================================================================='ifps2_mreadingThen'ifnotps2_mclockthen''MousetoPICtransmission(PS/2MouseClockislow)'ifps2_mbitcount<>0then'ifps2_mbitcount<9then'ps2_m_data=FnLSR(ps2_m_data,1)ps2_m_data.7=ps2_mdataps2_mparity=ps2_m_dataXorps2_mparityendif'else''firstbitgot,somoretoget'ps2_mreaddone=0ps2_mdidx=0ps2_m_data=0ps2_mparity=0endif'ps2_mbitcount=ps2_mbitcount+1'ifps2_mbitcount=11then''Alldataforthisbytegot.'ps2_mbitcount=0ps2_mdidx=ps2_mdidx+1ps2_mousedat(ps2_mdidx)=ps2_m_dataifps2_mdidx=3Then''Saved3bytesofmousedatasocode'sequenceisnowcomplete'ps2_mreaddone=1endifendifendifendif''================================================================='exit_int_sub:STATUS=reg_statusWREG=reg_wIntProcFlag=0endifendsub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The issue is caused by the XOR statement when you are XOR a bit and a byte. Line 439
~~~
dim myTemp as bit
myTemp = ps2_k_data.7 Xor ps2_kparity 'is this the correct bits??? I do not know.
ps2_kparity = myTemp
~~~
I suspect that 'ps2_mparity = ps2_m_data Xor ps2_mparity' will also require changing.
Please use the workaround above but we will look at resolving asap.
Anobium
PS: As a newbee your coding style is excellent. As I was able to isolate this issue in a few moments.
- You should not need the STATUS and WREG handlers we that is automatic in Great Cow BASIC.
- You may want to change the label loop: to a DO - LOOP, to remove the GOTO loop. I was surprised this compiled with the use of a reserved word as a label. :-)
Nice program - sorry for the issue in the generated ASM.
Last edit: Anobium 2018-09-09
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello everyone,
I am new to GCB (as in just started using it over thse last 6 months).
The compiler I am using is v98 (Installed Aug 18 on WIn 7 64bit).
The code compiles with no errors, yet when I want to make a "hex" file the process returns an error.
The Error is:
Error: GCASM: Symbol 40.0 has not been defined
Why or more importantly how can this be solved.
It still creates a hex file and when i have looked at the ".lst" file it does not list any errors in the assembly, so what gives? I have assumed the hex file is just a by-prodcut of the process and cannot be sure it is okay to use as is.
The code is for the PIC 18F4550 to initially handle a PS/2 keyboard or mouse input and re-map it to my old 1985 computer (AMSTRAD CPC6128).
The code is:
@Ray
The issue is caused by the XOR statement when you are XOR a bit and a byte. Line 439
~~~
dim myTemp as bit
myTemp = ps2_k_data.7 Xor ps2_kparity 'is this the correct bits??? I do not know.
ps2_kparity = myTemp
~~~
I suspect that 'ps2_mparity = ps2_m_data Xor ps2_mparity' will also require changing.
Please use the workaround above but we will look at resolving asap.
Anobium
PS: As a newbee your coding style is excellent. As I was able to isolate this issue in a few moments.
- You should not need the STATUS and WREG handlers we that is automatic in Great Cow BASIC.
- You may want to change the label loop: to a DO - LOOP, to remove the GOTO loop. I was surprised this compiled with the use of a reserved word as a label. :-)
Nice program - sorry for the issue in the generated ASM.
Last edit: Anobium 2018-09-09
Anobium,
Thanks for the advice. It does now work with out the error.
The DO...LOOP is something I should have used for proper software coding (i have been a programmer since my uni days, like 30+ years ago).
The code i change to is:
tmpbit = ps2_kdata Xor ps2_kparity
ps2_kparity = tmpbit
I also realised that ps2_k_data should have been ps2_kdata (was a fat finger problem).
Rap Palmer