From 3e45705c31b63d8f38b8448938d659dc1b38c376 Mon Sep 17 00:00:00 2001 From: tracer-ics2023 Date: Sat, 21 Sep 2024 15:10:29 +0800 Subject: [PATCH] =?UTF-8?q?>=20=20compile=20NEMU=20221220000=20=E5=BC=A0?= =?UTF-8?q?=E4=B8=89=20Linux=20zzy=205.15.146.1-microsoft-standard-WSL2=20?= =?UTF-8?q?#1=20SMP=20Thu=20Jan=2011=2004:09:03=20UTC=202024=20x86=5F64=20?= =?UTF-8?q?x86=5F64=20x86=5F64=20GNU/Linux=20=2015:10:28=20up=204=20days,?= =?UTF-8?q?=2010:16,=20=201=20user,=20=20load=20average:=200.37,=200.61,?= =?UTF-8?q?=200.61?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../am/src/platform/nemu/ioe/audio.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/abstract-machine/am/src/platform/nemu/ioe/audio.c b/abstract-machine/am/src/platform/nemu/ioe/audio.c index 98c2478..a3e0519 100644 --- a/abstract-machine/am/src/platform/nemu/ioe/audio.c +++ b/abstract-machine/am/src/platform/nemu/ioe/audio.c @@ -10,6 +10,7 @@ static uint32_t audio_write = 0; static uint32_t audio_sbuf_size; +#define MIN(a, b) ((a) < (b) ? (a) : (b)) void __am_audio_init() { } @@ -39,16 +40,15 @@ void __am_audio_play(AM_AUDIO_PLAY_T *ctl) { while (cnt) { // lock sbuf outl(AUDIO_INIT_ADDR, 2); - for (; i < cnt; i++) { - if (inl(AUDIO_COUNT_ADDR) == audio_sbuf_size) { - i--; - break; - } else { - outb(AUDIO_SBUF_ADDR + audio_write, ((uint8_t*)ctl->buf.start)[i]); - audio_write = (audio_write + 1) % audio_sbuf_size; - outl(AUDIO_COUNT_ADDR, inl(AUDIO_COUNT_ADDR) + 1); - } + + int last = audio_sbuf_size - inl(AUDIO_COUNT_ADDR); + int write_num = MIN(last, cnt); + for (int j = i; j < write_num; i ++, j ++) { + outb(AUDIO_SBUF_ADDR + audio_write, ((uint8_t*)(ctl->buf.start))[i]); + audio_write = (audio_write + 1) % audio_sbuf_size; } + cnt -= write_num; + outl(AUDIO_COUNT_ADDR, inl(AUDIO_COUNT_ADDR) + write_num); // unlock sbuf outl(AUDIO_INIT_ADDR, 0); }