From feb50268236efd2bf563352aa98e1eaa8b978eb9 Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Wed, 7 Aug 2024 18:27:09 +0200
Subject: [PATCH] Added option to disable the force-to-uppercase behavior of
the apple2 target. (#2474)
* Added option to disable the force-to-uppercase behavior of the apple2 target.
* Fixed dangling spaces.
---
doc/apple2.sgml | 1 +
doc/funcref.sgml | 1 +
include/apple2.h | 10 ++++++++++
libsrc/apple2/allow_lowercase.s | 23 +++++++++++++++++++++++
libsrc/apple2/cputc.s | 5 ++++-
libsrc/apple2/uppercasemask.s | 9 +++++++++
libsrc/apple2/write.s | 5 ++++-
7 files changed, 52 insertions(+), 2 deletions(-)
create mode 100644 libsrc/apple2/allow_lowercase.s
create mode 100644 libsrc/apple2/uppercasemask.s
diff --git a/doc/apple2.sgml b/doc/apple2.sgml
index 99ff8139e..c0255c4f7 100644
--- a/doc/apple2.sgml
+++ b/doc/apple2.sgml
@@ -330,6 +330,7 @@ usage.
- _dos_type
- _filetype
- _datetime
+
- allow_lowercase
- beep
- get_ostype
- gmtime_dt
diff --git a/doc/funcref.sgml b/doc/funcref.sgml
index a0a6d7ca8..130646538 100644
--- a/doc/funcref.sgml
+++ b/doc/funcref.sgml
@@ -95,6 +95,7 @@ function.
- _dos_type
+
- allow_lowercase
[
][
][
diff --git a/include/apple2.h b/include/apple2.h
index 875c10661..1a840be6e 100644
--- a/include/apple2.h
+++ b/include/apple2.h
@@ -232,6 +232,16 @@ struct tm* __fastcall__ gmtime_dt (const struct datetime* dt);
time_t __fastcall__ mktime_dt (const struct datetime* dt);
/* Converts a ProDOS date/time structure to a time_t UNIX timestamp */
+#if !defined(__APPLE2ENH__)
+unsigned char __fastcall__ allow_lowercase (unsigned char onoff);
+/* If onoff is 0, lowercase characters printed to the screen via STDIO and
+** CONIO are forced to uppercase. If onoff is 1, lowercase characters are
+** printed to the screen untouched. By default lowercase characters are
+** forced to uppercase because a stock Apple ][+ doesn't support lowercase
+** display. The function returns the old lowercase setting.
+*/
+#endif
+
/* End of apple2.h */
diff --git a/libsrc/apple2/allow_lowercase.s b/libsrc/apple2/allow_lowercase.s
new file mode 100644
index 000000000..648276b4c
--- /dev/null
+++ b/libsrc/apple2/allow_lowercase.s
@@ -0,0 +1,23 @@
+;
+; Oliver Schmidt, 2024-08-06
+;
+; unsigned char __fastcall__ allow_lowercase (unsigned char onoff);
+;
+
+ .export _allow_lowercase
+ .import uppercasemask, return0, return1
+
+_allow_lowercase:
+ tax
+ lda values,x
+ ldx uppercasemask
+ sta uppercasemask
+ cpx #$FF
+ beq :+
+ jmp return0
+: jmp return1
+
+ .rodata
+
+values: .byte $DF ; Force uppercase
+ .byte $FF ; Keep lowercase
diff --git a/libsrc/apple2/cputc.s b/libsrc/apple2/cputc.s
index 035b1c047..0a27abacd 100644
--- a/libsrc/apple2/cputc.s
+++ b/libsrc/apple2/cputc.s
@@ -11,6 +11,9 @@
.export _cputcxy, _cputc
.export cputdirect, newline, putchar, putchardirect
.import gotoxy, VTABZ
+ .ifndef __APPLE2ENH__
+ .import uppercasemask
+ .endif
.include "apple2.inc"
@@ -43,7 +46,7 @@ _cputc:
.ifndef __APPLE2ENH__
cmp #$E0 ; Test for lowercase
bcc cputdirect
- and #$DF ; Convert to uppercase
+ and uppercasemask
.endif
cputdirect:
diff --git a/libsrc/apple2/uppercasemask.s b/libsrc/apple2/uppercasemask.s
new file mode 100644
index 000000000..8b993bb1e
--- /dev/null
+++ b/libsrc/apple2/uppercasemask.s
@@ -0,0 +1,9 @@
+;
+; Oliver Schmidt, 2024-08-06
+;
+
+ .export uppercasemask
+
+ .data
+
+uppercasemask: .byte $DF ; Convert to uppercase
diff --git a/libsrc/apple2/write.s b/libsrc/apple2/write.s
index 7b50d0705..5fb51cca6 100644
--- a/libsrc/apple2/write.s
+++ b/libsrc/apple2/write.s
@@ -7,6 +7,9 @@
.export _write
.import rwprolog, rwcommon, rwepilog
.import COUT
+ .ifndef __APPLE2ENH__
+ .import uppercasemask
+ .endif
.include "zeropage.inc"
.include "errno.inc"
@@ -84,7 +87,7 @@ next: lda (ptr1),y
.ifndef __APPLE2ENH__
cmp #$E0 ; Test for lowercase
bcc output
- and #$DF ; Convert to uppercase
+ and uppercasemask
.endif
output: jsr COUT ; Preserves X and Y
]