mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-06-16 07:29:29 +00:00
entropy_tiny: not small enough
This commit is contained in:
parent
fb0a15ad9f
commit
99425eb87e
|
@ -14,56 +14,33 @@
|
||||||
; NEXT: NEXT: NEXT: NEXT
|
; NEXT: NEXT: NEXT: NEXT
|
||||||
|
|
||||||
|
|
||||||
|
; SCALE=(RND(1)<E)*RND(1)*E*20+1
|
||||||
|
;
|
||||||
|
; Equivalent to IF RND(1)<E THEN SCALE=RND(1)*E*20+1
|
||||||
|
; ELSE SCALE=1
|
||||||
|
|
||||||
|
; What this does:
|
||||||
|
; if EPOS is 8,9 then value is either 1 or 2
|
||||||
|
; if EPOS is 10,11,12,13,14 then value is either 1, 2, or 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; Optimization
|
; Optimization
|
||||||
; 144 bytes: first working version (including DOS33 4-byte size/addr)
|
; 88 bytes -- hack up the entropy code
|
||||||
; 141 bytes: nextx: cache XPOS in X register
|
; 83 bytes -- count down YPOS instead of up
|
||||||
; 140 bytes: nexty: we know state of carry flag
|
; 73 bytes -- XPOS only up to 256
|
||||||
; 139 bytes: change jmp to bcs
|
|
||||||
; 138 bytes: jmp at end now fits into a bcs
|
|
||||||
; 136 bytes: store YPOS on stack
|
|
||||||
; 135 bytes: store X to HGR_SCALE rather than TXA+STA
|
|
||||||
; 131 bytes: some fancy branch elimination by noticing X=1
|
|
||||||
; 126 bytes: nextx: simplify by using knowledge of possible x/y vals
|
|
||||||
; 124 bytes: qkumba noticed we can bump yloop up to include the
|
|
||||||
; pha, letting us remove two now unneeded stack ops
|
|
||||||
; 123 bytes: qkumba noticed XDRAW0 always exits with X==0 so
|
|
||||||
; we can move some things to use X instead and
|
|
||||||
; can get a "1" value simply by using INX
|
|
||||||
; 122 bytes: Nick Westgate noticed that we could save a byte
|
|
||||||
; in eloop by pushing the stx ELOOP to the beginning
|
|
||||||
; rather than the end.
|
|
||||||
|
|
||||||
;BLT=BCC, BGE=BCS
|
;BLT=BCC, BGE=BCS
|
||||||
|
|
||||||
; zero page locations
|
; zero page locations
|
||||||
HGR_SHAPE = $1A
|
HGR_SHAPE = $1A
|
||||||
FAC_EXP = $9D
|
|
||||||
FAC_HO = $9E
|
|
||||||
FAC_MOH = $9F
|
|
||||||
FAC_MO = $A0
|
|
||||||
FAC_LO = $A1
|
|
||||||
FAC_SGN = $A2
|
|
||||||
RND_EXP = $C9
|
|
||||||
RND_HO = $CA
|
|
||||||
RND_MOH = $CB
|
|
||||||
RND_MO = $CC
|
|
||||||
RND_LO = $CD
|
|
||||||
RND_SGN = $CE
|
|
||||||
HGR_SCALE = $E7
|
HGR_SCALE = $E7
|
||||||
HGR_ROTATION = $F9
|
HGR_ROTATION = $F9
|
||||||
EPOS = $FC
|
FRAME = $FC
|
||||||
XPOS = $FD
|
XPOS = $FD
|
||||||
XPOSH = $FE
|
|
||||||
YPOS = $FF
|
YPOS = $FF
|
||||||
|
|
||||||
; ROM calls
|
; ROM calls
|
||||||
CONINT = $E6FB
|
|
||||||
FMULT = $E97F
|
|
||||||
MUL10 = $EA39
|
|
||||||
DIV10 = $EA55
|
|
||||||
MOVAF = $EB63
|
|
||||||
FLOAT = $EB93
|
|
||||||
RND = $EFAE
|
|
||||||
HGR2 = $F3D8
|
HGR2 = $F3D8
|
||||||
HPOSN = $F411
|
HPOSN = $F411
|
||||||
XDRAW0 = $F65D
|
XDRAW0 = $F65D
|
||||||
|
@ -72,97 +49,28 @@ XDRAW0 = $F65D
|
||||||
entropy:
|
entropy:
|
||||||
|
|
||||||
jsr HGR2 ; Hi-res graphics, no text at bottom
|
jsr HGR2 ; Hi-res graphics, no text at bottom
|
||||||
; Y=0, A=$60 after this call
|
; Y=0, A=0 after this call
|
||||||
|
|
||||||
ldx #8 ; Unlike the BASIC, our loop is *100
|
|
||||||
; 8 to 15 rather than .08 to .15
|
|
||||||
eloop:
|
eloop:
|
||||||
stx EPOS ; EPOS was temporarily in X
|
lda #180 ; FOR Y=4 to 189 STEP 6
|
||||||
|
sta YPOS
|
||||||
|
|
||||||
lda #4 ; FOR Y=4 to 189 STEP 6
|
|
||||||
yloop:
|
yloop:
|
||||||
pha ; YPOS stored on stack
|
|
||||||
lda #4 ; FOR X=4 to 278 STEP 6
|
lda #4 ; FOR X=4 to 278 STEP 6
|
||||||
sta XPOS
|
sta XPOS
|
||||||
ldx #0 ; can't fit 278 in one byte, need overflow byte
|
|
||||||
stx XPOSH
|
|
||||||
xloop:
|
xloop:
|
||||||
|
|
||||||
|
ldx #1
|
||||||
; SCALE=(RND(1)<E)*RND(1)*E*20+1
|
ldy FRAME
|
||||||
;
|
lda $D000,y
|
||||||
; Equivalent to IF RND(1)<E THEN SCALE=RND(1)*E*20+1
|
bmi no_add
|
||||||
; ELSE SCALE=1
|
inx
|
||||||
|
no_add:
|
||||||
; Note the Apple II generates a seed based on keypresses
|
|
||||||
; but by default RND is never seeded from there.
|
|
||||||
; Someone actually wrote an entire academic paper complaining about
|
|
||||||
; this
|
|
||||||
;
|
|
||||||
; J.W. Aldridge. "Cautions regarding random number generation
|
|
||||||
; on the Apple II", Behavior Research Methods, Instruments,
|
|
||||||
; & Computers, 1987, 19 (4), 397-399.
|
|
||||||
|
|
||||||
; Many of these values are in Applesoft 5-byte floating point
|
|
||||||
|
|
||||||
; get random value in FAC
|
|
||||||
; (floating point accumlator)
|
|
||||||
|
|
||||||
inx ; X is always 0 coming in, increment to 1
|
|
||||||
|
|
||||||
; RND(1), Force 1
|
|
||||||
; returns "random" value between 0 and 1
|
|
||||||
jsr RND+6 ; we skip passing the argument
|
|
||||||
; as a floating point value
|
|
||||||
; as that would be a pain
|
|
||||||
|
|
||||||
; Compare to E
|
|
||||||
|
|
||||||
jsr MUL10 ; EPOS is E*100
|
|
||||||
jsr MUL10 ; so multiply rand*100 before compare
|
|
||||||
jsr CONINT ; now convert to int, result in X
|
|
||||||
; X is now RND(1)*100
|
|
||||||
|
|
||||||
cpx EPOS ; compare E*100 to RND*100
|
|
||||||
|
|
||||||
ldx #1 ; load 1 into X (this is clever)
|
|
||||||
|
|
||||||
bcs done ; if EPOS>=RND then SCALE=1, skip ahead
|
|
||||||
|
|
||||||
; SCALE=RND(1)*E*20+1
|
|
||||||
; EPOS is E*100, so RND(1)*(EPOS/10)*2+1
|
|
||||||
|
|
||||||
; What this does:
|
|
||||||
; if EPOS is 8,9 then value is either 1 or 2
|
|
||||||
; if EPOS is 10,11,12,13,14 then value is either 1, 2, or 3
|
|
||||||
|
|
||||||
|
|
||||||
; put random value in FAC
|
|
||||||
; ldx #1 ; RND(1), Force 1, this set from earlier
|
|
||||||
jsr RND+6 ; skip arg parsing in RND
|
|
||||||
|
|
||||||
lda EPOS
|
|
||||||
jsr FLOAT ; convert value in A to float in FAC
|
|
||||||
jsr DIV10 ; FAC=FAC/10
|
|
||||||
|
|
||||||
ldy #>RND_EXP ; point (Y,A) to RND value
|
|
||||||
lda #<RND_EXP
|
|
||||||
jsr FMULT ; multiply FAC by RND in (Y,A)
|
|
||||||
|
|
||||||
inc FAC_EXP ; multiply by 2
|
|
||||||
|
|
||||||
jsr CONINT ; convert to int (in X)
|
|
||||||
|
|
||||||
inx ; add 1
|
|
||||||
|
|
||||||
done:
|
|
||||||
stx HGR_SCALE ; set scale value
|
stx HGR_SCALE ; set scale value
|
||||||
|
|
||||||
ldy XPOSH ; setup X and Y co-ords
|
ldy #0 ; setup X and Y co-ords
|
||||||
ldx XPOS
|
ldx XPOS
|
||||||
pla ; YPOS is on stack
|
lda YPOS
|
||||||
pha
|
|
||||||
jsr HPOSN ; X= (y,x) Y=(a)
|
jsr HPOSN ; X= (y,x) Y=(a)
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,41 +83,22 @@ done:
|
||||||
; Both A and X are 0 at exit
|
; Both A and X are 0 at exit
|
||||||
|
|
||||||
nextx: ; NEXT X
|
nextx: ; NEXT X
|
||||||
|
inc FRAME
|
||||||
|
|
||||||
lda XPOS ; 2
|
lda XPOS ; 2
|
||||||
clc ; 1
|
clc ; 1
|
||||||
adc #6 ; x+=6 ; 2
|
adc #6 ; x+=6 ; 2
|
||||||
sta XPOS ; 2
|
sta XPOS ; 2
|
||||||
|
|
||||||
; we know that the X=4 to 278 STEP 6 loop passes through exactly 256
|
|
||||||
; so we can check for that by looking for overflow to zero
|
|
||||||
|
|
||||||
bne skip ; 2
|
|
||||||
inc XPOSH ; 2
|
|
||||||
skip:
|
|
||||||
; the X=4 to 278 STEP 6 loop actually ends when X is at 280, which
|
|
||||||
; is 256+24. The lower part of the loop does not hit 24, so we
|
|
||||||
; can check for the end by looking for the low byte at 24.
|
|
||||||
|
|
||||||
cmp #24 ; see if less than 278 ; 2
|
|
||||||
bne xloop ; if so, loop ; 2
|
bne xloop ; if so, loop ; 2
|
||||||
;============
|
|
||||||
; 15
|
|
||||||
nexty: ; NEXT Y
|
|
||||||
pla ; YPOS on stack
|
|
||||||
adc #5 ; y+=6
|
|
||||||
; carry always set coming in, so only add 5
|
|
||||||
cmp #189 ; see if less than 189
|
|
||||||
bcc yloop ; if so, loop
|
|
||||||
|
|
||||||
nexte: ; NEXT E
|
nexty:
|
||||||
ldx EPOS
|
sec
|
||||||
inx ; EPOS saved at beginning of eloop
|
lda YPOS
|
||||||
cpx #15
|
sbc #6 ; y+=6
|
||||||
bcc eloop ; branch if <15
|
sta YPOS
|
||||||
|
bne yloop ; if so, loop
|
||||||
bcs entropy
|
beq eloop
|
||||||
|
|
||||||
shape_table:
|
shape_table:
|
||||||
; .byte 1,0 ; 1 shape
|
|
||||||
; .byte 4,0 ; offset at 4 bytes
|
|
||||||
.byte 18,63,36,36,45,45,54,54,63,0 ; data
|
.byte 18,63,36,36,45,45,54,54,63,0 ; data
|
||||||
|
|
Loading…
Reference in New Issue
Block a user