You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
393 lines
6.1 KiB
393 lines
6.1 KiB
include "charmap.inc"
|
|
include "video.inc"
|
|
include "defines.inc"
|
|
include "utils.inc"
|
|
include "hardware.inc"
|
|
|
|
cursor_max equ 5
|
|
|
|
section "prog/ezflash_test.asm@wram", wram0
|
|
|
|
w_cursor: db
|
|
w_write_val: db
|
|
w_write_addr: dw
|
|
w_write2_val: db
|
|
w_write2_addr: dw
|
|
w_read_addr: dw
|
|
|
|
section "prog/ezflash_test.asm", rom0
|
|
|
|
prog_ezflash_test::
|
|
call lcd_disable
|
|
call font_load
|
|
call pals_set_bw
|
|
call vram_clear_bgmap
|
|
call lcd_enable
|
|
|
|
ld hl, string_title
|
|
bgcoord de, (screen_width - string_title.end + string_title + 1) / 2, 2
|
|
call prints
|
|
|
|
ld hl, string_write
|
|
bgcoord de, 2, 5
|
|
call prints
|
|
ld hl, string_write
|
|
bgcoord de, 2, 7
|
|
call prints
|
|
ld hl, string_read
|
|
bgcoord de, 2, 10
|
|
call prints
|
|
|
|
xor a
|
|
ld [w_cursor], a
|
|
ld [w_write_val], a
|
|
ld [w_write2_val], a
|
|
ld [w_write2_addr + 0], a
|
|
ld [w_read_addr + 0], a
|
|
ld a, $a0
|
|
ld [w_read_addr + 1], a
|
|
ld a, $c0
|
|
ld [w_write_addr + 0], a
|
|
ld a, $7f
|
|
ld [w_write_addr + 1], a
|
|
ld a, $a0
|
|
ld [w_write2_addr + 1], a
|
|
|
|
ld hl, ezf_write_code
|
|
ld de, ezf_write_ram
|
|
ld bc, ezf_write_end - ezf_write_ram
|
|
call memcpy
|
|
|
|
call ezf_unlock
|
|
|
|
call update_write_addr
|
|
call update_write_val
|
|
call update_write2_addr
|
|
call update_write2_val
|
|
call update_read_addr
|
|
xor a
|
|
call update_cursor
|
|
|
|
main:
|
|
call update_read_view
|
|
call vblank_wait
|
|
call joypad_update
|
|
ldh a, [h_joypad_pressed]
|
|
rra ; joy_a
|
|
jr c, .joy_a
|
|
rra ; joy_b
|
|
rra ; joy_select
|
|
rra ; joy_start
|
|
rra ; joy_right
|
|
jr c, .joy_right
|
|
rra ; joy_left
|
|
jr c, .joy_left
|
|
rra ; joy_up
|
|
jr c, .joy_up
|
|
rra ; joy_down
|
|
jr c, .joy_down
|
|
jr main
|
|
|
|
.joy_a
|
|
ld a, [w_cursor]
|
|
srl a
|
|
and a
|
|
jr z, .joy_a_write
|
|
dec a
|
|
jr z, .joy_a_write2
|
|
jr main
|
|
|
|
.joy_a_write
|
|
ld hl, w_write_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
ld a, [w_write_val]
|
|
call ezf_write
|
|
jr main
|
|
|
|
.joy_a_write2
|
|
ld hl, w_write2_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
ld a, [w_write2_val]
|
|
call ezf_write
|
|
jr main
|
|
|
|
.joy_right
|
|
ld a, 1
|
|
call update_cursor
|
|
jr main
|
|
|
|
.joy_left
|
|
ld a, cursor_max - 1
|
|
call update_cursor
|
|
jr main
|
|
|
|
.joy_up
|
|
ld de, $10
|
|
ldh a, [h_joypad_down]
|
|
bit joy_b_f, a
|
|
jr nz, .joy_up_done
|
|
ld de, 1
|
|
.joy_up_done
|
|
call update_val
|
|
jr main
|
|
|
|
.joy_down
|
|
ld de, -$10
|
|
ldh a, [h_joypad_down]
|
|
bit joy_b_f, a
|
|
jr nz, .joy_down_done
|
|
ld de, -1
|
|
.joy_down_done
|
|
call update_val
|
|
jr main
|
|
|
|
update_val:
|
|
; de: value increment
|
|
ld a, [w_cursor]
|
|
ld hl, .jumptable
|
|
ld c, 2
|
|
call array_index
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
jp hl
|
|
|
|
.jumptable
|
|
dw .write_addr
|
|
dw .write_val
|
|
dw .write2_addr
|
|
dw .write2_val
|
|
dw .read_addr
|
|
|
|
.write_addr
|
|
ld hl, w_write_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
add hl, de
|
|
ld a, l
|
|
ld [w_write_addr + 0], a
|
|
ld a, h
|
|
ld [w_write_addr + 1], a
|
|
jp update_write_addr
|
|
|
|
.write_val
|
|
ld hl, w_write_val
|
|
ld a, [hl]
|
|
add e
|
|
ld [hl], a
|
|
jp update_write_val
|
|
|
|
.write2_addr
|
|
ld hl, w_write2_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
add hl, de
|
|
ld a, l
|
|
ld [w_write2_addr + 0], a
|
|
ld a, h
|
|
ld [w_write2_addr + 1], a
|
|
jp update_write2_addr
|
|
|
|
.write2_val
|
|
ld hl, w_write2_val
|
|
ld a, [hl]
|
|
add e
|
|
ld [hl], a
|
|
jp update_write2_val
|
|
|
|
.read_addr
|
|
ld hl, w_read_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
add hl, de
|
|
ld a, l
|
|
ld [w_read_addr + 0], a
|
|
ld a, h
|
|
ld [w_read_addr + 1], a
|
|
jp update_read_addr
|
|
|
|
update_cursor:
|
|
; a: cursor increment
|
|
ld hl, w_cursor
|
|
ld e, [hl]
|
|
ld d, e
|
|
add e
|
|
ld c, cursor_max
|
|
call divide
|
|
ld [hl], a
|
|
ld e, a
|
|
; d: old, e: new
|
|
|
|
ld a, d
|
|
ld d, 0
|
|
call .set
|
|
ld a, e
|
|
ld d, "-"
|
|
|
|
.set
|
|
; a: position
|
|
; d: character
|
|
ld hl, .coords
|
|
ld c, 2
|
|
call array_index
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
call lcd_blank_wait
|
|
ld [hl], d
|
|
ret
|
|
|
|
.coords
|
|
dbgcoord 8, 5
|
|
dbgcoord 8 + 6, 5
|
|
dbgcoord 8, 7
|
|
dbgcoord 8 + 6, 7
|
|
dbgcoord 8, 10
|
|
|
|
update_write_addr:
|
|
ld hl, w_write_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
bgcoord de, 9, 5
|
|
jp print_hex_4digit
|
|
|
|
update_write_val:
|
|
ld a, [w_write_val]
|
|
bgcoord de, 9 + 6, 5
|
|
jp print_hex_2digit
|
|
|
|
update_write2_addr:
|
|
ld hl, w_write2_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
bgcoord de, 9, 7
|
|
jp print_hex_4digit
|
|
|
|
update_write2_val:
|
|
ld a, [w_write2_val]
|
|
bgcoord de, 9 + 6, 7
|
|
jp print_hex_2digit
|
|
|
|
update_read_addr:
|
|
ld hl, w_read_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
bgcoord de, 9, 10
|
|
jp print_hex_4digit
|
|
|
|
update_read_view:
|
|
ld hl, w_read_addr
|
|
ld a, [hl+]
|
|
ld h, [hl]
|
|
ld l, a
|
|
bgcoord de, 2, 12
|
|
ld b, 4
|
|
.loop
|
|
ld c, 8
|
|
.loop_inner
|
|
push bc
|
|
ld a, [hl+]
|
|
call print_hex_2digit
|
|
pop bc
|
|
dec c
|
|
jr nz, .loop_inner
|
|
add_r16_8 de, 32 - 16
|
|
dec b
|
|
jr nz, .loop
|
|
ret
|
|
|
|
ezf_unlock:
|
|
xor a
|
|
ld hl, $7f31
|
|
call ezf_write
|
|
ld a, $80
|
|
ld hl, $7f32
|
|
jp ezf_write
|
|
|
|
string_title: db "EZFLASH TESTER$"
|
|
.end
|
|
string_write: db "WRITE$"
|
|
string_read: db "READ$"
|
|
|
|
ezf_write:
|
|
; a: value
|
|
; hl: address
|
|
ld b, a
|
|
ld a, h
|
|
cp $7f
|
|
jp nz, ezf_write_do
|
|
ld a, l
|
|
cp $d2
|
|
jp z, .wait
|
|
cp $36
|
|
jp nz, ezf_write_do
|
|
|
|
.wait
|
|
push bc
|
|
push hl
|
|
ld hl, $7fc0
|
|
ld b, $05
|
|
call ezf_write_do
|
|
bgcoord de, 15, 10
|
|
ld a, "."
|
|
call lcd_blank_wait
|
|
ld [de], a
|
|
pop hl
|
|
pop bc
|
|
call ezf_write_7fd2
|
|
bgcoord de, 15, 10
|
|
xor a
|
|
call lcd_blank_wait
|
|
ld [de], a
|
|
ret
|
|
|
|
ezf_write_code:
|
|
load "prog/ezflash_test.asm@ezf_write", wram0
|
|
ezf_write_ram:
|
|
ezf_write_do:
|
|
ld de, $7f00
|
|
ld a, $e1
|
|
ld [de], a
|
|
ld e, $10
|
|
inc a
|
|
ld [de], a
|
|
ld e, $20
|
|
inc a
|
|
ld [de], a
|
|
ld [hl], b
|
|
ld e, $f0
|
|
inc a
|
|
ld [de], a
|
|
ret
|
|
|
|
ezf_write_7fd2:
|
|
di
|
|
call ezf_write_do
|
|
ld de, $a000
|
|
.loop
|
|
ld a, [de]
|
|
and a
|
|
jr nz, .loop
|
|
|
|
jr @ ; TEST
|
|
|
|
ld b, 0
|
|
call ezf_write_do
|
|
ei
|
|
ret
|
|
|
|
; 7f32:01 -> 7fd2:01 (hang)
|
|
; 7f36:02 (hang)
|
|
; 7f36:03 (hang)
|
|
|
|
ezf_write_end:
|
|
|