[A83] Re: More questions


[Prev][Next][Index][Thread]

[A83] Re: More questions




i got harper's routine to work fine, jus a sec.  i think i have the changes i 
made to it on my comp....

yep. here it is.


; TileMap demo by Harper Maddox



        .nolist

        #include "ion.inc"      ;tells TASM--the compiler--what file to read 
from to define rom call memory addresses and such
        #include "keys.inc"
        .list
rows = 14

scrollX = savesscreen
scrollY = scrollX+1
coord = scrollX

TILEstart = scrollY+1
#ifdef TI83P            ;a check for TASM to see whether it is making an 83 
program--if so, do the next two commands
        .org    progstart-2
        .db     $BB,$6D
#else               ;if it isn't an 83 program, then do something 
[#]else--the next line
        .org    progstart
#endif              ;simply ends the #ifdef command
        ret             

        jr      nc,begin        ;Jumps to the beginning of the program (this 
line and the below three will be 
        .db     "tilemap",0     ;The title displayed by ION--anything you want
begin:              ;defines where label begin is, program code follows this 
label
start:
 set textwrite,(iy+SGRFLAGS)        ; _vputs writes directly to graph
 set appTextSave,(iy+appFlags)

 ld hl,map
 ld (TILEstart),hl

 xor a
 ld (scrollX),a
 ld (scrollY),a

 call reloadTempMap

movementLoop:
 bcall(_cleargbuf)

 call drawmap

 ld hl,256*56
 ld (pencol),hl
 ld a,(coord)
 ld l,a
 ld h,0
 bcall(_setxxxxop2)
 bcall(_op2toop1)
 ld a,3
 bcall(_dispop1a)

; ld a,lComma
 bcall(_vputmap)

 ld a,(coord+1)
 ld l,a
 ld h,0
 bcall(_setxxxxop2)
 bcall(_op2toop1)
 ld a,3
 bcall(_dispop1a)

 call ionfastcopy

 ei
 halt

 ld a,0ffh          ;resets the keypad.
 out (1),a          ;'Required syntax' :)
 ld a,0feh          ;Enable group 1.
 out (1),a          
 in a,(1)           ;'Required Syntax'

 push af
 bit 0,a
 call z,moveDown
 pop af

 push af
 bit 1,a            
 call z,moveLeft
 pop af

 push af
 bit 2,a
 call z,moveRight
 pop af

 push af
 bit 3,a 
 call z,moveUp
 pop af

 ld a,$ff
 out (1),a
 ld a,$df
 out (1),a
 in a,(1)

; cp kAlpha
; jr z,alphaPressed

 ld a,$ff           ;Reset keypad again.
 out (1),a
 ld a,$bf           ;Enable group 2.
 out (1),a 
 in a,(1)

; cp k2nd
; jr z,secondPressed
 cp kMode
 jr nz,movementLoop

 ret

moveDown:
 ld a,(coord+1)
 add a,4
 ld (coord+1),a
 cp 24
 ret c

 sub 12
 ld (coord+1),a

 ld hl,(TILEstart)
 ld de,rows
 add hl,de

fixY:
 ld (TILEstart),hl
 jp reloadTempMap

moveLeft:
 ld a,(coord)
 sub 4
 jr c,scrollLEFT
 ld (coord),a
 ret

scrollLEFT:
 add a,13
 ld (scrollX),a

 ld hl,(TILEstart)
 dec hl

fixX:
 ld (TILEstart),hl
 jp reloadTempMap

moveRight:
 ld a,(coord)
 add a,4
 ld (coord),a
 cp 24
 ret c

 sub 12
 ld (coord),a

 ld hl,(TILEstart)
 inc hl
 jr fixX

moveUp:
 ld a,(coord+1)
 sub 4
 jr c,scrollUP
 ld (coord+1),a
 ret

scrollUP:
 add a,13
 ld (scrollY),a

 ld hl,(TILEstart)
 ld de,rows
 xor a
 sbc hl,de
 jr fixY


drawmap:
 ld a,(scrollY)

 ; we must move (scrollY) number of columns down
 ;  to accomplish this we offset the start of the data we read from tempMap

 ; the formula for the length of a row is:

 ; 12 + SpriteWidth/4
 ;ex: for a 12x12 sprite, 12+12/4 = 15

 inc a

 ld de,15
 ld hl,tempMap
 ld b,a         ; we don't need to worry about the zero case
 or a
 jr z,skipScrollMAPy

scrollMapYloop:
 add hl,de
 djnz scrollMapYloop

skipScrollMAPy:
 ld a,(scrollX)
 ld d,0     ; Do x/8
 ld e,a
 srl e
 srl e
 srl e
 add hl,de  ; hl, the sprite pointer, is now offset

 ld de,plotsscreen

 ld a,(scrollX)
 and %111
 jr z,Aligned

 push hl
 ex de,hl
 pop ix

 ld e,64    ; lines painted
 ld d,a     ; shift d bits per line

LineLOOP:
 
 ld b,12
shift_IT:
 push bc
 ld b,(ix+0)
 inc ix
 ld c,(ix+0)
 push de
 ld e,0
shiftLOOP:
 sla b
 rlc c
 rl e
 dec d
 jp nz,shiftLOOP

 ld a,e
 and c
 pop de

 or b             ; Write line to graphbuf
 ld (hl),a

 inc hl
 pop bc
 djnz Shift_IT

 ld bc,3           ; Calculate next line address
 add ix,bc
 dec e
 jr nz,LineLOOP        ; Next line
 ret


Aligned:
 ld b,64    ; b = 64 lines
alignedLOOP:
 push bc
 ld bc,12   ; paint this line on the screen
 ldir
 ld bc,3
 add hl,bc  ; advance pointer 64 bits, to the next start.
 pop bc
 djnz alignedLOOP
 ret


 ld hl,tempmap
 ld bc,1320
dumbloop:
 ld (hl),c
 inc hl
 dec bc
 ld a,b
 or c
 jr nz,dumbloop
 ret


reloadTempMap:
 ; always aligned

 ; a 10*7 map = bordered 8*5 map

 ; clear it
 ld hl,tempmap
 ld de,tempmap+1
 ld (hl),0
 ld bc,1319
 ldir

 ld hl,(TILEstart)
 ld de,tempmap

 ld c,7
mapColLoop:

 ld b,10
mapRowLoop:
 push hl
 push bc
 ld a,(hl)
 or a
 jp z,skipSprite2

 ld c,a

 ld hl,sprite-24
 push de
  ld de,24      ; 12 * 2
getMapSprite:
  add hl,de
  dec c
  jr nz,getMapSprite
 pop de
 push de

 ld a,10
 sub b
 ld b,12
 and %1
 jr nz,NonAlignedBlock

alignedBlock:
 push bc
 ld a,(de)
 or (hl)
 ld (de),a

 inc hl
 inc de
 ld a,(de)
 or (hl)
 ld (de),a

 inc hl
 push hl
  ld hl,14
  add hl,de
  ex de,hl
 pop hl
 pop bc
 djnz alignedBlock
 pop de

 jr skipSprite

nonAlignedBlock:
 push bc

 ld a,(hl)
 and %1111
 ld b,a

 xor a
 ld a,(hl)
 sra a
 sra a
 sra a
 sra a
 and %1111
 ld c,a
 ld a,(de)
 or c
 ld (de),a

 inc hl
 inc de

 xor a

 rl b
 rl b
 rl b
 rl b
 ld a,(de)
 or b
 ld (de),a

 xor a
 ld a,(hl)
 rra
 rra
 rra
 rra
 ld b,a
 ld a,(de)
 or b
 ld (de),a

 inc hl
 push hl
  ld hl,14
  add hl,de
  ex de,hl
 pop hl

 pop bc
 djnz nonAlignedBlock
 pop de
 inc de

skipSprite:
 inc de

 pop bc
 pop hl
 inc hl
 djnz mapRowLoop

 push de
  ld de,rows-10
  add hl,de     ; we just added an extra one above
 pop de

 push hl
  ld hl,12*14-3
  add hl,de
  ex de,hl
 pop hl

 dec c
 jp nz,mapColLoop

 ret

skipSprite2:
 ld a,10
 sub b
 and %1
 jr z,skipSprite

 inc de
 jr skipSprite

tempMap: .ds 1320   ; need lots of room for borders



map:
 .db 4,4,0,2,2,0,5,5,0,0,0,4,0,2
 .db 0,0,0,4,0,0,0,0,0,2,0,4,0,2
 .db 4,0,4,0,3,0,0,4,0,2,0,4,0,2
 .db 4,4,4,4,3,3,0,0,0,2,0,4,0,2
 .db 2,0,0,0,3,0,0,4,0,2,0,4,0,2
 .db 2,0,0,0,0,0,0,0,0,2,0,4,0,2
 .db 2,2,2,2,2,2,2,2,2,2,0,4,0,2
 .db 2,0,0,0,3,0,0,4,0,2,0,4,0,2
 .db 2,0,0,0,0,0,0,0,0,2,0,4,0,2
 .db 2,0,0,0,3,0,0,4,0,2,0,4,0,2
 .db 2,0,0,0,0,0,0,0,0,2,0,4,0,2


sprite:
 .db %00000000,%00000000
 .db %00000100,%00000000
 .db %01001010,%00000000
 .db %10100100,%00000000
 .db %01001010,%00000000
 .db %01010101,%00000000
 .db %01010010,%00000000
 .db %00000010,%01000000
 .db %00000100,%10100000
 .db %00001010,%01000000
 .db %00000100,%10000000
 .db %00000100,%10000000

;flowers ***
 .db %00000000,%00000000
 .db %00000100,%00000000
 .db %01001010,%00000000
 .db %10100100,%00000000
 .db %01001010,%00000000
 .db %01010101,%00000000
 .db %01010010,%00000000
 .db %00000010,%01000000
 .db %00000100,%10100000
 .db %00001010,%01000000
 .db %00000100,%10000000
 .db %00000100,%10000000

;desert
 .db %10100000,%00010000
 .db %01000000,%00100000
 .db %10000000,%01010000
 .db %00000000,%00100000
 .db %00000000,%10100000
 .db %00000000,%01010000
 .db %00000001,%10100000
 .db %00000010,%01000000
 .db %00000001,%10000000
 .db %00011010,%01000000
 .db %00010110,%10000000
 .db %10101000,%00000000

;floor
 .db %11111110,%00100000
 .db %10100001,%00000000
 .db %10010100,%11110000
 .db %01001010,%00010000
 .db %01010001,%00010000
 .db %01000000,%00110000
 .db %01001111,%11110000
 .db %00111100,%00100000
 .db %11000100,%10010000
 .db %00010100,%01010000
 .db %01100101,%01010000
 .db %00000100,%10110000

;Cut Grass
 .db 0,0
 .db 0,0
 .db %00010000,%00000000
 .db %01010100,%00000000
 .db %00101000,%00000000
 .db 0,0
 .db 0,0
 .db 0,0
 .db %00000000,%01000000
 .db %00000001,%01010000
 .db %00000000,%10100000
 .db 0,0

;Un-Cut grass
 .db 0,0
 .db %10000010,%00000000
 .db %01001001,%00100000
 .db %01011001,%01100000
 .db %01010001,%01000000
 .db %00010000,%01000000
 .db 0,0
 .db %10000010,%00000000
 .db %01001001,%00100000
 .db %01011001,%01100000
 .db %01010001,%01000000
 .db %00010000,%01000000 


.end
END