Merge pull request #2 from gungwald/merlin-impl

Merlin impl
This commit is contained in:
Bill Chatfield 2024-02-17 12:09:17 -05:00 committed by GitHub
commit 5e7e35e72a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 641 additions and 85 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
MORE
MORE.dsk
_FileInformation.txt
*.swp

View File

@ -25,8 +25,8 @@ endif
# the PowerBook G4 and iBook G3. This version only requires Java 1.3.
AC=java -jar AppleCommander-1.3.5-ac.jar
SRC=more.s
PGM=more
BASE_DSK=prodos-2.0.3-boot.dsk
PGM=MORE
BASE_DSK=prodos-2.0.3.dsk
VOL=$(PGM)
DSK=$(PGM).dsk
@ -35,12 +35,13 @@ DSK=$(PGM).dsk
# disk instead.
#$(AC) -pro140 $(DSK) $(VOL)
$(DSK): $(PGM)
$(DSK): $(PGM) test.txt
$(COPY) $(BASE_DSK) $(DSK)
$(AC) -p $(DSK) $(PGM) BIN 0x8000 < $(PGM)
$(AC) -p $(DSK) $(PGM) BIN 0x2000 < $(PGM)
cat test.txt | tr '\n' '\r' | $(AC) -p $(DSK) TEST TXT
$(PGM): $(SRC) Makefile
merlin32 --verbose $(SRC)
merlin32 $(SRC)
clean:
$(RM) $(DSK) $(PGM) *.zip _FileInformation.txt $(PGM)_Output.txt

517
more.S
View File

