Files
z80/zx_ula.cpp
Raimon Zamora ddcb40b289 - Deixe el Abu Simbel ací per a anar fent proves de càrrega
- [NEW] Mòdul zx_tape, encara no carrega correctament les cintes.
- [CHG] Gestió completa del só pasada a la ULA, i de la pantalla a zxscreen
2024-04-20 09:32:57 +02:00

141 lines
4.2 KiB
C++

#include "zx_ula.h"
#include <SDL2/SDL.h>
namespace zx_ula
{
static uint8_t border_color = 0;
static uint8_t ear = 0;
static uint8_t mic = 0;
int port_in(int port)
{
const uint8_t *keys = SDL_GetKeyboardState(NULL);
const uint8_t h_addr = (port>>8);
uint8_t result = ear ? 0xbf : 0xff;
if (!(h_addr & ~0xfe))
{
result &= ~(
keys[SDL_SCANCODE_LSHIFT]*0x01 +
keys[SDL_SCANCODE_Z]*0x02 +
keys[SDL_SCANCODE_X]*0x04 +
keys[SDL_SCANCODE_C]*0x08 +
keys[SDL_SCANCODE_V]*0x10 );
}
if (!(h_addr & ~0xfd))
{
result &= ~(
keys[SDL_SCANCODE_A]*0x01 +
keys[SDL_SCANCODE_S]*0x02 +
keys[SDL_SCANCODE_D]*0x04 +
keys[SDL_SCANCODE_F]*0x08 +
keys[SDL_SCANCODE_G]*0x10 );
}
if (!(h_addr & ~0xfb))
{
result &= ~(
keys[SDL_SCANCODE_Q]*0x01 +
keys[SDL_SCANCODE_W]*0x02 +
keys[SDL_SCANCODE_E]*0x04 +
keys[SDL_SCANCODE_R]*0x08 +
keys[SDL_SCANCODE_T]*0x10 );
}
if (!(h_addr & ~0xf7))
{
result &= ~(
keys[SDL_SCANCODE_1]*0x01 +
keys[SDL_SCANCODE_2]*0x02 +
keys[SDL_SCANCODE_3]*0x04 +
keys[SDL_SCANCODE_4]*0x08 +
keys[SDL_SCANCODE_5]*0x10 );
}
if (!(h_addr & ~0xef))
{
result &= ~(
keys[SDL_SCANCODE_0]*0x01 +
keys[SDL_SCANCODE_9]*0x02 +
keys[SDL_SCANCODE_8]*0x04 +
keys[SDL_SCANCODE_7]*0x08 +
keys[SDL_SCANCODE_6]*0x10 );
}
if (!(h_addr & ~0xdf))
{
result &= ~(
keys[SDL_SCANCODE_P]*0x01 +
keys[SDL_SCANCODE_O]*0x02 +
keys[SDL_SCANCODE_I]*0x04 +
keys[SDL_SCANCODE_U]*0x08 +
keys[SDL_SCANCODE_Y]*0x10 );
}
if (!(h_addr & ~0xbf))
{
result &= ~(
keys[SDL_SCANCODE_RETURN]*0x01 +
keys[SDL_SCANCODE_L]*0x02 +
keys[SDL_SCANCODE_K]*0x04 +
keys[SDL_SCANCODE_J]*0x08 +
keys[SDL_SCANCODE_H]*0x10 );
}
if (!(h_addr & ~0x7f))
{
result &= ~(
keys[SDL_SCANCODE_SPACE]*0x01 +
keys[SDL_SCANCODE_RSHIFT]*0x02 +
keys[SDL_SCANCODE_M]*0x04 +
keys[SDL_SCANCODE_N]*0x08 +
keys[SDL_SCANCODE_B]*0x10 );
}
return result;
}
void port_out(int port, int val)
{
border_color = val & 0x7;
mic = (val>>3)&0x1;
ear = (val>>4)&0x1;
//printf("EAR:%i MIC:%i\n", ear, mic);
}
uint8_t get_border_color() { return border_color; }
uint8_t get_ear() { return ear; }
void set_ear(const uint8_t val) { ear = val; }
SDL_AudioDeviceID sdlAudioDevice;
uint8_t sound_buffer[1024];
uint16_t sound_pos;
uint16_t t_sound=0;
void audioCallback(void * userdata, uint8_t * stream, int len)
{
const uint16_t top = sound_pos < len ? sound_pos : len;
memcpy(stream, sound_buffer, top);
sound_pos=0;
}
void sound_init()
{
SDL_AudioSpec audioSpec{11025, AUDIO_U8, 1, 0, 220, 0, 0, &audioCallback, NULL};
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
}
void sound_enable()
{
SDL_PauseAudioDevice(sdlAudioDevice, 0);
}
void sound_disable()
{
SDL_PauseAudioDevice(sdlAudioDevice, 1);
}
void sound_update(const uint8_t dt)
{
t_sound += dt;
if (t_sound>=400) {
t_sound-=400;
sound_buffer[sound_pos++] = ear*128;
}
}
}