aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_asm/builtin_asm/std_term.atk16
blob: 9a7af5f2951572cb14193b71baf6d241cc1aee94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
@data log_term_char_p log_term_char
@label log_term_char
  ; send a character to the terminal
  ; parameters:             RA = character code
  ; return:                 none

  ; RG is allowed to be clobbered by the calling convention
  ldi vt_term_pp_addr RG    ; RG := terminal address pointer
  ldr RG RG                 ; RG := terminal address

  str RA RG                 ; write 'A' to terminal
  return


@data log_term_string_p log_term_string
@label log_term_string
  ; send a string to the terminal
  ; parameters:             RA = address of string allocation
  ; return:                 none

  ; strings are encoded as a length word followed by the string data
  ; RG is allowed to be clobbered by the calling convention
  ldi vt_term_pp_addr RG    ; RG := terminal address pointer
  ldr RG RG                 ; RG := terminal address

  stack_stash RA RB RC RD

  ldr RA RB                 ; RB := string length
  ldi 0 RC                  ; RC := 0

@label log_term_string_loop
  sub RB RC RD              ; RD := remaining length
  bri zero log_term_string_done

  add RC RA RD              ; RD := pointer to next character - 1
  addi RD 1 RD              ; RD := pointer to next character

  ldr RD RD                 ; RD := next character

  str RD RG                 ; write character to terminal
  inc RC                    ; increment pointer

  jpi log_term_string_loop

@label log_term_string_done
  stack_restore RA RB RC RD
  return