News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_mr_lou

Help with SDCC

Started by mr_lou, 09:50, 11 December 11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TFM

Quote from: mr_lou on 08:21, 16 December 11
Updated the draw comparison thingy.

SDCC is faster than BASIC now, but not much. (And I still think it's cheating a bit using unsigned shorts).

RUN"compare

EDIT: Could mention, that the SDCC version is only about 4% faster than the BASIC version. So it's debatable if it's worth it.

Can anyone come up with a faster solution?

Haha, on my CPC (Caprice) its 3% faster. That much about CP/M users weird ideas ;-) Ok, that's all nothing new. Good to see it though.

I can of course come up with a way faster solution, but only for Small-C under CP/M and not for SDCC, because I have no time to rewrite all assembler stuff for that weird SDCC assembler code.
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

demoniak

A sample of drawline function using bresenham method:
void DrawLine(int x1, int y1, int x2, int y2)
{
    int a, xincr, dx, dy, d,aincr, bincr, x, y;
    int steep = abs(y2 - y1) < abs(x2 - x1);
    if (steep)
        {
        a = x1;
        x1 = y1;
        y1 = a;
        a = x2;
        x2 = y2;
        y2 = a;
        }

    if (y1 > y2)
        {
        a = x1;
        x1 = x2;
        x2 = a;
        a = y1;
        y1 = y2;
        y2 = a;
        }
    xincr = x2 > x1 ? 1 : -1;
    dy = y2 - y1;
    dx = abs(x2 - x1);
    d = (dx << 1) - dy;
    aincr = (dx - dy) << 1;
    bincr = dx << 1;
    x = x1;
    for (y = y1; y <= y2; ++y)
        {
        if (steep)
            plot(y, x,);
        else
            plot(x,y);

        if (d >= 0)
            {
            x += xincr;
            d += aincr;
            }
        else
            d += bincr;
        }
}


HAL6128

Quote from: TFM/FS on 22:17, 16 December 11

Haha, on my CPC (Caprice) its 3% faster. That much about CP/M users weird ideas ;-) Ok, that's all nothing new. Good to see it though.

I can of course come up with a way faster solution, but only for Small-C under CP/M and not for SDCC, because I have no time to rewrite all assembler stuff for that weird SDCC assembler code.

Hi TFM,
which Small-C version do you use? In your FIOLIB example (ftest for FOS) you were explaing to compile the file with "cc...", then assemble it with "zmac..." and link it with "zlnk". My Small-C version (for CP/M) has just "cc.com / mac.com / lnk.com" files with different options/switches. And there's no "printf1.h" library?
"
...proudly supported Schnapps Demo, Pentomino and NQ-Music-Disc with GFX

mr_lou

Well, I have written NoRecess asking if there's any chance SDCC2Pasmo will ever be ported to Linux.
If yes, or if I can get the source to make a Java version myself, then it wouldn't be a requirement to use ASXXXX assembler.

So, anyone who'd be interested if you're allowed to use Maxam syntax assembler?

mr_lou

NoRecess released the source for SDCC2Pasmo.
However, it's not as simple as just compiling it on Linux. Some adaptions has to be made first. For example, tchar.h is missing; a compiler-specific header to manage unicode. He also use windows resources system, so one needs to know cpp programming under windows before doing a port to gcc. That's sadly not me.

Anyone else cares to step up and do a Linux port of SDCC2Pasmo?

Meanwhile, what does the --asm=z80asm parameter of SDCC do? It changes the assembler syntax from ASXXXX to Z80 syntax. That's apparently not good enough either for pasmo to compile?

TFM

#55
Quote from: hal 6128 on 15:41, 17 December 11
Hi TFM,
which Small-C version do you use? In your FIOLIB example (ftest for FOS) you were explaing to compile the file with "cc...", then assemble it with "zmac..." and link it with "zlnk". My Small-C version (for CP/M) has just "cc.com / mac.com / lnk.com" files with different options/switches. And there's no "printf1.h" library?
"

I use the Small-C 1.2 for Z80. Download it from my homepage, direct link:
http://www.colorado-boys-muenchen.de/users/futureos/files/FIO.zip

That contains:
- CP/M Plus that reads 700K format on B
- DSK with FIOLIB and all stuff for B-drive in 700K Vortex format.

You need to set up CP/M's submit properly. I have to update that CP/M DSK there, but I miss that stuff on my virtual CPC here (and time too ,-)
Let me know if I can help in any other way  :)


EDIT: FIOLIB contains some commands like putchar. The corresponding print-stuff is also on that disc. And a lot more. It was my working disc actually ;-)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

mr_lou

#56
Yay!!! SDCC2Pasmo works under wine afterall, after installing vcredist_x86.exe!

So who can provide me an fast drawing routine in Maxam-syntax assembler?


void drawLine(x1, y1, x2, y2) {
// x1,y1,x2,y2 can be byte, unsigned short, whatever you like.
__asm
    ld    e,(ix+8)
    ld    d,(ix+9)  ; y1 is now in de
    ld    l,(ix+10)
    ld    h,(ix+11)  ; x1 is now in hl
;   Move to x1, y1
    ld    e,(ix+4)
    ld    d,(ix+5)  ; y2 is now in de
    ld    l,(ix+6)
    ld    h,(ix+7) ; x2 is now in hl
;   Draw to x2, y2
__endasm;
}

mr_lou

#57
Have compared firmware call draw vs Bresenham algorithm.

Firmware calls are fastest.

RUN"main

The plotting of the Bresenham algorithm is done using the fastplot assembler routine.
No one who can produce a faster line-drawing routine than the firmware call?

EDIT: Forgot to mention, Bresenham (in this case) only works on a CPC464 because of different locations of the pen number in memory. So set your emulator to CPC464.

Devilmarkus

Hummmm... I can't spot any difference in speed...
Is that right?
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

mr_lou

I see a big difference, with Caprice emulator and my real CPC464. (For some reason Arnold just gives me a red screen when I try to load from a CPC464).
It's particular noticeable with the more vertical lines. Notice, the more vertical the lines are, the faster the firmware call, while the bresenham method keeps the same slow speed on all lines.

demoniak

#60
Here is my small contribution, only works in CPC mode 1

2 functions :
SetPen( int numpen)
0<=numpen<=3

DrawLine(int x1,int y1, int x2, int y2)
0<=x1<=319
0<=y1<=199
0<=x2<=319
0<=y2<=199


SetPen:
        LD      A,(IX+4)
        AND     3
        ADD     A,A
        ADD     A,A
        LD      HL,TabPen0
        LD      B,0
        LD      C,A
        ADD     HL,BC
        LD      (TabPen+1),HL
        RET

DrawLine:
        LD      L,(ix+8)
        LD      H,(ix+9)                ; y1 is now in hl
        LD      E,(ix+10)
        LD      D,(ix+11)               ; x1 is now in de
        LD      (X1+1),DE
        LD      (y1+1),HL
        LD      E,(ix+4)
        LD      D,(ix+5)                ; y2 is now in de
        LD      C,(ix+6)
        LD      B,(ix+7)                ; x2 is now in bc
        LD      (X2+1),BC
        LD      (Y2+1),DE
        SBC     HL,DE                   ; y1-y2
        JR      NC,DrawLine2
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine2:
        LD      (absy+1),HL
        LD      HL,(x1+1)
        SBC     HL,BC                   ; x1-x2
        JR      NC,absy
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
absy:
        LD      DE,0
        XOR     A
        SBC     HL,DE                   ; HL = absx-absy
        JR      c,DrawLine3
        LD      A,#EB                   ; #EB = EX DE,HL
        LD      HL,(x1+1)
        LD      DE,(y1+1)
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      HL,(x2+1)
        LD      DE,(y2+1)
        LD      (x2+1),DE
        LD      (y2+1),HL
DrawLine3:
        LD      (exchg),A
        LD      DE,(y1+1)
        LD      HL,(y2+1)
        SBC     HL,DE
        JR      NC,DrawLine4
        LD      HL,(x1+1)
        LD      DE,(x2+1)
        LD      (x1+1),DE
        LD      (x2+1),HL
        LD      HL,(y1+1)
        LD      DE,(y2+1)
        LD      (y1+1),DE
        LD      (y2+1),HL
DrawLine4:
        LD      HL,(x2+1)
        LD      DE,(x1+1)
        SBC     HL,DE
        LD      HL,-1
        JR      c,DrawLine5
        LD      HL,1
DrawLine5:
        LD      (xincr+1),HL
        LD      HL,(y2+1)
        LD      DE,(y1+1)
        SBC     HL,DE
        LD      (dy+1),HL
x2:
        LD      DE,0
        LD      HL,(x1+1)
        SBC     HL,DE                   ; x1-x2
        JR      NC,DrawLine6
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine6:
        LD      (dx+1),HL
        ADD     HL,HL
dy:
        LD      DE,0
        SBC     HL,DE
        LD      (delta+1),HL
dx:
        LD      HL,0
        SBC     HL,DE
        ADD     HL,HL
        LD      (aincr+1),HL
        LD      HL,(dx+1)
        ADD     HL,HL
        LD      (bincr+1),HL
        LD      HL,(y1+1)
BclDrawLine:
        EX      DE,HL                   ; DE = y1
y2:
        LD      HL,0
        SBC     HL,DE                   ; HL = y2 - y1
        RET     C
x1:
        LD      HL,0                    ; HL = x1
exchg:
        NOP                             ; NOP or EX DE,HL
        SRA     H
        LD      A,L                     ; L = lowpart of x (0..319 & 255)
        RR      L
        AND     3
        LD      (varx+1),A
        RR      L                       ; L = x / 4 (0..79)
        LD      A,E                     ; E = y (0..199)
        LD      (vary+1),A
        LD      E,L
        LD      D,#C0
        AND     #F8
        LD      L,A
        XOR     A
        LD      H,A
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 16
        LD      B,H
        LD      C,L                     ; BC = ( Y >> 3 ) * 16
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 32
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 64
        ADD     HL,BC                   ; HL = ( Y >> 3 ) * 80
        ADD     HL,DE
        LD      E,A                     ; E = A = 0
vary:
        LD      A,0
        AND     7
        ADD     A,A
        ADD     A,A
        ADD     A,A
        LD      D,A                     ; DE = ( y & 7 ) * 2048
        ADD     HL,DE
        EX      DE,HL
        LD      H,L                     ; L=0
varx:
        LD      L,0
TabPen:
        LD      BC,TabPen1
        ADD     HL,BC
        LD      A,(HL)                  ; byte to draw
        EX      DE,HL
        LD      C,A
        RRCA
        RRCA
        RRCA
        RRCA
        OR      C                       ; Bits 0-3 | Bits 4-7
        CPL                             ; Mask
        AND     (HL)                    ; video memory's byte
        OR      C                       ; byte to draw
        LD      (HL),A                  ; in video memory
delta:
        LD      HL,0
        BIT     7,H
        JR      NZ,bincr
aincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
        LD      HL,(x1+1)
xincr:
        LD      DE,0
        ADD     HL,DE
        LD      (x1+1),HL
        JR      y1
bincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
y1:
        LD      HL,0
        INC     HL
        LD      (y1+1),HL
        JR      BclDrawLine

TabPen0:
        DB      #00,#00,#00,#00
TabPen1:
        DB      #80,#40,#20,#10
TabPen2:
        DB      #08,#04,#02,#01
TabPen3:
        DB      #88,#44,#22,#11

demoniak

#61
Small optimisation an small "test" program ;-)

        ORG     #4000

;
; "Sample" program to test functions
;
        LD      IX,#8000
        LD      A,1
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 1
        LD      HL,0
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,0
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,319
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(0,0,319,0)

        LD      A,2
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 2
        LD      HL,319
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,0
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,319
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,199
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(319,0,319,199)

        LD      A,3
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 3
        LD      HL,319
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,0
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,199
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(319,199,0,199)

        LD      A,1
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 1
        LD      HL,0
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,0
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(0,199,0,0)

        LD      A,2
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 2
        LD      HL,0
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,319
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(0,199,319,0)

        LD      A,3
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 3
        LD      HL,319
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,0
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(319,199,0,0)
        RET

;
; The functions begin here
;
SetPen:
        LD      A,(IX+4)
        AND     3
        ADD     A,A
        ADD     A,A
        ADD     A,A
        LD      HL,TabPen0
        LD      B,0
        LD      C,A
        ADD     HL,BC
        LD      (TabPen+1),HL
        RET

DrawLine:
        LD      L,(IX+8)
        LD      H,(IX+9)                ; y1 is now in hl
        LD      E,(IX+10)
        LD      D,(IX+11)               ; x1 is now in de
        LD      (X1+1),DE
        LD      (y1+1),HL
        LD      E,(IX+4)
        LD      D,(IX+5)                ; y2 is now in de
        LD      C,(IX+6)
        LD      B,(IX+7)                ; x2 is now in bc
        LD      (X2+1),BC
        LD      (Y2+1),DE
        SBC     HL,DE                   ; y1-y2
        JR      NC,DrawLine2
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine2:
        LD      (absy+1),HL
        LD      HL,(x1+1)
        SBC     HL,BC                   ; x1-x2
        JR      NC,absy
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
absy:
        LD      DE,0
        XOR     A
        SBC     HL,DE                   ; HL = absx-absy
        JR      c,DrawLine3
        LD      A,#EB                   ; #EB = EX DE,HL
        LD      HL,(x1+1)
        LD      DE,(y1+1)
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      HL,(x2+1)
        LD      DE,(y2+1)
        LD      (x2+1),DE
        LD      (y2+1),HL
DrawLine3:
        LD      (exchg),A
        LD      DE,(y1+1)
        LD      HL,(y2+1)
        SBC     HL,DE
        JR      NC,DrawLine4
        LD      HL,(x1+1)
        LD      DE,(x2+1)
        LD      (x1+1),DE
        LD      (x2+1),HL
        LD      HL,(y1+1)
        LD      DE,(y2+1)
        LD      (y1+1),DE
        LD      (y2+1),HL
DrawLine4:
        LD      HL,(x2+1)
        LD      DE,(x1+1)
        SBC     HL,DE
        LD      HL,-1
        JR      c,DrawLine5
        LD      HL,1
DrawLine5:
        LD      (xincr+1),HL
        LD      HL,(y2+1)
        LD      DE,(y1+1)
        SBC     HL,DE
        LD      (dy+1),HL
x2:
        LD      DE,0
        LD      HL,(x1+1)
        SBC     HL,DE                   ; x1-x2
        JR      NC,DrawLine6
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine6:
        LD      (dx+1),HL
        ADD     HL,HL
dy:
        LD      DE,0
        SBC     HL,DE
        LD      (delta+1),HL
dx:
        LD      HL,0
        SBC     HL,DE
        ADD     HL,HL
        LD      (aincr+1),HL
        LD      HL,(dx+1)
        ADD     HL,HL
        LD      (bincr+1),HL
        LD      HL,(y1+1)
BclDrawLine:
        EX      DE,HL                   ; DE = y1
y2:
        LD      HL,0
        SBC     HL,DE                   ; HL = y2 - y1
        RET     C
x1:
        LD      HL,0                    ; HL = x1
exchg:
        NOP                             ; NOP or EX DE,HL
        SRA     H
        LD      A,L                     ; L = lowpart of x (0..319 & 255)
        RR      L
        AND     3
        ADD     A,A
        LD      (varx+1),A
        RR      L                       ; L = x / 4 (0..79)
        LD      A,E                     ; E = y (0..199)
        LD      (vary+1),A
        LD      E,L
        LD      D,#C0
        AND     #F8
        LD      L,A
        XOR     A
        LD      H,A
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 16
        LD      B,H
        LD      C,L                     ; BC = ( Y >> 3 ) * 16
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 32
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 64
        ADD     HL,BC                   ; HL = ( Y >> 3 ) * 80
        ADD     HL,DE
vary:
        LD      A,0
        AND     7
        ADD     A,A
        ADD     A,A
        ADD     A,A
        ADD     A,H
        LD      H,A
        EX      DE,HL                   ; Save video memory's address in DE
varx:
        LD      HL,0
TabPen:
        LD      BC,TabPen1
        ADD     HL,BC
        LD      C,(HL)                  ; byte to draw
        INC     HL
        LD      A,(HL)                  ; Mask
        EX      DE,HL
        AND     (HL)                    ; video memory's byte
        OR      C                       ; byte to draw
        LD      (HL),A                  ; in video memory
delta:
        LD      HL,0
        BIT     7,H
        JR      NZ,bincr
aincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
        LD      HL,(x1+1)
xincr:
        LD      DE,0
        ADD     HL,DE
        LD      (x1+1),HL
        JR      y1
bincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
y1:
        LD      HL,0
        INC     HL
        LD      (y1+1),HL
        JR      BclDrawLine

TabPen0:
        DB      #00,#77,#00,#BB,#00,#DD,#00,#EE
TabPen1:
        DB      #80,#77,#40,#BB,#20,#DD,#10,#EE
TabPen2:
        DB      #08,#77,#04,#BB,#02,#DD,#01,#EE
TabPen3:
        DB      #88,#77,#44,#BB,#22,#DD,#11,#EE


Beware : The origin (0,0) is at the top left of the screen, and (319,199) is at the bottom right.

mr_lou

Thanks a lot Demoniak.

I can't get the optimized version working, but here is the adapted version of the first version you posted, that works with SDCC.


void setColor(unsigned char color) {
color;
__asm
        LD      A,(IX+4)
        AND     3
        ADD     A,A
        ADD     A,A
        LD      HL,TabPen0
        LD      B,0
        LD      C,A
        ADD     HL,BC
        LD      (TabPen+1),HL
       
TabPen0:
        DB      &00,&00,&00,&00
TabPen1:
        DB      &80,&40,&20,&10
TabPen2:
        DB      &08,&04,&02,&01
TabPen3:
        DB      &88,&44,&22,&11

__endasm;
}

void demoniakLine(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2) {
x1;x2;y1;y2;
__asm
        LD      l,(ix+6)
        LD      h,(ix+7)                ; y1 is now in hl
        LD      e,(ix+4)
        LD      d,(ix+5)               ; x1 is now in de
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      e,(ix+10)
        LD      d,(ix+11)                ; y2 is now in de
        LD      c,(ix+8)
        LD      b,(ix+9)                ; x2 is now in bc
        LD      (x2+1),BC
        LD      (y2+1),DE
        SBC     HL,DE                   ; y1-y2
        JR      NC,DrawLine2
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine2:
        LD      (absy+1),HL
        LD      HL,(x1+1)
        SBC     HL,BC                   ; x1-x2
        JR      NC,absy
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
absy:
        LD      DE,0
        XOR     A
        SBC     HL,DE                   ; HL = absx-absy
        JR      c,DrawLine3
        LD      A,&EB                   ; #EB = EX DE,HL
        LD      HL,(x1+1)
        LD      DE,(y1+1)
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      HL,(x2+1)
        LD      DE,(y2+1)
        LD      (x2+1),DE
        LD      (y2+1),HL
DrawLine3:
        LD      (exchg),A
        LD      DE,(y1+1)
        LD      HL,(y2+1)
        SBC     HL,DE
        JR      NC,DrawLine4
        LD      HL,(x1+1)
        LD      DE,(x2+1)
        LD      (x1+1),DE
        LD      (x2+1),HL
        LD      HL,(y1+1)
        LD      DE,(y2+1)
        LD      (y1+1),DE
        LD      (y2+1),HL
DrawLine4:
        LD      HL,(x2+1)
        LD      DE,(x1+1)
        SBC     HL,DE
        LD      HL,-1
        JR      c,DrawLine5
        LD      HL,1
DrawLine5:
        LD      (xincr+1),HL
        LD      HL,(y2+1)
        LD      DE,(y1+1)
        SBC     HL,DE
        LD      (dy+1),HL
x2:
        LD      DE,0
        LD      HL,(x1+1)
        SBC     HL,DE                   ; x1-x2
        JR      NC,DrawLine6
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine6:
        LD      (dx+1),HL
        ADD     HL,HL
dy:
        LD      DE,0
        SBC     HL,DE
        LD      (delta+1),HL
dx:
        LD      HL,0
        SBC     HL,DE
        ADD     HL,HL
        LD      (aincr+1),HL
        LD      HL,(dx+1)
        ADD     HL,HL
        LD      (bincr+1),HL
        LD      HL,(y1+1)
BclDrawLine:
        EX      DE,HL                   ; DE = y1
y2:
        LD      HL,0
        SBC     HL,DE                   ; HL = y2 - y1
        JP C,demoniakLineDone
x1:
        LD      HL,0                    ; HL = x1
exchg:
        NOP                             ; NOP or EX DE,HL
        SRA     H
        LD      A,L                     ; L = lowpart of x (0..319 & 255)
        RR      L
        AND     3
        LD      (varx+1),A
        RR      L                       ; L = x / 4 (0..79)
        LD      A,E                     ; E = y (0..199)
        LD      (vary+1),A
        LD      E,L
        LD      D,&C0
        AND     &F8
        LD      L,A
        XOR     A
        LD      H,A
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 16
        LD      B,H
        LD      C,L                     ; BC = ( Y >> 3 ) * 16
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 32
        ADD     HL,HL                   ; HL = ( Y >> 3 ) * 64
        ADD     HL,BC                   ; HL = ( Y >> 3 ) * 80
        ADD     HL,DE
        LD      E,A                     ; E = A = 0
vary:
        LD      A,0
        AND     7
        ADD     A,A
        ADD     A,A
        ADD     A,A
        LD      D,A                     ; DE = ( y & 7 ) * 2048
        ADD     HL,DE
        EX      DE,HL
        LD      H,L                     ; L=0
varx:
        LD      L,0
TabPen:
        LD      BC,TabPen1
        ADD     HL,BC
        LD      A,(HL)                  ; byte to draw
        EX      DE,HL
        LD      C,A
        RRCA
        RRCA
        RRCA
        RRCA
        OR      C                       ; Bits 0-3 | Bits 4-7
        CPL                             ; Mask
        AND     (HL)                    ; video memorys byte
        OR      C                       ; byte to draw
        LD      (HL),A                  ; in video memory
delta:
        LD      HL,0
        BIT     7,H
        JR      NZ,bincr
aincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
        LD      HL,(x1+1)
xincr:
        LD      DE,0
        ADD     HL,DE
        LD      (x1+1),HL
        JR      y1
bincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
y1:
        LD      HL,0
        INC     HL
        LD      (y1+1),HL
        JR      BclDrawLine
demoniakLineDone:
__endasm;
}

demoniak

#63
And what about this version:
void InitGfxLib() {
__asm
        LD      HL,#C000
        LD      IX,PreCalcAdr
        LD      B,200
InitGfxLib1:
        LD      (IX+0),L
        LD      (IX+1),H
        LD      DE,#800
        ADD     HL,DE
        JR      NC,InitGfxLibBcl2
        LD      DE,#C050
        ADD     HL,DE
InitGfxLibBcl2:
        INC     IX
        INC     IX
        DJNZ    InitGfxLib1
__endasm;
}

void setColor(unsigned char color) {
color;
__asm
        LD      A,(IX+4)
        AND     3
        ADD     A,A
        ADD     A,A
        ADD     A,A
        LD      HL,TabPen0
        LD      B,0
        LD      C,A
        ADD     HL,BC
        LD      (TabPen+1),HL
__endasm;
}

void demoniakLine(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2) {
x1;x2;y1;y2;
__asm
        LD      L,(IX+8)
        LD      H,(IX+9)                ; y1 is now in hl
        LD      E,(IX+10)
        LD      D,(IX+11)               ; x1 is now in de
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      E,(IX+4)
        LD      D,(IX+5)                ; y2 is now in de
        LD      C,(IX+6)
        LD      B,(IX+7)                ; x2 is now in bc
        LD      (x2+1),BC
        LD      (y2+1),DE
        SBC     HL,DE                   ; y1-y2
        JR      NC,DrawLine2
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine2:
        LD      (absy+1),HL
        LD      HL,(x1+1)
        SBC     HL,BC                   ; x1-x2
        JR      NC,absy
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
absy:
        LD      DE,0
        XOR     A
        SBC     HL,DE                   ; HL = absx-absy
        JR      c,DrawLine3
        LD      A,#EB                   ; #EB = EX DE,HL
        LD      HL,(x1+1)
        LD      DE,(y1+1)
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      HL,(x2+1)
        LD      DE,(y2+1)
        LD      (x2+1),DE
        LD      (y2+1),HL
DrawLine3:
        LD      (exchg),A
        LD      DE,(y1+1)
        LD      HL,(y2+1)
        SBC     HL,DE
        JR      NC,DrawLine4
        LD      HL,(x1+1)
        LD      DE,(x2+1)
        LD      (x1+1),DE
        LD      (x2+1),HL
        LD      HL,(y1+1)
        LD      DE,(y2+1)
        LD      (y1+1),DE
        LD      (y2+1),HL
DrawLine4:
        LD      HL,(x2+1)
        LD      DE,(x1+1)
        SBC     HL,DE
        LD      HL,-1
        JR      c,DrawLine5
        LD      HL,1
DrawLine5:
        LD      (xincr+1),HL
        LD      HL,(y2+1)
        LD      DE,(y1+1)
        SBC     HL,DE
        LD      (dy+1),HL
x2:
        LD      DE,0
        LD      HL,(x1+1)
        SBC     HL,DE                   ; x1-x2
        JR      NC,DrawLine6
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine6:
        LD      (dx+1),HL
        ADD     HL,HL
dy:
        LD      DE,0
        SBC     HL,DE
        LD      (delta+1),HL
dx:
        LD      HL,0
        SBC     HL,DE
        ADD     HL,HL
        LD      (aincr+1),HL
        LD      HL,(dx+1)
        ADD     HL,HL
        LD      (bincr+1),HL
        LD      HL,(y1+1)
BclDrawLine:
        EX      DE,HL                   ; DE = y1
y2:
        LD      HL,0
        SBC     HL,DE                   ; HL = y2 - y1
        JR      C,DemoniakLineDone
x1:
        LD      HL,0                    ; HL = x1
exchg:
        EX      DE,HL                   ; NOP or EX DE,HL
        SRA     H
        LD      A,L                     ; L = lowpart of x (0..319 & 255)
        RR      L
        AND     3
        ADD     A,A
        LD      B,A                     ; b = varx;
        RR      L
        XOR     A
        LD      D,A
        LD      A,L                     ; A = x / 4 (0..79)
        LD      HL,PreCalcAdr
        ADD     HL,DE
        ADD     HL,DE
        ADD     A,(HL)
        INC     HL
        LD      E,A
        LD      A,(HL)
        ADC     A,D
        LD      H,D                     ; H = 0
        LD      D,A
        LD      L,B                     ; L = varx
TabPen:
        LD      BC,TabPen1
        ADD     HL,BC
        LD      C,(HL)                  ; byte to draw
        INC     HL
        LD      A,(HL)                  ; Mask
        EX      DE,HL
        AND     (HL)                    ; video memory's byte
        OR      C                       ; byte to draw
        LD      (HL),A                  ; in video memory
delta:
        LD      HL,0
        BIT     7,H
        JR      NZ,bincr
aincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
        LD      HL,(x1+1)
xincr:
        LD      DE,0
        ADD     HL,DE
        LD      (x1+1),HL
        JR      y1
bincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
y1:
        LD      HL,0
        INC     HL
        LD      (y1+1),HL
        JR      BclDrawLine
TabPen0:
        DB      &00,&77,&00,&BB,&00,&DD,&00,&EE
TabPen1:
        DB      &80,&77,&40,&BB,&20,&DD,&10,&EE
TabPen2:
        DB      &08,&77,&04,&BB,&02,&DD,&01,&EE
TabPen3:
        DB      &88,&77,&44,&BB,&22,&DD,&11,&EE
PreCalcAdr:
        DS     400
demoniakLineDone:
__endasm;
}


Warning : You MUST call InitGfxLib() before drawing lines !

mr_lou

Yup, works after a few adaptions:
All # signs must be replaced with &  (what assembler syntax are you using?)
The LD calls in the beginning of demoniakLine() were in wrong order.
Jump relative to demoniakLineDone was out of range, so had to replace with a JP.


void InitGfxLib() {
__asm
        LD      HL,&C000
        LD      IX,PreCalcAdr
        LD      B,200
InitGfxLib1:
        LD      (IX+0),L
        LD      (IX+1),H
        LD      DE,&800
        ADD     HL,DE
        JR      NC,InitGfxLibBcl2
        LD      DE,&C050
        ADD     HL,DE
InitGfxLibBcl2:
        INC     IX
        INC     IX
        DJNZ    InitGfxLib1
__endasm;
}

void setColor(unsigned char color) {
color;
__asm
        LD      A,(IX+4)
        AND     3
        ADD     A,A
        ADD     A,A
        ADD     A,A
        LD      HL,TabPen0
        LD      B,0
        LD      C,A
        ADD     HL,BC
        LD      (TabPen+1),HL
__endasm;
}

