Advertisement
FoxCunning

RegisterName.asm

Mar 12th, 2021 (edited)
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; BANK $0C
  2.  
  3. ; Displays the alphabet and allows entering text
  4. ; Used for savegame and character names
  5. ; Text is saved to the $580-... area
  6. ;
  7. *=$871D
  8. RegisterName:
  9. ; This draws the whole alphabet
  10.   lda #$08  ; X
  11.   sta $2A
  12.   lda #$0C  ; Y
  13.   sta $29
  14.   lda #$14  ; Columns
  15.   sta $2E
  16.   lda #$06  ; Rows
  17.   sta $2D
  18.   lda #$03  ; Ptr 3: the input "keyboard"
  19.   sta $30
  20.   jsr DrawTextPreGame
  21.  
  22. ; This draws 5 empty spaces just above it?
  23. ; Likely where the input text will be displayed after each character entry
  24.   lda #$08
  25.   sta $2A
  26.   lda #$0A
  27.   sta $29
  28.   lda #$05
  29.   sta $2E
  30.   lda #$01
  31.   sta $2D
  32.   lda #$17  ; Ptr $17: five empty spaces
  33.   sta $30
  34.   jsr DrawTextPreGame
  35.  
  36. ; X = Index of currently selected "key"
  37. ; Y = Used to index the area of RAM where we store the text
  38. ; A = Count of entered characters
  39. ; Could have saved 3 bytes and CPU cycles by doing LAX #$00 TAY instead
  40.   ldx #$00
  41.   ldy #$00
  42.   lda #$00
  43.   sta $17
  44.  
  45. _GetInput:
  46.   jsr UpdateCursorTextInput
  47.   jsr ControllerInput_Bank0C
  48.   lda _ControllerStatus
  49.   cmp #$01  ; D-pad Right
  50.   bne $876A
  51.   cpx #$27  ; END "Key" (can't move to the right of that)
  52.   bne _CursorRight
  53.   jmp _GetInput
  54.  
  55. _CursorRight:
  56.   inx
  57.   jmp _GetInput
  58.  
  59.   cmp #$02  ; D-pad Left
  60.   bne _ButtonUp
  61.   cpx #$00
  62.   bne _CursorLeft
  63.   jmp _GetInput
  64.  
  65. _CursorLeft:
  66.   dex
  67.   jmp _GetInput
  68.  
  69. _ButtonUp:
  70.   cmp #$08  ; D-pad Up
  71.   bne _ButtonDown
  72.   lda KeyIndexTbl_Up,X
  73.   tax
  74.   jmp _GetInput
  75.  
  76. _ButtonDown:
  77.   cmp #$04  ; D-pad Down
  78.   bne _ButtonA
  79.   lda KeyIndexTbl_Down,X
  80.   tax
  81.   jmp _GetInput
  82.  
  83. _ButtonA:
  84.   cmp #$80  ; Button A
  85.   beq $8796
  86.   jmp _GetInput
  87.  
  88.   stx $19
  89.   sty $18
  90.   cpx #$26  ; Backspace "key"
  91.   bcc _EnterCharacter
  92.   beq _Backspace
  93.   rts       ; Return if END was selected
  94.             ; Note that there is no check for empty text here
  95.  
  96. ; User chose to end text input
  97. _Backspace:
  98.   lda $17
  99.   bne _DeleteLast
  100.   jmp _GetInput ; Back to input polling if text length is zero
  101.  
  102. _DeleteLast:
  103.   dec $17
  104.   ldy $17
  105.   lda #$FF
  106.   sta $0580,Y
  107.   dec $17
  108.   jmp _DisplayEnteredText
  109.  
  110. ; User pressed "A" on an input character
  111. _EnterCharacter:
  112.   lda $17
  113.   cmp #$05  ; Maximum length
  114.   bne _AddNew
  115.   jmp _GetInput
  116.  
  117. _AddNew:
  118.   lda AlphabetTileIdTbl,X
  119.   ldy $17
  120.   sta $0580,Y
  121.   lda #$FF
  122.   sta $0581,Y
  123.  
  124. _DisplayEnteredText:
  125.   lda #$08
  126.   sta $2A
  127.   lda #$09
  128.   sta $29
  129.   lda #$0A
  130.   sta $2E
  131.   lda #$01
  132.   sta $2D
  133.   lda #$FF
  134.   sta $30
  135.  
  136. ; Save cursor position
  137.   lda $19
  138.   pha
  139.   lda $18
  140.   pha
  141.   lda $17
  142.   pha
  143.  
  144.   jsr DrawTextPreGame
  145.  
  146. ; Restore cursor position
  147.   pla
  148.   sta $17
  149.   pla
  150.   sta $18
  151.   tay
  152.   pla
  153.   sta $19
  154.   tax
  155.   inc $17
  156.   jmp _GetInput
  157.  
  158. ; Index of the next key in the text input panel when moving
  159. ; the cursor up
  160. *=$8822
  161. KeyIndexTbl_Down:
  162. .byte $0A, $0B, $0C, $0D, $0E, $0F, $10, $11
  163. .byte $12, $13, $14, $15, $16, $17, $18, $19
  164. .byte $1A, $1B, $24, $25, $1C, $1D, $1E, $1F
  165. .byte $20, $21, $22, $23, $26, $26, $26, $26
  166. .byte $26, $26, $26, $26, $26, $26, $26, $27
  167.  
  168. ; Index of the next key in the text input panel when moving
  169. ; the cursor down
  170. *=$884A
  171. KeyIndexTbl_Up:
  172. .byte $00, $01, $02, $03, $04, $05, $06, $07
  173. .byte $08, $09, $00, $01, $02, $03, $04, $05
  174. .byte $06, $07, $08, $09, $0A, $0B, $0C, $0D
  175. .byte $0E, $0F, $10, $11, $14, $15, $16, $17
  176. .byte $18, $19, $1A, $1B, $12, $13, $22, $24
  177.  
  178. ; Tile IDs for alphabet letters, used for text input
  179. *=$87FC
  180. AlphabetTileIdTbl:
  181. .byte $8A, $8B, $8C, $8D, $8E, $8F, $90, $91
  182. .byte $92, $93, $94, $95, $96, $97, $98, $99
  183. .byte $9A, $9B, $9C, $9D, $9E, $9F, $A0, $A1
  184. .byte $A2, $A3
  185.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement