[go: up one dir, main page]

Menu

[r97]: / psrp / asm / t4a_3.asm  Maximize  Restore  History

Download this file

251 lines (188 with data), 5.6 kB

  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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
;
; Narrative formatter
; - Dictionary processing
;
; Written in TASM 3.0.1
;
#include "vars.asm"
.org $7ed0 ; $7fed0-7ffaf ($e0)
; substring inserter
; b = space left on line
; (STR)w = pointer to string
; (LEN)b = length
; returns tile index to be drawn in a,
; or a newline if a new line is needed for this insertion
Check_Autowait:
; LD A,(FLAG) ; Scan flag
; OR A ; See if auto-wait occurred
; JR Z,Lookup ; Not raised
; XOR A ; Lower flag
; LD (FLAG),A
; XOR A ; Reset it to zero
; LD (LINE_NUM),A
; LD A,NEWLINE ; Need to emit a newline [NOT NEEDED]
; RET ; No decoding needed
; ______________________________________________________
Lookup:
LD A,(LEN) ; Grab length of string
OR A ; Check for zero-length
LD A,EOS ; Load 'abort' flag
RET Z ; Return if NULL
Substring:
LD A,B ; Save width
LD (HLIMIT),A
PUSH HL ; Stack registers
PUSH BC
LD BC,(STR) ; Grab raw text location
LD HL,LEN ; Grab address of length
; ------------------------------------------------------
; Article (The, An, A, Some) handler
PUSH DE ; init
LD A,(ARTICLE) ; Check for article usage
OR A
JR Z,Art_Exit ; article = none
LD DE,TAB1
CP $01 ; article = a,an,the
JR Z,Start_Art
LD DE,TAB2
; CP $02 ; article = A,AN,THE
; JR Z,Start_Art
Start_Art:
LD A,(BC) ; Grab index
SUB $54 ; Remap index range
JR C,Art_Done ; if there is a letter there, it'll be 0..$40ish. So do nothing.
ADD A,A ; Multiply by two
ADD A,E ; Add offset
LD E,A ; (note: be careful we don't byte-wrap)
LD A,(DE) ; Grab final string offset
INC DE
PUSH AF
LD A,(DE)
LD D,A
POP AF
LD E,A
Add_Art:
LD A,(DE) ; grab font #
CP EOS
JR Z,Art_Done
DEC BC ; bump dst pointer
LD (BC),A ; add tile
INC DE ; bump src
INC (HL) ; bump length
JR Add_Art
Art_Done:
LD (STR),BC ; store new text pointer
XOR A
LD (ARTICLE),A ; lower flag
Art_Exit:
POP DE ; now proceed normally
LD BC,(STR) ; Grab raw text location (again)
JR Initial_Codes
; Articles in 'reverse' order
TAB1 .dw ART_11, ART_12, ART_13
ART_11 .db $00,$25,EOS ; 'a '
ART_12 .db $00,$32,$25,EOS ; 'an '
ART_13 .db $00,$29,$2c,$38,EOS ; 'the '
ART_14 .db $00,$29,$31,$33,$37,EOS ; 'some '
TAB2 .dw ART_21, ART_22, ART_23
ART_21 .db $00,$0b,EOS ; 'A '
ART_22 .db $00,$28,$0b,EOS ; 'An '
ART_23 .db $00,$29,$2c,$1e,EOS ; 'The '
ART_24 .db $00,$29,$31,$33,$1d,EOS ; 'Some '
; TAB3
; ART_31
; ART_32
; ________________________________________________________________
Initial_Codes:
LD A,(BC) ; Grab character
; CP EOS ; Check for abort code
; JR Z,Abort_Initial
CP $4F ; Skip initial codes
JR C,Begin_Scan ; Look for first real font tile
; Initial code skipper:
INC BC ; Bump pointer
LD (STR),BC ; Save pointer
DEC (HL) ; Shrink length
JR NZ,Initial_Codes ; Loop if still alive
;Abort_Initial:
; LD A,EOS ; Return abort #
; POP BC ; Restore stack registers
; POP HL
; JR Abort ; No text
Begin_Scan:
PUSH HL ; Save new current length
PUSH BC ; Save new text pointer
LD H,(HL) ; Init string counter
LD L,$00 ; Current length is zero
; CALL Scan_String ; Check for wrapping condition
CALL One_Font ; get length up to next whitespace in l
LD A,(HLIMIT) ; Remaining width
SUB L ; Remove characters used
; LD HL,(LIMIT) ; Grab limit pointer
; INC HL ; Bump pointer
; INC HL
; INC HL
; CP (HL) ; Compare against horizontal limit
; LD L,$12+$01 ; Screen limit without 2 borders
; CP L ; Compare against horizontal limit
JR NC,No_Spill ; No text spillage
; ________________________________________________________________
Text_Spill:
POP BC ; Restore old text pointer
POP HL ; Reload length pointer
LD A,(BC) ; Reload first scanned character
OR A ; Check for whitespace ($00)
JR NZ,Text_Spill_Line ; Don't eat non-WS
Text_Spill_WS:
INC BC ; Bump text pointer
LD (STR),BC ; Store new location
DEC (HL) ; Shrink length
Text_Spill_Line:
LD A,NEWLINE ; newline
POP BC ; Stack registers
POP HL
RET ; exit
; ________________________________________________________________
No_Spill:
POP BC ; Restore original text pointer
POP HL ; Restore length pointer
DEC (HL) ; Shrink text length
LD A,(BC) ; Read in text character
INC BC ; Bump text pointer
LD (STR),BC ; Store new location
POP BC ; Stack registers
POP HL
RET
Exit:
; OR A ; Check for abort
; RET NZ ; Return if font character
Abort:
; XOR A ; Length exhausted
; LD (LEN),A
; LD A,EOS ; Load 'abort' flag
; RET ; Done
; ______________________________________________________
; ______________________________________________________
; Note: Treat first character as a regular tile, regardless of WS
Scan_String:
INC BC ; Bump text cursor
DEC H ; Shrink text
JR Z,Stop ; Length exhausted == 0
LD A,(BC) ; Grab character
OR A ; Check for whitespace
JR Z,Break ; If char == 0, stop
CP $4F ; Control codes
JR NC,Scan_String ; Ignore special script values
One_Font:
INC L ; One font drawn
JR Scan_String
Stop:
LD BC,POST_LEN ; Load post-hint address
LD A,(BC) ; Load post-hint value
ADD A,L ; Tack on length BUG?: two-word substitutions get the extra added to the first word
LD L,A ; Store for return
XOR A
LD (BC),A ; Clear post-hint value
Break:
RET
.end ; TASM-only