Jump to content

Prog8 language and compiler topic


Recommended Posts

Use case is arrays of 320 & 256 of floating point values that I pre-calculate for 'speed' 😄 for the madelbrot & julia set calculations. It's not a huge deal and as you say, I could rip the assembly code from my assembly program. A more serious issue is one I'm wrestling with now that I just can't get my hands around! I have a couple of lines of text that I popup at the top of the fractal dsiplay, the hires text printing that I adapted from a Youtube channel, has two variables that track x&y , much like printing from basic. You can change them to relocate, like print@, newline etc.. With the hires text printing that you include, they need x&y positions, so I am attempting to keep track in variables...only I keep getting bad results. See the attached screenshot, where I have built a test program to try and figure things out, but am not making much headway, since I don't understand the results!prog8.thumb.jpg.e0b59d178bb597f6630db96e879385ed.jpg

Link to comment
Share on other sites

Here is a test program that demonstrates an apparent issue with calculations, that I can't figure out. I have no problem in another program, but this clearly is not working here. There is also a difference between these calculations using  uwords & ubytes in some cases and in using a literal (8) instead of a variable defined as 8 here.


Link to comment
Share on other sites

Version 7.6 has been released  https://github.com/irmen/prog8/releases/tag/v7.6

Documentation as always here:   https://prog8.readthedocs.io/

  • added in containment check operator, this enables things such as if xx in [1,2,3] ... or if '@' in email_address ...
  • added experimental 'c128' compiler target to create programs for the Commodore-128
  • added a porting guide to the manual for efforts to port the language to other systems
  • added -asmlist argument to also generate a listing file as output
  • added -noreinit argument (experimental) to not create the reinitialization code for global variables. Can make programs smaller, but can also cause problems.
  • returnvalue of diskio.load() (and similar routines) has changed meaning: it's now just the last load address +1 (same as regular kernal's LOAD routine returns)
  • fixed position of @shared in variable declaration for array types
  • be a bit less verbose in similar warnings
  • several code generation optimizations
  • several bugfixes
  • Like 1
Link to comment
Share on other sites

On 12/27/2021 at 11:53 AM, desertfish said:

I have not yet worked with the mouse on the x16, but perhaps there is something similar going on?   If not, all I can say is compare the resulting assembly code from prog8 to your own code and try to discover where the difference occurs.   The easiest way to do this is by making a minimal reproduction program

The mouse in X16 is janky. It only returns screen X Y positions and buttons. (i.e. no dX dY options) and it coopts sprite 0 even if you don't want to have a pointer on the screen. You can specify a blank sprite as sprite0 as the graphic for the pointer, but sprite 0 will be positioned at the X,Y the Kernal wants it to be. Whenever I get zsound to the point where I push it out the door, I might get back on my widget library I was working on, where I planned to counter this by making the engine hide the kernal pointer and move it back to the middle of the screen on each frame so you won't ever run into the edge of the screen and not be able to continue moving the mouse in that direction.

Link to comment
Share on other sites

  • 2 weeks later...

Version 7.7 has been released!   https://github.com/irmen/prog8/releases/tag/v7.7

Documentation here, as always https://prog8.readthedocs.io/

  • added pipe operator |>
  • added new syntax for string encodings, and added iso: encoding
  • on cx16: added txt.iso() to switch to iso charset
  • added @requirezp flag on variables to force them in Zeropage
  • added pokemon() function
  • fix assembly <-> prog8 label referencing issue (labels in asm no longer start with underscore)
  • less aggressive dead code (variables) removal
  • fixed some type casting issues
  • several small code gen optimizations
  • fix broken code generated for certain equality comparison expressions
  • several other bugfixes.
  • Like 2
Link to comment
Share on other sites

It's so nice to see so much regular progress for Prog8.

