Skip to content

Commit

Permalink
[qemu-pc9821] qemu-20120820-pc9821 import
Browse files Browse the repository at this point in the history
  • Loading branch information
roytam1 committed Apr 5, 2020
1 parent 6abfd64 commit 1295319
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 147 deletions.
2 changes: 1 addition & 1 deletion qemu-pc9821/qemu/hw/fdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static const fd_format_t fd_formats[] = {
/* 1.23 MB 5"1/4 floppy disks */
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 1024, 8, 77, 1, "1.23 MB 5\"1/4", },
/* 1.2 MB 5"1/4 floppy disks */
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 512, 15, 80, 1, "1.2 kB 5\"1/4", },
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 512, 15, 80, 1, "1.2 MB 5\"1/4", },
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 512, 18, 80, 1, "1.44 MB 5\"1/4", },
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 512, 18, 82, 1, "1.48 MB 5\"1/4", },
{ FDRIVE_DRV_120, FDRIVE_DISK_288, 512, 18, 83, 1, "1.49 MB 5\"1/4", },
Expand Down
4 changes: 2 additions & 2 deletions qemu-pc9821/qemu/hw/fmopna.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static inline uint16_t limit_sample(Sample sample)
return highlow;
}

void *opna_init(int frequency, int sample_rate)
void *opna_init(int frequency, int sample_rate, const char* path)
{
OPNAState *s = (OPNAState *)malloc(sizeof(OPNAState));

Expand All @@ -92,7 +92,7 @@ void *opna_init(int frequency, int sample_rate)
s->fifo_l = (Sample *)malloc(sizeof(Sample) * BUFLEN);
s->fifo_r = (Sample *)malloc(sizeof(Sample) * BUFLEN);

s->opna->Init(frequency, sample_rate, false, NULL);
s->opna->Init(frequency, sample_rate, false, path);
s->opna->Reset();
s->opna->SetReg(0x27, 0);

Expand Down
2 changes: 1 addition & 1 deletion qemu-pc9821/qemu/hw/fmopna.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
extern "C" {
#endif

void *opna_init(int frequency, int sample_rate);
void *opna_init(int frequency, int sample_rate, const char* path);
void opna_reset(void *opaque);
void opna_update_buffer(void *opaque, int16_t *buffer, int samples, int stereo);
void opna_advance_time(void *opaque, int usec);
Expand Down
21 changes: 12 additions & 9 deletions qemu-pc9821/qemu/hw/pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,12 +1199,8 @@ QEMUMachine isapc_machine = {

/* NEC PC-9821 */

#ifdef HAS_AUDIO
#define SUPPORT_PC98_FMSOUND

#ifdef SUPPORT_PC98_FMSOUND
#define PC98_NE2000_NB_MAX 1
#else
#define PC98_NE2000_NB_MAX 2
#endif

static void *pc98_sys;
Expand Down Expand Up @@ -1254,12 +1250,16 @@ static uint32_t pc98_ioport_9894_read(void *opaque, uint32_t addr)
return 0x90; /* cpu wait */
}

#ifndef SUPPORT_PC98_FMSOUND
#ifdef HAS_AUDIO
#ifdef SUPPORT_PC98_FMSOUND
/* This port is assigned in pc98fmsound.c */
#else
static uint32_t pc98_ioport_a460_read(void *opaque, uint32_t addr)
{
return 0x7f; /* Mate-X PCM */
}
#endif
#endif

void pc98_cpu_shutdown(void)
{
Expand All @@ -1276,8 +1276,10 @@ void pc98_select_ems(uint32_t value)
}

/* LGY-98 */
#define PC98_NE2000_NB_MAX 2

static const int pc98_ne2000_io[2] = { 0xd0, 0x10d0 };
static const int pc98_ne2000_irq[2] = { 6, 3 };
static const int pc98_ne2000_irq[2] = { 6, 5 };

static void pc98_init_ne2k_isa(NICInfo *nd, qemu_irq *pic)
{
Expand Down Expand Up @@ -1375,9 +1377,8 @@ static void pc98_init1(ram_addr_t ram_size,
1 KEYBOARD
2 CRTV
3 PC-9801-86
LGY-98 #2 (I/O=10D0h)
4 RS-232C
5 (SCSI)
5 LGY-98 #2 (I/O=10D0h)
6 LGY-98 #1 (I/O=00D0h)
7 SLAVE PIC
8 FPU
Expand All @@ -1401,10 +1402,12 @@ static void pc98_init1(ram_addr_t ram_size,
register_ioport_write(0x534, 1, 1, pc98_ioport_534_write, NULL);
register_ioport_read(0x534, 1, 1, pc98_ioport_534_read, NULL);
register_ioport_read(0x9894, 1, 1, pc98_ioport_9894_read, NULL);
#ifdef HAS_AUDIO
#ifdef SUPPORT_PC98_FMSOUND
/* This port is assigned in pc98fmsound.c */
#else
register_ioport_read(0xa460, 1, 1, pc98_ioport_a460_read, NULL);
#endif
#endif

cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1);
Expand Down
103 changes: 65 additions & 38 deletions qemu-pc9821/qemu/hw/pc98kbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,44 @@ enum {
};

/*
END -> HELP
F11 -> STOP
F12 -> COPY
F11 -> STOP
F12 -> COPY
Home -> HOME/CR
End -> HELP
PageUp -> ROLL UP
Page Down -> ROLL DOWN
L-Alt -> GRAPH
R-Alt -> KANA
Henkan -> XFER
Muhenkan -> NFER
*/

static const uint8_t kbd_table[128] = {
0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x74, 0x1d, 0x1e,
0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
0x27, 0xff, 0x70, 0x28, 0x29, 0x2a, 0x2b, 0x2c,
0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x70, 0xff,
0x70, 0x34, 0xff, 0x62, 0x63, 0x64, 0x65, 0x66,
0x67, 0x68, 0x69, 0x6a, 0x6b, 0xff, 0xff, 0x3e,
0x3a, 0x36, 0xff, 0x3b, 0xff, 0x3c, 0xff, 0x3f,
0x3d, 0x37, 0x38, 0x39, 0xff, 0xff, 0xff, 0x60,
0x61, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x33, 0xff, 0xff, 0xff, 0xff,
0xff, 0x35, 0xff, 0x51, 0xff, 0x0d, 0xff, 0xff,
0xff,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0e,0x0f,
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x74,0x1d,0x1e,
0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0xff,0x70,0x28,0x29,0x2a,0x2b,0x2c,
0x2d,0x2e,0x2f,0x30,0x31,0x32,0x70,0x45,0x73,0x34,0x71,0x62,0x63,0x64,0x65,0x66,
0x67,0x68,0x69,0x6a,0x6b,0xff,0xff,0x42,0x43,0x44,0x40,0x46,0x47,0x48,0x49,0x4a,
0x4b,0x4c,0x4e,0x50,0xff,0xff,0xff,0x60,0x61,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0x33,0xff,0xff,0xff,0xff,0xff,0x35,0xff,0x51,0xff,0x0d,0xff,0xff,
};
static const uint8_t kbd_table_e0[128] = {
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x1c,0x74,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0x41,0xff,0xff,0x72,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x3e,0x3a,0x36,0xff,0x3b,0xff,0x3c,0xff,0x3f,
0x3d,0x37,0x38,0x39,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
};

struct KeyBoardState {
/* keyboard */
uint8_t lock;
uint8_t pressed[128];
uint8_t recv_e0;

/* sio */
uint8_t mode;
Expand All @@ -112,7 +122,9 @@ typedef struct KeyBoardState KeyBoardState;

static void kbd_reset(KeyBoardState *s)
{
/*
printf("pc98kbd: reset\n");
*/
}

static void kbd_recv(KeyBoardState *s, uint8_t value)
Expand Down Expand Up @@ -177,37 +189,52 @@ static void kbd_send(KeyBoardState *s, uint8_t value)
static void kbd_event_handler(void *opaque, int keycode)
{
KeyBoardState *s = opaque;
const uint8_t *table;

if (s->recv_e0 != 0) {
s->recv_e0 = 0;
table = kbd_table_e0;
} else {
if (keycode == 0xe0) {
s->recv_e0 = 1;
return;
}
table = kbd_table;
}

if (keycode & 0x80) {
/* key released */
if ((keycode = kbd_table[keycode & 0x7f]) != 0xff) {
if ((keycode = table[keycode & 0x7f]) != 0xff) {
if (s->pressed[keycode]) {
kbd_recv(s, keycode | 0x80);
}
s->pressed[keycode] = 0;
}
} else {
/* key pressed */
if (keycode == 0x3a) {
s->lock ^= KBD_LOCK_CAPS;
if (s->lock & KBD_LOCK_CAPS) {
kbd_recv(s, 0x71);
if ((keycode = table[keycode]) != 0xff) {
if (keycode == 0x71) {
s->lock ^= KBD_LOCK_CAPS;
if (s->lock & KBD_LOCK_CAPS) {
kbd_recv(s, 0x71);
} else {
kbd_recv(s, 0x71 | 0x80);
}
} else if (keycode == 0x72) {
s->lock ^= KBD_LOCK_KANA;
if (s->lock & KBD_LOCK_KANA) {
kbd_recv(s, 0x72);
} else {
kbd_recv(s, 0x72 | 0x80);
}
} else {
kbd_recv(s, 0x71 | 0x80);
if (s->pressed[keycode]) {
kbd_recv(s, keycode | 0x80);
}
kbd_recv(s, keycode);
s->pressed[keycode] = 1;
}
} else if (keycode == 0x70) {
s->lock ^= KBD_LOCK_KANA;
if (s->lock & KBD_LOCK_KANA) {
kbd_recv(s, 0x72);
} else {
kbd_recv(s, 0x72 | 0x80);
}
} else if ((keycode = kbd_table[keycode]) != 0xff) {
if (s->pressed[keycode]) {
kbd_recv(s, keycode | 0x80);
}
kbd_recv(s, keycode);
s->pressed[keycode] = 1;

}
}
}
Expand Down
14 changes: 8 additions & 6 deletions qemu-pc9821/qemu/hw/pc98sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,17 @@ static void sound_regnum_ex_write(void *opaque, uint32_t addr, uint32_t value)
SoundState *s = opaque;

if(!(s->mask & 1)) {
// return;
return;
}
s->regnum_ex = value;
}

static uint32_t sound_status_ex_read(void *opaque, uint32_t addr)
{
/* 0x18C */
SoundState *s = opaque;

if(!(s->mask & 1)) {
// return 0xff;
return 0xff;
}

/* run fmgen to update status */
Expand All @@ -296,7 +295,7 @@ static void sound_reg_ex_write(void *opaque, uint32_t addr, uint32_t value)
SoundState *s = opaque;

if(!(s->mask & 1)) {
// return;
return;
}
opna_write_reg_ex(s->opna, s->regnum_ex, value);
update_interrupt(s);
Expand All @@ -317,7 +316,7 @@ static uint32_t sound_reg_ex_read(void *opaque, uint32_t addr)
SoundState *s = opaque;

if(!(s->mask & 1)) {
// return 0xff;
return 0xff;
}
return opna_read_reg_ex(s->opna, s->regnum_ex);
}
Expand Down Expand Up @@ -368,6 +367,7 @@ void pc98_sound_init(AudioState *audio, qemu_irq *pic, int irq)
{
SoundState *s;
struct audsettings as;
char temp_dir[MAX_PATH];

s = qemu_mallocz(sizeof(SoundState));

Expand All @@ -393,7 +393,9 @@ void pc98_sound_init(AudioState *audio, qemu_irq *pic, int irq)
AUD_remove_card(&s->card);
}

s->opna = opna_init(3993552 << 1, SAMPLE_RATE);
/* fmgen requires '/' at the end of wave file dir */
sprintf(temp_dir, "%s/", bios_dir);
s->opna = opna_init(7987200, SAMPLE_RATE, temp_dir);

register_ioport_write(0x188, 1, 1, sound_regnum_write, s);
register_ioport_read(0x188, 1, 1, sound_status_read, s);
Expand Down
Loading

0 comments on commit 1295319

Please sign in to comment.