hexed: fixup for newer binutils
[megadrive.git] / hexed / hexed.s
index cdaebcd..ae77a3e 100644 (file)
@@ -1,6 +1,6 @@
 ###############################################################################
 #
-# Copyright (c) 2009, Gražvydas Ignotas
+# Copyright (c) 2009,2011 Gražvydas Ignotas
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 #       names of its contributors may be used to endorse or promote products
 #       derived from this software without specific prior written permission.
 #
-# THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
+# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND ANY
 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
+# DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
@@ -37,6 +37,7 @@
 .globl main
 .globl INT
 .globl VBL
+.globl return_to_main
 
 ##################################################
 #                                                #
@@ -81,7 +82,7 @@
 .equ MMODE_START_MENU, 4
 .equ MMODE_GOTO_PREDEF,        5
 .equ MMODE_JMP_ADDR,   6
-.equ MMODE_DUMP,       7
+.equ MMODE_PC,         7
 
 .equ predef_addr_cnt,  ((predef_addrs_end-predef_addrs)/4)
 
 .macro do_dpad bit op val
        btst.l          #\bit,d0
        beq             0f
-       \op.l           \val,a6
+       \op             \val,a6
        bra             dpad_end
 0:
 .endm
@@ -202,7 +203,8 @@ sprite_data_end:
 
 predef_addrs:
        dc.l 0x000000, 0x200000, 0x400000, 0xa00000, 0xa10000
-       dc.l 0xa11100, 0xa12000, 0xa13000, 0xa14000, 0xc00000
+       dc.l 0xa11100, 0xa12000, 0xa13000, 0xa14000, 0xa15100
+       dc.l 0xc00000
 predef_addrs_end:
 
 safe_addrs:
@@ -213,13 +215,13 @@ safe_addrs:
        dc.l 0xa12000, 0xa120ff
        dc.l 0xa13000, 0xa130ff
 safe_addrs_end:
+       dc.l 0xa15100, 0xa1513f
+safe_addrs_end_32x:
+       dc.l 0xa15180, 0xa153ff
+safe_addrs_end_32x_vdp:
 
-transfer_mode:
-       dc.l 0x000000           /* 1 for recv */
-transfer_addr:
-       dc.l 0x000000
-transfer_len:
-       dc.l 0x000800
+sizeof_bin:
+       dc.l _edata
 
 txt_edit:
        .ascii  "- edit -\0"
@@ -234,15 +236,13 @@ txt_goto_predef:
 txt_jmp_addr:
        .ascii  "Jump to address\0"
 txt_dump:
-       .ascii  "Transfer\0"
+       .ascii  "PC Transfer\0"
 txt_dtack:
        .ascii  "DTACK safety\0"
-txt_ready_send:
-       .ascii  "Ready to send\0"
-txt_ready_recv:
-       .ascii  "Ready to recv\0"
+txt_transfer_ready:
+       .ascii  "Transfer Ready\0"
 txt_working:
-       .ascii  "Working..    \0"
+       .ascii  "PC mode       \0"
 txt_dtack_err:
        .ascii  "DTACK err?\0"
 txt_exc:
@@ -265,8 +265,47 @@ txt_exc:
 .align 2
 
 main:
-       /* mask irqs during init */
+       /* make sure io port 2 is doing inputs */
+       move.b          #0,(0xa1000b).l
+       /* make sure irqs are masked */
        move.w          #0x2700,sr
