refactor: extract keyboard to separate file
This commit is contained in:
parent
0e288f8063
commit
7a90fb17ee
3 changed files with 27 additions and 14 deletions
6
orao.py
6
orao.py
|
@ -3,6 +3,7 @@
|
|||
|
||||
import pygame, numpy, sys, datetime, wave, time
|
||||
from orao.cpu import CPU
|
||||
from orao.keyboard import listener as orao_kbd_listener
|
||||
|
||||
pygame.mixer.pre_init(44100, 8, 1, buffer=2048)
|
||||
pygame.init()
|
||||
|
@ -36,10 +37,7 @@ while running:
|
|||
if 650 < x < 700 and 720 < y < 790: # Reset button
|
||||
cpu.__init__(cpu.memory[:]) # Warm reset
|
||||
|
||||
if event.type in [pygame.KEYDOWN, pygame.KEYUP]:
|
||||
for address, keycodes in cpu._kbd.iteritems():
|
||||
keys = map(pygame.key.get_pressed().__getitem__, keycodes)
|
||||
cpu.memory[address] = ~numpy.dot(keys, [16,32,64,128][:len(keys)]) & 0xFF
|
||||
orao_kbd_listener(event, cpu)
|
||||
|
||||
if event.type == pygame.USEREVENT + 1:
|
||||
screen.blit(background, [0, 0])
|
||||
|
|
10
orao/cpu.py
10
orao/cpu.py
|
@ -50,16 +50,6 @@ class CPU(object):
|
|||
0xf0:(s.BEQ,s.re,4), 0xf1:(s.SBC,s.iy,6), 0xf5:(s.SBC,s.zx,4), 0xf6:(s.INC,s.zx,6),
|
||||
0xf8:(s.SED,s.no,2), 0xf9:(s.SBC,s.ay,5), 0xfd:(s.SBC,s.ax,5), 0xfe:(s.INC,s.ax,7)}
|
||||
|
||||
s._kbd = {0x83FE: (112, 240, 185, 39), 0x83FF: (45, 48), # [p đ š ;] [- 0]
|
||||
0x85FE: (232, 230, 190, 43), 0x85FF: (8, 94), # [č ć ž :] [BS ^]
|
||||
0x86FE: (102, 104, 103, 110), 0x86FF: (98, 118), # [f h g n] [b v]
|
||||
0x877E: (100, 97, 115, 122), 0x877F: (120, 99), # [d a s z] [x c]
|
||||
0x87BE: (108, 106, 107, 109), 0x87BF: (44, 46), # [l j k m] [, .]
|
||||
0x87DE: (101, 113, 119, 49), 0x87DF: (50, 51), # [e q w l] [2 3]
|
||||
0x87EE: (111, 105, 117, 55), 0x87EF: (56, 57), # [o i u 7] [8 9]
|
||||
0x87F6: (114, 121, 116, 54), 0x87F7: (53, 52), # [r y t 6] [5 4]
|
||||
0x87FA: (282, 283, 284, 285), 0x87FD: (13, 306), # [f1f2f3f4] [cr l_ctrl]
|
||||
0x87FC: (276, 273, 274, 275), 0x87FB: (32, 304)} # [arrows] [spc l_shift]
|
||||
|
||||
s.ticks = {s.im: 1, s.zp: 1, s.zx: 1, s.zy: 1, s.ab: 2, s.ax: 2, s.no: 0,
|
||||
s.ay: 2, s.jm: 2, s.id: 2, s.ix: 1, s.iy: 1, s.re: 1}
|
||||
|
|
25
orao/keyboard.py
Normal file
25
orao/keyboard.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf8 -*-
|
||||
|
||||
# defines orao keyboard
|
||||
|
||||
import pygame, numpy
|
||||
|
||||
_kbd = {
|
||||
0x83FE: (112, 240, 185, 39), 0x83FF: (45, 48), # [p đ š ;] [- 0]
|
||||
0x85FE: (232, 230, 190, 43), 0x85FF: (8, 94), # [č ć ž :] [BS ^]
|
||||
0x86FE: (102, 104, 103, 110), 0x86FF: (98, 118), # [f h g n] [b v]
|
||||
0x877E: (100, 97, 115, 122), 0x877F: (120, 99), # [d a s z] [x c]
|
||||
0x87BE: (108, 106, 107, 109), 0x87BF: (44, 46), # [l j k m] [, .]
|
||||
0x87DE: (101, 113, 119, 49), 0x87DF: (50, 51), # [e q w l] [2 3]
|
||||
0x87EE: (111, 105, 117, 55), 0x87EF: (56, 57), # [o i u 7] [8 9]
|
||||
0x87F6: (114, 121, 116, 54), 0x87F7: (53, 52), # [r y t 6] [5 4]
|
||||
0x87FA: (282, 283, 284, 285), 0x87FD: (13, 306), # [f1f2f3f4] [cr l_ctrl]
|
||||
0x87FC: (276, 273, 274, 275), 0x87FB: (32, 304) # [arrows] [spc l_shift]
|
||||
}
|
||||
|
||||
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)
|
||||
cpu.memory[address] = ~numpy.dot(keys, [16, 32, 64, 128][:len(keys)]) & 0xFF
|
||||
|
Loading…
Reference in a new issue