Jump to content
  • 0

Newbie file access and I/o struggles


AuntiePixel
 Share

Question

Edit: mystery solved. Thanks for the help.

 

TL:DR how can I open basic files from the downloadable Edit x16 editor in Windows, or write basic files in something like notepad++ that are readable by x16 basic?

 

Hi, I've been tinkering with the x16 emulator for a couple days and love it, but I'm kind of stumped by something. I've been writing basic at the x16 basic prompt. I want to switch to an actual editor. I want to be able to read my basic files in Windows 10 for copying/sharing/etc. I did finally figure out how to get a vhd set up. The emulator can use it, then I can mount it to access, then unmount to use again. But nothing seems compatible. I haven't found anything in Windows that can read/edit my basic files saved from x16 BASIC. I copied them to the new vhd to try the Edit x16 text editor, but it reads them as full of garbage. I tried Edit x16 without the vhd, but it doesn't see any storage device without the -sdcard flag. I wouldn't mind starting over with the Edit x16 editor, but when I mount the vhd in Windows, I haven't been able to open the files in anything I've tried. I guess the ideal solution would be a way to read the Edit x16 files in Windows, or else a way to write files in Windows in an editor like notepad++ and quickly load them on the emulator. Probably I'm missing something obvious, but I'm not sure what. 

Thanks for any help

Edited by AuntiePixel
Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

At present, the official emulator can only directly load and save BASIC programs in their tokenized form. If you want to export a BASIC program to a text file, you'll need to launch the official emulator with the "-echo" command line option, load your program, and then "LIST" it. From there, you should be able to copy the text from the console window.

If you have a BASIC program in text form that you want to "load" into the official emulator, you can use the "-bas <filename>" command line option to have the emulator automatically open the file and "type it in for you". You can also copy from the text editor and Ctrl-V to "paste" it, which works in a similar fashion under the hood.

Edited by StephenHorn
Link to comment
Share on other sites

  • 0

BASIC does not save programs as plain text. Instead, it tokenizes programs. The easiest way to convert a BASIC program to text (as described in the emulator documentation) is to run the emulator from the command line with -echo enabled, and list the program. BASIC code written in external programs can be pasted into the emulator using Ctrl-V.

Edited by Elektron72
Link to comment
Share on other sites

  • 0

If you have an sdcard image set up, and a tool for reading from the image, you can also use the old CMD/LIST method for generating program listings. It's a few more steps than the command line switch, though.

Link to comment
Share on other sites

  • 0
Posted (edited)

What I did, was to edit in atom (another editor like Notepad++). Then when ready to test or save, copy and paste it into the emulator. (ctrl-v). 

Note: Make sure your code is in upper case, otherwise you get lots of PETSCII characters instead of your commands.

Before pasting, I usually typed "new", to start afresh.  When I was happy with it, I saved it within the emulator.

Actually my code inside atom, had "new" on the first line, so it's automatic when I copy / paste.

 

Usually during the testing phase, I used the web emulator, since there you have an edit window, for small changes, and from there it is easy to "copy back" to you editor. Only when satisfied, I pasted it in the "real" emulator, and did a save command.
Hope it helps 🙂   To me it was super simple.

Edited by CursorKeys
Link to comment
Share on other sites

  • 0

So, as a couple people already said, the Commander (and most BASIC computers) don’t save their files as text. They save as “tokens”, where keywords like PRINT are saved as a number. Likewise, line numbers are saved as two 16-bit numbers (the actual line number and a link to the next line.)

This means you can’t just open up a BASIC program in notepad and view it. Instead, you need to detokenize it. Since the standard tokenizer/detokenizer programs for commodore computers don’t support Commander yet (the standard is PETCAT, which is included with the VICE emulator), you can do it yourself. 

To tokenize a program (turn text into BASIC), simply open the text file in Notepad, Edit->Select All, and Edit->Copy. (Or Control+A and Control+C). Then paste it into the Commander window with Control+V. Since scrolling will mess it up, make sure you clear the screen first (shift-Home) and type NEW to clear out any old programs.

