Page 1 of 1

Trying to enter a line from a book fails for some reason

Posted: Wed Apr 12, 2017 2:48 pm
by Balrockus
I am reading through the book "Spectrum Machine Language for the Absolute Beginner edited William Tang". I have got to the section where I need to enter a program from the book into my emulator (Spectacular). The program is EZ-Code Machine Language Editor The image (book.png) below is a screenshot from the book of the listing. When I try to enter line 130 into my emulator it just errors with a flashing red square "E" (see screenshot emulator.png below).

I have entered line 130 as one whole line into the emulator and it wraps around. Is the problem the last

Code: Select all

(s$ > "`") 
? I am not sure if I have entered the correct character in quotes.

If this is not a question for this forum, could anyone please recommend where I could get some help with Spectrum Basic and Assembly programming please.

Cheers, Paul

Book.png
Book.png (75.55 KiB) Viewed 1231 times

emulator.png
emulator.png (1.8 KiB) Viewed 1231 times

Re: Trying to enter a line from a book fails for some reason

Posted: Wed Apr 12, 2017 3:49 pm
by RWAP
(I moved this topic to Spectrum software as I assume you mean using the emulator, Spectaculator).

I suppose this might be a bug in Spectaculator - you need to enter DEF FN using the CAPS SHIFT + SYMBOL SHIFT then SYMBOL SHIFT 1 key combination.

Is that how you did it?

The character in the last set of quotes should be Symbol Shift 7

Re: Trying to enter a line from a book fails for some reason

Posted: Wed Apr 12, 2017 4:02 pm
by RWAP
I just tested the line in Eighty One and it enters correctly without reporting any errors (using Symbol Shift 7 as the character in quotes)

I do not have Spectaculator

Re: Trying to enter a line from a book fails for some reason

Posted: Wed Apr 12, 2017 4:22 pm
by XavSnap
Yes, RWAP point the right error.

Have a look to the "error" cursor ! It point the syntax error after the command or function.

You typed "D" + "E" + "F" + " " + "F" + "N" and not the "DEF FN" function !

The error cursor is located after the "D"... and not after the "DEF FN" function...

Re: Trying to enter a line from a book fails for some reason

Posted: Sat Mar 10, 2018 1:05 am
by harlandski
By the way, I also had a problem with this line of the listing, but for a different reason. The expression:

Code: Select all

(s$  > "'")
was clearly a misprint in the book and should read:

Code: Select all

(s$ > "9")
The function is to parse hexadecimal numbers to decimal, but does not work unless you make this change to the published text.

Re: Trying to enter a line from a book fails for some reason

Posted: Sat Mar 10, 2018 2:10 am
by XavSnap
harlandski wrote:
Sat Mar 10, 2018 1:05 am
The expression:
(s$ > "'")
was clearly a misprint in the book and should read:
No, this command is correct.
The Basic take the ASCII character's value! (A$ character and ' character)
This command take the first character in the A$ chain.
Capture_spec.JPG
But, the A$ had to be set.
Try to print the A$ value after the reported error... and check if it's a null char. string!

Just try the a$>"/" expression... if target all decimals char. codes.
a$>"@" all hexa (upper case) and a$>"£" (lower case)

Re: Trying to enter a line from a book fails for some reason

Posted: Sat Mar 10, 2018 4:16 pm
by harlandski
Your reasoning looks amazing, but it just fails to properly parse hex unless you make the alteration I suggest. Before making the change the code was unworkable, and since making it, it works.

Just try a simplified version:

Code: Select all

10 DEF FN d(s$) = (s$ > "9") * (CODE s$-55)+(s$ <= "9") * (CODE s$ - 48) - (s$ > "'") * 32
20 PRINT FN d("9")
30 PRINT FN d("f")
This produces:

-23
15

15 is f in hex, but 9 in hex is not -23!

With my amendment:

Code: Select all

10 DEF FN d(s$) = (s$ > "9") * (CODE s$-55)+(s$ <= "9") * (CODE s$ - 48) - (s$ > "9") * 32
20 PRINT FN d("9")
30 PRINT FN d("f")
This produces the correct:

9
15