Fix for mos_fgetc setting carry at every byte read with value >= 128 - #205
Open
envenomator wants to merge 1 commit into
Open
envenomator wants to merge 1 commit into
envenomator wants to merge 1 commit into
Conversation
Contributor
Author
|
Summary for the release notes: |
stevesims
approved these changes
Jul 15, 2026
stevesims
left a comment
Contributor
There was a problem hiding this comment.
nice work
such a subtle bug that's been in there since Dean first wrote this function nearly 4 years ago - hidden in plain sight 😁
I question the sanity of whoever it was that decided that char should be a signed 8-bit integer 😉
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MOS API call mos_fgetc (0x0C) incorrectly sets the carry flag after a byte is read with values >= 128.
This happens because in src/mos.c, the following code
An UINT24 type is returned to the caller, which the compiler handles transfers using the HL register.
for c = 0x80 or higher, signed char becomes 0xFFFF80, so the returned H byte becomes 0xFF.
The high byte is shifted in the upstream caller to the carry bit (in mos_api.asm):
A is returned as the character read, any carry set is indicating end-of-file, which is incorrectly set using above code for values read larger than 127.
This issue can be easily reproduced using the following BBC Basic V code (either z80 or ez80 versions):