Sprite attributes in ROM assembly code

Par fpracek

Resident (58)

Portrait de fpracek

22-05-2023, 13:24

Hi,
I don't undestand because if I have my sprite attributes ("sprite_attr" label) coded before "RAM" address is all ok and if I move in "RAM" zone (after org) the sprites are not displayed.
I must keep sprite attributes on "RAM" section because I need to change them values and after put them to VRAM...
Can you help me, please?

This code is OK:

; *************************°****
; ****** SAM PR ADVENTURE ******
; ******************************
;
;     ------------------
;     Fausto Pracek 2023
;     ------------------


; --- BIOS CALLS ---
INIGRP:             equ 00072h                                      ; Switch to screen 2 
LDIRVM:             equ 0005Ch                                      ; Block transfer to VRAM from memory
WRTVDP:             equ 00047h                                      ; Write data in the VDP-register

; --- BIOS VARIABLES ---				
FORCLR:             equ 0F3E9h
BAKCLR:             equ 0F3EAh
BDRCLR:             equ 0F3EBh
GRPATR:             equ 0F3CDh
GRPPAT:             equ 0F3CFh
RG0SAV:             equ 0F3DFh
RG1SAV:             equ 0F3E0h


; --- INIT ROM ---
	org #4000
	db "AB"															; ID for auto-executable ROM
	dw start														; Main program execution address.
	db 00,00,00,00,00,00 											; Unused

start:
; --- INIT SCREEN ---
init_screen:
    ld      hl,F FORCLR                                             ; Load the foreground variable position in HL
    ld      (hl), 15                                                ; Changes the value for FORCLR to 15 (White)
    ld      hl, BAKCLR                                              ; Load the background variable position in HL
    ld      (hl), 1                                                 ; Changes the value for BAKCLR to 1 (black)
    ld      hl, BDRCLR                                              ; Load the border variable position in HL
    ld      (hl), 1                                                 ; Changes the value for BDRCLR to 1 (black)
    call    INIGRP                                                  ; Calls the routine that initializes the screen mode
    
; --- LOAD SPRITES ---
load_sprites:
    ld      a,(RG1SAV)                                              ; Load into A the current value of VDP's register 1
    and     $FC                                                     ; AND A with $FC (11111100) resulting in xxxxxx00 (x=no change)
    or      $02                                                     ; OR A with 00000010 resulting in xxxxxx10
    di                                                              ; Disable interruptions before calling the VDP 
    ld      b, a                                                    ; Load value from A into B to be used by WRTVDP
    ld      c, $01                                                  ; Load the register value (#1) into C
    call    WRTVDP                                                  ; Send to VDP register set at C (#1) the data stored in B
    ei                                                              ; Enable interruptions

    ld      de, 03800h                                              ; Load in DE the VRAM position for sprite with ID 0
    LD      bc, 1920                                                ; The amount of data to be transferred: 4 x 16 bytes
    LD      hl, sprites                                             ; Load the sprites pattern in HL
    call LDIRVM                                                     ; Copy BC amount of bytes of the content pointed by HL into the VRAM at address loaded in DE 

    ld      de, 01B00h                                              ; Load in DE the VRAM position for the attributes
    ld      bc, 120                                                 ; The amount of data to be transferred: 4 bytes
    LD      hl, sprites_attrib                                      ; Load the attributes in HL
    call LDIRVM
    
   
            
foreverLoop:
    jp foreverLoop    ; Repeats the loop indefinitely
        
    
        
; --- SPRITES DEFINITIONS ---
sprites:
    ; --- Sprite 0-2 (Sam walking to right 1)
    ; color 2
    db $0F,$1F,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $00,$80,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$0F,$0D
    db $0B,$0B,$0D,$0F,$08,$08,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$80,$80,$00,$00
    ; color 9
    db $00,$00,$0D,$0F,$0D,$06,$00,$02
    db $04,$04,$02,$00,$00,$00,$08,$0C
    db $00,$00,$00,$80,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$80
    ; 
    ; --- Sprite 3-5 (Sam walking to right 2)
    ; color 2
    db $07,$0F,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $80,$C0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$07,$06
    db $05,$05,$07,$07,$04,$04,$00,$00
    db $00,$00,$00,$00,$00,$00,$80,$80
    db $80,$80,$80,$80,$80,$80,$80,$00
    ; color 9
    db $00,$00,$06,$07,$06,$03,$00,$01
    db $02,$02,$00,$00,$00,$00,$08,$08
    db $00,$00,$80,$C0,$80,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$C0
    ; 
    ; --- Sprite 6-8 (Sam walking to left 1)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$02
    db $03,$03,$02,$03,$04,$04,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $40,$40,$C0,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$01,$00,$01
    db $00,$00,$01,$00,$00,$00,$0C,$04
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $80,$80,$00,$00,$00,$00,$40,$C0
    ; 
    ; --- Sprite 9-11 (Sam walking to left 2)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$02
    db $03,$03,$03,$03,$02,$02,$02,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $40,$40,$C0,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$01,$00,$01
    db $00,$00,$00,$00,$00,$00,$00,$06
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $80,$80,$00,$00,$00,$00,$20,$20
    ; 
    ; --- Sprite 12-14 (Sam right waiting)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$03
    db $02,$02,$03,$03,$02,$02,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$40
    db $C0,$C0,$40,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$03,$03,$03,$01,$00,$00
    db $01,$01,$00,$00,$00,$00,$02,$03
    db $00,$00,$40,$E0,$40,$80,$00,$80
    db $00,$00,$80,$00,$00,$00,$40,$60
    ; 
    ; --- Sprite 15-17 (Sam left waiting)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$02
    db $03,$03,$02,$03,$02,$02,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $40,$40,$C0,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$01,$00,$01
    db $00,$00,$01,$00,$00,$00,$02,$06
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $80,$80,$00,$00,$00,$00,$40,$C0
    ; 
    ; --- Sprite 18-20 (Sam jump to left)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$03
    db $03,$03,$0B,$07,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$00
    db $C0,$C0,$C0,$C0,$20,$10,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$09,$04,$00
    db $00,$10,$00,$00,$00,$00,$00,$00
    db $00,$00,$C0,$C0,$C0,$80,$00,$C0
    db $20,$10,$00,$00,$00,$08,$00,$00
    ; 
    ; --- Sprite 21-23 (Sam jump to right)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$00
    db $03,$03,$03,$03,$04,$08,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $C0,$C0,$D0,$E0,$00,$00,$00,$00
    ; color 9
    db $00,$00,$03,$03,$03,$01,$00,$03
    db $04,$08,$00,$00,$00,$10,$00,$00
    db $00,$00,$40,$E0,$40,$90,$20,$00
    db $00,$08,$00,$00,$00,$00,$00,$00
    ; 
    ; --- Sprite 24-26 (Sam fall from right)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$03
    db $03,$03,$03,$03,$02,$01,$01,$00
    db $00,$00,$00,$00,$00,$00,$E0,$C0
    db $C0,$C0,$C0,$C0,$20,$20,$00,$00
    ; color 9
    db $00,$00,$03,$03,$03,$01,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$01
    db $00,$00,$40,$E0,$48,$90,$00,$10
    db $20,$00,$00,$00,$00,$00,$30,$80
    ; 
    ; --- Sprite 27-29 (Sam fall from left)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$07,$03
    db $03,$03,$03,$03,$04,$04,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $C0,$C0,$C0,$C0,$40,$80,$80,$00
    ; color 9
    db $00,$00,$02,$07,$12,$09,$00,$08
    db $04,$00,$00,$00,$00,$00,$0C,$01
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$80


; --- SPRITES ATTRIBUTES ---
sprites_attrib:
    ; --- Sprite 0-2 (Sam walking to right 1)
    db $0,$5,$4*0,$02
    db $0,$5,$4*1,$04
    db $0,$5,$4*2,$09

    ; --- Sprite 3-5 (Sam walking to right 2)
    db 195,0,4*3,2
    db 195,0,4*4,4
    db 195,0,4*5,9

    ; --- Sprite 6-8 (Sam walking to left 1)
    db 195,0,4*6,2
    db 195,0,4*7,4
    db 195,0,4*8,9

    ; --- Sprite 9-11 (Sam walking to left 2)
    db 195,0,4*9,2
    db 195,0,4*10,4
    db 195,0,4*11,9

    ; --- Sprite 12-14 (Sam right waiting)
    db 195,0,4*12,2
    db 195,0,4*13,4
    db 195,0,4*14,9

    ; --- Sprite 15-17 (Sam left waiting)
    db 195,0,4*15,2
    db 195,0,4*16,4
    db 195,0,4*17,9

    ; --- Sprite 18-20 (Sam jump to left)
    db 195,0,4*18,2
    db 195,0,4*19,4
    db 195,0,4*20,9


    ; --- Sprite 21-23 (Sam jump to right)
    db 195,0,4*21,2
    db 195,0,4*22,4
    db 195,0,4*23,9

    ; --- Sprite 24-26 (Sam fall from right)
    db 195,0,4*24,2
    db 195,0,4*25,4
    db 195,0,4*26,9

    ; --- Sprite 27-29 (Sam fall from left)
    db 195,100,4*27,2
    db 195,100,4*28,4
    db 195,100,4*29,9

; --- CONSTANT ---

; --- ROM 16KB ---
    ds #8000 - $  													; Fill the rest of the ROM (up to 16KB with 0s)

; --- RAM ---
    org #0c000  													; RAM address

; --- VARIABLES ---

This code doesn't work:

; *************************°****
; ****** SAM PR ADVENTURE ******
; ******************************
;
;     ------------------
;     Fausto Pracek 2023
;     ------------------


; --- BIOS CALLS ---
INIGRP:             equ 00072h                                      ; Switch to screen 2 
LDIRVM:             equ 0005Ch                                      ; Block transfer to VRAM from memory
WRTVDP:             equ 00047h                                      ; Write data in the VDP-register

; --- BIOS VARIABLES ---				
FORCLR:             equ 0F3E9h
BAKCLR:             equ 0F3EAh
BDRCLR:             equ 0F3EBh
GRPATR:             equ 0F3CDh
GRPPAT:             equ 0F3CFh
RG0SAV:             equ 0F3DFh
RG1SAV:             equ 0F3E0h


; --- INIT ROM ---
	org #4000
	db "AB"															; ID for auto-executable ROM
	dw start														; Main program execution address.
	db 00,00,00,00,00,00 											; Unused

start:
; --- INIT SCREEN ---
init_screen:
    ld      hl,F FORCLR                                             ; Load the foreground variable position in HL
    ld      (hl), 15                                                ; Changes the value for FORCLR to 15 (White)
    ld      hl, BAKCLR                                              ; Load the background variable position in HL
    ld      (hl), 1                                                 ; Changes the value for BAKCLR to 1 (black)
    ld      hl, BDRCLR                                              ; Load the border variable position in HL
    ld      (hl), 1                                                 ; Changes the value for BDRCLR to 1 (black)
    call    INIGRP                                                  ; Calls the routine that initializes the screen mode
    
; --- LOAD SPRITES ---
load_sprites:
    ld      a,(RG1SAV)                                              ; Load into A the current value of VDP's register 1
    and     $FC                                                     ; AND A with $FC (11111100) resulting in xxxxxx00 (x=no change)
    or      $02                                                     ; OR A with 00000010 resulting in xxxxxx10
    di                                                              ; Disable interruptions before calling the VDP 
    ld      b, a                                                    ; Load value from A into B to be used by WRTVDP
    ld      c, $01                                                  ; Load the register value (#1) into C
    call    WRTVDP                                                  ; Send to VDP register set at C (#1) the data stored in B
    ei                                                              ; Enable interruptions

    ld      de, 03800h                                              ; Load in DE the VRAM position for sprite with ID 0
    LD      bc, 1920                                                ; The amount of data to be transferred: 4 x 16 bytes
    LD      hl, sprites                                             ; Load the sprites pattern in HL
    call LDIRVM                                                     ; Copy BC amount of bytes of the content pointed by HL into the VRAM at address loaded in DE 

    ld      de, 01B00h                                              ; Load in DE the VRAM position for the attributes
    ld      bc, 120                                                 ; The amount of data to be transferred: 4 bytes
    LD      hl, sprites_attrib                                      ; Load the attributes in HL
    call LDIRVM
    
   
            
foreverLoop:
    jp foreverLoop    ; Repeats the loop indefinitely
        
    
        
; --- SPRITES DEFINITIONS ---
sprites:
    ; --- Sprite 0-2 (Sam walking to right 1)
    ; color 2
    db $0F,$1F,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $00,$80,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$0F,$0D
    db $0B,$0B,$0D,$0F,$08,$08,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$80,$80,$00,$00
    ; color 9
    db $00,$00,$0D,$0F,$0D,$06,$00,$02
    db $04,$04,$02,$00,$00,$00,$08,$0C
    db $00,$00,$00,$80,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$80
    ; 
    ; --- Sprite 3-5 (Sam walking to right 2)
    ; color 2
    db $07,$0F,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $80,$C0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$07,$06
    db $05,$05,$07,$07,$04,$04,$00,$00
    db $00,$00,$00,$00,$00,$00,$80,$80
    db $80,$80,$80,$80,$80,$80,$80,$00
    ; color 9
    db $00,$00,$06,$07,$06,$03,$00,$01
    db $02,$02,$00,$00,$00,$00,$08,$08
    db $00,$00,$80,$C0,$80,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$C0
    ; 
    ; --- Sprite 6-8 (Sam walking to left 1)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$02
    db $03,$03,$02,$03,$04,$04,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $40,$40,$C0,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$01,$00,$01
    db $00,$00,$01,$00,$00,$00,$0C,$04
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $80,$80,$00,$00,$00,$00,$40,$C0
    ; 
    ; --- Sprite 9-11 (Sam walking to left 2)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$02
    db $03,$03,$03,$03,$02,$02,$02,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $40,$40,$C0,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$01,$00,$01
    db $00,$00,$00,$00,$00,$00,$00,$06
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $80,$80,$00,$00,$00,$00,$20,$20
    ; 
    ; --- Sprite 12-14 (Sam right waiting)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$03
    db $02,$02,$03,$03,$02,$02,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$40
    db $C0,$C0,$40,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$03,$03,$03,$01,$00,$00
    db $01,$01,$00,$00,$00,$00,$02,$03
    db $00,$00,$40,$E0,$40,$80,$00,$80
    db $00,$00,$80,$00,$00,$00,$40,$60
    ; 
    ; --- Sprite 15-17 (Sam left waiting)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$02
    db $03,$03,$02,$03,$02,$02,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $40,$40,$C0,$C0,$40,$40,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$01,$00,$01
    db $00,$00,$01,$00,$00,$00,$02,$06
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $80,$80,$00,$00,$00,$00,$40,$C0
    ; 
    ; --- Sprite 18-20 (Sam jump to left)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$03
    db $03,$03,$0B,$07,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$00
    db $C0,$C0,$C0,$C0,$20,$10,$00,$00
    ; color 9
    db $00,$00,$02,$07,$02,$09,$04,$00
    db $00,$10,$00,$00,$00,$00,$00,$00
    db $00,$00,$C0,$C0,$C0,$80,$00,$C0
    db $20,$10,$00,$00,$00,$08,$00,$00
    ; 
    ; --- Sprite 21-23 (Sam jump to right)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$00
    db $03,$03,$03,$03,$04,$08,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $C0,$C0,$D0,$E0,$00,$00,$00,$00
    ; color 9
    db $00,$00,$03,$03,$03,$01,$00,$03
    db $04,$08,$00,$00,$00,$10,$00,$00
    db $00,$00,$40,$E0,$40,$90,$20,$00
    db $00,$08,$00,$00,$00,$00,$00,$00
    ; 
    ; --- Sprite 24-26 (Sam fall from right)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$03,$03
    db $03,$03,$03,$03,$02,$01,$01,$00
    db $00,$00,$00,$00,$00,$00,$E0,$C0
    db $C0,$C0,$C0,$C0,$20,$20,$00,$00
    ; color 9
    db $00,$00,$03,$03,$03,$01,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$01
    db $00,$00,$40,$E0,$48,$90,$00,$10
    db $20,$00,$00,$00,$00,$00,$30,$80
    ; 
    ; --- Sprite 27-29 (Sam fall from left)
    ; color 2
    db $03,$07,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    db $C0,$E0,$00,$00,$00,$00,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$00
    ; color 4
    db $00,$00,$00,$00,$00,$00,$07,$03
    db $03,$03,$03,$03,$04,$04,$00,$00
    db $00,$00,$00,$00,$00,$00,$C0,$C0
    db $C0,$C0,$C0,$C0,$40,$80,$80,$00
    ; color 9
    db $00,$00,$02,$07,$12,$09,$00,$08
    db $04,$00,$00,$00,$00,$00,$0C,$01
    db $00,$00,$C0,$C0,$C0,$80,$00,$00
    db $00,$00,$00,$00,$00,$00,$00,$80


; --- SPRITES ATTRIBUTES ---
sprites_attrib:
    ; --- Sprite 0-2 (Sam walking to right 1)
    db $0,$5,$4*0,$02
    db $0,$5,$4*1,$04
    db $0,$5,$4*2,$09

    ; --- Sprite 3-5 (Sam walking to right 2)
    db 195,0,4*3,2
    db 195,0,4*4,4
    db 195,0,4*5,9

    ; --- Sprite 6-8 (Sam walking to left 1)
    db 195,0,4*6,2
    db 195,0,4*7,4
    db 195,0,4*8,9

    ; --- Sprite 9-11 (Sam walking to left 2)
    db 195,0,4*9,2
    db 195,0,4*10,4
    db 195,0,4*11,9

    ; --- Sprite 12-14 (Sam right waiting)
    db 195,0,4*12,2
    db 195,0,4*13,4
    db 195,0,4*14,9

    ; --- Sprite 15-17 (Sam left waiting)
    db 195,0,4*15,2
    db 195,0,4*16,4
    db 195,0,4*17,9

    ; --- Sprite 18-20 (Sam jump to left)
    db 195,0,4*18,2
    db 195,0,4*19,4
    db 195,0,4*20,9


    ; --- Sprite 21-23 (Sam jump to right)
    db 195,0,4*21,2
    db 195,0,4*22,4
    db 195,0,4*23,9

    ; --- Sprite 24-26 (Sam fall from right)
    db 195,0,4*24,2
    db 195,0,4*25,4
    db 195,0,4*26,9

    ; --- Sprite 27-29 (Sam fall from left)
    db 195,100,4*27,2
    db 195,100,4*28,4
    db 195,100,4*29,9

; --- CONSTANT ---

; --- ROM 16KB ---
    ds #8000 - $  													; Fill the rest of the ROM (up to 16KB with 0s)

; --- RAM ---
    org #0c000  													; RAM address

; --- SPRITES ATTRIBUTES ---     *****  HERE ATTRIBUTSE ARE NOT OK *****
sprites_attrib:
    ; --- Sprite 0-2 (Sam walking to right 1)
    db $0,$5,$4*0,$02
    db $0,$5,$4*1,$04
    db $0,$5,$4*2,$09

    ; --- Sprite 3-5 (Sam walking to right 2)
    db 195,0,4*3,2
    db 195,0,4*4,4
    db 195,0,4*5,9

    ; --- Sprite 6-8 (Sam walking to left 1)
    db 195,0,4*6,2
    db 195,0,4*7,4
    db 195,0,4*8,9

    ; --- Sprite 9-11 (Sam walking to left 2)
    db 195,0,4*9,2
    db 195,0,4*10,4
    db 195,0,4*11,9

    ; --- Sprite 12-14 (Sam right waiting)
    db 195,0,4*12,2
    db 195,0,4*13,4
    db 195,0,4*14,9

    ; --- Sprite 15-17 (Sam left waiting)
    db 195,0,4*15,2
    db 195,0,4*16,4
    db 195,0,4*17,9

    ; --- Sprite 18-20 (Sam jump to left)
    db 195,0,4*18,2
    db 195,0,4*19,4
    db 195,0,4*20,9


    ; --- Sprite 21-23 (Sam jump to right)
    db 195,0,4*21,2
    db 195,0,4*22,4
    db 195,0,4*23,9

    ; --- Sprite 24-26 (Sam fall from right)
    db 195,0,4*24,2
    db 195,0,4*25,4
    db 195,0,4*26,9

    ; --- Sprite 27-29 (Sam fall from left)
    db 195,100,4*27,2
    db 195,100,4*28,4
    db 195,100,4*29,9

; --- VARIABLES ---
!login ou Inscrivez-vous pour poster

Par santiontanon

Paragon (1832)

Portrait de santiontanon

22-05-2023, 13:47

Yes, this is expected behavior. Notice that you are generating a ROM from this assembler code. Since you are not modifying any slot configuration, after booting, what the Z80 will see is:
- BIOS in addresses #0000 -> #3fff
- your ROM in addresses #4000 -> #7fff
- RAM in the rest

But whatever you put in your ROM in addresses #c000, etc. is not seen by the Z80. And even if you were to map addresses #c000 to your ROM cartridge, it would not work as you expect, as the content of your sprites_attrib would still be in ROM (just in the #c000 address space, and hence, it would not be modifiable).

The way to do it is to put it in ROM (like in your first example), and then copy it to RAM at the beginning. Usually, you would have "sprites_attrib_rom" and "sprites_attrib_ram" labels, one defined in ROM and one in RAM, and at the beginning of your cartridge, you do:

ld hl, sprites_attrib_rom
ld de, sprites_attrib_ram
ld bc, 160
ldir

and that's it, that should work.

Par albs_br

Champion (499)

Portrait de albs_br

22-05-2023, 13:53

Code in RAM area needs to be initialized, so you need to copy from ROM on program startup

Example code (untested):


; ROM
org 0x4000

Init:
  ; init SPRATR_buffer, copying data from SPRATR_init
  ld hl, SPRATR_init     ; source address
  ld de, SPRATR_buffer   ; destiny address
  ld bc, 32 * 4          ; size in bytes
  ldir

  ; rest of code here

SPRATR_init: db 96, 128, 0,15
; more db's here


; RAM
org 0xc000
SPRATR_buffer: rb 32 * 4

Edit: posted before I see @santi answer.

Par santiontanon

Paragon (1832)

Portrait de santiontanon

22-05-2023, 15:46

haha, yeah, we were typing the same thing Smile

Par fpracek

Resident (58)

Portrait de fpracek

22-05-2023, 15:50

THANKSSSSS TO ALL!!!!!!!!!!!!!!!!!!!!