I tried Vibe coding in BASIC using Grok and it went well
Previously, I was having difficulty vibing. Thanks to a comment on reddit by
droid_mike, I tried Grok and things are “better.”droid_mike: So, I hate to recommend this, but it really knows vintage BASIC well... Try Grok.
Grok
Hello World
Please write me a simple program in Applesoft BASIC that repeatedly prints “Hello, World” to the screen.
Here's a simple Applesoft BASIC program that repeatedly prints "Hello, World" to the screen: hello.bas
plain
10 PRINT "Hello, World" 20 GOTO 10*So it took me a moment to realize to click on “Download to file” and this will provide a file with newlines!Draw a Circle
Write me an Applesoft BASIC program that draws a blue circle in HGR graphics mode.
details…
Here's an Applesoft BASIC program that draws a blue circle in HGR (High-Resolution Graphics) mode:
This program:
circle.bas
plain
- Enters HGR mode (280x192 resolution)
- Sets color to
blue(HCOLOR=5)- Starts plotting at the center point (140,80)
- Uses a loop to draw a circle with radius 50 pixels
- Calculates X,Y coordinates using trigonometric functions
- Plots points to form the circle
10 HGR 20 HCOLOR=5 30 HPLOT 140,80 40 FOR R = 0 TO 50 50 FOR A = 0 TO 360 60 X = 140 + R * COS(A * 3.14159 / 180) 70 Y = 80 + R * SIN(A * 3.14159 / 180) 80 HPLOT X,Y 90 NEXT A 100 NEXT R
Grok is a bit color blind
That circle looks orange not blue.
I also flipped KEGS into
“as fast as possible!” mode
to render the almost filled-in circle.Create a Drawing Program
Write an Applesoft BASIC program that lets you draw on the screen using a joystick. It should use hires graphics and allow you to rotate between colors by pressing the push button.
details…
Here's an Applesoft BASIC program that allows drawing in HGR mode using a joystick to move the cursor and the joystick button to cycle through colors:
This program:
joystick_draw.bas
plain
- Initializes HGR mode and sets starting position (140,80) with color 1 (white)
- Plots initial point
- Reads joystick X (PDL(0)) and Y (PDL(1)) axes and button (PEEK(-16287))
- Updates cursor position based on joystick input, scaled for smooth movement
- Keeps cursor within screen bounds (0-279 for X, 0-191 for Y)
- Changes color when button is pressed (cycles through 8 colors: 0-7)
- Plots point at new position
- Loops continuously to track joystick movement
Note: This assumes a standard Apple II joystick where PDL(0) and PDL(1) return values from 0-255, and the button is read via PEEK(-16287). The color cycle includes the standard HGR colors (0=black, 1=green, 2=violet, 3=white, 4=
orange, 5=blue, 6=green2, 7=white2).816ms10 HGR: HCOLOR=1: X=140: Y=80: C=1 20 HPLOT X,Y 30 JX=PDL(0): JY=PDL(1): JB=PEEK(-16287) 40 X=X+(JX-128)/20: Y=Y+(JY-128)/20 50 IF X<0 THEN X=0 60 IF X>279 THEN X=279 70 IF Y<0 THEN Y=0 80 IF Y>191 THEN Y=191 90 IF JB>127 THEN C=C+1: IF C>7 THEN C=1: HCOLOR=C 100 HPLOT X,Y 110 GOTO 30
At this point I switched to AppleWin using Wine
I wasn't sure what was going at first. AppleWin graphically shows X and Y of the joystick which was helpful. The drawing color is always green and the joystick is a bit janky to use but the program works in both KEGS and AppleWin.
Create a Game
Create a simple version of Space Invaders using Applesoft BASIC. Use HGR graphics mode and draw aliens, spaceship and missiles. The player’s ship should be controlled with the joystick.
details…
I'll create a simple Space Invaders game in Applesoft BASIC using HGR (High-Resolution Graphics) mode, with joystick control for the player's spaceship, aliens, and missiles. The game will feature a player-controlled ship at the bottom, moving left and right with the joystick, firing missiles upward, and a row of aliens moving horizontally across the top. Due to Applesoft BASIC’s limitations, I'll keep the graphics simple using HPLOT for drawing and focus on core mechanics: player movement, missile firing, and alien movement with basic collision detection.
The Apple II joystick (via PDL(0) for horizontal position) will control the ship’s X-coordinate. The game will use HGR mode (280x192 resolution) for drawing, with HCOLOR for colors and HPLOT for shapes. The aliens will be a single row moving side-to-side, and the missile will be a simple vertical line. Collision detection will check if the missile’s position overlaps with an alien’s bounding box. The game ends if an alien reaches the bottom or the player destroys all aliens.
Here’s the implementation:
• How to play:
space_invaders.bas
plain
- Joystick Control: Use the Apple II joystick to move the player’s ship left and right (PDL(0) reads 0-255, mapped to X=5-274).
- Fire Missile: Press the joystick button (PDL(1)<100) to fire a missile upward from the ship’s position.
- Objective: Destroy all five aliens (5x5 pixel boxes) by hitting them with missiles. Aliens move side-to-side and descend when they hit screen edges.
- Game Over: The game ends if an alien reaches Y=170 (near the bottom) or if you destroy all aliens.
- Graphics: The ship is a simple triangle, aliens are 5x5 boxes, and missiles are 4-pixel vertical lines, all drawn in white (HCOLOR=3) on a black background.
- Restart: Press any key after winning or losing to restart.
This code is designed for Applesoft BASIC on an Apple II, using HGR for 280x192 graphics. The joystick’s X-axis (PDL(0)) controls the ship, and the button (PDL(1)) fires missiles. The game is simple but functional, with basic collision detection and win/lose conditions. Due to BASIC’s speed limitations, the game may run slowly, but it captures the core Space Invaders mechanics.
1.3s10 REM Simple Space Invaders in Applesoft BASIC 20 REM Initialize variables 30 HGR:HCOLOR=3:REM Set high-res graphics and white color 40 PX=140:REM Player X position (center of 0-279) 50 PY=180:REM Player Y position (near bottom of 0-191) 60 MX=-1:MY=-1:REM Missile X,Y (-1 means inactive) 70 DIM AX(5):DIM AY(5):REM Array for 5 aliens' X,Y positions 80 FOR I=0 TO 4:AX(I)=50+I*40:AY(I)=20:NEXT:REM Initialize aliens 90 AD=1:REM Alien direction (1=right, -1=left) 100 AS=1:REM Alien speed 110 REM Main game loop 120 GOSUB 300:REM Clear screen 130 GOSUB 400:REM Draw player 140 GOSUB 500:REM Draw aliens 150 GOSUB 600:REM Draw missile 160 GOSUB 700:REM Handle joystick 170 GOSUB 800:REM Move missile 180 GOSUB 900:REM Move aliens 190 GOSUB 1000:REM Check collisions 200 IF MY<0 THEN IF PDL(1)<100 THEN MX=PX:MY=PY-5:REM Fire missile if button pressed 210 IF AY(0)>170 THEN GOTO 1200:REM Game over if aliens reach bottom 220 IF NA=5 THEN GOTO 1100:REM Win if all aliens destroyed 230 GOTO 120 300 REM Clear screen 310 HGR:HCOLOR=3:RETURN 400 REM Draw player ship (triangle) 410 HCOLOR=0:HPLOT PX-5,PY TO PX,PY-5 TO PX+5,PY:HPLOT PX-3,PY TO PX+3,PY:REM Erase old 420 PX=PDL(0)*1.09:IF PX<5 THEN PX=5:IF PX>274 THEN PX=274:REM Read joystick, limit bounds 430 HCOLOR=3:HPLOT PX-5,PY TO PX,PY-5 TO PX+5,PY:HPLOT PX-3,PY TO PX+3,PY:REM Draw new 440 RETURN 500 REM Draw aliens (simple 5x5 box) 510 FOR I=0 TO 4 520 IF AY(I)=-1 THEN GOTO 550:REM Skip if alien is destroyed 530 HCOLOR=0:HPLOT AX(I)-2,AY(I)-2 TO AX(I)+2,AY(I)-2 TO AX(I)+2,AY(I)+2 TO AX(I)-2,AY(I)+2 TO AX(I)-2,AY(I)-2:REM Erase old 540 HCOLOR=3:HPLOT AX(I)-2,AY(I)-2 TO AX(I)+2,AY(I)-2 TO AX(I)+2,AY(I)+2 TO AX(I)-2,AY(I)+2 TO AX(I)-2,AY(I)-2:REM Draw new 550 NEXT 560 RETURN 600 REM Draw missile (vertical line) 610 IF MX=-1 THEN RETURN 620 HCOLOR=0:HPLOT MX,MY TO MX,MY+3:REM Erase old 630 HCOLOR=3:HPLOT MX,MY TO MX,MY+3:REM Draw new 640 RETURN 700 REM Handle joystick (already in player draw) 710 RETURN 800 REM Move missile 810 IF MX=-1 THEN RETURN 820 MY=MY-5:REM Move up 830 IF MY<0 THEN MX=-1:MY=-1:REM Deactivate if off screen 840 RETURN 900 REM Move aliens 910 FOR I=0 TO 4 920 IF AY(I)=-1 THEN GOTO 950 930 AX(I)=AX(I)+AD*AS 940 IF AX(I)<5 OR AX(I)>274 THEN AD=-AD:FOR J=0 TO 4:IF AY(J)<>-1 THEN AY(J)=AY(J)+5:NEXT:GOTO 960 950 NEXT 960 RETURN 1000 REM Check collisions 1010 NA=0:REM Count destroyed aliens 1020 FOR I=0 TO 4 1030 IF AY(I)=-1 THEN NA=NA+1:GOTO 1070 1040 IF MX=-1 THEN GOTO 1070 1050 IF MX>=AX(I)-2 AND MX<=AX(I)+2 AND MY>=AY(I)-2 AND MY<=AY(I)+2 THEN AY(I)=-1:MX=-1:MY=-1:REM Hit detected 1060 IF AY(I)>170 THEN GOTO 1200 1070 NEXT 1080 RETURN 1100 REM Win game 1110 HOME:VTAB 10:PRINT "YOU WIN! ALL ALIENS DESTROYED!" 1120 PRINT "PRESS ANY KEY TO RESTART" 1130 GET K$:GOTO 20 1200 REM Game over 1210 HOME:VTAB 10:PRINT "GAME OVER! ALIENS REACHED BASE!" 1220 PRINT "PRESS ANY KEY TO RESTART" 1230 GET K$:GOTO 20
It's slow and primitive but it works
Call me impressed. Thank you
droid_mike.
| I tried Vibe coding in BASIC and it didn't go well either | comments reddit | 2025-07-17 |