+ btst.l #15,d7
+ beq 0f
+ move.w #' ',(a0)
+0:
+ /* addr */
+ move.l a1,d2
+ moveq.l #6,d3
+ jsr print_hex_preped
+
+ btst.l #4,d6
+ bne draw_row_safe
+
+ bsr get_safety_mask
+ cmp.b #0xf,d0
+ beq draw_row_safe
+
+# unsafe or partially safe
+draw_row_hsafe:
+ move.l d0,d4
+ swap d4 /* mask in upper word */
+ btst.l #15,d7
+ bne draw_row_hsafe_words_pre
+
+draw_row_hsafe_bytes_pre:
+ /* 8 bytes */
+ moveq.l #2,d3
+ move.w #3,d4
+
+draw_row_hsafe_bytes:
+ move.w #' ',(a0)
+ move.b d4,d0
+ add.b #16,d0
+ btst.l d0,d4
+ bne 0f
+ move.l #'?'|('?'<<16),(a0)
+ move.w #' ',(a0)
+ move.l #'?'|('?'<<16),(a0)
+ bra 1f
+0:
+ move.b (0,a1),d2
+ jsr print_hex_preped
+ move.w #' ',(a0)
+ move.b (1,a1),d2
+ jsr print_hex_preped
+1:
+ addq.l #2,a1
+ dbra d4,draw_row_hsafe_bytes
+
+ move.w #' ',(a0)
+
+ move.l d5,d0
+ swap d0
+ cmp.w d5,d0
+ beq draw_cursor_unsafe_byte
+ bra draw_chars_hsafe_pre
+
+draw_row_hsafe_words_pre:
+ /* 4 shorts */
+ moveq.l #4,d3
+ move.w #3,d4
+
+draw_row_hsafe_words:
+ move.w #' ',(a0)
+ move.b d4,d0
+ add.b #16,d0
+ btst.l d0,d4
+ bne 0f
+ move.l #'?'|('?'<<16),(a0)
+ move.l #'?'|('?'<<16),(a0)
+ bra 1f
+0:
+ move.w (a1),d2
+ jsr print_hex_preped
+1:
+ addq.l #2,a1
+ dbra d4,draw_row_hsafe_words
+
+ move.l #(' '<<16)|' ',(a0)
+
+ move.l d5,d0
+ swap d0
+ cmp.w d5,d0
+ beq draw_cursor_unsafe_word
+
+draw_chars_hsafe_pre:
+ subq.l #8,a1
+ move.w #3,d4
+ moveq.l #0,d0
+
+draw_chars_hsafe:
+ move.b d4,d0
+ add.b #16,d0
+ btst.l d0,d4
+ bne 0f
+ move.l #'?'|('?'<<16),(a0)
+ bra draw_chars_hsafe_next
+0:
+ btst.l #15,d7 /* must perform correct read type */
+ bne 0f /* doing byte reads on security reg hangs */
+ move.b (0,a1),d0
+ lsl.l #8,d0
+ move.b (1,a1),d0
+ bra 1f
+0:
+ move.w (a1),d0
+1:
+ ror.l #8,d0
+ move.b d0,d1
+ sub.b #0x20,d1
+ cmp.b #0x60,d1
+ blo 0f
+ move.b #'.',d0
+0:
+ move.w d0,(a0)
+
+ move.b #0,d0
+ rol.l #8,d0
+ move.b d0,d1
+ sub.b #0x20,d1
+ cmp.b #0x60,d1
+ blo 0f
+ move.b #'.',d0
+0:
+ move.w d0,(a0)
+
+draw_chars_hsafe_next:
+ addq.l #2,a1
+ dbra d4,draw_chars_hsafe
+
+ move.l #(' '<<16)|' ',(a0)
+ add.w #0x80,a2
+ dbra d5,draw_row
+ bra draw_status_bar
+
+
+# normal draw
+draw_row_safe:
+ btst.l #15,d7
+ bne draw_row_words
+
+draw_row_bytes:
+ /* 8 bytes */
+ moveq.l #2,d3
+ moveq.l #8-1,d4
+draw_bytes:
+ move.w #' ',(a0)
+ move.b (a1)+,d2
+ jsr print_hex_preped
+ dbra d4,draw_bytes
+
+ move.w #' ',(a0)
+
+ move.l d5,d0
+ swap d0
+ cmp.w d5,d0
+ beq draw_cursor_byte
+ bra draw_chars_pre
+
+draw_row_words:
+ /* 4 shorts */
+ moveq.l #4,d3
+ moveq.l #4-1,d4
+draw_words:
+ move.w #' ',(a0)
+ move.w (a1)+,d2
+ jsr print_hex_preped
+ dbra d4,draw_words
+
+ move.l #(' '<<16)|' ',(a0)
+
+ move.l d5,d0
+ swap d0
+ cmp.w d5,d0
+ beq draw_cursor_word
+
+draw_chars_pre:
+ /* 8 chars */
+ subq.l #8,a1
+ moveq.l #8-1,d4
+draw_chars:
+ move.b (a1)+,d0
+ move.b d0,d1
+ sub.b #0x20,d1
+ cmp.b #0x60,d1
+ blo 0f
+ move.w #'.',d0
+0:
+ move.w d0,(a0)
+ dbra d4,draw_chars
+
+ move.l #(' '<<16)|' ',(a0)
+
+ add.w #0x80,a2
+ dbra d5,draw_row
+
+
+draw_status_bar:
+ /* status bar */
+ move.l a2,a0
+ jsr load_prepare
+
+ btst.l #15,d7
+ beq 0f
+ move.w #' ',(a0)
+0:
+ mk_a6_addr d2
+ move.l #0x4006,d3
+ jsr print_hex_preped
+
+ /* clear error */
+ moveq.l #5-1,d0
+0:
+ move.l #' '|(' '<<16),(a0)
+ move.l #' '|(' '<<16),(a0)
+ dbra d0,0b
+
+
+ /* handle input */
+ jsr get_input /* x0cbrldu x1sa00du */
+
+ 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
+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
+
+dpad_end:
+ /* update addr */
+ move.l a6,d1
+ cmp.b #0xf0,d1
+ blo 0f
+ sub.l #0xd800,a6
+ add.w #0x00d8,a6
+ bra 1f
+0:
+ cmp.b #0xd8,d1
+ blo 1f
+ add.l #0xd800,a6
+ sub.w #0x00d8,a6
+1:
+
+ /* other btns */
+ moveq.l #0,d1
+ btst.l #12,d0 /* B - switch byte/word mode */
+ beq input_nob
+ bclr.l #15,d7
+ add.w #0x4000,d7 /* changes between 01 10 */
+ move.l a6,d1
+ and.l #1,d1
+ sub.l d1,a6 /* make even, just in case */
+
+input_nob:
+ btst.l #13,d0 /* C - edit selected byte */
+ beq input_noc
+
+ change_mode MMODE_EDIT_VAL, MMODE_MAIN
+ write_vdp_r_dst 12,(VDP12_SCREEN_V224 | VDP12_SCREEN_H320 | VDP12_STE),(GFXCNTL)
+
+input_noc:
+ btst.l #5,d0 /* Start - menu */
+ beq input_nos
+
+ moveq.l #0,d5
+ change_mode MMODE_START_MENU, MMODE_MAIN
+ write_vdp_r_dst 12,(VDP12_SCREEN_V224 | VDP12_SCREEN_H320 | VDP12_STE),(GFXCNTL)
+
+input_nos:
+vbl_end:
+# movem.l (a7)+,d0-d4/a0-a5
+.if USE_VINT
+ rte
+.else
+ rts
+.endif
+
+
+draw_cursor_unsafe_byte:
+ move.l a6,d0
+ and.l #7,d0 /* byte offs */
+ move.b d0,d1
+ add.b d0,d0
+ add.b d1,d0 /* d0 *= 3 (chars) */
+ add.b d0,d0
+ lea (7*2,a2,d0),a0
+ jsr load_prepare
+ move.l #(0x2000|'?'|((0x2000|'?')<<16)),(a0)
+
+ move.l a2,a0
+ add.w #31*2,a0
+ jsr load_prepare /* restore a0 */
+ bra draw_chars_hsafe_pre
+
+draw_cursor_unsafe_word:
+ move.l a6,d0
+ and.l #7,d0 /* byte offs */
+ move.l d0,d1
+ lsr.b #1,d1 /* which word */
+ move.b d1,d2
+ lsl.b #2,d2
+ add.b d2,d1 /* num of chars to skip */
+ add.b d1,d1
+
+ lea (8*2,a2,d1),a0
+ jsr load_prepare
+ move.l #(0x2000|'?'|((0x2000|'?')<<16)),d0
+ move.l d0,(a0)
+ move.l d0,(a0)
+
+ move.l a2,a0
+ add.w #29*2,a0
+ jsr load_prepare /* restore a0 */
+ bra draw_chars_hsafe_pre
+
+
+draw_cursor_byte:
+ move.l a6,d0
+ and.l #7,d0 /* byte offs */
+ move.w #0x2002,d3
+
+ move.b (-8,a1,d0),d2
+ move.b d0,d1
+ add.b d0,d0
+ add.b d1,d0 /* d0 *= 3 (chars) */
+ add.b d0,d0
+ lea (7*2,a2,d0),a0
+ jsr load_prepare
+ jsr print_hex_preped
+
+ move.l a2,a0
+ add.w #31*2,a0
+ jsr load_prepare /* restore a0 */
+
+ bra draw_chars_pre
+
+draw_cursor_word:
+ move.l a6,d0
+ and.l #7,d0 /* byte offs */
+ move.l d0,d1
+ lsr.b #1,d1 /* which word */
+ move.b d1,d2
+ lsl.b #2,d2
+ add.b d2,d1 /* num of chars to skip */
+ add.b d1,d1
+ move.w #0x2004,d3
+
+ move.w (-8,a1,d0),d2
+ lea (8*2,a2,d1),a0
+ jsr load_prepare
+ jsr print_hex_preped
+
+ move.l a2,a0
+ add.w #29*2,a0
+ jsr load_prepare /* restore a0 */
+
+ bra draw_chars_pre
+
+
+#################### hedit #######################
+
+mode_edit_val:
+ btst.l #7,d6
+ bne mode_hedit_finish
+
+ /* read val to edit */
+ moveq.l #0,d5
+ mk_a6_addr d1
+ move.l d1,a0
+ btst.l #15,d7
+ bne 0f
+ move.b (a0),d5
+ lsl.l #8,d5
+ or.b #1,d5
+ bra 1f
+0:
+ move.w (a0),d5
+ lsl.l #8,d5
+ or.b #2,d5
+1:
+
+ change_mode MMODE_VAL_INPUT, MMODE_EDIT_VAL
+ bra vbl_end
+
+mode_hedit_finish:
+ /* write the val */
+ mk_a6_addr d1
+ move.l d1,a0
+ lsr.l #8,d5
+
+ btst.l #15,d7
+ bne 0f
+ move.b d5,(a0)
+ bra 1f
+0:
+ move.w d5,(a0)
+1:
+
+ bra return_to_main
+
+##################### goto #######################
+
+mode_goto:
+ btst.l #7,d6
+ bne mode_goto_finish
+
+ moveq.l #0,d5
+ swap d6
+ move.w d6,d5
+ swap d6
+ swap d5
+ or.b #3,d5 /* 3 bytes */
+ bclr.l #7,d6
+ change_mode MMODE_VAL_INPUT, MMODE_GOTO
+ bra vbl_end
+
+mode_goto_finish:
+ lsr.l #8,d5
+ move.l d5,d0
+ move.l d0,d1
+ and.l #7,d1
+ and.b #0xf8,d0
+ lsl.l #8,d0
+ or.l d1,d0
+ move.l d0,a6
+
+ lsr.l #8,d5
+ swap d6
+ move.w d5,d6
+ swap d6
+
+ bra return_to_main
+
+################### val edit #####################
+
+mode_val_input:
+ /* frame */
+ movea.l #0xe000+14*2+11*64*2,a1
+ moveq.l #6-1,d1
+0:
+ move.w a1,a0
+ jsr load_prepare
+ moveq.l #11-1,d0
+1:
+ move.w #0,(a0)
+ dbra d0,1b
+
+ add.w #64*2,a1
+ dbra d1,0b
+
+ /* text */
+ lea (txt_edit,pc),a0
+ move.l #15,d0
+ move.l #11,d1
+ move.l #0xc000,d2
+ jsr print
+
+ lea (txt_a_confirm,pc),a0
+ move.l #15,d0
+ move.l #15,d1
+ move.l #0xc000,d2
+ jsr print
+
+ /* edit field */
+ moveq.l #0,d0
+ moveq.l #0,d1
+ moveq.l #0,d3
+ move.b d5,d3
+ and.b #3,d3 /* edit field bytes */
+
+ move.b #19,d0
+ sub.b d3,d0
+ move.b #13,d1
+ move.l d5,d2
+ lsr.l #8,d2
+ add.b d3,d3
+ or.w #0x8000,d3
+ jsr print_hex
+
+ /* current char */
+ moveq.l #0,d0
+ moveq.l #0,d1
+
+ and.w #6,d3
+ move.b #19,d0
+ move.b d3,d1
+ lsr.b #1,d1 /* length in bytes */
+ sub.b d1,d0
+ move.b d5,d1
+ lsr.b #2,d1
+ and.b #7,d1 /* nibble to edit */
+ add.b d1,d0
+
+ sub.b d1,d3
+ sub.b #1,d3 /* chars to shift out */
+ lsl.b #2,d3
+ add.b #8,d3
+ move.l d5,d2
+ lsr.l d3,d2
+
+ move.b #13,d1
+ move.w #0xa001,d3
+ jsr print_hex
+
+ /* handle input */
+ jsr get_input /* x0cbrldu x1sa00du */
+
+ move.w d0,d1
+ and.w #0x0f00,d1
+ beq ai_no_dpad
+ move.b d5,d1
+ and.b #3,d1
+ add.b d1,d1 /* nibble count */
+ sub.b #1,d1 /* max n.t.e. val */
+ move.b d5,d2
+ lsr.b #2,d2
+ and.b #7,d2 /* nibble to edit */
+
+ move.b d0,d3
+ and.b #3,d3
+ beq ai_no_ud
+ moveq.l #0,d3
+ moveq.l #0,d4
+ move.b #0xf,d3
+ move.b #0x1,d4
+ sub.b d2,d1
+ lsl.b #2,d1
+ add.b #8,d1
+ lsl.l d1,d3 /* mask */
+ lsl.l d1,d4 /* what to add/sub */
+ move.l d5,d1
+ and.l d3,d1
+ btst.l #8,d0
+ beq 0f
+ add.l d4,d1
+ bra 1f
+0:
+ sub.l d4,d1
+1:
+ and.l d3,d1
+ eor.l #0xffffffff,d3
+ and.l d3,d5
+ or.l d1,d5
+ bra vbl_end
+
+ai_no_ud:
+ btst.l #10,d0
+ bne 0f
+ add.b #1,d2
+ bra 1f
+0:
+ sub.b #1,d2
+1:
+ cmp.b #0,d2
+ bge 0f
+ move.b d1,d2
+0:
+ cmp.b d1,d2
+ ble 0f
+ move.b #0,d2
+0:
+ and.b #0xe3,d5
+ lsl.b #2,d2
+ or.b d2,d5
+ bra vbl_end
+
+ai_no_dpad:
+ move.w d0,d1
+ and.w #0x1020,d1
+ beq ai_no_sb
+
+ bra return_to_main
+
+ai_no_sb:
+ btst.l #4,d0 /* A - confirm */
+ beq ai_no_input
+ bset.l #7,d6
+ move.w d7,d1 /* back to prev mode */
+ and.w #0x3800,d1
+ lsr.w #3,d1
+ and.w #0xc0ff,d7
+ or.w d1,d7
+
+ai_no_input:
+ bra vbl_end
+
+
+################### start menu ###################
+
+mode_start_menu:
+ /* frame */
+ bsr start_menu_box
+
+ /* text */
+ menu_text txt_about, 13, 9, 1
+ menu_text txt_goto, 13, 11, 0
+ menu_text txt_goto_predef, 13, 12, 0
+ menu_text txt_jmp_addr, 13, 13, 0
+ menu_text txt_dtack, 13, 14, 0
+ menu_text txt_a_confirm, 13, 16, 2
+
+ /* dtack safety on/off */
+ movea.l #0xe000+26*2+14*64*2,a0
+ jsr load_prepare
+ move.w #0x8000|'O',(a0)
+ btst.l #4,d6
+ bne 0f
+ move.w #0x8000|'N',(a0)
+ bra 1f
+0:
+ move.w #0x8000|'F',(a0)
+ move.w #0x8000|'F',(a0)
+1:
+
+ /* cursor */
+ movea.l #0xe000+11*2+11*64*2,a0
+ moveq.l #0,d0
+ move.b d5,d0
+ and.b #3,d0
+ lsl.w #7,d0
+ add.w d0,a0
+ jsr load_prepare
+ move.w #'>',(a0)
+
+ /* input */
+ jsr get_input /* x0cbrldu x1sa00du */
+
+ move.w d0,d1
+ and.w #3,d1
+ beq msm_no_ud
+ move.b d5,d1
+ and.b #3,d1
+ btst.l #0,d0
+ sne d2
+ or.b #1,d2 /* up -1, down 1 */
+ add.b d2,d1
+ cmp.b #0,d1
+ bge 0f
+ move.b #3,d1
+0:
+ cmp.b #3,d1
+ ble 0f
+ move.b #0,d1
+0:
+ and.b #0xfc,d5
+ or.b d1,d5
+ bra vbl_end
+
+msm_no_ud:
+ btst.l #4,d0 /* A - confirm */
+ beq msm_no_a
+ move.b d5,d1
+ and.b #3,d1
+ bne 0f
+ change_mode MMODE_GOTO, MMODE_MAIN
+ bsr start_menu_box
+ bra vbl_end
+0:
+ cmp.b #1,d1
+ bne 0f
+ moveq.l #0,d5
+ change_mode MMODE_GOTO_PREDEF, MMODE_MAIN
+ bsr start_menu_box
+ bra vbl_end
+0:
+ cmp.b #2,d1
+ bne 0f
+ change_mode MMODE_JMP_ADDR, MMODE_MAIN
+ bsr start_menu_box
+ bra vbl_end
+0:
+ cmp.b #3,d1
+ bne 0f
+ bchg.l #4,d6
+ bra vbl_end
+0:
+
+msm_no_a:
+ move.w d0,d1
+ and.w #0x3000,d1
+ beq msm_no_bc
+ bra return_to_main
+
+msm_no_bc:
+ bra vbl_end
+
+start_menu_box:
+ movea.l #0xe000+10*2+8*64*2,a1
+ move.w #10-1,d1
+0:
+ move.w a1,a0
+ jsr load_prepare
+ move.w #20-1,d0
+1:
+ move.w #0,(a0)
+ dbra d0,1b
+
+ add.w #64*2,a1
+ dbra d1,0b
+ rts
+
+################### goto predef ##################
+
+mode_goto_predef:
+ /* frame */
+ movea.l #0xe000+14*2+8*64*2,a1
+ move.l #predef_addr_cnt+2-1,d1
+0:
+ move.w a1,a0
+ jsr load_prepare
+ moveq.l #10-1,d0
+1:
+ move.w #0,(a0)
+ dbra d0,1b
+
+ add.w #64*2,a1
+ dbra d1,0b
+
+ /* draw addresses */
+ movea.l #0xe000+17*2+9*64*2,a1
+ lea (predef_addrs,pc),a2
+ move.w #predef_addr_cnt-1,d4
+ move.l #0x8006,d3
+mgp_da_loop:
+ move.w a1,a0
+ jsr load_prepare
+ move.l (a2)+,d2
+ jsr print_hex_preped
+ add.w #64*2,a1
+ dbra d4,mgp_da_loop
+
+ /* cursor */
+ movea.l #0xe000+15*2+9*64*2,a0
+ moveq.l #0,d0
+ move.b d5,d0
+ lsl.w #7,d0
+ add.w d0,a0
+ jsr load_prepare
+ move.w #'>',(a0)
+
+ /* input */
+ jsr get_input /* x0cbrldu x1sa00du */
+
+ move.w d0,d1
+ and.w #3,d1
+ beq mgp_no_ud
+ btst.l #0,d0
+ sne d2
+ or.b #1,d2 /* up -1, down 1 */
+ add.b d2,d5
+ cmp.b #0,d5
+ bge 0f
+ move.b #predef_addr_cnt-1,d5
+0:
+ cmp.b #predef_addr_cnt-1,d5
+ ble 0f
+ move.b #0,d5
+0:
+ bra vbl_end
+
+mgp_no_ud:
+ btst.l #4,d0 /* A - confirm */
+ beq mgp_no_a
+ moveq.l #0,d0
+ move.b d5,d0
+ lsl.w #2,d0
+ lea (predef_addrs,pc),a0
+ move.l (a0,d0),d5
+ lsl.l #8,d5
+ bra mode_goto_finish
+
+mgp_no_a:
+ move.w d0,d1
+ and.w #0x3000,d1
+ beq mgp_no_bc
+ bra return_to_main
+
+mgp_no_bc:
+ bra vbl_end
+
+##################### jmp ########################
+
+mode_jmp_addr:
+ btst.l #7,d6
+ bne mode_jmp_finish
+
+ moveq.l #0,d5
+ or.b #3,d5 /* 3 bytes */
+ bclr.l #7,d6
+ change_mode MMODE_VAL_INPUT, MMODE_JMP_ADDR
+ bra vbl_end
+
+mode_jmp_finish:
+ lsr.l #8,d5
+ write_vdp_r_dst 1,(VDP1_E_DISPLAY | VDP1_MODE5),(GFXCNTL) /* disable vint */
+ move.l d5,a0
+ jmp (a0)
+
+
+# go back to main mode
+return_to_main:
+ bclr.l #7,d6 /* not edited */
+ change_mode MMODE_MAIN, MMODE_MAIN
+ write_vdp_r_dst 12,(VDP12_SCREEN_V224 | VDP12_SCREEN_H320),(GFXCNTL)
+ bra vbl_end