-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.c
More file actions
120 lines (104 loc) · 3.79 KB
/
Copy pathmain.c
File metadata and controls
120 lines (104 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Title: Spectrum Next 3D Engine
* Author: Dean Belfield
* Contributors: Henrique Olifiers, Michael "Flash" Ware
* Created: 20/08/2025
* Last Updated: 30/11/2025
*
* Modinfo:
* 04/09/2025: Moved models to includes in models folder
* 22/09/2025: Beta version 0.5
* 07/10/2025: Moved demo code to demos folder
* 30/11/2025: Added buffer parameter to drawObject
*/
#pragma output REGISTER_SP = 0xbfff
#include <arch/zxn.h>
#include <stdint.h> // standard names for ints with no ambiguity
#include <stdio.h>
#include <stdlib.h>
#include <z80.h>
#include <im2.h>
#include <intrinsic.h>
#include "core.h"
#include "main.h"
#include "kernel.h"
#include "render.h"
#include "clipping.h"
#include "maths.h"
#include "maths_3D.h"
#include "render_3D.h"
#include "sprites.h"
#include "experiments.h" // Work-in-progress stuff
// ***************************************************************************************************************************************
// Model data
// ***************************************************************************************************************************************
#include "models/cube.h"
#include "models/cobra_mk3.h"
// ***************************************************************************************************************************************
// Global data
// ***************************************************************************************************************************************
uint8_t renderMode = 1; // Render mode: 0=Wireframe, 1=Filled
Point16 points[64]; // Buffer for translated points
Object_3D object[MAX_OBJECTS]; // Array of objects in the world
// ***************************************************************************************************************************************
// Main startup and loop
// ***************************************************************************************************************************************
void rotate(int i) {
Object_3D * self = &object[i];
self->theta.x+=1;
self->theta.y+=2;
self->theta.z-=1;
}
void main(void)
{
// BREAK;
NextReg(0x57,2); // Page in kernel
initKernel();
initIRQs();
NextReg(0x08,0x4A); // Disable RAM contention, enable DAC and turbosound
// NextReg(0x05,0x04); // 60Hz mode
NextReg(0x15,0x21); // Enable sprites and clipping, SLU priority
setCPU(3); // 28Mhz
initL2();
zx_border(INK_BLACK);
// Set up the object
//
object[0].flags=1; // Flag that the object is active
object[0].move = &rotate; // The callback routine to move the object
object[0].model = &cobra_m; // The model to display
object[0].pos.x = 0; // The location of the object in world space
object[0].pos.y = 0;
object[0].pos.z = pd * 1.5;
object[0].theta.x = 0; // The rotation of the object around its origin
object[0].theta.y = 0;
object[0].theta.z = 0;
while(1) {
clearL2(0); // Clear the offscreen drawing buffer
readKeyboard(); // Read the keyboard
if(Keys[VK_1]) setCPU(0); // Set the turbo mode when keys 1-4 pressed
if(Keys[VK_2]) setCPU(1);
if(Keys[VK_3]) setCPU(2);
if(Keys[VK_4]) setCPU(3);
// Toggle the render mode between wireframe and filled when space pressed
//
if(Keys[VK_SPACE]) {
renderMode = 1-renderMode;
while (Keys[VK_SPACE]) {
readKeyboard();
}
}
// Loop through the objects array, draw and render any that are
// active
//
for(int i=0; i<MAX_OBJECTS; i++) {
if(object[i].flags) {
drawObject(points, &object[i], renderMode);
if(object[i].move) {
object[i].move(i);
}
}
}
waitVBlank(); // Wait for the vblank before switching
swapL2(); // Do the double-buffering
};
}