Skip to content

Commit 1d2fee0

Browse files
committed
feat: make DRAW to use the screen buffer
Also make cosmetic changes in DRAW3 routine.
1 parent c7665f6 commit 1d2fee0

23 files changed

Lines changed: 498 additions & 321 deletions

src/arch/zx48k/library-asm/SP/PixelDown.asm

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,41 @@
1717
push namespace core
1818

1919
SP.PixelDown:
20+
PROC
21+
LOCAL leave
22+
23+
push de
24+
ld de, (SCREEN_ADDR)
25+
or a
26+
sbc hl, de
2027
inc h
2128
ld a,h
2229
and $07
23-
ret nz
24-
ex af, af' ; Sets carry on F'
25-
scf ; which flags ATTR must be updated
30+
jr nz, leave
31+
scf ; Sets carry on F', which flags ATTR must be updated
2632
ex af, af'
2733
ld a,h
2834
sub $08
2935
ld h,a
3036
ld a,l
3137
add a,$20
3238
ld l,a
33-
ret nc
39+
jr nc, leave
3440
ld a,h
3541
add a,$08
3642
ld h,a
37-
;IF DISP_HIRES
38-
; and $18
39-
; cp $18
40-
;ELSE
41-
cp $58
42-
;ENDIF
43+
cp $19 ; carry = 0 => Out of screen
44+
jr c, leave ; returns if out of screen
4345
ccf
46+
pop de
47+
ret
48+
49+
leave:
50+
add hl, de ; This always sets Carry = 0
51+
pop de
4452
ret
4553

54+
ENDP
4655
pop namespace
56+
57+
#include once <sysvars.asm>

src/arch/zx48k/library-asm/SP/PixelLeft.asm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,33 @@
2020
push namespace core
2121

2222
SP.PixelLeft:
23+
PROC
24+
25+
LOCAL leave
26+
27+
push de
28+
ld de, (SCREEN_ADDR)
29+
or a
30+
sbc hl, de ; This always sets Carry = 0
31+
2332
rlca ; Sets new pixel bit 1 to the right
24-
ret nc
33+
jr nc, leave
2534
ex af, af' ; Signal in C' we've moved off current ATTR cell
2635
ld a,l
2736
dec a
2837
ld l,a
2938
cp 32 ; Carry if in screen
3039
ccf
3140
ld a, 1
41+
42+
leave: ; Sets screen offset back again
43+
push af
44+
add hl, de
45+
pop af
46+
pop de
3247
ret
3348

49+
ENDP
3450
pop namespace
3551

52+
#include once <sysvars.asm>

src/arch/zx48k/library-asm/SP/PixelRight.asm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,33 @@
2121
push namespace core
2222

2323
SP.PixelRight:
24+
PROC
25+
26+
LOCAL leave
27+
28+
push de
29+
ld de, (SCREEN_ADDR)
30+
or a
31+
sbc hl, de ; This always sets Carry = 0
32+
2433
rrca ; Sets new pixel bit 1 to the right
25-
ret nc
34+
jr nc, leave
2635
ex af, af' ; Signal in C' we've moved off current ATTR cell
2736
ld a, l
2837
inc a
2938
ld l, a
3039
cp 32 ; Carry if IN screen
3140
ccf
3241
ld a, 80h
42+
43+
leave: ; Sets screen offset back again
44+
push af
45+
add hl, de
46+
pop af
47+
pop de
3348
ret
3449

50+
ENDP
3551
pop namespace
3652

53+
#include once <sysvars.asm>

src/arch/zx48k/library-asm/SP/PixelUp.asm

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,41 @@
1616
push namespace core
1717

1818
SP.PixelUp:
19+
PROC
20+
21+
LOCAL leave
22+
23+
push de
24+
ld de, (SCREEN_ADDR)
25+
or a
26+
sbc hl, de
27+
1928
ld a,h
2029
dec h
2130
and $07
22-
ret nz
23-
ex af, af'
24-
scf
31+
jr nz, leave
32+
scf ; sets C' to 1 (ATTR update needed)
2533
ex af, af'
2634
ld a,$08
2735
add a,h
2836
ld h,a
2937
ld a,l
3038
sub $20
3139
ld l,a
32-
ret nc
40+
jr nc, leave
3341
ld a,h
3442
sub $08
3543
ld h,a
36-
;IF DISP_HIRES
37-
; and $18
38-
; cp $18
39-
; ccf
40-
;ELSE
41-
cp $40
42-
;ENDIF
44+
45+
leave:
46+
push af
47+
add hl, de
48+
pop af
49+
pop de
4350
ret
4451

52+
ENDP
53+
4554
pop namespace
55+
56+
#include once <sysvars.asm>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ __DRAW_START:
100100
LOCAL __PIXEL_ADDR
101101
__PIXEL_ADDR EQU 22ACh
102102
call __PIXEL_ADDR
103+
res 6, h ; Starts from 0 offset
103104

104105
;; Now gets pixel mask in A register
105106
ld b, a
@@ -112,12 +113,15 @@ __PIXEL_MASK:
112113
djnz __PIXEL_MASK
113114

114115
ld b, d ; Restores B' from D'
116+
ld de, (SCREEN_ADDR)
117+
add hl, de
115118
pop de ; D'E' = y2, x2
116119
exx ; At this point: D'E' = y2,x2 coords
117120
; B'C' = y1, y1 coords
121+
; H'L' = Screen Address of pixel
122+
118123
ex af, af' ; Saves A reg for later
119124
; A' = Pixel mask
120-
; H'L' = Screen Address of pixel
121125

122126
ld bc, (COORDS) ; B,C = y1, x1
123127

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include once <plot.asm>
1212
#include once <stackf.asm>
1313
#include once <draw.asm>
14+
#include once <sysvars.asm>
1415

1516
; Ripped from the ZX Spectrum ROM
1617

@@ -20,7 +21,6 @@ DRAW3:
2021
PROC
2122
LOCAL STACK_TO_BC
2223
LOCAL STACK_TO_A
23-
LOCAL COORDS
2424
LOCAL L2477
2525
LOCAL L2420
2626
LOCAL L2439
@@ -30,7 +30,6 @@ DRAW3:
3030
LOCAL SUM_C, SUM_B
3131

3232
L2D28 EQU 02D28h
33-
COORDS EQU 5C7Dh
3433
STACK_TO_BC EQU 2307h
3534
STACK_TO_A EQU 2314h
3635

@@ -262,7 +261,7 @@ L23C1: CALL 247Dh ; routine CD-PRMS1
262261
POP BC ; Balance the machine stack
263262

264263
JP C,L2477 ; forward, if the coordinates of first line
265-
; don't add up to more than 1, to LINE-DRAW
264+
; don't add up to more than 1, to LINE-DRAW
266265

267266
; Continue when the arc will have a discernable shape.
268267

@@ -319,7 +318,8 @@ L23C1: CALL 247Dh ; routine CD-PRMS1
319318
; the jump will always be made to ARC-START.
320319

321320
;; DRW-STEPS
322-
L2420: DEC B ; decrement the arc count (4,8,12,16...).
321+
L2420:
322+
DEC B ; decrement the arc count (4,8,12,16...).
323323

324324
;JR Z,L245F ; forward, if zero (not possible), to ARC-END
325325

@@ -353,7 +353,8 @@ L2420: DEC B ; decrement the arc count (4,8,12,16...).
353353
; the formula returns the next relative coordinates to use.
354354

355355
;; ARC-LOOP
356-
L2425: RST 28H ;; FP-CALC
356+
L2425:
357+
RST 28H ;; FP-CALC
357358
DEFB $E1 ;;get-mem-1 rx.
358359
DEFB $31 ;;duplicate rx, rx.
359360
DEFB $E3 ;;get-mem-3 cos(a)
@@ -394,7 +395,8 @@ L2425: RST 28H ;; FP-CALC
394395
; The mid entry point.
395396

396397
;; ARC-START
397-
L2439: PUSH BC ; Preserve the arc counter on the machine stack.
398+
L2439:
399+
PUSH BC ; Preserve the arc counter on the machine stack.
398400

399401
; Store the absolute ay in temporary variable mem-0 for the moment.
400402

@@ -456,15 +458,16 @@ L2439: PUSH BC ; Preserve the arc counter on the machine stack.
456458
; can be deleted to expose the closing coordinates.
457459

458460
;; ARC-END
459-
L245F: RST 28H ;; FP-CALC tx, ty, ax, ay.
461+
L245F:
462+
RST 28H ;; FP-CALC tx, ty, ax, ay.
460463
DEFB $02 ;;delete tx, ty, ax.
461464
DEFB $02 ;;delete tx, ty.
462465
DEFB $01 ;;exchange ty, tx.
463466
DEFB $38 ;;end-calc ty, tx.
464467

465468
; First calculate the relative x coordinate to the end-point.
466469

467-
LD A,($5C7D) ; COORDS-x
470+
LD A,(COORDS) ; COORDS-x
468471
CALL L2D28 ; routine STACK-A
469472

470473
RST 28H ;; FP-CALC ty, tx, coords_x.
@@ -475,7 +478,7 @@ L245F: RST 28H ;; FP-CALC tx, ty, ax, ay.
475478
DEFB $01 ;;exchange rx, ty.
476479
DEFB $38 ;;end-calc rx, ty.
477480

478-
LD A,($5C7E) ; COORDS-y
481+
LD A,(COORDS + 1) ; COORDS-y
479482
CALL L2D28 ; routine STACK-A
480483

481484
RST 28H ;; FP-CALC rx, ty, coords_y

src/arch/zxnext/library-asm/SP/GetScrnAddr.asm

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
; Alvin Albrecht 2002
44
;
55

6-
;INCLUDE "SPconfig.def"
7-
;XLIB SPGetScrnAddr
8-
96
; Get Screen Address
107
;
118
; Computes the screen address given a valid pixel coordinate.
@@ -17,14 +14,13 @@
1714
; exit : de = screen address, b = pixel mask
1815
; uses : af, b, de, hl
1916

20-
;IF !DISP_HIRES
21-
2217
push namespace core
18+
PROC
19+
LOCAL rotloop, norotate
2320

2421
SPGetScrnAddr:
2522
ld a,h
2623
and $07
27-
or $40
2824
ld d,a
2925
ld a,h
3026
rra
@@ -55,57 +51,12 @@ norotate:
5551
and $e0
5652
or l
5753
ld e,a
54+
ld hl, (SCREEN_ADDR)
55+
add hl, de
56+
ex de, hl
5857
ret
5958

59+
ENDP
6060
pop namespace
6161

62-
63-
;ELSE
64-
;
65-
;.SPGetScrnAddr
66-
; ld b,0
67-
; ld d,b
68-
; rr l
69-
; rl b
70-
; srl l
71-
; rl b
72-
; srl l
73-
; rl b
74-
; srl l
75-
; jr nc, notodd
76-
; ld d,$20
77-
;
78-
;.notodd
79-
; ld a,b
80-
; or a
81-
; ld a,$80
82-
; jr z, norotate
83-
;
84-
;.rotloop
85-
; rra
86-
; djnz rotloop
87-
88-
;.norotate
89-
; ld b,a
90-
; ld a,h
91-
; and $07
92-
; or $40
93-
; or d
94-
; ld d,a
95-
; ld a,h
96-
; rra
97-
; rra
98-
; rra
99-
; and $18
100-
; or d
101-
; ld d,a
102-
;
103-
; ld a,h
104-
; rla
105-
; rla
106-
; and $e0
107-
; or l
108-
; ld e,a
109-
; ret
110-
111-
;ENDIF
62+
#include once <sysvars.asm>

0 commit comments

Comments
 (0)