Post your Commander X16 program here

May 22, 2019
504
266
63
Reply with a link to your CX16 programs.

Thread rules: PROGRAMS ONLY. No comments, commentary, questions, etc. To discuss an entry, create a new thread and link back to the post in this one.

For BASIC programs, please link to the source code (ie: BAS file in text and/or PRG format). For binary programs, please link to an assembled or compiled binary. We will reject posts that do not contain a PRG that can be run on the Commander X16.
Use the Share button (circled below) to get the URL of the specific message. The 1569900472637.png button can be used to copy the link to the clipboard.

1569900402996.png
 

Attachments

Last edited:

Schol-R-LEA

New Member
Sep 20, 2019
18
12
3
OK, Let's start off with a simple implementation of the assembly equivalent of "Hello, World!": printing out a list of ASCII (or in this case, PETSCII) characters. Now, just to be clear, I am not usually quite this prolix with my comments, but I wanted to start off things with a solid, clear example, as well as to eliminate any ambiguities about the dev and test systems if others can't get it working on different systems. If the comments are TL;DR for you, just scroll to the end of the code window for the actual code. ;)

Code:
;;; PETSCII-simple - a quick and dirty demo for Commander x16
;;; using the ca65 assembler (part of the cc65 toolchain,
;;; see https://github.com/cc65/cc65 for downloads).
;;;
;;; target platform: Commander X16, Sept 2019 design
;;; test platform: cx16emu r.32
;;; dev host platform: Ryzen 3 2200g PC running Manjaro Linux
;;;
;;;
;;; Uses the Kernal print-character routine to print all of the
;;; characters of the first character set (40 hex to 7F hex).
;;;
;;; Since this was just a quick demo, I kept it simple,
;;; with all of the constants as local equates rather than
;;; using a separate header (as I plan to do with future programs).
;;;
;;; to assemble:
;;;    ca65 petscii-simple.asm -o petscii-simple.o -l petscii-simple.lst
;;; link:
;;;    cl65 petscii-simple.o -C cx16-asm.cfg -o petscii-simple.prg
;;; run:
;;;    x16emu -prg petscii-simple.prg -run

;;; constants
Kernal_bank   = $07
ROM_bank_ctrl = $9F61
BSOUT         = $FFD2

.org  $0801

;; common header for binary executable PRGs
.byte $0b,$08,$01,$00,$9e,$32,$30,$36,$31,$00,$00,$00

start:
      ; initialize the ROM Bank to 'kernal'
      ; while this is not strictly necessary since
      ; the BASIC ROM also includes the Kernal ROM,
      ; I wanted to make sure I had the procedure correct
      lda #Kernal_bank       ; get the bank ID #
      sta ROM_bank_ctrl      ; set the bank control

      ; print out all of the characts of the primary code set
      lda #$40               ; load the character '@'
loop:
      jsr BSOUT              ; print the current char
      adc #1                 ; increment the accumulator
      cmp #$7F               ; are we at the end of the codeset?
      bne loop               ; if not, loop
exit:
      rts
To assemble using ACME instead, just change these lines:
Code:
.org  $0801

;; common header for binary executable PRGs
.byte $0b,$08,$01,$00,$9e,$32,$30,$36,$31,$00,$00,$00
to:
Code:
*=  $0801

;; common header for binary executable PRGs
!byte $0b,$08,$01,$00,$9e,$32,$30,$36,$31,$00,$00,$00
and assemble as:
Code:
acme -f cbm -DMACHINE_C64=0 -o petscii-simple-acme.prg petscii-simple-acme.asm
The output of this (truncated for screen space) is:

PETSCII-simple test.png
 
Last edited:

DarwinNE

New Member
Sep 19, 2019
12
14
3
Here is a text adventure game called Two Days to the Race.

commanderX16_two_days.png

Free download (search for the Commander X16 version): http://davbucci.chez-alice.fr/index.php?argument=varie/two_days/two_days.inc&language=English

Your name is Emilia Vittorini, You're the daughter of Augusto Vittorini, who founded the Industria Torinese Automobili (ITA) with his brother Tullio. Your father is abroad trying to raise funds, but something went wrong and you heard your uncle coming back slamming the door. Your mission is to find what happened and how you can help your family. I will be your ears and eyes. Good luck.

It's a classical adventure where you should read descriptions carefully and type commands such as 'examine bed'. Type "north", "south", ... to move around. Abbreviations are possible "x" for "examine", "l" to "look" (i.e. describe again the place where you are), "i" for "inventory," "n" for "north" and so on. To quit the game, type "bye". To restart it, type "restart".

Discussion here: https://murray2.com/threads/a-text-adventure-game-for-the-cx16.339/
 

millenniumtree

New Member
Oct 2, 2019
24
24
3
Here's a little color demonstration with some randomness built in for a funky dithered gradient effect
Code:
10 FOR Y=0 TO 56:FOR X=0 TO 79 : REM FILL THE SCREEN
20 P=Y*256+X*2: REM SCREEN POSITION
30 VPOKE 0,P,INT(RND(1)*2)+205: REM OUTPUT RANDOM SLASH CHARACTER
40 VPOKE 0,P+1,INT((X+Y+RND(1)*16)/16): REM WITH A SOMEWHAT RANDOM COLOR
50 NEXT X,Y
 

Attachments

May 22, 2019
504
266
63
Here's a quick SMPTE-like color bars program. (You can't actually have SMPTE color bars without NTSC video, but this gives you an approximation...)


