From a260d0a806467866ed94a39ec75ab67de6fb0305 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Fri, 12 Nov 2021 02:45:53 +0100 Subject: [PATCH] CBM BASIC loader should use the actual address of main (fixes #111) --- docs/api/commodore-programming-guide.md | 5 ++++ docs/lang/preprocessor.md | 2 ++ include/cbm/basic_loader.mfk | 31 +++++++++++++++++++++++++ include/loader_0401.mfk | 20 +--------------- include/loader_0801.mfk | 20 +--------------- include/loader_0801_16bit.mfk | 3 ++- include/loader_1001.mfk | 20 +--------------- include/loader_1201.mfk | 20 +--------------- include/loader_1c01.mfk | 20 +--------------- 9 files changed, 45 insertions(+), 96 deletions(-) create mode 100644 include/cbm/basic_loader.mfk diff --git a/docs/api/commodore-programming-guide.md b/docs/api/commodore-programming-guide.md index e597c08c..3aee9a49 100644 --- a/docs/api/commodore-programming-guide.md +++ b/docs/api/commodore-programming-guide.md @@ -2,6 +2,11 @@ ### A note about Commodore 64 +#### Unusual main function location + +If you're creating a prg file and your `main` function may be located at address $2710 hex (10000 decimal) or higher, +you might need to define the `DISPLACED_MAIN=1` preprocessor feature. + #### Multifile programs A multifile program is a program stored on a disk that consists of the main program file that is executed first diff --git a/docs/lang/preprocessor.md b/docs/lang/preprocessor.md index c1d29948..482588bf 100644 --- a/docs/lang/preprocessor.md +++ b/docs/lang/preprocessor.md @@ -103,6 +103,8 @@ Some libraries may require that some of these be defined. * `KEYBOARD` – 1 if the target has a keyboard, 0 otherwise +* `DISPLACED_MAIN` – set this to 1 if the `main` function is in a very unusual location for the target + * `USE_MOUSE_MBM` – set this to 1 if you want to enable middle button support for the mouse. * `JOYSTICKS` – the maximum number of joysticks using standard hardware configurations, may be 0 diff --git a/include/cbm/basic_loader.mfk b/include/cbm/basic_loader.mfk new file mode 100644 index 00000000..80ad12a1 --- /dev/null +++ b/include/cbm/basic_loader.mfk @@ -0,0 +1,31 @@ +#template $ADDR$ + +#if not(CBM) +#warn cbm/basic_loader module should be only used on Commodore targets +#endif + +const array _basic_loader @ $ADDR$ = [ +#if DISPLACED_MAIN + @word_le [ + $ADDR$ + 0xB + ], +#else + @word_le [ + $ADDR$ + if(main.addr >= 10000, 1/0, 0xA) // use -D DISPLACED_MAIN=1 if you get an error here + ], +#endif + 10, + 0, + $9e, +#if DISPLACED_MAIN + $30 + (main.addr/10000)%%10, +#endif + $30 + (main.addr/1000)%%10, + $30 + (main.addr/100)%%10, + $30 + (main.addr/10)%%10, + $30 + (main.addr/1)%%10, + 0, + 0, + 0 + ] + diff --git a/include/loader_0401.mfk b/include/loader_0401.mfk index 40f4a6b2..b95b0f1a 100644 --- a/include/loader_0401.mfk +++ b/include/loader_0401.mfk @@ -1,19 +1 @@ -#if not(CBM) -#warn loader_0401 module should be only used on Commodore targets -#endif - -const array _basic_loader @$401 = [ - $0b, - 4, - 10, - 0, - $9e, - $31, - $30, - $33, - $37, - 0, - 0, - 0 - ] - +import cbm/basic_loader<$401> diff --git a/include/loader_0801.mfk b/include/loader_0801.mfk index 82ddd414..eac63fed 100644 --- a/include/loader_0801.mfk +++ b/include/loader_0801.mfk @@ -1,19 +1 @@ -#if not(CBM) -#warn loader_0801 module should be only used on Commodore targets -#endif - -const array _basic_loader @$801 = [ - $0b, - $08, - 10, - 0, - $9e, - $32, - $30, - $36, - $31, - 0, - 0, - 0 - ] - +import cbm/basic_loader<$801> diff --git a/include/loader_0801_16bit.mfk b/include/loader_0801_16bit.mfk index 3ea6df22..d531c7b0 100644 --- a/include/loader_0801_16bit.mfk +++ b/include/loader_0801_16bit.mfk @@ -22,4 +22,5 @@ asm void __init_16bit() @$80D { clc xce sep #$30 -} \ No newline at end of file + jmp main +} diff --git a/include/loader_1001.mfk b/include/loader_1001.mfk index e15ed4fc..74b003c3 100644 --- a/include/loader_1001.mfk +++ b/include/loader_1001.mfk @@ -1,19 +1 @@ -#if not(CBM) -#warn loader_1001 module should be only used on Commodore targets -#endif - -const array _basic_loader @$1001 = [ - $0b, - $10, - 10, - 0, - $9e, - $34, - $31, - $30, - $39, - 0, - 0, - 0 - ] - +import cbm/basic_loader<$1001> diff --git a/include/loader_1201.mfk b/include/loader_1201.mfk index ae668bff..7cf1083e 100644 --- a/include/loader_1201.mfk +++ b/include/loader_1201.mfk @@ -1,19 +1 @@ -#if not(CBM) -#warn loader_1201 module should be only used on Commodore targets -#endif - -const array _basic_loader @$1201 = [ - $0b, - $12, - 10, - 0, - $9e, - $34, - $36, - $32, - $31, - 0, - 0, - 0 - ] - +import cbm/basic_loader<$1201> diff --git a/include/loader_1c01.mfk b/include/loader_1c01.mfk index 7f6c9c77..fa01b773 100644 --- a/include/loader_1c01.mfk +++ b/include/loader_1c01.mfk @@ -1,19 +1 @@ -#if not(CBM) -#warn loader_1c01 module should be only used on Commodore targets -#endif - -const array _basic_loader @$1C01 = [ - $0b, - $1C, - 10, - 0, - $9e, - $37, - $31, - $38, - $31, - 0, - 0, - 0 - ] - +import cbm/basic_loader<$1c01>