Add initial bits for Qt6 support
[carla.git] / source / modules / ysfx / sources / ysfx_eel_utils.cpp
bloba9a247b29c019a8407a9b9a174fb5c3b780567c6
1 // Copyright 2021 Jean Pierre Cimalando
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // SPDX-License-Identifier: Apache-2.0
18 #include "ysfx_eel_utils.hpp"
20 ysfx_eel_ram_reader::ysfx_eel_ram_reader(NSEEL_VMCTX vm, int64_t addr)
21 : m_vm(vm),
22 m_addr(addr)
26 EEL_F ysfx_eel_ram_reader::read_next()
28 if (m_block_avail == 0) {
29 m_block = (m_addr < 0 || m_addr > 0xFFFFFFFFu) ? nullptr :
30 NSEEL_VM_getramptr_noalloc(m_vm, (uint32_t)m_addr, (int32_t *)&m_block_avail);
31 if (m_block)
32 m_addr += m_block_avail;
33 else {
34 m_addr += 1;
35 m_block_avail = 1;
38 EEL_F value = m_block ? *m_block++ : 0;
39 m_block_avail -= 1;
40 return value;
43 //------------------------------------------------------------------------------
44 ysfx_eel_ram_writer::ysfx_eel_ram_writer(NSEEL_VMCTX vm, int64_t addr)
45 : m_vm(vm),
46 m_addr(addr)
50 bool ysfx_eel_ram_writer::write_next(EEL_F value)
52 if (m_block_avail == 0) {
53 m_block = (m_addr < 0 || m_addr > 0xFFFFFFFFu) ? nullptr :
54 NSEEL_VM_getramptr(m_vm, (uint32_t)m_addr, (int32_t *)&m_block_avail);
55 if (m_block)
56 m_addr += m_block_avail;
57 else {
58 m_addr += 1;
59 m_block_avail = 1;
62 if (m_block)
63 *m_block++ = value;
64 m_block_avail -= 1;
65 return true;