Skip to content

Add semicolon and hex notation support to the MOS VDU command#118

Open
HeathenUK wants to merge 2 commits intobreakintoprogram:mainfrom
HeathenUK:feature_VDUCommand
Open

Add semicolon and hex notation support to the MOS VDU command#118
HeathenUK wants to merge 2 commits intobreakintoprogram:mainfrom
HeathenUK:feature_VDUCommand

Conversation

@HeathenUK
Copy link
Contributor

Conscious decision to not support comma (rather than whitespace) delimited values, as this would increase code complexity and depth exponentially given the potential for whitespace, comma and semicolon to all act as a delimiter.

Conscious decision to not support comma (rather than whitespace) delimited values, as this would increase code complexity and depth exponentially given the potential for whitespace, comma and semicolon to all act as a delimiter.
src/mos.c Outdated
Comment on lines +663 to +664
value_str += 2;
len -= 2;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these 2 lines should be removed and let strtol() call below to deal with this prefix. Otherwise, the parsing code will allow input like 0x0xFE to be parsed as a valid number.

Also, the independent checks for prefix/suffix should probably be converted to sequence of if / elseif. The idea is to accept as valid only numbers with at most one prefix or suffix, not any combination of all possible prefixes/suffixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on those two lines, since strtol can handle 0x prefixes there's no need.

We discussed the second point and it costs us nothing to deal with situations where a user may double up on notation.

Comment on lines +660 to +675
// Check for '0x' or '0X' prefix
if (len > 2 && (value_str[0] == '0' && tolower(value_str[1] == 'x'))) {
base = 16;
}

// Check for '&' prefix
if (value_str[0] == '&') {
base = 16;
value_str++;
len--;
}
// Check for 'h' suffix
if (len > 0 && tolower(value_str[len - 1]) == 'h') {
value_str[len - 1] = '\0';
base = 16;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is cool - belt & braces style

I had a wild thought on hex handling... it might be nice for hex values to automatically be variable/arbitrary length. so 0x1 or 0x12 would send a single byte, 0x123 or 0x1234 two bytes, 0x12345 or 0x123456 three bytes, and so on

you could just interpret the string one byte at a time. the only tricky part really is dealing with odd length strings, where the first character is a stand-alone nibble rather than a full byte character pair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants