Chinese-language board. 为NES/FC开发商的中国语言论坛 | 為NES/FC開發商的中國語言論壇
Moderator: Moderators
-
zgh4000
- Posts: 29
- Joined: Tue May 30, 2006 10:11 am
Post
by zgh4000 » Wed Jun 07, 2006 11:36 am
乘除法
16位运算
定点坐标显示子程序
随机函数
时间
......
时间我已经做出来了。
原理是NTSC制式下每秒60帧,即刷60次。
我在每个VBLINK期间引发的NMI中断加1,加到60的时候就是1秒了。
同理PAL是50次。
随机函数:
rand:
CLC ; C=0
LDA $6003 ; A=$6003
ADC $6004 ; A+=$6004
STA $6004 ; $6004=A
ADC $6005 ; A+=$6005
STA $6005 ; $6005=A
ADC $6006 ; A+=$6006
STA $6006 ; $6006=A
CLC ; C=0
LDA $6003 ; A=$6003
ADC #$27 ; A+=27
STA $6003 ; $6003=A
LDA $6004 ; A=$6004
ADC #$59 ; A+=59
STA $6004 ; $6004=A
PHA ; A入栈
LDA $6005 ; A=$6005
ADC #$41 ; A+=41
STA $6005 ; $6005=A
AND #$7F ; A&=7F
TAX ; X=A
LDA $6006 ; A=$6006
ADC #$31 ; A+=31
STA $6006 ; $6006=A
PLA ; A出栈
RTS
SRAM选上
$6003
$6004
$6005
$6006
每回数据随机,可以自己写比上面更简单的代码。
Last edited by
zgh4000 on Sun Jun 11, 2006 10:23 am, edited 2 times in total.
-
tpu
- Posts: 9
- Joined: Sat Nov 05, 2005 6:38 pm
- Location: china
Post
by tpu » Thu Jun 08, 2006 7:38 pm
随机数算法一般都是给一个种子,即初始值,然后返回一系列的伪随机数。只要种子一样,产生的结果就一样。把地址放在sram里面,可以保证种子每次开机都不一样。
乘除法我写过一些,这里不能上传。改天发给你研究。
-
zgh4000
- Posts: 29
- Joined: Tue May 30, 2006 10:11 am
Post
by zgh4000 » Fri Jun 09, 2006 8:08 pm
tpu wrote:随机数算法一般都是给一个种子,即初始值,然后返回一系列的伪随机数。只要种子一样,产生的结果就一样。把地址放在sram里面,可以保证种子每次开机都不一样。
乘除法我写过一些,这里不能上传。改天发给你研究。
乘法我是这样理解的。
循环加运算
除法则是循环减运算。
是偶数的话可以用移位来提高效率。不知道你的代码是这个原理吗?
发我邮箱吧。
Last edited by
zgh4000 on Fri Jun 09, 2006 9:40 pm, edited 2 times in total.
-
zgh4000
- Posts: 29
- Joined: Tue May 30, 2006 10:11 am
Post
by zgh4000 » Fri Jun 09, 2006 8:20 pm
16位运算
最近研究后发现也很简单,利用进位判断可以容易做到.
定点坐标显示子程序
发现要实现他,要用到16位运算 和乘法。^_^
-
tpu
- Posts: 9
- Joined: Sat Nov 05, 2005 6:38 pm
- Location: china
Post
by tpu » Sun Jun 11, 2006 8:10 am
我直接贴上来:
math.asm
--------8<----------------------------
Code: Select all
.dataseg
;math
.public mtht0 .byte
.public mtht1 .byte
.public mtht2 .byte
.public mtht3 .byte
;result
.public mthr0 .byte
.public mthr1 .byte
.public mthr2 .byte
.public mthr3 .byte
.codeseg
.extrn str_addr : byte
;;
;; 24bitx8bit->24bit
;; mtht[210] x a => mthr[210]
;;
.proc mul24x8
sta mtht3
txa
pha
lda #$00
sta mthr0
sta mthr1
sta mthr2
tax
-: lda #$01
and mtht3
beq +
clc
lda mthr0
adc mtht0
sta mthr0
lda mthr1
adc mtht1
sta mthr1
lda mthr2
adc mtht2
sta mthr2
+: cpx #$07
beq +
clc
rol mtht0
rol mtht1
rol mtht2
clc
ror mtht3
inx
jmp -
+: pla
tax
rts
.endp
;;
;; 24bit/16bit => 24bit,16bit
;; mtht[210] / mthr[10] => mtht[210], mthr[32]
;;
.proc div24d16
txa
pha
lda #$00
sta mthr2
sta mthr3
ldx #$18
-: clc
rol mtht0
rol mtht1
rol mtht2
rol mthr2
rol mthr3
bcs +
lda mthr3
cmp mthr1
bne +
lda mthr2
cmp mthr0
+: bcc +
sec
lda mthr2
sbc mthr0
sta mthr2
lda mthr3
sbc mthr1
sta mthr3
lda mtht0
ora #$01
sta mtht0
+: dex
bne -
pla
tax
rts
.endp
;;
;; 24bit/8bit => 24bit,8bit
;; mtht[210] / a => mtht[210], mtht[3]
;;
.proc div24d8
sta str_addr
txa
pha
lda #$00
sta mtht3
ldx #$18
-: clc
rol mtht0
rol mtht1
rol mtht2
rol mtht3
lda mtht3
bcs ++
cmp str_addr
bcc +
++: sec
sbc str_addr
sta mtht3
lda mtht0
ora #$01
sta mtht0
+: dex
bne -
pla
tax
rts
.endp
;;
;; 24bit+8bit => 24bit
;; x[210] + a => x[210]
;;
.proc add24a8
clc
adc $00,x
sta $00,x
lda $01,x
adc #$00
sta $01,x
lda $02,x
adc #$00
sta $02,x
rts
.endp
;;
;; 24bit-8bit => 24bit
;; x[210] - a => x[210]
;;
.proc sub24s8
sta str_addr
sec
lda $00,x
sbc str_addr
sta $00,x
lda $01,x
sbc #$00
sta $01,x
lda $02,x
sbc #$00
sta $02,x
rts
.endp
.public mul24x8, div24d8, div24d16, add24a8, sub24s8
-
zgh4000
- Posts: 29
- Joined: Tue May 30, 2006 10:11 am
Post
by zgh4000 » Sun Jun 11, 2006 9:50 am
谢了,
不知道你对光枪有没研究?
-
tpu
- Posts: 9
- Joined: Sat Nov 05, 2005 6:38 pm
- Location: china
Post
by tpu » Sun Jun 11, 2006 6:48 pm
光枪你知道原理的话,编程实现应该很容易的
-
luoli83
- Posts: 1
- Joined: Thu Jun 01, 2006 4:00 pm
Post
by luoli83 » Fri Jun 16, 2006 12:22 pm
Will....... I really can not understand how NES works, it's just too complex.
I mean I can not manage asm will. so I tend to learn gameboy dev. Any way, the lay out of gameboy Ram is very similar as NES.
-
zgh4000
- Posts: 29
- Joined: Tue May 30, 2006 10:11 am
Post
by zgh4000 » Fri Jun 16, 2006 1:54 pm
tpu wrote:光枪你知道原理的话,编程实现应该很容易的
可以用NNNesterj做出来
但是没能自动检测出接了光枪,必须手动选择。
你对vnes模拟器比较熟悉,麻烦你看下源代码,什么原因。