printstr.asm 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include once <print.asm>
  2. #include once <sposn.asm>
  3. #include once <attr.asm>
  4. #include once <free.asm>
  5. ;
  6. ; PRINT command routine
  7. ; Prints string pointed by HL
  8. ;
  9. PRINT_STR:
  10. __PRINTSTR: ; __FASTCALL__ Entry to print_string
  11. ;- PROC
  12. ;- LOCAL __PRINT_STR_LOOP
  13. ;- LOCAL __PRINT_STR_END
  14. lda z80_a ;- ld d,a ; Saves A reg (Flag) for later
  15. sta z80_d
  16. lda z80_h ;- ld a,h
  17. sta z80_a
  18. ora z80_l ;- or l
  19. bne *+3 ;- ret z ; Return if the pointer is NULL
  20. rts
  21. lda z80_l ;- push hl
  22. pha
  23. lda z80_h
  24. pha
  25. ldy #$00 ;- ld c,(hl)
  26. lda (z80_hl),y
  27. sta z80_c
  28. inc z80_l ;- inc hl
  29. bne *+4
  30. inc z80_h
  31. ldy #$00 ;- ld b,(hl)
  32. lda (z80_hl),y
  33. sta z80_b
  34. inc z80_l ;- inc hl ; BC = LEN(a$); HL = &a$
  35. bne *+4
  36. inc z80_h
  37. __PRINT_STR_LOOP:
  38. lda z80_b ;- ld a,b
  39. sta z80_a
  40. ora z80_c ;- or c
  41. jeq __PRINT_STR_END ;- jr z, __PRINT_STR_END ; END if BC (counter = 0)
  42. ldy #$00 ;- ld a,(hl)
  43. lda (z80_hl),y
  44. sta z80_a
  45. jsr __PRINTCHAR ;- call __PRINTCHAR
  46. inc z80_l ;- inc hl
  47. bne *+4
  48. inc z80_h
  49. ;- dec bc
  50. jmp __PRINT_STR_LOOP ;- jp __PRINT_STR_LOOP
  51. __PRINT_STR_END:
  52. pla ;- pop hl
  53. sta z80_h
  54. pla
  55. sta z80_l
  56. lda z80_d ;- ld a,d ; Recovers A flag
  57. sta z80_a
  58. ora z80_a ;- or a ; If not 0 this is a temporary string. Free it
  59. bne *+3 ;- ret z
  60. rts
  61. jmp __MEM_FREE ;- jp __MEM_FREE ; Frees str from heap and return from there
  62. __PRINT_STR:
  63. ; Fastcall Entry
  64. ; It ONLY prints strings
  65. ; HL = String start
  66. ; BC = String length (Number of chars)
  67. lda z80_l ;- push hl ; Push str address for later
  68. pha
  69. lda z80_h
  70. pha
  71. lda z80_a ;- ld d,a ; Saves a FLAG
  72. sta z80_d
  73. jmp __PRINT_STR_LOOP ;- jp __PRINT_STR_LOOP
  74. ;- ENDP