layer-scroll-xy mit vforth

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

Moderator: Programming Moderators

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

layer-scroll-xy mit vforth

Postby funkheld » Fri Oct 08, 2021 7:26 pm

Hi good afternoon.
now it works with the layer scroll in x and y direction in layer21 with the vforth.
I drew a star in the middle. this is moved right and left in the x-direction and up and down in the y-direction.
I'm really happy ...


in the ordner inc from vforth ( layer21)

Code: Select all

\
\ layer21.f
\
\ Hi-Col Layer21
\
.( LAYER21 )
\
\
NEEDS IDE_MODE!

: LAYER21
    [ HEX ] 0201 IDE_MODE!
    1E EMITC 4 EMITC
;
DECIMAL
layer-scroll :

Code: Select all

needs value  
needs to 
needs +to
needs 2over  
needs dnegate
needs layer21

hex
: pixeladd ( x y -- a )  
  over ff and 5 rshift   
  12 reg@ 2* + mmu7!     
  swap 1f and            
  8 lshift +             
  e000 or
;

: plot  ( x y c -- )    
  -rot over 8 lshift over +
  C000 U< if 
      pixeladd c! 
   else 
       drop  2drop  
   then
;
decimal

0    value dx       
0    value dy       
0    value sx       
0    value sy       
0    value err      
255  value color
0 value wx
0 value wy

471 load

2 constant cell
: sinus@ cell * sine-table + @ ;

: sin 
  dup >r 
  abs 360 mod
  dup 180 > if 180 - -1 else 0 then >r
  dup 90 > if 180 swap - then
  sinus@
  r> +- 
  r> +-  ;

: cos 90 + sin ;

: draw-line ( x2 y2 x1 y1 c -- )
  to color rot swap                   
  
  2over -  1 over +- to sx  abs to dx
  2dup  -  1 over +- to sy  abs negate to dy
  dx dy + to err
  swap -rot 
  
  begin
    2dup 256 u< swap 192 u< and  >r      
    2dup color plot 2over 2over          
    rot - -rot - or  r> and      
  while
    err dup + >r                   
    r@ dy < not if
      dy +to err swap sx + swap
    endif
    r> dx > not if
      dx +to err sy +
    endif
    ?terminal if 2drop 2drop exit then
  repeat
  2drop color plot
;

: warte
  1000 0 do loop ;

: stern
360 0 do 
  i sin 80 10000 */ to wx
  i cos 80 10000 */ to wy
  
  wy 95 + wx 126 + 95 126 224 draw-line
5 +loop  
;

: scrollx
  256 0 do
    i 22 reg!
    warte 
  loop

  256 0 do
    256 i - 22 reg!
    warte
  loop 
;  

: scrolly
  192 0 do
    i 23 reg!
    warte
  loop

  192 0 do
    192 i - 23 reg!
    warte
  loop 
;  

: los
 layer21
 cls
 stern
 
 scrollx
 scrolly
 ;


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

Re: layer-scroll-xy mit vforth

Postby funkheld » Fri Oct 08, 2021 10:08 pm

hello, here is the layer21 with the sprite in the foreground.
the layer runs in INTERRUPT.

Layer scrolling can be switched on and off with A / D.
here in the picture the layer is scrolled by half

the sprite is moved with QEWS.

Greeting

Code: Select all

needs value  
needs to 
needs +to
needs 2over  
needs dnegate
needs layer21
NEEDS CASE
NEEDS INTERRUPT

include /fth/spriteproglayer.f
SPRITE-LOAD< ../../fth/sprite1.spr 

100 value wx 100 value wy
0 value wx1
0 value wy1

: ISR-TEST
  23672 ( FRAMES ) @ 7 AND 0= IF
    wx1 2 - to wx1
    wx1 22 reg!
  endif
;

INT-OFF
' ISR-TEST INT-W !
int-on 
int-off

  0  SPRITE  _spriteid   !
100  SPRITE  _xcoord     !
100  SPRITE  _ycoord     !
  0  SPRITE  _pattern    c!
  0  SPRITE  _rotmir     c!
  0  SPRITE  _anchor     c!

hex
: pixeladd ( x y -- a )  
  over ff and 5 rshift   
  12 reg@ 2* + mmu7!     
  swap 1f and            
  8 lshift +             
  e000 or
;

: plot  ( x y c -- )    
  -rot over 8 lshift over +
  C000 U< if 
      pixeladd c! 
   else 
       drop  2drop  
   then
;
decimal

0    value dx       
0    value dy       
0    value sx       
0    value sy       
0    value err      
255  value color

471 load

2 constant cell
: sinus@ cell * sine-table + @ ;

: sin 
  dup >r 
  abs 360 mod
  dup 180 > if 180 - -1 else 0 then >r
  dup 90 > if 180 swap - then
  sinus@
  r> +- 
  r> +-  ;

: cos 90 + sin ;

