view menu.s68 @ 820:cf6149b7c6e5

Implement a tiny bit of CPM BDOS and add a corresponding Z80 core driver so that simple CPM programs like ZEXDOC/ZEXALL can be run against my Z80 core
author Michael Pavone <pavone@retrodev.com>
date Wed, 29 Jul 2015 00:05:21 -0700
parents 109ac52ffecd
children 35f5658d141f
line wrap: on
line source

	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 int_4
	dc.l empty_handler
	dc.l int_6
	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 GENESIS    "
	dc.b "(c) 2015.JULY   "
	dc.b "Menu            "
	dc.b "                "
	dc.b "                "
	dc.b "Menu            "
	dc.b "                "
	dc.b "                "
	dc.b "GM MK-00000-00", 0, 0
	dc.b "                "
	dc.l $0, rom_end-1, $FF0000, $FFFFFF
	dc.b "                "
	dc.b "                "
	dc.b "                "
	dc.b "                "
	dc.b "JUE "
	
;register addresses
VDP_DATA equ $C00000
VDP_CTRL equ $C00004
VDP_HV   equ $C00008
Z80_RAM  equ $A00000
IO_AREA  equ $A10000

MODE_0   equ 0
MODE_1   equ 1
SCROLL_A equ 2
WINDOW   equ 3
SCROLL_B equ 4
SAT      equ 5
BG_COLOR equ 7
HINT     equ $A
MODE_3   equ $B
MODE_4   equ $C
HSCROLL  equ $D
AUTOINC  equ $F
SCROLL   EQU $10
WINDOW_H equ $11
WINDOW_V equ $12
DMALEN_L equ $13
DMALEN_H equ $14
DMASRC_L equ $15
DMASRC_M equ $16
DMASRC_H equ $17

VDP_VRAM_WRITE equ $40000000
VDP_CRAM_WRITE equ $C0000000
VDP_VSRAM_WRITE equ $40000010
VDP_DMA_FLAG equ $80

vdpregset macro
	move.w #(((\1) << 8) | $8000 | (\2)), (a1)
	endm

vdpreg macro
	dc.w (((\1) << 8) | $8000 | (\2))
	endm
	
;Writes a normal VDP command to the control port
;\1 - VDP address
;\2 - Access type
vdpaccess macro
	move.l #((\2) | (\1) << 16 & $3FFF0000 | (\1) >> 14 & 3), (a1)
	endm
	
empty_handler:
int_6:
	rte
int_4:
	rte
	
	rsset $FFFF8000
x_pos    rs.w 1
base_cmd rs.l 1

initial_regs:
	vdpreg MODE_1, $4    ;Mode 5, everything turned off
	vdpreg MODE_0, $4
	vdpreg SCROLL_A, $20 ;Scroll a table $8000
	vdpreg SCROLL_B, $05 ;Scroll b table $A000
	vdpreg SAT, $60      ;SAT table $C000
	vdpreg BG_COLOR, 0
	vdpreg HINT, $FF
	vdpreg MODE_3, 0     ;full screen scroll
	vdpreg MODE_4, $87   ;40 cell mode, double-res interlace
	vdpreg HSCROLL, 0
	vdpreg AUTOINC, 2
	vdpreg SCROLL, 1     ;64x32 scroll size
end_initial_regs

start:
	lea $C00000, a0
	lea $C00004, a1
	
	moveq #(end_initial_regs-initial_regs-1), d0
	lea initial_regs.w, a2
.regloop
	move.w (a2)+, (a1)
	dbra d0, .regloop
	
	vdpaccess $0, VDP_CRAM_WRITE
	move.w #$000, (a0)
	move.w #$EEE, (a0)

	;init scroll table
	vdpaccess $0, VDP_VRAM_WRITE
	move.w #0, (a0)
	move.w #4, (a0)

	;load tiles
	vdpaccess $800, VDP_VRAM_WRITE
	lea font(pc), a2
	move.w #((fontend-font)/4 - 1), d0
tloop:
	move.l (a2)+, (a0)
	dbra d0, tloop



	;clear name tables
	vdpaccess $8000, VDP_VRAM_WRITE
	moveq #32, d0
	move.w #(64*64-1), d1
ploop:
	move.l d0, (a0)
	dbra d1, ploop
	
	move.l #$40000002, d3
	move.l d3, (a1)
	move.l d3, base_cmd.w

	lea Message(pc), a6
	moveq #0, d0
	bsr print_string
	
	
	
	move.w #$8144, (a1) ;enable display
	move #$2300, sr
	

wait_forever
	stop #2500
	bra wait_forever

Message:
	dc.b "Journey From Darkness - Strider Returns (U) [c][!].bin", $A
	dc.b "Toejam & Earl in Panic on Funkotron (U) [!].bin", $A
	dc.b "Fire Shark (U) [c][!].bin", $A
	dc.b "Sonic and Knuckles (W) [!].bin", 0

	align 1

;Prints a null terminated string
;a6 - pointer to string
;a0 - VDP data port
;d0 - base tile attribute
;
;Clobbers: d1.w, d2.w, d3.l
print_string:
	lea widths(pc), a5
	move.w x_pos.w, d2
	move.l base_cmd.w, d3
.loop
	moveq #0, d1
	move.b (a6)+, d1
	beq .end
	cmp.b #$A, d1
	beq .newline
	tst.b (-32, a5, d1.w)
	beq .narrow
	add.w d0, d1
	move.w d1, (a0)
	addq #2, d2
	bra .loop
.narrow
	add.w d0, d1
	move.w d1, (a0)
	addq #1, d2
	move.l d2, d1
	;switch to other plane
	and.w #$FFFE, d1
	swap d1
	eor.l #$20000000, d3
	or.l d3, d1
	move.l d1, (a1)
	bra .loop
.newline
	moveq #0, d2
	;switch back to plane A
	and.l #$DFFFFFFF, d3
	;skip to next row
	add.l #$00800000, d3
	move.l d3, (a1)
	bra .loop
.end
	move.w d2, x_pos.w
	move.l d3, base_cmd.w
	rts

	align 1
font:
	incbin font_interlace_variable.tiles
fontend

widths:
	dc.b 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1
	dc.b 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0
	dc.b 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1
	dc.b 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
	dc.b 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1
	
rom_end: