Browse Source

iocs fixes

vampirefrog 1 year ago
parent
commit
ded26d0db5
3 changed files with 36 additions and 10 deletions
  1. 9
    8
      v68.c
  2. 23
    2
      v68iocscall.c
  3. 4
    0
      v68iocscall.h

+ 9
- 8
v68.c View File

@@ -5,10 +5,13 @@
5 5
 #include <limits.h>
6 6
 
7 7
 #include "v68.h"
8
+#include "v68ipl.h"
8 9
 #include "v68io.h"
9 10
 #include "v68periph.h"
11
+#include "v68iocscall.h"
10 12
 #include "musashi/m68kcpu.h"
11 13
 
14
+
12 15
 struct v68 v68;
13 16
 
14 17
 int v68_init(int clock, int ram_size, int sample_rate) {
@@ -33,6 +36,7 @@ int v68_init(int clock, int ram_size, int sample_rate) {
33 36
 	v68_periph_init();
34 37
 	v68_io_init();
35 38
 	v68_human_init();
39
+	v68_iocs_init();
36 40
 
37 41
 	return 0;
38 42
 }
@@ -219,17 +223,14 @@ unsigned int m68k_read_disassembler_32 (unsigned int addr) {
219 223
 	return m68k_read_memory_32(addr);
220 224
 }
221 225
 
222
-void v68_iocs_call(uint16_t instr);
223 226
 int v68_trap(int which) {
227
+	verbose1("v68_trap which=%d d0=0x%08x\n", which, m68k_get_reg(NULL, M68K_REG_D0));
224 228
 	switch(which) {
225
-		case 15: {
226
-				/* IOCS */
227
-				v68_iocs_call(m68k_get_reg(NULL, M68K_REG_D0));
228
-				return 0;
229
-			}
230
-			break;
229
+		case 15:
230
+			/* IOCS */
231
+			return v68_iocs_call(m68k_get_reg(NULL, M68K_REG_D0));
231 232
 		default:
232
-			verbose2("v68_trap %d\n", which);
233
+			verbose2("v68_trap unknown #%d d0=0x%08x\n", which, m68k_get_reg(0, M68K_REG_D0));
233 234
 	}
234 235
 	return 1;
235 236
 }

+ 23
- 2
v68iocscall.c View File

@@ -3,6 +3,7 @@
3 3
 #include <string.h>
4 4
 #include <sys/sysinfo.h>
5 5
 #include "v68.h"
6
+#include "v68iocscall.h"
6 7
 #include "musashi/m68k.h"
7 8
 #include "musashi/m68kcpu.h"
8 9
 #include "sjis.h"
@@ -463,18 +464,38 @@ static const char *iocs_call_names[256] = {
463 464
 	/* 0xff */ "_ABORTJOB",
464 465
 };
465 466
 
467
+void v68_iocs_init() {
468
+	/* Set the IOCS call addresses at 0x400 */
469
+	for(int i = 0; i < 256; i++) {
470
+		m68k_write_memory_32(0x400 + i * 4, 0xff0000);
471
+	}
472
+}
473
+
466 474
 int v68_iocs_call(uint16_t instr) {
467 475
 	uint8_t call = instr & 0xff;
476
+	uint32_t call_addr = m68k_read_memory_32(0x400 + call * 4);
468 477
 
469 478
 	if(v68.log_calls)
470
-		printf("V68 IOCS CALL %04x %s\n", instr, iocs_call_names[call]);
479
+		printf("v68_iocs_call call=0x%02x %s call_addr=0x%08x\n", instr, iocs_call_names[call], call_addr);
480
+
481
+	if(call_addr < 0xff0000) {/* Only implement calls that aren't overridden */
482
+		uint16_t sr = m68k_get_reg(0, M68K_REG_SR);
483
+		uint32_t sp = m68k_get_reg(0, M68K_REG_SP);
484
+		verbose2("v68_iocs_call call_addr=0x%08x implemented sp=0x%08x\n", call_addr, sp);
485
+		sp -= 4;
486
+		m68k_set_reg(M68K_REG_SR, sr | 0x2000);
487
+		uint32_t pc = m68k_get_reg(0, M68K_REG_PC);
488
+		m68k_write_memory_32(sp, pc);
489
+		m68k_set_reg(M68K_REG_SP, sp);
490
+		m68k_set_reg(M68K_REG_PC, call_addr);
491
+		return 0;
492
+	}
471 493
 
472 494
 	switch(call) {
473 495
 		case IOCS_CALL_B_PUTC: {
474 496
 				uint16_t chr = m68k_get_reg(0, M68K_REG_D0);
475 497
 				uint8_t chrbuf[2] = { chr >> 8, chr };
476 498
 				sjis_print_utf8(chrbuf[0] ? chrbuf : chrbuf+1, chrbuf[0] ? 2 : 1);
477
-
478 499
 				m68k_set_reg(M68K_REG_D0, 0x00100010);
479 500
 			}
480 501
 			break;

+ 4
- 0
v68iocscall.h View File

@@ -0,0 +1,4 @@
1
+#pragma once
2
+
3
+void v68_iocs_init(void);
4
+int v68_iocs_call(uint16_t instr);

Loading…
Cancel
Save