Skip to content

Commit

Permalink
[th02/zun_res] Reduce all known library functions
Browse files Browse the repository at this point in the history
From what I can tell, this program does exactly three things:
• preparing the initial high score list
• writing default settings to HUUMA.CFG
• and allocating the game's resident configuration structure and writing its
  segment address to bytes 6-7 of HUUMA.CFG

All that results in a COM file of 6.84 KiB, 83% of which is library code.
That's why C was once seen as a bloated high-level language as well.
  • Loading branch information
nmlgc committed Dec 1, 2014
1 parent 7d81d76 commit 3f1c1eb
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 4,183 deletions.
70 changes: 53 additions & 17 deletions libs/BorlandC/pathops.asm
@@ -1,3 +1,13 @@
if LDATA
issbcsValXOR macro
xor cx, cx
endm
else
issbcsValXOR macro
xor dx, dx
endm
endif

pathops_10010 proc near
push ax
push cx
Expand Down Expand Up @@ -29,7 +39,11 @@ pathops_10010 proc near

@@pathops_1003F:
mov si, offset ___path_dbcs_default
if LDATA
mov ax, seg ___path_dbcs_default
else
mov ax, ds
endif

@@pathops_10045:
mov word ptr ___path_dbcs_vector, si
Expand All @@ -52,8 +66,8 @@ pathops_10010 endp


public ___path_isdbcsleadbyte
___path_isdbcsleadbyte proc far
@@arg_0 = byte ptr 6
___path_isdbcsleadbyte proc
@@arg_0 = byte ptr (cPtrSize + 2)

push bp
mov bp, sp
Expand Down Expand Up @@ -85,49 +99,67 @@ ___path_isdbcsleadbyte endp


public ___path_issbcs
___path_issbcs proc far
var_4 = dword ptr -4
arg_0 = word ptr 6
arg_2 = word ptr 8
arg_4 = word ptr 0Ah
___path_issbcs proc
var_4 = DPTR_ -(dPtrSize)
arg_0 = DPTR_ +(cPtrSize + 2)
arg_4 = word ptr +(cPtrSize + 2 + dPtrSize)

push bp
mov bp, sp
sub sp, 4
sub sp, dPtrSize
push si
push di
xor cx, cx
mov dx, [bp+arg_2]
mov ax, [bp+arg_0]
issbcsValXOR
if LDATA
mov dx, word ptr [bp+arg_0+2]
mov ax, word ptr [bp+arg_0]
mov word ptr [bp+var_4+2], dx
mov word ptr [bp+var_4], ax
else
mov ax, [bp+arg_0]
mov word ptr [bp+var_4], ax
endif

@@pathops_10094:
les bx, [bp+var_4]
cmp byte ptr es:[bx], 0
LES_ bx, [bp+var_4]
cmp byte ptr ES_[bx], 0
jnz short @@pathops_100A1
xor cx, cx
issbcsValXOR
jmp short @@pathops_100CF

@@pathops_100A1:
if LDATA
cmp cx, 1
jnz short @@pathops_100AB
mov cx, 2
else
cmp dx, 1
jnz short @@pathops_100AB
mov dx, 2
endif
jmp short @@pathops_100C2

@@pathops_100AB:
les bx, [bp+var_4]
mov al, es:[bx]
LES_ bx, [bp+var_4]
if LDATA
mov al, ES_[bx]
push ax
else
push word ptr [bx]
endif
call ___path_isdbcsleadbyte
pop cx
or ax, ax
jz short @@pathops_100C0
if LDATA
mov cx, 1
else
mov dx, 1
endif
jmp short @@pathops_100C2

@@pathops_100C0:
xor cx, cx
issbcsValXOR

@@pathops_100C2:
mov ax, word ptr [bp+var_4]
Expand All @@ -137,7 +169,11 @@ arg_4 = word ptr 0Ah
jmp short @@pathops_10094

@@pathops_100CF:
if LDATA
or cx, cx
else
or dx, dx
endif
jnz short @@pathops_100D8
mov ax, 1
jmp short @@pathops_100DA
Expand Down
10 changes: 6 additions & 4 deletions libs/BorlandC/setargv.asm
Expand Up @@ -65,7 +65,7 @@ endif
pop word ptr SavedReturn
pop word ptr SavedDS2
pop word ptr SavedReturn2
mov SavedDS, ds
mov cs:SavedDS, ds
mov SavedSI, si
mov SavedDI, di
cld
Expand Down Expand Up @@ -623,8 +623,10 @@ EndArgument label near
; Invalid program name

BadProgName label near
if LDATA
nop ; PC-98 / Japanese-specific
nop ; PC-98 / Japanese-specific
endif
jmp __abort

; Character test function used in SetArgs
Expand Down Expand Up @@ -659,7 +661,7 @@ NextChar0 label near
push dx
push ds
push es
mov ds, SavedDS
mov ds, cs:SavedDS
push ax
nopcall ___path_isdbcsleadbyte
or ax, ax
Expand Down Expand Up @@ -700,7 +702,7 @@ BuildArgv label near
pop cx
xor dh, dh ; PC-98 / Japanese-specific
add cx, dx ; CX = Argument area size
mov ds, SavedDS
mov ds, cs:SavedDS
mov _argc@, bx
inc bx ; argv ends with a NULL pointer
add bx, bx ; argc * 2 (LDATA = 0)
Expand Down Expand Up @@ -741,7 +743,7 @@ endif ; ifdef WILD

; Restore caller context and exit

mov ds,SavedDS
mov ds,cs:SavedDS
mov si,SavedSI
mov di,SavedDI
push word ptr SavedReturn2
Expand Down

0 comments on commit 3f1c1eb

Please sign in to comment.