网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
03月08日漏签0天
fx-es(ms)吧 关注:17,962贴子:317,197
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 4回复贴,共1页
<<返回fx-es(ms)吧
>0< 加载中...

Random Object on Screen

  • 取消只看楼主
  • 收藏

  • 回复
  • casio2009
  • 991EX
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
Hey, long time no see! Today, I want to introduce to you how to display object on screen with random position that isn't exceeding the screen.
Logic here is:
1. Use num_randint for pos_x and pos_y with min_x = 0 (0x00) and max_x = 191 - (dec)m (0xBF - (hex)m), store result to var_x; min_y = 1 (0x01) and max_y = 63 - (dec)n (0x3F - (hex)n), store result to var_y. Note than "m" and "n" are size_x and size_y of object respectively.
2. Use calc_func to calculate this formula: "256 × y + x" and store result to 0xD3A0. Of course result always be decimal.
3. Use a pair of gadgets/functions that can convert decimal result to hexadecimal, and store it at anywhere (e.g: 0xD730).
4. Draw object and render it using render_bitmap and render.ddd4 (read my older post about render_bitmap usage)
5. Loop with delay (to change position continuously after a few seconds)


  • casio2009
  • 991EX
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
On the 1st floor, I will teach you how to write the program step by step. Now, suppose that I want to display a 7×7 (m×n size) square object in random position. First we call:
/*
pop xr0
hex D4 DD 00 06
memzero ;0:8FBA
*/
to clear the 1st_buffer. Then we call num_frombyte (1:D94CH) like this:
/*
;You should skip LR for any functions that start with "PUSH LR" instruction
pop xr0
hex 40 E6 ;example address for storing min_x value
hex 00 00
num_frombyte
;Note that storing one number to any destination, it always accounts for 10 bytes.
pop xr0
hex 50 E6 ;example address for storing max_x value
hex B8 00 ;0xB8 = 191 - 7 = 184
num_frombyte
pop xr0
hex 60 E6 ;example address for storing min_y value
hex 01 00
num_frombyte
pop xr0
hex 70 E6 ;example address for storing max_y value
hex 38 00 ;0x38 = 63 - 7 = 56
num_frombyte
*/
After that, we call num_randint (1:395EH) like this:
/*
pop xr0
hex 40 E6 ;min_x result addr
hex 50 E6 ;max_x result addr
num_randint
pop xr0
hex 60 E6 ;min_y result addr
hex 70 E6 ;max_y result addr
num_randint
;Note that result of these num_randint will overwrite [ER0] so you must loop program from "num_frombyte" part again to ensure it could reset the min_x and min_y value for next execution.
*/
Now, we must copy back the result from each [ER0] to var_x (0xD36A) and var_y (0xD374) respectively using memcpy (length: 10 bytes = 0A 00)
/*
pop xr0
hex 6A D3 ;dest
hex 40 E6 ;src
BL memcpy, pop er0 ;0:86F0H
hex 0A 00 ;length
pop xr0
hex 74 D3
hex 60 E6
BL memcpy, pop er0
hex 0A 00
*/


