def key_down(self, key): armv2.debug_log("key down " + str(key)) self.key_state |= 1 << key self.ring_buffer[self.pos] = key self.pos += 1 if self.pos == len(self.ring_buffer): self.pos = 0 self.cpu.interrupt(self.id, self.InterruptCodes.KEY_DOWN)
def delete(self): with self.cv: self.running = False self.cv.notify() armv2.debug_log("joining thread") self.thread.join() armv2.debug_log("Killed") if self.tape_drive: self.tape_drive.delete()
def read_byte_callback(self, addr, value): armv2.debug_log("keyboard reader byte %x %x\n" % (addr, value)) if addr < self.ringbuffer_start: # It's a state request return self.key_state >> (8 * addr) & 0xFF elif addr < self.ringbuffer_pos: pos = addr - self.ringbuffer_start out = self.ring_buffer[pos] armv2.debug_log("Read key data %d\n" % out) return out elif addr == self.ringbuffer_pos: return self.pos else: return 0
def read_callback(self, addr, value): armv2.debug_log("keyboard reader %x %x\n" % (addr, value)) if addr < self.ringbuffer_start: # It's a state request return self.key_state >> (8 * addr) & 0xFFFFFFFF elif addr < self.ringbuffer_pos: pos = addr - self.ringbuffer_start bytes = [ self.ring_buffer[pos + i % len(self.ring_buffer)] for i in range(4) ] return (bytes[0]) | (bytes[1] << 8) | (bytes[2] << 16) | ( bytes[3] << 24) elif addr == self.ringbuffer_pos: return self.pos return 0
def thread_main_loop(self): while self.running and ( (self.steps_to_run == 0) or (self.status == armv2.Status.WAIT_FOR_INTERRUPT and not (self.cpu.pins & armv2.Pins.INTERRUPT))): self.cv.wait(5) num_left = self.steps_to_run if self.steps_to_run > 0: # self.cv.release() # self.cv.notify() self.status, num_left = self.cpu.step(self.steps_to_run) # self.cv.acquire() if num_left != self.steps_to_run: armv2.debug_log( f"{self.steps_to_run=:d} {self.status=:x} {num_left=} {self.cpu.pins=:x}" ) self.steps_to_run = 0 self.cv.notify()
def write_callback(self, addr, value): armv2.debug_log("keyboard writer %x %x\n" % (addr, value)) return 0
def key_up(self, key): armv2.debug_log("key up " + str(key)) self.key_state &= ~(1 << key) self.cpu.interrupt(self.id, self.InterruptCodes.KEY_UP)