File: dc_vmu.cpp

package info (click to toggle)
wolf4sdl 1.7+svn262+dfsg1-5
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye, buster, sid
  • size: 4,112 kB
  • sloc: cpp: 34,696; ansic: 1,257; objc: 246; makefile: 159; sh: 44
file content (181 lines) | stat: -rw-r--r-- 4,417 bytes parent folder | download | duplicates (4)
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
//Wolf4SDL\DC
//dc_vmu.cpp
//2009 - Cyle Terry

#if defined(_arch_dreamcast)

#include <string.h>
#include "../wl_def.h"
#include "dc/maple.h"
#include "dc/maple/controller.h"
#include "dc/maple/vmu.h"
#include "dc/vmu_pkg.h"
#include "kos/fs.h"
#include "zlib/zlib.h"
#include "dc_vmu.h"

maple_device_t *vmu_lcd_addr[8];

void DC_StatusDrawLCD(int lcd) {
    const char *character;
    int x, y;
    int xi, xb;
    int i = 0;
    uint8 bitmap[48 * 32 / 8];
    maple_device_t *vmu_lcd_addr;

    memset(bitmap, 0, sizeof(bitmap));
    character = e_BJFaces[lcd - FACE1APIC];

    if(character) {
        for(y = 0; y < LCD_HEIGHT; y++) {
            for(x = 0; x < LCD_WIDTH; x++) {
                xi = x / 8;
                xb = 0x80 >> (x % 8);
                if(character[(31 - y) * 48 + (47 - x)] == '.')
                    bitmap[y * (48 / 8) + xi] |= xb;
            }
        }
    }

    while ((vmu_lcd_addr = maple_enum_type(i++, MAPLE_FUNC_LCD)))
        vmu_draw_lcd(vmu_lcd_addr, bitmap);
    vmu_shutdown ();
}

void DC_StatusClearLCD() {
    int x, y;
    int xi;
    int i = 0;
    uint8 bitmap[48 * 32 / 8];
    maple_device_t *vmu_lcd_addr;

    memset(bitmap, 0, sizeof(bitmap));
    for(y = 0; y < LCD_HEIGHT; y++) {
        for(x = 0; x < LCD_WIDTH; x++) {
            xi = x / 8;
            bitmap[y * (48 / 8) + xi] |= 0;
        }
    }

    while ((vmu_lcd_addr = maple_enum_type(i++, MAPLE_FUNC_LCD)))
        vmu_draw_lcd(vmu_lcd_addr, bitmap);
    vmu_shutdown ();
}


void DC_SaveToVMU(char *fname, char *str) {
    char destination[32];
    int filesize = 0;
    int vmu_package_size;
    unsigned long  zipsize = 0;
    unsigned char *vmu_package_out;
    unsigned char *data;
    unsigned char *zipdata;
    file_t file;
    vmu_pkg_t vmu_package;

    DiskFlopAnim(102, 85);

    strcpy(destination, "/vmu/a1/");
    strcat(destination, fname);
    file = fs_open(fname, O_RDONLY);
    filesize = fs_total(file);
    data = (unsigned char*)malloc(filesize);
    fs_read(file, data, filesize);
    fs_close(file);

    DiskFlopAnim(102, 85);

    zipsize = filesize * 2;
    zipdata = (unsigned char*)malloc(zipsize);
    compress(zipdata, &zipsize, data, filesize);

    DiskFlopAnim(102, 85);

#ifdef SPEAR
    strcpy(vmu_package.desc_short, "Sod4SDL\\DC");
    strcpy(vmu_package.app_id, "Sod4SDL\\DC");
#else
    strcpy(vmu_package.desc_short, "Wolf4SDL\\DC");
    strcpy(vmu_package.app_id, "Wolf4SDL\\DC");
#endif
    if(str == NULL)
        strcpy(vmu_package.desc_long, "Configuration");
    else {
        strcpy(vmu_package.desc_long, "Game Save - ");
        strcat(vmu_package.desc_long, str);
    }

    vmu_package.icon_cnt = 1;
    vmu_package.icon_anim_speed = 0;
    memcpy(&vmu_package.icon_pal[0], vmu_bios_save_icon, 32);
    vmu_package.icon_data = vmu_bios_save_icon + 32;
    vmu_package.eyecatch_type = VMUPKG_EC_NONE;
    vmu_package.data_len = zipsize;
    vmu_package.data = zipdata;
    vmu_pkg_build(&vmu_package, &vmu_package_out, &vmu_package_size);

    DiskFlopAnim(102, 85);

    fs_unlink(destination);
    file = fs_open(destination, O_WRONLY);
    fs_write(file, vmu_package_out, vmu_package_size);
    fs_close(file);

    DiskFlopAnim(102, 85);

    free(vmu_package_out);
    free(data);
    free(zipdata);
}


int DC_LoadFromVMU(char *fname) {
    char fpath[64];
    int file;
    int filesize;
    unsigned long unzipsize;
    unsigned char *data;
    unsigned char *unzipdata;
    vmu_pkg_t vmu_package;

    sprintf(fpath, "/vmu/a1/%s", fname);
    file = fs_open(fpath, O_RDONLY);
    if(file == 0) return 0;
    filesize = fs_total(file);
    if(filesize <= 0) return 0;
    data = (unsigned char*)malloc(filesize);
    fs_read(file, data, filesize);
    fs_close(file);

    if(!strcmp(fname, configname))
        DiskFlopAnim(102, 85);

    vmu_pkg_parse(data, &vmu_package);

    if(!strcmp(fname, configname))
        DiskFlopAnim(102, 85);

    unzipdata = (unsigned char*)malloc(65536);
    unzipsize = 65536;
    uncompress(unzipdata, &unzipsize, (unsigned char*)vmu_package.data, vmu_package.data_len);

    if(!strcmp(fname, configname))
        DiskFlopAnim(102, 85);

    fs_unlink(fname);
    file = fs_open(fname, O_WRONLY);
    fs_write(file, unzipdata, unzipsize);
    fs_close(file);

    if(!strcmp(fname, configname))
        DiskFlopAnim(102, 85);

    free(data);
    free(unzipdata);

    return 1;
}

#endif