Skip to content

Commit 42610a6

Browse files
committed
keyboard detection
1 parent 71edb34 commit 42610a6

File tree

18 files changed

+301
-278
lines changed

18 files changed

+301
-278
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Blocks are invisible until the end of the game.
248248

249249
![Hard Drop](./assets/screens/harddrop.png)
250250

251-
Press `up` to hard drop and `select` to soft drop.
251+
Press `up` to hard drop and `select` to sonic drop.
252252

253253
## Level Menu
254254

build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ console.log();
100100
// build / compress nametables
101101

102102
console.time('nametables');
103+
process.env['GYM_FLAGS'] = compileFlags.join(' ');
103104
require('./src/nametables/build');
104105
console.timeEnd('nametables');
105106

src/constants.asm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,17 @@ MODE_LINECAP
101101
MODE_DASONLY
102102
MODE_QUAL
103103
MODE_PAL
104+
.if KEYBOARD = 1
105+
MODE_KEYBOARD
106+
.endif
104107
.endenum
105108

109+
.if KEYBOARD = 1
110+
MODE_QUANTITY = MODE_KEYBOARD + 1
111+
.else
106112
MODE_QUANTITY = MODE_PAL + 1
113+
.endif
114+
107115
MODE_GAME_QUANTITY = MODE_HARDDROP + 1
108116

109117
SCORING_CLASSIC := 0 ; for scoringModifier
@@ -169,6 +177,9 @@ MENU_TOP_MARGIN_SCROLL := 7 ; in blocks
169177
.byte $1 ; MODE_DASONLY
170178
.byte $1 ; MODE_QUAL
171179
.byte $1 ; MODE_PAL
180+
.if KEYBOARD = 1
181+
.byte $1 ; MODE_KEYBOARD
182+
.endif
172183
.endmacro
173184

174185
.macro MODENAMES

src/gamemode/bootscreen.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ gameMode_bootScreen: ; boot
1515
jsr updateAudioAndWaitForNmi
1616
jsr checkRegion
1717

18+
.if KEYBOARD = 1
19+
jsr detectKeyboard
20+
.endif
21+
1822
.if !QUAL_BOOT
1923
; check if qualMode is already set
2024
lda qualFlag

src/gamemode/gametypemenu/menu.asm

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,37 +152,43 @@ seedControls:
152152
@skipSeedRight:
153153

154154
lda menuSeedCursorIndex
155-
.if KEYBOARD <> 1
156-
beq @skipSeedControl
157-
.else
158-
bne @readKeys
155+
156+
.if KEYBOARD = 1
157+
@kbSeedLow = generalCounter
158+
@kbSeedHigh = generalCounter2
159+
bne @checkForKbSeedEntry
159160
jmp @skipSeedControl
160-
@readKeys:
161+
@checkForKbSeedEntry:
161162
jsr readKbSeedEntry
162163
bmi @noKeysPressed
163-
sta generalCounter
164+
sta @kbSeedLow
165+
asl
166+
asl
167+
asl
168+
asl
169+
sta @kbSeedHigh
164170
ldy menuSeedCursorIndex
165171
dey
166172
tya
167173
lsr
168-
tay ; save seed offset
169-
bcc @highByte
174+
tay
175+
; y = (index-1) // 2
176+
; c = (index-1) % 2
170177
lda set_seed_input,y
178+
bcc @highByte
179+
; low byte:
171180
and #$F0
172-
ora generalCounter
173-
sta set_seed_input,y
174-
jmp @moveRight
181+
ora @kbSeedLow
182+
bcs @storeSeed
175183
@highByte:
176-
lda set_seed_input,y
177184
and #$0F
178-
asl generalCounter
179-
asl generalCounter
180-
asl generalCounter
181-
asl generalCounter
182-
ora generalCounter
185+
ora @kbSeedHigh
186+
@storeSeed:
183187
sta set_seed_input,y
184188
jmp @moveRight
185189
@noKeysPressed:
190+
.else
191+
beq @skipSeedControl
186192
.endif
187193

188194
lda menuSeedCursorIndex

src/gamemodestate/handlegameover.asm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ gameModeState_handleGameOver:
1818
lda #$03
1919
sta renderMode
2020
.if KEYBOARD = 1
21-
inc entryActive
21+
; flag for keyboard poll to ignore mapped keys except start/return
22+
inc highScoreEntryActive
2223
jsr handleHighScoreIfNecessary
23-
dec entryActive
24+
dec highScoreEntryActive
2425
.else
2526
jsr handleHighScoreIfNecessary
2627
.endif

src/highscores/entry_screen.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ highScoreEntryScreen:
178178
@checkForAOrRightPressed:
179179

180180
.if KEYBOARD = 1
181-
jsr readKbScoreInput
181+
jsr readKbHighScoreEntry
182182
bmi @noKeyboardInput
183183
beq @nextTile
184184
cmp #$7F

src/io.asm

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ SND_CHN := $4015
3434
JOY1 := $4016
3535
JOY2_APUFC := $4017 ; read: bits 0-4 joy data lines (bit 0 being normal controller), bits 6-7 are FC inhibit and mode
3636

37-
; Used by Family Basic Keyboard
38-
.if KEYBOARD
39-
KB_INIT := $05
40-
KB_COL_0 := $04
41-
KB_COL_1 := $06
42-
KB_MASK := $1E
43-
.endif
4437

4538
MMC1_Control := $8000
4639
MMC1_CHR0 := $BFFF

src/keyboard/buttonmap.asm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
; see keymap.asm for full list of keys
2-
31
kbMappedUp = keyK
42
kbMappedDown = keyJ
53
kbMappedLeft = keyH

src/keyboard/constants.asm

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
1-
; Assisted with the following python:
2-
; kbmap = """
3-
; CloseBracket OpenBracket RETURN F8 STOP Yen SHIFTRight KANA
4-
; Semicolon Colon atSign F7 Caret Dash Slash Underscore
5-
; K L O F6 0 P Comma Period
6-
; J U I F5 8 9 N M
7-
; H G Y F4 6 7 V B
8-
; D R T F3 4 5 C F
9-
; A S W F2 3 E Z X
10-
; CTR Q ESC F1 2 1 GRPH SHIFTLeft
11-
; Left Right UP CLR_HOME INS DEL Space Down
12-
; """
13-
; for row, keys in enumerate(kbmap.strip().splitlines()):
14-
; for mask, key in enumerate(keys.split()):
15-
; print(f"key{key:<12} = ${((8 - row) << 3) | mask:02X}")
16-
17-
.macro readKeyDirect keyMap
18-
lda keyboardInput + (keyMap >> 3)
19-
and #$80 >> (keyMap & 7)
20-
.endmacro
21-
22-
.macro expandKeyRow keyMap
23-
.byte keyMap >> 3
24-
.endmacro
25-
26-
.macro expandKeyMask keyMap
27-
.byte $80 >> (keyMap & 7)
28-
.endmacro
29-
30-
311
; each key is represented by a byte 0RRRRCCC
32-
; row is 0-8 and is inverted
2+
; row is 0-8
333
; col is byte position from left to right
344

355
keyF1 = $0B
@@ -113,3 +83,27 @@ keyW = $12
11383
keyX = $17
11484
keyY = $22
11585
keyZ = $16
86+
87+
88+
KB_DISABLE = $00
89+
KB_INIT = $05
90+
KB_COL_0 = $04
91+
KB_COL_1 = $06
92+
KB_MASK = $1E
93+
94+
UPDOWN = BUTTON_UP | BUTTON_DOWN
95+
LEFTRIGHT = BUTTON_LEFT | BUTTON_RIGHT
96+
97+
.macro readKeyDirect keyMap
98+
; not zero - key is pressed
99+
lda kbRawInput + (keyMap >> 3)
100+
and #$80 >> (keyMap & 7)
101+
.endmacro
102+
103+
.macro expandKeyRow keyMap
104+
.byte keyMap >> 3
105+
.endmacro
106+
107+
.macro expandKeyMask keyMap
108+
.byte $80 >> (keyMap & 7)
109+
.endmacro

0 commit comments

Comments
 (0)