Skip to content

Commit bc8f428

Browse files
committed
refact: big PRINT and related refact
1 parent 2d48ade commit bc8f428

4 files changed

Lines changed: 113 additions & 94 deletions

File tree

examples/colors.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
REM From the ZX Spectrum 48K Manual
2+
CLS
23

34
DIM m, n, c AS BYTE
45

@@ -16,4 +17,3 @@ FOR c = 4 TO 7
1617
INK c: PRINT c; " ";
1718
NEXT c: NEXT m
1819
PAPER 7: INK 0: BRIGHT 0
19-

src/arch/zx48k/library-asm/attr.asm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ SET_ATTR:
3838
call __IN_SCREEN
3939
ret nc
4040

41+
call __ATTR_ADDR
42+
4143
__SET_ATTR:
4244
; Internal __FASTCALL__ Entry used by printing routines
45+
; HL contains the address of the ATTR cell to set
4346
PROC
4447

45-
call __ATTR_ADDR
46-
4748
__SET_ATTR2: ; Sets attr from ATTR_T to (HL) which points to the scr address
4849
ld de, (ATTR_T) ; E = ATTR_T, D = MASK_T
4950

src/arch/zx48k/library-asm/print.asm

Lines changed: 76 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@ __PRINT_INIT: ; To be called before program starts (initializes library)
2929
ld hl, __PRINT_START
3030
ld (PRINT_JUMP_STATE), hl
3131

32-
ld hl, 1821h
32+
ld hl, 1820h
3333
ld (MAXX), hl ; Sets current maxX and maxY
3434

35-
call __LOAD_S_POSN
36-
call __ATTR_ADDR
37-
3835
xor a
3936
ld (FLAGS2), a
4037

41-
ret
42-
43-
38+
LOCAL SET_SCR_ADDR
39+
SET_SCR_ADDR:
4440

41+
call __LOAD_S_POSN
42+
jp __SAVE_S_POSN
4543

4644
__PRINTCHAR: ; Print character store in accumulator (A register)
4745
; Modifies H'L', B'C', A'F', D'E', A
@@ -78,46 +76,39 @@ __SCROLL: ; Scroll?
7876
#endif
7977

8078
__PRINT_START:
81-
cp ' '
82-
jr c, __PRINT_SPECIAL ; Characters below ' ' are special ones
83-
8479
exx ; Switch to alternative registers
8580
ex af, af' ; Saves a value (char to print) for later
8681

87-
#ifndef DISABLE_SCROLL
88-
call __SCROLL
89-
#endif
90-
call __LOAD_S_POSN
91-
92-
; At this point we have the new coord
93-
ld hl, (SCREEN_ADDR)
94-
95-
ld a, d
96-
ld c, a ; Saves it for later
97-
98-
and 0F8h ; Masks 3 lower bit ; zy
99-
ld d, a
100-
101-
ld a, c ; Recovers it
102-
and 07h ; MOD 7 ; y1
103-
rrca
104-
rrca
105-
rrca
106-
107-
or e
108-
ld e, a
109-
add hl, de ; HL = Screen address + DE
110-
ex de, hl ; DE = Screen address
111-
112-
ex af, af'
82+
ld hl, (S_POSN)
83+
dec l
84+
jr nz, 1f
85+
ld a, (MAXX)
86+
ld l, a
87+
dec h
88+
jr nz, 2f
89+
inc h
90+
push hl
91+
call __ROM_SCROLL_SCR
92+
pop hl
93+
2:
94+
ld (S_POSN), hl
95+
call SET_SCR_ADDR
96+
jr __PRINT_CHR
97+
1:
98+
ld (S_POSN), hl
99+
100+
__PRINT_CHR:
101+
ex af, af' ; Recovers char to print
102+
cp ' '
103+
jr c, __PRINT_SPECIAL ; Characters below ' ' are special ones
113104

114105
cp 80h ; Is it an UDG or a ?
115106
jr c, __SRCADDR
116107

117108
cp 90h
118109
jr nc, __PRINT_UDG
119110

120-
; Print a 8 bit pattern (80h to 8Fh)
111+
; Print an 8 bit pattern (80h to 8Fh)
121112

122113
ld b, a
123114
call PO_GR_1 ; This ROM routine will generate the bit pattern at MEM0
@@ -129,7 +120,7 @@ PO_GR_1 EQU 0B38h
129120
__PRINT_UDG:
130121
sub 90h ; Sub ASC code
131122
ld bc, (UDG)
132-
jp __PRGRAPH0
123+
jr __PRGRAPH0
133124

134125
__SOURCEADDR EQU (__SRCADDR + 1) ; Address of the pointer to chars source
135126
__SRCADDR:
@@ -150,15 +141,19 @@ __PRGRAPH:
150141
bit 4, (iy + $47)
151142
call nz, __ITALIC
152143
ld b, 8 ; 8 bytes per char
144+
145+
ld hl, (DFCC)
146+
push hl
147+
153148
__PRCHAR:
154-
ld a, (de) ; DE *must* be ALWAYS source, and HL destiny
149+
ld a, (de) ; DE *must* be source, and HL destiny
155150

156151
PRINT_MODE: ; Which operation is used to write on the screen
157152
; Set it with:
158153
; LD A, <OPERATION>
159154
; LD (PRINT_MODE), A
160155
;
161-
; Available opertions:
156+
; Available operations:
162157
; NORMAL : 0h --> NOP ; OVER 0
163158
; XOR : AEh --> XOR (HL) ; OVER 1
164159
; OR : B6h --> OR (HL) ; PUTSPRITE
@@ -174,20 +169,18 @@ INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
174169
inc h ; Next line
175170
djnz __PRCHAR
176171

177-
call __LOAD_S_POSN
178-
push de
172+
pop hl
173+
inc hl
174+
ld (DFCC), hl
175+
176+
ld hl, (DFCCL) ; current ATTR Pos
177+
push hl
179178
call __SET_ATTR
180-
pop de
181-
inc e ; COL = COL + 1
182-
ld hl, (MAXX)
183-
ld a, e
184-
dec l ; l = MAXX
185-
cp l ; Lower than max?
186-
jp nc, __PRINT_EOL1
179+
pop hl
180+
inc hl
181+
ld (DFCCL),hl
187182

188183
__PRINT_CONT:
189-
call __SAVE_S_POSN
190-
191184
__PRINT_CONT2:
192185
exx
193186
ret
@@ -204,35 +197,28 @@ PRINT_EOL: ; Called WHENEVER there is no ";" at end of PRINT sentence
204197
exx
205198

206199
__PRINT_0Dh: ; Called WHEN printing CHR$(13)
207-
#ifndef DISABLE_SCROLL
208-
call __SCROLL
209-
#endif
210-
call __LOAD_S_POSN
200+
ld hl, (S_POSN)
211201

212202
__PRINT_EOL1: ; Another entry called from PRINT when next line required
213-
ld e, 0
203+
ld a, (MAXX)
204+
ld l, a
214205

215206
__PRINT_EOL2:
216-
ld a, d
217-
inc a
207+
dec h
208+
jr nz, __PRINT_EOL_END
218209

219-
__PRINT_AT1_END:
220-
ld hl, (MAXY)
221-
cp l
222-
jr c, __PRINT_EOL_END ; Carry if (MAXY) < d
223210
#ifndef DISABLE_SCROLL
224-
ld hl, TVFLAGS
225-
set 1, (hl)
226-
dec a
211+
inc h
212+
push hl
213+
call __ROM_SCROLL_SCR
214+
pop hl
227215
#else
228-
xor a
216+
ld hl, (MAXX)
229217
#endif
230218

231219
__PRINT_EOL_END:
232-
ld d, a
233-
234-
__PRINT_AT2_END:
235-
call __SAVE_S_POSN
220+
ld (S_POSN), hl
221+
call SET_SCR_ADDR
236222
exx
237223
ret
238224

@@ -270,13 +256,13 @@ __PRINT_TAB2:
270256
pop hl
271257
ret
272258

259+
__PRINT_AT:
260+
ld hl, __PRINT_AT1
261+
jr __PRINT_SET_STATE
262+
273263
__PRINT_NOP:
274264
__PRINT_RESTART:
275265
ld hl, __PRINT_START
276-
jr __PRINT_SET_STATE
277-
278-
__PRINT_AT:
279-
ld hl, __PRINT_AT1
280266

