Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. ; this program takes input from the user and prints it back out after hitting enter
  2.  
  3. .text
  4. .reset $0200
  5. .org $0200
  6.  
  7. ; X for print offset
  8. ; $00 for locking key input to prevent spam
  9. ; $01 for name length
  10.  
  11. Start:
  12. LDA Intro,X
  13. CMP #$00
  14. BEQ Scan
  15. STA $A000,X
  16. INX
  17. JMP Start
  18.  
  19. Scan:
  20. LDA #'_' ; print underscore
  21. STA $A000,X
  22. LDA $9FFF ; read keyboard input, go to subroutines
  23. CMP #$0D
  24. BEQ Enter
  25. CMP #$08
  26. BEQ Back
  27. CMP #$00
  28. BEQ Rels
  29. JMP PrLett
  30.  
  31. Rels:
  32. LDY #$00 ; release key
  33. STY $00
  34. JMP Scan
  35.  
  36. Back:
  37. LDY $00 ; if locked (currently holding key), return
  38. CPY #$01
  39. BEQ Scan
  40. LDY $01 ; if already 0 characters, return
  41. CPY #$00
  42. BEQ Scan
  43. INC $00 ; lock input
  44. LDA #$00 ; blank last character, decrement length and offset
  45. STA $A000,X
  46. ;LDY $01
  47. ;STA $A000,Y
  48. DEX
  49. DEC $01
  50. JMP Scan
  51.  
  52. PrLett:
  53. LDY $00
  54. CPY #$01
  55. BEQ Scan
  56. INC $00 ; lock input
  57. LDY $01 ; if already 6 characters long, return
  58. CPY #$06
  59. BEQ Scan
  60. STA $A000,X
  61. INX
  62. LDY $01
  63. STA Name,Y
  64. INC $01
  65. JMP Scan
  66.  
  67. Enter:
  68. LDX #$00
  69. LDY #$00
  70. STY $00 ; repurpose $00 for offset in name in PrName
  71. PrOut:
  72. LDA Outro,Y
  73. CMP #$00
  74. BEQ PrName
  75. STA $A023,X
  76. INX
  77. INY
  78. JMP PrOut
  79.  
  80. PrName:
  81. LDY $00
  82. LDA Name,Y
  83. CMP #$00
  84. BEQ End
  85. STA $A023,X
  86. INX
  87. INC $00
  88. JMP PrName
  89.  
  90. End: HLT
  91.  
  92. ; program data
  93. .org $2000
  94. Intro:
  95. .db "Name:", $00
  96. Outro:
  97. .db "Your name is ", $00
  98.  
  99. ; dummy label for placing input
  100. .org $3000
  101. Name:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement