New dev using sjasm for MSX2, requesting aid :)

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

Por shram86

Expert (95)

Imagen del shram86

24-04-2019, 06:00

Hi all,

I'm not new to 8-bit assembly (I've gotten demos running on VIC-20, C64, NES and GB/C) and I got an application booting but the cryptic description of how the 9938 works in the programmer's guide has left me fairly puzzled as to why I can't get a sprite displaying.

Its either something obvious and stupid that I'm not seeing, or there's possibly something wrong with the documentation (there are certainly discrepancies between the 9938 guide and ChibiAkuma's website, for instance)

My graphics init code is this:

 di 
 ld a, %00000100                 
 out ($99),a 
 ld a,0+128         
 out ($99),a 
 ld a, %01000010
 out ($99),a 
 ld a,1+128         
 out ($99),a 

which should presumably set m4 on (graphics mode 3), h/v interrupts off, sprites to 16x16, and screen rendering enabled.
I'll leave out most of the boring repetitive code, but I'm setting sprites to $3800, attributes @$1e00 which makes the palette at $1c00.

The only thing I could be doing wrong is mis-interpreting how to write to vram, if the above looks correct. Here is my copy-in code:

; set the target address for data write - $3800
 ld a,%00000000    
 di 
 out ($99),a 
 ld a,14+128
 out ($99),a        ; store 0 in r#14
 ld a,0
 out ($99),a        ; write bits 0-7 to port 1
 ld a,%01111000  ;$38+64
 out ($99),a 
 ei                
 ; now, copy all data into reg #0 ($98)
 ld hl,testsprite   
 ld b,(8*4)         ; size of sprite = 8*4
.loadloop
 ld a,(hl)         
 inc hl 
 dec b              
 ret z              ; do while b > 0, else ret back to main loop
 out ($98),a
 jr .loadloop

And finally, here's my sprite data:

testsprite     
 DB $00,$0F,$1F,$3F,$3F,$71,$71,$7F
 DB $7F,$7F,$78,$7E,$7F,$3F,$1F,$07
 DB $00,$E0,$F0,$F8,$F8,$88,$8C,$8C
 DB $FC,$FC,$FC,$1C,$F8,$F8,$F0,$00
testspriteattr 
 DB 100,100,0,0
testspritepal
 DB 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

If anyone has any clue, let me know. I'd also be happy to upload my source or a .dsk file. Here is my current result:
Imgur link
Thanks all!

Login sesión o register para postear comentarios

Por NYYRIKKI

Enlighted (5399)

Imagen del NYYRIKKI

24-04-2019, 09:12

This part looks ok to me... How about the routine where you transfer testspriteattr ?

Por NYYRIKKI

Enlighted (5399)

Imagen del NYYRIKKI

24-04-2019, 09:25

... you may need to reset also register r#11

Por ARTRAG

Enlighted (6281)

Imagen del ARTRAG

24-04-2019, 09:40

Another suggestion is to avoid fmsx for developing code. Better to use openMSX and its debugger

Por NYYRIKKI

Enlighted (5399)

Imagen del NYYRIKKI

24-04-2019, 09:41

Tip:

In the beginning, do something like:

	LD A,4
	CALL #5F

This will clear your screen, select correct screen mode and give you memory layout of:
0000-17FF Charcter patterns
1800-1AFF Name table (char positions)
1C00-1DFF Sprite colours
1E00-1E7F Sprite attribute table
2000-37FF PixelByte colour table
3800-3FFF Sprite character patterns

... if you start modifying from here you will see if you are missing something or if something is actually working incorrectly.

Por NYYRIKKI

Enlighted (5399)

Imagen del NYYRIKKI

24-04-2019, 09:49

ARTRAG wrote:

Another suggestion is to avoid fmsx for developing code. Better to use openMSX and its debugger

Yes, this is also very good tip. You may want to use the debugger to view register values and memory content so that you can know that after running your code everything is really how you imagine.

Por shram86

Expert (95)

Imagen del shram86

24-04-2019, 14:39

NYYRIKKI wrote:

This part looks ok to me... How about the routine where you transfer testspriteattr ?

Basically the same.

; set target for data write - $1e00
 ld a,0
 out ($99),a 
 ld a,14+128        ; bits 14-16 in r#14
 out ($99),a 
 ld a, 0 
 out ($99),a        ; bits 0-7 to port 1
 ld a,%01011110     ;=$1e+64
 out ($99),a        ; bits 8-13 +64 to port 1
 ; copy attribute
 ld hl, testspriteattr
 ld b, 4
.attrtestloop 
 ld a,(hl)
 inc hl 
 dec b 
 jr z,.endattr 
 out ($98),a 
 jr .attrtestloop
.endattr
NYYRIKKI wrote:

... you may need to reset also register r#11

Is this just writing a 0-byte to it? e.g. ld a,0 : out ($99),a : ld a,11+128 : out ($99),a ?

ARTRAG wrote:

Another suggestion is to avoid fmsx for developing code. Better to use openMSX and its debugger

I will do that, thanks. I'm on Linux so I wasn't sure what the best option would be, but good to know openMSX has a debugger Smile

NYYRIKKI wrote:

Tip:

In the beginning, do something like:

	LD A,4
	CALL #5F

This will clear your screen, select correct screen mode and give you memory layout of:

Awesome, I will do this instead of re-setting all the 9938 addresses Smile

Thanks for the help all, I will give this another go this afternoon.

Por ARTRAG

Enlighted (6281)

Imagen del ARTRAG

24-04-2019, 15:36

Openmsx has a Linux version currently maintained
If I may suggest some improvements this code should set one sprite in screen 4

RG0SAV	 equ #F3DF	;Mirror of VDP register 0 (Basic: VDP(0))
RG1SAV	equ #F3E0		; Mirror of VDP register 1 (Basic: VDP(1))

 ld a,(RG1SAV)
 or 2            		; sprite 16x16
 ld (RG1SAV),a

 ld a,4
 call $5F     ; set screen 4 using bios: it will use RAM mirror of R#1

 di 
 xor a
 out ($99),a 
 ld a,14+128        ; bits 14-16 in r#14
 out ($99),a          ; set R#14 once if unchanged
 xor a 
 out ($99),a        ; bits 0-7 to port 1
 ld a,64 + $1c      ;=$1c+64
 out ($99),a        ; bits 8-13 +64 to port 1
 ei
 ; copy colors at $1C000
 ld hl, testspritcolors
 ld bc, 16*256+$98
1: outi
 jp nz,1b

 di 	
 xor a                  ; no need to change R#14 anymore
 out ($99),a        ; bits 0-7 to port 1
 ld a,64 + $38      ;=$38+64
 out ($99),a        ; bits 8-13 +64 to port 1
 ei
 ; copy definitions at $3800
 ld hl, testspritdefinition
 ld bc, 32*256+$98
1: outi
 jp nz,1b

; set target for data write - $1e00
 di 
  xor a                  ; no need to change R#14 anymore
 out ($99),a        ; bits 0-7 to port 1
 ld a,64 + $1e      ;=$1e+64
 out ($99),a        ; bits 8-13 +64 to port 1
 ei
 ; copy attribute
 ld hl, testspriteattr
 ld bc, 4*256+$98
1: outi
 jp nz,1b

Por ARTRAG

Enlighted (6281)

Imagen del ARTRAG

24-04-2019, 15:29

IIRC the sequence
1: outi
jp nz,1b
could be replaced by
otir
on msx2
Only msx1 has timing problems and asks for 29 cycles of delay between OUTs

Por shram86

Expert (95)

Imagen del shram86

24-04-2019, 16:20

ARTRAG wrote:

IIRC the sequence
1: outi
jp nz,1b
could be replaced by
otir
on msx2
Only msx1 has timing problems and asks for 29 cycles of delay between OUTs

Nice, I'll look into this also. OTIR seems like a very useful op!
What is the syntax meaning of 1b? My understanding of jp nz,1b means jump (non-relative) to $0001 if z-flag is not set?

Por ARTRAG

Enlighted (6281)

Imagen del ARTRAG

24-04-2019, 16:44

In sjasm 1: 2: 3: etc. are temporary labels. They have to appear on the 1st column of the text.
They can be referred to as 1b if you mean 1: backwards or 1f if you are referring to 1: forward
It is sjasm specific, if you feel uncomfortable with them, replace the couple 1: and 1b with labels you like

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