Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:01 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : DOS MMBasic 4.0 bug?

Author Message
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 09:57pm 09 Oct 2012
Copy link to clipboard 
Print this post

I think I've found a bug in DOS MMBasic 4.0.

The description for the Input$ command says it should return the carriage return and line feed as separate characters. It looks like it only returns the line feed character (ACSII 10, Hex 0A). It skips over carriage return characters (ASCII 13, Hex 0D) until it finds the next returnable character.

If I'm right, it will muck up any programs that read binary data from files, as well as ignoring the line feed in text files.

I've written a small data file and edited it with a hex editor so there are various combinations of CR and LF characters at the end of lines. ShowBug.bas reads the bytes from the data file one at a time and identifies any <CR> and <LF> characters.

Have I made any obvious mistakes?

If it's a bug, has it already been reported? I don't recall seeing anything about it on the forum.

2012-10-10_075635_ShowBug.zip

Thanks

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 10:39am 10 Oct 2012
Copy link to clipboard 
Print this post

This is not a new feature.
MMbasic will stop reading when it finds a ^Z (26 decimal) which is the old end of file marker.
There may be other control codes that have undesirable outcomes if you are hoping for binary input.

Being able to handle the various line endings and treating them the same can be very handy but I would like to have BINARY file IO as a mode on its own.

Jim
VK7JH
MMedit   MMBasic Help
 
James_From_Canb

Senior Member

Joined: 19/06/2011
Location: Australia
Posts: 265
Posted: 06:21pm 10 Oct 2012
Copy link to clipboard 
Print this post

I agree Jim. Binary file IO would be really useful.

However, these aren't binary files. I'm helping another member read text files that I suspect originated on a Linux system that only used LF as a line delimiter. The files were then edited in a Windows environment and CR LF pairs were added - sometimes before the LF, sometimes after.

The member's DOS MMBasic program reads from these text files and processes each line. The mish-mash of control characters stopped the program working properly, so with a bit of help he wrote another program to correct the control characters. It only identified the LF characters.

The DOS MMBasic language Manual says of the INPUT$ function:
"Will return a string composed of "nbr" characters read from a file previously opened for INPUT with the file number "fnbr". This function will read all characters including carriage return and new line without translation." (My bolding)

Given that it identified the Line Feed (aka new line) character, either MMBasic has a bug, or the manual is wrong.

I'll put in a bug report.

James
My mind is aglow with whirling, transient nodes of thought careening through a cosmic vapor of invention.

Hedley Lamarr, Blazing Saddles (1974)
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 08:01pm 10 Oct 2012
Copy link to clipboard 
Print this post

I think its only the DOS MMBasic that has the problem.
The DOS version also won't recognise the enter key on my numeric keypad.
Not a big problem once you know...

Jim

VK7JH
MMedit   MMBasic Help
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 01:06am 11 Oct 2012
Copy link to clipboard 
Print this post

Hi James, Interesting issue. I ran a series of tests on Duinomite Mega and Maximite SM1 (the original Dontronics one) and DOS MMBasic, all running MMBasic 4.

With the data file DATA.TXT, 58 bytes long, loaded on an SD card, SHOWBUG.BAS correctly loads all the characters including 0D's and 0A's without any changes (ie. the full 58 bytes) on both the Duinomite Mega and the Maximite SM1.

However, as you have allready discovered, MMBasic drops all the 0D's but keeps all the 0A's. I suspect that this is an issue for Windows/DOS rather than MMbasic but Geof may know more.

In my testing, I threw up a few more anomolies: When you XMODEM a file into the Duinomite/Maximite, 1A's are padded onto the end of the file up to the next 128 byte boundary. Don't know if this is TerraTerm XMODEM send or MMBasic XMODEM receive?

It gets even more interesting: When I LOAD "DATA.TXT" then SAVE "DATA_1.TXT" on both DM and MM, the resulting file DATA_1.TXT has all 0D's on their own to a 0D0A pair, all 0D0A pairs are left alone and all 0A's on their own are converted to a 0D0A pair!

