Edit here is a genesis program that will display the filesize on the screen
align macro
cnop 0,\1
endm
DPORT EQU $C00000 ; VDP Data port
CPORT EQU $C00004 ; VDP Command port
rsset $FF0000
;all varibles go here
; ---------------------------------------------------------------------------
; disable interrupts
; ---------------------------------------------------------------------------
disable_ints: macro
move #$2700,sr
endm
; ---------------------------------------------------------------------------
; enable interrupts
; ---------------------------------------------------------------------------
enable_ints: macro
move #$2300,sr
endm
; ---------------------------------------------------------------------------
; DMA copy data from 68K (ROM/RAM) to the VRAM
; input: source, length, destination
; ---------------------------------------------------------------------------
writeVRAM: macro
lea (CPORT).l,a5
move.l #$94000000+(((\2>>1)&$FF00)<<8)+$9300+((\2>>1)&$FF),(a5)
move.l #$96000000+(((\1>>1)&$FF00)<<8)+$9500+((\1>>1)&$FF),(a5)
move.w #$9700+((((\1>>1)&$FF0000)>>16)&$7F),(a5)
move.w #$4000+(\3&$3FFF),(a5)
move.w #$80+((\3&$C000)>>14),(a5)
;move.w (v_vdp_buffer2).w,(a5)
endm
; ---------------------------------------------------------------------------
; DMA copy data from 68K (ROM/RAM) to the CRAM
; input: source, length, destination
; ---------------------------------------------------------------------------
writeCRAM: macro
lea (CPORT).l,a5
move.l #$94000000+(((\2>>1)&$FF00)<<8)+$9300+((\2>>1)&$FF),(a5)
move.l #$96000000+(((\1>>1)&$FF00)<<8)+$9500+((\1>>1)&$FF),(a5)
move.w #$9700+((((\1>>1)&$FF0000)>>16)&$7F),(a5)
move.w #$C000+(\3&$3FFF),(a5)
move.w #$80+((\3&$C000)>>14),(A5)
;move.w (v_vdp_buffer2).w,(a5)
endm
Vectors:
dc.l $FFFE00, Entrypoint, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l HBlank, Error, VBlank, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
dc.l Error, Error, Error, Error
Header:
dc.b "SEGA MEGA DRIVE " ; Console name
dc.b "(C) Sega 16 2012" ; Copyright/Date
DomesticName:
;dc.b "Code template by drx - www.hacking-cult.org " ; Domestic Name
dc.b "Genesis does "
;dc.b "Code template by drx - www.hacking-cult.org " ; International Name
dc.b "Genesis does "
dc.b "GM 00000000-42" ; Version
Checksum:
dc.w $0042 ; Checksum
dc.b "J " ; I/O Support
RomStartLoc:
dc.l 0 ; ROM Start
RomEndLoc:
dc.l RomEnd ; ROM End
RamStartLoc:
dc.l $FF0000 ; RAM Start
RamEndLoc:
dc.l $FFFFFF ; RAM End
dc.b $20,$20,$20,$20 ; 'RA',$F8,$20 if SRAM = on
SramStart:
dc.l $20202020 ; $200000 if SRAM = on
SramEnd:
dc.l $20202020 ; $20xxxx if SRAM = on
dc.b " "
dc.b " "
dc.b " "
dc.b " "
dc.b "F " ; enable any hardware configuration
FMPORT1 EQU $A04000
FMPORT2 EQU $A04001
FMPORT3 EQU $A04002
FMPORT4 EQU $A04003
;---------------------
; Code start
;---------------------
Entrypoint:
tst.l ($A10008).l ;Test Port A control
bne PortA_Ok
tst.w ($A1000C).l ;Test Port C control
PortA_Ok:
bne SkipSetup
move.b ($A10001).l,d0 ;version
andi.b #$F,d0
beq SkipSecurity ;if the smd/gen model is 1, skip the security
move.l #'SEGA',($A14000).l
SkipSecurity:
move.w ($C00004).l,d0 ;hang if VDP locked due to security failure
moveq #0,d0
movea.l d0,a6
move.l a6,usp ;set usp to $0
;---------------------
; Setup VDP registers
;---------------------
lea (VDPSetupArray,pc),a0
move.w #(VDPSetupArrayEnd-VDPSetupArray)/2,d1 ;$18 VDP registers
VDPSetupLoop:
move.w (a0)+,($C00004).l
dbra d1,VDPSetupLoop
move.l #$40000080,($C00004).l
move.w #0,($C00000).l ;clean the screen
;---------------------
; Init the Z80
;---------------------
move.w #$100,($A11100).l ;Stop the Z80
move.w #$100,($A11200).l ;Deassert reset to the Z80
Waitforz80:
btst #0,($A11100).l
bne Waitforz80 ;Wait for z80 to halt
lea (Z80Init,pc),a0
lea ($A00000).l,a1
move.w #Z80InitEnd-Z80Init,d1
InitZ80:
move.b (a0)+,(a1)+
dbra d1,InitZ80
move.w #0,($A11200).l ;Assert reset to the Z80
move.w #0,($A11100).l ;Start the Z80
move.w #$100,($A11200).l ;Deassert reset to the Z80
;---------------------
; Reset the RAM
;---------------------
lea ($FFFF0000).l,a0
move.w #$3fff,d1
ClearRAM:
move.l #0,(a0)+
dbra d1,ClearRAM
;---------------------
; VDP again
;---------------------
move.w #$8174,($C00004).l
move.w #$8F02,($C00004).l
;---------------------
; Clear the CRAM
;---------------------
move.l #$C0000000,($C00004).l ;Set VDP ctrl to CRAM write
move.w #$3f,d1
ClearCRAM:
move.w #0,($C00000).l
dbra d1,ClearCRAM
;---------------------
; Clear the VDP stuff
;---------------------
move.l #$40000010,($C00004).l
move.w #$13,d1
ClearStuff:
move.l #0,($C00000).l
dbra d1,ClearStuff
;---------------------
; Init the PSG
;---------------------
move.b #$9F,($C00011).l
move.b #$BF,($C00011).l
move.b #$DF,($C00011).l
move.b #$FF,($C00011).l
;---------------------
; Load the z80 driver
;---------------------
move.w #$100,($A11100).l ;Stop the Z80
move.w #$100,($A11200).l ;Deassert reset to the Z80
Waitforz80a:
btst #0,($A11100).l
bne Waitforz80a ;Wait for z80 to halt
lea (Z80Driver,pc),a0
lea ($A00000).l,a1
move.w #Z80DriverEnd-Z80Driver,d1
LoadZ80Driver:
move.b (a0)+,(a1)+
dbra d1,LoadZ80Driver
move.w #0,($A11200).l ;Assert reset to the Z80
move.w #0,($A11100).l ;Start the Z80
move.w #$100,($A11200).l ;Deassert reset to the Z80
;---------------------
; Clear the registers
; and set the SR
;---------------------
movem.l ($FF0000).l,d0-a6
lea ($FFFE00).l,a7
move #$2700,sr
SkipSetup:
;-----------------------
; Here starts your code
;-----------------------
Main:
; input: source, length, destination
; ---------------------------------------------------------------------------
writeVRAM font,512,32
writeCRAM palette,4,0
lea (nemdat).l,a0
move.l #$45440000,($C00004).l ; Starts at tile 17
bsr.s nemdec
lea (nemdat).l,a1
move.l a0,d0
subi.l #nemdat,d0
subq #1,d0
bsr.w showhexulong
;---------------------------------
; nothing else for the 68000 to do
;---------------------------------
loop:
bra.s loop
rts
;---------------------
; Error exceptions
;---------------------
Error:
rte
;---------------------
; Horizontal Blank
;---------------------
HBlank:
rte
;---------------------
; Vertical Blank
;---------------------
VBlank:
rte
NemDec: ; CODE XREF: ROM:00000C60p
; ROM:00000D52p ...
;movem.l d0-a1/a3-a5,-(sp)
lea (loc_15332).l,a3
lea ($C00000).l,a4
bra.s loc_152C2
; ---------------------------------------------------------------------------
loc_152B8: ; CODE XREF: ROM:000007A4p
; ROM:000007ECp ...
movem.l d0-a1/a3-a5,-(sp)
lea (loc_15348).l,a3
loc_152C2: ; CODE XREF: NemDec+10j
lea ($FFFFCA00).w,a1
move.w (a0)+,d2
lsl.w #1,d2
bcc.s loc_152D0
adda.w #$A,a3
loc_152D0: ; CODE XREF: NemDec+24j
lsl.w #2,d2
movea.w d2,a5
moveq #8,d3
moveq #0,d2
moveq #0,d4
bsr.w sub_15362
move.b (a0)+,d5
asl.w #8,d5
move.b (a0)+,d5
move.w #$10,d6
loc_152E8: ; CODE XREF: NemDec+7Cj
moveq #8,d0
bsr.w sub_153C4
cmpi.w #$FC,d1 ; 'ü'
bcc.s loc_15324
add.w d1,d1
move.b (a1,d1.w),d0
ext.w d0
bsr.w sub_153D8
move.b 1(a1,d1.w),d1
loc_15304: ; CODE XREF: NemDec+8Aj
move.w d1,d0
andi.w #$F,d1
andi.w #$F0,d0 ; 'ð'
lsr.w #4,d0
loc_15310: ; CODE XREF: NemDec:loc_1531Ej
lsl.l #4,d4
or.b d1,d4
subq.w #1,d3
bne.s loc_1531E
jmp (a3)
; ---------------------------------------------------------------------------
loc_1531A: ; CODE XREF: ROM:00015338j
; ROM:00015344j ...
moveq #0,d4
moveq #8,d3
loc_1531E: ; CODE XREF: NemDec+70j
dbf d0,loc_15310
bra.s loc_152E8
; ---------------------------------------------------------------------------
loc_15324: ; CODE XREF: NemDec+4Cj
moveq #6,d0
bsr.w sub_153D8
moveq #7,d0
bsr.w sub_153D4
bra.s loc_15304
; End of function NemDec
; ---------------------------------------------------------------------------
loc_15332: ; DATA XREF: NemDec+4o
move.l d4,(a4)
subq.w #1,a5
move.w a5,d4
bne.s loc_1531A
bra.s loc_1535C
; ---------------------------------------------------------------------------
eor.l d4,d2
move.l d2,(a4)
subq.w #1,a5
move.w a5,d4
bne.s loc_1531A
bra.s loc_1535C
; ---------------------------------------------------------------------------
loc_15348: ; DATA XREF: NemDec+16o
move.l d4,(a4)+
subq.w #1,a5
move.w a5,d4
bne.s loc_1531A
bra.s loc_1535C
; ---------------------------------------------------------------------------
eor.l d4,d2
move.l d2,(a4)+
subq.w #1,a5
move.w a5,d4
bne.s loc_1531A
loc_1535C: ; CODE XREF: ROM:0001533Aj
; ROM:00015346j ...
;movem.l (sp)+,d0-a1/a3-a5
rts
; =============== S U B R O U T I N E =======================================
sub_15362: ; CODE XREF: NemDec+34p
move.b (a0)+,d0
loc_15364: ; CODE XREF: sub_15362+12j
cmpi.b #$FF,d0
bne.s loc_1536C
rts
; ---------------------------------------------------------------------------
loc_1536C: ; CODE XREF: sub_15362+6j
move.w d0,d7
loc_1536E: ; CODE XREF: sub_15362+38j
; sub_15362:loc_153B2j
move.b (a0)+,d0
cmpi.b #$80,d0
bcc.s loc_15364
move.b d0,d1
andi.w #$F,d7
andi.w #$70,d1 ; 'p'
or.w d1,d7
andi.w #$F,d0
move.b d0,d1
lsl.w #8,d1
or.w d1,d7
moveq #8,d1
sub.w d0,d1
bne.s loc_1539C
move.b (a0)+,d0
add.w d0,d0
move.w d7,(a1,d0.w)
bra.s loc_1536E
; ---------------------------------------------------------------------------
loc_1539C: ; CODE XREF: sub_15362+2Ej
move.b (a0)+,d0
lsl.w d1,d0
add.w d0,d0
moveq #1,d5
lsl.w d1,d5
subq.w #1,d5
loc_153A8: ; CODE XREF: sub_15362+4Cj
move.w d7,(a1,d0.w)
addq.w #2,d0
dbf d5,loc_153A8
loc_153B2: ; DATA XREF: sub_153C4+Ar
bra.s loc_1536E
; End of function sub_15362
; ---------------------------------------------------------------------------
dc.b 0
dc.b 1
dc.b 0
dc.b 3
dc.b 0
dc.b 7
dc.b 0
dc.b $F
dc.b 0
dc.b $1F
dc.b 0
dc.b $3F ; ?
dc.b 0
dc.b $7F ;
dc.b 0
dc.b $FF
; =============== S U B R O U T I N E =======================================
sub_153C4: ; CODE XREF: NemDec+44p sub_153D4p
move.w d6,d7
sub.w d0,d7
move.w d5,d1
lsr.w d7,d1
add.w d0,d0
and.w loc_153B2(pc,d0.w),d1
rts
; End of function sub_153C4
; =============== S U B R O U T I N E =======================================
sub_153D4: ; CODE XREF: NemDec+86p
bsr.s sub_153C4
lsr.w #1,d0
; End of function sub_153D4
; =============== S U B R O U T I N E =======================================
sub_153D8: ; CODE XREF: NemDec+56p NemDec+80p
sub.w d0,d6
cmpi.w #9,d6
bcc.s locret_153E6
addq.w #8,d6
asl.w #8,d5
move.b (a0)+,d5
locret_153E6: ; CODE XREF: sub_153D8+6j
rts
; End of function sub_153D8
showhexulong:
;input d0 the long unsigned hex value that you need to be displaed
;return value garbage
move.l #$46000003,d2
lea ($C00004).l,a1
lea ($C00000).l,a0
move.l d2,(a1) ;send command to the command port
move.l d0,d1
;first display bits 32-24
swap d1
lsr.l #8,d1
bsr.s showhexuchar
move.l d0,d1
lsr.l #8,d1
lsr.l #8,d1
bsr.s showhexuchar;24-16
move.l d0,d1
lsr.l #8,d1
bsr.s showhexuchar;16-8
move.l d0,d1
bsr.s showhexuchar;8-0
rts
showhexuchar:
;this function assumes that A0 points to correct vram location and auto increment is all set up
;input d1
;returns nothing relay just the same data in d1 and garbage in d2
moveq #0,d2
moveq #0,d3
move.b d1,d2 ;make sure we have only 1 byte
move.b d1,d3
lsr.b #4,d3
addq #1,d3
move.w d3,(a0)
and.b #15,d2
addq #1,d2
move.w d2,(a0)
rts
nemdat:
;to calulate the filesize do (whatever a0 is minus nemdat offset)-1
incbin nemsega.bin
even
palette:
dc.w 0
dc.w $EEE
font:
;0
dc.l $01111110
dc.l $01000010
dc.l $01000110
dc.l $01001010
dc.l $01001010
dc.l $01010010
dc.l $01100010
dc.l $01111110
;1
dc.l $01100000
dc.l $10100000
dc.l $00100000
dc.l $00100000
dc.l $00100000
dc.l $00100000
dc.l $00100000
dc.l $11111000
;2
dc.l $01111000
dc.l $00001000
dc.l $00010000
dc.l $00100000
dc.l $00100000
dc.l $01000000
dc.l $10000000
dc.l $11111100
;3
dc.l $01111100
dc.l $00000100
dc.l $00000100
dc.l $00000100
dc.l $01111100
dc.l $00000100
dc.l $00000100
dc.l $01111100
;4
dc.l $01000100
dc.l $01000100
dc.l $01000100
dc.l $01111100
dc.l $00000100
dc.l $00000100
dc.l $00000100
dc.l $00000100
;5
dc.l $01111110
dc.l $01000000
dc.l $01111100
dc.l $00000100
dc.l $00000100
dc.l $00000100
dc.l $00001000
dc.l $01110000
;6
dc.l $00000100
dc.l $00001000
dc.l $00010000
dc.l $00100000
dc.l $01111000
dc.l $10000100
dc.l $01000010
dc.l $00111100
;7
dc.l $01111100
dc.l $00001000
dc.l $00001000
dc.l $00010000
dc.l $00010000
dc.l $00100000
dc.l $01000000
dc.l $01000000
;8
dc.l $01111110
dc.l $01000010
dc.l $01000010
dc.l $01111110
dc.l $01000010
dc.l $01000010
dc.l $01000010
dc.l $01111110
;9
dc.l $01111000
dc.l $01000100
dc.l $01000010
dc.l $01111110
dc.l $00000100
dc.l $00001000
dc.l $00010000
dc.l $00100000
;A
dc.l $00001000
dc.l $00010100
dc.l $00100100
dc.l $00111100
dc.l $00100100
dc.l $01000010
dc.l $01000010
dc.l $01000010
;B
dc.l $01110000
dc.l $01001000
dc.l $01000100
dc.l $01111100
dc.l $01000100
dc.l $01000100
dc.l $01001000
dc.l $01110000
;C
dc.l $00000100
dc.l $00001000
dc.l $00010000
dc.l $00100000
dc.l $01000000
dc.l $00100000
dc.l $00010000
dc.l $00001000
;D
dc.l $01100000
dc.l $01010000
dc.l $01001000
dc.l $01000100
dc.l $01000010
dc.l $01000100
dc.l $01001000
dc.l $01110000
;E
dc.l $01111100
dc.l $01000000
dc.l $01000000
dc.l $01111100
dc.l $01000000
dc.l $01000000
dc.l $01000000
dc.l $01111100
;F
dc.l $01111100
dc.l $01000000
dc.l $01000000
dc.l $01111100
dc.l $01000000
dc.l $01000000
dc.l $01000000
dc.l $01000000
;---------------------
; VDP registers array
;---------------------
VDPSetupArray:
dc.w $8004 ;9-bit palette = 1 (otherwise would be 3-bit), HBlank = 0
dc.w $8134 ;Genesis display = 1, DMA = 1, VBlank = 1, display = 0
dc.w $8230 ;Scroll A - $C000
dc.w $8338 ;Window - $E000
dc.w $8407 ;Scroll B - $E000
dc.w $857c ;Sprites - $F800
dc.w $8600 ;Unused
dc.w $8700 ;Backdrop color - $00
dc.w $8800 ;Unused
dc.w $8900 ;Unused
dc.w $8A00 ;H Interrupt register
dc.w $8B00 ;Full screen scroll, no external interrupts
dc.w $8C81 ;40 cells display
dc.w $8D3F ;H Scroll - $FC00
dc.w $8E00 ;Unused
dc.w $8F02 ;VDP auto increment
dc.w $9001 ;64 cells scroll
dc.w $9100 ;Window H position
dc.w $9200 ;Window V position
dc.w $93FF ;DMA stuff (off)
dc.w $94FF ;DMA stuff (off)
dc.w $9500 ;DMA stuff (off)
dc.w $9600 ;DMA stuff (off)
dc.w $9780 ;DMA stuff (off)
VDPSetupArrayEnd:
;---------------------
; Z80 init code
;---------------------
Z80Init:
dc.w $af01, $d91f, $1127, $0021, $2600, $f977
dc.w $edb0, $dde1, $fde1, $ed47, $ed4f, $d1e1
dc.w $f108, $d9c1, $d1e1, $f1f9, $f3ed, $5636
dc.w $e9e9
Z80InitEnd:
;---------------------
; Music driver (z80)
;---------------------
Z80Driver:
dc.b $c3,$46,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
dc.b $00,$00,$00,$00,$00,$f3,$ed,$56,$31,$00,$20,$3a,$39,$00,$b7,$ca,$4c,$00,$21,$3a,$00,$11,$40,$00,$01,$06,$00,$ed,$b0,$3e,$00,$32,$39,$00,$3e,$b4,$32,$02,$40,$3e,$c0,$32,$03,$40,$3e,$2b,$32,$00,$40,$3e,$80,$32,$01,$40,$3a,$43,$00,$4f,$3a,$44,$00,$47,$3e,$06,$3d
dc.b $c2,$81,$00,$21,$00,$60,$3a,$41,$00,$07,$77,$3a,$42,$00,$77,$0f,$77,$0f,$77,$0f,$77,$0f,$77,$0f,$77,$0f,$77,$0f,$77,$3a,$40,$00,$6f,$3a,$41,$00,$f6,$80,$67,$3e,$2a,$32,$00,$40,$7e,$32,$01,$40,$21,$40,$00,$7e,$c6,$01,$77,$23,$7e,$ce,$00,$77,$23,$7e,$ce,$00,$77
dc.b $3a,$39,$00,$b7,$c2,$4c,$00,$0b,$78,$b1,$c2,$7f,$00,$3a,$45,$00,$b7,$ca,$4c,$00,$3d,$3a,$45,$00,$06,$ff,$0e,$ff,$c3,$7f,$00
Z80DriverEnd:
RomEnd:
Edited by Sonic master, 03 September 2012 - 12:08 AM.



This topic is locked








