乘除法
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
每回数据随机,可以自己写比上面更简单的代码。
目前在学习这些,有谁有源码或资料的发下,谢谢!
Moderator: Moderators
目前在学习这些,有谁有源码或资料的发下,谢谢!
Last edited by zgh4000 on Sun Jun 11, 2006 10:23 am, edited 2 times in total.
乘法我是这样理解的。tpu wrote:随机数算法一般都是给一个种子,即初始值,然后返回一系列的伪随机数。只要种子一样,产生的结果就一样。把地址放在sram里面,可以保证种子每次开机都不一样。
乘除法我写过一些,这里不能上传。改天发给你研究。
循环加运算
除法则是循环减运算。
是偶数的话可以用移位来提高效率。不知道你的代码是这个原理吗?
发我邮箱吧。
Last edited by zgh4000 on Fri Jun 09, 2006 9:40 pm, edited 2 times in total.
我直接贴上来:
math.asm
--------8<----------------------------
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