2007-04-27 22:42:41 +00:00
|
|
|
#
|
|
|
|
! $Source$
|
|
|
|
! $State$
|
|
|
|
! $Revision$
|
|
|
|
|
|
|
|
! Declare segments (the order is important).
|
|
|
|
|
|
|
|
.sect .text
|
|
|
|
.sect .rom
|
|
|
|
.sect .data
|
|
|
|
.sect .bss
|
|
|
|
|
2007-04-29 00:28:06 +00:00
|
|
|
MAX_ARGV = 8
|
|
|
|
|
2007-04-27 22:42:41 +00:00
|
|
|
.sect .bss
|
|
|
|
STACKSIZE = 2*1024
|
|
|
|
.comm stack, STACKSIZE
|
|
|
|
|
|
|
|
.sect .text
|
|
|
|
begtext:
|
2013-06-02 21:02:15 +00:00
|
|
|
! Check if bss would overlap BDOS. We must not overwrite
|
|
|
|
! BDOS and crash CP/M. We cheat by comparing only high bytes
|
|
|
|
! of each address.
|
|
|
|
|
|
|
|
lda 0x0007
|
2019-06-11 18:32:00 +00:00
|
|
|
mov c, a ! c = high byte of BDOS address
|
|
|
|
lda _cpm_ram+1 ! a = high byte of top of BSS, a.k.a. _end
|
2013-06-02 21:02:15 +00:00
|
|
|
cmp c
|
2019-06-11 18:32:00 +00:00
|
|
|
lxi d, noroom
|
|
|
|
mvi c, 9
|
|
|
|
jnc 0x0005 ! print error and exit if a >= c
|
2013-06-02 21:02:15 +00:00
|
|
|
|
|
|
|
! We have to clear the bss. (argify requires it.)
|
2007-04-29 00:28:06 +00:00
|
|
|
|
|
|
|
lxi h, begbss
|
|
|
|
lxi b, endbss
|
|
|
|
mvi e, 0
|
|
|
|
1:
|
|
|
|
mov m, e
|
|
|
|
inx h
|
|
|
|
mov a, b
|
|
|
|
cmp h
|
|
|
|
jnz 1b
|
|
|
|
mov a, c
|
|
|
|
cmp l
|
|
|
|
jnz 1b
|
|
|
|
|
|
|
|
! Set up the stack (now it's been cleared, since it's in the BSS).
|
2013-06-02 21:02:15 +00:00
|
|
|
|
2019-06-10 21:54:23 +00:00
|
|
|
lxi h, 0
|
|
|
|
dad sp
|
|
|
|
shld saved_sp ! save old stack pointer
|
2013-06-02 21:02:15 +00:00
|
|
|
lxi sp, stack + STACKSIZE
|
2007-04-29 00:28:06 +00:00
|
|
|
|
2019-02-06 23:06:32 +00:00
|
|
|
! Initialise the rsts (if desired).
|
|
|
|
|
|
|
|
#ifdef USE_I80_RSTS
|
|
|
|
call .rst_init
|
|
|
|
#endif
|
|
|
|
|
2019-06-10 21:54:23 +00:00
|
|
|
! Now the 'heap'.
|
|
|
|
|
2019-06-11 18:32:00 +00:00
|
|
|
lhld 0x0006 ! BDOS entry point
|
|
|
|
lxi d, -0x806 ! offset to start of CCP
|
|
|
|
dad d
|
|
|
|
shld _cpm_ramtop
|
2019-06-10 21:54:23 +00:00
|
|
|
|
2007-04-29 00:28:06 +00:00
|
|
|
! C-ify the command line at 0x0080.
|
2019-06-10 21:54:23 +00:00
|
|
|
|
2007-04-29 00:28:06 +00:00
|
|
|
lxi h, 0x0080
|
|
|
|
mov a, m ! a = length of command line
|
|
|
|
cpi 0x7F ! 127-byte command lines...
|
|
|
|
jnz 1f
|
|
|
|
dcr a ! ...lose the last character
|
|
|
|
1:
|
|
|
|
adi 0x81 ! write a 0 at 0x0081+length
|
|
|
|
mov l, a
|
|
|
|
mov m, h
|
|
|
|
|
|
|
|
! Now argify it.
|
|
|
|
|
|
|
|
lxi b, 0x0081 ! bc = command line pointer
|
2013-06-02 21:02:15 +00:00
|
|
|
lxi h, argv ! hl = argv pointer
|
|
|
|
|
|
|
|
loop_of_argify:
|
|
|
|
ldax b ! a = next character
|
|
|
|
ora a ! check for end of string
|
|
|
|
jz end_of_argify
|
|
|
|
cpi ' ' ! scan for non-space
|
|
|
|
jz 2f
|
|
|
|
|
|
|
|
mov m, c ! put next argument in argv
|
|
|
|
inx h
|
|
|
|
mov m, b
|
|
|
|
inx h
|
|
|
|
|
|
|
|
lda argc ! increment argc
|
2007-04-29 00:28:06 +00:00
|
|
|
inr a
|
|
|
|
sta argc
|
2013-06-02 21:02:15 +00:00
|
|
|
cpi MAX_ARGV ! exit loop if argv is full
|
|
|
|
jz end_of_argify
|
|
|
|
|
|
|
|
1: inx b ! scan for space
|
|
|
|
ldax b
|
|
|
|
ora a
|
|
|
|
jz end_of_argify
|
|
|
|
cpi ' '
|
|
|
|
jnz 1b
|
|
|
|
|
|
|
|
xra a ! replace the space with a '\0'
|
|
|
|
stax b
|
|
|
|
|
|
|
|
2: inx b
|
|
|
|
jmp loop_of_argify
|
2007-04-29 00:28:06 +00:00
|
|
|
end_of_argify:
|
|
|
|
|
|
|
|
! Add the fake parameter for the program name.
|
|
|
|
|
|
|
|
lxi h, progname
|
|
|
|
shld argv0
|
|
|
|
lxi h, argc
|
|
|
|
inr m
|
|
|
|
|
|
|
|
! Push the main() arguments and go.
|
2007-04-27 22:42:41 +00:00
|
|
|
|
2007-04-29 00:28:06 +00:00
|
|
|
lxi h, envp
|
2007-04-27 22:42:41 +00:00
|
|
|
push h
|
2007-04-29 00:28:06 +00:00
|
|
|
lxi h, argv0
|
2007-04-27 22:42:41 +00:00
|
|
|
push h
|
2007-04-29 00:28:06 +00:00
|
|
|
lhld argc ! slightly evil
|
|
|
|
mvi h, 0
|
2007-04-27 22:42:41 +00:00
|
|
|
push h
|
2019-06-11 18:32:00 +00:00
|
|
|
call __m_a_i_n
|
|
|
|
.define _cpm_exit, EXIT, __exit
|
|
|
|
_cpm_exit:
|
|
|
|
EXIT:
|
|
|
|
__exit:
|
|
|
|
stc ! set carry bit
|
|
|
|
jnc _cpm_warmboot ! warm boot if not set
|
|
|
|
saved_sp = . + 1
|
2019-06-10 21:54:23 +00:00
|
|
|
lxi sp, 0 ! patched on startup
|
|
|
|
ret
|
2013-06-02 21:02:15 +00:00
|
|
|
|
2007-04-27 22:42:41 +00:00
|
|
|
! Emergency exit routine.
|
|
|
|
|
2019-06-11 18:32:00 +00:00
|
|
|
.define _cpm_warmboot
|
|
|
|
_cpm_warmboot = 0
|
2007-04-27 22:42:41 +00:00
|
|
|
|
2019-06-10 21:54:23 +00:00
|
|
|
! Special CP/M stuff.
|
|
|
|
|
|
|
|
.define _cpm_fcb
|
|
|
|
_cpm_fcb = 0x005c
|
|
|
|
|
|
|
|
.define _cpm_ramtop
|
2019-06-11 18:32:00 +00:00
|
|
|
.comm _cpm_ramtop, 2
|
2019-06-10 21:54:23 +00:00
|
|
|
|
|
|
|
.define _cpm_default_dma
|
|
|
|
_cpm_default_dma = 0x0080
|
|
|
|
|
|
|
|
.define _cpm_cmdlinelen, _cpm_cmdline
|
|
|
|
_cpm_cmdlinelen = 0x0080
|
|
|
|
_cpm_cmdline = 0x0081
|
|
|
|
|
2007-04-27 22:42:41 +00:00
|
|
|
! Define symbols at the beginning of our various segments, so that we can find
|
|
|
|
! them. (Except .text, which has already been done.)
|
|
|
|
|
|
|
|
.define begtext, begdata, begbss
|
|
|
|
.sect .data; begdata:
|
|
|
|
.sect .rom; begrom:
|
|
|
|
.sect .bss; begbss:
|
|
|
|
|
|
|
|
! Some magic data. All EM systems need these.
|
|
|
|
|
2019-06-11 18:02:03 +00:00
|
|
|
.define .ignmask, _errno
|
2007-04-27 22:42:41 +00:00
|
|
|
.comm .ignmask, 2
|
|
|
|
.comm _errno, 2
|
|
|
|
|
2007-04-29 00:28:06 +00:00
|
|
|
! Used to store the argv array.
|
|
|
|
|
|
|
|
argc: .space 1 ! number of args
|
|
|
|
argv0: .space 2 ! always points at progname
|
|
|
|
argv: .space 2*MAX_ARGV ! argv array (must be after argv0)
|
|
|
|
envp: .space 2 ! envp array (always empty, must be after argv)
|
|
|
|
|
|
|
|
! These are used specifically by the i80 code generator.
|
2007-04-27 22:42:41 +00:00
|
|
|
|
2019-06-11 18:02:03 +00:00
|
|
|
.define .retadr, .retadr1
|
2007-04-27 22:42:41 +00:00
|
|
|
.define .bcreg, .areg
|
|
|
|
.define .tmp1, .fra, block1, block2, block3
|
|
|
|
|
|
|
|
.comm .retadr, 2 ! used to save return address
|
|
|
|
.comm .retadr1, 2 ! reserve
|
|
|
|
.comm .bcreg, 2
|
|
|
|
.comm .areg, 1
|
|
|
|
.comm .tmp1, 2
|
|
|
|
.comm .fra, 8 ! 8 bytes function return area
|
|
|
|
block1: .space 4 ! used by 32 bits divide and
|
|
|
|
block2: .space 4 ! multiply routines
|
|
|
|
block3: .space 4 ! must be contiguous (.comm doesn't guarantee this)
|
2007-04-29 00:28:06 +00:00
|
|
|
|
2019-06-11 18:32:00 +00:00
|
|
|
.sect .data
|
|
|
|
.define _cpm_ram
|
|
|
|
_cpm_ram: .data2 __end
|
|
|
|
|
2007-04-29 00:28:06 +00:00
|
|
|
.sect .rom
|
|
|
|
progname: .asciz 'ACKCPM'
|
2019-06-11 18:32:00 +00:00
|
|
|
noroom: .ascii 'No room$'
|