mfld-fr / emu86

Intel IA16 emulator for embedded development
35 stars 6 forks source link

Refactor main loop #37

Closed mfld-fr closed 3 years ago

mfld-fr commented 3 years ago

Tried to make the main loop more readable:

ghaerr commented 3 years ago

Quick first review: very nice, exactly what is needed.

Lets hold overnight before commit. I'm deep inside #31 (^C terminal exit) and it's proving to be very, very strange. I have Linux VM running. However, I found in debugging that that we have another small problem: the atexit call in char-stdio.c ends up calling char_term multiple times when exit is called explicitly to end EMU86. Now, in this version, exit is removed and return is used from main, which will call exit in crt0.S. I suggest calling _exit in main to fix this. Or this can be done separately with my fix, when I finally figure it out!

ghaerr commented 3 years ago

@mfld-fr: In emu-main.c line 611, suggest changing 'return' to '_exit', and merge. This will fix multiple calls to char_term caused by atexit in char-stdio.c::char_init. The atexit is currently necessary because EMU86 may call exit at various times, and console could be left in raw mode. Better fix would be to replace all 'exit' calls with 'emu_term' which calls all image_close/con_term/serial_term and then 'exit'.

After merge, I will test Emscripten/browser port.

Thank you!

ghaerr commented 3 years ago

Update: I have tested Emscripten/browser support with this PR included and it works! However, there is a small tuneup that needs to be made for speed in timer-elks.c with SDL or Emscripten. I will submit tuning PR and instructions for Emscripten build after merge.

mfld-fr commented 3 years ago

Suggestion applied. Thanks for PR testing !