Page 2 of 3

Posted: Tue Aug 18, 2015 7:51 am
by BigEvilCorporation
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.

Posted: Wed Aug 19, 2015 11:18 pm
by SegaDev
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.
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.

Sincerely,

SegaDev

Posted: Thu Aug 20, 2015 8:54 am
by BigEvilCorporation
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'.

Posted: Mon Aug 24, 2015 10:36 pm
by SegaDev
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'.
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.

Sincerely,

SegaDev

Posted: Wed Aug 26, 2015 7:41 am
by BigEvilCorporation
SegaDev wrote:
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'.
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.

Sincerely,

SegaDev
It just so happens I wrote a routine to do this over the weekend, I'll share it when I get home.

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

Posted: Thu Aug 27, 2015 12:04 pm
by BigEvilCorporation
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.

Re: Sprite Isn't Showing Up

Posted: Tue Sep 01, 2015 10:52 pm
by SegaDev
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'm getting errors when assembling the source code with that subroutine:
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
I added the appropriate labels to framework/charmap.asm as stated and still am getting the errors:

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
Any assistance in this matter would be greatly appreciated.

Sincerely,

SegaDev

Re: Sprite Isn't Showing Up

Posted: Wed Sep 02, 2015 8:53 am
by BigEvilCorporation
Your labels need colons: after them :)

Re: Sprite Isn't Showing Up

Posted: Wed Sep 02, 2015 10:51 pm
by SegaDev
BigEvilCorporation wrote:Your labels need colons: after them :)
Nope that didn't work either:
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
Any assistance in this matter would be greatly appreciated.

Sincerely,

SegaDev

Re: Sprite Isn't Showing Up

Posted: Thu Sep 03, 2015 1:24 am
by Sik
BigEvilCorporation wrote:Your labels need colons: after them :)
Wrong, it's determined by whether there's whitespace before the text or not. The colon is actually optional.

Re: Sprite Isn't Showing Up

Posted: Thu Sep 03, 2015 7:17 pm
by BigEvilCorporation
Sik wrote:
BigEvilCorporation wrote:Your labels need colons: after them :)
Wrong, it's determined by whether there's whitespace before the text or not. The colon is actually optional.
Awesome, didn't know that!
SegaDev wrote:...
I'm not sure then, it looks fine from what I can see. Send full source?

Re: Sprite Isn't Showing Up

Posted: Fri Sep 04, 2015 10:45 pm
by SegaDev
BigEvilCorporation wrote:
Sik wrote:
BigEvilCorporation wrote:Your labels need colons: after them :)
Wrong, it's determined by whether there's whitespace before the text or not. The colon is actually optional.
Awesome, didn't know that!
SegaDev wrote:...
I'm not sure then, it looks fine from what I can see. Send full source?
Sure here the link to the latest version of the source code with the "improvements". :) Any assistance in this matter would be greatly appreciated.

Sincerely,

SegaDev

Re: Sprite Isn't Showing Up

Posted: Wed Sep 09, 2015 8:18 pm
by BigEvilCorporation
Ahh my apologies, they weren't supposed to be labels, but offsets into the charmap:

Code: Select all

ASCIIStart equ 0x20 ; First ASCII code in table
ASCIIAlphaOffset equ ASCIIStart+(ASCIIAlphaStart-ASCIIMap)
ASCIINumericOffset equ ASCIIStart+(ASCIINumericStart-ASCIIMap)
then your labels in the map need to be:

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
...
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 ;)

Re: Sprite Isn't Showing Up

Posted: Wed Sep 09, 2015 8:51 pm
by BigEvilCorporation
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
Image

Re: Sprite Isn't Showing Up

Posted: Wed Sep 16, 2015 3:38 am
by SegaDev
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
Image
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?

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
but it still prints as a hex number. :(

Sincerely,

SegaDev