;=======================================; ;= COLDFUSION =; ;= Codenamed: Skull =; ;=======================================; ; By Deathsting ;Map size = 50 X 100 = 5000 bytes ;sprite data size = 61(8X8) = 976 .nolist #ifdef VTI #define TI83P #endif #include "keycode.inc" #include "ion.inc" .list #ifdef TI83P .org progstart-2 .db $BB,$6D #else .org progstart #endif ret jr nc,start_of_program .db " ColdFusion 0.0001a",0 ;===================================================== ;= VARIABLES = ;===================================================== TankX = saferam3 ;tank sprite coordinates TankY = saferam3+1 Direction = saferam3+2 ;1-forward,2-Back, 3-left ,4-right, 5- ForwardRight, 6 - forwardLeft, 7- DownRight, 8 - DownLeft MapXCord = saferam3+3 ;Map coordinates MapYCord = saferam3+4 Fire1 = saferam3+5 Fire1X = saferam3+6 Fire1Y = saferam3+7 Fire1D = saferam3+8 Fire2 = saferam3+9 Fire2X = saferam3+10 Fire2Y = saferam3+11 Fire2D = saferam3+12 Fire3 = saferam3+13 Fire3X = saferam3+14 Fire3Y = saferam3+15 Fire3D = saferam3+16 Fire4 = saferam3+17 Fire4X = saferam3+18 Fire4Y = saferam3+19 Fire4D = saferam3+20 Fire5 = saferam3+21 Fire5X = saferam3+22 Fire5Y = saferam3+23 Fire5D = saferam3+24 Fire6 = saferam3+25 Fire6X = saferam3+26 Fire6Y = saferam3+27 Fire6D = saferam3+28 Fire7 = saferam3+29 Fire7X = saferam3+30 Fire7Y = saferam3+31 Fire7D = saferam3+32 Fire8 = saferam3+33 Fire8X = saferam3+34 Fire8Y = saferam3+35 Fire8D = saferam3+36 Fire9 = saferam3+37 Fire9X = saferam3+38 Fire9Y = saferam3+39 Fire9D = saferam3+40 Fire10 = saferam3+41 Fire10X = saferam3+42 Fire10Y = saferam3+43 Fire10D = saferam3+44 SaveSP: .dw 0 #define output(XPOS,YPOS,STRING) ld hl,(XPOS*256)+YPOS \ ld (CURROW),hl \ ld hl,STRING \ bcall(_puts) Mapwidth = 100 ;universal register ;hl = map ;a=direction start_of_program: ;========================================================== ; start of program ;========================================================== call ClearSaferam call gsEnable call gsClearbuffer Start: ld hl,mapdata ld de,200 add hl,de ld (map),hl ; Indicates where exactly you are in the map ld a,5 ld (MapXCord),a ; ld a,5 ld (MapYCord),a ;=======Tank Cordinates of the first tank sprite ld a,5 ld (TankX),a ld a,24 ld (TankY),a ld a,1 ld (direction),a ; ld b,10 push a Mainloop: call drawmap call drawchar call gsCopyBuffer Keypress: ;see keycode.inc ld a,$FF ;resets the keypad. out (1),a ;'Required syntax' ld a,KeyGroup1 ;Enable group 2. out (1),a in a,(1) ;'Required Syntax' cp Kleft ;check if [left] was pressed jp z,Left cp Kright ;check if [right] was pressed jp z,Right cp Kdown jp z,down cp KUp jp z,up ld a,$FF ;resets the keypad. out (1),a ;'Required syntax' ld a,KeyGroup7 ;Enable group 2. out (1),a in a,(1) ;'Required Syntax' cp K2nd jp z,fire cp KDel jp z,quit jr Keypress Fire: ret Right: pop a ld a,4 push a call DetectRight cp 16 ;check tile1 jp nc,Mainloop ld a,l cp 16 ;check tile2 jp nc,Mainloop ld a,(MapXCord) inc a ld (MapXCord),a ld hl,(map) ;moves to next col inc hl ;assuming you organize left to right, top to bottom ld (map),hl jp mainloop DetectRight: ;collision detection ld hl,(map) ;tile 1 ld de,307 add hl,de ;points to the tile ld a,(hl) ; get tile number ; ld a,l ; ld hl,(map) ;Tile 2 ld de,100 add hl,de ;points to the tile ld l,(hl) ; get tile number ;tile 1 in a and tile 2 in l ret Left: ld a,3 ld (direction),a call DetectLeft cp 16 jp nc,Mainloop ld a,l cp 16 ;check tile2 jp nc,Mainloop ld a,(MapXCord) dec a ld (MapXCord),a ld hl,(map) ;moves to next col dec hl ;" " ld (map),hl ;Loads it back to map variable jp mainloop ;Go back DetectLeft: ;collision detection ; ld hl,(map) ;tile 1 ld de,304 add hl,de ;points to the tile ld a,(hl) ; get tile number ; ld a,l ; ld hl,(map) ;Tile 2 ld de,100 add hl,de ;points to the tile ld l,(hl) ; get tile number ;tile 1 in a and tile 2 in l ret Down: ld a,2 ld (direction),a call DetectDown cp 16 ;tile 1 jp nc,Mainloop ld a,l cp 16 ;check tile2 jp nc,Mainloop ld a,(MapYCord) inc a ;increase The map Y cordinate ld (MapYCord),a ;increase The map Y cordinate ;Move the map pointer ld hl,(map) ld de,Mapwidth ;move to next row add hl,de ;" " ld (map),hl ;Loads it back to map variable jp mainloop DetectDown: ;collision detection ld hl,(map) ;tile 1 ld de,505 add hl,de ;points to the tile ld a,(hl) ; get tile number ; ld a,l ; ld hl,(map) ;Tile 2 inc hl ; add hl,de ;points to the tile ld l,(hl) ; get tile number ;tile 1 in a and tile 2 in l ret Up: ld a,1 ;change direction ld (direction),a call DetectUp cp 16 ;tile 1 jp nc,Mainloop ld a,l cp 16 ;check tile2 jp nc,Mainloop ld a,(MapYCord) dec a ld (MapYCord),a ;Move the map pointer ld hl,(map) ld de,-100 ;move to next row add hl,de ;" " ld (map),hl ;Loads it back to map variable jp mainloop DetectUp: ;collision detection ld hl,(map) ;tile 1 ld de,205 add hl,de ;points to the tile ld a,(hl) ; get tile number ; ld a,l ; ld hl,(map) ;Tile 2 inc hl ; add hl,de ;points to the tile ld l,(hl) ; get tile number ;tile 1 in a and tile 2 in l ret ClearSaferam: di ld (SaveSP), SP ld SP,saferam3+127 ; 128 byte area ld hl,$0000 ld B,16 ; PUSH 16*4=64 times, @ 2 bytes a PUSH = 128 bytes ClearSaferamLoop: push hl ; Do multiple PUSHes in the loop to save cycles push hl push hl push hl djnz ClearSaferamLoop ld SP, (SaveSP) ei ret DrawMap: ld de,0 ; e = x, d = y ld b,8 ;8 rows per screen ; ld hl,(map) DrawMapLoop: push hl ; save map pointer push de ; save tile coords ld l,(hl) ; get tile number ld h,0 ; clear upper byte add hl,hl add hl,hl add hl,hl add hl,hl ; hl = tile number * 16 (as each tile occupies 16 bytes) ld bc,TileData ; tiledata add hl,bc ; offsett tiledata to point to correct tile push hl ; push hl pop ix ; pop in ix ld a,e ; tile x ld l,d ; tile y call gsALIGNEDSPRITE ; draw tile pop de ; restore tile coords pop hl ; restore map pointer inc hl ; increase to next tile number inc e ; increase tile x coord ld a,e ; we can only test a cp 12 ; test if 12 (we only want to draw in cols 0-11) jp nz,DrawMapLoop ; if it isnt 12, continue drawing the row ld bc,mapWIDTH-12 ;here ;offset add hl,bc ;next row ld e,0 ; if at the end of a row, rester x coord ld a,8 ; we want to move 8 pixels down add a,d ; increase y coord by 8 ld d,a ; store back in d (y coord) cp 64 ; test if its at the bottom of the screen jp nz,DrawMapLoop ; if not then continue drawing until it is ret ; otherwise we are all done Drawchar: ;Draws the tank also refered to as char ld a,(tankX) ld h,a ld a,(tankY) ld l,a ;Checks direction ld a,(direction) cp 1 call z,SpriteUp cp 2 call z,SpriteDown cp 3 call z,SpriteRight cp 4 call z,SpriteLeft ;====Display Sprites ; ___________________ ; | | | ; | 1 | 2 | ; |_________|________ | ; | | | ; | 3 | 4 | ; |_________|________| ;H = X L=Y A= Sprite number De = Sprite xor a ;1st sprite call DispGSAlignSprite ;==============First Sprite ld a,l ;inc l by eight add a,8 ; " ld l,a ; " ld a,2 ;3rd Sprite call DispGSAlignSprite ;=============Third Sprite ld a,h inc a ld h,a ld a,3 ;4th Sprite call DispGSAlignSprite ;==============4th Sprite ld a,l add a,-8 ld l,a ld a,1 ;===============2nd sprite call GsAlignedMaskedsprite ret SpriteUp: ld de,tankUp ret SpriteDown: ld de,tankDown ret SpriteRight: ld de,tankRight ret SpriteLeft: ld de,tankLeft ret DispGSAlignSprite: push hl push de call GsAlignedMaskedsprite pop de pop hl ret ;========================================================== ; Math routines ;========================================================== ;========================================================== ;Tile data ;========================================================== #include "tankdata.z80" #include "tileData.z80" #include "mapdata.inc" map .dw 0 quit: call gsDisable ret ;========================================================== ; grayscale include file ;========================================================== ; comment these defines in or out to activate/deactivate them ;#DEFINE NODOUBLEBUFFER ;when on,routines write directly to screen (faster and smaller) ;#DEFINE 3LEVELGRAY ;makes it 3-level grayscale (a bit faster) ;#DEFINE XORSPRITE ;includes gsPutSprite ;#DEFINE LARGESPRITE ;includes gsLargeSprite #DEFINE ALIGNEDSPRITE ;includes gsAlignedsprite #define FASTER #define CONTRASTCTRL #define REVERSEMASK #DEFINE ALIGNEDMASKEDSPRITE #DEFINE VTI #include graylib.inc .end END