INPUT A$ in assembly

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
marste
Posts: 250
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

INPUT A$ in assembly

Post by marste »

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!
olofsen
Posts: 189
Joined: Wed Jan 08, 2014 12:29 pm

Re: INPUT A$ in assembly

Post by olofsen »

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
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: INPUT A$ in assembly

Post by PokeMon »

Maybe the source would be better than the binary. ;)
olofsen
Posts: 189
Joined: Wed Jan 08, 2014 12:29 pm

Re: INPUT A$ in assembly

Post by olofsen »

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
User avatar
marste
Posts: 250
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: INPUT A$ in assembly

Post by marste »

olofsen wrote:In the code in the attachment ...
It works! :D

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$
For the first part is ok (even if I miss some detail):
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!
User avatar
marste
Posts: 250
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: INPUT A$ in assembly

Post by marste »

olofsen wrote:You're right! And this seems to work too and is two bytes shorter. It just interprets "INPUT A$".
Regarding this new variant seems to work too!! :D :D

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
The smaller the better, so on this I would miss just the place where the actual content has been put, and how to be sure that this it is not "invading" the rest of my code! :)
(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.
User avatar
marste
Posts: 250
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: INPUT A$ in assembly

Post by marste »

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! :))
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).

So seems to that the jump instruction is not returning back to the caller!
olofsen
Posts: 189
Joined: Wed Jan 08, 2014 12:29 pm

Re: INPUT A$ in assembly

Post by olofsen »

Returning from input at 0x0ee9 seems to be tricky indeed, unfortunately :geek:
olofsen
Posts: 189
Joined: Wed Jan 08, 2014 12:29 pm

Re: INPUT A$ in assembly

Post by olofsen »

Would you consider returning from the machine code to just do the INPUT in BASIC? This will be the easiest and probably the smallest.

Code: Select all

100 print usr 16514
110 input a$
120 print a$
130 goto 100
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

        org 0x4082
        ld hl,(0x4029)
        call 0x07b7
        ld (0x4016),hl
        call 0x111c
        ld bc,0
        ret c
        inc hl
        ld c,(hl)
        ret
User avatar
marste
Posts: 250
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: INPUT A$ in assembly

Post by marste »

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.
Yesss!... I was thinking the same! :)
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.
Find the variable should be easy for me: would be the only basic variable!...

The last point is: can I fix the lenght / maximum lenght of it? :)

Thank you!
Post Reply