From: notaz Date: Tue, 17 Mar 2009 23:09:51 +0000 (+0000) Subject: cleanup and vbl a0 corruption fix X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=megadrive.git;a=commitdiff_plain;h=0fc4f06b333d14deaa5250add135d326f381da6c cleanup and vbl a0 corruption fix --- diff --git a/hexed/hexed.s b/hexed/hexed.s index 6ca711a..18ea5c2 100644 --- a/hexed/hexed.s +++ b/hexed/hexed.s @@ -65,40 +65,31 @@ .endm -# make VDP word from address adr to d0 -# destroys d7 -.macro VRAM_ADDR_var adr +.macro CRAM_ADDR reg adr + move.l #(((0xc000 + (\adr & 0x3fff)) << 16) + (\adr >> 14)),\reg +.endm + + +# make VDP word from address adr and store in d0 +.macro XRAM_ADDR_var adr move.l \adr,d0 - move.l \adr,d7 - and.w #0x3fff,d0 - lsr.w #7,d7 - lsr.w #7,d7 - add.w #0x4000,d0 - lsl.l #7,d0 - lsl.l #7,d0 - lsl.l #2,d0 - or.l d7,d0 + lsl.l #8,d0 + lsl.l #8,d0 + rol.l #2,d0 + lsl.b #2,d0 + lsr.l #2,d0 .endm -.macro CRAM_ADDR reg adr - move.l #(((0xc000 + (\adr & 0x3fff)) << 16) + (\adr >> 14)),\reg +.macro VRAM_ADDR_var adr + XRAM_ADDR_var \adr + or.l #0x40000000,d0 .endm -/* For indirect (variable) addresses */ -.macro CRAM_ADDR_var reg adr - move.l \adr,d6 - move.l \adr,d7 - and.w #0x3fff,d6 - lsr.w #7,d7 - lsr.w #7,d7 - add.w #0xc000,d6 - lsl.l #7,d6 - lsl.l #7,d6 - lsl.l #2,d6 - or.l d7,d6 - move.l d6,\reg +.macro CRAM_ADDR_var adr + XRAM_ADDR_var \adr + or.l #0xc0000000,d0 .endm @@ -146,46 +137,46 @@ main: jsr init_gfx /* Load color data */ - movea.l #0,a3 - movea.l #colors,a4 - moveq.l #(colors_end-colors)/2,d4 + movea.l #0,a0 + movea.l #colors,a1 + moveq.l #(colors_end-colors)/2,d0 jsr load_colors /* load patterns */ - movea.l #0,a3 - movea.l #font,a4 - move.l #128,d4 + movea.l #0,a0 + movea.l #font,a1 + move.l #128,d0 jsr load_tiles /* generate A layer map */ movea.l #0xe000,a6 move.l #28-1,d4 lmaploop0: - movea.l a6,a3 + movea.l a6,a0 jsr load_prepare move.l #64/2-1,d3 -0: move.l #0x00000000,(a3) +0: move.l #0x00000000,(a0) dbra d3,0b add.l #64*2,a6 dbra d4,lmaploop0 /* generate B layer map */ - movea.l #0xc000,a3 + movea.l #0xc000,a0 jsr load_prepare move.l #64*28/2-1,d3 -0: move.l #0x00000000,(a3) +0: move.l #0x00000000,(a0) dbra d3,0b /* upload sprite data */ - movea.l #0xfc00,a3 + movea.l #0xfc00,a0 jsr load_prepare - movea.l #sprite_data,a0 + movea.l #sprite_data,a1 move.l #(sprite_data_end-sprite_data)/2-1,d3 -0: move.l (a0)+,(a3) +0: move.l (a1)+,(a0) dbra d3,0b jsr wait_vsync @@ -236,95 +227,80 @@ init_gfx: rts - -################################################# -# # -# Load tile data from ROM # -# # -# Parameters: # -# a3: VRAM base # -# a4: pattern address # -# d4: number of tiles to load # -# Destroys a2,d0,d7... # -# # -################################################# +# Load tile data from ROM +# a0: VRAM base +# a1: pattern address +# d0: number of tiles to load +# destroys d1 load_tiles: - move.l #GFXCNTL,a2 - VRAM_ADDR_var a3 - move.l d0,(a2) - lsl #3,d4 + move.l d0,d1 + VRAM_ADDR_var a0 + move.l d0,(GFXCNTL).l - move.l #GFXDATA,a3 - subq.l #1,d4 -_copy_tile_data: - move.l (a4)+,(a3) - dbra d4,_copy_tile_data + move.l #GFXDATA,a0 + lsl.w #3,d1 + subq.l #1,d1 +0: + move.l (a1)+,(a0) + dbra d1,0b rts # Prepare to write to VDP RAM @a3 -# a3: VRAM base -# a3 set to VDP data port for convenience -# destroys a2,d0,d7 +# sets a0 to VDP data port for convenience +# a0: VRAM base +# destroys d0 load_prepare: - move.l #GFXCNTL,a2 - VRAM_ADDR_var a3 - move.l d0,(a2) - move.l #GFXDATA,a3 - + VRAM_ADDR_var a0 + move.l d0,(GFXCNTL).l + move.l #GFXDATA,a0 rts -################################################# -# # -# Load color data from ROM # -# # -# Parameters: # -# a3: CRAM base # -# a4: color list address # -# d4: number of colors to load # -# # -################################################# +# Load color data from ROM +# a0: CRAM base +# a1: color list address +# d0: number of colors to load +# destroys d1 load_colors: - move.l #GFXCNTL,a2 - CRAM_ADDR_var d0,a3 - move.l d0,(a2) + move.l d0,d1 + CRAM_ADDR_var a0 + move.l d0,(GFXCNTL).l - move.l #GFXDATA,a3 - subq.w #1,d4 -_copy_color_data: - move.w (a4)+,(a3) - dbra d4,_copy_color_data + move.l #GFXDATA,a0 + subq.w #1,d1 +0: + move.w (a1)+,(a0) + dbra d1,0b rts -################################################# -## -## print -# a0 - string -# d0 - x -# d1 - y + +# print +# a0 - string +# d0 - x +# d1 - y +# destroys a1 print: + move.l a0,a1 lsl.w #6,d1 add.w d1,d0 - movea.l #0xe000,a6 lsl.w #1,d0 - add.w d0,a6 - moveq.l #0,d1 + movea.l #0xe000,a0 + add.w d0,a0 + jsr load_prepare + moveq.l #0,d0 _print_loop: - move.b (a0)+,d1 + move.b (a1)+,d0 beq _print_end - move.l a6,a3 - jsr load_prepare - move.w d1,(a3) - addq.l #2,a6 + move.w d0,(a0) jmp _print_loop _print_end: diff --git a/hexed/sega_gcc.s b/hexed/sega_gcc.s index a295692..8b201d5 100644 --- a/hexed/sega_gcc.s +++ b/hexed/sega_gcc.s @@ -18,8 +18,8 @@ dc.l INT,INT,INT,INT,INT,INT,INT,INT dc.l INT,INT,INT,INT,INT,INT,INT .ascii "SEGA GENESIS " - .ascii "notaz's Shadow / Hilight test " - .ascii "NOTAZ'S SHADOW HILIGHT TEST " + .ascii "hex editor (c) notaz " + .ascii "HEX EDITOR (C) NOTAZ " .ascii "GM 00000000-00" .byte 0xa5,0xfb .ascii "JD " @@ -159,250 +159,9 @@ HBL: rte VBL: - /* addq.l #1,vtimer */ - move.l #vtimer,a0 - addq.l #1,(a0) + addq.l #1,(vtimer).l rte -*------------------------------------------------ -* -* Get a random number. This routine -* was found in TOS. -* -* Output -* ------ -* d0 = random number -* -*------------------------------------------------ - - .globl random - -random: - move.l rand_num,%d0 - tst.l %d0 - bne .L1 - moveq #16,%d1 - lsl.l %d1,%d0 - or.l htimer,%d0 - move.l %d0,rand_num -.L1: - move.l #-1153374675,-(%sp) - move.l rand_num,-(%sp) - bsr lmul - addq.w #8,%sp - addq.l #1,%d0 - move.l %d0,rand_num - - lsr.l #8,%d0 - and.l #16777215,%d0 - rts - - -*------------------------------------------------ -* -* 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 -* AB 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 *---------------------------------------------------------- * * Z80 Sound Driver