First Demo from My New Programming Language, Elena

Show us your work, thrill and amaze us :)

Moderator: Programming Moderators

User avatar
MrKWatkins
Posts: 39
Joined: Tue May 30, 2017 8:37 pm

First Demo from My New Programming Language, Elena

Post by MrKWatkins » Sun Mar 04, 2018 6:00 pm

When the Facebook group for the Next was first starting there were discussions about whether modern languages such as C# or JavaScript would be available for the Next. The general consensus seemed to be that no, there wouldn't. Which sounded like a decent programming challenged to me. :)

Since then I've been working off-and-on creating a new programming language for the Next called Elena. I'm hoping to create a language similar to C# that should hide away some of the complexities of coding in Z80 assembly or C whilst still being powerful enough to create some decent Next software.

I've finally managed to get it to the stage where I can produce a demo that can bounce some Next sprites around the screen:



And if you what to see what the language currently looks like here is the corresponding Elena code:

Code: Select all

using System;
using System.Maths;
using System.Spectrum;
using System.Spectrum.Next;

namespace Elena.Test
{
   static type Program
   {
      private static UnsignedByte BorderColour = 1b;
      private static Array[Particle] Particles = Array[Particle](12b);

      entrypoint void Main()
      {
         Screen.Cls(0b);
         Screen.SetBorder(BorderColour);

         InitializeParticles();
         InitializeSprites();
         
         while (true)
         {
            UpdateParticles();
         }
      }

      private static void InitializeParticles()
      {
         UnsignedWord position = 32w;
         for (Particle particle in Particles)
         {
            particle.Position = UnsignedWordVector(position, position);
            particle.Velocity = SignedByteVector(1sb, 1sb);

            position = position + 12w;
         }
      }

      private static void InitializeSprites()
      {
         Sprites.SetAreVisible(true);
         
         Sprites.SetPattern(0b, Patterns.Particle);
      }

      private static void UpdateParticles()
      {
         UnsignedByte index = 0b;

         for (Particle particle in Particles)
         {
            UpdatePosition(particle);
            UpdateVelocity(particle, index);

            Sprites.SetAttributes(index, particle.Position.X, particle.Position.Y, 0b, true);
            index++;
         }
      }

      private static void UpdatePosition(Particle particle)
      {
         particle.Position += particle.Velocity;
      }

      private static void UpdateVelocity(Particle particle, UnsignedByte particleIndex)
      {
         if ((particle.Position.X == 32w) || (particle.Position.X == 270w))
         {
            particle.Velocity.X = -particle.Velocity.X;         
            if (particleIndex == (Particles.Length - 1b))
            {
               CycleBorder();
            }
         }

         if ((particle.Position.Y == 32b) || (particle.Position.Y == 208b))
         {
            particle.Velocity.Y = -particle.Velocity.Y;
            if (particleIndex == (Particles.Length - 1b))
            {
               CycleBorder();
            }
         }
      }

      private static void CycleBorder()
      {
         if (BorderColour == 7b)
         {
            BorderColour = 1b;
         }
         else
         {
            BorderColour++;
         }

         Screen.SetBorder(BorderColour);
      }
   }

   type Particle
   {
      public UnsignedWordVector Position;
      public SignedByteVector Velocity;
   }

   static type Patterns
   {
      public static Array[UnsignedByte] Particle = 0xE3E3E3E3E3242424242424E3E3E3E3E3E3E3E324252549494949252524E3E3E3E3E3242549496D6D6D6D49492524E3E3E32425496D6D6D92926D6D6D492524E3E325496D6D9292B6B692926D6D4925E32425496D92B6B6B6B6B6B6926D49252424496D6D92B6DBDBDBDBB6926D6D492424496D92B6B6DBFFFFDBB6B6926D492424496D92B6B6DBFFFFDBB6B6926D492424496D6D92B6DBDBDBDBB6926D6D49242425496D92B6B6B6B6B6B6926D492524E325496D6D9292B6B692926D6D4925E3E32425496D6D6D92926D6D6D492524E3E3E3242549496D6D6D6D49492524E3E3E3E3E324252549494949252524E3E3E3E3E3E3E3E3242424242424E3E3E3E3E3_a;
   }
}
Hopefully you programmers out there won't find it completely alien! The above gets compiled into C, which then gets compiled for the Next using the excellent z88dk. I've written up a bit more detail on my blog at https://www.mrkwatkins.co.uk/2018/03/04 ... irst-demo/ and attached a .sna of the demo to this post.

