getsn.s 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. |getsn() (gets() with maximum size) implementation for TIGCCLIB
  2. |Copyright (C) Kevin Kofler, 2002-2003
  3. /* Prototype:
  4. char *getsn(char *string asm("a2"), unsigned long maxlen asm("d3")); */
  5. .equ __SaveScrState,0x1a0 /* SaveScrState */
  6. .equ __MoveTo,0x19d /* MoveTo */
  7. .text
  8. .xdef getsn
  9. getsn:
  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. |if (current_pointer>=string+maxlen-1), refuse additional input
  36. lea.l -1(%a2,%d3:l),%a0
  37. cmpa.l %a0,%a4
  38. bcc.s 1b
  39. move.b %d0,(%a4)+ |store the character
  40. clr.b (%a4) |null-terminate the string
  41. 3: |output the changed string
  42. |MoveTo(ss.CurX,ss.CurY);
  43. move.l -8(%a6),(%a7)
  44. jsr (%a5)
  45. |printf("%s_ ",string);
  46. move.l %a2,(%a7)
  47. pea.l L.format1(%pc)
  48. jsr (%a3)
  49. addq.l #4,%a7 |cleanup the stack (we don't want our loop to overflow it)
  50. bra.s 1b |next character
  51. 0: |output the final string
  52. |MoveTo(ss.CurX,ss.CurY);
  53. move.l -8(%a6),(%a7)
  54. jsr (%a5)
  55. |printf("%s ",string);
  56. move.l %a2,(%a7)
  57. pea.l L.format2(%pc)
  58. jsr (%a3)
  59. |MoveTo(ss.CurX,ss.CurY);
  60. move.l -8(%a6),(%a7)
  61. jsr (%a5)
  62. |printf("%s",string);
  63. move.l %a2,(%a7)
  64. pea.l L.format3(%pc)
  65. jsr (%a3)
  66. unlk %a6
  67. movem.l (%a7)+,%a3-%a5
  68. movea.l %a2,%a0 |return the string
  69. rts
  70. L.format1: .asciz "%s_ "
  71. L.format2: .asciz "%s "
  72. L.format3: .asciz "%s"