| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,261 @@ |
| 1 |
+; Author: Pawel Jablonski |
|
| 2 |
+; E-mail: pj@xirx.net |
|
| 3 |
+; WWW: xirx.net |
|
| 4 |
+; GIT: git.xirx.net |
|
| 5 |
+; |
|
| 6 |
+; License: You can use this code however you like |
|
| 7 |
+; but leave information about the original author. |
|
| 8 |
+; Code is free for non-commercial and commercial use. |
|
| 9 |
+ |
|
| 10 |
+map ../../../bin/rom/rom.map |
|
| 11 |
+ |
|
| 12 |
+; Start message |
|
| 13 |
+const keyHelpHeader "Keymap:" |
|
| 14 |
+ |
|
| 15 |
+; Piano key description |
|
| 16 |
+const keyHelp00 " ! @ $ % ^ * ( " |
|
| 17 |
+const keyHelp01 "c#2 d#2 f#2 g#2 a#2 c#3 d#3 " |
|
| 18 |
+const keyHelp02 " 1 2 3 4 5 6 7 8 9 0 " |
|
| 19 |
+const keyHelp03 "c2 d2 e2 f2 g2 a2 b2 c3 d3 e3 " |
|
| 20 |
+ |
|
| 21 |
+const keyHelp04 " Q W E T Y I O P " |
|
| 22 |
+const keyHelp05 "f#3 g#3 a#3 c#4 d#4 f#4 g#4 a#4" |
|
| 23 |
+const keyHelp06 " q w e r t y u i o p " |
|
| 24 |
+const keyHelp07 "f3 g3 a3 b3 c4 d4 e4 f4 g4 a4 " |
|
| 25 |
+ |
|
| 26 |
+const keyHelp08 " S D G H J L " |
|
| 27 |
+const keyHelp09 " c#5 d#5 f#5 g#5 a#5 c#6 " |
|
| 28 |
+const keyHelp10 " a s d f g h j k l " |
|
| 29 |
+const keyHelp11 "b4 c5 d5 e5 f5 g5 a5 b5 c6 " |
|
| 30 |
+ |
|
| 31 |
+const keyHelp12 " Z C V B " |
|
| 32 |
+const keyHelp13 "d#6 f#6 g#6 a#6 " |
|
| 33 |
+const keyHelp14 " z x c v b n m " |
|
| 34 |
+const keyHelp15 "d6 e6 f6 g6 a6 b6 c7 " |
|
| 35 |
+ |
|
| 36 |
+; Bottom help message |
|
| 37 |
+const keyHelpExit "ESC - Exit +- Duration: " |
|
| 38 |
+const keyHelpClear " " |
|
| 39 |
+const keyHelpMs "0ms" |
|
| 40 |
+ |
|
| 41 |
+; Tone numbers connected to keyboard keys |
|
| 42 |
+const tone2x 0, 17, 0, 0, 22, 24, 0, 0, 31, 0, 29, 0, 0, 0, 0, 0 |
|
| 43 |
+const tone3x 32, 16, 18, 20, 21, 23, 25, 27, 28, 30, 0, 0, 0, 0, 0, 0 |
|
| 44 |
+const tone4x 19, 0, 74, 70, 55, 38, 0, 58, 60, 46, 62, 0, 65, 0, 0, 48 |
|
| 45 |
+const tone5x 50, 34, 0, 53, 41, 0, 72, 36, 0, 43, 67, 0, 0, 0, 26, 0 |
|
| 46 |
+const tone6x 0, 51, 73, 69, 54, 37, 56, 57, 59, 45, 61, 63, 64, 76, 75, 47 |
|
| 47 |
+const tone7x 49, 33, 39, 52, 40, 44, 71, 35, 68, 42, 66, 0, 0, 0, 0, 0 |
|
| 48 |
+ |
|
| 49 |
+; Set tone duration |
|
| 50 |
+var toneDuration |
|
| 51 |
+ |
|
| 52 |
+; First label is the entry point |
|
| 53 |
+.entry: |
|
| 54 |
+ call .main |
|
| 55 |
+ ret |
|
| 56 |
+ |
|
| 57 |
+; No arguments |
|
| 58 |
+; No return |
|
| 59 |
+.main: |
|
| 60 |
+ push A |
|
| 61 |
+ push B |
|
| 62 |
+ ; Set default tone duration |
|
| 63 |
+ str 50, *toneDuration |
|
| 64 |
+ ; Print start messages |
|
| 65 |
+ call .printKeyHelp |
|
| 66 |
+ ; Print current tone duration |
|
| 67 |
+ call .printMs |
|
| 68 |
+ ; Stop playing sounds |
|
| 69 |
+ call .xSpeakerClear |
|
| 70 |
+ ; Set sound values to default |
|
| 71 |
+ mov 8, A |
|
| 72 |
+ call .xSpeakerSetFill |
|
| 73 |
+ mov 15, A |
|
| 74 |
+ call .xSpeakerSetVolume |
|
| 75 |
+.main_loop: |
|
| 76 |
+ call .xKeyboardGetChar |
|
| 77 |
+ ; Exit if clicked key is ESC |
|
| 78 |
+ cmp 0x1b, A |
|
| 79 |
+ je .main_end |
|
| 80 |
+ ; Check for increse tone duration command |
|
| 81 |
+ cmp '=', A |
|
| 82 |
+ je .main_durationPlus |
|
| 83 |
+ cmp '+', A |
|
| 84 |
+ je .main_durationPlus |
|
| 85 |
+ ; Check for decrese tone duration command |
|
| 86 |
+ cmp '-', A |
|
| 87 |
+ je .main_durationMinus |
|
| 88 |
+ cmp '_', A |
|
| 89 |
+ je .main_durationMinus |
|
| 90 |
+ ; Play tone based on clicked key |
|
| 91 |
+ call .playTone |
|
| 92 |
+ jmp .main_loop |
|
| 93 |
+ ; Increse tone duration |
|
| 94 |
+.main_durationPlus: |
|
| 95 |
+ ldr *toneDuration, B |
|
| 96 |
+ cmp 250, B |
|
| 97 |
+ ; 250 <= B |
|
| 98 |
+ jle .main_loop |
|
| 99 |
+ add 5, B |
|
| 100 |
+ str B, *toneDuration |
|
| 101 |
+ ; Print current tone duration |
|
| 102 |
+ call .printMs |
|
| 103 |
+ jmp .main_loop |
|
| 104 |
+ ; Decrese tone duration |
|
| 105 |
+.main_durationMinus: |
|
| 106 |
+ ldr *toneDuration, B |
|
| 107 |
+ cmp 5, B |
|
| 108 |
+ ; 5 >= B |
|
| 109 |
+ jge .main_loop |
|
| 110 |
+ sub 5, B |
|
| 111 |
+ str B, *toneDuration |
|
| 112 |
+ ; Print current tone duration |
|
| 113 |
+ call .printMs |
|
| 114 |
+ jmp .main_loop |
|
| 115 |
+.main_end: |
|
| 116 |
+ pop B |
|
| 117 |
+ pop A |
|
| 118 |
+ ret |
|
| 119 |
+ |
|
| 120 |
+; No arguments |
|
| 121 |
+; No return |
|
| 122 |
+.printKeyHelp: |
|
| 123 |
+ push A |
|
| 124 |
+ push B |
|
| 125 |
+ push X |
|
| 126 |
+ push Y |
|
| 127 |
+ ; Load address to start message |
|
| 128 |
+ mov low(*keyHelpHeader), X |
|
| 129 |
+ mov high(*keyHelpHeader), Y |
|
| 130 |
+ ; Print start message |
|
| 131 |
+ call .xStringPrint |
|
| 132 |
+ call .xStringNewLine |
|
| 133 |
+ ; Load address to |
|
| 134 |
+ mov low(*keyHelp00), X |
|
| 135 |
+ mov high(*keyHelp00), Y |
|
| 136 |
+ ; Reset loop counter |
|
| 137 |
+ clr B |
|
| 138 |
+.printKeyHelp_loop: |
|
| 139 |
+ ; New line |
|
| 140 |
+ call .xStringNewLine |
|
| 141 |
+ ; Check if it is an even or odd line |
|
| 142 |
+ mov B, A |
|
| 143 |
+ and 0x1, A |
|
| 144 |
+ cmp 0x1, A |
|
| 145 |
+ jne .printKeyHelp_loop_white |
|
| 146 |
+ ; Set foregound color to green |
|
| 147 |
+ mov 0x0a, A |
|
| 148 |
+ call .xLcdSetForeground |
|
| 149 |
+ jmp .printKeyHelp_loop_print |
|
| 150 |
+.printKeyHelp_loop_white: |
|
| 151 |
+ ; Set foreground color to default |
|
| 152 |
+ mov 0x0f, A |
|
| 153 |
+ call .xLcdSetForeground |
|
| 154 |
+.printKeyHelp_loop_print: |
|
| 155 |
+ ; Print line |
|
| 156 |
+ call .xStringPrint |
|
| 157 |
+ ; Move address to next line |
|
| 158 |
+ add 40, X |
|
| 159 |
+ incc Y |
|
| 160 |
+ ; Calc keyboard row number |
|
| 161 |
+ mov B, A |
|
| 162 |
+ and 0x3, A |
|
| 163 |
+ cmp 0x3, A |
|
| 164 |
+ jne .printKeyHelp_loop_noNewLine |
|
| 165 |
+ ; New line if it is a keyboard row was printed |
|
| 166 |
+ call .xStringNewLine |
|
| 167 |
+.printKeyHelp_loop_noNewLine: |
|
| 168 |
+ ; Repeat print lines 15+1 times |
|
| 169 |
+ loope 15, B, .printKeyHelp_loop |
|
| 170 |
+ ; Set foreground color to default |
|
| 171 |
+ mov 0x0f, A |
|
| 172 |
+ call .xLcdSetForeground |
|
| 173 |
+ call .xStringNewLine |
|
| 174 |
+ call .xStringNewLine |
|
| 175 |
+ ; Load address to bottom message |
|
| 176 |
+ mov low(*keyHelpExit), X |
|
| 177 |
+ mov high(*keyHelpExit), Y |
|
| 178 |
+ ; Print bottom message |
|
| 179 |
+ call .xStringPrint |
|
| 180 |
+ ; Refresh the screen |
|
| 181 |
+ call .xLcdRefresh |
|
| 182 |
+ pop Y |
|
| 183 |
+ pop X |
|
| 184 |
+ pop B |
|
| 185 |
+ pop A |
|
| 186 |
+ ret |
|
| 187 |
+ |
|
| 188 |
+; No arguments |
|
| 189 |
+; No return |
|
| 190 |
+.printMs: |
|
| 191 |
+ push A |
|
| 192 |
+ push X |
|
| 193 |
+ push Y |
|
| 194 |
+ ; Move print start at begin of the tone duration field |
|
| 195 |
+ mov 34, A |
|
| 196 |
+ call .xStringSetCursorX |
|
| 197 |
+ ; Load address to empty value |
|
| 198 |
+ mov low(*keyHelpClear), X |
|
| 199 |
+ mov high(*keyHelpClear), Y |
|
| 200 |
+ ; Clear field by empty value |
|
| 201 |
+ call .xStringPrint |
|
| 202 |
+ ; Move print start at begin of the tone duration field |
|
| 203 |
+ call .xStringSetCursorX |
|
| 204 |
+ ; Load tone duration |
|
| 205 |
+ ldr *toneDuration, A |
|
| 206 |
+ ; Print new tone duration |
|
| 207 |
+ call .xStringPrintU8 |
|
| 208 |
+ ; Load address to second part of tone duration string |
|
| 209 |
+ mov low(*keyHelpMs), X |
|
| 210 |
+ mov high(*keyHelpMs), Y |
|
| 211 |
+ ; Print second part of tone duration string |
|
| 212 |
+ call .xStringPrint |
|
| 213 |
+ ; Refresh the screen |
|
| 214 |
+ call .xLcdRefresh |
|
| 215 |
+ pop Y |
|
| 216 |
+ pop X |
|
| 217 |
+ pop A |
|
| 218 |
+ ret |
|
| 219 |
+ |
|
| 220 |
+; Arguments |
|
| 221 |
+; A - keyboard key |
|
| 222 |
+; No return |
|
| 223 |
+.playTone: |
|
| 224 |
+ push A |
|
| 225 |
+ push X |
|
| 226 |
+ push Y |
|
| 227 |
+ ; Make sure the key is beetwen 0x20 and 0x7f |
|
| 228 |
+ cmp 0x20, A |
|
| 229 |
+ ; 0x20 > A |
|
| 230 |
+ jg .playTone_end |
|
| 231 |
+ cmp 0x7f, A |
|
| 232 |
+ ; 0x7f < A |
|
| 233 |
+ jl .playTone_end |
|
| 234 |
+ ; Make offset |
|
| 235 |
+ sub 0x20, A |
|
| 236 |
+ ; Load address to tone table |
|
| 237 |
+ mov low(*tone2x), X |
|
| 238 |
+ mov high(*tone2x), Y |
|
| 239 |
+ ; Add offset to tone |
|
| 240 |
+ add A, X |
|
| 241 |
+ incc Y |
|
| 242 |
+ ; Load tone number |
|
| 243 |
+ ldr A |
|
| 244 |
+ ; Do not play empty tone |
|
| 245 |
+ cmp 0, A |
|
| 246 |
+ ; 0 == A |
|
| 247 |
+ je .playTone_end |
|
| 248 |
+ call .xSpeakerSetNote |
|
| 249 |
+ ; Load tone duration |
|
| 250 |
+ ldr *toneDuration, A |
|
| 251 |
+ ; Write tone duration |
|
| 252 |
+ call .xSpeakerSetTime |
|
| 253 |
+ ; Stop playing sounds |
|
| 254 |
+ call .xSpeakerClear |
|
| 255 |
+ ; Add and play tone from buffer |
|
| 256 |
+ call .xSpeakerAddNote |
|
| 257 |
+.playTone_end: |
|
| 258 |
+ pop Y |
|
| 259 |
+ pop X |
|
| 260 |
+ pop A |
|
| 261 |
+ ret |