.nolist #include "ion.inc" ;altered so I don't have to redefine equates #include "ti83plus.inc" ;altered to be compatible with tasm not zilog .list .org progstart-2 .db $BB,$6D xor a jr nc,Start .db "physics",0 NUM_TILES = 24 IntMode = 0 IntSpeed = 1620 / ( 3 + ( Intmode << 2 ) ) .echo "INterrutps: ",IntSpeed FrameRate = 40 FrameSQ = FrameRate*FrameRate DecBit = 5 Decimal = 1<0 srl h rr l #endif #if decbit>1 srl h rr l #endif #if decbit>2 srl h rr l #endif #if decbit>3 srl h rr l #endif #if decbit>4 srl h rr l #endif #if decbit>5 srl h rr l #endif #if decbit>6 srl h rr l #endif #if decbit>7 srl h rr l #endif ret Div8: srl h rr l srl h rr l srl h rr l ret Multdec: #if decbit>0 sla l rl h #endif #if decbit>1 sla l rl h #endif #if decbit>2 sla l rl h #endif #if decbit>3 sla l rl h #endif #if decbit>4 sla l rl h #endif #if decbit>5 sla l rl h #endif #if decbit>6 sla l rl h #endif #if decbit>7 sla l rl h #endif ret Mult8: sla l rl h sla l rl h sla l rl h ret cphlde: push hl or a sbc hl,de pop hl ret cpabshlde: push hl bit 7,h call nz,neghl or a sbc hl,de pop hl ret neghl: push af ld a,h cpl ld h,a ld a,l cpl ld l,a inc hl pop af ret ;HLnodec: ; push bc ; ld b,8-decbit ; inc b ; dec b ; jr z,doneHLnodec ;decloop: ; rl l ; rl h ; djnz decloop ;doneHLnodec: ; pop bc ; ret DRAW: ld hl,(playerx) call divdec ld de,48 or a sbc hl,de jr nc,nzviewx ld hl,0 nzviewx: push hl ld hl,(mapwidth) call mult8 ld de,96 sbc hl,de ex de,hl pop hl call cphlde jr c,nmviewx ex de,hl nmviewx: ld (viewx),hl ld hl,(playery) call divdec ld de,32 or a sbc hl,de jr nc,nzviewy ld hl,0 nzviewy: push hl ld hl,(maphieght) call mult8 ld de,64 sbc hl,de ex de,hl pop hl call cphlde jr c,nmviewy ex de,hl nmviewy: ld (viewy),hl call Fastmap drawball: ld hl,(playerx) ld de,(viewx) or a rl e rl d rl e rl d rl e rl d rl e rl d rl e rl d or a sbc hl,de call mult8 ld a,h cp 96-7 ret nc ld c,a ld hl,(playery) ld de,(viewy) or a rl e rl d rl e rl d rl e rl d rl e rl d rl e rl d or a sbc hl,de call mult8 ld a,h cp 64-7 ret nc ld l,a ld a,c ld ix,ball ld b,8 jp ionputsprite IntOn: di ld hl,$8b00 ld (hl),$8a ld de,$8b01 ld bc,256 ldir ld a,$8b ld i,a ld hl,$8a8a ld de,interrupt ld (hl),$c3 inc hl ld (hl),e inc hl ld (hl),d ld a,IntMode<<1 out (4),a ;set frequency ld a,8 out (3),a ;resets any waiting interrupts ld a,10 out (3),a ;resets any waiting interrupts im 2 ei ret Interrupt: push af push hl push de ld hl,(timer) ld de,0+(256*FrameRate)/IntSpeed add hl,de ld (timer),hl ld a,IntMode<<1 out (4),a ;set frequency ld a,8 out (3),a ;resets any waiting interrupts ld a,10 out (3),a ;sets the normal interrupt timer pop de pop hl pop af ei reti IntOff: di ld a,6 out (4),a ;set frequency ld a,8 out (3),a ;resets any waiting interrupts ld a,11 out (3),a ;sets the normal interrupt timer im 1 ei ret ;################################################################################### ;Fastcopy + Horizontal + Vertical Scrolling Tilemap by Jim e ;Based on dwedit's mapper ;Messuptiles is 50% faster ;The mapper is 14% faster. ;Like it needed to be faster ;) ; ; ;Input: ; de = plotsscreen ; (Mapaddress) = word,Base address of map ; (viewY) = word,vertical location of camera ; (viewX) = word,horizontal location of camera ; (tilesAdress) = word,pointer to tileset ; tilesbuf = label,destructable tileset buffer equal in size to the tileset ; tilesbuf2 = label,another destructable tileset buffer, also equal in size to the tileset ; NUM_TILES = byte constant,number of tiles in the tileset (size of tileset/8) ; (mapWidth) = word,width of tilemap ; ;Output: ; screen copied from buffer to screen ; tilemap drawn on buffer, with origin (viewX,viewY) ; ;Destroys: ; AF BC DE HL IX ; AF' BC' DE' HL' ; ; ;Notes: ;The current version has it so that the viewY Can not be greater than 2047. ;If your map is longer on the y than the x, read the mapwidth with A and ;viewY with DE. ;If you are using maps of multiple sizes(longer on X or Y) than you may need ;a 16bit times 16bit multiplication routine to accomodate. ; ;BIG NOTE: ;This routine copies the previous buffer to the screen. ;You should update the screen at a steady rate for this method of mapping. Fastmap: ld de,gbuf push de ;===================================== ;Rotate the tiles into the buffer ;===================================== call Messuptiles ;===================================== ;Set write to top row of LCD ;===================================== ld a,$80 out ($10),a ;===================================== ;Calculate the Y offset to map ;===================================== ld de,(viewY) ld a,e srl d rra srl d rra srl d rra ;;; ld e,a ld de,(mapWidth) call mult ;you may want to change this ;===================================== ;Add the X offset ;===================================== ld de,(viewx) ld a,e srl d rra srl d rra srl d rra ld e,a add hl,de ex de,hl ;===================================== ;add the map address to get pointer ;===================================== ld ix,(Mapaddress) add ix,de ;===================================== ;Calculate clipping for the top row ;===================================== ld a,(viewY) and 7 ld (cliptoptile1),a ld (cliptoptile2),a ld c,a add a,a add a,a ld b,a add a,b add a,b sub c ld e,a ld d,0 ld hl,Rendertile add hl,de ld (Rendertopmod),hl ;===================================== ;Calculate clipping for bottom row ;===================================== ld a,8 sub c ld c,a add a,a add a,a ld b,a add a,b add a,b sub c ld e,a ld d,0 ld hl,Rendertile add hl,de ld (Renderbotmod),hl ;===================================== ;Prepare for main loop ;===================================== pop hl ld a,$20 ld bc,12 ld de,(mapwidth) exx ld c,0 ;========================================================== ;========================================================== TilemapCol: ;===================================== ;Set the column to write to on LCD ;===================================== out ($10),a ;set col ex af,af' push ix ;===================================== ;Find one side of tile and add clipping ;===================================== ld l,(ix) ld h,c add hl,hl add hl,hl add hl,hl ld de,tilesbuf add hl,de cliptoptile1 = $+1 ld de,0 add hl,de push hl ; ld a,$80 ;This could reduce chance of wavy effect but isn't needed. ; out ($10),a ;Could be used for SEs at 15mhz with minor changes. ;===================================== ;Find one side of tile and add clipping ;===================================== ld l,(ix+1) ld h,c add hl,hl add hl,hl add hl,hl ld de,tilesbuf2 add hl,de cliptoptile2 = $+1 ld de,0 add hl,de pop de ;===================================== ;Render clipped ;===================================== exx Rendertopmod = $+1 call Rendertile add ix,de exx ;===================================== ;Row loop, No clipping ;===================================== ld b,7 ;------------------------------------------------- ;------------------------------------------------- TileMapMid: ;===================================== ;Find one side of tile ;===================================== ld l,(ix) ld h,c add hl,hl add hl,hl add hl,hl ld de,tilesbuf add hl,de push hl ;===================================== ;Find one side of tile ;===================================== ld l,(ix+1) ld h,c add hl,hl add hl,hl add hl,hl ld de,tilesbuf2 add hl,de pop de ;===================================== ;Render tile then loop ;===================================== exx call Rendertile add ix,de exx djnz TileMapMid ;------------------------------------------------- ;------------------------------------------------- ;===================================== ;Find one side of tile ;===================================== ld l,(ix) ld h,c add hl,hl add hl,hl add hl,hl ld de,tilesbuf add hl,de push hl ;===================================== ;Find one side of tile ;===================================== ld l,(ix+1) ld h,c add hl,hl add hl,hl add hl,hl ld de,tilesbuf2 add hl,de pop de ;===================================== ;Render clipped ;===================================== exx Renderbotmod = $+1 call Rendertile add ix,de dec h dec h dec h inc hl exx pop ix inc ix ;===================================== ;Loop for all Columns ;===================================== ex af,af' inc a cp $2c jp nz,TilemapCol ;=================================================================== ;=================================================================== ret ;===================================== ;Renders rotated tiles to the screen ;===================================== ;Read byte from buffer ;write to lcd ;read rotated tile ;OR other rotated tile ;write to buffer ;===================================== Rendertile: ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ld a,(hl) out ($11),a exx ld a,(de) or (hl) inc hl inc de exx ld (hl),a add hl,bc ret ;############################################################ ;Mess up tiles is a routine in itself. If you have less than ;117 tiles this is very fast compared to other mappers. ;If you have more, Than a more imaginative routine may be ;required. I'll finish that at a later date. ; ;You should know this routine may use the majority of the ;drawing time. ; ;Tstate Comparison (lower numbers mean better performance) ;------------------------------------------------ ; ; Jim e's ; Dwedit's ; ;------------------------------------------------ ;Overhead ; 991 ; 149 ; ;------------------------------------------------ ;Per tile ; 646 ; ~1032 ; ;------------------------------------------------ ;10 tiles ; 7451 ; ~10469 ; ;------------------------------------------------ ;64 tiles ; 42335 ; ~66197 ; ;------------------------------------------------ ;128 tiles ; 83679 ; ~132245 ; ;------------------------------------------------ ;MAX 256 ; 166367 ; ~264341 ; ;------------------------------------------------ ;===================================== ;Rotates the tiles to two different ;buffers. ;===================================== Messuptiles: ld a,(viewx) call Findrotation ld de,Rotatewhat1 push hl ldi ldi ldi ldi pop hl ld de,Rotatewhat2 push hl ldi ldi ldi ldi pop hl ld de,Rotatewhat3 push hl ldi ldi ldi ldi pop hl ld de,Rotatewhat4 push hl ldi ldi ldi ldi pop hl ld de,Rotatewhat5 push hl ldi ldi ldi ldi pop hl ld de,Rotatewhat6 push hl ldi ldi ldi ldi pop hl ld de,Rotatewhat7 push hl ldi ldi ldi ldi pop hl ld de,Rotatewhat8 push hl ldi ldi ldi ldi pop hl ld de,tilesbuf ld c,a exx ld hl,(tilesAdress) ld de,tilesbuf2 cpl ld c,a ld b,NUM_TILES messtiles: ld a,(hl) inc hl Rotatewhat1: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de ld a,(hl) inc hl Rotatewhat2: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de ld a,(hl) inc hl Rotatewhat3: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de ld a,(hl) inc hl Rotatewhat4: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de ld a,(hl) inc hl Rotatewhat5: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de ld a,(hl) inc hl Rotatewhat6: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de ld a,(hl) inc hl Rotatewhat7: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de ld a,(hl) inc hl Rotatewhat8: nop nop nop nop exx ld h,a and c ld (de),a inc de ld a,h exx and c ld (de),a inc de dec b jp nz,messtiles ret ;===================================== ;This gives 4 opcodes to rotate a tile ;to any position, and the mask ;===================================== Findrotation: and 7 ld hl,lsn bit 2,a jp z,notmsn ld hl,msn notmsn: ld c,a res 2,c ld b,0 add hl,bc push hl ld c,a ld hl,masks add hl,bc ld a,(hl) pop hl ret MSN: rrca rrca rrca rrca LSN: nop nop nop nop rlca rlca rlca rlca Masks: .db %11111111 .db %11111110 .db %11111100 .db %11111000 .db %11110000 .db %11100000 .db %11000000 .db %10000000 ;########################################################### ;Note: this routine may be removed, depending on your needs ;recommend find the most optimised way of multiply you can. ;This method is general and could be better. ;===================================== ;AxDE = AHL ;this can be changed to whatever you ;may need ;===================================== Mult: ld hl,0 rla jp nc,$+4 add hl,de add hl,hl rla jp nc,$+4 add hl,de add hl,hl rla jp nc,$+4 add hl,de add hl,hl rla jp nc,$+4 add hl,de add hl,hl rla jp nc,$+4 add hl,de add hl,hl rla jp nc,$+4 add hl,de add hl,hl rla jp nc,$+4 add hl,de add hl,hl rla ret nc add hl,de ret Ball: .db $3C,$7E,$FF,$FF,$FF,$FF,$7E,$3C Dirleft: ;left right .db 0,1,2,4,5,6,7,0,2,0,4,5,0,0,0,0,0,0 DirRight: .db 0,1,2,4,5,6,7,0,0,3,0,0,6,7,0,0,0,0 Dirup: .db 0,1,2,4,5,6,7,0,0,0,0,0,0,0,0,0,0,0 Dirdown: .db 0,1,2,4,5,6,7,1,2,3,4,5,6,7,1,1,0,0 #include "map.asm" ;altered so I don't have to redefine equates tilestart: #include "tile.asm" ;altered to be compatible with tasm not zilog Tileend: tilesbuf: .block NUM_TILES*8 tilesbuf2: .block NUM_TILES*8 .end