[TI ASM] Displaying random text

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

That_One_Guy
New Member
Posts: 65
Joined: Sun 03 Apr, 2005 7:55 pm
Location: The seventh circle of Hell.
Contact:

[TI ASM] Displaying random text

Post by That_One_Guy »

I need to know the equivelant of
RandInt(1,5)->A
If A=1
Disp "blah"
If A=2
...
in ASM...can anyone help me? I'm planning on porting my KillBot game from BASIC to Asm
Truly great madness cannot be achieved without significant intelligence.

http://www.xanga.com/jakku_kun, rants by me.
Gambit
Sir Posts-A-Lot
Posts: 252
Joined: Mon 21 Feb, 2005 5:34 am
Location: Laveen, Arizona

Post by Gambit »

Code: Select all

If A=1
Assuming that there's a random # in register a, use the opcode 'cp':

Code: Select all

cp $01
A cp is a "virtual" subtraction that doesn't actually subtract, all it does is affect the flags. So if register a was indeed a one, the zero flag would be set, and you would jump/call a routine that displays it. The cool thing with assembly is that you can display your text anywhere with _PutS and curRow/curCol... I'm not making much sense, am I? :| First off, do you know what flags are and registers and so forth? 'Cause that's what you need to know to do this.

As to random #s, I'm too lazy to explain at the moment (there are many ways to get one, the question is how much "randomness" you want in it).
"If SOURCE is outlawed, only outlaws will have SOURCE."
That_One_Guy
New Member
Posts: 65
Joined: Sun 03 Apr, 2005 7:55 pm
Location: The seventh circle of Hell.
Contact:

Post by That_One_Guy »

I only need to display about 16 bits of text for the bots "attacks".go to ticalc.org and download Killbot, and look at the source for KILLBOT1 to see what I mean.
Truly great madness cannot be achieved without significant intelligence.

http://www.xanga.com/jakku_kun, rants by me.
User avatar
Shadow Phoenix
Calc Guru
Posts: 835
Joined: Mon 03 Jan, 2005 7:54 pm
Location: out there. seriosly.

Post by Shadow Phoenix »

If you are using Ion/Mirage :

Code: Select all

ld b,4                ;From 0--->4    b=upper boundy 
ionRandom        ; outputs a random number between zero (0) and a number                                                      ld b,1                ;you load into register b
add a,b             ;But you want 1---> 5 so we add one to a 
cp 1
jp z, DisplayWhatHappensIfRandomIs1
cp 2
jp z, DisplayWhatHappensIfRandomIs2


Life is getting better.
koolmansam375
Extreme Poster
Posts: 479
Joined: Fri 17 Dec, 2004 11:09 pm
Contact:

Post by koolmansam375 »

Code: Select all

ld b,4                ;From 0--->4    b=upper boundy 
ionRandom        ; outputs a random number between zero (0) and a number                                                      
inc a           ;But you want 1---> 5 so we add one to a 
cp 1
jp z, DisplayWhatHappensIfRandomIs1
cp 2
jp z, DisplayWhatHappensIfRandomIs2
:D Its better now but if you want it even smaller and faster (and can deal with 0-4 being equal to 1-5):

Code: Select all

ld b,4                ;From 0--->4    b=upper boundy 
ionRandom        ; outputs a random number between zero (0) and a number                                                      
or a
jp z, DisplayWhatHappensIfRandomIs1
cp 1
jp z, DisplayWhatHappensIfRandomIs2
Image

Pongwars shall live!

blog is down atm. :-(
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

This code works for any number of strings, just change the table and the random range from 8.

Code: Select all

	ld b,8
	call ionrandom
	ld h,0
	ld l,a
	add hl,hl
	ld bc,stringtable
	add hl,bc
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	bcall(_puts)

...

StringTable:
	.dw String1
	.dw String2
	.dw String3
	.dw String4
	.dw String5
	.dw String6
	.dw String7
	.dw String8

String1: .db "This is string 1!",0
String2: .db "This is string 2!",0
String3: .db "This is string 3!",0
String4: .db "This is string 4!",0
String5: .db "This is string 5!",0
String6: .db "This is string 6!",0
String7: .db "This is string 7!",0
String8: .db "This is string 8!",0
You know your hexadecimal output routine is broken when it displays the character 'G'.
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 »

I was just about to post an identical example. Using tables is a much better way to code. It will save you a lot of time and space.
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."
Image
Image
That_One_Guy
New Member
Posts: 65
Joined: Sun 03 Apr, 2005 7:55 pm
Location: The seventh circle of Hell.
Contact:

Post by That_One_Guy »

Could you break that code down and explain the bits? Otherwise i wouldnt be learning anything, just copying what others did. Plus, i dunno how to use the ion routines or anything :puzzled:
Truly great madness cannot be achieved without significant intelligence.

http://www.xanga.com/jakku_kun, rants by me.
User avatar
Dwedit
Maxcoderz Staff
Posts: 579
Joined: Wed 15 Dec, 2004 6:06 am
Location: Chicago!
Contact:

Post by Dwedit »

Code: Select all

   ld b,8
   call ionrandom
This uses ionrandom to generate a random number in the range [0...7]. If you want to see the code for ionrandom itself, look in ionf.z80, which comes with ion. The random number gets stored into register A.

Then the code uses A as an index into the string table.

Code: Select all

   ld h,0
   ld l,a
HL = A

Code: Select all

   add hl,hl
Multiplies HL by 2, since pointers are 2 bytes long.

Code: Select all

   ld bc,stringtable
   add hl,bc
Loads the address of the first table entry into BC, then adds the offset to get the address of the pointer.

Code: Select all

   ld a,(hl)
   inc hl
   ld h,(hl)
   ld l,a
Loads the contents of the table (the string's address) into HL. It has a little optimization which overwrites the no-longer-necessary H instead of using an extra register.

Code: Select all

   bcall(_puts)
This is just any text display routine that takes in HL for the string to display. Doesn't have to be _puts, it could be vputs, or even a custom text displayer.

...

The string table contains a bunch of .dw's. .dw defines a 16-bit (2 byte) word, such as an Address. The string table contains a bunch of addresses of each text string.

Code: Select all

StringTable:
   .dw String1
   .dw String2
   .dw String3
   .dw String4
   .dw String5
   .dw String6
   .dw String7
   .dw String8
These are the text strings themselves. They are null-terminated.

Code: Select all

String1: .db "This is string 1!",0
String2: .db "This is string 2!",0
String3: .db "This is string 3!",0
String4: .db "This is string 4!",0
String5: .db "This is string 5!",0
String6: .db "This is string 6!",0
String7: .db "This is string 7!",0
String8: .db "This is string 8!",0
Go ahead and ask more questions if you want.
You know your hexadecimal output routine is broken when it displays the character 'G'.
That_One_Guy
New Member
Posts: 65
Joined: Sun 03 Apr, 2005 7:55 pm
Location: The seventh circle of Hell.
Contact:

Post by That_One_Guy »

Ahh, thanks a lot. Now, to use ionRandom, you just include ion in the header?
Truly great madness cannot be achieved without significant intelligence.

http://www.xanga.com/jakku_kun, rants by me.
DarkerLine
Calc Wizard
Posts: 526
Joined: Tue 08 Mar, 2005 1:37 am
Location: who wants to know?
Contact:

Post by DarkerLine »

not only do you include ion.inc, but you also supply the program description and all the rest of the stuff in the ion header. And then your program is forever doomed to require Ion or Mirage to run it.
just try to be nice to people.
_________________
My TI Blog - http://mpl.unitedti.org/
That_One_Guy
New Member
Posts: 65
Joined: Sun 03 Apr, 2005 7:55 pm
Location: The seventh circle of Hell.
Contact:

Post by That_One_Guy »

What is the proper header for an Ion program?
Truly great madness cannot be achieved without significant intelligence.

http://www.xanga.com/jakku_kun, rants by me.
User avatar
Shadow Phoenix
Calc Guru
Posts: 835
Joined: Mon 03 Jan, 2005 7:54 pm
Location: out there. seriosly.

Post by Shadow Phoenix »

Code: Select all

       .nolist			;remember, first we need the ION Header
        #include "ion.inc"
        .list

#ifdef TI83P
        .org    progstart-2
        .db     $BB,6D
#else
        .org    progstart
#endif
        ret				
        jr      nc,begin			;where to go to start the program

        .db     "First ION prgm!",0		;the title

Information gathered from IG by Matthew Hernandez
Life is getting better.
That_One_Guy
New Member
Posts: 65
Joined: Sun 03 Apr, 2005 7:55 pm
Location: The seventh circle of Hell.
Contact:

Post by That_One_Guy »

Ahhh, doumo arigato gozaimasu! Maybe i can get this damned game to work after all.
Truly great madness cannot be achieved without significant intelligence.

http://www.xanga.com/jakku_kun, rants by me.
That_One_Guy
New Member
Posts: 65
Joined: Sun 03 Apr, 2005 7:55 pm
Location: The seventh circle of Hell.
Contact:

Post by That_One_Guy »

Okay, maybe not. here's the source, maybe one of you folk can fix it?
.NOLIST
#define EQU .equ
#define equ .equ
#define END .end
#define end .end
#include "ti83plus.inc"
#include "mirage.inc"
.LIST
#ifdef TI83P
.org progstart-2
.db $BB,6D
#else
.org progstart
#endif
ret
jr nc,rnd
.db "ION prgm!",0

rnd: ;choose a random number and go
ld b,16 ;to corresponding string
call irandom
ld h,0
ld l,a
add hl,hl
ld bc,atktable
add hl, bc
ld a,(hl)
inc hl
ld h,(hl)
ld l,a
B_CALL(_PutS)
ret
atktable: ;tells it what string to display
.dw atk1
.dw atk2
.dw atk3
.dw atk4
.dw atk5
.dw atk6
.dw atk7
.dw atk8
.dw atk9
.dw atk10
.dw atk11
.dw atk12
.dw atk13
.dw atk14
.dw atk15
.dw atk16
atk1: ;the strings to be displayed
.db "(stabs user)",0
jp rnd
atk2:
.db "(kicks user)",0
jp rnd
atk3:
.db "(throws user",0
.db "into wall)",0
jp rnd
atk4:
.db "(bitchslaps",0
.db "user)",0
jp rnd
atk5:
.db "(punches user)",0
jp rnd
atk6:
.db "(shoots user",0
.db "in the head)",0
jp rnd
atk7:
.db "(spits acid on",0
.db "user)",0
jp rnd
atk8:
.db "(cuts user)",0
jp rnd
atk9:
.db "(slices user)",0
jp rnd
atk10:
.db "(bites user)",0
jp rnd
atk11:
.db "(impales user)",0
jp rnd
atk12:
.db "(cuts user's",0
.db "throat)",0
jp rnd
atk13:
.db "(zaps user with",0
.db "laser eyes)",0
jp rnd
atk14:
.db "(uses",0
.db "head explody on",0
.db "user)",0
jp rnd
atk15:
.db "(tortures user)",0
jp rnd
atk16:
.db "fires a rocket",0
.db "at user)",0
jp rnd
END
.end
Truly great madness cannot be achieved without significant intelligence.

http://www.xanga.com/jakku_kun, rants by me.
Post Reply