Afraid the compiler isn't available yet as it needs a bit more work yet before I can give it out. Currently if your program is correct then it will compile fine, but if not you might get a message telling you the problem, but it's far more likely to crash horribly... When I've got the error handling and reporting a bit better and the compiler a bit more stable then I'll release a version for people to play with. Eventually I'll release the code for the compiler too as open source.
Attachments
FirstElenaDemo.zip
First Elena Demo
(1.77 KiB) Downloaded 46 times

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First Demo from My New Programming Language, Elena

Post by SamusDrake » Sun Mar 04, 2018 8:15 pm

It'll be interesting to see where this takes you. Keep up the good work! ^_^

Stefan123
Posts: 98
Joined: Mon Jun 05, 2017 9:38 pm

Re: First Demo from My New Programming Language, Elena

Post by Stefan123 » Sat Mar 10, 2018 3:33 pm

What an ambitious project, I'm looking forward to try it out :)

User avatar
MrKWatkins
Posts: 39
Joined: Tue May 30, 2017 8:37 pm

Re: First Demo from My New Programming Language, Elena

Post by MrKWatkins » Mon May 07, 2018 5:13 pm

I've written a blog post about Next palettes and some of the support that will be in the Elena compiler: https://www.mrkwatkins.co.uk/2018/05/07 ... difference. Second demo coming soon...

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First Demo from My New Programming Language, Elena

Post by SamusDrake » Mon May 07, 2018 6:02 pm

Glad to see this is going ahead.

Kevin, I've noticed your description of the Next's colour palette matches that of the Sega megadrive, for which I'm currently programming for. Sadly I'm at a loss as how to generate suitable bitmaps with the correct palette data. Would you mind giving me some direction as how to do that in Gimp? I've heard one needs to add an "index" but beyond that its hard to locate relevent tutorials.

User avatar
MrKWatkins
Posts: 39
Joined: Tue May 30, 2017 8:37 pm

Re: First Demo from My New Programming Language, Elena

Post by MrKWatkins » Mon May 07, 2018 6:44 pm

I'm by no means a GIMP expert (having only been using it for a week or two now!) myself, but here are some things that I've discovered:

1. GIMP works in either RGB mode, (colours are represented as 24-bit RGB values), greyscale (just with 8-bit greys) or indexed, which uses a palette of 256 colours, and is what I've been working with. You can switch to indexed mode by going to Image -> Mode -> Indexed. From there you can either get GIMP to generate a palette for you or pick a specific one.
2. Windows -> Dockable Dialogs -> Palette brings up the palette dialog which shows you the set of palettes you have available, and gives functionality for editing them. The current image's palette should be at the top, if you're in indexed mode.
3. I can't see a way to edit the current palette! I've therefore been copying it (right click, duplicate) and editing a copy, then remapping my image to the new palette.
4. Colours -> Map -> Set colour map will apply a palette to your image, but won't remap the colours. So not that much use really.
5. To remap to a new palette I've been switching to RGB from indexed, then switching back and picking the new one.
6. Custom palettes are stored on disk at C:\Users\<USER>\.gimp-2.8\palettes for me. (I'm running Windows 10, swap <USER> for your user name) If you copy .gpl files in there they should appear after restarting GIMP. Or just use the import palette option.
7. Colours -> Map -> Rearrange colourmap can be useful. It allows you to reorder the colours in your palette, and it will update your image accordingly. I found this really handy as I needed some of my colours in certain positions in the palette for some sprite-palette-offset trickery.

That's pretty much my sum-total knowledge of GIMP. Hope it helps. :)

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First Demo from My New Programming Language, Elena

Post by SamusDrake » Mon May 07, 2018 6:51 pm

Kevin, you're a diamond mate. Cheers for that!

User avatar
MrKWatkins
Posts: 39
Joined: Tue May 30, 2017 8:37 pm

Re: First Demo from My New Programming Language, Elena

Post by MrKWatkins » Mon May 07, 2018 7:55 pm

No worries. Out of interest how are you coding for the MegaDrive? Assembly or C or some other language?

SamusDrake
Posts: 250
Joined: Mon Jun 26, 2017 10:11 pm
Contact:

Re: First Demo from My New Programming Language, Elena

Post by SamusDrake » Mon May 07, 2018 8:45 pm

Ah, I'm using SGDK which employs C. I doubt I will make a full game with it but to make even a small joypad input demo that actually ran on an emulator was like...Paul Atreides sand-surfing on that big worm thing in Dune! THAT awesome! Sigh, I'm so easily impressed....

User avatar
MrKWatkins
Posts: 39
Joined: Tue May 30, 2017 8:37 pm

Re: First Demo from My New Programming Language, Elena

Post by MrKWatkins » Mon May 07, 2018 9:01 pm

I totally understand that! Those balls bouncing around on my demo video isn't really that complicated a thing to do but when I got it working... Ludicrously happy. :)

Post Reply