To detokenize the program, you need to run the emulator in echo mode. IIRC, you just need to launch the emulator with the -echo parameter, which will cause the console to display everything that the KERNAL prints. You can then just LIST a program, then copy and paste it from the terminal window back to Notepad (or a real code editor like VS Code, Notepad++, or Atom.)

At one point, I was also working on a tokenizer/detokenizer for Windows; it’s actually mostly functional, but I haven’t been using it much, sine the tokens kept changing (for some reason, Mike introduced some new commands, then actually changed the token codes when he introduced other commands, so things like VPOKE and SCREEN got transposed.)

Now that the instruction set seems mostly stable, I might re-visit my tokenizer. It will open and display a BASIC program as text, as well as converting text to BASIC token code. 

Link to comment
Share on other sites

  • 0
On 7/1/2021 at 12:26 PM, TomXP411 said:

At one point, I was also working on a tokenizer/detokenizer for Windows; it’s actually mostly functional, but I haven’t been using it much, sine the tokens kept changing (for some reason, Mike introduced some new commands, then actually changed the token codes when he introduced other commands, so things like VPOKE and SCREEN got transposed.)

 

What language is your tokenizer written in? I ask because I'd like to have something that would work on all major OSes .

Link to comment
Share on other sites

  • 0
32 minutes ago, Edmond D said:

What language is your tokenizer written in? I ask because I'd like to have something that would work on all major OSes .

My first pass was in c#, which can be compiled for Linux and MacOS, if you install Mono. However, I'm planning on re-writing it in Python and using the tkinter ui toolkit for the GUI stuff.

 

Link to comment
Share on other sites

  • 0
2 hours ago, TomXP411 said:

My first pass was in c#, which can be compiled for Linux and MacOS, if you install Mono. However, I'm planning on re-writing it in Python and using the tkinter ui toolkit for the GUI stuff.

 

Thanks for the prompt response. I'm primarily on a MAC platform so moving to C# or Python would be a significant investment of time & effort. So I'm going to put it on a wish list for someday.... 

Link to comment
Share on other sites

  • 0
38 minutes ago, Edmond D said:

MAC platform so moving to C# or Python would be a significant investment of time & effort

Step 1: open terminal.

Step 2: type python <scriptname>.py

Step 3: press the enter key

Edited by Cullen
Link to comment
Share on other sites

  • 0
29 minutes ago, Edmond D said:

Thanks for the prompt response. I'm primarily on a MAC platform so moving to C# or Python would be a significant investment of time & effort. So I'm going to put it on a wish list for someday.... 

are you talking about this from a technical standpoint (installing the toolchain) or a learning standpoint?

