Hallo Besucher, der Thread wurde 3,4k mal aufgerufen und enthält 12 Antworten

letzter Beitrag von Bananzi65 am

LLVM-MOS and the function scanf

  • Hi to everyone,


    I'm trying to do my first steps in C-programming the Mega 65 wilt the LLVM-MOS compiler/linker. I'm struggling with the scan-function. The following code will compile without any errors, but when I let it run on the XMega65-Emulator, I'm waiting for my machine, thus I have to use the emulator, than it crashes with the following screen output:



    Any ideas or hints regarding this issue? Problem of the scanf implementation or of the emulator?


    The bad guy is obviously the scanf-function. After commenting it out the code is producing the expected behavior.

  • Hi Kibabalu!

    I compiled your prg on my Mac and started it on Xemu. After providing the date of today I see fast changing border and background colors, which are not in sync, so they produce kind of an animating line desaster - which may not be intended?!

    But nevertheless it does not really crash. The first time you start the prg on a restarted Xemu, you have an illegal write operation. When you ignore this silently, you can start the prg multiple times on the same Xemu session w/o problems.

    (The screenshot of the lines is of course just a moment of a wild flickering situation.)


    I have:

    llvm-mos-17.0.0

    Xemu - next - 20240121115517

    ROM 920388 beta (which shlould be the same as the release)



    I have also unexpected crashes with my project as soon as it grows in the 24kb area of simple computation tasks. No VIC related stuff at all. I am really not sure if llvm-mos is ready for the M65. Do you have additional documentation for it, which explains limits and expectations of the system? A little lost with that... :-(


    Or is there a more stable C for M65 out there, I should try instead? Maybe the "old rabbits" have some tips for us?

  • Oh, thank you for testing. The flickering border after computing and printing the day of the year is the desired behavior.


    Thus, the code seems to run for you. I'm using a "selfmade" older core inside my emulator, because I don't own a physical Mega 65 machine yet.


    I'll try to "produce" a more recent core to test again.


    I startet with the LLVM-MOS toolchain, because it is supposed to be more efficient regarding memory and computing time than the CC65 compiler. I don't have any deeper knowledge with it.

  • I believe it's a ROM bug, see this issue on ROM: https://github.com/MEGA65/mega65-rom-public/issues/129

    So basically this is same as would be on a real MEGA65, the only difference that Xemu being an emulator can report _some_ problem at least ("unhandled memory access") while on real MEGA65 the problem is silently ignored and you have a "silent crash" ...


    As far as I know (as the issue describes that as well), it's more likely a bad/invalid DMA job done by the ROM when trying to scroll the screen.


    By the way, the issue states: "Starting with ROM 920382, llvm-mos's implementation of printf() appears to crash sometimes". So, it's a good test to try this with an older ROM than 920382, if there is no crash there, it's very likely that indeed, this is the same bug. But I would think it's the case, especially it's also LLVM-MOS/printf related problem, looks the same issue for me at the first glance at least.

  • I think also, it's a ROM bug. I compiled the same code for an C64 and it run well on the emulator.


    But in my case it's the scanf function and not the printf function. Maybe another error.

    Maybe. However the test program seems to contain printf as well, so I am not sure which causes the problem. I would bet more on the printf side of the story, since it seems that ROM bug is about scrolling the screen on output, thus it's more likely. However, for sure, I can't be 100% sure.

  • Or is there a more stable C for M65 out there, I should try instead? Maybe the "old rabbits" have some tips for us?

    You can try the Mega65-port of vbcc (get the latest vbcc6502-distribution from http://www.compilers.de/vbcc). It supports 32bit instructions, comes with a C-library adapted for M64, and allows using the entire available RAM.

  • I think also, it's a ROM bug. I compiled the same code for an C64 and it run well on the emulator.


    But in my case it's the scanf function and not the printf function. Maybe another error.

    Maybe. However the test program seems to contain printf as well, so I am not sure which causes the problem. I would bet more on the printf side of the story, since it seems that ROM bug is about scrolling the screen on output, thus it's more likely. However, for sure, I can't be 100% sure.

    I can confirm that hypothesis with my project. I have no scanf, but printf and a reproducible crash where the screen would need to scroll. I will see what it does when I replace scrolling by roll over to screen start…