From cc165a486127d9df586fff631ed10e68b59daf68 Mon Sep 17 00:00:00 2001 From: bebbo Date: Sun, 24 Mar 2024 17:47:29 +0100 Subject: [PATCH 1/2] implement WaitForChar --- amitools/vamos/lib/DosLibrary.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/amitools/vamos/lib/DosLibrary.py b/amitools/vamos/lib/DosLibrary.py index c4a7b084..aa0334ab 100644 --- a/amitools/vamos/lib/DosLibrary.py +++ b/amitools/vamos/lib/DosLibrary.py @@ -2,6 +2,7 @@ import ctypes import re import os +import select from amitools.vamos.machine.regs import * from amitools.vamos.libcore import LibImpl @@ -594,6 +595,22 @@ def Close(self, ctx): self.setioerr(ctx, 0) return self.DOSTRUE + def WaitForChar(self, ctx): + # file,timeout)(d1/d2) + fh_b_addr = ctx.cpu.r_reg(REG_D1) + fh = self.file_mgr.get_by_b_addr(fh_b_addr, False) + if select.select([fh.obj], [], [], 0.)[0]: + return self.DOSTRUE + + ms = ctx.cpu.r_reg(REG_D2) + if ms > 0: + time.sleep(ms * 1e-3) + + if select.select([fh.obj], [], [], 0.)[0]: + return self.DOSTRUE + + return self.DOSFALSE + def Read(self, ctx): fh_b_addr = ctx.cpu.r_reg(REG_D1) buf_ptr = ctx.cpu.r_reg(REG_D2) From 2bad53e2b9b3c73552d6db9c08f64d5c4964fe42 Mon Sep 17 00:00:00 2001 From: bebbo Date: Mon, 25 Mar 2024 12:58:53 +0100 Subject: [PATCH 2/2] simpler WaitForChar --- amitools/vamos/lib/DosLibrary.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/amitools/vamos/lib/DosLibrary.py b/amitools/vamos/lib/DosLibrary.py index aa0334ab..23adbac0 100644 --- a/amitools/vamos/lib/DosLibrary.py +++ b/amitools/vamos/lib/DosLibrary.py @@ -599,15 +599,9 @@ def WaitForChar(self, ctx): # file,timeout)(d1/d2) fh_b_addr = ctx.cpu.r_reg(REG_D1) fh = self.file_mgr.get_by_b_addr(fh_b_addr, False) - if select.select([fh.obj], [], [], 0.)[0]: - return self.DOSTRUE - ms = ctx.cpu.r_reg(REG_D2) - if ms > 0: - time.sleep(ms * 1e-3) - - if select.select([fh.obj], [], [], 0.)[0]: - return self.DOSTRUE + if select.select([fh.obj], [], [], ms * 1e-3)[0]: + return self.DOSTRUE return self.DOSFALSE