changeset 0:826a1cb3f873

Copied SGDK project skeleton
author Mike Pavone <pavone@retrodev.com>
date Sun, 12 Jan 2014 11:24:36 -0800
parents
children 99f5e303fca1
files Makefile boot/rom_head.c boot/sega.s
diffstat 3 files changed, 636 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Sun Jan 12 11:24:36 2014 -0800
@@ -0,0 +1,173 @@
+CC = m68k-elf-gcc
+AS = m68k-elf-as
+OBJC = m68k-elf-objcopy
+LD = m68k-elf-ld
+RM = rm -f
+ASMZ80 = zasm
+BINTOS = bintos
+PCMTORAW = pcmtoraw
+WAVTORAW = wavtoraw
+NM = nm
+NM2WCH = nm2wch
+SIZEBND = sizebnd
+MKISOFS = mkisofs
+
+SCD_LOADER = scd/LukeProjectCD
+
+OPTION =
+INCS = -I. -I$(GENDEV)/m68k-elf/include -I$(GENDEV)/m68k-elf/m68k-elf/include -Isrc -Ires
+CCFLAGS = $(OPTION) -m68000 -Wall -O2 -c -fomit-frame-pointer
+HWCCFLAGS = $(OPTION) -m68000 -Wall -O1 -c -fomit-frame-pointer
+Z80FLAGS = -vb2
+ASFLAGS = -m68000 --register-prefix-optional
+#LIBS =  -L$(GENDEV)/m68k-elf/lib -L$(GENDEV)/m68k-elf/lib/gcc/m68k-elf/4.5.2 -L$(GENDEV)/m68k-elf/m68k-elf/lib -lmd -lc -lgcc -lnosys -lm 
+LIBS =  -L$(GENDEV)/m68k-elf/lib -L$(GENDEV)/m68k-elf/lib/gcc/m68k-elf/4.5.2 -L$(GENDEV)/m68k-elf/m68k-elf/lib -lmd -lnosys 
+LINKFLAGS = -T $(GENDEV)/ldscripts/sgdk.ld -nostdlib 
+SCDLINKFLAGS = -T scd/mdcd.ld -nostdlib 
+ARCHIVES = $(GENDEV)/m68k-elf/lib/libmd.a $(GENDEV)/m68k-elf/lib/gcc/m68k-elf/4.5.2/libgcc.a 
+
+RESOURCES=
+BOOT_RESOURCES=
+
+BOOTSS=$(wildcard boot/*.s)
+BOOTSS+=$(wildcard src/boot/*.s)
+BOOT_RESOURCES+=$(BOOTSS:.s=.o)
+
+SCDBOOTSS=$(wildcard scd/*.s)
+SCDBOOTSS+=$(wildcard src/scd/*.s)
+SCDBOOT_RESOURCES=$(SCDBOOTSS:.s=.o)
+
+BMPS=$(wildcard res/*.bmp)
+VGMS=$(wildcard res/*.vgm)
+RAWS=$(wildcard res/*.raw)
+PCMS=$(wildcard res/*.pcm)
+MVSS=$(wildcard res/*.mvs)
+TFDS=$(wildcard res/*.tfd)
+WAVS=$(wildcard res/*.wav)
+WAVPCMS=$(wildcard res/*.wavpcm)
+BMPS+=$(wildcard *.bmp)
+VGMS+=$(wildcard *.vgm)
+RAWS+=$(wildcard *.raw)
+PCMS+=$(wildcard *.pcm)
+MVSS+=$(wildcard *.mvs)
+TFDS+=$(wildcard *.tfd)
+WAVS+=$(wildcard *.wav)
+WAVPCMS+=$(wildcard *.wavpcm)
+RESOURCES+=$(BMPS:.bmp=.o)
+RESOURCES+=$(VGMS:.vgm=.o)
+RESOURCES+=$(RAWS:.raw=.o)
+RESOURCES+=$(PCMS:.pcm=.o)
+RESOURCES+=$(MVSS:.mvs=.o)
+RESOURCES+=$(TFDS:.tfd=.o)
+RESOURCES+=$(WAVS:.wav=.o)
+RESOURCES+=$(WAVPCMS:.wavpcm=.o)
+
+CS=$(wildcard src/*.c)
+SS=$(wildcard src/*.s)
+S80S=$(wildcard src/*.s80)
+CS+=$(wildcard *.c)
+SS+=$(wildcard *.s)
+S80S+=$(wildcard *.s80)
+RESOURCES+=$(CS:.c=.o)
+RESOURCES+=$(SS:.s=.o)
+RESOURCES+=$(S80S:.s80=.o)
+
+OBJS = $(RESOURCES)
+
+all: out.bin 
+
+boot/sega.o: boot/rom_head.bin
+	$(AS) $(ASFLAGS) boot/sega.s -o $@
+
+scd/segacd.o: 
+	$(AS) $(ASFLAGS) scd/segacd.s -o $@
+
+
+out.iso: out.elf_scd
+	#
+	# Create a sega cd image.  Limited to 256K or smaller Roms
+	#
+	$(NM) -n -S -t x out.elf_scd > out.nm
+	$(OBJC) -O binary out.elf_scd out.bin
+	$(SIZEBND) out.bin -sizealign 131072   
+	$(OBJC) -O binary out.elf_scd $(SCD_LOADER)/_filesystem/M_INIT.PRG
+	$(SIZEBND) $(SCD_LOADER)/_filesystem/M_INIT.PRG -sizealign 131072    
+	$(MKISOFS) -iso-level 1 -o $(SCD_LOADER)/filesystem.img -pad $(SCD_LOADER)/_filesystem
+	tail -c +32769 $(SCD_LOADER)/filesystem.img > $(SCD_LOADER)/filesystem.bin
+	$(RM) -f $(SCD_LOADER)/filesystem.img
+	cd $(SCD_LOADER) && $(AS) $(ASFLAGS) -M -ahlsm=listing.asm  main-us-as.asm -o out.iso
+	tail -c +53 $(SCD_LOADER)/out.iso > out.iso
+	$(RM) -f $(SCD_LOADER)/filesystem.bin
+
+%.bin: %.elf
+	$(OBJC) -O binary $< temp.bin
+	dd if=temp.bin of=$@ bs=8K conv=sync
+
+%.elf: $(OBJS) $(BOOT_RESOURCES)
+	$(CC) -o $@ $(LINKFLAGS) $(BOOT_RESOURCES) $(ARCHIVES) $(OBJS) $(LIBS)
+
+%.elf_scd: $(OBJS) $(SCDBOOT_RESOURCES)
+	$(CC) -o $@ $(SCDLINKFLAGS) $(SCDBOOT_RESOURCES) $(ARCHIVES) $(OBJS) $(LIBS)
+
+%.o80: %.s80
+	$(ASMZ80) $(Z80FLAGS) -o $@ $<
+
+%.c: %.o80
+	$(BINTOS) $<
+
+%.o: %.c
+	$(CC) $(CCFLAGS) $(INCS) -c $< -o $@
+
+%.o: %.s 
+	$(AS) $(ASFLAGS) $< -o $@
+
+%.s: %.bmp
+	bintos -bmp $<
+
+%.rawpcm: %.pcm
+	$(PCMTORAW) $< $@
+
+%.raw: %.wav
+	$(WAVTORAW) $< $@ 16000
+
+%.pcm: %.wavpcm
+	$(WAVTORAW) $< $@ 22050
+
+#%.tfc: %.tfd
+#	$(TFMCOM) $<
+
+#%.o80: %.s80
+#	$(ASMZ80) $(FLAGSZ80) $< $@ out.lst
+
+%.s: %.tfd
+	$(BINTOS) -align 32768 $<
+
+%.s: %.mvs
+	$(BINTOS) -align 256 $<
+
+%.s: %.esf
+	$(BINTOS) -align 32768 $<
+
+%.s: %.eif
+	$(BINTOS) -align 256 $<
+
+%.s: %.vgm 
+	$(BINTOS) -align 256 $<
+
+%.s: %.raw
+	$(BINTOS) -align 256 -sizealign 256 $<
+
+%.s: %.rawpcm
+	$(BINTOS) -align 128 -sizealign 128 -nullfill 136 $<
+
+%.s: %.rawpcm
+	$(BINTOS) -align 128 -sizealign 128 -nullfill 136 $<
+
+boot/rom_head.bin: boot/rom_head.o
+	$(LD) $(LINKFLAGS) --oformat binary -o $@ $<
+	
+
+clean:
+	$(RM) $(RESOURCES)
+	$(RM) *.o *.bin *.elf *.elf_scd *.map *.iso
+	$(RM) boot/*.o boot/*.bin
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/boot/rom_head.c	Sun Jan 12 11:24:36 2014 -0800
@@ -0,0 +1,43 @@
+#include "types.h"
+
+
+const struct
+{
+    char console[16];               /* Console Name (16) */
+    char copyright[16];             /* Copyright Information (16) */
+    char title_local[48];           /* Domestic Name (48) */
+    char title_int[48];             /* Overseas Name (48) */
+    char serial[14];                /* Serial Number (2, 12) */
+    u16 checksum;                   /* Checksum (2) */
+    char IOSupport[16];             /* I/O Support (16) */
+    u32 rom_start;                  /* ROM Start Address (4) */
+    u32 rom_end;                    /* ROM End Address (4) */
+    u32 ram_start;                  /* Start of Backup RAM (4) */
+    u32 ram_end;                    /* End of Backup RAM (4) */
+    char sram_sig[2];               /* "RA" for save ram (2) */
+    u16 sram_type;                  /* 0xF820 for save ram on odd bytes (2) */
+    u32 sram_start;                 /* SRAM start address - normally 0x200001 (4) */
+    u32 sram_end;                   /* SRAM end address - start + 2*sram_size (4) */
+    char modem_support[12];         /* Modem Support (24) */
+    char notes[40];                 /* Memo (40) */
+    char region[16];                /* Country Support (16) */
+} rom_header = {
+    "SEGA MEGA DRIVE ",
+    "(C)FLEMTEAM 2013",
+    "SAMPLE PROGRAM                                  ",
+    "SAMPLE PROGRAM                                  ",
+    "GM 00000000-00",
+    0x0000,
+    "JD              ",
+    0x00000000,
+    0x00100000,
+    0x00FF0000,
+    0x00FFFFFF,
+    "  ",
+    0x0000,
+    0x00200000,
+    0x002001FF,
+    "            ",
+    "DEMONSTRATION PROGRAM                   ",
+    "JUE             "
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/boot/sega.s	Sun Jan 12 11:24:36 2014 -0800
@@ -0,0 +1,420 @@
+.text
+
+*-------------------------------------------------------
+*
+*       Sega startup code for the GNU Assembler
+*       Translated from:
+*       Sega startup code for the Sozobon C compiler
+*       Written by Paul W. Lee
+*       Modified by Charles Coty
+*       Modified by Stephane Dallongeville
+*
+*-------------------------------------------------------
+
+        .org    0x00000000
+
+_Start_Of_Rom:
+_Vecteurs_68K:
+        dc.l    0x00FFFE00              /* Stack address */
+        dc.l    _Entry_Point            /* Program start address */
+        dc.l    _Bus_Error
+        dc.l    _Address_Error
+        dc.l    _Illegal_Instruction
+        dc.l    _Zero_Divide
+        dc.l    _Chk_Instruction
+        dc.l    _Trapv_Instruction
+        dc.l    _Privilege_Violation
+        dc.l    _Trace
+        dc.l    _Line_1010_Emulation
+        dc.l    _Line_1111_Emulation
+        dc.l     _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
+        dc.l     _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
+        dc.l     _Error_Exception, _Error_Exception, _Error_Exception, _Error_Exception
+        dc.l    _Error_Exception, _INT, _EXTINT, _INT
+        dc.l    _HINT
+        dc.l    _INT
+        dc.l    _VINT
+        dc.l    _INT
+        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
+        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
+        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
+        dc.l    _INT,_INT,_INT,_INT,_INT,_INT,_INT,_INT
+
+        .incbin "boot/rom_head.bin", 0x10, 0x100
+
+_Entry_Point:
+        move    #0x2700,%sr
+        tst.l   0xa10008
+        bne.s   SkipJoyDetect
+        tst.w   0xa1000c
+SkipJoyDetect:
+        bne.s   SkipSetup
+
+        lea     Table,%a5
+        movem.w (%a5)+,%d5-%d7
+        movem.l (%a5)+,%a0-%a4
+* Check Version Number
+        move.b  -0x10ff(%a1),%d0
+        andi.b  #0x0f,%d0
+        beq.s   WrongVersion
+* Sega Security Code (SEGA)
+        move.l  #0x53454741,0x2f00(%a1)
+WrongVersion:
+        move.w  (%a4),%d0
+        moveq   #0x00,%d0
+        movea.l %d0,%a6
+        move    %a6,%usp
+        move.w  %d7,(%a1)
+        move.w  %d7,(%a2)
+        jmp     Continue
+
+Table:
+        dc.w    0x8000,0x3fff,0x0100
+        dc.l    0xA00000,0xA11100,0xA11200,0xC00000,0xC00004
+
+SkipSetup:
+        move.w  #0,%a7
+        jmp     _reset_entry
+
+Continue:
+
+* clear Genesis RAM
+        lea     0xff0000,%a0
+        moveq   #0,%d0
+        move.w  #0x3FFF,%d1
+
+ClearRam:
+        move.l  %d0,(%a0)+
+        dbra    %d1,ClearRam
+
+* copy initialized variables from ROM to Work RAM
+        lea     _stext,%a0
+        lea     0xFF0000,%a1
+        move.l  #_sdata,%d0
+        lsr.l   #1,%d0
+        beq     NoCopy
+
+        subq.w  #1,%d0
+CopyVar:
+        move.w  (%a0)+,(%a1)+
+        dbra    %d0,CopyVar
+
+NoCopy:
+
+* Jump to initialisation process...
+
+        move.w  #0,%a7
+        jmp     _start_entry
+
+
+*------------------------------------------------
+*
+*       interrupt functions
+*
+*------------------------------------------------
+
+_Bus_Error:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  busErrorCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Address_Error:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  addressErrorCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Illegal_Instruction:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  illegalInstCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Zero_Divide:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  zeroDivideCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Chk_Instruction:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  chkInstCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Trapv_Instruction:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  trapvInstCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Privilege_Violation:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  privilegeViolationCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Trace:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  traceCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Line_1010_Emulation:
+_Line_1111_Emulation:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  line1x1xCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_Error_Exception:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  errorExceptionCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_INT:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  intCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_EXTINT:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  internalExtIntCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_HINT:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  internalHIntCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+_VINT:
+        movem.l %d0-%d1/%a0-%a1,-(%sp)
+        move.l  internalVIntCB, %a0
+        jsr    (%a0)
+        movem.l (%sp)+,%d0-%d1/%a0-%a1
+        rte
+
+*------------------------------------------------
+*
+* Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
+*
+* Permission is granted to anyone to use this software for any purpose
+* on any computer system, and to redistribute it freely, with the
+* following restrictions:
+* 1) No charge may be made other than reasonable charges for reproduction.
+* 2) Modified versions must be clearly marked as such.
+* 3) The authors are not responsible for any harmful consequences
+*    of using this software, even if they result from defects in it.
+*
+*------------------------------------------------
+
+ldiv:
+        move.l  4(%a7),%d0
+        bpl     ld1
+        neg.l   %d0
+ld1:
+        move.l  8(%a7),%d1
+        bpl     ld2
+        neg.l   %d1
+        eor.b   #0x80,4(%a7)
+ld2:
+        bsr     i_ldiv          /* d0 = d0/d1 */
+        tst.b   4(%a7)
+        bpl     ld3
+        neg.l   %d0
+ld3:
+        rts
+
+lmul:
+        move.l  4(%a7),%d0
+        bpl     lm1
+        neg.l   %d0
+lm1:
+        move.l  8(%a7),%d1
+        bpl     lm2
+        neg.l   %d1
+        eor.b   #0x80,4(%a7)
+lm2:
+        bsr     i_lmul          /* d0 = d0*d1 */
+        tst.b   4(%a7)
+        bpl     lm3
+        neg.l   %d0
+lm3:
+        rts
+
+lrem:
+        move.l  4(%a7),%d0
+        bpl     lr1
+        neg.l   %d0
+lr1:
+        move.l  8(%a7),%d1
+        bpl     lr2
+        neg.l   %d1
+lr2:
+        bsr     i_ldiv          /* d1 = d0%d1 */
+        move.l  %d1,%d0
+        tst.b   4(%a7)
+        bpl     lr3
+        neg.l   %d0
+lr3:
+        rts
+
+ldivu:
+        move.l  4(%a7),%d0
+        move.l  8(%a7),%d1
+        bsr     i_ldiv
+        rts
+
+lmulu:
+        move.l  4(%a7),%d0
+        move.l  8(%a7),%d1
+        bsr     i_lmul
+        rts
+
+lremu:
+        move.l  4(%a7),%d0
+        move.l  8(%a7),%d1
+        bsr     i_ldiv
+        move.l  %d1,%d0
+        rts
+*
+* A in d0, B in d1, return A*B in d0
+*
+i_lmul:
+        move.l  %d3,%a2           /* save d3 */
+        move.w  %d1,%d2
+        mulu    %d0,%d2           /* d2 = Al * Bl */
+
+        move.l  %d1,%d3
+        swap    %d3
+        mulu    %d0,%d3           /* d3 = Al * Bh */
+
+        swap    %d0
+        mulu    %d1,%d0           /* d0 = Ah * Bl */
+
+        add.l   %d3,%d0           /* d0 = (Ah*Bl + Al*Bh) */
+        swap    %d0
+        clr.w   %d0               /* d0 = (Ah*Bl + Al*Bh) << 16 */
+
+        add.l   %d2,%d0           /* d0 = A*B */
+        move.l  %a2,%d3           /* restore d3 */
+        rts
+*
+*A in d0, B in d1, return A/B in d0, A%B in d1
+*
+i_ldiv:
+        tst.l   %d1
+        bne     nz1
+
+*       divide by zero
+*       divu    #0,%d0            /* cause trap */
+        move.l  #0x80000000,%d0
+        move.l  %d0,%d1
+        rts
+nz1:
+        move.l  %d3,%a2           /* save d3 */
+        cmp.l   %d1,%d0
+        bhi     norm
+        beq     is1
+*       A<B, so ret 0, rem A
+        move.l  %d0,%d1
+        clr.l   %d0
+        move.l  %a2,%d3           /* restore d3 */
+        rts
+*       A==B, so ret 1, rem 0
+is1:
+        moveq.l #1,%d0
+        clr.l   %d1
+        move.l  %a2,%d3           /* restore d3 */
+        rts
+*       A>B and B is not 0
+norm:
+        cmp.l   #1,%d1
+        bne     not1
+*       B==1, so ret A, rem 0
+        clr.l   %d1
+        move.l  %a2,%d3           /* restore d3 */
+        rts
+*  check for A short (implies B short also)
+not1:
+        cmp.l   #0xffff,%d0
+        bhi     slow
+*  A short and B short -- use 'divu'
+        divu    %d1,%d0           /* d0 = REM:ANS */
+        swap    %d0               /* d0 = ANS:REM */
+        clr.l   %d1
+        move.w  %d0,%d1           /* d1 = REM */
+        clr.w   %d0
+        swap    %d0
+        move.l  %a2,%d3           /* restore d3 */
+        rts
+* check for B short
+slow:
+        cmp.l   #0xffff,%d1
+        bhi     slower
+* A long and B short -- use special stuff from gnu
+        move.l  %d0,%d2
+        clr.w   %d2
+        swap    %d2
+        divu    %d1,%d2           /* d2 = REM:ANS of Ahi/B */
+        clr.l   %d3
+        move.w  %d2,%d3           /* d3 = Ahi/B */
+        swap    %d3
+
+        move.w  %d0,%d2           /* d2 = REM << 16 + Alo */
+        divu    %d1,%d2           /* d2 = REM:ANS of stuff/B */
+
+        move.l  %d2,%d1
+        clr.w   %d1
+        swap    %d1               /* d1 = REM */
+
+        clr.l   %d0
+        move.w  %d2,%d0
+        add.l   %d3,%d0           /* d0 = ANS */
+        move.l  %a2,%d3           /* restore d3 */
+        rts
+*       A>B, B > 1
+slower:
+        move.l  #1,%d2
+        clr.l   %d3
+moreadj:
+        cmp.l   %d0,%d1
+        bhs     adj
+        add.l   %d2,%d2
+        add.l   %d1,%d1
+        bpl     moreadj
+* we shifted B until its >A or sign bit set
+* we shifted #1 (d2) along with it
+adj:
+        cmp.l   %d0,%d1
+        bhi     ltuns
+        or.l    %d2,%d3
+        sub.l   %d1,%d0
+ltuns:
+        lsr.l   #1,%d1
+        lsr.l   #1,%d2
+        bne     adj
+* d3=answer, d0=rem
+        move.l  %d0,%d1
+        move.l  %d3,%d0
+        move.l  %a2,%d3           /* restore d3 */
+        rts
+