[Ti-ASM] My ASM Projects so far

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

User avatar
tr1p1ea
Maxcoderz Staff
Posts: 4141
Joined: Thu 16 Dec, 2004 10:06 pm
Location: I cant seem to get out of this cryogenic chamber!
Contact:

Post by tr1p1ea »

It can be bad when you chain them though as a call will return and if you dont preseve the flags, random stuff could happen.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
Liazon
Calc Guru
Posts: 962
Joined: Thu 27 Oct, 2005 8:28 pm

Post by Liazon »

that's why i did ld a,4 before every ret

edit: oh ya, what's the difference between an App and a Program? Are they both written in ASM?
Image Image Image
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

They are, but an APP is run from archive (or a page of ram, can't remember) and has to be written differently. To exit from the program, you have to use bjump(_JForceCmdNoChar) instead of ret to exit the program. Theres other wierd things like that you have to do. Also, you hve to sign it, which I don't know what it means or does.

And tr1p1ea, you don't think I pointed that out to him??? :(
Image
Liazon
Calc Guru
Posts: 962
Joined: Thu 27 Oct, 2005 8:28 pm

Post by Liazon »

Okay, I need help again, I'm sry I'm sry. I thought for sure I could write this entirely on my own. The jumping routine that made the player's sprite move and jump was working fine until I added the box Respawning/Drawing code. I must have accidentally created an infinite loop but I don't see it. Nothing appears on the screen btw.

Code: Select all

.nolist
#include ion.inc
.list

#ifdef TI83P
    .org progstart-2
    .db $BB,$6D
#else
    .org progstart
#endif
     ret
     jr nc,lblStart

    .db "Get the Presents",0
;_________________________________
;
;I use jp instead of jr most of the time because I think jp may take up more RAM,
;but it is much faster.
;_________________________________
lblstart:
 bcall(_indicatorOff)
 bcall(_ClrLCDFull)
 ld b,40
 ld c,4
 ld a,4
 ld l,a
 ld ix,titlesprite
 call ionLargeSprite
 call ionFastCopy
 ld hl,0523h
 ld (penCol),hl
 ld hl,TitleString
 bcall(_vPutS)
 ld hl,3700h
 ld (penCol),hl
 ld hl,MyNombre
 bcall(_vPutS)
 bcall(_getkey)
 cp 009h
 jp z,iquit
;___________________________________
;
;Loads starting values into correct "permanent" variables.
;___________________________________
 xor a
 ld (yourpos),a
 ld b,a
 ld a,52
 ld (yourpos+1),a
 ld a,57
 ld hl,(boxlocationy)
BoxLoadLoop:			;Loop to repeat loading process for all 12 boxes.
 ld (hl),a
 inc hl
 inc b
 cp 11
 jr nz,BoxLoadLoop
BiggameLoop:
;___________________________
;
;Box Respawner
;
;hl is preloaded with the first memory location before entering loop
;e is the loop counter
;a=miscellaneous temporary values
;b=ionRandom ceiling range
;d=temporary holder of data at memmory location
;___________________________
 ld hl,boxlocationy
 ld e,12
 push de
 push hl
GenerationLoop
 pop hl
 ld a,(hl)
 cp 57
 jp nz,Falling
 ld d,a
 ld b,5
 push hl
 call ionRandom
 cp 0
 jp nz,GenerationLoop2
 ld a,8
 ld (boxlocationy),a
GenerationLoop2:
 
 inc hl
 dec e
 ld a,e
 cp 0
 jp nz,GenerationLoop
 bcall(_GrBufCLr)
;______________________________
;
;Drawing Code
;
;  Pushes starting numbers for ionPutSprite
;  Onto the stack to allow for change and reuse
;______________________________
 ld a,0
 push af
 ld hl,boxlocationy
 push hl
 ld b,8
 ld c,12
 push bc
;_____________________________________
;
;Actual Loop that repeats to draw all 12 boxes
;
;b=sprite height (8), c=counter
;a=sprite x position, l=sprite y position, hl/de=memmory address
;_____________________________________
BoxDrawLoop:
 pop bc
 pop hl 
 ld a,(hl)
 ld d,h
 ld e,l
 ld l,a
 cp 57			;Checks if that box should even be on the screen.
 jp z,Skip		;If it should be, it skips over ionPutSprite
 pop af
 push af
 push de
 push bc
 ld ix,boxsprite
 call ionPutSprite
 jp Continue		;After successfully drawing the sprite to buffer
Skip:			;Continue will update variables for next box. 
 push de
 push bc
Continue:
 pop bc
 dec c
 cp 0
 jp z,YourDraw
 pop hl
 inc hl
 pop af
 add a,b
 push af
 push hl
 push bc
 jp BoxDrawLoop
 
YourDraw:
 pop hl
 pop af
 ld b,12
 ld a,(yourpos+1)
 ld l,a
 ld a,(yourpos)
 ld ix,yoursprite
 call ionPutSprite
 call ionFastCopy
;__________________________
;
;Direct Input Code
;__________________________
YouMove:
 ld a,$BF
 out (1),a
 in a,(1)
 cp $DF
 call z,JUMP
 cp $7F
 jp z,iquit
 ld a,$FE
 out (1),a
 in a,(1)
 cp $FD
 call z,LEFT
 cp $FB
 call z,RIGHT
 ld a,(yourpos+1)
 cp 52
 jp z,BiggameLoop	;lowers altitude unless sprite is already on ground.
 inc a
 ld (yourpos+1),a
 jp BiggameLoop
;_________________________________
;
;Controls vertical movement JUMPING!!
;_________________________________
JUMP:
 ld a,(yourpos+1)
 cp 52			;initial y position is 52 because of 8x12 dimension.
 ret nz
 ld a,36
 ld (yourpos+1),a
 ld a,4
 ret
;_______________________________________
;
;Updates sprite position and checks if new position is valid.
;_______________________________________
LEFT:
 ld a,(yourpos)
 cp 0
 ret z
 dec a
 ld (yourpos),a
 ld a,4
 ret
RIGHT:
 ld a,(yourpos)
 cp 87
 ret z
 inc a
 ld (yourpos),a
 ld a,4
 ret
;___________________________
;
;Controls falling (rate) of boxes.
;___________________________
Falling:
 ld a,(hl)
 inc a
 ld (hl),a
 jp GenerationLoop2
;__________________________________
;
;Quit Code
;__________________________________
iquit:
 bcall(_indicatorOn)
 bcall(_ClrLCDFull)
 ret
;_________________________________________________
;
;Sprite Data, Variable Data, String Data
;_________________________________________________
yourpos:
 .db 0,52
yoursprite:
 .db %00010001
 .db %10111011
 .db %11111110
 .db %01111110
 .db %00111010
 .db %00111000
 .db %00101000
 .db %11111111
 .db %10011001
 .db %00011000
 .db %00100100
 .db %11100111
boxsprite:
 .db %00100100
 .db %01011010
 .db %00111100
 .db %01100110
 .db %01111110
 .db %01111110
 .db %01111110
 .db %01111110
boxlocationy:
 .db 57,57,57,57,57,57
 .db 57,57,57,57,57,57
TitleString:
 .db "Get the Presents!",0
Opt1:
 .db "Start",0
Opt2:
 .db "HiScores",0
Opt3:
 .db "Quit",0
MyNombre:
 .db "by Jason Lee 2005",0
HighestScores:
 .dw 0
 .dw 0
 .dw 0

titlesprite:
 .db %00011110	;row 1
 .db %00000000	
 .db %00000000	
 .db %00000000	

 .db %00111011	;row 2
 .db %10000000
 .db %00000000
 .db %00000000

 .db %01100000	;row 3
 .db %10000000
 .db %00000000
 .db %00000000

 .db %01000000	;row 4
 .db %00000000
 .db %00000000
 .db %00000000

 .db %01000000	;row 5
 .db %10000000
 .db %00000000	
 .db %00000000	

 .db %01100000	;row 6
 .db %10000000
 .db %00000000
 .db %00000000

 .db %00110111	;row 7
 .db %11100000
 .db %00000000
 .db %00000000

 .db %00011111	;row 8
 .db %11111110
 .db %00000000
 .db %00000000

 .db %00011111	;row 9
 .db %11111111	
 .db %00000000	
 .db %00000000	

 .db %00111111	;row 10
 .db %11111111
 .db %11000000
 .db %00000000

 .db %00111111	;row 11
 .db %11111111
 .db %11100000
 .db %00000000

 .db %01111111	;row 12
 .db %11111111
 .db %11100000
 .db %00000000

 .db %01111111	;row 13
 .db %11111111
 .db %11110000
 .db %00000000

 .db %11111111	;row 14
 .db %11111111
 .db %11110000
 .db %00000000

 .db %11111111	;row 15
 .db %11111111
 .db %11110000
 .db %00000000

 .db %11111111	;row 16
 .db %11111111
 .db %11111000
 .db %00000000

 .db %11111111	;row 17
 .db %11111111
 .db %11111000
 .db %00000000

 .db %11111111	;row 18
 .db %11111111
 .db %11111110
 .db %00000000

 .db %11111111	;row 19
 .db %11111111
 .db %11111111
 .db %00000000

 .db %11111111	;row 20
 .db %11111111
 .db %11111111
 .db %01110000

 .db %01111111	;row 21
 .db %11111111
 .db %11111111
 .db %11010000

 .db %00111111	;row 22
 .db %11111111
 .db %11111111
 .db %00011000

 .db %00011111	;row 23
 .db %11111111
 .db %11111100
 .db %00001100

 .db %00011111	;row 24
 .db %11111111
 .db %11111100
 .db %00000100

 .db %00001111	;row 25
 .db %11111111
 .db %11110000
 .db %00000100

 .db %00001111	;row 26
 .db %11111111
 .db %11100000
 .db %00000100

 .db %00011111	;row 27
 .db %11111111
 .db %11000000
 .db %00001100

 .db %00011111	;row 28
 .db %11111111
 .db %10000000
 .db %00001000

 .db %00111111	;row 29
 .db %11111100
 .db %00000000
 .db %00011000

 .db %00111110	;row 30
 .db %00000000
 .db %00000000
 .db %00110000

 .db %00111000	;row 31
 .db %00000000
 .db %00000000
 .db %01100000

 .db %11100000	;row 32
 .db %00000000
 .db %00000001
 .db %11000000

 .db %10000000	;row 33
 .db %00000000	
 .db %00001111	
 .db %00000000	

 .db %10000000	;row 34
 .db %00000000
 .db %00111000
 .db %00000000

 .db %10000000	;row 35
 .db %00000000
 .db %01000000
 .db %00000000

 .db %11000000	;row36
 .db %00000000
 .db %11000000
 .db %00000000

 .db %01000000	;row 37
 .db %00000001
 .db %10000000
 .db %00000000

 .db %01000000	;row 38
 .db %00000011
 .db %00000000
 .db %00000000

 .db %01100000	;row 39
 .db %11111110
 .db %00000000
 .db %00000000

 .db %00111111	;row 40
 .db %10000000
 .db %00000000
 .db %00000000

.end
END
Thanks!
Image Image Image
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

I think the problem is here:

Code: Select all

Continue: 
 pop bc 
 dec c 
 cp 0
You say in the comments (nice comments, by the way) that c is your counter. However, cp compares a to the number following (in this case 0). You can't compare c to a number, you can only compare a to w/e. So to compare c to 0, do this:

Code: Select all

 push af          ;if you need to preserve af
 ld a,0
 cp 0
 pop af
 jp z,YourDraw
Otherwise, you are just staying in the loop until a is 0.

On a side note, that's a lot of stackwork there. Follow through that a couple of times to make sure there isn't a stack issue. Using PindurTI's debugger can help you keep track of the stack, register values, and program counter. Open the debugger with F10 and go through each line of code one at a time with F7 (I think).
Image
Liazon
Calc Guru
Posts: 962
Joined: Thu 27 Oct, 2005 8:28 pm

Post by Liazon »

wow, I haven't coded ASM in so long. Right now I'm debating over whether I want to revive DEM as an 83+ project instead. Man! I'll have to relearn ASM all over again. Either way, I need to know how to update Brass in the current version of Latenite (4.xx?) and incorporate Jim e's Greyscale Package into my projects.

I'm still debating whether I want to go back to ASM because atm I really want to learn Java but I'm so pressed with time I barely have time to learn how to program 68k with TIGCC. I still have a lot to do before I can make any calc games, though I think if I had a solid 3 hrs of time, I'll finish the battle engine and isometric mapper for the 68k game.

Should I learn Java and perhaps make a Java RPG, or should I revive Deus Ex Mortalis (title will probably change) as a z80 ASM project?
Image Image Image
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

threefingeredguy wrote:I think the problem is here:

Code: Select all

Continue: 
 pop bc 
 dec c 
 cp 0
You say in the comments (nice comments, by the way) that c is your counter. However, cp compares a to the number following (in this case 0). You can't compare c to a number, you can only compare a to w/e. So to compare c to 0, do this:

Code: Select all

 push af          ;if you need to preserve af
 ld a,0
 cp 0
 pop af
 jp z,YourDraw
Otherwise, you are just staying in the loop until a is 0.

On a side note, that's a lot of stackwork there. Follow through that a couple of times to make sure there isn't a stack issue. Using PindurTI's debugger can help you keep track of the stack, register values, and program counter. Open the debugger with F10 and go through each line of code one at a time with F7 (I think).
"dec c" updates the zero flag already, so there's no need to retest the value of register c.
You know your hexadecimal output routine is broken when it displays the character 'G'.
Post Reply