; This is the ASM source code to MAKEFREQ, written by Chad Robinson on 8/9/93
; This is MAKEFREQ version 1.0 - the public release version
;
; This file is designed to be assembled with the A86 shareware assembler


jmp     start

hellomsg        db      0FEh, ' MAKEFREQ, Written by Chad Robinson'
                db      ' on 8/9/93.  Public Domain.'
                db      0Dh, 0Ah, '$'
pathfile        db      'FILEPATH.EZY', 0       ; Where to find the pathnames
inhandle        dw      ?                       ; For filepath.ezy's handle
freqfile        db      'FREQ.DIR', 0           ; Output filename
outhandle       dw      ?                       ; For output filename's handle

notfound        db      0FEh, ' Cannot find FILEPATH.EZY', 0Dh, 0Ah
                db      0FEh, ' Exiting with Errorlevel 1', 0Dh, 0Ah, '$'


; Structure length: 79 bytes
pathlen         db      ?                       ; Length of pathname
filepath        db      60 dup (?)              ; Actual pathname
security        dw      ?                       ; Security to DL from area
flags           dd      ?                       ; Flags as above (1 byte/flag)
ularea          dw      ?                       ; Upload area template
pword           db      9 dup (?)               ; Password to access area
attr            db      ?                       ; Attribute for area
crlf            db      0Dh, 0Ah

start:          mov     ah, 09h
                mov     dx, offset hellomsg
                int     21h

                mov     ah, 41h                 ; Delete output file so write-
                mov     dx, offset freqfile     ; over errors don't occur
                int     21h

                mov     ax, 3D00h               ; Open file for READ ONLY
                mov     dx, offset pathfile     ; file to open is FILEPATH.EZY
                int     21h
                mov     inhandle, ax            ; Store file handle in inhandle
                jnc     keepon                  ; no errors occurred

                mov     ah, 09h
                mov     dx, offset notfound     ; Display 'file not found'
                int     21h                     ; message
                mov     ax, 4C01h               ; Errorlevel 1 = FNF
                int     21h

keepon:         mov     ah, 3Ch
                mov     dx, offset freqfile
                mov     cx, 00100000b
                int     21h
                mov     ax, 3D01h               ; Open file for READ ONLY
                mov     dx, offset freqfile     ; file to open is FILEPATH.EZY
                int     21h
                mov     outhandle, ax           ; Store handle in outhandle

fileloop:       mov     ah, 3Fh                 ; Read in 79 bytes = 1 record
                mov     bx, inhandle            ; from FILEPATH.EZY
                mov     cx, 79                  ;
                mov     dx, offset pathlen      ;
                int     21h
                cmp     ax, 0000h               ; If 0, end of file was reached
                jne     floop1
                jmp     theend

floop1:         mov     al, attr                ; Check attribute byte
                and     al, 2                   ; Is it FNF or not enough sec?
                jz      fileloop                ; No security = skip area
                mov     cl, pathlen
                cmp     cl, 00h
                jne     okaycont
                jmp     fileloop

okaycont:       mov     ah, 40h
                mov     bx, outhandle
                xor     ch, ch
                mov     cl, pathlen             ; bytes to write = lengh of
                mov     dx, offset filepath
                int     21h                     ; pathstring
                mov     ah, 40h
                mov     bx, outhandle
                mov     dx, offset crlf         ; add a CR+LF to the end
                xor     ch, ch
                mov     cl, 2                   ; bytes to write = lengh of
                int     21h                     ; pathstring

                jmp fileloop

theend:         mov     ah, 3Eh                 ; Close the output file
                mov     bx, outhandle
                int     21h
                mov     ah, 3Eh
                mov     bx, inhandle            ; Close the input file
                int     21h
                mov     ax, 4C00h               ; Program successful
                int     21h

