Author Topic: Best approach to text input?  (Read 808 times)

0 Members and 1 Guest are viewing this topic.

Offline duncan_bayne

  • CPC464
  • **
  • Posts: 49
  • Country: au
    • Duncan Bayne
  • Liked: 27
  • Likes Given: 3
Best approach to text input?
« on: 01:56, 20 July 13 »
Hi Folks,

I notice that SDCC doesn't have scanf() or gets().  What's the usual approach for cross-platform (i.e. 464-, 664-, and 6128- compatible) text input?  I see from the firmware manual that a text input routine is available at &BD5E, but that seems to be 664 & 6128 only.

Thanks in advance for any pointers ... :)

Yours,
Duncan

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.919
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1132
  • Likes Given: 1902
Re: Best approach to text input?
« Reply #1 on: 06:58, 20 July 13 »
Probably more compatible using routines in the KM, the 2 I was just looking at were KM WAIT CHAR (&BB06) & KM WAIT KEY (&BB18), both Wait for a keypress and once a key is press A holds the character value. I'm not sure which is better, I wrote this small routine which Loops around until Return/Enter is pressed and just writes the characters to the area of memory I designated. Only issue with this is if I make a mistake, unlike an typical Input, I cannot go back and correct it.

Code: [Select]
  org &4000

  ld hl,text
.loop
  call &bb06
  ld (hl),a
  inc hl
  call &bb5a
  cp &0d
  jr nz,loop

.exit
  ret
.text
  defs 200
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline SyX

  • 6128 Plus
  • ******
  • Posts: 1.129
  • Country: br
  • Liked: 1121
  • Likes Given: 1871
Re: Best approach to text input?
« Reply #2 on: 11:02, 21 July 13 »
As AMSDOS says, you should use KM_WAIT_CHAR or KM_WAIT_KEY, and if you don't need to wait for a keypress then use KM_READ_CHAR or KM_READ_KEY. I use this code everytime that i need an input firmware friendly:
Code: [Select]
    LD   DE,input_variable
    LD   B,9                        ; length of input string
.loop_key_input
    CALL KM_WAIT_KEY
    CALL make_sound
    CP   $0D
    JR   Z,.end_loop_key_input
    CP   $7F
    JR   NZ,.print_char
    LD   A,B
    CP   9
    JR   Z,.loop_key_input
    LD   HL,delete_char_text
    CALL print_text
    INC  B
    DEC  DE
    LD   A," "
    LD   (DE),A
    JR   .loop_key_input       
.print_char
    LD   L,A
    LD   A,B
    CP   1
    JR   Z,.loop_key_input
    LD   A,L
    CALL TXT_OUTPUT
    LD   (DE),A
    INC  DE
    LD   HL,cursor_text
    CALL print_text
    DJNZ .loop_key_input
.end_loop_key_input
    LD   A," "
    CALL TXT_OUTPUT
.
.
.
; ---------------------------------------------------------------------------
; Make a click, to give feedback when a key is pressed
; ---------------------------------------------------------------------------
make_sound
    PUSH AF
    PUSH BC
    PUSH DE
    PUSH HL
    PUSH IX

    LD   HL,SOUND_CLICK     ; sound_data in central ram
    CALL SOUND_QUEUE

    POP  IX
    POP  HL
    POP  DE
    POP  BC
    POP  AF
    RET

sound_data
    DEFB 2,0,0
    DEFW 478
    DEFB 0,15

delete_char_text
    DEFB " ",$08," ",$08,$08
cursor_text
    DEFB "_",$08,$FF