I think I have all the above correct - just keeping track of where a file is and where it came from was a challenge;-)

Lastly, just a note, moving files between Windows/DOS and Linux often throws up some unexpected transformations. BTW, I have written a hexdump program to display any file in hex format in 16 hex bytes per line - copy below (still a bit to do on it - it pads out to a full screen with 0's but it may be useful in any testing you do).

Cheers, Doug.

' Program to dump a text file to the screen as hex
' - 80 characters per line and pausing each screen
' at 35 lines
Start:
Line Input "Enter file name to be displayed ? ",FileName$
Option Error Continue
Open FileName$ For Input As #1
FExists=0
If MM.ERRNO = 6 Then
Print "File does not exist"
Option Error Abort
Goto Start
EndIf
Option Error Abort
ChrCnt = 0
Do While NOT EOF(#1)
For ScreenLines = 1 to 35
ChrCnt$ = Format$(ChrCnt,"%04.0f")
Print ChrCnt$ + " ";
For CharInLineCount = 1 to 16
InputChar$ = Input$(1,#1)
ChrCnt = ChrCnt + 1
InputChar = Asc(InputChar$)
HexChar$ = Hex$(Asc(InputChar$))
If Len(HexChar$) = 1 Then
hexChar$ = "0" + HexChar$
EndIf
If CharInLineCount = 9 Then
Print " ";
EndIf
Print HexChar$ + " ";
Next CharInLineCount
Print
Next ScreenLines
Line Input "Press any key to continue - ",Junk$
Loop
End

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 01:28am 11 Oct 2012
Copy link to clipboard 
Print this post

Jim, I embedded a &H1A (decimal 26) inside a file then tried loading it as per previously above - in the DM, this loads up to the physical ? (logical ?) end of the file, including the 1A previously embedded so it does not appear to filter &H1A's, at least in the DM. I am going to do a bit more testing to se what characters are not accepted. Regards, Doug.

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 01:47am 11 Oct 2012
Copy link to clipboard 
Print this post

Sorry Guys, I'm a bit like a dog with a bone on this - I'm in a caravan in SA on my way around the world (Oz) with nothing better to do - the missus is in bed and I'm sitting here playing!!!

The code below generates a file with 256 bytes, values from &H00 to &HFF. Using my hexdump program above, I read all 256 bytes in correctly, no changes and no skips! This is on a DM running MMBasic 4.
Cheers, Doug.

' Program to create a text file with all byte values from 0 to 255

Start:
Line Input "Enter file name to be created ? ",FileName$
Option Error Continue
Open FileName$ For Output As #1
FExists=0
If MM.Errno = 6 Then
Print "File does not exist"
Option Error Abort
GoTo Start
EndIf
Option Error Abort
For byte_in = 0 To 255
Print #1,chr$(byte_in);
Next byte_in
Close #1
Error "Data file created" ' no error just the end.


... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 02:24am 11 Oct 2012
Copy link to clipboard 
Print this post

Last post guys honest!

When writing a file from DOS MMBasic using PRINT File_number, CHR$(value_0_thru_255)all values from 0 to 255 are written correct EXCEPT &H0A which is translated into the &H0D0A pair (ie. two bytes are written.

When reading a file in DOS MMBasic using INPUT$(nbr_chars,file_number), &H0D is dropped (ie. ignored) and &H1A is translated into &H0000 (a pair of nulls). Note that there is no End of File character as such, at least not in the range 0 thru 255.

Cheers, Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 10:49am 11 Oct 2012
Copy link to clipboard 
Print this post

XMODEM first:
"In my testing, I threw up a few more anomolies: When you XMODEM a file into the Duinomite/Maximite, 1A's are padded onto the end of the file up to the next 128 byte boundary. Don't know if this is TerraTerm XMODEM send or MMBasic XMODEM receive?"

XMODEM only works in 128 byte blocks and it has no way of knowing the size of the file so it has to pad the end with something.
In MMedit XMODEM pads with zeros, not 1A but either seems to be acceptable from my research.
In MMEdit I cheated and read the file size from the Maximite and truncate the pad characters off when transferring from the MM to the PC. I was not able to do it the other way (PC to MM)

On my W7 64bit PC DOS MMBasic definitely stops at 1A characters when reading using the original test program.
Different Windows versions may behave differently which will make fixing it even more fun!

Jim

VK7JH
MMedit   MMBasic Help
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 02:28pm 11 Oct 2012
Copy link to clipboard 
Print this post

"On my W7 64bit PC DOS MMBasic definitely stops at 1A characters when reading using the original test program.
Different Windows versions may behave differently which will make fixing it even more fun! "


Thanks Jim, Same here. I have led myself astray with poor programming! In my little hexdump program, the logic is wrong in that I continue to read characters after an EOF character is received to complete the number of lines of dump to 35. I have confirmed this is also true on the DM. My only consolation is that I believe I have proved the DM does not drop the <LF> &H0D character using the input$ function as happens in DOS MMBasic. Cheers, Doug.

PS. I love MMBasic and am in awe of the job Geoff has done but DOS MMBasic is extremely frustrating - no edit and many other weird things different to the MM version - the joys of trying to work with Redmond's product I guess!
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 03:14pm 11 Oct 2012
Copy link to clipboard 
Print this post

Panky,
May I add your hex dump program to the MM library as others may find it useful?

I would also like to offer a small mod which prints the text to the right of the hex codes, replacing any non-display characters with a full stop, in time honoured fashion.
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 03:19pm 11 Oct 2012
Copy link to clipboard 
Print this post

Panky,
May I add your hex dump program to the MM Library as others may find it useful?

I would also like to add a small mod which prints the text to the right of the dump, replacing any non-printable codes with a full stop, in time-honoured fashion.

Cheers,
Hugh

' Program to dump a text file to the screen as hex
' - 80 characters per line and pausing each screen
' at 35 lines
' Author Panky from The Back Shed forum Oct 2012
Start:
Line Input "Enter file name to be displayed ? ",FileName$
Option Error Continue
Open FileName$ For Input As #1
If MM.Errno = 6 Then
Print "File does not exist"
Option Error Abort
GoTo Start
EndIf
Option Error Abort
ChrCnt = 0
Do While Not Eof(#1)
For ScreenLines = 1 To 35
Text$=""
ChrCnt$ = Format$(ChrCnt,"%04.0f")
Print ChrCnt$ + " ";
For CharInLineCount = 1 To 16
InputChar$ = Input$(1,#1)
If Asc(InputChar$) < 32 Then
Text$ = Text$ + "."
Else
Text$ = Text$ + InputChar$
EndIf
ChrCnt = ChrCnt + 1
InputChar = Asc(InputChar$)
HexChar$ = Hex$(Asc(InputChar$))
If Len(HexChar$) = 1 Then
hexChar$ = "0" + HexChar$
EndIf
If CharInLineCount = 9 Then
Print " ";
EndIf
Print HexChar$ + " ";
Next CharInLineCount
Print Text$
Next ScreenLines
Line Input "Press any key to continue - ",Junk$
Loop
End
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 06:08pm 11 Oct 2012
Copy link to clipboard 
Print this post

  TassyJim said  
On my W7 64bit PC DOS MMBasic definitely stops at 1A characters when reading using the original test program.
Different Windows versions may behave differently which will make fixing it even more fun!
Jim

Hi Jim/Panky/James,

I confess - I'm the culprit that James has been helping with this issue. I've (actually "we've") written a program to read plain song lyric text (.txt) files, or folders of files, and turn them into time-stamped lyric text (.lrc) files that are readable on my TViX media player - some other players too. The media player can then display synchronised lyrics a line at a time on the TV or monitor so you can sing-along! To get the time-stamping you have to play the song on your PC and hit a key as each line finishes - the MMBasic "timer" function keeps track of time. It's considerably more complicated than that but you get the drift.

I'm using DOS MMBasic because all the music and lyrics and places you can download lyrics and the media player, are on my Windows PC and network. It's great being able to use MMBasic with the "System" command on my Windows system because now I can "program" things there in a language I can use. I'm no expert at programming but I'm having fun and I can improve my MMBasic skills for the hardware project things I'm also doing with the standard MMBasic.

My PC system is still using Win XP Home (SP2) - (my wife has claimed our new Win 7 gear) - and the issue is there with this, so it's common to 7 & XP apparently. I'm not sure about the 1A "substitute" character but the issue with CR & LF as James described it is certainly there.

It's good having some proper programming brains on this - it's gotten a smidge beyond me. BTW I'll be happy to post the code when it's a proper "goer" - it sort of is already actually but only on some .txt files.

Greg Edited by paceman 2012-10-13
 
brucepython

Regular Member

Joined: 19/06/2011
Location: Australia
Posts: 64
Posted: 06:15pm 11 Oct 2012
Copy link to clipboard 
Print this post

I just know that program is going to get me out of trouble one day!
Thanks for the effort that went into getting it done.
Can I suggest changing the third-last line to the following, purely to allow that legendary "ANY" key to be used.

Print "Press any key to continue." : Do While Inkey$="" : Loop

BruceEdited by brucepython 2012-10-13
 
rodent59
Newbie

Joined: 02/03/2012
Location: Australia
Posts: 7
Posted: 07:26pm 11 Oct 2012
Copy link to clipboard 
Print this post

Hugh,

TEXTLOOK.bas, already in the library, does a similar job.

Rod.
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 08:00pm 11 Oct 2012
Copy link to clipboard 
Print this post

  rodent59 said   Hugh,

TEXTLOOK.bas, already in the library, does a similar job.

Rod.


Yes it does, but some may prefer Panky's format.

There is just a small addition I would make to Bruce's change...

Print "Press any key to continue.";: Do while Inkey$="": Loop
Print


Without the semicolon and subsequent Print, the top line of the next page is lost.

Cheers,
Hugh
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 08:55pm 11 Oct 2012
Copy link to clipboard 
Print this post

Hugh,

Happy to have the program listed although as I said earlier, it still needs a bit of work regarding end of file. It appears possible to write a file with an embedded hex 1A with additional data following that but when read back, terminates at the 1A.

As Jim said earlier, it would be nice to have a real byte or binary i/o capability to do away with manipulating string characters with the constraints that offers.

I will keep plugging away at improvements and forward them to you as soon as I can. Cheers, Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 01:08pm 12 Oct 2012
Copy link to clipboard 
Print this post

  panky said   Hugh,

Happy to have the program listed although as I said earlier, it still needs a bit of work regarding end of file. It appears possible to write a file with an embedded hex 1A with additional data following that but when read back, terminates at the 1A.

As Jim said earlier, it would be nice to have a real byte or binary i/o capability to do away with manipulating string characters with the constraints that offers.

I will keep plugging away at improvements and forward them to you as soon as I can. Cheers, Doug.


Doug, it will be in the next library update.
Hugh
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1101
Posted: 03:56pm 12 Oct 2012
Copy link to clipboard 
Print this post

Off the original topic a bit but James has sent in some mods to my hexdump program that improve it considerably - thanks James (PS. Your inbox is full so I couldn't reply direct to your message ;-) ) For Hugh, updated hexdump below.

Cheers, Doug.

2012-10-13_015642_hexdump.zip
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
shoebuckle
Senior Member

Joined: 21/01/2012
Location: Australia
Posts: 189
Posted: 02:44pm 13 Oct 2012
Copy link to clipboard 
Print this post

  panky said   For Hugh, updated hexdump below.

Thanks Doug. Geoff is away so it will be about a month until the library gets updated with this and your CVanBM. In the meantime, if you have any other thoughts, please feel free to post them on The Back Shed or email to mmlib@geoffg.net .
Cheers,
Hugh
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024