10REM" A.MEDIT
20REM" FROM K1H
30REM" AUTHOR UNKNOWN
40MODE7
50REM VDU23,1,0;0;0;0;
60PRINT'''" Memory editor for the BBC
Micro"
70PRINT'" Asks for a start address an
d then"
80PRINT'" displays that area in memor
y in DFS"
90PRINT'" 'dump' format. This may be
edited"
100PRINT'" in hex or ASCII using the c
ursor keys"
110PRINT'" to move around and COPY to
switch"
120PRINT'" between hex and ASCII modes
."
130PRINT'''" Press any key to start"
140A=GET
150ON ERROR PROCerror
160
170PROCinit
180
190REPEAT
200IF hex% THEN VDU tabXY%,3*x%+6,y% E
LSE VDU tabXY%,offset%+x%,y%
210in%=GET
220IF in%>=copyCode% AND in%<=upCode%
THEN PROCcursor: GOTO 240
230IF hex% THEN PROChexInput ELSE PROC
asciiInput
240UNTIL FALSE
250
260DEF PROCinit
270REM Find height% (max y%+1), width%
(max x%+1) etc
280REM and set-up the screen for editi
ng
290
300INPUT "Address &"base$
310IF LEFT$(base$,1)="&" THEN base$=MI
D$(base$,2)
320base%=EVAL("&"+base$) AND &FFFF
330
340osbyte=&FFF4 : readVdu=&A0
350leftCol=&308 : bottomRow=&309
360rightCol=&30A: topRow=&30B
370
380PROCass
390
400width%=FNvduVar(rightCol)-FNvduVar(
leftCol)
410height%=FNvduVar(bottomRow)-FNvduVa
r(topRow)+1
420
430width%=(width%-5) DIV 4
440IF width%<1 THEN END ELSE width%=2^
INT(LN(width%)/LN(2))
450?`width=width%
460offset%=3*width%+5
470
480*FX4,1
490copyCode%=&87 : upCode%=&8B
500home%=30 : vt%=11
510shiftKey%=1
520
530hex%=TRUE : tabXY%=31
540x%=0 : y%=0
550CLS
560PROCinitScreen
570ENDPROC
580
590DEF FNvduVar(v%)
600REM read the v%th VDU variable
610A%=readVdu : X%=v%
620=USR osbyte DIV &100 AND &FF
630
640DEF PROCinitScreen
650REM Get the screen into its initial
state
660REM ie. full of hex and ASCII
670LOCAL y%
680VDU home%
690FOR y%=0 TO height%-1
700!`addr=base%+width%*y%
710CALL printRow
720IF y%<>height%-1 PRINT
730NEXT y%
740ENDPROC
750
760DEF PROCcursor
770REM Does and up, down, left or righ
t
780REM or switches between hex and ASC
II input
790IF in%=copyCode% THEN hex%=NOT hex%
: ENDPROC
800
810s%=INKEY-shiftKey%
820ON in%-copyCode% GOSUB 850,890,930,
980
830ENDPROC
840
850REM Cursor left
860IF s% THEN x%=0 ELSE IF x%>0 THEN x
%=x%-1 ELSE x%=width%-1:GOSUB 980
870RETURN
880
890REM Cursor right
900IF s% THEN x%=width%-1 ELSE IF x%<w
idth%-1 THEN x%=x%+1 ELSE x%=0:GOSUB 930
910RETURN
920
930REM Cursor down
940IF s% THEN base%=base%+width%*heigh
t%:PROCinitScreen:RETURN
950IF y%<height%-1 THEN y%=y%+1 ELSE P
RINT:base%=base%+width%:!`addr=base%+wid
th%*y%:CALL printRow
960RETURN
970
980REM Cursor up
990IF s% THEN base%=base%-width%*heigh
t%:PROCinitScreen:RETURN
1000IF y%>0 THEN y%=y%-1 ELSE VDUvt%:ba
se%=base%-width%:!`addr=base%+width%*y%:
CALL printRow
1010RETURN
1020
1030DEF PROChexInput
1040REM Treat in% as a hex digit if pos
sible
1050REM and updates the current locatio
n accordingly
1060IF in%<ASC"0" OR in%>ASC"F" THEN EN
DPROC
1070IF in%>ASC"9" AND in%<ASC"A" THEN E
NDPROC
1080IF in%>=ASC"A" THEN in%=10+in%-ASC"
A" ELSE in%=in%-ASC"0"
1090base%?(y%*width%+x%)=&10*base%?(y%*
width%+x%)+in%
1100!`addr=base%+width%*y%:CALL printRo
w
1110ENDPROC
1120
1130DEF PROCasciiInput
1140REM Treat in% as a character and up
dates
1150REM the current location accordingl
y
1160base%?(y%*width%+x%)=in%
1170!`addr=base%+width%*y%:CALL printRo
w
1180s%=0:GOSUB 890
1190ENDPROC
1200
1210DEF PROCass
1220REM Machine code to do one row of t
he dump
1230`addr=&71 : `width=&70
1240oswrch=&FFEE : cursorPos=&86
1250tabXY=31
1260DIM code 100
1270FOR opt=0 TO 2 STEP 2
1280P%=code
1290[OPT opt
1300.printRow
1310lda #cursorPos ½ Move 0,VPOS
1320jsr osbyte
1330lda #tabXY
1340jsr oswrch
1350lda #0
1360jsr oswrch
1370tya
1380jsr oswrch
1390lda `addr+1 ½ Print the address
1400jsr outHex
1410lda `addr
1420jsr outHexSpc ½ Followed by a spa
ce
1430ldy#0 ½ Do `width bytes
1440.loop1
1450lda (`addr),Y
1460jsr outHexSpc ½ First the hex
1470iny
1480cpy `width ½ Finished ?
1490bcc loop1
1500
1510ldy #0 ½ Now the ASCII par
t
1520.loop2
1530lda (`addr),Y
1540jsr outch ½ Print "." for non
-ascii
1550iny
1560cpy `width ½ Finished ?
1570bcc loop2
1580
1590rts
1600
1610.outHexSpc
1620jsr outHex ½ Print Acc in hex,
then space
1630lda #ASC" "
1640jmp oswrch
1650
1660.outHex
1670pha ½ First upper nibbl
e
1680lsr A
1690lsr A
1700lsr A
1710lsr A
1720jsr outNibble
1730pla ½ Then lower nibble
1740and #&0F
1750
1760.outNibble
1770cmp #10 ½ Letter ?
1780bcs letter
1790ora #ASC"0" ½ Make into ASCII
1800jmp oswrch
1810.letter
1820adc #ASC"A"-11 ½ Make into ASCII
1830jmp oswrch
1840
1850.outch
1860cmp #ASC" " ½ Print "." for non
-ascii
1870bcc outDot
1880cmp #ASC"÷"+1
1890bcc printIt
1900.outDot
1910lda #ASC"."
1920.printIt
1930jmp oswrch
1940]
1950NEXT
1960ENDPROC
1970
1980DEF PROCerror
1990*FX4
2000REPORT:PRINT" at line ";ERL
2010END