Skip to content

Commit e6965dc

Browse files
committed
MEGA65: hyppo 0.97 for Xemu #436
Merging the result of the `hypup` branch. The previous HYPPO inside Xemu is about 3 years old for now, which already causes many problems, including the problems with newest ROMs using the new D81 attach method, just to name one problem. Besides this, trying to make GEOS65 a smoother experience with Xemu, as it does some tricky stuff to be able to work, which caused problems for Xemu in the past. Thanks to @gurcei for some preliminary testings in his own repository.
1 parent f092bc2 commit e6965dc

File tree

8 files changed

+7866
-7073
lines changed

8 files changed

+7866
-7073
lines changed

build/m65-memcontent-generator.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
44
# Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
5-
# Copyright (C)2016-2022 LGB (Gábor Lénárt) <[email protected]>
5+
# Copyright (C)2016-2025 LGB (Gábor Lénárt) <[email protected]>
66
#
77
# This program is free software; you can redistribute it and/or modify
88
# it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
2525
# This must be incremented by ONE every time, when memcontent.c changes, or even
2626
# if sdcontent.c is changed in a way to write new files, new content, or whatever
2727
# to the SD-card as part of the "update system files" process.
28-
MEMCONTENT_VERSION_ID = 2
28+
MEMCONTENT_VERSION_ID = 3
2929

3030
FILE_DB = {
3131
# -------------------------------------------------------------------- #
@@ -45,6 +45,11 @@
4545
"SPRITED.M65": ("sprited", "SPRITED.M65" ),
4646
"charrom.bin": ("chrwom", None ),
4747
"MAKEDISK.M65": ("makedisk", "MAKEDISK.M65" ),
48+
# Added ones at 2025/06 - as part of the issue https://github.com/lgblgblgb/xemu/issues/436
49+
"M65THUMB.M65": ("m65thumb", "M65THUMB.M65" ),
50+
"MONITOR.M65": ("monitor", "MONITOR.M65" ),
51+
"ETHLOAD.M65": ("ethload", "ETHLOAD.M65" ),
52+
"MEGAINFO.M65": ("megainfo", "MEGAINFO.M65" ),
4853
}
4954

