Cannot create .sna file with CRT_ORG_CODE less than 0x8000

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

Cannot create .sna file with CRT_ORG_CODE less than 0x8000

Post by Stefan123 »

If you create an .sna snapshot file you will get the following error if CRT_ORG_CODE is less than 0x8000:

"Error: ORG address xxxx not in range"

For example, I have set CRT_ORG_CODE to 0x6164.

The following lines in z88dk/src/appmake/zx.c are suspicious:

Code: Select all

if ((origin -= 0x4000) < 0x4000)
    exit_log(1, "Error: ORG address %u not in range\n", origin);
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

It should be fixed now.
Stefan123
Member
Posts: 85
Joined: Fri Oct 21, 2016 7:57 am

Post by Stefan123 »

Thanks, I will try it out tonight.
Stefan123
Member
Posts: 85
Joined: Fri Oct 21, 2016 7:57 am

Post by Stefan123 »

I can now set CRT_ORG_CODE to something lower than 0x8000 when building an SNA file but I have encountered another problem.

I'm trying to put my IM2 interrupt service routine at 0x6000 (257 bytes long filled with 0x61 bytes). Then I have an empty ISR at 0x6161 occupying three bytes and thus have room for the CRT_ORG_CODE at 0x6164. This works fine when building a TAP file. However, when building an SNA file and trying to run it in ZEsarUX or CSpect, it crashes. If I move CRT_ORG_CODE to 0x6200, the SNA file works. Is this because of a bug in z88dk or a limitation in the SNA format or is the memory right below 0x6200 used for some other purpose?

Here is a simple test program that demonstrates the problem (without any IM2 ISR). If CRT_ORG_CODE is set to 0x6164, the program crashes. However, if set to 0x6200 or higher it works.

Code: Select all

/*
 * Build:
 * zcc +zx -vn -O3 -startup=30 -clib=new -m test_sna.c -o test_sna -create-app -Cz"--sna"
 *
 * Run:
 * CSpect.exe -zxnext -s7 -mmc=.\ test_sna.sna
 */

#include <input.h>
#include <stdio.h>

// CRT_ORG_CODE = 0x6164 doesn't work for snapshot
// images but, for example, 0x6200 works.

#pragma output CRT_ORG_CODE = 0x6164
//#pragma output CRT_ORG_CODE = 0x6200
#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

int main(void)
{
    printf("Hello world!\n");
    in_wait_key();
    return 0;
}
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

I think the problem is we're using a prototype sna and filling that in. The prototype sna has a stack location of 25000 IIRC which is 0x61a8 so in the course of making the sna, the starting PC will be pushed on the stack there.

I'll have to change that to something more robust like using the program's defined stack pointer or stealing a couple of screen bytes.
alvin
Well known member
Posts: 1872
Joined: Mon Jul 16, 2007 7:39 pm

Post by alvin »

Should be fixed now. The snapshot creator now pays attention to CRT_ORG_CODE, REGISTER_SP and CRT_ENABLE_EIDI (to know if interrupts are initially enabled)
Stefan123
Member
Posts: 85
Joined: Fri Oct 21, 2016 7:57 am

Post by Stefan123 »

I have tested your fix now and it works perfect.
Post Reply