Code:
5 POKE $0286,1:PRINT"ô"
20 DATA 5, 35, 2
25 DATA 7, 1 ,7,3,13,4,10,14
30 DATA 40, 5, 2
35 DATA 7, 14,00,4,00,3,0,1
40 DATA 45,10, 10
45 DATA 7, 1,15,12,11,0,0,0
100 DIM C(16)
110 FOR Z=1 TO 3
120 READ Y1, YC, X1, CN
130 CN=CN-1:FOR I=0 TO CN:READ C(I):NEXT
140 GOSUB 2000
150 NEXT
999 END
1000 FOR N=0 TO 15
1010 POKE $0286,N
1020 PRINT N
1030 NEXT
1040 END
1999 :
2000 REM DRAW COLOR BARS
2005 :
2010 W=INT(80/(CN+1))
2020 FOR Y=1 TO YC
2030 N=Y1*256+X1:Y1=Y1+1
2040 FOR C=0 TO CN
2050 FOR X=1 TO W
2060 VPOKE 0,N,160
2070 VPOKE 0,N+1,C(C)
2080 N=N+2
2090 NEXT
2100 NEXT
2110 C=0
2120 NEXT
2130 RETURN

1570225716835.png
 

qbradq

New Member
Sep 14, 2019
24
15
3
Updated .BAS file with one compatible with more recent releases (r32+)

MINEFIELD.BAS
A work-in-progress Mine Sweeper game in BASIC. Comments welcome via DM for now, thanks! WARNING: Large minefields take a while to generate and run slow. But watching the flood fill algorithm in real-time is kinda neat :) Instructions on opening screen.

At the moment I am distributing as source code due to some token changes causing issues with users.

Screenshot_2019-10-05_20-27-38.png
 

Attachments

Last edited:
  • Like
Reactions: JayLewis

thrawn235

New Member
Oct 12, 2019
7
8
3
My very first Program for the X16.
Snake!

snake.jpg

Its still pretty crude, especially the keyboard function, it doesn't react sometimes.
I would need an interrupt to fix this.
Unfortunately i have no idea how to implement one. Maybe one of you can help me.

The Tail is also bugged. thats unfortunatly a major design flaw. it would require a complete redesign so i left it for now, maybe ill figure something out later.

I also have no idea how to return to the basic promt...

comments and critique welcome!

(source code and assets are included in the archive)

Discussion here: https://murray2.com/threads/my-snake-program.453/
 

Attachments

Last edited:

blitmaps

New Member
Oct 25, 2019
1
4
3
Reply with a link to your CX16 programs.

Thread rules: PROGRAMS ONLY. No comments, commentary, questions, etc. To discuss an entry, create a new thread and link back to the post in this one.

Use the Share button (circled below) to get the URL of the specific message. The View attachment 310 button can be used to copy the link to the clipboard.

View attachment 308
Here is a small puzzle game I put together in C. You use the Enter Key to start, then the SPACE key to change the colour of your stack of blocks. Matching blocks are deleted when blocks collide, levels get harder quickly. Just a quick demo, I think it should return to BASIC properly. Works in R33, should work with a JOY1 too.


Screenshot 2019-10-25 at 14.16.46.pngScreenshot 2019-10-25 at 14.17.02.png
 

