summaryrefslogtreecommitdiff
path: root/source/arm-linux/main.c
blob: a6b270bf650e65290129c1c9585a56f04c8b2f20 (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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>

#include "main.h"
#include "v810_mem.h"
#include "drc_core.h"
#include "vb_dsp.h"
#include "vb_set.h"
#include "vb_gui.h"
#include "rom_db.h"

int arm_keys;
void sigint_handler(int sig) {
    int i;
    if (!scanf("%d", &i)) {
        drc_dumpDebugInfo();
        v810_exit();
        V810_DSP_Quit();
        drc_exit();
        exit(1);
    }
    arm_keys = 0xffffffff;
}

int main(int argc, char* argv[]) {
    int qwe;
    int frame = 0;
    int err = 0;
    static int Left = 0;
    int skip = 0;
    signal(SIGINT, sigint_handler);

    setDefaults();
    if (loadFileOptions() < 0)
        saveFileOptions();

    V810_DSP_Init();

    if (argc < 2) {
        printf("Usage: r3Ddragon [ROM file]\n");
        return 1;
    }

    tVBOpt.ROM_NAME = argv[1];
    printf("Opening %s\n", argv[1]);

    if (!v810_init(argv[1])) {
        goto exit;
    }

    v810_reset();
    drc_init();

    clearCache();

    while(1) {
        uint64_t startTime = 0;

        int keys = 0;

//        if (0) {
//            openMenu(&main_menu);
//            if (guiop & GUIEXIT) {
//                goto exit;
//            }
//        }

        for (qwe = 0; qwe <= tVBOpt.FRMSKIP; qwe++) {
            err = drc_run();
            if (err) {
                dprintf(0, "[DRC]: error #%d @ PC=0x%08X\n", err, v810_state->PC);
                printf("\nDumping debug info...\n");
                drc_dumpDebugInfo();
                goto exit;
            }

            // Display a frame, only after the right number of 'skips'
            if((tVIPREG.FRMCYC & 0x00FF) < skip) {
                skip = 0;
                Left ^= 1;
            }

            // Increment skip
            skip++;
            frame++;
        }

        // Display
        if (tVIPREG.DPCTRL & 0x0002) {
            V810_Dsp_Frame(Left); //Temporary...
        }
    }

exit:
    v810_exit();
    V810_DSP_Quit();
    drc_exit();
    return 0;
}