Week #11
Using memory block copy routine MOVEUP and MOVEDOWN for scrolling.
Disassemble the two routines to get an idea how they work.
Note in these examples, the full display(131 width) is scrolled. A
simple variation using a loop will allow you to scroll different widths.
--
Scrolling the screen down(ie, screen elements coming into view from the top):
Of course you need to update whatever is coming into view.
CODE
GOSBVL =SAVPTR *
GOSBVL =D0->Row1 * A[A] screen address
LC(5) 34*55+34 * destination offset
C=C+A A *
D1=C * destination
LC(5) 34*41+34 * source offset
C=C+A A *
D0=C * source
LC(5) 34*41 * nibbles to move
GOSBVL =MOVEUP * block copy
GOVLNG =GETPTRLOOP *
ENDCODE
Scrolling the screen up(ie, screen elements coming into view from the bottom):
Of course you need to update whatever is coming into view.
CODE
GOSBVL =SAVPTR *
GOSBVL =D0->Row1 * A[A] screen address
D1=A * destination
LC(5) 34*14 * source offset
C=C+A A * source offset + screen address
D0=C * source
LC(5) 34*41 * nibbles to move
GOSBVL =MOVEDOWN * block copy
GOVLNG =GETPTRLOOP *
ENCODE
Depending on where you begin/end(ie. destination and source) the block
copying, effects how the scrolling will occur. Note that 34 nibbles x 41
lines are "scrolled" in both examples.
Week #10
Find which type of HP48, a program is running on. Returns TRUE if G(X)
and FALSE for S(X).
CODE
CD0EX * temporarily save instruction pointer
D0=(5) =IRAM@ * D0 -> IRAM
C=DAT0 S * 7=S, 8=G
CD0EX * restore instruction pointer
C=C+C S * 7+7 = carry clear, 8+8 = carry set
GOVLNG =PushT/FLoop * carry clear, then return FALSE=SX
* carry set, then return TRUE=GX
ENDCODE
Week #9
Detailed description of a program similar to Week #2.
Week #8
Assuming A[A] has a value, it will be multiplied by 34. Display line
offsets can be calculated in this manner.
CODE
......
C=A A * duplicate of original value
CSL A * x16
C=C+C A * x32
A=A+A A * x2
C=C+A A * x34
......
ENDCODE
Week #7
Drawing a GROB to the display.
No arguments required.
CODE
GOSBVL =SAVPTR * save system pointers
GOSBVL =D0->Row1 * D0 -> first row, first column of display
GOSUB GrobDat * RTN for this GOSUB used as start address
* of grob data (NIBHEX ....)
NIBHEX 80 * 1st line of grob
NIBHEX E3 * 2nd line of grob
NIBHEX B6 * 3rd line of grob
NIBHEX E3 * 4th line of grob
NIBHEX 80 * 5th line of grob
GrobDat C=RSTK * RTN address is start address for grob
D1=C * D1 -> start of grob
P= 16-5 * 5 lines of grob data to draw
GrbLoop C=DAT1 B * read one line of grob data(2 nibs)
DAT0=C B * write to screen
D1=D1+ 2 * next line in grob data
D0=D0+ 16 *
D0=D0+ 16 *
D0=D0+ 2 * next row in screen
P=P+1 * increment counter
GONC GrbLoop * continue until carry set
GOVLNG =GETPTRLOOP * restore system pointers
ENDCODE
Week #6
Add two real numbers together.
No argument checking!
2: 22
1: 1023
CODE
GOSBVL =POP2% * pop 2 reals from stack
GOSBVL =SPLTAC * convert 2 reals(%) to long reals(%%)
GOSBVL =ADDF * add 2 long reals
GOSBVL =PACK * pack %% to %
GOSBVL =PUSH%LOOP * push real to stack
ENDCODE
Week #5
Producing random numbers by reading the hardware CRC.
For example, random number ranges can be:
(4=16384, 5=13107, 6=10923, 8=8192, 10=6554, 12=5462, 20=3277, 100=656)
Substitute LC(5) instruction with desired value.
CODE
GOSBVL =SAVPTR * save system pointers
D0=(5) =TIMER2 * D0 -> TIMER2
A=DAT0 8 * read TIMER2 for randomness
D0=(5) =CRC * D0 -> CRC
A=0 A * zero out A[A]
A=DAT0 4 * read 4 nibbles, numerator for IntDiv
LC(5) 16384 * divisor for IntDiv
GOSBVL =IntDiv * quotient = random number between 0-3
C=C+1 A * add 1 to get range from 1-4
A=C A * prepare to push random number
GOVLNG =PUSH#ALOOP * push random number as a bint
ENDCODE
Week #4
Program to draw a small line segment on the first line, first
column of the display. The screen write will occur very quickly!
If you have problems seeing the line being drawn, use a program
to freeze the display, such as "program 7 FREEZE".
No arguments required.
CODE
GOSBVL =SAVPTR * save system pointers
GOSBVL =D0->Row1 * D0 -> first row, first column
* also A[A] display address
LCHEX #F * binary 1111
DAT0=C P * write to screen, four pixels drawn
GOVLNG =GETPTRLOOP * restore system pointers
ENDCODE
This one draws a longer line segment.
CODE
GOSBVL =SAVPTR * save system pointers
GOSBVL =D0->Row1 * D0 -> first row, first column
* also, A[A] display address
LCHEX #FF * binary 1111 1111
DAT0=C B * write to screen, eight pixels drawn
GOVLNG =GETPTRLOOP * restore system pointers
ENDCODE
Week #3
Program to find the number of occurrences of a character in a string.
Accepts search string in level 2 and search character in level 1,
No argument checking!
2: "SEARCH THIS STRING"
1: "S"
CODE
GOSBVL =SAVPTR * save system pointers
A=DAT1 A * stack level 1 object address
D0=A * D0 -> search character
D0=D0+ 10 * skip prologue and length
A=DAT0 B * search character
D1=D1+ 5 * D1 -> stack level 2
GOSBVL =GetStrLenStk * C[A] number of chars in string
* D1 -> body
B=0 A * inititalize match counter
D=C A * D[A] characters in string
D=D-1 A * adjust, base length 0
GOC Quit * null string, then quit
Search C=DAT1 B * read character from search string
?C#A B * character does not match?
GOYES NxMatch * yes, then continue by finding next match
B=B+1 A * else, increment match counter
NxMatch D=D-1 A * decrement total character counter
GOC Quit * quit when length of string reached
D1=D1+ 2 * D1 -> next character in search string
GOTO Search * continue searching
Quit A=B A * A[A] character match count
GOVLNG =PUSH#ALOOP * push character counter as a bint
* and restore system pointers
ENDCODE
Week #2
Program to change the first character in a string to 'A'
Accepts string in level 1,
No argument checking!
View DB output
1: "TEST STRING"
CODE
GOSBVL =SAVPTR * save system pointers
C=DAT1 A * stack level 1 object address
D1=C * D1 -> string
D1=D1+ 10 * skip prologue and length
LCASC \A\ * 'A'
DAT1=C B * change character in string
GOVLNG =GETPTRLOOP * restore system pointers
ENDCODE
Week #1
Program which returns the size of string.
Accepts string in level 1,
No argument checking!
1: "TEST STRING"
CODE
GOSBVL =SAVPTR * save system pointers
GOSBVL =GetStrLenStk * C[A] number of chars in string
A=C A * prepare for push
GOVLNG =PUSH#ALOOP * push string size to stack as a bint
* and restore system pointers
ENDCODE