Attachments

Schol-R-LEA

New Member
Sep 20, 2019
18
12
3
Relating to another threa, I ended up implementing the Bresenham circle algorithm in BASIC. As it turns out, there wasn't much point to it (as Tom made it clear he knew the algorithm better than I do), but I figured I'd post it anyway.

Code:
5 SCREEN $80
10 PI=3:LF=150:TP=50:RT=250:BT=150:FC=10
20 FRAME LF,TP,RT,BT,FC
30 CX=200:CY=100:R=50:CC=6
40 X=0:Y=R:D=PI-(2*R)
100 IF X>Y THEN 500
110 PSET CX+X,CY+Y,CC
120 PSET CX+X,CY-Y,CC
130 PSET CX-X,CY+Y,CC
140 PSET CX-X,CY-Y,CC
150 PSET CX+Y,CY+X,CC
160 PSET CX+Y,CY-X,CC
170 PSET CX-Y,CY+X,CC  
180 PSET CX-Y,CY-X,CC
200 X=X+1
210 IF D>0 THEN 300
230 D=D+(4*X)+6
240 GOTO 100
300 Y=Y-1
310 D=D+(4*(X-Y))+10
320 GOTO 100
500 END
To illustrate the algorithm better for those more familiar with newer languages, I also came up with the following Python code:
Code:
# assumes that 0,0 is in the upper left.
# adjust accordingly for other coordinate maps
circle (cx, cy, radius):
    if r < 0:
        plot(cx, cy)
    else:
        x = 0
        y = r
        # D is the 'decision value' which determines how to
        # update x and y
        # For the integer version, set PI to 3;
        # accuracy improves with more significant figures
        D = PI - 2 * r
      
        while y >= x:
            # first, plot the existing points at the quadrants
            for dx in [x, -x]:
               for dy in [y, -y]:
                   plot(cx+dx, cy+dy)
                   plot(cx+dy, cy+dx)
            # then, update the values for D, x, and y
            x += 1
            if D > 0:
                y -= 1
                D += (4 * (x - y)) + 10
            else:
                D += (4 * x) + 6
 
  • Like
Reactions: Grunchy

Grunchy

New Member
Nov 21, 2019
7
0
1
Calgary, Alberta, Canada
Lunar LEM Rocket
This game in its many different versions and names (ROCKET, LUNAR, LEM, and APOLLO) is by far and away the single most popular computer game.
Note: play a few iterations, notice the screen scroll bug (duplicated lines here & there).

