This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 07 Sep 2008 03:58:51 pm    Post subject:

i was learning asm, and i was trying to create a tilemap draw routine for practice
however, my routine ends up drawing only sprite 1
this is my code, i comented it so it is easer to read

i probaby did someting wrong in calucating the sprite offset (check comments)

by the way, we really need options for hiding those huge code blocks Neutral


Code:
.nolist
#include "ti83plus.inc"
#include "ti83plusasm.inc"
#define    ProgStart    $9D95 -2
.list
.org    ProgStart
    .db    t2ByteTok, tAsmCmp

;BCALL(_runindicoff)
;BCALL(_clrLCDfull)


 LD   H, 0;Xpos
 LD   L, 0;Ypos

loopX:
 PUSH   HL
 CALL  sprite
 BCALL(_GrBufCpy)   ;i know this is slow... just did it so it is easier to see whats going on
 POP   HL
 INC   H
 LD  A,H
 CP   12
 JR   Z,loopY
 JR   loopX

loopY:
 LD   H, 0
 INC   L
 INC   L
 INC   L
 INC   L
 INC   L
 INC   L
 INC   L
 INC   L
 LD   A, L
 CP   8*8
 JR   Z,exit
 JR   loopX


;-----the next part is wrong???-----(up to the next line)-------
sprite:
 PUSH   HL
 PUSH  HL;multiply Ypos by 12
 LD   H,0;L=ypos
 ADD   HL,HL;HL=2Y
 ADD   HL,HL;4Y
 LD   D,H;D=0
 LD   E,L;E=2Y
 ADD   HL,HL;8Y
 ADD   HL,DE;12Y

 POP   DE;get Xpos back....
 LD   A,D;A=Xpos
 LD   E,A;E=xpos
 LD   D,0;DE=$00+Xpos
 ADD   HL,DE;HL is now offset tilemap
 LD   DE,tilemap ;get adress of tilemap
 ADD   HL,DE;add offset to tilemap
 EX   DE,HL;DE is now (finaly) adress of correct byte in tilemap
;get whatever is in tilemap
 LD   A,(HL)   
;and multiply by 8
 ADD   A,A;2
 ADD   A,A;4
 ADD   A,A;8
;A = 8*tilemap
 LD   C,A;save 8*tilemap[y][x]
 LD   B,0
 POP  HL;next block of code requires X and Y pos in HL
 PUSH   BC   


;---------------------------------works-------------------------------------------
 LD  A,H            ;preserve "X" as HL is being worked on
 LD  H,$00     ;clear out H so HL has nothing but "Y".
 ADD  HL,HL   ;HL x 2 (starting multiply by 12)
 ADD  HL,HL   ;HL x 4
 LD  E,L      ;Save HL to DE while HL = HL times 4
 LD  D,H       ;
 ADD  HL,HL   ;HL x 8
 ADD  HL,DE    ;HL x 12. HL now is at start of row indicated
 LD  E,A       ;Restore "X" back into LSB of DE
 LD  D,$00 ;Clear out top of register pair
 ADD  HL,DE   ;row + col....
 LD  DE,plotsscreen ;getting address of the buffer
 ADD  HL,DE   ;we now have correct address in the buffer
;-----------------------------------------------------------------------------------


 POP   DE
 PUSH   HL
 LD   HL,pic
 ADD   HL,DE;get correct bit from sprite..
 EX   DE,HL
 LD  B,8          ;eight copy loops for height.
 POP   HL

;-------------works----------------
spriteloop:         
 PUSH  BC         ;preserve BC (not enough registers)
  LD  A,(DE)      ;get a byte from the sprite
  OR  (HL)        ;OR sprite with contents of the buffer
  LD  (HL),A      ;save the result back to the buffer
  INC  DE         ;go to next byte in sprite
  LD  BC,12       ;next row below is 12 bytes
  ADD  HL,BC      ;go to next byte underneath this
 POP  BC          ;restore the byte in BC (B is the loop counter)
 DJNZ spriteloop ;simple loop that stops after eight iterations.
 RET             ;return
;--------------------------------------

exit:
 RET

tilemap:
.db $010101010101010101010101;1,1,1,1,1,1,1,1,1,1,1,1
.db $010000000000000000000001;1,0,0,0,0,0,0,0,0,0,0,1
.db $010002000200020002000001;1,0,2,0,2,0,2,0,2,0,0,1
.db $010000020002000200020001;1,0,0,2,0,2,0,2,0,2,0,1
.db $010002000200020002000001;1,0,2,0,2,0,2,0,2,0,0,1
.db $010000020002000200020001;1,0,0,2,0,2,0,2,0,2,0,1
.db $010000000000000000000001;1,0,0,0,0,0,0,0,0,0,0,1
.db $010101010101010101010101;1,1,1,1,1,1,1,1,1,1,1,1

 
pic:
;sprite 0
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111
.db %11111111

