It's working!
This commit is contained in:
parent
77f655785b
commit
43a5c4870c
3 changed files with 30 additions and 29 deletions
34
src/a23d2.c
34
src/a23d2.c
|
@ -131,31 +131,31 @@ void a23d2Init(void) {
|
|||
// lose Apple ][ stuff we're not using anyway.
|
||||
POKE(MMU_MEM_BANK_3, A23D2_FAR_BLOCK);
|
||||
|
||||
// We're going to clobber from 0x80fb to 0x8101. Back it up.
|
||||
// We're going to clobber from 0x80fb to 0x8101 with our setup database.
|
||||
// Usually we'd swap in bank 4, but we'd have to save that, too. Back it up.
|
||||
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;
|
||||
_pointer = (byte *)A23D2_TEST_DATABASE; // Standard location for test database in A2-3D2.
|
||||
_pointer[_bytes++] = SCRSZ; // Screen size. 256x240. Center is 0,0.
|
||||
_pointer = (byte *)A23D2_TEST_DATABASE; // Standard location for test database in A2-3D2.
|
||||
_pointer[_bytes++] = SCRSZ; // Screen size. 256x240. Center is 0,0.
|
||||
_pointer[_bytes++] = 255;
|
||||
_pointer[_bytes++] = 239;
|
||||
_pointer[_bytes++] = 0;
|
||||
_pointer[_bytes++] = 0;
|
||||
_pointer[_bytes++] = END; // Setup complete!
|
||||
_pointer[_bytes++] = END; // Setup complete!
|
||||
|
||||
// Save ZP that A2-3D2 is going to clobber.
|
||||
scdMemCpy((byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), (byte *)COMPILER_ZP_START, COMPILER_ZP_LENGTH);
|
||||
scdMemCpy((byte *)COMPILER_ZP_SAVE, (byte *)COMPILER_ZP_START, COMPILER_ZP_LENGTH);
|
||||
|
||||
// Call ENTRYN. This sets up A2-3D2. We need to preserve processor state and ZP.
|
||||
// Call ENTRYN. This sets up A2-3D2.
|
||||
__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);
|
||||
// Save A2-3D2s ZP for later.
|
||||
scdMemCpy((byte *)A23D2_ZP_SAVE, (byte *)A23D2_ZP_START, A23D2_ZP_LENGTH);
|
||||
|
||||
// Restore ZP that A2-3D2 clobbered.
|
||||
scdMemCpy((byte *)COMPILER_ZP_START, (byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), COMPILER_ZP_LENGTH);
|
||||
scdMemCpy((byte *)COMPILER_ZP_START, (byte *)COMPILER_ZP_SAVE, COMPILER_ZP_LENGTH);
|
||||
|
||||
// Put back the RAM we clobbered.
|
||||
scdMemCpy((byte *)A23D2_TEST_DATABASE, (byte *)(SCRATCH_END - 0x06), 0x06);
|
||||
|
@ -204,11 +204,10 @@ void a23d2Render(void) {
|
|||
_cameraInDatabase->h = _camera->h;
|
||||
|
||||
// Save ZP that A2-3D2 is going to clobber.
|
||||
scdMemCpy((byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), (byte *)COMPILER_ZP_START, COMPILER_ZP_LENGTH);
|
||||
scdMemCpy((byte *)COMPILER_ZP_SAVE, (byte *)COMPILER_ZP_START, COMPILER_ZP_LENGTH);
|
||||
|
||||
// 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);
|
||||
// Restore A2-3D2s ZP.
|
||||
scdMemCpy((byte *)A23D2_ZP_START, (byte *)A23D2_ZP_SAVE, A23D2_ZP_LENGTH);
|
||||
|
||||
// Set IBP.
|
||||
POKEW(A23D2_IBP, DATABASE);
|
||||
|
@ -216,12 +215,11 @@ void a23d2Render(void) {
|
|||
// Call NXTPT.
|
||||
__attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_NXTPT) : "a","x","y","c","v"); // Call NXTPT.
|
||||
|
||||
// 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);
|
||||
// Save A2-3D2s ZP for later.
|
||||
scdMemCpy((byte *)A23D2_ZP_SAVE, (byte *)A23D2_ZP_START, A23D2_ZP_LENGTH);
|
||||
|
||||
// Restore ZP that A2-3D2 clobbered.
|
||||
scdMemCpy((byte *)COMPILER_ZP_START, (byte *)(SCRATCH_END - COMPILER_ZP_LENGTH), COMPILER_ZP_LENGTH);
|
||||
scdMemCpy((byte *)COMPILER_ZP_START, (byte *)COMPILER_ZP_SAVE, COMPILER_ZP_LENGTH);
|
||||
|
||||
// Restore memory map.
|
||||
POKE(MMU_MEM_BANK_4, 4);
|
||||
|
|
10
src/a23d2.h
10
src/a23d2.h
|
@ -62,21 +62,19 @@ typedef uint8_t byte;
|
|||
#define A23D2_TEST_DATABASE 0x80fb
|
||||
#define A23D2_TDATA 0x613e
|
||||
#define A23D2_IBP 0x9b
|
||||
#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
|
||||
#define A23D2_ZP_START COMPILER_ZP_START
|
||||
#define A23D2_ZP_LENGTH COMPILER_ZP_LENGTH
|
||||
|
||||
// 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
|
||||
#define COMPILER_ZP_SAVE (CAMERA_SHARED_START + CAMERA_SHARED_LENGTH)
|
||||
#define A23D2_ZP_SAVE (COMPILER_ZP_SAVE + COMPILER_ZP_LENGTH)
|
||||
|
||||
|
||||
// A2-3D1 Commands. Commented out items are Apple ][ only.
|
||||
|
|
15
src/main.c
15
src/main.c
|
@ -113,6 +113,11 @@
|
|||
* code calls into slots 2 to 4 has a program counter between 0xa000 and
|
||||
* 0xbfff - well out of the way of the 3D stuff.
|
||||
*
|
||||
* When enabling compiler optimizations, both the compiler and A2-3D2 want
|
||||
* use of the remaining zero page. We maintain copies of the area that
|
||||
* gets clobbered by each and make sure the right one is in place at the
|
||||
* right time.
|
||||
*
|
||||
* The last thing to worry about is data needed by both the simulator and
|
||||
* A2-3D2. This is basically only the camera position and rotation. These
|
||||
* 10 bytes will be stored directly into RAM from 0x200 to 0x20a overwriting
|
||||
|
@ -601,14 +606,14 @@ void runSimulation(void) {
|
|||
// Erase old scene.
|
||||
bitmapSetColor(0);
|
||||
_useColor = false;
|
||||
textPrint("a23d2Draw()\n");
|
||||
//textPrint("a23d2Draw()\n");
|
||||
a23d2Draw();
|
||||
|
||||
// Draw new scene.
|
||||
textPrint("a23d2Render()\n");
|
||||
//textPrint("a23d2Render()\n");
|
||||
a23d2Render();
|
||||
_useColor = true;
|
||||
textPrint("a23d2Draw()\n");
|
||||
//textPrint("a23d2Draw()\n");
|
||||
a23d2Draw();
|
||||
|
||||
#if 0
|
||||
|
@ -670,7 +675,7 @@ int main(int argc, char *argv[]) {
|
|||
// Load EGA palette into CLUT0.
|
||||
for (c=0; c<16; c++) graphicsDefineColor(0, c, ega[c][0], ega[c][1], ega[c][2]);
|
||||
|
||||
textPrint("a23d2Init()\n");
|
||||
//textPrint("a23d2Init()\n");
|
||||
a23d2Init();
|
||||
|
||||
_camera->x = 5000;
|
||||
|
@ -691,7 +696,7 @@ int main(int argc, char *argv[]) {
|
|||
bitmapSetVisible(0, true);
|
||||
bitmapSetVisible(1, false);
|
||||
|
||||
textPrint("runSimulation()\n");
|
||||
//textPrint("runSimulation()\n");
|
||||
runSimulation();
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue