Back to BASICs. Commodore 64 BASIC V2.

Fast-forward to nowadays, I continue to be interested in how hardware and software work and watched quite a few reverse engineering videos on YouTube, like Apollo Guidance Computer restoration series on CuriousMarc channel and others. Due to this YT algorithm suggests me similar videos. A couples of days ago it suggested me to watch the 27c3: Reverse Engineering the MOS 6502 CPU video about how 6502 CPU was reverse engineered by peeling layers from the chip, taking photographs and then reconstructing actual transistors from the photos. The talk was given by Michael Steil who extensively contributed to documenting everything there is about MOS 6502 CPU and various types of BASIC it ran.
The people who reversed engineered the MOS 6502, Greg James, Brian and Barry Silverman also wrote a
JavaScript visualization of the inner workings of the 6502 as it chugs alone.

It turns out that Michael Steil implemented a C based simulation of the MOS 6502 and hooked it up to the Commodore BASIC emulator to see how it worked. And it worked indeed!

Prerequisites

  • Interest in this topic 🙂
  • Operating System: Linux or Windows 10 with Windows Subsystem For Linux 2 (WSL2)
  • Source control software: git (should come preinstalled on WSL) to be able to check out the implementation of the 6502 CPU and BASIC
  • make tool installed
  • C compiler like, gcc installed

What to expect?

Let’s begin

Install WSL and Ubuntu

Clone GitHub repository

Now, that we have Ubuntu installed let’s download (clone) the MOS 6502 repository from GitHub to be able to build it locally.

  • When you navigated to that repository in GitHub click on the code button in the right upper hand side,
  • and click on copy icon

Create directory to clone repository into

mkdir perfect6502
cd perfect6502
git clone https://github.com/mist64/perfect6502.git
Cloning into 'perfect6502'...
remote: Enumerating objects: 643, done.
remote: Total 643 (delta 0), reused 0 (delta 0), pack-reused 643
Receiving objects: 100% (643/643), 997.31 KiB | 4.96 MiB/s, done.
Resolving deltas: 100% (391/391), done.

Install make and gcc on Ubuntu

sudo apt install make
sudo apt install gcc
make
amc@MINE-LAPTOP-130JJTQ6:~/perfect6502$ make
cc -Werror -Wall -O3   -c -o perfect6502.o perfect6502.c
cc -Werror -Wall -O3   -c -o netlist_sim.o netlist_sim.c
netlist_sim.c: In function ‘getGroupValue’:
netlist_sim.c:390:1: error: control reaches end of non-void function [-Werror=return-type]

To fix this issue there is a need to apply Pull Request (PR) one of the users submitted.

git fetch origin pull/10/head:pr_number10
OBJS+=measure.o

Update Makefile using Windows notepad

explorer.exe .

amc@MINE-LAPTOP-130JJTQ6:~/perfect6502$ make
cc -Werror -Wall -O3   -c -o perfect6502.o perfect6502.c
cc -Werror -Wall -O3   -c -o netlist_sim.o netlist_sim.c
cc -Werror -Wall -O3   -c -o cbmbasic/cbmbasic.o cbmbasic/cbmbasic.c
cc -Werror -Wall -O3   -c -o cbmbasic/runtime.o cbmbasic/runtime.c
cc -Werror -Wall -O3   -c -o cbmbasic/runtime_init.o cbmbasic/runtime_init.c
cc -Werror -Wall -O3   -c -o cbmbasic/plugin.o cbmbasic/plugin.c
cc -Werror -Wall -O3   -c -o cbmbasic/console.o cbmbasic/console.c
cc -Werror -Wall -O3   -c -o cbmbasic/emu.o cbmbasic/emu.c
cc -o cbmbasic/cbmbasic perfect6502.o netlist_sim.o cbmbasic/cbmbasic.o cbmbasic/runtime.o cbmbasic/runtime_init.o cbmbasic/plugin.o cbmbasic/console.o cbmbasic/emu.o
cbmbasic/cbmbasic

What can you do now?

You can do even more pretty trick using BASIC to print “Hello, world!” in Assembly code. I saw this implementation in the “Hello World” on Commodore 64 in Assembly Language, Machine Code video.

You can watched how it worked in real time below

Some useful commands to know

PRINT CHR$(147)
NEW
SYS 64738
LIST

To update particular line there is a need to retype it in this emulator, while in other emulators you can edit them. As you can see on the C64 online emulator

SUMMARY

REFERENECES

2 thoughts on “Back to BASICs. Commodore 64 BASIC V2.

  1. vlad eugen says:

    Your last step for the fix don’t work !!!!!!!!!
    all went good till here. I commented the line as you said and it still give the same error. I done that step before to update as well, all step by step. It does not MAKE.
    so I fuckin wasted hours to do all step by step to finally fix the bugs -ie the cretin bug that does not accept password for user unless you are in su -and in the end now I have to stop because the f incompetence of these guy who are not even able to build a f* healthy ubuntu environment w/o 1000 bugs and TEMPORARY fixes who would pop up again with every new OS patch. this is why I hate Linux

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.