Skip to content

Commit

Permalink
autoexec sequence support
Browse files Browse the repository at this point in the history
  • Loading branch information
nihirash committed Mar 3, 2025
1 parent 600063c commit 9fdc8b5
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
*.sys
*.lst
*.bak
autoexec/*.com
cpm*.dsk
release/
.DS_Store
bootstrap/*.bin
bootstrap/*.sys
*.bin
163 changes: 163 additions & 0 deletions autoexec/autoexec.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
;; PROFILE.SUB on start processor :-)
;;
;; Simple way implement autostart in CP/M
;; (c) 2023 Aleksandr Sharikhin
;; Nihirash's Coffeeware License
org $100
output "autoexec.com"

BDOS_ENTRY EQU 5

CPM_EXIT EQU 0
CPM_OPEN EQU 15
CPM_CLOSE EQU 16
CPM_READ EQU 20
CPM_WRITE EQU 21
CPM_SETDMA EQU 26
CPM_DELETE EQU 19
CPM_CREATE EQU 22
CPM_RESET EQU 13
CPM_PRINT EQU 9

CPM_EOF EQU $1A

NEW_LINE EQU $0a
C_RETURN EQU $0d

macro BDOS_CALL n, arg
ld c, n
ld de, arg
call BDOS_ENTRY
endm

start:
ld sp, $80

;; Output buffer
ld hl, (BDOS_ENTRY + 1) : ld de, 512 : or a : sbc hl, de : ld l, 0 : ld (buf_ptr), hl
BDOS_CALL CPM_PRINT, banner

BDOS_CALL CPM_RESET, 0
BDOS_CALL CPM_SETDMA, buf

BDOS_CALL CPM_OPEN, fcb
;; If $FF - error happens
xor $ff : jp z, .exit

BDOS_CALL CPM_PRINT, found_msg
.read_loop
ld de, (dma_ptr) : ld c, CPM_SETDMA : call BDOS_ENTRY
BDOS_CALL CPM_READ, fcb
cp #1 : jr z, .done
cp #ff : jr z, .done
ld hl, (dma_ptr) : ld de, 128 : add hl, de : ld (dma_ptr), hl
jr .read_loop
.done
ld hl, (dma_ptr) : ld a, CPM_EOF : ld (hl), a

BDOS_CALL CPM_CLOSE, fcb

ld hl, buf
.loop
ld a, (hl)
cp CPM_EOF : jr z, .found
inc hl
jr nz, .loop
.found
dec l
ld a, l : ld (count), a

BDOS_CALL CPM_DELETE, fcb2
BDOS_CALL CPM_CREATE, fcb2
cp $ff : jr z, .exit
ld c, CPM_SETDMA : ld de, (buf_ptr) : call BDOS_ENTRY

;; Processing loop
ld hl, buf
.processing_loop:
ld a, (hl)
and a : jr z, .close
cp CPM_EOF : jr z, .close
push hl
call process_byte
pop hl
inc hl
jr .processing_loop
.close
ld de, (buf_ptr)
ld a, (record_count) : ld b, a
and a : jr z, .exit
.store_loop
inc d
push de
push bc
ld c, CPM_SETDMA : call BDOS_ENTRY
BDOS_CALL CPM_WRITE, fcb2
pop bc
pop de
djnz .store_loop

.exit
BDOS_CALL CPM_CLOSE, fcb2
rst 0

; A - byte to process
process_byte:
cp C_RETURN : jr z, .store
cp NEW_LINE : ret z
ld c, a
ld hl, (buf_ptr) : ld a, (record_fill) : ld l, a
inc hl

ld a, c : ld (hl), a
ld a, l : ld (record_fill), a

ret
.store:
ld hl, (buf_ptr) : ld l, 0
ld a, (record_fill)
ld (hl), a

ld l, a
inc hl : xor a : ld (hl), a
ld (record_fill), a

ld hl, buf_ptr+1 : dec (hl)
ld hl, record_count : inc (hl)
ret

record_fill db 0
record_count db 0
banner:
db "PROFILE.SUB support activated!"
db '$'
found_msg:
db C_RETURN, NEW_LINE
db "PROFILE.SUB was found - launching it!"
db C_RETURN, NEW_LINE
db '$'

;; File with autostart
fcb:
.start
db 00
db "PROFILE "
db "SUB"
ds 36-($ - .start), 0

;; CCP batch file
fcb2:
.start
db 00
db "$$$ "
db "SUB"
ds 36-($ - .start), 0

dma_ptr dw buf
buf_ptr dw 0

count: db 0
buf: equ $
8 changes: 8 additions & 0 deletions bootstrap/cpm.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ _main:

call _term_init
call.lil _cpm_restore

ld hl, _autoexec
ld de, CPM_SEG * $10000 + $100
ld bc, _autoexec_end - _autoexec
ldir
ld a, CPM_SEG
ld mb, a
Expand Down Expand Up @@ -56,3 +61,6 @@ _cpm_image:
incbin "cpm.sys"
_cpm_end:

_autoexec:
incbin "../autoexec/autoexec.com"
_autoexec_end:
10 changes: 9 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#!/bin/bash
(cd autoexec && sjasmplus autoexec.asm)
(cd sources && sjasmplus -DCRT=1 main.asm)
(cd bootstrap && ez80asm cpm.asm)

cp bootstrap/cpm.bin cpm.bin

(cd sources && sjasmplus main.asm)
(cd bootstrap && ez80asm cpm.asm)
(cd bootstrap && ez80asm cpm.asm)

cp bootstrap/cpm.bin cpm-uart.bin
18 changes: 13 additions & 5 deletions sources/bios/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ boot:
xor a
ld (TDRIVE), a
call SELDSK

jp gocpm
IFDEF CRT
ld a, 1
ELSE
xor a
ENDIF
ld (IOBYTE),a
call gocpm
jp $100
wboot:
ld sp, stack
CALL_GATE GATE_RESTORE
call HOME

call gocpm
jp CBASE
gocpm:
ld a, $c3 ; JP instruction
ld (0), a
Expand All @@ -30,8 +40,6 @@ gocpm:
ld (38), a
ld hl, int_handler
ld (39), hl

ld a, 1 : ld (IOBYTE),a
ld bc, $80
call SETDMA
Expand All @@ -42,7 +50,7 @@ gocpm:
pop af
ld c, a
jp CBASE
ret

int_handler:
reti
Expand Down

0 comments on commit 9fdc8b5

Please sign in to comment.