I usually use direct input without any problem but I don't know what's wrong.
In fact the issue is not direct input it seems.

Here's the code with the issue :

Code:
EXECUTE_UNTIL_KEYPRESS:
        push    af 
        push    hl 
euk_boucle:
        pop     hl 
        pop     af 
        ld      de, euk_continuer
        push    de 
        jp      (hl)
euk_continuer:
        push    hl 
        push    af 
        ld     a,$FF               
        out    (1),a               
        ld     a,$FD             
        out    (1),a             
        in     a,(1)           
        cp     254      ; Tested with sub 254 too       
        jp     nz,euk_boucle             
           
        pop     af 
        pop     hl 

        ret


I can't exit the loop even by pressing enter.
I've tested to put the direct input in the beginning of this function, same issue.
I've tester with another group/key, same issue.


If I remove :

Code:
 
        ld      de, euk_continuer
        push    de 
        jp      (hl)


It works fine...

Someone has an idea ?

About the jp (hl) jump, here's the called function :

Code:
PUT_BYTE:
        ld      hl, plotsscreen
        ld      (hl), a
        call   FASTCOPY
        ret


I could probably find by myself as I do usually, but if someone could say me what's wrong, that's pretty cool :p
try this


Code:
EXECUTE_UNTIL_KEYPRESS:
        push    af 
        push    hl 
euk_boucle:
        pop     hl 
        pop     af 
        ld      de, euk_continuer
        push    de 
        jp      (hl)
euk_continuer:
        push    hl 
        push    af 
        ld     a,$FF               
        out    (1),a               
       nop
       nop 
       ld     a,$FD             
        out    (1),a             
        nop
        nop
        in     a,(1)           
        cp     254      ; Tested with sub 254 too       
        jp     nz,euk_boucle             
           
        pop     af 
        pop     hl 

        ret

[/quote]
You're clobbering hl in your PUT_BYTE routine. The EXECUTE_UNTIL_KEYPRESS routine doesn't save hl before calling the routine in hl.

Once you fix that problem, here's a little optimization you can do. The smallest and fastest way to call a routine whose address is in hl is like this:
Code:
    ; ...
    ; routine to call is in hl
    call jp_hl
    ; ...

; somewhere else...
jp_hl:
    jp (hl)


Instead of this:

Code:
    ld de,return
    push de
    jp (hl)
return:

It's a byte shorter and a handful of cycles faster, and it doesn't modify any registers.
Yes, I was already trying to correct this mistake before reading your post.

Thank you, the issue is resolved, the value of hl wasn't correctly saved.

Here is my solution :

Code:
EXECUTE_UNTIL_KEYPRESS:
        push    hl
        push    af
euk_boucle:
        ld      de, euk_continuer
        pop     af    ; Pop and push just before jp
        pop     hl
        push    hl
        push    af
        push    de  ; adress for the ret
        jp      (hl)
euk_continuer:
        ld     a,$FF           
        out    (1),a           
        nop
        nop
        ld     a,$FD         
        out    (1),a
        nop
        nop         
        in     a,(1)       
        ;cp     126         
        bit 0,a
        jp z, keyispressed
        ld a, 0FFh ;Reset the keypad.
        out (1), a

       
        jp      euk_boucle
       
keyispressed:
        pop     af
        pop     hl

        ret


Another little question...
Is there an easy way to do a "push pc" ?
(without defining labels)
contra-sh wrote:
Another little question...
Is there an easy way to do a "push pc" ?
(without defining labels)

Yes, "call $+3" will do that. Why would you need to do that, anyway? I already showed how you can do a "call (hl)" operation without pushing anything or changing any registers.


Note: Be aware that "call $+3" will push the PC of the next instruction. The z80 effectively increments the program counter to the next instruction before executing each instruction. This is because it first has to fetch and decode the instruction before it can execute it. The fetch and decode stages change the PC as they work on each instruction. This also explains why the "jr" instruction can jump up to 129 bytes forward or 126 bytes backward; the 8-bit signed displacement (which has a range of -128..127) is relative to the next instruction.

EDIT: Here is my rewrite. I changed only the pushes/pops/jr/call stuff. I left the port read/write stuff as-is:

Code:
EXECUTE_UNTIL_KEYPRESS:
   push   af
loop:
   push   hl
   call   jp_hl
   pop   hl

   ; is this code necessary?
   ld   a,$FF  ; <
   out   (1),a ; <
   nop         ; <
   nop         ; <
   ; ^^^^^^^^

   ld   a,$FD
   out   (1),a
   nop
   nop
   in   a,(1)
   bit   0,a
   jr   z,keyispressed
   ld   a,$FF ;Reset the keypad.
   out   (1),a
   jr   loop
keyispressed:
   pop   af
   ret

jp_hl:
   jp   (hl)




(The following is mostly off topic and can be ignored)
I just thought of something kind of clever. At least I haven't seen it done anywhere to this extent yet:

Code:
    call $+3
    call $+3
    call $+3
    ; do something
    ret

That will "do something" 8 (2^3) times. Each additional "call $+3" doubles the number of times "do something" runs. This is a solution in search of a problem. In other words: "This is a special hammer. Find those special nails!". Very Happy
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement