Description:
In the VICE emulator, a bug occurs when COMAL80 uses its internal CALL routine
to invoke a ROM-based routine from a RAM-based COMAL software package.
Background:
COMAL80 uses up to six switchable 16KB ROM banks. Paging is done by writing to $DE00.
Based on hardware design, the bit layout of $DE00 is as following in COMAL80:
To switch banks during execution, COMAL80 uses a RAM-based CALL routine:
JSR CALL
!by PAGE
!word ADDR
Bug Description:
Technical Note:
Page ID $4x = %-1---xxx
High bits $4x = RAM indicator
Low bits x = page number
Steps to Reproduce:
Expected Result:
CALL should work and return to caller page ID $4x.
Actual Result:
VICE fails to return correctly from CALL, causing crashes.
Test Program:
A minimal test program demonstrates the issue:
Environment:
Conclusion:
VICE's $DE00 handling is not fully compatible with COMAL80 paging logic.
VICE must support valid COMAL80 page identifiers ($4x) for correct behavior.
VICE uses this right now:
and implements the upper bits like this:
case 0xe0: cmode = CMODE_RAM
case 0x80: cmode = CMODE_16KGAME
case 0x40: cmode = CMODE_8KGAME
so yeah, the software uses them and they probably are used for something :)
Also, "banks 1.-6" confuses me - it's not 8 banks? Perhaps that is the problem here, ie banking is not linear, but there is a "gap" we need to consider?
Thank you for your response.
I would like to provide additional background and reasoning to support the conclusion that the current COMAL80 CRT file is likely based on a hardware variant that does not match the official Commodore cartridge and that this mismatch contributes to the issues observed in emulation (specifically in VICE).
Context and Assumption
It appears that the COMAL80 CRT was created using a hardware layout corresponding to a cartridge distributed by the Comal Users Group, U.S.A., Limited (Madison, Wisconsin), rather than the official Commodore version.
Historical Overview
No additional socket, but it was possible to piggyback a fifth EPROM via minor hardware mod
Black Cartridge (Official Commodore Release)
Software Behavior
In the official COMAL80 v2.01 source (e.g. C64SYMB), the cartridge banks are switched using the following definitions:
PAGE0 = %11100000 ; NO EXPANSION
PAGE1 = %10000000 ; CARTRIDGE OVERLAY 1 ($8000-$BFFF)
PAGE2 = %10000001 ; OVERLAY 2
PAGE3 = %10000010 ; OVERLAY 3
PAGE4 = %10000011 ; OVERLAY 4
PAGE5 = %10000100 ; OVERLAY 5
PAGE6 = %10000101 ; OVERLAY 6
Notably, PAGE0 sets Bit 5 to 1, which does not match the behavior of the official Commodore black cartridge. However, because Bit 5 is not explicitly checked in the software, this does not cause issues on real hardware.
The complete, but only very slightly documented Source-Code of COMAL80 2.01 can be found on my GitHub Page: https://github.com/LeshanDaFo/C64-COMAL-2.01
However, it should be possible to switch up to 8 banks in the VICE emulation software, as this was used in the past by the PAKMA extension. And it doesn't interfere with the normal operation of the original software.
Observed Issue
In the VICE emulator, the actual software design leads to unexpected switching behavior or failure to correctly map cartridge banks, likely because VICE emulates the U.S. layout variant, not the official Commodore cartridge layout variant.
Recommendation
To ensure consistent emulator behavior and future compatibility, I recommend:
Conclusion
This issue appears to affect VICE emulation only — not real C64 hardware or other C64 emulation software. However, for long-term preservation and accurate emulation, it would be beneficial to adapt the CRT to reflect the widely recognized official Commodore design, or clearly mark it as being based on the U.S. variant.
Attachments:
– Schematics of both cartridge types can be found on my GitHub-Page:
https://github.com/LeshanDaFo/C64-COMAL-2.01/blob/main/PCB-Layout/2.0%20Cartridge%20Black.pdf
https://github.com/LeshanDaFo/C64-COMAL-2.01/blob/main/PCB-Layout/2.0%20Cartridge%20Gray.pdf
I have found a solution.
Replacing the following code:
with this:
will solve the problem.
Interesting info... I'll have a look at those layouts and see if we really need two variants
Could you point to the exact cartridge image that you used to reproduce the problem?
Actually there are 2 different version existing of COMAL80 2.01
the pictures of the start screen can be found on my GitHub page in the README.md
And the two CRT files are also available there.
Last edit: ClausS 2025-06-14
Oh and the most important question here is: The software does (always) run on both of these cartridges? Or is there software that only works on one of those variants? In that case, i'd like to see at least one image of each (and a way to tell it "works") :)
For my understanding, the software should run on both versions. And with your fixes, it will.
(I was going to point you to the Comal80 efforts going on in F64 - then realized you were knee deep into it. lol!)
I probably have the best overview of Comal's internal processes, but maybe I'm wrong. lol
would you give me some instructions for dummys? ideally also a d64 with whatever i need to load? i have never used this thing :)
I fixed it all up locally (by default it behaves like "black", and there is a new hardware variant that behaves like "grey" - should we ever need that)
As soon as you tell me how to test this i can commit :D
ah well, check r45698 - test it please :)
I get an error during compiling the code on my mac:
/Volumes/Common/SourceForge/vice-emu-code/vice/src/arch/gtk3/joystickdrv/joystick_osx.c:327:64: fatal error: too many arguments to function call, expected 2, have 3
327 | joy_axis_event(joyport, e.ordinal, JOY_AXIS_NEGATIVE);
| ~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~
/Volumes/Common/SourceForge/vice-emu-code/vice/src/joyport/joystick.h:408:6: note: 'joy_axis_event' declared here
408 | void joy_axis_event (joystick_axis_t *axis, int32_t value);
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[5]: *** [joystick_osx.o] Error 1
make[4]: *** [install-recursive] Error 1
make[3]: *** [install-recursive] Error 1
make[2]: *** [install-recursive] Error 1
make[1]: *** [install] Error 2
make: *** [install-recursive] Error 1
Will at least get it building again today.
Then I will try to compile it later.
gna yes, macOS is currently broken :( not sure if you can disable joystick support completely as a workaround...
I think to disable the joystick support is beyond my capabilities. :(
But I have some good news.
I managed to patch an older version with the changes you made.
I'm able to compile this, and it works now as expected.
Existing CRT images are now correctly recognized as the black CRT image.
If you set bit $1A in the CRT image to $01, it will be recognized as the gray CRT module.
I tested it with my test program and it now works as it should under both images.
From my point of view this patch is ok
Additional Info:
As you may know, Comal80 can load so-called packages. These packages contain procedures and functions that can be used from a running program.
Instructions on how these packages should be structured can be found in the book https://archive.org/details/comal-80-for-the-commodore-64 starting on page 255, or directly starting on page 261.
There are also demo disks with the corresponding source code; one can be found on my GitHub page: https://github.com/LeshanDaFo/C64-COMAL-2.01/raw/main/C64-comal-80-demo-disk.d64
My test program has a very simple structure:
You can find a disk with a test program attched.
How to use:
with the old version of VICE, it will crash, but with the new version, it workd fine.
About MacOS joystick support: there is a patch that fixes the THEC64 joystick on MacOS and uses the updated API, fixing joystick support for MacOS in the process.
However, I'm currently working on the joystick code in a branch, so to avoid any possible merge conflicts, applying that patch will need to happen after I've merged my work in the branch back into trunk.
I don't have a timeline for when we can fix the MacOS joystick code: I'm working on polling joysticks from the UI (that works) but creating usable and non-messy dialogs and widgets for mappings and calibration is taking a bit more time than I thought :)
No Problem for me, take your time.
I only have patched on older Version, to see, if the problem is solved now.
And it seems it is. So far i did not get any error.