changeset 11:19226d79f839

Add direct color DMA demo and converter
author Mike Pavone <pavone@retrodev.com>
date Fri, 06 Sep 2013 19:09:19 -0700
parents eddc4ba6b0c3
children 580b64af2241
files Makefile directcolor.s68 img2dcolor.py
diffstat 3 files changed, 249 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Sep 06 19:08:56 2013 -0700
+++ b/Makefile	Fri Sep 06 19:09:19 2013 -0700
@@ -26,6 +26,9 @@
 genesis.bin : genesis.s68 sprites.s68 logo.bin
 	vasmm68k_mot -Fbin -m68000 -spaces genesis.s68 -o genesis.bin
 
+directcolor.bin : directcolor.s68 dcolor.bin
+	vasmm68k_mot -Fbin -m68000 -spaces directcolor.s68 -o directcolor.bin
+
 clean :
 	rm subboot.bin mainboot.bin boot.bin
 	rm *.iso
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/directcolor.s68	Fri Sep 06 19:09:19 2013 -0700
@@ -0,0 +1,191 @@
+	dc.l $0, start
+	dc.l empty_handler
+	dc.l empty_handler
+	;$10
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$20
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$30
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$40
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$50
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$60
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$70
+	dc.l HINT
+	dc.l empty_handler
+	dc.l VINT
+	dc.l empty_handler
+	;$80
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$90
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$A0
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$B0
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$C0
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$D0
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$E0
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	;$F0
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.l empty_handler
+	dc.b "SEGA"
+empty_handler:
+	rte
+start:
+;background and sprite test
+
+ButtonState	equ	$FFFFEFF0
+ButtonStateNew	equ	ButtonState+2
+PalAddress equ ButtonStateNew+2
+
+CRAMXferSizeCmd equ $9308
+CRAMDMACmd equ $C0000080
+
+	move.b  #$40, $A10009
+	move.l	#$C00000, a4
+	move.l	#$c00004, a5
+
+	move.l	#$0, a7
+
+	move.w	#$8004, (a5)
+	move.w	#$8104, (a5)	;turn off display
+	move.w	#$8200, (a5)	;Table A = 0000
+	move.w	#$8400, (a5)	;Table B = 0000
+	move.w	#$857C, (a5)	;Sprite Table = F800
+	move.w	#$8B00, (a5)		;set full screen vertical and horizontal scrolling
+	move.w  #$8C01, (a5)    ;H40 mode, no shadow/hilight, no interlace
+	move.w	#$8D3F, (a5)	;H Scroll = FC00
+	move.w	#$9001, (a5)	;64x32 scroll tables
+
+
+
+
+
+	move #$2300, SR
+
+Top:
+	lea	BgData(pc), a0 ;set DMA source address
+	move.l a0, d7
+	sub.l	#258, d7
+	move.w	#$9500, d6
+	ror.l	#1, d7
+	move.b	d7, d6
+	move.w	d6, (a5)
+	ror.l	#8, d7
+	move.b	d7, d6
+	add.w	#$100, d6
+	move.w	d6,(a5)
+	ror.l	#8, d7
+	move.b	d7, d6
+	add.w	#$100, d6
+	and.b	#$7F, d6
+	move.w	d6,(a5)
+
+	move.l  #$94AE9342, (a5) ;set DMA length
+
+	move.w #$8F00, (a5) ;set auto-increment to 0
+
+	move.w	#$8174, (a5)
+
+
+	move.l #$40000000, (a5) ;Setup VRAM writes
+	addq #1, a5
+WaitVBlank:
+	btst.b #3, (a5)
+	beq.s WaitVBlank
+WaitActive:
+	btst.b #3, (a5)
+	bne.s   WaitActive
+
+	move.l d0, (a4) ;fill FIFO
+	move.l d0, (a4)
+	move.w d0, (a4)
+	subq #1, a5
+	move.w #$8114, (a5) ;turn off display
+	nop
+	nop
+	nop
+	nop
+	move.l #$C0000080, (a5)
+
+	bra Top
+
+
+
+HINT:
+	rte
+VINT:
+	bsr	ReadPad
+	rte
+
+
+ReadPad:
+	move.b	#$FF, $a10003	;set TH for controller A
+	move.b	$a10003, d0	;CBRLUD
+	andi.b	#$3F, d0
+	move.b	#0, $a10003
+	move.b	$a10003, d1	;SA00UD
+	andi.b	#$30, d1
+	lsl.b	#2, d1
+	or.b	d1, d0		;SACBRLUD
+	not.b	d0
+	move.b	(ButtonState).w, d1
+	eor.b	d0, d1
+	and.b	d0, d1
+	move.b	d0, (ButtonState).w
+	move.b	d1, (ButtonStateNew).w
+
+	rts
+
+
+BgData:
+	incbin  dcolor.bin
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/img2dcolor.py	Fri Sep 06 19:09:19 2013 -0700
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+from PIL import Image
+
+def gchannel(Val):
+	return (Val >> 4) & 0xE
+
+def gcolor(color):
+	if len(color) == 4:
+		(R, G, B, A) = color
+	else:
+		(R, G, B) = color
+	return (gchannel(R), gchannel(G), gchannel(B))
+
+def trans_image(im):
+	pixels = im.getdata()
+	(width, height) = im.size
+	gpixels = bytearray()
+	A = 255
+	x = 0
+	y = 0
+	for pixel in pixels:
+		if x == width:
+			x = 0
+			y += 1
+		if x == 0:
+			pad = 198-width/2
+			print 'pad', pad
+			for i in xrange(0, pad*2):
+				gpixels.append(0)
+		if not (x & 1):
+			(R,G,B) = gcolor(pixel)
+			gpixels.append(B)
+			gpixels.append(G << 4 | R)
+		x += 1
+	return gpixels
+
+def appendword(b, word):
+	b.append(word >> 8)
+	b.append(word & 0xff)
+
+
+
+def main(argv):
+	if len(argv) < 3:
+		print "Not enough arguments"
+		return
+	fname = argv[1]
+	im = Image.open(fname)
+	pix = trans_image(im)
+	out = open(argv[2], 'wb')
+	out.write(pix)
+
+if __name__ == '__main__':
+	import sys
+	main(sys.argv)