]> git.sur5r.net Git - cc65/commitdiff
Merge pull request #297 from groessler/something_to_pull
authorOliver Schmidt <ol.sc@web.de>
Thu, 26 May 2016 21:36:22 +0000 (23:36 +0200)
committerOliver Schmidt <ol.sc@web.de>
Thu, 26 May 2016 21:36:22 +0000 (23:36 +0200)
Atari: add new function '_is_cmdline_dos()' and some other small changes

doc/atari.sgml
doc/funcref.sgml
include/atari.h
libsrc/atari/getdefdev.s
libsrc/atari/is_cmdline_dos.s [new file with mode: 0644]
libsrc/atari/sysrmdir.s
libsrc/atari/targetutil/w2cas.c
testcode/lib/atari/defdev.c
testcode/lib/atari/mem.c

index 2087a854102d1f56bb918e38c0244c6c3e711188..f911d568ec660bd1239852935bd2f75eb905d568 100644 (file)
@@ -275,6 +275,7 @@ See the <url url="funcref.html" name="function reference"> for declaration and u
 <item>_getcolor
 <item>_getdefdev
 <item>_graphics
+<item>_is_cmdline_dos
 <item>_rest_vecs
 <item>_save_vecs
 <item>_scroll
index a2ccf6c73c653df3a0ddf395bbafd93085bea59c..9bd4a35957a8515ec6443373387c8cc2110af5af 100644 (file)
@@ -98,6 +98,7 @@ function.
 <!-- <item><ref id="_getcolor" name="_getcolor"> -->
 <!-- <item><ref id="_getdefdev" name="_getdefdev"> -->
 <!-- <item><ref id="_graphics" name="_graphics"> -->
+<item><ref id="_is_cmdline_dos" name="_is_cmdline_dos">
 <!-- <item><ref id="_rest_vecs" name="_rest_vecs"> -->
 <!-- <item><ref id="_save_vecs" name="_save_vecs"> -->
 <!-- <item><ref id="_scroll" name="_scroll"> -->
@@ -939,6 +940,40 @@ id="malloc" name="malloc"> may still return <tt/NULL/.
 </quote>
 
 
+<sect1>_is_cmdline_dos<label id="_is_cmdline_dos"><p>
+
+<quote>
+<descrip>
+<tag/Function/Determines whether the underlying DOS supports command line arguments.
+<tag/Header/<tt/<ref id="atari.h" name="atari.h">/
+<tag/Declaration/<tt/unsigned char _is_cmdline_dos (void);/
+<tag/Description/The function returns 0 if the DOS doesn't support command line arguments.
+It returns 1 if it does.
+<tag/Notes/<itemize>
+<item>Many Atari DOSes which don't support command line arguments immediately clear the screen
+and display their menu after a program exits. Therefore it might be difficult to read
+the last messages printed by the program prior to its exit. This function can be used
+to decide if a delay or wait for a key press should be executed when then program
+exits.
+</itemize>
+<tag/Availability/cc65 (<tt/atari/ and <tt/atarixl/ platforms)
+<tag/Example/<verb>
+/* Hello World for Atari */
+#include <stdio.h>
+#include <unistd.h>
+#include <atari.h>
+int main(void)
+{
+    printf("Hello World\n");
+    if (! _is_cmdline_dos())
+        sleep(5);
+    return 0;
+}
+</verb>
+</descrip>
+</quote>
+
+
 <sect1>_poserror<label id="_poserror"><p>
 
 <quote>
index 5e36b1daa76303af17b11e97022c652c5b25f0a5..fa99fca20d719e1676d725349b73ed20437c3635 100644 (file)
@@ -161,11 +161,12 @@ extern void __fastcall__ _scroll (signed char numlines);
                                           /* numlines < 0  scrolls down */
 
 /* misc. functions */
-extern unsigned char get_ostype(void);  /* get ROM version */
-extern unsigned char get_tv(void);      /* get TV system */
-extern void _save_vecs(void);           /* save system vectors */
-extern void _rest_vecs(void);           /* restore system vectors */
-extern char *_getdefdev(void);          /* get default floppy device */
+extern unsigned char get_ostype(void);       /* get ROM version */
+extern unsigned char get_tv(void);           /* get TV system */
+extern void _save_vecs(void);                /* save system vectors */
+extern void _rest_vecs(void);                /* restore system vectors */
+extern char *_getdefdev(void);               /* get default floppy device */
+extern unsigned char _is_cmdline_dos(void);  /* does DOS support command lines */
 
 /* global variables */
 extern unsigned char _dos_type;         /* the DOS flavour */
index 47d8714e65d0a029524dd77a0bc4e750a2199793..280c042e5caad1acefdb28990a0c116b180f4fb6 100644 (file)
 __getdefdev:
 
         lda     __dos_type      ; which DOS?
-        cmp     #ATARIDOS
-        beq     finish
-        cmp     #MYDOS
-        beq     finish
+        cmp     #OSADOS+1
+        bcs     finish          ; only supported on OS/A+ and SpartaDOS
+                                ; (TODO: add XDOS support)
 
         ldy     #BUFOFF
         lda     #0
diff --git a/libsrc/atari/is_cmdline_dos.s b/libsrc/atari/is_cmdline_dos.s
new file mode 100644 (file)
index 0000000..71b35fb
--- /dev/null
@@ -0,0 +1,20 @@
+;
+; Christian Groessler, May-2016
+;
+; unsigned char _is_cmdline_dos(void);
+;
+; returns 0 for non-commandline DOS, 1 for commandline DOS
+;
+
+        .export  __is_cmdline_dos
+        .import  __dos_type
+        .include "atari.inc"
+
+__is_cmdline_dos:
+        ldx     #0
+        lda     __dos_type
+        cmp     #MAX_DOS_WITH_CMDLINE + 1
+        txa
+        rol     a
+        eor     #$01
+        rts
index 3f5b9e447b25a996a3bca8d1ede782b6612da25d..f568ded6ea0c26278e7b420c8948122859cc4b6c 100644 (file)
 
         pha
         lda     __dos_type
-        beq     not_impl                ; AtariDOS
         cmp     #OSADOS+1
         bcc     do_sparta               ; OS/A and SpartaDOS
+        cmp     #MYDOS
+        bne     not_impl                ; neither MyDOS, OS/A, nor SpartaDOS
         pla
-        jmp     __sysremove             ; MyDOS and others (TODO: check XDOS)
+        jmp     __sysremove             ; MyDOS
 
 not_impl:
         pla
index 4d574da073b9a4f93c8d776907e9b5c0ca2d3e95..453785140054ec01b9da8d5cf13697b748c84d7f 100644 (file)
@@ -45,7 +45,7 @@ int main(int argc, char **argv)
 
     if (! iocb) {
         fprintf(stderr, "couldn't find a free iocb\n");
-        if (_dos_type != 1)
+        if (! _is_cmdline_dos())
             cgetc();
         return 1;
     }
@@ -57,10 +57,20 @@ int main(int argc, char **argv)
         printf("\nfilename: ");
         x = fgets(buf, 19, stdin);
         printf("\n");
-        if (! x)
+        if (! x) {
+            printf("empty filename, exiting...\n");
+            if (! _is_cmdline_dos())
+                cgetc();
             return 1;
+        }
         if (*x && *(x + strlen(x) - 1) == '\n')
             *(x + strlen(x) - 1) = 0;
+        if (! strlen(x)) {  /* empty filename */
+            printf("empty filename, exiting...\n");
+            if (! _is_cmdline_dos())
+                cgetc();
+            return 1;
+        }
         filename = x;
     }
     else {
@@ -74,7 +84,7 @@ int main(int argc, char **argv)
         buffer = malloc(buflen);
         if (! buffer) {
             fprintf(stderr, "cannot alloc %ld bytes -- aborting...\n", (long)buflen);
-            if (_dos_type != 1)
+            if (! _is_cmdline_dos())
                 cgetc();
             return 1;
         }
@@ -87,7 +97,7 @@ int main(int argc, char **argv)
     if (! file) {
         free(buffer);
         fprintf(stderr, "cannot open '%s': %s\n", filename, strerror(errno));
-        if (_dos_type != 1)
+        if (! _is_cmdline_dos())
             cgetc();
         return 1;
     }
@@ -101,7 +111,7 @@ int main(int argc, char **argv)
     file_err:
         fclose(file);
         free(buffer);
-        if (_dos_type != 1)
+        if (! _is_cmdline_dos())
             cgetc();
         return 1;
     }
@@ -133,7 +143,7 @@ int main(int argc, char **argv)
     if (regs.y != 1) {
         fprintf(stderr, "CIO call to open cassette returned %d\n", regs.y);
         free(buffer);
-        if (_dos_type != 1)
+        if (! _is_cmdline_dos())
             cgetc();
         return 1;
     }
@@ -157,7 +167,7 @@ int main(int argc, char **argv)
         regs.pc = 0xe456;   /* CIOV */
         _sys(&regs);
 
-        if (_dos_type != 1)
+        if (! _is_cmdline_dos())
             cgetc();
         return 1;
     }
@@ -173,14 +183,14 @@ int main(int argc, char **argv)
 
     if (regs.y != 1) {
         fprintf(stderr, "CIO call to close cassette returned %d\n", regs.y);
-        if (_dos_type != 1)
+        if (! _is_cmdline_dos())
             cgetc();
         return 1;
     }
 
     /* all is fine */
     printf("success\n");
-    if (_dos_type != 1)
+    if (! _is_cmdline_dos())
         cgetc();
     return 0;
 }
index f679985ec536ac7e2cef18c7bd7f3eb9b9862052..06ddb6365564cab02c07b42679a84dbb5e791fbf 100644 (file)
@@ -13,6 +13,6 @@ extern char _defdev[];
 int main(void)
 {
         printf("default device: %s\n", _defdev);
-        if (_dos_type != SPARTADOS && _dos_type != OSADOS) cgetc();
+        if (! _is_cmdline_dos()) cgetc();
         return 0;
 }
index 36222e08b2e321f1bf35e482510252d906eeb6f2..a8d50cf30923e34db58ddd8003f7c59506e835da 100644 (file)
@@ -11,7 +11,6 @@
 
 extern int getsp(void);                         /* comes from ../getsp.s */
 
-extern char _dos_type;                          /* bss variable */
 unsigned char data = 0x12;                      /* data variable */
 
 unsigned int *APPMHI = (unsigned int *)14;      /* 14,15 */
@@ -42,6 +41,6 @@ int main(void)
   printf("  sp:              $%04X  (stack ptr)\n", getsp());
 
   if (allocmem) free(allocmem);
-  if (_dos_type != 1) cgetc();
+  if (! _is_cmdline_dos()) cgetc();
   return(0);
 }