;sprite 1
.db %11111111; the program draws only this sprite atm
.db %11000011
.db %11000011
.db %11000011
.db %11000011
.db %11000011
.db %11000011
.db %11111111

;sprite 2
.db %01111000 ;by the way, this sprite looks like a '2'
.db %10000100
.db %00000010
.db %00000100
.db %00001000
.db %00010000
.db %00100000
.db %01111111


.end
.end

[code] → [codebox]


Last edited by Guest on 07 Sep 2008 04:26:29 pm; edited 1 time in total
Back to top
tr1p1ea


Elite


Joined: 03 Aug 2003
Posts: 870

Posted: 07 Sep 2008 04:46:53 pm    Post subject:

I dont have time to go over your code but just quickly this might be a more straightforward approach:


Code:
.nolist
#define end .end
#define END .end
#define equ .equ
#define EQU .equ

#include "ti83plus.inc"
#define ProgStart $9D95
.list

.org ProgStart - 2
.db t2ByteTok, tAsmCmp

prog_start:
        bcall(_RunIndicOff)             ; turn off the Run Indicator
        call drawmap                    ; draw map
        bcall(_grBufCpy)                ; update screen
        bcall(_getkey)                  ; wait for keypress
        bcall(_grBufClr)                ; clear graph buffer
        ret                             ; return (exit)

drawmap:
        ld ix,tilemap                   ; ix = pointer tilemap data
        ld de,plotsscreen               ; de = graph buffer
        ld bc,(12*256)+8                ; 12 cloumns, 8 rows
loopx:
        push bc                         ; save x,y
        push de                         ; save buffer position
        ld l,(ix + 0)                   ; get tileid
        ld h,0
        add hl,hl                       ; * 2
        add hl,hl                       ; * 4
        add hl,hl                       ; tileid * 8 (since tiles are 8 bytes each)
        ld bc,tiledata                  ; offset tiledata
        add hl,bc                       ; hl now points to tile in tiledata
        ex de,hl                        ; de = tiledata, hl = buffer
        ld a,8
        ld bc,12
tileloop:
        push af
        ld a,(de)                       ; get tiledata
        ld (hl),a                       ; copy to buffer
        add hl,bc                       ; increase bufer to next row
        inc de                          ; increase to next byte in tiledata
        pop af
        dec a
        jr nz,tileloop                  ; copy tiledata to buffer
        inc ix                          ; inc to next tileid
        pop de
        inc de                          ; inc the next spot in buffer
        pop bc
        djnz loopx                      ; loop x 12 times
        ld hl,84
        add hl,de                       ; move down a row of tiles - 12
        ex de,hl                        ; de points to new row
        dec c
        ret z
        ld b,12                         ; restore x counter
        jr loopx                        ; loop y 8 times

tilemap:
        .db 1,1,1,1,1,1,1,1,1,1,1,1
        .db 1,0,0,0,0,0,0,0,0,0,0,1
        .db 1,0,2,0,2,0,2,0,2,0,0,1
        .db 1,0,0,2,0,2,0,2,0,2,0,1
        .db 1,0,2,0,2,0,2,0,2,0,0,1
        .db 1,0,0,2,0,2,0,2,0,2,0,1
        .db 1,0,0,0,0,0,0,0,0,0,0,1
        .db 1,1,1,1,1,1,1,1,1,1,1,1


tiledata:
;sprite 0
        .db %11111111
        .db %11111111
        .db %11111111
        .db %11111111
        .db %11111111
        .db %11111111
        .db %11111111
        .db %11111111

;sprite 1
        .db %11111111; the program draws only this sprite atm
        .db %11000011
        .db %11000011
        .db %11000011
        .db %11000011
        .db %11000011
        .db %11000011
        .db %11111111

;sprite 2
        .db %01111000 ;by the way, this sprite looks like a '2'
        .db %10000100
        .db %00000010
        .db %00000100
        .db %00001000
        .db %00010000
        .db %00100000
        .db %01111111

.end
END
Back to top
darkstone knight


Advanced Member


Joined: 07 Sep 2008
Posts: 438

Posted: 08 Sep 2008 02:08:29 am    Post subject:

thanks for that code, i was thiunking too much like basic code

as each byte on the screen is actualy 8*12(X/Cool+X, you dont need an y byte(theoreticaly..)

edit: that means, you check for mod 86, and than add 12*8+1 bytes to x position


Last edited by Guest on 08 Sep 2008 02:18:06 am; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement