+#include <stdlib.h>
#include <stdarg.h>
#define u8 unsigned char
#define u32 unsigned int
#define noinline __attribute__((noinline))
+#define _packed __attribute__((packed))
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#include "edos.h"
#include "asmtools.h"
/* scroll plane */
write32(GFX_CTRL_PORT, GFX_WRITE_VSRAM_ADDR(0));
- write16(GFX_DATA_PORT, (printf_ypos - 27) * 8);
+ write16(GFX_DATA_PORT, (printf_ypos - CSCREEN_H + 1) * 8);
}
}
break;
case 'x':
uval = va_arg(ap, int);
- while (fwidth > 0 && uval < (1 << (fwidth - 1) * 4)) {
+ while (fwidth > 1 && uval < (1 << (fwidth - 1) * 4)) {
buf[d++] = prefix0 ? '0' : ' ';
fwidth--;
}
return d; // wrong..
}
-void exception(void)
+static const char *exc_names[] = {
+ NULL,
+ NULL,
+ "Bus Error",
+ "Address Error",
+ "Illegal Instruction",
+ "Zero Divide",
+ "CHK Instruction",
+ "TRAPV Instruction",
+ "Privilege Violation", /* 8 8 */
+ "Trace",
+ "Line 1010 Emulator",
+ "Line 1111 Emulator",
+ NULL,
+ NULL,
+ NULL,
+ "Uninitialized Interrupt",
+ NULL, /* 10 16 */
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ "Spurious Interrupt", /* 18 24 */
+ "l1 irq",
+ "l2 irq",
+ "l3 irq",
+ "l4 irq",
+ "l5 irq",
+ "l6 irq",
+ "l7 irq",
+};
+
+struct exc_frame {
+ u32 dr[8];
+ u32 ar[8];
+ u16 ecxnum; // from handler
+ union {
+ struct {
+ u16 sr;
+ u32 pc;
+ } g _packed;
+ struct {
+ u16 fc;
+ u32 addr;
+ u16 ir;
+ u16 sr;
+ u32 pc;
+ } bae _packed; // bus/address error frame
+ };
+} _packed;
+
+int xtttt(void) { return sizeof(struct exc_frame); }
+
+void exception(const struct exc_frame *f)
{
- VDP_drawTextML("============", APLANE, 0, 0);
- VDP_drawTextML(" exception! ", APLANE, 0, 1);
- VDP_drawTextML("============", APLANE, 0, 2);
- while (1)
+ int i;
+
+ while (read16(GFX_CTRL_PORT) & 2)
;
+ write16(GFX_CTRL_PORT, 0x8000 | (VDP_MODE1 << 8) | 0x04);
+ write16(GFX_CTRL_PORT, 0x8000 | (VDP_MODE2 << 8) | 0x44);
+ /* adjust scroll */
+ write32(GFX_CTRL_PORT, GFX_WRITE_VSRAM_ADDR(0));
+ write16(GFX_DATA_PORT,
+ printf_ypos >= CSCREEN_H ?
+ (printf_ypos - CSCREEN_H + 1) * 8 : 0);
+
+ printf("exception %i ", f->ecxnum);
+ if (f->ecxnum < ARRAY_SIZE(exc_names) && exc_names[f->ecxnum] != NULL)
+ printf("(%s)", exc_names[f->ecxnum]);
+ if (f->ecxnum < 4)
+ printf(" (%s)", (f->bae.fc & 0x10) ? "r" : "w");
+ printf(" \n");
+
+ if (f->ecxnum < 4) {
+ printf(" PC: %08x SR: %04x \n", f->bae.pc, f->bae.sr);
+ printf("addr: %08x IR: %04x FC: %02x \n",
+ f->bae.addr, f->bae.ir, f->bae.fc);
+ }
+ else {
+ printf(" PC: %08x SR: %04x \n", f->g.pc, f->g.sr);
+ }
+ for (i = 0; i < 8; i++)
+ printf(" D%d: %08x A%d: %08x \n", i, f->dr[i], i, f->ar[i]);
+ printf(" \n");
}
void vbl(void)
- dc.l 0x0,0x200\r
- dc.l INT,INT,INT,INT,INT,INT,INT\r
- dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
- dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
- dc.l INT,INT,INT,HBL,INT,VBL,INT,INT\r
- dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
- dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
- dc.l INT,INT,INT,INT,INT,INT,INT,INT\r
- dc.l INT,INT,INT,INT,INT,INT,INT\r
- .ascii "SEGA EVERDRIVE "\r
- .ascii "MEGA-ED host "\r
- .ascii "MEGA-ED host "\r
- .ascii "GM 00000000-00"\r
- .byte 0x00,0x00\r
- .ascii "JD "\r
- .byte 0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00\r
- .byte 0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff\r
- .ascii " "\r
- .ascii " "\r
- .ascii " "\r
- .ascii "JUE "\r
+exc_tab:\r
+ dc.l 0, 0x200, exc02, exc03, exc04, exc05, exc06, exc07\r
+ dc.l exc08, exc09, exc0a, exc0b, exc0c, exc0d, exc0e, exc0f\r
+ dc.l exc10, exc11, exc12, exc13, exc14, exc15, exc16, exc17\r
+ dc.l exc18, exc19, exc1a, exc1b, HBL, exc1d, VBL, exc1f\r
+ dc.l exc20, exc21, exc22, exc23, exc24, exc25, exc26, exc27\r
+ dc.l exc28, exc29, exc2a, exc2b, exc2c, exc2d, exc2e, exc2f\r
+ dc.l exc30, exc31, exc32, exc33, exc34, exc35, exc3e, exc37\r
+ dc.l exc38, exc39, exc3a, exc3b, exc3c, exc3d, exc3e, exc3f\r
+\r
+ .ascii "SEGA EVERDRIVE "\r
+ .ascii "MEGA-ED host "\r
+ .ascii "MEGA-ED host "\r
+ .ascii "GM 00000000-00"\r
+ .byte 0x00,0x00\r
+ .ascii "JD "\r
+ .byte 0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00\r
+ .byte 0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff\r
+ .ascii " "\r
+ .ascii " "\r
+ .ascii " "\r
+ .ascii "JUE "\r
\r
RST:\r
- move.w #0x2700, sr\r
+ move.w #0x2700, %sr\r
/* magic ED app init */\r
move.w #0x0000, (0xA13006)\r
jmp init_ed.l\r
dbra %d0, 0b\r
\r
move.w #0x10af, (0xA13006)\r
- move.l #HBL, (0x70)\r
- move.l #VBL, (0x78)\r
+\r
+ lea exc_tab, %a0\r
+ adda.l #4*2, %a0\r
+ movea.l #4*2, %a1\r
+ move.l #64-2-1, %d0\r
+0:\r
+ move.l (a0)+, (a1)+\r
+ dbra %d0, 0b\r
\r
moveq #0, %d0\r
movea.l %d0, %a7\r
move %a7, %usp\r
- move.w #0x2000, sr\r
+ move.w #0x2000, %sr\r
bra main\r
\r
-INT:\r
- movem.l %d0-%d1/%a0-%a1,-(%sp)\r
- jsr exception\r
- movem.l (%sp)+,%d0-%d1/%a0-%a1\r
- rte\r
-\r
HBL:\r
rte\r
\r
movem.l (%sp)+,%d0-%d1/%a0-%a1\r
rte\r
\r
+pre_exception:\r
+ move.w #0x2700, %sr\r
+ movem.l %d0-%d7/%a0-%a7,-(%sp)\r
+ move.l %sp, %d0\r
+ move.l %d0,-(%sp)\r
+ jsr exception\r
+0:\r
+ bra 0b\r
+\r
\r
* Standard 32X startup code for MD side at 0x3F0\r
.org 0x3F0\r
.word 0xFFC0,0x4CD6,0x7FF9,0x44FC,0x0000,0x6014,0x43F9,0x00A1\r
.word 0x5100,0x3340,0x0006,0x303C,0x8000,0x6004,0x44FC,0x0001\r
\r
+.macro exc_stub num\r
+exc\num:\r
+ move.w #0x\num, -(%sp)\r
+ jmp pre_exception\r
+.endm\r
+\r
+exc_stub 02\r
+exc_stub 03\r
+exc_stub 04\r
+exc_stub 05\r
+exc_stub 06\r
+exc_stub 07\r
+exc_stub 08\r
+exc_stub 09\r
+exc_stub 0a\r
+exc_stub 0b\r
+exc_stub 0c\r
+exc_stub 0d\r
+exc_stub 0e\r
+exc_stub 0f\r
+exc_stub 10\r
+exc_stub 11\r
+exc_stub 12\r
+exc_stub 13\r
+exc_stub 14\r
+exc_stub 15\r
+exc_stub 16\r
+exc_stub 17\r
+exc_stub 18\r
+exc_stub 19\r
+exc_stub 1a\r
+exc_stub 1b\r
+# exc_stub 1c\r
+exc_stub 1d\r
+# exc_stub 1e\r
+exc_stub 1f\r
+exc_stub 20\r
+exc_stub 21\r
+exc_stub 22\r
+exc_stub 23\r
+exc_stub 24\r
+exc_stub 25\r
+exc_stub 26\r
+exc_stub 27\r
+exc_stub 28\r
+exc_stub 29\r
+exc_stub 2a\r
+exc_stub 2b\r
+exc_stub 2c\r
+exc_stub 2d\r
+exc_stub 2e\r
+exc_stub 2f\r
+exc_stub 30\r
+exc_stub 31\r
+exc_stub 32\r
+exc_stub 33\r
+exc_stub 34\r
+exc_stub 35\r
+exc_stub 36\r
+exc_stub 37\r
+exc_stub 38\r
+exc_stub 39\r
+exc_stub 3a\r
+exc_stub 3b\r
+exc_stub 3c\r
+exc_stub 3d\r
+exc_stub 3e\r
+exc_stub 3f\r
+\r
+# vim:filetype=asmM68k:ts=4:sw=4:expandtab\r