void demoniakLine(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2) {
x1;x2;y1;y2;
__asm
        LD      L,(IX+6)
        LD      H,(IX+7)                ; y1 is now in hl
        LD      E,(IX+4)
        LD      D,(IX+5)               ; x1 is now in de
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      E,(IX+10)
        LD      D,(IX+11)                ; y2 is now in de
        LD      C,(IX+8)
        LD      B,(IX+9)                ; x2 is now in bc
        LD      (x2+1),BC
        LD      (y2+1),DE
        SBC     HL,DE                   ; y1-y2
        JR      NC,DrawLine2
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine2:
        LD      (absy+1),HL
        LD      HL,(x1+1)
        SBC     HL,BC                   ; x1-x2
        JR      NC,absy
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
absy:
        LD      DE,0
        XOR     A
        SBC     HL,DE                   ; HL = absx-absy
        JR      c,DrawLine3
        LD      A,&EB                   ; #EB = EX DE,HL
        LD      HL,(x1+1)
        LD      DE,(y1+1)
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      HL,(x2+1)
        LD      DE,(y2+1)
        LD      (x2+1),DE
        LD      (y2+1),HL
DrawLine3:
        LD      (exchg),A
        LD      DE,(y1+1)
        LD      HL,(y2+1)
        SBC     HL,DE
        JR      NC,DrawLine4
        LD      HL,(x1+1)
        LD      DE,(x2+1)
        LD      (x1+1),DE
        LD      (x2+1),HL
        LD      HL,(y1+1)
        LD      DE,(y2+1)
        LD      (y1+1),DE
        LD      (y2+1),HL
DrawLine4:
        LD      HL,(x2+1)
        LD      DE,(x1+1)
        SBC     HL,DE
        LD      HL,-1
        JR      c,DrawLine5
        LD      HL,1
DrawLine5:
        LD      (xincr+1),HL
        LD      HL,(y2+1)
        LD      DE,(y1+1)
        SBC     HL,DE
        LD      (dy+1),HL
x2:
        LD      DE,0
        LD      HL,(x1+1)
        SBC     HL,DE                   ; x1-x2
        JR      NC,DrawLine6
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine6:
        LD      (dx+1),HL
        ADD     HL,HL
dy:
        LD      DE,0
        SBC     HL,DE
        LD      (delta+1),HL
dx:
        LD      HL,0
        SBC     HL,DE
        ADD     HL,HL
        LD      (aincr+1),HL
        LD      HL,(dx+1)
        ADD     HL,HL
        LD      (bincr+1),HL
        LD      HL,(y1+1)
BclDrawLine:
        EX      DE,HL                   ; DE = y1
y2:
        LD      HL,0
        SBC     HL,DE                   ; HL = y2 - y1
        JP      C,demoniakLineDone
x1:
        LD      HL,0                    ; HL = x1
exchg:
        EX      DE,HL                   ; NOP or EX DE,HL
        SRA     H
        LD      A,L                     ; L = lowpart of x (0..319 & 255)
        RR      L
        AND     3
        ADD     A,A
        LD      B,A                     ; b = varx;
        RR      L
        XOR     A
        LD      D,A
        LD      A,L                     ; A = x / 4 (0..79)
        LD      HL,PreCalcAdr
        ADD     HL,DE
        ADD     HL,DE
        ADD     A,(HL)
        INC     HL
        LD      E,A
        LD      A,(HL)
        ADC     A,D
        LD      H,D                     ; H = 0
        LD      D,A
        LD      L,B                     ; L = varx
TabPen:
        LD      BC,TabPen1
        ADD     HL,BC
        LD      C,(HL)                  ; byte to draw
        INC     HL
        LD      A,(HL)                  ; Mask
        EX      DE,HL
        AND     (HL)                    ; video memory's byte
        OR      C                       ; byte to draw
        LD      (HL),A                  ; in video memory
delta:
        LD      HL,0
        BIT     7,H
        JR      NZ,bincr
aincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
        LD      HL,(x1+1)
xincr:
        LD      DE,0
        ADD     HL,DE
        LD      (x1+1),HL
        JR      y1
bincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
y1:
        LD      HL,0
        INC     HL
        LD      (y1+1),HL
        JR      BclDrawLine
TabPen0:
        DB      &00,&FF,&00,&FF,&00,&FF,&00,&FF
TabPen1:
        DB      &80,&77,&40,&BB,&20,&DD,&10,&EE
TabPen2:
        DB      &08,&77,&04,&BB,&02,&DD,&01,&EE
TabPen3:
        DB      &88,&77,&44,&BB,&22,&DD,&11,&EE
PreCalcAdr:
        DS     400
demoniakLineDone:
__endasm;
}


Quite fast.
I'm putting together another comparison thingy, but need some way of getting the system time in order to time the various methods.
Like in BASIC when I type PRINT TIME, how do I get that TIME value from within assembler?

Can we have a look at that other routine too? :) The one that can only draw a line of 255 pixels. (Is 255 pixels equal to 510 coordinate?)

mr_lou

#65
Alright. Here is another comparison.

BASIC vs SDCC Bresenham algorithm vs SDCC Firmware call vs SDCC Demoniak's routine.

On my CPC464 the results are:
BASIC: 973
Bresenham: 1262
Firmware: 938
Demoniak: 481

So Demoniak's routine is clearly the winner, almost half the time required by firmware calls.

RUN"compare

Can anyone beat that?  :D

NOTE: The Bresenham method requires a CPC464, because it's getting the PEN number from a certain address.

P.S.: Demoniak, it would be interesting to make another comparison including your other routine. And then just adapt all draw-stuff to match the limitations of that.

demoniak

#66
Fast CLS :

void FastCls( unsigned char color )
{
__asm
        LD      HL,(TabPen+1)
        LD      A,(HL)
        INC     HL
        INC     HL
        OR      (HL)
        INC     HL
        INC     HL
        OR      (HL)
        INC     HL
        INC     HL
        OR      (HL)
        LD      L,A
        LD      H,A
        DI
        LD      (OldSP+1),SP
        LD      SP,0
        LD      B,0
BclCls:
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        DJNZ    BclCls
OldSp:
    LD    SP,0
    EI
__endasm;
}

demoniak

Last (?) update for the library with a small optimisation of the DrawLine function :

        ORG     #4000

