User login

Open Source Commodore 64 Development - (mini) BASIC Listings (C-64, C64, CBM64)

 C64 32x32 pixels Remember those good old days when the next new game for your home computer would come from typing in a listing published in the latest magazine? Well I thought it would be nice to re-introduce those golden days by starting a topic focusing on (mini) listings especially for the Commodore 64 computer.

Please modify this listing or add your own easy to enter mini C-64-BASIC demos as comments underneath. So how much C-64 hardcore coding is still in your brain? It's amazing to find out how much information on C-64 BASIC coding still resides in the brain. Wanna share your code, jump in.

Here's a link to the C-64 memory-map so that you can refresh those hidden peek and poke numbers.

Title: Colorful Pie

Code:
10 print chr$(147)
20 poke 646,int(rnd(1)*255+1)
30 poke 53281,int(rnd(1)*255+1)
40 poke 53280,int(rnd(1)*255+1)
50 print chr$(255);:goto 20

Description & screenshot:
Produces a nice psychedelic Pi-based forever scrolling 'pie-demo'
c64 listing 'colorpie'

Now who wants to do a basic-smooth scrolling text demo next?


Comments

Mark Vergeer's picture

Explenation of the gravity-code

It is very quick and dirty, not refined at all. It is basically a lookup table defined by a couple of if-then statements something like the following.

10 print chr$(147)
20 x=1:y=1:ax=1:ay=1
30 print chr$(147):for t=1 to y:print:next t:print spc(x)"o"
31 if y<6 then acc=0.5
32 if y>=6 and y<12 then acc=1.5
33 if y>=12 and y<18 then acc=3
34 if y>=18 then acc=6
35 ay=ay*acc
40 x=x+ax:y=y+ay
50 if x<=0 or x>=39 then ax=-ax
60 if y<=0 or y>=23 then ay=-ay
65 ay=ay/acc
70 goto 30

What I did was declare certain areas on the screen where the ball would have a different speed.
I devided the screen into 4 areas and created an extra variable called acc and made it 0.5 on the top quarter of the screen. 1.5 on the 2nd quarter, 3 on the 3rd quarter and 6 on the bottom part. This is done by adding extra lines above line 40 where simple if then statements will check which part of the screen the ball is on and define the acc variable accordingly. On the bottom part the ball moves fastest and on top the slowest.
To be able to effectuate the different speeds the standard vertical speed variable ay is multiplied with the acc varibale. Then the new position of the ball is calculated, the direction is checked and on line 65 the standard vertical speed is restored by deviding it by the acc variable. This way standard speed is returned to the ay variable after the new position is calculated.
Line 31 to 35 can of course be changed into something resembling real gravity physics or by using goniometric functions like a sine or cosine function but the way I did it is a speedy way of approximating it by using something that could be called a caculation- or lookup table, a technique often used in cpu emulators. It's faster on slower computers this way.

Now come on y'all, gimme some code!



Editor / Pixelator - Armchair Arcade, Inc.
www.markvergeer.nl


Matt Barton's picture

I guess this is why I have a

I guess this is why I have a hard time working with graphics when programming. I just don't get the math very well. Too much snoozing in geometry and trig! :(

Can you explain how the formulas work?


Mark Vergeer's picture

You don't need peeks and pokes

Bouncing ball without pokes

10 print chr$(147)
20 x=1:y=1:ax=1:ay=1
30 print chr$(147):for t=1 to y:print:next t:print spc(x)"o"
40 x=x+ax:y=y+ay
50 if x<=0 or x>=39 then ax=-ax
60 if y<=0 or y>=23 then ay=-ay
70 goto 30

Creates the same ball demo but then with the print function. The c64 basic is very rudimentary so that there is no easy way to set the coordinates and you do this artificially by printing the screen 'clear' with chr$(147) and then printing y lines in a for next loop that counts the y coordinates followed by a print command that the character of your 'ball' after x spaces.



I tweaked the above code a little to include a more pronounced bouncing effect as I did above, mind you this is done without using a single poke (Matt!!!) but with the addition of an acceleration parameter that will multiply and devide the ay parameter depending on specific vertical regions on the screen. How would you do it?



Editor / Pixelator - Armchair Arcade, Inc.
www.markvergeer.nl


Matt Barton's picture

I have to admit, I never

I have to admit, I never understood how poke and peek worked. No clue.


Mark Vergeer's picture

The beginnings of pong

10 poke 53281,0:poke 53280,7:poke 646,7:print chr$(147)
20 x=1:y=1:ax=1:ay=1
30 poke 1024+x+(y*40),160:xm=x:ym=y
40 x=x+ax:y=y+ay
50 if x<=0 or x>=39 then ax=-ax
60 if y<=0 or y>=24 then ay=-ay
70 poke 1024+xm+(ym*40),32
80 goto 30

c64 listing - beginnings of pong?

This produces a black screen with yellow borders and a yellow block bouncing around. Where x, y are the coordinates. ax and ay are the variables that are added to the x- and y-coordinates to make the ball move. xm and ym are the memory variables to be able to clear the old ball position after the new coordinates are calculated and the new ball position is drawn. This allows the ball to be displayed as long as the computer is calculating the new position.
The beginnings of a simple pong-game?

The ball movement produced by the code above is rather uniform with only the direction of the ball changing when a wall is hit, very like the original pong. It is much nicer to do it with a gravity effect on the y coordinates where the ball accelerates and decelerates. Here's my gravity effect pong-demo:


how would you change the above listing to achieve this effect?



Editor / Pixelator - Armchair Arcade, Inc.
www.markvergeer.nl


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.