@ -5,10 +5,26 @@
* *
********************************
* DSK MORE ;WRITE ASSEMBLED FILE TO DISK
* TYP $06 ;$FF=SYSTEM, $06=BINARY
.OR $2000 ;ASSEMBLE START ADDRESS
* Memory Map
*
* $0000 - $00FF Zero Page
* $0100 - $01FF Stack
* $0200 - $03FF Mostly Free, Input Buffer, Interrupt Vectors
* $0400 - $07FF Lo-res/Text Page1
* $0800 - $0BFF Lo-res/Text Page2 (BASIC programs load here)
* $0C00 - $1FFF Free
* $2000 - $3FFF Hi-res Page1
* $4000 - $5FFF Hi-res Page2
* $6000 - $95FF Free
* $9600 - $BFFF DOS3.3 and Buffers
* $C000 - $CFFF Soft Switches, Expansion Card I/O and ROM
* $D000 - $F7FF BASIC ROM (can be bankswitched later models)
* $F800 - $FFFF Machine Language Monitor ROM (also can be bankswitched)
DSK MORE ;WRITE ASSEMBLED FILE TO DISK
TYP $06 ;$FF=SYSTEM, $06=BINARY
ORG $2000 ;ASSEMBLE START ADDRESS
* SYSTEM VARIABLES
*
IN .EQ $200 ;256-CHAR INPUT BUF
@ -23,19 +39,26 @@ COUT .EQ $FDED
PRBYTE .EQ $FDDA
*
* SUBROUTINES IN BASIC.SYSTEM ROM:
*
GETBUFR .EQ $BEF5 ;ALLOCATE BUFFER, DESTROYS X & Y
FREEBUFR .EQ $BEF8 ;FREE BUFFER
*
GETBUFR EQU $BEF5 ;BCC=OKAY & A=HIBYTE OF BUF
;BCS=FAIL & A=ERRCODE
;X & Y ARE DESTROYED
FREEBUFR EQU $BEF8 ;FREE BUFFER
* PRODOS ENTRY POINT
PRODOS_MLI EQU $BF00 ;MACHINE LANG IFACE (MLI)
*
MLI .EQ $BF00
* MEMORY MAPPED I/O: $C000 - $CFFF
*
* MEMORY LOCATIONS
RD80VID EQU $C01F ;<=128->40COL, >128->80COL
*
OURCH .EQ $057B ;80-COL HORIZ CURSOR POSITION
OURCV .EQ $05FB ;VERTICAL CURSOR POSITION
* SLOT 3 SCRATCHPAD RAM - TEXT PAGE 0 SCREEN HOLE
* http://yesterbits.com/media/books/apple/heiserman-1983-intermediate-level-apple-ii-handbook.pdf
*
OURCH EQU $057B ;80-COL HORIZ CURSOR POSITION
OURCV EQU $05FB ;VERTICAL CURSOR POSITION
* ZERO-PAGE ADDRESSES
*
ZP.A1L .EQ $3C ;MONITOR GENERAL PURPOSE
@ -58,8 +81,8 @@ BUFSIZE .EQ $00FF
SCR.HGHT .EQ 24 ;SCREEN HEIGHT
*
* DEBUGGING
*
TRACE .EQ 0
TRACE EQU 0
********************************
* *
@ -164,31 +187,52 @@ MAIN CLD ;CLEAR DECIMAL FLG, AVOID CRASH
*
* GET FILE NAME
*
>PUTS PROMPT
PUTS INFOLINE
JSR CROUT
:ASKFILE PUTS PROMPT
JSR GETLN1 ;LENGTH IN X, CR AT END
CPX #0 ;IS THE LENGTH ZERO?
BEQ END ;USER JUST PRESSED RETURN
CPIN FILENAME ;COPY "IN" BUF TO FILENAME
BNE :CONT0 ;USER JUST PRESSED RETURN
JMP :END
:CONT0 CPX #1
BNE :CONT1
LDA #"?"
CMP IN
BNE :CONT1
JSR HELPINFO
JMP :ASKFILE
:CONT1 CPIN FILENAME ;COPY "IN" BUF TO FILENAME
DO TRACE
JSR PRSTRBYTES
JSR GETLN
FIN
*
* GET FILE I/O BUFFER FOR OPEN CALL
*
LDA #4 ;FOUR 256 BYTE PAGES = 1KB
JSR GETBUFR ;GET BUF FROM BASIC.SYSTEM
BCS ERRFWDR ;CARRY SET INDICATES AN ERROR
STA OBUFADDR+1 ;GETBUFR RETURNS HIBYTE IN A
BCC :CONT2 ;CARRY CLEAR MEANS NO ERROR
JSR OBUFERR
JMP :END
:CONT2 STA OBUFADDR+1 ;GETBUFR RETURNS HIBYTE IN A
LDA #0 ;PREPARE
STA OBUFADDR ;LOBYTE IS 0 B/C ADDR OF PAGE
*
* OPEN FILE
*
JSR MLI
JSR PRODOS_MLI
DB OPENCMD
DA OPENPRMS
BNE ERRFWDR
BEQ :CONT3
JSR OPENERR
JSR FREEBUFR ;CLEAN UP BEFORE TRY AGAIN
JMP :ASKFILE
*
* COPY FILE NUMBER FROM OPEN PARAMETERS TO READ AND CLOSE
*
LDA OPENFNUM
:CONT3 LDA OPENFNUM
STA READFNUM
STA CLOSFNUM
*
@ -196,49 +240,168 @@ MAIN CLD ;CLEAR DECIMAL FLG, AVOID CRASH
*
LDA #1 ;ONE 256 BYTE BUFFER
JSR GETBUFR ;CALL BASIC.SYSTEM SUB
BCS ERRFWDR ;CARRY SET MEANS ERROR
STA RBADDR+1 ;STORE HI-BYTE
STA ZP.A1H ;AGAIN, FOR 0-PAGE INDIRECTION
BCC :CONT4
JSR RBUFERR ;CARRY SET MEANS ERROR
JMP :CLOSFILE
:CONT4 STA RBADDR+1 ;STORE HI-BYTE
STA ZP_A1H ;FOR 0-PAGE INDIRECTION
LDA #0 ;0 FOR LO-BYTE
STA RBADDR ;STORE IT
STA ZP.A1L ;AGAIN, FOR 0-PAGE INDIRECTION
*
* PRINT THE FILE
*
JSR VIEWFILE ;MUST CLOSE BEFORE ERR HANDLING
JSR VIEWFILE
*
* FREE READ BUFFER
* CLEANUP
*
JSR FREEBUFR
JSR FREEBUFR ;FREE READ BUFFER
*
* CLOSE FILE
* Close file
*
JSR MLI
:CLOSFILE JSR PRODOS_MLI ;CLOSE THE FILE
DB CLOSCMD
DA CLOSPRMS
STA CLOSERR
*
* FREE FILE BUFFER USED IN OPEN CALL
*
JSR FREEBUFR
*
* CHECK FOR ERRORS
*
LDA READERR ;RELOAD THE READ RESULT CODE
CMP EOFERR ;WAS IT AN EOF "ERROR"
BEQ END ;EOF IS NOT REALLY AN ERROR
CMP #0
BNE ERRFWDR
LDA CLOSERR
BNE ERRFWDR
JMP END
*
* FINISH
*
ERRFWDR JSR ERRPROC
END NOP
BEQ :FREEOBUF
JSR CLOSERR
:FREEOBUF JSR FREEBUFR ;FREE OPEN I/O BUFFER
:END NOP
RTS
********************************
* *
* END OF MAIN - PROGRAM EXIT *
* *
********************************
********************************
* *
* PROGRAM INFO AND HELP *
* *
********************************
HELPINFO JSR CROUT
PUTS INFO0
JSR CROUT
PUTS INFO1
JSR CROUT
PUTS INFO2
JSR CROUT
PUTS INFO3
JSR CROUT
PUTS INFO4
JSR CROUT
JSR CROUT
RTS
********************************
* *
* HANDLE ERROR WHEN OPENING *
* FILE *
* *
********************************
OPENERR STA ERRCODE
PUTS OERRMSG
PUTS FILENAME
LDA #":"
JSR COUT
LDA ERRCODE
JSR ERRPROC
RTS
********************************
* *
* HANDLE ERROR WHEN CLOSING *
* FILE *
* *
********************************
CLOSERR STA ERRCODE
PUTS CERRMSG
PUTS FILENAME
LDA #"'"
JSR COUT
LDA #":"
JSR COUT
LDA ERRCODE
JSR ERRPROC
RTS
********************************
* *
* HANDLE ERROR WHEN REQUESTING *
* READ BUFFER *
* *
********************************
RBUFERR STA ERRCODE
PUTS RBERRMSG
LDA #":"
JSR COUT
LDA ERRCODE
JSR ERRPROC
RTS
********************************
* *
* HANDLE ERROR WHEN REQUESTING *
* READ BUFFER *
* *
********************************
OBUFERR STA ERRCODE
PUTS OBERRMSG
LDA #":"
JSR COUT
LDA ERRCODE
JSR ERRPROC
RTS
********************************
* *
* PRINT "IN" BUFFER *
* *
********************************
PRINT_IN
PUSHY
LDA #"X"
JSR COUT
LDA #"="
JSR COUT
TXA
JSR PRBYTE
JSR CROUT
LDY #0
:LOOP CPY #255
BEQ :ENDLOOP
LDA IN,Y
JSR PRBYTE
LDA #" "
JSR COUT
INY
JMP :LOOP
:ENDLOOP JSR CROUT
POPY
RTS
********************************
* *
* PRINT STRING BYTES *
* *
********************************
PRSTRBYTES
PUSHY
LDY #0
:LOOP CPY #255
BEQ :ENDLOOP
LDA FILENAME,Y
JSR PRBYTE
LDA #" "
JSR COUT
INY
JMP :LOOP
:ENDLOOP JSR CROUT
POPY
RTS
********************************
* *
* VIEW FILE SUB *
@ -250,18 +413,18 @@ VIEWFILE
>PUTS ENVIEW
FIN
>SET1 LINENUM ;INIT LINE NUMBER
.1 JSR MLI ;CALL PRODOS TO READ FILE
SET1 LINENUM ;INIT LINE NUMBER
:LOOP JSR PRODOS_MLI ;CALL PRODOS TO READ FILE
DB READCMD ;SPECIFY PRODOS READ COMMAND
DA READPRMS ;READ PARAMETERS
STA READERR ;SAVE RESULT OF READ OPERATION
BNE .2 ;IF ERROR THEN END SUB
BNE :READERR
JSR WRITEBUF ;WRITE TO SCREEN WHAT WAS READ
LDA #1 ;PREPARE FOR NEXT OP
CMP USRQUIT ;IF USER WANTS TO QUIT, THEN
BEQ .2 ;EXIT THE LOOP
JMP .1 ;ELSE, GET THE NEXT BUFFER
.2 NOP
BEQ :ENDLOOP ;EXIT THE LOOP
JMP :LOOP ;ELSE, GET THE NEXT BUFFER
:READERR JSR ERRPROC
:ENDLOOP NOP
RTS
********************************
@ -299,7 +462,7 @@ WRITEBUF
.3 >POPY
DO TRACE
>PUTS EXVIEW
PUTS EXWRITEBUF
FIN
RTS
@ -387,14 +550,172 @@ ERASEBAR
********************************
* *
* ERROR HANDLER *
* INPUT PARAM: A HOLDS ERRCODE *
* *
********************************
ERRPROC STA ERRCODE
>PUTS ERRTXT
JSR PRBYTE
JSR CROUT
RTS
ERRPROC
STA ERRCODE
CMP #0
BNE :EEOF
JMP :END
:EEOF CMP #EOFERR
BNE :E01
JMP :END
:E01 CMP #1
BNE :E04
PUTS E01MSG
JMP :END
:E04 CMP #4
BNE :E25
PUTS E04MSG
JMP :END
:E25 CMP #$25
BNE :E27
PUTS E25MSG
JMP :END
:E27 CMP #$27
BNE :E28
PUTS E27MSG
JMP :END
:E28 CMP #$28
BNE :E2B
PUTS E28MSG
JMP :END
:E2B CMP #$2B
BNE :E2E
PUTS E2BMSG
JMP :END
:E2E CMP #$2E
BNE :E40
PUTS E2EMSG
JMP :END
:E40 CMP #$40
BNE :E42
PUTS E40MSG
JMP :END
:E42 CMP #$42
BNE :E43
PUTS E42MSG
JMP :END
:E43 CMP #$43
BNE :E44
PUTS E43MSG
JMP :END
:E44 CMP #$44
BNE :E45
PUTS E44MSG
JMP :END
:E45 CMP #$45
BNE :E46
PUTS E45MSG
JMP :END
:E46 CMP #$46
BNE :E47
PUTS E46MSG
JMP :END
:E47 CMP #$47
BNE :E48
PUTS E47MSG
JMP :END
:E48 CMP #$48
BNE :E49
PUTS E48MSG
JMP :END
:E49 CMP #$49
BNE :E4A
PUTS E49MSG
JMP :END
:E4A CMP #$4A
BNE :E4B
PUTS E4AMSG
JMP :END
:E4B CMP #$4B
BNE :E4C
PUTS E4BMSG
JMP :END
:E4C CMP #$4C
BNE :E4D
PUTS E4CMSG
JMP :END
:E4D CMP #$4D
BNE :E4E
PUTS E4DMSG
JMP :END
:E4E CMP #$4E
BNE :E50
PUTS E4EMSG
JMP :END
:E50 CMP #$50
BNE :E51
PUTS E50MSG
JMP :END
:E51 CMP #$51
BNE :E52
PUTS E51MSG
JMP :END
:E52 CMP #$52
BNE :E53
PUTS E52MSG
JMP :END
:E53 CMP #$53
BNE :E55
PUTS E53MSG
JMP :END
:E55 CMP #$55
BNE :E56
PUTS E55MSG
JMP :END
:E56 CMP #$56
BNE :E57
PUTS E56MSG
JMP :END
:E57 CMP #$57
BNE :E5A
PUTS E57MSG
JMP :END
:E5A CMP #$5A
BNE :E_UNK
PUTS E5AMSG
JMP :END
:E_UNK PUTS E_UNK_MSG
LDA #":"
JSR COUT
LDA ERRCODE
JSR PRBYTE
:END JSR CROUT
RTS
********************************
* *
@ -402,26 +723,62 @@ ERRPROC STA ERRCODE
* *
********************************
PROMPT .DA #5 ;LENGTH BYTE
.AS "FILE:"
INFOLINE STR "ENTER [?] FOR PROGRAM INFO AND HELP"
INFO0 STR "MORE - PAGES THROUGH TEXT FILE"
INFO1 STR "COPYRIGHT (C) 2024 BILL CHATFIELD"
INFO2 STR "DISTRIBUTED UNDER THE GPL VERSION 3"
INFO3 STR "https://github.com/gungwald/prodos-more"
INFO4 STR "PRESS RETURN TO QUIT"
PROMPT STR "FILE:"
ERRTXT STR "ERROR:"
FILENAME DS $FF
ERRCODE DS 1
LINENUM DS 1
BAR STR '[RET] LINE [SPC] PAGE [Q]UIT'
USRQUIT DS 1
BUFCHAR DS 1
USRCHAR DS 1
ERRTXT .DA #6 ;LENGTH BYTE
.AS "ERROR:"
BAR .DA #42
.AS '[RET] NEXT LINE / [SPC] NEXT PAGE / [Q]UIT'
OERRMSG STR "CANNOT OPEN "
CERRMSG STR "CANNOT CLOSE "
RBERRMSG STR "CANNOT CREATE READ BUFFER"
OBERRMSG STR "CANNOT CREATE FILE BUFFER"
FILENAME .BS $FF
ERRCODE .BS 1
READERR .BS 1
CLOSERR .BS 1
LINENUM .BS 1
USRQUIT .BS 1
BUFCHAR .BS 1
USRCHAR .BS 1
E00MSG STR "NO ERROR"
E01MSG STR "BAD SYSTEM CALL NUMBER"
E04MSG STR "BAD SYSTEM CALL PARAMETER COUNT"
E25MSG STR "INTERRUPT TABLE FULL"
E27MSG STR "I/O ERROR"
E28MSG STR "NO DEVICE CONNECTED"
E2BMSG STR "DISK WRITE PROTECTED"
E2EMSG STR "DISK SWITCHED"
E40MSG STR "INVALID PATHNAME"
E42MSG STR "MAXIMUM NUMBER OF FILES OPEN"
E43MSG STR "INVALID REFERENCE NUMBER"
E44MSG STR "DIRECTORY NOT FOUND"
E45MSG STR "VOLUME NOT FOUND"
E46MSG STR "FILE NOT FOUND"
E47MSG STR "DUPLICATE FILENAME"
E48MSG STR "VOLUME FULL"
E49MSG STR "VOLUME DIRECTORY FULL"
E4AMSG STR "INCOMPATIBLE FILE FORMAT OR PRODOS DIRECTORY"
E4BMSG STR "UNSUPPORTED STORAGE TYPE"
E4CMSG STR "END OF FILE ENCOUNTERED"
E4DMSG STR "POSITION OUT OF RANGE"
E4EMSG STR "FILE ACCESS ERROR OR FILE LOCKED"
E50MSG STR "FILE IS OPEN"
E51MSG STR "DIRECTORY STRUCTURE DAMAGED"
E52MSG STR "NOT A PRODOS VOLUME"
E53MSG STR "INVALID SYSTEM CALL PARAMETER"
E55MSG STR "VOLUME CONTROL BLOCK TABLE FULL"
E56MSG STR "BAD BUFFER ADDRESS"
E57MSG STR "DUPLICATE VOLUME"
E5AMSG STR "FILE STRUCTURE DAMAGED"
E_UNK_MSG STR "UNKNOWN ERROR CODE"
ENVIEW STR 'ENTERING VIEWFILE'
EXVIEW STR 'EXITING VIEWFILE'
EXWRITEBUF STR 'EXITING WRITEBUF'
ENSTATB STR 'ENTERING STATUSBAR'
EXSTATB STR 'EXITING STATUSBAR'
ENERASEB STR 'ENTERING ERASEBAR'
@ -452,5 +809,5 @@ CLOSFNUM .BS 1
* CONSUME ALL BYTES UP TO THE NEXT PAGE BOUNDRY
*FILLER DS \,$00
* MUST START ON PAGE BOUNDRY
*OPENBUF .BS 1024
*READBUF .BS BUFSIZE
*OPENBUF DS 1024
*READBUF DS BUFSIZE

195
test.txt Normal file
View File

@ -0,0 +1,195 @@
MORE(1) User Commands MORE(1)
NAME
more - display the contents of a file in a terminal
SYNOPSIS
more [options] file ...
DESCRIPTION
more is a filter for paging through text one screenful at a time. This
version is especially primitive. Users should realize that less(1)
provides more(1) emulation plus extensive enhancements.
OPTIONS
Options are also taken from the environment variable MORE (make sure to
precede them with a dash (-)) but command-line options will override
those.
-d, --silent
Prompt with "[Press space to continue, 'q' to quit.]", and display
"[Press 'h' for instructions.]" instead of ringing the bell when an
illegal key is pressed.
-l, --logical
Do not pause after any line containing a ^L (form feed).
-e, --exit-on-eof
Exit on End-Of-File, enabled by default if POSIXLY_CORRECT
environment variable is not set or if not executed on terminal.
-f, --no-pause
Count logical lines, rather than screen lines (i.e., long lines are
not folded).
-p, --print-over
Do not scroll. Instead, clear the whole screen and then display the
text. Notice that this option is switched on automatically if the
executable is named page.
-c, --clean-print
Do not scroll. Instead, paint each screen from the top, clearing
the remainder of each line as it is displayed.
-s, --squeeze
Squeeze multiple blank lines into one.
-u, --plain
Suppress underlining. This option is silently ignored as backwards
compatibility.
-n, --lines number
Specify the number of lines per screenful. The number argument is a
positive decimal integer. The --lines option shall override any
values obtained from any other source, such as number of lines
reported by terminal.
-number
A numeric option means the same as --lines option argument.
+number
Start displaying each file at line number.
+/string
The string to be searched in each file before starting to display
it.
-h, --help
Display help text and exit.
-V, --version
Print version and exit.
COMMANDS
Interactive commands for more are based on vi(1). Some commands may be
preceded by a decimal number, called k in the descriptions below. In
the following descriptions, ^X means control-X.
h or ?
Help; display a summary of these commands. If you forget all other
commands, remember this one.
SPACE
Display next k lines of text. Defaults to current screen size.
z
Display next k lines of text. Defaults to current screen size.
Argument becomes new default.
RETURN
Display next k lines of text. Defaults to 1. Argument becomes new
default.
d or ^D
Scroll k lines. Default is current scroll size, initially 11.
Argument becomes new default.
q or Q or INTERRUPT
Exit.
s
Skip forward k lines of text. Defaults to 1.
f
Skip forward k screenfuls of text. Defaults to 1.
b or ^B
Skip backwards k screenfuls of text. Defaults to 1. Only works with
files, not pipes.
'
Go to the place where the last search started.
=
Display current line number.
/pattern
Search for kth occurrence of regular expression. Defaults to 1.
n
Search for kth occurrence of last regular expression. Defaults to
1.
!command or :!command
Execute command in a subshell.
v
Start up an editor at current line. The editor is taken from the
environment variable VISUAL if defined, or EDITOR if VISUAL is not
defined, or defaults to vi(1) if neither VISUAL nor EDITOR is
defined.
^L
Redraw screen.
:n
Go to kth next file. Defaults to 1.
:p
Go to kth previous file. Defaults to 1.
:f
Display current file name and line number.
.
Repeat previous command.
ENVIRONMENT
The more command respects the following environment variables, if they
exist:
MORE
This variable may be set with favored options to more.
SHELL
Current shell in use (normally set by the shell at login time).
TERM
The terminal type used by more to get the terminal characteristics
necessary to manipulate the screen.
VISUAL
The editor the user prefers. Invoked when command key v is pressed.
EDITOR
The editor of choice when VISUAL is not specified.
POSIXLY_CORRECT
Disable exit-on-eof (see option -e for more details).
HISTORY
The more command appeared in 3.0BSD. This man page documents more
version 5.19 (Berkeley 6/29/88), which is currently in use in the Linux
community. Documentation was produced using several other versions of
the man page, and extensive inspection of the source code.
AUTHORS
Eric Shienbrood, UC Berkeley.
Modified by Geoff Peck, UCB to add underlining, single spacing.
Modified by John Foderaro, UCB to add -c and MORE environment variable.
SEE ALSO
less(1), vi(1)
REPORTING BUGS
For bug reports, use the issue tracker at
https://github.com/util-linux/util-linux/issues.
AVAILABILITY
The more command is part of the util-linux package which can be
downloaded from Linux Kernel Archive
<https://www.kernel.org/pub/linux/utils/util-linux/>.
util-linux 2.39.3 2023-11-21 MORE(1)