Code:
5 DEF FN CAT(X)=INT(X*100+.5)/100
10 PRINT TAB(33);"LUNAR"
20 PRINT TAB(15);"CREATIVE COMPUTING, MORRISTOWN, NEW JERSEY"
25 PRINT: PRINT: PRINT
30 PRINT "THIS IS A COMPUTER SIMULATION OF AN APOLLO LUNAR"
40 PRINT "LANDING CAPSULE.": PRINT: PRINT
50 PRINT "THE ON-BOARD COMPUTER HAS FAILED (IT WAS MADE BY"
60 PRINT "XEROX) SO YOU HAVE TO LAND THE CAPSULE MANUALLY."
70 PRINT: PRINT "SET BURN RATE OF RETRO ROCKETS TO ANY VALUE BETWEEN"
80 PRINT "0 (FREE FALL) AND 200 (MAXIMUM BURN) POUNDS PER SECOND."
90 PRINT "SET NEW BURN RATE EVERY 10 SECONDS.": PRINT
100 PRINT "CAPSULE WEIGHT 32,500 LBS; FUEL WEIGHT 16,500 LBS."
110 PRINT: PRINT: PRINT: PRINT "GOOD LUCK"
120 L=0
130 PRINT: PRINT "SEC","MI + FT   ","MPH","LB FUEL","BURN RATE": PRINT
140 A=120: V=1: M=33000: N=16500: G=1E-03: Z=1.8
150 PRINT L,INT(A);INT(5280*(A-INT(A)));"   ",FN CAT(3600*V),FN CAT(M-N),
155 INPUT K: T=10
160 IF M-N<1E-03 THEN 240
170 IF T<1E-03 THEN 150
180 S=T: IF M>=N+S*K THEN 200
190 S=(M-N)/K
200 GOSUB 420: IF I<=0 THEN 340
210 IF V<=0 THEN 230
220 IF J<0 THEN 370
230 GOSUB 330: GOTO 160
240 PRINT "FUEL OUT AT";FN CAT(L);"SECONDS":S=(-V+SQR(V*V+2*A*G))/G
250 V=V+G*S: L=L+S
260 W=3600*V
265 PRINT "ON MOON AT";FN CAT(L);"SECONDS - IMPACT VELOCITY";FN CAT(W);"MPH"
270 IF W<=1.2 THEN PRINT "PERFECT LANDING!": GOTO 440
280 IF W<=10 THEN PRINT "GOOD LANDING (COULD BE BETTER)": GOTO 440
282 IF W>60 THEN 300
284 PRINT "CRAFT DAMAGE... YOU'RE STRANDED HERE UNTIL A RESCUE"
286 PRINT "PARTY ARRIVES. HOPE YOU HAVE ENOUGH OXYGEN!"
288 GOTO 440
300 PRINT "SORRY THERE WERE NO SURVIVORS.  YOU BLEW IT!"
310 PRINT "IN FACT, YOU BLASTED A NEW LUNAR CRATER";FN CAT(W*.277);"FEET DEEP!"
320 GOTO 440
330 L=L+S: T=T-S: M=M-S*K: A=I: V=J: RETURN
340 IF S<5E-03 THEN 260
350 D=V+SQR(V*V+2*A*(G-Z*K/M)): S=2*A/D
360 GOSUB 420: GOSUB 330: GOTO 340
370 W=(1-M*G/(Z*K))/2: S=M*V/(Z*K*(W+SQR(W*W+V/Z)))+.05: GOSUB 420
380 IF I<=0 THEN 340
390 GOSUB 330: IF J>0 THEN 160
400 IF V>0 THEN 370
410 GOTO 160
420 Q=S*K/M: J=V+G*S+Z*(-Q-Q*Q/2-Q^3/3-Q^4/4-Q^5/5)
430 I=A-G*S*S/2-V*S+Z*S*(Q/2+Q^2/6+Q^3/12+Q^4/20+Q^5/30): RETURN
440 PRINT: PRINT: PRINT: PRINT "TRY AGAIN?";:INPUT A$
450 IF LEFT$(A$,1)="Y" THEN GOTO 70
 

Attachments

Last edited:

NielsGudmundsson

New Member
Nov 25, 2019
1
3
3
This is a bunch of beginner examples

Code:
10 REM PRINT TEXT
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 PRINT "HELLO WORLD"

10 REM CLEAR SCREEN
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 PRINT "THIS TEXT SHOULD NOT BE SEEN"
110 PRINT CHR$(147);
120 PRINT "HELLO WORLD"

10 REM 80 x 60
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 SCREEN $2
110 PRINT CHR$(147);"HELLO WORLD"

10 REM SIMPLE VERA TEST
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 PRINT CHR$(147);
110 SCREEN $2
120 FOR X=0 TO 79
130 VPOKE 0,X*2,X   : REM WRITE CHAR
140 VPOKE 0,X*2+1,1 : REM FORGROUND/BACKGROUND
150 NEXT X

10 REM ROWS
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 PRINT CHR$(147);
110 SCREEN $0
120 FOR R=0 TO 19
130 VPOKE 0,R*256+5*2,R : REM POSITION R,5
140 VPOKE 0,R*256+5*2+1,1 : REM FORGROUND/BACKGROUND
150 NEXT R

10 REM ALL CHARS
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 PRINT CHR$(147);
110 SCREEN $0
120 FOR Y=0 TO 15
130 FOR X=0 TO 15
140 P=(Y+2)*256+(X+10)*2
150 VPOKE 0,P,X+Y*16
160 VPOKE 0,P+1,1
170 NEXT X
180 NEXT Y

10 REM COLORS FORGROUND/BACKGROUND
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 PRINT CHR$(147);
110 SCREEN $0
120 FOR Y=0 TO 15
130 FOR X=0 TO 15
140 P=(Y+2)*256+(X+5)*2
150 VPOKE 0,P,81
160 VPOKE 0,P+1,X+Y*16 : REM FORGROUND/BACKGROUND 0-255
170 NEXT X
180 NEXT Y

