@@ -4029,157 +4029,103 @@ _ScaleSprite:
4029
4029
; arg1 : Pointer to sprite struct output
4030
4030
; Returns:
4031
4031
; arg1 : Pointer to sprite struct output
4032
- ld hl ,- 27
4033
- call __frameset
4034
-
4035
- or a , a
4036
- sbc hl , hl
4037
- ld (ix - 24 ) , hl ; uint8_t *PrevSource = null
4038
- ld (ix - 20 ) , hl ; uint8_t Err = 0
4039
-
4040
- ld hl , (ix + 9 )
4032
+ ld iy , 0
4033
+ lea bc , iy
4034
+ add iy , sp
4035
+ push ix
4036
+ ld hl , (iy + 6 )
4037
+ push hl
4041
4038
ld a , (hl)
4042
- ld (ix - 1 ) , a ; uint8_t TgtWidth = sprite_out->width
4043
- ld (TgtWidth) , a \.r
4044
- ld (TgtWidth_2) , a \.r
4039
+ ld ixh , a ; target_width
4040
+ ld (targetwidth) , a \.r
4045
4041
inc hl
4046
- ld a , (hl)
4047
- ld (TgtHeight) , a \.r ; uint8_t TgtHeight = sprite_out->height
4048
- ld iyh , a ; uint8_t NumPixels = TgtHeight
4049
- ld e , a
4042
+ xor a , a
4043
+ sub a , (hl)
4044
+ ld ixl , a ; -target_height
4050
4045
inc hl
4051
- ld (ix - 4 ) , hl ; uint8_t *Target = sprite_out->data
4052
- ld hl , (ix + 6 )
4053
- ld a , (hl)
4054
- ld c , a
4055
- ld (SrcWidth) , a \.r ; uint8_t SrcWidth = sprite_in->width
4046
+ push hl ; hl->tgt_data
4047
+ ld hl , (iy + 3 )
4048
+ ld e , (hl) ; src_width
4056
4049
inc hl
4057
- ld d , (hl) ; uint8_t SrcHeight = sprite_in->height
4050
+ ld c , (hl) ; src_height
4058
4051
inc hl
4059
- push hl ; uint8_t *Source = sprite_in->data
4052
+ push hl ; hl->src_data
4053
+ push de ; e = src_width
4054
+ call _UCDivA_ASM \.r ; ca = dv = (source_height*256)/target_height
4055
+ pop hl ; l = src_width
4056
+ ld (dv_shl_16 + 2 ) , a \.r
4057
+ ld h , c
4058
+ ld c , l
4059
+ mlt hl
4060
+ ld (dv_shr_8_times_width) , hl \.r
4061
+ add hl , bc
4062
+ ld (dv_shr_8_times_width_plus_width) , hl \.r
4063
+ xor a , a
4064
+ sub a , ixh ; -target_width
4065
+ call _UCDivA_ASM \.r ; ca = du = (source_width*256)/target_width
4066
+ pop hl ; hl->src_data
4067
+ pop de ; de->tgt_data
4068
+ ld iy , 0
4069
+ ld iyl , a
4070
+ ld a , c ; du = bc:iyl
4071
+ ld (du) , a \.r ; ixl = target_height
4060
4072
4073
+ ; b = out_loop_times
4074
+ ; de = target buffer adress
4075
+ out :
4076
+ push hl
4077
+ targetwidth =$ + 2
4078
+ ld iyh , 0
4061
4079
xor a , a
4062
- ld b , 8
4063
- _: sla d
4064
- rla
4065
- cp a , e
4066
- jr c ,+ _
4067
- sub e
4068
- inc d
4069
- _: djnz -- _
4070
- ld e , c
4071
- mlt de
4072
- ld (FractPart) , a \.r ; uint8_t FractPart = SrcHeight % TgtHeight
4073
- ld (IntPart) , de \.r ; uint8_t IntPart = (SrcHeight / TgtHeight) * SrcWidth
4080
+ ld b , a
4081
+ du =$ + 1
4082
+ ld c , 0
4083
+ loop : ldi
4084
+ add a , iyl
4085
+ adc hl , bc ; xu += du
4086
+ inc bc ; bc:iyl is du
4087
+ dec iyh
4088
+ jr nz , loop
4089
+ pop hl ; add up to hla
4090
+ dv_shl_16 =$ + 1
4091
+ ld bc , 0 ; dv<<16
4092
+ add iy , bc
4093
+ dv_shr_8_times_width =$ + 1
4094
+ ld bc , 0 ; dv>>8*src_width
4095
+ jr nc ,+ _
4096
+ dv_shr_8_times_width_plus_width =$ + 1
4097
+ ld bc , 0 ; dv>>8*src_width+src_width
4098
+ _: add hl , bc
4099
+ inc ixl
4100
+ jr nz , out
4101
+ pop hl
4102
+ pop ix
4103
+ ret
4074
4104
4075
- ld d , c
4076
- ld e , (ix - 1 )
4077
- xor a , a
4078
- ld b , 8
4079
- _: sla d
4080
- rla
4081
- cp a , e
4082
- jr c ,+ _
4083
- sub e
4084
- inc d
4085
- _: djnz -- _
4086
- ld (FractPartWidth) , a \.r ; uint8_t FractPartWidth = SrcWidth % TgtWidth;
4087
- ld a , d
4088
- ld (IntPartWidth) , a \.r ; uint8_t IntPartWidth = SrcWidth / TgtWidth
4089
-
4090
- pop de
4091
- jp WhileNumPixelsLoop \.r ; while (NumPixels-- > 0)
4092
- WhileNumPixels:
4093
- ld hl , (ix - 24 )
4094
- or a , a
4095
- sbc hl , de
4096
- push de
4097
- ld bc , 0
4098
- jr nz , Source_NotEq_Prev ; if (Source == PrevSource)
4099
- ld c , (ix - 1 )
4100
- or a , a
4105
+ _UCDivA_ASM:
4101
4106
sbc hl , hl
4102
- ld l , c
4107
+ ld h , a
4108
+ xor a , a
4109
+ ld l , a
4103
4110
ex de , hl
4104
- ld hl , (ix - 4 )
4105
- push hl
4106
- or a , a
4107
- sbc hl , de
4108
- pop de
4109
- ldir ; memcpy(Target, Target-TgtWidth, TgtWidth)
4110
- ld (ix - 4 ) , de ; Target += TgtWidth
4111
- jr DoneLine
4112
- Source_NotEq_Prev:
4113
- ld (ix - 24 ) , de ; PrevSource = Source; uint8_t *SourceLine = Source;
4114
- TgtWidth_2 =$ + 2
4115
- ld iyl , 0 ; uint8_t NumPixelsLine = TgtWidth;
4116
- or a , a
4117
4111
sbc hl , hl
4118
- push ix
4119
- ld ix , (ix - 4 )
4120
- jr WhileNumPixelsLineStart ; while (NumPixelsLine-- > 0)
4121
- WhileNumPixelsLineLoop:
4122
- push hl
4123
- ld a , (de)
4124
- ld (ix) , a
4125
- inc ix ; *Target++ = *SourceLine
4126
- IntPartWidth =$ + 1
4127
- ld hl , 0
4128
- add hl , de
4129
- ex de , hl ; SourceLine += IntPartWidth
4130
- pop hl
4131
- FractPartWidth =$ + 1
4132
- ld c , 0
4133
- add hl , bc
4134
- TgtWidth =$ + 1
4135
- ld c , 0
4136
- or a , a
4137
- sbc hl , bc ; if (ErrLine >= TgtWidth)
4138
- jr c , WhileNumPixelsLine
4139
- inc de ; SourceLine++
4140
- jr WhileNumPixelsLineStart
4141
- WhileNumPixelsLine:
4142
- add hl , bc ; Errline -= TgtWidth
4143
- WhileNumPixelsLineStart:
4144
- ld a , iyl
4145
- dec iyl
4146
- or a , a
4147
- jr nz , WhileNumPixelsLineLoop
4148
- lea hl , ix
4149
- pop ix
4150
- ld (ix - 4 ) , hl
4151
- DoneLine:
4152
- pop de
4153
- IntPart =$ + 1
4154
- ld hl , 0
4155
- add hl , de
4156
- ex de , hl ; Source += IntPart
4157
- FractPart =$ + 1
4158
- ld c , 0
4159
- ld hl , (ix - 20 )
4160
- add hl , bc
4161
- ld (ix - 20 ) , hl ; Err += FractPart
4162
- TgtHeight =$ + 1
4163
- ld c , 0
4164
- or a , a
4165
- sbc hl , bc ; if (Err >= TgtHeight)
4166
- jr c , WhileNumPixelsLoop
4167
- ld (ix - 20 ) , hl ; Err -= tgtheight;
4168
- SrcWidth =$ + 1
4169
- ld hl , 0
4112
+ ld l , c
4113
+ call + _ \.r
4114
+ ld c , a
4115
+ _: ld b , 8
4116
+ _: add hl , hl
4170
4117
add hl , de
4171
- ex de , hl ; Source += SrcWidth;
4172
- WhileNumPixelsLoop:
4173
- ld a , iyh
4174
- dec iyh
4175
- or a , a
4176
- jp nz , WhileNumPixels \.r
4177
- ld hl , (ix + 9 ) ; return sprite_out;
4178
- ld sp , ix
4118
+ jr c ,+ _
4119
+ sbc hl , de
4120
+ _: rla
4121
+ djnz -- _
4122
+ ret ; ca = c*256/a, h = c*256%a
4123
+
4124
+ ;-------------------------------------------------------------------------------
4179
4125
RestoreStack:
4126
+ ld sp , ix
4180
4127
pop ix
4181
4128
ret
4182
-
4183
4129
;-------------------------------------------------------------------------------
4184
4130
_FloodFill:
4185
4131
; Preforms an implementation of a flood fill so no one hopefully crashes the stack
0 commit comments