File tree 1 file changed +21
-24
lines changed
1 file changed +21
-24
lines changed Original file line number Diff line number Diff line change @@ -6401,33 +6401,39 @@ _UCDivA:
6401
6401
6402
6402
;-------------------------------------------------------------------------------
6403
6403
_DivideHLBC:
6404
- ; Performs signed integer division
6404
+ ; Performs signed integer division, rounding towards negative
6405
6405
; Inputs:
6406
6406
; HL : Operand 1
6407
6407
; BC : Operand 2
6408
6408
; Outputs:
6409
- ; HL = HL/BC
6409
+ ; HL = floor(HL/BC)
6410
+ ld a , 23
6410
6411
ex de , hl
6411
- xor a , a
6412
6412
sbc hl , hl
6413
+ ccf
6413
6414
sbc hl , bc
6414
- jp p , .next0
6415
+ jp m , .positive
6416
+ add hl , bc
6417
+ inc hl
6418
+ sbc hl , de
6419
+ jp po , .signcheck
6420
+ inc a
6421
+ jr .overflowed
6422
+ .positive:
6423
+ inc hl
6415
6424
push hl
6416
6425
pop bc
6417
- inc a
6418
- .next0:
6419
- or a , a
6420
- sbc hl , hl
6421
- sbc hl , de
6422
- jp m , .next1
6423
6426
ex de , hl
6424
- inc a
6425
- .next1:
6426
- add hl , de
6427
- rra
6428
- ld a , 24
6427
+ .signcheck:
6428
+ add hl , hl
6429
+ ex de , hl
6430
+ sbc hl , hl
6431
+ jr nc , . loop
6432
+ inc hl
6433
+ sbc hl , bc
6429
6434
. loop :
6430
6435
ex de , hl
6436
+ .overflowed:
6431
6437
adc hl , hl
6432
6438
ex de , hl
6433
6439
adc hl , hl
@@ -6437,17 +6443,8 @@ _DivideHLBC:
6437
6443
.spill:
6438
6444
dec a
6439
6445
jr nz , . loop
6440
-
6441
6446
ex de , hl
6442
6447
adc hl , hl
6443
- ret c
6444
- dec de ; ude=UDE-1
6445
- add hl , de ; uhl=UHL+UDE-1
6446
- add hl , bc ; uhl=UHL+UDE+UBC-1
6447
- ex de , hl ; uhl=UDE-1, ude=UHL+UDE+UBC-1
6448
- add hl , bc ; uhl=UDE+UBC-1, carry set if UDE==0
6449
- ccf ; carry set if UDE!=0
6450
- sbc hl , de ; uhl=-UHL-(UDE!=0)
6451
6448
ret
6452
6449
6453
6450
;-------------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments