From 09e50d433da2354b91fab27b4eb1ddaee69c87dc Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Sun, 9 Nov 2014 06:32:11 -0500
Subject: [PATCH 1/8] * Changed the way that Atmos programs are started.

  - Put a BASIC-language stub at the beginning.
  - Removed the Autostart flag.

  Those changes make it easy to give command-line arguments to a program.

* Made the Atmos configure file accept a special symbol definition on ld65's command line.  We can use "__RAMEND__" to increase the amount of RAM that's available to programs.
---
 cfg/atmos.cfg          | 20 +++++++++++-----
 doc/atmos.sgml         | 52 +++++++++++++++++++++++++++++-------------
 libsrc/atmos/bashdr.s  | 24 +++++++++++++++++++
 libsrc/atmos/crt0.s    | 37 ++++++++++--------------------
 libsrc/atmos/tapehdr.s | 30 ++++++++++++++++++++++++
 5 files changed, 116 insertions(+), 47 deletions(-)
 create mode 100644 libsrc/atmos/bashdr.s
 create mode 100644 libsrc/atmos/tapehdr.s

diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg
index 137c0e9a9..062711b96 100644
--- a/cfg/atmos.cfg
+++ b/cfg/atmos.cfg
@@ -1,22 +1,30 @@
 SYMBOLS {
-    __STACKSIZE__: type = weak, value = $0800; # 2k stack
+    __TAPEHDR__:   type = import;
+    __BASHDR__:    type = import;
+    __PROGFLAG__:  type = weak, value = $00; # $00=BASIC, $80=machine code
+    __AUTORUN__:   type = weak, value = $00; # $C7=run, $00=only load
+    __STACKSIZE__: type = weak, value = $0800; # 2K stack
+    __RAMEND__:    type = weak, value = $9800; # graphics RAM not grabbed
+#   __RAMEND__:    type = weak, value = $B400; # graphics RAM grabbed
 }
 MEMORY {
     ZP:      file = "", define = yes, start = $00E2, size = $001A;
-    TAPEHDR: file = %O, type   = ro,  start = $0000, size = $0011;
-    RAM:     file = %O, define = yes, start = $0500, size = $9300 - __STACKSIZE__;
+    TAPEHDR: file = %O, type   = ro,  start = $0000, size = $001F;
+    BASHEAD: file = %O, define = yes, start = $0501, size = $000D;
+    RAM:     file = %O, define = yes, start = __BASHEAD_LAST__, size = __RAMEND__ - __RAM_START__ - __STACKSIZE__;
 }
 SEGMENTS {
+    ZEROPAGE: load = ZP,      type = zp;
     TAPEHDR:  load = TAPEHDR, type = ro;
+    BASHDR:   load = BASHEAD, type = ro,  define = yes, optional = yes;
     STARTUP:  load = RAM,     type = ro;
     LOWCODE:  load = RAM,     type = ro,                optional = yes;
-    INIT:     load = RAM,     type = ro,  define = yes, optional = yes;
     CODE:     load = RAM,     type = ro;
     RODATA:   load = RAM,     type = ro;
+    INIT:     load = RAM,     type = ro,  define = yes, optional = yes;
     DATA:     load = RAM,     type = rw;
-    ZPSAVE:   load = RAM,     type = bss, define = yes;
+    ZPSAVE:   load = RAM,     type = rw,  define = yes;
     BSS:      load = RAM,     type = bss, define = yes;
-    ZEROPAGE: load = ZP,      type = zp;
 }
 FEATURES {
     CONDES: type    = constructor,
diff --git a/doc/atmos.sgml b/doc/atmos.sgml
index 805fc7a03..ab63c667b 100644
--- a/doc/atmos.sgml
+++ b/doc/atmos.sgml
@@ -7,7 +7,7 @@
 <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline>
 <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline>
 <url url="mailto:greg.king5@verizon.net" name="Greg King">
-<date>2014-03-27
+<date>2014-09-23
 
 <abstract>
 An overview over the Atmos runtime system as it is implemented for the cc65 C
@@ -32,27 +32,37 @@ more than one platform. Please see the function reference for more
 information.
 
 
+
 <sect>Binary format<p>
 
 The standard binary output format generated by the linker for the Atmos target
-is a machine language program with a 17 byte tape header including a cc65 tag.
-The standard load and autostart address is &dollar;500.
+is a machine language program with a one-line BASIC stub that jumps to the
+machine-language part through <tt/CALL/.  It has a 24-byte tape header.
+It means that a file can be loaded as a BASIC program, and started with RUN.
+The standard load address is &dollar;501.
+
 
 
 <sect>Memory layout<p>
 
-In the standard setup, cc65 generated programs use the memory from
-&dollar;500 to &dollar;9800, so nearly 37K of memory (including the stack) is
+In the standard setup, cc65-generated programs use the memory from
+&dollar;0501 to &dollar;9800; so, nearly 37K of memory (including the stack) is
 available. ROM calls are possible without further precautions.
 
+If your program needs more memory, and it won't use TGI graphics, then you can
+use the ld65 command-line option, <tt/-D __RAMEND__=$B400/, when building the
+program, to "grab" the graphics screen RAM.  Then, nearly 44K of memory is
+available.
+
 Special locations:
 
 <descrip>
   <tag/Stack/
-  The C runtime stack is located at &dollar;97FF and growing downwards.
+  The C runtime stack is located at &dollar;97FF (or &dollar;B3FF), and grows
+  downwards.
 
   <tag/Heap/
-  The C heap is located at the end of the program and grows towards the C
+  The C heap is located at the end of the program, and grows towards the C
   runtime stack.
 
 </descrip><p>
@@ -117,7 +127,8 @@ The names in the parentheses denote the symbols to be used for static linking of
 
 <sect1>Graphics drivers<p>
 
-The default drivers, <tt/tgi_stddrv (tgi_static_stddrv)/, point to <tt/atmos-240-200-2.tgi (atmos_240_200_2_tgi)/.
+The default drivers, <tt/tgi_stddrv (tgi_static_stddrv)/,
+point to <tt/atmos-240-200-2.tgi (atmos_240_200_2_tgi)/.
 
 <descrip>
 
@@ -175,13 +186,14 @@ No mouse drivers are currently available for the Atmos.
 
 <sect1>Disk I/O<p>
 
-The existing library for the Atmos doesn't implement C file
-I/O. There are hacks for the <tt/read()/ and <tt/write()/ routines in
-place, which will make functions work that read from and write to <tt/stdout/
-(like <tt/printf()/). However, those functions have some shortcomings which
-won't be fixed, because they're going to be replaced anyway.
+The existing library for the Atmos doesn't implement C file I/O. There are
+hacks for the <tt/read()/ and <tt/write()/ routines in place, which will make
+functions work that read from <tt/stdin/ and write to <tt/stdout/ and
+<tt/stderr/ (such as <tt/printf()/). However, those functions have some
+shortcomings which won't be fixed, because they're going to be replaced
+anyway.
 
-To be more concrete, the limitation means that you cannot use any of the
+To be more concrete, that limitation means that you cannot use any of the
 following functions (and a few others):
 
 <itemize>
@@ -202,7 +214,13 @@ following functions (and a few others):
 
 <sect1>Function keys<p>
 
-These are defined to be FUNCT + number key.
+They are defined to be FUNCT + a number key.
+
+
+<sect1>Capitals Lock<p>
+
+The "CAPS Lock" mode is turned off while the program is running.  The previous
+mode (usually turned on) is restored when the program stops.
 
 
 <sect1>Passing arguments to the program<p>
@@ -211,10 +229,12 @@ Command-line arguments can be passed to <tt/main()/. Since that is not
 supported directly by BASIC, the following syntax was chosen:
 
 <tscreen><verb>
-    CALL#500:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5
+    RUN:REM arg1 " ARG2 IS QUOTED" ARG3 "" ARG5
 </verb></tscreen>
 
 <enum>
+<item>You must turn <tt/CAPS/ lock off (tap CTRL-T) when you want to type
+      lower-case arguments.
 <item>Arguments are separated by spaces.
 <item>Arguments may be quoted.
 <item>Leading and trailing spaces around an argument are ignored. Spaces within
diff --git a/libsrc/atmos/bashdr.s b/libsrc/atmos/bashdr.s
new file mode 100644
index 000000000..e09bc9fec
--- /dev/null
+++ b/libsrc/atmos/bashdr.s
@@ -0,0 +1,24 @@
+;
+; 2010-11-14, Ullrich von Bassewitz
+; 2014-09-06, Greg King
+;
+; This module supplies a small BASIC stub program that uses CALL
+; to jump to the machine-language code that follows it.
+;
+
+        ; The following symbol is used by the linker config. file
+        ; to force this module to be included into the output file.
+        .export __BASHDR__:abs = 1
+
+
+.segment        "BASHDR"
+
+        .addr   Next
+        .word   .version        ; Line number
+        .byte   $BF,'#'         ; CALL token, mark number as hexadecimal
+        .byte   <(Start >> 8      ) + '0' + (Start >> 8       > $09) * $07
+        .byte   <(Start >> 4 & $0F) + '0' + (Start >> 4 & $0F > $09) * $07
+        .byte   <(Start      & $0F) + '0' + (Start      & $0F > $09) * $07
+        .byte   $00             ; End of BASIC line
+Next:   .addr   $0000           ; BASIC program end marker
+Start:
diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s
index 1d919f348..63961bfe8 100644
--- a/libsrc/atmos/crt0.s
+++ b/libsrc/atmos/crt0.s
@@ -2,39 +2,18 @@
 ; Startup code for cc65 (Oric version)
 ;
 ; By Debrune J�r�me <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org>
-; 2014-08-22, Greg King
+; 2014-11-09, Greg King
 ;
 
         .export         _exit
         .export         __STARTUP__ : absolute = 1      ; Mark as startup
         .import         initlib, donelib
         .import         callmain, zerobss
-        .import         __RAM_START__, __RAM_SIZE__
-        .import         __ZPSAVE_LOAD__, __STACKSIZE__
+        .import         __RAM_START__, __RAM_SIZE__, __STACKSIZE__
 
         .include        "zeropage.inc"
         .include        "atmos.inc"
 
-; ------------------------------------------------------------------------
-; Oric tape header
-
-.segment        "TAPEHDR"
-
-        .byte   $16, $16, $16   ; Sync bytes
-        .byte   $24             ; End of header marker
-
-        .byte   $00                             ; $2B0
-        .byte   $00                             ; $2AF
-        .byte   $80                             ; $2AE Machine code flag
-        .byte   $C7                             ; $2AD Autoload flag
-        .dbyt   __ZPSAVE_LOAD__ - 1             ; $2AB
-        .dbyt   __RAM_START__                   ; $2A9
-        .byte   $00                             ; $2A8
-        .byte   ((.VERSION >> 8) & $0F) + '0'
-        .byte   ((.VERSION >> 4) & $0F) + '0'
-        .byte   (.VERSION & $0F) + '0'
-        .byte   $00                             ; Zero terminated compiler version
-
 ; ------------------------------------------------------------------------
 ; Place the startup code in a special segment.
 
@@ -79,7 +58,7 @@ L1:     lda     sp,x
 
 ; Call the module destructors. This is also the exit() entry.
 
-_exit:  jsr     donelib         ; Run module destructors
+_exit:  jsr     donelib
 
 ; Restore the system stuff.
 
@@ -104,7 +83,15 @@ L2:     lda     zpsave,x
 
 .segment        "ZPSAVE"
 
-zpsave: .res    zpspace
+zpsave:
+
+; This padding is needed by a bug in the ROM.
+; (The CLOAD command starts BASIC's variables table on top of the last byte
+; that was loaded [instead of at the next address].)
+
+        .byte   0
+
+        .res    zpspace - 1
 
 ; ------------------------------------------------------------------------
 
diff --git a/libsrc/atmos/tapehdr.s b/libsrc/atmos/tapehdr.s
new file mode 100644
index 000000000..b8562eb02
--- /dev/null
+++ b/libsrc/atmos/tapehdr.s
@@ -0,0 +1,30 @@
+;
+; Based on code by Debrune J�r�me <jede@oric.org>
+; 2013-08-15, Greg King
+;
+
+        ; The following symbol is used by the linker config. file
+        ; to force this module to be included into the output file.
+        .export __TAPEHDR__:abs = 1
+
+        .import __BASHDR_LOAD__, __ZPSAVE_LOAD__, __AUTORUN__, __PROGFLAG__
+
+
+; ------------------------------------------------------------------------
+; Oric cassette-tape header
+
+.segment        "TAPEHDR"
+
+        .byte   $16, $16, $16   ; Sync bytes
+        .byte   $24             ; Beginning-of-header marker
+
+        .byte   $00             ; $2B0
+        .byte   $00             ; $2AF
+        .byte   <__PROGFLAG__   ; $2AE Language flag ($00=BASIC, $80=machine code)
+        .byte   <__AUTORUN__    ; $2AD Auto-run flag ($C7=run, $00=only load)
+        .dbyt   __ZPSAVE_LOAD__ ; $2AB Address of end of file
+        .dbyt   __BASHDR_LOAD__ ; $2A9 Address of start of file
+        .byte   $00             ; $2A8
+
+        ; File name (a maximum of 17 characters), zero-terminated
+        .asciiz .sprintf("%u", .time)

From 8d5bb552818ec7b52426be223e1c1ab837021147 Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Wed, 3 Dec 2014 12:02:48 -0500
Subject: [PATCH 2/8] Made some descriptions less ambiguous.

---
 doc/atmos.sgml | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/doc/atmos.sgml b/doc/atmos.sgml
index ab63c667b..a9d59a407 100644
--- a/doc/atmos.sgml
+++ b/doc/atmos.sgml
@@ -7,7 +7,7 @@
 <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline>
 <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline>
 <url url="mailto:greg.king5@verizon.net" name="Greg King">
-<date>2014-09-23
+<date>2014-12-03
 
 <abstract>
 An overview over the Atmos runtime system as it is implemented for the cc65 C
@@ -219,8 +219,9 @@ They are defined to be FUNCT + a number key.
 
 <sect1>Capitals Lock<p>
 
-The "CAPS Lock" mode is turned off while the program is running.  The previous
-mode (usually turned on) is restored when the program stops.
+The keyboard's "CAPS Lock" mode is turned off while the program is running.
+The previous mode (usually, CAPS Lock turned on [because Oric BASIC keywords
+must be UPPER-case]) is restored when the program stops.
 
 
 <sect1>Passing arguments to the program<p>
@@ -234,7 +235,7 @@ supported directly by BASIC, the following syntax was chosen:
 
 <enum>
 <item>You must turn <tt/CAPS/ lock off (tap CTRL-T) when you want to type
-      lower-case arguments.
+      lower-case arguments (but, <tt/RUN/ and <tt/REM/ must be UPPER-case).
 <item>Arguments are separated by spaces.
 <item>Arguments may be quoted.
 <item>Leading and trailing spaces around an argument are ignored. Spaces within

From d9df576fa6e894a2d6321084dd5423549b5176ba Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Sat, 13 Dec 2014 09:52:39 -0500
Subject: [PATCH 3/8] Used an easier-to-remember way of creating a program that
 uses graphics RAM for other purposes.

---
 cfg/atmos.cfg  |  6 +++---
 doc/atmos.sgml | 21 +++++++++++++++------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg
index 062711b96..691bd467d 100644
--- a/cfg/atmos.cfg
+++ b/cfg/atmos.cfg
@@ -2,10 +2,10 @@ SYMBOLS {
     __TAPEHDR__:   type = import;
     __BASHDR__:    type = import;
     __PROGFLAG__:  type = weak, value = $00; # $00=BASIC, $80=machine code
-    __AUTORUN__:   type = weak, value = $00; # $C7=run, $00=only load
+    __AUTORUN__:   type = weak, value = $00; # $00=only load, $C7=run
     __STACKSIZE__: type = weak, value = $0800; # 2K stack
-    __RAMEND__:    type = weak, value = $9800; # graphics RAM not grabbed
-#   __RAMEND__:    type = weak, value = $B400; # graphics RAM grabbed
+    __GRAB__:      type = weak, value = 0; # 0=don't grab graphics RAM, 1=grab graphics RAM
+    __RAMEND__:    type = weak, value = $9800 + $1C00 * __GRAB__;
 }
 MEMORY {
     ZP:      file = "", define = yes, start = $00E2, size = $001A;
diff --git a/doc/atmos.sgml b/doc/atmos.sgml
index a9d59a407..913e50ed7 100644
--- a/doc/atmos.sgml
+++ b/doc/atmos.sgml
@@ -7,7 +7,7 @@
 <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline>
 <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline>
 <url url="mailto:greg.king5@verizon.net" name="Greg King">
-<date>2014-12-03
+<date>2014-12-05
 
 <abstract>
 An overview over the Atmos runtime system as it is implemented for the cc65 C
@@ -50,9 +50,9 @@ In the standard setup, cc65-generated programs use the memory from
 available. ROM calls are possible without further precautions.
 
 If your program needs more memory, and it won't use TGI graphics, then you can
-use the ld65 command-line option, <tt/-D __RAMEND__=$B400/, when building the
-program, to "grab" the graphics screen RAM.  Then, nearly 44K of memory is
-available.
+use the ld65 command-line option, <tt/-D __GRAB__=1/, when building the
+program, to include the graphics screen RAM.  Then, nearly 44K of memory
+(&dollar;0501 to &dollar;B400) is available.
 
 Special locations:
 
@@ -100,7 +100,7 @@ structures; accessing the struct fields will access the chip registers.
 <descrip>
 
   <tag><tt/VIA/</tag>
-  Access to the VIA (versatile interface adapter) chip is available via the
+  Access to the VIA (Versatile Interface Adapter) chip is available via the
   <tt/VIA/ variable. The structure behind this variable is explained in <tt/_6522.h/.
 
 </descrip><p>
@@ -217,7 +217,7 @@ following functions (and a few others):
 They are defined to be FUNCT + a number key.
 
 
-<sect1>Capitals Lock<p>
+<sect1>Capitals lock<p>
 
 The keyboard's "CAPS Lock" mode is turned off while the program is running.
 The previous mode (usually, CAPS Lock turned on [because Oric BASIC keywords
@@ -246,6 +246,15 @@ supported directly by BASIC, the following syntax was chosen:
 </enum>
 
 
+<sect1>Automatic starting<p>
+
+Usually, a cc65-built program just will sit quietly in memory, after it is
+CLOADed.  It waits for you to start it (by typing BASIC's <tt/RUN/ command).
+But, if you want to create a program that will start running immediately after
+it is loaded, then you can use the linker command-line option
+<tt/-D __AUTORUN__=$C7/.
+
+
 <sect1>Interrupts<p>
 
 The runtime for the Atmos uses routines marked as <tt/.INTERRUPTOR/ for

From d61feae7f8e61d02297c1b48ea93bf68bfdb31ef Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Wed, 7 Jan 2015 10:51:48 -0500
Subject: [PATCH 4/8] Added a comment.

---
 libsrc/atmos/tapehdr.s | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libsrc/atmos/tapehdr.s b/libsrc/atmos/tapehdr.s
index b8562eb02..b67f69d81 100644
--- a/libsrc/atmos/tapehdr.s
+++ b/libsrc/atmos/tapehdr.s
@@ -7,6 +7,7 @@
         ; to force this module to be included into the output file.
         .export __TAPEHDR__:abs = 1
 
+        ; These symbols, also, come from the configuration file.
         .import __BASHDR_LOAD__, __ZPSAVE_LOAD__, __AUTORUN__, __PROGFLAG__
 
 

From 22e06c41d1608ee1b4f79353b7f2b21b831de29c Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Thu, 8 Jan 2015 03:51:20 -0500
Subject: [PATCH 5/8] Fixed a bug that had padded Atmos binaries with 25 bytes
 too many.

---
 cfg/atmos.cfg          | 3 ++-
 libsrc/atmos/crt0.s    | 9 ++++++---
 libsrc/atmos/tapehdr.s | 6 +++---
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg
index 691bd467d..5bb61bb26 100644
--- a/cfg/atmos.cfg
+++ b/cfg/atmos.cfg
@@ -23,7 +23,8 @@ SEGMENTS {
     RODATA:   load = RAM,     type = ro;
     INIT:     load = RAM,     type = ro,  define = yes, optional = yes;
     DATA:     load = RAM,     type = rw;
-    ZPSAVE:   load = RAM,     type = rw,  define = yes;
+    ZPSAVE1:  load = RAM,     type = rw,  define = yes;
+    ZPSAVE2:  load = RAM,     type = bss;
     BSS:      load = RAM,     type = bss, define = yes;
 }
 FEATURES {
diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s
index 63961bfe8..ecbc00391 100644
--- a/libsrc/atmos/crt0.s
+++ b/libsrc/atmos/crt0.s
@@ -2,7 +2,7 @@
 ; Startup code for cc65 (Oric version)
 ;
 ; By Debrune J�r�me <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org>
-; 2014-11-09, Greg King
+; 2015-01-08, Greg King
 ;
 
         .export         _exit
@@ -31,7 +31,8 @@ L1:     lda     sp,x
 
         jsr     zerobss
 
-; Unprotect screen columns 0 and 1.
+; Currently, color isn't supported on the text screen.
+; Unprotect screen columns 0 and 1 (where each line's color codes would sit).
 
         lda     STATUS
         sta     stsave
@@ -81,7 +82,7 @@ L2:     lda     zpsave,x
 
 ; ------------------------------------------------------------------------
 
-.segment        "ZPSAVE"
+.segment        "ZPSAVE1"
 
 zpsave:
 
@@ -91,6 +92,8 @@ zpsave:
 
         .byte   0
 
+.segment        "ZPSAVE2"
+
         .res    zpspace - 1
 
 ; ------------------------------------------------------------------------
diff --git a/libsrc/atmos/tapehdr.s b/libsrc/atmos/tapehdr.s
index b67f69d81..d90c908eb 100644
--- a/libsrc/atmos/tapehdr.s
+++ b/libsrc/atmos/tapehdr.s
@@ -1,6 +1,6 @@
 ;
 ; Based on code by Debrune J�r�me <jede@oric.org>
-; 2013-08-15, Greg King
+; 2015-01-08, Greg King
 ;
 
         ; The following symbol is used by the linker config. file
@@ -8,7 +8,7 @@
         .export __TAPEHDR__:abs = 1
 
         ; These symbols, also, come from the configuration file.
-        .import __BASHDR_LOAD__, __ZPSAVE_LOAD__, __AUTORUN__, __PROGFLAG__
+        .import __BASHDR_LOAD__, __ZPSAVE1_LOAD__, __AUTORUN__, __PROGFLAG__
 
 
 ; ------------------------------------------------------------------------
@@ -23,7 +23,7 @@
         .byte   $00             ; $2AF
         .byte   <__PROGFLAG__   ; $2AE Language flag ($00=BASIC, $80=machine code)
         .byte   <__AUTORUN__    ; $2AD Auto-run flag ($C7=run, $00=only load)
-        .dbyt   __ZPSAVE_LOAD__ ; $2AB Address of end of file
+        .dbyt   __ZPSAVE1_LOAD__ ;$2AB Address of end of file
         .dbyt   __BASHDR_LOAD__ ; $2A9 Address of start of file
         .byte   $00             ; $2A8
 

From 43342366ed1bc365f9dd6918bd160b8e60dcd073 Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Thu, 8 Jan 2015 17:07:28 -0500
Subject: [PATCH 6/8] Added comments that say why the ZPSAVE1 and ZPSAVE2
 segments must be together.

---
 cfg/atmos.cfg       | 4 ++--
 libsrc/atmos/crt0.s | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg
index 5bb61bb26..a1f935efa 100644
--- a/cfg/atmos.cfg
+++ b/cfg/atmos.cfg
@@ -23,8 +23,8 @@ SEGMENTS {
     RODATA:   load = RAM,     type = ro;
     INIT:     load = RAM,     type = ro,  define = yes, optional = yes;
     DATA:     load = RAM,     type = rw;
-    ZPSAVE1:  load = RAM,     type = rw,  define = yes;
-    ZPSAVE2:  load = RAM,     type = bss;
+    ZPSAVE1:  load = RAM,     type = rw,  define = yes; # ZPSAVE1, ZPSAVE2 must be together
+    ZPSAVE2:  load = RAM,     type = bss;               # see "libsrc/atmos/crt0.s"
     BSS:      load = RAM,     type = bss, define = yes;
 }
 FEATURES {
diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s
index ecbc00391..61f40cc9a 100644
--- a/libsrc/atmos/crt0.s
+++ b/libsrc/atmos/crt0.s
@@ -92,6 +92,9 @@ zpsave:
 
         .byte   0
 
+; The segments "ZPSAVE1" and "ZPSAVE2" always must be together.
+; They create a single object (the zpsave buffer).
+
 .segment        "ZPSAVE2"
 
         .res    zpspace - 1

From 2ef83bd66ceb7947a79c08e1cee213de03ec96cb Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Fri, 9 Jan 2015 13:55:16 -0500
Subject: [PATCH 7/8] Mentioned, in the Atmos document, the extra byte at the
 end of program binaries.

---
 doc/atmos.sgml | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/doc/atmos.sgml b/doc/atmos.sgml
index 913e50ed7..68f7f9d65 100644
--- a/doc/atmos.sgml
+++ b/doc/atmos.sgml
@@ -7,7 +7,7 @@
 <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline>
 <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline>
 <url url="mailto:greg.king5@verizon.net" name="Greg King">
-<date>2014-12-05
+<date>2015-01-09
 
 <abstract>
 An overview over the Atmos runtime system as it is implemented for the cc65 C
@@ -37,9 +37,11 @@ information.
 
 The standard binary output format generated by the linker for the Atmos target
 is a machine language program with a one-line BASIC stub that jumps to the
-machine-language part through <tt/CALL/.  It has a 24-byte tape header.
-It means that a file can be loaded as a BASIC program, and started with RUN.
-The standard load address is &dollar;501.
+machine-language part through <tt/CALL/.  It has one sacrificial byte attached
+to the end (a bug in the Oric ROM means that BASIC can put a variable on top
+of the last byte that was loaded).  It has a 24-byte tape header.  A file can
+be CLOADed as a BASIC program, and started by typing <tt/RUN/.  The standard
+load address is &dollar;501.
 
 
 

From fccd2bf66a834bd8682720705a4b56bdfe9df001 Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Fri, 9 Jan 2015 22:19:35 -0500
Subject: [PATCH 8/8] Added more info to a comment.

---
 libsrc/atmos/crt0.s | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s
index 61f40cc9a..e789b28c2 100644
--- a/libsrc/atmos/crt0.s
+++ b/libsrc/atmos/crt0.s
@@ -2,7 +2,7 @@
 ; Startup code for cc65 (Oric version)
 ;
 ; By Debrune J�r�me <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org>
-; 2015-01-08, Greg King
+; 2015-01-09, Greg King
 ;
 
         .export         _exit
@@ -89,6 +89,7 @@ zpsave:
 ; This padding is needed by a bug in the ROM.
 ; (The CLOAD command starts BASIC's variables table on top of the last byte
 ; that was loaded [instead of at the next address].)
+; This is overlaid on a buffer, so that it doesn't use extra space in RAM.
 
         .byte   0