kernalemu is a C reimplementation of the Commodore KERNAL API, combined with a 6502 emulator.

Related tags

CLI kernalemu
Overview

kernalemu - Commodore KERNAL emulator

kernalemu is a C reimplementation of the Commodore KERNAL API, combined with a 6502 emulator. It allows runnung cleanly written PET/C64/C128 etc. command line applications on the UNIX command line, like BASIC interpreters, assemblers, monitors and text adventures.

Features

  • Channel I/O API
    • Devices 0 (keyboard) and 3 (keyboard) map UNIX stdin and stdout.
    • Devices 4-7 writes the printer output to files printer4.txt etc. on disk.
    • Devices 8-15 goes through a basic Commodore DOS layer that maps to the UNIX filesystem. Reading and writing files, sending certain disk commands and loading the directory ("$") is supported.
    • Devices 1 (tape) and 2 (tape or RS-232) are not supported.
  • Time API: bridged to system time
  • IEEE-488 API: not yet supported

Usage

kernalemu [options] file...

You have to specify one or more programs. They have to be in PRG format, i.e. the first two bytes of the file contain the load address. All files are loaded into the emulator's memory.

Options

  • -start : entry point
  • -startind : location of entry point vector
  • -machine : KERNAL API level, valid arguments are pet (v1/2/3), pet4 (v4), c64, ted (C16, C116, Plus/4), c128, c65 (default: c64)
  • -text: assume PETSCII upper/lower; convert to ASCII
  • -graphics: assume PETSCII upper/graphics; do not convert (default)
  • -columns : insert hard line breaks after columns

Comments

  • If no machine is specified, it is autodetected from the load address.
  • If no entry point is specified:
    • If the program has a SYS BASIC header, the entry point is extracted from it automatically.
    • Otherwise, it defaults to the load address.

Examples

There are several applications in the demo subdirectory. Here is how to run them:

PET BASIC V4

$ kernalemu demo/basic4.prg -start 0xd3b5 -machine pet4

*** COMMODORE BASIC 4.0 ***

 31743 BYTES FREE

READY.

VIC-20 BASIC V2

$ kernalemu demo/vic20basic.prg -startind 0xc000 -machine vic20

**** CBM BASIC V2 ****
38911 BYTES FREE

READY.

VIC-20 BASIC V2 + BASIC V4

$ kernalemu demo/vic20basic.prg demo/vic20basic4.prg -startind 0xa000 -machine vic20

**** CBM BASIC V2 ****
38911 BYTES FREE

READY.

C64 BASIC V2

$ kernalemu demo/basic2.prg -startind 0xa000 -machine c64


    **** COMMODORE 64 BASIC V2 ****

 64K RAM SYSTEM  38911 BASIC BYTES FREE

READY.

C64 BASIC V2 + SIMONS BASIC

$ kernalemu demo/simonsbasic.prg demo/basic2.prg -startind 0x8000

*** EXTENDED CBM V2 BASIC ***

38911 BASIC BYTES FREE

READY.

Plus/4 BASIC V3.5

$ kernalemu demo/c16basic.prg -start 0x8000 -machine 264

?OUT OF MEMORY ERROR IN 0
READY.

TODO

C128 BASIC V7

$ kernalemu demo/c128basic.prg -start 0x4000 -machine c128


 COMMODORE BASIC V7.0 122365 BYTES FREE
   (C)1986 COMMODORE ELECTRONICS, LTD.
	 (C)1977 MICROSOFT CORP.
	   ALL RIGHTS RESERVED

READY.

Assembler 64

$ kernalemu demo/assembler64.prg


CBM RESIDENT ASSEMBLER V080282
(C) 1982 BY COMMODORE BUSINESS MACHINES

OBJECT FILE (CR OR D:NAME): 

This is the assembler Commodore used to build their ROMs. It will successfully build e.g. the C64 KERNAL source if you extract the files from the disk image and pass kernal as the source file name:

echo "kernal.hex\r\r\rkernal" | kernalemu assembler64.prg

This will create kernal.hex with the hex output. You can convert it to binary using:

tr '\r' '\n' < kernal.hex > kernal_lf.hex
srec_cat kernal_lf.hex -MOS_Technologies \
    -offset -0xe000 \
    -fill 0xaa 0x0000 0x1fff \
    -o kernal.bin -Binary

The assembler sends the LST output to the printer, which you can find in the file printer4.txt:

[...]
01727  EE13              ;INPUT A BYTE FROM SERIAL BUS
01728  EE13              ;
01729  EE13              ACPTR
01730  EE13  78                 SEI             ;NO IRQ ALLOWED
01731  EE14  A9 00              LDA #$00        ;SET EOI/ERROR FLAG
01732  EE16  85 A5              STA COUNT
01733  EE18  20 85 EE           JSR CLKHI       ;MAKE SURE CLOCK LINE IS RELEASED
01734  EE1B  20 A9 EE    ACP00A JSR DEBPIA      ;WAIT FOR CLOCK HIGH
01735  EE1E  10 FB              BPL ACP00A
01736  EE20              ;
01737  EE20              EOIACP
01738  EE20  A9 01              LDA #$01        ;SET TIMER 2 FOR 256US
01739  EE22  8D 07 DC           STA D1T2H
01740  EE25  A9 19              LDA #TIMRB
[...]

Assembler 128

$ kernalemu demo/assembler128.prg -start 0x2000 -machine c128

C/128 6502 ASSEMBLER V022086
(C)1986 BY COMMODORE BUSINESS MACHINES


SOURCE FILE  (SYNTAX: [DRIVE:]FILENAME) ? 

TODO

VIC-Mon for VIC-20

$ kernalemu demo/vicmon.prg -startind 0x4002 -machine vic20

VIC20 MICROMON V1.2   BILL YEE 22 JAN  83
B*
    PC  IRQ  SR AC XR YR SP
.; 404D 4391 22 33 00 00 FF
.

Commodore Monitor for C64

$ kernalemu demo/monitor64.prg -machine c64

B*
   PC  SR AC XR YR SP
.;C03D 22 00 C3 00 FF
.

Final Cartridge III Monitor

$ kernalemu demo/fc3monitor.prg -machine c64

C*
   PC  IRQ  BK AC XR YR SP NV#BDIZC
.;4024 0000 07 8D FF 00 FF *.*.....
.

Scott Adams Text Adventures

$ kernalemu 1.Adventure\ Land.prg -machine vic20 -start 0x7F50

COMMODORE Presents:

***** ADVENTURE *****

(C) 1981
by Scott Adams,INC

Adventure number: 1

Version: 1/416

Want to restore
previously saved game?

Credits

This repository is maintained by Michael Steil, [email protected], www.pagetable.com.

Some of the code is derived from cbmbasic, see there for additional authors.

The license is 2-clause BSD.

You might also like...
vrEmu6502 - 6502/65c02 emulator written in C

vrEmu6502 6502/65c02 emulator written in C Initially created for the HBC-56 Emulator Includes: Support for standard 6502, 65C02, WDC65C02 and R65C02.

Learn how to connect your Flexispot (LoctekMotion) desk to the internet. This repository contains a collection of scripts to get your started, combined with research and instructions.
Learn how to connect your Flexispot (LoctekMotion) desk to the internet. This repository contains a collection of scripts to get your started, combined with research and instructions.

(image source: Windows Central) Turn your LoctekMotion/FlexiSpot desk into a smart desk Recently I acquired a new standing desk from FlexiSpot. During

A combined suite of utilities for manipulating binary data files.

BinaryTools A combined suite of utilities for manipulating binary data files. It was developed for use on Windows but might compile on other systems.

combined decoder for DAB and FM
combined decoder for DAB and FM

DUORECEIVER 1.0 COMBINED FM AND DAB MINI RECEIVER I got questions from family members why there was no combined FM and DAB receiver available, since t

A combined suite of utilities for exporting images to retro formats.

ImageTools A combined suite of utilities for exporting images to retro formats. It was developed for use on Windows but might compile on other systems

Easing the task of comparing code generated by cc65, vbcc, and 6502-gcc

6502 C compilers benchmark Easing the way to compare code generated by cc65, 6502-gcc, vbcc, and KickC. This repository contains scripts to: Compile t

A library to play Commodore 64 music

libsidplayfp ============ https://github.com/libsidplayfp/libsidplayfp libsidplayfp is a C64 music player library which integrates the reSID SID chi

Microcontroller based switchless ROM switcher for the Commodore 1541-II disk drive

Retroninja 1541-II Switchless Multi-ROM A microcontroller based switchless ROM switcher for the Commodore 1541-II disk drive. Switch between stock CBM

C64 Watch is a customized T-Watch 2020 that was inspired by the Commodore 64 computer. It features a C64 theme and a built-in BASIC interpreter.
C64 Watch is a customized T-Watch 2020 that was inspired by the Commodore 64 computer. It features a C64 theme and a built-in BASIC interpreter.

C64 Watch C64 Watch is a customized T-Watch 2020 that was inspired by the Commodore 64 computer. It features a C64 theme and a built-in BASIC interpre

Commodore 64 VIC-II 6567/6569 Replacement Project

This is a WIP. Beta testing is underway on hardware. Check back later for updates. VIC-II Kawari What is VIC-II Kawari? VIC-II Kawari is a hardware re

cbmconvert: create, extract and convert 8-bit Commodore binary archives

cbmconvert: create, extract and convert 8-bit Commodore binary archives cbmconvert extracts files from most known archive file formats that are used o

A MOS-6502 implementation in C++ 17
A MOS-6502 implementation in C++ 17

cpu-6502 A MOS-6502 implementation in C++ 17 More about this microprocessor Photographer: Dirk Oppelt (From Wikimedia Commons, the free media reposito

A 6502 microprocessor implementation in modern C++ (20)

cpu6502 A 6502 microprocessor implementation in modern C++ (20) Features and code structure The reference memory layout used and implemented: /* 6

 Reimplementation of the Diablo2 game coupled with patching facilities for modders.
Reimplementation of the Diablo2 game coupled with patching facilities for modders.

D2MOO - Diablo II Method and Ordinal Overhaul This project is a re-implementation of the Diablo2 game coupled with patching facilities for modders.

Clean-room reimplementation of Half-Life: Deathmatch and Half-Life (Experimental) in QuakeC.
Clean-room reimplementation of Half-Life: Deathmatch and Half-Life (Experimental) in QuakeC.

FreeHL Clean-room reimplementation of Half-Life: Deathmatch and Half-Life (Experimental). Similar to FreeCS, this aims to recreate the feeling of the

Snowboy reimplementation

Snowman Hotword Detection Snowman Hotword Detection is an open source rewrite of the popular Snowboy library originally developed by Kitt.AI. It was c

An open source standard C library that includes useful functions && (Reimplementation of libc functions + own functions).
An open source standard C library that includes useful functions && (Reimplementation of libc functions + own functions).

📖 LIBFT-42 : Artistic view of LIBC: 🎭 HOW DOES IT FEEL HAVING YOUR OWN LIB: SUBJECT : ENGLISH PDF ℹ️ What is LIBFT : This project aims to code a C l

Open-source flog (Nintendo Switch's Golf NES easter egg) reimplementation
Open-source flog (Nintendo Switch's Golf NES easter egg) reimplementation

This repository is dedicated to flog, an easter egg present on Nintendo Switch consoles, containing various tools and information, which are the result of progressive reverse-engineering of the easter egg.

Reimplementation of some of the Standard C Library functions.
Reimplementation of some of the Standard C Library functions.

42-libft Reimplementation of some of the Standard C Library functions. This repository contains some of the standard library C functions. List of avai

Comments
  • Simons basic is not working

    Simons basic is not working

    Running

    echo 'LIST' | ./build/kernalemu demo/simonsbasic.prg demo/basic2.prg -machine c64 -startind 0x8000 | head

    you get

    ?NEXT WITHOUT FOR ERROR READY.

    It apply for every command you try to run in simonsbasic. We huble suggest to put a "TODO" in the readme

    opened by daitangio 0
  • Dos commands do not work on Basic4

    Dos commands do not work on Basic4

    How to reproduce:

    $ ./build/kernalemu demo/basic4.prg -start 0xd3b5 -machine pet4 *** COMMODORE BASIC 4.0 ***

    31743 BYTES FREE

    READY. LOAD "$",8

    unknown PC=$B782 S=$FA (caller: $0101)

    How can I fix it (pull request will follow)?

    opened by daitangio 0
  • Updates and fixes to Fake6502

    Updates and fixes to Fake6502

    I've made several fixes to fake6502, and... I've made it header-only!

    It is 100% compatible with your repository and I maintain a fork of your repository here; https://github.com/gek169/kernalemu-fake6502-dev

    If you would be so kind, try throwing some test programs (I was only able to boot the test programs in the repo) and make sure they work with the emulator

    Of note: I fixed interrupt masking, and I fixed decimal mode. Fake6502 had issues with how it implemented both of those and they are now corrected to conform to the specification.

    My update to fake6502 is fully CC0, so feel free to incorporate it into your repository.

    Thank you very much for the code.

    P.S. Your repository doesn't contain a license...

    opened by gek169 0
Owner
Michael Steil
Michael Steil
CLIp is a clipboard emulator for a command line interface written in 100% standard C only. Pipe to it to copy, pipe from it to paste.

CLIp v2 About CLIp is a powerful yet easy to use and minimal clipboard manager for a command line environment, with no dependencies or bloat. Usage Sy

A.P. Jo. 12 Sep 18, 2021
Contour - A modern C++ Terminal Emulator

contour is a modern terminal emulator, for everyday use. It is aiming for power users with a modern feature mindset.

Contour Terminal Emulator 1.1k Dec 28, 2022
A terminal emulator that runs in your terminal. Powered by Turbo Vision.

tvterm A terminal emulator that runs in your terminal. Powered by Turbo Vision. tvterm is an experimental terminal emulator widget and application bas

null 21 Aug 8, 2022
Make your terminal emulator colorful!

libvterm Make your terminal emulator colorful! LibVTerm is an embeddable ANSI C89 (C90) library for parsing ANSI escape sequences. It is constructed i

Kirill GPRB 5 Jun 4, 2022
A simple header-only C++ argument parser library. Supposed to be flexible and powerful, and attempts to be compatible with the functionality of the Python standard argparse library (though not necessarily the API).

args Note that this library is essentially in maintenance mode. I haven't had the time to work on it or give it the love that it deserves. I'm not add

Taylor C. Richberger 1.1k Jan 4, 2023
A simple header-only C++ argument parser library. Supposed to be flexible and powerful, and attempts to be compatible with the functionality of the Python standard argparse library (though not necessarily the API).

args Note that this library is essentially in maintenance mode. I haven't had the time to work on it or give it the love that it deserves. I'm not add

Taylor C. Richberger 896 Aug 31, 2021
JSONes - c++ json parser & writer. Simple api. Easy to use.

JSONes Just another small json parser and writer. It has no reflection or fancy specs. It is tested with examples at json.org Only standart library. N

Enes Kaya ÖCAL 2 Dec 28, 2021
Commodore 6502ASM, the original 6502/65C02/65CE02 Assembler used by Commodore for C65 project

Commodore 6502ASM This is the source code of the 6502/65C02/65CE02 assembler developed and used by Commodore for the C65 project. It aims to be compat

Michael Steil 17 Nov 29, 2022
✔️The smallest header-only GUI library(4 KLOC) for all platforms

Welcome to GUI-lite The smallest header-only GUI library (4 KLOC) for all platforms. 中文 Lightweight ✂️ Small: 4,000+ lines of C++ code, zero dependenc

null 6.6k Jan 8, 2023
A fast and simple 6502 emulator in plain C.

6502js But C A hobby project that replicates the 6502js emulator, but with the speed of C. Why? For fun and learning :D Simple on the outside: Replica

Lim Ding Wen 2 Nov 25, 2021