Skip to content
This repository was archived by the owner on Sep 10, 2025. It is now read-only.

Commit 6bda891

Browse files
committed
Allow getting the CCP/CONSOLE driver names, not just setting
This improves the value of our utilities.
1 parent 68e780e commit 6bda891

File tree

6 files changed

+114
-20
lines changed

6 files changed

+114
-20
lines changed

EXTENSIONS.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,29 @@ Demonstrated in [samples/ctrlc.z80](samples/ctrlc.z80).
5151

5252

5353

54-
## Function 0x02: Change Console Driver
54+
## Function 0x02: Get/Set Console Driver
5555

5656
On entry DE points to a text-string, terminated by NULL, which represents the name of the
5757
console output driver to use.
5858

59+
If DE is 0x0000 then the DMA area is filled with the name of the current driver, NULL-terminated.
60+
5961
Demonstrated in [samples/console.z80](samples/console.z80)
6062

6163

6264

63-
## Function 0x03: Change CCP Driver
65+
## Function 0x03: Get/Set CCP
6466

6567
On entry DE points to a text-string, terminated by NULL, which represents the name of the
6668
CCP to use.
6769

70+
If DE is 0x0000 then the DMA area is filled with the name of the currently active CCP, NULL-terminated.
71+
6872
Demonstrated in [samples/ccp.z80](samples/ccp.z80)
6973

7074

7175

72-
## Function 0x04: Set Quiet
76+
## Function 0x04: Get/Set Quiet
7377

7478
* If C is 0x00 quiet-mode is enabled.
7579
* If C is 0x01 quiet-mode is disabled.

cpm/cpm_bios.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,25 @@ func BiosSysCallReserved1(cpm *CPM) error {
245245
}
246246

247247
case 0x0002:
248+
249+
if de == 0x0000 {
250+
// Fill the DMA area with NULL bytes
251+
addr := cpm.dma
252+
253+
end := addr + uint16(127)
254+
for end > addr {
255+
cpm.Memory.Set(end, 0x00)
256+
end--
257+
}
258+
259+
// now populate with our console driver
260+
str := cpm.output.GetName()
261+
for i, c := range str {
262+
cpm.Memory.Set(addr+uint16(i), uint8(c))
263+
}
264+
return nil
265+
}
266+
248267
// Get the string pointed to by DE
249268
str := getStringFromMemory(de)
250269