10 REM COLORS FORGROUND/BACKGROUND
20 REM TESTED ON EMULATOR R34
30 REM CREATED BY NIELS GUDMUNDSSON
40 REM LICENCE FREEWARE
100 PRINT CHR$(147);
110 SCREEN $0
120 FOR C=0 TO 15
130 Y=INT(C/4)
140 X=C-INT(C/4)*4
150 FOR X1=0 TO 7
160 FOR Y1=0 TO 3
170 P=((Y*4)+Y1+2)*256+(X*8+X1+5)*2
180 VPOKE 0,P,32
190 CC=C*16
200 IF C=0 THEN CC=1
210 VPOKE 0,P+1,CC : REM BACKGROUND 16-240
220 NEXT Y1
230 NEXT X1
240 P1=((Y*4)+1+2)*256+(X*8+1+5)*2
250 VPOKE 0,P1,6
260 VPOKE 0,P1+2,58
270 VPOKE 0,P1+256,2
280 VPOKE 0,P1+256+2,58
290 VV=C: PP=P1+4: GOSUB 1000
300 VV=C*16: PP=P1+256+4: GOSUB 1000
310 NEXT C
320 FOR I=1 TO 20: PRINT:NEXT I
330 PRINT "FX YOU WANT RED FORGROUND"
340 PRINT " AND GREEN BACKGROUND"
350 PRINT "RED F=2           (F=RED B=BLUE)"
360 CC=2+96:PP=22*256:GOSUB 2000
370 PRINT "GREEN B=80        (F=WHITE B=GREEN)"
380 CC=81:PP=23*256:GOSUB 2000
390 PRINT "COLOR = 2 + 80    (F=RED B=GREEN)"
400 CC=80+2:PP=24*256:GOSUB 2000
999 END
1000 REM PRINT THREE CHAR INT
1010 REM VV VALUE TO BE PRINTED
1020 REM PP VERA MEMORY POSITION
1030 V1=INT(VV/100)
1040 V2=INT((VV-V1*100)/10)
1050 V3=VV-INT(VV/10)*10
1060 VPOKE 0,PP,V1+48
1070 VPOKE 0,PP+2,V2+48
1080 VPOKE 0,PP+4,V3+48
1090 RETURN
2000 REM SET COLOR FOR 40 CHARACTERS
2010 REM CC COLOR TO BE SET
2020 REM PP VERA MEMORY POSITION (CHAR POSITION)
2040 FOR I=0 TO 39
2050 VPOKE 0, PP + (I*2) +1, CC
2060 NEXT I
2070 RETURN
 

SlithyMatt

New Member
Sep 14, 2019
2
4
3
  • Like
Reactions: Funnybones
May 22, 2019
504
266
63
Jimmy, thank you for your contribution - but it does not have PRG that can be loaded on the CX16. Could you please add an assembled PRG file, either to the Github page or to your post here?

Thanks.
 

AlmightyTodd

New Member
Dec 4, 2019
1
0
1
01 REM ** COMMANDER X16 BASIC **
02 REM ** TODD GEIGER 2019 **
03 REM ** DISPLAY NUMBERS 0 - 255 IN DECIMAL, HEX, BINARY, AND PETSCII **

10 REM ** BINARY/HEX NUMBERS **

20 FOR I=0 TO 255
30 LET B=I
40 GOSUB 200
50 IF I<10 THEN PRINT " ";
60 IF I<100 THEN PRINT " ";
70 PRINT I;" ";H$;" ";Z$;
75 IF I>32 AND I<127 THEN PRINT " ";CHR$(I)
80 IF I<33 OR I>126 THEN PRINT " "
90 NEXT I

100 REM ** LOOP FOREVER **
110 PRINT ""
120 GOTO 20

200 REM ** ASSIGN BITS **
205 LET Z$=""
210 FOR J=0 TO 7
220 GOSUB 500
230 IF (A-B) > 0 THEN LET Z$="1"+Z$
235 IF (A-B) = 0 THEN LET Z$="0"+Z$
240 NEXT J
245 GOSUB 800
250 RETURN

500 REM ** CALC BIT **
510 LET X=B
520 LET A=X/2
530 LET B=INT(X/2)
540 RETURN

800 REM ** D2HEX **
810 N=I
820 C$="0123456789ABCDEF"
830 H$=""
840 H = INT(N/16)
850 L = N -(H*16)
870 H$=MID$(C$,(L+1),1)
880 H$=MID$(C$,(H+1),1)+H$
900 RETURN
 
Last edited: