Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; BANK $0C
- ; Displays the alphabet and allows entering text
- ; Used for savegame and character names
- ; Text is saved to the $580-... area
- ;
- *=$871D
- RegisterName:
- ; This draws the whole alphabet
- lda #$08 ; X
- sta $2A
- lda #$0C ; Y
- sta $29
- lda #$14 ; Columns
- sta $2E
- lda #$06 ; Rows
- sta $2D
- lda #$03 ; Ptr 3: the input "keyboard"
- sta $30
- jsr DrawTextPreGame
- ; This draws 5 empty spaces just above it?
- ; Likely where the input text will be displayed after each character entry
- lda #$08
- sta $2A
- lda #$0A
- sta $29
- lda #$05
- sta $2E
- lda #$01
- sta $2D
- lda #$17 ; Ptr $17: five empty spaces
- sta $30
- jsr DrawTextPreGame
- ; X = Index of currently selected "key"
- ; Y = Used to index the area of RAM where we store the text
- ; A = Count of entered characters
- ; Could have saved 3 bytes and CPU cycles by doing LAX #$00 TAY instead
- ldx #$00
- ldy #$00
- lda #$00
- sta $17
- _GetInput:
- jsr UpdateCursorTextInput
- jsr ControllerInput_Bank0C
- lda _ControllerStatus
- cmp #$01 ; D-pad Right
- bne $876A
- cpx #$27 ; END "Key" (can't move to the right of that)
- bne _CursorRight
- jmp _GetInput
- _CursorRight:
- inx
- jmp _GetInput
- cmp #$02 ; D-pad Left
- bne _ButtonUp
- cpx #$00
- bne _CursorLeft
- jmp _GetInput
- _CursorLeft:
- dex
- jmp _GetInput
- _ButtonUp:
- cmp #$08 ; D-pad Up
- bne _ButtonDown
- lda KeyIndexTbl_Up,X
- tax
- jmp _GetInput
- _ButtonDown:
- cmp #$04 ; D-pad Down
- bne _ButtonA
- lda KeyIndexTbl_Down,X
- tax
- jmp _GetInput
- _ButtonA:
- cmp #$80 ; Button A
- beq $8796
- jmp _GetInput
- stx $19
- sty $18
- cpx #$26 ; Backspace "key"
- bcc _EnterCharacter
- beq _Backspace
- rts ; Return if END was selected
- ; Note that there is no check for empty text here
- ; User chose to end text input
- _Backspace:
- lda $17
- bne _DeleteLast
- jmp _GetInput ; Back to input polling if text length is zero
- _DeleteLast:
- dec $17
- ldy $17
- lda #$FF
- sta $0580,Y
- dec $17
- jmp _DisplayEnteredText
- ; User pressed "A" on an input character
- _EnterCharacter:
- lda $17
- cmp #$05 ; Maximum length
- bne _AddNew
- jmp _GetInput
- _AddNew:
- lda AlphabetTileIdTbl,X
- ldy $17
- sta $0580,Y
- lda #$FF
- sta $0581,Y
- _DisplayEnteredText:
- lda #$08
- sta $2A
- lda #$09
- sta $29
- lda #$0A
- sta $2E
- lda #$01
- sta $2D
- lda #$FF
- sta $30
- ; Save cursor position
- lda $19
- pha
- lda $18
- pha
- lda $17
- pha
- jsr DrawTextPreGame
- ; Restore cursor position
- pla
- sta $17
- pla
- sta $18
- tay
- pla
- sta $19
- tax
- inc $17
- jmp _GetInput
- ; Index of the next key in the text input panel when moving
- ; the cursor up
- *=$8822
- KeyIndexTbl_Down:
- .byte $0A, $0B, $0C, $0D, $0E, $0F, $10, $11
- .byte $12, $13, $14, $15, $16, $17, $18, $19
- .byte $1A, $1B, $24, $25, $1C, $1D, $1E, $1F
- .byte $20, $21, $22, $23, $26, $26, $26, $26
- .byte $26, $26, $26, $26, $26, $26, $26, $27
- ; Index of the next key in the text input panel when moving
- ; the cursor down
- *=$884A
- KeyIndexTbl_Up:
- .byte $00, $01, $02, $03, $04, $05, $06, $07
- .byte $08, $09, $00, $01, $02, $03, $04, $05
- .byte $06, $07, $08, $09, $0A, $0B, $0C, $0D
- .byte $0E, $0F, $10, $11, $14, $15, $16, $17
- .byte $18, $19, $1A, $1B, $12, $13, $22, $24
- ; Tile IDs for alphabet letters, used for text input
- *=$87FC
- AlphabetTileIdTbl:
- .byte $8A, $8B, $8C, $8D, $8E, $8F, $90, $91
- .byte $92, $93, $94, $95, $96, $97, $98, $99
- .byte $9A, $9B, $9C, $9D, $9E, $9F, $A0, $A1
- .byte $A2, $A3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement