about summary refs log tree commit diff stats
path: root/src/libtools/sdl1align32.c
blob: cb0b8176a95548ea49063128da477ae69a9a84a4 (plain) (blame)
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
187
188
189
190
191
192
193
194
195
196
197
198
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stddef.h>
#include <wchar.h>
#include <sys/epoll.h>
#include <fts.h>
#include <sys/socket.h>

#include "x64emu.h"
#include "emu/x64emu_private.h"
#include "myalign32.h"
#include "debug.h"
#include "box32.h"
#include "sdl1align32.h"


void inplace_SDL_Palette_to_64(void* a) {
    if(!a) return;
    my_SDL_Palette_32_t* src = a;
    my_SDL_Palette_t* dst = a;
    dst->colors = from_ptrv(src->colors);
}
void inplace_SDL_Palette_to_32(void* a) {
    if(!a) return;
    my_SDL_Palette_t* src = a;
    my_SDL_Palette_32_t* dst = a;
    dst->colors = to_ptrv(src->colors);
}
void inplace_SDL_PixelFormat_to_64_nopalette(void* a) {
    if(!a) return;
    my_SDL_PixelFormat_32_t* src = a;
    my_SDL_PixelFormat_t* dst = a;
    memmove(&dst->BitsPerPixel, &src->BitsPerPixel, sizeof(my_SDL_PixelFormat_t)-offsetof(my_SDL_PixelFormat_t, BitsPerPixel));
    dst->palette = from_ptrv(src->palette);
}
void inplace_SDL_PixelFormat_to_64(void* a) {
    if(!a) return;
    my_SDL_PixelFormat_32_t* src = a;
    my_SDL_PixelFormat_t* dst = a;
    memmove(&dst->BitsPerPixel, &src->BitsPerPixel, sizeof(my_SDL_PixelFormat_t)-offsetof(my_SDL_PixelFormat_t, BitsPerPixel));
    dst->palette = from_ptrv(src->palette);
    inplace_SDL_Palette_to_64(dst->palette);
}
void inplace_SDL_PixelFormat_to_32(void* a) {
    if(!a) return;
    my_SDL_PixelFormat_t* src = a;
    my_SDL_PixelFormat_32_t* dst = a;
    inplace_SDL_Palette_to_32(src->palette);
    dst->palette = to_ptrv(src->palette);
    memmove(&dst->BitsPerPixel, &src->BitsPerPixel, sizeof(my_SDL_PixelFormat_32_t)-offsetof(my_SDL_PixelFormat_32_t, BitsPerPixel));
}

void inplace_SDL_Surface_to_64(void* a) {
    if(!a) return;
    my_SDL_Surface_32_t* src = a;
    my_SDL_Surface_t* dst = a;
    dst->refcount = src->refcount;
    dst->format_version = src->format_version;
    dst->map = from_ptrv(src->map);
    dst->locked = src->locked;
    dst->unused1 = src->unused1;
    memmove(&dst->clip_rect, &src->clip_rect, sizeof(dst->clip_rect));
    dst->hwdata = from_ptrv(src->hwdata);
    dst->offset = src->offset;
    dst->pixels = from_ptrv(src->pixels);
    dst->pitch = src->pitch;
    dst->h = src->h;
    dst->w = src->w;
    dst->format = from_ptrv(src->format);
    inplace_SDL_PixelFormat_to_64(dst->format);
}
void inplace_SDL_Surface_to_32(void* a) {
    if(!a) return;
    my_SDL_Surface_t* src = a;
    my_SDL_Surface_32_t* dst = a;
    inplace_SDL_PixelFormat_to_32(src->format);
    dst->format = to_ptrv(src->format);
    dst->w = src->w;
    dst->h = src->h;
    dst->pitch = src->pitch;
    dst->pixels = to_ptrv(src->pixels);
    dst->offset = src->offset;
    dst->hwdata = to_ptrv(src->hwdata);
    memmove(&dst->clip_rect, &src->clip_rect, sizeof(dst->clip_rect));
    dst->unused1 = src->unused1;
    dst->locked = src->locked;
    dst->map = to_ptrv(src->map);
    dst->format_version = src->format_version;
    dst->refcount = src->refcount;
}


