From 9fdc8b5d1fcf34f6e93344f0c72017ea0dfa3a08 Mon Sep 17 00:00:00 2001 From: Aleksandr Sharikhin Date: Mon, 3 Mar 2025 19:06:34 +0100 Subject: [PATCH] autoexec sequence support --- .gitignore | 3 +- autoexec/autoexec.asm | 163 ++++++++++++++++++++++++++++++++++++++++++ bootstrap/cpm.asm | 8 +++ build.sh | 10 ++- sources/bios/boot.asm | 18 +++-- 5 files changed, 195 insertions(+), 7 deletions(-) create mode 100644 autoexec/autoexec.asm diff --git a/.gitignore b/.gitignore index 92a1be8..2922b64 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,9 @@ *.sys *.lst *.bak +autoexec/*.com cpm*.dsk release/ .DS_Store -bootstrap/*.bin bootstrap/*.sys +*.bin \ No newline at end of file diff --git a/autoexec/autoexec.asm b/autoexec/autoexec.asm new file mode 100644 index 0000000..5e9a323 --- /dev/null +++ b/autoexec/autoexec.asm @@ -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 $ diff --git a/bootstrap/cpm.asm b/bootstrap/cpm.asm index da7fcf4..277d4be 100755 --- a/bootstrap/cpm.asm +++ b/bootstrap/cpm.asm @@ -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 @@ -56,3 +61,6 @@ _cpm_image: incbin "cpm.sys" _cpm_end: +_autoexec: + incbin "../autoexec/autoexec.com" +_autoexec_end: \ No newline at end of file diff --git a/build.sh b/build.sh index 09b5fb7..e96689e 100755 --- a/build.sh +++ b/build.sh @@ -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) \ No newline at end of file +(cd bootstrap && ez80asm cpm.asm) + +cp bootstrap/cpm.bin cpm-uart.bin \ No newline at end of file diff --git a/sources/bios/boot.asm b/sources/bios/boot.asm index b62cbfc..afa9b8e 100644 --- a/sources/bios/boot.asm +++ b/sources/bios/boot.asm @@ -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 @@ -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 @@ -42,7 +50,7 @@ gocpm: pop af ld c, a - jp CBASE + ret int_handler: reti