gb_test2
changeset 3:d7c6e1165028
added input handling
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 10 Jan 2019 06:05:21 +0200 |
parents | a8b7297e7e2c |
children | 216bdbc75cf4 |
files | hw.inc test.asm |
diffstat | 2 files changed, 102 insertions(+), 7 deletions(-) [+] |
line diff
1.1 --- a/hw.inc Thu Jan 10 04:48:34 2019 +0200 1.2 +++ b/hw.inc Thu Jan 10 06:05:21 2019 +0200 1.3 @@ -1,4 +1,5 @@ 1.4 ; vi:ft=rgbasm: 1.5 +REG_P1 equ $ff00 1.6 REG_LCDC equ $ff40 1.7 REG_STAT equ $ff41 1.8 REG_SCY equ $ff42 1.9 @@ -11,6 +12,17 @@ 1.10 REG_WY equ $ff4a 1.11 REG_WX equ $ff4b 1.12 1.13 +P1_RIGHT equ $01 1.14 +P1_A equ $01 1.15 +P1_LEFT equ $02 1.16 +P1_B equ $02 1.17 +P1_UP equ $04 1.18 +P1_SELECT equ $04 1.19 +P1_DOWN equ $08 1.20 +P1_START equ $08 1.21 +P1_DPAD equ $20 1.22 +P1_BUTTONS equ $10 1.23 + 1.24 LCDC_BGON equ $01 1.25 LCDC_OBJON equ $02 1.26 LCDC_OBJ16 equ $04
2.1 --- a/test.asm Thu Jan 10 04:48:34 2019 +0200 2.2 +++ b/test.asm Thu Jan 10 06:05:21 2019 +0200 2.3 @@ -4,7 +4,19 @@ 2.4 xoffs_center equ 4 2.5 yoffs_center equ 12 2.6 2.7 -frame_ptr equ $ff80 2.8 +frame equ $ff80 2.9 +bnstate equ $ff81 2.10 +bnxor equ $ff82 2.11 +pause equ $ff83 2.12 + 2.13 +BN_A equ $01 2.14 +BN_B equ $02 2.15 +BN_SELECT equ $04 2.16 +BN_START equ $08 2.17 +BN_RIGHT equ $10 2.18 +BN_LEFT equ $20 2.19 +BN_UP equ $40 2.20 +BN_DOWN equ $80 2.21 2.22 section "hdr", ROM0[$100] 2.23 nop 2.24 @@ -20,16 +32,53 @@ 2.25 call init 2.26 2.27 xor a, a 2.28 - ldh [frame_ptr], a 2.29 + ldh [frame], a 2.30 + ldh [bnstate], a 2.31 + ldh [bnxor], a 2.32 + ldh [pause], a 2.33 + 2.34 .mainloop: 2.35 ldh a, [REG_LY] 2.36 cp a, 144 2.37 jr c, .wait_hsync 2.38 2.39 - ; we're in vsync, increment frame counter and wait for the next frame 2.40 - ldh a, [frame_ptr] 2.41 + ; we're in vsync, increment frame counter, handle input, 2.42 + ; and wait for the next frame 2.43 + call read_input 2.44 + 2.45 + ; swap palette if A is pressed 2.46 + ldh a, [bnxor] 2.47 + and a, BN_A 2.48 + jr z, .skip_akey ; skip if A haven't changed state since last frame 2.49 + ldh a, [bnstate] 2.50 + and a, BN_A 2.51 + jr z, .skip_akey ; skip if A is not pressed 2.52 + ldh a, [REG_BGP] 2.53 + cpl 2.54 + ldh [REG_BGP], a 2.55 +.skip_akey: 2.56 + ; toggle pause if start is pressed 2.57 + ldh a, [bnxor] 2.58 + and a, BN_START 2.59 + jr z, .skip_startkey ; skip if start haven't changed state since last frame 2.60 + ldh a, [bnstate] 2.61 + and a, BN_START 2.62 + jr z, .skip_startkey ; skip if start is not pressed 2.63 + ldh a, [pause] 2.64 + cpl 2.65 + ldh [pause], a 2.66 +.skip_startkey: 2.67 + 2.68 + ; increment frame if we're not paused 2.69 + ldh a, [pause] 2.70 + bit 0, a 2.71 + jr nz, .skip_frameinc 2.72 + ldh a, [frame] 2.73 inc a 2.74 - ldh [frame_ptr], a 2.75 + ldh [frame], a 2.76 +.skip_frameinc: 2.77 + 2.78 + 2.79 .wait_newframe: 2.80 ldh a, [REG_LY] 2.81 cp a, 0 2.82 @@ -41,7 +90,7 @@ 2.83 and a, STAT_MODE_MASK 2.84 jr nz, .wait_hsync 2.85 2.86 - ldh a, [frame_ptr] 2.87 + ldh a, [frame] 2.88 ld d, a 2.89 2.90 xor a, a 2.91 @@ -98,7 +147,7 @@ 2.92 and a, STAT_MODE_MASK 2.93 jr z, .wait_endhsync 2.94 2.95 - jr .mainloop 2.96 + jp .mainloop 2.97 2.98 2.99 di 2.100 @@ -166,6 +215,40 @@ 2.101 jr c, wait_vsync 2.102 ret 2.103 2.104 +read_input: 2.105 + ; read D-pad 2.106 + ld a, P1_DPAD 2.107 + ld [REG_P1], a 2.108 + ld a, [REG_P1] 2.109 + ld a, [REG_P1] 2.110 + cpl 2.111 + and a, $0f 2.112 + swap a 2.113 + ld b, a 2.114 + ; read buttons 2.115 + ld a, P1_BUTTONS 2.116 + ld [REG_P1], a 2.117 + ld a, [REG_P1] 2.118 + ld a, [REG_P1] 2.119 + ld a, [REG_P1] 2.120 + ld a, [REG_P1] 2.121 + ld a, [REG_P1] 2.122 + ld a, [REG_P1] 2.123 + cpl 2.124 + and a, $0f 2.125 + or a, b 2.126 + ld b, a 2.127 + ; reset port 2.128 + ld a, P1_DPAD | P1_BUTTONS 2.129 + ldh [REG_P1], a 2.130 + ; calculate differences and save state variables 2.131 + ldh a, [bnstate] 2.132 + xor a, b 2.133 + ldh [bnxor], a 2.134 + ld a, b 2.135 + ldh [bnstate], a 2.136 + ret 2.137 + 2.138 section "data", ROM0, align[8] 2.139 sintab: 2.140 include "sin.inc"