From 9fa90e2265b0d54e3fd9e6ec0227821f6a09d9de Mon Sep 17 00:00:00 2001
From: Greg King <gregdk@users.sf.net>
Date: Thu, 24 Oct 2019 05:15:42 -0400
Subject: [PATCH 079/170] Added VERA peek() and poke() to the cx16 library.
They simplify C programs' direct access to VERA's internal address space.
---
include/cx16.h | 19 ++++++++++++++-----
libsrc/cx16/vpeek.s | 19 +++++++++++++++++++
libsrc/cx16/vpoke.s | 21 +++++++++++++++++++++
libsrc/cx16/vset.s | 20 ++++++++++++++++++++
4 files changed, 74 insertions(+), 5 deletions(-)
create mode 100644 libsrc/cx16/vpeek.s
create mode 100644 libsrc/cx16/vpoke.s
create mode 100644 libsrc/cx16/vset.s
diff --git a/include/cx16.h b/include/cx16.h
index db32d846..a2f52850 100644
--- a/include/cx16.h
+++ b/include/cx16.h
@@ -144,9 +144,10 @@ struct __emul {
unsigned char debug; /* Boolean: debugging enabled */
unsigned char vera_action; /* Boolean: displaying VERA activity */
unsigned char keyboard; /* Boolean: displaying typed keys */
- unsigned char echo; /* Boolean: Kernal output echoed to host */
+ unsigned char echo; /* How Kernal output should be echoed to host */
unsigned char save_on_exit; /* Boolean: save SD card when quitting */
- unsigned char unused[0xD - 0x5];
+ unsigned char gif_method; /* How GIF movie is being recorded */
+ unsigned char unused[0xD - 0x6];
unsigned char keymap; /* Keyboard layout number */
const char detect[2]; /* "16" if running on x16emu */
};
@@ -173,16 +174,24 @@ signed char get_ostype (void);
** Positive -- release build
*/
-void __fastcall__ set_tv (unsigned char);
-/* Set the video mode the machine will use.
+void __fastcall__ set_tv (unsigned char type);
+/* Set the video type that the machine will use.
** Call with a TV_xx constant.
*/
-unsigned char __fastcall__ videomode (unsigned char Mode);
+unsigned char __fastcall__ videomode (unsigned char mode);
/* Set the video mode, return the old mode. Call with one of the VIDEOMODE_xx
** constants.
*/
+unsigned char __fastcall__ vpeek (unsigned long addr);
+/* Get a byte from a location in VERA's internal address space. */
+
+void __fastcall__ vpoke (unsigned char data, unsigned long addr);
+/* Put a byte into a location in VERA's internal address space.
+** (addr is second instead of first for the sake of code efficiency.)
+*/
+
/* End of cX16.h */
diff --git a/libsrc/cx16/vpeek.s b/libsrc/cx16/vpeek.s
new file mode 100644
index 00000000..0c1a9465
--- /dev/null
+++ b/libsrc/cx16/vpeek.s
@@ -0,0 +1,19 @@
+;
+; 2019-10-22, Greg King
+;
+; unsigned char fastcall vpeek (unsigned long addr);
+; /* Get a byte from a location in VERA's internal address space. */
+;
+
+ .export _vpeek
+
+ .import vset
+ .include "cx16.inc"
+
+
+_vpeek: php ; (vset blocks interrupts)
+ jsr vset ; put VERA's address
+ ldx #>$0000
+ lda VERA::DATA0 ; read VERA port zero
+ plp
+ rts
diff --git a/libsrc/cx16/vpoke.s b/libsrc/cx16/vpoke.s
new file mode 100644
index 00000000..8c21e9b2
--- /dev/null
+++ b/libsrc/cx16/vpoke.s
@@ -0,0 +1,21 @@
+;
+; 2019-10-22, Greg King
+;
+; void fastcall vpoke (unsigned char data, unsigned long addr);
+; /* Put a byte into a location in VERA's internal address space.
+; ** (addr is second instead of first for the sake of code efficiency.)
+; */
+;
+
+ .export _vpoke
+
+ .import vset, popa
+ .include "cx16.inc"
+
+
+_vpoke: php ; (vset blocks interrupts)
+ jsr vset ; put VERA's address
+ jsr popa
+ sta VERA::DATA0 ; write data to VERA port zero
+ plp
+ rts
diff --git a/libsrc/cx16/vset.s b/libsrc/cx16/vset.s
new file mode 100644
index 00000000..9178850e
--- /dev/null
+++ b/libsrc/cx16/vset.s
@@ -0,0 +1,20 @@
+;
+; 2019-10-22, Greg King
+;
+; Set the __far__ address that VERA will use for data access.
+; This is a support function for the fastcall functions vpeek() and vpoke().
+;
+
+ .export vset
+
+ .importzp sreg
+ .include "cx16.inc"
+
+
+vset: ldy sreg
+ sei ; don't let interrupt handlers interfere
+ stz VERA::CTRL ; set address for VERA's data port zero
+ sta VERA::ADDR
+ stx VERA::ADDR+1
+ sty VERA::ADDR+2
+ rts
--
2.26.0