Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
49cb98d
More efficient keyboard reading (when more keys are read)
zohassadar Sep 26, 2024
035950b
Use family basic keyboard for score name entry
zohassadar Sep 27, 2024
45909bf
replace space
zohassadar Sep 27, 2024
ae72c50
Delay before first row
zohassadar Sep 27, 2024
95c9e40
wait before column 1
zohassadar Sep 27, 2024
f1c76b8
save 5 cycles in wait loop and still be >50
zohassadar Sep 27, 2024
9382e3e
Merge remote-tracking branch 'origin/master' into keyboard_score_entry
zohassadar Feb 26, 2025
d940c77
better mapping
zohassadar Aug 25, 2025
eb8a77f
Merge remote-tracking branch 'origin/master' into keyboard_score_entry
zohassadar Aug 25, 2025
f33260e
preferred keybindings
zohassadar Aug 25, 2025
02da1ca
read keyboard after nmi wait
zohassadar Aug 25, 2025
aed681e
map only start during high score entry
zohassadar Aug 25, 2025
0830448
no longer applicable
zohassadar Aug 25, 2025
d312cc2
add note & build flag for var
zohassadar Aug 25, 2025
c3b4e9c
fix b-type crash when using keyboard code
zohassadar Aug 29, 2025
da59823
add mapping for every key & macro to use them
zohassadar Sep 22, 2025
7875127
untested revamp of everything
zohassadar Sep 23, 2025
55e4e44
fix bugs after testing
zohassadar Sep 23, 2025
8d0cd56
seed input with keyboard
zohassadar Sep 23, 2025
4480354
update kb doc from nesdev site
zohassadar Sep 24, 2025
d999b6d
move things around
zohassadar Sep 24, 2025
71edb34
Rename map.asm to constants.asm
zohassadar Sep 26, 2025
42610a6
keyboard detection
zohassadar Sep 27, 2025
350e56c
read 10th row instead of first
zohassadar Sep 27, 2025
6a4bc04
update addresses in ram comments
zohassadar Sep 27, 2025
ff3914c
proper ram reservation when no-keyboard
zohassadar Sep 29, 2025
012532d
Merge remote-tracking branch 'upstream/master' into keyboard_score_entry
zohassadar Sep 29, 2025
491b5ad
specify low byte for negative numbers
zohassadar Sep 29, 2025
8fe6f18
Update src/nametables/nametables.js
zohassadar Sep 29, 2025
fe9df0a
fix offset var
zohassadar Sep 29, 2025
831a04a
save bytes
zohassadar Sep 30, 2025
6f72aa2
disable controller while keyboard is active
zohassadar Sep 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ console.log();
// build / compress nametables

console.time('nametables');
process.env['GYM_FLAGS'] = compileFlags.join(' ');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

require('./src/nametables/build');
console.timeEnd('nametables');

Expand Down
11 changes: 11 additions & 0 deletions src/constants.asm
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,17 @@ MODE_LINECAP
MODE_DASONLY
MODE_QUAL
MODE_PAL
.if KEYBOARD = 1
MODE_KEYBOARD
.endif
.endenum

.if KEYBOARD = 1
MODE_QUANTITY = MODE_KEYBOARD + 1
.else
MODE_QUANTITY = MODE_PAL + 1
.endif

MODE_GAME_QUANTITY = MODE_HARDDROP + 1

SCORING_CLASSIC := 0 ; for scoringModifier
Expand Down Expand Up @@ -169,6 +177,9 @@ MENU_TOP_MARGIN_SCROLL := 7 ; in blocks
.byte $1 ; MODE_DASONLY
.byte $1 ; MODE_QUAL
.byte $1 ; MODE_PAL
.if KEYBOARD = 1
.byte $1 ; MODE_KEYBOARD
.endif
.endmacro

.macro MODENAMES
Expand Down
4 changes: 4 additions & 0 deletions src/gamemode/bootscreen.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ gameMode_bootScreen: ; boot
jsr updateAudioAndWaitForNmi
jsr checkRegion

.if KEYBOARD = 1
jsr detectKeyboard
.endif

.if !QUAL_BOOT
; check if qualMode is already set
lda qualFlag
Expand Down
38 changes: 38 additions & 0 deletions src/gamemode/gametypemenu/menu.asm
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ seedControls:
lda #BUTTON_RIGHT
jsr menuThrottle
beq @skipSeedRight
@moveRight:
lda #$01
sta soundEffectSlot1Init
inc menuSeedCursorIndex
Expand All @@ -151,7 +152,44 @@ seedControls:
@skipSeedRight:

lda menuSeedCursorIndex

.if KEYBOARD = 1
@kbSeedLow = generalCounter
@kbSeedHigh = generalCounter2
bne @checkForKbSeedEntry
jmp @skipSeedControl
@checkForKbSeedEntry:
jsr readKbSeedEntry
bmi @noKeysPressed
sta @kbSeedLow
asl
asl
asl
asl
sta @kbSeedHigh
ldy menuSeedCursorIndex
dey
tya
lsr
tay
; y = (index-1) // 2
; c = (index-1) % 2
lda set_seed_input,y
bcc @highByte
; low byte:
and #$F0
ora @kbSeedLow
bcs @storeSeed
@highByte:
and #$0F
ora @kbSeedHigh
@storeSeed:
sta set_seed_input,y
jmp @moveRight
@noKeysPressed:
.else
beq @skipSeedControl
.endif

lda menuSeedCursorIndex
sbc #1
Expand Down
7 changes: 7 additions & 0 deletions src/gamemodestate/handlegameover.asm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ gameModeState_handleGameOver:
@gameOver:
lda #$03
sta renderMode
.if KEYBOARD = 1
; flag for keyboard poll to ignore mapped keys except start/return
inc highScoreEntryActive
jsr handleHighScoreIfNecessary
dec highScoreEntryActive
.else
jsr handleHighScoreIfNecessary
.endif
lda #$01
sta playState
lda #$EF
Expand Down
9 changes: 9 additions & 0 deletions src/gamemodestate/initstate.asm
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,16 @@ L8824: ldx #rng_seed
tay
lda #EMPTY_TILE
sta playfield,y
.if KEYBOARD = 1
; this can probably be the same whether keyboard or not.
; the keyboard code adds the keyboard reading right before the oam staging reset.
; the additional keyboard reading cycles causes the b type setup to crash.
; Using the wait routine that skips the oam staging reset (and keyboard read) for now and
; keeping separate until b-type board test is developed.
jsr updateAudioAndWaitForNmi
.else
jsr updateAudioWaitForNmiAndResetOamStaging
.endif
dec generalCounter
bne L87E7
L884A:
Expand Down
53 changes: 47 additions & 6 deletions src/highscores/data.asm
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
highScorePpuAddrTable:
.dbyt $2284,$22C4,$2304
highScoreCharToTile:
.byte $FF,$0A,$0B,$0C,$0D,$0E,$0F,$10
.byte $11,$12,$13,$14,$15,$16,$17,$18
.byte $19,$1A,$1B,$1C,$1D,$1E,$1F,$20
.byte $21,$22,$23,$00,$01,$02,$03,$04
.byte $05,$06,$07,$08,$09,$25,$4F,$5E
.byte $5F,$6E,$6F,$52,$55,$24
.byte $FF ; Space
.byte $0A ; A
.byte $0B ; B
.byte $0C ; C
.byte $0D ; D
.byte $0E ; E
.byte $0F ; F
.byte $10 ; G
.byte $11 ; H
.byte $12 ; I
.byte $13 ; J
.byte $14 ; K
.byte $15 ; L
.byte $16 ; M
.byte $17 ; N
.byte $18 ; O
.byte $19 ; P
.byte $1A ; Q
.byte $1B ; R
.byte $1C ; S
.byte $1D ; T
.byte $1E ; U
.byte $1F ; V
.byte $20 ; W
.byte $21 ; X
.byte $22 ; Y
.byte $23 ; Z
.byte $00 ; 0
.byte $01 ; 1
.byte $02 ; 2
.byte $03 ; 3
.byte $04 ; 4
.byte $05 ; 5
.byte $06 ; 6
.byte $07 ; 7
.byte $08 ; 8
.byte $09 ; 9
.byte $25 ; ,
.byte $4F ; /
.byte $5E ; (
.byte $5F ; )
.byte $6E ; <3
.byte $6F ; .
.byte $52 ; !
.byte $55 ; ?
.byte $24 ; -

highScoreCharSize := $2E
11 changes: 11 additions & 0 deletions src/highscores/entry_screen.asm
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ highScoreEntryScreen:
jmp @ret

@checkForAOrRightPressed:

