MiniMorse For 1K ZX81 Basic

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
Post Reply
TheSnial
Posts: 8
Joined: Sun Apr 14, 2019 10:42 pm

MiniMorse For 1K ZX81 Basic

Post by TheSnial »

This is always the kind of Morse Tutor I would have wanted to use, even though it doesn't care about the relative lengths of the dots and dashes. That's because I want a low-barrier to entry and I don't want it to be too guided, with me having to progress from Level 1 to whatever they've prescribed. Also, the basics of Morse code is simple, so a program that handles it should be simple.

Image

It's really simple to use, just type a letter or digit and it'll convert the character to a morse code made of dots and dashes. Alternatively, type a sequence of '.'s (to the right of the 'M') and '-'s (Shift+J), fairly quickly and it'll translate your Morse code. In that case it's best to select the sequence you want and remember it, then type it out rather than trying to read and copy it. You'll find you'll pick up the technique fairly quickly. It only shows one letter at a time.

MiniMorse encodes Morse into the arrays: K$ (to convert from a character to a pattern) and M$ (to convert from a pattern to a character). We can encode Morse without needing variable length strings, simply by preceding each Morse code pattern with a dash (or 1). This forces all the bit patterns to be different (e.g. E = 10 and H = 10000 instead of 0 and 0000 and reconciles the fact that in basic Morse code, there are no more than 5 symbols in a pattern, but there are more than 32 characters encoded.

I was surprised at how fast I could learn Morse code with this tutor! I wrote a bit of a blog about it:https://oneweekwonder.blogspot.com/2023 ... morse.html (which goes into more detail than here). I've attached a .zx file which is used by ZEsaruX, but I think it is fun to type the listing - it doesn't take long!
Attachments
MiniMorse.zx.zip
(7.64 KiB) Downloaded 45 times
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: MiniMorse For 1K ZX81 Basic

Post by XavSnap »

:shock:

M$ and K$ only used one time !
33 PRINT ".ETI..."(M);
40 LET A=CODE("ZYWS..." (CODE A$-27))
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
TheSnial
Posts: 8
Joined: Sun Apr 14, 2019 10:42 pm

Re: MiniMorse For 1K ZX81 Basic

Post by TheSnial »

Ha! Yes, that's a really good point! I did use an indexed literal string in part of the program, but it didn't occur to me to use it for the actual translation strings.

I could have saved quite a number of other bytes in the code by using CODE "x", VAL "x", NOT PI, SGN PI, kind of thing. Mostly I was just trying to get it into 1K (which wasn't hard). I might optimise it in a future iteration and I'd certainly include that improvement if I did!

-thanks.
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: MiniMorse For 1K ZX81 Basic

Post by XavSnap »

Code: Select all

   10 LET K$="ZYWSK457BJ»)+¾·="+CHR$ VAL "11"+"(¹2$>¼º?-.¿½¸£/:;1<"
   12 LET M$=".ETIANMSURWDKGOHVF.L.PJBXCYZQš.54.3...2›....:.16.œ....:7...8.90"
   13 LET M=1
   15 PRINT AT 0,0;
   16 PAUSE 4E4
   17 LET A$=INKEY$
   21 IF A$<>"." AND A$<>"-" THEN GOTO 40
   23 LET M=M*2+(A$="-")
   24 IF INKEY$<>"" THEN GOTO 24
   25 FOR F=1 TO 10
   27 LET A$=INKEY$
   29 IF A$="" THEN NEXT F
   31 IF A$<>"" THEN GOTO 23
   33 PRINT M$(M);
   35 GOTO 13
   40 LET A=CODE K$(CODE A$-27)
   50 PRINT ".-"(A-INT (A/2)*2+1);
   60 LET A=INT (A/2)
   70 IF A>1 THEN GOTO 50
   80 PRINT "      ";
   90 GOTO 15

Code: Select all

   10 LET I=PI/PI
   11 LET B=I+I
   13 LET M=I
   15 PRINT AT I-I,I-I;
   16 PAUSE 4E4
   17 LET A$=INKEY$
   21 IF A$<>"." AND A$<>"-" THEN GOTO VAL"40"
   23 LET M=M*B+(A$="-")
   24 IF INKEY$<>"" THEN GOTO VAL"24"
   25 FOR F=I TO VAL"10"
   27 LET A$=INKEY$
   29 IF A$="" THEN NEXT F
   31 IF A$<>"" THEN GOTO VAL"23"
   33 PRINT ".ETIANMSURWDKGOHVF.L.PJBXCYZQš.54.3...2›....:.16.œ....:7...8.90"(M);
   35 GOTO VAL"13"
   40 LET A=CODE (("ZYWSK457BJ»)+¾·="+CHR$ VAL "11"+"(¹2$>¼º?-.¿½¸£/:;1<")(CODE A$-27))
   50 PRINT ".-"(A-INT (A/B)*B+I);
   60 LET A=INT (A/B)
   70 IF A>I THEN GOTO VAL"50"
   80 PRINT "      ";
   90 GOTO VAL"15"
Attachments
MINI2.P
(609 Bytes) Downloaded 44 times
MINIMORSE.P
(769 Bytes) Downloaded 38 times
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
TheSnial
Posts: 8
Joined: Sun Apr 14, 2019 10:42 pm

Re: MiniMorse For 1K ZX81 Basic

Post by TheSnial »

Excellent! Here's a version that's only a mere 405 bytes long of actual code, with just 32b of variables. Using I to represent 1 doesn't yet save as much space as repeatedly using SGN PI does; similarly, B=I+I is slightly longer than using CODE "[Graphic+Shift+2]". I've replaced all the remaining numbers with either CODE "x" if the value was also a character and VAL otherwise. I could reduce variable usage a bit further by combining M and A as they're never used at the same time (though it wouldn't make the program shorter). ZEsarUX can't save the program as a .p properly, because I've changed RAMTOP and then did NEW to force it into 1K mode, so the .zx isn't representative of the real size.

Thanks for the space-saving challenge! Are there any other improvements?

Here's the listing and the .zx follows:
Image
Attachments
MinMorse.zx.zip
(7.64 KiB) Downloaded 45 times
Fruitcake
Posts: 346
Joined: Wed Sep 01, 2010 10:53 pm

Re: MiniMorse For 1K ZX81 Basic

Post by Fruitcake »

You could save 18 more bytes from the program as follows:
  • Save 3 bytes from the program by changing line 35 to GOTO PI, which would jump to line 3. Hence you could change line 13 to become line 3.
  • Save 4 bytes by changing line 31 to IF LEN A$ THEN GOTO CODE EXP PI
  • Save 2 byes by changing line 24 to IF LEN INKEY$ THEN GOTO CODE "/"
  • Save 1 byte by changing line 29 to IF NOT LEN A$ THEN NEXT F
  • Save 1 byte by changing line 21's GOTO CODE "C" to GOTO PI**PI, which will jump to line 36. Line 40 will therefore need to be changed to line 36.
  • Save 2 bytes by changing line 25 to FOR F=. TO PI*PI
  • Save 2 bytes by changing line 15 to PRINT AT .,.;
  • Save 3 bytes in line 80 by only printing 4 spaces and removing the semicolon.
TheSnial
Posts: 8
Joined: Sun Apr 14, 2019 10:42 pm

Re: MiniMorse For 1K ZX81 Basic

Post by TheSnial »

Thanks! Good insights here too! I hadn't really considered using LEN A$ in place of A$<>"" (2bytes) or NOT LEN A$ (saving 1b). I'd use GOTO PI and the FOR F ... PI*PI, but probably not the EXP PI and PI**PI as they might slow the program more than I'd want. For some applications though it'd be a better choice. Wow, I'm blown away by the idea that there's an even shorter version of 0: '.'. However, I found that although it uses less typed-in characters, it uses 5 bytes more memory space, because the '.' gets expanded into the byte sequence { 27, 114, 0, 0, 0, 0, 0}.

Still the rest of the savings apply and work for me, giving a new, 393 byte program :-)

