]> git.sur5r.net Git - cc65/commitdiff
Added Apple II linker configs for programs including a hires screen.
authorOliver Schmidt <ol.sc@web.de>
Mon, 29 Jan 2018 16:46:36 +0000 (17:46 +0100)
committerOliver Schmidt <ol.sc@web.de>
Mon, 29 Jan 2018 16:46:36 +0000 (17:46 +0100)
The Apple II hires screen buffer is located at $2000 (and can't be moved). The usual way to get along with this is to load the cc65 program above the hires screen buffer at $4000. However, that means that it becomes difficult to make good use of the memory below the hires screen buffer. The simplest approach is to add that memory to the heap. But there are programs containing just lots of code and not much data. One could think of moving the code to the area below the hires screen after loading (like it is done with the code for the language card). But if the program is really large (and already contains code to be moved to the language card) it won't just fit into memory in the first place.

The alternative is to load the program at the usual $803 and have it "cover" the hires screen buffer. Of course the part of the program that actually "covers" the hires screen buffer mustn't contain anything necessary for the program. The downside of this approach is that the program file on disk contains 8kB that can't be used by the program. But instead of just containing zeros the program can as well contain a hires screen picture that can be displayed right after startup.

Now the user can have code loaded below the hires screen buffer by setting the code-name to LOWCODE. However, he needs to explicitly do so. Otherwise the memory below the hires screen is totally wasted.

Trivia: Allowing to do this hires screen buffer "covering" was the very reason to change tgi_init() to not clear the hires screen anymore.

cfg/apple2-hgr.cfg [new file with mode: 0644]
cfg/apple2enh-hgr.cfg [new file with mode: 0644]
testcode/lib/apple2/hgrtest.c [new file with mode: 0644]
testcode/lib/apple2/werner.pic [new file with mode: 0644]
testcode/lib/apple2/werner.s [new file with mode: 0644]

diff --git a/cfg/apple2-hgr.cfg b/cfg/apple2-hgr.cfg
new file mode 100644 (file)
index 0000000..540578b
--- /dev/null
@@ -0,0 +1,52 @@
+# Configuration for programs including a hires screen (with 6KB LOWCODE)
+
+FEATURES {
+    STARTADDRESS: default = $0803;
+}
+SYMBOLS {
+    __EXEHDR__:     type = import;
+    __STACKSIZE__:  type = weak,   value = $0800; # 2k stack
+    __HIMEM__:      type = weak,   value = $9600; # Presumed RAM end
+    __LCADDR__:     type = weak,   value = $D400; # Behind quit code
+    __LCSIZE__:     type = weak,   value = $0C00; # Rest of bank two
+    __MAIN_START__: type = export, value = %S;
+    __MAIN_LAST__:  type = export, value = __HIGH_LAST__;
+}
+MEMORY {
+    ZP:     file = "", define = yes, start = $0080,        size = $001A;
+    HEADER: file = %O,               start = %S - 4,       size = $0004;
+    LOW:    file = %O, fill   = yes, start = %S,           size = $2000 - %S;
+    HGR:    file = %O, fill   = yes, start = $2000,        size = $2000;
+    HIGH:   file = %O, define = yes, start = $4000,        size = __HIMEM__ - $4000;
+    BSS:    file = "",               start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__;
+    LC:     file = "", define = yes, start = __LCADDR__,   size = __LCSIZE__;
+}
+SEGMENTS {
+    ZEROPAGE: load = ZP,             type = zp;
+    EXEHDR:   load = HEADER,         type = ro;
+    STARTUP:  load = LOW,            type = ro;
+    LOWCODE:  load = LOW,            type = ro,  optional = yes;
+    HGR:      load = HGR,            type = rw,  optional = yes;
+    CODE:     load = HIGH,           type = ro;
+    RODATA:   load = HIGH,           type = ro;
+    DATA:     load = HIGH,           type = rw;
+    INIT:     load = HIGH,           type = rw;
+    ONCE:     load = HIGH,           type = ro,  define   = yes;
+    LC:       load = HIGH, run = LC, type = ro,  optional = yes;
+    BSS:      load = BSS,            type = bss, define   = yes;
+}
+FEATURES {
+    CONDES: type    = constructor,
+            label   = __CONSTRUCTOR_TABLE__,
+            count   = __CONSTRUCTOR_COUNT__,
+            segment = ONCE;
+    CONDES: type    = destructor,
+            label   = __DESTRUCTOR_TABLE__,
+            count   = __DESTRUCTOR_COUNT__,
+            segment = RODATA;
+    CONDES: type    = interruptor,
+            label   = __INTERRUPTOR_TABLE__,
+            count   = __INTERRUPTOR_COUNT__,
+            segment = RODATA,
+            import  = __CALLIRQ__;
+}
diff --git a/cfg/apple2enh-hgr.cfg b/cfg/apple2enh-hgr.cfg
new file mode 100644 (file)
index 0000000..540578b
--- /dev/null
@@ -0,0 +1,52 @@
+# Configuration for programs including a hires screen (with 6KB LOWCODE)
+
+FEATURES {
+    STARTADDRESS: default = $0803;
+}
+SYMBOLS {
+    __EXEHDR__:     type = import;
+    __STACKSIZE__:  type = weak,   value = $0800; # 2k stack
+    __HIMEM__:      type = weak,   value = $9600; # Presumed RAM end
+    __LCADDR__:     type = weak,   value = $D400; # Behind quit code
+    __LCSIZE__:     type = weak,   value = $0C00; # Rest of bank two
+    __MAIN_START__: type = export, value = %S;
+    __MAIN_LAST__:  type = export, value = __HIGH_LAST__;
+}
+MEMORY {
+    ZP:     file = "", define = yes, start = $0080,        size = $001A;
+    HEADER: file = %O,               start = %S - 4,       size = $0004;
+    LOW:    file = %O, fill   = yes, start = %S,           size = $2000 - %S;
+    HGR:    file = %O, fill   = yes, start = $2000,        size = $2000;
+    HIGH:   file = %O, define = yes, start = $4000,        size = __HIMEM__ - $4000;
+    BSS:    file = "",               start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__;
+    LC:     file = "", define = yes, start = __LCADDR__,   size = __LCSIZE__;
+}
+SEGMENTS {
+    ZEROPAGE: load = ZP,             type = zp;
+    EXEHDR:   load = HEADER,         type = ro;
+    STARTUP:  load = LOW,            type = ro;
+    LOWCODE:  load = LOW,            type = ro,  optional = yes;
+    HGR:      load = HGR,            type = rw,  optional = yes;
+    CODE:     load = HIGH,           type = ro;
+    RODATA:   load = HIGH,           type = ro;
+    DATA:     load = HIGH,           type = rw;
+    INIT:     load = HIGH,           type = rw;
+    ONCE:     load = HIGH,           type = ro,  define   = yes;
+    LC:       load = HIGH, run = LC, type = ro,  optional = yes;
+    BSS:      load = BSS,            type = bss, define   = yes;
+}
+FEATURES {
+    CONDES: type    = constructor,
+            label   = __CONSTRUCTOR_TABLE__,
+            count   = __CONSTRUCTOR_COUNT__,
+            segment = ONCE;
+    CONDES: type    = destructor,
+            label   = __DESTRUCTOR_TABLE__,
+            count   = __DESTRUCTOR_COUNT__,
+            segment = RODATA;
+    CONDES: type    = interruptor,
+            label   = __INTERRUPTOR_TABLE__,
+            count   = __INTERRUPTOR_COUNT__,
+            segment = RODATA,
+            import  = __CALLIRQ__;
+}
diff --git a/testcode/lib/apple2/hgrtest.c b/testcode/lib/apple2/hgrtest.c
new file mode 100644 (file)
index 0000000..7323cbb
--- /dev/null
@@ -0,0 +1,26 @@
+// cl65 -t apple2 -C apple2-hgr.cfg hgrtest.c werner.s
+
+#include <tgi.h>
+#include <conio.h>
+
+#pragma code-name (push, "LOWCODE")
+
+void say (const char* text)
+{
+    tgi_setcolor (TGI_COLOR_BLACK);
+    tgi_outtextxy (41, 33, text);
+}
+
+#pragma code-name (pop)
+
+void main (void)
+{
+    tgi_install (a2_hi_tgi);
+    tgi_init ();
+    cgetc ();
+
+    say ("Hi Dude !");
+    cgetc ();
+
+    tgi_uninstall ();
+}
diff --git a/testcode/lib/apple2/werner.pic b/testcode/lib/apple2/werner.pic
new file mode 100644 (file)
index 0000000..2405e24
Binary files /dev/null and b/testcode/lib/apple2/werner.pic differ
diff --git a/testcode/lib/apple2/werner.s b/testcode/lib/apple2/werner.s
new file mode 100644 (file)
index 0000000..6456ade
--- /dev/null
@@ -0,0 +1,2 @@
+.segment "HGR"
+.incbin "werner.pic"