[Reverse-engineering] [th02/th03/th04/th05] Random number ring buffer

Yes, you're reading that correctly. If the cursor is at 255, reading a
16-bit value will fill the upper 8 bits with the neighboring cursor
value, which always is 0xFF.

Funded by -Tom-.
This commit is contained in:
nmlgc 2018-03-16 09:19:50 +01:00
parent f98fba3c9d
commit 4b8baf1413
14 changed files with 746 additions and 1291 deletions

View File

@ -0,0 +1,15 @@
; Ring buffer of random numbers.
RANDRING_SIZE = 256
; TH05 wants it publicly...
public _randring
public _randring_p
_randring db RANDRING_SIZE dup (?)
if GAME ge 4
_randring_p dw ?
else
_randring_p db ?
db ?
endif

View File

@ -0,0 +1,18 @@
; void randring_fill(void)
public _randring_fill
_randring_fill proc near
push bp
mov bp, sp
push si
xor si, si
@@loop:
call IRand
mov _randring[si], al
inc si
cmp si, RANDRING_SIZE
jl short @@loop
pop si
pop bp
ret
_randring_fill endp

View File

@ -0,0 +1,37 @@
RANDRING_NEXT_DEF macro instance
; void randring_next8(void)
public _randring&instance&_next8
_randring&instance&_next8 proc near
mov bl, _randring_p
inc _randring_p
mov bh, 0
mov al, _randring[bx]
ret
_randring&instance&_next8 endp
; void randring_next8_and(unsigned char mask)
public _randring&instance&_next8_and
_randring&instance&_next8_and proc near
arg @@mask:byte
push bp
mov bp, sp
mov bl, _randring_p
inc _randring_p
mov bh, 0
mov al, _randring[bx]
and al, @@mask
pop bp
ret 2
_randring&instance&_next8_and endp
; void randring_next16(void)
public _randring&instance&_next16
_randring&instance&_next16 proc near
mov bl, _randring_p
inc _randring_p
mov bh, 0
mov ax, word ptr _randring[bx]
ret
_randring&instance&_next16 endp
endm

View File

@ -1,6 +1,7 @@
GAME = 2
include defconv_c.inc
include th02/hardware/input.inc
include th02/math/randring_next.inc
kajacall macro func, param := <0>
call _snd_kaja_interrupt pascal, (func shl 8) or (param and 0ffh)

View File

