Tilemap in vForth - first example

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

funkheld
Posts: 78
Joined: Tue May 11, 2021 5:36 pm

Re: Tilemap in vForth - first example

Postby funkheld » Sat Oct 09, 2021 7:47 pm

hello, thanks for your quick help.
as always, your tips are masterful. it works.

thanks.
greeting
Attachments
tilemap1.jpg
tilemap1.jpg (28.92 KiB) Viewed 331 times

funkheld
Posts: 78
Joined: Tue May 11, 2021 5:36 pm

Re: Tilemap in vForth - first example

Postby funkheld » Sun Oct 10, 2021 7:04 am

Hi there Mmattsteel,
thanks for your help for the tilemap in vforth

thanks.
greeting
Last edited by funkheld on Mon Oct 11, 2021 8:08 am, edited 1 time in total.

funkheld
Posts: 78
Joined: Tue May 11, 2021 5:36 pm

Re: Tilemap in vForth - first example

Postby funkheld » Mon Oct 11, 2021 7:08 am

hello, good afternoon master.
I once looked at this table:
https://wiki.specnext.dev/Board_feature_control

address $12 is interesting for moving the layer2 address.
only when i move this layer2 address, i don't know which new address it is.

with address $18 I can switch off layer2 at tilemap.
I have not yet understood how to switch off with x1, x2, y1, y2 at address $18 ????
sometimes it goes 0 0 0 0 24 reg! or 255 255 255 255 24 reg! ???

the tilemap works fine.
with empty everything is "leer" delete and with tile-example I write it again.
Super....

greeting

start with "los" :

Code: Select all

Hex 
needs binary 
needs layers
needs j

MARKER TASK
\ 0x68 (104) - ULA Control. disable ULA output
\ 80 68 reg!
\ 0x6B (107) - Tilemap Control
\ bin 10100001 hex 6b reg!

\ 0x6B (107) Tilemap Control
\ bit 7 = 1 enable the tilemap
\ bit 6 = 0 for 40x32, 1 for 80x32
\ bit 5 = 1 eliminate the attribute entry in the tilemap
\ bit 4 = Palette select
\ bit 3-2 = reserved, must be 0
\ bit 1 = 1 Activate 512 tile mode
\ bit 0 = 1 Force tilemap on top of ULA

: TILE-ON
  [ binary ] 11100001 [ hex ] 6B reg!
;

: TILE-OFF
  [ binary ] 00100001 [ hex ] 6B reg!
;

HEX
: TILE-BASE
  0B 6F reg!  \ Tile Definitions Base Address
  00 6E reg!  \ Tilemap Base Address at $4000
;
DECIMAL

: TILE-BIT        ( c -- d )
  7 LSHIFT 0 0    ( n d )
  8 0 DO
    2DUP D+ 2DUP D+ 2DUP D+ 2DUP D+
    ROT DUP + DUP             ( d n n )
    0< IF -ROT 11 0 D+ ELSE -ROT ENDIF
  LOOP ROT DROP
  256 /MOD ROT 256 /MOD 2SWAP
;

DECIMAL
: TILE-DEF
  [ HEX ] 5C36 @     \ CHARS address
  5B00 4B00 DO
    DUP C@ TILE-BIT
    I       C!
    I 1+    C!
    I CELL+ C!
    I CELL+ 1+ C!
    1+
  4 +LOOP DROP
;

: leer
  [ hex ] 4000 [ decimal ]
  2560 blanks ;

DECIMAL
: TILE-EXAMPLE 
  2560 0 do
    128 32 DO
      I DUP BL - [ HEX ] 4000 j + [ DECIMAL ] + C!
    LOOP
  160 +loop
;

: los
 layer2
 cls
 tile-base
 tile-def
 tile-on
 leer
 tile-example ;
 
 
\ layer2
\ TILE-BASE
\ TILE-DEF
\ TILE-ON
\ TILE-EXAMPLE
\ TILE-OFF
Attachments
tilemaptest1.jpg
tilemaptest1.jpg (128.51 KiB) Viewed 261 times

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

Re: Tilemap in vForth - first example

Postby Alcoholics Anonymous » Mon Oct 11, 2021 4:38 pm

Up to date documentation for the ports and nextreg have a few more details. These come from the fpga repository and are always current with the committed core version:

https://gitlab.com/SpectrumNext/ZX_Spec ... /ports.txt
https://gitlab.com/SpectrumNext/ZX_Spec ... extreg.txt

These links go to the master branch which currently holds core 3.01.10 so will be ahead of your machine unless you have updated to the developers' core.

The wiki might have some details as well, however current requires comparing to the above.

funkheld
Posts: 78
Joined: Tue May 11, 2021 5:36 pm

Re: Tilemap in vForth - first example

Postby funkheld » Mon Oct 11, 2021 5:30 pm

hello ,thanks for the good info.

I didn't understand this with the x1, x2, y1, y2, where are the four corner points on the screen?
------------------------------
with address $18 I can switch off layer2 at tilemap.
I have not yet understood how to switch off with x1, x2, y1, y2 at address $18 ????
sometimes it goes 0 0 0 0 24 reg! or 255 255 255 255 24 reg! ???
------------------------------

greeting.

User avatar
Mmattsteel
Posts: 31
Joined: Wed May 31, 2017 5:38 am
Location: Venice Italy
Contact:

Re: Tilemap in vForth - first example

Postby Mmattsteel » Mon Oct 11, 2021 5:54 pm

Hi Peter, Reg $12 is used to set or to know which 8k Ram page Layer2 is.
I never used to write it, instead I used in my Layer2 DRAW-LINE example to know which 8k Page has to be fitted at $E000 via MMU7!

Sorry I am in a hurry, will study the other question
M.
Matteo.
Backer #1227. ZX Spectrum+ m/c programmer since 1985.
Take a look to https://github.com/mattsteeldue/vforth-next

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

Re: Tilemap in vForth - first example

Postby Alcoholics Anonymous » Mon Oct 11, 2021 5:54 pm

Those are the clipping rectangles. You are defining a rectangle on screen within which the layer will be visible.

Code: Select all

(x1,y1)
      +---------------+
      +               +
      +               +
      +               +
      +---------------+  (x2,y2)
The coordinates are inclusive.

The x coordinate can change meaning if the horizontal resolution of the layer is greater than 256 pixels. For layer 2, the default resolution is 256x192 so the x coordinate is a pixel value 0-255 as you'd expect. However if layer 2 is in a 320x256 or 640x256 mode then the x coordinate is halved and internally doubled by the hardware. 640 pixels is not treated differently from 320 -- the hardware groups a pair of 640 pixels into a single 320 wide pixel for clipping purposes.

The same goes for the tilemap. The tilemap can be 320x256 resolution (40x32 tiles) or 640x256 resolution (80x32 tiles). So its window x coordinates are halved and are internally doubled by the hardware. 640 pixels is not treated differently from 320 -- the hardware groups a pair of 640 pixels into a single 320 wide pixel for clipping purposes.

So for windows the top left coordinate (x1,y1) and the bottom right coordinate (x2,y2) you'd imagine are coming from a fixed coordinate system on the screen and are independent of the layer's current scroll amount.

You program a window by first resetting the window coordinates by writing a 1 to the corresponding layer in nextreg 0x1C. Then you can write the window coordinates by writing four bytes to nextreg 0x18 (for layer 2).

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

Re: Tilemap in vForth - first example

Postby Alcoholics Anonymous » Mon Oct 11, 2021 6:07 pm

Mmattsteel wrote: Mon Oct 11, 2021 5:54 pm Reg $12 is used to set or to know which 8k Ram page Layer2 is.
16K ram bank rather than 8K page :) If you change this value, the hardware will instantly change where it fetches layer 2 pixels from for display.

There are two ways to view memory :- as 16K banks or 8K pages. It's the same memory but numbered differently. If you have 1MB of ram, 768K is available as ram (the rest is used for rom, multiface, divmmc, etc). This can be viewed as 768/16 = 48 16K banks numbered 0-47 or 768/8 = 96 8K pages numbered 0-95. Whether you refer to the memory by bank number or page number, it's the same memory numbered differently. 16K bank 20 is composed of two 8K pages 40 and 41 (double the bank number).

The reason this double naming exists is that the 128K spectrum does banking 16K at a time at address 0xc000 using port 0x7ffd. So this is inherited in the Spectrum Next. New to the Spectrum Next is the ability to map any 8K page into any 8K slot in the cpu's 64K memory space. 8K was chosen as the size because 16K was considered too coarse and we have peripherals that divide on 8K boundaries. For example, both the divmmc and multiface divide the bottom 16K into an 8K rom portion and an 8K ram portion. There is also the example of the TS2068 (American Spectrum) that divides the memory space into 8K segments.

nextreg 0x12 tells you where the displayed layer 2 is stored in memory by 16K bank number. Although nextreg 0x13 is called the layer 2 shadow bank, it's actually something more general than that. It indicates the first 16K bank that is mapped into memory using layer 2 mapping which is different from mmu mapping. It can map memory into the bottom 16K or the bottom 48K in a read only / write only / read-write capacity. It allows the cpu to see more than 64K of memory at a time.
Last edited by Alcoholics Anonymous on Tue Oct 12, 2021 4:31 pm, edited 1 time in total.

funkheld
Posts: 78
Joined: Tue May 11, 2021 5:36 pm

Re: Tilemap in vForth - first example

Postby funkheld » Mon Oct 11, 2021 6:54 pm

hello, thanks for the good news.
must process this today first.

thanks.
greeting

funkheld
Posts: 78
Joined: Tue May 11, 2021 5:36 pm

Re: Tilemap in vForth - first example

Postby funkheld » Mon Oct 11, 2021 7:40 pm

Hmmm.

I can't get rid of this layer2 (white 256x192) so that I can see this tilemap completely.

there always remains something small white.
I do not understand that.


greeting
Attachments
layerweg2.jpg
layerweg2.jpg (65.09 KiB) Viewed 198 times


Who is online

Users browsing this forum: No registered users and 1 guest