Skip to content

Commit

Permalink
[Reduction] #171: _bgm_bell_org
Browse files Browse the repository at this point in the history
[Binary change] db 0 → nop before the function in every affected executable.
  • Loading branch information
nmlgc committed Aug 25, 2014
1 parent 36a4a02 commit 674ecce
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 410 deletions.
1 change: 1 addition & 0 deletions ReC98.inc
Expand Up @@ -6,6 +6,7 @@ locals
include libs/BorlandC/RULES.ASI
include libs/master.lib/func.inc
include libs/master.lib/super.inc
include libs/master.lib/bgm.inc

nopcall macro func
if LDATA
Expand Down
49 changes: 25 additions & 24 deletions libs/BorlandC/H_LDIV.ASM
Expand Up @@ -2,6 +2,7 @@
; Changes include:
; * removal of RULES.ASI to eliminate redundancy
; * removal of the 'CODE' segment declaration (for obvious reasons)
; * the @@ prefix on any local labels to avoid name collisions with master.lib

;[]-----------------------------------------------------------------[]
;| H_LDIV.ASM -- long division routine |
Expand Down Expand Up @@ -84,20 +85,20 @@ common:
mov cx,16[bp] ; get the second high word

or cx,cx
jnz slow@ldiv ; both high words are zero
jnz @@slow@ldiv ; both high words are zero

or dx,dx
jz quick@ldiv
jz @@quick@ldiv

or bx,bx
jz quick@ldiv ; if cx:bx == 0 force a zero divide
jz @@quick@ldiv ; if cx:bx == 0 force a zero divide
; we don't expect this to actually
; work

slow@ldiv:
@@slow@ldiv:

test di,1 ; signed divide?
jnz positive ; no: skip
jnz @@positive ; no: skip
;
; Signed division should be done. Convert negative
; values to positive and do an unsigned division.
Expand All @@ -106,19 +107,19 @@ slow@ldiv:
; that bit will determine the sign of the result.
;
or dx,dx ; test sign of dividend
jns onepos
jns @@onepos
neg dx
neg ax
sbb dx,0 ; negate dividend
or di,0Ch
onepos:
@@onepos:
or cx,cx ; test sign of divisor
jns positive
jns @@positive
neg cx
neg bx
sbb cx,0 ; negate divisor
xor di,4
positive:
@@positive:
mov bp,cx
mov cx,32 ; shift counter
push di ; save the flags
Expand All @@ -142,22 +143,22 @@ positive:
;
xor di,di ; fake a 64 bit dividend
xor si,si ;
xloop:
@@xloop:
shl ax,1 ; shift dividend left one bit
rcl dx,1
rcl si,1
rcl di,1
cmp di,bp ; dividend larger?
jb nosub
ja subtract
jb @@nosub
ja @@subtract
cmp si,bx ; maybe
jb nosub
subtract:
jb @@nosub
@@subtract:
sub si,bx
sbb di,bp ; subtract the divisor
inc ax ; build quotient
nosub:
loop xloop
@@nosub:
loop @@xloop
;
; When done with the loop the four register value look like:
;
Expand All @@ -166,30 +167,30 @@ nosub:
;
pop bx ; get control bits
test bx,2 ; remainder?
jz usequo
jz @@usequo
mov ax,si
mov dx,di ; use remainder
shr bx,1 ; shift in the remainder sign bit
usequo:
@@usequo:
test bx,4 ; needs negative
jz finish
jz @@finish
neg dx
neg ax
sbb dx,0 ; negate
finish:
@@finish:
pop di
pop si
pop bp
retf 8

quick@ldiv:
@@quick@ldiv:
div bx ; unsigned divide
; DX = remainder AX = quotient
test di,2 ; want remainder?
jz quick@quo
jz @@quick@quo
xchg ax,dx

quick@quo:
@@quick@quo:

xor dx,dx
jmp short finish
jmp short @@finish
143 changes: 143 additions & 0 deletions libs/master.lib/bgm.inc
@@ -0,0 +1,143 @@
BGM_STAT_PLAY equ 1 ;リターンコード
BGM_STAT_MUTE equ 0
BGM_STAT_REPT equ 1
BGM_STAT_1TIM equ 0
BGM_STAT_ON equ 1
BGM_STAT_OFF equ 0
BGM_MES_ON equ 1 ;パラメータ
BGM_MES_OFF equ 0
BGM_MUSIC equ 1
BGM_SOUND_ equ 2
; ↑'BGM_SOUND'より変更
BGM_COMPLETE equ NoError ; エラーナンバー
BGM_FILE_ERR equ FileNotFound
BGM_FORMAT_ERR equ InvalidFormat
BGM_OVERFLOW equ InsufficientMemory
BGM_TOOMANY equ InvalidData
BGM_NO_MUSIC equ InvalidData
BGM_NOT_PLAY equ GeneralFailure
BGM_NOT_STOP equ GeneralFailure
BGM_EXTENT_ERR equ InvalidData

ON equ 1
OFF equ 0
TRUE equ 1
FALSE equ 0
FINISH equ 1
NOTFIN equ 0
SEND equ 0
VEND equ 0
BEEP_SW equ 37h ;ポートアドレス・設定値
BEEP_ON equ 06h
BEEP_OFF equ 07h
BEEP_CNT equ 3fdbh
BEEP_MODE equ 3fdfh
BEEP_CNT_AT equ 42h
BEEP_MODE_AT equ 43h
INTCTRL equ 00h
EOI equ 20h
IMR equ 02h
TIMERMASK equ 01h
TIMER_CNT equ 71h
TIMER_SET equ 77h
CLOCK_CHK equ 42h
PMAX equ 3 ;パート数
ALL_PART equ 7 ;演奏終了チェック用
BUFMAX equ 4096 ;1パートのバッファ長
SBUFMAX equ 256 ;効果音1音のバッファ長
MINNOTE equ 32 ;最小音符
MINLCNT equ 1 ;最小カウントデータ
DEFTEMPO equ 120 ;デフォルトテンポ
TEMPOMAX equ 240 ;最大テンポ
TEMPOMIN equ 30 ;最小テンポ
DEFOCT equ 4 ;デフォルトオクターブ
DEFLEN equ 4 ;デフォルト音長
DEFLCNT equ 8 ;デフォルト音長カウント値
DIVNUM equ 8 ;1オクターブの音数
REST equ 'H' ;休符
UNDF equ 100 ;未定義音符
MMAX equ 16 ;最大曲数
SMAX equ 16 ;最大効果音数
TIMER equ 1 ;タイマ = 1ms
TVAL8ORG equ 1997 ;タイマ設定値 8MHz(1msec)
TVAL10ORG equ 2458 ;タイマ設定値 10MHz(1msec)
TVALATORG_RTC equ 16 ;タイマ設定値 8192Hz*2(AT互換機) (1msec)
TVALATORG equ 1193 ;タイマ設定値 1193.18K(AT互換機) (1msec)
TVAL8ORG2 equ 19968 ;タイマ設定値 8MHz(10msec)
TVAL10ORG2 equ 24576 ;タイマ設定値 10MHz(10msec)
;TVALATORG2 equ 41 ;タイマ設定値 4096Hz(AT互換機) (10msec)
;TVALATORG2 equ 11931 ;タイマ設定値 1193.18K(AT互換機) (10msec)
TCNTMAX equ 20 ;割り込み何回に 1回処理するか

;
;ステータス構造体
;
SBSTAT struc
bmusic dw ? ;演奏処理 ON/OFF
bsound dw ? ;効果音処理 ON/OFF
bplay dw ? ;演奏中か否か
beffect dw ? ;効果音出力中か否か
brepeat dw ? ;リピート演奏か否か
bmnum dw ? ;登録曲数
brnum dw ? ;セレクト中曲番号
btempo dw ? ;現在のテンポ
bsnum dw ? ;登録効果音数
bfnum dw ? ;セレクト中効果音番号
SBSTAT ends

;
;グローバルデータ構造体
;
SGLB struc
simr dw ? ;interrupt mask register
; ↑'imr'より変更
tval dw ? ;タイマ設定値
tp dw ? ;テンポ
rflg dw ? ;BGM ON/OFF
pnum dw ? ;パート数
pcnt dw ? ;パートカウンタ
fin dw ? ;パート終了フラグ
repsw dw ? ;リピート ON/OFF
; ↑'rep'より変更
tcnt dw ? ;処理カウンタ(4回に 1回処理)
bufsiz dw ? ;楽譜バッファのサイズ
buflast dw ? ;楽譜バッファのラスト
mnum dw ? ;登録曲数
mcnt dw ? ;セレクト中曲番号
track dw MMAX dup(?) ;曲のトラックナンバー
pmask dw ? ;パートマスク情報
; ↑'mask'より変更
mtp dw MMAX dup(?) ;曲ごとのテンポ情報
effect dw ? ;効果音 ON/OFF
snum dw ? ;登録効果音数
scnt dw ? ;セレクト中効果音番号
music dw ? ;演奏処理 ON/OFF
sound dw ? ;効果音処理 ON/OFF
init dw ? ;イニシャライズ実行フラグ
clockbase dd ? ;tempo120時のタイマカウント
SGLB ends

;
;パート構造体
;
SPART struc
pptr dd ? ;楽譜バッファポインタ
; ↑'ptr'より変更
mbuf dd ? ;楽譜バッファ
note dw ? ;現在の音符
oct dw ? ;現在のオクターブ
len dw ? ;現在の音長
dflen dw ? ;デフォルトの音長
lcnt dw ? ;音長カウンタ
msk dw ? ;パートマスク ON/OFF
; ↑'mask'より変更
tnt dw ? ;テヌート ON/OFF
SPART ends

;
;効果音構造体
;
SESOUND struc
sptr dd ? ;効果音データポインタ
sbuf dd ? ;効果音データバッファ
SESOUND ends
71 changes: 71 additions & 0 deletions libs/master.lib/bgm_bell_org.asm
@@ -0,0 +1,71 @@
; master library - BGM
;
; Description:
;
;
; Function/Procedures:
; void _bgm_bell_org(void);
;
; Parameters:
;
;
; Returns:
;
;
; Binding Target:
; Microsoft-C / Turbo-C / Turbo Pascal
;
; Running Target:
; PC-9801V
;
; Requiring Resources:
; CPU: V30
;
; Notes:
;
;
; Assembly Language Note:
;
;
; Compiler/Assembler:
; TASM 3.0
; OPTASM 1.6
;
; Author:
; femy(淀 文武) : オリジナル・C言語版
; steelman(千野 裕司) : アセンブリ言語版
; 恋塚
;
; Revision History:
; 93/12/19 Initial: b_b_org.asm / master.lib 0.22 <- bgmlibs.lib 1.12
; 94/ 4/11 [M0.23] AT互換機対応

func _BGM_BELL_ORG
test Machine_State,10h
jnz short @@PCAT

@@PC98:
xor AX,AX
mov ES,AX
test byte ptr ES:[0501H],80h
mov BX,TVAL8ORG/2
jnz short @@CLOCK8MHZ
mov BX,TVAL10ORG/2
@@CLOCK8MHZ:
;タイマカウント値設定
mov DX,BEEP_CNT
mov AL,BL
out DX,AL ; 98
mov AL,BH
out DX,AL ; 98
;ビープOFF
mov AL,BEEP_OFF
out BEEP_SW,AL ; 98
ret
@@PCAT:
;ビープOFF
in AL,61h
and AL,not 3
out 61h,AL ; AT
ret
endfunc

0 comments on commit 674ecce

Please sign in to comment.