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

Bug: Bad assembly code generated for bytes marked as 'Text' #65

Open
ChristopheF opened this issue Oct 6, 2021 · 5 comments
Open

Bug: Bad assembly code generated for bytes marked as 'Text' #65

ChristopheF opened this issue Oct 6, 2021 · 5 comments

Comments

@ChristopheF
Copy link

Diztinguish allows me to mark any bytes as 'Text' in a project. However, if non-printable characters are marked as text, Diztinguish generates an asm output that asar cannot process.

Example: in a ROM where there is a C-like string containing a single underscore, I marked the two bytes as being 'Text' (the underscore itself, and the following 00 byte marking the end of the string).
The asm file generated by Diztinguish contains this: db "_ " (Here I wrote a space after the underscore but there is actually a 00 byte in the asm file which asar cannot process, causing the following error message:

test.asm:725: error: (E5029): Mismatched quotes. [ db "_]

If I only mark the underscore character as 'Text' and I use '8-Bit Data' for the 00 byte, then the asm file is fine and assembles correctly.
Yet it does not seem logical not to mark the 00 as text as it is part of the string.

The same issue occurs with any other non-printable characters like line feed, or most Japanese text data.
I think Diztinguish should only output quoted characters for byte values corresponding to ASCII printable characters. For any other byte value, it should output hex bytes so that asar will understand the asm file.

@binary1230
Copy link
Collaborator

whew. nice find! I will have a look. language bugs... phew.

@binary1230
Copy link
Collaborator

reminder to self, check out: #73

@binary1230
Copy link
Collaborator

for this issue, potentially the simplest implementation to make this play nice with Asar would be to modify IsPrintableCharacter() to exclude any non-ASCII-printable chars from strings.

while doing that might produce assembly output that Asar doesn't choke on, it might result in strings that could have been more human-readable if we were doing localized/unicode text better in the disassembly output.

@binary1230
Copy link
Collaborator

2023 update too is that in #73 are commits that exclude newlines, linefeeds, and nulls already (by breaking up strings and including them as individual data bytes).

I haven't tested it on non-english text though so it might still be handling the case you mentioned here. if you get a sec feel free to test out latest version see what it generates

@ChristopheF
Copy link
Author

ChristopheF commented Feb 19, 2024

I just tested with Diz v2.3.1.2. Things are much better! But not yet perfect because I stumbled on one last issue.
Bytes marked as text data are now output in the asm file as either quoted strings (for printable characters) or with raw byte values (for non-printable characters).

In my test sample, I have this piece of text data:
Raw bytes
0x18 0xC0 0x0A 0x80 0x49 0xC0 0x14 0x41 0x21 0x41 0x00 0x00
Text generated with Diz export disassembly
G5191_: db ";", $C0, $0A, $80, "+", $C0, $00, $80, $14, "A!A", $17, $80, "3", $80, $00, $00

This export looks fine. However, when asar runs it generates the following error for this line:
error: (E5088): Define 'A' wasn't found.

In order to fix this issue, I had to insert a \ before the "!" inside the quoted string. The exclamation mark seems to mean something special for asar that it tries to process. With this line:
G5191_: db ";", $C0, $0A, $80, "+", $C0, $00, $80, $14, "A\!A", $17, $80, "3", $80, $00, $00
asar does not complain anymore, and it generates an output ROM file that is perfectly identical to the source ROM file that I initially imported into Diz. To fix this issue, Diz asm output should escape the ! characters with \ in the output? Or it may output ! characters just like any other non printable character as a raw byte value.

Anyway many thanks for your support, and keep up the good work on diz (I am patiently waiting version 3)

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

No branches or pull requests

2 participants