sjasm 0.42 and structs

By ARTRAG

Enlighted (6923)

ARTRAG's picture

01-02-2014, 19:00

I'm experimenting sjasm's struct and map commands.
I want to allocate in RAM an array of 24 structs to store enemies data.
I defined a map area starting from 0xc000 for all RAM data with this code:

[...]             ; <-- rom code and data here in the 0x4000-0x7FFF range
	map 0xc000
; other variables
dxmap		#1
xmap			#2
yship			#1
xship			#2
aniframe		#1
anispeed		#1
ram_sat			#128

; struct declared
	struct enemy_data
y		db	0
x		dw	0
status	db	0
	ends

; actual enemy data  - at least in my idea ;-)
enemies:
	[24] enemy_data

	endmap

The problem is that, from what I can see, the labels generated for enemies are allocated in ROM, and not in the map area allocated at 0xc000 in the RAM.
I get this in the .lst file:

[...]
00:00006C42 X ms_demo_shapes_95   ; <- last location used in rom 
00:0000C000   dxmap                ; <- ram variables correctly allocated in 0xc000
00:0000C001   xmap
00:0000C003   yship
00:0000C004 X xship
00:0000C006   aniframe
00:0000C007   anispeed
00:0000C008   ram_sat
00:00000000 X enemy_data.y
00:00000001 X enemy_data.x
00:00000003 X enemy_data.status
00:00000004 X enemy_data
00:00006C62 X enemies            ; <- ARRAY of STRUCTS allocated in ROM instead of RAM !!!

How to say to sjasm that these variables defined as struct go in the 0xc000 area ?

Login or register to post comments

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

02-02-2014, 00:24

Hmm... I have always used PHASE or ORG

Edit: Sorry I got your question wrong...

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

02-02-2014, 00:34

I don't know if this is what you seek, but you can give offset address as parameter for struct. ie.
struct enemy_data,#C000

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

02-02-2014, 01:01

Reading once again I think I got your question right in the first place after all... Your struct array is not part of label map as it contains data. Therefore you have to use PHASE instead to get the pointers correct. The data will still remain in ROM-area unless you move it to RAM with ie LDIR.

By ARTRAG

Enlighted (6923)

ARTRAG's picture

02-02-2014, 01:10

Hi, thanks a lot
in the end I changed the way I allocate variables in ram: instead of MAP now I'm using code and all seems to work as expected
This is my code now

	code @ 0C000h

dxmap			ds 1
xmap			ds 2

yship			ds 1
xship			ds 2
aniframe		ds 1
anispeed		ds 1

ram_sat			ds 128
	
	struct enemy_data
y		db	0
x		dw	0
status	db	0
	ends
	
enemies:
	[24] enemy_data
	

that leads to this:

     858   00:6CC7                      	code @ 0C000h
     859   00:C000                      
     860   00:C000  00 (1)              dxmap			ds 1
     861   00:C001  00 (2)              xmap			ds 2
     862   00:C003                      
     863   00:C003  00 (1)              yship			ds 1
     864   00:C004  00 (2)              xship			ds 2
     865   00:C006  00 (1)              aniframe		ds 1
     866   00:C007  00 (1)              anispeed		ds 1
     867   00:C008                      
     868   00:C008  00 (128)            ram_sat			ds 128
     869   00:C088                      	
     870   00:C088                      	struct enemy_data
     871   00:C088                    < y		db	0
     872   00:C088                    < x		dw	0
     873   00:C088                    < status	db	0
     874   00:C088                    < 	ends
     875   00:C088                      	
     876   00:C088                      enemies:
     877   00:C088                      	[24] enemy_data
     877   00:C088  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
     877   00:C098  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
     877   00:C0A8  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
     877   00:C0B8  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
     877   00:C0C8  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
     877   00:C0D8  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
     878   00:C0E8  

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

02-02-2014, 01:14

Maybe in the first place you wanted to do:
enemies: #enemy_data*24

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

02-02-2014, 01:24

	map 0xc000
; other variables
dxmap		#1
xmap			#2
yship			#1
xship			#2
aniframe		#1
anispeed		#1
ram_sat			#128
                                
; struct declared
	struct enemy_data
y		db	0
x		dw	0
status	db	0
	ends

; actual enemy data  - at least in my idea ;-)
enemies:    #enemy_data*24

end_of_enemies #0

	endmap

       1   00:0000  (C000)              	map 0xc000
       2   00:0000                      ; other variables
       3   00:0000  (00:C000)           dxmap		#1
       4   00:0000  (00:C001)           xmap			#2
       5   00:0000  (00:C003)           yship			#1
       6   00:0000  (00:C004)           xship			#2
       7   00:0000  (00:C006)           aniframe		#1
       8   00:0000  (00:C007)           anispeed		#1
       9   00:0000  (00:C008)           ram_sat			#128
      10   00:0000                                                      
      11   00:0000                      ; struct declared
      12   00:0000                      	struct enemy_data
      13   00:0000                    < y		db	0
      14   00:0000                    < x		dw	0
      15   00:0000                    < status	db	0
      16   00:0000                    < 	ends
      17   00:0000                      
      18   00:0000                      ; actual enemy data  - at least in my idea ;-)
      19   00:0000  (00:C088)           enemies:    #enemy_data*24
      20   00:0000                      
      21   00:0000  (00:C0E8)           end_of_enemies #0
      22   00:0000                      
      23   00:0000  (0000)              	endmap

    LABELS
-------------------------------------------------
00:0000C000 X dxmap
00:0000C001 X xmap
00:0000C003 X yship
00:0000C004 X xship
00:0000C006 X aniframe
00:0000C007 X anispeed
00:0000C008 X ram_sat
00:00000000 X enemy_data.y
00:00000001 X enemy_data.x
00:00000003 X enemy_data.status
00:00000004   enemy_data
00:0000C088 X enemies
00:0000C0E8 X end_of_enemies

By ARTRAG

Enlighted (6923)

ARTRAG's picture

02-02-2014, 02:36

Great! using
enemies: #enemy_data*24
in map area works perfectly. Thanks !