Skip to content

Commit

Permalink
DraCo Amiga HD disk support, PC disk write/format support, keyboard r…
Browse files Browse the repository at this point in the history
…epeat support.
  • Loading branch information
tonioni committed Jan 14, 2024
1 parent 49e4c1d commit 76ac1b5
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 213 deletions.
74 changes: 45 additions & 29 deletions draco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "zfile.h"
#include "keybuf.h"
#include "rommgr.h"
#include "disk.h"

static int maxcnt = 100;

Expand Down Expand Up @@ -650,43 +651,56 @@ static void draco_1wire_reset(void)
#endif
}

static uae_u16 draco_floppy_data;
static int draco_floppy_bits, draco_floppy_rate;

// draco reads amiga disks by polling register
// that returns time since last flux change.
static uae_u8 draco_floppy_get_data(void)
{
static uae_u16 data;
static int bits;
if (bits < 8) {
uae_u16 t = floppy_get_raw_data();
data |= (t & 0xff) << (8 - bits);
bits += 8;
if (draco_floppy_bits < 8) {
uae_u16 t = floppy_get_raw_data(&draco_floppy_rate);
draco_floppy_data |= (t & 0xff) << (8 - draco_floppy_bits);
draco_floppy_bits += 8;
}
int bit1 = (data & 0x8000);
int bit2 = (data & 0x4000);
int bit3 = (data & 0x2000);
int bit4 = (data & 0x1000);
int bit1 = (draco_floppy_data & 0x8000);
int bit2 = (draco_floppy_data & 0x4000);
int bit3 = (draco_floppy_data & 0x2000);
int bit4 = (draco_floppy_data & 0x1000);
int v = 0;

if (bit1) {
data <<= 1;
bits--;
return 8;
}
if (bit2) {
data <<= 2;
bits -= 2;
return 24;
draco_floppy_data <<= 1;
draco_floppy_bits--;
v = 8;
} else if (bit2) {
draco_floppy_data <<= 2;
draco_floppy_bits -= 2;
v = 24;
} else if (bit3) {
draco_floppy_data <<= 3;
draco_floppy_bits -= 3;
v = 40;
} else if (bit4) {
draco_floppy_data <<= 4;
draco_floppy_bits -= 4;
v = 56;
}
if (bit3) {
data <<= 3;
bits -= 3;
return 40;
}
if (bit4) {
data <<= 4;
bits -= 4;
return 56;
switch (draco_floppy_rate) {
case FLOPPY_RATE_250K:
// above values are in 250Kbs
break;
case FLOPPY_RATE_500K:
v /= 2;
break;
case FLOPPY_RATE_300K:
v = v * 30 / 25;
break;
case FLOPPY_RATE_1M:
v /= 4;
break;
}
return 0;
return v;
}

static void vmotion_write(uaecptr addr, uae_u8 v)
Expand Down Expand Up @@ -1184,7 +1198,7 @@ void draco_ext_interrupt(bool i6)
draco_irq();
}

void draco_keycode(uae_u8 scancode, uae_u8 state)
void draco_keycode(uae_u16 scancode, uae_u8 state)
{
if (currprefs.cs_compatible == CP_DRACO && (currprefs.cpuboard_settings & 0x10)) {
if (draco_kbd_buffer_len == 0 && !(draco_reg[3] & DRSTAT_KBDRECV)) {
Expand Down Expand Up @@ -1300,6 +1314,8 @@ void draco_reset(int hardreset)
draco_superio_cfg[6] = 0xff;
draco_superio_cfg[13] = 0x65;
draco_superio_cfg[14] = 1;
draco_floppy_data = 0;
draco_floppy_bits = 0;
memset(draco_reg, 0, sizeof(draco_reg));
draco_reg[1] = DRCNTRL_FDCINTENA | DRCNTRL_KBDINTENA;
draco_reg[5] = 0xff;
Expand Down
2 changes: 1 addition & 1 deletion include/draco.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ void draco_free(void);
bool draco_mouse(int port, int x, int y, int z, int b);
void draco_bustimeout(uaecptr addr);
void draco_ext_interrupt(bool);
void draco_keycode(uae_u8 scancode, uae_u8 state);
void draco_keycode(uae_u16 scancode, uae_u8 state);
28 changes: 26 additions & 2 deletions inputdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ static int temp_uid_cnt[IDTYPE_MAX];
static int gp_swappeddevices[MAX_INPUT_DEVICES][IDTYPE_MAX];
static int osk_state;

extern int draco_keyboard_get_rate(void);
static int draco_keybord_repeat_cnt, draco_keybord_repeat_code;

bool osk_status(void)
{
return osk_state != 0;
Expand Down Expand Up @@ -4382,6 +4385,17 @@ void inputdevice_hsync (bool forceread)
maybe_read_input();
}
}
if (draco_keybord_repeat_cnt > 0) {
draco_keybord_repeat_cnt--;
if (draco_keybord_repeat_cnt == 0) {
int rate = draco_keyboard_get_rate();
int b = (rate >> 3) & 3;
int d = (rate >> 0) & 7;
float r = ((1 << b) * (d + 8) / 240.0f) * 1000.0f;
draco_keybord_repeat_cnt = (int)(vblank_hz * maxvpos * r / 1000);
draco_keycode(draco_keybord_repeat_code, 1);
}
}
}

static uae_u16 POTDAT (int joy)
Expand Down Expand Up @@ -5800,6 +5814,7 @@ void inputdevice_reset (void)
lightpen_trigger2 = 0;
cubo_flag = 0;
alg_flag &= 1;
draco_keybord_repeat_cnt = 0;
}

static int getoldport (struct uae_input_device *id)
Expand Down Expand Up @@ -10458,9 +10473,18 @@ void inputdevice_draco_key(int kc)
if (events[i].data == kc && events[i].data2 && events[i].allow_mask == AM_K) {
int code = events[i].data2;
if ((code & 0xff00) == 0xe000) {
draco_keycode((code & 0xff) | 0x100, state);
code = (code & 0xff) | 0x100;
} else {
code &= 0xff;
}
draco_keycode(code, state);
if (state) {
int rate = draco_keyboard_get_rate();
int init = ((rate >> 5) & 3) * 250 + 250;
draco_keybord_repeat_cnt = (int)(vblank_hz * maxvpos * init / 1000);
draco_keybord_repeat_code = code;
} else {
draco_keycode(code & 0xff, state);
draco_keybord_repeat_code = 0;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion inputevents.def
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ DEFEVENTKB(KEY_ALT_LEFT,_T("Left Alt"),AM_K,AK_LALT,0x38)
DEFEVENTKB(KEY_AMIGA_LEFT,_T("Left Amiga"),AM_K,AK_LAMI,0xe05b)
DEFEVENTKB(KEY_AMIGA_RIGHT,_T("Right Amiga"),AM_K,AK_RAMI,0xe05c)
DEFEVENTKB(KEY_ALT_RIGHT,_T("Right Alt"),AM_K,AK_RALT,0xe038)
DEFEVENTKB(KEY_SHIFT_RIGHT,_T("Right Shift"),AM_K,AK_RSH,0x59)
DEFEVENTKB(KEY_SHIFT_RIGHT,_T("Right Shift"),AM_K,AK_RSH,0x36)
DEFEVENTKB(KEY_SPACE,_T("Space"),AM_K,AK_SPC,0x39)
DEFEVENTKB(KEY_CURSOR_UP,_T("Cursor Up"),AM_K,AK_UP,0xe048)
DEFEVENTKB(KEY_CURSOR_DOWN,_T("Cursor Down"),AM_K,AK_DN,0xe050)
Expand Down
15 changes: 15 additions & 0 deletions od-win32/winuae_msvc15/keyboard_at_draco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@
Bits 0 - 1 = scan code set. */
uint8_t keyboard_mode = 0x02;

extern void write_log(const char *, ...);

void draco_kdb_queue_add(void *d, uint8_t val, int state);

void kbc_at_dev_reset(void *d, int r)
{
}
void keyboard_at_log(const char *txt, ...)
{
char buffer[256];
va_list parms;
va_start(parms, txt);
vsprintf(buffer, txt, parms);
write_log(buffer);
va_end(parms);
}
void fatalx(const char *txt, ...)
{
Expand Down Expand Up @@ -1155,6 +1163,13 @@ draco_key_process(uint16_t scan, int down)
void *draco_keyboard_init(void)
{
draco_kbd.type = 10;
draco_kbd.name = "draco";
memset(oldkey, 0, sizeof(oldkey));
keyboard_at_set_defaults(&draco_kbd);
return &draco_kbd;
}

int draco_keyboard_get_rate(void)
{
return draco_kbd.rate;
}
Loading

0 comments on commit 76ac1b5

Please sign in to comment.