: draw-line ( x2 y2 x1 y1 c -- )
  to color rot swap                   
  
  2over -  1 over +- to sx  abs to dx
  2dup  -  1 over +- to sy  abs negate to dy
  dx dy + to err
  swap -rot 
  
  begin
    2dup 256 u< swap 192 u< and  >r      
    2dup color plot 2over 2over          
    rot - -rot - or  r> and      
  while
    err dup + >r                   
    r@ dy < not if
      dy +to err swap sx + swap
    endif
    r> dx > not if
      dx +to err sy +
    endif
    ?terminal if 2drop 2drop exit then
  repeat
  2drop color plot
;

: warte
  1000 0 do loop ;

: stern
360 0 do 
  i sin 80 10000 */ to wx1
  i cos 80 10000 */ to wy1
  
  wy1 95 + wx1 126 + 95 126 224 draw-line
5 +loop  
;

hex 5c08 constant last-k decimal
: keypress ( — c )
  0 last-k c!
  begin last-k c@ until
  last-k c@
;

: oben
  wy 2 - to wy
  wy SPRITE _ycoord !
  0 SPRITE _spriteid !
  SPRITE  0  SPRITE-UPDATE
  ;
  
: unten
  wy 2 + to wy
  wy SPRITE _ycoord !
  0 SPRITE _spriteid !
  SPRITE  0  SPRITE-UPDATE
  ;
  
: rechts
  wx 2 + to wx
  wx SPRITE _xcoord !
  0 SPRITE _spriteid !
  SPRITE  0  SPRITE-UPDATE
  ;
  
: links
  wx 2 - to wx
  wx SPRITE _xcoord !
  0 SPRITE _spriteid !
  SPRITE  0  SPRITE-UPDATE
  ;

: starte
case
  97 of int-on  endof
  100 of int-off  endof
  119 of oben   endof
  101 of rechts endof
  113 of links  endof
  115 of unten  endof 
endcase ; 

: start
  begin
  keypress
  starte
?terminal until ;

: los
 layer21
 cls
 stern
 
 SPRITE  0  SPRITE-UPDATE
 
 start
 ;
  
Attachments
layersprite.jpg
layersprite.jpg (67.49 KiB) Viewed 287 times

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

Re: layer-scroll-xy mit vforth

Postby funkheld » Sat Oct 09, 2021 7:01 am

Hello Master.

can you please also set the sequence of the interrupt faster?

thanks
greeting

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

Re: layer-scroll-xy mit vforth

Postby Mmattsteel » Sun Oct 10, 2021 2:57 pm

Hi Peter,

I tryed your first example, good job ideed !

I suggest, in the four DO-LOOPs, to loop between 0 and 257 for y-direction and 0 to 193 for x-direction instead of 256 and 192.
This way you will return to ZERO scroll in both directions. This is typical in Forth in that the Loop-limit is never reached.

As far I know, in IDE_MODE NextOS call, for Layer 2 there is no sub-mode then using 0200 or 0201 should be the same.
Why did you define LAYER21 ? Did you found any difference between LAYER2 and LAYER21 ?
Anyway, I prefer to use NEEDS LAYERS that in turn loads all the other Layer related words.

For the second example, keep in mind that your ISR (ISR-TEST) scrolls Layer2 only once every 8 frame by checking "FRAMES system variable" and doing a "7 AND" as an equivalent but faster "8 MOD". Try to reduce it to 3 or to 1 to increase the speed or remove it to achive maximum scroll speed.

To make your example suitable to run on my system I had to change your "include /fth/spriteproglayer.f" to some parts I found in "400 LOAD".

Regards.
_Matteo.
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: layer-scroll-xy mit vforth

Postby funkheld » Sun Oct 10, 2021 4:49 pm

yes ... yes .. to learn the asm i have a few
small programs implemented by you directly in asm and then
the binary with my purebasic program converted into the "code xsprite-hide". I also didn't want to always include the forth-asm compiler.

that's my gimmick.

I didn't know that this layer2 also opened the scrolling function, that's why I made layer21.

thanks for your tip, layer2 also does the scrolling and for the isr.

can I run several ISR-TESTs please?
ISR-TEST, ISR-TEST1, ISR-TEST2 ....?

greeting

Code: Select all


xsprite-hide-asm :
------------------------------------------------------
spriteslotselectport equ &303b
spriteattributeport equ &57

exx
pop hl

ld bc,spriteslotselectport
out (c),l

ld bc,spriteattributeport

ld a,0
out (c),a
ld a,0
out (c),a
ld a,0
out (c),a
ld a,0
out (c),a

exx

jp (ix)  
------------------------------------------

NEEDS CODE
HEX

CODE xsprite-hide
 D9 C, E1 C, 01 C, 3B C, 30 C, ED C, 69 C, 01 C, 57 C, 00 C,
 3E C, 00 C, ED C, 79 C, 3E C, 00 C, ED C, 79 C, 3E C, 00 C,
 ED C, 79 C, 3E C, 00 C, ED C, 79 C, D9 C, DD C, E9 C,

FORTH
SMUDGE
DECIMAL

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

Re: layer-scroll-xy mit vforth

Postby funkheld » Sun Oct 10, 2021 5:37 pm

hello ..... another crazy question for vforth.

can you please put two layers2 on top of each other and move them?
One is then transparent in a few places?

thanks.
greeting


Who is online

Users browsing this forum: funkheld and 1 guest