Convert AT co-ordinates to PLOT co-ordinates

edited January 2014 in Development
How do you convert the 2 from MC? I don't know how to convert the vertical value as they're differently ordered...

Heres what I have so far:
org 47000-2
x	defb 0
y	defb 0		;calculated plot points

	ld a,(50000-3)	;vertical AT co-ord

	ld b,22	
	sub b

	add a,a
	ADD A,A
	add a,a		;times by 8
	
	ld (x),a	;store vertical plot point
	ret
Post edited by daveysludge on

Comments

  • edited January 2014
    PLOT is from the bottom of the screen upward, but since it's BASIC, it's from the bottom of the 22nd character row, not the 24th. So do 175-Y to get the plot position down the screen (from 0), then divide by 8 if you want the character row.

    To go the other way round, multiply the character row by 8, then do 175-Y to turn it upside down. Though that will give you the plot position of the top of the character row. For the bottom of the character row, subtract another 7 to move down 7 pixels (or simply use 168-Y instead). e.g. 21 x 8 = 168 then 175-168 = 7 or 168-168 = 0.

    Multiply and divide by two by using the arithmetic shift instructions rather than ADDs.

    It's not neccesarily the quickest but you can probably follow:

    LD A,(nnnn)
    SLA A
    SLA A
    SLA A
    LD B,A
    LD A,168
    SUB B
    LD (nnnn),A

    Or you could reverse the order of the sum by making A
    negative first, then simply adding 168:

    LD A,(nnnn)
    SLA A
    SLA A
    SLA A
    NEG A
    ADD A,168
    LD (nnnn),A

    I think this is OK. The vertical position, because it could be greater than 127, is kind of breaking the rules for negative 8-bit numbers, but since they all wrap around it should work out OK in the end.
    Joefish
    - IONIAN-GAMES.com -
  • edited January 2014
    Cheers mate, sorted!
  • edited January 2014
    It depends if you want to convert to the highest or lowest PLOT coordinate within the same character position.

    Converting from AT vertical coordinate to lowest PLOT vertical coordinate (optimized):
    ld a,(VERT_AT)
    add a,a
    add a,a
    add a,a
    cpl
    add a,169
    ld (VERT_PLOT),a
    

    Converting from AT vertical coordinate to highest PLOT vertical coordinate (optimized):
    ld a,(VERT_AT)
    add a,a
    add a,a
    add a,a
    cpl
    add a,176
    ld (VERT_PLOT),a
    

    And converting from PLOT vertical coordinate to AT vertical coordinate (optimized):
    ld a,(VERT_PLOT)
    and $f8
    rrca
    rrca
    rrca
    cpl
    add a,22
    ld (VERT_AT),a
    
    Creator of ZXDB, BIFROST/NIRVANA, ZX7/RCS, etc. I don't frequent this forum anymore, please look for me elsewhere.
Sign In or Register to comment.