gets.s 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. |improved gets() implementation for TIGCCLIB
  2. |Copyright (C) Kevin Kofler, 2002-2003
  3. /* Prototype:
  4. char *gets(char *string asm("a2")); */
  5. .equ __SaveScrState,0x1a0 /* SaveScrState */
  6. .equ __MoveTo,0x19d /* MoveTo */
  7. .text
  8. .xdef gets
  9. gets:
  10. movem.l %a3-%a5,-(%a7)
  11. |SaveScrState(&ss);
  12. link.w %a6,#-18
  13. pea.l (%a7)
  14. move.l 0xc8:w,%a3
  15. move.l __SaveScrState*4(%a3),%a0
  16. jsr (%a0)
  17. |fputchar('_');
  18. move.w #'_',(%a7)
  19. jbsr fputchar
  20. move.l %a2,%a4 |current string pointer
  21. clr.b (%a4) | null-terminate the string
  22. move.l __MoveTo*4(%a3),%a5 |prepare MoveTo for repeated calling
  23. lea.l printf,%a3 |prepare printf for repeated calling
  24. 1:
  25. jbsr __fgetchar
  26. cmp.w #13,%d0 |KEY_ENTER
  27. beq.s 0f
  28. cmp.w #257,%d0 |KEY_BACKSPACE
  29. bne.s 2f
  30. cmp.l %a4,%a2
  31. beq.s 1b |don't go back if we are already at the first char
  32. clr.b -(%a4) |delete the last character and null-terminate the string
  33. bra.s 3f
  34. 2:
  35. move.b %d0,(%a4)+ |store the character
  36. clr.b (%a4) |null-terminate the string
  37. 3: |output the changed string
  38. |MoveTo(ss.CurX,ss.CurY);
  39. move.l -8(%a6),(%a7)
  40. jsr (%a5)
  41. |printf("%s_ ",string);
  42. move.l %a2,(%a7)
  43. pea.l L.format1(%pc)
  44. jsr (%a3)
  45. addq.l #4,%a7 |cleanup the stack (we don't want our loop to overflow it)
  46. bra.s 1b |next character
  47. 0: |output the final string
  48. |MoveTo(ss.CurX,ss.CurY);
  49. move.l -8(%a6),(%a7)
  50. jsr (%a5)
  51. |printf("%s ",string);
  52. move.l %a2,(%a7)
  53. pea.l L.format2(%pc)
  54. jsr (%a3)
  55. |MoveTo(ss.CurX,ss.CurY);
  56. move.l -8(%a6),(%a7)
  57. jsr (%a5)
  58. |printf("%s",string);
  59. move.l %a2,(%a7)
  60. pea.l L.format3(%pc)
  61. jsr (%a3)
  62. unlk %a6
  63. movem.l (%a7)+,%a3-%a5
  64. movea.l %a2,%a0 |return the string
  65. rts
  66. L.format1: .asciz "%s_ "
  67. L.format2: .asciz "%s "
  68. L.format3: .asciz "%s"