diff --git a/build.sh b/build.sh index 5b4065c..11d7103 100755 --- a/build.sh +++ b/build.sh @@ -28,7 +28,7 @@ PROJECT=shotel F256=$(readlink -f $(pwd)/../f256) LLVM=${F256}/llvm-mos PATH=${LLVM}/bin:${PATH} -CLANG="mos-f256k-clang -I${F256} -I$(pwd)/src -Os" +CLANG="mos-f256k-clang -I${F256} -I$(pwd)/src -Os -Wall" # Update f256lib and tools. diff --git a/src/a23d2.c b/src/a23d2.c index e3359dd..d44954e 100644 --- a/src/a23d2.c +++ b/src/a23d2.c @@ -26,13 +26,13 @@ #include // For memcopy -cameraT *_camera = (cameraT *)0x200; // Simulation copy of camera. -cameraT *_cameraInDatabase; +volatile cameraT *_camera = (cameraT *)0x200; // Simulation copy of camera. +volatile cameraT *_cameraInDatabase; +volatile byte *_pointer; uint16_t _drawlist; uint16_t _drawlistInDatabase; -byte *_pointer; uint16_t _bytes; uint8_t _x1; uint8_t _y1; @@ -41,7 +41,7 @@ uint8_t _y2; bool _useColor; byte _mmu; byte _ram; -float _trig; +//float _trig; #define SEGMENT_A23D2 @@ -50,14 +50,28 @@ float _trig; // There's a lot of global use in here. We can't use the virtual stack. +#if 0 void a23d2Cos(void) { + // 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. + POKE(MMU_MEM_BANK_3, A23D2_FAR_BLOCK); + // Map 0-359 into 0-255. _tdata = _tdata % 359; _y1 = (360/256) * _tdata; + + // Call COSEX. POKE(A23D2_TDATA, _y1); - asm("jsr %[addy]":: [addy] "i"(A23D2_COSEX)); + __attribute__((leaf)) asm volatile("jsr %[addy]":: [addy] "i"(A23D2_COSEX)); + + // Convert to float. _trig = (float)PEEKW(A23D2_TDATA) / 32768; + + // Restore memory map. + POKE(MMU_MEM_BANK_3, 3); } +#endif void a23d2Draw(void) { @@ -118,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 *)0x2f7, (byte *)A23D2_TEST_DATABASE, 0x06); + memcpy((byte *)(0x2ff - 0x06), (byte *)A23D2_TEST_DATABASE, 0x06); // Initialize A2-3D2 so we can use the "fast entry point" (NXTPT) when rendering. _bytes = 0; @@ -130,11 +144,11 @@ void a23d2Init(void) { _pointer[_bytes++] = 0; _pointer[_bytes++] = END; // Setup complete! - asm("jsr %[addy]":: [addy] "i"(A23D2_ENTRYS)); // Call ENTRYS. This preserves the ZP for us. -// asm("jsr 0x606c"); // Call ENTRYS. This preserves the ZP for us. +// __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. // Put back the RAM we clobbered. - memcpy((byte *)A23D2_TEST_DATABASE, (byte *)0x2f7, 0x06); + memcpy((byte *)A23D2_TEST_DATABASE, (byte *)(0x2ff - 0x06), 0x06); // Move our 3D/2D data buffer at 0x56000 into slot 4. POKE(MMU_MEM_BANK_4, DATABASE_FAR_BLOCK); @@ -160,6 +174,8 @@ 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. @@ -179,11 +195,30 @@ void a23d2Render(void) { _cameraInDatabase->b = _camera->b; _cameraInDatabase->h = _camera->h; - memcpy((byte *)0x29d, (byte *)A23D2_ZP_START, A23D2_ZP_LENGTH); // Save the ZP we're going to clobber. - POKEW(A23D2_IBP, DATABASE); // Set IBP. - __attribute__((leaf)) asm("jsr %[addy]":: [addy] "i"(A23D2_NXTPT) : "a","x","y","c","v"); // Call NXTPT. -// __attribute__((leaf)) asm("jsr 0x6118"::: "a","x","y","c","v"); // Call NXTPT. - memcpy((byte *)A23D2_ZP_START, (byte *)0x29d, A23D2_ZP_LENGTH); // Put the ZP back. + //memcpy((byte *)(0x2ff - A23D2_ZP_LENGTH), (byte *)A23D2_ZP_START, A23D2_ZP_LENGTH); // Save the ZP we're going to clobber. + + for (i=0; ip += 1; // Change pitch angle. - _camera->b += 2; // Change bank angle. - _camera->h += 3; // Change heading angle. + //_camera->p += 1; // Change pitch angle. + //_camera->b += 2; // Change bank angle. + _camera->h += 1; // Change heading angle. } } @@ -660,8 +670,14 @@ 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"); a23d2Init(); + _camera->x = 5000; + _camera->y = 1000; + _camera->z = 5000; + _camera->p = 25; + // Set up bitmap planes. for (c=0; c<2; c++) { // Clear screen. @@ -675,6 +691,7 @@ int main(int argc, char *argv[]) { bitmapSetVisible(0, true); bitmapSetVisible(1, false); + textPrint("runSimulation()\n"); runSimulation(); return 0; diff --git a/tools/scene.c b/tools/scene.c index 1f00b3c..f673960 100644 --- a/tools/scene.c +++ b/tools/scene.c @@ -107,9 +107,9 @@ void landscape(void) { } // Runway - 3000' x 100' - min = 1500; + min = 3500; max = min + 300; - x = 1500; + x = 3500; db[bytes++] = STCOL; db[bytes++] = 8; // Dark Grey for (i=0; i<=10; i+=2) {