@@ -274,6 +293,24 @@ func BiosSysCallReserved1(cpm *CPM) error {
274293

275294
case 0x0003:
276295

296+
if de == 0x0000 {
297+
// Fill the DMA area with NULL bytes
298+
addr := cpm.dma
299+
300+
end := addr + uint16(127)
301+
for end > addr {
302+
cpm.Memory.Set(end, 0x00)
303+
end--
304+
}
305+
306+
// now populate with our CCP
307+
str := cpm.ccp
308+
for i, c := range str {
309+
cpm.Memory.Set(addr+uint16(i), uint8(c))
310+
}
311+
return nil
312+
}
313+
277314
// Get the string pointed to by DE
278315
str := getStringFromMemory(de)
279316

samples/ccp.com

33 Bytes
Binary file not shown.

samples/ccp.z80

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ BDOS_ENTRY_POINT: EQU 5
3838
;; then we've got nothing specified
3939
ld a, (FCB1 + 1)
4040
cp 0x20 ; 0x20 = 32 == SPACE
41-
jp z, missing_argument ; Got a space, report the error
41+
jp z, show_ccp ; Got a space, show the CCP
4242

4343
ld HL, 03
4444
ld de, FCB1 + 1
@@ -49,15 +49,39 @@ exit:
4949
LD C,0x00
5050
CALL BDOS_ENTRY_POINT
5151

52-
;;
53-
;; Error Routines
54-
;;
55-
missing_argument:
56-
LD DE, MISSING_ARGUMENT_STR
52+
53+
;; Show the current CCP
54+
show_ccp:
55+
LD DE, CCP_PREFIX
5756
LD C, BDOS_OUTPUT_STRING
58-
call BDOS_ENTRY_POINT
57+
CALL BDOS_ENTRY_POINT
58+
59+
ld HL, 03
60+
ld de, 0x0000
61+
ld a, 31
62+
out (0xff), a
63+
64+
LD HL, 0x0080
65+
loopy:
66+
LD A, (HL)
67+
cp 0
68+
JR Z, finished_loop
69+
push HL
70+
ld e,a
71+
ld c, 0x02
72+
call 0x0005
73+
pop HL
74+
inc hl
75+
jr loopy
76+
finished_loop:
77+
LD DE, CCP_SUFFIX
78+
LD C, BDOS_OUTPUT_STRING
79+
CALL BDOS_ENTRY_POINT
5980
jr exit
6081

82+
;;
83+
;; Error Routines
84+
;;
6185
not_cpmulator:
6286
LD DE, WRONG_EMULATOR
6387
LD C, BDOS_OUTPUT_STRING
@@ -68,8 +92,11 @@ not_cpmulator:
6892
;;
6993
;; Text output strings.
7094
;;
71-
MISSING_ARGUMENT_STR:
72-
db "Usage: CCP [CCP|CCPZ]", 0x0a, 0x0d, "$"
95+
CCP_PREFIX:
96+
db "CCP is set to '$"
97+
CCP_SUFFIX:
98+
db "'", 0x0a, 0x0d, "$"
99+
73100
WRONG_EMULATOR:
74101
db "This binary is not running under cpmulator, aborting.", 0x0a, 0x0d, "$"
75102

samples/console.com

37 Bytes
Binary file not shown.

samples/console.z80

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BDOS_OUTPUT_STRING: EQU 9
3636
;; then we've got nothing specified
3737
ld a, (FCB1 + 1)
3838
cp 0x20 ; 0x20 = 32 == SPACE
39-
jp z, missing_argument ; Got a space, report the error
39+
jp z, show_driver ; Got a space, show the console driver name
4040

4141

4242
;; OK we're running under cpmulator
@@ -50,14 +50,38 @@ exit:
5050
LD C,0x00
5151
CALL BDOS_ENTRY_POINT
5252

53+
;; Show the current console driver
54+
show_driver:
55+
LD DE, CONSOLE_PREFIX
56+
LD C, BDOS_OUTPUT_STRING
57+
CALL BDOS_ENTRY_POINT
58+
59+
ld HL, 02
60+
ld de, 0x0000
61+
ld a, 31
62+
out (0xff), a
63+
64+
LD HL, 0x0080
65+
loopy:
66+
LD A, (HL)
67+
cp 0
68+
JR Z, finished_loop
69+
push HL
70+
ld e,a
71+
ld c, 0x02
72+
call 0x0005
73+
pop HL
74+
inc hl
75+
jr loopy
76+
finished_loop:
77+
LD DE, CONSOLE_SUFFIX
78+
LD C, BDOS_OUTPUT_STRING
79+
CALL BDOS_ENTRY_POINT
80+
jr exit
81+
5382
;;
5483
;; Error Routines
5584
;;
56-
missing_argument:
57-
LD DE, MISSING_ARGUMENT_STR
58-
LD C, BDOS_OUTPUT_STRING
59-
call BDOS_ENTRY_POINT
60-
jr exit
6185

6286
not_cpmulator:
6387
LD DE, WRONG_EMULATOR
@@ -69,8 +93,10 @@ not_cpmulator:
6993
;;
7094
;; Text output strings.
7195
;;
72-
MISSING_ARGUMENT_STR:
73-
db "Usage: console [adm-3a|ansi]", 0x0a, 0x0d, "$"
96+
CONSOLE_PREFIX:
97+
db "Console driver is set to '$"
98+
CONSOLE_SUFFIX:
99+
db "'", 0x0a, 0x0d, "$"
74100
WRONG_EMULATOR:
75101
db "This binary is not running under cpmulator, aborting.", 0x0a, 0x0d, "$"
76102
END

0 commit comments

Comments
 (0)