+ /* 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_dump, 13, 14, 0
+ menu_text txt_dtack, 13, 15, 0
+ menu_text txt_a_confirm, 13, 17, 2
+
+ /* dtack safety on/off */
+ movea.l #0xe000+26*2+15*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 #7,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 #7,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 #4,d1
+0:
+ cmp.b #4,d1
+ ble 0f
+ move.b #0,d1
+0:
+ and.b #0xf8,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 #7,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
+ change_mode MMODE_PC, MMODE_MAIN
+ bsr start_menu_box
+ bra vbl_end
+0:
+ cmp.b #4,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 #11-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)
+
+mode_transfer:
+.if PC_TRANSFER
+ move.b #0x40,(0xa1000b).l /* port 2 ctrl */
+ move.b #0x00,(0xa10005).l /* port 2 data - start with TH low */
+
+ lea (txt_transfer_ready,pc),a0
+ move.l #13,d0
+ move.l #13,d1
+ move.l #0x8000,d2
+ jsr print
+
+wait_tl_low0:
+ move.b (0xa10005),d0
+ btst.b #4,d0
+ bne wait_tl_low0
+
+ menu_text txt_working, 13, 13, 0
+ bsr do_transfer
+.endif
+ bra return_to_main
+
+# 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