1
0
mirror of https://github.com/pfusik/xasm.git synced 2025-01-19 15:30:12 +00:00

X-BOOT 5.0.

This commit is contained in:
Piotr Fusik 2000-02-10 16:03:56 +01:00
parent 6a5daaff83
commit 88362dba94

421
xboot.asm
View File

@ -1,4 +1,4 @@
; ><-B00T IV b. Fox ; ><-B00T V b. Fox
IDEAL IDEAL
P386 P386
@ -6,19 +6,42 @@
CODESEG CODESEG
zero db 100h dup(?) zero db 100h dup(?)
blen = 60*1024 blen = 59*1024
m_pro = 1 ; /p switch m_pro = 1 ; /p switch
m_wild = 2 ; obx has wild char m_errs = 2 ; error/warning occured while current file
m_errs = 4 ; error/warning occured while current file m_file = 4 ; single file (atr name for one file given)
m_donta = 8 ; don't change output ext to atr m_lfn = 8 ; LFN search
ffnam = 80h+1eh
eol equ 13,10 eol equ 13,10
eot equ 13,10,'$' eot equ 13,10,'$'
MACRO lda _rg ;shorter than 'mov (e)ax, _rg' struc finddata16
db 21 dup(?)
attr db ?
time dw ?
date dw ?
fsize dd ?
fname db 13 dup(?)
ends
struc filetime32
dd ?,?
ends
struc finddata32
attr dd ?
creat filetime32 ?
acces filetime32 ?
write filetime32 ?
fsizeh dd ?
fsizel dd ?
dd ?,?
fname db 260 dup(?)
aname db 14 dup(?)
ends
MACRO lda _rg ; shorter than 'mov (e)ax, _rg'
_rge SUBSTR <_rg>, 1, 1 _rge SUBSTR <_rg>, 1, 1
IFIDNI _rge, <e> IFIDNI _rge, <e>
xchg eax, _rg xchg eax, _rg
@ -27,7 +50,7 @@ ELSE
ENDIF ENDIF
ENDM ENDM
MACRO sta _rg ;shorter than 'mov _rg, (e)ax' MACRO sta _rg ; shorter than 'mov _rg, (e)ax'
_rge SUBSTR <_rg>, 1, 1 _rge SUBSTR <_rg>, 1, 1
IFIDNI _rge, <e> IFIDNI _rge, <e>
xchg _rg, eax xchg _rg, eax
@ -36,7 +59,7 @@ ELSE
ENDIF ENDIF
ENDM ENDM
MACRO dos _func MACRO dos _func ; call DOS function
IFNB <_func> IFNB <_func>
IF _func and 0ff00h IF _func and 0ff00h
mov ax, _func mov ax, _func
@ -69,7 +92,7 @@ ENDIF
jmp xdisk jmp xdisk
ENDM ENDM
MACRO print _text MACRO print _text ; print ascii$ text
IFNB <_text> IFNB <_text>
mov dx, offset _text mov dx, offset _text
ENDIF ENDIF
@ -82,126 +105,191 @@ start:
mov [spt], sp mov [spt], sp
print hello print hello
mov si, 81h ; pobierz argumenty ; Get arguments: obxnam, atrnam & /p switch
mov di, offset obxnam ; Set onam & anam to end of filenames
mov ch, -1 mov si, 81h
mov bx, offset onam
arg1: lodsb arg1: lodsb
cmp al, ' ' cmp al, ' '
je arg1 ; spacje omijamy je arg1 ; skip spaces
cmp al, '-'
je swit
cmp al, '/' cmp al, '/'
jne nswit jne nswit
lodsb ; '/' - switch ; Switch
swit: lodsb
and al, 0dfh and al, 0dfh
cmp al, 'P' cmp al, 'P'
jne usg jne usg
or [flags], m_pro ; '/P' or [flags], m_pro ; '/P'
jmp arg1 jmp arg1
nswit: cmp al, 0dh nswit: cmp al, 0dh
je argx je argx
cmp di, offset atrnam ; Filename
ja usg ; byly juz dwie nazwy cmp bx, offset enam
jae usg ; two names already parsed
spath: mov dl, -1 ; dolaczaj rozsz. mov di, [bx]
cmp di, offset atrnam mov ah, '"'
jnb snam1 cmp al, ah
and [flags], not m_wild je qname ; "file name with spaces"
mov [onam], di ; onam - adres nazwy PLIKU .obx mov ah, ' '
snam1: cmp di, offset atrnam gname: stosb ; copy name
ja snam2 qname: lodsb
cmp al, '*' ; w obx sprawdzaj wildy cmp al, ah ; space/'"', eol and '/' terminate name
je wildch je xname
cmp al, '?'
jne snam2
wildch: or [flags], m_wild
snam2: cmp al, '.'
jne npoint
xor dl, dl ; jest rozszerzenie - nie dolaczaj .obx
npoint: stosb ; przepisz nazwe
lodsb
cmp al, ' ' ; spacja lub eol konczy
je snamx
cmp al, 0dh cmp al, 0dh
je snamx je bname
cmp al, '/' cmp al, '/'
je snamx ; '/' tez konczy jne gname
cmp [byte di-1], '\' bname: dec si
je spath xname: mov [bx], di ; save end of name ptr
jmp snam1 inc bx
inc bx
mov [byte di], 0
jmp arg1
; Usage
usg: print usgtxt usg: print usgtxt
dos 4c03h dos 4c03h
snamx: mov eax, 'XBO.' ; End of arguments
cmp di, offset atrnam argx: cmp bx, offset anam
jb adobx jb usg ; no obxnam given
test [flags], m_wild
jz atrnwl ; Find where obx FILE name begins
mov al, '\' mov di, [onam]
cmp al, [di-1] lea cx, [di+1+zero-obxnam]
je panam fofna1: dec di
stosb cmp [byte di], '\'
panam: mov [anam], di je fofnax
jmp nadext cmp [byte di], ':'
atrnwl: test dl, dl loopne fofna1
jz adatr ; jest podane rozszerzenie - fofnax: inc di
or [flags], m_donta ; nie zmieniaj go na atr mov [ofna], di
adatr: mov eax, 'RTA.'
adobx: test dl, dl ; Is atr given?
jz nadext cmp bx, offset anam
stosd ja atrgvn ; atr given
nadext: xor al, al
stosb ; Only obx given
mov [nfin], di ; Move path of obx to atrnam
dec si mov si, offset obxnam
cmp di, offset atrnam
mov di, offset atrnam mov di, offset atrnam
jb jarg1 mobat1: lodsb
inc di stosb
jarg1: jmp arg1 cmp al, '\'
je mobat2
cmp al, ':'
jne mobat3
mobat2: mov [anam], di
mobat3: test al, al
jnz mobat1
mov di, [anam]
mov [byte di], 0
jmp srvobx
argx: cmp di, offset atrnam ; Atr given
jb usg ; nie ma nazwy ; Delete trailing '\' if not "\" or "C:\"
ja jesatr atrgvn: mov di, [anam]
mov cx, [nfin] dec di
test [flags], m_wild cmp [byte di], '\'
jz nowil1 ; jak jeden plik, to przepiszemy cala nazwe jne atrg1
mov cx, [onam] ; jak wiele, to tylko sciezke mov [anam], di
nowil1: mov si, offset obxnam cmp di, offset atrnam
sub cx, si jbe atrg1
rep movsb cmp [byte di-1], ':'
mov [nfin], di je atrg1
jesatr: mov [byte di], 0
atrg1:
; Check if it is file or dir
mov dx, offset atrnam
xor bx, bx ; try LFN function
stc
dos 7143h
jnc chkafd
cmp ax, 7100h ; LFN not supported
jne afile ; possibly file/dir doesn't exist -> file
dos 43h ; call MS-DOS function 4300h
jc afile ; failed -> file
chkafd: test cl, 10h
jnz adir
; It is file
; Add .atr extension, if none
afile: or [flags], m_file
mov di, [anam]
lea cx, [di+zero-atrnam]
mov eax, 'rta.'
call adext
jmp srvobx
; It is dir
; Add trailing '\'
adir: mov di, [anam]
mov [byte di], '\'
inc [anam]
test [flags], m_wild ; Serve obx
jz nowild ; Add .obx extension, if none
xor cx, cx srvobx: mov di, [onam]
lea cx, [di+zero-obxnam]
mov eax, 'xbo.'
call adext
; Find first file
mov dx, offset obxnam mov dx, offset obxnam
mov ah, 4eh ; jak wiele, to szukamy mov cx, 7 ; try LFN
mov si, 1
mov di, offset f32
stc
dos 714eh
jnc flfn
cmp ax, 7100h ; LFN not supported
jne nofil
xor cx, cx ; call MS-DOS function 4Eh
dos 4eh
jnc main1
nofil: print e_nofil ; "No file found"
dos 4c02h
flfn: or [flags], m_lfn ; LFN successfull
mov [fhand], ax
; Main loop - convert found file
main1: and [flags], not m_errs main1: and [flags], not m_errs
mov [ohand], 0 mov [ohand], 0
mov [ahand], 0 mov [ahand], 0
mov [len], lodlen+endlen mov [len], lodlen+endlen
dos
jc fin ; Move name from finddata to obxnam
mov si, 80h+1eh mov si, offset (finddata16 80h).fname
mov di, [anam] test [flags], m_lfn
mov bx, [onam] jz nolfn1
mov si, offset f32.fname
nolfn1: mov di, [ofna]
mona1: lodsb mona1: lodsb
stosb stosb
mov [bx], al
inc bx
test al, al test al, al
jnz mona1 jnz mona1
mov [nfin], di
nowild: mov si, offset obxnam ; Print "file.obx"
call printz ; file.obx mov si, offset obxnam
mov dx, offset obxnam call printz
; Open obx for reading
mov bp, offset e_open mov bp, offset e_open
file 3d00h ; open for reading mov dx, offset obxnam ; MS-DOS
mov ax, 3d00h
test [flags], m_lfn
jz nolfn2
mov si, dx ; LFN
xor bx, bx
mov dx, 1
mov ax, 716ch
nolfn2: file
mov [ohand], ax mov [ohand], ax
; Check if Atari executable
call xreadh call xreadh
jb enate jb enate
cmp [head], -1 cmp [head], -1
@ -214,39 +302,57 @@ nowild: mov si, offset obxnam
enate: mov dx, offset e_nota enate: mov dx, offset e_nota
jmp error jmp error
nenate: nenate:
; Set default run address at first block
mov ax, [head] mov ax, [head]
mov [l1runl], al mov [l1runl], al
mov [l2runl], al mov [l2runl], al
mov [l1runh], ah mov [l1runh], ah
mov [l2runh], ah mov [l2runh], ah
print arrow ; -> ; Print "->"
test [flags], m_donta print arrow
jnz jatrex
mov di, [nfin] ; Atr FILE name given?
mov si, di test [flags], m_file
cetatr: dec si jnz sfile
cmp [byte si], '\' ; No: move name from obx, replacing extension with ".atr"
je cetafn mov si, [ofna]
cmp [byte si], '.' mov di, [anam]
jne cetatr mona2: lodsb
mov di, si stosb
cetafn: mov eax, 'RTA.' cmp al, '.'
jne mona2
mov eax, 'rta'
stosd stosd
mov [byte di], 0 sfile:
jatrex:
; Print "file.atr"
mov si, offset atrnam mov si, offset atrnam
call printz ; file.atr call printz ; file.atr
xor cx, cx
mov dx, offset atrnam
mov bp, offset e_creat
file 3ch ; create
mov [ahand], ax
print kropki ; ...
; Create atr file
mov bp, offset e_creat
mov dx, offset atrnam
xor cx, cx
mov ax, 3c00h
test [flags], m_lfn
jz nolfn3
mov si, dx
mov bx, 1
mov dx, 12h ; create or truncate
mov ax, 716ch
nolfn3: file
mov [ahand], ax
; Print "..."
print kropki
; Write atr header
mov cx, beglen mov cx, beglen
mov dx, offset begin mov dx, offset begin
call xwrite call xwrite
; Write loader in boot sector
mov cx, lodlen mov cx, lodlen
mov dx, offset stdlod mov dx, offset stdlod
test [flags], m_pro test [flags], m_pro
@ -255,8 +361,9 @@ jatrex:
stlo: call xwrite stlo: call xwrite
jmp firs jmp firs
skff: ; Converting
call xreadh ; Read obx header
skff: call xreadh
jb chtrun jb chtrun
cmp [head], -1 cmp [head], -1
je skff je skff
@ -264,6 +371,7 @@ skff:
call xread2 call xread2
jb trunca jb trunca
; Read block
firs: mov cx, [head+2] firs: mov cx, [head+2]
sub cx, [head] sub cx, [head]
inc cx inc cx
@ -273,9 +381,11 @@ firs: mov cx, [head+2]
okhead: mov dx, offset blok okhead: mov dx, offset blok
call xread call xread
jb trunc jb trunc
; Write
call xwrihd call xwrihd
jmp skff jmp skff
; Check if block is truncated
chtrun: test ax, ax chtrun: test ax, ax
jnz trunca jnz trunca
jmp finfil jmp finfil
@ -290,7 +400,11 @@ trunc: test ax, ax
call xwrihd call xwrihd
trunca: mov dx, offset w_trunc trunca: mov dx, offset w_trunc
; Warning
warfin: call warni warfin: call warni
; End of file
; Write endsequence
finfil: mov dx, offset endseq1 finfil: mov dx, offset endseq1
test [flags], m_pro test [flags], m_pro
jz endst jz endst
@ -306,7 +420,10 @@ endst: mov cx, endlen
and ecx, 7fh and ecx, 7fh
jz fuls jz fuls
call xwrith call xwrith
fuls: xor cx, cx ; seek back to para's atr header field fuls:
; Write number of paragraphs (para=16 bytes) to atr
xor cx, cx ; seek back to para's atr header field
mov dx, 2 mov dx, 2
mov bp, offset e_write mov bp, offset e_write
file 4200h file 4200h
@ -315,6 +432,7 @@ fuls: xor cx, cx ; seek back to para's atr header field
mov dx, offset len mov dx, offset len
call xwrite call xwrite
; Close files
shut: mov bx, [ahand] shut: mov bx, [ahand]
mov bp, offset e_write mov bp, offset e_write
call xclose call xclose
@ -326,14 +444,42 @@ shut: mov bx, [ahand]
jnz nook jnz nook
print oktxt print oktxt
nook: print eoltxt nook: print eoltxt
test [flags], m_wild
jz fin ; Find next file
mov ah, 4fh test [flags], m_lfn
jnz lfnnx
dos 4fh ; MS-DOS function
jc fin
nexfil: test [flags], m_file
jnz singl
jmp main1 jmp main1
lfnnx: mov bx, [fhand] ; LFN function
mov si, 1
mov di, offset f32
dos 714fh
jnc nexfil
dos 71a1h ; LFN search close
fin: mov ax, [exitcod] fin: mov ax, [exitcod]
dos dos
singl: print e_singl
dos 4c02h
; Add extension if none (di=end of name, cx=len, eax=ext)
adext: mov bx, di
adext1: dec bx
cmp [byte bx], '.'
je adextr
cmp [byte bx], '\'
loopne adext1
stosd
adextr: mov [byte di], 0
ret
xdisk: push bp xdisk: push bp
dos dos
pop dx pop dx
@ -405,13 +551,10 @@ printz: lodsb
jnz pnam1 jnz pnam1
ret ret
hello db 'X-BOOT 4.1.-9 by Fox/Taquart',eot hello db 'X-BOOT 5.0 by Fox/Taquart',eot
usgtxt db 'XBOOT [/p] obxfile [atrfile]',eol usgtxt db 'Converts Atari 8-bit executables to .ATR disk images.',eol
db ' Convert single Atari 8-bit executable into .ATR disk image.',eol db 'Syntax: XBOOT [/p] obxfiles [atrpath][atrfile]',eol
db 'XBOOT [/p] obxfiles [atrpath]',eol db '/p Write professional loader rather than standard.'
db ' Convert many files - wildcards allowed.',eol
db '/p switch',eol
db ' Write professional loader rather than standard.'
eoltxt db eot eoltxt db eot
arrow db ' -> $' arrow db ' -> $'
kropki db ' ... $' kropki db ' ... $'
@ -419,6 +562,8 @@ oktxt db 'OK$'
w_mem db eol,' WARNING: Memory conflict$' w_mem db eol,' WARNING: Memory conflict$'
w_prof db eol,' WARNING: Professional loader needed$' w_prof db eol,' WARNING: Professional loader needed$'
w_trunc db eol,' WARNING: File is truncated$' w_trunc db eol,' WARNING: File is truncated$'
e_nofil db 'ERROR: File not found',eot
e_singl db 'ERROR: Single target for many files',eot
e_nota db eol,' ERROR: Not Atari executable$' e_nota db eol,' ERROR: Not Atari executable$'
e_open db eol,' ERROR: Can''t open file$' e_open db eol,' ERROR: Can''t open file$'
e_read db eol,' ERROR: Disk read error$' e_read db eol,' ERROR: Disk read error$'
@ -440,7 +585,7 @@ l1runh db 7,141,225,2,169,7,141,5,3,169,255
db 11,3,32,83,228,48,217,14,210,7,173,127,7,166,67,208,223,129 db 11,3,32,83,228,48,217,14,210,7,173,127,7,166,67,208,223,129
db 68,230,68,208,2,230,69,165,70,197,68,165,71,229,69,176,210,169 db 68,230,68,208,2,230,69,165,70,197,68,165,71,229,69,176,210,169
db 3,141,15,210,108,226,2,44,111,97,100,105,110,103,14,14,14,0 db 3,141,15,210,108,226,2,44,111,97,100,105,110,103,14,14,14,0
db 52,46,48 db 53,46,48
lodlen = $-stdlod lodlen = $-stdlod
; Ending Header for loader #1 ; Ending Header for loader #1
@ -456,7 +601,7 @@ l2runh db 4,141,225,2,173,56,96
db 67,238,220,4,16,32,238,10,3,208,3,238,11,3,169,255,141,1 db 67,238,220,4,16,32,238,10,3,208,3,238,11,3,169,255,141,1
db 211,78,14,212,88,32,83,228,48,208,120,238,14,212,206,1,211,14 db 211,78,14,212,88,32,83,228,48,208,120,238,14,212,206,1,211,14
db 220,4,173,127,4,166,67,208,207,129,68,230,68,208,2,230,69,165 db 220,4,173,127,4,166,67,208,207,129,68,230,68,208,2,230,69,165
db 70,197,68,165,71,229,69,176,194,169,3,141,15,210,108,226,2,52 db 70,197,68,165,71,229,69,176,194,169,3,141,15,210,108,226,2,53
db 46,48,112 db 46,48,112
; Ending Header for loader #2 ; Ending Header for loader #2
@ -465,16 +610,20 @@ endseq2 db 250,4,250,4,224
exitcod dw 4c00h exitcod dw 4c00h
flags db 0 flags db 0
len dd lodlen+endlen len dd lodlen+endlen
ohand dw 0 onam dw obxnam
ahand dw 0
anam dw atrnam anam dw atrnam
onam dw ? enam:
nfin dw ? fhand dw ?
ohand dw ?
ahand dw ?
ofna dw ?
spt dw ? spt dw ?
obxnam db 100h dup(?) obxnam db 100h dup(?)
atrnam db 100h dup(?) atrnam db 100h dup(?)
f32 finddata32 ?
head dw ?,? head dw ?,?
blok db blen dup(?) blok db blen dup(?)