BTW, I first encountered a language with "piping" syntax during my university days. That was in the BETA programming language (https://en.wikipedia.org/wiki/BETA_(programming_language)). There is looked like this

(* x = 1 *)
1 -> x ;

(* x = f(1)  *)
1 -> f -> x ;

(* res = fibonacci(1,5)  *)
(1,5) -> fibonacci -> res;

Multiple parameters was supported and "safe" so that

(x, y) -> (y, x)

did a "swap".

This syntax is a lot easier read for long functions chains but I have to admit that I never got 100% comfortable with this syntax style. I guess the traditional Algol syntax was already firmly embedded in my skull by the time I encountered BETA.

Link to comment
Share on other sites

pokemon(address, value)

Attempts to write a byte to a ROM at a location in machine language monitor bank. Doesn’t have anything to do with a certain video game.


because writing to rom is not possible the function effectively does nothing and is implemented as such




Link to comment
Share on other sites

  • 3 weeks later...

👉  Version 7.8 has been released   https://github.com/irmen/prog8/releases/tag/v7.8

  • removed old @"screencodes" string encoding syntax (use sc:"hello" instead)
  • library API change: moved cx16.vload() to cx16diskio module
  • API change: added alignment parameter to memory() function
  • library API change: string.find now returns index of character + carry bit status (instead of substring address)
  • completely rewritten variable allocation, resulting in large program size savings
  • diskio.list_files() now has a larger buffer to be able to list larger directories
  • restructured code generator and added -expericodegen command line flag to select alternate experimental code generator (only a stub at the moment)
  • tweak compiler output to be less noisy
  • various bugfixes and optimizations


  • Like 2
Link to comment
Share on other sites

  • 3 weeks later...

👉  Version 7.9 has been released  https://github.com/irmen/prog8/releases/tag/v7.9

  • added atari compilation target, to create programs for the Atari 800XL. It's very rudimentary still.
  • breaking syntax change of the pipe operator |> : the functions in a pipe now have to be actual function calls (without the first argument specified), rather than just the function names
  • breaking change of the pipe operator |>: you can no longer use a variable at the end to store the value into. Just use an assignment instead.
  • sys.memcopy and sys.memset on the cx16 target no longer depend on kernal routine so now work even when the kernal is not banked in.
  • fix program crash bug caused by non-inlined asmsub not having a proper RTS instruction.
  • fixed compile time calculated constant results of sin() and cos() functions to now be identical to their runtime counterpart
  • better searching for used variable names inside assembly code so unused variable elimination is smarter
  • properly report duplicate label names
  • properly report invalid text encoding selection
  • properly report in check against non-constant range
  • many internal refactorings in the code generator as ongoing attempts to make it easier to change/replace


  • Like 3
Link to comment
Share on other sites

  • 3 weeks later...
Posted (edited)

👉  Version 8.0 has been released   https://github.com/irmen/prog8/releases/tag/v8.0

Documentation here: https://prog8.readthedocs.io/

A new major version release to commemorate the long awaited official "r39" release of the Commander X16 emulator and kernal roms.
Some fundamental changes were made there that had to be reflected in Prog8's cx16 target and libraries.

For current cx16 development, prog8 8.0 is required. Older versions won't work properly anymore.


  • support for the official r39 commander x16 release (new Vera memory layout, changes to rom routines, etc.)
  • updated cx16 examples to new routines
  • breaking syntax change: ** operator has been removed. Use floats.pow() instead.
  • make '&&' a parser error instead of treating it as bitwise and followed by address-of
  • library API change: moved pattern_match() from prog8_lib to string module
  • fixed string encoding for escaped characters
  • fixed bug in codegen for containment check in bytearrays and strings
  • fixed error for certain typecasted expressions inside comparisons
  • fixed return type error for asmsubs with >1 result values
  • [internal] new simplified Ast meant to build better code generators on in the future
  • [experiment] new 'virtual' target and built-in VM to compile prog8 programs for
  • [experiment] new syscall builtin function to interface with the VM


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

  • 2 weeks later...

I've decided to remove the plethora of integer trig builtin functions (sin8u, cos8u, ...) in the next prog8 version.

My expectation is that if you need to use trig functions, that a tailor made implementation for your program is better than the general functions that prog8 used to provide.

I think I'll move the old builtin functions into a regular library module instead, if you really want to use them.

Link to comment
Share on other sites

A library module would be nice, since my custom trig things are neither particularly usable nor documented, so...

Looking over the stuff prog8 has, plus my using C for the past year for the X16, has finally started to pique my interest.


Link to comment
Share on other sites

  • 1 month later...

I've had my old C64, 1741 floppydrive and an old Samsung "portable" TV in the attick so to speak for, well something like 30 to 35 years. During the the Corona period I dragged this out and tested and unfortunately my C64 didn't work anymore. Got the Light Blue/Blue screen without any text so I guess it could one of the ROMs that are bad. However, I did get hold of another C64 a few years ago that I hadn't tested yet. I found out the old power supplies where untrustworthy so I didn't want to risk anything and it took me a while to get around to order a new.

Well, now I have new powerbrick (ordered from here : https://www.c64psu.com/c64psu/43-1488-commodore-64-c64-psu-power-supply.html) and the other C64 works without any trouble so far. Even the 1741 workes fine. At least 4 of the 5 old floppies (with hrm, "backups") works. I still didn't have any way to get the game over to the C64 but after looking a bit only I ended up with a TapeCartSD solution (cheap, easy to use for non-disk images like prg files).

So today I tested Petaxian on real hardware for the first time.

I may have to make the game a bit harder since I beat this on first try even with the terrible joystic (none of the decent joystic I bought back then lasted very long as far as I remember).

The screen quality of the TV wasn't great when it was new, and has probably not gotten any better in the last 35 years and the antenna output is pretty bad as well. I actually tested with a monitor I have that takes just about anything as input (including from antenna) and the picture quality was actually worse than the one in the CRT. I'll just have to order C64 to SCART plug. Those are pretty cheap.


  • Like 2
Link to comment
Share on other sites

Posted (edited)

Wow amazing!! I have yet to beat the game, but I play mostly with keyboard on the emulator, which isn't ideal for this.


Also, is that a D&D character sheet on the table?

Edited by desertfish
Link to comment
Share on other sites

On 5/19/2022 at 1:58 AM, desertfish said:

Wow amazing!! I have yet to beat the game, but I play mostly with keyboard on the emulator, which isn't ideal for this.


Also, is that a D&D character sheet on the table?

Keyboard isn't as good as a controller that is true. And I may have played the game a few times more than you for some reason 😉.

And well spotted, it's a D&D sheet. Though this was printed for my son and not myself. I haven't been able to inspire my son to take up computers and programming, but I did manage get him into D&D.

  • Haha 1
Link to comment
Share on other sites

👉  Version 8.1has been released!  https://github.com/irmen/prog8/releases/tag/v8.1

Documentation here: https://prog8.readthedocs.io/

- API change: moved all integer trig builtin functions (sin8u, cos8u etc) to regular subroutines in the math module
- API change: moved all floating piont builtin functions to regular subroutines in the floats module
- API change: sum() builtin function was removed altogether
- API change: max() min() and abs() now always return uword type.
- API change: abs() supports only integer arguments now, use floats.fabs() for floating point.
- compiler now correctly accepts string multiplication "xxxx" * expr   where expr is not just a number literal (but still must be constant)
- compiler now automatically converts multi compare expression (if x==1 or x==2 or x==3..) into a more efficient containment check (used to only give a warning)
- compiler now gives a warning in many cases about shadowing symbols (re-definitions)
- compiler now automatically inlines some more trivial non-assembly subroutines
- added %option merge  to merge module content with existing
- improve checks for invalid pipe expressions
- improve error message for invalid args to min() and max()
- fixed superfluous printing of WARN and ERROR
- optimized cx16.setcc() and setcc2() library routines
- finished the 'virtual' compiler target codegen and the 'emulator'
- several other minor bugfixes and improvements


  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

👉  Version 8.2 has been released!   https://github.com/irmen/prog8/releases/tag/v8.2

Documentation here https://prog8.readthedocs.io/

- Syntax change: The pipe expression "|>" has been removed from the language.
- Syntax change: now allows casting of negative numbers to unsigned (will result in the proper 2's complement)
- API change:  swap() builtin function has been removed.
- API change: boolean() builtin function has been added, to get the 'thruthy' value of a number.
- diskio.f_read_all() now returns correct size.
- cx16: fixed macptr() signature and it is now used in cx16diskio.f_read(),  vastly improving load times.
- fix for regression: again gives proper name redefinition errors in same scope
- Improved (not) mentioning of the GPL software license in the shared library files.
- greatly improved  code gen for logical expressions and array / pointer indexing.
- zsound examples added for cx16.
- improved compatibility with running the compiler on windows (some file/path errors solved)
- bugfixes.


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

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