Skip to content

Examples

cursorkeys edited this page Mar 8, 2022 · 24 revisions

The most fun way of getting the hang of programming is by doing. Take example programs, modify them and see what happens. Below are a number of examples, from simple to medium, which you can type into the emulator directly. For the longer ones you can also copy and past them into the emulator.

Hello World

  • 10 print chr$(147) ; prints control character 147 to the screen to clear the screen
  • 15 print chr$(5) ; prints control character 147 to the screen change text color to white
  • 20 print "hello world" ; prints the text "Hello World" on the screen
  • 25 poke 53280,0 : poke 53281,0 ; changes the border and background color to 0 (black)

Download Listing

Exercise Change the color of the background.

Simple Snake

Download Listing

A simple implementation of the snake game. There is only two rules. Don't hit anything, and survive as long as possible. Controls: Keyboard up/down ("Q"/"A"), left/right ("O"/"P"), continue ()

# Code Walkthrough

NOTE: Line 100 has no purpose, and is removed from the code walkthrough

  • 110 print"�" ;Clear screen with special control character
  • 120 fort=0to39:poke1024+t,102:next ;Poke in screen memory
  • 130 fort=0to39:poke1984+t,102:next ; with checkered PETSCII character
  • 140 fort=0to23:poke1024+(t*40),102:next ; to create boundary wall around the screen
  • 150 fort=0to23:poke1063+(t*40),102:next
  • 160 x=20:y=20:sc=0:dx=1:dy=0:sw=5:sl=sw ; init variables for position, score, x/y direction, sleep/delay timer
  • 170 geta$ ; scan keyboard
  • 180 ifa$="q"thendy=-1:dx=0 ; set x/y direction based on key pressed
  • 190 ifa$="a"thendy=1:dx=0
  • 200 ifa$="o"thendy=0:dx=-1
  • 210 ifa$="p"thendy=0:dx=1
  • 220 sl=sl-1:ifsl>0thengoto170 ; delay logic, control game speed
  • 230 sl=sw:sc=sc+1 ; delay logic, control game speed, increase score
  • 240 poke1024+x+(y*40),81 ; poke snake segment on screen (code 81)
  • 250 print"";sc:sl=sl-1 ; print score + delay logic
  • 260 x=x+dx:y=y+dy ; update snakepos
  • 270 ad=1024+x+(y*40) ; calculate screen address of segment
  • 280 ifpeek(ad)<>32thengoto300 ; if not "empty space", goto game over
  • 290 goto170 ;loop
  • 300 print" ** game over ** " ;game over
  • 310 geta$ : ifa$<>" "thengoto310 **;check key, if not space, keep trying **
  • 320 goto110 ;start game again

TicTacToe

Play TicTacToe

Extended commands

Basic64-JS extended commands make many things easier, then in vanilla Basic.

Here are some examples:

Sprite Example

Sprite Example

Hires Mandelbrot fractal

Multicolor Hires Screensaver

Clone this wiki locally