void convert_SDL_Event_to_32(void* dst_, const void* src_)
{
    if(!src_|| !dst_) return;
    const my_SDL_Event_t *src = src_;
    my_SDL_Event_32_t* dst = dst_;
    dst->type = src->type;
    switch(src->type) {
        case SDL_ACTIVEEVENT:
            dst->active.gain = src->active.gain;
            dst->active.state = src->active.state;
            break;
        case SDL_KEYUP:
        case SDL_KEYDOWN:
            dst->key.keysym.mod = src->key.keysym.mod;
            dst->key.keysym.scancode = src->key.keysym.scancode;
            dst->key.keysym.sym = src->key.keysym.sym;
            dst->key.keysym.unicode = src->key.keysym.unicode;
            dst->key.state = src->key.state;
            dst->key.which = dst->key.which;
            break;
        case SDL_MOUSEMOTION:
            dst->motion.state = src->motion.state;
            dst->motion.which = src->motion.which;
            dst->motion.x = src->motion.x;
            dst->motion.y = src->motion.y;
            dst->motion.xrel = src->motion.xrel;
            dst->motion.yrel = src->motion.yrel;
            break;
        case SDL_MOUSEBUTTONUP:
        case SDL_MOUSEBUTTONDOWN:
            dst->button.button = src->button.button;
            dst->button.state = src->button.state;
            dst->button.which = src->button.which;
            dst->button.x = src->button.x;
            dst->button.y = src->button.y;
            break;
        case SDL_JOYAXISMOTION:
            dst->jaxis.axis = src->jaxis.axis;
            dst->jaxis.value = src->jaxis.value;
            dst->jaxis.which = src->jaxis.which;
            break;
        case SDL_JOYBALLMOTION:
            dst->jball.ball = src->jball.ball;
            dst->jball.which = src->jball.which;
            dst->jball.xrel = src->jball.xrel;
            dst->jball.yrel = src->jball.yrel;
            break;
        case SDL_JOYHATMOTION:
            dst->jhat.hat = src->jhat.hat;
            dst->jhat.value = src->jhat.value;
            dst->jhat.which = src->jhat.which;
            break;
        case SDL_JOYBUTTONUP:
        case SDL_JOYBUTTONDOWN:
            dst->jbutton.button = src->jbutton.button;
            dst->jbutton.state = src->jbutton.state;
            dst->jbutton.which = src->jbutton.which;
            break;
        case SDL_VIDEORESIZE:
            dst->resize.h = src->resize.h;
            dst->resize.w = src->resize.w;
            break;
        case SDL_VIDEOEXPOSE:
        case SDL_QUIT:
            break;
        case SDL_USEREVENT:
            dst->user.code = src->user.code;
            dst->user.data1 = to_ptrv(src->user.data1);
            dst->user.data2 = to_ptrv(src->user.data2);
        case SDL_SYSWMEVENT:
            printf_log(LOG_NONE, "TODO: Convert SDL_SYSWMEVENT\n");
            abort();
            break;
        default:
            printf_log(LOG_INFO, "Warning, unsuported SDL1.2 event %d\n", src->type);
            memcpy(dst, src, sizeof(my_SDL_Event_32_t));
    }
}

void inplace_SDL_RWops_to_64(void* a)
{
    if(!a) return;
    my_SDL_RWops_32_t* src = a;
    my_SDL_RWops_t* dst = a;
    memmove(&dst->hidden, &src->hidden, sizeof(dst->hidden));
    dst->type = src->type;
    dst->close = from_ptrv(src->close);
    dst->write = from_ptrv(src->write);
    dst->read = from_ptrv(src->read);
    dst->seek = from_ptrv(src->seek);

}
void inplace_SDL_RWops_to_32(void* a)
{
    if(!a) return;
    my_SDL_RWops_t* src = a;
    my_SDL_RWops_32_t* dst = a;
    dst->seek = to_ptrv(src->seek);
    dst->read = to_ptrv(src->read);
    dst->write = to_ptrv(src->write);
    dst->close = to_ptrv(src->close);
    dst->type = src->type;
    memmove(&dst->hidden, &src->hidden, sizeof(dst->hidden));
}