# HG changeset patch # User John Tsiombikas # Date 1485757313 -7200 # Node ID 909c22dc18d26180e233216c14d4f476b6c1d284 initial commit diff -r 000000000000 -r 909c22dc18d2 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Mon Jan 30 08:21:53 2017 +0200 @@ -0,0 +1,6 @@ +\.o$ +\.d$ +\.swp$ +\.elf$ +\.bin$ +link\.map$ diff -r 000000000000 -r 909c22dc18d2 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Jan 30 08:21:53 2017 +0200 @@ -0,0 +1,32 @@ +asrc = $(wildcard src/*.s) +aSsrc = $(wildcard src/*.S) +obj = $(asrc:.s=.o) $(aSsrc:.S=.o) + +name = test1 +elf = $(name).elf +bin = $(name).bin + +warn = -pedantic -Wall +dbg = -g +def = -DGAMENAME=\"testgame\" -DVERSTR=\"01\" + +tool_prefix = m68k-linux-gnu- + +CC = $(tool_prefix)gcc +AS = $(tool_prefix)as +LD = $(tool_prefix)ld +OBJCOPY = $(tool_prefix)objcopy + +CFLAGS = -m68000 -nostdinc -fno-builtin $(warn) $(dbg) $(opt) $(def) +ASFLAGS = -m68000 +LDFLAGS = -T megadrive.ldscript -print-gc-sections + +$(bin): $(elf) + $(OBJCOPY) -O binary $< $@ + +$(elf): $(obj) + $(LD) -o $@ $(LDFLAGS) $(obj) -Map link.map + +.PHONY: clean +clean: + rm -f $(obj) $(elf) $(bin) diff -r 000000000000 -r 909c22dc18d2 megadrive.ldscript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/megadrive.ldscript Mon Jan 30 08:21:53 2017 +0200 @@ -0,0 +1,44 @@ +OUTPUT_ARCH(m68k) + +MEMORY +{ + rom : ORIGIN = 0x00000000, LENGTH = 0x00a00000 + ram : ORIGIN = 0x00ff0000, LENGTH = 0x00010000 +} + +PROVIDE (_stacktop = 0x01000000); + +SECTIONS { + /* ---- start of ROM ---- */ + /* .vect section is used to place the m68k exception vectors at the + * beginning of the address space + */ + .vect : { KEEP (* (.vect)); } >rom + /* .romhdr section is used to place the SEGA ROM header at 0x100 */ + . = 0x100; + .romhdr : { KEEP (* (.romhdr)); } >rom + .text : { * (.text); } >rom + .rodata : { * (.rodata); } >rom + + /* place the load address of the .data section after .rodata */ + _data_lma = .; + _rom_end = _data_lma + _data_size; + + /* ---- start of RAM ---- */ + . = 0xff0000; + /* place the .data section at the start of RAM */ + .data : AT (_data_lma) { + _data_start = .; + * (.data); + _data_end = .; + } >ram + _data_size = SIZEOF(.data); + + /* place the .bss section at the end */ + .bss : { + _bss_start = .; + * (.bss); + _bss_end = .; + } >ram + _bss_size = SIZEOF(.bss); +} diff -r 000000000000 -r 909c22dc18d2 src/intr.s --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/intr.s Mon Jan 30 08:21:53 2017 +0200 @@ -0,0 +1,82 @@ +| the following will go into the .vect section which will be placed at the very +| begining of the binary at address 0 by the linker (see lnkscript). + .section .vect,"a" + .extern start +| exception vectors + .long _stacktop | 00 reset - initial SSP + .long start | 01 reset - initial PC + .long intr_fatal | 02 bus error + .long intr_fatal | 03 address error + .long intr_fatal | 04 illegal instruction + .long intr_fatal | 05 zero divide + .long intr_fatal | 06 chk instruction + .long intr_fatal | 07 trapv instruction + .long intr_fatal | 08 privilege violation + .long intr_fatal | 09 trace + .long intr_fatal | 0a line 1010 emulator + .long intr_fatal | 0b line 1111 emulator + .long intr_fatal | 0c reserved + .long intr_fatal | 0d reserved + .long intr_fatal | 0e format error (mc68010 only) + .long intr_fatal | 0f uninitialized interrupt vector + .long intr_fatal | 10 \ + .long intr_fatal | 11 | + .long intr_fatal | 12 | + .long intr_fatal | 13 > reserved + .long intr_fatal | 14 | + .long intr_fatal | 15 | + .long intr_fatal | 16 | + .long intr_fatal | 17 / + .long intr_fatal | 18 spurious interrupt + .long intr_fatal | 19 level 1 interrupt + .long intr_fatal | 1a level 2 interrupt + .long intr_fatal | 1b level 3 interrupt + .long intr_hblank | 1c level 4 interrupt (hblank in the mega drive) + .long intr_fatal | 1d level 5 interrupt + .long intr_vblank | 1e level 6 interrupt (vblank in the mega drive) + .long intr_fatal | 1f level 7 interrupt + .long intr_fatal | 20 trap 0 + .long intr_fatal | 21 trap 1 + .long intr_fatal | 22 trap 2 + .long intr_fatal | 23 trap 3 + .long intr_fatal | 24 trap 4 + .long intr_fatal | 25 trap 5 + .long intr_fatal | 26 trap 6 + .long intr_fatal | 27 trap 7 + .long intr_fatal | 28 trap 8 + .long intr_fatal | 29 trap 9 + .long intr_fatal | 2a trap a + .long intr_fatal | 2b trap b + .long intr_fatal | 2c trap c + .long intr_fatal | 2d trap d + .long intr_fatal | 2e trap e + .long intr_fatal | 2f trap f + .long intr_fatal | 30 \ + .long intr_fatal | 31 | + .long intr_fatal | 32 | + .long intr_fatal | 33 | + .long intr_fatal | 34 | + .long intr_fatal | 35 | + .long intr_fatal | 36 | + .long intr_fatal | 37 | + .long intr_fatal | 38 > reserved + .long intr_fatal | 39 | + .long intr_fatal | 3a | + .long intr_fatal | 3b | + .long intr_fatal | 3c | + .long intr_fatal | 3d | + .long intr_fatal | 3e | + .long intr_fatal | 3f / + +| from here on we continue in the regular .text section since we don't care +| where this code ends up. + .text +| interrupt handlers +intr_fatal: + stop #0x2700 + +| TODO hblank/vblank code +intr_hblank: + rte +intr_vblank: + rte diff -r 000000000000 -r 909c22dc18d2 src/main.s --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.s Mon Jan 30 08:21:53 2017 +0200 @@ -0,0 +1,4 @@ + .text + .global main +main: + rts diff -r 000000000000 -r 909c22dc18d2 src/romhdr.S --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/romhdr.S Mon Jan 30 08:21:53 2017 +0200 @@ -0,0 +1,37 @@ +| the following will go into the custom .romhdr section which will be placed at +| address 100 of the binary by the linker (see lnkscript). + .section .romhdr,"a" + +#ifndef GAMENAME +#define GAMENAME "unnamed" +#endif +#ifndef VERSTR +#define VERSTR "00" +#endif + + .ascii "SEGA MEGA DRIVE (C)MINDLAPSE2017" +hdr_game_dom: + .ascii GAMENAME +hdr_game_dom_end: + .fill 48 - (hdr_game_dom_end - hdr_game_dom),1,32 | pad to 48 bytes with spaces +hdr_game_int: + .ascii GAMENAME +hdr_game_int_end: + .fill 48 - (hdr_game_int_end - hdr_game_int),1,32 | pad to 48 bytes with spaces + .ascii "GM" | it's a game (who cares what it is?) + .ascii "0000000-" | product code + .ascii VERSTR | version string + .short 0 | checksum + .ascii "J " | I/O support (joypad) + .long 0 | start address of ROM + .long _rom_end | last address of ROM + .long 0xff0000 | start address of RAM + .long 0xffffff | last address of RAM + .long 0 | SRAM enabled(?) + .long 0 | ??? + .long 0 | start address of SRAM + .long 0 | last address of SRAM + .long 0 | ??? + .long 0 | ??? + .fill 40,1,32 | notes (fill with spaces for now TODO) + .ascii "JUE " | country codes diff -r 000000000000 -r 909c22dc18d2 src/startup.s --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/startup.s Mon Jan 30 08:21:53 2017 +0200 @@ -0,0 +1,8 @@ +| TODO: copy .data and zero .bss + .text + .extern main + + .global start +start: + jsr main + stop #0x2700