And in other Morse news, thanks to this program, I can now remember the whole of the alphabet + digits! Yay! Takes me a bit of time for a few and I sometimes get P and R mixed up! J is 7 in binary with a dot at the beginning (like a lower case j upside down, ish); Q is like O, but with a '.' just before the end. UVW are related: U is '..-', V adds another dot, W doubles the dashes (and has one dot); X is like Y: -.--, but there's 2 points at the bottom, like X has two points vs Y. D, B and G are closely related -.. -... --. So, although I'm fairly slow, I have remembered it all now: an achievement after 40 years of half-hearted trying :D !

Image

Thanks everyone!
Attachments
Min2Morse.zx.zip
(7.46 KiB) Downloaded 34 times
Fruitcake
Posts: 346
Joined: Wed Sep 01, 2010 10:53 pm

Re: MiniMorse For 1K ZX81 Basic

Post by Fruitcake »

TheSnial wrote: Tue Jan 31, 2023 4:19 pm However, I found that although it uses less typed-in characters, it uses 5 bytes more memory space, because the '.' gets expanded into the byte sequence { 27, 114, 0, 0, 0, 0, 0}.
Yes now you mention it, obviously it would! Still, might come in handy some other time.

TheSnial wrote: Tue Jan 31, 2023 4:19 pm but probably not the EXP PI and PI**PI as they might slow the program more than I'd want
Yeah, size isn't everything!
User avatar
XavSnap
Posts: 1940
Joined: Sat May 10, 2008 4:23 pm
Location: 'Zx81 France' Fb group.

Re: MiniMorse For 1K ZX81 Basic

Post by XavSnap »

60 LET A=INT (A/B)
70 IF A>SGN PI THEN GOTO CODE"M"
=
60 IF INT (A/B)>SGN PI THEN GOTO CODE"M"

And 15 CLS ... reset to AT 0,0, line 80 can be deleted. But put the PAUSE before the CLS

8-)
Xavier ...on the Facebook groupe : "Zx81 France"(fr)
Post Reply