INPUT A$ in assembly
INPUT A$ in assembly
I need to read in assembly ZX81 a little string as user input. I've seen various routines that allow to read it 1 character at a time.
I was wondering if there is a possibility to call the standard basic subroutine that perform the instruction "INPUT A$".
It will have various advantages:
1. should be shorter in terms of code size (very important for this little creature)
2. should be read all at once (I do not need single characters and I would avoid the waiting loop)
3. should allow the "edit" facilities (to correct the input until enter)
The best would be also to limit the maximum input length, but this is a "nice to have"
Thank you!
I was wondering if there is a possibility to call the standard basic subroutine that perform the instruction "INPUT A$".
It will have various advantages:
1. should be shorter in terms of code size (very important for this little creature)
2. should be read all at once (I do not need single characters and I would avoid the waiting loop)
3. should allow the "edit" facilities (to correct the input until enter)
The best would be also to limit the maximum input length, but this is a "nice to have"
Thank you!
Re: INPUT A$ in assembly
In the code in the attachment system variable "ch-add" is set to point to the text "A$" at the end of the line, and then "look-vars" and "input" are called.
- Attachments
-
- i.p
- (1.29 KiB) Downloaded 155 times
Re: INPUT A$ in assembly
Maybe the source would be better than the binary.
Re: INPUT A$ in assembly
You're right! And this seems to work too and is two bytes shorter. It just interprets "INPUT A$".
Code: Select all
org 0x4082
ld hl,basic
ld (0x4016),hl
jp 0x0cde
basic:
defb 238
defb 38
defb 13
Re: INPUT A$ in assembly
It works!olofsen wrote:In the code in the attachment ...
Before seen your last answer I tried to disassemble myself and seems I did despite 25+ years of not using Z80 code anymore!
(btw never used it on ZX81)
Code: Select all
rem content to run:
33 21 LD HL,408E ; 16526 -> A$ ADDRESS OF THE PRINT STATEMENT
142 8E
64 40
34 22 LD (4016),HL ; CH_ADD
22 16
64 40
205 CD CALL 0D3C ; COMMAND CLASS-1
60 3C
13 0D
195 C3 JP 0EE9 ; INPUT ROUTINE OF BASIC INTERPRETER
233 E9
14 0E
38 26 LD H,0D ; ?
13 0D
then there is the instruction:
PRINT A$
1. seems confirmed that the first instruction point to the text A$<endofline> of the BASIC instruction (but what is the endofline value?)
2. the previous pointer has to be set in the CH_ADD pointer and COMMAND CLASS-1 (that start then with LOOK_VARS) routine has to be called to prepare the variable for the actual input command
Then I do not fully understand how it works:
3. how is possible that a jump (to the input routine) is returning back to where is called? (I need to call from and return to machine code)
4. what does the final assembler instruction LD H,0Dh? (is useful for the next statement PRINT A$? or has not to be disassembled and then what is used for?)
PS:
5. how to find/know the input(ted) string address in pure assembler? (not the "A$" text but the actual value inserted by the user)
Thank you!
Re: INPUT A$ in assembly
Regarding this new variant seems to work too!!olofsen wrote:You're right! And this seems to work too and is two bytes shorter. It just interprets "INPUT A$".
I had to "rewrite a bit for TASM to work:
Code: Select all
startofprogram:
.org 4082h
ld hl,instructiontextinputadollar
ld (4016h),hl ; CH_ADD
jp 0CDEh ; LINE-NULL ?
; done let's exit
jp endofprogram
instructiontextinputadollar:
.byte 238,38,13 ; INPUT A$
;other stuff removed...
endofprogram:
jp NEXTLINE
(and I have the same curiosity on how is possible to return back to the same place after a jump! )
Last edited by marste on Wed Aug 20, 2014 9:32 pm, edited 1 time in total.
Re: INPUT A$ in assembly
I tried to change the last instruction instead of "jp endofprogram" to "jp startofprogram" but seems it is not working (the program ends anyway without looping).marste wrote: Regarding this new variant seems to work too
//...//
(and I have the same curiosity on how is possible to return back to the same place after a jump! )
So seems to that the jump instruction is not returning back to the caller!
Re: INPUT A$ in assembly
Returning from input at 0x0ee9 seems to be tricky indeed, unfortunately
Re: INPUT A$ in assembly
Would you consider returning from the machine code to just do the INPUT in BASIC? This will be the easiest and probably the smallest.
The following code gets the A$ at line 110 from NXTLIN and some increments and stores this at CH-ADD. It then calls "look-vars"; the carry is set if A$ is not set; one length byte of A$ is returned.
Code: Select all
100 print usr 16514
110 input a$
120 print a$
130 goto 100
Code: Select all
org 0x4082
ld hl,(0x4029)
call 0x07b7
ld (0x4016),hl
call 0x111c
ld bc,0
ret c
inc hl
ld c,(hl)
ret
Re: INPUT A$ in assembly
Yesss!... I was thinking the same!olofsen wrote:Would you consider returning from the machine code to just do the INPUT in BASIC? This will be the easiest and probably the smallest.
Find the variable should be easy for me: would be the only basic variable!...The following code gets the A$ at line 110 from NXTLIN and some increments and stores this at CH-ADD. It then calls "look-vars"; the carry is set if A$ is not set; one length byte of A$ is returned.
The last point is: can I fix the lenght / maximum lenght of it?
Thank you!