R45 BASIC Etch-A-Sketch Example

All aspects of programming on the Commander X16.
Post Reply
4KbShort
Posts: 2
Joined: Tue Oct 31, 2023 5:26 am

File Download R45 BASIC Etch-A-Sketch Example

Post by 4KbShort »

Hey guys,

I wasn't sure if this was a How-to or Programming, but since it's raw code I figured it was more programming.
I am NOT a classic C64 or 8-bit programmer. I got my C64 three years ago and it's been sitting in a box for 2 of them. For this reason I wanted to make things on the x16 that "normal" users would find interesting rather than the awesome, yet often overwhelming, assembly and such I see here most of the time. I also wanted to learn how to do the things that some of the new BASIC commands do for us; such as switching modes and drawing pictures and things. Mostly, I just wanted full control over bitmap mode and with all that I made this:

Code: Select all

01 SCREEN$80
10 PX = 0 : PY = 0 : CL = 8 : S = $9F23 : I = 0
20 POKE $9F25, 0
30 REM POKE $9F2A, 64 : POKE $9F2B, 64
40 POKE $9F2D, %00000111
50 POKE $9F29, %0110001
60 POKE $9F20, PX : POKE $9F21, PY : POKE $9F22, %00000000
70 GET A$: IF A$="" THEN 70
80 A=ASC(A$)
90 IF A=17 THEN I = 320 : GOTO 8000
100 IF A=29 THEN I = 1 : GOTO 8000
110 IF A=145 THEN I = -320 : GOTO 8000
120 IF A=157 THEN I = -1 : GOTO 8000
130 IF A=48 THEN CL = 0
140 IF A=49 THEN CL = 1
150 IF A=50 THEN CL = 2
160 IF A=51 THEN CL = 3
170 IF A=52 THEN CL = 4
180 IF A=53 THEN CL = 5
190 IF A=54 THEN CL = 6
200 IF A=55 THEN CL = 7
210 IF A=56 THEN CL = 8
220 IF A=56 THEN CL = 9
230 GOTO 70
8000 PX = PX + I
8010 IF PX > 255 THEN GOSUB 9000
8011 IF PX < 0 THEN GOSUB 9040
8012 IF PY > 255 THEN POKE $9F22, 1 : PY = 0
8013 IF PY < 0 THEN PY = 0 : IF PX > 0 THEN PX = PX - 1
8020 POKE $9F20, PX : POKE $9F21, PY : POKE S, CL
8030 GOTO 70
9000 PY = PY + 1
9010 PX = PX - 256
9020 IF PX > 255 THEN GOTO 9000
9030 RETURN
9040 IF PY > 1 THEN PY = PY - 1
9050 PX = PX + 256
9060 IF PX < 0 THEN GOTO 9040
9070 RETURN
This code is not pretty and it can be optimized a ton, but that's the point: I don't want it to be pretty or optimized. I'd rather people, like me, who are just starting out on the Cx16 or other 8-bit machines to look at this and go "Oh! That's how you do that!" David said he wanted this to be a learning computer and I want to lower that barrier of entry by being bad at using it well enough others can follow behind.

Thanks!
Last edited by 4KbShort on Tue Oct 31, 2023 4:35 pm, edited 1 time in total.
mortarm
Posts: 320
Joined: Tue May 16, 2023 6:21 pm

Re: R45 BASIC Etch-A-Sketch Example

Post by mortarm »

Nice goin', Short. As someone who deals with newbies on a regular basis, I'm always glad to see someone who has similar intent. I'm planning on writing a beginner's guide to BASIC and the X16.
4KbShort
Posts: 2
Joined: Tue Oct 31, 2023 5:26 am

Re: R45 BASIC Etch-A-Sketch Example

Post by 4KbShort »

Thanks!
Having attempted to use it I found bugs (obviously) and have correct most of them. I'm still having issues with screen space vs memory allocation so the bottom right of the screen becomes a nightmare, but it's just math so I'll eventually figure it out... I hope! Either way, it's a good start to show people some of the power of BASIC that is mostly relegated to assembly right now.
User avatar
ahenry3068
Posts: 1194
Joined: Tue Apr 04, 2023 9:57 pm

Re: R45 BASIC Etch-A-Sketch Example

Post by ahenry3068 »

It actually took me a minute to understand what his code was doing. He's not using any of the built-in BASIC commands or even vpoke, He's using Poke to setup the VERA registers himself. And then writing out to VRAM just like you would in assembler. Kudos. :)
mortarm
Posts: 320
Joined: Tue May 16, 2023 6:21 pm

Re: R45 BASIC Etch-A-Sketch Example

Post by mortarm »

Hmmm, sounds like a good challenge for a new programmer: Convert this program to an X16-specific version.
Post Reply