Skip to content

Commit 04bbf95

Browse files
authored
Merge pull request #251 from venomix666/more
more utility
2 parents dcf018b + 5874689 commit 04bbf95

File tree

4 files changed

+298
-3
lines changed

4 files changed

+298
-3
lines changed

apps/build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def asm(self, name, src: Target = None, deps: Targets = []):
3030
"dinfo",
3131
"dump",
3232
"ls",
33+
"more",
3334
"scrntest",
3435
"kbdtest",
3536
"xrecv",

apps/more.asm

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
\ Copyright © 2025 Henrik Löfgren
2+
\ This file is licensed under the terms of the 2-clause BSD license. Please
3+
\ see the COPYING file in the root project directory for the full text.
4+
5+
\ More utility, for viewing long text files
6+
7+
.include "cpm65.inc"
8+
.include "drivers.inc"
9+
10+
.zp linepos, 1
11+
.zp colpos, 1
12+
.zp linemax, 1
13+
.zp colmax, 1
14+
.zp screen_present, 1
15+
.zp temp, 1
16+
17+
.label BIOS
18+
.label SCREEN
19+
20+
.label cannot_open
21+
.label newline
22+
.label syntax_error
23+
.label more_wait
24+
.label more_wait_print
25+
.label more_exit
26+
.label more_newline
27+
.label more_string
28+
29+
.expand 1
30+
.label printchar
31+
32+
zproc start
33+
\ Did we get a parameter?
34+
35+
lda cpm_fcb + 1
36+
cmp #' '
37+
beq syntax_error
38+
39+
\ Try and open the file.
40+
41+
lda #0
42+
sta cpm_fcb+0x20 \ must clear CR before opening. Why?
43+
lda #<cpm_fcb
44+
ldx #>cpm_fcb
45+
ldy #BDOS_OPEN_FILE
46+
jsr BDOS
47+
bcs cannot_open
48+
49+
\ Set default values used without screen driver
50+
lda #0
51+
sta screen_present
52+
sta linepos
53+
sta colpos
54+
lda #39
55+
sta colmax
56+
lda #23
57+
sta linemax
58+
59+
\ Check if the screen driver is available
60+
ldy #BDOS_GET_BIOS
61+
jsr BDOS
62+
sta BIOS+1
63+
stx BIOS+2
64+
65+
lda #<DRVID_SCREEN
66+
ldx #>DRVID_SCREEN
67+
ldy #BIOS_FINDDRV
68+
jsr BIOS
69+
70+
\ Driver found?
71+
zif cc
72+
sta SCREEN+1
73+
stx SCREEN+2
74+
lda #1
75+
sta screen_present
76+
77+
\ Get screen size
78+
ldy #SCREEN_GETSIZE
79+
jsr SCREEN
80+
sta colmax
81+
stx linemax
82+
dec linemax
83+
84+
\ Clear screen
85+
ldy #SCREEN_CLEAR
86+
jsr SCREEN
87+
88+
\ Set cursor position at 0,0
89+
lda #0
90+
ldx #0
91+
ldy #SCREEN_SETCURSOR
92+
jsr SCREEN
93+
zendif
94+
95+
\ Print the file
96+
97+
lda #<cpm_default_dma
98+
ldx #>cpm_default_dma
99+
ldy #BDOS_SET_DMA
100+
jsr BDOS
101+
102+
zloop
103+
lda #<cpm_fcb
104+
ldx #>cpm_fcb
105+
ldy #BDOS_READ_SEQUENTIAL
106+
jsr BDOS
107+
zbreak cs
108+
109+
ldy #128
110+
sty temp
111+
zrepeat
112+
ldy temp
113+
lda cpm_default_dma-128,y
114+
cmp #26
115+
beq more_exit
116+
\ Newline?
117+
cmp #13
118+
zif eq
119+
lda #0
120+
sta colpos
121+
inc linepos
122+
lda #13
123+
jsr printchar
124+
jmp more_newline
125+
zendif
126+
jsr printchar
127+
128+
\ End of line?
129+
lda colpos
130+
cmp colmax
131+
zif eq
132+
lda #0
133+
sta colpos
134+
inc linepos
135+
jmp more_newline
136+
zendif
137+
138+
inc colpos
139+
more_newline:
140+
\ End of screen?
141+
lda linepos
142+
cmp linemax
143+
zif eq
144+
lda #0
145+
sta linepos
146+
\ Wait for keypress
147+
jsr more_wait
148+
\ Exit if Q,q or ctrl+c is pressed
149+
cmp #'q'
150+
beq more_exit
151+
cmp #'Q'
152+
beq more_exit
153+
cmp #3
154+
beq more_exit
155+
\ Only scroll one line if enter is pressed
156+
cmp #13
157+
bne more_nextpage
158+
ldx linemax
159+
dex
160+
stx linepos
161+
lda #0
162+
sta colpos
163+
\ Clear last line if screen driver is present
164+
lda screen_present
165+
cmp #1
166+
zif eq
167+
lda #0
168+
ldx linemax
169+
inx
170+
ldy #SCREEN_SETCURSOR
171+
jsr SCREEN
172+
173+
ldy #SCREEN_CLEARTOEOL
174+
jsr SCREEN
175+
176+
lda #0
177+
ldx linemax
178+
ldy #SCREEN_SETCURSOR
179+
jsr SCREEN
180+
181+
zendif
182+
\ Otherwise just emit a newline
183+
lda screen_present
184+
cmp #1
185+
zif ne
186+
jsr newline
187+
zendif
188+
jmp more_done
189+
more_nextpage:
190+
\ Setup for next page of text
191+
jsr newline
192+
lda screen_present
193+
cmp #1
194+
zif eq
195+
ldy #SCREEN_CLEAR
196+
jsr SCREEN
197+
198+
lda #0
199+
ldx #0
200+
ldy #SCREEN_SETCURSOR
201+
jsr SCREEN
202+
zendif
203+
more_done:
204+
zendif
205+
inc temp
206+
zuntil eq
207+
zendloop
208+
209+
more_exit:
210+
jmp newline
211+
rts
212+
zendproc
213+
214+
BIOS:
215+
jmp 0
216+
217+
SCREEN:
218+
jmp 0
219+
220+
zproc syntax_error
221+
lda #<msg
222+
ldx #>msg
223+
ldy #BDOS_PRINTSTRING
224+
jmp BDOS
225+
msg:
226+
.byte "No input file", 13, 10, 0
227+
zendproc
228+
229+
zproc cannot_open
230+
lda #<msg
231+
ldx #>msg
232+
ldy #BDOS_PRINTSTRING
233+
jmp BDOS
234+
msg:
235+
.byte "Cannot open file", 13, 10, 0
236+
zendproc
237+
238+
zproc more_wait
239+
jsr newline
240+
jsr more_wait_print
241+
\ Wait for a keystroke
242+
ldx #0xfd
243+
ldy #BDOS_CONIO
244+
jsr BDOS
245+
rts
246+
zendproc
247+
248+
zproc more_wait_print
249+
\ Print a fancy more prompt if a screen driver is present
250+
lda screen_present
251+
cmp #1
252+
zif eq
253+
lda #1
254+
ldy #SCREEN_SETSTYLE
255+
jsr SCREEN
256+
lda #0
257+
ldx linemax
258+
inx
259+
ldy #SCREEN_SETCURSOR
260+
jsr SCREEN
261+
lda #<more_string
262+
ldx #>more_string
263+
ldy #SCREEN_PUTSTRING
264+
jsr SCREEN
265+
lda #0
266+
ldy #SCREEN_SETSTYLE
267+
jmp SCREEN
268+
zendif
269+
\ Just print the string if it's not
270+
lda #<more_string
271+
ldx #>more_string
272+
ldy #BDOS_PRINTSTRING
273+
jmp BDOS
274+
zendproc
275+
276+
more_string:
277+
.byte "--More--", 0
278+
279+
zproc printchar
280+
ldy #BDOS_CONOUT
281+
jmp BDOS
282+
zendproc
283+
284+
zproc newline
285+
lda #13
286+
jsr printchar
287+
lda #10
288+
jmp printchar
289+
zendproc
290+
291+
\ vim: filetype=asm sw=4 ts=4 et
292+

293+

config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"0:ls.com": "apps+ls",
1515
"0:stat.com": "apps+stat",
1616
"0:submit.com": "apps+submit",
17+
"0:more.com": "apps+more",
1718
}
1819

1920
# Programs which only work on a real CP/M filesystem (not emulation).

src/arch/osi/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@
338338
}
339339
| MINIMAL_APPS
340340
| BIG_APPS
341-
| SCREEN_APPS
342-
| BIG_SCREEN_APPS,
341+
| SCREEN_APPS,
343342
)
344343

345344
mkcpmfs(
@@ -351,7 +350,8 @@
351350
}
352351
| MINIMAL_APPS_SRCS
353352
| BIG_APPS_SRCS
354-
| SCREEN_APPS_SRCS,
353+
| SCREEN_APPS_SRCS
354+
| BIG_SCREEN_APPS,
355355
)
356356

357357
mkcpmfs(

0 commit comments

Comments
 (0)