diff --git a/apps/basic/README.md b/apps/basic/README.md index 3175d64..2d963f3 100644 --- a/apps/basic/README.md +++ b/apps/basic/README.md @@ -95,3 +95,10 @@ by the next, and so on). **if**. If specified condition is true, execute the rest of the line. Otherwise, do nothing. For example, `if 2>1 print 12` prints `12` and `if 2<1 print 12` does nothing. The argument for this command is a "thruth expression". + +**input**. Prompts the user for a numerical value and puts that value in the +specified variable. The prompted value is evaluated as an expression and then +stored where specified. For example, `input x` stores the result of the +evaluation in variable `x`. Before the variable name, a quoted string literal +can be specified. In that case, that string will be printed as-is just before +the prompt. diff --git a/apps/basic/main.asm b/apps/basic/main.asm index b98095c..1ef9537 100644 --- a/apps/basic/main.asm +++ b/apps/basic/main.asm @@ -250,6 +250,23 @@ basIF: ld de, basCmds2 jp basCallCmd +basINPUT: + ; If our first arg is a string literal, spit it + call spitQuoted + call rdSep + ld a, (hl) + call varChk + ret nz ; not in variable range + push af ; --> lvl 1. remember var index + call stdioReadLine + call parseExpr + push ix \ pop de + pop af ; <-- lvl 1. restore var index + call varAssign + call printcrlf + cp a ; ensure Z + ret + ; direct only basCmds1: .dw basBYE @@ -266,4 +283,6 @@ basCmds2: .db "goto", 0, 0 .dw basIF .db "if", 0, 0, 0, 0 + .dw basINPUT + .db "input", 0 .db 0xff, 0xff, 0xff ; end of table diff --git a/apps/basic/var.asm b/apps/basic/var.asm index b76f58b..085e420 100644 --- a/apps/basic/var.asm +++ b/apps/basic/var.asm @@ -55,14 +55,8 @@ varTryAssign: call parseExpr ; --> number in IX jr nz, .exprErr pop af ; <-- lvl 4 - add a, a ; * 2 because each element is a word - ld hl, VAR_TBL - call addHL - ; HL placed, write number - push ix \ pop de - ld (hl), e - inc hl - ld (hl), d + push ix \ pop de ; send number to DE + call varAssign xor a ; ensure Z .end: pop de ; <-- lvl 3 @@ -73,6 +67,21 @@ varTryAssign: pop af ; <-- lvl 4 jr .end +; Given a variable **index** in A (call varChk to transform) and a value in +; DE, assign that value in the proper cell in VAR_TBL. +; No checks are made. +varAssign: + push hl + add a, a ; * 2 because each element is a word + ld hl, VAR_TBL + call addHL + ; HL placed, write number + ld (hl), e + inc hl + ld (hl), d + pop hl + ret + ; Check if value at (HL) is a variable. If yes, returns its associated value. ; Otherwise, jump to parseLiteral. parseLiteralOrVar: