Compare commits

...

3 commits

Author SHA1 Message Date
shokre
94bc7f7401 fix: fix wav loading 2023-10-21 06:43:19 +02:00
shokre
3bd5c9ddc1 fix: fix python invocation 2023-10-21 05:35:17 +02:00
shokre
2ec18cc353 refactor: port to python3 2023-10-21 05:23:40 +02:00
4 changed files with 17 additions and 8 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import pygame, numpy, sys, datetime

View file

@ -85,7 +85,7 @@ class CPU(object):
def get_word(self, addr): return 256 * self.get_byte(addr + 1) + self.get_byte(addr)
def get_filename(self): return 'wav/{0}.WAV'.format(str(self.memory[592:602]).rstrip())
def get_filename(self): return 'wav/{0}.WAV'.format(str(self.memory[592:602], 'ASCII').rstrip())
def speaker(self):
self.flipflop ^= 1
@ -95,14 +95,18 @@ class CPU(object):
self.sndbuf += [255] * self.samples + [0] * self.samples
self.last_sound_cycles = self.cycles
def tape_load_gen(self):
for i in wave.open(self.get_filename()).readframes(2 ** 24):
for j in 2 * [i]:
yield 255 * (j > 128)
def get_byte(self, addr):
if addr == 0x87FF: # Adresa ulaza kasetofona
if not self.tape:
self.tape = (255*(ord(j)>128) for i in \
wave.open(self.get_filename()).readframes(2**24) for j in 2*i)
self.tape = self.tape_load_gen()
try:
return self.tape.next()
return next(self.tape)
except StopIteration:
self.tape = None
@ -136,7 +140,9 @@ class CPU(object):
self.sp = (self.sp + 1) & 0xFF
return self.get_byte(256 + self.sp)
def stack_push_word(self, val): map(self.stack_push, [(val >> 8) & 0xFF, val & 0xFF])
def stack_push_word(self, val):
self.stack_push((val >> 8) & 0xFF)
self.stack_push(val & 0xFF)
def stack_pop_word(self): return self.stack_pop() + (self.stack_pop() << 8)
###########################################################################

View file

@ -20,7 +20,7 @@ _kbd = {
def listener(event, cpu):
if event.type in [pygame.KEYDOWN, pygame.KEYUP]:
for address, keycodes in _kbd.iteritems():
keys = map(pygame.key.get_pressed().__getitem__, keycodes)
for address, keycodes in _kbd.items():
keys = list(map(pygame.key.get_pressed().__getitem__, keycodes))
cpu.memory[address] = ~numpy.dot(keys, [16, 32, 64, 128][:len(keys)]) & 0xFF

3
requirements.txt Normal file
View file

@ -0,0 +1,3 @@
numpy==1.26.1
pygame==2.5.2
Wave==0.0.2