+       /* take care of TMSS */
+       move.b          (0xa10000).l,d0
+       andi.b          #0x0f,d0
+       beq             no_tmss
+       move.l          #0x53454741,(0xa14000).l
+       /* want cart, not OS rom if cart pops in */
+       move.w          #1,(0xa14100).l
+       /* touch VDP after TMSS setup? */
+       tst.w           (0xc00004).l
+no_tmss:
+
+       /* want to do early PC transfer (with RAM/VRAM intact and such)?
+        * also give time PC to see start condition */
+       move.l          #0x2000,d0
+0:     dbra            d0,0b
+
+       move.l          #0xa10005,a0
+       btst.b          #5,(a0)
+       bne             no_early_transfer
+move.b #1,(0)
+       move.b          #0x40,(0xa1000b).l      /* port 2 ctrl */
+       move.b          #0x00,(a0)              /* port 2 data - start with TH low */
+       move.l          #0x2000,d0
+0:
+       btst.b          #4,(a0)
+       beq             do_early_transfer
+       dbra            d0,0b
+
+move.b #2,(0)
+       move.b          #0,(0xa1000b).l
+       bra             no_early_transfer       /* timeout */
+
+do_early_transfer:
+move.b #9,(0)
+       bsr             do_transfer
+
+no_early_transfer:
 
 .if COPY_TO_EXP
        /* copy to expansion device if magic number is set */
@@ -275,7 +314,8 @@ main:
        bne             0f
 
        move.l          #0,a0
-       move.w          #0x2000/8-1,d0
+       move.l          (sizeof_bin,pc),d0
+       lsr.l           #3,d0
 1:
        move.l          (a0)+,(a1)+
        move.l          (a0)+,(a1)+
@@ -292,7 +332,8 @@ main:
 
        /* copy, assume 8K size */
        move.l          #0xFF0100,a1
-       move.w          #0x2000/8-1,d0
+       move.l          (sizeof_bin,pc),d0
+       lsr.l           #3,d0
 1:
        move.l          (a0)+,(a1)+
        move.l          (a0)+,(a1)+
@@ -436,6 +477,12 @@ VBL:
        addq.b          #1,d7
 #      movem.l         d0-d4/a0-a5,-(a7)
 
+       btst.b          #5,(0xa10005).l
+       bne             no_auto_transfer
+       change_mode     MMODE_PC, MMODE_MAIN
+       write_vdp_r_dst 12,(VDP12_SCREEN_V224 | VDP12_SCREEN_H320 | VDP12_STE),(GFXCNTL)
+
+no_auto_transfer:
        moveq.l         #0,d0
        move.w          d7,d0
        lsr.w           #6,d0
@@ -443,6 +490,7 @@ VBL:
        lea             (jumptab,pc,d0),a0
        jmp             (a0)
 jumptab:
+       /* branch insns here because we want to be position independent */
        bra             mode_main
        bra             mode_val_input
        bra             mode_edit_val   /* edit val in editor */
@@ -703,20 +751,20 @@ draw_status_bar:
        btst.l          #16+4,d0                /* A - scroll modifier */
        beq             input_noa
 
-       do_dpad         16+0,  sub, #0x0800
-       do_dpad         16+1,  add, #0x0800
-       do_dpad         16+10, sub, #0xd800
-       do_dpad         16+11, add, #0xd800
+       do_dpad         16+0,  sub.l, #0x0800
+       do_dpad         16+1,  add.l, #0x0800
+       do_dpad         16+10, sub.l, #0xd800
+       do_dpad         16+11, add.l, #0xd800
 input_noa:
        moveq.l         #0,d1
        move.w          d7,d1
        lsr.w           #7,d1
        lsr.w           #7,d1
 
-       do_dpad         0,  subq, #0x0008
-       do_dpad         1,  addq, #0x0008
-       do_dpad         10, sub, d1
-       do_dpad         11, add, d1
+       do_dpad         0,  subq.l, #0x0008
+       do_dpad         1,  addq.l, #0x0008
+       do_dpad         10, sub.l, d1
+       do_dpad         11, add.l, d1
 
 dpad_end:
        /* update addr */
@@ -1164,7 +1212,7 @@ msm_no_ud:
 0:
        cmp.b           #3,d1
        bne             0f
-       change_mode     MMODE_DUMP, MMODE_MAIN
+       change_mode     MMODE_PC, MMODE_MAIN
        bsr             start_menu_box
        bra             vbl_end
 0:
@@ -1295,20 +1343,11 @@ mode_jmp_finish:
        move.l          d5,a0
        jmp             (a0)
 
-################### transfer #####################
-
 mode_transfer:
-       move.b          #0x40,(0xa1000b).l
-       move.b          #0x40,(0xa10005).l
+       move.b          #0x40,(0xa1000b).l      /* port 2 ctrl */
+       move.b          #0x00,(0xa10005).l      /* port 2 data - start with TH low */
 
-       move.l          (transfer_mode,pc),d0
-       tst.l           d0
-       bne             0f
-       lea             (txt_ready_send,pc),a0
-       bra             1f
-0:
-       lea             (txt_ready_recv,pc),a0
-1:
+       lea             (txt_transfer_ready,pc),a0
        move.l          #13,d0
        move.l          #13,d1
        move.l          #0x8000,d2
@@ -1320,75 +1359,9 @@ wait_tl_low0:
        bne             wait_tl_low0
 
        menu_text       txt_working, 13, 13, 0
-
-       lea             0xa10005,a1
-       move.l          (transfer_addr,pc),a0
-       move.l          (transfer_len,pc),d2
-
-       move.l          (transfer_mode,pc),d0
-       tst.l           d0
-       bne             transfer_recv
-
-transfer_send:
-       move.b          #0x4f,(0xa1000b).l
-
-tr_send_loop:
-       move.b          (a0),d1
-       and.b           #0x0f,d1
-
-wait_tl_low1:
-       move.b          (a1),d0
-       btst.b          #4,d0
-       bne             wait_tl_low1
-
-       move.b          d1,(a1)         /* clears TH and writes data */
-
-       move.b          (a0)+,d1
-       lsr.b           #4,d1
-       bset.b          #6,d1           /* prepare TH */
-
-wait_tl_hi1:
-       move.b          (a1),d0
-       btst.b          #4,d0
-       beq             wait_tl_hi1
-
-       move.b          d1,(a1)
-       subq.l          #1,d2
-       bne             tr_send_loop
-
-       move.b          #0,(0xa1000b).l
-       bra             return_to_main
-
-transfer_recv:
-       move.b          #0,(a1)         /* clear TH */
-
-tr_recv_loop:
-wait_tl_low2:
-       move.b          (a1),d0
-       btst.b          #4,d0
-       bne             wait_tl_low2
-
-       move.b          #0x40,(a1)      /* set TH */
-       move.b          d0,d1
-       and.b           #0x0f,d1
-
-wait_tl_hi2:
-       move.b          (a1),d0
-       btst.b          #4,d0
-       beq             wait_tl_hi2
-
-       move.b          #0,(a1)         /* clear TH */
-       lsl.b           #4,d0
-       or.b            d0,d1
-       move.b          d1,(a0)+
-
-       subq.l          #1,d2
-       bne             tr_recv_loop
-
-       move.b          #0,(0xa1000b).l
+       bsr             do_transfer
        bra             return_to_main
 
-
 # go back to main mode
 return_to_main:
        bclr.l          #7,d6           /* not edited */
@@ -1434,6 +1407,19 @@ get_safety_mask:
        lsr.l           #8,d1
        lea             (safe_addrs,pc),a1
        move.w          #(safe_addrs_end - safe_addrs)/8-1,d2
+       cmp.l           #0x4D415253,(0xa130ec)  /* 'MARS' */
+       bne             no_32x
+       move.w          #(safe_addrs_end_32x - safe_addrs)/8-1,d2
+       move.w          (0xa15100),d0
+       and.w           #3,d0
+       cmp.w           #3,d0                   /* ADEN and nRES */
+       bne             no_32x_vdp
+       btst.b          #7,d0                   /* FM */
+       bne             no_32x_vdp
+       move.w          #(safe_addrs_end_32x_vdp - safe_addrs)/8-1,d2
+no_32x_vdp:
+no_32x:
+
 0:
        move.l          (a1)+,d0
        cmp.l           d0,d1