From 8a082c5ff66f10f02fcf494ab6577d651c1de338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sat, 18 Mar 2023 16:32:40 +0100 Subject: [PATCH 01/25] Build release version of intro. --- Makefile | 2 +- config.mk | 10 +++++----- effects/Config.fs-uae | 1 + include/system/debug.h | 2 +- intro/Makefile | 2 +- intro/data/JazzCat-DerKlang.asm | 1 + system/kernel/memory.c | 4 ++-- system/loader.c | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index dbd927c5..c8ca0246 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ TOPDIR = $(realpath .) -SUBDIRS = tools lib system effects intro +SUBDIRS = tools lib system intro EXTRA-FILES = tags cscope.out CLEAN-FILES = bootloader.bin a500rom.bin addchip.bootblock.bin diff --git a/config.mk b/config.mk index c7efd1c8..0f953a67 100644 --- a/config.mk +++ b/config.mk @@ -2,13 +2,13 @@ # to aid debugging and profiling. This may render executable files # unusable (most likely crash) on real hardware. # 0 => Disable use of aforementioned features. Required for a release! -UAE := 1 +UAE := 0 # [only when UAE=0] Redirect diagnostic and log messages to: # 0 => null output (drop messages) # 1 => parallel port # 2 => serial port -LOGOUT := 2 +LOGOUT := 0 # 1 => Make executable files compatible with AmigaOS. Created ADFs will # be formatted with Old Filesystem (KS1.3) and contain special bootblock @@ -16,14 +16,14 @@ LOGOUT := 2 # automatically facilitating `startup-sequence` feature of AmigaDOS. # 0 => Executable files must be started from ROM or ADF since they require # custom environment created by bootstrap code. -AMIGAOS := 0 +AMIGAOS := 1 # [only when AMIGAOS=1] Amount of chip and fast (or public) memory # (in kilobytes!) passed to our custom memory allocator. # To calculate total memory taken after an executable file # is loaded into memory please use `m68k-amigaos-objdump` tool. -CHIPMEM := 160 -FASTMEM := 288 +CHIPMEM := 240 +FASTMEM := 240 # Pass "VERBOSE=1" at command line to display command being invoked by GNU Make VERBOSE ?= 0 diff --git a/effects/Config.fs-uae b/effects/Config.fs-uae index 62038770..c050044a 100644 --- a/effects/Config.fs-uae +++ b/effects/Config.fs-uae @@ -5,6 +5,7 @@ fade_in_duration = 0 fade_out_duration = 0 accuracy = 1 amiga_model = A500 +#amiga_model = A1200 # A500 A500+ A600 A1200 A1200/020 A3000 A4000/040 # chip_memory = 512 # slow_memory = 512 diff --git a/include/system/debug.h b/include/system/debug.h index 0fc9698e..24335b59 100644 --- a/include/system/debug.h +++ b/include/system/debug.h @@ -14,7 +14,7 @@ void Log(const char *format, ...) __noreturn void Panic(const char *format, ...) __attribute__ ((format (printf, 1, 2))); #else -#define Log(...) +#define Log(...) ((void)0) #define Panic(...) HALT() #endif #endif diff --git a/intro/Makefile b/intro/Makefile index 54cc22c4..8950131e 100644 --- a/intro/Makefile +++ b/intro/Makefile @@ -2,7 +2,7 @@ TOPDIR := $(realpath ..) DELTA := 0 VQ := 0 -KLANG := 0 +KLANG := 1 MODULE := JazzCat-DerKlang diff --git a/intro/data/JazzCat-DerKlang.asm b/intro/data/JazzCat-DerKlang.asm index f8a00809..a16e3a4f 100755 --- a/intro/data/JazzCat-DerKlang.asm +++ b/intro/data/JazzCat-DerKlang.asm @@ -9,6 +9,7 @@ _Samples: _ExtSamples: incbin 'data/JazzCat-DerKlang.raw' + ds.b 280 section '.text', code xdef _AK_Generate diff --git a/system/kernel/memory.c b/system/kernel/memory.c index 5dc19cf3..29ac5a13 100644 --- a/system/kernel/memory.c +++ b/system/kernel/memory.c @@ -119,7 +119,7 @@ static inline WordT *BtPrev(WordT *bt) { return (void *)bt - BtSize(ft); } -static const char *MemoryName(u_int attributes) { +__unused static const char *MemoryName(u_int attributes) { if (attributes & MEMF_CHIP) return "chip"; if (attributes & MEMF_FAST) @@ -380,7 +380,7 @@ static void ArenaCheck(ArenaT *ar, int verbose) { for (; bt < ar->end; prev = bt, bt = BtNext(bt)) { int flag = !!BtGetPrevFree(bt); - int is_last = !!BtGetIsLast(bt); + __unused int is_last = !!BtGetIsLast(bt); Msg("$%08lx: [%c%c:%ld] %c\n", (uintptr_t)bt, "FU"[BtUsed(bt)], " P"[flag], BtSize(bt), " *"[is_last]); if (BtFree(bt)) { diff --git a/system/loader.c b/system/loader.c index 336613fd..d932295b 100644 --- a/system/loader.c +++ b/system/loader.c @@ -73,7 +73,7 @@ void Loader(BootDataT *bd) { CallFuncList(&__INIT_LIST__); { - int retval = main(); + __unused int retval = main(); Log("[Loader] main() returned %d.\n", retval); } From 68f9fc709aa04c12f5180524a1bd66cbd9ae7801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 10:44:37 +0100 Subject: [PATCH 02/25] Disable profiler in the release build. --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index d1e0c82e..e65b5309 100644 --- a/config.mk +++ b/config.mk @@ -22,7 +22,7 @@ AMIGAOS := 1 # lines measured between calls to ProfilerStart / ProfilerStop. # The measurement is reported every 50 frames (i.e. once a second). # 0 => Disable the profiler. -PROFILER := 1 +PROFILER := 0 # [only when AMIGAOS=1] Amount of chip and fast (or public) memory # (in kilobytes!) passed to our custom memory allocator. From 379f59f7edfa0f5c5b013ed888e7d1d8c1d550c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 11:59:45 +0100 Subject: [PATCH 03/25] Start work on disable multitasking when it's not needed. --- build/common.mk | 2 +- config.mk | 2 ++ include/effect.h | 4 ++++ include/system/mutex.h | 10 ++++++++++ system/Makefile | 5 ++++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/build/common.mk b/build/common.mk index b8ae74a1..66d40367 100644 --- a/build/common.mk +++ b/build/common.mk @@ -29,7 +29,7 @@ LDSCRIPT := $(TOPDIR)/system/amiga.lds # Don't reload library base for each call CPPFLAGS += -D__CONSTLIBBASEDECL__=const CPPFLAGS += -DCHIPMEM_KB=$(CHIPMEM) -DFASTMEM_KB=$(FASTMEM) -DLOGOUT=$(LOGOUT) -CPPFLAGS += -DPROFILER=$(PROFILER) +CPPFLAGS += -DPROFILER=$(PROFILER) -DMULTITASK=$(MULTITASK) include $(TOPDIR)/config.mk diff --git a/config.mk b/config.mk index e65b5309..4ff0aff2 100644 --- a/config.mk +++ b/config.mk @@ -24,6 +24,8 @@ AMIGAOS := 1 # 0 => Disable the profiler. PROFILER := 0 +MULTITASK := 0 + # [only when AMIGAOS=1] Amount of chip and fast (or public) memory # (in kilobytes!) passed to our custom memory allocator. # To calculate total memory taken after an executable file diff --git a/include/effect.h b/include/effect.h index 77e14d2c..47d9c98c 100644 --- a/include/effect.h +++ b/include/effect.h @@ -130,9 +130,13 @@ typedef struct Profile { #define ProfilerStop(NAME) #endif +#if MULTITASK /* Puts a task into sleep waiting for Vertical Blank interrupt. * Let's background task do its job. */ void TaskWaitVBlank(void); +#else +#define TaskWaitVBlank WaitVBlank +#endif void _ProfilerStart(ProfileT *prof); void _ProfilerStop(ProfileT *prof); diff --git a/include/system/mutex.h b/include/system/mutex.h index 2beead4e..21eb41e9 100644 --- a/include/system/mutex.h +++ b/include/system/mutex.h @@ -6,6 +6,7 @@ struct Task; +#if MULTITASK typedef struct Mutex { volatile struct Task *owner; TAILQ_HEAD(, Task) waitList; @@ -23,5 +24,14 @@ static inline void MutexInit(MutexT *mtx) { void MutexLock(MutexT *mtx); void MutexUnlock(MutexT *mtx); +#else +typedef struct Mutex {} MutexT; + +#define MUTEX(name) MutexT name = (MutexT){} + +static inline void MutexInit(MutexT *mtx) { (void)mtx; } +static inline void MutexLock(MutexT *mtx) { (void)mtx; } +static inline void MutexUnlock(MutexT *mtx) { (void)mtx; } +#endif #endif /* !__SYSTEM_MUTEX_H__ */ diff --git a/system/Makefile b/system/Makefile index 798197d7..65ca6461 100644 --- a/system/Makefile +++ b/system/Makefile @@ -32,11 +32,14 @@ SOURCES := \ kernel/interrupt.c \ kernel/intr-entry.S \ kernel/memory.c \ - kernel/mutex.c \ kernel/task.c \ kernel/trap-entry.S \ kernel/trap.c +ifeq ($(MULTITASK), 1) +SOURCES += kernel/mutex.c +endif + CFLAGS.amigaos = -Wno-strict-prototypes BUILD-FILES = crt0.o From 39e332e371ed320f56a158af7af1eca514d12329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 12:34:43 +0100 Subject: [PATCH 04/25] Throw away memory debugging routines. --- build/common.mk | 2 +- config.mk | 1 + include/system/memory.h | 4 ++++ system/kernel/memory.c | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build/common.mk b/build/common.mk index 66d40367..43ea5de5 100644 --- a/build/common.mk +++ b/build/common.mk @@ -29,7 +29,7 @@ LDSCRIPT := $(TOPDIR)/system/amiga.lds # Don't reload library base for each call CPPFLAGS += -D__CONSTLIBBASEDECL__=const CPPFLAGS += -DCHIPMEM_KB=$(CHIPMEM) -DFASTMEM_KB=$(FASTMEM) -DLOGOUT=$(LOGOUT) -CPPFLAGS += -DPROFILER=$(PROFILER) -DMULTITASK=$(MULTITASK) +CPPFLAGS += -DPROFILER=$(PROFILER) -DMULTITASK=$(MULTITASK) -DMEMDEBUG=$(MEMDEBUG) include $(TOPDIR)/config.mk diff --git a/config.mk b/config.mk index 4ff0aff2..924107e1 100644 --- a/config.mk +++ b/config.mk @@ -25,6 +25,7 @@ AMIGAOS := 1 PROFILER := 0 MULTITASK := 0 +MEMDEBUG := 0 # [only when AMIGAOS=1] Amount of chip and fast (or public) memory # (in kilobytes!) passed to our custom memory allocator. diff --git a/include/system/memory.h b/include/system/memory.h index 55626347..497d06c9 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -20,7 +20,11 @@ #endif #ifdef _SYSTEM +#if MEMDEBUG void MemCheck(int verbose); +#else +#define MemCheck(x) { (void)0; } +#endif u_int MemAvail(u_int attributes); void AddMemory(void *ptr, u_int byteSize, u_int attributes); #endif diff --git a/system/kernel/memory.c b/system/kernel/memory.c index 29ac5a13..a990defb 100644 --- a/system/kernel/memory.c +++ b/system/kernel/memory.c @@ -364,6 +364,7 @@ static void *ArenaMemResize(ArenaT *ar, void *old_ptr, u_int size) { return new_ptr; } +#if MEMDEBUG #define Msg(...) if (verbose) Log(__VA_ARGS__) static void ArenaCheck(ArenaT *ar, int verbose) { @@ -410,6 +411,7 @@ static void ArenaCheck(ArenaT *ar, int verbose) { MutexUnlock(&MemMtx); } +#endif static ArenaT *ArenaOf(void *ptr) { ArenaT *ar; @@ -480,11 +482,13 @@ void *MemResize(void *old_ptr, u_int size) { return NULL; } +#if MEMDEBUG void MemCheck(int verbose) { ArenaT *ar; for (ar = FirstArena; ar != NULL; ar = ar->succ) ArenaCheck(ar, verbose); } +#endif u_int MemAvail(u_int attributes) { ArenaT *ar; From 01b3509ed43fc22d1216bab28aed0bc7604e1e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 12:35:16 +0100 Subject: [PATCH 05/25] Throw away more multitasking code. --- system/kernel/task.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/system/kernel/task.c b/system/kernel/task.c index 4b8cbe6e..00387a82 100644 --- a/system/kernel/task.c +++ b/system/kernel/task.c @@ -51,6 +51,7 @@ void TaskInit(TaskT *tsk, const char *name, void *stkptr, u_int stksz) { #define PushWord(v) \ { *--(u_short *)sp = (u_short)(v); } +#if MULTITASK void TaskRun(TaskT *tsk, u_char prio, void (*fn)(void *), void *arg) { void *sp = tsk->stkUpper; @@ -224,3 +225,9 @@ void TaskSwitch(TaskT *curtsk) { Debug("Switching to '%s', prio: %d.", curtsk->name, curtsk->prio); CurrentTask = curtsk; } +#else +void TaskSwitch(TaskT *curtsk) { + (void)curtsk; + HALT(); +} +#endif From 4438769d043a7280d62ce45047cf4a2e214e796e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 12:55:06 +0100 Subject: [PATCH 06/25] Disable MemAvail when MEMDEBUG is 0 --- include/system/memory.h | 5 +++-- system/kernel/memory.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index 497d06c9..9abce961 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -22,10 +22,11 @@ #ifdef _SYSTEM #if MEMDEBUG void MemCheck(int verbose); +u_int MemAvail(u_int attributes); #else -#define MemCheck(x) { (void)0; } +#define MemCheck(_) { (void)0; } +#define MemAvail(_) 0 #endif -u_int MemAvail(u_int attributes); void AddMemory(void *ptr, u_int byteSize, u_int attributes); #endif diff --git a/system/kernel/memory.c b/system/kernel/memory.c index a990defb..d565827c 100644 --- a/system/kernel/memory.c +++ b/system/kernel/memory.c @@ -488,7 +488,6 @@ void MemCheck(int verbose) { for (ar = FirstArena; ar != NULL; ar = ar->succ) ArenaCheck(ar, verbose); } -#endif u_int MemAvail(u_int attributes) { ArenaT *ar; @@ -498,3 +497,4 @@ u_int MemAvail(u_int attributes) { avail += ar->totalFree; return avail; } +#endif From 2f3fab6b5365399393958161026bd7dc11e57318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 12:55:22 +0100 Subject: [PATCH 07/25] MemResize is not used in intro. --- system/kernel/memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/kernel/memory.c b/system/kernel/memory.c index d565827c..2c1ffa04 100644 --- a/system/kernel/memory.c +++ b/system/kernel/memory.c @@ -308,6 +308,7 @@ static void ArenaMemFree(ArenaT *ar, void *ptr) { MutexUnlock(&MemMtx); } +#if 0 static void *ArenaMemResize(ArenaT *ar, void *old_ptr, u_int size) { void *new_ptr = NULL; u_int reqsz, sz; @@ -363,6 +364,7 @@ static void *ArenaMemResize(ArenaT *ar, void *old_ptr, u_int size) { Debug("%s(%p, %ld) = %p", __func__, old_ptr, size, new_ptr); return new_ptr; } +#endif #if MEMDEBUG #define Msg(...) if (verbose) Log(__VA_ARGS__) @@ -454,6 +456,7 @@ void MemFree(void *p) { ArenaMemFree(ArenaOf(p), p); } +#if 0 void *MemResize(void *old_ptr, u_int size) { void *new_ptr; ArenaT *ar; @@ -481,6 +484,7 @@ void *MemResize(void *old_ptr, u_int size) { return NULL; } +#endif #if MEMDEBUG void MemCheck(int verbose) { From 94599d39d9b013cd8f2da8a443151884586a789f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 15:24:44 +0100 Subject: [PATCH 08/25] EffectRun is not used -> comment out. --- system/effect.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/system/effect.c b/system/effect.c index 6e643885..8cc48499 100644 --- a/system/effect.c +++ b/system/effect.c @@ -85,6 +85,7 @@ void EffectUnLoad(EffectT *effect) { SendEffectStatus(effect); } +#if 0 void EffectRun(EffectT *effect) { SetFrameCounter(0); @@ -99,3 +100,4 @@ void EffectRun(EffectT *effect) { lastFrameCount = t; } while (!exitLoop); } +#endif From e5afa28ca3f494035f913e28f7946a0ed965d493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 19 Mar 2023 15:25:30 +0100 Subject: [PATCH 09/25] Truly disable multitasking. --- system/Makefile | 5 +++-- system/kernel/exception.c | 2 +- system/kernel/interrupt.c | 18 ++++++++++++++++++ system/kernel/intr-entry.S | 4 ++++ system/kernel/task.c | 18 ------------------ system/loader.c | 2 ++ 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/system/Makefile b/system/Makefile index 65ca6461..13cb34a1 100644 --- a/system/Makefile +++ b/system/Makefile @@ -32,12 +32,13 @@ SOURCES := \ kernel/interrupt.c \ kernel/intr-entry.S \ kernel/memory.c \ - kernel/task.c \ kernel/trap-entry.S \ kernel/trap.c ifeq ($(MULTITASK), 1) -SOURCES += kernel/mutex.c +SOURCES += \ + kernel/mutex.c \ + kernel/task.c endif CFLAGS.amigaos = -Wno-strict-prototypes diff --git a/system/kernel/exception.c b/system/kernel/exception.c index 8657a6f7..ef2d097b 100644 --- a/system/kernel/exception.c +++ b/system/kernel/exception.c @@ -30,7 +30,7 @@ void SetupExceptionVector(BootDataT *bd) { ExcVec[EXC_FMTERR] = FmtErrTrap; /* Intialize TRAP instruction handlers. */ - ExcVec[EXC_TRAP(0)] = YieldHandler; + ExcVec[EXC_TRAP(0)] = MULTITASK ? YieldHandler : TrapInstTrap; for (i = EXC_TRAP(1); i <= EXC_TRAP(15); i++) ExcVec[i] = TrapInstTrap; diff --git a/system/kernel/interrupt.c b/system/kernel/interrupt.c index d6188bf5..26004555 100644 --- a/system/kernel/interrupt.c +++ b/system/kernel/interrupt.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -24,6 +25,23 @@ void SetIntVector(u_int irq, IntHandlerT code, void *data) { iv->data = data; } +#if MULTITASK +#define IntrNest CurrentTask->intrNest +#else +static __code short IntrNest = 0; +#endif + +void IntrEnable(void) { + Assume(IntrNest > 0); + if (--IntrNest == 0) + CpuIntrEnable(); +} + +void IntrDisable(void) { + CpuIntrDisable(); + IntrNest++; +} + /* List of interrupt servers. */ typedef struct IntChain { IntServerT *head; diff --git a/system/kernel/intr-entry.S b/system/kernel/intr-entry.S index 19013efe..8ac91ae0 100644 --- a/system/kernel/intr-entry.S +++ b/system/kernel/intr-entry.S @@ -71,6 +71,7 @@ ENTRY(EnterIntr) END(EnterIntr) ENTRY(LeaveIntr) +#if MULTITASK /* * Check if we need to reschedule a task - usually as a result waking * up a higher priorty task while running interrupt service routine. @@ -91,6 +92,7 @@ ENTRY(LeaveIntr) clr.b (a0) /* clear reschedule flag */ movem.l (sp)+,d0-d1/a0-a1 /* restore registers */ jra _L(YieldHandler)+4 /* force a task switch (skip or.w to sr) */ +#endif .Lnoswitch: movem.l (sp)+,d0-d1/a0-a1 @@ -140,10 +142,12 @@ END(DummyInterruptHandler) rte /* restore SR and PC */ .endm +#if MULTITASK ENTRY(YieldHandler) SAVECTX jsr _L(TaskSwitch) LOADCTX END(YieldHandler) +#endif # vim: ft=gas:ts=8:sw=8:noet: diff --git a/system/kernel/task.c b/system/kernel/task.c index 00387a82..05336e68 100644 --- a/system/kernel/task.c +++ b/system/kernel/task.c @@ -11,17 +11,6 @@ static TaskListT ReadyList = TAILQ_HEAD_INITIALIZER(ReadyList); static TaskListT WaitList = TAILQ_HEAD_INITIALIZER(WaitList); u_char NeedReschedule = 0; -void IntrEnable(void) { - Assume(CurrentTask->intrNest > 0); - if (--CurrentTask->intrNest == 0) - CpuIntrEnable(); -} - -void IntrDisable(void) { - CpuIntrDisable(); - CurrentTask->intrNest++; -} - void TaskInit(TaskT *tsk, const char *name, void *stkptr, u_int stksz) { bzero(tsk, sizeof(TaskT)); strlcpy(tsk->name, name, MAX_TASK_NAME_SIZE); @@ -51,7 +40,6 @@ void TaskInit(TaskT *tsk, const char *name, void *stkptr, u_int stksz) { #define PushWord(v) \ { *--(u_short *)sp = (u_short)(v); } -#if MULTITASK void TaskRun(TaskT *tsk, u_char prio, void (*fn)(void *), void *arg) { void *sp = tsk->stkUpper; @@ -225,9 +213,3 @@ void TaskSwitch(TaskT *curtsk) { Debug("Switching to '%s', prio: %d.", curtsk->name, curtsk->prio); CurrentTask = curtsk; } -#else -void TaskSwitch(TaskT *curtsk) { - (void)curtsk; - HALT(); -} -#endif diff --git a/system/loader.c b/system/loader.c index d932295b..e56c05d6 100644 --- a/system/loader.c +++ b/system/loader.c @@ -69,7 +69,9 @@ void Loader(BootDataT *bd) { /* Lower interrupt priority level to nominal. */ SetIPL(IPL_NONE); +#if MULTITASK TaskInit(CurrentTask, "main", bd->bd_stkbot, bd->bd_stksz); +#endif CallFuncList(&__INIT_LIST__); { From 48c5749256872513fe2260524a1516de0031c3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Thu, 23 Mar 2023 20:25:02 +0100 Subject: [PATCH 10/25] Restore configuration after merge. --- config.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.mk b/config.mk index 71c259df..98fe84ad 100644 --- a/config.mk +++ b/config.mk @@ -21,15 +21,15 @@ AMIGAOS := 1 # 1 => Turn on profiler that reports minimum-average-maximum number of raster # lines measured between calls to ProfilerStart / ProfilerStop. # The measurement is reported every 50 frames (i.e. once a second). -PROFILER := 1 +PROFILER := 0 # 1 => Enable multitasking feature. It can be necessary to run background thread # that loads data from disk while the effects are running. -MULTITASK := 1 +MULTITASK := 0 # 1 => Enable dynamic memory allocation debugging incl. nice diagnostic printout # when memory corruption is detected or we run out of memory. -MEMDEBUG := 1 +MEMDEBUG := 0 # [only when AMIGAOS=1] Amount of chip and fast (or public) memory # (in kilobytes!) passed to our custom memory allocator. From a562cc0fe3f1c92d29bac0b431495a0f147e105b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sat, 25 Mar 2023 19:12:15 +0100 Subject: [PATCH 11/25] Disable unused track types. --- lib/libmisc/sync.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libmisc/sync.c b/lib/libmisc/sync.c index 06c3cc7e..034aea89 100644 --- a/lib/libmisc/sync.c +++ b/lib/libmisc/sync.c @@ -69,6 +69,7 @@ short TrackValueGet(TrackT *track, short frame) { case TRACK_LINEAR: return curr->value + div16(step * track->delta, track->interval); +#if 0 case TRACK_SMOOTH: /* Less than 1% error compared to real smoothstep function. */ { @@ -83,6 +84,7 @@ short TrackValueGet(TrackT *track, short frame) { short k = normfx(t * t); return curr->value + normfx(track->delta * k); } +#endif case TRACK_TRIGGER: { From 79e8a92b7459cc5e55c2f6cfec0c9751c2e9dd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sat, 25 Mar 2023 23:34:37 +0100 Subject: [PATCH 12/25] Shrink sinus table representation. --- lib/libmisc/sintab.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/lib/libmisc/sintab.py b/lib/libmisc/sintab.py index 1bf097f8..19e447e6 100755 --- a/lib/libmisc/sintab.py +++ b/lib/libmisc/sintab.py @@ -7,26 +7,33 @@ with open('sintab.c', 'w') as fh: with redirect_stdout(fh): prec = 4096 + n = prec // 4 print('#include ') print('#include \n') - print('short sintab[%d] = {' % prec) + print('short sintab[%d];\n' % (prec + 1)) - sintab = [int(sin(i * 2 * pi / prec) * prec) for i in range(prec)] - prev = 0 - - for a in sintab: - print('\t%d,' % (a - prev)) - prev = a + sintab = [int(sin(i * 2 * pi / prec) * prec) for i in range(n + 1)] + print('static char _sintab_encoded[%d] = {' % len(sintab)) + prev = 0 + for curr in sintab: + print('\t%d,' % (curr - prev)) + prev = curr print('};') + print('\nvoid InitSinTab(void) {') - print(' short sum = 0, n = %d;' % prec) - print(' short *tab = sintab;') + print(' short sum = 0, n = %d;' % n) + print(' char *encoded = _sintab_encoded;') + print(' short *inc = &sintab[0];') + print(' short *dec = &sintab[%d + 1];' % (n * 2)) print(' Log("[Init] Preparing sinus table\\n");') - print(' while (--n >= 0) {') - print(' sum += *tab;') - print(' *tab++ = sum;') - print(' }') + print(' do {') + print(' sum += *encoded++;') + print(' inc[2048] = -sum;') + print(' *inc++ = sum;') + print(' *--dec = sum;') + print(' dec[2048] = -sum;') + print(' } while (--n != -1);') print('}') print('\nADD2INIT(InitSinTab, 0);') From 995b222a383e00869f1b54157e27cdf2e7c80b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 26 Mar 2023 11:37:27 +0200 Subject: [PATCH 13/25] Replace automatic constructors with direct calls. --- include/linkerset.h | 8 ++++++++ intro/main.c | 4 ++++ system/loader.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/include/linkerset.h b/include/linkerset.h index 72d7aaa5..66a33eef 100644 --- a/include/linkerset.h +++ b/include/linkerset.h @@ -18,12 +18,20 @@ * Constructors are called in ascending order of priority, * while destructors in descending. */ +#if 0 #define ADD2INIT(ctor, pri) \ ADD2LIST(ctor, __INIT_LIST__, N_SETT); \ STABS(_L(__INIT_LIST__), N_SETA, 0, 0, pri + 128) +#else +#define ADD2INIT(ctor, pri) +#endif +#if 0 #define ADD2EXIT(dtor, pri) \ ADD2LIST(dtor, __EXIT_LIST__, N_SETT); \ STABS(_L(__EXIT_LIST__), N_SETA, 0, 0, 128 - pri) +#else +#define ADD2EXIT(dtor, pri) +#endif #endif /* !__LINKERSET_H__ */ diff --git a/intro/main.c b/intro/main.c index 486d5a80..d3c7d796 100644 --- a/intro/main.c +++ b/intro/main.c @@ -147,12 +147,16 @@ static void RunEffects(void) { } extern void InitSamples(void); +extern void InitColorTab(void); +extern void InitSinTab(void); int main(void) { /* NOP that triggers fs-uae debugger to stop and inform GDB that it should * fetch segments locations to relocate symbol information read from file. */ asm volatile("exg %d7,%d7"); + InitColorTab(); + InitSinTab(); InitSamples(); PtInstallCIA(); PtInit(Module, Samples, 0); diff --git a/system/loader.c b/system/loader.c index e56c05d6..5b0034a1 100644 --- a/system/loader.c +++ b/system/loader.c @@ -72,14 +72,18 @@ void Loader(BootDataT *bd) { #if MULTITASK TaskInit(CurrentTask, "main", bd->bd_stkbot, bd->bd_stksz); #endif +#if 0 CallFuncList(&__INIT_LIST__); +#endif { __unused int retval = main(); Log("[Loader] main() returned %d.\n", retval); } +#if 0 CallFuncList(&__EXIT_LIST__); +#endif Log("[Loader] Shutdown complete!\n"); } From 02d515ee1eb52fe7ba36a3677fce9ea9c048180f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 26 Mar 2023 13:19:54 +0200 Subject: [PATCH 14/25] Remove workaround for old module version. --- intro/data/JazzCat-DerKlang.asm | 1 - 1 file changed, 1 deletion(-) diff --git a/intro/data/JazzCat-DerKlang.asm b/intro/data/JazzCat-DerKlang.asm index 144c9abd..91c3aa19 100644 --- a/intro/data/JazzCat-DerKlang.asm +++ b/intro/data/JazzCat-DerKlang.asm @@ -9,7 +9,6 @@ _Samples: _ExtSamples: incbin 'data/JazzCat-DerKlang.raw' - ds.b 280 section '.text', code xdef _AK_Generate From 22bcee7d1a5a4e546295affecf0595d0a35cf3ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 26 Mar 2023 15:50:37 +0200 Subject: [PATCH 15/25] Fix memory size. Log available memory on startup. --- config.mk | 4 ++-- system/amigaos.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config.mk b/config.mk index 98fe84ad..a7b317a8 100644 --- a/config.mk +++ b/config.mk @@ -35,8 +35,8 @@ MEMDEBUG := 0 # (in kilobytes!) passed to our custom memory allocator. # To calculate total memory taken after an executable file # is loaded into memory please use `m68k-amigaos-objdump` tool. -CHIPMEM := 240 -FASTMEM := 240 +CHIPMEM := 235 +FASTMEM := 210 # Pass "VERBOSE=1" at command line to display command being invoked by GNU Make VERBOSE ?= 0 diff --git a/system/amigaos.c b/system/amigaos.c index 385638bf..1ca1ecc9 100644 --- a/system/amigaos.c +++ b/system/amigaos.c @@ -81,6 +81,9 @@ BootDataT *SaveOS(void) { Log("[Startup] Save AmigaOS state.\n"); + Log("[Startup] AvailMem: CHIP=%lu FAST=%lu\n", + AvailMem(MEMF_CHIP), AvailMem(MEMF_FAST)); + /* KS 1.3 and earlier are brain-dead since they don't clear BSS sections :( */ if (ExecVer <= 34) { bzero(_bss, (size_t)_bss_size); From 70a119489e19073b88949be99bd3fd37809a0fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Tue, 4 Apr 2023 08:48:24 +0200 Subject: [PATCH 16/25] Put a compressed intro onto floppy image. --- build/effect.mk | 2 +- config.mk | 4 ++-- intro/Makefile | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/build/effect.mk b/build/effect.mk index 35830abc..7bcb3b57 100644 --- a/build/effect.mk +++ b/build/effect.mk @@ -84,7 +84,7 @@ ifeq ($(AMIGAOS), 0) @echo "[ROM] $(DIR)$< -> $(DIR)$@" $(ROMUTIL) $(ROMSTARTUP) $< $@ else -%.adf: %.exe $(BOOTBLOCK) +%.adf: %.exe.packed $(BOOTBLOCK) @echo "[ADF] $(DIR)$< -> $(DIR)$@" echo $< > startup-sequence xdftool $@ format dos + write $< + makedir s + write startup-sequence s diff --git a/config.mk b/config.mk index a7b317a8..845dcd08 100644 --- a/config.mk +++ b/config.mk @@ -35,8 +35,8 @@ MEMDEBUG := 0 # (in kilobytes!) passed to our custom memory allocator. # To calculate total memory taken after an executable file # is loaded into memory please use `m68k-amigaos-objdump` tool. -CHIPMEM := 235 -FASTMEM := 210 +CHIPMEM := 230 +FASTMEM := 190 # Pass "VERBOSE=1" at command line to display command being invoked by GNU Make VERBOSE ?= 0 diff --git a/intro/Makefile b/intro/Makefile index b7a77732..091b3f52 100644 --- a/intro/Makefile +++ b/intro/Makefile @@ -208,6 +208,10 @@ data/gradient.png: $(GRADIENT) data/texture-inside.png @echo "[GEN] $@" $(PYTHON3) $(GRADIENT) load $(word 2,$^) copy hue 0.4 save $@ +%.exe.packed: %.exe + @echo "[PACK] $(DIR)$< -> $(DIR)$@" + Shrinkler -o -f 0xdff180 $< $@ + audiovq: audiovq.c @echo "[HOSTCC] $(DIR)$< -> $(DIR)$@" cc -O2 -march=native -Wall -o $@ $^ -lm From f565532996c0f0760be6b5948a3300b8b593ab28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Tue, 4 Apr 2023 21:37:22 +0200 Subject: [PATCH 17/25] Require less memory to start. --- config.mk | 4 ++-- intro/main.c | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config.mk b/config.mk index 845dcd08..6ee515f4 100644 --- a/config.mk +++ b/config.mk @@ -35,8 +35,8 @@ MEMDEBUG := 0 # (in kilobytes!) passed to our custom memory allocator. # To calculate total memory taken after an executable file # is loaded into memory please use `m68k-amigaos-objdump` tool. -CHIPMEM := 230 -FASTMEM := 190 +CHIPMEM := 220 +FASTMEM := 180 # Pass "VERBOSE=1" at command line to display command being invoked by GNU Make VERBOSE ?= 0 diff --git a/intro/main.c b/intro/main.c index 6de5bbd4..63249fb7 100644 --- a/intro/main.c +++ b/intro/main.c @@ -53,7 +53,8 @@ static EffectT *AllEffects[] = { }; static void ShowMemStats(void) { - Log("[Memory] CHIP: %d FAST: %d\n", MemAvail(MEMF_CHIP), MemAvail(MEMF_FAST)); + Log("[Memory] CHIP: %d FAST: %d\n", + MemAvail(MEMF_CHIP), MemAvail(MEMF_PUBLIC)); } void PixmapToBitmap(BitmapT *bm, short width, short height, short depth, From 129e5cc04ae940fcc68e68388064adaabb25e255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Fri, 7 Apr 2023 14:04:00 +0200 Subject: [PATCH 18/25] Add decrunching message with shortened build hash. --- intro/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/intro/Makefile b/intro/Makefile index d2d93913..5d2bbe68 100644 --- a/intro/Makefile +++ b/intro/Makefile @@ -219,9 +219,12 @@ data/gol-transitions.png: $(GRADIENT) $(PYTHON3) $(GRADIENT) load data/gol-pal-1.png load data/gol-pal-2.png \ load data/gol-pal-3.png load data/gol-pal-4.png save $@ +REPOHEAD := $(shell git rev-parse --short HEAD) + %.exe.packed: %.exe @echo "[PACK] $(DIR)$< -> $(DIR)$@" - Shrinkler -o -f 0xdff180 $< $@ + Shrinkler -o -f 0xdff180 \ + -t "Electric Lifeforms by Ghostown (build: $(REPOHEAD))" $< $@ audiovq: audiovq.c @echo "[HOSTCC] $(DIR)$< -> $(DIR)$@" From a4fc8ecf54236e55be20f91676f65cb0563b9a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Fri, 7 Apr 2023 20:23:27 +0200 Subject: [PATCH 19/25] We really need smoothstep xD --- lib/libmisc/sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libmisc/sync.c b/lib/libmisc/sync.c index 62f87ba0..fd317520 100644 --- a/lib/libmisc/sync.c +++ b/lib/libmisc/sync.c @@ -82,7 +82,6 @@ short TrackValueGet(TrackT *track, short frame) { case TRACK_LINEAR: return curr->value + div16(step * track->delta, track->interval); -#if 0 case TRACK_SMOOTH: /* Less than 1% error compared to real smoothstep function. */ { @@ -91,6 +90,7 @@ short TrackValueGet(TrackT *track, short frame) { return curr->value + normfx(track->delta * k); } +#if 0 case TRACK_QUADRATIC: { short t = div16(shift12(step), track->interval); From b9015f80ee442cee349063520f509d713f9365db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sat, 15 Apr 2023 20:40:56 +0200 Subject: [PATCH 20/25] Attempt to fix the build process. --- .github/workflows/default.yml | 21 ++++++++++++++++++--- build/go.mk | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index a15f2e89..fac74971 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -14,8 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: nschloe/action-cached-lfs-checkout@v1 - - name: Setup Python 3 + uses: actions/checkout@v3 + with: + lfs: true + - name: Setup Python 3.9 uses: actions/setup-python@v3 with: python-version: 3.9 @@ -32,6 +34,19 @@ jobs: container: cahirwpz/demoscene:latest steps: - name: Checkout code - uses: nschloe/action-cached-lfs-checkout@v1 + uses: actions/checkout@v3 + with: + lfs: true + - name: Setup GoLang + uses: actions/setup-go@v4 + with: + go-version: '>=1.19.0' - name: Build everything run: make + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: intro + path: | + intro/intro.adf + intro/data/JazzCat-DerKlang.mod diff --git a/build/go.mk b/build/go.mk index 2af5b7b6..f5f89c9b 100644 --- a/build/go.mk +++ b/build/go.mk @@ -1,5 +1,5 @@ all: - go build + go build -buildvcs=false windows: GOOS=windows GOARCH=amd64 go build From f24eda2255f88ed9946ee6a2f7a366806f67605b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Mon, 17 Apr 2023 20:54:15 +0200 Subject: [PATCH 21/25] Squashed commit of the following: * [uvmap] Fix race between CPU and Blitter * [dumphunk] Correctly parse GNU local symbols --- intro/uvmap.c | 4 +++- tools/hunk/hunk.go | 2 ++ tools/hunk/hunk_debug.go | 1 - tools/hunk/hunk_ext.go | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/intro/uvmap.c b/intro/uvmap.c index e3813d82..77f63a98 100644 --- a/intro/uvmap.c +++ b/intro/uvmap.c @@ -22,7 +22,7 @@ static u_short *texFstHi, *texFstLo; static u_short *texSndHi, *texSndLo; static BitmapT *screen[2]; static __code u_short active = 0; -static __code short c2p_phase; +static __code volatile short c2p_phase; static __code void **c2p_bpl; static CopListT *cp; static CopInsT *bplptr[DEPTH]; @@ -499,6 +499,8 @@ static void Render(void) { } ProfilerStop(UVMap); + while (c2p_phase < 7) + WaitBlitter(); c2p_phase = 0; c2p_bpl = screen[active]->planes; ChunkyToPlanar(); diff --git a/tools/hunk/hunk.go b/tools/hunk/hunk.go index 1bbe49ab..952728a5 100644 --- a/tools/hunk/hunk.go +++ b/tools/hunk/hunk.go @@ -39,6 +39,7 @@ const ( EXT_DEF = 1 // relocatable definition EXT_ABS = 2 // Absolute definition EXT_RES = 3 // no longer supported + EXT_GNU_LOCAL = 33 // GNU local symbol definition EXT_REF32 = 129 // 32 bit absolute reference to symbol EXT_COMMON = 130 // 32 bit absolute reference to COMMON block EXT_REF16 = 131 // 16 bit PC-relative reference to symbol @@ -103,6 +104,7 @@ func init() { EXT_DEF: "EXT_DEF", EXT_ABS: "EXT_ABS", EXT_RES: "EXT_RES", + EXT_GNU_LOCAL: "EXT_GNU_LOCAL", EXT_REF32: "EXT_REF32", EXT_COMMON: "EXT_COMMON", EXT_REF16: "EXT_REF16", diff --git a/tools/hunk/hunk_debug.go b/tools/hunk/hunk_debug.go index 8eb634d7..b5a26c40 100644 --- a/tools/hunk/hunk_debug.go +++ b/tools/hunk/hunk_debug.go @@ -45,7 +45,6 @@ func readStrTab(r io.Reader, size uint32) []byte { } func readHunkDebugGnu(r io.Reader, name string) HunkDebugGnu { - fmt.Printf("HunkDebugGnu: %s\n", name) var stabTab []Stab var stabstrTab []byte if name == "" { diff --git a/tools/hunk/hunk_ext.go b/tools/hunk/hunk_ext.go index 122dac12..9186ca89 100644 --- a/tools/hunk/hunk_ext.go +++ b/tools/hunk/hunk_ext.go @@ -29,7 +29,7 @@ func readHunkExt(r io.Reader) HunkExt { extType := ExtType(nlongs >> 24) name := readStringOfSize(r, length) switch extType { - case EXT_DEF, EXT_ABS, EXT_RES: + case EXT_DEF, EXT_ABS, EXT_RES, EXT_GNU_LOCAL: value := readLong(r) ext = append(ext, Extern{extType, name, value, nil}) case EXT_REF32, EXT_REF16, EXT_REF8, EXT_DEXT32, EXT_DEXT16, EXT_DEXT8: @@ -38,7 +38,7 @@ func readHunkExt(r io.Reader) HunkExt { size := readLong(r) ext = append(ext, Extern{extType, name, size, readArrayOfLong(r)}) default: - panic("unknown external type") + panic(fmt.Sprintf("unknown external type: %v", extType)) } } sort.Slice(ext, func(i, j int) bool { From 3364ecc36c285623e8e2185845e36abe161dc7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Tue, 18 Apr 2023 22:53:18 +0200 Subject: [PATCH 22/25] Squashed commit of the following: * [growing-tree] Fix the effect on faster Amigas * [uvmap] Fix race between CPU and Blitter * [dumphunk] Correctly parse GNU local symbols --- intro/growing-tree.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/intro/growing-tree.c b/intro/growing-tree.c index 1f2b995f..39059881 100644 --- a/intro/growing-tree.c +++ b/intro/growing-tree.c @@ -463,7 +463,6 @@ void GrowingTree(BranchT *branches, BranchT **lastp) { PROFILE(GrowTree); static void Render(void) { - static short waitFrame = 0; short val; if ((val = TrackValueGet(&TreeVariant, frameCount))) { @@ -471,27 +470,15 @@ static void Render(void) { nrPal = val - 1; BitmapClear(screen); GreetsNextTrack(); - waitFrame = 0; for (i = 0; i < NSPRITES; i++) CopInsSetSprite(sprptr[i], &grass[i]); - } - if (waitFrame > 0) { - if (frameCount - waitFrame < 150) { - TaskWaitVBlank(); - HandleDrawingGreets(); - return; - } - } - - if (lastBranch == branches) { MakeBranch(WIDTH / 2, HEIGHT - fruit_height / 2 - 1); } ProfilerStart(GrowTree); - // Call function twice to make drawing trees - // visually faster + // Call function twice to make drawing trees visually faster GrowingTree(branches, &lastBranch); GrowingTree(branches, &lastBranch); @@ -499,10 +486,6 @@ static void Render(void) { ProfilerStop(GrowTree); - if (lastBranch == branches) { - waitFrame = frameCount; - } - TaskWaitVBlank(); } From 7e2218f6a936b8f6de9cac21c6cd8ef2dce25239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 23 Apr 2023 11:06:44 +0200 Subject: [PATCH 23/25] Save & restore CIA state correctly. --- system/amigaos.c | 137 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 118 insertions(+), 19 deletions(-) diff --git a/system/amigaos.c b/system/amigaos.c index 9273f374..aa03c0e3 100644 --- a/system/amigaos.c +++ b/system/amigaos.c @@ -5,7 +5,10 @@ #include #include #include +#include #include +#define LP2NB LP2UB +#include #include #undef Debug #include @@ -13,6 +16,7 @@ #include #include #include +#include #include #include @@ -32,12 +36,76 @@ static void WaitVBlank(void) { continue; } +typedef struct TimerState { + u_char cr; /* control register */ + u_char tlo, thi; /* timer values */ + u_char llo, lhi; /* latch values */ +} TimerStateT; + +typedef volatile u_char *CiaRegT; + +static inline void nop(void) { + asm volatile("nop;" ::: "memory"); +} + +static inline void bclr(CiaRegT reg, char bit) { + asm volatile("bclr %1,%0" :: "m" (*reg), "dI" (bit) : "memory"); + nop(); +} + +static inline void bset(CiaRegT reg, char bit) { + asm volatile("bset %1,%0" :: "m" (*reg), "dI" (bit) : "memory"); + nop(); +} + +/* Based on jst_cus.asm from https://github.com/jotd666/jst */ +static void GetTimerState(CiaRegT cr asm("a0"), CiaRegT tlo asm("a1"), + CiaRegT thi asm("a2"), TimerStateT *ts asm("a3")) +{ + ts->cr = *cr; + + bclr(cr, CIACRB_START); + + ts->tlo = *tlo; + ts->thi = *thi; + + bclr(cr, CIACRB_RUNMODE); + bclr(cr, CIACRB_PBON); + bset(cr, CIACRB_LOAD); + + ts->llo = *tlo; + ts->lhi = *thi; +} + +static void SetTimerState(CiaRegT cr asm("a0"), CiaRegT tlo asm("a1"), + CiaRegT thi asm("a2"), TimerStateT *ts asm("a3")) +{ + *cr = 0; + nop(); + + *tlo = ts->tlo; + *thi = ts->thi; + nop(); + + bset(cr, CIACRB_LOAD); + *tlo = ts->llo; + *thi = ts->thi; + nop(); + + *cr = ts->cr; +} + /* AmigaOS state that we want to preserve. */ -static struct View *oldView; -static u_short oldDmacon, oldIntena, oldAdkcon; -static u_int oldCacheBits; -static ExcVecT oldExcVec; -static void *oldSysStack; +static __code struct { + struct View *view; + u_short dmacon, intena, intreq, adkcon; + u_int cacheBits; + ExcVecT excVec; + void *sysStack; + TimerStateT timer[4]; + struct Library *resCiaA, *resCiaB; + u_char icrCiaA, icrCiaB; +} old; /* Memory for framework allocator. */ static __aligned(4) __bss_chip char ChipMem[CHIPMEM_KB * 1024]; @@ -94,6 +162,9 @@ BootDataT *SaveOS(void) { *(struct GfxBase **)&GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33); + old.resCiaA = OpenResource(CIAANAME); + old.resCiaB = OpenResource(CIABNAME); + /* Allocate blitter. */ WaitBlit(); OwnBlitter(); @@ -103,18 +174,19 @@ BootDataT *SaveOS(void) { /* Disable CPU caches. */ if (ExecVer >= 36) - oldCacheBits = CacheControl(0, -1); + old.cacheBits = CacheControl(0, -1); /* Intercept the view of AmigaOS. */ - oldView = GfxBase->ActiView; + old.view = GfxBase->ActiView; LoadView(NULL); WaitTOF(); WaitTOF(); /* DMA & interrupts take-over. */ - oldAdkcon = custom->adkconr; - oldDmacon = custom->dmaconr; - oldIntena = custom->intenar; + old.adkcon = custom->adkconr; + old.dmacon = custom->dmaconr; + old.intena = custom->intenar; + old.intreq = custom->intreqr; /* Prohibit dma & interrupts. */ custom->adkcon = (UWORD)~ADKF_SETCLR; @@ -126,6 +198,22 @@ BootDataT *SaveOS(void) { custom->intreq = (UWORD)~INTF_SETCLR; custom->intreq = (UWORD)~INTF_SETCLR; + /* CIA-A & CIA-B: Mask all interrupts, get old masks. */ + old.icrCiaA = AbleICR(old.resCiaA, CIAICRF_ALL); + old.icrCiaB = AbleICR(old.resCiaB, CIAICRF_ALL); + + /* CIA-A & CIA-B: Save state of all timers. */ + GetTimerState(&ciaa->ciacra, &ciaa->ciatalo, &ciaa->ciatahi, &old.timer[0]); + GetTimerState(&ciaa->ciacrb, &ciaa->ciatblo, &ciaa->ciatbhi, &old.timer[1]); + GetTimerState(&ciab->ciacra, &ciab->ciatalo, &ciab->ciatahi, &old.timer[2]); + GetTimerState(&ciab->ciacrb, &ciab->ciatblo, &ciab->ciatbhi, &old.timer[3]); + + /* CIA-A & CIA-B: Stop timers and return to default settings. */ + ciaa->ciacra = 0; + ciaa->ciacrb = 0; + ciab->ciacra = 0; + ciab->ciacrb = 0; + { struct Task *self = FindTask(NULL); bd->bd_stkbot = self->tc_SPLower; @@ -134,7 +222,7 @@ BootDataT *SaveOS(void) { /* Enter supervisor mode and save exception vector * since the framework takes full control over it. */ - oldSysStack = SuperState(); + old.sysStack = SuperState(); /* Detect CPU model and fetch VBR on 68010 and later. */ { @@ -160,7 +248,7 @@ BootDataT *SaveOS(void) { bd->bd_cpumodel = cpu; } - memcpy(oldExcVec, bd->bd_vbr, sizeof(oldExcVec)); + memcpy(old.excVec, bd->bd_vbr, sizeof(old.excVec)); return &BootData; } @@ -180,27 +268,38 @@ void RestoreOS(void) { custom->intreq = (UWORD)~INTF_SETCLR; /* Restore exception vector and leave supervisor mode. */ - memcpy(bd->bd_vbr, oldExcVec, sizeof(oldExcVec)); + memcpy(bd->bd_vbr, old.excVec, sizeof(old.excVec)); /* TODO: This function is broken in V33/34 Kickstart, hangs on 68010. */ - UserState(oldSysStack); + UserState(old.sysStack); + + /* CIA-A & CIA-B: Restore state of all timers. */ + SetTimerState(&ciaa->ciacra, &ciaa->ciatalo, &ciaa->ciatahi, &old.timer[0]); + SetTimerState(&ciaa->ciacrb, &ciaa->ciatblo, &ciaa->ciatbhi, &old.timer[1]); + SetTimerState(&ciab->ciacra, &ciab->ciatalo, &ciab->ciatahi, &old.timer[2]); + SetTimerState(&ciab->ciacrb, &ciab->ciatblo, &ciab->ciatbhi, &old.timer[3]); + + /* CIA-A & CIA-B: Restore old interrupts masks. */ + AbleICR(old.resCiaA, old.icrCiaA | CIAICRF_SETCLR); + AbleICR(old.resCiaB, old.icrCiaB | CIAICRF_SETCLR); /* Restore AmigaOS state of dma & interrupts. */ - custom->dmacon = oldDmacon | DMAF_SETCLR; - custom->intena = oldIntena | INTF_SETCLR; - custom->adkcon = oldAdkcon | ADKF_SETCLR; + custom->intreq = old.intreq | INTF_SETCLR; + custom->intena = old.intena | INTF_SETCLR; + custom->dmacon = old.dmacon | DMAF_SETCLR; + custom->adkcon = old.adkcon | ADKF_SETCLR; /* Restore old copper list... */ custom->cop1lc = (ULONG)GfxBase->copinit; WaitTOF(); /* ... and original view. */ - LoadView(oldView); + LoadView(old.view); WaitTOF(); WaitTOF(); /* Enable CPU caches. */ if (ExecVer >= 36) - CacheControl(oldCacheBits, -1); + CacheControl(old.cacheBits, -1); /* Restore multitasking. */ Permit(); From 6e02f58286dc070ddda81ac9d77ec8eda60051d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 23 Apr 2023 11:37:01 +0200 Subject: [PATCH 24/25] Limit memory usage by 20kB of CHIP and FAST. Runs on A600/A500+. --- config.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.mk b/config.mk index 6ee515f4..209317a4 100644 --- a/config.mk +++ b/config.mk @@ -35,8 +35,8 @@ MEMDEBUG := 0 # (in kilobytes!) passed to our custom memory allocator. # To calculate total memory taken after an executable file # is loaded into memory please use `m68k-amigaos-objdump` tool. -CHIPMEM := 220 -FASTMEM := 180 +CHIPMEM := 200 +FASTMEM := 160 # Pass "VERBOSE=1" at command line to display command being invoked by GNU Make VERBOSE ?= 0 From 9278c8373b4733b06e26ca62910b9b0b068414b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krystian=20Bac=C5=82awski?= Date: Sun, 26 Nov 2023 11:42:34 +0100 Subject: [PATCH 25/25] Do not compile effects in release build. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3d629dde..90302be1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ TOPDIR = $(realpath .) -SUBDIRS = tools lib system intro effects +SUBDIRS = tools lib system intro EXTRA-FILES = tags cscope.out CLEAN-FILES = bootloader.bin a500rom.bin addchip.bootblock.bin vbrmove