Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate FillDispatchTable with a Source Generator and method attribute like [InterruptHandler(AL = 0x38, BH = 0x23, SetCarryFlagOnError = true] #374

Open
maximilien-noal opened this issue Jul 7, 2023 · 0 comments
Labels
enhancement New feature or request feature request This would be good to have low priority Fixing this is not urgent, or would take too much manpower for too little gain refactoring Involves refactoring existing code

Comments

@maximilien-noal
Copy link
Member

maximilien-noal commented Jul 7, 2023

Is your feature request related to a problem? Please describe.

Filling out the FillDispatchTable method is a long and repetitive task, prone to errors. Especially for the DOS kernel, which is very large.

An error can be for example: the same key is used in the dictionary for several interrupt handlers, leading to an exception when the emulator initializes.

Describe the solution you'd like

A Source Generator could take care of that instead. Driven by a method attribute. For a code that is supposed to run when AL and/or AL and AH (which means AX), and/or BL are certain values, and that is supposed to set the carry flag on error:


public void ChangeCurrentDirectory(bool calledFromVm) {
        string newDirectory = GetStringAtDsDx();
        if (_loggerService.IsEnabled(LogEventLevel.Verbose)) {
            _loggerService.Verbose("SET CURRENT DIRECTORY: {NewDirectory}", newDirectory);
        }
        DosFileOperationResult dosFileOperationResult = _dosFileManager.SetCurrentDir(newDirectory);
        SetStateFromDosFileOperationResult(calledFromVm, dosFileOperationResult);
    }

Could be instead:

[InterruptHandler(AL = 0x38, SetCarryFlagOnError = true]
public void ChangeCurrentDirectory(bool calledFromVm) {
        string newDirectory = GetStringAtDsDx();
        if (_loggerService.IsEnabled(LogEventLevel.Verbose)) {
            _loggerService.Verbose("SET CURRENT DIRECTORY: {NewDirectory}", newDirectory);
        }
        DosFileOperationResult dosFileOperationResult = _dosFileManager.SetCurrentDir(newDirectory);
        SetStateFromDosFileOperationResult(calledFromVm, dosFileOperationResult);
    }

The FillDispatchTable method would be generated, with entries such as:

        _dispatchTable.Add(0x3B, new Callback(0x3B, () => ChangeCurrentDirectory(true)));

We would only have to declare the class as partial and to call FillDispatchTable in the ctor.

And the compiler could be used to raise a compiler error when several handlers share the same values in the callback handlers dictionnary (that would require writing an analyzer).

Describe alternatives you've considered

None.

Additional context

Interrupt handlers that use the value of AL and other registers to determine what code to run also exist in the EMS handler, for example.

@maximilien-noal maximilien-noal added enhancement New feature or request low priority Fixing this is not urgent, or would take too much manpower for too little gain refactoring Involves refactoring existing code feature request This would be good to have labels Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature request This would be good to have low priority Fixing this is not urgent, or would take too much manpower for too little gain refactoring Involves refactoring existing code
Projects
None yet
Development

No branches or pull requests

1 participant