Karoshi MSX Community
05 de Julio de 2021, 01:13:54 pm *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: 4player sprite example  (Leído 5739 veces)
0 Usuarios y 1 Visitante están viendo este tema.
jltursan
Karoshi Forum's Guru
*******
Mensajes: 1516


¿Que es lo que has aprendido hoy?


WWW Email
« : 02 de Octubre de 2006, 07:16:13 pm »

Mensaje original por Nitrofurano

Here is a .asm (asMSX compatible), based on the movable sprites example from Dioniso, but with 4 sprites controlled from one keyboard (4 players)

WSAD controls the sprite '1'
TGFH controls the sprite '2'
IKJL controls the sprite '3'
cursor keys controls the sprite '4'

the lack is it's being based on the 'international' keyboard (used on CBios and the most usual Bios) - i don't know if it work on brazilian MSX machines, per example (i think they used 'american' keyboard ) (for information take a look at the msx red book)

Who knows this example can be a start for 4 player games on MSX games, even on MSXDEV workshop?

I'm having lots of ideas for using it - cloning Warlords, a Combat clone for 4 players, a Bomberman clone with 4 players, an lots of original ideas can appear too...

Código:
    ;- 4 player sprite example
    ;- started from Dioniso - June '05
    ;- 4 player implement by Nitrofurano
    :- player1:'wsad', player2:'tgfh', player3:'ikjl', player4:cursors
    ;-(counting with international keyboad compatibility)
    ;- bug: i can't set default sprite positions of sprites '2', '3' and '4'
    ; else (0,0) (what is wrong?) (this bug seems to get fixed when i
    ; use the msx2 palette code posted by BiFi in this forum...
    ; Very weird...)
    ;BASIC program to handle sprites with keyboard
    ;SPEED is set to one pixel in every frame
    ;variables
    ;$c000 = keyboard read
    ;$c001 = Y position of the sprite 0
    ;$c002 = X position of the sprite 0
    ;$c003 = Y position of the sprite 1
    ;$c004 = X position of the sprite 1
    ;$c005 = Y position of the sprite 2
    ;$c006 = X position of the sprite 2
    ;$c007 = Y position of the sprite 3
    ;$c008 = X position of the sprite 3
    ;you can use BIOS to read the keyboard and write to VRAM, instead of these
    ;routines
    ;positions in VRAM to write:
    ;0x1B00 with $C001 (Y of sprite 0)
    ;0x1B01 with $C002 (X of sprite 0)
    ;0x1B04 with $C003 (Y of sprite 1)
    ;0x1B05 with $C004 (X of sprite 1)
    ;0x1B08 with $C005 (Y of sprite 2)
    ;0x1B09 with $C006 (X of sprite 2)
    ;0x1B0C with $C007 (Y of sprite 3)
    ;0x1B0D with $C008 (X of sprite 3)
    .bios
    .page 2
    .rom
    .start BEGIN
    ;-----------------------------------------------
    ;- vram address labels
    CHRTBL equ 0x0000
    NAMTBL equ 0x1800
    CLRTBL equ 0x2000
    SPRTBL equ 0x3800
    SPRATR equ 0x1B00
    ;-----------------------------------------------
    ;- declaring variables
    .page 3
    V_KBD: ds 1
    V_Y0: ds 1
    V_X0: ds 1
    V_Y1: ds 1
    V_X1: ds 1
    V_Y2: ds 1
    V_X2: ds 1
    V_Y3: ds 1
    V_X3: ds 1
    ;-----------------------------------------------
    ;- code start
    ;start......................................>
    .page 2
    .org 0x8010
    BEGIN:
    ;- colour 1,14,6
    ld a,1
    ld [$f3e9],a
    ld a,14
    ld [$f3ea],a
    ld a,6
    ld [$f3eb],a
    xor a
    ;- no keyboard-click
    ld [$f3db],a
    ;- screen 2
    ld a,2
    call 0x005f
    ;- turn off screen
    call 0x0041
    ;- sprites 16*16
    ld a,[$F3E0]
    or 00000010b
    and 11111110b
    ld b,a
    ld c,1
    call 0x0047
    ;- waitvbl
    halt
    ;- clear all sprites definitions
    ld hl,14336
    ld bc,2048
    xor a
    call 0x0056
    ;- sprite definitions
    ld hl,spr_definition
    ld de,14336
    ld bc,128 ;(4 sprites * 32 datas)
    call 0x005c
    ld hl,spr_attributes
    ld de,6912
    ld bc,16 ;(4 sprites * 4 attributes)
    call 0x005c
    ;...............................................;
    ;- turn on screen
    call 0x0044
    ;- important!!!!!!
    ;- let's initialize the Y and X variables in RAM
    ld a,80
    ld [V_Y0],a ;Y
    ld a,110
    ld [V_X0],a ;X
    ld a,80
    ld [V_Y1],a ;Y
    ld a,150
    ld [V_X1],a ;X
    ld a,120
    ld [V_Y2],a ;Y
    ld a,110
    ld [V_X2],a ;X
    ld a,120
    ld [V_Y3],a ;Y
    ld a,150
    ld [V_X3],a ;X
    ;keyboard ----> MAIN LOOP OF THE PROGRAM!
    loop_main:
    ;.................................................................;
    ;- waitvbl
    halt
    ;- sprite 00: 'wsad'
    ;-right: line 3, bit 1: key ='d'
    ld a,3
    call SNSMAT
    bit 1,a
    call z,mov_right_00
    ;-left: line 2, bit 6: key ='a'
    ld a,2
    call SNSMAT
    bit 6,a
    call z,mov_left_00
    ;-down: line 5, bit 0: key ='s'
    ld a,5
    call SNSMAT
    bit 0,a
    call z,mov_down_00
    ;-up: line 5, bit 4: key ='w'
    ld a,5
    call SNSMAT
    bit 4,a
    call z,mov_up_00
    ;- sprite 01: 'tgfh'
    ;-right: line 3, bit 5: key ='h'
    ld a,3
    call SNSMAT
    bit 5,a
    call z,mov_right_01
    ;-left: line 3, bit 3: key ='f'
    ld a,3
    call SNSMAT
    bit 3,a
    call z,mov_left_01
    ;-down: line 3, bit 4: key ='g'
    ld a,3
    call SNSMAT
    bit 4,a
    call z,mov_down_01
    ;-up: line 5, bit 1: key ='t'
    ld a,5
    call SNSMAT
    bit 1,a
    call z,mov_up_01
    ;- sprite 02: 'ikjl'
    ;-right: line 4, bit 1: key ='l'
    ld a,4
    call SNSMAT
    bit 1,a
    call z,mov_right_02
    ;-left: line 3, bit 7: key ='j'
    ld a,3
    call SNSMAT
    bit 7,a
    call z,mov_left_02
    ;-down: line 4, bit 0: key ='k'
    ld a,4
    call SNSMAT
    bit 0,a
    call z,mov_down_02
    ;-up: line 3, bit 6: key ='i'
    ld a,3
    call SNSMAT
    bit 6,a
    call z,mov_up_02
    ;- sprite 03: cursors
    ;-right: line 8, bit 7: key ='right'
    ld a,8
    call SNSMAT
    bit 7,a
    call z,mov_right_03
    ;-left: line 8, bit 4: key ='left'
    ld a,8
    call SNSMAT
    bit 4,a
    call z,mov_left_03
    ;-down: line 8, bit 6: key ='down'
    ld a,8
    call SNSMAT
    bit 6,a
    call z,mov_down_03
    ;-up: line 8, bit 5: key ='up'
    ld a,8
    call SNSMAT
    bit 5,a
    call z,mov_up_03
    ;- write the new/same attributes of the two sprites = 4 bytes to write....;
    ld hl,0x1B00 ;sprite 0
    call set_VRAM
    ld hl,V_Y0 ;Y,X sprite 0
    call write_2bytes_VRAM
    ld hl,0x1B04 ;sprite 1
    call set_VRAM
    ld hl,V_Y1 ;Y,X sprite 1
    call write_2bytes_VRAM
    ld hl,0x1B08 ;sprite 2
    call set_VRAM
    ld hl,V_Y2 ;Y,X sprite 2
    call write_2bytes_VRAM
    ld hl,0x1B0C ;sprite 3
    call set_VRAM
    ld hl,V_Y3 ;Y,X sprite 3
    call write_2bytes_VRAM
    ;...............................................;
    jp loop_main ;we read the keyboard again; GOTO loop_main
    ;routines for writting to VRAM (easier if you use BIOS).....;
    set_VRAM:
    ld a,l
    di
    out [$99],a
    ld a,h
    or $40
    out [$99],a
    ei
    ret
    write_2bytes_VRAM:
    ld bc,$0298 ;number of datas [$02] + port [$98]
    di
    outi
    outi
    ei
    ld a,0 ;better than NOP
    ret
    ;...........................................................;
    ;THIS IS VERY BASIC!
    ;mov_up_down_right_left with border detection.........;
    ;- replaced 'or a' with 'cp 0' for more coding flexibility
    ;- sprite 00
    mov_up_00:
    ld a,[V_Y0]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_Y0],a
    ret
    mov_down_00:
    ld a,[V_Y0]
    cp 191-16 ;192-16 pixels of sprites
    ret z
    inc a
    ld [V_Y0],a
    ret
    mov_right_00:
    ld a,[V_X0]
    cp 255-16 ;256-16 pixels of sprites
    ret z
    inc a
    ld [V_X0],a
    ret
    mov_left_00:
    ld a,[V_X0]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_X0],a
    ret
    ;- sprite 01
    mov_up_01:
    ld a,[V_Y1]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_Y1],a
    ret
    mov_down_01:
    ld a,[V_Y1]
    cp 191-16 ;192-16 pixels of sprites
    ret z
    inc a
    ld [V_Y1],a
    ret
    mov_right_01:
    ld a,[V_X1]
    cp 255-16 ;256-16 pixels of sprites
    ret z
    inc a
    ld [V_X1],a
    ret
    mov_left_01:
    ld a,[V_X1]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_X1],a
    ret
    ;- sprite 02
    mov_up_02:
    ld a,[V_Y2]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_Y2],a
    ret
    mov_down_02:
    ld a,[V_Y2]
    cp 191-16 ;192-16 pixels of sprites
    ret z
    inc a
    ld [V_Y2],a
    ret
    mov_right_02:
    ld a,[V_X2]
    cp 255-16 ;256-16 pixels of sprites
    ret z
    inc a
    ld [V_X2],a
    ret
    mov_left_02:
    ld a,[V_X2]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_X2],a
    ret
    ;- sprite 03
    mov_up_03:
    ld a,[V_Y3]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_Y3],a
    ret
    mov_down_03:
    ld a,[V_Y3]
    cp 191-16 ;192-16 pixels of sprites
    ret z
    inc a
    ld [V_Y3],a
    ret
    mov_right_03:
    ld a,[V_X3]
    cp 255-16 ;256-16 pixels of sprites
    ret z
    inc a
    ld [V_X3],a
    ret
    mov_left_03:
    ld a,[V_X3]
    cp 0 ; or a ????
    ret z
    dec a
    ld [V_X3],a
    ret
    ;.....................................................;
    ;- sprites data
    spr_definition:
    ;- Sprite patterndata for sprite 0
    db $FF,$FF,$FE,$FC,$F0,$F0,$F0,$FE,$FE,$FE,$FE,$FE,$FE,$FE,$FE,$FF
    db $FF,$FF,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F,$FF
    ;- Sprite patterndata for sprite 1
    db $FF,$FF,$F0,$C0,$80,$81,$03,$FF,$F0,$C0,$80,$83,$00,$00,$00,$FF
    db $FF,$FF,$07,$01,$00,$C0,$C0,$00,$01,$03,$3F,$FF,$00,$00,$00,$FF
    ;- Sprite patterndata for sprite 2
    db $FF,$FF,$F0,$C0,$80,$81,$FF,$FC,$FC,$FC,$FF,$03,$00,$80,$E0,$FF
    db $FF,$FF,$07,$01,$00,$C0,$C0,$01,$01,$00,$E0,$E0,$00,$01,$03,$FF
    ;- Sprite patterndata for sprite 3
    db $FF,$FF,$FE,$FC,$F8,$F0,$E0,$C1,$83,$03,$00,$00,$00,$FF,$FF,$FF
    db $FF,$FF,$03,$03,$03,$03,$83,$83,$83,$83,$00,$00,$00,$83,$83,$FF
    ;- sprites attributes
    spr_attributes:
    db 40, 50, 0,12 ;sprite 0 (Y,X,plane,colour)
    db 90, 50, 4, 5 ;sprite 1 (Y,X,plane,colour)
    db 40,110, 8, 9 ;sprite 2 (Y,X,plane,colour)
    db 90,110,12,13 ;sprite 3 (Y,X,plane,colour)
    ;..........................................................;
En línea

Doom dee doom dee doom
nitrofurano
Karoshi Maniac
****
Mensajes: 259



WWW
« Respuesta #1 : 12 de Octubre de 2007, 01:57:23 pm »

only now i'm seeing this, which i thaugh were lost! - thank you jltursan for posting! :-D
En línea
Dioniso
Visitante
« Respuesta #2 : 12 de Octubre de 2007, 11:49:11 pm »

only now i'm seeing this, which i thaugh were lost! - thank you jltursan for posting! :-D

About the keyboard, maybe you find this thread interesting: here.

All the testing there was right, whatever nationality was the keyboard.
En línea
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!