Login
Back to forumReply to this topicGo to last reply

Posted By

orac81
on 2025-08-09
09:56:27
 Experimenting with OSCAR64 C Compiler, it generates very fast 6502 code..

So I have little C app, SCONNEX, (simple 4-in-a-line game) that I have been using to experiment and benchtest different compilers. I have managed to make it build versions for C64, C16, Vic20, etc, with the OSCAR64 C compiler, and a range of other compilers.

(Source+bins: https://github.com/orac81/miniapples/raw/refs/heads/main/sconnex-latest.zip )

Here are my Benchmarks with SCONNEX, on a fixed/same search with each compiler (same node count, eval, etc).

Run with new board, set IQ, then G for computer to compute first move:

OSCAR64-C64: (-O2) iq5:12 sec,(5,37,3283n). iq6:57 sec,(5,52,16550n). iq7:194 sec,(5,36,-13383n [52153n]) (269 nodes per second)

VBCC-C64: (-O2) iq5:23 sec,(4,37,3283n). iq6:111 sec,(5,52,16550). iq7:371 sec,(5,36,-13383n [52153n]) (140nps)

CC65-C64: (-Osir) iq5:36 sec,(5,37,3283n). iq6:171 sec,(5,52,16550). iq7:575 sec,(5,36,-13383n [52153n]) (90nps)

Z88DK-ZX-SPECTRUM iq6:102sec (5,52,16550n).

The brackets have (move#, eval, node count).

VBCC, CC65 and Z88DK are very good and comprehensive C99 compilers (VBCC is fast), but OSCAR seems to be even faster. It also generates very compact code. It is even twice as fast as the ZX-Spectrum build, thats a 1mhz 6502 against a 3.5mhz Z80. Amazing.

While it mainly targets the C64, there are stub build options for Vic20, c16, Pet, Atari800, nes, etc. Adding libs for apple2, oric, etc should be straightforward.

(SCONNEX will build for C64, C16, VIC20, PET, ZX81, Spectrum, so its possible to test across different targets. By building with OSCAR it is twice as fast, and 2k smaller!)

I have managed to get Hi-res graphics working on the Vic20 and C16 with OSCAR too, you can look at my source to see how thats done. The plot libs I have posted here for the Vic20+vbcc should work with a few tweaks.

There are a few quirks with OSCAR, and even the odd bug, but over all a very impressive piece of work by dr mortalwombat.

Open source too! You can find it here:

https://github.com/drmortalwombat

You need to build it from source, see oscar64.md for instructions, so to build in Linux:

make -C make compiler

should work. I can post up an Ubuntu 64 bit build if wanted.

Some of my notes and hints:

OSCAR seems to take a different approach to libraries, there are none! Or at least no traditional .lib files, instead each header has a #pragma that includes source code for the library directly, so for example the header "conio.h" ends with:

#pragma compile("conio.c")

This way, the optimizer can fold in and optimize the code fully with the app. This is particularly useful for a 6502 target, and can reduce memory usage and improve code speed.

VIC20: To use hires graphics on a VIC20 with 16k, you need to move the code start up to $2000. For OSCAR you can use the C64 memmap lib for this. This #pragma will do this, add this at the start of your code:


// Force VIC20 start up high ($2000) for hires gfx at $1000-1fff
#include
#pragma region( main, 0x2000, 0x6000, , , {code, data, bss, heap, stack} )


There is now space from $1000-1fff for VIC20 hi-res graphics. Note that you can choose a lower start point depending on how much graphics space you need. (you can use much less just for a char set)

Plus4/C16
RAM is switched in by default, to access ROM (kernal, copy chrset etc) you need sta $ff3e/ff3f around your code switching RAM/ROM.

conio.c/bkhit() not working for C16/+4 ( 0xc6 is NOT keybd queue len, its 0xef.) Personally I would just use a little asm routine with "jsr $ffe4" to read a char from the keyboard.
Posted By

Mad
on 2025-08-09
12:50:17
 Re: Experimenting with OSCAR64 C Compiler, it generates very fast 6502 code..

Wow, this is a fairly fast c compiler!! Nice find..


Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2025. Support Plus/4 World on Patreon