;
; "Sample" program to test functions
;
        CALL    InitGfxLib
        XOR     A
        CALL    SetPen                  ; Pen0
        CALL    FastCls
        LD      IX,#8000
        LD      A,1
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 1
        LD      HL,0
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,0
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,319
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(0,0,319,0)

        LD      A,2
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 2
        LD      HL,319
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,0
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,319
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,199
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(319,0,319,199)

        LD      A,3
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 3
        LD      HL,319
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,0
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,199
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(319,199,0,199)

        LD      A,1
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 1
        LD      HL,0
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,0
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(0,199,0,0)

        LD      A,2
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 2
        LD      HL,0
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,319
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(0,199,319,0)

        LD      A,3
        LD      (IX+4),A
        CALL    SetPen                  ; Pen 3
        LD      HL,319
        LD      (IX+11),H
        LD      (IX+10),L
        LD      HL,199
        LD      (IX+9),H
        LD      (IX+8),L
        LD      HL,0
        LD      (IX+7),H
        LD      (IX+6),L
        LD      HL,0
        LD      (IX+5),H
        LD      (IX+4),L
        CALL    DrawLine                ; line(319,199,0,0)
        RET

InitGfxLib:
        LD      DE,&C000
        LD      HL,PreCalcAdr
        LD      A,200
InitGfxLib1:
        LD      (HL),E
        INC     H
        LD      (HL),D
        DEC     H
        INC     HL
        EX      DE,HL
        LD      BC,&800
        ADD     HL,BC
        JR      NC,InitGfxLibBcl2
        LD      BC,&C050
        ADD     HL,BC
InitGfxLibBcl2:
        EX      DE,HL
        DEC     A
        JR      NZ,InitGfxLib1
        RET

SetPen:
        LD      A,(IX+4)
        AND     3
        ADD     A,A
        ADD     A,A
        ADD     A,A
        LD      HL,TabPen0
        LD      B,0
        LD      C,A
        ADD     HL,BC
        LD      (TabPen+1),HL
        RET

FastCls:
        LD      HL,(TabPen+1)
        LD      A,(HL)
        INC     HL
        INC     HL
        OR     (HL)
        INC     HL
        INC     HL
        OR     (HL)
        INC     HL
        INC     HL
        OR      (HL)
        LD      L,A
        LD      H,A
        DI
        LD      (OldSP+1),SP
        LD      SP,0
        LD      B,0
BclCls:
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        PUSH    HL
        DJNZ    BclCls
OldSp:
        LD    SP,0
        EI
        RET

DrawLine:
        LD      L,(IX+8)
        LD      H,(IX+9)                ; y1 is now in hl
        LD      E,(IX+10)
        LD      D,(IX+11)               ; x1 is now in de
        LD      (X1+1),DE
        LD      (y1+1),HL
        LD      E,(IX+4)
        LD      D,(IX+5)                ; y2 is now in de
        LD      C,(IX+6)
        LD      B,(IX+7)                ; x2 is now in bc
        LD      (X2+1),BC
        LD      (Y2+1),DE
        SBC     HL,DE                   ; y1-y2
        JR      NC,DrawLine2
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine2:
        LD      (absy+1),HL
        LD      HL,(x1+1)
        SBC     HL,BC                   ; x1-x2
        JR      NC,absy
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
absy:
        LD      DE,0
        XOR     A
        SBC     HL,DE                   ; HL = absx-absy
        JR      c,DrawLine3
        LD      A,&EB                   ; #EB = EX DE,HL
        LD      HL,(x1+1)
        LD      DE,(y1+1)
        LD      (x1+1),DE
        LD      (y1+1),HL
        LD      HL,(x2+1)
        LD      DE,(y2+1)
        LD      (x2+1),DE
        LD      (y2+1),HL
DrawLine3:
        LD      (exchg),A
        LD      DE,(y1+1)
        LD      HL,(y2+1)
        SBC     HL,DE
        JR      NC,DrawLine4
        LD      HL,(x1+1)
        LD      DE,(x2+1)
        LD      (x1+1),DE
        LD      (x2+1),HL
        LD      HL,(y1+1)
        LD      DE,(y2+1)
        LD      (y1+1),DE
        LD      (y2+1),HL
DrawLine4:
        LD      HL,(x2+1)
        LD      DE,(x1+1)
        SBC     HL,DE
        LD      HL,-1
        JR      c,DrawLine5
        LD      HL,1
DrawLine5:
        LD      (xincr+1),HL
        LD      HL,(y2+1)
        LD      DE,(y1+1)
        SBC     HL,DE
        LD      (dy+1),HL
x2:
        LD      DE,0
        LD      HL,(x1+1)
        SBC     HL,DE                   ; x1-x2
        JR      NC,DrawLine6
        XOR     A
        SUB     L
        LD      L,A
        SBC     A,A
        SUB     H
        LD      H,A
DrawLine6:
        LD      (dx+1),HL
        ADD     HL,HL
dy:
        LD      DE,0
        SBC     HL,DE
        LD      (delta+1),HL
dx:
        LD      HL,0
        SBC     HL,DE
        ADD     HL,HL
        LD      (aincr+1),HL
        LD      HL,(dx+1)
        ADD     HL,HL
        LD      (bincr+1),HL
        LD      HL,(y1+1)
BclDrawLine:
        EX      DE,HL                   ; DE = y1
y2:
        LD      HL,0
        SBC     HL,DE                   ; HL = y2 - y1
        JP      C,demoniakLineDone
x1:
        LD      HL,0                    ; HL = x1
exchg:
        EX      DE,HL                   ; NOP or EX DE,HL
        SRA     H
        LD      A,L                     ; L = lowpart of x (0..319 & 255)
        RR      L
        AND     3
        ADD     A,A
        LD      B,A                     ; b = varx;
        XOR     A
        LD      D,A
        LD      A,L                     ; A = x / 4 (0..79)
        RRA
        LD      HL,PreCalcAdr
        ADD     HL,DE
        ADD     A,(HL)
        LD      E,A
        INC     H
        LD      A,(HL)
        ADC     A,D
        LD      H,D                     ; H = 0
        LD      D,A
        LD      L,B                     ; L = varx