281267
__PRINT_SET_STATE:
282268
ld (PRINT_JUMP_STATE), hl ; Saves next entry call
@@ -285,38 +271,41 @@ __PRINT_SET_STATE:
285271

286272
__PRINT_AT1: ; Jumps here if waiting for 1st parameter
287273
exx
274+
ld hl, (S_POSN)
275+
ld a, (MAXY)
276+
sub h
277+
ld (S_POSN + 1), a
278+
288279
ld hl, __PRINT_AT2
289-
ld (PRINT_JUMP_STATE), hl ; Saves next entry call
290-
call __LOAD_S_POSN
291-
jr __PRINT_AT1_END
280+
jr __PRINT_SET_STATE
292281

293282
__PRINT_AT2:
294283
exx
295284
ld hl, __PRINT_START
296285
ld (PRINT_JUMP_STATE), hl ; Saves next entry call
297-
call __LOAD_S_POSN
298-
ld e, a
299-
ld hl, (MAXX)
300-
cp l
301-
jr c, __PRINT_AT2_END
302-
jr __PRINT_EOL1
286+
ld hl, (S_POSN)
287+
ld a, (MAXX)
288+
sub l
289+
ld l, a
290+
jr __PRINT_EOL_END
303291

304292
__PRINT_DEL:
305293
call __LOAD_S_POSN ; Gets current screen position
306294
dec e
307295
ld a, -1
308296
cp e
309-
jp nz, __PRINT_AT2_END
297+
jr nz, 3f
310298
ld hl, (MAXX)
311299
ld e, l
312300
dec e
313-
dec e
314301
dec d
315302
cp d
316-
jp nz, __PRINT_AT2_END
303+
jr nz, 3f
317304
ld d, h
318305
dec d
319-
jp __PRINT_AT2_END
306+
3:
307+
call __SAVE_S_POSN
308+
jr __PRINT_RESTART
320309

321310
__PRINT_INK:
322311
ld hl, __PRINT_INK2
@@ -390,7 +379,6 @@ __PRINT_ITA2:
390379
call ITALIC_TMP
391380
jp __PRINT_RESTART
392381

393-
394382
__BOLD:
395383
push hl
396384
ld hl, MEM0
@@ -493,7 +481,6 @@ PRINT_AT: ; Changes cursor to ROW, COL
493481
LOCAL __PRINT_EOL2
494482
LOCAL __PRINT_AT1
495483
LOCAL __PRINT_AT2
496-
LOCAL __PRINT_AT2_END
497484
LOCAL __PRINT_BOLD
498485
LOCAL __PRINT_BOLD2
499486
LOCAL __PRINT_ITA

src/arch/zx48k/library-asm/sposn.asm

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,55 @@
11
#include once <sysvars.asm>
2+
#include once <attr.asm>
23

34
; Printing positioning library.
45
push namespace core
56

7+
; Loads into DE current ROW, COL print position from S_POSN mem var.
8+
__LOAD_S_POSN:
69
PROC
710

8-
__LOAD_S_POSN: ; Loads into DE current ROW, COL print position from S_POSN mem var.
911
ld de, (S_POSN)
1012
ld hl, (MAXX)
1113
or a
1214
sbc hl, de
1315
ex de, hl
1416
ret
1517

18+
ENDP
19+
20+
21+
; Saves ROW, COL from DE into S_POSN mem var.
22+
__SAVE_S_POSN:
23+
PROC
1624

17-
__SAVE_S_POSN: ; Saves ROW, COL from DE into S_POSN mem var.
1825
ld hl, (MAXX)
1926
or a
2027
sbc hl, de
2128
ld (S_POSN), hl ; saves it again
29+
30+
push de
31+
call __ATTR_ADDR
32+
ld (DFCCL), hl
33+
pop de
34+
35+
ld a, d
36+
ld c, a ; Saves it for later
37+
38+
and 0F8h ; Masks 3 lower bit ; zy
39+
ld d, a
40+
41+
ld a, c ; Recovers it
42+
and 07h ; MOD 7 ; y1
43+
rrca
44+
rrca
45+
rrca
46+
47+
or e
48+
ld e, a
49+
50+
ld hl, (SCREEN_ADDR)
51+
add hl, de ; HL = Screen address + DE
52+
ld (DFCC), hl
2253
ret
2354

2455
ENDP

0 commit comments

Comments
 (0)