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

Post Reply
Balrockus
Posts: 1
Joined: Wed Apr 12, 2017 2:26 pm

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

Post by Balrockus » Wed Apr 12, 2017 2:48 pm

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 1217 times

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

RWAP
Site Admin
Posts: 1265
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

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

Post by RWAP » Wed Apr 12, 2017 3:49 pm

(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

RWAP
Site Admin
Posts: 1265
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

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

Post by RWAP » Wed Apr 12, 2017 4:02 pm

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

User avatar
XavSnap
Posts: 495
Joined: Sat May 10, 2008 4:23 pm

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

Post by XavSnap » Wed Apr 12, 2017 4:22 pm

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...

harlandski
Posts: 5
Joined: Sun Feb 11, 2018 8:24 am

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

Post by harlandski » Sat Mar 10, 2018 1:05 am

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.

User avatar
XavSnap
Posts: 495
Joined: Sat May 10, 2008 4:23 pm

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

Post by XavSnap » Sat Mar 10, 2018 2:10 am

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)

harlandski
Posts: 5
Joined: Sun Feb 11, 2018 8:24 am

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

Post by harlandski » Sat Mar 10, 2018 4:16 pm

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

Post Reply