| ... | ... |
@@ -125,9 +125,14 @@ const messageFreeRam "28K Data memory free" |
| 125 | 125 |
.xTerminalGetCommand: |
| 126 | 126 |
; Reset color |
| 127 | 127 |
call .xTerminalColorReset |
| 128 |
- ; Show command line |
|
| 128 |
+ ; Do not make a new line if the cursor is at beginning |
|
| 129 |
+ call .xStringGetCursorY |
|
| 130 |
+ cmp 0, A |
|
| 131 |
+ je .xTerminalGetCommand_no_newLine |
|
| 129 | 132 |
call .xStringNewLine |
| 130 | 133 |
call .xStringNewLine |
| 134 |
+.xTerminalGetCommand_no_newLine: |
|
| 135 |
+ ; Show command line |
|
| 131 | 136 |
mov '>', A |
| 132 | 137 |
call .xStringPrintChar |
| 133 | 138 |
call .xLcdRefresh |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,303 @@ |
| 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 string.asm |
|
| 12 |
+include speaker.asm |
|
| 13 |
+include fs.asm |
|
| 14 |
+ |
|
| 15 |
+; Command buffer |
|
| 16 |
+var commandBuffer[39] |
|
| 17 |
+ |
|
| 18 |
+; No arguments |
|
| 19 |
+; No return |
|
| 20 |
+global .xTerminal: |
|
| 21 |
+ ; Reset |
|
| 22 |
+ call .xTerminalReset |
|
| 23 |
+ ; Print start message |
|
| 24 |
+ call .xTerminalStartMessage |
|
| 25 |
+ ; Play start sound |
|
| 26 |
+ call .xTerminalStartSound |
|
| 27 |
+ ; Refresh screen |
|
| 28 |
+ call .xLcdRefresh |
|
| 29 |
+ |
|
| 30 |
+.xTerminal_loop: |
|
| 31 |
+ ; Get command |
|
| 32 |
+ call .xTerminalGetCommand |
|
| 33 |
+ ; Check command length |
|
| 34 |
+ mov low(*commandBuffer), X |
|
| 35 |
+ mov high(*commandBuffer), Y |
|
| 36 |
+ call .xStringLength |
|
| 37 |
+ ; 0 == A |
|
| 38 |
+ cmp 0, A |
|
| 39 |
+ je .xTerminal_loop |
|
| 40 |
+ ; Run app if command is not empty |
|
| 41 |
+ call .xTerminalRunApp |
|
| 42 |
+ ; Get another command |
|
| 43 |
+ jmp .xTerminal_loop |
|
| 44 |
+ |
|
| 45 |
+; No arguments |
|
| 46 |
+; No return |
|
| 47 |
+external .xTerminalReset: |
|
| 48 |
+ push X |
|
| 49 |
+ push Y |
|
| 50 |
+ ; Reset color |
|
| 51 |
+ call .xTerminalColorReset |
|
| 52 |
+ ; Clear screen |
|
| 53 |
+ call .xLcdClear |
|
| 54 |
+ ; Reset cursor position |
|
| 55 |
+ mov 0, X |
|
| 56 |
+ mov 0, Y |
|
| 57 |
+ call .xStringSetCursor |
|
| 58 |
+ pop Y |
|
| 59 |
+ pop X |
|
| 60 |
+ ret |
|
| 61 |
+ |
|
| 62 |
+; No arguments |
|
| 63 |
+; No return |
|
| 64 |
+external .xTerminalColorReset: |
|
| 65 |
+ push A |
|
| 66 |
+ ; Change colors to default |
|
| 67 |
+ mov 0x0, A |
|
| 68 |
+ call .xLcdSetBackground |
|
| 69 |
+ mov 0xf, A |
|
| 70 |
+ call .xLcdSetForeground |
|
| 71 |
+ pop A |
|
| 72 |
+ ret |
|
| 73 |
+ |
|
| 74 |
+; Start message to show |
|
| 75 |
+const messageSystem "XiOS 0.1" |
|
| 76 |
+const messageFreeRom "32K Program memory free" |
|
| 77 |
+const messageFreeRam "28K Data memory free" |
|
| 78 |
+ |
|
| 79 |
+; No arguments |
|
| 80 |
+; No return |
|
| 81 |
+.xTerminalStartMessage: |
|
| 82 |
+ ; Print name and system version |
|
| 83 |
+ mov low(*messageSystem), X |
|
| 84 |
+ mov high(*messageSystem), Y |
|
| 85 |
+ call .xStringPrintRom |
|
| 86 |
+ call .xStringNewLine |
|
| 87 |
+ call .xStringNewLine |
|
| 88 |
+ ; Print information about ROM for apps |
|
| 89 |
+ mov low(*messageFreeRom), X |
|
| 90 |
+ mov high(*messageFreeRom), Y |
|
| 91 |
+ call .xStringPrintRom |
|
| 92 |
+ call .xStringNewLine |
|
| 93 |
+ ; Print information about RAM for apps |
|
| 94 |
+ mov low(*messageFreeRam), X |
|
| 95 |
+ mov high(*messageFreeRam), Y |
|
| 96 |
+ call .xStringPrintRom |
|
| 97 |
+ ret |
|
| 98 |
+ |
|
| 99 |
+; No arguments |
|
| 100 |
+; No return |
|
| 101 |
+.xTerminalStartSound: |
|
| 102 |
+ push A |
|
| 103 |
+ ; Set fill parameter |
|
| 104 |
+ mov 8, A |
|
| 105 |
+ call .xSpeakerSetFill |
|
| 106 |
+ ; Set volume parameter |
|
| 107 |
+ mov 8, A |
|
| 108 |
+ call .xSpeakerSetVolume |
|
| 109 |
+ ; Set time parameter |
|
| 110 |
+ mov 24, A |
|
| 111 |
+ call .xSpeakerSetTime |
|
| 112 |
+ ; Play e6 tone |
|
| 113 |
+ mov 68, A |
|
| 114 |
+ call .xSpeakerSetNote |
|
| 115 |
+ call .xSpeakerAddNote |
|
| 116 |
+ ; Play e5 tone |
|
| 117 |
+ mov 56, A |
|
| 118 |
+ call .xSpeakerSetNote |
|
| 119 |
+ call .xSpeakerAddNote |
|
| 120 |
+ pop A |
|
| 121 |
+ ret |
|
| 122 |
+ |
|
| 123 |
+; No arguments |
|
| 124 |
+; No return |
|
| 125 |
+.xTerminalGetCommand: |
|
| 126 |
+ ; Reset color |
|
| 127 |
+ call .xTerminalColorReset |
|
| 128 |
+ ; Show command line |
|
| 129 |
+ call .xStringNewLine |
|
| 130 |
+ call .xStringNewLine |
|
| 131 |
+ mov '>', A |
|
| 132 |
+ call .xStringPrintChar |
|
| 133 |
+ call .xLcdRefresh |
|
| 134 |
+ mov 39, A |
|
| 135 |
+ mov low(*commandBuffer), X |
|
| 136 |
+ mov high(*commandBuffer), Y |
|
| 137 |
+ call .xStringRead |
|
| 138 |
+ call .xStringNewLine |
|
| 139 |
+ ret |
|
| 140 |
+ |
|
| 141 |
+; Error messages for run app |
|
| 142 |
+const appNameLengthError "Error: Bad length of app name" |
|
| 143 |
+const appNameUnknownNameError "Error: Unknown app" |
|
| 144 |
+ |
|
| 145 |
+; Address of app argument string |
|
| 146 |
+var appArgX |
|
| 147 |
+var appArgY |
|
| 148 |
+ |
|
| 149 |
+; No arguments |
|
| 150 |
+; No return |
|
| 151 |
+.xTerminalRunApp: |
|
| 152 |
+ push A |
|
| 153 |
+ push X |
|
| 154 |
+ push Y |
|
| 155 |
+ ; Load command buffer address |
|
| 156 |
+ mov low(*commandBuffer), X |
|
| 157 |
+ mov high(*commandBuffer), Y |
|
| 158 |
+ ; Load first char |
|
| 159 |
+ ldr A |
|
| 160 |
+ ; First char cannot be a space |
|
| 161 |
+ cmp ' ', A |
|
| 162 |
+ je .xTerminalRunApp_appNameLengthError |
|
| 163 |
+ ; Find a space after command |
|
| 164 |
+ mov ' ', A |
|
| 165 |
+ call .xStringFind |
|
| 166 |
+ ; If the space is not found then it is no arguments |
|
| 167 |
+ cmp 0, A |
|
| 168 |
+ je .xTerminalRunApp_no_arg |
|
| 169 |
+ ; Move address at space after app name |
|
| 170 |
+ add A, X |
|
| 171 |
+ incc Y |
|
| 172 |
+ ; Replace a space by end of string char |
|
| 173 |
+ str 0 |
|
| 174 |
+ ; Move address at begin of arguments |
|
| 175 |
+ inc X |
|
| 176 |
+ incc Y |
|
| 177 |
+ call .xStringLength |
|
| 178 |
+ ; It is no arguments if string length is equal zero |
|
| 179 |
+ cmp 0, A |
|
| 180 |
+ je .xTerminalRunApp_no_arg |
|
| 181 |
+ jmp .xTerminalRunApp_checkAppName |
|
| 182 |
+ ; Set arguments address for case where no argument was found |
|
| 183 |
+.xTerminalRunApp_no_arg: |
|
| 184 |
+ ; Load command buffer address |
|
| 185 |
+ mov low(*commandBuffer), X |
|
| 186 |
+ mov high(*commandBuffer), Y |
|
| 187 |
+ call .xStringLength |
|
| 188 |
+ ; Move address at end+1 of app name |
|
| 189 |
+ inc A |
|
| 190 |
+ add A, X |
|
| 191 |
+ incc Y |
|
| 192 |
+ ; Store end of string char |
|
| 193 |
+ str 0 |
|
| 194 |
+ ; Check app name |
|
| 195 |
+.xTerminalRunApp_checkAppName: |
|
| 196 |
+ ; Store arguments address to local variables |
|
| 197 |
+ str X, *appArgX |
|
| 198 |
+ str Y, *appArgY |
|
| 199 |
+ ; Load command buffer address |
|
| 200 |
+ mov low(*commandBuffer), X |
|
| 201 |
+ mov high(*commandBuffer), Y |
|
| 202 |
+ ; Check app name length |
|
| 203 |
+ call .xStringLength |
|
| 204 |
+ ; If app name lenght is equal to zero then show error message |
|
| 205 |
+ cmp 0, A |
|
| 206 |
+ je .xTerminalRunApp_appNameLengthError |
|
| 207 |
+ ; If app name lenght is greather than 8 then show error message |
|
| 208 |
+ cmp 8, A |
|
| 209 |
+ ; 8 < A |
|
| 210 |
+ jl .xTerminalRunApp_appNameLengthError |
|
| 211 |
+ ; Run load app procedure |
|
| 212 |
+ call .xTerminalLoadApp |
|
| 213 |
+ ; If load app procedure returned flase then show error message |
|
| 214 |
+ cmp 0, A |
|
| 215 |
+ je .xTerminalRunApp_appUnknownNameError |
|
| 216 |
+ ; Make a new line before app output |
|
| 217 |
+ call .xStringNewLine |
|
| 218 |
+ ; Load args address |
|
| 219 |
+ ldr *appArgX, X |
|
| 220 |
+ ldr *appArgY, Y |
|
| 221 |
+ ; Run app |
|
| 222 |
+ call 0x8000 |
|
| 223 |
+ pop Y |
|
| 224 |
+ pop X |
|
| 225 |
+ pop A |
|
| 226 |
+ ret |
|
| 227 |
+ ; Show length error message |
|
| 228 |
+.xTerminalRunApp_appNameLengthError: |
|
| 229 |
+ call .xStringNewLine |
|
| 230 |
+ mov low(*appNameLengthError), X |
|
| 231 |
+ mov high(*appNameLengthError), Y |
|
| 232 |
+ call .xStringPrintRom |
|
| 233 |
+ pop Y |
|
| 234 |
+ pop X |
|
| 235 |
+ pop A |
|
| 236 |
+ ret |
|
| 237 |
+ ; Show unknow name of app error message |
|
| 238 |
+.xTerminalRunApp_appUnknownNameError: |
|
| 239 |
+ call .xStringNewLine |
|
| 240 |
+ mov low(*appNameUnknownNameError), X |
|
| 241 |
+ mov high(*appNameUnknownNameError), Y |
|
| 242 |
+ call .xStringPrintRom |
|
| 243 |
+ pop Y |
|
| 244 |
+ pop X |
|
| 245 |
+ pop A |
|
| 246 |
+ ret |
|
| 247 |
+ |
|
| 248 |
+; No arguments |
|
| 249 |
+; Return: |
|
| 250 |
+; A - success (0 - error, 1 - ok) |
|
| 251 |
+.xTerminalLoadApp: |
|
| 252 |
+ push B |
|
| 253 |
+ push X |
|
| 254 |
+ push Y |
|
| 255 |
+ ; Set name of app |
|
| 256 |
+ mov low(*commandBuffer), X |
|
| 257 |
+ mov high(*commandBuffer), Y |
|
| 258 |
+ call .xFSSetName |
|
| 259 |
+ ; Open app |
|
| 260 |
+ call .xFSOpenApp |
|
| 261 |
+ cmp 0, A |
|
| 262 |
+ je .xTerminalLoadApp_fail |
|
| 263 |
+ ; Get app size and compare to max loadable size |
|
| 264 |
+ call .xFSSize |
|
| 265 |
+ ; 0x80 < B |
|
| 266 |
+ cmp 0x80, B |
|
| 267 |
+ jl .xTerminalLoadApp_fail |
|
| 268 |
+ ; Do not load empty file |
|
| 269 |
+ push B |
|
| 270 |
+ or A, B |
|
| 271 |
+ ; 0 == B |
|
| 272 |
+ cmp 0, B |
|
| 273 |
+ pop B |
|
| 274 |
+ je .xTerminalLoadApp_fail |
|
| 275 |
+ ; Calc how many block are needed to read |
|
| 276 |
+ dec A |
|
| 277 |
+ decc B |
|
| 278 |
+ ; Set starting block |
|
| 279 |
+ mov 0, A |
|
| 280 |
+ ; Set starting address |
|
| 281 |
+ mov 0x00, X |
|
| 282 |
+ mov 0x80, Y |
|
| 283 |
+ ; Run copy loop B+1 times |
|
| 284 |
+.xTerminalLoadApp_loop: |
|
| 285 |
+ call .xFSReadBlock |
|
| 286 |
+ inc A |
|
| 287 |
+ inc Y |
|
| 288 |
+ loopz B, .xTerminalLoadApp_loop |
|
| 289 |
+ pop Y |
|
| 290 |
+ pop X |
|
| 291 |
+ pop B |
|
| 292 |
+ ; Return true for success |
|
| 293 |
+ mov 1, A |
|
| 294 |
+ ret |
|
| 295 |
+ ; Fail exit of load app |
|
| 296 |
+.xTerminalLoadApp_fail: |
|
| 297 |
+ pop Y |
|
| 298 |
+ pop X |
|
| 299 |
+ pop B |
|
| 300 |
+ ; Return false for fail |
|
| 301 |
+ mov 0, A |
|
| 302 |
+ ret |
|
| 303 |
+ |