• Stars
    star
    400
  • Rank 107,843 (Top 3 %)
  • Language
    Assembly
  • Created about 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Source code of GEOS 2.0 for the Commodore 64 and 128

GEOS Source Code

by Berkeley Softworks, reverse engineered by Maciej Witkowiak, Michael Steil.

Description

GEOS is a graphical user interface for 6502-based computers. In the 1980s, it was commercially available for the Commodore 64, 128 and Plus/4 as well as the Apple II.

GEOS has extremly low hardware requirements:

  • a MOS 6502-compatible CPU (usually at 1 MHz or higher)
  • 64 KB of RAM
  • one disk drive (capacity application-dependent)
  • a 320x200 monochrome screen
  • a pointing device

With just 20 KB of binary code, the GEOS "KERNAL" has the following features:

  • Application Model
    • One full screen application at a time
    • One "desk accessory" can be launched in a window while an application is running
    • Multi-segmented applications can be swapped in from disk
    • Runloop model
    • Cooperative multithreading
  • Graphical User Interface
    • Menu bar with nested sub-menus
    • Dialog boxes
    • Buttons
    • Loadable proportional fonts at different sizes
    • Rich text rendering
    • Text input
    • Generic graphics drawing library supporting compressed images and fill patterns
  • Device Driver Interface
    • Disk/storage
    • Mice
    • Printers
  • Other
    • Multi-fork ("VLIR") file system API
    • External RAM extension support
    • Sprite library
    • Math library
    • Memory and strings library
    • Realtime clock with alarm

The default shell of GEOS is deskTop, a file manager an application launcher.

Several powerful applications are available for GEOS, including

  • geoWrite
  • geoPaint
  • geoPublish
  • geoCalc
  • geoFile
  • geoBASIC

The cc65 compiler suite allows writing GEOS applications in C or assembly.

Source

This is the reverse engineered source code of the KERNAL (plus disk and input drivers) of the English version of GEOS 2.0 for Commodore 64 and Commodore 128.

The source has been heavily reorganized and modularized, nevertheless, a standard compile will generate binaries that are identical with the GEOS 64 2.0 and GEOS 128 2.0 distribution binaries.

Optionally, the following features that were not part of the original GEOS 2.0 can be enabled for GEOS64:

  • gateWay 2.51 KERNAL patches
  • +60K RAM support
  • Ram Cart 64/128 support

Requirements

  • make, bash, dd
  • cc65 for assembling and linking
  • pucrunch for generating a compressed executable
  • c1541 for generating the disk image

Without pucrunch/c1541, you can still build an uncompressed KERNAL binary image.

Building

Run make to build the original "BSW" GEOS for C64. This will create the following files in directory build/bsw:

  • raw KERNAL components: kernal.bin, lokernal.bin, init.bin
  • disk drive drivers: drv1541.bin, drv1571.bin, drv1581.bin
  • input drivers: amigamse.bin, joydrv.bin, lightpen.bin, mse1351.bin, koalapad.bin, pcanalog.bin
  • combined KERNAL image (SYS 49155): kernal_combined.prg
  • compressed KERNAL image (RUN): kernal_compressed.prg
  • disk image: geos.d64

If you have the cbmfiles.com GEOS64.D64 image in the current directory, the disk image will be based on that one, with the GEOS and GEOBOOT files deleted and the newly built kernel added. Otherwise, it will be a new disk image with the kernel, and, if you have a desktop.cvt file in the current directory, with DESK TOP added.

Variants

The build system supports the following variants:

  • bsw (default): Berkeley Softworks GEOS 64 2.0 variant
  • cbmfiles: The cbmfiles.com version. It starts out with a different date, and has some variables in the kernel pre-filled.
  • gateway: The patched KERNEL shipped by gateWay 2.51. It contains a slightly modified BSW font, has the Panic code replaced with code to swap the disk driver on a RESTORE press, and it loads GATEWAY instead of DESK TOP as the shell.
  • wheels: The Wheels 64 variant. It is heavily patched, optimized for size and speed, and contains additional features. It requires a RAM extension. The current version compiles into the same binary, but won't actually run because of missing boot code. More work is needed here.
  • bsw128: Berkeley Softworks GEOS 128 2.0 variant, i.e. GEOS for C128 with 128 KB RAM and VDC 640px width support. This needs some more work to actually boot.
  • custom: See below.

You can build a specific variant like this:

make VARIANT=<variant>

All output will be put into build/<variant>.

Drivers

By default, the KERNAL image will contain the Commodore 1541 disk driver (drv1541) and the joystick input driver (joydrv). You can specify different drivers to be included like this:

make DRIVE=<drive> INPUT=<input>

Supported drives are drv1541, drv1571 and drv1581. Supported input devices are amigamse, joydrv, koalapad, lightpen, mse1351 and pcanalog.

Customization

The KERNAL variant custom is meant for your experimentation. Inside the .ifdef custom section in config.inc, you can toggle several compile time options:

  • removeToBASIC = 1: Don't include the ToBASIC code required for deskTop to launch non-GEOS applications, in order to save RAM for code.
  • use2MHz = 1: Switch a C128 in C64 mode to 2 MHz outside of the visible screen.
  • usePlus60K = 1: Enable support for the +60K RAM expansion.
  • useRamCart64 = 1, useRamCart128 = 1: Enable support for the Ram Cart expansion.

With RAM expansion support, GEOS will use the extra RAM for caching deskTop and for holding the swap area when running desk accessories. GEOS will show an error at startup and reset the system if support for a particular memory expansion is enabled but it is not available.

Note that the changing settings and adding code may cause certain memory areas to overflow. In this case, you can try moving segments between the LOKERNAL and KERNAL areas. The file kernal.map in the build output will give you an idea about the sizes of segments. The custom variant starts out with about 550 bytes of usable memory in the KERNAL area.

Source Tree

  • Makefile
  • config.inc: kernel config options
  • regress.sh: script that compares output with reference
  • drv/: disk drive driver source
  • inc/: include files: macros and symbols
  • input/: input driver source
  • kernal/: kernal source
  • reference/: original binaries from the cbmfiles.com version

Hacking

Code layout

Great care was taken to split the KERNAL into small, independent components. This division does not necessarily match the layout of the original binary code, but with the help of .segments, the layout in the binary does not have to match the layout in source.

The goal of this division of the source was to keep the number of .imports minimal (i.e. to make individual source files as self-contained and independent as possible).

One example of this is the file system and application/accessory loading code. In the original GEOS KERNAL binary, they were not separate, but here, the file system code is in filesys.s and the loading code is in load.s, with only two symbol dependencies.

Another example is the ToBasic logic: In the original kernel, it the binary code was split, a part resided between the header and the jump table ($C000-$C0FF), and different part was in the "lokernal" area ($9000-$9FFF). In the source, both parts are in the same file tobasic.s.

Machine-specific Code

In case you want to adapt the source for other 6502-based systems, you will want to know which parts have C64 dependencies.

All C64-specific code can be easily recognized: Since all C64 symbols have to be imported from c64.inc, you can tell which source files have C64 depencency by looking for that include. Remove the include to see which parts of the code are platform-specific.

InitTextPrompt in conio.s, for example, accesses sprites directly, in the middle of hardware-independent code.

Memory Layout

The GEOS KERNAL has a quite complicated memory layout:

  • $9000-$9FFF: KERNAL ("lokernal")
  • $A000-$BF3F: (graphics bitmap)
  • $BF40-$BFFF: KERNAL
  • $C000-$C01A: KERNAL Header
  • $C01B-$C0FF: KERNAL
  • $C100-$C2E5: KERNAL Jump Table
  • $C2E6-$FFFF: KERNAL

The header and the jump table must be at $C000 and $C100, respectively. Together with the graphics bitmap at $A000, this partitions the KERNAL into four parts: lokernal, below header, between header and jump table, and above jump table.

The linker config file positions the segments from the source files into these parts. If the code of any segment changes, the header and the jump table will remain at their positions. If a part overruns, the linker will report and error, and you can consult the kernal.map output file to find out where to best put the extra code.

