Skip to content

Commit 8facf51

Browse files
Optimize gfx_ScaleSprite
1 parent 3b04b3d commit 8facf51

File tree

3 files changed

+118
-160
lines changed

3 files changed

+118
-160
lines changed

CEdev/include/lib/ce/intce.h

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@ asm("di")
4747
#define int_Wait() \
4848
asm("halt")
4949

50-
#define ON_IVECT 0 // [on] key interrupt source
51-
#define TIMER1_IVECT 1 // Timer 1 interrupt source
52-
#define TIMER2_IVECT 2 // Timer 2 interrupt source
53-
#define TIMER3_IVECT 3 // Timer 3 interrupt source
54-
#define TIMEROS_IVECT 4 // Timer OS interrupt source
55-
#define KEYBOARD_IVECT 10 // Keyboard interrupt source
56-
#define LCD_IVECT 11 // LCD interrupt source
57-
#define RTC_IVECT 12 // Real Time Clock interrupt source
58-
#define USB_IVECT 13 // USB interrupt source
50+
#define ON_IVECT 0 /**< [on] key interrupt source */
51+
#define TIMER1_IVECT 1 /**< Timer 1 interrupt source */
52+
#define TIMER2_IVECT 2 /**< Timer 2 interrupt source */
53+
#define TIMER3_IVECT 3 /**< Timer 3 interrupt source */
54+
#define TIMEROS_IVECT 4 /**< Timer OS interrupt source */
55+
#define KEYBOARD_IVECT 10 /**< Keyboard interrupt source */
56+
#define LCD_IVECT 11 /**< LCD interrupt source */
57+
#define RTC_IVECT 12 /**< Real Time Clock interrupt source */
58+
#define USB_IVECT 13 /**< USB interrupt source */
5959

60-
#define INT_ON 1<<ON_IVECT // [on] key interrupt source mask
61-
#define INT_TIMER1 1<<TIMER1_IVECT // Timer 1 interrupt source mask
62-
#define INT_TIMER2 1<<TIMER2_IVECT // Timer 2 interrupt source mask
63-
#define INT_TIMER3 1<<TIMER3_IVECT // Timer 3 interrupt source mask
64-
#define INT_TIMEROS 1<<TIMEROS_IVECT // Timer OS interrupt source mask
65-
#define INT_KEYBOARD 1<<KEYBOARD_IVECT // Keyboard interrupt source mask
66-
#define INT_LCD 1<<LCD_IVECT // LCD interrupt source mask
67-
#define INT_RTC 1<<RTC_IVECT // Real Time Clock interrupt source mask
68-
#define INT_USB 1<<USB_IVECT // USB interrupt source mask
60+
#define INT_ON 1<<ON_IVECT /**< [on] key interrupt source mask */
61+
#define INT_TIMER1 1<<TIMER1_IVECT /**< Timer 1 interrupt source mask */
62+
#define INT_TIMER2 1<<TIMER2_IVECT /**< Timer 2 interrupt source mask */
63+
#define INT_TIMER3 1<<TIMER3_IVECT /**< Timer 3 interrupt source mask */
64+
#define INT_TIMEROS 1<<TIMEROS_IVECT /**< Timer OS interrupt source mask */
65+
#define INT_KEYBOARD 1<<KEYBOARD_IVECT /**< Keyboard interrupt source mask */
66+
#define INT_LCD 1<<LCD_IVECT /**< LCD interrupt source mask */
67+
#define INT_RTC 1<<RTC_IVECT /**< Real Time Clock interrupt source mask */
68+
#define INT_USB 1<<USB_IVECT /**< USB interrupt source mask */
6969

70-
#define int_RawStatus (*(volatile uint24_t*)0x0F00000) /**< State of interrupt signals */
70+
#define int_RawStatus (*(volatile uint24_t*)0x0F00000) /**< State of interrupt signals */
7171
#define int_MaskedStatus (*(volatile uint24_t*)0x0F00014) /**< Masked state of interrupt signals */
72-
#define int_EnableConfig (*(uint24_t*)0x0F00004) /**< Enabled interrupt signals */
73-
#define int_LatchConfig (*(uint24_t*)0x0F0000C) /**< Latchable interrupt signals */
74-
#define int_InvertConfig (*(uint24_t*)0x0F00010) /**< Invertable interrupt signals */
75-
#define int_Acknowledge (*(uint24_t*)0x0F00008) /**< Acknowledge interrupt signals */
72+
#define int_EnableConfig (*(uint24_t*)0x0F00004) /**< Enabled interrupt signals */
73+
#define int_LatchConfig (*(uint24_t*)0x0F0000C) /**< Latchable interrupt signals */
74+
#define int_InvertConfig (*(uint24_t*)0x0F00010) /**< Invertable interrupt signals */
75+
#define int_Acknowledge (*(uint24_t*)0x0F00008) /**< Acknowledge interrupt signals */
7676

7777
#endif

CEdev/include/lib/ce/tice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,19 @@ typedef uint8_t sk_key_t;
658658
/**
659659
* Performs an OS call to get the keypad scan code
660660
*
661-
* Technically return type is uint24_t, but that is not useful as the high byte is 0
661+
* You can also use this function to get input from the user as a string like this:
662+
* @code
663+
* const char *chars = "\0\0\0\0\0\0\0\0\0\0\"WRMH\0\0?[VQLG\0\0:ZUPKFC\0 YTOJEB\0\0XSNIDA\0\0\0\0\0\0\0\0";
664+
* uint8_t key, i = 0;
665+
* char buffer[50];
666+
*
667+
* while((key = os_GetCSC()) != sk_Enter) {
668+
* if(chars[key]) {
669+
* buffer[i++] = chars[key];
670+
* }
671+
* }
672+
* @endcode
673+
* Feel free to modify the string to suit your needs.
662674
* @returns Key scan code
663675
*/
664676
sk_key_t os_GetCSC(void);

CEdev/lib/src/graphics/graphx/graphics_lib.asm

Lines changed: 82 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,157 +4029,103 @@ _ScaleSprite:
40294029
; arg1 : Pointer to sprite struct output
40304030
; Returns:
40314031
; 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
40414038
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
40454041
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
40504045
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
40564049
inc hl
4057-
ld d,(hl) ; uint8_t SrcHeight = sprite_in->height
4050+
ld c,(hl) ; src_height
40584051
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
40604072

4073+
; b = out_loop_times
4074+
; de = target buffer adress
4075+
out:
4076+
push hl
4077+
targetwidth =$+2
4078+
ld iyh, 0
40614079
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
40744104
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:
41014106
sbc hl,hl
4102-
ld l,c
4107+
ld h,a
4108+
xor a,a
4109+
ld l,a
41034110
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
41174111
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
41704117
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+
;-------------------------------------------------------------------------------
41794125
RestoreStack:
4126+
ld sp,ix
41804127
pop ix
41814128
ret
4182-
41834129
;-------------------------------------------------------------------------------
41844130
_FloodFill:
41854131
; Preforms an implementation of a flood fill so no one hopefully crashes the stack

0 commit comments

Comments
 (0)