Skip to content

Commit 4215f31

Browse files
authored
Merge pull request #27 from nihirash/update
autoexec sequence support
2 parents 8d8b8af + 9fdc8b5 commit 4215f31

File tree

5 files changed

+195
-7
lines changed

5 files changed

+195
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
*.sys
33
*.lst
44
*.bak
5+
autoexec/*.com
56
cpm*.dsk
67
release/
78
.DS_Store
8-
bootstrap/*.bin
99
bootstrap/*.sys
10+
*.bin

autoexec/autoexec.asm

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
;; PROFILE.SUB on start processor :-)
2+
;;
3+
;; Simple way implement autostart in CP/M
4+
;; (c) 2023 Aleksandr Sharikhin
5+
;; Nihirash's Coffeeware License
6+
7+
org $100
8+
output "autoexec.com"
9+
10+
BDOS_ENTRY EQU 5
11+
12+
CPM_EXIT EQU 0
13+
CPM_OPEN EQU 15
14+
CPM_CLOSE EQU 16
15+
CPM_READ EQU 20
16+
CPM_WRITE EQU 21
17+
CPM_SETDMA EQU 26
18+
CPM_DELETE EQU 19
19+
CPM_CREATE EQU 22
20+
CPM_RESET EQU 13
21+
CPM_PRINT EQU 9
22+
23+
CPM_EOF EQU $1A
24+
25+
NEW_LINE EQU $0a
26+
C_RETURN EQU $0d
27+
28+
macro BDOS_CALL n, arg
29+
ld c, n
30+
ld de, arg
31+
call BDOS_ENTRY
32+
endm
33+
34+
start:
35+
ld sp, $80
36+
37+
;; Output buffer
38+
ld hl, (BDOS_ENTRY + 1) : ld de, 512 : or a : sbc hl, de : ld l, 0 : ld (buf_ptr), hl
39+
40+
BDOS_CALL CPM_PRINT, banner
41+
42+
BDOS_CALL CPM_RESET, 0
43+
BDOS_CALL CPM_SETDMA, buf
44+
45+
BDOS_CALL CPM_OPEN, fcb
46+
;; If $FF - error happens
47+
xor $ff : jp z, .exit
48+
49+
BDOS_CALL CPM_PRINT, found_msg
50+
.read_loop
51+
ld de, (dma_ptr) : ld c, CPM_SETDMA : call BDOS_ENTRY
52+
BDOS_CALL CPM_READ, fcb
53+
cp #1 : jr z, .done
54+
cp #ff : jr z, .done
55+
ld hl, (dma_ptr) : ld de, 128 : add hl, de : ld (dma_ptr), hl
56+
jr .read_loop
57+
.done
58+
ld hl, (dma_ptr) : ld a, CPM_EOF : ld (hl), a
59+
60+
BDOS_CALL CPM_CLOSE, fcb
61+
62+
ld hl, buf
63+
.loop
64+
ld a, (hl)
65+
cp CPM_EOF : jr z, .found
66+
inc hl
67+
jr nz, .loop
68+
.found
69+
dec l
70+
ld a, l : ld (count), a
71+
72+
BDOS_CALL CPM_DELETE, fcb2
73+
BDOS_CALL CPM_CREATE, fcb2
74+
cp $ff : jr z, .exit
75+
ld c, CPM_SETDMA : ld de, (buf_ptr) : call BDOS_ENTRY
76+
77+
;; Processing loop
78+
ld hl, buf
79+
.processing_loop:
80+
ld a, (hl)
81+
and a : jr z, .close
82+
cp CPM_EOF : jr z, .close
83+
push hl
84+
call process_byte
85+
pop hl
86+
inc hl
87+
jr .processing_loop
88+
.close
89+
ld de, (buf_ptr)
90+
ld a, (record_count) : ld b, a
91+
and a : jr z, .exit
92+
.store_loop
93+
inc d
94+
push de
95+
push bc
96+
ld c, CPM_SETDMA : call BDOS_ENTRY
97+
BDOS_CALL CPM_WRITE, fcb2
98+
pop bc
99+
pop de
100+
djnz .store_loop
101+
102+
.exit
103+
BDOS_CALL CPM_CLOSE, fcb2
104+
rst 0
105+
106+
; A - byte to process
107+
process_byte:
108+
cp C_RETURN : jr z, .store
109+
cp NEW_LINE : ret z
110+
ld c, a
111+
112+
ld hl, (buf_ptr) : ld a, (record_fill) : ld l, a
113+
inc hl
114+
115+
ld a, c : ld (hl), a
116+
ld a, l : ld (record_fill), a
117+
118+
ret
119+
.store:
120+
ld hl, (buf_ptr) : ld l, 0
121+
ld a, (record_fill)
122+
ld (hl), a
123+
124+
ld l, a
125+
inc hl : xor a : ld (hl), a
126+
ld (record_fill), a
127+
128+
ld hl, buf_ptr+1 : dec (hl)
129+
ld hl, record_count : inc (hl)
130+
ret
131+
132+
record_fill db 0
133+
record_count db 0
134+
banner:
135+
db "PROFILE.SUB support activated!"
136+
db '$'
137+
found_msg:
138+
db C_RETURN, NEW_LINE
139+
db "PROFILE.SUB was found - launching it!"
140+
db C_RETURN, NEW_LINE
141+
db '$'
142+
143+
;; File with autostart
144+
fcb:
145+
.start
146+
db 00
147+
db "PROFILE "
148+
db "SUB"
149+
ds 36-($ - .start), 0
150+
151+
;; CCP batch file
152+
fcb2:
153+
.start
154+
db 00
155+
db "$$$ "
156+
db "SUB"
157+
ds 36-($ - .start), 0
158+
159+
dma_ptr dw buf
160+
buf_ptr dw 0
161+
162+
count: db 0
163+
buf: equ $

bootstrap/cpm.asm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ _main:
2323

2424
call _term_init
2525
call.lil _cpm_restore
26+
27+
ld hl, _autoexec
28+
ld de, CPM_SEG * $10000 + $100
29+
ld bc, _autoexec_end - _autoexec
30+
ldir
2631
2732
ld a, CPM_SEG
2833
ld mb, a
@@ -56,3 +61,6 @@ _cpm_image:
5661
incbin "cpm.sys"
5762
_cpm_end:
5863

64+
_autoexec:
65+
incbin "../autoexec/autoexec.com"
66+
_autoexec_end:

build.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
#!/bin/bash
2+
(cd autoexec && sjasmplus autoexec.asm)
3+
(cd sources && sjasmplus -DCRT=1 main.asm)
4+
(cd bootstrap && ez80asm cpm.asm)
5+
6+
cp bootstrap/cpm.bin cpm.bin
7+
28
(cd sources && sjasmplus main.asm)
3-
(cd bootstrap && ez80asm cpm.asm)
9+
(cd bootstrap && ez80asm cpm.asm)
10+
11+
cp bootstrap/cpm.bin cpm-uart.bin

sources/bios/boot.asm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@ boot:
1111
xor a
1212
ld (TDRIVE), a
1313
call SELDSK
14-
15-
jp gocpm
14+
IFDEF CRT
15+
ld a, 1
16+
ELSE
17+
xor a
18+
ENDIF
19+
20+
ld (IOBYTE),a
21+
call gocpm
22+
jp $100
1623
wboot:
1724
ld sp, stack
1825
CALL_GATE GATE_RESTORE
1926
call HOME
27+
28+
call gocpm
29+
jp CBASE
2030
gocpm:
2131
ld a, $c3 ; JP instruction
2232
ld (0), a
@@ -30,8 +40,6 @@ gocpm:
3040
ld (38), a
3141
ld hl, int_handler
3242
ld (39), hl
33-
34-
ld a, 1 : ld (IOBYTE),a
3543
3644
ld bc, $80
3745
call SETDMA
@@ -42,7 +50,7 @@ gocpm:
4250
pop af
4351
ld c, a
4452
45-
jp CBASE
53+
ret
4654

4755
int_handler:
4856
reti

0 commit comments

Comments
 (0)