/
ifcharw.asm
147 lines (121 loc) · 3.33 KB
/
ifcharw.asm
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;
; RRPGE User Library functions - Character writer interface
;
; Author Sandor Zsuga (Jubatian)
; Copyright 2013 - 2015, GNU GPLv3 (version 3 of the GNU General Public
; License) extended as RRPGEvt (temporary version of the RRPGE
; License): see LICENSE.GPLv3 and LICENSE.RRPGEvt in the project
; root.
;
;
; The character writer interface provides a common solution for writing
; character data, accomodating up to 32 bits wide characters. It may normally
; be used to output UTF-32 source, but other uses are possible.
;
; The object structure is as follows:
;
; Word0: Set next character function implementation
; Word1: Initialize for output function implementation
; Word2: Set output style function implementation
;
; The set output style and the initialize functions not necessarily have to
; be provided. If not, they must be loaded with zeros, then calling these will
; do nothing.
;
; This interface may be extended (charwr) for character writers which produce
; readable data (with a character reader). For those, the object structure is
; extended with an extra function:
;
; Word3: Get next index function implementation
;
include "rrpge.asm"
section code
;
; Implementation of us_cw_new
;
us_cw_new_i:
.opt equ 0 ; Character writer pointer
.nfn equ 1 ; Set next character function implementation
.ifn equ 2 ; Initialize for output function implementation
.sfn equ 3 ; Set output style function implementation
xug 4, sp
jms .po ; All 4 parameters provided
mov x3, sp
mov sp, 4
mov c, 0
mov [$.sfn], c ; 3 parameters: no .sfn
xug x3, 2
mov [$.ifn], c ; 2 parameters: no .sfn and .ifn
.po: mov x3, [$.opt]
mov c, [$.nfn]
mov [x3], c
mov c, [$.ifn]
mov [x3], c
mov c, [$.sfn]
mov [x3], c
rfn c:x3, x3
;
; Implementation of us_cw_setnc
;
us_cw_setnc_i:
.opt equ 0 ; Character writer pointer
.chh equ 1 ; Character, high
.chl equ 2 ; Character, low
mov x3, [$.opt]
jma [x3] ; Simply tail-transfer
;
; Implementation of us_cw_setst
;
us_cw_setst_i:
.opt equ 0 ; Character writer pointer
.atr equ 1 ; Attribute to set
.val equ 2 ; Value to set
mov x3, [$.opt]
add x3, 2
mov c, [x3]
xeq c, 0
jma c ; Simply tail-transfer
rfn c:x3, 0
;
; Implementation of us_cw_init
;
us_cw_init_i:
.opt equ 0 ; Character writer pointer
mov x3, [$.opt]
add x3, 1
mov c, [x3]
xeq c, 0
jma c ; Simply tail-transfer
rfn c:x3, 0
;
; Implementation of us_cwr_new
;
us_cwr_new_i:
.opt equ 0 ; Character writer (extended) pointer
.nfn equ 1 ; Set next character function implementation
.ifn equ 2 ; Initialize for output function implementation
.sfn equ 3 ; Set output style function implementation
.ffn equ 4 ; Get next index function implementation
xug 5, sp ; 3 or 4 parameters: at least .opt, .nfn and .ffn
jms .po
mov x3, sp
mov sp, 5
sub x3, 1
mov c, [$x3] ; .ffn comes as last parameter
mov [$.ffn], c
mov c, 0 ; .sfn unimplemented
mov [$.sfn], c
xug x3, 3
mov [$.ifn], c ; 3 parameters: .ifn is also unimplemented
.po: jfa us_cw_new_i {[$.opt], [$.nfn], [$.ifn], [$.sfn]}
mov c, [$.ffn]
mov [x3], c
rfn c:x3, x3
;
; Implementation of us_cwr_nextsi
;
us_cwr_nextsi_i:
.opt equ 0 ; Character writer (extended) pointer
mov x3, [$.opt]
add x3, 3
jma [x3] ; Simply tail-transfer