include "cpu/6x09/include/common.inc" include "cpu/6x09/include/handlers/memory_write.inc" global memory_write_generic_write global memory_write_handler global d_str_last_written COLUMN_START equ SCREEN_START_X ROW_START equ SCREEN_START_Y + 4 section code ; params: ; x = mw_settings_ptr ; callbacks: ; highlight_cb (params: x is at seek_xy) ; This is responsible for applying a highlight to the char at the ; tile address at x and also removing the highlight from the ; previous's calls x address. ; write_memory_cb (no params) ; The is called when the user presses B2 to write memory. You ; should write the contents of your buffer to your memory location ; and print whatever you see fit on screen. ie: last written. ; loop_cb (no params) ; This is called each input loop and can be used for monitoring ; or displaying stuff outside of the user doing a write. ie: if ; you wanted to test nmi enable/disable, you could have an nmi ; handler that increments a counter and then have this callback ; constantly printing the couter value to the screen. memory_write_handler: stx r_mw_settings lda s_mw_num_bytes, x deca sta r_num_bytes ; saving off 0 indexed clr r_active_bit clr r_active_byte ldy #d_screen_xys_list jsr print_xy_string_list .loop_redraw_data: jsr print_data .loop_redraw_active: lda #COLUMN_START + 7 suba r_active_bit ldb #ROW_START addb r_active_byte RSUB screen_seek_xy ldy r_mw_settings jsr [s_mw_highlight_cb, y] .loop_input: WATCHDOG ldy r_mw_settings jsr [s_mw_loop_cb, y] jsr input_update lda r_input_edge bita #INPUT_UP beq .up_not_pressed dec r_active_byte bpl .loop_redraw_active lda r_num_bytes sta r_active_byte bra .loop_redraw_active .up_not_pressed: bita #INPUT_DOWN beq .down_not_pressed inc r_active_byte lda r_active_byte cmpa r_num_bytes ble .loop_redraw_active clr r_active_byte bra .loop_redraw_active .down_not_pressed: bita #INPUT_LEFT beq .left_not_pressed inc r_active_bit lda r_active_bit cmpa #$7 ble .loop_redraw_active clr r_active_bit bra .loop_redraw_active .left_not_pressed: bita #INPUT_RIGHT beq .right_not_pressed dec r_active_bit bpl .loop_redraw_active lda #$7 sta r_active_bit lbra .loop_redraw_active .right_not_pressed: bita #INPUT_B1 beq .b1_not_pressed ldy #d_xor_table lda r_active_bit ldb a, y stb r_scratch lda r_active_byte ldy r_mw_settings ldy s_mw_buffer_ptr, y ldb a, y eorb r_scratch stb a, y lbra .loop_redraw_data .b1_not_pressed: bita #INPUT_B2 lbeq .loop_input lda r_input_raw bita #INPUT_RIGHT bne .do_exit ldy r_mw_settings jsr [s_mw_write_memory_cb, y] lbra .loop_input .do_exit: rts print_data: ldy r_mw_settings ldy s_mw_buffer_ptr, y ldb r_num_bytes stb r_scratch .print_next_byte: lda #COLUMN_START ldb #ROW_START addb r_scratch RSUB screen_seek_xy ldb r_scratch lda b, y pshs y RSUB print_bits_byte puls y lda #COLUMN_START + 10 ldb #ROW_START addb r_scratch RSUB screen_seek_xy ldb r_scratch lda b, y pshs y RSUB print_hex_byte puls y dec r_scratch bpl .print_next_byte rts ; params: ; a = number of bytes to write ; x = dest address memory_write_generic_write: ldy r_mw_settings ldy s_mw_buffer_ptr, y lda r_num_bytes inca sta r_scratch adda #ROW_START + 1 sta r_y_offset lda #SCREEN_START_X sta r_x_offset pshs x, y ; try and find a better home for this. Can't put it in the ; main handler since custom write callbacks might want it in ; a different location on screen ldb r_y_offset RSUB screen_seek_xy ldy #d_str_last_written RSUB print_string puls y, x lda r_y_offset adda #$2 sta r_y_offset .loop_next_byte: pshs x lda r_x_offset ldb r_y_offset RSUB screen_seek_xy lda , y+ pshs a, y RSUB print_hex_byte puls y, a puls x sta , x+ lda r_x_offset adda #$3 sta r_x_offset dec r_scratch bne .loop_next_byte rts section data d_screen_xys_list: XY_STRING SCREEN_START_X, (SCREEN_START_Y + 2), "76543210 HEX" XY_STRING SCREEN_START_X, (SCREEN_B1_Y - 1), "JOY SELECT BIT" XY_STRING SCREEN_START_X, SCREEN_B1_Y, "B1 TOGGLE BIT" XY_STRING SCREEN_START_X, SCREEN_B2_Y, "B2 WRITE MEMORY" XY_STRING SCREEN_START_X, (SCREEN_B2_Y + 1), "EXIT HOLD R B2" XY_STRING_LIST_END d_str_last_written: STRING "LAST WRITTEN" d_xor_table: dc.b $01, $02, $04, $08, $10, $20, $40, $80 section bss r_mw_settings: dcb.w 1 r_num_bytes: dcb.b 1 r_active_bit: dcb.b 1 r_active_byte: dcb.b 1 r_x_offset: dcb.b 1 r_y_offset: dcb.b 1