Code Monkey home page Code Monkey logo

Comments (5)

SteveFosdick avatar SteveFosdick commented on June 12, 2024

Ok, I will have a look later.

from b-em.

SteveFosdick avatar SteveFosdick commented on June 12, 2024

OK, so when I looked at this the pause feature was indeed on Windows only.

It looks like it may have been introduced originally because the Windows port runs the actual emulation on one thread, i.e. that _mainthread function, and the UI and other Windows messages in another thread and needed a way to pause the emulation while the UI thread was tinkering with it, i.e. calling reset functions etc. Hooking pause up to a key was a bonus.

So in the version I have pushed to the sf/pause branch I have moved the implementation from win.c to main.c so it works on Linux too. I have also added the check for whether paused to the int50 function which is obviously called 50x a second from a timer and indicates. by incrementing fcount, that another frame should be processed so when paused it just doesn't increment it so the main loop will do whatever it does between frames, i.e. call wait(1). This should also use less CPU when paused as removing the sleep(100) when paused looks like it would busy wait.

There is a tiny bit of extra complexity in that within the context of main.c we only know if a key is down, not that it has just that moment been pressed so it necessary to track the previous state of the key to avoid acting more than once on the same keypress. I think this is preferable to having two separate implementations (and the Linux one would have to do that anyway).

from b-em.

ThomasAdam avatar ThomasAdam commented on June 12, 2024

I had a quick look at that commit. Again, looks OK, however I would say that:

  • Do we really need to keep adding extern to the definition of variables in header files? I'd say not, as it's not needed.
  • file-scoped static variables (i.e., those not declared static inside functions) do not need to be set explicitly to 0 as the compiler will do this (per the ANSI standard).
  • There's a tonne of whitespace changes here which are really distracting to the diff, not to mention nothing to do with adding a pause. Again, this is better addressed differently rather than just randomly always letting whitespace changes through.

from b-em.

SteveFosdick avatar SteveFosdick commented on June 12, 2024

On the question of 'extern' that is what makes what appears in the header file a declaration rather than a definition. The header file may be included in more than one module and #including a header is just included text - C has no proper concept of importing modules. So if the header file has a definition of a variable and the header file is included in multiple C modules then the variable is then defined in multiple modules. If the linker resolves that by pointing all references to one of those and removes the others then it is being helpful but it is not required to do that, it could just as well complain and not link the program.

On the question of static variables, some people use the '= 0' explicit syntax, which is harmless otherwise, to indicate that code elsewhere relies on the fact this variable starts out as zero whereas in many cases the initial value of a variable is of no consequence. Not everyone adopts that style but it isn't a broken thing to do.

On the question of the whitespace I didn't do that. It looks like at some point I turned on an option in Geany to remove trailing spaces from lines because I didn't want them for something I was writing rather than making minor changes to and it has obviously found some cases where a line consists only of spaces and a newline. If you want prepare a different version that keeps the functional changes but reverts the whitespace then be my guest but I don't propose to spend the time doing it.

from b-em.

SteveFosdick avatar SteveFosdick commented on June 12, 2024

This is now merged to master.

from b-em.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.