5055
HEADER = """/* !THIS IS A GENERATED FILE! DO NOT EDIT!
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
diff --git a/src/utilities/onboard.c b/src/utilities/onboard.c
2+
index 8b946f7..f93a1be 100644
3+
--- a/src/utilities/onboard.c
4+
+++ b/src/utilities/onboard.c
5+
@@ -7,6 +7,10 @@
6+
#include <time.h>
7+
#include <random.h>
8+
9+
+static int is_xemu;
10+
+static const unsigned char xemu_fpga_firmware_id[4] = { 0x58, 0x65, 0x6d, 0x75 }; // 'X','e','m','u' in ASCII
11+
+static const unsigned char xemu_cpld_firmware_id[4] = { 0x4e, 0x6f, 0x77, 0x21 }; // 'N','o','w','!' in ASCII
12+
+
13+
short i, y;
14+
unsigned char crt_mode = 1;
15+
unsigned char last_video_mode = 0;
16+
@@ -352,6 +356,7 @@ void main(void)
17+
unsigned char idle_time = 0, update_rtc = 0;
18+
19+
mega65_io_enable();
20+
+ is_xemu = !memcmp((void*)0xD632U, xemu_fpga_firmware_id, 4) && !memcmp((void*)0xD62CU, xemu_cpld_firmware_id, 4);
21+
22+
// Disable OSK
23+
lpoke(0xFFD3615L, 0x7F);
24+
@@ -373,6 +378,8 @@ void main(void)
25+
// do hardware version dependent setup
26+
hardware_setup();
27+
28+
+restart_screen:
29+
+
30+
printf("%cWelcome to the MEGA65!\n\n"
31+
"Before you go further, there are couple of things you need to do.\n\n"
32+
"Press F3 - F13 to set the time and date (shift toggles direction).", 0x93);
33+
@@ -443,6 +450,32 @@ void main(void)
34+
POKE(0x286, 1);
35+
printf(" to save and exit.");
36+
37+
+ if (is_xemu) {
38+
+ // Xemu's case, provide own screen, etc ...
39+
+ printf(
40+
+ "%cWelcome to Xemu emulation of MEGA65!\n\n"
41+
+ "This is MEGA65's ONBOARDing utility\n"
42+
+ "running. In case of an emulator it's\n"
43+
+ "not so useful, but still part of the\nprocess.\n\n"
44+
+ "Please press RETURN and accept the\n"
45+
+ "FPGA reconfiguration request of Xemu.\n", 0x93);
46+
+ for (;;) {
47+
+ c = PEEK(0xD610);
48+
+ if (c) POKE(0xD610,0);
49+
+ if (c == 0x0a || c == 0x0d) {
50+
+ crt_mode = 0;
51+
+ video_mode = 1;
52+
+ video_mode_change_pending = 0;
53+
+ last_video_mode = video_mode;
54+
+ goto write_result;
55+
+ }
56+
+ if (c == 0x4d || c == 0x6d) { // secret 'm' key to allow to run the original utility ...
57+
+ is_xemu = 0;
58+
+ goto restart_screen;
59+
+ }
60+
+ }
61+
+ }
62+
+
63+
c = PEEK(0xD610);
64+
if (!c) {
65+
if (idle_time < 75)
66+
@@ -651,7 +684,7 @@ void main(void)
67+
last_video_mode = video_mode;
68+
}
69+
else {
70+
-
71+
+write_result:
72+
// First make sure we have the config sector freshly loaded
73+
lpoke(0xffd3681, 0x01);
74+
lpoke(0xffd3682, 0x00);
75+
@@ -711,10 +744,16 @@ void main(void)
76+
while (lpeek(0xffd3680) & 0x03)
77+
continue;
78+
79+
- printf("%c\n\n\n\n\n\n\n\n\n\n\n"
80+
- " Please POWER-CYCLE your MEGA65 now\n"
81+
- " by turning it off and on again!", 0x93);
82+
- while (1);
83+
+ if (!is_xemu) {
84+
+ printf("%c\n\n\n\n\n\n\n\n\n\n\n"
85+
+ " Please POWER-CYCLE your MEGA65 now\n"
86+
+ " by turning it off and on again!", 0x93);
87+
+ while (1);
88+
+ } else {
89+
+ printf("\n\nFPGA reconfiguration ...");
90+
+ while (1)
91+
+ POKE(0xD6CFU,0x42); // asks for FPGA reconfiguration
92+
+ }
93+
}
94+
}
95+
}

targets/mega65/Makefile

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,34 @@ CFLAGS_TARGET_xmega65 = $(SDL2_CFLAGS) $(MATH_CFLAGS) $(SOCKET_CFLAGS) $(XEMUGUI
2626
LDFLAGS_TARGET_xmega65 = $(SDL2_LIBS) $(MATH_LIBS) $(SOCKET_LIBS) $(XEMUGUI_LIBS)
2727
LDFLAGS_TARGET_xmega65_ON_html = -s STACK_SIZE=655360 --preload-file=$$HOME/.local/share/xemu-lgb/mega65/mega65.img.compressed3@/files/mega65.img --preload-file=$$HOME/mega65/megapoly.d81@/files/files/hdos/mega65.d81
2828

29-
MEGA65_CORE = ../../../mega65-core-master
29+
MEGA65_CORE = ../../../mega65-core-0.97-for-xemu
30+
MEGA65_REPO = https://github.com/MEGA65/mega65-core.git
31+
MEGA65_COMMITID = aaf4542d02679271b5fb84ad933cc39bbe091c3f
32+
MEGA65_PATCH = ../../build/mega65-core-0.97-aaf4542d02679271b5fb84ad933cc39bbe091c3f-patch.diff
3033
MEGA65_FILES = bin/charrom.bin bin/HICKUP.M65 bin/COLOURRAM.BIN sdcard-files/BANNER.M65 sdcard-files/ONBOARD.M65 src/open-roms/bin/mega65.rom
3134
MEGA65_FILES += sdcard-files/FREEZER.M65 sdcard-files/MAKEDISK.M65
3235
MEGA65_FILES += sdcard-files/AUDIOMIX.M65 sdcard-files/C64THUMB.M65 sdcard-files/C65THUMB.M65 sdcard-files/ROMLOAD.M65 sdcard-files/SPRITED.M65
36+
MEGA65_FILES += sdcard-files/M65THUMB.M65 sdcard-files/MONITOR.M65 sdcard-files/ETHLOAD.M65 sdcard-files/MEGAINFO.M65
3337

3438
MEGA65_FP_FILES = $(addprefix $(MEGA65_CORE)/,$(MEGA65_FILES))
3539
MEGA65_LOCALDIR = .sys-files-mega65-core
40+
3641
MATRIX_TAB_VHDL = $(MEGA65_CORE)/src/vhdl/matrix_to_ascii.vhdl
3742

3843
include ../../build/Makefile.common
3944

4045
# mega65-core has very tricky build system, it's very hard to be sure, that everything
4146
# is up-to-date, this is the reason for this mess
4247
recreatememcontent:
48+
$(MAKE) $(MEGA65_CORE)/xemu_patched
4349
@echo "*** Compiling needed files from mega65-core at $(MEGA65_CORE) ***"
44-
$(MAKE) -C $(MEGA65_CORE) clean
45-
for dir in src/mega65-freezemenu src/mega65-fdisk src/open-roms ; do $(MAKE) -C $(MEGA65_CORE)/$$dir clean || exit 1 ; done
46-
find $(MEGA65_CORE) -name "*.o" | xargs -n 100 rm -f
47-
find $(MEGA65_CORE) -name "*.M65" | xargs -n 100 rm -f
4850
mkdir -p $(MEGA65_CORE)/sdcard-files
49-
rm -f `echo $(MEGA65_FP_FILES) | fgrep -v mega65.rom`
50-
rm -f $(MEGA65_CORE)/sdcard-files/* $(MEGA65_CORE)/src/mega65-fdisk/*.prg $(MEGA65_CORE)/src/utilities/*.prg
51-
rm -f $(MEGA65_CORE)/src/hyppo/HICKUP.rep $(MEGA65_CORE)/src/hyppo/HICKUP.sym
52-
$(MAKE) -C $(MEGA65_CORE)/src/mega65-fdisk m65fdisk.prg
53-
$(MAKE) -C $(MEGA65_CORE)/src/mega65-freezemenu
54-
$(MAKE) -C $(MEGA65_CORE) freezer_files
55-
$(MAKE) -C $(MEGA65_CORE) $(MEGA65_FILES)
51+
cd $(MEGA65_CORE) ; $(MAKE) cc65/bin/cc65
52+
cd $(MEGA65_CORE) ; $(MAKE) -C src/mega65-libc
53+
cd $(MEGA65_CORE) ; $(MAKE) freezer_files
54+
cd $(MEGA65_CORE) ; $(MAKE) -C src/mega65-fdisk m65fdisk.prg
55+
cd $(MEGA65_CORE) ; $(MAKE) -C src/mega65-freezemenu
56+
cd $(MEGA65_CORE) ; $(MAKE) $(MEGA65_FILES)
5657
mkdir -p $(MEGA65_LOCALDIR)
5758
rm -f $(MEGA65_LOCALDIR)/*
5859
cp $(MEGA65_FP_FILES) $(MEGA65_LOCALDIR)/
@@ -61,6 +62,38 @@ recreatememcontent:
6162
@echo "*** Generating C files from mega65-core binary results ***"
6263
python3 $(TOPDIR)/build/m65-memcontent-generator.py memcontent.c memcontent.h $(MEGA65_FP_FILES)
6364

65+
cleanmega65core:
66+
cd $(MEGA65_CORE) ; $(MAKE) clean
67+
cd $(MEGA65_CORE) ; for dir in src/mega65-freezemenu src/mega65-fdisk src/open-roms ; do $(MAKE) -C $$dir clean || exit 1 ; done
68+
find $(MEGA65_CORE) -name "*.o" | xargs -n 100 rm -f
69+
find $(MEGA65_CORE) -name "*.M65" | xargs -n 100 rm -f
70+
mkdir -p $(MEGA65_CORE)/sdcard-files
71+
rm -f `echo $(MEGA65_FP_FILES) | fgrep -v mega65.rom`
72+
rm -f $(MEGA65_CORE)/sdcard-files/* $(MEGA65_CORE)/src/mega65-fdisk/*.prg $(MEGA65_CORE)/src/utilities/*.prg
73+
rm -f $(MEGA65_CORE)/src/hyppo/HICKUP.rep $(MEGA65_CORE)/src/hyppo/HICKUP.sym
74+
75+
$(MEGA65_CORE)/xemu_checked_out:
76+
@echo "*** Checking out $(MEGA65_REPO) to $(MEGA65_CORE) at commit-id $(MEGA65_COMMITID) ***"
77+
rm -f "$@"
78+
rm -fr "$(MEGA65_CORE)"
79+
git -c init.defaultBranch=whocares init "$(MEGA65_CORE)"
80+
git -C "$(MEGA65_CORE)" remote add origin "$(MEGA65_REPO)"
81+
git -C "$(MEGA65_CORE)" fetch --depth 1 origin "$(MEGA65_COMMITID)"
82+
git -C "$(MEGA65_CORE)" -c advice.detachedHead=false checkout "$(MEGA65_COMMITID)"
83+
git -C "$(MEGA65_CORE)" submodule update --init --recursive --depth 1
84+
echo "$(MEGA65_REPO) at commit-id $(MEGA65_COMMITID)" > "$@.new"
85+
date >> "$@.new"
86+
du -sh "$(MEGA65_CORE)" >> "$@.new"
87+
cat "$@.new" | sed 's/^/| /'
88+
mv "$@.new" "$@"
89+
90+
$(MEGA65_CORE)/xemu_patched:
91+
$(MAKE) $(MEGA65_CORE)/xemu_checked_out
92+
@echo "*** Patching mega65-core for Xemu at $(MEGA65_CORE) ***"
93+
@if test -f "$@"; then echo "ERROR: Already patched"; false; fi
94+
patch -p1 -d "$(MEGA65_CORE)" < $(MEGA65_PATCH)
95+
date > "$@"
96+
6497
showmatrix:
6598
bash $(TOPDIR)/build/m65-import-matrix2ascii.sh < $(MATRIX_TAB_VHDL)
6699
bash $(TOPDIR)/build/m65-import-matrix2petscii.sh < $(MATRIX_TAB_VHDL)

0 commit comments

Comments
 (0)