aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
blob: dce4a78a1ecf3099fc4825985330dfd392f48c72 (plain)
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
179
180
181
182
183
184
185
186
/*
    Copyright 2016-2017 StapleButter

    This file is part of melonDS.

    melonDS is free software: you can redistribute it and/or modify it under
    the terms of the GNU General Public License as published by the Free
    Software Foundation, either version 3 of the License, or (at your option)
    any later version.

    melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with melonDS. If not, see http://www.gnu.org/licenses/.
*/

#include <stdio.h>
#include <windows.h>
#include "NDS.h"
#include "GPU.h"


#define VERSION "0.1"


HINSTANCE instance;
HWND melon;
BITMAPV4HEADER bmp;
bool quit;


LRESULT CALLBACK derpo(HWND window, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch (msg)
    {
    case WM_CLOSE:
        printf("close\n");
        {
            // 6006800 6008000
            FILE* f = fopen("vramABG.bin", "wb");
            for (int i = 0; i < 128; i++)
                fwrite(GPU::VRAM_ABG[i], 16384, 1, f);
            fclose(f);
        }
        PostQuitMessage(0);
        return 0;

    case WM_KEYDOWN:
        switch (wparam)
        {
        case VK_RETURN: NDS::PressKey(3); break;
        case VK_SPACE:  NDS::PressKey(2); break;
        case VK_UP:     NDS::PressKey(6); break;
        case VK_DOWN:   NDS::PressKey(7); break;
        case VK_LEFT:   NDS::PressKey(5); break;
        case VK_RIGHT:  NDS::PressKey(4); break;
        case 'P': NDS::PressKey(16+6); break;
        case 'D': NDS::debug(0); break;
        }
        return 0;

    case WM_KEYUP:
        switch (wparam)
        {
        case VK_RETURN: NDS::ReleaseKey(3); break;
        case VK_SPACE:  NDS::ReleaseKey(2); break;
        case VK_UP:     NDS::ReleaseKey(6); break;
        case VK_DOWN:   NDS::ReleaseKey(7); break;
        case VK_LEFT:   NDS::ReleaseKey(5); break;
        case VK_RIGHT:  NDS::ReleaseKey(4); break;
        case 'P': NDS::ReleaseKey(16+6); break;
        }
        return 0;

    /*case WM_PAINT:
        {

        }
        return 0;*/
    }

    return DefWindowProc(window, msg, wparam, lparam);
}


int main()
{
    printf("melonDS version uh... 0.1??\n");
    printf("it's a DS emulator!!!\n");
    printf("http://melonds.kuribo64.net/\n");
    quit = false;

    instance = GetModuleHandle(NULL);

    // god this shit sucks
    WNDCLASSEX shit;
    shit.cbSize = sizeof(shit);
    shit.style = CS_HREDRAW | CS_VREDRAW;
    shit.lpfnWndProc = derpo;
    shit.cbClsExtra = 0;
    shit.cbWndExtra = 0;
    shit.hInstance = instance;
    shit.hIcon = NULL;
    shit.hIconSm = NULL;
    shit.hCursor = NULL;
    shit.hbrBackground = (HBRUSH)(COLOR_WINDOWFRAME+1);
    shit.lpszMenuName = NULL;
    shit.lpszClassName = "v0ltmeters";
    RegisterClassEx(&shit);

    RECT rekt;
    rekt.left = 0;    rekt.top = 0;
    rekt.right = 256; rekt.bottom = 384;
    AdjustWindowRect(&rekt, WS_OVERLAPPEDWINDOW, FALSE);

    melon = CreateWindow("v0ltmeters",
                         "melonDS " VERSION,
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT,
                         rekt.right-rekt.left, rekt.bottom-rekt.top,
                         NULL,
                         NULL,
                         instance,
                         NULL);

    ShowWindow(melon, SW_SHOW);

    // more sucky shit!
    memset(&bmp, 0, sizeof(bmp));
    bmp.bV4Size = sizeof(bmp);
    bmp.bV4Width = 256;
    bmp.bV4Height = -384;
    bmp.bV4Planes = 1;
    bmp.bV4BitCount = 16;
    bmp.bV4V4Compression = BI_RGB|BI_BITFIELDS;
    bmp.bV4RedMask = 0x001F;
    bmp.bV4GreenMask = 0x03E0;
    bmp.bV4BlueMask = 0x7C00;

    NDS::Init();

    u32 nframes = 0;
    u32 lasttick = GetTickCount();

    for (;;)
    {
        MSG msg;
        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                quit = true;
                break;
            }

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        if (quit) break;

        NDS::RunFrame();

        HDC dc = GetDC(melon);
        SetDIBitsToDevice(dc, 0, 0, 256, 384, 0, 0, 0, 384, GPU::Framebuffer, (BITMAPINFO*)&bmp, DIB_RGB_COLORS);
        UpdateWindow(melon);

        nframes++;
        if (nframes >= 30)
        {
            u32 tick = GetTickCount();
            u32 diff = tick - lasttick;
            lasttick = tick;

            u32 fps = (nframes * 1000) / diff;
            nframes = 0;

            char melontitle[100];
            sprintf(melontitle, "melonDS " VERSION " | %d FPS", fps);
            SetWindowText(melon, melontitle);
        }
    }

    return 0;
}