Tilemap in vForth - first example

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

Moderator: Programming Moderators

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

Tilemap in vForth - first example

Postby Mmattsteel » Fri Oct 08, 2021 10:51 pm

Hello,
I succeeded on my first Tilemap test using vForth.

Just to start, I used the standard ROM Spectrum Font as the base to draw the first 128 Tiles like an Ascii-Table, then put the first 96 printable codes on top of screen.

I experienced that Layer 2 can co-exist with Layer 3 / Tilemap system and in the attached picture you can see Layer 2 over Tilemap.

tilemap1.png
tilemap1.png (45.77 KiB) Viewed 464 times
Matteo.
Backer #1227. ZX Spectrum+ m/c programmer since 1985.
Take a look to https://github.com/mattsteeldue/vforth-next

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

Re: Tilemap in vForth - first example

Postby funkheld » Sat Oct 09, 2021 6:54 am

hello, that's great.

can you please provide me with a vforth demo, too
if they are still unfinished, that would be a great thing for me.

thanks.
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 » Sat Oct 09, 2021 12:45 pm

Here is the code that produced the image I attached tonight

Code: Select all


( TILEMAP study )
Hex needs binary needs layers
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 = eliminate the attribute entry in the tilemap
\ bit 4 = Palette select
\ bit 3 = reserved, must be 0
\ bit 2 = Activate 512 tile mode
\ bit 0 = Force tilemap on top of ULA

: TILE-ON
  [ binary ] 10100001 [ 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 -- n1 n2 n3 n4 )
  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
;

DECIMAL
: TILE-EXAMPLE
  [ hex ] 4000 [ decimal ]
  2560 blanks
  128 32 DO
    I DUP BL - [ HEX ] 4000 [ DECIMAL ] + C!
  LOOP
;



Last edited by Mmattsteel on Mon Oct 11, 2021 2:36 pm, edited 1 time in total.
Matteo.
Backer #1227. ZX Spectrum+ m/c programmer since 1985.
Take a look to https://github.com/mattsteeldue/vforth-next

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 » Sat Oct 09, 2021 12:52 pm

Oh well, you have to execute these words, like this:

Code: Select all

 TILE-BASE
 TILE-DEF
 TILE-ON
 TILE-EXAMPLE
 TILE-OFF
Matteo.
Backer #1227. ZX Spectrum+ m/c programmer since 1985.
Take a look to https://github.com/mattsteeldue/vforth-next

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

Re: Tilemap in vForth - first example

Postby funkheld » Sat Oct 09, 2021 3:44 pm

hello, thank you for your masterpiece.

this tilemap is not that easy to understand.
you are a master. thanks.
it works great.

must now read everything carefully through this vforth-tilemap.

many greetings, thank you.

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

Re: Tilemap in vForth - first example

Postby funkheld » Sat Oct 09, 2021 5:19 pm

the tilemap actually seemed more exciting to me.

what are the important things done with the tilemap?
- graphics?
- pictures ?
- text?

thanks.
greeting

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

Re: Tilemap in vForth - first example

Postby Ped7g » Sat Oct 09, 2021 5:48 pm

pictures are difficult, as you have limited amount of tiles to define graphics, so picture without repeating tile-able patterns is difficult to display (you would need to dynamically upload different tile graphics during frame to display pixel-based picture).

But you can fit about 400-700 tiles - depending on which exact mode and memory layout you use (even few more on future cores where tilemode can use both Bank5 and first half of Bank7, in current core 3.1.5 only Bank5 is available). So that's like 256x100 of unique pixels.

This is the original introductory article: https://www.specnext.com/tilemap-mode/
(the details about next registers may be somewhat outdated in details, check wiki or "nextreg.txt" from your core version for updated details, but as a whole, it's probably good introduction).

It's good choice for tiled graphics, like NES/SNES/SEGA platform games, or for text UI (similar to VGA/EGA text modes).

I did release (for text-UI example) assembler library to squish the 8x8 tiles to 8xN (8/7/6/5/4) by copper code, extending the visible tilemap from 80x32 to 80x42 (8x6) and similar. You can check example NEX to get idea: https://github.com/ped7g/ZXSpectrumNext ... er/tile8xN
(or screenshot of the example app).

And there exist another project using the tilemode for text-UI, the "Calm Commander": https://github.com/perrada69/CalmCommander

(sorry for no direct vForth connection, I don't use vForth, this is general information about the tilemode)

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

Re: Tilemap in vForth - first example

Postby funkheld » Sat Oct 09, 2021 6:55 pm

hello, thanks for the briefing.
so tilemap are an interesting thing for the next.
will continue to deal with it.

greeting

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

Re: Tilemap in vForth - first example

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

hello Mmattsteel, can you use the whole page for the tilemap in vforth, so that my layer2 is gone?
I have put the tilemap deeper.
the tilemap is covered by layer2.

thanks.
greeting
Attachments
tilemap.jpg
tilemap.jpg (14.81 KiB) Viewed 390 times

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 » Sat Oct 09, 2021 7:22 pm

Hi Peter,
Once you enable tilemap via TILE-ON, old fashion ULA Layer1 isn't visibile anymore.
To see Layer1 again you have to "blindly type" TILE-OFF. For "blindly" I mean you have to type it without having any cursor or feedback of what you're typing in.
Having LAYER2 enabled, like your're showing in your last post, allows you to see tilemode ON or OFF underneath Layer2 itself. Maybe using the "transparent" color will allow you to see throught Layer2.
Again to hide Layer2 and see the whole tilemap you have to pass to LAYER11 but again there will be no cursor to see what is going on.
In this case, I suggest to use the sequence LAYER11 KEY LAYER2 so it'll show the whole screen, wait for a keypress and then return to Layer2 where you have full control of everything.

_ Matteo.
Matteo.
Backer #1227. ZX Spectrum+ m/c programmer since 1985.
Take a look to https://github.com/mattsteeldue/vforth-next


Who is online

Users browsing this forum: funkheld and 2 guests