Skip to content

Commit e0fd1e7

Browse files
committed
reused gfy_FillCircle to implement gfy_FillCircle_NoClip for now, copied updates to graphx, and cleaned up unused functions
1 parent dc7d2b9 commit e0fd1e7

File tree

2 files changed

+333
-240
lines changed

2 files changed

+333
-240
lines changed

src/graphy/graphy.asm

Lines changed: 187 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,8 +1432,8 @@ _Ellipse:
14321432
ld (ix - el_comp_a),hl
14331433
inc hl
14341434
sbc hl,bc
1435-
ld bc,(ix - el_a2)
1436-
call _MultiplyHLBC
1435+
ld de,(ix - el_a2)
1436+
call _MultiplyHLDE
14371437
ld bc,(ix - el_b2)
14381438
add hl,bc
14391439
add hl,bc
@@ -1446,13 +1446,13 @@ _Ellipse:
14461446
sbc hl,hl
14471447
inc hl
14481448
sbc hl,de
1449-
ld bc,(ix - el_fb2)
1450-
call _MultiplyHLBC
1449+
ld de,(ix - el_fb2)
1450+
call _MultiplyHLDE
14511451
ld (ix - el_sigma_2),hl ; int sigma_add_2 = fb2 * (1 - a);
14521452

14531453
ld hl,(ix - el_a2)
1454-
ld bc,(ix - el_y)
1455-
call _MultiplyHLBC
1454+
ld de,(ix - el_y)
1455+
call _MultiplyHLDE
14561456
ld (ix - el_comp_b),hl
14571457
14581458
wait_quick
@@ -1525,16 +1525,16 @@ _ellipse_loop_draw_2 := $-3
15251525
mlt de
15261526
inc hl
15271527
sbc hl,de
1528-
ld bc,(ix - el_b2)
1529-
call _MultiplyHLBC
1528+
ld de,(ix - el_b2)
1529+
call _MultiplyHLDE
15301530
ld de,(ix - el_a2)
15311531
add hl,de
15321532
add hl,de
15331533
ld (ix - el_sigma), hl
15341534

15351535
ld hl,(ix - el_b2)
1536-
ld bc,(ix - el_temp1)
1537-
call _MultiplyHLBC
1536+
ld de,(ix - el_temp1)
1537+
call _MultiplyHLDE
15381538
ld (ix - el_comp_b),hl
15391539

15401540
.main_loop2:
@@ -1944,6 +1944,7 @@ gfy_FillCircle: ; MODIFIED_FROM_GRAPHX
19441944
;-------------------------------------------------------------------------------
19451945
; not working at the moment
19461946
if 0
1947+
19471948
fcnc_x := 6
19481949
fcnc_y := 9
19491950
_FillCircle_NoClip:
@@ -2074,6 +2075,139 @@ gfy_FillCircle_NoClip: ; MODIFIED_FROM_GRAPHX
20742075
sbc hl, bc ; HL = 1 - BC
20752076
call gfy_Wait
20762077
jr _FillCircle_NoClip.loop
2078+
2079+
else
2080+
2081+
_FillCircle_NoClip:
2082+
.fillsectors:
2083+
ld hl,(ix-3)
2084+
add hl,hl
2085+
inc hl
2086+
ld (.circle0),hl
2087+
push hl ; len
2088+
ld bc,(ix-3)
2089+
ld hl, (ix + fc_x)
2090+
or a,a
2091+
sbc hl,bc
2092+
ld (.circle1),hl
2093+
push hl ; x
2094+
ld bc,(ix-6)
2095+
ld hl, (ix + fc_y)
2096+
add hl,bc
2097+
push hl ; y
2098+
call gfy_VertLine_NoClip
2099+
ld hl,0
2100+
.circle0 := $-3
2101+
push hl ; len
2102+
ld hl,0
2103+
.circle1 := $-3
2104+
push hl ; x
2105+
ld bc,(ix-6)
2106+
ld hl, (ix + fc_y)
2107+
or a,a
2108+
sbc hl,bc
2109+
push hl ; y
2110+
call gfy_VertLine_NoClip
2111+
ld hl,(ix-6)
2112+
add hl,hl
2113+
inc hl
2114+
ld (.circle2),hl
2115+
push hl ; len
2116+
ld bc,(ix-6)
2117+
ld hl, (ix + fc_x)
2118+
or a,a
2119+
sbc hl,bc
2120+
ld (.circle3),hl
2121+
push hl ; x
2122+
ld bc,(ix-3)
2123+
ld hl, (ix + fc_y)
2124+
add hl,bc
2125+
push hl ; y
2126+
call gfy_VertLine_NoClip
2127+
ld hl,0
2128+
.circle2 := $-3
2129+
push hl ; len
2130+
ld hl,0
2131+
.circle3 := $-3
2132+
push hl ; x
2133+
ld bc,(ix-3)
2134+
ld hl, (ix + fc_y)
2135+
or a,a
2136+
sbc hl,bc
2137+
push hl ; y
2138+
call gfy_VertLine_NoClip
2139+
lea hl,ix-9
2140+
ld sp,hl
2141+
ld bc,(ix-3)
2142+
inc bc
2143+
ld (ix-3),bc
2144+
ld bc,(ix-9)
2145+
or a,a
2146+
sbc hl,hl
2147+
sbc hl,bc
2148+
jp m,.cmp0
2149+
jp pe,.cmp2
2150+
jr .cmp1
2151+
.cmp0:
2152+
jp po,.cmp2
2153+
.cmp1:
2154+
ld hl,(ix-3)
2155+
add hl,hl
2156+
inc hl
2157+
add hl,bc
2158+
jr .cmp3
2159+
.cmp2:
2160+
ld bc,(ix-6)
2161+
dec bc
2162+
ld (ix-6),bc
2163+
ld hl,(ix-3)
2164+
ld de,(ix-9)
2165+
or a,a
2166+
sbc hl,bc
2167+
add hl,hl
2168+
inc hl
2169+
add hl,de
2170+
.cmp3:
2171+
ld (ix-9),hl
2172+
ld bc,(ix-3)
2173+
ld hl,(ix-6)
2174+
or a,a
2175+
sbc hl,bc
2176+
jp p,.check
2177+
jp pe,.fillsectors
2178+
ld sp,ix
2179+
pop ix
2180+
ret
2181+
.check:
2182+
jp po,.fillsectors
2183+
.ResetStack:
2184+
ld sp,ix
2185+
pop ix
2186+
ret
2187+
; reuse the implementation from gfy_FillCircle for now
2188+
gfy_FillCircle_NoClip: ; MODIFIED_FROM_GRAPHX
2189+
; Draws an clipped circle
2190+
; Arguments:
2191+
; arg0 : X coordinate
2192+
; arg1 : Y coordinate
2193+
; arg2 : Radius
2194+
; Returns:
2195+
; None
2196+
push ix
2197+
ld ix, 0
2198+
add ix, sp
2199+
lea hl, ix - 9
2200+
ld sp, hl
2201+
ld bc, (ix + 12)
2202+
sbc hl, hl
2203+
adc hl, bc ; carry won't be set since HL is zero here
2204+
jr z, _FillCircle_NoClip.ResetStack
2205+
ld (ix - 6), bc
2206+
sbc hl, hl
2207+
ld (ix - 3), hl
2208+
inc hl
2209+
sbc hl, bc ; HL = 1 - BC
2210+
jr _FillCircle_NoClip.cmp3
20772211
end if
20782212

20792213
;-------------------------------------------------------------------------------
@@ -3872,15 +4006,15 @@ end if
38724006
ld hl, (ix - 12)
38734007
or a, a
38744008
sbc hl, bc
3875-
ld bc, (ix - 30)
3876-
call _MultiplyHLBC ; sa = dx12 * (y - y1);
4009+
ld de, (ix - 30)
4010+
call _MultiplyHLDE ; sa = dx12 * (y - y1);
38774011
ld (ix - 15), hl
38784012
ld bc, (ix + ft_y0)
38794013
ld hl, (ix - 12)
38804014
or a, a
38814015
sbc hl, bc
3882-
ld bc, (ix - 21)
3883-
call _MultiplyHLBC ; sb = dx02 * (y - y0);
4016+
ld de, (ix - 21)
4017+
call _MultiplyHLDE ; sb = dx02 * (y - y0);
38844018
ld (ix - 18), hl
38854019
jp .secondloopstart ; for(; y <= y2; y++)
38864020
.secondloop:
@@ -4785,21 +4919,23 @@ _smc_dsrs_sinf_1: ; smc = sinf
47854919

47864920
getSinCos:
47874921
; returns a = sin/cos(a) * 128
4788-
ld c,a
4789-
bit 7,a
4790-
jr z,$+4
4791-
sub a,128
4792-
bit 6,a
4793-
jr z,$+6
4794-
ld e,a
4795-
ld a,128
4796-
sub a,e
4797-
ld de,0
4798-
ld e,a
4799-
ld hl,_SineTable
4800-
add hl,de
4801-
ld a,(hl)
4802-
bit 7,c
4922+
ld de, $80
4923+
ld c, a
4924+
bit 7, a
4925+
jr z, .bit7
4926+
sub a, e ; sub a, 128
4927+
.bit7:
4928+
bit 6, a
4929+
jr z, .bit6
4930+
; A = 128 - A
4931+
neg
4932+
add a, e ; add a, 128
4933+
.bit6:
4934+
ld e, a
4935+
ld hl, _SineTable
4936+
add hl, de
4937+
ld a, (hl)
4938+
bit 7, c
48034939
ret z
48044940
neg
48054941
ret
@@ -5201,33 +5337,39 @@ _UCDivA: ; COPIED_FROM_GRAPHX
52015337

52025338
;-------------------------------------------------------------------------------
52035339
_DivideHLBC: ; COPIED_FROM_GRAPHX
5204-
; Performs signed integer division
5340+
; Performs signed integer division, rounding towards negative
52055341
; Inputs:
52065342
; HL : Operand 1
52075343
; BC : Operand 2
52085344
; Outputs:
5209-
; HL = HL/BC
5345+
; HL = floor(HL/BC)
5346+
ld a,23
52105347
ex de,hl
5211-
xor a,a
52125348
sbc hl,hl
5349+
ccf
52135350
sbc hl,bc
5214-
jp p,.next0
5351+
jp m,.positive
5352+
add hl,bc
5353+
inc hl
5354+
sbc hl,de
5355+
jp po,.signcheck
5356+
inc a
5357+
jr .overflowed
5358+
.positive:
5359+
inc hl
52155360
push hl
52165361
pop bc
5217-
inc a
5218-
.next0:
5219-
or a,a
5220-
sbc hl,hl
5221-
sbc hl,de
5222-
jp m,.next1
52235362
ex de,hl
5224-
inc a
5225-
.next1:
5226-
add hl,de
5227-
rra
5228-
ld a,24
5363+
.signcheck:
5364+
add hl,hl
5365+
ex de,hl
5366+
sbc hl,hl
5367+
jr nc,.loop
5368+
inc hl
5369+
sbc hl,bc
52295370
.loop:
52305371
ex de,hl
5372+
.overflowed:
52315373
adc hl,hl
52325374
ex de,hl
52335375
adc hl,hl
@@ -5237,13 +5379,8 @@ _DivideHLBC: ; COPIED_FROM_GRAPHX
52375379
.spill:
52385380
dec a
52395381
jr nz,.loop
5240-
52415382
ex de,hl
52425383
adc hl,hl
5243-
ret c
5244-
ex de,hl
5245-
sbc hl,hl
5246-
sbc hl,de
52475384
ret
52485385

52495386
;-------------------------------------------------------------------------------
@@ -5455,8 +5592,6 @@ _SetSmcBytes: ; COPIED_FROM_GRAPHX
54555592
djnz .loop
54565593
ret
54575594

5458-
5459-
54605595
;-------------------------------------------------------------------------------
54615596
; Internal library data
54625597
;-------------------------------------------------------------------------------
@@ -5798,39 +5933,7 @@ __lshru := $0001EC
57985933
; for debugging
57995934
_boot_sprintf := $0000BC
58005935

5801-
__bremu:
5802-
; I: A=dividend, C=divisor
5803-
; O: a=A%C
5804-
push bc
5805-
push hl
5806-
ld b, a
5807-
call __bdvrmu
5808-
ld a, h
5809-
pop hl
5810-
pop bc
5811-
ret
5812-
5813-
__bdvrmu:
5814-
; I: B=dividend, C=divisor
5815-
; O: a=?, b=0, h=B%C, l=B/C
5816-
ld l, b
5817-
.hijack_l_dividend:
5818-
ld h, 0
5819-
ld b, 8
5820-
.loop:
5821-
add hl, hl
5822-
ld a, h
5823-
sub a, c
5824-
jr c, .bit_skip
5825-
ld h, a
5826-
inc l
5827-
.bit_skip:
5828-
djnz .loop
5829-
ret
5830-
5831-
5832-
__indcallhl:
5833-
jp (hl)
5936+
__indcallhl := _indcallHL
58345937

58355938
;-------------------------------------------------------------------------------
58365939
; inlined routines
@@ -5866,16 +5969,6 @@ __set_bc_and_mul_hl_by_240:
58665969
ld bc, 240
58675970
ret
58685971

5869-
__set_bc_and_mul_hl_by_minus2:
5870-
add hl, hl
5871-
push hl
5872-
pop bc
5873-
or a, a
5874-
sbc hl, hl
5875-
sbc hl, bc
5876-
ld bc, -2
5877-
ret
5878-
58795972
_memset:
58805973
ld iy, 0
58815974
add iy, sp

0 commit comments

Comments
 (0)