Jump to content
sebassco

My First Steps with the X16: Questions and goals!

Recommended Posts

Hi everyone!

This may be a long one... so hang on tight cuz' I don't have a TL;DR 😅  Although, if you just want to take a look my questions, you can check that at the end of the post.

 

I am looking to understand the first steps I (or, in any case, anyone) should take while starting to use the X16 and how to develop any kind of stuff for it. In fact, if things go as expected I  am thinking of using this thread as a kind of log about my journey through the X16 developing world 🙂. This is in order to achieve a greater goal, an educational one, not just for me but for anyone that finds this interesting.

So, let's begin with a short(ish) introduction!

Main goal: From what I've seen on the videos Dave uploaded to his channel, I get that the computer should be "simple" enough for someone with some knowledge to understand what is going on at any moment without having to worry about other much more complicated concepts. Basically what I see about it is that it should let me build things that emulate how an OS works in real life or, even better, work like that. It may sound a little boring or even non-ambitious at all,  but after getting there I will obviously set other goals in the future. Right now my main focus is on learning and building things that help me get to a more in-depth understanding.

My background: I am 30 years old and work focused mainly on Integration (REST APIs, SOAP, etc). Basically some of the products I worked with tend to have a kind of unique way of solving their deployment challenges, including being non-dependant to a JVM and run a direct communication with the OS to manage their processes and access memory. That means I usually take into account how things work inside the server I am using and what would be the way to extract the best behaviour out of it, what relates to the other thing I've done in my career: getting to understand how OS's work and, more important, learning about low-level coding. From my experience as a student (I'm still working on getting my degree), I think there are features anyone could take advange of with the X16. So, yeah, it should be mainly about software, and very little about hardware... well, just enough hardware in order to be able to do what I plan to do.

My experience with retro computers: Given my age you would think it's not great but it is something. Well... I have no experience at all. My dad had a 386 clone running DOS back when I was 5, but after that we jumped directly to pentiums and such. I did use plenty of DOS and Windows 3.1.

Skills I have and stuff I do know about and think will be useful:

  • (And I think this is an important one)
  • Process management (Multithreading, planning, etc.)
  • File systems (NTFS, FAT32, EXT2)

Skills I do not have and stuff I do not know about and wish to learn:

  • 6502 architecture
  • Assembly (I'm guessing this is a must)
  • Basic (I am reading about that at the moment)
  • cc65

Skills I do not have and stuff I do not know about but are not a priority:

  • GUI design
  • Graphics in general

What I do not care about (for the time being, at least):

  • Games: I know this may be a bummer to many of you and will stop reading after looking at this, but while I love retro games, I am not interesting in developing them.
  • In-depth knowledge of hardware: By this I mean soldering, boards, chips, etc. I do not have any skills for that and never will, so I better keep it real and learn about what each component does without caring about how they are built and wired in.
  • Building an entire OS: It is not my scope at the moment, and tbh I don't know if it will ever be. But dreaming is always allowed, right? lol.

 

Ok, enough of introduction. Let's pan out my current location on this "journey":

What resources have I checked? What was the outcome of that?

I checked the FAQ, Docs, and the "Getting Started" Wiki. I don't know if I am short of knowledge right now or if I need things layed out differently but while I got to run things on the emulator (programs of the software library and some small basic tests), I haven't been able to understand yet what should I do as a first "hello world" creation using something else apart from BASIC.

What have I done? What am I doing at the moment?

So, as I said before, I've been reading all the docs and tried some software from the library besides trying some basic examples on my own. Right now I am trying to learn a little bit about KERNAL and BASIC with the C64 user guide in addition to the X16 Programmer's reference in order to get a little more experience on how to operate the X16.

What's the primary objective right now?

To get something running that has been written on my own. Just a basic program asking for an input and returning something. But I don't know if I should change this, maybe you can help me with my questions.

 

Here are all the questions I have at the moment

  • Should I bother to learn BASIC or maybe should I get straigh into C? I am skipping assembly for now, but will tackle that in the future.
  • If the previous answer is C : How should I start? I've seen the cc65 webpage, but should I take something else into account? Is there a "hello world" example or something like that to get into terms with the compiler and such?
  • Is process management a too far-fetched concept with the 6502? I'm guessing that if C is usable, I could use concepts as threads, but I am hesitant about that being doable on that CPU.

 

DISCLAIMER: I haven't seen any posts like this one, or at least haven't found them. If you deem this is a "repost" please let me know and accept my apologies 🙂

 

Ok, I really hope you find this interesting.

Let the learning begin!

Edited by sebassco
  • Like 1

Share this post


Link to post
Share on other sites

Definitely learn BASIC.  The thing runs on a BASIC interpreter. You need to know how to make the machine do things outside of just loading in your compiled program and running it.  Writing some BASIC programs to play around with graphics, etc. is a good way to get a feel for how the machine works and the ways to make it do things.

For C, honestly? Not a lot of people are using C right now. Probably 90% of the people messing around with the X16 are using BASIC or assembly. I think I've seen one game written in C (there are probably more though).  cc65's X16 support is a bit shaky.  As development of the ROM continues (although I think the major breaking changes are over/close to being over) cc65's X16 support will break and you'll have to keep waiting for fixes or fix them yourself. For assembly, though, support doesn't break since it's just dependent on the 65C02 instruction set.  I think also, in order to understand what your program is doing, or why your program will have to do a lot of seemingly random placing of values into certain memory addresses, it's good to learn the assembly first so you can understand what the heck is going on in a X16 C program.

For threads, I'm pretty sure it's possible but it would be very tricky to do.  It's definitely something the 6502/65C02 wasn't designed for, and not something natively supported in the C.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

As one of the folks using C for the X16 I'd say don't discount it.  There are a couple of C examples in the x16-demo repo (https://github.com/commanderx16).  I've done a Lode Runner port and a utility library in C (https://github.com/CJLove/x16-LodeRunner).  The number of available registers on the 6502 don't make it a great cpu for compiled languages like C.  But just like the X16's higher clock speed enables a lot more to be done in BASIC that couldn't be done on the C64 it gives a margin for cases of less than stellar code generation by CC65.

 

  • Like 3

Share this post


Link to post
Share on other sites

I'm also one of those using cc65 and implement my games for the X16 in C. Sometimes there is a need of implementing some optimized parts in assembler (interrupt handlers, sound effects player, etc.). cc65 has the advantage that combining C and assembler is easy. I sometimes check the generated assembly code, to see what the C compiler does and the hand-optimize some of it. Or I change the way I do my C code.

I also didn't experience any case of cc65 being really broken... if so, it was possible to fix it myself as the source is on github.

Basic was too limited for me and I wanted the comfort and usability of cross development tools on a PC - and then run it on the emulator. So I went for Visual Studio Code and cc65.

But hey - the beauty of the X16 is that there are different ways of programming for it.

  • Like 1
  • Thanks 2

Share this post


Link to post
Share on other sites

Just want to cover some thoughts on the threading.

Threading has come up with CPUs with a lot of cycles and the main routine sitting around most of the time and idling. Also having multiple cores requires threads as otherwise you would not be able to use it in a single program. Threads come with at least two disadvantages:

1. you need to make your code thread save. As threads will run asynchronous, you cannot forecast when a thread will finish its task and if this is inline with the main loop. So you need to write message queues and handlers and such things to ensure that you have everything in the right order. That will put a lot of overhead on both CPU and RAM. Even if RAM is not a big issue any longer with the X16, CPU cycles are precious.

2. You need a MMU or you need to program one yourself to ensure that threads are always accessing their memory. 

Regarding the first point: 

X16 has a very small CPU that is not powerful at all. Yes it is 8times faster than the C64, but the compute power on your hands is less than an Arduino (ESP-12f for instance with WIFI and USB and other components runs at 80Mhz and with much better CPU. 4USD price range 🙂 ) . So if you are starting to use thing like threads you need to use Interrupts, each of the interrupt handlers need to decide what to do (actually multitasking/multithreading) and then save everything somewhere (stack), load the current thread environment and start executing, until the next interrupt happens. Depending on the complexity you are wasting 50% of the available cycles just for the thread handler. Remember the CPU and the whole System has no support of that ready. No multi tasking, No multi threading. No MMU.

So given all that, it is definitely possible to implement multithreading in any CPU as long as you have enough memory to handle it (and you have on X16), however there is most likely nothing that justifies the overhead. 

 

Instead you write a main loop (game loop) and branch into all the individual "tasks" and ensure that it is as efficient as possible and that whatever task you have to complete within a frame fits into the available cycles of a frame (e.g. 8.000.000 cycles/60 =  133k cycles per frame. If you consider that you need at least 2 cycles per instruction, that is not a lot of things you can do within that time frame. (C64 had only 16k cycles per Frame).

  • Like 1

Share this post


Link to post
Share on other sites

Actually, you don't need a MMU, if you are okay with a system that doesn't have memory protection. (Wich is a weird thing to expect from  a 8 bit system anyway..)

I believe the only thing that you have to do is:

  • save cpu state including status flags on a context switch
  • give each thread access to their own hardware cpu stack.

The second point means that you have to write stack swapping code on a plain 65(c)02 because it has its stack fixed at $0100 in memory at all times. I believe the Commodore-128 had a tiny MMU that allowed to remap the zeropage and stack to another page in memory, but I am not sure about this.

Here is a multitasking unix-like operating system for the Commodore-64 that uses multiple threads and stack swap trickery: http://www.6502.org/users/andre/osa/index.html

It's quite unbelievable to see it in action to be honest    https://youtu.be/jtlAOdJmeDI

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Hey guys, I am really glad you all joined the discussion 🙂

Thank you very much for all your suggestions. Yes, I was taking into consideration that threading should be a tough call considering the lack of MMU. But, enhancing what I said in the first post, it is not about doing something 'elegant' or even super functional, but instead it is about seeing what can be done and to what extent.

 

@desertfish those links are awesome! Thanks a lot!

 

So, everyone, regarding the first question then: What should I start with? I still reading the C64 manual and probably will end it by next week. From what I see there are not a lot of things in common between both languages but it seem BASIC should give me a better handle of the computer, right? In the other hand, I am starting to think that in order to use cc65 I wil have to take a look at assembly first, is that true?

Edited by sebassco

Share this post


Link to post
Share on other sites
7 minutes ago, sebassco said:

In the other hand, I am starting to think that in order to use cc65 I wil have to take a look at assembly first, is that true?

No, you don't need assembler at all if you don't want to with cc65. It will for sure offer more performance than Basic.

But if you just want to get going right away - Basic is the right choice. No installation needed, except for the emulator.

Edited by AndyMt
  • Thanks 1

Share this post


Link to post
Share on other sites
1 minute ago, AndyMt said:

No, you don't need assembler at all if you don't want to with cc65. It will for sure offer more performance than Basic.

But if you just want to get going right away - Basic is the right choice. No installation needed, except for the emulator.

Awesome, thanks!

Share this post


Link to post
Share on other sites

I agree to try some BASIC first to get a hang of the machine. You'll need some commands anyway to operate it regardless -- as Ender pointed out above.

That said, the C64 basic isn't a very good basic. Even the PET that came before it had a better basic... and I remember being extremely jealous about the basic on the BBC Acorn Electron that my friend had in school, it was way more advanced.  I think I wouldn't stick to basic beyond the basics (pun intended) and switch to something else once you mastered it a little.

Personally I made the jump to assembly code back in the days. But there are a lot more choices available today...
My own interests nowadays lie with cross-compilation that allows you to develop comfy on the PC and just run the compiled output on the target machine. This is what CC65 does and also my own Prog8 language and some others too.  ( Obviously I'm using Prog8 myself but its kinda experimental and very very new on the CommanderX16 but I think I'm making good progress 🙂   )

  • Like 2

Share this post


Link to post
Share on other sites

After reading C64 manual, read the X16 docs. Start with BASIC and the examples to understand how the computer works.

Then get into Assembler  ... read Jim Butterfields book: 

http://www.1000bit.it/support/manuali/commodore/c64/ML_for_the_C64_and_Other_Commodore_Computers.pdf

Then read the X16 docs again (esp. regarding firmware and VERA). 

Work both through the Assembler examples.

65c02 Assembler is not hard to learn (actually very few instructions) and Jim Butterworth book is legend. I would use VICE for the first steps to understand the Assembler examples and to ensure they work. After that you can start working with the X16emu and use it natively.

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, desertfish said:

I agree to try some BASIC first to get a hang of the machine. You'll need some commands anyway to operate it regardless -- as Ender pointed out above.

That said, the C64 basic isn't a very good basic. Even the PET that came before it had a better basic... and I remember being extremely jealous about the basic on the BBC Acorn Electron that my friend had in school, it was way more advanced.  I think I wouldn't stick to basic beyond the basics (pun intended) and switch to something else once you mastered it a little.

Personally I made the jump to assembly code back in the days. But there are a lot more choices available today...
My own interests nowadays lie with cross-compilation that allows you to develop comfy on the PC and just run the compiled output on the target machine. This is what CC65 does and also my own Prog8 language and some others too.  ( Obviously I'm using Prog8 myself but its kinda experimental and very very new on the CommanderX16 but I think I'm making good progress 🙂   )

Hey @desertfish! Do you have any docs on Prog8 I can take a look at? Just to see what it does and what it can do 🙂

 

1 hour ago, SerErris said:

After reading C64 manual, read the X16 docs. Start with BASIC and the examples to understand how the computer works.

Then get into Assembler  ... read Jim Butterfields book: 

http://www.1000bit.it/support/manuali/commodore/c64/ML_for_the_C64_and_Other_Commodore_Computers.pdf

Then read the X16 docs again (esp. regarding firmware and VERA). 

Work both through the Assembler examples.

65c02 Assembler is not hard to learn (actually very few instructions) and Jim Butterworth book is legend. I would use VICE for the first steps to understand the Assembler examples and to ensure they work. After that you can start working with the X16emu and use it natively.

Ok, great data. I think this will be my path then. Maybe swapping C and Assembler in order (Because, yeah, I love C and want to user it anyways, lol)

  • Like 1

Share this post


Link to post
Share on other sites

Hey!

So... Days 1 and 2 are over and I am feeling way more confident on this.

Following your advice (and more specifically the ones given to me by @SerErris and @desertfish) I kept on going with my learning of basic. So far, and so good! I am finishing chapter 4 (advanced basic) of the c64 user manual and I am blown away with how simple and understandable things are. At this rate, I am thinking I will be achieving my primary objective by next week!

 

Something that got my attention is an example given by using the GET operation. It goes like this:

1 PRINT "{CLR/HOME}"

10 GET A$: IF A$ = "" THEN 10

20 PRINT A$;

30 GOTO 10

Then something struck my mind: Is that piece of code throwing an interruption (or anything of that nature) everytime it gets to line 10? so basically the cpu will spend all its time on that loop until you press a key? Is that how it works?

Will keep on reading, this is getting interesting! 🙂

Edited by sebassco
  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, sebassco said:

10 GET A$: IF A$ = "" THEN 10

This just keeps looping back on it self until A$ is something other than empty i.e.

Share this post


Link to post
Share on other sites

Ok, so is not like the computer lays "dormant" until you hit a key, but instead it  keeps busy-waiting until you do something?

Edited by sebassco

Share this post


Link to post
Share on other sites

Yes, it is a busy-loop. I just tested it and the GET function just returns an empty string if a key has not been pressed.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi everyone!

So... new log enty today 🤣

Got through the firsts chapters of BASIC without any problems until I got to the obvious one: Graphics.

At first I said Ok, this is not in my scope, I should skip it, but the curious kid inside me started to poke (oh yes, you did see that joke) my brain asking me why not, and it was a good thing he did, specially because I would be able to play around with memory addresses and their values!!

So there was I, being a total noob reading my C64 manual when it hit me: I won't be able to use peek and poke that simply because we have the VERA chip. So I went to David's video (Part 2) and saw he did an example with VPOKE 0,0,1. That basically puts a letter in the first character space. While it is something really simple, it could be useful to understand how memory works in the X16 and the VERA.

The other thing I knew is that the monitor should let me dump the values stored in the VRAM, so I went and digged a little bit into that. Nothing too special, I knew I had to dust off my hex/binary skills a little bit in order to get something working, I just only took my chance.

Well... I think I am failing to do so. I thought the COLOR command should let me change the background color, so I ran it and tried to read the value at $9F35 to see if something change: much to my surprise, it didn't! I am still searching what am I doing wrong, but if in the meantime someone reads this and can give me a hint, I would appreciate it, I think my main issue is that I still don't understand how the tables in the documentation relates to the vpeek and vpoke parameters.

 

Here's a screenshot of what I got until now:

 image.thumb.png.27aad1e25bc9e65c99584d26581eb920.png

 

That's all for now! I will get cracking this and see if I can solve it on my own (and save my pride while doing that 🙂 )

Edited by sebassco

Share this post


Link to post
Share on other sites

Two entries on the same day, I'm happy! lol

So I've seen this post had a couple views, and I don't want to be bothering with technical questions here while breaking some forum rules, so I created this question:

 

Also, I decided to keep just posting my advances here, but without asking things because I don't think this is the place. I will super appreciate your advice in the following steps! As for now, I will focus on learning those 3 subjects I was recommended to.

 

Cheers!

Share this post


Link to post
Share on other sites

quick answer :

You cannot read the VRAM with a monitor, nor with PEEK. The reason is, that the CPU cannot acces the VRAM at all. Instead you need to use the VERA registers to read from or write to the VRAM (VPOKE or VPEEK are implementing that).

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
On 9/10/2020 at 11:15 AM, SerErris said:

quick answer :

You cannot read the VRAM with a monitor, nor with PEEK. The reason is, that the CPU cannot acces the VRAM at all. Instead you need to use the VERA registers to read from or write to the VRAM (VPOKE or VPEEK are implementing that).

Dude, if you ever come to Argentina, remind me that I owe you a beer 🙂

Your answer in the question I made (Well, yours and @Greg King's) really helped me understand a little bit more about memory management.

In case anyone's interested, I am writing a tutorial made by a newbie for newbies, hahaha. I am going to cover every aspect of my process learning how to use the x16 and the skills it needs to do so. I will be posting the link as soon as I deem it is not too embarassing 🤣

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, sebassco said:

Dude, if you ever come to Argentina, remind me that I owe you a beer 🙂

Your answer in the question I made (Well, yours and @Greg King's) really helped me understand a little bit more about memory management.

In case anyone's interested, I am writing a tutorial made by a newbie for newbies, hahaha. I am going to cover every aspect of my process learning how to use the x16 and the skills it needs to do so. I will be posting the link as soon as I deem it is not too embarassing 🤣

That is great stuff. Esp if you write about the things you stumbled across during your learning experience. The X16 project really requires (right now) a bit of understanding how the C64 worked and does not touch on anything that is connected to it. On the other hand, some things work differently and things are difficult to find for a newbie. E.g. even if you know the C64 quite a bit and are used to PEEK and POKE, you will have a hard time to find the memory locations you have been used to in the past. Esp. the Memory Map is on of the things that require documentation. However as things still can massively change, it is not a good investment in time to document the memory map now, as that also might change completely.

So your writeup together with other resources will get a better and better picture to enter the platform.

 

BTW: here is another book of great value for the commodore platform ... and a lot of things still hold true on a X16 (also a lot of things are different).
https://archive.org/details/Complete_Commodore_Inner_Space_Anthology_The_1985-03_Transactor_Publishing

Edited by SerErris

Share this post


Link to post
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
Reply to this topic...

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


×
×
  • Create New...

Important Information

Please review our Terms of Use