Jump to content

Prog8 language and compiler topic


desertfish
 Share

Recommended Posts

On 6/15/2022 at 10:57 PM, desertfish said:

- greatly improved  code gen for logical expressions and array / pointer indexing.

I didn't get around to checking out the new compiler before now but there is a marked improvement in Petaxian when all enemies are on screen and moving with the latest update. 

I definitly use a lot of logical expresion and tons of array indexing so assume the above update is why 🙂

Very very nice.

  • Like 1
Link to comment
Share on other sites

Yeah! I noticed this as well (I am using Petaxian as a test bench for compiler changes).  The prg shrunk by a couple hundred bytes too.

I do think I'm at the limits of what I can reasonably improve in the current codegen. For the future I want to write a new one based on the 'vm' intermediate code but that will be a big undertaking. I do think that may eventually be a) way better to maintain and better structured and b) generating better code.

 

Link to comment
Share on other sites

On 6/28/2022 at 5:43 PM, desertfish said:

@borgar with the recent improvements made, is the game still too slow on the C64?

No, I'm not experiencing noticable slowdown on C64. The last update really helped a lot here.

I've just commited some updates with a couple of more enemies, more stages and a new bomb types now so the games should hopefully be more challenging as well. I got some comments that it was a bit easy 😉 At least I have not been able to complete the game myself yet after the update.

  • Like 1
Link to comment
Share on other sites

On 6/28/2022 at 9:11 PM, desertfish said:

I was asking because the readme still contains the note about the speed on C64.

Ah, yes. The description hasn't been updated for a while. I took this as a gentle reminder and have done so now. The text should better reflects the current state of the project.

I'll update the game in the CX16 pages when it can work with the latest emulator.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...
  • 1 month later...
  • 3 weeks later...

Hello just trying out Prog8. Installed everything and compiled the hello world example with no issues.

I load the HELLO.PRG in the emulator and when I list it everything seems fine, but when I run it the screen flashes and the emulator seems to reset itself.

Might I be doing something wrong?

Compiling with: java -jar ~/Documents/workspace/prog8/prog8compiler-8.6.2-all.jar -target cx16 -emu hello.p8

Compiles with no issues. Using R41 emulator.

BTW, thank you for doing this and the great effort you have put behind it!

I just went through all the comments here. Impressive work.

Been using so far cc65 with C and mostly asm. Intrigued to try Prog8 and benchmark my prime number finder using trial division comparing cc65 vs Prog8 performance.

Link to comment
Share on other sites

Understood. Thank you!

Will try it out more. Super intrigued. Always start coding new languages just by checking a few examples briefly 😉

Time to read the docs more thoroughly

Edited by arkorott
Link to comment
Share on other sites

  • 2 weeks later...

Hi, I'm new around here, but I want to dive in to programming for the X16 using the emulator.
I program in C++ for my job, and am familiar with a lot of modern and old languages and some microcontroller stuff like Propeller 1 & 2, and their languages.

I've scanned through this thread, and I think I want to try using Prog8 for my retro game for the X16. What I am posting for is to ask if there are any gotchas or things I should be aware of like maybe X16 features that are not fully support (if at all), or just common things newcomers to the language stumble on?

It seems like you've done a pretty nice bit of work on the X16 target/support, so I expect I will like using Prog8 for my game. Thanks for doing this, and for any reply to my question above.

 

Link to comment
Share on other sites

On 10/19/2022 at 6:52 AM, Roy Eltham said:

Hi, I'm new around here, but I want to dive in to programming for the X16 using the emulator.
I program in C++ for my job, and am familiar with a lot of modern and old languages and some microcontroller stuff like Propeller 1 & 2, and their languages.

I've scanned through this thread, and I think I want to try using Prog8 for my retro game for the X16. What I am posting for is to ask if there are any gotchas or things I should be aware of like maybe X16 features that are not fully support (if at all), or just common things newcomers to the language stumble on?

It seems like you've done a pretty nice bit of work on the X16 target/support, so I expect I will like using Prog8 for my game. Thanks for doing this, and for any reply to my question above.

Welcome to forum and to the Prog8 thread.

The main issue with the low level code is that it's a lot easier to shoot oneself in the foot. I.e. nothing preventing you from setting a random memory location and breaking everything. Expect to spend time looking for weird bugs that are hard to pin down. Prog8 is low level so it's more like C than C++. On the other hand, it's a compact and neat language that is easy to learn. Especially if you know anything about the 6502 processor.

It's easy to add in some function implemented in assembly if you need to speed up some critical parts which may be needed if you are coding a game. I you want to look at longer code example feel free to check out the source of my game Petaxian, which is written in Prog8 plus a bit of assembly : https://github.com/cyborgar/Petaxian. Feel free to steal.. I mean borrow from there. There are certainly parts here that was "inspired" by the example programs from desertfish in the first place.

Most gotchas are probably just related to the the CX16 platform and not so much about Prog8 though I have a couple things I will mention

First Prog8 currently doesn't support short-circuit evaluation, i.e. for something like

 if x >1 and x < 128 { ...

all parts of the express is evaluated even if the first fails. Using something like

  if x > 1 {
    if x < 128 {
      ...
may yield faster code. And if you have side effects in the evaluations you could even get bugs if you are to careful.

Sometimes the compiler also struggle with more complex expression (though complex has more to do with the compiler evaluation than the complexity of the statment). E.g. right now something like this

  test_fun( arr_one[i + 1], arr_two[i + 1] )

will give a compiler error ("it's not possible to use more than one complex array indexing expression in a single statement; break it up via a temporary variable for instance").

In that case I extracted out the array index calculation to

  ubyte tmp = i+1
  test_fun( arr_one[tmp], arr_two[tmp] )

Often if you run into trouble with the compiler, breaking operation down into simpler steps tend to solve issues.

And also, reporting issues here will usually get you help quickly from the Prog8 developer himself 😀

Edited by borgar
  • Like 2
Link to comment
Share on other sites

borgar,
Thank you, this is exactly the kinds of things I was interested in learning about.

I am familiar with the 6502 (almost all of my early coding was on the VIC-20, C64, and C128).

I also understand the low level aspects, and mostly bare metal type programming where a mistyped address or value can break everything.

Anyway, thank you very much for the tips and I will be around here posting as I go with any issues I run into or progress update.

  • Like 1
Link to comment
Share on other sites

A little heads up for users of the rnd() and/or rndw() builtin functions.

The next release of the compiler will have some changes and improvements to the random number generation routines. For example, a way to seed the RNG's will be added. 

But also for consistency sake, it looks like I will be removing the rnd() and rndw() builtin functions and instead move them into the math module as regular functions.  This will break programs that use the builtins now, but is easily fixed by importing the math module and calling them as math.rnd() / math.rndw() instead..

 

Link to comment
Share on other sites

Been doing a little dabbling in prog8. Implemented a few sprite functions, and made a little test program that looks like this.

SpriteTest.gif.3a4bd17157bfbbb96ca2818d93874387.gif

Source can be found here:
https://gist.github.com/reltham/cb607cb91eae8bc8a7a1609e791fe6ea

Using X16EMU R41.  The birdsprites.bin file is attached, and should be place into your sdcard.img and passed into the emulator.

Thanks to @desertfish for the help in Discord.

BIRDSPRITES.BIN

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...

Wow! That's one big pointy finger for a minor release. 😜

That being said, congrats on getting it out. Coming onto almost 4 years of continuous development for an alternative language for the X16 (and others) is certainly a major achievement. 

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

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use