2026-03-08 13:58:01
广告
不感兴趣
开通SVIP免广告
  • casio2009
  • 991EX
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
2nd floor: Continue
After did copying result step, you can easily use this formula: "256 × y + x" to calculate pos in decimal using calc_func (1:77DAH). Note that the address of formula would increase after calculating formula, so try to loop whole program including formula address and whole token in this formula too.
/*
pop xr0
adr addr_formula_calc
hex A0 D3 ;dest to store result
calc_func
<loop part here>
addr_formula_calc: # for example label addr here is 0xD880. If you write code by hand, you should account the address correctly.
adr formula_calc
formula_calc: # 0xD882
hex 32 35 36 A8 49 A6 48 00 ;token of 256×y + x formula
object: ;0xD88A
<hex of object here>
*/
Next, we must convert the position from decimal to hexadecimal. We will use this pair: 1:5F86 and 1:5FFC (remember to skip LR) to convert, and converted result will store to ER0.
/*
pop er0
hex A0 D3
pop er12
hex A0 D3
call 15F88
call 15FFE
*/
Now, we can store the result to any address, for example 0xE9D4. We simply do this:
/*
setlr
er2 = er0,er0 += er4,rt
pop er8
hex D4 E9
[er8] = er2, pop xr8
hex D4 E9 00 00
*/
We almost done. Now we will render the object using render_bitmap (0:8ACEH) with position we stored before, we just load the value from 0xE9D4 to er0 and set size of object to 7×7 and specify addr of object (in hex).
/*
pop er2
hex 00 00
[er8] += er2, pop xr8
hex 00 00 00 00 ;to load value from 0xE9D4 to er2
er0 = er2,rt ;copy to er0
pop er2
hex 07 07
render_bitmap
pop er0
hex 8A D8 ;example address
render.ddd4
*/


  • casio2009
  • 991EX
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
3rd floor: Last step
Finally, we just need to loop the program. Use @贴吧用户_QQR3MM4 (xyzst) loop for more efficient (a.k.a memcpy loop). But first we should set delay because we want to see object display in random position:
/*
pop er0
hex 00 20
delay
DI,RT
pop er8
adr length
pop er2
hex 01 00
[er8] = er2, pop xr8
hex 00 00 00 00
pop qr0
<program length>
<src addr>
<dest addr>
<sp jump addr> - 2
hex CC 87
length:
start_label:
<end of program - start_label> ;to calculate remaining length
hex 00 00
sp = er6,pop er8
*/
That's it. If you dont understand, you can read my example program in the 4th floor


  • casio2009
  • 991EX
    8
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
4th floor: Example program.
Inject data to 0xE9E0 and run it using this launcher: FD24 30 30 D8 91 30 30 8C 92 30 30 E2 30 31 30 16 01 E0 E9 30 D8 2E D8 CC 87 31 30 30 30 38 1D 32 30.
Some explanation:
1. D8A0: 34 61 01 00 [34 D9] A0 D3 DC 77 01 00...
It means ER0 = 34 D9 (0xD934). 0xD934 contains "address of formula", not "formula" itself. Data at 0xD934 is 36 D9 which is 0xD936 = address of formula. 32 35 36 A8 49 A6 48 00 is token of formula: "256×y+x".
2. D8F0: 00 00 A8 21 01 00 [3E D9] 06 87 00 00...
3E D9 (0xD93E) here is address of picture/object that is written in hexadecimal form, you can look at the data at 0xD93E.
3. D90A: 36 9A 00 00 [2C D9]; D910: C2 8F 00 00 [01 00] 28 8F 00 00 00 00 00 00...
It means 0xD92C is addr of remaining length, which is replaced by 01 00 and because 1:87CC is BL memcpy but indirect, we must replace the remaining length to memcpy (segment 1) continuously to make it loop by repeating storing 01 00 to addr of remaining length.
4. D91E: E2 30 01 00 [16 01] [E0 E9] [30 D8] [2E D8] ...
0x0116 = 278 bytes = length of whole program
0xE9E0 = backup addr
0xD830 = source addr (= where to execute and process the program)
0xD82E = sp jump ER6, we must copy repeatedly from backup to src, so that we could jump back to the starting point and loop (using 38 1D 32 30 at the end of program)
5. D92A: CC 87 [12 00] 00 00
0012 = remaining length, count from 0xD92C to 0xD93E (from the addr after CC 87 to the end (that we configured before). The purpose here is to make the remaining part to be fixed, cannot change, like even if the addr of addr of formula increases from D936 to D93E (there are 8 tokens in that formula) it still reset to D936, and we can repeat executing the formula again and again.
That's all. If you have any questions, feel free to ask in this post.


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 4回复贴,共1页
<<返回fx-es(ms)吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示