Despite my misgivings about Python as a language (I stronly dislike the fact that it doesn't have type enforcement on function calls or variable declarations), it's still the easiest language to get into from a technical perspective. You should be able to install the interpreter in just a few seconds, and the actual tools are... any text editor. On Linux, Python is just an apt-get away. 

From a learning perspective: I just decided to force myself to work in Python, and it only took a few days to get to the point where I could be comfortable using Python in a production environment. (I dove into VB.Net and c# headfirst as well, and it was the same there.) 

 

Link to comment
Share on other sites

  • 0
2 hours ago, Cullen said:

Step 1: open terminal.

Step 2: type python <scriptname>.py

Step 3: press the enter key

Yes - but then there's the learning curve of python, plus the challenge of translating the c# code (with it's own curve) if I had it, then building the app.

I figure that I've learnt/dabbled in about 50 computer languages since the 80's (starting with CBM Basic 2.0 on a PET then VIC 20.) Add on the amazing number of apps I've had to learn/use, plus the number of OSes that have come and gone on many different hardware platforms. I've also invested tons of times with major  PLC platforms and programmable instruments on various industrial networks. 

Some things have stuck with me such as C, but others have been one-off ventures; interesting but were of little value in the long run. APL anyone? My point is that the X16 is going to be a hobby platform for me. I know basic and 6502 assembly so I'm well set.  The tools for assembly (and perhaps C) will take me some time. VERA will be new, plus the whole how many sound different chips/types packed into the box now. I look forward to enjoying building the X16 hardware and hope to build a copy hardware/software projects. I might even perhaps create some tutorials covering things most already here take for granted.

So, it's not that I'm against diving into new things such as building a tokenizer tool, rather I've got lots (too much) I want to do. Plus there's always supporting the community here in some way.

 

Link to comment
Share on other sites

  • 0
9 hours ago, desertfish said:

@TomXP411 you can use "mypy" with type annotations to statically check for types in your Python source code.  It's still not enforced, but can catch many object type related mistakes at compile/build time.

That doesn't fix the underlying problems that come with the language's lack of type safety. As an experienced programmer, I don't get caught by that problem, but for people just learning to code or people working with unfamiliar libraries, type safety should have been built into the language as a core tenant. My problems with Python are all academic, not so much practical. 

So while I appreciate the thought, suggesting lexers to analyze the code doesn't help the fact that the language is deficient. And that's something that can only be fixed by the people making the interpreter.

Link to comment
Share on other sites

  • 0

Regarding "the language is deficient" comment which was asserted, and now one has disagreed with allow me to say:

Every language is deficient in some way. There is not a perfect language. There are some languages that are better for some tasks than others. There are some languages that aren't good for anything (I'm looking at you, Brain-f-bomb; your name only pours salt in the wounds).

I worked on a program some years ago (https://www.storagecraft.com/products/granular-recovery-exchange) that tried to leverage Python. I was part of the team doing the business logic in a DLL accessible framework. We had another team that was all gung ho about Python and how they could whip out a desktop GUI for it in just a few weeks. They basically did, but they wrote it as though it was a web app. It was constantly polling for event notifications instead of using the event notification system which would have allowed it to go to sleep and use no CPU. But if it had just been inefficient, I could forgive it. But the GUI library they were using and Python kept disagreeing on the state of the UI widgets. I don't know how much of it was due to Python vs the GUI library vs the team that wrote it, and it doesn't matter. The fact is it sort of ran but regularly crashed. Then the people who wrote the original program had to go work on other tasks so I got assigned maintaining / fixing the defects. After six months of playing whack-a-bug I finally convinced them to let me re-write the GUI in C++. It no longer had a dependency on Python. It no longer had a dependency on the same GUI library. It no longer required multiple redundant versions of run time libraries (one for the C++ based framework and another for the original GUI library). We removed some layered abstractions, reduced the memory footprint. I was able to modify it to do event driven that polling, and suddenly it was responsive and defect reports went way down.

The problem wasn't Python itself. It was just the wrong tool for the job, like using a hammer to saw a piece of wood or some such. You might be able to do something approximating the desired result, but no one was going to be happy with it.

I like Python and use it and am teaching a middle school class using it this semester. But it's not perfect. And neither is any language, esp when you use it the wrong way.

Link to comment
Share on other sites

  • 0
3 hours ago, Scott Robison said:

I like Python and use it and am teaching a middle school class using it this semester. But it's not perfect. And neither is any language, esp when you use it the wrong way.

I like Python as well. As a language, I think Ruby is better and more consistent. But it's about selecting the right tool for the job and not being obsessive about it. What are the libraries like, the documentation and so on ? Figure out what you want to do and what criteria you have and what skills are available and then use whatever fits them best.

It does sound a bit like your other team was useless rather than it was a particular issue with Python mind.

Link to comment
Share on other sites

  • 0
6 hours ago, paulscottrobson said:

I like Python as well. As a language, I think Ruby is better and more consistent. But it's about selecting the right tool for the job and not being obsessive about it. What are the libraries like, the documentation and so on ? Figure out what you want to do and what criteria you have and what skills are available and then use whatever fits them best.

It does sound a bit like your other team was useless rather than it was a particular issue with Python mind.

The people on that team were bright, but they were mostly web app developers (or so I understood) and were approaching it as such, and they were very busy with multiple projects at one time (which is why I wound up inheriting the code base). They didn't have the time (or maybe experience) to design a real desktop app, so they used what they knew and shoehorned it into a web paradigm. When all you have is a hammer everything looks like a nail, they say. 🙂

Link to comment
Share on other sites

  • 0
14 hours ago, Scott Robison said:

Regarding "the language is deficient" comment which was asserted, and now one has disagreed with allow me to say:

Every language is deficient in some way. There is not a perfect language. There are some languages that are better for some tasks than others. There are some languages that aren't good for anything (I'm looking at you, Brain-f-bomb; your name only pours salt in the wounds).

