Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdcc][zx81] Broken binary for XChaze zx81 #1976

Open
Fabrizio-Caruso opened this issue Feb 17, 2022 · 8 comments
Open

[sdcc][zx81] Broken binary for XChaze zx81 #1976

Fabrizio-Caruso opened this issue Feb 17, 2022 · 8 comments

Comments

@Fabrizio-Caruso
Copy link

Fabrizio-Caruso commented Feb 17, 2022

If I compile my game Cross Horde(built with Cross-Lib), I get a broken binary (blank screen after pressing a key) with ZSDCC and a working binary with SCCZ80.

@feilipu, I may have a new failing test.

I have included .map and binaries.
HORDE_builds.zip

My Makefile target looks like:

zx81_no_gfx_16k:
	$(Z88DK_PATH)$(MYZ88DK) +zx81 $(ZSDCC_OPTS) \
	$(INCLUDE_OPTS) -compiler=sdcc   \
	--opt-code-size -D_XL_SLOW_DOWN_FACTOR=1 \
	-vn -D_API_VERSION=2 \
	-D__ZX81__ -DFULL_GAME -pragma-define:ZX_CHAR_XLATE_MODE=1 \
...
	-lndos \
	-create-app -o  $(BUILD_PATH)/X$(GAME_NAME)_zx81_16k.prg \
	$(CROSS_LIB_PATH)/sleep/sleep_macros.c \
	$(FULL_FILES)
	rm $(BUILD_PATH)/X$(GAME_NAME)_zx81_16k.prg

This target can be built with Cross-Lib by the following command (run in the ./src directory)

xl horde zx81
@suborb
Copy link
Member

suborb commented Feb 17, 2022

The zx81 uses one of the index registers for display generation and sdcc may well end up using both of them as part of the codegen with the default options.

Adding --reserve-regs-iy may help.

@Fabrizio-Caruso
Copy link
Author

@suborb
Using --reserve-regs-iy -compiler=sdcc does not fix the issue :-(

I have included the binary and map compiled with --reserve-regs-iy
RESERVE_Y_build.zip

@Fabrizio-Caruso
Copy link
Author

@suborb @feilipu
Maybe it helps to know that the compiler is printing some message about conditional flow change:

zcc.exe +zx81  --reserve-regs-iy -compiler=sdcc -SO3  -DFORCE_NARROW -DFULL_LOWER_BORDER -DALT_SLEEP -DNO_SLOW_DOWN_MACRO -DNO_WALL -DNO_BLINKING -D_API_VERSION=2 \
-Icross_lib -Icross_lib/sleep -Icross_lib/display -Icross_lib/display/graphics_mode -Icross_lib/display/alt_print -Icross_lib/include -Icross_lib/sound -Icross_lib/sound/cc65/atmos -Icross_lib/sound/cc65/c264 -Icross_lib/sound/cc65/pokey -Icross_lib/sound/cc65/sid -Icross_lib/sound/cc65/vic20 -Icross_lib/sound/cc65/gamate -Icross_lib/sound/cc65/creativision -Icross_lib/sound/cc65/pet -Icross_lib/sound/z88dk/bit_bang -Icross_lib/sound/z88dk/gb -Icross_lib/sound/z88dk/psg -Icross_lib/sound/lcc1802/comx -Icross_lib/sound/cmoc/mo5 -Icross_lib/sound/generic -Icross_lib/text -Icross_lib/input -Icross_lib/rand -Icross_lib/display/redefine_characters -Icross_lib/display/tiles -Igames/horde/generated_assets -Igames/horde   \
--opt-code-size -D_XL_SLOW_DOWN_FACTOR=1 \
-vn -D_API_VERSION=2 \
-D__ZX81__ -DFULL_GAME -pragma-define:ZX_CHAR_XLATE_MODE=1 \
-DMAX_ARROWS_ON_SCREEN=7 -DNUMBER_OF_MISSILES=4 -DMISSILE_DROP_LOOP_MASK=1 -DSMALL_WALL \
-DEND_SCREEN -DBETWEEN_LEVEL \
-DCONIO -DNO_INIT_GRAPHICS \
-lndos \
-create-app -o  ../build/Xhorde_zx81_16k.prg \
cross_lib/sleep/sleep_macros.c \
cross_lib/display/display_macros.c cross_lib/input/input_macros.c cross_lib/text/text_macros.c games/horde/main.c
games/horde/main.c:376: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
games/horde/main.c:471: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
games/horde/main.c:825: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
games/horde/main.c:2395: warning 126: unreachable code

@dbolli
Copy link

dbolli commented Feb 17, 2022

ZX81 uses IX register for display (including WRX hires) so unless your code runs in the equivalent of FAST mode, you will need to preserve IX via --reserve-regs-ix

@suborb
Copy link
Member

suborb commented Feb 17, 2022

@dbolli zx81 runs with --IXIY which swaps the index registers at assembly time. This does makes for a bit of head scratching at times but does work.

I guess there's 3 areas where something could be wrong:

  1. The CRT
  2. The compiled program
  3. The library routines

Given that it works with sccz80 that should eliminate 1 and 3 (though sdcc will some different library routines). Running it through a quick disassembly (z88dk-dis -o 0x4009 -x Xhorde_zx81_16k.map Xhorde_zx81_16k.P) the only place I can see ix being used (outside of crt0) is in a routine that shouldn't be used (I guess you don't use 64 bit numbers!)

Likewise I've got a memory of af' being reserved as well but again there's no uses.

So it's pointing at 2, I guess the first thing to try is to remove the optimisation (--opt-code-size and change the SO option?)

@dbolli
Copy link

dbolli commented Feb 17, 2022

@suborb

I've got a memory of af' being reserved as well

Correct, the NMI display ROM routine at $0066 uses AF' as a display line counter.

@feilipu
Copy link
Collaborator

feilipu commented Feb 18, 2022

I've built it, but I can't do much as will be AFK for a few days.

Is there a web emulator around for ZX81 that you can drop .P files into and run them?
I've only found emulators with pre-canned executables.

@dbolli
Copy link

dbolli commented Feb 18, 2022

@feilipu

Is there a web emulator around for ZX81 that you can drop .P files into and run them?

http://www.vavasour.ca/jeff/ts1000/

if your browser supports java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants