Sprite Isn't Showing Up
Moderator: BigEvilCorporation
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Oh I forgot to mention the alignment bug! Your strings file is an odd number of bytes, then you include the spritedesc file underneath it. Add an 'even' keyword or include the strings file last.
On hardware it crashes, on emulators the sprites table is one byte out.
On hardware it crashes, on emulators the sprites table is one byte out.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
Thanks, i managed to get it working thanks to you. I uploaded the source code to bitbucket. so others may learn from it. What is the alignment bug, i tried to google it and couldn't find anything on it.BigEvilCorporation wrote:Oh I forgot to mention the alignment bug! Your strings file is an odd number of bytes, then you include the spritedesc file underneath it. Add an 'even' keyword or include the strings file last.
On hardware it crashes, on emulators the sprites table is one byte out.
Sincerely,
SegaDev
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Opcodes and word/longword data must rest on an aligned boundary - e.g., you can't move a word from an address like 0x00FF001B since it's not divisible by 2.
In your code you have a strings.asm file which holds data of an odd size, so anything you include after it will rest on an uneven boundary, and you'll get errors trying to read words/longwords or execute code from those addresses.
At the end of your strings.asm file use the keyword 'even' to align it, or pad your string data with an extra '0'.
In your code you have a strings.asm file which holds data of an odd size, so anything you include after it will rest on an uneven boundary, and you'll get errors trying to read words/longwords or execute code from those addresses.
At the end of your strings.asm file use the keyword 'even' to align it, or pad your string data with an extra '0'.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
Dumb Question, how do i draw numbers from a ram location such as the player's score without having to define a million text strings or using 60 sprites, or 1 number per sprite and position of the score. Any assistance in this matter would be greatly appreciated.BigEvilCorporation wrote:Opcodes and word/longword data must rest on an aligned boundary - e.g., you can't move a word from an address like 0x00FF001B since it's not divisible by 2.
In your code you have a strings.asm file which holds data of an odd size, so anything you include after it will rest on an uneven boundary, and you'll get errors trying to read words/longwords or execute code from those addresses.
At the end of your strings.asm file use the keyword 'even' to align it, or pad your string data with an extra '0'.
Sincerely,
SegaDev
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
It just so happens I wrote a routine to do this over the weekend, I'll share it when I get home.SegaDev wrote:Dumb Question, how do i draw numbers from a ram location such as the player's score without having to define a million text strings or using 60 sprites, or 1 number per sprite and position of the score. Any assistance in this matter would be greatly appreciated.BigEvilCorporation wrote:Opcodes and word/longword data must rest on an aligned boundary - e.g., you can't move a word from an address like 0x00FF001B since it's not divisible by 2.
In your code you have a strings.asm file which holds data of an odd size, so anything you include after it will rest on an uneven boundary, and you'll get errors trying to read words/longwords or execute code from those addresses.
At the end of your strings.asm file use the keyword 'even' to align it, or pad your string data with an extra '0'.
Sincerely,
SegaDev
Basically:
- Walk the number 4 bits at a time
- Mask 0x0F
- Test if it's a decimal (0-9) or an alpha (A-F) character
- Add the decimal/alpha offset into the ASCII table (see framewk/charmap.asm) and write to string address
- Shift number 4 bits and advance string pointer
- Loop until you've processed the whole word/longword
- Terminate the string with a 0
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Here's the hex word version:
You'll need to add the appropriate labels to framewk/charmap.asm. Use DrawTextPlaneA to get it on screen.
Can be shortened or expanded for byte or longword, and for 10-base decimal it'll need to use divs instead of shifts. I'm sure you'll figure something out
The string address will be the same on the way out as it was on the way in (since it jumps forwards and works backwards) so no need to backup the address to the stack first.
Code: Select all
ItoA_Hex_w:
; Converts a word to hex ASCII
; a0 --- In/Out: String address
; d0 (w) In: Number to convert
; 4 nybbles + 0x + terminator, working backwards
add.l #0x7, a0
; Zero terminate
move.b #0x0, -(a0)
move.w #0x0, d1 ; Char ptr
move.w #0x3, d2 ; 4 nybbles in a word
@NybbleLp:
move.b d0, d3 ; Byte to d3
andi.b #0x0F, d3 ; Bottom nybble
cmp.b #0x9, d3
ble @Numeric ; Branch if in numeric range
add.b #(ASCIIAlphaOffset-0xA), d3 ; In alpha range (A - F)
move.b d3, -(a0) ; Back to string
lsr.w #0x4, d0 ; Next nybble
dbra d2, @NybbleLp ; Loop
bra @End
@Numeric:
add.b #ASCIINumericOffset, d3 ; In numeric range (0 - 9)
move.b d3, -(a0) ; Back to string
lsr.w #0x4, d0 ; Next nybble
dbra d2, @NybbleLp ; Loop
@End:
;0X
move.b #'X', -(a0)
move.b #'0', -(a0)
rts
Can be shortened or expanded for byte or longword, and for 10-base decimal it'll need to use divs instead of shifts. I'm sure you'll figure something out
The string address will be the same on the way out as it was on the way in (since it jumps forwards and works backwards) so no need to backup the address to the stack first.
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
Re: Sprite Isn't Showing Up
I'm getting errors when assembling the source code with that subroutine:BigEvilCorporation wrote:Here's the hex word version:
Code: Select all
ItoA_Hex_w: ; Converts a word to hex ASCII ; a0 --- In/Out: String address ; d0 (w) In: Number to convert ; 4 nybbles + 0x + terminator, working backwards add.l #0x7, a0 ; Zero terminate move.b #0x0, -(a0) move.w #0x0, d1 ; Char ptr move.w #0x3, d2 ; 4 nybbles in a word @NybbleLp: move.b d0, d3 ; Byte to d3 andi.b #0x0F, d3 ; Bottom nybble cmp.b #0x9, d3 ble @Numeric ; Branch if in numeric range add.b #(ASCIIAlphaOffset-0xA), d3 ; In alpha range (A - F) move.b d3, -(a0) ; Back to string lsr.w #0x4, d0 ; Next nybble dbra d2, @NybbleLp ; Loop bra @End @Numeric: add.b #ASCIINumericOffset, d3 ; In numeric range (0 - 9) move.b d3, -(a0) ; Back to string lsr.w #0x4, d0 ; Next nybble dbra d2, @NybbleLp ; Loop @End: ;0X move.b #'X', -(a0) move.b #'0', -(a0) rts
You'll need to add the appropriate labels to framewk/charmap.asm. Use DrawTextPlaneA to get it on screen.
Can be shortened or expanded for byte or longword, and for 10-base decimal it'll need to use divs instead of shifts. I'm sure you'll figure something out
The string address will be the same on the way out as it was on the way in (since it jumps forwards and works backwards) so no need to backup the address to the stack first.
I added the appropriate labels to framework/charmap.asm as stated and still am getting the errors:SN 68k version 2.53
C:\SEGADEV\SRC\FRAMEWORK\UTILITY.ASM(26) : Error : Symbol 'asciialphaoffset' not defined
C:\SEGADEV\SRC\FRAMEWORK\UTILITY.ASM(32) : Error : Symbol 'asciinumericoffset' not defined
Assembly completed.
2 error(s) from 2835 lines in 0.2 seconds
Code: Select all
;==============================================================
; BIG EVIL CORPORATION .co.uk
;==============================================================
; SEGA Genesis Framework (c) Matt Phillips 2014
;==============================================================
; charmap.asm - ASCII character map
;==============================================================
ASCIIStart: equ 0x20 ; First ASCII code in table
ASCIIMap:
dc.b 0x00 ; SPACE (ASCII code 0x20)
dc.b 0x28 ; ! Exclamation mark
dc.b 0x2B ; " Double quotes
dc.b 0x2E ; # Hash
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x2C ; ' Single quote
dc.b 0x29 ; ( Open parenthesis
dc.b 0x2A ; ) Close parenthesis
dc.b 0x00 ; UNUSED
dc.b 0x2F ; + Plus
dc.b 0x26 ; , Comma
dc.b 0x30 ; - Minus
dc.b 0x25 ; . Full stop
dc.b 0x31 ; / Slash or divide
ASCIINumericOffset
dc.b 0x1B ; 0 Zero
dc.b 0x1C ; 1 One
dc.b 0x1D ; 2 Two
dc.b 0x1E ; 3 Three
dc.b 0x1F ; 4 Four
dc.b 0x20 ; 5 Five
dc.b 0x21 ; 6 Six
dc.b 0x22 ; 7 Seven
dc.b 0x23 ; 8 Eight
dc.b 0x24 ; 9 Nine
dc.b 0x2D ; : Colon
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x27 ; ? Question mark
dc.b 0x00 ; UNUSED
ASCIIAlphaOffset
dc.b 0x01 ; A
dc.b 0x02 ; B
dc.b 0x03 ; C
dc.b 0x04 ; D
dc.b 0x05 ; E
dc.b 0x06 ; F
dc.b 0x07 ; G
dc.b 0x08 ; H
dc.b 0x09 ; I
dc.b 0x0A ; J
dc.b 0x0B ; K
dc.b 0x0C ; L
dc.b 0x0D ; M
dc.b 0x0E ; N
dc.b 0x0F ; O
dc.b 0x10 ; P
dc.b 0x11 ; Q
dc.b 0x12 ; R
dc.b 0x13 ; S
dc.b 0x14 ; T
dc.b 0x15 ; U
dc.b 0x16 ; V
dc.b 0x17 ; W
dc.b 0x18 ; X
dc.b 0x19 ; Y
dc.b 0x1A ; Z (ASCII code 0x5A)
EVEN
Sincerely,
SegaDev
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Re: Sprite Isn't Showing Up
Your labels need colons: after them
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
Re: Sprite Isn't Showing Up
Nope that didn't work either:BigEvilCorporation wrote:Your labels need colons: after them
C:\segadev\src> build
C:\segadev\src>del rom.bin
C:\segadev\src>asm68k.exe /p source.asm,rom.bin
SN 68k version 2.53
C:\SEGADEV\SRC\FRAMEWORK\UTILITY.ASM(26) : Error : Symbol 'asciialphaoffset' not defined
C:\SEGADEV\SRC\FRAMEWORK\UTILITY.ASM(32) : Error : Symbol 'asciinumericoffset' not defined
Assembly completed.
2 error(s) from 2835 lines in 0.3 seconds
C:\segadev\src>pause
Code: Select all
;==============================================================
; BIG EVIL CORPORATION .co.uk
;==============================================================
; SEGA Genesis Framework (c) Matt Phillips 2014
;==============================================================
; charmap.asm - ASCII character map
;==============================================================
ASCIIStart: equ 0x20 ; First ASCII code in table
ASCIIMap:
dc.b 0x00 ; SPACE (ASCII code 0x20)
dc.b 0x28 ; ! Exclamation mark
dc.b 0x2B ; " Double quotes
dc.b 0x2E ; # Hash
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x2C ; ' Single quote
dc.b 0x29 ; ( Open parenthesis
dc.b 0x2A ; ) Close parenthesis
dc.b 0x00 ; UNUSED
dc.b 0x2F ; + Plus
dc.b 0x26 ; , Comma
dc.b 0x30 ; - Minus
dc.b 0x25 ; . Full stop
dc.b 0x31 ; / Slash or divide
ASCIINumericOffset:
dc.b 0x1B ; 0 Zero
dc.b 0x1C ; 1 One
dc.b 0x1D ; 2 Two
dc.b 0x1E ; 3 Three
dc.b 0x1F ; 4 Four
dc.b 0x20 ; 5 Five
dc.b 0x21 ; 6 Six
dc.b 0x22 ; 7 Seven
dc.b 0x23 ; 8 Eight
dc.b 0x24 ; 9 Nine
dc.b 0x2D ; : Colon
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x00 ; UNUSED
dc.b 0x27 ; ? Question mark
dc.b 0x00 ; UNUSED
ASCIIAlphaOffset:
dc.b 0x01 ; A
dc.b 0x02 ; B
dc.b 0x03 ; C
dc.b 0x04 ; D
dc.b 0x05 ; E
dc.b 0x06 ; F
dc.b 0x07 ; G
dc.b 0x08 ; H
dc.b 0x09 ; I
dc.b 0x0A ; J
dc.b 0x0B ; K
dc.b 0x0C ; L
dc.b 0x0D ; M
dc.b 0x0E ; N
dc.b 0x0F ; O
dc.b 0x10 ; P
dc.b 0x11 ; Q
dc.b 0x12 ; R
dc.b 0x13 ; S
dc.b 0x14 ; T
dc.b 0x15 ; U
dc.b 0x16 ; V
dc.b 0x17 ; W
dc.b 0x18 ; X
dc.b 0x19 ; Y
dc.b 0x1A ; Z (ASCII code 0x5A)
EVEN
Sincerely,
SegaDev
Re: Sprite Isn't Showing Up
Wrong, it's determined by whether there's whitespace before the text or not. The colon is actually optional.BigEvilCorporation wrote:Your labels need colons: after them
Sik is pronounced as "seek", not as "sick".
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Re: Sprite Isn't Showing Up
Awesome, didn't know that!Sik wrote:Wrong, it's determined by whether there's whitespace before the text or not. The colon is actually optional.BigEvilCorporation wrote:Your labels need colons: after them
I'm not sure then, it looks fine from what I can see. Send full source?SegaDev wrote:...
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
Re: Sprite Isn't Showing Up
Sure here the link to the latest version of the source code with the "improvements". Any assistance in this matter would be greatly appreciated.BigEvilCorporation wrote:Awesome, didn't know that!Sik wrote:Wrong, it's determined by whether there's whitespace before the text or not. The colon is actually optional.BigEvilCorporation wrote:Your labels need colons: after them
I'm not sure then, it looks fine from what I can see. Send full source?SegaDev wrote:...
Sincerely,
SegaDev
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Re: Sprite Isn't Showing Up
Ahh my apologies, they weren't supposed to be labels, but offsets into the charmap:
then your labels in the map need to be:
Also you were including 'charactermap.asm' instead of 'charmap.asm', again my fault since the last source I sent back to you had all filenames shortened to 8 chars (I'm running MSDOS!).
I shouldn't try helping when I'm tired, sorry
Code: Select all
ASCIIStart equ 0x20 ; First ASCII code in table
ASCIIAlphaOffset equ ASCIIStart+(ASCIIAlphaStart-ASCIIMap)
ASCIINumericOffset equ ASCIIStart+(ASCIINumericStart-ASCIIMap)
Code: Select all
ASCIINumericStart:
dc.b 0x1B ; 0 Zero
dc.b 0x1C ; 1 One
dc.b 0x1D ; 2 Two
dc.b 0x1E ; 3 Three
...
ASCIIAlphaStart:
dc.b 0x01 ; A
dc.b 0x02 ; B
dc.b 0x03 ; C
...
I shouldn't try helping when I'm tired, sorry
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
-
- Very interested
- Posts: 209
- Joined: Sat Sep 08, 2012 10:41 am
- Contact:
Re: Sprite Isn't Showing Up
Tested and working:
Code: Select all
sub.l #0x8, sp ; Alloc string space on stack
move.l sp, a0 ; String to a0
move.w #0xAB12, d0 ; Integer to d0
jsr ItoA_Hex_w ; Integer to ASCII (hex word)
move.l sp, a0 ; String to a0
move.l #PixelFontTileID, d0 ; Font to d0
move.l #0x0808, d1 ; Position to d1
move.l #0x0, d2 ; Palette to d2
jsr DrawTextPlaneA ; Draw text
add.l #0x8, sp ; Free string
A blog of my Megadrive programming adventures: http://www.bigevilcorporation.co.uk
Re: Sprite Isn't Showing Up
Dumb question, what if i want to print an integer number like say 100, 550 etc instead of a hex number, how would i go about doing that?BigEvilCorporation wrote:Tested and working:
Code: Select all
sub.l #0x8, sp ; Alloc string space on stack move.l sp, a0 ; String to a0 move.w #0xAB12, d0 ; Integer to d0 jsr ItoA_Hex_w ; Integer to ASCII (hex word) move.l sp, a0 ; String to a0 move.l #PixelFontTileID, d0 ; Font to d0 move.l #0x0808, d1 ; Position to d1 move.l #0x0, d2 ; Palette to d2 jsr DrawTextPlaneA ; Draw text add.l #0x8, sp ; Free string
Tried
Code: Select all
sub.l #0x8, sp ; Alloc string space on stack
move.l sp, a0 ; String to a0
move.w #0, d0 ; Integer to d0
jsr ItoA_Hex_w ; Integer to ASCII (hex word)
move.l sp, a0 ; String to a0
move.l #PixelFontTileID, d0 ; Font to d0
move.l #0x0808, d1 ; Position to d1
move.l #0x0, d2 ; Palette to d2
jsr DrawTextPlaneA ; Draw text
add.l #0x8, sp ; Free string
Sincerely,
SegaDev