1 /*
2  * This file is part of libbdplus
3  * Copyright (C) 2008-2010  Accident
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see
17  * <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "event.h"
21 
22 #include "dlx_internal.h"
23 
24 #include "util/logging.h"
25 #include "util/macro.h"
26 
27 #include <string.h>
28 #include <stdlib.h>
29 #include <gcrypt.h>
30 
bdplus_send_event(VM * vm,uint32_t eventID,uint32_t arg1,uint32_t table,uint32_t segment)31 void bdplus_send_event(VM *vm, uint32_t eventID, uint32_t arg1,
32                        uint32_t table, uint32_t segment)
33 {
34 
35     BD_DEBUG(DBG_BDPLUS_EVENT,"[bdplus] ** posting EVENT %X (%08X, %d, %d)\n", eventID,
36           arg1, table, segment);
37 
38     if (!vm || !vm->addr) return;
39 
40     STORE4( &vm->addr[ 0x0 ], eventID );
41     STORE4( &vm->addr[ 0x4 ], arg1    );
42     STORE4( &vm->addr[ 0x8 ], table   );
43     if (eventID == EVENT_ComputeSP) {
44 
45         STORE4( &vm->addr[ 0xC ], segment );
46         STORE4( &vm->addr[ 0x20 ], 0 ); // Set by Jumper, clearing MASK?
47         STORE4( &vm->addr[ 0x24 ], 0 ); // Set by Jumper
48 #if 0
49         /* this should be set already ... */
50         if (plus->conv_tab)
51             segment_setSegment(plus->conv_tab, table, segment);
52 #endif
53     }
54 
55     // Remember break location?
56     // send_event sets R28, but it MUST be clear to start.
57 
58     // If we are Starting, don7t touch R28, since they must all be 0 at start.
59     if (eventID != EVENT_Start)
60         vm->R[28] = dlx_getPC(vm);
61 
62     dlx_setPC(vm, 0x1000);
63     dlx_setWD(vm, 0x7FFFFFFF);
64     vm->event_processing = 1;
65     vm->event_current = eventID;
66 }
67