Assembly experiment: bouncing block

Página 3/7
1 | 2 | | 4 | 5 | 6 | 7

Por Pbk71

Expert (101)

imagem de Pbk71

09-05-2021, 12:07

Thanks, I like it here Wink
I'm now going to experiment with some scrolling on screen 1. Using name and pattern tables.

Por Pbk71

Expert (101)

imagem de Pbk71

10-05-2021, 11:52

Ok, I've got my first scrolling example working: a scrolling wall with smooth pixel perfect scrolling: https://msxpen.com/codes/-M_KdvrvCxl8fZIJHe2E

I also bought a real MSX today (Philips VG-8020). I can only connect it to an old tv, so I decided dump my code as hexadecimal characters and enter these in my real machine using a little basic program (a loop with read data, poke, etc.). Oldskool listing typing ;)

After entering the defusr and usr commands to start it up it actually worked! Really cool, after more then 35 years after I owned my first MSX I now run my first machine code program on a real MSX :D

Por Grauw

Ascended (10707)

imagem de Grauw

10-05-2021, 12:29

Looks great, nice job! Smile Also congrats on the MSX!

Por ro

Scribe (4916)

imagem de ro

10-05-2021, 13:26

great!

Por Pbk71

Expert (101)

imagem de Pbk71

10-05-2021, 13:33

Thanks, I'm going to order a MegaFlashRom at https://www.msxcartridgeshop.com/ to transfer my programs to the real MSX. I also found a second hand Arcade joystick from Suzo to make my setup complete.

Por Grauw

Ascended (10707)

imagem de Grauw

10-05-2021, 16:57

Pbk71 wrote:

Thanks, I'm going to order a MegaFlashRom at https://www.msxcartridgeshop.com/ to transfer my programs to the real MSX.

You won’t regret it! I use it all the time. Be sure to get the version with 512K memory.

Por ARTRAG

Enlighted (6933)

imagem de ARTRAG

10-05-2021, 23:01

Hi PbK71
this section of your code could be optimized as you have done at displaysprite:
Try setting the VRAM start address using SETWRT and use out and the self increment of the VRAM pointer in the VDP

; --- UPDATE Y AND X COORDINATE in VRAM ---
ld HL,SPRITEAT ; VRAM address to write attributes of sprite 0
ld a,(y+1) ; y-coordinate = high byte of word y
call WRTVRM ; write to VRAM
INC HL
ld a,(x) ; x-coordinate
call WRTVRM ; write to VRAM

ld HL,SPRITEAT+4 ; VRAM address to write attributes of sprite 1
ld a,(y+1) ; y-coordinate = high byte of word y
call WRTVRM ; write to VRAM
INC HL
ld a,(x) ; x-coordinate
call WRTVRM ; write to VRAM

ld HL,SPRITEAT+8 ; VRAM address to write attributes of sprite 2
ld a,(y+1) ; y-coordinate = high byte of word y
call WRTVRM ; write to VRAM
INC HL
ld a,(x) ; x-coordinate
call WRTVRM ; write to VRAM

ld HL,SPRITEAT+12 ; VRAM address to write attributes of sprite 3
ld a,(y+1) ; y-coordinate = high byte of word y
call WRTVRM ; write to VRAM
INC HL
ld a,(x) ; x-coordinate
call WRTVRM ; write to VRAM

Por santiontanon

Paragon (1770)

imagem de santiontanon

10-05-2021, 23:05

Agreed! Something that is very useful for fast transfers to the VDP is to setup the variables you are using to store x/y of your objects in exactly the same order and layout as they will be when transferred to the VDP to control the sprites. In that way, you can just copy them all in a block, saving a lot of CPU time.

Por Pbk71

Expert (101)

imagem de Pbk71

11-05-2021, 08:30

Hello ARTRAG,

Thanks for the advice. I tried this, but ran into the problem that after writing the x and y coordinate of a sprite I either have to skip 2 bytes (sprite pattern and color) or 'rewrite' those values again. My attempt on skipping them was this:

