Browse Source

Add ezflash testing program

master
mid-kid 3 years ago
parent
commit
b97aa85e98
  1. 1
      .gitignore
  2. 4
      Makefile
  3. 19
      source/home/math.asm
  4. 37
      source/home/text.asm
  5. 8
      source/home/vblank.asm
  6. 7
      source/main.asm
  7. 393
      source/prog/ezflash_test.asm
  8. 11
      source/prog/serial_test.asm
  9. 23
      source/utils.inc
  10. 26
      source/video.inc

1
.gitignore

@ -1,4 +1,5 @@
/*.gb
/*.sav
/*.map
/*.sym
/build

4
Makefile

@ -9,9 +9,9 @@ RGBGFX := rgbgfx
RGBLINK := rgblink
RGBFIX := rgbfix
RGBASMFLAGS := -p 0xff -L
RGBASMFLAGS := -p 0xff -L -Weverything
RGBLINKFLAGS := -p 0xff -d -t
RGBFIXFLAGS := -p 0xff -j -m 0 -r 0 -n 0 -k "HB" -i "SMTH" -t "Something"
RGBFIXFLAGS := -p 0xff -j -m 1 -r 0 -n 0 -k "HB" -i "SMTH" -t "Something"
rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
objects := $(patsubst $(dir_source)/%.asm, $(dir_build)/%.o, $(call rwildcard, $(dir_source)/, *.asm))

19
source/home/math.asm

@ -13,7 +13,26 @@ bits_swap::
jr nc, .loop
ret
; TODO: There was a more optimal way to do this with max 16 iterations
array_index::
; hl: array base
; c: entry size
; a: index
and a
ret z
ld b, 0
.loop
add hl, bc
dec a
jr nz, .loop
ret
divide::
; a: value
; c: divisor
; Returns:
; b: result
; a: remainder
ld b, 0
.loop
inc b

37
source/home/text.asm

@ -30,7 +30,7 @@ print::
inc de
jr print
print_num_3digit::
print_dec_3digit::
; a: Number
; de: Tilemap positon
push af
@ -58,6 +58,41 @@ print_num_3digit::
jr nz, .loop
ret
print_hex_4digit::
; hl: Number
; de: Tilemap position
ld a, h
swap a
call print_hex_1digit
ld a, h
call print_hex_1digit
ld a, l
swap a
call print_hex_1digit
ld a, l
jr print_hex_1digit
print_hex_2digit::
; a: Number
; de: Tilemap position
ld b, a
swap a
call print_hex_1digit
ld a, b
jr print_hex_1digit
print_hex_1digit:
and $f
add "0"
cp "9" + 1
jr c, .skip
add "A" - "0" - $a
.skip
call lcd_blank_wait
ld [de], a
inc de
ret
font_load::
ld hl, gfx_font
ld de, v_font_numbers

8
source/home/vblank.asm

@ -34,3 +34,11 @@ vblank_wait::
and a
jr z, .loop
ret
vblank_wait_frames::
ld c, a
.loop
call vblank_wait
dec c
jr nz, .loop
ret

7
source/main.asm

@ -1,21 +1,20 @@
include "charmap.inc"
include "defines.inc"
include "video.inc"
section "main.asm", rom0
main::
;call prog_serial_test
call prog_ezflash_test
call lcd_disable
call font_load
call pals_set_bw
;call vram_clear_bgmap
call lcd_enable
ld hl, string_something
bgcoord de, (screen_width - string_something.end + string_something + 1) / 2, 2
call print
;call prog_serial_test
jp _halt_
string_something: db "SOMETHING$"

393
source/prog/ezflash_test.asm

@ -0,0 +1,393 @@
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 print
ld hl, string_write
bgcoord de, 2, 5
call print
ld hl, string_write
bgcoord de, 2, 7
call print
ld hl, string_read
bgcoord de, 2, 10
call print
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:

11
source/prog/serial_test.asm

@ -8,6 +8,7 @@ prog_serial_test::
call lcd_disable
call font_load
call pals_set_bw
call vram_clear_bgmap
call lcd_enable
ld hl, string_title
@ -16,8 +17,9 @@ prog_serial_test::
call serial_init_master
main_loop:
main:
call joypad_update
ldh a, [h_joypad_released]
bit joy_a_f, a
jr nz, .send_shit
@ -27,14 +29,9 @@ main_loop:
.continue
call vblank_wait
jr main_loop
jr main
.send_shit
call vblank_wait
call joypad_update
bit joy_a_f, a
jr nz, .send_shit
bgcoord hl, 7, 5
call lcd_blank_wait
ld [hl], "A"

23
source/utils.inc

@ -0,0 +1,23 @@
if !def(_utils_inc_)
_utils_inc_ equ 0
_add_r16_8: macro
ld a, \2
add (\3)
ld \2, a
adc \1
sub \2
ld \1, a
endm
add_r16_8: macro
if "\1" == "hl"
_add_r16_8 h, l, (\2)
elif "\1" == "bc"
_add_r16_8 b, c, (\2)
elif "\1" == "de"
_add_r16_8 d, e, (\2)
endc
endm
endc

26
source/video.inc

@ -12,20 +12,36 @@ len_2bpp_tile equ 2 * tile_height
tile equs "+ len_2bpp_tile *"
tiles equs "* len_2bpp_tile"
coord: MACRO
coord: macro
if _NARG < 4
ld \1, (\3) * screen_width + (\2) + w_tilemap
else
ld \1, (\3) * screen_height + (\2) + (\4)
ld \1, (\3) * screen_width + (\2) + (\4)
endc
ENDM
endm
bgcoord: MACRO
dcoord: macro
if _NARG < 4
dw (\2) * screen_width + (\1) + w_tilemap
else
dw (\2) * screen_width + (\1) + (\3)
endc
endm
bgcoord: macro
if _NARG < 4
ld \1, (\3) * bgmap_width + (\2) + v_bgmap1
else
ld \1, (\3) * bgmap_width + (\2) + (\4)
endc
ENDM
endm
dbgcoord: macro
if _NARG < 3
dw (\2) * bgmap_width + (\1) + v_bgmap1
else
dw (\2) * bgmap_width + (\1) + (\3)
endc
endm
endc

Loading…
Cancel
Save