-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (54 loc) · 1.85 KB
/
main.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"
using namespace std;
extern "C" {
#include "pd_api.h"
static unique_ptr<APPLICATION_CLASS> __application;
#if TARGET_PLAYDATE
// Sets up the BSS segment, clearing global variables
void SetupExtension(void);
#endif
int eventHandler(PlaydateAPI* playdate, PDSystemEvent event, uint32_t argument) {
switch (event) {
case kEventGetHeapPosition: // device only--use template code for this! :)
#if TARGET_PLAYDATE
extern char bssend asm("__bss_end__");
return (int)&bssend;
#else
return 0;
#endif
case kEventGetVersion: // return API_VERSION
return API_VERSION;
case kEventInit: // 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>(new APPLICATION_CLASS());
return 0;
case kEventTerminate:
// Destroy application
__application = nullptr;
return 0;
default:
// Dispatch event to application
if (__application)
return __application->HandleEvent(event, argument);
else
return 0;
}
}
#if TARGET_PLAYDATE
PDEventHandler* PD_eventHandler __attribute__((section(".extension_reg"))) = &eventHandler;
#endif
}