DAAD Adventure Writer and ZX Next

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

Alcoholics Anonymous
Posts: 508
Joined: Mon May 29, 2017 7:00 pm

Re: DAAD Adventure Writer and ZX Next

Post by Alcoholics Anonymous » Sun Sep 15, 2019 10:24 pm

Ped7g wrote:
Sun Sep 15, 2019 9:33 pm
Can't even recall how long ago that was, I think the cards have now something like 2.00.12 +- ... But I recall "it was the last time, there's no more budget for another rewrite" ...
I can't remember when that was either, maybe when the pcbs were first made and some tests were done? There has been another time when things were set to go and the core was frozen but I don't think it was that time. Anyway as the hardware end was not ready, the flashing didn't go ahead and we got more time.

3.00.00 and the initial pi card being worked on now is the goal. Hopefully it will be ready in time, otherwise 3.00.00 will in fact be 2.00.29 (sms requires a version number ahead of time and 3.00.00 was given to them).

User avatar
Uto
Posts: 55
Joined: Tue May 30, 2017 9:33 am

Re: DAAD Adventure Writer and ZX Next

Post by Uto » Sun Sep 15, 2019 10:54 pm

Ok guys, i'll go for 3.0 compatibility, as that should be enough for most people.

May you plese check if this logic makes sense?

1) Set up Layer2:

LD A, 2 ; Activate Layer 2
LD BC, LAYER2_ACCESS_PORT
OUT (C),A

NEXTREG REG_SPRITE_LAYERS, 0 ; Make sure it's S-L-U

NEXTREG REG_LAYER2_RAM_PAGE, 12 ; Use page 12, 13 and 14 for Layer2

LD A, 116 ; My test image is 116 pixels high
NEXTREG REG_CLIP_WINDOW_CTRL, $20
NEXTREG REG_CLIP_LAYER2, A
NEXTREG REG_CLIP_WINDOW_CTRL, $30
NEXTREG REG_CLIP_LAYER2, A

2) Load the palette:

First I set the index (just once)

NEXTREG REG_PALETTE_INDEX,0

Then call this 256 times (with A changing values of course, one per each palette color):

NEXTREG REG_PALETTE_VALUE, A

3) Load pixel data:

I change MM7 to 24 (as I put Layer2 at 16K bank 12), and read 8K from file at 0xE000, if there are more, then I change MMU7 to 25, and readk 8K more. I do that as much times as needed until the file is loaded (MMU7=24,25,26,27 etc.)



I change the MMU using the MMU regiters:

NEXTREG REG_MMU7, 1

Finally I restore the original MMU7 page, that according documentation is OK page 1:

NEXTREG REG_MMU7, 1

That's all, but it doesn't work, The game doesn't freeze or reset, and I know the ULA layer is there somewhere although i cannot see it, cause I can use the compass directions to move around the game, and when I enter valid direcitions I see my code is fired (to paint the new location picture) and when I enter invalid directions it is not fired.

I can only see a dark green layer that covers the whole screen, and ocassilnaly I see an single column of random pixels.

Oh, that's is my definition of ports:

Code: Select all

	define LAYER2_ACCESS_PORT   $123B
			

			define REG_LAYER2_RAM_PAGE  $12
			define REG_TRANSPARENCY	    $14
			define REG_SPRITE_LAYERS	$15
			define REG_CLIP_LAYER2		$18
			define REG_CLIP_WINDOW_CTRL $1C
			define REG_PALETTE_INDEX    $40
			define REG_PALETTE_VALUE	$41
			define REG_MMU7			 	$57

User avatar
Uto
Posts: 55
Joined: Tue May 30, 2017 9:33 am

Re: DAAD Adventure Writer and ZX Next

Post by Uto » Sun Sep 15, 2019 10:59 pm

I'm just wondering right now if I have made the clip window wrong, I 've condidered the window I define in the registers is the one that is visible. Maybe it's the other way around?

Or maybe clipping doesn't mean the rest of the screen is visible, and only means whatever is in layer 2 out of that window is not shown, but it doesn't make it transparent.

Well, it's too late, I'll check tomorrow :-)

Ped7g
Posts: 109
Joined: Mon Jul 16, 2018 7:11 pm

Re: DAAD Adventure Writer and ZX Next

Post by Ped7g » Mon Sep 16, 2019 4:06 am

Uto wrote:
Sun Sep 15, 2019 10:54 pm
LD A, 116 ; My test image is 116 pixels high
NEXTREG REG_CLIP_WINDOW_CTRL, $20
NEXTREG REG_CLIP_LAYER2, A
NEXTREG REG_CLIP_WINDOW_CTRL, $30
NEXTREG REG_CLIP_LAYER2, A
The $1C clip control has bits 7-4 reserved, only bits 3-0 are to reset index of particular window (index = which coordinate the next write will replace, reset = first "X1" coordinate)
The $18 is then use to define "window" which is visible, everything else is clipped away.

If you want to show only rectangular area [20,10] -> [199,99] (inclusive, i.e. 180x90 pixels rectangle), then like this:

Code: Select all

        NEXTREG REG_CLIP_WINDOW_CTRL, 1   ; reset Layer2 clip window index (to X1)
        NEXTREG REG_CLIP_LAYER2, 20     ; clip.layer2.x1 = 20
        NEXTREG REG_CLIP_LAYER2, 199    ; clip.layer2.x2 = 199
        NEXTREG REG_CLIP_LAYER2, 10     ; clip.layer2.y1 = 10
        NEXTREG REG_CLIP_LAYER2, 99     ; clip.layer2.y2 = 99
(the default values after reset are: 0,255,0,191 = full 256x192 layer2 area is visible)
2) Load the palette:
You don't show the active palette setup? i.e. I would expect you to: NEXTREG $43, %0'001'0'0'0'0
= auto-increment ON, active palette = first layer2 pal, use all "first" palettes for display and Enhanced ULA off
Then setting $40 = 0 and 256x $41 = RRRGGGBB should work and set up palette for Layer2 image.
3) Load pixel data:
Should be correct and work.

User avatar
SevenFFF
Posts: 221
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: DAAD Adventure Writer and ZX Next

Post by SevenFFF » Mon Sep 16, 2019 2:31 pm

I think Ped has covered it.

The clip window is definitely wrong, and his correction should fix that.

Check to see if the first palette entry is dark green. If so, then it's likely you're writing the same value to all 256 entries. You can test this by temporarily commenting out the palette setting code, after fixing the clip window. If you see your image, but in the wrong colours, then the palette writing code is buggy.

It's less likely to be a problem with image loading failing/going to the wrong addresses/banks. 16k Banks >8 are filled with random values at power on, so if the image loading code was buggy you would see a multicolour noise pattern if the palette loading code is buggy.

Are you doing this on a hardware board? If so, you can use the Multiface/M1 (button to the right of the SD card) to inspect memory in a particular bank, and inspect register values. (Not on core 3.00.00 yet though - there is a Multoface problem in this test core that will be corrected in the next version.)
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

User avatar
Uto
Posts: 55
Joined: Tue May 30, 2017 9:33 am

Re: DAAD Adventure Writer and ZX Next

Post by Uto » Mon Sep 16, 2019 4:09 pm

Thanks, I did your suggested changes and still doesn't work, althoug at least now I don't see the green layer, just nothing, or almost nothing it's painted (I see some pixels erased in the area where there is text in the ULA layer).

Anyway, it looks much better, and I believe I'm close. I'm using ZesarUX and I think it allows me to view different memory areas, so I can check if the pixels are where they should be. I'll have some time later tonight to review the code, run it step by step a bit, and see what happens.

Anyway, If I'm not successful, I will post code here, it's not that I want to keep it secret, the whole project is open source and soon or later the next version will join other 8 bit friends versions at github :-)

User avatar
SevenFFF
Posts: 221
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: DAAD Adventure Writer and ZX Next

Post by SevenFFF » Mon Sep 16, 2019 4:28 pm

Sounds good.

Another thing to double-check regarding loading pixel data: after the rst 0x08 call, test carry, and if set, a contains the error code. Sometimes people skip the this check, but it's good to always do it, and freeze with a red border if there are any errors, or something similar.

Sometimes unexpected things happen, like you are not in the directory you assumed you were, so you are not expecting a DOS fail.

Code: Select all

Unknown error ; 0, esx_ok
OK ; 1, esx_eok
Nonsense in esxDOS ; 2, esx_nonsense
Statement end error ; 3, esx_estend
Wrong file type ; 4, esx_ewrtype
No such file or dir ; 5, esx_enoent
I/O error ; 6, esx_eio
Invalid filename ; 7, esx_einval
Access denied ; 8, esx_eacces
Drive full ; 9, esx_enospc
Invalid i/o request ; 10, esx_enxio
No such drive ; 11, esx_enodrv
Too many files open ; 12, esx_enfile
Bad file number ; 13, esx_ebadf
No such device ; 14, esx_enodev
File pointer overflow ; 15, esx_eoverflow
Is a directory ; 16, esx_eisdir
Not a directory ; 17, esx_enotdir
Already exists ; 18, esx_eexist
Invalid path ; 19, esx_epath
Missing system ; 20, esx_esys
Path too long ; 21, esx_enametoolong
No such command ; 22, esx_enocmd
In use ; 23, esx_einuse
Read only ; 24, esx_erdonly
Verify failed ; 25, esx_everify
Sys file load error ; 26, esx_eloadingko
Directory in use ; 27, esx_edirinuse
MAPRAM is active ; 28, esx_emapramactive
Drive busy ; 29, esx_edrivebusy
Unknown filesystem ; 30, esx_efsunknown
Device busy ; 31, esx_edevicebusy
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

Ped7g
Posts: 109
Joined: Mon Jul 16, 2018 7:11 pm

Re: DAAD Adventure Writer and ZX Next

Post by Ped7g » Mon Sep 16, 2019 6:25 pm

ZEsarUX has quite powerful debugger... I find it's GUI a bit cumbersome and limiting, but compared to "no debugger at all" it's beautiful and works really well (you can even view copper code, sprite memory, etc, but most often just breakpointing into code and single-stepping over instructions checking register values is enough, at least for me).

I still kinda prefer CSpect from UX point of view and how it displays the debugger, but unfortunately both emulators are mixed bag when it comes to accuracy, so in the end I'm often forced to use the one where the particular feature is emulated better. But for your current "load L2 image and use clip window" none of that should worry you, these basic flags and nextregs are emulated on both sides really well. Although it may be tricky to run them correctly, also setting directory where they should look for `fopen` files, etc.. I'm not even sure how to do it correctly with Zes except building full card image, I think it actually doesn't check host file system? Maybe that's your issue, opening other files while you don't have them on the card image? But I may remember it incorrectly. CSpect can definitely work with host file system, you just need to provide current (or whichever you want) directory by "-mmc=./" argument (maybe opposite slash on windows, but I have only linux, so I don't know for sure).

User avatar
SevenFFF
Posts: 221
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: DAAD Adventure Writer and ZX Next

Post by SevenFFF » Mon Sep 16, 2019 7:06 pm

Yes, that's a very good point.

ZEsarux will use the host file system if you use some options: tbblue-fast-boot-mode, enable-esxdos-handler, esxdos-root-dir. But you can only use a few file types for the launch program - SNA, TAP, maybe a couple more. Here's a full example:

zesarux.exe --noconfigfile --machine tbblue --realvideo --enabletimexvideo --frameskip 0 --disable-autoframeskip --nosplash --nowelcomemessage --quickexit --gui-style "ZXSpectr" --def-f-function F4 "HardReset" --def-f-function F10 "ExitEmulator" --tbblue-fast-boot-mode --sna-no-change-machine --enable-esxdos-handler --esxdos-root-dir "C:\Users\robin\Documents\Visual Studio 2015\Projects\Spectron2084\sd" "C:\Users\robin\Documents\Visual Studio 2015\Projects\Spectron2084\bin\Spectron2084.sna"

Actually the realvideo option is important too. Without this, I think, layer 2 is not rendered at all. Worth checking you have it set.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel Spectron 2084blog

Stefan123
Posts: 102
Joined: Mon Jun 05, 2017 9:38 pm

Re: DAAD Adventure Writer and ZX Next

Post by Stefan123 » Mon Sep 16, 2019 8:31 pm

Hi Uto,

Great news that you are adding layer 2 graphics support to DAAD! I use layer 2 as the foreground layer for displaying images in the Spectrum Next conversions of the Magnetic Scrolls games. The background layer uses either standard ULA mode or Timex hi-res mode for displaying the text. The layer 2 screen is limited to the first 136 lines using a clip window. The height of the layer 2 clip window can be changed by the user using the mouse (drag or mouse wheel) or the keyboard (up and down arrow keys) to make more or less room for the text.

The status bar (showing the current location, score and number of turns) is displayed above the image in the top border (using hardware sprites) to save screen real estate.

I temporarily use MMU slot 2 (ULA screen, 16K - 24K) to load layer 2 images in 8 KB chunks to MMU pages 16 to 21 (or 22 to 27 depending on which layer 2 screen is set as front/back buffer). It's safe to use MMU slot 2 in this way since the ULA screen is rendered from the contents of MMU page 10 and not from what is currently mapped in to the address range 16K - 24K.

There are several tools available for converting images to the layer 2 raw format. I use my own tools on GitHub, which are based on Jim's original BMP conversion tools.

Post Reply