- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
Latest commit
66 lines (54 loc) · 1.85 KB
/
Copy pathmain.cpp
File metadata and controls
66 lines (54 loc) · 1.85 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
//
// main.cpp
// Playdate Native
//
// Created by Max Weisel on 10/19/19.
// Copyright © 2019 Max Weisel. All rights reserved.
//
#include<memory>
#include"Config.h"
#include"Playdate/Playdate.h"
usingnamespacestd;
extern"C" {
#include"pd_api.h"
static unique_ptr<APPLICATION_CLASS> __application;
#if TARGET_PLAYDATE
// Sets up the BSS segment, clearing global variables
voidSetupExtension(void);
#endif
inteventHandler(PlaydateAPI* playdate, PDSystemEvent event, uint32_t argument) {
switch (event) {
casekEventGetHeapPosition: // device only--use template code for this! :)
#if TARGET_PLAYDATE
externchar bssend asm("__bss_end__");
return (int)&bssend;
#else
return0;
#endif
casekEventGetVersion: // return API_VERSION
returnAPI_VERSION;
casekEventInit: // should call SetupExtension() on the device to intialize globals
#if TARGET_PLAYDATE
SetupExtension();
#endif
// Setup Playdate C++ API
SetPlaydateAPI(playdate);
// Create application
__application = unique_ptr<APPLICATION_CLASS>(newAPPLICATION_CLASS());
return0;
casekEventTerminate:
// Destroy application
__application = nullptr;
return0;
default:
// Dispatch event to application
if (__application)
return __application->HandleEvent(event, argument);
else
return0;
}
}
#if TARGET_PLAYDATE
PDEventHandler* PD_eventHandler __attribute__((section(".extension_reg"))) = &eventHandler;
#endif
}