mirror of
https://github.com/pevans/erc-c.git
synced 2024-10-31 13:07:14 +00:00
Finish map, mapper handling for keyboard events
We still need to revise the test code we currently have for handling keyboard functions; I imagine some code will need to be removed.
This commit is contained in:
parent
8d4283b1dc
commit
bf529d6c9b
@ -305,12 +305,10 @@ typedef struct {
|
|||||||
vm_8bit memory_mode;
|
vm_8bit memory_mode;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The last_key field is the ASCII value of the last key that was
|
* We have a simple boolean value to determine if the strobe is set
|
||||||
* pressed. We also have a simple boolean value to determine if the
|
* (it always is when the key is pressed, and stays that way until
|
||||||
* strobe is set (it always is when the key is pressed, and stays
|
* someone reads the "any-key-down" soft switch).
|
||||||
* that way until someone reads the "any-key-down" soft switch).
|
|
||||||
*/
|
*/
|
||||||
vm_8bit last_key;
|
|
||||||
bool strobe;
|
bool strobe;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
#define _APPLE2_KB_H_
|
#define _APPLE2_KB_H_
|
||||||
|
|
||||||
#include "apple2.h"
|
#include "apple2.h"
|
||||||
|
#include "vm_screen.h"
|
||||||
#include "vm_segment.h"
|
#include "vm_segment.h"
|
||||||
|
|
||||||
|
extern void apple2_kb_map(vm_segment *);
|
||||||
|
extern SEGMENT_READER(apple2_kb_switch_read);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "vm_area.h"
|
#include "vm_area.h"
|
||||||
|
#include "vm_bits.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/*
|
/*
|
||||||
@ -31,10 +32,12 @@ typedef struct {
|
|||||||
int ycoords;
|
int ycoords;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is true when a key is pressed, and false if not. We
|
* Hang onto the last key pressed and the status of whether a key
|
||||||
* determine this from an SDL_PollEvent() call.
|
* is pressed right now or not.
|
||||||
*/
|
*/
|
||||||
|
vm_8bit last_key;
|
||||||
bool key_pressed;
|
bool key_pressed;
|
||||||
|
|
||||||
} vm_screen;
|
} vm_screen;
|
||||||
|
|
||||||
extern bool vm_screen_active(vm_screen *);
|
extern bool vm_screen_active(vm_screen *);
|
||||||
|
@ -4,6 +4,7 @@ set(erc_sources
|
|||||||
apple2.dbuf.c
|
apple2.dbuf.c
|
||||||
apple2.dd.c
|
apple2.dd.c
|
||||||
apple2.draw.c
|
apple2.draw.c
|
||||||
|
apple2.kb.c
|
||||||
apple2.mem.c
|
apple2.mem.c
|
||||||
apple2.pc.c
|
apple2.pc.c
|
||||||
log.c
|
log.c
|
||||||
|
@ -4,6 +4,23 @@
|
|||||||
|
|
||||||
#include "apple2.kb.h"
|
#include "apple2.kb.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This mapper is considerably simpler than most, because it handles
|
||||||
|
* only two addresses and only read maps. It merely performs the mapping
|
||||||
|
* for keyboard switches.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
apple2_kb_map(vm_segment *seg)
|
||||||
|
{
|
||||||
|
vm_segment_read_map(seg, 0xC000, apple2_kb_switch_read);
|
||||||
|
vm_segment_read_map(seg, 0xC010, apple2_kb_switch_read);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This mapper handles reads to switches that report info on the
|
||||||
|
* keyboard state. Note that there is no write switch function; there
|
||||||
|
* are only reads that need to be handled.
|
||||||
|
*/
|
||||||
SEGMENT_READER(apple2_kb_switch_read)
|
SEGMENT_READER(apple2_kb_switch_read)
|
||||||
{
|
{
|
||||||
apple2 *mach = (apple2 *)_mach;
|
apple2 *mach = (apple2 *)_mach;
|
||||||
@ -50,4 +67,8 @@ SEGMENT_READER(apple2_kb_switch_read)
|
|||||||
// pressed down.
|
// pressed down.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This can only happen if we were mapped to an address we weren't
|
||||||
|
// prepared to handle
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
|
|
||||||
#include "apple2.bank.h"
|
#include "apple2.bank.h"
|
||||||
#include "apple2.dbuf.h"
|
#include "apple2.dbuf.h"
|
||||||
#include "apple2.pc.h"
|
|
||||||
#include "apple2.h"
|
#include "apple2.h"
|
||||||
|
#include "apple2.kb.h"
|
||||||
#include "apple2.mem.h"
|
#include "apple2.mem.h"
|
||||||
|
#include "apple2.pc.h"
|
||||||
#include "objstore.h"
|
#include "objstore.h"
|
||||||
|
|
||||||
static size_t switch_reads[] = {
|
static size_t switch_reads[] = {
|
||||||
@ -49,8 +50,13 @@ apple2_mem_map(apple2 *mach, vm_segment *segment)
|
|||||||
// Here we handle the 80STORE bit for our display buffers.
|
// Here we handle the 80STORE bit for our display buffers.
|
||||||
apple2_dbuf_map(segment);
|
apple2_dbuf_map(segment);
|
||||||
|
|
||||||
|
// All of our peripheral card (PC) mapper functions are handled
|
||||||
|
// here.
|
||||||
apple2_pc_map(segment);
|
apple2_pc_map(segment);
|
||||||
|
|
||||||
|
// And this handles our keyboard soft switches
|
||||||
|
apple2_kb_map(segment);
|
||||||
|
|
||||||
// We will do the mapping for the zero page and stack addresses.
|
// We will do the mapping for the zero page and stack addresses.
|
||||||
// Accessing those addresses can be affected by bank-switching, but
|
// Accessing those addresses can be affected by bank-switching, but
|
||||||
// those addresses do not actually exist in the capital
|
// those addresses do not actually exist in the capital
|
||||||
|
@ -175,16 +175,16 @@ vm_screen_active(vm_screen *screen)
|
|||||||
ch = '\0';
|
ch = '\0';
|
||||||
|
|
||||||
// It seems we may have pressed a key...
|
// It seems we may have pressed a key...
|
||||||
if (event.key) {
|
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) {
|
||||||
// The sym field is of type SDL_Keycode; this type, however,
|
// The sym field is of type SDL_Keycode; this type, however,
|
||||||
// maps roughly to Unicode, which of course maps roughly to
|
// maps roughly to Unicode, which of course maps roughly to
|
||||||
// ASCII in the low range.
|
// ASCII in the low range.
|
||||||
ch = (char)event.key->keysym.sym;
|
ch = (char)event.key.keysym.sym;
|
||||||
|
|
||||||
// If we had shift pressed, we need to uppercase the
|
// If we had shift pressed, we need to uppercase the
|
||||||
// character.
|
// character.
|
||||||
if (event.key->keysym.mod & KMOD_LSHIFT ||
|
if (event.key.keysym.mod & KMOD_LSHIFT ||
|
||||||
event.key->keysym.mod & KMOD_RSHIFT
|
event.key.keysym.mod & KMOD_RSHIFT
|
||||||
) {
|
) {
|
||||||
ch = toupper(ch);
|
ch = toupper(ch);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user