Skip to content

Commit

Permalink
/ ZXDev/Lib/Basic/ CIRCLE, CIRCLEROM, CIRCLEW & CLS: optimize, sort.
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg-N-Cher committed Dec 24, 2016
1 parent ebe601e commit b693d9c
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 89 deletions.
Binary file modified ZXDev/Lib/Basic.lib
Binary file not shown.
121 changes: 58 additions & 63 deletions ZXDev/Lib/C/Basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ void Basic_BEEP_DI (unsigned int ms, signed char freq) __z88dk_callee;
void Basic_BEEP_EI (unsigned int ms, signed char freq) __z88dk_callee;
void Basic_BORDER_fastcall (unsigned char color) __z88dk_fastcall;
void Basic_BRIGHT (unsigned char mode) __z88dk_fastcall;
void Basic_CIRCLE (unsigned char cx, unsigned char cy, unsigned char radius);
void Basic_CIRCLEW_DI (unsigned char cx, unsigned char cy, INTEGER radius);
void Basic_CIRCLEW_EI (unsigned char cx, unsigned char cy, INTEGER radius);
void Basic_CIRCLEROM (unsigned char cx, unsigned char cy, unsigned char radius);
void Basic_CLS_ZX (void);
void Basic_CIRCLE (unsigned char cx, unsigned char cy, unsigned char radius) __z88dk_callee;
void Basic_CIRCLEROM (unsigned char cx, unsigned char cy, unsigned char radius) __z88dk_callee;
void Basic_CIRCLEW_DI (unsigned char cx, unsigned char cy, int radius) __z88dk_callee;
void Basic_CIRCLEW_EI (unsigned char cx, unsigned char cy, int radius) __z88dk_callee;
void Basic_CLS_FULLSCREEN (void);
void Basic_CLS_ZX (void);
void Basic_COLOR (unsigned char atr) __z88dk_fastcall;
void Basic_DRAW_S (signed char x, signed char y);
void Basic_FLASH (unsigned char mode) __z88dk_fastcall;
Expand Down Expand Up @@ -291,16 +291,16 @@ __endasm;
} //Basic_BRIGHT

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CIRCLE (unsigned char cx, unsigned char cy, unsigned char radius) __naked {
void Basic_CIRCLE (unsigned char cx, unsigned char cy, unsigned char radius) __z88dk_callee {
__asm // Fixed for OVER 1 & small radius by Reobne
LD IY, #0x5C3A
POP BC
POP HL ; L = x; H = y
POP DE ; E = radius
PUSH DE
PUSH HL
DEC SP
POP AF ; A = radius
PUSH BC

LD C, E
LD E, A
LD C, A
LD B, #0
CALL DOTCI$
XOR A
Expand Down Expand Up @@ -381,19 +381,40 @@ DOTCI$: PUSH HL
POP BC
POP DE
POP HL
RET
__endasm;
} //Basic_CIRCLE

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CIRCLEW_DI (unsigned char cx, unsigned char cy, INTEGER radius) __naked {
void Basic_CIRCLEROM (unsigned char cx, unsigned char cy, unsigned char radius) __z88dk_callee {
__asm
POP HL
DEC SP
EX (SP),HL
LD A,H /* cx */
CALL 0x2D28
POP HL
DEC SP
EX (SP),HL
LD A,H /* cy */
CALL 0x2D28
POP HL
DEC SP
EX (SP),HL
LD A,H /* radius */
CALL 0x2D28
CALL 0x232D
LD A,(ATTR_P$)
LD (ATTR_T$),A
__endasm;
} //Basic_CIRCLEROM

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CIRCLEW_DI (unsigned char cx, unsigned char cy, INTEGER radius) __z88dk_callee {
__asm
LD IY, #0x5C3A
POP DE
POP BC
POP HL
PUSH HL
PUSH BC
PUSH DE
LD A, H
OR L
Expand Down Expand Up @@ -561,27 +582,24 @@ WRAP01$: // fixed for OVER 1 by Destr
LD (WRAP01$+1), BC
SBC HL, BC
JP NZ, 0x22E5
RET
__endasm;
} //Basic_CIRCLEW_DI

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CIRCLEW_EI (unsigned char cx, unsigned char cy, INTEGER radius) __naked {
void Basic_CIRCLEW_EI (unsigned char cx, unsigned char cy, int radius) __z88dk_callee {
__asm
LD IY, #0x5C3A
POP DE
POP BC
POP HL
PUSH HL
PUSH BC
PUSH DE
LD A, H
OR L
RET Z
BIT 7, H
RET NZ
PUSH IX
DI
PUSH IX
LD D, #0
LD E, C
LD C, B
Expand Down Expand Up @@ -743,29 +761,34 @@ WRAP11$: // fixed for OVER 1 by Destr
LD (WRAP11$+1), BC
SBC HL, BC
JP NZ, 0x22E5
RET
__endasm;
} //Basic_CIRCLEW_EI

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CIRCLEROM (unsigned char cx, unsigned char cy, unsigned char radius) __naked {
void Basic_CLS_FULLSCREEN (void) {
__asm
PUSH IX
LD IX,#0
ADD IX,SP
LD A,4(IX) /* cx */
CALL 0x2D28
LD A,5(IX) /* cy */
CALL 0x2D28
LD A,6(IX) /* radius */
CALL 0x2D28
CALL 0x232D
POP IX
LD IY,#0x5C3A
LD A,(#0x5C48)
EX AF,AF
LD A,(ATTR_P$)
LD (#0x5C48),A
CALL 0xD6B // IX-safe
EX AF,AF
LD (#0x5C48),A
LD A,(ATTR_P$)
LD (ATTR_T$),A
RET
__endasm;
} //Basic_CIRCLEROM
} //Basic_CLS_FULLSCREEN

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CLS_ZX (void) {
__asm
LD IY,#0x5C3A
CALL 0xD6B // IX-safe
LD A,(ATTR_P$)
LD (ATTR_T$),A
__endasm;
} //Basic_CLS_ZX

/*--------------------------------- Cut here ---------------------------------*/
void Basic_COLOR (unsigned char atr) __z88dk_fastcall {
Expand Down Expand Up @@ -857,34 +880,6 @@ __asm
__endasm;
} //Basic_OVER_ROM

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CLS_ZX (void)
{
__asm
LD IY,#0x5C3A
CALL 0xD6B // IX-safe
LD A,(ATTR_P$)
LD (ATTR_T$),A
__endasm;
} //Basic_CLS_ZX

/*--------------------------------- Cut here ---------------------------------*/
void Basic_CLS_FULLSCREEN (void)
{
__asm
LD IY,#0x5C3A
LD A,(#0x5C48)
PUSH AF
LD A,(ATTR_P$)
LD (#0x5C48),A
CALL 0xD6B // IX-safe
POP AF
LD (#0x5C48),A
LD A,(ATTR_P$)
LD (ATTR_T$),A
__endasm;
} //Basic_CLS_FULLSCREEN

/*--------------------------------- Cut here ---------------------------------*/
void Basic_PAINT (unsigned char x, unsigned char y, unsigned char ink) __z88dk_callee {
__asm
Expand Down
52 changes: 28 additions & 24 deletions ZXDev/Lib/C/Basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ extern void Basic_BORDER_fastcall (unsigned char color) __z88dk_fastcall __prese
//---------------------------- BRIGHT (mode: Mode) -----------------------------
extern void Basic_BRIGHT (unsigned char mode) __z88dk_fastcall __preserves_regs(b,c,d,e);

//----------------------- CIRCLE (cx, cy, radius: UBYTE) -----------------------
extern void Basic_CIRCLE (unsigned char cx, unsigned char cy, unsigned char radius) __z88dk_callee __preserves_regs(d);

//--------------------- CIRCLEROM (cx, cy, radius: UBYTE) ----------------------
extern void Basic_CIRCLEROM (unsigned char cx, unsigned char cy, SHORTINT radius) __z88dk_callee;

//------------------ CIRCLEW (cx, cy: UBYTE; radius: INTEGER) ------------------
extern void Basic_CIRCLEW_DI (unsigned char cx, unsigned char cy, int radius) __z88dk_callee;
extern void Basic_CIRCLEW_EI (unsigned char cx, unsigned char cy, int radius) __z88dk_callee;
#if defined (MODE_DI) || defined (MODE_DI_inline)
# define Basic_CIRCLEW Basic_CIRCLEW_DI
#endif //MODE_DI
#if defined (MODE_IM1) || defined (MODE_IM1_inline)
# define Basic_CIRCLEW Basic_CIRCLEW_EI
#endif //MODE_IM1
#if defined (MODE_IM2) || defined (MODE_IM2_inline)
# define Basic_CIRCLEW Basic_CIRCLEW_EI
#endif //MODE_IM2

//------------------------------------ CLS -------------------------------------
extern void Basic_CLS_FULLSCREEN (void);
extern void Basic_CLS_ZX (void);
#ifdef CLS_FULLSCREEN
#define Basic_CLS Basic_CLS_FULLSCREEN
#else
#define Basic_CLS Basic_CLS_ZX
#endif

//---------------------------- COLOR (attr: UBYTE) -----------------------------
extern void Basic_COLOR (unsigned char atr) __z88dk_fastcall __preserves_regs(b,c,d,e,h,iyl,iyh);

Expand Down Expand Up @@ -105,14 +133,6 @@ extern void Basic_OVER_ROM (unsigned char mode) __z88dk_fastcall __preserves_reg
# define Basic_OVER Basic_OVER_FAST
#endif

extern void Basic_CLS_ZX (void);
extern void Basic_CLS_FULLSCREEN (void);
#ifdef CLS_FULLSCREEN
#define Basic_CLS Basic_CLS_FULLSCREEN
#else
#define Basic_CLS Basic_CLS_ZX
#endif

//-------------------------- PAINT (x, y, ink: UBYTE) --------------------------
extern void Basic_PAINT (unsigned char x, unsigned char y, unsigned char ink) __z88dk_callee;

Expand Down Expand Up @@ -167,20 +187,6 @@ extern unsigned char Basic_POINT (unsigned char x, unsigned char y) __z88dk_call
extern void Basic_DRAW_S (signed char x, signed char y);
#define Basic_DRAW(x, y) Basic_DRAW_S((signed char)(x), (signed char)(y))

extern void Basic_CIRCLE (unsigned char cx, unsigned char cy, unsigned char radius);

extern void Basic_CIRCLEW_DI (unsigned char cx, unsigned char cy, INTEGER radius);
extern void Basic_CIRCLEW_EI (unsigned char cx, unsigned char cy, INTEGER radius);
#if defined (MODE_DI) || defined (MODE_DI_inline)
# define Basic_CIRCLEW Basic_CIRCLEW_DI
#endif //MODE_DI
#if defined (MODE_IM1) || defined (MODE_IM1_inline)
# define Basic_CIRCLEW Basic_CIRCLE_EIW
#endif //MODE_IM1
#if defined (MODE_IM2) || defined (MODE_IM2_inline)
# define Basic_CIRCLEW Basic_CIRCLEW_EI
#endif //MODE_IM2

export void Basic_PRINT_FAST (INTEGER i);
export void Basic_PRINT_ROM (INTEGER i);
#ifdef ROM_OUTPUT
Expand All @@ -197,8 +203,6 @@ extern void Basic_PRWORD_ROM (CARDINAL n);
#define Basic_PRWORD Basic_PRWORD_FAST
#endif

extern void Basic_CIRCLEROM (unsigned char cx, unsigned char cy, SHORTINT radius);

#define Basic_POKE(addr,val) (*(unsigned char*) (addr) = (val))
#define Basic_POKEW(addr,val) (*(unsigned*) (addr) = (val))
#define Basic_PEEK(addr) (*(unsigned char*) (addr))
Expand Down
12 changes: 12 additions & 0 deletions ZXDev/Mod/TestSaveRegs1.Mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ BEGIN
b.COLOR(b.Yellow); b.PRSTR("BRIGHT ");
d.SaveRegsDef; b.BRIGHT(1); d.CheckRegs;

b.COLOR(b.Yellow); b.PRSTR("CIRCLE ");
d.SaveRegsDef; b.CIRCLE(250, 170, 3); d.CheckRegs;

b.COLOR(b.Yellow); b.PRSTR("CIRCLEROM ");
d.SaveRegsDef; b.CIRCLEROM(240, 170, 3); d.CheckRegs;

b.COLOR(b.Yellow); b.PRSTR("CIRCLEW_DI ");
d.SaveRegsDef; b.CIRCLEW(250, 170, 5); d.CheckRegs;

(*b.COLOR(b.Yellow); b.PRSTR("CLS_ZX ");
d.SaveRegsDef; b.CLS; d.CheckRegs;*)

b.COLOR(b.Yellow); b.PRSTR("PLOT_callee ");
d.SaveRegsDef; b.PLOT(255, 175); d.CheckRegs;

Expand Down
6 changes: 6 additions & 0 deletions ZXDev/Mod/TestSaveRegs2.Mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ BEGIN
b.COLOR(b.Yellow); b.PRSTR("BORDER ");
d.SaveRegsDef; b.BORDER(3); d.CheckRegs;

b.COLOR(b.Yellow); b.PRSTR("CIRCLEW_EI ");
d.SaveRegsDef; b.CIRCLEW(250, 170, 5); d.CheckRegs;

(*b.COLOR(b.Yellow); b.PRSTR("CLS_FULLSCREEN ");
d.SaveRegsDef; b.CLS; d.CheckRegs;*)

b.COLOR(b.Yellow); b.PRSTR("PLOT_fastcall ");
d.SaveRegsDef; b.PLOT(255, 175); d.CheckRegs;

Expand Down
15 changes: 15 additions & 0 deletions ZXDev/Obj/TestSaveRegs1.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ int main(int argc, char **argv)
Basic_BRIGHT(1);
Debug_CheckRegs();
Basic_COLOR(6);
Basic_PRSTR((CHAR*)"CIRCLE ", 8);
Debug_SaveRegsDef();
Basic_CIRCLE(250, 170, 3);
Debug_CheckRegs();
Basic_COLOR(6);
Basic_PRSTR((CHAR*)"CIRCLEROM ", 11);
Debug_SaveRegsDef();
Basic_CIRCLEROM(240, 170, 3);
Debug_CheckRegs();
Basic_COLOR(6);
Basic_PRSTR((CHAR*)"CIRCLEW_DI ", 12);
Debug_SaveRegsDef();
Basic_CIRCLEW(250, 170, 5);
Debug_CheckRegs();
Basic_COLOR(6);
Basic_PRSTR((CHAR*)"PLOT_callee ", 13);
Debug_SaveRegsDef();
Basic_PLOT(255, 175);
Expand Down
5 changes: 5 additions & 0 deletions ZXDev/Obj/TestSaveRegs2.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ int main(int argc, char **argv)
Basic_BORDER(3);
Debug_CheckRegs();
Basic_COLOR(6);
Basic_PRSTR((CHAR*)"CIRCLEW_EI ", 12);
Debug_SaveRegsDef();
Basic_CIRCLEW(250, 170, 5);
Debug_CheckRegs();
Basic_COLOR(6);
Basic_PRSTR((CHAR*)"PLOT_fastcall ", 15);
Debug_SaveRegsDef();
Basic_PLOT(255, 175);
Expand Down
3 changes: 1 addition & 2 deletions ZXDev/Obj/TestSaveRegs2/BasicCfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
//#define PRSTR_fastcall

/* Use CLS for whole screen (with PAPER attributes in bottom lines): */
//#define CLS_FULLSCREEN

#define CLS_FULLSCREEN
Binary file modified ZXDev/TestSaveRegs1.tap
Binary file not shown.
Binary file modified ZXDev/TestSaveRegs2.tap
Binary file not shown.

0 comments on commit b693d9c

Please sign in to comment.