| ... | ... |
@@ -77,6 +77,30 @@ external .xStringGetCursorX: |
| 77 | 77 |
ldr *xStringCursorX, A |
| 78 | 78 |
ret |
| 79 | 79 |
|
| 80 |
+; Arguments: |
|
| 81 |
+; A - row |
|
| 82 |
+; No return |
|
| 83 |
+external .xStringSetCursorY: |
|
| 84 |
+ push X |
|
| 85 |
+ push Y |
|
| 86 |
+ ; Write new row position to set |
|
| 87 |
+ mov A, Y |
|
| 88 |
+ ; Read current column position to set |
|
| 89 |
+ ldr *xStringCursorX, X |
|
| 90 |
+ ; Set new row position and leave column position |
|
| 91 |
+ call .xStringSetCursor |
|
| 92 |
+ pop Y |
|
| 93 |
+ pop X |
|
| 94 |
+ ret |
|
| 95 |
+ |
|
| 96 |
+; No arguments |
|
| 97 |
+; Return: |
|
| 98 |
+; A - row |
|
| 99 |
+external .xStringGetCursorY: |
|
| 100 |
+ ; Get current row position |
|
| 101 |
+ ldr *xStringCursorY, A |
|
| 102 |
+ ret |
|
| 103 |
+ |
|
| 80 | 104 |
; No arguments |
| 81 | 105 |
; No return |
| 82 | 106 |
external .xStringNewLine: |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,601 @@ |
| 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 |
+include lcd.asm |
|
| 11 |
+include keyboard.asm |
|
| 12 |
+ |
|
| 13 |
+; Current cursor position |
|
| 14 |
+var xStringCursorX |
|
| 15 |
+var xStringCursorY |
|
| 16 |
+ |
|
| 17 |
+; No arguments |
|
| 18 |
+; No return |
|
| 19 |
+global .xStringInit: |
|
| 20 |
+ push A |
|
| 21 |
+ ; Reset cursor position |
|
| 22 |
+ mov 0, A |
|
| 23 |
+ str A, *xStringCursorX |
|
| 24 |
+ str A, *xStringCursorY |
|
| 25 |
+ pop A |
|
| 26 |
+ ret |
|
| 27 |
+ |
|
| 28 |
+; Arguments: |
|
| 29 |
+; X - column |
|
| 30 |
+; Y - row |
|
| 31 |
+; No return |
|
| 32 |
+external .xStringSetCursor: |
|
| 33 |
+ push X |
|
| 34 |
+ push Y |
|
| 35 |
+ ; Check maximum column |
|
| 36 |
+ ; 40 >= X |
|
| 37 |
+ cmp 40, X |
|
| 38 |
+ jge .xStringSetCursor_x_ok |
|
| 39 |
+ ; Value is too high, set default |
|
| 40 |
+ mov 0, X |
|
| 41 |
+.xStringSetCursor_x_ok: |
|
| 42 |
+ ; Check maximum row |
|
| 43 |
+ ; 30 > Y |
|
| 44 |
+ cmp 30, Y |
|
| 45 |
+ jg .xStringSetCursor_y_ok |
|
| 46 |
+ ; Value is too high, set default |
|
| 47 |
+ mov 0, Y |
|
| 48 |
+.xStringSetCursor_y_ok: |
|
| 49 |
+ ; Save new cursor position |
|
| 50 |
+ str X, *xStringCursorX |
|
| 51 |
+ str Y, *xStringCursorY |
|
| 52 |
+ pop Y |
|
| 53 |
+ pop X |
|
| 54 |
+ ret |
|
| 55 |
+ |
|
| 56 |
+; Arguments: |
|
| 57 |
+; A - column |
|
| 58 |
+; No return |
|
| 59 |
+external .xStringSetCursorX: |
|
| 60 |
+ push X |
|
| 61 |
+ push Y |
|
| 62 |
+ ; Write new column position to set |
|
| 63 |
+ mov A, X |
|
| 64 |
+ ; Read current row position to set |
|
| 65 |
+ ldr *xStringCursorY, Y |
|
| 66 |
+ ; Set new column position and leave row position |
|
| 67 |
+ call .xStringSetCursor |
|
| 68 |
+ pop Y |
|
| 69 |
+ pop X |
|
| 70 |
+ ret |
|
| 71 |
+ |
|
| 72 |
+; No arguments |
|
| 73 |
+; Return: |
|
| 74 |
+; A - column |
|
| 75 |
+external .xStringGetCursorX: |
|
| 76 |
+ ; Get current column position |
|
| 77 |
+ ldr *xStringCursorX, A |
|
| 78 |
+ ret |
|
| 79 |
+ |
|
| 80 |
+; No arguments |
|
| 81 |
+; No return |
|
| 82 |
+external .xStringNewLine: |
|
| 83 |
+ push A |
|
| 84 |
+ ; Set cursor at begin of line |
|
| 85 |
+ mov 0, A |
|
| 86 |
+ str A, *xStringCursorX |
|
| 87 |
+ ; Set cursor at next line |
|
| 88 |
+ ldr *xStringCursorY, A |
|
| 89 |
+ inc A |
|
| 90 |
+ ; Check if scrolling is needed |
|
| 91 |
+ ; 30 > A |
|
| 92 |
+ cmp 30, A |
|
| 93 |
+ jg .xStringNewLine_no_scroll |
|
| 94 |
+ ; Scroll and update cursor row |
|
| 95 |
+ call .xLcdScroll |
|
| 96 |
+ mov 29, A |
|
| 97 |
+.xStringNewLine_no_scroll: |
|
| 98 |
+ str A, *xStringCursorY |
|
| 99 |
+ pop A |
|
| 100 |
+ ret |
|
| 101 |
+ |
|
| 102 |
+; Arguments: |
|
| 103 |
+; A - char to print |
|
| 104 |
+; No return |
|
| 105 |
+external .xStringPrintChar: |
|
| 106 |
+ push A |
|
| 107 |
+ push B |
|
| 108 |
+ ; Select low address register |
|
| 109 |
+ mov 2, A |
|
| 110 |
+ call .xIOSetRegister |
|
| 111 |
+ ldr *xStringCursorX, A |
|
| 112 |
+ mov 0, B |
|
| 113 |
+ ; Check maximum column |
|
| 114 |
+ ; 40 > A |
|
| 115 |
+ cmp 40, A |
|
| 116 |
+ jg .xStringPrintChar_x_ok |
|
| 117 |
+ ; Set cursor at begin of line |
|
| 118 |
+ mov 0, A |
|
| 119 |
+ ; Scrolling is needed |
|
| 120 |
+ mov 1, B |
|
| 121 |
+.xStringPrintChar_x_ok: |
|
| 122 |
+ call .xIOWrite |
|
| 123 |
+ inc A |
|
| 124 |
+ str A, *xStringCursorX |
|
| 125 |
+ ldr *xStringCursorY, A |
|
| 126 |
+ ; Check if scrolling is needed |
|
| 127 |
+ ; 1 != B |
|
| 128 |
+ cmp 1, B |
|
| 129 |
+ jne .xStringPrintChar_y_ok |
|
| 130 |
+ inc A |
|
| 131 |
+ ; Check maximum row |
|
| 132 |
+ ; 30 > A |
|
| 133 |
+ cmp 30, A |
|
| 134 |
+ jg .xStringPrintChar_no_scroll |
|
| 135 |
+ ; Scroll and update cursor row |
|
| 136 |
+ call .xLcdScroll |
|
| 137 |
+ mov 29, A |
|
| 138 |
+.xStringPrintChar_no_scroll: |
|
| 139 |
+ str A, *xStringCursorY |
|
| 140 |
+.xStringPrintChar_y_ok: |
|
| 141 |
+ mov 3, A |
|
| 142 |
+ ; Select high address register |
|
| 143 |
+ call .xIOSetRegister |
|
| 144 |
+ ldr *xStringCursorY, A |
|
| 145 |
+ call .xIOWrite |
|
| 146 |
+ pop B |
|
| 147 |
+ pop A |
|
| 148 |
+ call .xLcdSetChar |
|
| 149 |
+ ret |
|
| 150 |
+ |
|
| 151 |
+; Arguments: |
|
| 152 |
+; X - low address |
|
| 153 |
+; Y - high address |
|
| 154 |
+; No return |
|
| 155 |
+global .xStringPrintRom: |
|
| 156 |
+ push X |
|
| 157 |
+ push Y |
|
| 158 |
+ push A |
|
| 159 |
+.xStringPrintRom_loop: |
|
| 160 |
+ ; Load char from ROM |
|
| 161 |
+ ldf A |
|
| 162 |
+ ; Check if it is end of string |
|
| 163 |
+ cmp 0, A |
|
| 164 |
+ je .xStringPrintRom_end |
|
| 165 |
+ ; Print char |
|
| 166 |
+ call .xStringPrintChar |
|
| 167 |
+ ; Incrementing address |
|
| 168 |
+ inc X |
|
| 169 |
+ incc Y |
|
| 170 |
+ jmp .xStringPrintRom_loop |
|
| 171 |
+.xStringPrintRom_end: |
|
| 172 |
+ pop A |
|
| 173 |
+ pop Y |
|
| 174 |
+ pop X |
|
| 175 |
+ ret |
|
| 176 |
+ |
|
| 177 |
+; Arguments: |
|
| 178 |
+; X - low address |
|
| 179 |
+; Y - high address |
|
| 180 |
+; No return |
|
| 181 |
+external .xStringPrint: |
|
| 182 |
+ push X |
|
| 183 |
+ push Y |
|
| 184 |
+ push A |
|
| 185 |
+.xStringPrint_loop: |
|
| 186 |
+ ; Load char from RAM |
|
| 187 |
+ ldr A |
|
| 188 |
+ ; Check if it is end of string |
|
| 189 |
+ cmp 0, A |
|
| 190 |
+ je .xStringPrint_end |
|
| 191 |
+ ; Print char |
|
| 192 |
+ call .xStringPrintChar |
|
| 193 |
+ ; Incrementing address |
|
| 194 |
+ inc X |
|
| 195 |
+ incc Y |
|
| 196 |
+ jmp .xStringPrint_loop |
|
| 197 |
+.xStringPrint_end: |
|
| 198 |
+ pop A |
|
| 199 |
+ pop Y |
|
| 200 |
+ pop X |
|
| 201 |
+ ret |
|
| 202 |
+ |
|
| 203 |
+; Multiplier values |
|
| 204 |
+const u8toDecTable 100, 10, 1 |
|
| 205 |
+ |
|
| 206 |
+; Current multiplier value |
|
| 207 |
+var u8toDec |
|
| 208 |
+ |
|
| 209 |
+; Current working value |
|
| 210 |
+var u8Value |
|
| 211 |
+ |
|
| 212 |
+; Allow print digits flag |
|
| 213 |
+var u8LetPrint |
|
| 214 |
+ |
|
| 215 |
+; Arguments: |
|
| 216 |
+; A - value |
|
| 217 |
+; No return |
|
| 218 |
+external .xStringPrintU8: |
|
| 219 |
+ push A |
|
| 220 |
+ push B |
|
| 221 |
+ push X |
|
| 222 |
+ push Y |
|
| 223 |
+ ; Set local variables |
|
| 224 |
+ str A, *u8Value |
|
| 225 |
+ str 0, *u8LetPrint |
|
| 226 |
+ ; Reset loop counter |
|
| 227 |
+ clr B |
|
| 228 |
+ ; Print every digit in one execution of loop |
|
| 229 |
+.xStringPrintU8_loop: |
|
| 230 |
+ ; Load address to multiplier table |
|
| 231 |
+ mov low(*u8toDecTable), X |
|
| 232 |
+ mov high(*u8toDecTable), Y |
|
| 233 |
+ ; Move address to current multipier |
|
| 234 |
+ add B, X |
|
| 235 |
+ incc Y |
|
| 236 |
+ ; Load multiplier |
|
| 237 |
+ ldf A |
|
| 238 |
+ ; Store multiplier in temporary variable |
|
| 239 |
+ str A, *u8toDec |
|
| 240 |
+ ; Save to stack main loop counter |
|
| 241 |
+ push B |
|
| 242 |
+ ; Load current working value |
|
| 243 |
+ ldr *u8Value, X |
|
| 244 |
+ ; Reset loop counter |
|
| 245 |
+ clr B |
|
| 246 |
+ ; Convert hex to dec using multiplier |
|
| 247 |
+.xStringPrintU8_minusLoop: |
|
| 248 |
+ ; Load multiplier |
|
| 249 |
+ ldr *u8toDec, A |
|
| 250 |
+ ; Try substract |
|
| 251 |
+ sub A, X |
|
| 252 |
+ ldr *u8Value, A |
|
| 253 |
+ cmp A, X |
|
| 254 |
+ ; A < X |
|
| 255 |
+ jl .xStringPrintU8_minusLoopEnd |
|
| 256 |
+ str X, *u8Value |
|
| 257 |
+ ; Increment try counter |
|
| 258 |
+ inc B |
|
| 259 |
+ jmp .xStringPrintU8_minusLoop |
|
| 260 |
+ ; End of substracting loop |
|
| 261 |
+.xStringPrintU8_minusLoopEnd: |
|
| 262 |
+ ; Load let print flag |
|
| 263 |
+ ldr *u8LetPrint, A |
|
| 264 |
+ cmp 0, A |
|
| 265 |
+ jne .xStringPrintU8_minusPrint |
|
| 266 |
+ cmp 0, B |
|
| 267 |
+ je .xStringPrintU8_minusDontPrint |
|
| 268 |
+ ; Set true to let print flag |
|
| 269 |
+ str 1, *u8LetPrint |
|
| 270 |
+ ; Print digit |
|
| 271 |
+.xStringPrintU8_minusPrint: |
|
| 272 |
+ ; Load digit to print |
|
| 273 |
+ mov B, A |
|
| 274 |
+ ; Convert to ASCII char |
|
| 275 |
+ add '0', A |
|
| 276 |
+ ; Print char |
|
| 277 |
+ call .xStringPrintChar |
|
| 278 |
+ ; Do not print zeros at begin |
|
| 279 |
+.xStringPrintU8_minusDontPrint: |
|
| 280 |
+ ; Get back counter value of main loop |
|
| 281 |
+ pop B |
|
| 282 |
+ ; Execute loop only 2+1 times |
|
| 283 |
+ loope 2, B, .xStringPrintU8_loop |
|
| 284 |
+ ; Check if nothing was printed |
|
| 285 |
+ ldr *u8LetPrint, A |
|
| 286 |
+ cmp 0, A |
|
| 287 |
+ jne .xStringPrintU8_dontPrintZero |
|
| 288 |
+ ; It needs to print zero if nothing was printed before |
|
| 289 |
+ mov '0', A |
|
| 290 |
+ call .xStringPrintChar |
|
| 291 |
+.xStringPrintU8_dontPrintZero: |
|
| 292 |
+ pop Y |
|
| 293 |
+ pop X |
|
| 294 |
+ pop B |
|
| 295 |
+ pop A |
|
| 296 |
+ ret |
|
| 297 |
+ |
|
| 298 |
+; Multiplier values |
|
| 299 |
+const u16toDecTableLow 0x10, 0xe8, 0x64, 0x0a, 0x01 |
|
| 300 |
+const u16toDecTableHigh 0x27, 0x03, 0x00, 0x00, 0x00 |
|
| 301 |
+ |
|
| 302 |
+; Current multiplier value |
|
| 303 |
+var u16toDecLow |
|
| 304 |
+var u16toDecHigh |
|
| 305 |
+ |
|
| 306 |
+; Current working value |
|
| 307 |
+var u16ValueLow |
|
| 308 |
+var u16ValueHigh |
|
| 309 |
+ |
|
| 310 |
+; Allow print digits flag |
|
| 311 |
+var u16LetPrint |
|
| 312 |
+ |
|
| 313 |
+; Arguments: |
|
| 314 |
+; A - low value |
|
| 315 |
+; B - high value |
|
| 316 |
+; No return |
|
| 317 |
+external .xStringPrintU16: |
|
| 318 |
+ push A |
|
| 319 |
+ push B |
|
| 320 |
+ push X |
|
| 321 |
+ push Y |
|
| 322 |
+ ; Set local variables |
|
| 323 |
+ str A, *u16ValueLow |
|
| 324 |
+ str B, *u16ValueHigh |
|
| 325 |
+ str 0, *u16LetPrint |
|
| 326 |
+ ; Reset loop counter |
|
| 327 |
+ clr B |
|
| 328 |
+.xStringPrintU16_loop: |
|
| 329 |
+ ; Load address to multiplier low table |
|
| 330 |
+ mov low(*u16toDecTableLow), X |
|
| 331 |
+ mov high(*u16toDecTableLow), Y |
|
| 332 |
+ ; Move address to current multipier low |
|
| 333 |
+ add B, X |
|
| 334 |
+ incc Y |
|
| 335 |
+ ; Load multiplier low |
|
| 336 |
+ ldf A |
|
| 337 |
+ ; Store multiplier low in temporary variable |
|
| 338 |
+ str A, *u16toDecLow |
|
| 339 |
+ ; Load address to multiplier high table |
|
| 340 |
+ mov low(*u16toDecTableHigh), X |
|
| 341 |
+ mov high(*u16toDecTableHigh), Y |
|
| 342 |
+ ; Move address to current multipier high |
|
| 343 |
+ add B, X |
|
| 344 |
+ incc Y |
|
| 345 |
+ ; Load multiplier high |
|
| 346 |
+ ldf A |
|
| 347 |
+ ; Store multiplier high in temporary variable |
|
| 348 |
+ str A, *u16toDecHigh |
|
| 349 |
+ ; Save to stack main loop counter |
|
| 350 |
+ push B |
|
| 351 |
+ ; Load current working values |
|
| 352 |
+ ldr *u16ValueLow, X |
|
| 353 |
+ ldr *u16ValueHigh, Y |
|
| 354 |
+ ; Reset loop counter |
|
| 355 |
+ clr B |
|
| 356 |
+ ; Convert hex to dec using multiplier |
|
| 357 |
+.xStringPrintU16_minusLoop: |
|
| 358 |
+ ; Load multiplier low |
|
| 359 |
+ ldr *u16toDecLow, A |
|
| 360 |
+ ; Try substract low |
|
| 361 |
+ sub A, X |
|
| 362 |
+ ; Load multiplier high |
|
| 363 |
+ ldr *u16toDecHigh, A |
|
| 364 |
+ ; Try substract high |
|
| 365 |
+ subc A, Y |
|
| 366 |
+ ldr *u16ValueHigh, A |
|
| 367 |
+ cmp A, Y |
|
| 368 |
+ ; A < Y |
|
| 369 |
+ jl .xStringPrintU16_minusLoopEnd |
|
| 370 |
+ str X, *u16ValueLow |
|
| 371 |
+ str Y, *u16ValueHigh |
|
| 372 |
+ ; Increment try counter |
|
| 373 |
+ inc B |
|
| 374 |
+ jmp .xStringPrintU16_minusLoop |
|
| 375 |
+ ; End of substracting loop |
|
| 376 |
+.xStringPrintU16_minusLoopEnd: |
|
| 377 |
+ ; Load let print flag |
|
| 378 |
+ ldr *u16LetPrint, A |
|
| 379 |
+ cmp 0, A |
|
| 380 |
+ jne .xStringPrintU16_minusPrint |
|
| 381 |
+ cmp 0, B |
|
| 382 |
+ je .xStringPrintU16_minusDontPrint |
|
| 383 |
+ ; Set true to let print flag |
|
| 384 |
+ str 1, *u16LetPrint |
|
| 385 |
+ ; Print digit |
|
| 386 |
+.xStringPrintU16_minusPrint: |
|
| 387 |
+ ; Load digit to print |
|
| 388 |
+ mov B, A |
|
| 389 |
+ ; Convert to ASCII char |
|
| 390 |
+ add '0', A |
|
| 391 |
+ ; Print char |
|
| 392 |
+ call .xStringPrintChar |
|
| 393 |
+ ; Do not print zeros at begin |
|
| 394 |
+.xStringPrintU16_minusDontPrint: |
|
| 395 |
+ ; Get back counter value of main loop |
|
| 396 |
+ pop B |
|
| 397 |
+ ; Execute loop only 4+1 times |
|
| 398 |
+ loope 4, B, .xStringPrintU16_loop |
|
| 399 |
+ ; Check if nothing was printed |
|
| 400 |
+ ldr *u16LetPrint, A |
|
| 401 |
+ cmp 0, A |
|
| 402 |
+ jne .xStringPrintU16_dontPrintZero |
|
| 403 |
+ ; It needs to print zero if nothing was printed before |
|
| 404 |
+ mov '0', A |
|
| 405 |
+ call .xStringPrintChar |
|
| 406 |
+.xStringPrintU16_dontPrintZero: |
|
| 407 |
+ pop Y |
|
| 408 |
+ pop X |
|
| 409 |
+ pop B |
|
| 410 |
+ pop A |
|
| 411 |
+ ret |
|
| 412 |
+ |
|
| 413 |
+; No arguments |
|
| 414 |
+; No return |
|
| 415 |
+.xStringReadBackspace: |
|
| 416 |
+ push A |
|
| 417 |
+ push X |
|
| 418 |
+ push Y |
|
| 419 |
+ ; Load cursor position |
|
| 420 |
+ ldr *xStringCursorX, X |
|
| 421 |
+ ldr *xStringCursorY, Y |
|
| 422 |
+ ; Erasing last char |
|
| 423 |
+ mov 0x00, A |
|
| 424 |
+ call .xStringPrintChar |
|
| 425 |
+ ; Move left cursor |
|
| 426 |
+ dec X |
|
| 427 |
+ ; Save cursor position |
|
| 428 |
+ str X, *xStringCursorX |
|
| 429 |
+ str Y, *xStringCursorY |
|
| 430 |
+ pop Y |
|
| 431 |
+ pop X |
|
| 432 |
+ pop A |
|
| 433 |
+ ret |
|
| 434 |
+ |
|
| 435 |
+; No arguments |
|
| 436 |
+; No return |
|
| 437 |
+.xStringReadShowPrompt: |
|
| 438 |
+ push A |
|
| 439 |
+ push X |
|
| 440 |
+ push Y |
|
| 441 |
+ ; Load cursor position |
|
| 442 |
+ ldr *xStringCursorX, X |
|
| 443 |
+ ldr *xStringCursorY, Y |
|
| 444 |
+ ; Print cursor |
|
| 445 |
+ mov 0xDB, A |
|
| 446 |
+ call .xStringPrintChar |
|
| 447 |
+ ; Save cursor position |
|
| 448 |
+ str X, *xStringCursorX |
|
| 449 |
+ str Y, *xStringCursorY |
|
| 450 |
+ pop Y |
|
| 451 |
+ pop X |
|
| 452 |
+ pop A |
|
| 453 |
+ ret |
|
| 454 |
+ |
|
| 455 |
+; Arguments: |
|
| 456 |
+; A - buffer length |
|
| 457 |
+; X - low address |
|
| 458 |
+; Y - high address |
|
| 459 |
+; No return |
|
| 460 |
+external .xStringRead: |
|
| 461 |
+ ; Push registers to stack |
|
| 462 |
+ push A |
|
| 463 |
+ push B |
|
| 464 |
+ push X |
|
| 465 |
+ push Y |
|
| 466 |
+ mov A, B |
|
| 467 |
+ call .xStringReadShowPrompt |
|
| 468 |
+ call .xLcdRefresh |
|
| 469 |
+.xStringRead_loop: |
|
| 470 |
+ ; Push buffer length |
|
| 471 |
+ push A |
|
| 472 |
+ call .xKeyboardGetChar |
|
| 473 |
+ ; Check for backspace |
|
| 474 |
+ cmp 0x08, A |
|
| 475 |
+ je .xStringRead_backspace |
|
| 476 |
+ ; Check for enter |
|
| 477 |
+ cmp 0x0d, A |
|
| 478 |
+ je .xStringRead_enter |
|
| 479 |
+ ; Check for not printable char |
|
| 480 |
+ ; 0x20 > A |
|
| 481 |
+ cmp 0x20, A |
|
| 482 |
+ jg .xStringRead_not_print |
|
| 483 |
+ ; 0x80 <= A |
|
| 484 |
+ cmp 0x80, A |
|
| 485 |
+ jle .xStringRead_not_print |
|
| 486 |
+ ; Respect buffer size limit |
|
| 487 |
+ ; 1 >= B |
|
| 488 |
+ cmp 1, B |
|
| 489 |
+ jge .xStringRead_not_print |
|
| 490 |
+ dec B |
|
| 491 |
+ ; Print readed char |
|
| 492 |
+ call .xStringPrintChar |
|
| 493 |
+ call .xStringReadShowPrompt |
|
| 494 |
+ call .xLcdRefresh |
|
| 495 |
+ ; Save char to buffer |
|
| 496 |
+ str A |
|
| 497 |
+ ; Incrementing address |
|
| 498 |
+ inc X |
|
| 499 |
+ incc Y |
|
| 500 |
+ ; Pop buffer length |
|
| 501 |
+ pop A |
|
| 502 |
+ jmp .xStringRead_loop |
|
| 503 |
+.xStringRead_not_print: |
|
| 504 |
+ ; Pop buffer length |
|
| 505 |
+ pop A |
|
| 506 |
+ jmp .xStringRead_loop |
|
| 507 |
+.xStringRead_backspace: |
|
| 508 |
+ ; Pop buffer length |
|
| 509 |
+ pop A |
|
| 510 |
+ ; Do not go back too far |
|
| 511 |
+ cmp A, B |
|
| 512 |
+ je .xStringRead_loop |
|
| 513 |
+ inc B |
|
| 514 |
+ ; Decrementing address |
|
| 515 |
+ dec X |
|
| 516 |
+ decc Y |
|
| 517 |
+ ; Moving back prompt |
|
| 518 |
+ call .xStringReadBackspace |
|
| 519 |
+ call .xStringReadShowPrompt |
|
| 520 |
+ call .xLcdRefresh |
|
| 521 |
+ jmp .xStringRead_loop |
|
| 522 |
+.xStringRead_enter: |
|
| 523 |
+ ; Pop buffer length |
|
| 524 |
+ pop A |
|
| 525 |
+ ; Add null terminator to buffer |
|
| 526 |
+ str 0x00 |
|
| 527 |
+ ; Pop from stack |
|
| 528 |
+ pop Y |
|
| 529 |
+ pop X |
|
| 530 |
+ pop B |
|
| 531 |
+ pop A |
|
| 532 |
+ ret |
|
| 533 |
+ |
|
| 534 |
+; Arguments: |
|
| 535 |
+; X - low address |
|
| 536 |
+; Y - high address |
|
| 537 |
+; Return: |
|
| 538 |
+; A - length |
|
| 539 |
+external .xStringLength: |
|
| 540 |
+ push X |
|
| 541 |
+ push Y |
|
| 542 |
+ push B |
|
| 543 |
+ mov 0, A |
|
| 544 |
+.xStringLength_loop: |
|
| 545 |
+ ldr B |
|
| 546 |
+ ; 0 == B |
|
| 547 |
+ cmp 0, B |
|
| 548 |
+ ; End of string found |
|
| 549 |
+ je .xStringLength_end |
|
| 550 |
+ ; Increment the string pointer |
|
| 551 |
+ inc X |
|
| 552 |
+ incc Y |
|
| 553 |
+ ; Increment string length |
|
| 554 |
+ inc A |
|
| 555 |
+ jmp .xStringLength_loop |
|
| 556 |
+.xStringLength_end: |
|
| 557 |
+ pop B |
|
| 558 |
+ pop Y |
|
| 559 |
+ pop X |
|
| 560 |
+ ret |
|
| 561 |
+ |
|
| 562 |
+var charToFind |
|
| 563 |
+ |
|
| 564 |
+; Arguments: |
|
| 565 |
+; A - char to find |
|
| 566 |
+; X - low address |
|
| 567 |
+; Y - high address |
|
| 568 |
+; Return: |
|
| 569 |
+; A - offset |
|
| 570 |
+external .xStringFind: |
|
| 571 |
+ push X |
|
| 572 |
+ push Y |
|
| 573 |
+ push B |
|
| 574 |
+ str A, *charToFind |
|
| 575 |
+ mov 0, A |
|
| 576 |
+.xStringFind_loop: |
|
| 577 |
+ push A |
|
| 578 |
+ ldr *charToFind, A |
|
| 579 |
+ ldr B |
|
| 580 |
+ ; A == B |
|
| 581 |
+ cmp A, B |
|
| 582 |
+ pop A |
|
| 583 |
+ ; Char found |
|
| 584 |
+ je .xStringFind_end |
|
| 585 |
+ ; 0 == B |
|
| 586 |
+ cmp 0, B |
|
| 587 |
+ ; End of string found |
|
| 588 |
+ je .xStringFind_stringEnded |
|
| 589 |
+ ; Increment the string pointer |
|
| 590 |
+ inc X |
|
| 591 |
+ incc Y |
|
| 592 |
+ ; Increment string length |
|
| 593 |
+ inc A |
|
| 594 |
+ jmp .xStringFind_loop |
|
| 595 |
+.xStringFind_stringEnded: |
|
| 596 |
+ mov 0, A |
|
| 597 |
+.xStringFind_end: |
|
| 598 |
+ pop B |
|
| 599 |
+ pop Y |
|
| 600 |
+ pop X |
|
| 601 |
+ ret |