mamedev / mame

MAME
https://www.mamedev.org/
Other
8.43k stars 2.04k forks source link

Serial emulation : bytes are read too slow #12762

Closed colinleroy closed 2 months ago

colinleroy commented 2 months ago

MAME version

0.263 (unknown) (0.263+dfsg.1-0ubuntu1~ppa1~mantic1)

System information

Linux Ubuntu 23.04, x86_64, en_US.UTF-8 locale.

INI configuration details

#
# CORE CONFIGURATION OPTIONS
#
readconfig                1
writeconfig               1

#
# CORE SEARCH PATH OPTIONS
#
homepath                  .
rompath                   $HOME/mame/roms;/usr/local/share/games/mame/roms;/usr/share/games/mame/roms
hashpath                  files
samplepath                $HOME/mame/samples;/usr/local/share/games/mame/samples;/usr/share/games/mame/samples
artpath                   $HOME/mame/artwork;/usr/local/share/games/mame/artwork;/usr/share/games/mame/artwork
ctrlrpath                 /usr/share/games/mame/ctrlr
inipath                   $HOME/.mame;/etc/mame
fontpath                  /usr/share/games/mame/fonts
cheatpath                 $HOME/mame/cheat;/usr/local/share/games/mame/cheat;/usr/share/games/mame/cheat
crosshairpath             $HOME/mame/crosshair;/usr/local/share/games/mame/crosshair;/usr/share/games/mame/crosshair
pluginspath               /usr/share/games/mame/plugins
languagepath              /usr/share/games/mame/language
swpath                    software

#
# CORE OUTPUT DIRECTORY OPTIONS
#
cfg_directory             $HOME/.mame/cfg
nvram_directory           $HOME/.mame/nvram
input_directory           $HOME/.mame/inp
state_directory           $HOME/.mame/sta
snapshot_directory        $HOME/.mame/snap
diff_directory            $HOME/.mame/diff
comment_directory         $HOME/.mame/comments
share_directory           share

#
# CORE STATE/PLAYBACK OPTIONS
#
state                     
autosave                  0
rewind                    0
rewind_capacity           100
playback                  
record                    
exit_after_playback       0
mngwrite                  
aviwrite                  
wavwrite                  
snapname                  %g/%i
snapsize                  auto
snapview                  auto
snapbilinear              1
statename                 %g
burnin                    0

#
# CORE PERFORMANCE OPTIONS
#
autoframeskip             0
frameskip                 0
seconds_to_run            0
throttle                  1
sleep                     1
speed                     1.0
refreshspeed              0
lowlatency                0

#
# CORE RENDER OPTIONS
#
keepaspect                1
unevenstretch             1
unevenstretchx            0
unevenstretchy            0
autostretchxy             0
intoverscan               0
intscalex                 0
intscaley                 0

#
# CORE ROTATION OPTIONS
#
rotate                    1
ror                       0
rol                       0
autoror                   0
autorol                   0
flipx                     0
flipy                     0

#
# CORE ARTWORK OPTIONS
#
artwork_crop              0
fallback_artwork          
override_artwork          

#
# CORE SCREEN OPTIONS
#
brightness                1.0
contrast                  1.0
gamma                     1.0
pause_brightness          0.65
effect                    none

#
# CORE VECTOR OPTIONS
#
beam_width_min            1.0
beam_width_max            1.0
beam_dot_size             1.0
beam_intensity_weight     0
flicker                   0

#
# CORE SOUND OPTIONS
#
samplerate                48000
samples                   1
volume                    0
compressor                1
speaker_report            0

#
# CORE INPUT OPTIONS
#
coin_lockout              1
ctrlr                     
mouse                     0
joystick                  1
lightgun                  0
multikeyboard             0
multimouse                0
steadykey                 0
ui_active                 0
offscreen_reload          0
joystick_map              auto
joystick_deadzone         0.3
joystick_saturation       0.85
joystick_threshold        0.3
natural                   0
joystick_contradictory    0
coin_impulse              0

#
# CORE INPUT AUTOMATIC ENABLE OPTIONS
#
paddle_device             keyboard
adstick_device            keyboard
pedal_device              keyboard
dial_device               keyboard
trackball_device          keyboard
lightgun_device           keyboard
positional_device         keyboard
mouse_device              mouse

#
# CORE DEBUGGING OPTIONS
#
verbose                   0
log                       0
oslog                     0
debug                     1
update_in_pause           0
debugscript               
debuglog                  0

#
# CORE COMM OPTIONS
#
comm_localhost            0.0.0.0
comm_localport            15112
comm_remotehost           127.0.0.1
comm_remoteport           15112
comm_framesync            0

#
# CORE MISC OPTIONS
#
drc                       1
drc_use_c                 0
drc_log_uml               0
drc_log_native            0
bios                      
cheat                     0
skip_gameinfo             0
uifont                    default
ui                        cabinet
ramsize                   
confirm_quit              0
ui_mouse                  1
language                  
nvram_save                1

#
# SCRIPTING OPTIONS
#
autoboot_command          
autoboot_delay            0
autoboot_script           
console                   0
plugins                   1
plugin                    
noplugin                  

#
# HTTP SERVER OPTIONS
#
http                      0
http_port                 8080
http_root                 web

#
# OSD INPUT MAPPING OPTIONS
#
uimodekey                 DEL
controller_map            none
background_input          0

#
# OSD FONT OPTIONS
#
uifontprovider            auto

#
# OSD OUTPUT OPTIONS
#
output                    auto

#
# OSD INPUT OPTIONS
#
keyboardprovider          auto
mouseprovider             auto
lightgunprovider          auto
joystickprovider          auto

#
# OSD DEBUGGING OPTIONS
#
debugger                  auto
debugger_port             23946
debugger_font             auto
debugger_font_size        0
watchdog                  0

#
# OSD PERFORMANCE OPTIONS
#
numprocessors             auto
bench                     0

#
# OSD VIDEO OPTIONS
#
video                     bgfx
numscreens                1
window                    1
maximize                  1
waitvsync                 0
syncrefresh               0
monitorprovider           auto

#
# OSD PER-WINDOW VIDEO OPTIONS
#
screen                    auto
aspect                    auto
resolution                560x384
view                      auto
screen0                   auto
aspect0                   auto
resolution0               auto
view0                     auto
screen1                   auto
aspect1                   auto
resolution1               auto
view1                     auto
screen2                   auto
aspect2                   auto
resolution2               auto
view2                     auto
screen3                   auto
aspect3                   auto
resolution3               auto
view3                     auto

#
# OSD FULL SCREEN OPTIONS
#
switchres                 0

#
# OSD ACCELERATED VIDEO OPTIONS
#
filter                    1
prescale                  1

#
# OpenGL-SPECIFIC OPTIONS
#
gl_forcepow2texture       0
gl_notexturerect          0
gl_vbo                    1
gl_pbo                    1
gl_glsl                   0
gl_glsl_filter            1
glsl_shader_mame0         none
glsl_shader_mame1         none
glsl_shader_mame2         none
glsl_shader_mame3         none
glsl_shader_mame4         none
glsl_shader_mame5         none
glsl_shader_mame6         none
glsl_shader_mame7         none
glsl_shader_mame8         none
glsl_shader_mame9         none
glsl_shader_screen0       none
glsl_shader_screen1       none
glsl_shader_screen2       none
glsl_shader_screen3       none
glsl_shader_screen4       none
glsl_shader_screen5       none
glsl_shader_screen6       none
glsl_shader_screen7       none
glsl_shader_screen8       none
glsl_shader_screen9       none

#
# OSD SOUND OPTIONS
#
sound                     auto
audio_latency             2

#
# PORTAUDIO OPTIONS
#
pa_api                    none
pa_device                 none
pa_latency                0

#
# OSD MIDI OPTIONS
#
midiprovider              auto

#
# OSD EMULATED NETWORKING OPTIONS
#
networkprovider           auto

#
# BGFX POST-PROCESSING OPTIONS
#
bgfx_path                 /usr/share/games/mame/bgfx
bgfx_backend              auto
bgfx_debug                0
bgfx_screen_chains        crt-geom-deluxe
bgfx_shadow_mask          slot-mask.png
bgfx_lut                  lut-default.png
bgfx_avi_name             auto

#
# SDL PERFORMANCE OPTIONS
#
sdlvideofps               0

#
# SDL VIDEO OPTIONS
#
centerh                   1
centerv                   1
scalemode                 none

#
# SDL FULL SCREEN OPTIONS
#
useallheads               0
attach_window             

#
# SDL KEYBOARD MAPPING
#
keymap                    0
keymap_file               keymap.dat

#
# SDL JOYSTICK MAPPING
#
sixaxis                   0

#
# SDL LIGHTGUN MAPPING
#
lightgun_index1           auto
lightgun_index2           auto
lightgun_index3           auto
lightgun_index4           auto
lightgun_index5           auto
lightgun_index6           auto
lightgun_index7           auto
lightgun_index8           auto

#
# SDL LOW-LEVEL DRIVER OPTIONS
#
videodriver               auto
renderdriver              auto
audiodriver               auto
gl_lib                    auto

#
# FRONTEND COMMAND OPTIONS
#
dtd                       1

#
# SLOT DEVICES
#
printer                   null_modem
modem                     null_modem

#
# IMAGE DEVICES
#
floppydisk1               /home/colin/Documents/git-oss/a2tools/wozamp-65c02.po
floppydisk2               /home/colin/Documents/git-oss/a2tools/disks/qt100.dsk
bitbanger                 /home/colin/Documents/git-oss/a2tools/socket.localhost:2001
bitbanger2                /home/colin/Documents/git-oss/a2tools/socket.localhost:2000

Emulated system/software

apple2c0

Incorrect behaviour

Hi, I am currently developing an audio/video player for the Apple II, and have noticed that MAME is feeding bytes from the bitbangers to the emulated Apple II too slowly.

The symptoms are visible in this demo video : https://www.youtube.com/watch?v=cqWVqEN_OCw It consists of three parts:

A bit more information about the serial emulation: My transcoder gets a video file, transcodes it to a video part and a sound part. The sound part is 5bit, 11520Hz PCM data, and is streamed to the Apple II's modem port, configured at 115200 8n1.

That takes perfect care of the playback speed on real hardware, as 115200 8n1 means 11520 bytes/s, including 1 start bit, 8 data bits, 1 stop bit.

(The video is streamed to the printer port. In this demo it is not slowed down because it uses less bandwidth (~1400 bytes/s), so even if MAME reads it slowly, it's still fast enough to do 25fps).

On MAME, the serial stack is as follows:

The last part of my test video is there to verify that the tty0tty + ser2net part of the emulation is not responsible for the slowdown (on the contrary, it is much too fast, transferring 60*11520 'A' characters in less than 6 seconds. This causes me other problems, but they're not MAME-related).

I would love to help fix this, but I have no idea where to start in the code. I hope that, if nobody can take care of this issue for me, maybe someone with a good knowledge of MAME's codebase could point me in the right direction and help me solve it?

Thanks a lot in advance!

Expected behaviour

MAME sends 11520 bytes per second to the emulated serial port.

Steps to reproduce

mame apple2c0 -window -flop1 wozamp-65c02.po -resolution 560x384 -printer null_modem -bitb socket.localhost:2001 -modem null_modem -bitb2 socket.localhost:2000 -nomouse

Additional details

No response

MooglyGuy commented 2 months ago

@rb6502 This seems to be Apple II specific, pinging you in case you inadvertently overlook the report.

colinleroy commented 2 months ago

@rb6502 This seems to be Apple II specific, pinging you in case you inadvertently overlook the report.

I'm unsure it's Apple II specific. The serial ports for the Apple IIc are defined like this:

    MOS6551(config, m_acia2, 0);
    m_acia2->set_xtal(1.8432_MHz_XTAL);   // matches SSC so modem software is compatible
    m_acia2->txd_handler().set("modem", FUNC(rs232_port_device::write_txd));

That's the correct clock rate.

I think it may either be a problem in mos6551.cpp, null_modem.cpp or maybe the bitbanger (which I don't find the source to) ?

colinleroy commented 2 months ago

Hi,

I've started looking, and it seems I found the cause using this commit: https://github.com/colinleroy/mame/commit/c076ac8adcd496d4429848adeab558f1b728020d

It seems like mos6551.cpp delivers one data byte every 176 clock ticks, which is 95µs at 1.8432MHz. That should be 160 clock ticks (86µs).

I've not yet figured out how the code is wrong but this also explains why sometimes I lose bytes on real hardware and not on emulation.

colinleroy commented 2 months ago

This commit https://github.com/colinleroy/mame/commit/7e74bcdde8de267d8cc66e732a0198014fb47d8a shows me that we postpone the start bit by 16 ticks because m_rxd != 0.

Still have to find out what calls mos6551_device::write_rxd and toggles m_rxd.

colinleroy commented 2 months ago

OK, I figured it out ! PR sent.