mirror of
https://github.com/deater/dos33fsprogs.git
synced 2025-03-04 04:30:18 +00:00
peasant: update the random code
old random generator not very random. The new one is, makes the cliff climb impossibly hard
This commit is contained in:
parent
14bdb6cfa1
commit
73b38a02e5
@ -133,7 +133,7 @@ qload_hd.o: qload_hd.s qboot.inc \
|
||||
hgr_copy.s \
|
||||
gr_offsets.s \
|
||||
qkumba_popwr.s \
|
||||
random16.s
|
||||
random8.s
|
||||
ca65 -o qload_hd.o qload.s -DFLOPPY=0 -l qload_hd.lst
|
||||
|
||||
####
|
||||
@ -166,7 +166,7 @@ qload.o: qload.s qboot.inc \
|
||||
hgr_copy.s \
|
||||
gr_offsets.s \
|
||||
qkumba_popwr.s \
|
||||
random16.s
|
||||
random8.s
|
||||
ca65 -o qload.o qload.s -DFLOPPY=1 -l qload.lst
|
||||
|
||||
###
|
||||
@ -248,7 +248,7 @@ qload.inc: generate_common QLOAD
|
||||
./generate_common -a 0xb00 -s location_names_l qload.lst >> qload.inc
|
||||
./generate_common -a 0xb00 -s location_names_h qload.lst >> qload.inc
|
||||
./generate_common -a 0xb00 -s wait_until_keypress qload.lst >> qload.inc
|
||||
./generate_common -a 0xb00 -s random16 qload.lst >> qload.inc
|
||||
./generate_common -a 0xb00 -s random8 qload.lst >> qload.inc
|
||||
./generate_common -a 0xb00 -s score_points qload.lst >> qload.inc
|
||||
./generate_common -a 0xb00 -s print_score qload.lst >> qload.inc
|
||||
./generate_common -a 0xb00 -s update_score qload.lst >> qload.inc
|
||||
|
@ -227,7 +227,7 @@ skip_rock:
|
||||
bne move_bird
|
||||
maybe_new_bird:
|
||||
|
||||
jsr random16
|
||||
jsr random8
|
||||
bird_freq_smc:
|
||||
and #$1f ; 1/32 of time start new bird?
|
||||
bne move_bird_done
|
||||
@ -235,7 +235,7 @@ bird_freq_smc:
|
||||
; bird on base level, 12 .. 76 (MAP_LOCATION==0)
|
||||
; bird on other levels, 12 .. 140
|
||||
|
||||
jsr random16
|
||||
jsr random8
|
||||
|
||||
ldx MAP_LOCATION
|
||||
bne new_bird_wider
|
||||
@ -313,7 +313,7 @@ move_rock_waiting:
|
||||
|
||||
; see if start new rock
|
||||
|
||||
jsr random16
|
||||
jsr random8
|
||||
rock_freq_smc:
|
||||
and #$1f ; 1/32 of time start new rock
|
||||
bne rock_good
|
||||
@ -324,7 +324,7 @@ start_new_rock:
|
||||
; bit of a hack, really should be from 0..38
|
||||
; but we actually do 2..34 as it's easier
|
||||
|
||||
jsr random16
|
||||
jsr random8
|
||||
and #$1f ; 0... 31
|
||||
clc
|
||||
adc #2 ; push away from edge a bit
|
||||
|
@ -194,7 +194,7 @@ kerrek_setup:
|
||||
bne kerrek_setup_dead
|
||||
|
||||
kerrek_setup_alive:
|
||||
jsr random16
|
||||
jsr random8
|
||||
and #$1
|
||||
beq kerrek_alive_not_there
|
||||
kerrek_alive_out:
|
||||
|
@ -342,7 +342,7 @@ gary_scare_horse_mask:
|
||||
|
||||
gary_scare_horse_nomask:
|
||||
|
||||
jsr random16
|
||||
jsr random8
|
||||
and #$3 ; 0..4
|
||||
beq gary_scare_try2
|
||||
cmp #$1
|
||||
|
@ -405,7 +405,7 @@ jhonka_cant_knock_door:
|
||||
jmp parse_common_unknown
|
||||
|
||||
jhonka_knock_door:
|
||||
jsr random16
|
||||
jsr random8
|
||||
and #$7
|
||||
|
||||
beq jhonka_knock5
|
||||
|
@ -201,8 +201,9 @@ not_kerrek:
|
||||
; init ned
|
||||
; randomly waits 126-64 frames
|
||||
|
||||
jsr random16
|
||||
jsr random8
|
||||
and #$3f
|
||||
|
||||
; lda #64
|
||||
sta NED_STATUS
|
||||
|
||||
|
@ -100,7 +100,7 @@ load_file:
|
||||
.include "gr_offsets.s"
|
||||
.include "loadsave_menu.s"
|
||||
.include "wait_keypress.s"
|
||||
.include "random16.s"
|
||||
.include "random8.s"
|
||||
.include "score.s"
|
||||
;.include "speaker_beeps.s"
|
||||
.include "redbook_sound.s"
|
||||
|
24
games/peasant/random8.s
Normal file
24
games/peasant/random8.s
Normal file
@ -0,0 +1,24 @@
|
||||
; https://wimcouwenberg.wordpress.com/2020/11/15/a-fast-24-bit-prng-algorithm-for-the-6502-processor/
|
||||
|
||||
random8:
|
||||
lda rand_a ; Operation 7 (with carry clear).
|
||||
asl
|
||||
eor rand_b
|
||||
sta rand_b
|
||||
rol ; Operation 9.
|
||||
eor rand_c
|
||||
sta rand_c
|
||||
eor rand_a ; Operation 5.
|
||||
sta rand_a
|
||||
lda rand_b ; Operation 15.
|
||||
ror
|
||||
eor rand_c
|
||||
sta rand_c
|
||||
eor rand_b ; Operation 6.
|
||||
sta rand_b
|
||||
|
||||
rts
|
||||
|
||||
rand_a: .byte 0
|
||||
rand_b: .byte 0
|
||||
rand_c: .byte 1
|
@ -2,7 +2,15 @@ CC = gcc
|
||||
CFLAGS = -O2 -Wall
|
||||
LFLAGS =
|
||||
|
||||
all: random16 random8 #random15
|
||||
all: random16 random8 random24
|
||||
|
||||
###
|
||||
|
||||
random24: random24.o
|
||||
$(CC) $(LFLAGS) -o random24 random24.o
|
||||
|
||||
random24.o: random24.c
|
||||
$(CC) $(CFLAGS) -c random24.c
|
||||
|
||||
###
|
||||
|
||||
@ -23,4 +31,4 @@ random8.o: random8.c
|
||||
###
|
||||
|
||||
clean:
|
||||
rm -f *~ *.o random16 random8 random15
|
||||
rm -f *~ *.o random16 random8 random24
|
||||
|
62
random/random24.c
Normal file
62
random/random24.c
Normal file
@ -0,0 +1,62 @@
|
||||
// https://wimcouwenberg.wordpress.com/2020/11/15/a-fast-24-bit-prng-algorithm-for-the-6502-processor/
|
||||
|
||||
// lda a ; Operation 7 (with carry clear).
|
||||
// asl
|
||||
// eor b
|
||||
// sta b
|
||||
// rol ; Operation 9.
|
||||
// eor c
|
||||
// sta c
|
||||
// eor a ; Operation 5.
|
||||
// sta a
|
||||
// lda b ; Operation 15.
|
||||
// ror
|
||||
// eor c
|
||||
// sta c
|
||||
// eor b ; Operation 6.
|
||||
// sta b
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned char a=0,b=0,c=1,carry,carry_new,accum;
|
||||
|
||||
int rand24(void) {
|
||||
accum=a; // LDA A
|
||||
carry=!!(accum&0x80);
|
||||
accum<<=1; // ASL
|
||||
accum=accum^b; // EOR B
|
||||
b=accum; // STA B
|
||||
carry_new=!!(accum&0x80); // ROL
|
||||
accum<<=1;
|
||||
accum|=carry;
|
||||
carry=carry_new;
|
||||
accum=accum^c; // EOR C
|
||||
c=accum; // STA C
|
||||
accum=accum^a; // EOR A
|
||||
a=accum; // STA A
|
||||
accum=b; // LDA B
|
||||
carry_new=accum&1; // ROR
|
||||
accum>>=1;
|
||||
accum|=(carry<<7);
|
||||
carry=carry_new;
|
||||
accum=accum^c; // EOR C
|
||||
c=accum; // STA C
|
||||
accum=accum^b; // EOR B
|
||||
b=accum; // STA B
|
||||
|
||||
return (a<<16)|(b<<8)|c;
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
int i,r;
|
||||
|
||||
for(i=0;i<1024;i++) {
|
||||
r=rand24();
|
||||
printf("%d: %06X m%02X\n",i,r,r&0x1f);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user