0

I know this is a noob question bit I am not familiar with c++ . My understanding is that arduino code compiles in c++ and this is what causes the problem in compiling.

The code below will compile fine in codeblocks and will run correctly , however if I use the same code without any modifications then it will produce an error at compile time.

heres is the .ino file

#include "MCS6502.h"

int8_t ram [65535];
//////CALL BACK FUNCTION ///////////////////////////////////////////////
uint8_t readBytesFunction(uint16_t add) {
    uint8_t tc = 5;
    tc = ram[add];
    return tc;
}
//////CALL BACK FUNCTION ///////////////////////////////////////////////
void writeBytesFunction(uint16_t add,uint8_t bb)  {
}
void setup()
{
    Serial.begin(115200);
    Serial.println();

    ///CODE BELOW WILL COMPILE AND RUN IN CODEBLOCKS BUT WILL NOT COMPILE IN ARDUINO

    /////////////////////////////////////////////////////////////////////
    MCS6502ExecutionContext context;
    MCS6502Init(&context, readBytesFunction, writeBytesFunction, NULL);  // Final param is optional conte>

    MCS6502Reset(&context);

    MCS6502Tick(&context); //use timings
    MCS6502ExecNext(&context);  //as fast as possible
}

these are the errors after compiling in arduino for esp32

MCS6502.ino: In function 'void setup()':

wahid_MCS6502:22:27: error: invalid conversion from 'uint8_t (*)(uint16_t)' {aka 'unsigned char (*)(short unsigned int)'} to 'MCS6502DataReadByteFunction' {aka 'unsigned char (*)(short unsigned int, void*)'} [-fpermissive]

     MCS6502Init(&context, readBytesFunction, writeBytesFunction, NULL);  // Final param is optional conte>

                           ^~~~~~~~~~~~~~~~~

 

 MCS6502.h:91:33: note:   initializing argument 2 of 'void MCS6502Init(MCS6502ExecutionContext*, MCS6502DataReadByteFunction, MCS6502DataWriteByteFunction, void*)'

     MCS6502DataReadByteFunction readByteFn,

     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

 MCS6502:22:46: error: invalid conversion from 'void (*)(uint16_t, uint8_t)' {aka 'void (*)(short unsigned int, unsigned char)'} to 'MCS6502DataWriteByteFunction' {aka 'void (*)(short unsigned int, unsigned char, void*)'} [-fpermissive]

     MCS6502Init(&context, readBytesFunction, writeBytesFunction, NULL);  // Final param is optional conte>

                                              ^~~~~~~~~~~~~~~~~~

 

 MCS6502.h:92:34: note:   initializing argument 3 of 'void MCS6502Init(MCS6502ExecutionContext*, MCS6502DataReadByteFunction, MCS6502DataWriteByteFunction, void*)'

     MCS6502DataWriteByteFunction writeByteFn,

     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~

exit status 1

invalid conversion from 'uint8_t (*)(uint16_t)' {aka 'unsigned char (*)(short unsigned int)'} to 'MCS6502DataReadByteFunction' {aka 'unsigned char (*)(short unsigned int, void*)'} [-fpermissive]

what do i need to do it compiles in arduino ?? apologies if some details are missing from this question but its my 1st ever time asking a question here.

many thanks

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
davidos
  • 1
  • 2
  • 2
    If code does not compile you should include the error messages in the question. Please read [ask] with a [mcve]. Try and produce the smallest complete code that reproduces the error(s). – Richard Critten May 31 '22 at 14:41
  • In the preferences of the Arduino IDE you can switch on verbose output during compilation. – the busybee May 31 '22 at 14:43
  • exit status 1 invalid conversion from 'uint8_t (*)(uint16_t)' {aka 'unsigned char (*)(short unsigned int)'} to 'MCS6502DataReadByteFunction' {aka 'unsigned char (*)(short unsigned int, void*)'} [-fpermissive] – davidos May 31 '22 at 14:58
  • 1
    you should [edit] this error into your question – Alan Birtles May 31 '22 at 15:03
  • The error message seems pretty clear. You are supposed to pass a function which takes _two_ arguments, not one. The second parameter should be of type `void*`. The code is also broken in C. – user17732522 May 31 '22 at 15:07
  • please forgive me on this as I am a total noob in c/c++ , but it does work in codeblocks Can you please modify so I can get it to compile in arduino ? Many thanks – davidos May 31 '22 at 15:10

1 Answers1

1

I'm guessing that you are using this library?

Looking at the signatures of the callback functions both require a final void* parameter which your callbacks are missing.

You need:

uint8_t readBytesFunction(uint16_t add, void*) {
    uint8_t tc = 5;
    tc = ram[add];
    return tc;
}
void writeBytesFunction(uint16_t add,uint8_t bb, void*)  {
}
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • Thankyou Alan ! , You are an absolute star !! , I did say I was a noob and completely missed that , a million and 1 thanks ! – davidos May 31 '22 at 15:16
  • Sorry alan , I spoke too soon ! after compiling I now get this error : undefined reference to `MCS6502Init(_MCS6502ExecutionContext*, unsigned char (*)(unsigned short, void*), void (*)(unsigned short, unsigned char, void*), void*)' – davidos May 31 '22 at 15:52
  • @davidos see https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix – Alan Birtles May 31 '22 at 16:34
  • Thanks again alan , thing is the code does work in codeblocks so puzzled why it does not compile in arduino – davidos May 31 '22 at 21:46
  • I'd guess you've configured code blocks differently to the Arduino – Alan Birtles Jun 01 '22 at 06:07
  • Many thanks once again, , seriously you have been an absolute star in helping me on this , BUT , that link you provided is massive and I would not know where to begin! So I can close this , could you be so kind to amend the offending line : MCS6502ExecutionContext context; so that hopefully it will finally compile ? – davidos Jun 01 '22 at 09:37
  • If you have a new question then you should raise a new question, asking questions in the comments on an answer to a previous question isn't how this site works – Alan Birtles Jun 01 '22 at 10:29
  • OK , first time here so will live and learn ! thanks , and will do as you suggested.. – davidos Jun 01 '22 at 11:33