I worked on a program some years ago (https://www.storagecraft.com/products/granular-recovery-exchange) that tried to leverage Python. I was part of the team doing the business logic in a DLL accessible framework. We had another team that was all gung ho about Python and how they could whip out a desktop GUI for it in just a few weeks. They basically did, but they wrote it as though it was a web app. It was constantly polling for event notifications instead of using the event notification system which would have allowed it to go to sleep and use no CPU. But if it had just been inefficient, I could forgive it. But the GUI library they were using and Python kept disagreeing on the state of the UI widgets. I don't know how much of it was due to Python vs the GUI library vs the team that wrote it, and it doesn't matter. The fact is it sort of ran but regularly crashed. Then the people who wrote the original program had to go work on other tasks so I got assigned maintaining / fixing the defects. After six months of playing whack-a-bug I finally convinced them to let me re-write the GUI in C++. It no longer had a dependency on Python. It no longer had a dependency on the same GUI library. It no longer required multiple redundant versions of run time libraries (one for the C++ based framework and another for the original GUI library). We removed some layered abstractions, reduced the memory footprint. I was able to modify it to do event driven that polling, and suddenly it was responsive and defect reports went way down.

The problem wasn't Python itself. It was just the wrong tool for the job, like using a hammer to saw a piece of wood or some such. You might be able to do something approximating the desired result, but no one was going to be happy with it.

I like Python and use it and am teaching a middle school class using it this semester. But it's not perfect. And neither is any language, esp when you use it the wrong way.

I'm happy to discuss what I think is wrong with Python... on another thread. This threadis about file access and I/O on the Commander, after all. 😃 

 

Link to comment
Share on other sites

  • 0
4 hours ago, TomXP411 said:

I'm happy to discuss what I think is wrong with Python... on another thread. This threadis about file access and I/O on the Commander, after all. 😃 

 

It was about file access, then it became a tokenizer, followed by cross platform development, then onto  a mis-use of Python. Perhaps a new thread in another forum "I believe Python has flaws" would be appropriate. I'd read it but know little about Python.

If the x16 development team released a new emulator or hardware we'd be all over it and not bending threads in new directions 😜

Link to comment
Share on other sites

  • 0

Returning to the original questions by @AuntiePixel, there are at least two solutions in the "downloads/dev tools" area.

One is @Scott Robison's BASIC PREPROCESSOR. It takes BASIC source code stored in a plain text source file with some additional markups for labels and long variable names, and outputs a runnable tokenized BASIC program. You don't use line numbers in the source file. One cool thing is that the preprocessor apparently is written in its own BASIC file format.

The other is my BASLOAD program. It loads BASIC source code files stored as plain text into RAM. While loading a file it's tokenized so that it can be run be the built-in interpreter. It's made to work in parallel to X16 Edit. As the BASIC PREPROCESSOR, it doesn't use line numbers.

Both solutions let you write the BASIC source files in any editor of your choosing. That includes writing source files on modern PCs and transferring them to the SD card.

Edited by Stefan
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use