.if KEYBOARD = 1
jsr readKbHighScoreEntry
bmi @noKeyboardInput
beq @nextTile
cmp #$7F
beq @prevTile
jmp @waitForVBlank
@noKeyboardInput:

.endif
lda #BUTTON_RIGHT
jsr menuThrottle
bne @nextTile
Expand Down
7 changes: 0 additions & 7 deletions src/io.asm
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ SND_CHN := $4015
JOY1 := $4016
JOY2_APUFC := $4017 ; read: bits 0-4 joy data lines (bit 0 being normal controller), bits 6-7 are FC inhibit and mode

; Used by Family Basic Keyboard
.if KEYBOARD
KB_INIT := $05
KB_COL_0 := $04
KB_COL_1 := $06
KB_MASK := $1E
.endif

MMC1_Control := $8000
MMC1_CHR0 := $BFFF
Expand Down
8 changes: 8 additions & 0 deletions src/keyboard/buttonmap.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kbMappedUp = keyK
kbMappedDown = keyJ
kbMappedLeft = keyH
kbMappedRight = keyL
kbMappedB = keyD
kbMappedA = keyF
kbMappedSelect = keyShiftLeft
kbMappedStart = keyReturn
109 changes: 109 additions & 0 deletions src/keyboard/constants.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
; each key is represented by a byte 0RRRRCCC
; row is 0-8
; col is byte position from left to right

keyF1 = $0B
keyF2 = $13
keyF3 = $1B
keyF4 = $23
keyF5 = $2B
keyF6 = $33
keyF7 = $3B
keyF8 = $43

keyStop = $44
keyReturn = $42

keyShiftRight = $46
keyShiftLeft = $0F

keyESC = $0A
keyCTR = $08
keyGRPH = $0E

keyCLR_HOME = $03
keyINS = $04
keyDEL = $05

keyUp = $02
keyLeft = $00
keyRight = $01
keyDown = $07

keyCloseBracket = $40 ; ]
keyOpenBracket = $41 ; [
keyYen = $45 ; ¥
keySemicolon = $38 ; ;
keyColon = $39 ; :
keyatSign = $3A ; @
keyCaret = $3C ; ^
keySlash = $3E ; /
keyUnderscore = $3F ; _
keyComma = $36 ; ,
keyPeriod = $37 ; .
keyDash = $3D ; -
keyKana = $47

keySpace = $06

key0 = $34
key1 = $0D
key2 = $0C
key3 = $14
key4 = $1C
key5 = $1D
key6 = $24
key7 = $25
key8 = $2C
key9 = $2D

keyA = $10
keyB = $27
keyC = $1E
keyD = $18
keyE = $15
keyF = $1F
keyG = $21
keyH = $20
keyI = $2A
keyJ = $28
keyK = $30
keyL = $31
keyM = $2F
keyN = $2E
keyO = $32
keyP = $35
keyQ = $09
keyR = $19
keyS = $11
keyT = $1A
keyU = $29
keyV = $26
keyW = $12
keyX = $17
keyY = $22
keyZ = $16


KB_DISABLE = $00
KB_INIT = $05
KB_COL_0 = $04
KB_COL_1 = $06
KB_MASK = $1E

UPDOWN = BUTTON_UP | BUTTON_DOWN
LEFTRIGHT = BUTTON_LEFT | BUTTON_RIGHT

.macro readKeyDirect keyMap
; not zero - key is pressed
lda kbRawInput + (keyMap >> 3)
and #$80 >> (keyMap & 7)
.endmacro

.macro expandKeyRow keyMap
.byte keyMap >> 3
.endmacro

.macro expandKeyMask keyMap
.byte $80 >> (keyMap & 7)
.endmacro
15 changes: 15 additions & 0 deletions src/keyboard/keymap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
keymap = """
CloseBracket OpenBracket RETURN F8 STOP Yen SHIFTRight KANA
Semicolon Colon atSign F7 Caret Dash Slash Underscore
K L O F6 0 P Comma Period
J U I F5 8 9 N M
H G Y F4 6 7 V B
D R T F3 4 5 C F
A S W F2 3 E Z X
CTR Q ESC F1 2 1 GRPH SHIFTLeft
Left Right UP CLR_HOME INS DEL Space Down
"""

for row, keys in enumerate(keymap.strip().splitlines()):
for mask, key in enumerate(keys.split()):
print(f"key{key:<12} = ${((8 - row) << 3) | mask:02X}")
Loading