Problem with intrinsic_ldi() for sdcc_ix

ZX80, ZX 81, ZX Spectrum, TS2068 and other clones
Post Reply
Stefan123
Member
Posts: 85
Joined: Fri Oct 21, 2016 7:57 am

Problem with intrinsic_ldi() for sdcc_ix

Post by Stefan123 »

When writing Next layer 2 screen code I found a problem with the intrinsic_ldi() function for sdcc_ix. It works fine for sccz80 and sdcc_iy but not for sdcc_ix.

Below is a test program that should clear the layer 2 screen to a given color (yellow) using intrinsic_ldi():

Code: Select all

/*
 * zcc +zx -vn -SO3 -startup=30 -clib=sdcc_ix -m --max-allocs-per-node200000 test_ldi.c -o test_ldi -create-app
 */

#include <input.h>
#include <intrinsic.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

#pragma output CRT_ORG_CODE = 0x8000
#pragma output REGISTER_SP = 0
#pragma output CLIB_MALLOC_HEAP_SIZE = 0
#pragma output CLIB_STDIO_HEAP_SIZE = 0
#pragma output CLIB_FOPEN_MAX = -1

__sfr __banked __at 0x123B IO_LAYER2_PORT;

static uint8_t buf_256[256];

static void layer2_config(uint8_t layer2_screen_section)
{
    IO_LAYER2_PORT = 0x03 | (layer2_screen_section << 6);
}

static void layer2_clear_screen_section(void)
{
    uint8_t height = 64;
    uint8_t *dest = 0;

    while (height--)
    {
        // This doesn't work with sdcc_ix
        intrinsic_ldi(dest, buf_256, 256);
        dest += 256;
    }
}

static void layer2_clear_screen(uint8_t color)
{
    memset(buf_256, color, 256);

    layer2_config(0);
    layer2_clear_screen_section();

    layer2_config(1);
    layer2_clear_screen_section();

    layer2_config(2);
    layer2_clear_screen_section();
}

int main(void)
{
    layer2_clear_screen(0xFE);
    in_wait_key();
    return 0;
}
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

The generated code is awful for sdcc_ix:

Code: Select all

l_layer2_clear_screen_section_00101:
        ld        b, c
        dec        c
        ld        a, b
        or        a, a
        ret        Z
        ld        de,_buf_256
        push        hl
        pop        iy
        push        hl
        push        bc
        push        de
        push        iy
        pop        de
        pop        hl
        pop        bc
        pop        hl  ;; *
        push        hl
        push        bc
        call        ____sdcc_ldi_256
All that pushing and popping is about doing an effective "ex de,hl" and it bungles that by the pop marked * above.

I'll see if it can be done a different way.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I'm fixing this one in the peephole optimizer. There's something inside sdcc that's doing this crazy push/pop series.
https://github.com/z88dk/z88dk/commit/d ... ac57ed147d
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I should say fixed for compiles with at least -SO2 (this includes the default compile). SO1 level keeps sdcc's native behaviour.
Stefan123
Member
Posts: 85
Joined: Fri Oct 21, 2016 7:57 am

Post by Stefan123 »

Unfortunately, the intrinsic_ldi() function for sdcc_ix is still broken as can be seen by running the test program I included in my first post.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

The test program is working for me? However, I can't get it to run as .sna so I am still looking at this.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

There was a bug in sna file generation when sp=0:
https://github.com/z88dk/z88dk/commit/7 ... 00cbd67607

It should work now. The sna I generated caused cspect to immediately crash but it works on ZEsaruX.

The clib=sdcc_ix compile runs for me.
Stefan123
Member
Posts: 85
Joined: Fri Oct 21, 2016 7:57 am

Post by Stefan123 »

Alvin, I'm sorry for misleading you. When I retested intrinsic_ldi() for sdcc_ix, I must have used the wrong version of z88dk. My intention was to use the snapshot from 2017-08-27 but I must have used another one... I have over twenty different z88dk installations on my computer. I save the older ones when I upgrade in case I need to revert. I guess I have hit my limit on how many z88dk versions I'm capable of managing - time to do some clean-up now :)
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

I've no plans to delete the old nightly kits - I do eventually move them into year folders, so you can always download old versions easily enough.
Post Reply