; --- UPDATE Y AND X COORDINATE in VRAM ---
              ld HL,SPRITEAT  	; VRAM address to write attributes of sprite 0
	      call SETWRT		; enable VDP to write	
	      ld c,0x98			; load port 0x98 to write to in c
              ld a,(y+1)		; y-coordinate = high byte of word y
              out(c),a     		; write to VRAM  
              ld a,(x)	    	; x-coordinate
              out(c),a     		; write to VRAM  

              ld HL,SPRITEAT+4  ; VRAM address to write attributes of sprite 1
	     call SETWRT		; enable VDP to write
              ld a,(y+1)		; y-coordinate = high byte of word y
              out(c),a     		; write to VRAM  
              ld a,(x)	    	; x-coordinate
              out(c),a     		; write to VRAM  

              ld HL,SPRITEAT+8  ; VRAM address to write attributes of sprite 2
			  call SETWRT		; enable VDP to write
              ld a,(y+1)		; y-coordinate = high byte of word y
              out(c),a     		; write to VRAM  
              ld a,(x)	    	; x-coordinate
              out(c),a     		; write to VRAM  

              ld HL,SPRITEAT+12 ; VRAM address to write attributes of sprite 3
              call SETWRT		; enable VDP to write
              ld a,(y+1)		; y-coordinate = high byte of word y
              out(c),a     		; write to VRAM  
              ld a,(x)	    	; x-coordinate
              out(c),a     		; write to VRAM  

I could adjust it to rewriting sprite pattern and color. So, something lik this I gues:

; --- UPDATE Y AND X COORDINATE in VRAM ---
              ld HL,SPRITEAT  	; VRAM address to write attributes of sprite 0
	      call SETWRT		; enable VDP to write	
	     ld c,0x98			; load port 0x98 to write to in c
              ld a,(y+1)		; y-coordinate = high byte of word y
              out(c),a     		; write to VRAM  
              ld a,(x)	    	; x-coordinate
              out(c),a     		; write to VRAM 
              ld a,0			; sprite pattern 0
              out(c),a     		; write to VRAM                         
              ld a,1			; color 1
              out(c),a     		; write to VRAM  

              ld a,(y+1)		; y-coordinate = high byte of word y
              out(c),a     		; write to VRAM  
              ld a,(x)	    	; x-coordinate
              out(c),a     		; write to VRAM  
              ld a,4			; sprite pattern 1 (starts at 4)
              out(c),a     		; write to VRAM           
              ld a,10			; color
              out(c),a     		; write to VRAM 
       
            ... and so on ....

Which one is preferred? Or is there another solution?

@santiontanon: If I would your solution I would have to update the x and y coordinate 4 times when thay change? Because then I would have to store it 4 each sprite separate.

Por thegeps

Paragon (1175)

imagem de thegeps

11-05-2021, 15:02

Reserve 128 bytes of RAM (or ROM) area for sprites attributes then move them to VRAM simply doing:

     Ld hl,RAMSAT  ;your reserved 128 bytes start address
     Ld c,98h
     Ld b,128
Sprite_to_vram:
     Outi
     Jp nz,Sprite_to_vram

Ti modify your values in RAM you can address them easily in this way:

     Ld hl,RAMSAT  ;point to sprite0 byte (y coord)
     Ld (hl),whatever value you need

     Ld hl,RAMSAT+1 ; sprite0 x coord
     Ld hl,RAMSAT+4 ; sprite1 y coord

And so on.
And if your RAMSAT is 256 aligned you can do this faster:

Ramsat:     equ 0c000h

     Ld hl,ramsat ;set this address as start point (sprite0 y coord)
     Ld (hl),your value
     Ld l,1  ;sprite0 x coord
     Ld (hl),your value
     Ld l,4  ;sprite1 y coord
     Ld (hl),your value
     Ld l,5  ;sprite1 x coord
     Ld (hl),your value

And so on...

Página 3/7
1 | 2 | | 4 | 5 | 6 | 7