Getting Started

Let's start your CpcdosC+ journey! There's a lot to learn, but every journey starts somewhere. In this chapter, we'll discuss:

  • Installing cpcsc on GNU/Linux and Windows
  • Writing a program that print Hello, world!

Installation

On Ubuntu:

$ sudo add-apt-repository ppa:cpcsc
$ sudo apt update
$ sudo apt install cpcsc

Hello, World!

Filename: hello.cpc

txt/ Hello, world!

Listing 1-1: A program that prints Hello, world!

Save the file and go back to your terminal window. On GNU/Linux, enter the following commands to compile and run the file:

$ cpcsc hello.cpc
$ ld -o hello hello.o -lcpc_runtime
$ ./hello
Hello, world!

On Windows, enter the following commands:

> cpcsc hello.cpc
> cl hello.o libcpc_runtime.lib /link /out:hello.exe
> .\hello.exe
Hello, world!

Programming a Guessing Game

txt/ Guess the number!
fix/ number = /F:CPC.INT(%CPC.RND%)

:loop:

txt/ Please input your guess.
fix/ /q guess
txt/ You guessed: %guess%

if/ "%guess%" == "%number%" then:
    txt/ You win!
    stop/
else:
    if/ "%guess%" > "%number%" then:
        txt/ Too big!
    else:
        txt/ Too small!
    end/ if
end/ if

goto/ loop

Common Programming Concepts

Comments

REM/ a comment
// also a comment
' another comment

Variables

fix/ var = 3

Array

fix/ arr[0 to 2]

Control Flow

if/ "3" == "4" then:
    txt/ WTF?!
else:
    txt/ all green
end/ if
if/ "8" < "4" then: txt/ True ! else: Txt/ False !

Functions

function/ BEFORE_DOS()
    REM/ todo
end/ function

GUI programming

Network programming