From 4bdd81666ca70ce0914a3be2b246e693f678725b Mon Sep 17 00:00:00 2001 From: Alexander Sharihin Date: Sat, 4 May 2024 18:48:09 +0200 Subject: [PATCH 1/3] Console fixes --- .version | 2 +- CHANGELOG.md | 6 +++++- src/edos/console.asm | 1 - src/edos/core.asm | 1 + src/edos/ebios/console.asm | 32 +++++++++++++++++++++++--------- src/edos/ebios/index.asm | 16 ++++++++++++++-- src/edos/mos.asm | 4 ++++ 7 files changed, 48 insertions(+), 14 deletions(-) diff --git a/.version b/.version index 97f7bd0..8ddb940 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -2024.05.02 +2024.05.04 diff --git a/CHANGELOG.md b/CHANGELOG.md index 087c70f..31e861d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog -## 2024.04.02 +## 2024.05.04 + + * Console status and reading working fine now + +## 2024.05.02 * File leak fixed diff --git a/src/edos/console.asm b/src/edos/console.asm index e820088..5fbe2dd 100644 --- a/src/edos/console.asm +++ b/src/edos/console.asm @@ -45,7 +45,6 @@ raw_io: ret z jp CONIN - get_io_byte: ld a, (IOBYTE) ret diff --git a/src/edos/core.asm b/src/edos/core.asm index f0b8d2e..db508c8 100644 --- a/src/edos/core.asm +++ b/src/edos/core.asm @@ -7,6 +7,7 @@ TDRIVE: equ $04 IOBYTE: equ $03 TFCB: equ $5c +DEFDMA: equ $80 NFUNC: equ 40 diff --git a/src/edos/ebios/console.asm b/src/edos/ebios/console.asm index 326a9d4..9615d30 100644 --- a/src/edos/ebios/console.asm +++ b/src/edos/ebios/console.asm @@ -3,32 +3,46 @@ ;; ;; All rights are reserved + +;; Single source of truth is better +keycode: + db 0 + bios_const: + ld.lil hl, (keycount_ptr) + ld.lil a, (hl) + and a + ret z + + ld.lil hl, (keydown_ptr) + ld.lil a, (hl) + and a + ret z + ld.lil hl, (keycode_ptr) ld.lil a, (hl) - or a + and $7f + ld (keycode), a ret z ld a, $ff ret - bios_in: ;; You shouldn't use application stack(it will broke wordstar, for example) ;; So, using our BIOS-stack for all places where we'll need stack LOCALSP @rep: - MOSCALL MOS_GET_KEY - or a + call bios_const + and a jr z, @rep - ld c, a - - xor a - ld.lil hl, (keycode_ptr) + xor a + ld.lil hl, (keydown_ptr) ld.lil (hl), a - ld a, c + ld a, (keycode) + RESTORESP ret diff --git a/src/edos/ebios/index.asm b/src/edos/ebios/index.asm index 35f9dc5..7eae510 100644 --- a/src/edos/ebios/index.asm +++ b/src/edos/ebios/index.asm @@ -60,9 +60,17 @@ init: rst.lil $18 MOSCALL MOS_SYS_VARS - lea.lil hl, ix + 5 ;; ASCII KEYCODE + + lea.lil hl, ix + VAR_KEYASCII ;; ASCII KEYCODE ld.lil (keycode_ptr), hl + lea.lil hl, ix + VAR_KEYDOWN ;; VKEYDOWN + ld.lil (keydown_ptr), hl + + lea.lil hl, ix + VAR_VKEYCOUNT ;; VKEYCOUNT + ld.lil (keycount_ptr), hl + + ;; Cleaning last keypress on start - no waiting for key on start of some apps xor a ld.lil (hl), a @@ -78,7 +86,7 @@ init: ld hl, entrypoint ld (6), hl - ld bc, $80 + ld bc, DEFDMA ld (dma_ptr), bc ld a, 1 @@ -98,6 +106,10 @@ banner: include "ebios/console.asm" include "ebios/disk.asm" +keycount_ptr: + dl 0 +keydown_ptr: + dl 0 keycode_ptr: dl 0 diff --git a/src/edos/mos.asm b/src/edos/mos.asm index 7dcea47..aacf8db 100644 --- a/src/edos/mos.asm +++ b/src/edos/mos.asm @@ -36,3 +36,7 @@ FA_WRITE: equ $02 FA_CREATE: equ $04 FA_CREATE_ALW: equ $08 FA_OPEN_ALW: equ $10 + +VAR_VKEYCOUNT: equ $19 +VAR_KEYASCII: equ $05 +VAR_KEYDOWN: equ $18 \ No newline at end of file From c66776562dadda4a2f758e8f8713bf9cb839c8e9 Mon Sep 17 00:00:00 2001 From: Alexander Sharihin Date: Sat, 4 May 2024 20:09:24 +0200 Subject: [PATCH 2/3] update --- CHANGELOG.md | 4 ++++ src/edos/core.asm | 11 ++++++++--- src/edos/ebios/index.asm | 19 ++++++++++++++++++- src/edos/fcb.asm | 19 +++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31e861d..03720d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 2024.05.04 + * "Update random access pointer" call implemented + + * "Printer" now outputs to VPD's printer + * Console status and reading working fine now ## 2024.05.02 diff --git a/src/edos/core.asm b/src/edos/core.asm index db508c8..1a6b307 100644 --- a/src/edos/core.asm +++ b/src/edos/core.asm @@ -74,8 +74,8 @@ fun_table: dw console_out ; 02 Console out dw trace ; 03 Aux read - dw trace ; 04 Aux write - dw do_nothing ; 05 Printer write + dw print ; 04 Aux write + dw print ; 05 Printer write dw raw_io ; 06 Raw IO dw get_io_byte ; 07 Get IO Byte @@ -107,7 +107,7 @@ fun_table: dw fread_rnd ; 33 Random read dw fwrite_rnd ; 34 Random write dw calc_size ; 35 Compute file size - dw trace ; 36 Update random access pointer + dw calc_random_offset ; 36 Update random access pointer dw do_nothing ; 37 reset selected disks dw trace ; 38 not used in CP/M 2.2 dw trace ; 39 not used in CP/M 2.2 @@ -117,6 +117,11 @@ fun_table: bye: jp.lil ZINC_EXIT +;; Just send byte to VDP "Printer" +print: + ld c, e + jp list + do_nothing: xor a ld hl, 0 diff --git a/src/edos/ebios/index.asm b/src/edos/ebios/index.asm index 7eae510..2324702 100644 --- a/src/edos/ebios/index.asm +++ b/src/edos/ebios/index.asm @@ -15,7 +15,7 @@ CONST: JP bios_const CONIN: JP bios_in CONOUT: JP bios_out -LIST: JP nothing +LIST: JP list PUNCH: JP nothing READER: JP reader @@ -33,6 +33,23 @@ nothing: ld a, $ff ret +list: + LOCALSP + + ld a, c + ld (@char), a + ld hl, @vdu + ld bc, 4 + rst.lil $18 + + RESTORESP + ret +@vdu: + db 2, 1 +@char: + db 0 + db 3 + reader: ld a, 26 ret diff --git a/src/edos/fcb.asm b/src/edos/fcb.asm index 2178b5d..eb85ed4 100644 --- a/src/edos/fcb.asm +++ b/src/edos/fcb.asm @@ -39,6 +39,25 @@ fcb_calc_offset: pop ix ret +calc_random_offset: + push ix + ld ix, (args) + + ld l, (IX + FCB_EX) + ld h, $80 + mlt hl + + ld d, 0 + ld e, (IX + FCB_CR) + + add hl, de + + ld (ix + FCB_RN), hl + + pop ix + xor a + ret + ; IX - FCB fcb_next_record: push ix From f137a8e0f88f0cb116cb053480ec0468262ceafb Mon Sep 17 00:00:00 2001 From: Alexander Sharihin Date: Sat, 4 May 2024 22:09:51 +0200 Subject: [PATCH 3/3] simple terminal emulation --- CHANGELOG.md | 2 + src/config.asm | 7 +- src/edos/disk.asm | 8 ++- src/edos/ebios/console.asm | 2 +- src/edos/ebios/index.asm | 1 + src/terminal.asm | 144 +++++++++++++++++++++++++++++++++++++ src/zinc.asm | 5 +- 7 files changed, 163 insertions(+), 6 deletions(-) create mode 100644 src/terminal.asm diff --git a/CHANGELOG.md b/CHANGELOG.md index 03720d2..e5f2438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 2024.05.04 + * Very basic ADM-3 terminal emulation + * "Update random access pointer" call implemented * "Printer" now outputs to VPD's printer diff --git a/src/config.asm b/src/config.asm index ff1d487..bd89404 100644 --- a/src/config.asm +++ b/src/config.asm @@ -16,8 +16,9 @@ ;; Replace ZINC_BASE to $40000 for using it from `/bin` path or as standalone application ;; Or keep it as usual moslet - emulator is really tiny and works fine here -ZINC_BASE: equ $B0000 -ZINC_EXIT: equ ZINC_BASE + 4 +ZINC_BASE: equ $B0000 +ZINC_EXIT: equ ZINC_BASE + 4 +ZINC_TERMOUT: equ ZINC_EXIT + 4 ;; By changing this value you can change used memory page for CP/M application EDOS_BASE: equ $A0000 @@ -25,6 +26,8 @@ EDOS_BASE: equ $A0000 EDOS_ORG: equ EDOS_BASE + $F500 ;; TPA area starts here EDOS_TPA: equ EDOS_BASE + $100 +;; MB pointer +EDOS_PAGE: equ EDOS_BASE / $10000 ;; CP/M 2.2 is $22 ;; Personal CP/M-80 is $28 diff --git a/src/edos/disk.asm b/src/edos/disk.asm index 789f4d3..4ae2893 100644 --- a/src/edos/disk.asm +++ b/src/edos/disk.asm @@ -76,15 +76,19 @@ catalog_scan_next: jr scan_ok nope: - ld a, $ff + ld a, -1 + ld hl, -1 + ld bc, -1 ret scan_ok: ld de, (dma_ptr) ld hl, ffs_lfn call ascciz_to_fcb - + xor a + ld hl, 0 + ld bc, 0 ret ;; Calculation file lenght diff --git a/src/edos/ebios/console.asm b/src/edos/ebios/console.asm index 9615d30..e9e0df9 100644 --- a/src/edos/ebios/console.asm +++ b/src/edos/ebios/console.asm @@ -49,6 +49,6 @@ bios_in: bios_out: LOCALSP ld a, c - rst.lil $10 + call.lil ZINC_TERMOUT RESTORESP ret \ No newline at end of file diff --git a/src/edos/ebios/index.asm b/src/edos/ebios/index.asm index 2324702..b5d07b6 100644 --- a/src/edos/ebios/index.asm +++ b/src/edos/ebios/index.asm @@ -113,6 +113,7 @@ init: jp bye banner: + db 4 db 13,10, 17, 1 db "ZINC is Not CP/M", 13, 10, 17, 2 db "(c) 2024 Aleksandr Sharikhin", 13, 10, 17, 15 diff --git a/src/terminal.asm b/src/terminal.asm new file mode 100644 index 0000000..722a305 --- /dev/null +++ b/src/terminal.asm @@ -0,0 +1,144 @@ +;; ZINC is Not CP/M +;; +;; CP/M compatibility layer for Agon's MOS +;; (c) 2024 Aleksandr Sharikhin +;; +;; All rights are reserved + +;; Terminal emulation layer + +;; Emulates simple ADM-3a like terminal +;; It's good enough and fast + +TERM_HOME: equ $01 +TERM_LEFT: equ $08 +TERM_CLS: equ $0C +TERM_UP: equ $14 +TERM_LEFT2: equ $16 +TERM_RIGHT: equ $17 +TERM_CLINE: equ $18 +TERM_CLS2: equ $1A +TERM_ESC: equ $1B + + macro VDU byte + ld a, byte + rst.lil $10 + endmacro + +termout: + call _putc +term_fsm: equ $ - 3 + + ret.lil + +_cls: + VDU 12 + ret + +_home: + VDU 30 + ret + +_left: + VDU 8 + ret +_up: + VDU 11 + ret +_right: + VDU 9 + ret + +_esc: + cp '=' + jr z, @load_coords +;; You can add some ESC codes here + + jr exit_fsm +@load_coords: + ld hl, _loadx + ld (term_fsm), hl + ret + +_loadx: + sub 32 + ld (term_x), a + + ld hl, _loady + ld (term_fsm), hl + ret + +_loady: + sub 32 + ld (term_y), a + + xor a + ld mb, a + + ld hl, set_pos_cmd + ld bc, 3 + rst.lil $18 + + ld a, EDOS_PAGE + ld mb, a + +exit_fsm: + ld hl, _putc + ld (term_fsm), hl + ret + +_putc: + and $7f + + cp ' ' + jr nc, @draw + + cp 13 + jr z, @draw + + cp 10 + jr z, @draw + +;; Move cursor + cp TERM_LEFT + jp z, _left + cp TERM_LEFT2 + jp z, _left + cp TERM_UP + jp z, _up + cp TERM_RIGHT + jp z, _right + +;; Home cursor + cp TERM_HOME + jp z, _home +;; Clear screen + cp TERM_CLS + jp z, _cls + cp TERM_CLS2 + jp z, _cls + +;; ESC control sequences + cp TERM_ESC + jr z, @set_esc + +;; Isolate rest things + ret + +@draw: + rst.lil $10 + ret + +@set_esc: + ld hl, _esc + ld (term_fsm), hl + ret + +set_pos_cmd: + db 31 +term_y: + db 0 +term_x: + db 0 + + dl 0 \ No newline at end of file diff --git a/src/zinc.asm b/src/zinc.asm index 76a1581..11bce8c 100644 --- a/src/zinc.asm +++ b/src/zinc.asm @@ -19,6 +19,8 @@ MAX_ARGS: EQU 15 jp _start bye_ptr: jp exit +term_out_ptr: + jp termout argc: db 0 @@ -97,7 +99,7 @@ _start: call close_all ;; Setting base address for legacy mode - ld a, EDOS_BASE / $10000 + ld a, EDOS_PAGE ld mb, a ;; Jumping into EDOS jp.sis EDOS_ORG + $3 @@ -221,6 +223,7 @@ path_buffer: stack_save: dl 0 include "cpm-data.asm" + include "terminal.asm" os: incbin "edos/edos.bin"