-
Notifications
You must be signed in to change notification settings - Fork 1
/
trainyard.c
179 lines (145 loc) · 3.7 KB
/
trainyard.c
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <arch/zxn.h>
#include <z80.h>
#include <input.h>
#include <stdlib.h>
#include "types.h"
////////////////////////////////////////////////////
// this block here for measuring code start location
// dummydummer function must be here
ubyte dummydummer() { return 0; }
extern ubyte start_of_code;
__asm
_start_of_code:
DEFB 0
__endasm
////////////////////////////////////////////////////
#include "types.h"
#include <input.h>
#include <stdlib.h>
// #include "zxlib/keyb.h"
// #include "zxlib/keyb.c"
#define WAIT_FOR_SCANLINE(line) { \
while (ZXN_READ_REG(REG_ACTIVE_VIDEO_LINE_L) == line); \
while (ZXN_READ_REG(REG_ACTIVE_VIDEO_LINE_L) != line); }
#include "params.h"
#include "train.h"
#include "tilesymbols.h"
#include "colors.h"
#include "spmgr.h"
#include "level.h"
#include "board.h"
#include "design.h"
#include "print_tile.h"
#include "mouse.h"
#include "keyb.h"
#include "joystick.h"
#include "gui.h"
#include "io.h"
#include "screen_controller.h"
#include "screen_tests.h"
#include "screen_main.h"
#include "screen_provs.h"
#include "screen_levels.h"
#include "screen_game.h"
#include "screen_epilog.h"
#include "player_data.h"
#include "page0.h"
#include "sound.h"
#include <string.h>
__asm
EXTERN load_static_sprites
EXTERN setup_tilemap
EXTERN setup_sprites
__endasm;
int main(void)
{
// CPU SPEED
// register $07, bits 1-0
// %00 = 3.5MHz
// %01 = 7MHz
// %10 = 14MHz
// %11 = 28MHz (works since core 3.0)
//__asm__("NEXTREG $07, %00");
__asm
LD A, $07
CALL ReadNextReg
AND A, %11111100
OR A, %00000011
NEXTREG $07, A
__endasm;
zx_border(INK_BLACK);
#define WAIT_ON_START
#ifdef WAIT_ON_START
uword waitframes = 50;
while (waitframes--) {
WAIT_FOR_SCANLINE(254);
WAIT_FOR_SCANLINE(255);
}
#endif
// initialize player data, loading while splash is still visible
pd_init();
// sprites must be loaded first, before 0x4000-0x7FFF gets overwritten
__asm__("CALL load_static_sprites");
// level_pagein_levels();
__asm__("CALL setup_tilemap");
__asm__("CALL setup_sprites");
spmgr_init();
keyb_init();
joystick_init();
mouse_init();
snd_init();
sc_switch_screen(si_enter, si_update, NULL);
// sc_switch_screen(so_enter, so_update, NULL);
// sc_switch_screen(sm_enter, sm_update, NULL);
// sc_switch_screen(sp_enter, sp_update, NULL);
// sc_switch_screen(se_enter, se_update, NULL);
// sc_switch_screen(sa_enter, sa_update, NULL);
// sg_level_idx = 54;
// sc_switch_level(sg_level_idx);
// sc_switch_screen(sta_enter, sta_update, NULL);
// sc_switch_screen(sv_enter, sv_update, NULL);
// sc_switch_screen(sw_enter, sw_update, NULL);
while(1) {
joystick_update();
// joystick_print();
keyb_update();
// keyb_print();
mouse_update();
// update sound
snd_update();
// update screen controller
sc_update();
WAIT_FOR_SCANLINE(255);
}
//NEXTREG(0x15, 0b00010011);
}
// pd_init in player_data.c should be in $8000 - $9FFF slot
#include "player_data.c"
#include "train.c"
#include "board.c"
#include "spmgr.c"
#include "level.c"
#include "design.c"
#include "print_tile.c"
#include "mouse.c"
#include "keyb.c"
#include "joystick.c"
#include "gui.c"
#include "io.c"
#include "screen_controller.c"
#include "screen_tests.c"
#include "screen_main.c"
#include "screen_provs.c"
#include "screen_levels.c"
#include "screen_game.c"
#include "screen_epilog.c"
#include "sound.c"
// #include "page0.c"
__asm
#include "params.asm"
#include "setup_tilemap.asm"
#include "setup_sprites.asm"
#include "trackdefs.asm"
#include "train_sprites_def.asm"
#include "levels.asm"
__endasm;