@ -2229,7 +2229,7 @@ var_C = byte ptr -0Ch
call _snd_se_reset
call sub_1028C
nopcall sub_CA1C
call sub_C224
call _randring_fill
mov PaletteTone, 64h ; 'd'
call far ptr palette_show
mov ax, 0D0h
@ -3390,72 +3390,8 @@ loc_C222:
retf
sub_C1E4 endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_C224 proc near
push bp
mov bp, sp
push si
xor si, si
loc_C22A:
call IRand
mov [si+26FAh], al
inc si
cmp si, 100h
jl short loc_C22A
pop si
pop bp
retn
sub_C224 endp
; =============== S U B R O U T I N E =======================================
sub_C23D proc near
mov bl, byte_2026A
inc byte_2026A
mov bh, 0
mov al, [bx+26FAh]
retn
sub_C23D endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_C24C proc near
arg_0 = byte ptr 4
push bp
mov bp, sp
mov bl, byte_2026A
inc byte_2026A
mov bh, 0
mov al, [bx+26FAh]
and al, [bp+arg_0]
pop bp
retn 2
sub_C24C endp
; =============== S U B R O U T I N E =======================================
sub_C264 proc near
mov bl, byte_2026A
inc byte_2026A
mov bh, 0
mov ax, [bx+26FAh]
retn
sub_C264 endp
include th02/math/randring_fill.asm
RANDRING_NEXT_DEF 1
; =============== S U B R O U T I N E =======================================
@ -4517,7 +4453,7 @@ loc_CB78:
loc_CB83:
push 8
push 3
call sub_C24C
call _randring1_next8_and
add al, 0BEh
push ax
call sub_CA62
@ -4532,7 +4468,7 @@ loc_CB93:
loc_CB9D:
push [bp+var_2]
push 7
call sub_C24C
call _randring1_next8_and
add al, 0BCh
push ax
@ -4605,7 +4541,7 @@ loc_CBFD:
loc_CC09:
push 1Fh
call sub_C24C
call _randring1_next8_and
mov ah, 0
add ax, 0B1h
mov [bp+var_2], ax
@ -4834,7 +4770,7 @@ loc_CD81:
loc_CD8C:
push 8
push 3
call sub_C24C
call _randring1_next8_and
add al, 0BEh
jmp short loc_CDA0
; ---------------------------------------------------------------------------
@ -4842,7 +4778,7 @@ loc_CD8C:
loc_CD97:
push 8
push 7
call sub_C24C
call _randring1_next8_and
add al, 0BCh
loc_CDA0:
@ -4863,7 +4799,7 @@ loc_CDAF:
loc_CDB1:
push 7
call sub_C24C
call _randring1_next8_and
add al, 0BCh
push ax
call sub_CA62
@ -4950,7 +4886,7 @@ loc_CE29:
loc_CE30:
push 1Fh
call sub_C24C
call _randring1_next8_and
mov ah, 0
add ax, 0B1h
mov [bp+var_2], ax
@ -4994,7 +4930,7 @@ loc_CE5B:
call iatan2
mov [bp+var_2], ax
push 7
call sub_C24C
call _randring1_next8_and
mov ah, 0
add ax, 0FFFDh
add [bp+var_2], ax
@ -5025,7 +4961,7 @@ loc_CE9F:
call iatan2
mov [bp+var_2], ax
push 7
call sub_C24C
call _randring1_next8_and
mov ah, 0
add ax, 0FFFDh
add [bp+var_2], ax
@ -5325,7 +5261,7 @@ loc_D0D2:
loc_D0DD:
push 8
push 3
call sub_C24C
call _randring1_next8_and
add al, 0BEh
jmp short loc_D0F1
; ---------------------------------------------------------------------------
@ -5333,7 +5269,7 @@ loc_D0DD:
loc_D0E8:
push 8
push 7
call sub_C24C
call _randring1_next8_and
add al, 0BCh
loc_D0F1:
@ -6089,7 +6025,7 @@ sub_D629 proc near
mov bp, sp
push si
push 7
call sub_C24C
call _randring1_next8_and
mov byte_218A0, al
xor si, si
jmp short loc_D644
@ -6147,7 +6083,7 @@ loc_D67B:
idiv bx
or dx, dx
jnz short loc_D6C4
call sub_C264
call _randring1_next16
and ax, 1FFh
cmp ax, 12h
jnz short loc_D69F
@ -6341,7 +6277,7 @@ loc_D7B4:
jnz short loc_D82B
cmp [bp+var_4], 0
jz short loc_D810
call sub_C23D
call _randring1_next8
mov ah, 0
mov bx, 5
sub bx, di
@ -6354,7 +6290,7 @@ loc_D7B4:
; ---------------------------------------------------------------------------
loc_D7FE:
call sub_C23D
call _randring1_next8
mov ah, 0
mov bx, 2
cwd
@ -6367,7 +6303,7 @@ loc_D80B:
; ---------------------------------------------------------------------------
loc_D810:
call sub_C23D
call _randring1_next8
mov ah, 0
mov bx, 2
cwd
@ -7976,7 +7912,7 @@ sub_E512 proc near
; ---------------------------------------------------------------------------
loc_E525:
call sub_C264
call _randring1_next16
mov bx, 180h
xor dx, dx
div bx
@ -7985,7 +7921,7 @@ loc_E525:
add bx, si
shl bx, 2
mov [bx+3F5Ch], dx
call sub_C264
call _randring1_next16
mov bx, 170h
xor dx, dx
div bx
@ -9772,49 +9708,7 @@ main_03_TEXT segment byte public 'CODE' use16
;org 6
assume es:nothing, ss:nothing, ds:_DATA, fs:nothing, gs:nothing
; =============== S U B R O U T I N E =======================================
sub_FAC6 proc near
mov bl, byte_2026A
inc byte_2026A
mov bh, 0
mov al, [bx+26FAh]
retn
sub_FAC6 endp
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_FAD5 proc near
arg_0 = byte ptr 4
push bp
mov bp, sp
mov bl, byte_2026A
inc byte_2026A
mov bh, 0
mov al, [bx+26FAh]
and al, [bp+arg_0]
pop bp
retn 2
sub_FAD5 endp
; =============== S U B R O U T I N E =======================================
sub_FAED proc near
mov bl, byte_2026A
inc byte_2026A
mov bh, 0
mov ax, [bx+26FAh]
retn
sub_FAED endp
RANDRING_NEXT_DEF 2
; =============== S U B R O U T I N E =======================================
@ -11101,7 +10995,7 @@ loc_10613:
; ---------------------------------------------------------------------------
loc_10618:
call sub_FAC6
call _randring2_next8
mov ah, 0
mov [bp+var_2], ax
mov di, 1
@ -11109,7 +11003,7 @@ loc_10618:
; ---------------------------------------------------------------------------
loc_10625:
call sub_FAC6
call _randring2_next8
mov ah, 0
mov [bp+var_2], ax
mov al, [si+10h]
@ -11121,11 +11015,11 @@ loc_10625:
; ---------------------------------------------------------------------------
loc_1063C:
call sub_FAC6
call _randring2_next8
mov ah, 0
mov [bp+var_2], ax
push 1Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add [bp+arg_0], ax
mov al, [si+10h]
@ -13499,7 +13393,7 @@ loc_11975:
push word_22D98
push word_22D9A
push 0Fh
call sub_FAD5
call _randring2_next8_and
add al, 0F9h
push ax
push 19h
@ -13922,7 +13816,7 @@ var_1 = byte ptr -1
call iatan2
mov [bp+var_1], al
push 1Fh
call sub_FAD5
call _randring2_next8_and
add al, 10h
loc_11CC4:
@ -14073,7 +13967,7 @@ loc_11E0A:
mov bx, si
add bx, bx
push word ptr [bx+531Eh]
call sub_FAC6
call _randring2_next8
push ax
push 83h
push 520020h
@ -14107,7 +14001,7 @@ sub_11E40 proc near
jnz short loc_11E66
push word_22D98
push word_22D9A
call sub_FAC6
call _randring2_next8
push ax
push word_20670+1
mov ax, word_20650
@ -14147,7 +14041,7 @@ sub_11E76 proc near
or dx, dx
jnz short loc_11EBE
mov byte_23A70, 1Eh
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 18h
cwd
@ -14190,7 +14084,7 @@ loc_11EE5:
; ---------------------------------------------------------------------------
loc_11EFC:
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 18h
cwd
@ -17125,7 +17019,7 @@ loc_134CD:
mov es:[bx+4], di
mov es:[bx+8], ax
push 3
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, 3
les bx, [bp+var_4]
@ -17408,7 +17302,7 @@ loc_13739:
add ax, 3EAh
cmp ax, word_1ED94
jge short loc_13771
call sub_FAED
call _randring2_next16
mov bx, 280h
xor dx, dx
div bx
@ -18456,7 +18350,7 @@ loc_14083:
jnz short loc_140AC
mov PaletteTone, 64h ; 'd'
call far ptr palette_show
call sub_FAED
call _randring2_next16
and ax, 3FFh
add ax, 14h
add word_250E4, ax
@ -18486,7 +18380,7 @@ loc_140D4:
inc word_1EDA2
test byte ptr word_1EDA2, 1
jnz short loc_140F2
call sub_FAED
call _randring2_next16
mov bx, 280h
xor dx, dx
div bx
@ -20119,7 +20013,7 @@ loc_14ED8:
mov ax, [bx]
add ax, 18h
push ax
call sub_FAC6
call _randring2_next8
push ax
push 87h
mov ax, si
@ -20219,13 +20113,13 @@ loc_14F8F:
loc_14FAE:
cmp di, 3
jl short loc_14F8F
call sub_FAED
call _randring2_next16
mov bx, 140h
xor dx, dx
div bx
add dx, 20h ; ' '
mov word_252F0, dx
call sub_FAC6
call _randring2_next8
mov ah, 0
add ax, 10h
mov word_252F2, ax
@ -20292,7 +20186,7 @@ loc_1505F:
mov ax, [bx]
add ax, 18h
push ax
call sub_FAC6
call _randring2_next8
push ax
push 87h
lea ax, [di+7Ah]
@ -21862,7 +21756,7 @@ loc_15DD7:
loc_15DF2:
push 7Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, word_254E6
push ax
@ -21872,7 +21766,7 @@ loc_15DF2:
push 40h
push 20h ; ' '
push 1Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, 1Eh
push ax
@ -21884,7 +21778,7 @@ loc_15E19:
cmp word_20650, 1B8h
jge short loc_15E7B
inc byte_25596
call sub_FAC6
call _randring2_next8
mov ah, 0
mov dl, byte_25596
mov dh, 0
@ -21905,7 +21799,7 @@ loc_15E19:
loc_15E4D:
push 7Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, word_254E6
push ax
@ -21915,7 +21809,7 @@ loc_15E4D:
push word ptr [bp+var_1]
push 20h ; ' '
push 1Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, 1Eh
push ax
@ -22082,7 +21976,7 @@ sub_15F6F proc near
jnz short loc_15F93
push word_253B6
push word_253B8
call sub_FAC6
call _randring2_next8
push ax
push 27h ; '''
push 55h ; 'U'
@ -22250,7 +22144,7 @@ loc_16122:
jnz short loc_16172
push word_253B6
push word_253B8
call sub_FAC6
call _randring2_next8
push ax
push 27h ; '''
push 50h ; 'P'
@ -22291,7 +22185,7 @@ sub_16176 proc near
jnz short loc_1619A
push word_253B6
push word_253B8
call sub_FAC6
call _randring2_next8
push ax
push 25h ; '%'
push 32h ; '2'
@ -22681,7 +22575,7 @@ loc_1652F:
loc_16540:
push word_253B6
push word_253B8
call sub_FAC6
call _randring2_next8
push ax
push 25h ; '%'
push 3Ch ; '<'
@ -22726,7 +22620,7 @@ loc_16589:
jnz short loc_165A3
push word_253B6
push word_253B8
call sub_FAC6
call _randring2_next8
push ax
push 27h ; '''
push 3Ch ; '<'
@ -22909,7 +22803,7 @@ loc_166BE:
jnz short loc_166DC
push word_253B6
push word_253B8
call sub_FAC6
call _randring2_next8
push ax
push 25h ; '%'
push 3Ch ; '<'
@ -23615,7 +23509,7 @@ arg_6 = word ptr 0Ah
mov bx, [bp+arg_2]
imul bx, 26h
mov word ptr [bx+7B5Ah], 0
call sub_FAC6
call _randring2_next8
mov bx, [bp+arg_2]
imul bx, 26h
mov [bx+7B5Fh], al
@ -23876,7 +23770,7 @@ loc_16F0F:
; ---------------------------------------------------------------------------
loc_16F19:
call sub_FAC6
call _randring2_next8
mov [bp+var_3], al
mov al, [bp+var_7]
mov ah, 0
@ -24032,7 +23926,7 @@ loc_17025:
; ---------------------------------------------------------------------------
loc_1705E:
call sub_FAED
call _randring2_next16
mov dl, [bp+var_7]
mov dh, 0
add dx, word_26C44
@ -24083,7 +23977,7 @@ loc_170C1:
; ---------------------------------------------------------------------------
loc_170CF:
call sub_FAED
call _randring2_next16
mov dl, [bp+var_7]
mov dh, 0
add dx, word_26C44
@ -25969,7 +25863,7 @@ loc_18170:
push word_26C58
push word_26C60
push 0Fh
call sub_FAD5
call _randring2_next8_and
add al, 38h ; '8'
push ax
push word_2066E
@ -26118,7 +26012,7 @@ loc_182DD:
mov [bx], dx
call grcg_setcolor pascal, (GC_RMW shl 16) + 13
push 7Fh
call sub_FAD5
call _randring2_next8_and
mov [bp+var_1], al
mov ah, 0
mov bx, word_2065C
@ -26784,7 +26678,7 @@ loc_1895D:
jnz short loc_18985
call _snd_se_play c, 10
mov word_2064E, 86h
call sub_FAC6
call _randring2_next8
mov byte ptr word_26CDA, al
jmp short loc_189DC
; ---------------------------------------------------------------------------
@ -26963,7 +26857,7 @@ loc_18B0D:
push word_26C5A
push word_26C62
push 3Fh ; '?'
call sub_FAD5
call _randring2_next8_and
add al, 20h ; ' '
push ax
push 20h ; ' '
@ -26972,7 +26866,7 @@ loc_18B0D:
push word_26C5A
push word_26C62
push 3Fh ; '?'
call sub_FAD5
call _randring2_next8_and
add al, 20h ; ' '
push ax
push 20h ; ' '
@ -27397,7 +27291,7 @@ var_3 = word ptr -3
add ax, 50h ; 'P'
mov word_26CE8, ax
mov word_26CEA, 4
call sub_FAC6
call _randring2_next8
mov byte_26CEC, al
jmp loc_19169
; ---------------------------------------------------------------------------
@ -27927,7 +27821,7 @@ loc_1941F:
; ---------------------------------------------------------------------------
loc_19430:
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 3
cwd
@ -28073,7 +27967,7 @@ loc_1953B:
mov byte_26CFA, 0
mov word_26C68, 1
mov word_20650, 0
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 3
cwd
@ -28149,7 +28043,7 @@ loc_195F8:
jle loc_198A8
mov word_26C68, 3
mov word_20650, 0
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 3
cwd
@ -28227,7 +28121,7 @@ loc_196A3:
jle loc_198A8
mov word_26C68, 5
mov word_20650, 0
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 3
cwd
@ -28308,7 +28202,7 @@ loc_19770:
mov word_26C68, 7
mov word_20650, 0
push 7
call sub_FAD5
call _randring2_next8_and
mov ah, 0
mov word_26C6A, ax
mov word_26CBE, 0
@ -28442,7 +28336,7 @@ loc_198A8:
mov word_2064E, 80h
mov word_26CBE, 0
mov word_20650, 0
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 3
cwd
@ -29419,7 +29313,7 @@ loc_1A1D5:
push ax
push word_26D00
push 3Fh ; '?'
call sub_FAD5
call _randring2_next8_and
add al, 20h ; ' '
push ax
push 20h ; ' '
@ -29537,7 +29431,7 @@ loc_1A30A:
mov ax, 0FFFFh
imul word_26CFE
mov word_26CFE, ax
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 5
cwd
@ -29608,7 +29502,7 @@ loc_1A3A3:
mov ax, 0FFFFh
imul word_26CFE
mov word_26CFE, ax
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 5
cwd
@ -30367,7 +30261,7 @@ loc_1AB43:
add bx, bx
cmp word ptr [bx-6D4Eh], 6Eh ; 'n'
jl short loc_1ABEE
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 50h ; 'P'
cwd
@ -31276,7 +31170,7 @@ sub_1B35F proc near
call sub_1B19D
cmp word_20650, 32h ; '2'
jnz short loc_1B39A
call sub_FAC6
call _randring2_next8
mov byte ptr word_26D7F+1, al
mov al, byte_1EEA4
mov ah, 0
@ -31550,7 +31444,7 @@ loc_1B592:
test byte ptr word_20650, 0Fh
jnz short loc_1B654
push 3
call sub_FAD5
call _randring2_next8_and
mov ah, 0
mov si, ax
mov bx, si
@ -32119,7 +32013,7 @@ loc_1BAC5:
push ax
push 20h ; ' '
push 1Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, 10h
push ax
@ -32427,13 +32321,13 @@ loc_1BDBD:
loc_1BDC4:
push 7
call sub_FAD5
call _randring2_next8_and
mov dl, byte_1EEA5
shl dl, 4
add al, dl
add al, 40h
mov byte ptr [bp+var_3], al
call sub_FAED
call _randring2_next16
mov bx, 170h
xor dx, dx
div bx
@ -32444,13 +32338,13 @@ loc_1BDC4:
push 0FFh
push 55h ; 'U'
push 1Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, 10h
push ax
call sub_10865
push si
call sub_FAED
call _randring2_next16
mov bx, 140h
xor dx, dx
div bx
@ -32460,7 +32354,7 @@ loc_1BDC4:
push 0FFh
push 55h ; 'U'
push 1Fh
call sub_FAD5
call _randring2_next8_and
mov ah, 0
add ax, 10h
push ax
@ -32547,7 +32441,7 @@ loc_1BEA6:
; ---------------------------------------------------------------------------
loc_1BEB2:
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 3
cwd
@ -32629,7 +32523,7 @@ loc_1BF3A:
jz short loc_1BF78
loc_1BF53:
call sub_FAED
call _randring2_next16
mov bx, 180h
xor dx, dx
div bx
@ -32794,7 +32688,7 @@ loc_1C086:
; ---------------------------------------------------------------------------
loc_1C0A5:
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 5
cwd
@ -32827,7 +32721,7 @@ loc_1C0E4:
loc_1C0F2:
inc byte_26D4E
call sub_FAC6
call _randring2_next8
mov ah, 0
mov bx, 3
cwd
@ -37037,72 +36931,7 @@ word_20164 dw ?
word_20166 dw ?
byte_20168 db ?
byte_20169 db ?
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
dd ? ;
byte_2026A db ?
db ?
include th02/math/randring[bss].asm
mikoconfig dd ?
db ? ;
db ? ;

View File

@ -0,0 +1,17 @@
; void randring_fill(void)
public _randring_fill
_randring_fill proc near
push si
mov si, RANDRING_SIZE - 1
@@loop:
call IRand
mov _randring[si], al
dec si
jge short @@loop
if GAME ge 4
mov _randring_p, 0
endif
pop si
ret
_randring_fill endp

View File

@ -0,0 +1,53 @@
RANDRING_NEXT_DEF_NOMOD macro instance, dist
; void randring_next16(void)
public _randring&instance&_next16
_randring&instance&_next16 proc dist
xor bh, bh
mov bl, _randring_p
add bx, offset _randring
inc _randring_p
mov ax, [bx]
ret
_randring&instance&_next16 endp
nop
; void randring_next16_and(unsigned short mask)
public _randring&instance&_next16_and
_randring&instance&_next16_and proc dist
arg @@mask:word
push bp
mov bp, sp
xor bh, bh
mov bl, _randring_p
add bx, offset _randring
inc _randring_p
mov ax, [bx]
and ax, @@mask
pop bp
ret 2
_randring&instance&_next16_and endp
endm
RANDRING_NEXT_DEF macro instance, dist
RANDRING_NEXT_DEF_NOMOD instance, dist
; void randring_next16_mod(unsigned short n)
public _randring&instance&_next16_mod
_randring&instance&_next16_mod proc dist
arg @@n:word
push bp
mov bp, sp
xor bh, bh
mov bl, _randring_p
add bx, offset _randring
inc _randring_p
mov ax, [bx]
xor dx, dx
div @@n
mov ax, dx
pop bp
ret 2
_randring&instance&_next16_mod endp
endm

View File

@ -1,2 +1,3 @@
GAME = 3
include defconv_pascal.inc
include th03/math/randring_next.inc

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
RANDRING_NEXT_DEF macro instance
; void randring_next16(void)
public _randring&instance&_next16
_randring&instance&_next16 proc near
mov bx, _randring_p
mov ax, word ptr _randring[bx]
inc byte ptr _randring_p
ret
_randring&instance&_next16 endp
nop
; void randring_next16_and(unsigned char mask)
public _randring&instance&_next16_and
_randring&instance&_next16_and proc near
arg @@mask:byte
mov bx, _randring_p
mov ax, word ptr _randring[bx]
inc byte ptr _randring_p
mov bx, sp
and ax, ss:[bx+2]
ret 2
_randring&instance&_next16_and endp
nop
; void randring_next16_mod(unsigned short n)
public _randring&instance&_next16_mod
_randring&instance&_next16_mod proc near
arg @@n:word
mov bx, _randring_p
mov ax, word ptr _randring[bx]
inc byte ptr _randring_p
xor dx, dx
mov bx, sp
div word ptr ss:[bx+2]
mov ax, dx
ret 2
_randring&instance&_next16_mod endp
endm

View File

@ -2,3 +2,4 @@ GAME = 4
include defconv_pascal.inc
include th04/formats/map.inc
include th04/math/randring_next.inc

File diff suppressed because it is too large Load Diff

View File

@ -2,3 +2,4 @@ GAME = 5
include defconv_pascal.inc
include th04/formats/map.inc
include th04/math/randring_next.inc

File diff suppressed because it is too large Load Diff