Switched to ENTRYN and custom memcpy. Still broken.

This commit is contained in:
Scott Duensing 2024-04-17 19:19:09 -05:00
parent fe52add80e
commit 77f655785b
2 changed files with 56 additions and 30 deletions

View file

@ -26,7 +26,7 @@
#include <string.h> // For memcopy
volatile cameraT *_camera = (cameraT *)0x200; // Simulation copy of camera.
volatile cameraT *_camera = (cameraT *)CAMERA_SHARED_START; // Simulation copy of camera.
volatile cameraT *_cameraInDatabase;
volatile byte *_pointer;
@ -132,7 +132,7 @@ void a23d2Init(void) {
POKE(MMU_MEM_BANK_3, A23D2_FAR_BLOCK);
// We're going to clobber from 0x80fb to 0x8101. Back it up.
memcpy((byte *)(0x2ff - 0x06), (byte *)A23D2_TEST_DATABASE, 0x06);
scdMemCpy((byte *)(SCRATCH_END - 0x06), (byte *)A23D2_TEST_DATABASE, 0x06);
// Initialize A2-3D2 so we can use the "fast entry point" (NXTPT) when rendering.
_bytes = 0;
@ -144,11 +144,21 @@ void a23d2Init(void) {
_pointer[_bytes++] = 0;
_pointer[_bytes++] = END; // Setup complete!
// __attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_ENTRYS)); // Call ENTRYS. This preserves the ZP for us.
__attribute__((leaf)) asm volatile("jsr 0x606c"); // Call ENTRYS. This preserves the ZP for us.
// Save ZP that A2-3D2 is going to clobber.
scdMemCpy((byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), (byte *)COMPILER_ZP_START, COMPILER_ZP_LENGTH);
// Call ENTRYN. This sets up A2-3D2. We need to preserve processor state and ZP.
__attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_ENTRYN));
// Save A2-3D2s variables for later.
scdMemCpy((byte *)VARS_1_START, (byte *)A23D2_VARS_1_START, A23D2_VARS_1_LENGTH);
scdMemCpy((byte *)VARS_2_START, (byte *)A23D2_VARS_2_START, A23D2_VARS_2_LENGTH);
// Restore ZP that A2-3D2 clobbered.
scdMemCpy((byte *)COMPILER_ZP_START, (byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), COMPILER_ZP_LENGTH);
// Put back the RAM we clobbered.
memcpy((byte *)A23D2_TEST_DATABASE, (byte *)(0x2ff - 0x06), 0x06);
scdMemCpy((byte *)A23D2_TEST_DATABASE, (byte *)(SCRATCH_END - 0x06), 0x06);
// Move our 3D/2D data buffer at 0x56000 into slot 4.
POKE(MMU_MEM_BANK_4, DATABASE_FAR_BLOCK);
@ -174,8 +184,6 @@ void a23d2Init(void) {
void a23d2Render(void) {
uint16_t i;
// We need to manually page 0x54000 into 0x6000.
// This isn't actually large enough for A2-3D2 but what we should only
// lose Apple ][ stuff we're not using anyway.
@ -195,30 +203,25 @@ void a23d2Render(void) {
_cameraInDatabase->b = _camera->b;
_cameraInDatabase->h = _camera->h;
//memcpy((byte *)(0x2ff - A23D2_ZP_LENGTH), (byte *)A23D2_ZP_START, A23D2_ZP_LENGTH); // Save the ZP we're going to clobber.
// Save ZP that A2-3D2 is going to clobber.
scdMemCpy((byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), (byte *)COMPILER_ZP_START, COMPILER_ZP_LENGTH);
for (i=0; i<A23D2_ZP_LENGTH; i++) POKE(0x2ff + i, PEEK(A23D2_ZP_START + i));
// Restore A2-3D2s variables.
scdMemCpy((byte *)A23D2_VARS_1_START, (byte *)VARS_1_START, A23D2_VARS_1_LENGTH);
scdMemCpy((byte *)A23D2_VARS_2_START, (byte *)VARS_2_START, A23D2_VARS_2_LENGTH);
/*
__attribute__((leaf)) asm volatile( \
" ldx #%[length] \n" \
"%=: \n" \
" lda %[start],x \n" \
" sta %[dest],x \n" \
" dex \n" \
" bne %=b \n" \
: \
: [length] "i"(A23D2_ZP_LENGTH), [start] "i"(A23D2_ZP_START), [dest] "i"(0x2ff) \
: "a", "x", "c", "v");
*/
// Set IBP.
POKEW(A23D2_IBP, DATABASE);
POKEW(A23D2_IBP, DATABASE); // Set IBP.
// __attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_NXTPT) : "a","x","y","c","v"); // Call NXTPT.
__attribute__((leaf)) asm volatile("jsr 0x6118"::: "a","x","y","c","v"); // Call NXTPT.
// Call NXTPT.
__attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_NXTPT) : "a","x","y","c","v"); // Call NXTPT.
//memcpy((byte *)A23D2_ZP_START, (byte *)(0x2ff - A23D2_ZP_LENGTH), A23D2_ZP_LENGTH); // Put the ZP back.
// Save A2-3D2s variables for later.
scdMemCpy((byte *)VARS_1_START, (byte *)A23D2_VARS_1_START, A23D2_VARS_1_LENGTH);
scdMemCpy((byte *)VARS_2_START, (byte *)A23D2_VARS_2_START, A23D2_VARS_2_LENGTH);
for (i=0; i<A23D2_ZP_LENGTH; i++) POKE(A23D2_ZP_START + i, PEEK(0x2ff + i));
// Restore ZP that A2-3D2 clobbered.
scdMemCpy((byte *)COMPILER_ZP_START, (byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), COMPILER_ZP_LENGTH);
// Restore memory map.
POKE(MMU_MEM_BANK_4, 4);

View file

@ -30,6 +30,16 @@ typedef uint8_t byte;
#endif
//#define scdMemCpy memcpy
#define scdMemCpy(d,s,l) \
({ \
volatile byte *dp = (d); \
volatile byte *sp = (s); \
uint16_t i = 0; \
for (i=0; i<(l); i++) *dp++ = *sp++; \
})
#define A23D2_FAR_BLOCK 42
#define DATABASE_FAR_BLOCK 43
@ -43,7 +53,7 @@ typedef uint8_t byte;
// A2-3D2 Function Addresses.
#define A23D2_ENTRYS 0x606c
#define A23D2_ENTRYN 0x6090
#define A23D2_NXTPT 0x6118
#define A23D2_SINEX 0x61f6
#define A23D2_COSEX 0x620f
@ -52,8 +62,21 @@ typedef uint8_t byte;
#define A23D2_TEST_DATABASE 0x80fb
#define A23D2_TDATA 0x613e
#define A23D2_IBP 0x9b
#define A23D2_ZP_START 0x60
#define A23D2_ZP_LENGTH 0x62
#define A23D2_VARS_1_START 0x7c
#define A23D2_VARS_1_LENGTH 0x20
#define A23D2_VARS_2_START 0xbb
#define A23D2_VARS_2_LENGTH 0x3
// Stuff A2-3D2 is going to clobber that our compiler may want.
#define COMPILER_ZP_START 0x60 // To 0xC2
#define COMPILER_ZP_LENGTH 0x62
// Our Scratch Addresses.
#define CAMERA_SHARED_START 0x200 // To 0x209
#define CAMERA_SHARED_LENGTH 0x9
#define VARS_1_START 0x20a // To 0x22a
#define VARS_2_START 0x22b // To 0x22d
#define SCRATCH_END 0x2ff
// A2-3D1 Commands. Commented out items are Apple ][ only.
@ -92,7 +115,7 @@ typedef uint8_t byte;
#define END 0x79 // End of Database
typedef struct cameraS {
typedef struct cameraS { // 9 bytes.
int16_t x;
int16_t y;
int16_t z;