   if (!((pin>=2 && pin<=13) || (pin>=44 && pin <=46))) error(ANALOGWRITE, invalidpin, number(pin));
 #elif defined(__AVR_ATmega1284P__)
   if (!(pin==3 || pin==4 || pin==6 || pin==7 || (pin>=12 && pin<=15))) error(ANALOGWRITE, invalidpin, number(pin));
+#elif defined(ARDUINO_AVR_ATmega4809)  /* MegaCoreX core */
+  if (!((pin>=16 && pin<=19) || (pin>=38 && pin<=39))) error(ANALOGWRITE, invalidpin, number(pin));
 #elif defined(__AVR_ATmega4809__)
   if (!(pin==3 || pin==5 || pin==6 || pin==9 || pin==10)) error(ANALOGWRITE, invalidpin, number(pin));
 #elif defined(__AVR_ATtiny3216__)

/* uLisp AVR Version 2.9b - www.ulisp.com
   David Johnson-Davies - www.technoblogy.com - 25th September 2019

   Licensed under the MIT license: https://opensource.org/licenses/MIT
*/

#define SYMBOLTABLESIZE 512             /* Bytes */

#elif defined(ARDUINO_AVR_NANO_EVERY)
#define WORKSPACESIZE 1068-SDSIZE       /* Objects (4*bytes) */
#define EEPROMSIZE 256                  /* Bytes */
#define SYMBOLTABLESIZE BUFFERSIZE      /* Bytes - no long symbols */

#elif defined(ARDUINO_AVR_ATmega4809)   /* Curiosity Nano using MegaCoreX */
#define Serial Serial3
#define WORKSPACESIZE 1068-SDSIZE       /* Objects (4*bytes) */
#define EEPROMSIZE 256                  /* Bytes */
#define SYMBOLTABLESIZE BUFFERSIZE      /* Bytes - no long symbols */

#define WORKSPACESIZE 1068-SDSIZE       /* Objects (4*bytes) */
#define EEPROMSIZE 256                  /* Bytes */
#define SYMBOLTABLESIZE BUFFERSIZE      /* Bytes - no long symbols */