TabPen:
        LD      BC,TabPen1
        ADD     HL,BC
        LD      C,(HL)                  ; byte to draw
        INC     HL
        LD      A,(HL)                  ; Mask
        EX      DE,HL
        AND     (HL)                    ; video memory's byte
        OR      C                       ; byte to draw
        LD      (HL),A                  ; in video memory
delta:
        LD      HL,0
        BIT     7,H
        JR      NZ,bincr
aincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
        LD      HL,(x1+1)
xincr:
        LD      DE,0
        ADD     HL,DE
        LD      (x1+1),HL
        JR      y1
bincr:
        LD      DE,0
        ADD     HL,DE
        LD      (delta+1),HL
y1:
        LD      HL,0
        INC     HL
        LD      (y1+1),HL
        JR      BclDrawLine

TabPen0:
        DB      &00,&77,&00,&BB,&00,&DD,&00,&EE
TabPen1:
        DB      &80,&77,&40,&BB,&20,&DD,&10,&EE
TabPen2:
        DB      &08,&77,&04,&BB,&02,&DD,&01,&EE
TabPen3:
        DB      &88,&77,&44,&BB,&22,&DD,&11,&EE
PreCalcAdr:
        DS     512
demoniakLineDone:
        RET


Sorry, the arguments are perhaps in bad order, I've only tested this code directly in winape's assembler...

mr_lou

Demoniak you rule.

After that last optimization, your routine is down to 460, which is more than twice the speed of firmware call from SDCC.

RUN"compare

The Bresenham algorithm is no longer part of it.

One thing I've noticed about Demoniak's routine though, is that the first 13 lines seem to be shorter than the rest. Dunno why that is.

TFM

Quote from: mr_lou on 15:29, 19 December 11
Can anyone beat that?  :D

Maybe. Since your C skills are good, may you can provide the example in proper Small-C so I could check my routine. I have no time to install SDCC, sorry. What I need is just the C program using the drawline() routine. I have no docs for Small-C, so I get errors and don't know why.

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

mr_lou

Attached is the SDCC source I've done so far. (Rename main.asm to main.c - can't attach files that ends with .c)

All this here is only initial experiments though. It's not yet the framework I have in mind.

mr_lou

Quote from: TFM/FS on 20:58, 19 December 11
Just tell me exactly what you want (email: futuresoft at gmx . de). My stupid quesion about the "what" is not to bother you, I just need to konw. :)  However, I'm not into SDCC, but if I get some examples I may can adapt what I have, the assembler part is not problem (as long as I know the syntax of that wired XXXX assembler, so some examples will be good). But let's do that via email, it's IMHO more efficient.

I have asked Gryzor about adding a project page at the Wiki. Then I can describe everything there, and maybe get more people interested and contributing.
I will post a link to the project-page when/if I get to make it.

TFM

Quote from: mr_lou on 22:48, 19 December 11
I have asked Gryzor about adding a project page at the Wiki. Then I can describe everything there, and maybe get more people interested and contributing.
I will post a link to the project-page when/if I get to make it.

That's a great idea!
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

demoniak

mr_lou: can you test this :

void FillRect(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2) {
__asm
        LD      E,(IX+6)
        LD      D,(IX+7)                ; y1 is now in DE
        LD      L,(IX+4)
        LD      H,(IX+5)                ; x1 is now in HL
        LD      (FillRectBcl+1),HL
        LD      A,(IX+10)               ; y2
        LD      (rectY2+1),A
        LD      C,(IX+8)
        LD      B,(IX+9)                ; x2 is now in HL
        LD      (rectX2+1),HL
FillRectBcl:
        LD      BC,0                    ; rectX1
rectX2:
        LD      HL,0                    ; rectX2
        PUSH    DE
        XOR     A
        SBC     HL,BC                   ; HL=x2-x1;
        PUSH    HL                      ; Sauvegarde X2-x1
        LD      HL,PreCalcAdr
        ADD     HL,DE
        LD      D,A
        LD      A,(HL)
        INC     H
        LD      H,(HL)
        LD      L,A
        LD      A,B
        RRA                             ; Bit de poids fort x1 dans carry
        LD      A,C                     ; bits 0..7 de x1
        RRA                             ; x1/2
        AND     A
        RRA
        LD      E,A
        ADD     HL,DE
        EX      DE,HL                   ; DE = screen adr
        LD      HL,(TabPen+1)
        LD      B,(HL)
        LD      A,B
        LD      (DrawLigneHor7+1),A
        LD      A,C
        AND     3
        LD      C,B
        EX      DE,HL                   ; HL = screen adr
        LD      B,4
DrawLigneHor1:
        AND     A
        JR      Z,DrawLigneHor2
        RRC     C
        DEC     B
        DEC     A
        JR      DrawLigneHor1
DrawLigneHor2:
        LD      A,(DrawLigneHor7+1)
        LD      D,A
        RRCA
        OR      D
        RRCA
        OR      D
        RRCA
        OR      D
        LD      (DrawLigneHor5+1),A
        POP     DE
        INC     DE
DrawLigneHor3:
        LD      A,(HL)
        OR      C
        LD      (HL),A
        RRC     C
        DJNZ    DrawLigneHor8
        LD      A,E
DrawLigneHor4:
        INC     HL
        SUB     4
        JR      C,DrawLigneHor7
        LD      E,A
DrawLigneHor5:
        LD      (HL),0
        JR      DrawLigneHor4
DrawLigneHor7:
        LD      BC,&400
DrawLigneHor8:
        DEC     DE
        LD      A,D
        OR      E
        JR      NZ,DrawLigneHor3
        POP     DE
        INC     E
        LD      A,E
rectY2:
        CP      0
        JR      NZ,FillRectBcl
__endasm;
}


mr_lou

Quote from: demoniak on 13:24, 20 December 11
mr_lou: can you test this

You bet.
First I have to submit a project-page on the wiki though, but I'm blocked when I try to submit. :(
Says my page is spam. Then I clicked "Return" and the whole text was gone!!!
Luckily I'd typed everything in gEdit first, so nothing is lost.

Powered by SMFPacks Menu Editor Mod