But it gets more complicated: Code between $D000 and $DFFF is under the I/O registers, so it cannot enable the I/O area to access hardware. The macro ASSERT_NOT_BELOW_IO makes sure that the current code is not under the I/O area. Existing code uses this macro just befor turning on the I/O area and just after turning it off. New code should use this macro, too.

Naming Conventions

  • Symbols used outside of the current source file are supposed to be prefixed with an _. (This hasn't been done consistently yet.)
  • Labels that are only used within a subroutine should use the @ notation.

Copy protection

The original GEOS was copy protected in three ways:

  • The original loader decrypted the KERNAL at load time and refused to do so if the floppy disk was a copy. Like the cbmfiles.com version, this version doesn't use the original loader, and the kernel is available in plaintext.
  • deskTop assigned a random serial number to the kernel on first boot and keyed all major applications to itself. This version comes with a serial number of 0x58B5 pre-filled, which matches the cbmfiles.com version.
  • To counter tampering with the serial number logic, the KERNAL contained two traps that could sabotage the kernel. The code is included in this version, but can be removed by setting trap = 0.

Contributing

Pull requests are greatly appreciated. Please keep in mind that a default build should always recreate the orginal binaries, so for smaller changes use conditional assembly using .if, and for larger changes create new source files that are conditionally compiled.

The following command line will build the bsw and wheels variants of GEOS and compare the resulting binaries with reference binaries:

make regress

TODO

  • Reconstruction/cleanup:
    • complete inline documentation of KERNAL calls
    • boot.s should be based on the original GEOS version
    • REU detection is missing from boot.s
    • The 1541 driver is hardcoded. We should create one version per drive.
    • Some of Maciej's original changes/improvements have bitrotten and need to be resurrected
    • Wheels
      • The Wheels variant needs boot code to start up correctly.
      • The additional Wheels code needs to be reverse engineered properly.
  • Integrate other versions as compile time options
    • Localized versions
    • Plus/4 version
    • C128 version (includes 640px support, linear framebuffer graphics, new APIs)
    • Apple II version (includes new APIs)
  • Integrate existing patches as compile time options
    • megaPatch
    • SuperCPU
    • Flash 8
    • misc
  • Add third party disk drivers
    • CMD hardware
    • Modern hardware
  • Optimizations
    • Faster (with size tradeoff) font.s and graph.s code
    • Alternate code paths for 65C02, 65CE02, 65816
  • Extensions
    • upgrade DlgBox to support more than 16 files
    • support +60K and RamCart simultaneousy (hell!)
    • support swapping KERNAL modules to/from expansion
    • disk cache (at least dir cache) (hell!)
    • try to rewrite 1571/81 to use burst commands instead of turbodos (only on burst-enabled C64/128 in C64 mode - see Pasi Ojala's design)
  • Reverse-engineer other components, like deskTop
  • Port to new systems. :)

References

License

For the underlying work on GEOS, please respect its license.

The intellectual property added by the reverse-engineering and the subsequent improvements is in the public domain, but the authors request to be credited.

Authors

GEOS was initially developed by Berkeley Softworks in 1985-1988.

The original reverse-engineering was done by Maciej 'YTM/Elysium' Witkowiak in 1999-2002, targeted the ACME assembler and was released as GEOS 2000, which included several code optimizations and code layout differences.

In 2015/2016, Michael Steil ported the sources to cc65, reconstructed the original code layout, did some more reverse-engineering and cleanups, and modularized the code aggressively.

More Repositories

1

c64ref

Ultimate Commodore 64 Reference: ROM Disassembly, Memory Map, ...
Python
454
star
2

hvdos

hvdos, a simple DOS emulator based on the OS X Hypervisor.framework
C
442
star
3

cbmsrc

Original source code of various Commodore computers and peripherals.
Roff
435
star
4

cbmbasic

cbmbasic, a portable version of Commodore's version of Microsoft BASIC 6502 as found on the Commodore 64
C
434
star
5

msbasic

Microsoft BASIC for 6502 (Commodore, Apple, KIM-1, AIM-65, OSI, ...)
Assembly
320
star
6

perfect6502

perfect6502, a MOS 6502 CPU emulator that performs a simulation of the original NMOS 6502 netlist
C
294
star
7

c64rom

Commodore 64 BASIC and KERNAL Source
Assembly
194
star
8

msdos1

A collection of disassembled and commented source of parts of MS-DOS 1.0
Assembly
182
star
9

visualize_1541

A tool that creates visualizations of the data layout on Commodore 1541 disk images
Python
69
star
10

64er-magazin.de

HTML
68
star
11

80columns

80x25 text mode for the Commodore 64 BASIC/KERNAL environment
Assembly
65
star
12

ccgmsterm

CCGMS Future, a terminal program for the Commodore 64
Assembly
64
star
13

pucrunch

pucrunch, an Optimizing Hybrid LZ77 RLE Data Compression Program for C64/C128/VIC-20/Plus4
C
56
star
14

geowrite

Source code of geoWrite 2.1 for the Commodore 64
Assembly
55
star
15

final_cartridge

Assembly
53
star
16

ctools

ctools, programs for accessing C64 and C128 CP/M disk images (*.D64).
C++
48
star
17

kernalemu

Commodore KERNAL emulator, to run C64/C128 etc. command line applications on UNIX
C
40
star
18

fc3-geos

Final Cartridge III with GEOS
Assembly
33
star
19

extract-adf

extract-adf, a tool that extracts files from (broken) Amiga OFS ADF/ADZ/DMS disk images
C
30
star
20

c64_kernal

Assembly
29
star
21

cbm6502asm

Commodore 6502ASM, the original 6502/65C02/65CE02 Assembler used by Commodore for C65 project
C
28
star
22

cbmbus_doc

HTML
26
star
23

fastboot1541

fastboot1541, an autostart fastloader for the Commodore 64 and 1541 that fits into a single sector.
Assembly
26
star
24

dos1541

The Commodore 1541 DOS ROM, buildable with cc65
Assembly
24
star
25

mxass

mxass, a cross assembler that targets Commodore 64-like platforms (6502/65816/Z80)
Assembly
23
star
26

TopDesk

The TopDesk file manager for the C64/C128 GEOS operating system
Assembly
22
star
27

thewave

The Wave Web Browser for C64/C128 GEOS Wheels
Assembly
19
star
28

datasette_load

A minimal Commodore 64 Datasette program loader
Assembly
16
star
29

nes_snes_controller_6502

NES & SNES Controller Driver for 6502 (Commodore 64)
Assembly
16
star
30

c64bs

C64 KERNAL patch to support ACIA hardware serial, parallel IEEE-488 and more
Assembly
15
star
31

defrag1541

A visual Commodore 64/1541 disk defragmentation program
Visual Basic
15
star
32

ted_kernal

The Commodore TED (C16, C116, Plus/4) KERNAL, buildable with cc65
Assembly
14
star
33

geowrite2rtf

geowrite2txt, a simple tool to convert C64/C128 GEOS GeoWrite documents into plain text
C
14
star
34

static6502

Roff
11
star
35

cbmfs

cbmfs, a Commodore 1541 file system driver for MacFUSE
C
10
star
36

ultimatetron2

Ultimate Tron II is a game for the Commodore 64
Assembly
9
star
37

vis2ascii

vis2ascii, a tool to convert VisAss/F8 AssBlaster C64 assembly into ASCII
C
9
star
38

combine_d64

combine_d64 D64 File Reconstruction Tool
Python
9
star
39

anatomy-4040

Reconstruction of the book "Anatomy of the 4040 Disk Drive" (1988) by Hilaire Gagne from the original files
HTML
8
star
40

extract-md

extract-md, a tool to extract text and graphics from disk images of issues of the German Commodore 64 disk magazine "Magic Disk 64"
C
5
star
41

ps2keyboard

Assembly
4
star
42

darmok

darmok.com: Memes in the Tamarian language
Shell
3
star