2018-09-15 14:21:05 +00:00
Prog8 documentation - |version|
===============================
2018-08-06 01:35:43 +00:00
.. image :: _static/logo.jpg
:align: center
2018-09-15 14:21:05 +00:00
:alt: Prog8 logo
2018-08-06 01:35:43 +00:00
2018-09-15 14:21:05 +00:00
.. index :: what is Prog8
2018-08-06 01:35:43 +00:00
2018-09-15 14:21:05 +00:00
What is Prog8?
--------------
2018-08-06 01:35:43 +00:00
2024-07-03 18:33:59 +00:00
This is a compiled programming language targeting the 8-bit 6502 CPU family.
The language aims to provide many conveniences over raw assembly code (even when using a macro assembler),
while still being low level enough to create high performance programs.
They targeted CPUs are the `6502 <https://en.wikipedia.org/wiki/MOS_Technology_6502> `_ /
2020-12-22 15:44:05 +00:00
`6510 <https://en.wikipedia.org/wiki/MOS_Technology_6510> `_ /
`65c02 <https://en.wikipedia.org/wiki/MOS_Technology_65C02> `_ microprocessors.
2024-07-03 18:33:59 +00:00
They are from the late 1970's and early 1980's and was used in many home computers from that era,
2022-10-28 21:45:09 +00:00
such as the `Commodore 64 <https://en.wikipedia.org/wiki/Commodore_64> `_ .
2022-03-02 22:31:07 +00:00
2024-07-03 18:33:59 +00:00
You can compile programs for various machines:
* Commander X16 (with 65c02 cpu, 65816 cpu specifics are currently not supported)
2023-12-02 22:56:59 +00:00
* Commodore 64
* Commodore 128 (limited support)
* Commodore PET (limited support)
* Atari 800 XL (limited support)
2018-08-06 01:35:43 +00:00
2024-09-27 18:19:28 +00:00
Some language features are mentioned below, and you can also read :ref: `comparingprog8` if you
want to quickly read about how Prog8 compares to well-known other languages.
2024-07-03 18:33:59 +00:00
Open source Software License
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Full source code is on github: https://github.com/irmen/prog8.git
2024-04-09 16:30:56 +00:00
Prog8 is copyright © Irmen de Jong (irmen@razorvine.net | http://www.razorvine.net).
2024-01-12 19:18:41 +00:00
This is free software, as defined in the GNU GPL 3.0 (https://www.gnu.org/licenses/gpl.html)
2022-05-30 18:12:20 +00:00
*Exception:* All output files generated by the compiler (intermediary files and compiled binary programs)
2024-01-12 19:18:41 +00:00
are excluded from this particular license: you can do with those *whatever you want* .
This means, for instance, that you can use the Prog8 compiler to create commercial software as long as you only sell *the actual resulting program* .
2024-09-20 18:12:33 +00:00
Community
^^^^^^^^^
Most of the development on Prog8 and the use of it is currently centered around
the `Commander X16 <https://www.commanderx16.com/> `_ retro computer.
However, the other compiler targets are also still worked on, most notably the C64 target where it all started with!
The X16 `Discord server <https://discord.gg/nS2PqEC> `_ contains a small channel
dedicated to Prog8. Besides that, you can use the issue tracker on github for questions or problems or contributions.
2024-01-12 19:18:41 +00:00
Want to buy me a coffee or a pizza perhaps?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This project was created over the last couple of years by dedicating thousands of hours of my free time to it, to make it the best I possibly can.
If you like Prog8, and think it's worth a nice cup of hot coffee or a delicious pizza,
you can help me out a little bit over at https://ko-fi.com/irmen .
2018-08-06 01:35:43 +00:00
2019-03-19 20:39:01 +00:00
.. image :: _static/cube3d.png
:width: 33%
:alt: 3d rotating sprites
.. image :: _static/wizzine.png
:width: 33%
:alt: Simple wizzine sprite effect
.. image :: _static/tehtriz.png
:width: 33%
:alt: Fully playable tetris clone
2024-01-12 19:18:41 +00:00
.. image :: _static/rrgame.png
:width: 33%
:alt: BoulderDash(tm) clone for the X16
.. image :: _static/x16paint.png
:width: 33%
:alt: Paint program for the X16
.. image :: _static/x16chess.png
:width: 33%
:alt: Chess program for the X16
2024-04-09 16:30:56 +00:00
Features
--------
2019-03-19 20:39:01 +00:00
2024-04-09 16:30:56 +00:00
- it is a cross-compiler running on modern machines (Linux, MacOS, Windows, ...)
- the compiled programs run very fast, because compilation to highly efficient native machine code.
2024-06-29 15:47:13 +00:00
- code often is smaller and faster than equivalent C code compiled with CC65 or even LLVM-MOS
- provides a convenient and fast edit/compile/run cycle by being able to directly launch
2020-11-30 21:42:51 +00:00
the compiled program in an emulator and provide debugging information to this emulator.
2024-04-09 16:30:56 +00:00
- the language looks like a mix of Python and C so should be quite easy to learn
2024-10-12 00:56:36 +00:00
- Modular programming, scoping via module source files, code blocks, and subroutines. No need for forward declarations.
- Provides high level programming constructs but at the same time stay close to the metal;
2020-11-30 21:42:51 +00:00
still able to directly use memory addresses and ROM subroutines,
and inline assembly to have full control when every register, cycle or byte matters
2024-10-12 00:56:36 +00:00
- Variables are all allocated statically, no memory allocation overhead
2024-04-09 16:30:56 +00:00
- Conditional branches for status flags that map 1:1 to processor branch instructions for optimal efficiency
2021-12-29 17:24:05 +00:00
- `` when `` statement to avoid if-else chains
- `` in `` expression for concise and efficient multi-value/containment test
2024-07-06 16:49:03 +00:00
- Several specialized built-in functions, such as `` lsb `` , `` msb `` , `` min `` , `` max `` , `` rol `` , `` ror ``
2021-04-29 17:57:14 +00:00
- Variable data types include signed and unsigned bytes and words, arrays, strings.
2024-04-09 16:30:56 +00:00
- Various powerful built-in libraries to do I/O, number conversions, graphics and more
2024-10-12 00:56:36 +00:00
- Floating point math is supported on certain compiler targets.
2024-04-09 16:30:56 +00:00
- Easy and highly efficient integration with external subroutines and ROM routines on the target systems.
2022-10-29 12:07:04 +00:00
- Strings can contain escaped characters but also many symbols directly if they have a PETSCII equivalent, such as "♠♥♣♦π▚●○╳". Characters like ^, _, \\, {, } and | are also accepted and converted to the closest PETSCII equivalents.
2024-04-09 16:30:56 +00:00
- Encode strings and characters into petscii or screencodes or even other encodings, as desired (C64/Cx16)
2023-12-05 00:34:41 +00:00
- Identifiers can contain Unicode Letters, so `` knäckebröd `` , `` приблизительно `` , `` 見せしめ `` and `` π `` are all valid identifiers.
2024-04-09 16:30:56 +00:00
- Advanced code optimizations to make the resulting program smaller and faster
- Programs can be restarted after exiting (i.e. run them multiple times without having to reload everything), due to automatic variable (re)initializations.
2024-10-12 00:56:36 +00:00
- Supports the sixteen 'virtual' 16-bit registers R0 to R15 as defined on the Commander X16. You can look at them as general purpose global variables. These are also available on the other compilation targets!
2024-04-09 16:30:56 +00:00
- On the Commander X16: Support for low level system features such as Vera Fx, which includes 16x16 bits multiplication in hardware and fast memory copy and fill.
- Many library routines are available across compiler targets. This means that as long as you only use standard Kernal
2024-10-12 00:56:36 +00:00
and core prog8 library routines, it is sometimes possible to compile the *exact same program* for different machines by just changing the compilation target flag.
2020-11-30 21:42:51 +00:00
2020-09-23 16:50:32 +00:00
Code example
------------
2019-01-24 01:43:25 +00:00
2021-06-09 21:25:11 +00:00
Here is a hello world program::
%import textio
2022-10-28 21:49:23 +00:00
%zeropage basicsafe
2021-06-09 21:25:11 +00:00
main {
sub start() {
txt.print("hello world i ♥ prog8\n")
}
}
2019-04-12 20:34:43 +00:00
This code calculates prime numbers using the Sieve of Eratosthenes algorithm::
2019-01-24 01:43:25 +00:00
2020-09-21 16:21:24 +00:00
%import textio
2021-01-08 00:31:28 +00:00
%zeropage basicsafe
2019-01-24 01:43:25 +00:00
2019-07-29 21:11:13 +00:00
main {
2024-04-18 20:22:29 +00:00
bool[256] sieve
2020-09-21 16:21:24 +00:00
ubyte candidate_prime = 2 ; is increased in the loop
2019-04-12 20:34:43 +00:00
2019-01-24 01:43:25 +00:00
sub start() {
2024-04-18 19:50:48 +00:00
sys.memset(sieve, 256, 0) ; clear the sieve
2020-08-27 16:10:22 +00:00
txt.print("prime numbers up to 255:\n\n")
2019-04-12 20:34:43 +00:00
ubyte amount=0
2020-07-26 11:50:14 +00:00
repeat {
2019-04-12 20:34:43 +00:00
ubyte prime = find_next_prime()
if prime==0
break
2020-08-27 16:10:22 +00:00
txt.print_ub(prime)
txt.print(", ")
2019-04-12 20:34:43 +00:00
amount++
}
2021-01-08 15:56:17 +00:00
txt.nl()
2020-08-27 16:10:22 +00:00
txt.print("number of primes (expected 54): ")
txt.print_ub(amount)
2021-01-08 15:56:17 +00:00
txt.nl()
2019-01-24 22:31:16 +00:00
}
2019-01-24 01:43:25 +00:00
2019-04-12 20:34:43 +00:00
sub find_next_prime() -> ubyte {
while sieve[candidate_prime] {
candidate_prime++
if candidate_prime==0
2024-04-18 19:50:48 +00:00
return 0 ; we wrapped; no more primes
2019-04-12 20:34:43 +00:00
}
2020-09-21 16:21:24 +00:00
2020-08-27 16:10:22 +00:00
; found next one, mark the multiples and return it.
2019-04-12 20:34:43 +00:00
sieve[candidate_prime] = true
uword multiple = candidate_prime
2020-08-27 16:10:22 +00:00
2019-04-12 20:34:43 +00:00
while multiple < len(sieve) {
sieve[lsb(multiple)] = true
multiple += candidate_prime
}
return candidate_prime
}
}
2019-01-26 17:44:30 +00:00
2022-10-29 12:12:10 +00:00
when compiled an ran on a C64 you get this:
2019-01-24 01:43:25 +00:00
2019-04-12 20:34:43 +00:00
.. image :: _static/primes_example.png
2019-01-24 22:31:16 +00:00
:align: center
2022-10-29 12:12:10 +00:00
:alt: result when run on C64
2019-01-24 01:43:25 +00:00
2020-10-05 17:59:51 +00:00
when the exact same program is compiled for the Commander X16 target, and run on the emulator, you get this:
.. image :: _static/primes_cx16.png
:align: center
:alt: result when run on CX16 emulator
2019-01-24 01:43:25 +00:00
2024-09-27 18:19:28 +00:00
Getting the software
2021-06-03 19:21:44 +00:00
--------------------
2024-09-27 18:19:28 +00:00
Usually you just download a fat jar of an official released compiler version, but you can also build it yourself from source.
2021-06-03 19:21:44 +00:00
Detailed instructions on how to obtain a version of the compiler are in :ref: `building_compiler` .
2024-09-27 18:19:28 +00:00
You can also read there what extra tools you need to get going.
2021-06-03 19:21:44 +00:00
2024-09-27 18:19:28 +00:00
You may look for an **emulator** (or a real machine of course) to test and run your programs on.
2023-12-17 13:47:20 +00:00
For the PET, C64 and C128 targets, the compiler assumes the presence of the `VICE emulator <http://vice-emu.sourceforge.net/> `_ .
2023-04-23 13:13:53 +00:00
If you're targeting the Commander X16 instead,
2023-11-07 22:39:39 +00:00
download a recent emulator version for the CommanderX16, such as `x16emu <https://cx16forum.com/forum/viewforum.php?f=30> `_
2023-04-23 13:13:53 +00:00
(preferred, this is the official emulator. If required, source code is `here <https://github.com/X16Community/x16-emulator/> `_ .
There is also `Box16 <https://github.com/indigodarkwolf/box16> `_ which has powerful debugging features.
2023-12-17 13:47:20 +00:00
For the Atari target, it assumes the "atari800" or "altirra" emulator.
If multiple options are listed above, you can select which one you want to launch using the `` -emu `` or `` -emu2 `` command line options.
2021-06-12 13:48:04 +00:00
2022-10-25 19:24:38 +00:00
**Syntax highlighting:** for a few different editors, syntax highlighting definition files are provided.
Look in the `syntax-files <https://github.com/irmen/prog8/tree/master/syntax-files> `_ directory in the github repository to find them.
2018-08-06 01:35:43 +00:00
.. toctree ::
:maxdepth: 2
:caption: Contents of this manual:
2024-09-27 18:19:28 +00:00
comparing.rst
2023-06-25 19:35:30 +00:00
compiling.rst
2018-08-06 01:35:43 +00:00
programming.rst
syntaxreference.rst
2020-10-15 19:30:03 +00:00
libraries.rst
2021-04-04 10:55:29 +00:00
targetsystem.rst
2020-12-19 02:18:40 +00:00
technical.rst
2021-12-30 22:57:54 +00:00
portingguide.rst
2023-09-13 19:51:48 +00:00
software.rst
2018-08-06 01:35:43 +00:00
todo.rst
Index
=====
* :ref: `genindex`