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