Skip to content

Commit 77e1bee

Browse files
committed
feat: add getPaintData and getChars functions
These does the opposite of putChars() and paint() functions.
1 parent 069b9f3 commit 77e1bee

File tree

3 files changed

+576
-9
lines changed

3 files changed

+576
-9
lines changed

src/lib/arch/zx48k/stdlib/putchars.bas

Lines changed: 201 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,139 @@ BLPutCharsEnd:
148148
END SUB
149149

150150

151+
' ----------------------------------------------------------------
152+
' SUB getChars
153+
'
154+
' Gets a rectangle region of the screen into many chars (opposite of putChars)
155+
'
156+
' Parameters:
157+
' x - x coordinate (cell column)
158+
' y - y coordinate (cell row)
159+
' width - width (number of columns)
160+
' height - height (number of rows)
161+
' dataAddress - Chars bytes address
162+
'
163+
' ----------------------------------------------------------------
164+
SUB getChars(x as uByte,y as uByte, width as uByte, height as uByte, dataAddress as uInteger)
165+
' Copyleft Conrado Badenas Feel free to use as you will. Please attribute me if you use this, however!
166+
167+
Asm
168+
PROC
169+
LOCAL BLGetChar, BLGetCharColumnLoop, BLGetCharInColumnLoop, BLGetCharSameThird
170+
LOCAL BLGetCharNextThird, BLGetCharNextColumn, BLGetCharsEnd
171+
172+
BLGetChar:
173+
ld a,(ix+5)
174+
ld l,a
175+
ld a,(ix+7) ; Y value
176+
ld d,a
177+
and 24
178+
ld h,a
179+
ld a,d
180+
and 7
181+
rrca
182+
rrca
183+
rrca
184+
or l
185+
ld l,a
186+
187+
push hl ; save our address
188+
ld e,(ix+12) ; data address
189+
ld d,(ix+13)
190+
ld b,(ix+9) ; width
191+
push bc ; save our column count
192+
193+
BLGetCharColumnLoop:
194+
ld b, (ix+11) ; height
195+
196+
BLGetCharInColumnLoop:
197+
198+
push hl
199+
push de
200+
ld de, (.core.SCREEN_ADDR)
201+
add hl, de ;Adds the offset to the screen att address
202+
pop de
203+
204+
; gets screen address in HL, and bytes address in DE. Copies the 8 bytes from the screen
205+
ld a,(hl) ; First Row
206+
ld (de),a
207+
208+
inc de
209+
inc h
210+
ld a,(hl)
211+
ld (de),a ; second Row
212+
213+
inc de
214+
inc h
215+
ld a,(hl)
216+
ld (de),a ; Third Row
217+
218+
inc de
219+
inc h
220+
ld a,(hl)
221+
ld (de),a ; Fourth Row
222+
223+
inc de
224+
inc h
225+
ld a,(hl)
226+
ld (de),a ; Fifth Row
227+
228+
inc de
229+
inc h
230+
ld a,(hl)
231+
ld (de),a ; Sixth Row
232+
233+
inc de
234+
inc h
235+
ld a,(hl)
236+
ld (de),a ; Seventh Row
237+
238+
inc de
239+
inc h
240+
ld a,(hl)
241+
ld (de),a ; Eighth Row
242+
243+
pop hl
244+
inc de ; Move to next data item.
245+
dec b
246+
jr z, BLGetCharNextColumn
247+
248+
;The following code calculates the address of the next line down below current HL address.
249+
push de ; save DE
250+
ld a,l
251+
and 224
252+
cp 224
253+
jr z,BLGetCharNextThird
254+
255+
BLGetCharSameThird:
256+
ld de,32
257+
add hl,de
258+
pop de ; get our data point back.
259+
jp BLGetCharInColumnLoop
260+
261+
BLGetCharNextThird:
262+
ld de,1824
263+
add hl,de
264+
pop de ; get our data point back.
265+
jp BLGetCharInColumnLoop
266+
267+
BLGetCharNextColumn:
268+
pop bc
269+
pop hl
270+
dec b
271+
jr z, BLGetCharsEnd
272+
273+
inc l ; Note this would normally be Increase HL - but block painting should never need to increase H, since that would wrap around.
274+
push hl
275+
push bc
276+
jp BLGetCharColumnLoop
277+
278+
BLGetCharsEnd:
279+
ENDP
280+
End Asm
281+
END SUB
282+
283+
151284
' ----------------------------------------------------------------
152285
' SUB Paint
153286
'
@@ -281,6 +414,74 @@ BLPaintDataHeightExitLoop:
281414
END SUB
282415

283416

417+
' ----------------------------------------------------------------
418+
' SUB getPaintData
419+
'
420+
' Gets the colors of a rectangle region of the screen into memory (opposite of paintData)
421+
'
422+
' Parameters:
423+
' x - x coordinate (cell column)
424+
' y - y coordinate (cell row)
425+
' width - width (number of columns)
426+
' height - height (number of rows)
427+
' address - address of the byte-encoded attr sequence
428+
'
429+
' ----------------------------------------------------------------
430+
SUB getPaintData(x as uByte,y as uByte, width as uByte, height as uByte, address as uInteger)
431+
REM Copyleft Conrado Badenas. Feel free to use as you will. Please attribute me if you use this, however!
432+
433+
Asm
434+
PROC
435+
LOCAL BLGetPaintDataHeightLoop, BLGetPaintDataWidthLoop, BLGetPaintDataWidthExitLoop, BLGetPaintDataHeightExitLoop
436+
437+
ld a,(ix+7) ;ypos
438+
rrca
439+
rrca
440+
rrca ; Multiply by 32
441+
ld l,a ; Pass to L
442+
and 3 ; Mask with 00000011
443+
ld h,a ; Put it in the High Byte
444+
ld a,l ; We get y value *32
445+
and 224 ; Mask with 11100000
446+
ld l,a ; Put it in L
447+
ld a,(ix+5) ; xpos
448+
add a,l ; Add it to the Low byte
449+
ld l,a ; Put it back in L, and we're done. HL=Address.
450+
ld de,(.core.SCREEN_ATTR_ADDR)
451+
add hl, de ;Adds the offset to the screen att address
452+
453+
push hl ; save address
454+
ld d,(ix+13)
455+
ld e,(ix+12)
456+
ld c,(ix+11) ; height
457+
458+
BLGetPaintDataHeightLoop:
459+
ld b,(ix+9) ; width
460+
461+
BLGetPaintDataWidthLoop:
462+
ld a,(hl)
463+
ld (de),a ; paint a character
464+
inc hl
465+
inc de
466+
djnz BLGetPaintDataWidthLoop
467+
468+
BLGetPaintDataWidthExitLoop:
469+
pop hl ; recover our left edge
470+
dec c
471+
jr z, BLGetPaintDataHeightExitLoop
472+
push de
473+
ld de,32
474+
add hl,de ; move 32 down
475+
pop de
476+
push hl ; save it again
477+
jp BLGetPaintDataHeightLoop
478+
479+
BLGetPaintDataHeightExitLoop:
480+
ENDP
481+
End Asm
482+
END SUB
483+
484+
284485
' ----------------------------------------------------------------
285486
' SUB putCharsOverMode
286487
'
@@ -464,4 +665,3 @@ END SUB
464665
#pragma pop(case_insensitive)
465666

466667
#endif
467-

0 commit comments

Comments
 (0)