Page 1 of 1

7Eh near end of REM

Posted: Tue Mar 12, 2024 6:25 am
by stroebeljc
Forgive me if this has already been addressed, but I encountered a strange issue while trying to list my combo MC and BASIC program. The line after the REM (line 5 in my code) was either buried at the end of the REM or displayed with no line number (see picture), although the program ran correctly. When I tried to edit the REM line (line 0) with the BASIC editor, the ZX81 crashed.
Screenshot 2024-03-12 001027.png
Screenshot 2024-03-12 001027.png (8.65 KiB) Viewed 1617 times
I discovered that the problem was including an LD A,(HL) instruction (7Eh) within 5 bytes of the Newline. The listing interpreter expects that a numeric always follows a 7Eh, even in a REM. So, either don't place this instruction or data that could be equal to 7Eh at the end of your code, or add enough bytes to the end of the REM to allow the Newline to be properly handled by the BASIC lister.
Screenshot 2024-03-12 001146.png
Screenshot 2024-03-12 001146.png (8.83 KiB) Viewed 1617 times

Re: 7Eh near end of REM

Posted: Tue Mar 12, 2024 7:38 am
by dr beep
Why would you edit machinecode?

You should always place new versions of your code over the line, but better
code outside the ZX81 and built a .P from that.

In this way you can use much more of the RAM, like printerbuffer, sysvar and no loss of bytes for line nimbers and lengt or start of machinecode.

Re: 7Eh near end of REM

Posted: Tue Mar 12, 2024 1:09 pm
by stroebeljc
The point is the behavior of the BASIC lister. For small MC routines mixed with BASIC there may be lots of editing of lines after the REM. I also observed the crash at times when editing the BASIC line after REM. The behavior is undefined and care must be taken when working with mixed code.

I actually found this because I generated the program entirely using TASM and didn't observe a problem until I saw how it was listed.

Re: 7Eh near end of REM

Posted: Tue Mar 12, 2024 4:19 pm
by stroebeljc
I did find something on this topic in this ancient post.

Re: 7Eh near end of REM

Posted: Tue Mar 12, 2024 10:29 pm
by sboisvert
As you noted I observed this in that post you referenced.

Probably the best way to avoid this is to have a double 76h at the start of that 0 REM line, making the system omit displaying all the contents. You would still be able to list subsequent lines, with:

Code: Select all

LIST 5
in this case.