Merge pull request #307 from groessler/something_to_pull2

Add Atari version of of doesclrscrafterexit().
This commit is contained in:
Oliver Schmidt
2016-06-07 15:13:28 +02:00
8 changed files with 81 additions and 38 deletions

View File

@@ -949,27 +949,7 @@ id="malloc" name="malloc"> may still return <tt/NULL/.
<tag/Declaration/<tt/unsigned char _is_cmdline_dos (void);/ <tag/Declaration/<tt/unsigned char _is_cmdline_dos (void);/
<tag/Description/The function returns 0 if the DOS doesn't support command line arguments. <tag/Description/The function returns 0 if the DOS doesn't support command line arguments.
It returns 1 if it does. 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/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> </descrip>
</quote> </quote>
@@ -2587,6 +2567,40 @@ ldiv
</quote> </quote>
<sect1>doesclrscrafterexit<label id="doesclrscrafterexit"><p>
<quote>
<descrip>
<tag/Function/Determines whether the screen is going to be cleared after program exit.
<tag/Header/<tt/<ref id="cc65.h" name="cc65.h">/
<tag/Declaration/<tt/unsigned char doesclrscrafterexit (void);/
<tag/Description/The function returns zero if the screen won't be cleared immediately after
program termination. It returns a non-zero value if it will.
<tag/Notes/<itemize>
<item>Some systems, maybe depending on configuration, immediately clear the screen
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
<tag/Example/<verb>
/* Hello World */
#include <stdio.h>
#include <unistd.h>
#include <cc65.h>
int main(void)
{
printf("Hello World\n");
if (doesclrscrafterexit())
sleep(5);
return 0;
}
</verb>
</descrip>
</quote>
<sect1>em_commit<label id="em_commit"><p> <sect1>em_commit<label id="em_commit"><p>
<quote> <quote>

View File

@@ -85,6 +85,11 @@ int __fastcall__ cc65_cos (unsigned x);
** is in 8.8 fixed point format, which means that 1.0 = $100 and -1.0 = $FF00. ** is in 8.8 fixed point format, which means that 1.0 = $100 and -1.0 = $FF00.
*/ */
unsigned char doesclrscrafterexit (void);
/* Indicates whether the screen automatically be cleared after program
** termination.
*/
/* End of cc65.h */ /* End of cc65.h */

19
libsrc/atari/doesclrscr.s Normal file
View File

@@ -0,0 +1,19 @@
;
; Christian Groessler, June-2016
;
; unsigned char doesclrscr(void);
;
; returns 0/1 if after program termination the screen isn't/is cleared
;
.export _doesclrscrafterexit
.import __dos_type
.include "atari.inc"
_doesclrscrafterexit:
ldx #0
lda __dos_type
cmp #MAX_DOS_WITH_CMDLINE + 1
txa
rol a
rts

View File

@@ -7,14 +7,9 @@
; ;
.export __is_cmdline_dos .export __is_cmdline_dos
.import __dos_type .import _doesclrscrafterexit
.include "atari.inc"
__is_cmdline_dos: __is_cmdline_dos:
ldx #0 jsr _doesclrscrafterexit ; currently (unless a DOS behaving differently is popping up)
lda __dos_type eor #$01 ; we can get by with the inverse of _doesclrscrafterexit
cmp #MAX_DOS_WITH_CMDLINE + 1
txa
rol a
eor #$01
rts rts

View File

@@ -14,6 +14,7 @@
#include <errno.h> #include <errno.h>
#include <6502.h> #include <6502.h>
#include <atari.h> #include <atari.h>
#include <cc65.h>
#include <conio.h> #include <conio.h>
static int verbose = 1; static int verbose = 1;
@@ -32,13 +33,6 @@ static struct __iocb *findfreeiocb(void)
return NULL; return NULL;
} }
static void exitfn(void)
{
/* if DOS will automatically clear the screen, after the program exits, wait for a keypress... */
if (! _is_cmdline_dos())
cgetc();
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char *filename, *x; char *filename, *x;
@@ -50,7 +44,9 @@ int main(int argc, char **argv)
struct __iocb *iocb = findfreeiocb(); struct __iocb *iocb = findfreeiocb();
int iocb_num; int iocb_num;
atexit(exitfn); /* if DOS will automatically clear the screen after the program exits, wait for a keypress... */
if (doesclrscrafterexit())
atexit((void (*)(void))cgetc);
if (! iocb) { if (! iocb) {
fprintf(stderr, "couldn't find a free iocb\n"); fprintf(stderr, "couldn't find a free iocb\n");

View File

@@ -0,0 +1,12 @@
;
; Christian Groessler, June-2016
;
; unsigned char doesclrscr(void);
;
; returns 0/1 if after program termination the screen isn't/is cleared
;
.export _doesclrscrafterexit
.import return0
_doesclrscrafterexit = return0

View File

@@ -7,12 +7,13 @@
#include <stdio.h> #include <stdio.h>
#include <conio.h> #include <conio.h>
#include <atari.h> #include <atari.h>
#include <cc65.h>
extern char _defdev[]; extern char _defdev[];
int main(void) int main(void)
{ {
printf("default device: %s\n", _defdev); printf("default device: %s\n", _defdev);
if (! _is_cmdline_dos()) cgetc(); if (doesclrscrafterexit()) cgetc();
return 0; return 0;
} }

View File

@@ -8,6 +8,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <conio.h> #include <conio.h>
#include <atari.h> #include <atari.h>
#include <cc65.h>
extern int getsp(void); /* comes from ../getsp.s */ extern int getsp(void); /* comes from ../getsp.s */
@@ -41,6 +42,6 @@ int main(void)
printf(" sp: $%04X (stack ptr)\n", getsp()); printf(" sp: $%04X (stack ptr)\n", getsp());
if (allocmem) free(allocmem); if (allocmem) free(allocmem);
if (! _is_cmdline_dos()) cgetc(); if (doesclrscrafterexit()) cgetc();
return(0); return(0);
} }