News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_duncan_bayne

Best approach to text input?

Started by duncan_bayne, 23:56, 19 July 13

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

duncan_bayne

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

AMSDOS

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.


  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

SyX

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:

    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

Powered by SMFPacks Menu Editor Mod