/*                                                                           */
 /*                                   ace.h                                   */
 /*                                                                           */
-/*                      ACE system specific definitions                      */
+/*                      ACE system-specific definitions                      */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2001 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2015, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
     char            ad_name [17];       /* Name itself, ASCIIZ */
 };
 
-int aceDirOpen (char* dir);
-int aceDirClose (int handle);
-int aceDirRead (int handle, struct aceDirentBuf* buf);
+int __cdecl__ aceDirOpen (char* dir);
+int __cdecl__ aceDirClose (int handle);
+int __cdecl__ aceDirRead (int handle, struct aceDirentBuf* buf);
 
 /* Type of an ACE key. Key in low byte, shift mask in high byte */
 typedef unsigned int aceKey;
 #define aceOP_RPTRATE           11      /* Key repeat rate */
 
 /* Console functions */
-void aceConWrite (char* buf, size_t count);
-void aceConPutLit (int c);
-void aceConPos (unsigned x, unsigned y);
-void aceConGetPos (unsigned* x, unsigned* y);
+void __cdecl__ aceConWrite (char* buf, size_t count);
+void __cdecl__ aceConPutLit (int c);
+void __cdecl__ aceConPos (unsigned x, unsigned y);
+void __cdecl__ aceConGetPos (unsigned* x, unsigned* y);
 unsigned aceConGetX (void);
 unsigned aceConGetY (void);
-char* aceConInput (char* buf, unsigned initial);
+char __cdecl__* aceConInput (char* buf, unsigned initial);
 int aceConStopKey (void);
 aceKey aceConGetKey (void);
-int aceConKeyAvail (aceKey* key);
-void aceConKeyMat (char* matrix);
-void aceConSetOpt (unsigned char opt, unsigned char val);
-int aceConGetOpt (unsigned char opt);
+int __cdecl__ aceConKeyAvail (aceKey* key);
+void __cdecl__ aceConKeyMat (char* matrix);
+void __cdecl__ aceConSetOpt (unsigned char opt, unsigned char val);
+int __cdecl__ aceConGetOpt (unsigned char opt);
 
 /* Misc stuff */
-int aceMiscIoPeek (unsigned addr);
-void aceMiscIoPoke (unsigned addr, unsigned char val);
+int __cdecl__ aceMiscIoPeek (unsigned addr);
+void __cdecl__ aceMiscIoPoke (unsigned addr, unsigned char val);
 
 
 
 
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2000, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 #ifdef NDEBUG
 #  define assert(expr)
 #else
-extern void _afailed (const char*, unsigned);
+extern void __cdecl__ _afailed (const char*, unsigned);
 #  define assert(expr)  ((expr)? (void)0 : _afailed(__FILE__, __LINE__))
 #endif
 
 
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/* (C) 1998-2015, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
 
 
 
-unsigned int cbm_load (const char* name, unsigned char device, void* data);
+unsigned int __cdecl__ cbm_load (const char* name, unsigned char device, void* data);
 /* Loads file "name", from given device, to given address -- or, to the load
 ** address of the file if "data" is the null pointer (like load"name",8,1
 ** in BASIC).
 
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2000, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 int __fastcall__ DbgIsRAM (unsigned Addr);
 /* Return true if we can read and write the given address */
 
-char* DbgMemDump (unsigned Addr, char* Buf, unsigned char Len);
+char* __cdecl__ DbgMemDump (unsigned Addr, char* Buf, unsigned char Len);
 /* Create a line of a memory dump in the given buffer. The buffer contains
 ** the starting address (4 digits hex), then Len bytes in this format:
 ** "AAAA__XX_YY_ZZ_...". The passed char buffer must hold Len*3+5 bytes
 
 /*                                                                           */
 /*                                  lynx.h                                   */
 /*                                                                           */
-/*                     Lynx system specific definitions                      */
+/*                     Lynx system-specific definitions                      */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
 /*                           Sound support                                   */
 /*****************************************************************************/
 
-void lynx_snd_init ();
+void lynx_snd_init (void);
 /* Initialize the sound driver */
 
-void lynx_snd_pause ();
+void lynx_snd_pause (void);
 /* Pause sound */
 
-void lynx_snd_continue ();
+void lynx_snd_continue (void);
 /* Continue sound after pause */
 
 void __fastcall__ lynx_snd_play (unsigned char channel, unsigned char *music);
 /* Play tune on channel */
 
-void lynx_snd_stop ();
+void lynx_snd_stop (void);
 /* Stop sound on all channels */
 
 void __fastcall__ lynx_snd_stop_channel (unsigned char channel);
 /* Stop sound on all channels */
 
-unsigned char lynx_snd_active();
+unsigned char lynx_snd_active(void);
 /* Show which channels are active */
 
 /*****************************************************************************/
 
 */\r
 \r
 \r
-int uncompress (char* dest, unsigned* destLen,\r
-                const char* source, unsigned sourceLen);\r
+int __cdecl__ uncompress (char* dest, unsigned* destLen,\r
+                          const char* source, unsigned sourceLen);\r
 /*\r
    Original zlib description:\r
 \r
 
 /*
 ** Marc 'BlackJack' Rintsch, 06.03.2001
 **
-** unsigned int cbm_load(const char* name,
-**                       unsigned char device,
-**                       const unsigned char* data);
+** unsigned int __cdecl__ cbm_load(const char* name,
+**                                 unsigned char device,
+**                                 const unsigned char* data);
 */
 
 #include <cbm.h>
 /* loads file "name" from given device to given address or to the load address
 ** of the file if "data" is 0
 */
-unsigned int cbm_load(const char* name, unsigned char device, void* data)
+unsigned int __cdecl__ cbm_load(const char* name, unsigned char device, void* data)
 {
     /* LFN is set to 0; but, it's not needed for loading
     ** (BASIC V2 sets it to the value of the SA for LOAD).
 
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001-2012, Ullrich von Bassewitz                                      */
+/* (C) 2001-2015, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
     ** Search for it in the list of builtin functions.
     */
     if (Name[0] == '_') {
-
         /* Search in the symbol table, skip the leading underscore */
         SymEntry* E = FindGlobalSym (Name+1);
 
-        /* Did we find it in the top level table? */
+        /* Did we find it in the top-level table? */
         if (E && IsTypeFunc (E->Type)) {
-
             FuncDesc* D = E->V.F.Func;
 
-            /* A function may use the A or A/X registers if it is a fastcall
-            ** function. If it is not a fastcall function but a variadic one,
-            ** it will use the Y register (the parameter size is passed here).
-            ** In all other cases, no registers are used. However, we assume
-            ** that any function will destroy all registers.
+            /* A variadic function will use the Y register (the parameter list
+            ** size is passed there). A fastcall function will use the A or A/X
+            ** registers. In all other cases, no registers are used. However,
+            ** we assume that any function will destroy all registers.
             */
-            if (IsQualFastcall (E->Type) && D->ParamCount > 0) {
-                /* Will use registers depending on the last param */
-                unsigned LastParamSize = CheckedSizeOf (D->LastParam->Type);
-                if (LastParamSize == 1) {
-                    *Use = REG_A;
-                } else if (LastParamSize == 2) {
-                    *Use = REG_AX;
-                } else {
-                    *Use = REG_EAX;
-                }
-            } else if ((D->Flags & FD_VARIADIC) != 0) {
+            if ((D->Flags & FD_VARIADIC) != 0) {
                 *Use = REG_Y;
+            } else if (!IsQualCDecl (E->Type) && D->ParamCount > 0) {
+                /* Will use registers depending on the last param. */
+                switch (CheckedSizeOf (D->LastParam->Type)) {
+                    case 1u:
+                        *Use = REG_A;
+                        break;
+                    case 2u:
+                        *Use = REG_AX;
+                        break;
+                    default:
+                        *Use = REG_EAX;
+                }
             } else {
                 /* Will not use any registers */
                 *Use = REG_NONE;
 
 /* expr.c
 **
-** Ullrich von Bassewitz, 21.06.1998
+** 1998-06-21, Ullrich von Bassewitz
+** 2015-03-10, Greg King
 */
 
 
     IsFuncPtr = IsTypeFuncPtr (Expr->Type);
     if (IsFuncPtr) {
 
-        /* Check wether it's a fastcall function that has parameters */
-        IsFastcall = IsQualFastcall (Expr->Type + 1) && (Func->ParamCount > 0);
+        /* Check whether it's a fastcall function that has parameters */
+        IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type + 1) && (Func->ParamCount > 0);
 
         /* Things may be difficult, depending on where the function pointer
         ** resides. If the function pointer is an expression of some sort
         }
 
         /* If we didn't inline the function, get fastcall info */
-        IsFastcall = IsQualFastcall (Expr->Type);
+        IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type);
     }
 
     /* Parse the parameter list */
 
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2012, Ullrich von Bassewitz                                      */
+/* (C) 2000-2015, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
         */
         if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) {
             g_importmainargs ();
+
+            /* The start-up code doesn't fast-call main(). */
+            Func->Type->C |= T_QUAL_CDECL;
         }
 
         /* Determine if this is a main function in a C99 environment that
     PushLiteralPool (Func);
 
     /* If this is a fastcall function, push the last parameter onto the stack */
-    if (IsQualFastcall (Func->Type) && D->ParamCount > 0) {
-
+    if ((D->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Func->Type) && D->ParamCount > 0) {
         unsigned Flags;
 
-        /* Fastcall functions may never have an ellipsis or the compiler is buggy */
-        CHECK ((D->Flags & FD_VARIADIC) == 0);
-
         /* Generate the push */
         if (IsTypeFunc (D->LastParam->Type)) {
             /* Pointer to function */